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

📄 dxfdlg.cpp

📁 利用VC++开发
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// DXFDlg.cpp : implementation file
//

#include "stdafx.h"
#include "DXF.h"
#include "DXFDlg.h"
#include "ProgDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
DUANMIAN  m_date;
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()

/////////////////////////////////////////////////////////////////////////////
// CDXFDlg dialog

CDXFDlg::CDXFDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDXFDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDXFDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	
	m_DrawingWindow.m_pDrawing = &drawing;

}

void CDXFDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDXFDlg)
	DDX_Control(pDX, IDC_BUTTON9, m_9);
	DDX_Control(pDX, IDC_BUTTON8, m_8);
	DDX_Control(pDX, IDC_BUTTON6, m_6);
	DDX_Control(pDX, IDC_BUTTON7, m_7);
	DDX_Control(pDX, IDC_BUTTON5, m_5);
	DDX_Control(pDX, IDC_BUTTON4, m_4);
	DDX_Control(pDX, IDC_BUTTON3, m_3);
	DDX_Control(pDX, IDC_BUTTON2, m_2);
	DDX_Control(pDX, IDC_BUTTON1, m_1);
	DDX_Control(pDX, IDC_DXFVIEW, m_DrawingWindow);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CDXFDlg, CDialog)
	//{{AFX_MSG_MAP(CDXFDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON8, OnSaveDxf)
	ON_BN_CLICKED(IDC_BUTTON4, OnZoomIN)
	ON_BN_CLICKED(IDC_BUTTON5, OnZoomOut)
	ON_BN_CLICKED(IDC_BUTTON3, OnExit)
	ON_BN_CLICKED(IDC_BUTTON6, OnZoomExtents)
	ON_WM_MOUSEWHEEL()
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_BUTTON9, OnOPENDXF)
	ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDXFDlg message handlers

BOOL CDXFDlg::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
	
	// TODO: Add extra initialization here
	short	shBtnColor = 30;
	//m_1.SetIcon(IDI_1);
	m_1.SetIcon(IDI_1, 16, 16, IDI_1, 32, 32);
    m_1.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, shBtnColor);
    
//	m_1.SetFlat(FALSE);
	m_8.SetIcon(IDI_80, IDI_81);
	
    m_8.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, shBtnColor);
	#ifdef	BTNST_USE_SOUND
	m_8.SetSound(MAKEINTRESOURCE(IDR_WAVE1), ::GetModuleHandle(NULL));
      #endif
    //m_9.SetIcon(IDI_9);
	m_9.SetIcon(IDI_9, 16, 16, IDI_9, 32, 32);
    m_9.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, shBtnColor);
    m_7.SetIcon(IDI_70, IDI_71);
    m_7.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, shBtnColor);
    m_4.SetIcon(IDI_41, IDI_40);
	m_4.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, shBtnColor);
	//m_5.SetIcon(IDI_5);
	m_5.SetIcon(IDI_5, 16, 16, IDI_5, 32, 32);
    m_5.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, shBtnColor);
   // m_6.SetIcon(IDI_6);
	m_6.SetIcon(IDI_6, 16, 16, IDI_6, 32, 32);
    m_6.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, shBtnColor);
	//m_3.SetIcon(IDI_3);
	m_3.SetIcon(IDI_3, 16, 16, IDI_3, 32, 32);
    m_3.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, shBtnColor);
	//m_2.SetIcon(IDI_2);
	m_2.SetIcon(IDI_2, 16, 16, IDI_2, 32, 32);
	m_2.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, shBtnColor);

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CDXFDlg::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 CDXFDlg::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 CDXFDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CDXFDlg::OnButton1() 
{
	

	

	// TODO: Add your command handler code here
	TRY
{
		// TODO: Add your command handler code here
	    double n;
		CString strLine;
		CString ss;
		
	//	int i=1;int j=1; int k=1;
		CFileDialog dlg(TRUE);
		dlg.m_ofn.lpstrTitle="请选择横断面文件";
		dlg.m_ofn.lpstrFilter="text files(*.txt)\0*.txt\0dat files(*.dat)\0*.dat\0all files(*.*)\0*.*\0\0;";
		dlg.m_ofn.lpstrDefExt="";
		if(dlg.DoModal() == IDOK)
		{
			CString inFile = dlg.GetPathName();
			CStdioFile txtFile;
			txtFile.Open( inFile, CFile::modeRead);
	
			BOOL  flag=txtFile.ReadString(strLine);
            while(flag&&strLine.Compare("")!=0)
			{
				if(strLine.Find(",")==-1)
				{
						DUANMIANDATE *p=new DUANMIANDATE;
						 strLine.TrimLeft();
	                     strLine.TrimRight();
						 n=atof(strLine);
						//_stscanf(strLine,_T("%f"),&n);
						p->zhuanghao=n;
						if(txtFile.ReadString(strLine)&&strLine.Compare("")!=0)
						{
								if(strLine.Find(",")!=-1)
								{
								          p->ReadYOUorZOU1(strLine);
										  if(txtFile.ReadString(strLine)&&strLine.Compare("")!=0)
										  {
												  if(strLine.Find(",")!=-1)
												  {

													 p->ReadYOUorZOU(strLine);
													 m_date.AddTail(p);
													 flag=txtFile.ReadString(strLine);
                                                     
												  }
												  else
												  m_date.AddTail(p);

										  }
										  else 
										  break;
								  }
								  else
								  {
								 m_date.AddTail(p);
								  }
                                // flag=txtFile.ReadString(strLine);

							}
				    		else
							{
					    		m_date.AddTail(p);
					    		break;
							}
					}
			    	else
					flag=txtFile.ReadString(strLine);
				
						
				}


            txtFile.Close();
			}

			CString s;
            int m=m_date.GetCount();
			if(m>=1)
			{
			DUANMIANDATE *P1,*P2;
			POSITION pos1=m_date.FindIndex(0);
     		POSITION pos2=m_date.FindIndex(m-1);

			P1=m_date.GetAt(pos1);
			P2=m_date.GetAt(pos2);
			
			s.Format("导入数据是从桩号%f到%f!\n一共%d组数据",P1->zhuanghao,P2->zhuanghao,m);
			AfxMessageBox(s,MB_ICONSTOP );
		    
            }



	
}

CATCH( CFileException, e )
{
    if( e->m_cause == CFileException::fileNotFound )
        AfxMessageBox( "ERROR: File not found\n");
	if( e->m_cause == CFileException::badSeek )
	{
		 AfxMessageBox( "ERROR:   There was an error trying to set the file pointer\n");
	}
	 if( e->m_cause == CFileException::generic  )
        AfxMessageBox( "ERROR: An unspecified error occurred");
	
      if( e->m_cause == CFileException::invalidFile  )
        AfxMessageBox( "ERROR: An unspecified error occurred");
	
}
END_CATCH
}

