Files
envi-code/SourceCode/Code2026/Pool3dCmd/CRZZDlg.cpp
T
2026-09-28 15:28:50 +08:00

997 lines
25 KiB
C++

#include "stdafx.h"
#include "StdArx.h"
#include "CRZZDlg.h"
#include "dbobjptr.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#ifndef KTData_DB
#define KTData_DB _T("\\Plumbing.db")
#endif
int g_nColNo = 1;
extern CAcExtensionModule Pool3dCmdDll;
DLLIMPEXP CString IDCreate();
CCRZZDlg::CCRZZDlg(CWnd *pParent /*=NULL*/)
: CDialog(CCRZZDlg::IDD, pParent)
, m_dBomEl(0.0)
, m_dH(3000.0)
, m_sMaterial(_T("钢筋混凝土"))
, m_sNo(_T(""))
, m_bNOSetDefault(TRUE)
, m_sHatch(HATCH_DEFAULT)
, m_bAddHatch(TRUE)
, m_bInplace(false)
, m_sModel(_T(""))
, m_nSteel(0)
{
//{{AFX_DATA_INIT(CCRZZDlg)
m_dXOffset = 0.0;
m_dYOffset = 0.0;
m_iInsertType = 0;
m_nShape = 0;
m_dXSize = 500;
m_dYSize = 500;
m_dRotAngle = 0.0;
m_sA = _T("");
m_sB = _T("");
m_sC = _T("");
m_sD = _T("Z-001");
//}}AFX_DATA_INIT
m_sBlockName = _T("_FZH.DWG");
m_pDb = NULL;
m_sNo.Format(_T("Z-%d"),g_nColNo);
GET_CACHE(CCRZZDlg
, %f%f%f%f%s%s%s%s%s%s%d%d%f%f%s%s%d
, &m_dXOffset
, &m_dYOffset
, &m_dBomEl
, &m_dH
, &m_sA
, &m_sB
, &m_sC
, &m_sD
, &m_sMaterial
, &m_sNo
, &m_iInsertType
, &m_nShape
, &m_dXSize
, &m_dYSize
, &m_sHatch
, &m_sModel
, &m_nSteel);
if (m_bNOSetDefault)
m_sNo = IDCreate();
}
CCRZZDlg::~CCRZZDlg(void)
{
g_nColNo++;
}
void CCRZZDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_CMBSTEEL, m_wndComSteel);
DDX_Control(pDX, IDC_CMB_ANGLE, m_wndComboAngle);
DDX_Control(pDX, IDC_CMB_YSIZE, m_wndComboYSize);
DDX_Control(pDX, IDC_CMB_XSIZE, m_wndComboXSize);
DDX_Control(pDX, IDC_CMB_SHAPE, m_wndComboShape);
DDX_Text(pDX, IDC_EDT_XOFFSET, m_dXOffset);
DDX_Text(pDX, IDC_EDT_YOFFSET, m_dYOffset);
DDX_Text(pDX, IDC_EDIT1, m_dBomEl);
DDX_Text(pDX, IDC_EDIT3, m_dH);
DDX_Text(pDX, IDC_EDITA, m_sA);
DDX_Text(pDX, IDC_EDITB, m_sB);
DDX_Text(pDX, IDC_EDITC, m_sC);
DDX_Text(pDX, IDC_EDITD, m_sD);
DDX_Text(pDX, IDC_EDIT2, m_sMaterial);
DDX_Text(pDX, IDC_EDIT6, m_sNo);
DDX_Radio(pDX, IDC_POINT, m_iInsertType);
DDX_CBIndex(pDX, IDC_CMB_SHAPE, m_nShape);
DDX_Check(pDX, IDC_CHECK1, m_bNOSetDefault);
DDX_Control(pDX, IDC_BTN_FILL, m_wndBtHatch);
DDX_Check(pDX, IDC_CHECK_HATCH, m_bAddHatch);
DDX_Text(pDX, IDC_BTN_FILL, m_sHatch);
DDX_CBString(pDX, IDC_CMBSTEEL, m_sModel);
DDX_CBIndex(pDX, IDC_CMBSTEEL, m_nSteel);
}
BEGIN_MESSAGE_MAP(CCRZZDlg, CDialog)
//{{AFX_MSG_MAP(CCRZZDlg)
ON_CBN_SELCHANGE(IDC_CMB_SHAPE, OnSelchangeCmbShape)
ON_CBN_SELCHANGE(IDC_CMBSTEEL, OnSelchangeCmbsteel)
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDOK, &CCRZZDlg::OnBnClickedOk)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_CHECK1, &CCRZZDlg::OnBnClickedCheck1)
ON_BN_CLICKED(IDC_BTN_FILL, &CCRZZDlg::OnBnClickedBtnFill)
ON_BN_CLICKED(IDC_CHECK_HATCH, &CCRZZDlg::OnBnClickedCheckHatch)
END_MESSAGE_MAP()
BOOL CCRZZDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CString path = FilePath::GetSysDir() + KTData_DB;
if (!m_dbSQLite.InitADOServer(path))
{
AfxMessageBox(CString(_T("数据库初始化失败,请检查 sys")) + KTData_DB + _T("文件是否存在."));
return FALSE;
}
CString sXSize;
if (!m_bInplace)
{
sXSize.Format(_T("%d"), (int)m_dXSize);
int nCursel = m_wndComboXSize.FindString(0, sXSize);
if (nCursel != -1)
{
m_wndComboXSize.SetCurSel(nCursel);
}
else
{
m_wndComboXSize.SetWindowText(sXSize);
}
sXSize.Format(_T("%d"), (int)m_dYSize);
nCursel = m_wndComboYSize.FindString(0, sXSize);
if (nCursel != -1)
{
m_wndComboYSize.SetCurSel(nCursel);
}
else
{
m_wndComboYSize.SetWindowText(sXSize);
}
}
else
{
sXSize.Format(_T("%d"), (int)m_dXSize);
m_wndComboXSize.SetWindowText(sXSize);
sXSize.Format(_T("%d"), (int)m_dYSize);
m_wndComboYSize.SetWindowText(sXSize);
}
if (!m_wndPreview.SubclassDlgItem(IDC_STC_PICTURE,this))
return FALSE;
if (m_idCol.isValid())
{
UpdateData(FALSE);
}
// 工字钢或槽钢,备份
CString sA;
CString sB;
CString sC;
CString sD;
int nSteel;
if (m_nShape >= 3)
{
sA = m_sA;
sB = m_sB;
sC = m_sC;
sD = m_sD;
nSteel = m_nSteel;
}
OnSelchangeCmbShape();
if (m_nShape >= 3)
{
m_sA = sA;
m_sB = sB;
m_sC = sC;
m_sD = sD;
if (nSteel < m_wndComSteel.GetCount() && nSteel >= 0)
m_nSteel = nSteel;
}
CString sAng;
sAng.Format(_T("%d"),(int)(m_dRotAngle));
m_wndComboAngle.SetWindowText(sAng);
#ifndef ZWCAD
#if ARX < 20
if (m_wndPreview.mpView)
m_wndPreview.mpView->setMode(AcGsView::k2DOptimized);
#else
AcGiVisualStyle style;
style.setType(AcGiVisualStyle::k2DWireframe);
if (m_wndPreview.mpView)
m_wndPreview.mpView->setVisualStyle(style);
#endif
#else
#if defined(R24)
if (m_wndPreview.mpView)
m_wndPreview.mpView->setMode(AcGsView::k2DOptimized);
#else
AcGiVisualStyle style;
style.setType(AcGiVisualStyle::k2DWireframe);
if (m_wndPreview.mpView)
m_wndPreview.mpView->setVisualStyle(style);
#endif
#endif
if (m_idCol.isValid())
{
GetDlgItem(IDC_POINT)->EnableWindow(FALSE);
GetDlgItem(IDC_LINE)->EnableWindow(FALSE);
GetDlgItem(IDC_SQUARE)->EnableWindow(FALSE);
}
if (m_bNOSetDefault)
{
GetDlgItem(IDC_EDIT6)->EnableWindow(FALSE);
}
UpdateData(FALSE);
m_wndBtHatch.EnableWindow(m_bAddHatch);
return TRUE;
}
void CCRZZDlg::GetColumnParam(ColumnParam& ColParam) const
{
::memset(&ColParam, 0, sizeof(ColParam));
ColParam.m_dXExtend = m_dXOffset;
ColParam.m_dYExtend = m_dYOffset;
ColParam.m_iInsertType = m_iInsertType;
ColParam.m_dXScale = m_dXSize;
ColParam.m_dYScale = m_dYSize;
ColParam.m_nShape = m_nShape;
_tcscpy(ColParam.m_sBlockName,m_sBlockName);
ColParam.m_idRec = m_idStellCol;
ColParam.m_nShape = m_nShape;
ColParam.m_dRotAngle = m_dRotAngle;
ColParam.m_dH = m_dH;
ColParam.m_dBomEl = m_dBomEl;
_tcscpy(ColParam.m_sMaterial,m_sMaterial);
_tcscpy(ColParam.m_szNo,m_sNo);
if (m_nShape == 1 || m_nShape == 2) // 圆形,正六边
{
// 不然会变形
ColParam.m_dYScale = ColParam.m_dXScale;
}
else if (m_nShape == 3 || m_nShape == 4) // 工字,槽钢
{
ColParam.m_dYScale = ColParam.m_dXScale = 1;
}
ColParam.m_dSizes[0] = _ttof(m_sA);
ColParam.m_dSizes[1] = _ttof(m_sB);
ColParam.m_dSizes[2] = _ttof(m_sC);
ColParam.m_dSizes[3] = _ttof(m_sD);
ColParam.bPtPos = false;
ColParam.ptPos.set(0,0,0);
_tcscpy(ColParam.m_sHatch, m_sHatch);
_tcscpy(ColParam.m_sModel, m_sModel);
}
void CCRZZDlg::OnOK()
{
UpdateData();
CString sXScale,sYScale,sAngle;
m_wndComboXSize.GetWindowText(sXScale);
m_wndComboYSize.GetWindowText(sYScale);
m_wndComboAngle.GetWindowText(sAngle);
m_dYSize = _ttof(sYScale);
m_dXSize = _ttof(sXScale);
m_dRotAngle = _ttof(sAngle);
if (m_nShape == 0)//矩形
{
if (m_dXSize < 1.e-1 || m_dYSize < 1.e-1)
{
AfxMessageBox(_T("柱子尺寸不正确!"));
return;
}
}
if (m_nShape == 1) //圆形
{
if (m_dXSize < 1.e-1 )
{
AfxMessageBox(_T("柱子尺寸不正确!"));
return;
}
}
if (m_nShape == 2)//正六边形
{
if (m_dXSize < 1.e-1 )
{
AfxMessageBox(_T("柱子尺寸不正确!"));
return;
}
}
if (m_nShape == 3)//工字形
{
m_dYSize = 1.0;
m_dXSize = 1.0;
m_idStellCol = CreateIStellBlock();
}
if (m_nShape == 4)//槽钢
{
m_dYSize = 1.0;
m_dXSize = 1.0;
m_idStellCol = CreateOStellBlock();
}
if (m_dH < 1.e-1)
{
AfxMessageBox(_T("柱子高度尺寸不正确!"));
return;
}
if (m_idCol.isValid())
{
UpdateColData();
}
SET_CACHE(CCRZZDlg
, %f%f%f%f%s%s%s%s%s%s%d%d%f%f%s%s%d
, m_dXOffset
, m_dYOffset
, m_dBomEl
, m_dH
, m_sA
, m_sB
, m_sC
, m_sD
, m_sMaterial
, m_sNo
, m_iInsertType
, m_nShape
, m_dXSize
, m_dYSize
, m_sHatch
, m_sModel
, m_nSteel);
CDialog::OnOK();
}
AcDbObjectId CCRZZDlg::CreateIStellBlock()
{
double dA = _ttof(m_sA);
double dB = _ttof(m_sB);
double dC = _ttof(m_sC);
double dD = _ttof(m_sD);
AcGePoint3d ptGe[12],ptGeT;
ptGeT.set(0,0,0);
ptGeT.y += dA / 2.0;
ptGeT.x -= dB / 2.0;
ptGe[0] = ptGeT;
ptGe[1] = ptGe[0] + dB * AcGeVector3d::kXAxis;
ptGe[2] = ptGe[1] - dC * AcGeVector3d::kYAxis;
ptGe[3] = ptGe[2] - (dB - dD) / 2.0 * AcGeVector3d::kXAxis;
ptGe[4] = ptGe[3] - (dA - 2.0 * dC) * AcGeVector3d::kYAxis;
ptGe[5] = ptGe[4] + (dB - dD) / 2.0 * AcGeVector3d::kXAxis;
ptGe[6] = ptGe[5] - dC * AcGeVector3d::kYAxis;
ptGe[7] = ptGe[6] - dB * AcGeVector3d::kXAxis;
ptGe[8] = ptGe[7] + dC * AcGeVector3d::kYAxis;
ptGe[9] = ptGe[8] + (dB - dD) / 2.0 * AcGeVector3d::kXAxis;
ptGe[10] = ptGe[9] + (dA - 2.0 * dC) * AcGeVector3d::kYAxis;
ptGe[11] = ptGe[10] - (dB - dD) / 2.0 * AcGeVector3d::kXAxis;
AcDbBlockTableRecord* pRec = new AcDbBlockTableRecord;
pRec->setOrigin(AcGePoint3d::kOrigin);
pRec->setName(_T("*U"));
AcDbPolyline* pPl = new AcDbPolyline;
for (int i = 0;i < 12;i++)
{
pPl->addVertexAt(i,ptGe[i].convert2d(AcGePlane::kXYPlane));
}
pPl->setClosed(Adesk::kTrue);
pRec->appendAcDbEntity(pPl);
pPl->close();
AcDbBlockTable* pTable = NULL;
acdbCurDwg()->getBlockTable(pTable,AcDb::kForWrite);
if (pTable != NULL)
{
pTable->add(m_idStellCol,pRec);
pRec->close();
pTable->close();
}
return m_idStellCol;
}
AcDbObjectId CCRZZDlg::CreateOStellBlock()
{
AcGePoint3d ptGe[8],ptGeT;
ptGeT.set(0,0,0);
double dA = _ttof(m_sA);
double dB = _ttof(m_sB);
double dC = _ttof(m_sC);
double dD = _ttof(m_sD);
//ptGeT.x += dB / 2.0;
ptGeT.y += (dA - 2 * dC) / 2.0;
ptGe[0] = ptGeT;
ptGe[1] = ptGe[0] + dC * AcGeVector3d::kYAxis;
ptGe[2] = ptGe[1] + dB * AcGeVector3d::kXAxis;
ptGe[3] = ptGe[2] - dA * AcGeVector3d::kYAxis;
ptGe[4] = ptGe[3] - dB * AcGeVector3d::kXAxis;
ptGe[5] = ptGe[4] + dC * AcGeVector3d::kYAxis;
ptGe[6] = ptGe[5] + (dB - dD) * AcGeVector3d::kXAxis;
ptGe[7] = ptGe[6] + (dA - 2.0 * dC) * AcGeVector3d::kYAxis;
AcDbBlockTableRecord* pRec = new AcDbBlockTableRecord;
pRec->setOrigin(AcGePoint3d::kOrigin);
pRec->setName(_T("*U"));
//AcDbPolyline* pPl = new AcDbPolyline;
//for (int i = 0;i < 8;i++)
//{
// pPl->addVertexAt(i,ptGe[i].convert2d(AcGePlane::kXYPlane));
//}
//pPl->setClosed(Adesk::kTrue);
//pRec->appendAcDbEntity(pPl);
//pPl->close();
ptGeT = ptGe[2];
AcDbLine* pLine1 = new AcDbLine(ptGe[2],ptGeT.mirror(AcGePlane::kYZPlane));
pLine1->setVisibility(AcDb::kInvisible);
pRec->appendAcDbEntity(pLine1);
pLine1->close();
ptGeT = ptGe[3];
pLine1 = new AcDbLine(ptGe[3],ptGeT.mirror(AcGePlane::kYZPlane));
pLine1->setVisibility(AcDb::kInvisible);
pRec->appendAcDbEntity(pLine1);
pLine1->close();
AcDbPolyline* pPl2 = new AcDbPolyline;
for (int i = 0;i < 8;i++)
{
ptGe[i].mirror(AcGePlane::kYZPlane);
pPl2->addVertexAt(i,ptGe[i].convert2d(AcGePlane::kXYPlane));
}
pPl2->setClosed(Adesk::kTrue);
pRec->appendAcDbEntity(pPl2);
pPl2->close();
AcDbBlockTable* pTable = NULL;
acdbCurDwg()->getBlockTable(pTable,AcDb::kForWrite);
if (pTable != NULL)
{
pTable->add(m_idStellCol,pRec);
pRec->close();
pTable->close();
}
return m_idStellCol;
}
void CCRZZDlg::OnSelchangeCmbShape()
{
if (!m_bInplace)
UpdateData();
int nRo = (int)(m_dRotAngle + 0.5);
CString sRo;
sRo.Format(_T("%d"),nRo);
int nPos = m_wndComboAngle.FindString(0,sRo);
if (nPos != -1) m_wndComboAngle.SetCurSel(nPos);
if (m_nShape >= 0 && m_nShape <= 2)
{
GetDlgItem(IDC_STEELTYPE)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_CMBSTEEL)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_A)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_B)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_C)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_D)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_EDITA)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_EDITB)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_EDITC)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_EDITD)->ShowWindow(SW_HIDE);
}
if (m_nShape == 0) //矩形
{
m_sBlockName = _T("_FZH.DWG");
GetDlgItem(IDC_STC_XSIZE)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_STC_YSIZE)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_STC_DIAMETER)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_STC_EDGESIZE)->ShowWindow(SW_HIDE);
m_wndComboXSize.ShowWindow(SW_SHOW);
m_wndComboYSize.ShowWindow(SW_SHOW);
}
else if (m_nShape == 1) //圆形
{
m_sBlockName = _T("_YZH.DWG");
GetDlgItem(IDC_STC_XSIZE)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_STC_YSIZE)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_STC_DIAMETER)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_STC_EDGESIZE)->ShowWindow(SW_HIDE);
m_wndComboXSize.ShowWindow(SW_SHOW);
m_wndComboYSize.ShowWindow(SW_HIDE);
}
else if(m_nShape == 2) // 正六边形
{
m_sBlockName = _T("_DBXZH6.DWG");
GetDlgItem(IDC_STC_XSIZE)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_STC_YSIZE)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_STC_DIAMETER)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_STC_EDGESIZE)->ShowWindow(SW_SHOW);
m_wndComboXSize.ShowWindow(SW_SHOW);
m_wndComboYSize.ShowWindow(SW_HIDE);
}
else if (m_nShape == 3)// 工字形
{
m_sBlockName = _T("_ZZH.dwg");
GetDlgItem(IDC_STC_XSIZE)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_STC_YSIZE)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_STC_DIAMETER)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_STC_EDGESIZE)->ShowWindow(SW_HIDE);
m_wndComboXSize.ShowWindow(SW_HIDE);
m_wndComboYSize.ShowWindow(SW_HIDE);
GetDlgItem(IDC_STEELTYPE)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_CMBSTEEL)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_A)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_B)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_C)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_D)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_EDITA)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_EDITB)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_EDITC)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_EDITD)->ShowWindow(SW_SHOW);
//加载数据
CString sSQL = _T("select [型钢型号] from AecSteeldata where [型钢类型]='工字钢' order by A DESC");
CStringArray arValues;
m_dbSQLite.GetSelData(sSQL,arValues);
m_wndComSteel.ResetContent();
for (int i = 0;i < arValues.GetSize();i++)
{
m_wndComSteel.AddString(arValues.GetAt(i));
}
if (!m_bInplace)
{
m_wndComSteel.SetCurSel(0);
OnSelchangeCmbsteel();
}
}
else if (m_nShape == 4) // 槽钢
{
m_sBlockName = _T("_OZH.dwg");
GetDlgItem(IDC_STC_XSIZE)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_STC_YSIZE)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_STC_DIAMETER)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_STC_EDGESIZE)->ShowWindow(SW_HIDE);
m_wndComboXSize.ShowWindow(SW_HIDE);
m_wndComboYSize.ShowWindow(SW_HIDE);
GetDlgItem(IDC_STEELTYPE)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_CMBSTEEL)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_A)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_B)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_C)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_D)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_EDITA)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_EDITB)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_EDITC)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_EDITD)->ShowWindow(SW_SHOW);
//加载数据
CString sSQL = _T("select [型钢型号] from AecSteeldata where [型钢类型]='槽钢' order by A DESC");
CStringArray arValues;
m_dbSQLite.GetSelData(sSQL,arValues);
m_wndComSteel.ResetContent();
for (int i = 0;i < arValues.GetSize();i++)
{
m_wndComSteel.AddString(arValues.GetAt(i));
}
if (!m_bInplace)
{
m_wndComSteel.SetCurSel(0);
OnSelchangeCmbsteel();
}
}
PreviewColumn();
}
void CCRZZDlg::PreviewColumn()
{
CString sPath;
sPath = FilePath::GetSysDir();
sPath.Replace(_T("\\sys"),_T("\\Support"));
CString sDwgFile = sPath + _T("\\Cells\\") + m_sBlockName;
m_wndPreview.clearAll();
if (m_pDb != NULL)
delete m_pDb;
m_pDb = new AcDbDatabase(Adesk::kFalse);
Acad::ErrorStatus es = m_pDb->readDwgFile(sDwgFile);
if (es != Acad::eOk)
{
AfxMessageBox(CString(_T("打开文件失败 \"")) + sDwgFile + _T("\""));
delete m_pDb;
m_pDb = NULL;
return;
}
// now initialise the drawing control
InitDrawingControl(m_pDb);
Invalidate();
RedrawWindow();
}
Acad::ErrorStatus CCRZZDlg::InitDrawingControl (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
AcGeMatrix3d xform;
SetViewTo(m_wndPreview.mpView, pDb, xform);
// tell the view to display this space
m_wndPreview.view()->add(spaceRec.object(), m_wndPreview.model());
}
return spaceRec.openStatus();
}
bool CCRZZDlg::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 CCRZZDlg::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();
// 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 CCRZZDlg::OnSelchangeCmbsteel()
{
UpdateData();
//加载数据
int nCursel = m_wndComSteel.GetCurSel();
if (nCursel != -1)
{
CString sText,sSQL;
m_wndComSteel.GetLBText(nCursel,sText);
if (m_nShape == 3)
{
sSQL.Format(_T("select A,B,C,D from AecSteeldata where [型钢类型]='工字钢' and [型钢型号]='%s'"),sText);
}
else if (m_nShape == 4)
{
sSQL.Format(_T("select A,B,C,D from AecSteeldata where [型钢类型]='槽钢' and [型钢型号]='%s'"),sText);
}
CStringArray arValues;
m_dbSQLite.GetSelData(sSQL,arValues);
if (arValues.GetSize() == 4)
{
m_sA = arValues.GetAt(0);
m_sB = arValues.GetAt(1);
m_sC = arValues.GetAt(2);
m_sD = arValues.GetAt(3);
UpdateData(FALSE);
}
}
}
void CCRZZDlg::SetFromCol(const AcDbObjectId& id)
{
m_idCol = id;
AcAxDocLock lock;
AcDbEntity* pEnt = NULL;
if ( Acad::eOk == acdbOpenAcDbEntity(pEnt,id,AcDb::kForRead))
{
AecDbColumn* pCol = AecDbColumn::cast(pEnt);
if (pCol != NULL)
{
ColumnParam data;
memset(&data,0,sizeof(ColumnParam));
pCol->GetColumnData(data);
pCol->GetSpecialtyData(AcDb::kForRead)->GetAt(KEY_NO,m_sNo);
m_sHatch = data.m_sHatch;
if (m_sHatch == HATCH_NO_NEED)
m_bAddHatch = FALSE;
else
m_bAddHatch = TRUE;
m_sModel = data.m_sModel;
m_sBlockName = data.m_sBlockName;
m_sA.Format(_T("%g"),data.m_dSizes[0]);
m_sB.Format(_T("%g"),data.m_dSizes[1]);
m_sC.Format(_T("%g"),data.m_dSizes[2]);
m_sD.Format(_T("%g"),data.m_dSizes[3]);
m_dRotAngle = data.m_dRotAngle;
m_dXOffset = data.m_dXExtend;
m_dYOffset = data.m_dYExtend;
m_dXSize = data.m_dXScale;
m_dYSize = data.m_dYScale;
m_nShape = data.m_nShape;
m_dBomEl = data.m_dBomEl;
m_dH = data.m_dH;
m_sMaterial = data.m_sMaterial;
m_bInplace = true;
}
pEnt->close();
}
}
extern "C" AcDbRegion *GetColumnRegion(const ColumnParam &ColParam);
void CCRZZDlg::UpdateColData()
{
AcAxDocLock lock;
AcDbEntity* pEnt = NULL;
if ( Acad::eOk == acdbOpenAcDbEntity(pEnt,m_idCol,AcDb::kForWrite))
{
AecDbColumn* pCol = AecDbColumn::cast(pEnt);
if (pCol != NULL)
{
pCol->GetSpecialtyData()->SetAt(KEY_NO,m_sNo);
ColumnParam ColParam;
GetColumnParam(ColParam);
AcDbRegion* pRegAll = GetColumnRegion(ColParam);
if (pRegAll != NULL)
{
pCol->SetSection(pRegAll,AcGePoint3d::kOrigin);
}
pCol->SetHeight(ColParam.m_dH);
pCol->SetElev(ColParam.m_dBomEl);
pCol->GetSpecialtyData()->SetAt(KEY_MATERIAL,ColParam.m_sMaterial);
pCol->GetSpecialtyData()->SetAt(KEY_SHAPE,ColParam.m_nShape);
pCol->GetSpecialtyData()->SetAt(KEY_BLOCKNAME,ColParam.m_sBlockName);
pCol->GetSpecialtyData()->SetAt(KEY_ROTATION,0.0);//ColParam.m_dRotAngle);
pCol->GetSpecialtyData()->SetAt(KEY_ROTATIONBK,ColParam.m_dRotAngle);
pCol->GetSpecialtyData()->SetAt(KEY_SIZE1,ColParam.m_dSizes[0]);
pCol->GetSpecialtyData()->SetAt(KEY_SIZE2,ColParam.m_dSizes[1]);
pCol->GetSpecialtyData()->SetAt(KEY_SIZE3,ColParam.m_dSizes[2]);
pCol->GetSpecialtyData()->SetAt(KEY_SIZE4,ColParam.m_dSizes[3]);
pCol->GetSpecialtyData()->SetAt(KEY_XE,ColParam.m_dXExtend);
pCol->GetSpecialtyData()->SetAt(KEY_YE,ColParam.m_dYExtend);
pCol->GetSpecialtyData()->SetAt(KEY_XS,ColParam.m_dXScale);
pCol->GetSpecialtyData()->SetAt(KEY_YS,ColParam.m_dYScale);
pCol->GetSpecialtyData(AcDb::kForRead)->SetAt(KEY_SECTION_HATCH, m_sHatch);
pCol->GetSpecialtyData(AcDb::kForRead)->SetAt(AecDbColumn::KEY_COL_MODEL, m_sModel);
}
pEnt->close();
}
}
void CCRZZDlg::OnBnClickedOk()
{
OnOK();
}
void CCRZZDlg::OnDestroy()
{
CDialog::OnDestroy();
m_wndPreview.clearAll();
if (m_pDb != NULL)
delete m_pDb;
m_pDb = NULL;
}
void CCRZZDlg::OnBnClickedCheck1()
{
UpdateData();
if (m_bNOSetDefault)
{
GetDlgItem(IDC_EDIT6)->EnableWindow(FALSE);
}
else
{
GetDlgItem(IDC_EDIT6)->EnableWindow(TRUE);
}
}
extern bool __cdecl acedHatchPalletteDialog(wchar_t const* , bool , wchar_t *&);
void CCRZZDlg::OnBnClickedBtnFill()
{
UpdateData();
TCHAR *psz = new TCHAR[1024];
::memset(psz, 0, sizeof(TCHAR) * 1024);
CString sHatch(m_sMaterial);
if (!m_sHatch.IsEmpty())
sHatch = m_sHatch;
if (acedHatchPalletteDialog(sHatch, false, psz))
{
m_sHatch = psz;
m_wndBtHatch.SetWindowText(m_sHatch);
}
delete[] psz;
}
void CCRZZDlg::OnBnClickedCheckHatch()
{
UpdateData();
m_wndBtHatch.EnableWindow(m_bAddHatch);
if (!m_bAddHatch)
m_sHatch = HATCH_NO_NEED;
else
m_sHatch = HATCH_DEFAULT;
UpdateData(FALSE);
}