⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ifo2tfwdlg.cpp

📁 ifo文件算tfw信息文件VC++编写
💻 CPP
字号:
// Ifo2TfwDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Ifo2Tfw.h"
#include "Ifo2TfwDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
///////////////////////
int is_num(char c)
	{if ( (c>='0')&&(c<='9') || (c=='.') || (c=='-'))
	 return 1;
	 return 0;}
int is_nums(char *s)
	{ int done=1;
	while(*s) {if(!is_num(*s)){ done=0;goto BG;}s++;}
	BG:;
	if(*s=='\0')  done=1;
	return done;
	}

int is_fgf(char *ch)
	{
		return(!strcmp(ch," ")||!strcmp(ch,"\n")|| !strcmp(ch,";")||!strcmp(ch,",")||!strcmp(ch,"	")||!strcmp(ch,"=") ? 1:0);
	}

int readWord(char *s,FILE *f)
{ 
	int ret=0;
	char *stm=new char[64],ch[]=" ";
	strcpy(stm,"");
	do
	{
		fgets(ch,2,f);
		}while((!feof(f))&&is_fgf(ch));
    do
	{
		if((strcmp(ch,"\n")) && strcmp(ch," ") )strcat(stm,ch);
		fgets(ch,2,f);
	}while((!feof(f))&&(!is_fgf(ch)));
	if(!feof(f))
	{
		strcpy(s,stm);
		ret=1;
	}
	delete stm;
	return ret;
}

int readLine(char *s,FILE *f)
{ 
	int ret=0;
	char *stm=new char[1024],ch[]=" ";
	strcpy(stm,"");
	do
	{
		fgets(ch,2,f);
		}while((!feof(f))&& !strcmp(ch,"\n"));
    do
	{
		if((strcmp(ch,"\n")))strcat(stm,ch);
		fgets(ch,2,f);
	}while((!feof(f)) && strcmp(ch,"\n"));
	if(!feof(f))
	{
		strcpy(s,stm);
		ret=1;
	}
	delete stm;
	return ret;
}
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CIfo2TfwDlg dialog

CIfo2TfwDlg::CIfo2TfwDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CIfo2TfwDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CIfo2TfwDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CIfo2TfwDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CIfo2TfwDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CIfo2TfwDlg, CDialog)
	//{{AFX_MSG_MAP(CIfo2TfwDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_OPEN, OnOpen)
	ON_BN_CLICKED(IDC_SUB, OnSub)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CIfo2TfwDlg message handlers

BOOL CIfo2TfwDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	mSub=true;
	CheckDlgButton(IDC_SUB,mSub);
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CIfo2TfwDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CIfo2TfwDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CIfo2TfwDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CIfo2TfwDlg::OnOpen() 
{
	// TODO: Add your control notification handler code here
	BROWSEINFO bi;
	char dispname[MAX_PATH],path[MAX_PATH];
	ITEMIDLIST *pidl;
	bi.hwndOwner=this->m_hWnd;
	bi.pidlRoot=0;
	bi.pszDisplayName=dispname;
	bi.lpszTitle="选择测区路径:";
	bi.ulFlags=BIF_RETURNONLYFSDIRS;
	bi.lpfn=0;
	bi.lParam=0;
	bi.iImage=0;
	if(pidl=SHBrowseForFolder(&bi))
	{
		SHGetPathFromIDList(pidl,path);
		
	}
	else
	{
		return;
	}
	CString str(path);
	if(str.Right(1)!='\\')str+="\\";
	SetDlgItemText(IDC_PATH,str);
}
void ifo2tfw(CString path,bool sub)
{
	int fd=1;
	WIN32_FIND_DATA ffd ;
	char szDirFile[MAX_PATH];
	sprintf(szDirFile,"%s%s",path,"*.*");
	HANDLE hFind = FindFirstFile(szDirFile,&ffd);
	while((hFind != INVALID_HANDLE_VALUE) && fd)
	{
		DWORD a=ffd.dwFileAttributes;
		if(!strcmp(ffd.cFileName,".") || !strcmp(ffd.cFileName,"..")) a=0;
		CString name=ffd.cFileName;
		name.MakeLower();

		if(a & FILE_ATTRIBUTE_DIRECTORY && sub)
		{
			CString npath;//=new char[strlen(path)+strlen(find_data.cFileName)+1];
			npath =path+name+"\\";
			ifo2tfw(npath,sub);
		}
		else
		if(name.Right(4)==".ifo")
		{
			CString pn=path+name;
			CString tfw=pn.Left(pn.GetLength()-3)+"tfw";
			FILE *ftfw,*fifo;
			fifo=fopen(pn,"rt");
			ftfw=fopen(tfw,"wt");
			char w[80];
			while(!feof(fifo))
			{
				readLine(w,fifo);
				if(!strcmp(w,"[Image info]"))
				{
					double x,y,fbl;
					int ret;
					readWord(w,fifo);
					if(!strcmp(w,"Data"))
					{
						readLine(w,fifo);
						readLine(w,fifo);
						readLine(w,fifo);
						readLine(w,fifo);
						readLine(w,fifo);
						readWord(w,fifo);
						readWord(w,fifo);
						y=atof(w);
						readWord(w,fifo);
						readWord(w,fifo);
						x=atof(w);
						readWord(w,fifo);
						ret=readWord(w,fifo);
						CString HBL=w;
						int n=HBL.Find("米");
						HBL=HBL.Left(n);
						fbl=atof(HBL);
					}
					else
					{
						readLine(w,fifo);
						readLine(w,fifo);
						readLine(w,fifo);
						readWord(w,fifo);
						readWord(w,fifo);
						int H=atoi(w);
						readLine(w,fifo);
						readLine(w,fifo);
						readLine(w,fifo);
						readLine(w,fifo);
						readWord(w,fifo);
						readWord(w,fifo);
						readWord(w,fifo);
						y=atof(w);
						readWord(w,fifo);
						readWord(w,fifo);
						readWord(w,fifo);
						x=atof(w);
						readWord(w,fifo);
						ret=readWord(w,fifo);
						fbl=atof(w);
						y=y+H*fbl;
					}
					if(ret>0)
					{
						fprintf(ftfw,"%24.6lf\n",fbl);
						fprintf(ftfw,"                0.000000\n");
						fprintf(ftfw,"                0.000000\n");
						fprintf(ftfw,"%24.6lf\n",-fbl);
						fprintf(ftfw,"%24.6lf\n",x);
						fprintf(ftfw,"%24.6lf\n",y);
					}
				}
			}
			fclose(fifo);
			fclose(ftfw);
		}
		fd=FindNextFile(hFind,&ffd);
	}
}
void CIfo2TfwDlg::OnOK() 
{
	// TODO: Add extra validation here
	CString path;
	GetDlgItemText(IDC_PATH,path);
	ifo2tfw(path,mSub);
//	CDialog::OnOK();
}

void CIfo2TfwDlg::OnSub() 
{
	// TODO: Add your control notification handler code here
	if(mSub)
		mSub=false;
	else
		mSub=true;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -