815 lines
20 KiB
C++
815 lines
20 KiB
C++
#include "stdafx.h"
|
|
#include "MCXGDlg.h"
|
|
#include "KTBlkRecsView.h"
|
|
#include "dbobjptr.h"
|
|
#include "KTSetting.h"
|
|
|
|
extern CAcExtensionModule Pool3dCmdDll;
|
|
|
|
#ifndef WM_VIEWDBLCLKSEL
|
|
#define WM_VIEWDBLCLKSEL (WM_USER + 0x1200)
|
|
#endif
|
|
|
|
IMPLEMENT_DYNAMIC(CMCXGDlg, CDialog)
|
|
|
|
CMCXGDlg::CMCXGDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CMCXGDlg::IDD, pParent)
|
|
, m_dHeight(1500)
|
|
, m_dBomEl(1200)
|
|
, m_sMaterial(_T("断桥铝合金玻璃门窗"))
|
|
, m_sProvider(_T("斯卡特门窗"))
|
|
{
|
|
m_sNo = _T("No");
|
|
m_sWidth = _T("1500");
|
|
|
|
m_sDwgFile = _T("WIN2.dwg");
|
|
m_sDwg3DFile = _T("WIN2_3D.dwg");
|
|
m_dwData.m_sBlock = _T("KTWIN02");
|
|
m_dwData.m_sBlock3D = _T("KTWIN02_3D");
|
|
m_dwData.m_eInsStyle = kByCenter;
|
|
m_dwData.m_nType = 1;
|
|
}
|
|
|
|
CMCXGDlg::~CMCXGDlg()
|
|
{
|
|
|
|
}
|
|
|
|
void CMCXGDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
DDX_Control(pDX, IDC_COMBOWIDTH, m_wndComboWidth);
|
|
DDX_CBString(pDX, IDC_COMBOWIDTH, m_sWidth);
|
|
DDX_Control(pDX, IDC_COMBONO, m_wndComboNo);
|
|
DDX_CBString(pDX, IDC_COMBONO, m_sNo);
|
|
DDX_Text(pDX, IDC_EDIT1, m_dHeight);
|
|
DDX_Text(pDX, IDC_EDIT2, m_dBomEl);
|
|
DDX_Text(pDX, IDC_EDIT12, m_sMaterial);
|
|
DDX_Text(pDX, IDC_EDIT3, m_sProvider);
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CMCXGDlg, CDialog)
|
|
ON_BN_CLICKED(IDOK, &CMCXGDlg::OnBnClickedOk)
|
|
ON_MESSAGE(WM_VIEWDBLCLKSEL, OnStaticPreview)
|
|
END_MESSAGE_MAP()
|
|
|
|
bool CMCXGDlg::SetOpeningData(const OpeningData& data)
|
|
{
|
|
m_dwData.m_nType = data.nType;
|
|
m_dHeight = data.dHeight;
|
|
m_sWidth.Format(_T("%d"),(int)(data.dWidth + 0.5) );
|
|
m_dBomEl = data.dBomEl;
|
|
|
|
//命名规则不能变KT
|
|
m_dwData.m_sBlock = data.szBlockName2d;
|
|
m_dwData.m_sBlock3D = data.szBlockName3d;
|
|
m_dwData.m_sProvider = data.szFactory;
|
|
m_dwData.m_sMaterial = data.szSpec;
|
|
m_sProvider = data.szFactory;
|
|
m_sMaterial = data.szSpec;
|
|
|
|
CString sDbtxtFile = _T("DoorDb.txt");
|
|
if (data.nType == 1)//窗
|
|
{
|
|
sDbtxtFile = _T("WindowDb.txt");
|
|
}
|
|
|
|
bool bFindBlk = false;
|
|
CString sPath,sPath2;
|
|
KTSetting::GetKTPsPath(sPath);
|
|
|
|
sPath += _T("Support\\Cells\\");
|
|
sPath2 = sPath;
|
|
sPath += sDbtxtFile;
|
|
|
|
CString sDwgFile,sRecName,sRecName3D,s3DDwgFile;
|
|
int nIndex = -1,nIndex2 = -1;
|
|
CStdioFile file;
|
|
if (file.Open(sPath,CFile::modeRead))
|
|
{
|
|
CString sText,sTmp;
|
|
while(file.ReadString(sText))
|
|
{
|
|
if (sText.FindOneOf(_T("//")) != -1)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
nIndex = sText.Find(_T(';'));
|
|
if (nIndex != -1)
|
|
{
|
|
//WIN1.dwg;KTWIN01;KTWIN01_3D;3D.DWG
|
|
sDwgFile = sText.Mid(0,nIndex);
|
|
sTmp = sText.Mid(nIndex + 1);
|
|
|
|
nIndex2 = sTmp.Find(_T(';'));
|
|
if (nIndex2 != -1)
|
|
{
|
|
sRecName = sTmp.Mid(0,nIndex2);
|
|
sText = sTmp.Mid(nIndex2 + 1);
|
|
}
|
|
|
|
//KTWIN01_3D
|
|
nIndex = sText.Find(_T(';'));
|
|
if (nIndex != -1)
|
|
{
|
|
sRecName3D = sText.Mid(0,nIndex);
|
|
sTmp = sText.Mid(nIndex + 1);
|
|
|
|
nIndex2 = sTmp.ReverseFind(_T(';'));
|
|
if (nIndex2 != -1)
|
|
{
|
|
s3DDwgFile = sTmp.Mid(nIndex2);
|
|
}
|
|
else
|
|
{
|
|
s3DDwgFile = sTmp;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
sRecName3D = sText;
|
|
}
|
|
|
|
if ( sRecName.CompareNoCase(data.szBlockName2d) == 0 &&
|
|
sRecName3D.CompareNoCase(data.szBlockName3d) == 0 )
|
|
{
|
|
m_sDwgFile = sDwgFile;
|
|
bFindBlk = true;
|
|
|
|
if (s3DDwgFile.IsEmpty())
|
|
{
|
|
m_sDwg3DFile = m_sDwgFile;
|
|
m_sDwg3DFile.MakeLower();
|
|
m_sDwg3DFile.TrimRight(_T(".dwg"));
|
|
m_sDwg3DFile += _T("_3D.dwg");
|
|
}
|
|
else
|
|
{
|
|
m_sDwg3DFile = s3DDwgFile;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
file.Close();
|
|
}
|
|
m_sNo = data.szNo;
|
|
if (!bFindBlk)
|
|
{
|
|
//没有找到,区默认
|
|
if (data.nType == 1)//窗
|
|
{
|
|
m_sDwgFile = _T("WIN2.dwg");
|
|
m_sDwg3DFile = _T("WIN2_3D.dwg");
|
|
m_dwData.m_sBlock = _T("KTWIN02");
|
|
m_dwData.m_sBlock3D = _T("KTWIN02_3D");
|
|
}
|
|
else
|
|
{
|
|
m_sDwgFile = _T("KTDOOR02.dwg");
|
|
m_sDwg3DFile = _T("KTDOOR02_3D.dwg");
|
|
m_dwData.m_sBlock = _T("KTDOOR02");
|
|
m_dwData.m_sBlock3D = _T("KTDOOR02_3D");
|
|
}
|
|
}
|
|
return bFindBlk;
|
|
}
|
|
|
|
DWDATA* CMCXGDlg::GetData()
|
|
{
|
|
AcDbBlockTable* pTable = NULL;
|
|
acdbCurDwg()->getBlockTable(pTable,AcDb::kForRead);
|
|
if (pTable != NULL)
|
|
{
|
|
pTable->getAt(m_dwData.m_sBlock,m_dwData.m_idRec);
|
|
pTable->close();
|
|
}
|
|
m_dwData.m_dHeight = m_dHeight;
|
|
m_dwData.m_dBomEl = m_dBomEl;
|
|
m_dwData.m_sMaterial = m_sMaterial;
|
|
m_dwData.m_sProvider = m_sProvider;
|
|
return &m_dwData;
|
|
}
|
|
|
|
void CMCXGDlg::GetOpeningData(OpeningData& data)
|
|
{
|
|
//更新内容
|
|
data.dHeight = m_dHeight;
|
|
data.dWidth = _ttof(m_sWidth);
|
|
data.dBomEl = m_dBomEl;
|
|
_tcscpy(data.szNo,m_sNo);
|
|
_tcscpy(data.szBlockName2d,(LPCTSTR)m_dwData.m_sBlock);
|
|
_tcscpy(data.szBlockName3d,(LPCTSTR)m_dwData.m_sBlock3D);
|
|
_tcscpy(data.szName,(LPCTSTR)m_dwData.m_sBlock);
|
|
_tcscpy(data.szFactory, (LPCTSTR)m_dwData.m_sProvider);
|
|
_tcscpy(data.szSpec, (LPCTSTR)m_dwData.m_sMaterial);
|
|
}
|
|
|
|
BOOL CMCXGDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
if (m_dwData.m_nType == 2)//门
|
|
{
|
|
GetDlgItem(IDC_STATIC_W)->SetWindowText(_T("门宽:"));
|
|
GetDlgItem(IDC_STATIC_H)->SetWindowText(_T("门高:"));
|
|
GetDlgItem(IDC_STATIC_E)->SetWindowText(_T("门槛高:"));
|
|
}
|
|
|
|
if (!m_wndPreView.SubclassDlgItem(IDC_STATIC_PREVIEW,this))
|
|
return FALSE;
|
|
|
|
ShowSlide();
|
|
|
|
#ifndef ZWCAD
|
|
#if ARX>=20
|
|
m_wndPreView.mpView->setVisualStyle(AcGiVisualStyle::k2DWireframe);
|
|
#else
|
|
m_wndPreView.mpView->setMode(AcGsView::k2DOptimized);
|
|
#endif
|
|
#else
|
|
#if defined(R24)
|
|
m_wndPreView.mpView->setMode(AcGsView::k2DOptimized);
|
|
#else
|
|
m_wndPreView.mpView->setVisualStyle(AcGiVisualStyle::k2DWireframe);
|
|
#endif
|
|
#endif
|
|
|
|
InitGenDoorWidthCombo();
|
|
|
|
UpdateData(FALSE);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CMCXGDlg::InitGenDoorWidthCombo()
|
|
{
|
|
LPCTSTR pszWidths[] = {_T("700"),_T("750"),_T("800"),_T("900"),_T("1000"),_T("1100"),
|
|
_T("1200"),_T("1500"),_T("1800"),_T("2000"),_T("2400"),_T("2700"),_T("3000"),_T("3600"),0};
|
|
|
|
int i = 0;
|
|
while(pszWidths[i] != NULL)
|
|
{
|
|
if (m_wndComboWidth.FindString(0,pszWidths[i]) == -1)
|
|
{
|
|
m_wndComboWidth.AddString(pszWidths[i]);
|
|
}
|
|
++i;
|
|
}
|
|
}
|
|
|
|
LRESULT CMCXGDlg::OnStaticPreview(WPARAM wparam,LPARAM lparam)
|
|
{
|
|
KTBlkRecsView recView;
|
|
recView.SetCurRec(m_dwData.m_sBlock,(m_dwData.m_nType == 2 ) ? FALSE : TRUE);
|
|
int nRes = recView.DoModal();
|
|
if (nRes == IDOK)
|
|
{
|
|
CString s3DFile,sDwgPath;
|
|
recView.GetCurRec(m_sDwgFile,m_dwData.m_sBlock,m_dwData.m_sBlock3D,s3DFile);
|
|
|
|
m_sDwg3DFile = m_sDwgFile;
|
|
m_sDwg3DFile.MakeLower();
|
|
|
|
int nPos = m_sDwg3DFile.ReverseFind(_T('\\'));
|
|
if (nPos != -1)
|
|
{
|
|
if (s3DFile.IsEmpty())
|
|
{
|
|
sDwgPath = m_sDwg3DFile.Mid(0, nPos);
|
|
m_sDwg3DFile = sDwgPath;
|
|
m_sDwg3DFile += _T("\\");
|
|
m_sDwg3DFile += m_dwData.m_sBlock3D;
|
|
m_sDwg3DFile += _T(".dwg");
|
|
}
|
|
else
|
|
{
|
|
sDwgPath = m_sDwg3DFile.Mid(0, nPos);
|
|
m_sDwg3DFile = sDwgPath;
|
|
m_sDwg3DFile += _T("\\");
|
|
m_sDwg3DFile += s3DFile;
|
|
}
|
|
}
|
|
|
|
ShowSlide();
|
|
Invalidate();
|
|
RedrawWindow();
|
|
}
|
|
return 0l;
|
|
}
|
|
|
|
void CMCXGDlg::ShowSlide()
|
|
{
|
|
int nIndex = m_sDwgFile.ReverseFind(_T('\\'));
|
|
if (nIndex != -1)
|
|
{
|
|
m_sDwgFile = m_sDwgFile.Mid(nIndex + 1);
|
|
}
|
|
|
|
CString sDwgFile;
|
|
KTSetting::GetKTPsPath(sDwgFile);
|
|
sDwgFile += _T("Support\\Cells\\");
|
|
sDwgFile += m_sDwgFile;
|
|
m_sDwgFile = sDwgFile;
|
|
|
|
CFileFind find;
|
|
if (!find.FindFile(m_sDwgFile))
|
|
{
|
|
return;
|
|
}
|
|
|
|
AcDbDatabase *pDb = new AcDbDatabase(false);
|
|
Acad::ErrorStatus es = pDb->readDwgFile(m_sDwgFile);
|
|
if (es != Acad::eOk)
|
|
{
|
|
AfxMessageBox(CString(_T("打开文件失败 \"")) + m_sDwgFile + _T("\""));
|
|
delete pDb;
|
|
return;
|
|
}
|
|
|
|
AcGsView *pView = m_wndPreView.view();
|
|
if (pView != NULL) pView->eraseAll();
|
|
|
|
// now initialise the drawing control
|
|
InitDrawingControl(pDb, m_dwData.m_sBlock);
|
|
m_arpDb.append(pDb);
|
|
}
|
|
|
|
Acad::ErrorStatus CMCXGDlg::InitDrawingControl (AcDbDatabase *pDb, const TCHAR *space)
|
|
{
|
|
if (m_dwData.m_nType == 1)//窗
|
|
{
|
|
return InitDrawingControlWin(pDb, space);
|
|
}
|
|
return InitDrawingControlDoor(pDb, space);
|
|
}
|
|
|
|
Acad::ErrorStatus CMCXGDlg::InitDrawingControlWin(AcDbDatabase *pDb, const TCHAR *space)
|
|
{
|
|
// have we got a valid drawing
|
|
if (pDb == NULL)
|
|
return Acad::eNullBlockName;
|
|
|
|
AcDbBlockTableRecordPointer spaceRec(space, pDb, AcDb::kForRead);
|
|
// if ok
|
|
if (spaceRec.openStatus() == Acad::eOk)
|
|
{
|
|
// initialize the preview control
|
|
m_wndPreView.init(true);
|
|
// set the view to the *Active* AutoCAD view
|
|
|
|
CGsPreviewCtrl *pPreViewCtrl = &m_wndPreView;
|
|
|
|
AcGeMatrix3d xform;
|
|
SetViewTo(m_wndPreView.mpView, pDb, xform);
|
|
|
|
AcDbBlockReference *pRef = new AcDbBlockReference();
|
|
pRef->setBlockTableRecord(spaceRec->objectId());
|
|
pRef->setPosition(AcGePoint3d::kOrigin);
|
|
pRef->setRotation(0.0);
|
|
|
|
bool bIsDoor = false;
|
|
AcGeScale3d scale(500, 500, 500);
|
|
if (!bIsDoor)
|
|
scale.set(500, 240, 500);
|
|
|
|
pRef->setScaleFactors(scale);
|
|
pRef->setColorIndex(4);
|
|
pPreViewCtrl->view()->add(pRef, pPreViewCtrl->model());
|
|
|
|
AcGePoint3d ptS, ptE;
|
|
|
|
//绘制两侧墙体
|
|
AcDbLine *pLn = new AcDbLine;
|
|
ptS.set(-550, 120, 0);
|
|
ptE.set(-250, 120, 0);
|
|
pLn->setStartPoint(ptS); pLn->setEndPoint(ptE);
|
|
pLn->setColorIndex(9);
|
|
pPreViewCtrl->view()->add(pLn, pPreViewCtrl->model());
|
|
|
|
pLn = new AcDbLine;
|
|
ptS.set(-250, 120, 0);
|
|
ptE.set(-250, -120, 0);
|
|
pLn->setStartPoint(ptS); pLn->setEndPoint(ptE);
|
|
pLn->setColorIndex(9);
|
|
pPreViewCtrl->view()->add(pLn, pPreViewCtrl->model());
|
|
|
|
pLn = new AcDbLine;
|
|
ptS.set(-250, -120, 0);
|
|
ptE.set(-550, -120, 0);
|
|
pLn->setStartPoint(ptS); pLn->setEndPoint(ptE);
|
|
pLn->setColorIndex(9);
|
|
pPreViewCtrl->view()->add(pLn, pPreViewCtrl->model());
|
|
|
|
//R
|
|
pLn = new AcDbLine;
|
|
ptS.set(550, 120, 0);
|
|
ptE.set(250, 120, 0);
|
|
pLn->setStartPoint(ptS); pLn->setEndPoint(ptE);
|
|
pLn->setColorIndex(9);
|
|
pPreViewCtrl->view()->add(pLn, pPreViewCtrl->model());
|
|
|
|
pLn = new AcDbLine;
|
|
ptS.set(250, 120, 0);
|
|
ptE.set(250, -120, 0);
|
|
pLn->setStartPoint(ptS); pLn->setEndPoint(ptE);
|
|
pLn->setColorIndex(9);
|
|
pPreViewCtrl->view()->add(pLn, pPreViewCtrl->model());
|
|
|
|
pLn = new AcDbLine;
|
|
ptS.set(250, -120, 0);
|
|
ptE.set(550, -120, 0);
|
|
pLn->setStartPoint(ptS); pLn->setEndPoint(ptE);
|
|
pLn->setColorIndex(9);
|
|
pPreViewCtrl->view()->add(pLn, pPreViewCtrl->model());
|
|
|
|
|
|
// tell the view to display this space
|
|
m_wndPreView.view()->add(spaceRec.object(), m_wndPreView.model());
|
|
}
|
|
return spaceRec.openStatus();
|
|
}
|
|
|
|
Acad::ErrorStatus CMCXGDlg::InitDrawingControlDoor(AcDbDatabase *pDb, const TCHAR *space)
|
|
{
|
|
// have we got a valid drawing
|
|
if (pDb == NULL)
|
|
return Acad::eNullBlockName;
|
|
|
|
AcDbBlockTableRecordPointer spaceRec(space, pDb, AcDb::kForRead);
|
|
// if ok
|
|
if (spaceRec.openStatus() == Acad::eOk)
|
|
{
|
|
// initialize the preview control
|
|
m_wndPreView.init(true);
|
|
// set the view to the *Active* AutoCAD view
|
|
|
|
CGsPreviewCtrl *pPreViewCtrl = &m_wndPreView;
|
|
|
|
AcGeMatrix3d xform;
|
|
SetViewTo(m_wndPreView.mpView, pDb, xform);
|
|
|
|
AcDbBlockReference *pRef = new AcDbBlockReference();
|
|
pRef->setBlockTableRecord(spaceRec->objectId());
|
|
pRef->setPosition(AcGePoint3d::kOrigin);
|
|
pRef->setRotation(0.0);
|
|
|
|
bool bIsDoor = true;
|
|
AcGeScale3d scale(500, 500, 500);
|
|
if (!bIsDoor)
|
|
scale.set(500, 240, 500);
|
|
|
|
pRef->setScaleFactors(scale);
|
|
pRef->setColorIndex(4);
|
|
pPreViewCtrl->view()->add(pRef, pPreViewCtrl->model());
|
|
|
|
AcGePoint3d ptS, ptE;
|
|
|
|
//绘制两侧墙体
|
|
AcDbLine *pLn = new AcDbLine;
|
|
ptS.set(-550, 120, 0);
|
|
ptE.set(-250, 120, 0);
|
|
pLn->setStartPoint(ptS); pLn->setEndPoint(ptE);
|
|
pLn->setColorIndex(9);
|
|
pPreViewCtrl->view()->add(pLn, pPreViewCtrl->model());
|
|
|
|
pLn = new AcDbLine;
|
|
ptS.set(-250, 120, 0);
|
|
ptE.set(-250, -120, 0);
|
|
pLn->setStartPoint(ptS); pLn->setEndPoint(ptE);
|
|
pLn->setColorIndex(9);
|
|
pPreViewCtrl->view()->add(pLn, pPreViewCtrl->model());
|
|
|
|
pLn = new AcDbLine;
|
|
ptS.set(-250, -120, 0);
|
|
ptE.set(-550, -120, 0);
|
|
pLn->setStartPoint(ptS); pLn->setEndPoint(ptE);
|
|
pLn->setColorIndex(9);
|
|
pPreViewCtrl->view()->add(pLn, pPreViewCtrl->model());
|
|
|
|
//R
|
|
pLn = new AcDbLine;
|
|
ptS.set(550, 120, 0);
|
|
ptE.set(250, 120, 0);
|
|
pLn->setStartPoint(ptS); pLn->setEndPoint(ptE);
|
|
pLn->setColorIndex(9);
|
|
pPreViewCtrl->view()->add(pLn, pPreViewCtrl->model());
|
|
|
|
pLn = new AcDbLine;
|
|
ptS.set(250, 120, 0);
|
|
ptE.set(250, -120, 0);
|
|
pLn->setStartPoint(ptS); pLn->setEndPoint(ptE);
|
|
pLn->setColorIndex(9);
|
|
pPreViewCtrl->view()->add(pLn, pPreViewCtrl->model());
|
|
|
|
pLn = new AcDbLine;
|
|
ptS.set(250, -120, 0);
|
|
ptE.set(550, -120, 0);
|
|
pLn->setStartPoint(ptS); pLn->setEndPoint(ptE);
|
|
pLn->setColorIndex(9);
|
|
pPreViewCtrl->view()->add(pLn, pPreViewCtrl->model());
|
|
|
|
// tell the view to display this space
|
|
m_wndPreView.view()->add(spaceRec.object(), m_wndPreView.model());
|
|
}
|
|
return spaceRec.openStatus();
|
|
}
|
|
|
|
bool CMCXGDlg::GetActiveViewPortInfo (AcDbDatabase *pDb, ads_real &height, ads_real &width, AcGePoint3d &target, AcGeVector3d &viewDir, ads_real &viewTwist, bool getViewCenter)
|
|
{
|
|
// if not ok
|
|
if (pDb == NULL)
|
|
return false;
|
|
|
|
// get the current working database as a backup
|
|
AcDbDatabase *workingDataBase = acdbHostApplicationServices()->workingDatabase();
|
|
// now set the working database
|
|
//acdbHostApplicationServices()->setWorkingDatabase(pDb);
|
|
|
|
// make sure the active view port is uptodate
|
|
// acedVports2VportTableRecords();
|
|
|
|
// open the view port records
|
|
AcDbViewportTable *pVTable = NULL;
|
|
Acad::ErrorStatus es = pDb->getViewportTable (pVTable, AcDb::kForRead);
|
|
// if we opened them ok
|
|
if (es == Acad::eOk)
|
|
{
|
|
AcDbViewportTableRecord *pViewPortRec = NULL;
|
|
es = pVTable->getAt (_T("*Active"), pViewPortRec, AcDb::kForRead);
|
|
if (es == Acad::eOk)
|
|
{
|
|
// get the height of the view
|
|
height = pViewPortRec->height ();
|
|
// get the width
|
|
width = pViewPortRec->width ();
|
|
// if the user wants the center of the viewport used
|
|
if (getViewCenter == true)
|
|
{
|
|
struct resbuf rb;
|
|
memset (&rb, 0, sizeof (struct resbuf));
|
|
// get the system var VIEWCTR
|
|
acedGetVar (_T("VIEWCTR"), &rb);
|
|
// set that as the target
|
|
target = AcGePoint3d (rb.resval.rpoint[X], rb.resval.rpoint[Y], rb.resval.rpoint[Z]);
|
|
}
|
|
// we want the viewports camera target setting
|
|
else
|
|
{
|
|
// get the target of the view
|
|
target = pViewPortRec->target ();
|
|
}
|
|
|
|
// get the view direction
|
|
viewDir = pViewPortRec->viewDirection ();
|
|
// get the view twist of the viewport
|
|
viewTwist = pViewPortRec->viewTwist ();
|
|
}
|
|
// close after use
|
|
pVTable->close ();
|
|
pViewPortRec->close();
|
|
}
|
|
|
|
// now restore the original working database
|
|
//acdbHostApplicationServices()->setWorkingDatabase(workingDataBase);
|
|
|
|
return (true);
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// set the passed AcGsView to the *Active* AutoCAD AcDbDatabase view
|
|
void CMCXGDlg::SetViewTo(AcGsView *pView, AcDbDatabase *pDb, AcGeMatrix3d& viewMat)
|
|
{
|
|
// we are going to set the view to the current view of the drawing
|
|
// The overall approach is to calculate the extents of the database in the coordinate system of the view
|
|
// Calculate the extents in WCS
|
|
//AcGePoint3d extMax = pDb->extmax();
|
|
//AcGePoint3d extMin = pDb->extmin();
|
|
|
|
AcGePoint3d extMax(500, 500, 0); //= pDb->extmax();
|
|
AcGePoint3d extMin(-500, -500, 0); //= pDb->extmin();
|
|
|
|
// get the view port information - see parameter list
|
|
ads_real height = 0.0, width = 0.0, viewTwist = 0.0;
|
|
AcGePoint3d targetView;
|
|
AcGeVector3d viewDir;
|
|
GetActiveViewPortInfo (pDb, height, width, targetView, viewDir, viewTwist, true);
|
|
|
|
// we are only interested in the directions of the view, not the sizes, so we normalise.
|
|
viewDir = viewDir.normal();
|
|
|
|
//**********************************************
|
|
// Our view coordinate space consists of z direction
|
|
// get a perp vector off the z direction
|
|
// Make sure its normalised
|
|
AcGeVector3d viewXDir = viewDir.perpVector ().normal();
|
|
// correct the x angle by applying the twist
|
|
viewXDir = viewXDir.rotateBy (viewTwist, -viewDir);
|
|
// now we can work out y, this is of course perp to the x and z directions. No need to normalise this,
|
|
// as we know that x and z are of unit length, and perpendicular, so their cross product must be on unit length
|
|
AcGeVector3d viewYDir = viewDir.crossProduct (viewXDir);
|
|
|
|
// find a nice point around which to transform the view. We'll use the same point as the center of the view.
|
|
AcGePoint3d boxCenter = extMin + 0.5 * ( extMax - extMin );
|
|
|
|
//**********************************************
|
|
// create a transform from WCS to View space
|
|
// this represents the transformation from WCS to the view space. (Actually not quite since
|
|
// we are keeping the fixed point as the center of the box for convenience )
|
|
viewMat = AcGeMatrix3d::alignCoordSys (boxCenter, AcGeVector3d::kXAxis, AcGeVector3d::kYAxis, AcGeVector3d::kZAxis,
|
|
boxCenter, viewXDir, viewYDir, viewDir).inverse();
|
|
|
|
AcDbExtents wcsExtents(extMin, extMax);
|
|
// now we have the view Extents
|
|
AcDbExtents viewExtents = wcsExtents;
|
|
// transforms the extents in WCS->view space
|
|
viewExtents.transformBy (viewMat);
|
|
|
|
//**********************************************
|
|
// get the extents of the AutoCAD view
|
|
double xMax = fabs(viewExtents.maxPoint ().x - viewExtents.minPoint ().x);
|
|
double yMax = fabs(viewExtents.maxPoint ().y - viewExtents.minPoint ().y);
|
|
|
|
//**********************************************
|
|
// setup the view
|
|
AcGePoint3d eye = boxCenter + viewDir;
|
|
|
|
// upvector
|
|
pView->setView(eye, boxCenter, viewYDir, xMax, yMax);
|
|
// update the gsView
|
|
if (pView != NULL)
|
|
{
|
|
pView->invalidate();
|
|
pView->update();
|
|
}
|
|
}
|
|
|
|
void CMCXGDlg::OnBnClickedOk()
|
|
{
|
|
UpdateData();
|
|
|
|
double dWidth = _ttof(m_sWidth);
|
|
if (dWidth < 1.0)
|
|
{
|
|
AfxMessageBox(_T("窗宽度太小,请输入合适的宽度!"));
|
|
return;
|
|
}
|
|
|
|
//创建blockrec id;
|
|
if (!CreateBlockRecord())
|
|
{
|
|
AfxMessageBox(_T("创建门窗块失败,检查软件安装是否正确!"));
|
|
return;
|
|
}
|
|
|
|
if (!CreateBlockRecord3d())
|
|
{
|
|
AfxMessageBox(_T("创建门窗块失败,检查软件安装是否正确!"));
|
|
return;
|
|
}
|
|
|
|
m_wndComboNo.GetWindowText(m_sNo);
|
|
|
|
m_dwData.m_dWidth = dWidth;
|
|
m_dwData.m_sNo = m_sNo;
|
|
m_dwData.m_dBomEl = m_dBomEl;
|
|
m_dwData.m_dHeight = m_dHeight;
|
|
m_dwData.m_sMaterial = m_sMaterial;
|
|
m_dwData.m_sProvider = m_sProvider;
|
|
|
|
CDialog::OnOK();
|
|
}
|
|
|
|
BOOL CMCXGDlg::CreateBlockRecord()
|
|
{
|
|
AcDbDatabase *pWorkDb = acdbHostApplicationServices()->workingDatabase();
|
|
Acad::ErrorStatus es;
|
|
AcDbObjectId idBlock;
|
|
AcDbBlockTable *pBT = NULL;
|
|
if (Acad::eOk == pWorkDb->getSymbolTable(pBT, AcDb::kForRead))
|
|
{
|
|
if (Acad::eOk == (es = pBT->getAt(m_dwData.m_sBlock, idBlock)))
|
|
{
|
|
m_dwData.m_idRec = idBlock;
|
|
}
|
|
pBT->close();
|
|
if (es == Acad::eOk) return TRUE;
|
|
}
|
|
|
|
AcDbDatabase* pDb = new AcDbDatabase(false);
|
|
ASSERT(pDB != NULL);
|
|
if (pDb->readDwgFile(m_sDwgFile, AcDbDatabase::kForReadAndAllShare) != Acad::eOk)
|
|
{
|
|
delete pDb;
|
|
return FALSE;
|
|
}
|
|
|
|
pBT = NULL;
|
|
pDb->getSymbolTable(pBT, AcDb::kForRead);
|
|
if (pBT == NULL)
|
|
{
|
|
delete pDb;
|
|
return FALSE;
|
|
}
|
|
|
|
|
|
es = pBT->getAt(m_dwData.m_sBlock, idBlock);
|
|
pBT->close();
|
|
|
|
if (es != Acad::eOk)
|
|
{
|
|
acutPrintf(_T("\nErrorStatus : %d"), es);
|
|
}
|
|
|
|
AcDbDatabase* pTempDb = NULL;
|
|
es = pDb->wblock(pTempDb, idBlock);
|
|
delete pDb;
|
|
if (pTempDb == NULL)
|
|
{
|
|
acutPrintf(_T("\nErrorStatus : %d"), es);
|
|
return FALSE;
|
|
}
|
|
|
|
if (pWorkDb->insert(m_dwData.m_idRec, m_dwData.m_sBlock, pTempDb) != Acad::eOk)
|
|
{
|
|
delete pTempDb;
|
|
return FALSE;
|
|
}
|
|
delete pTempDb;
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CMCXGDlg::CreateBlockRecord3d()
|
|
{
|
|
AcDbDatabase *pWorkDb = acdbHostApplicationServices()->workingDatabase();
|
|
Acad::ErrorStatus es;
|
|
AcDbObjectId idBlock;
|
|
AcDbBlockTable *pBT = NULL;
|
|
if (Acad::eOk == pWorkDb->getSymbolTable(pBT, AcDb::kForRead))
|
|
{
|
|
if (Acad::eOk == (es = pBT->getAt(m_dwData.m_sBlock3D, idBlock)))
|
|
{
|
|
m_dwData.m_idRec3d = idBlock;
|
|
}
|
|
pBT->close();
|
|
if (es == Acad::eOk) return TRUE;
|
|
}
|
|
|
|
CString sDwgFile,sName;
|
|
KTSetting::GetKTPsPath(sDwgFile);
|
|
sDwgFile += _T("Support\\Cells\\");
|
|
|
|
int nPos = m_sDwg3DFile.ReverseFind(_T('\\'));
|
|
if (nPos != -1)
|
|
{
|
|
sName = m_sDwg3DFile.Mid(nPos + 1);
|
|
sDwgFile += sName;
|
|
}
|
|
else
|
|
{
|
|
sDwgFile += m_sDwg3DFile;
|
|
m_sDwg3DFile = sDwgFile;
|
|
}
|
|
|
|
AcDbDatabase* pDb = new AcDbDatabase(false);
|
|
ASSERT(pDB != NULL);
|
|
if (pDb->readDwgFile(m_sDwg3DFile, AcDbDatabase::kForReadAndAllShare) != Acad::eOk)
|
|
{
|
|
delete pDb;
|
|
return FALSE;
|
|
}
|
|
|
|
pBT = NULL;
|
|
pDb->getSymbolTable(pBT, AcDb::kForRead);
|
|
if (pBT == NULL)
|
|
{
|
|
delete pDb;
|
|
return FALSE;
|
|
}
|
|
|
|
es = pBT->getAt(m_dwData.m_sBlock3D, idBlock);
|
|
pBT->close();
|
|
|
|
if (es != Acad::eOk)
|
|
{
|
|
acutPrintf(_T("\nErrorStatus : %d"), es);
|
|
}
|
|
|
|
AcDbDatabase* pTempDb = NULL;
|
|
es = pDb->wblock(pTempDb, idBlock);
|
|
delete pDb;
|
|
if (pTempDb == NULL)
|
|
{
|
|
acutPrintf(_T("\nErrorStatus : %d"),es);
|
|
return FALSE;
|
|
}
|
|
|
|
if (pWorkDb->insert(m_dwData.m_idRec3d, m_dwData.m_sBlock3D, pTempDb) != Acad::eOk)
|
|
{
|
|
delete pTempDb;
|
|
return FALSE;
|
|
}
|
|
delete pTempDb;
|
|
return TRUE;
|
|
} |