void CDXFDlg::OnSaveDxf() 
{
	if(m_date.GetCount()>0)
	{

 TURN_DATE_DXF();
// TODO: Add your control notification handler code here
	static char szFilter[] = "DXF file format(*.dxf) |*.dxf|All Files (*.*)|*.*||";

	CFileDialog SaveDlg( FALSE, NULL, NULL/*LastFilePath*/, OFN_HIDEREADONLY | OFN_EXPLORER, szFilter, NULL );
	SaveDlg.m_ofn.lpstrTitle = "Save DXF File As";

	if(SaveDlg.DoModal()==IDOK)
	{	// Saving sample dxf file data
		CString DxfFileName( SaveDlg.GetPathName() );
//		CDrawing drw;

		if(SaveDlg.GetFileExt().IsEmpty())
			DxfFileName += ".dxf";

		BOOL result=TRUE;

		// Create Drawing
		if(!drawing.Create())
		{
			MessageBox("Fatal error on creating CDrawing!", "Error", MB_ICONERROR | MB_OK);
			return;
		}

		// Tables Section ------------------------------------------
		//  LTYPE table type -------------------------
		LTYPE		ltype;
		OBJHANDLE	objhandle1;

		//  Continuous
		ZeroMemory(&ltype, sizeof(ltype));
		strcpy(ltype.Name, "Continuous");
		strcpy(ltype.DescriptiveText, "Solid line");
		objhandle1 = drawing.AddLinetype(&ltype);

		//  DASHDOT2
		ZeroMemory(&ltype, sizeof(ltype));
		strcpy(ltype.Name, "DASHDOT2");
		strcpy(ltype.DescriptiveText, "Dash dot (.5x) _._._._._._._._._._._._._._._.");
		ltype.ElementsNumber = 4;
		ltype.PatternLength = 0.5;
		ltype.Elements[0] = 0.25;
		ltype.Elements[1] = -0.125;
		ltype.Elements[2] = 0.0;
		ltype.Elements[3] = -0.125;
		drawing.AddLinetype(&ltype);

		//  LAYER table type -------------------------
		LAYER	layer;

		// Layer1
		ZeroMemory(&layer, sizeof(layer));
		strcpy(layer.Name, "Layer1");
		layer.Color = 1;
		layer.LineTypeObjhandle = objhandle1; // Continuous
		drawing.AddLayer(&layer);

		// Layer2
		ZeroMemory(&layer, sizeof(layer));
		strcpy(layer.Name, "Layer2");
		layer.Color = 2;
		layer.LineTypeObjhandle = objhandle1; // Continuous
		drawing.AddLayer(&layer);

		// Layer3
		ZeroMemory(&layer, sizeof(layer));
		strcpy(layer.Name, "Layer3");
		layer.Color = 3;

⌨️ 快捷键说明

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