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

📄 forcaddlg.cpp

📁 Can convert data file(txt format)to CAD(scr)file,and draw curve!
💻 CPP
字号:
// ForCADDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ForCAD.h"
#include "ForCADDlg.h"

#include "stdio.h"
#include "fstream.h"
#include "conio.h"
#include "string.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CForCADDlg dialog

CForCADDlg::CForCADDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CForCADDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CForCADDlg)
	m_edit_openfile = _T("");
	m_edit_closefile = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CForCADDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CForCADDlg)
	DDX_Text(pDX, IDC_EDIT_OPENFILE, m_edit_openfile);
	DDX_Text(pDX, IDC_EDIT_SAVEFILE, m_edit_closefile);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CForCADDlg, CDialog)
	//{{AFX_MSG_MAP(CForCADDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_OPEN, OnButtonOpen)
	ON_BN_CLICKED(IDC_BUTTON_SEVE, OnButtonSeve)
	ON_BN_CLICKED(IDC_BUTTON_LOOK, OnButtonLook)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CForCADDlg message handlers

BOOL CForCADDlg::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

	//this->ShowWindow(SW_SHOWMAXIMIZED);//最大化窗口
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CForCADDlg::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 CForCADDlg::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 CForCADDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}
CString filename;//申明文件名变量
CString filename1;
CString savefilename;
int kk;
void CForCADDlg::OnOK() 
{
	// TODO: Add extra validation here
	kk=0;
	float temp;
	float Depth[200];
	float L[200];
	float Lurong[200];
	ifstream in(filename);//提取文件
loop:
	if(in.eof()==0)
	{
		in>>temp;//读深度
		Depth[kk]=temp;
		temp=NULL;

		in>>temp;
		L[kk]=temp;///存原始数据的数组
		temp=NULL;
	
		if(L[kk]!=1000*Lurong[kk])
		{
			kk++;
			goto loop;
		}
		else goto ppp;
	}

ppp:
	in.close();

	ofstream out(savefilename);//写文件
	out<<"PLINE"<<"\n";
	for(int i=0;i<kk;i++)
		Lurong[i]=float(L[i]/1);///////吕荣值
	out<<Lurong[0]<<","<<-Depth[0]<<"\n";//画线起始点的位置
	out<<"0"<<"\n";
	out<<"w"<<"\n";
	out<<"0.015"<<"\n";
	out<<"0.015"<<"\n";
	out<<Lurong[0]<<","<<-Depth[1]<<"\n";
    for(int p=2;p<kk-1;p++) 
	{
		out<<Lurong[p]<<","<<-Depth[p-1]<<"\n";//PLine输出操作
		out<<Lurong[p]<<","<<-Depth[p]<<"\n";
	}
	out<<Lurong[kk-2]<<","<<-Depth[kk-3]<<"\n";
	out<<Lurong[kk-2]<<","<<-Depth[kk-2]<<" "<<"\n";
	
	

///////////////画竖线///////////
	out<<"pline"<<"\n";
	out<<Lurong[0]<<","<<-Depth[0]<<"\n";
	out<<0<<"\n";
	out<<"w"<<"\n";
	out<<"0.01"<<"\n";
	out<<"0.01"<<"\n";
	out<<0<<","<<-Depth[0]<<"\n";
	out<<0<<","<<-Depth[kk-2]<<"\n";
	out<<Lurong[kk-2]<<","<<-Depth[kk-2]<<" "<<"\n";
	
/////////////////写文字/////////////////
	out<<"text"<<"\n";
	out<<2.5<<","<<0.8<<"\n";
	out<<0.3<<"\n";
	out<<0<<"\n";
	out<<filename1<<"\n";
	
	out<<"zoom"<<"\n";//////////显示合适大小
	out<<"e"<<"\n";

	
}

void CForCADDlg::OnButtonOpen() 
{
	// TODO: Add your control notification handler code here
	CString Filter="文本文件(*.txt)|*.txt|所有文件|*.*||";
	CString String;

	CFileDialog dlgOpenFile(TRUE,0,0,OFN_HIDEREADONLY|OFN_FILEMUSTEXIST|OFN_LONGNAMES,(LPCTSTR)Filter);
	dlgOpenFile.m_ofn.lpstrTitle=_T("打开文本文件");
	int iRet=dlgOpenFile.DoModal();
	if(iRet!=IDOK)
		return;
	String=dlgOpenFile.GetPathName();/////////获得路径名

	filename1=dlgOpenFile.GetFileTitle ();/////////只获得文件名////////
	
	m_edit_openfile=String;
	UpdateData(FALSE);
	filename=dlgOpenFile.GetFileName();///取回文件名
}

void CForCADDlg::OnButtonSeve() 
{
	// TODO: Add your control notification handler code here
	CString Filter="CAD脚本文件(*.scr)|*.scr|文本文件|*.txt|所有文件|*.*||";
	CString String;
	CFileDialog dlgSaveFile(FALSE,"scr","*.scr",OFN_HIDEREADONLY|OFN_LONGNAMES,(LPCTSTR)Filter);
	dlgSaveFile.m_ofn.lpstrTitle=_T("保存文件路径");
	int iRet=dlgSaveFile.DoModal();
	if(iRet!=IDOK)
		return;
	/////////////// 判断文件是否已存在
	ifstream file2;
    file2.open(dlgSaveFile.GetFileName(),ios::nocreate);
    if(file2)
    {
		int ret=AfxMessageBox(dlgSaveFile.GetPathName()+"该文件已经存在,要替换吗?",MB_YESNO);
		if(ret != IDYES)
			return;
		CDialog::OnClose();
     }
	/////////////////////
	String=dlgSaveFile.GetPathName();	
	m_edit_closefile=String;
	UpdateData(FALSE);

	savefilename=dlgSaveFile.GetFileName();//所保存文件的名字
}

void CForCADDlg::OnButtonLook() 
{
	// TODO: Add your control notification handler code here
	ShellExecute(NULL, "open", "1-1孔曲线图.dwg" , NULL, "", SW_SHOWNORMAL);//直接打打开CAD文件
	//ShellExecute(NULL, "open", "1-1孔曲线图.dwg" , NULL, ".\\", SW_SHOWNORMAL);//2000以上系统用
}

⌨️ 快捷键说明

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