162 lines
3.9 KiB
C++
162 lines
3.9 KiB
C++
// ModifyPatDlg.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "ModifyPatDlg.h"
|
|
#include "resource.h"
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CModifyPatDlg dialog
|
|
|
|
|
|
CModifyPatDlg::CModifyPatDlg(CWnd* pParent /*=NULL*/)
|
|
: CModelessDialog(CModifyPatDlg::IDD, pParent)
|
|
{
|
|
//{{AFX_DATA_INIT(CModifyPatDlg)
|
|
m_sPatName = _T("");
|
|
m_sSpinScale = _T("1");
|
|
//}}AFX_DATA_INIT
|
|
}
|
|
|
|
|
|
void CModifyPatDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CModifyPatDlg)
|
|
DDX_Control(pDX, IDC_SPIN1, m_cSpinScale);
|
|
DDX_Text(pDX, IDC_EDIT_PAT, m_sPatName);
|
|
DDX_Text(pDX, IDC_EDIT_SCALE, m_sSpinScale);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CModifyPatDlg, CModelessDialog)
|
|
//{{AFX_MSG_MAP(CModifyPatDlg)
|
|
ON_EN_CHANGE(IDC_EDIT_SCALE, OnChangeEditScale)
|
|
ON_WM_DESTROY()
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CModifyPatDlg message handlers
|
|
|
|
void CModifyPatDlg::PreView()
|
|
{
|
|
AcDbBlockTable *pBlockTab=NULL;
|
|
VERIFY(dbPreview.getSymbolTable(pBlockTab, AcDb::kForWrite)==Acad::eOk);
|
|
AcDbBlockTableRecord *pMspace = new AcDbBlockTableRecord;
|
|
pMspace->setName(_T("*U"));
|
|
pBlockTab->add(pMspace);
|
|
pBlockTab->close();
|
|
|
|
XPoly2D polyRect(1);
|
|
polyRect.AppendNode(XPoint(0,0));
|
|
polyRect.AppendNode(XPoint(0,1));
|
|
polyRect.AppendNode(XPoint(1,1));
|
|
polyRect.AppendNode(XPoint(1,0));
|
|
AcDbHatch *pHatch = NewHatchFromPoly2D(polyRect,LPCTSTR(m_sPatName),0.1);
|
|
if(pHatch!=NULL)
|
|
{
|
|
if(pMspace->appendAcDbEntity(pHatch)==Acad::eOk)
|
|
pHatch->close();
|
|
else
|
|
delete pHatch;
|
|
}
|
|
|
|
m_ctrlPreview.clearAll();
|
|
m_ctrlPreview.init(true);
|
|
m_ctrlPreview.view()->setView(AcGePoint3d(0.5,0.5,1000),AcGePoint3d(0.5,0.5,0),
|
|
AcGeVector3d(0.0, 1.0, 0.0),1,1);
|
|
m_ctrlPreview.view()->add(pMspace,m_ctrlPreview.model());
|
|
pMspace->close();
|
|
Invalidate();
|
|
}
|
|
|
|
BOOL CModifyPatDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
// TODO: Add extra initialization here
|
|
if(!FindFile(_T("acad.pat"), sfilename))
|
|
return FALSE;
|
|
int i = (int)_tcslen(sfilename),j = 0;
|
|
while(j != i - 8)
|
|
{
|
|
sDirname[j] = sfilename[j];
|
|
j++;
|
|
}
|
|
sDirname[j++] = _T('\0');
|
|
|
|
CStdioFile file;
|
|
if(!file.Open(LPCTSTR(sfilename),CFile::modeRead))
|
|
return FALSE;
|
|
pats<<file;
|
|
file.Close();
|
|
|
|
CString stemp;
|
|
stemp = stemp + sDirname + _T("bak.pat");
|
|
if(!file.Open(LPCTSTR(stemp),CFile::modeCreate|CFile::modeReadWrite))
|
|
return FALSE;
|
|
pats>>file;
|
|
file.Close();
|
|
m_ctrlPreview.SubclassDlgItem(IDC_STATIC_MODIFY,this);
|
|
m_cSpinScale.SetBuddy(GetDlgItem(IDC_EDIT_SCALE));
|
|
m_cSpinScale.SetRange(0,4);
|
|
PreView();
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
|
}
|
|
|
|
void CModifyPatDlg::OnChangeEditScale()
|
|
{
|
|
// TODO: If this is a RICHEDIT control, the control will not
|
|
// send this notification unless you override the CDialog::OnInitDialog()
|
|
// function and call CRichEditCtrl().SetEventMask()
|
|
// with the ENM_CHANGE flag ORed into the mask.
|
|
UpdateData();
|
|
long i = 0;
|
|
|
|
if(!FindFile(_T("bak.pat"), sfilename))
|
|
return ;
|
|
CStdioFile file;
|
|
if(!file.Open(LPCTSTR(sfilename),CFile::modeRead))
|
|
return ;
|
|
pats.Reset();
|
|
pats<<file;
|
|
file.Close();
|
|
|
|
CString str;
|
|
str = _T("*") + m_sPatName + _T(", Tangent");
|
|
i = pats.Find(str);
|
|
if (i == -1)
|
|
{
|
|
return;
|
|
}
|
|
double dTemp;
|
|
dTemp = _tstof(LPCTSTR(m_sSpinScale));
|
|
pats[i].Scale(dTemp);
|
|
if(!FindFile(_T("acad.pat"), sfilename))
|
|
return ;
|
|
if(!file.Open(LPCTSTR(sfilename),CFile::modeRead))
|
|
return ;
|
|
file.Close();
|
|
CFile::Remove(sfilename);
|
|
|
|
if(!file.Open(LPCTSTR(sfilename),CFile::modeCreate|CFile::modeReadWrite))
|
|
return ;
|
|
pats>>file;
|
|
file.Close();
|
|
PreView();
|
|
}
|
|
void CModifyPatDlg::OnDestroy()
|
|
{
|
|
CDialog::OnDestroy();
|
|
// TODO: Add your message handler code here
|
|
m_ctrlPreview.clearAll();
|
|
}
|