#include "stdafx.h" #include "JLHCDlg.h" #include "dbobjptr.h" #include "KTSetting.h" IMPLEMENT_DYNAMIC(CJLHCDlg, CDialog) CJLHCDlg::CJLHCDlg(CWnd* pParent /*=NULL*/) : CDialog(CJLHCDlg::IDD, pParent) , m_sRoofMaterial(_T("沥青覆瓦")) , m_sFloorMaterial(_T("混凝土")) , m_sEavsMaterial(_T("混凝土")) , m_sWallMaterial(_T("混凝土")) , m_sGlassMaterial(_T("中空玻璃")) , m_sWindowMaterial(_T("断桥铝合金")) { m_nDormerType = 0; m_sEaves = _T(""); m_sFloor = _T(""); m_sGlass = _T(""); m_sRoof = _T(""); m_sWall = _T(""); m_sWindow = _T(""); m_bShowWindow = TRUE; m_sExtendEaves = _T(""); m_sExtendHill = _T(""); m_sSlopeGrade = _T(""); m_sSlopeHeight = _T(""); m_sSlopeThickness = _T(""); m_sWallHeight = _T(""); m_sWallThickness = _T(""); m_sWallWidth = _T(""); m_sWindowWidth = _T(""); m_sWindowHeight = _T(""); m_csLabel = _T("LHC_001"); GET_CACHE(CJLHCDlg , %s %s %s %s %s %s %d %s %s %s %s %s %s %d %s %s %s %s %s %s %s %s %s %s %s , &m_sRoofMaterial , &m_sFloorMaterial , &m_sEavsMaterial , &m_sWallMaterial , &m_sGlassMaterial , &m_sWindowMaterial , &m_nDormerType , &m_sEaves , &m_sFloor , &m_sGlass , &m_sRoof , &m_sWall , &m_sWindow , &m_bShowWindow , &m_sExtendEaves , &m_sExtendHill , &m_sSlopeGrade , &m_sSlopeHeight , &m_sSlopeThickness , &m_sWallHeight , &m_sWallThickness , &m_sWallWidth , &m_sWindowWidth , &m_sWindowHeight , &m_csLabel); } CJLHCDlg::~CJLHCDlg() { } void CJLHCDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CJLHCDlg) DDX_CBIndex(pDX, IDC_DORMERTYPE, m_nDormerType); DDX_CBString(pDX, IDC_COMBO_EAVES, m_sEaves); DDX_CBString(pDX, IDC_COMBO_FLOOR, m_sFloor); DDX_CBString(pDX, IDC_COMBO_GLASS, m_sGlass); DDX_CBString(pDX, IDC_COMBO_ROOF, m_sRoof); DDX_CBString(pDX, IDC_COMBO_WALL, m_sWall); DDX_CBString(pDX, IDC_COMBO_WINDOW, m_sWindow); DDX_Check(pDX, IDC_CHECK_SHOWWINDOW, m_bShowWindow); DDX_Control(pDX, IDC_COMBO_WINDOW, m_comboWindow); DDX_Control(pDX, IDC_COMBO_WALL, m_comboWall); DDX_Control(pDX, IDC_COMBO_ROOF, m_comboRoof); DDX_Control(pDX, IDC_COMBO_GLASS, m_comboGlass); DDX_Control(pDX, IDC_COMBO_FLOOR, m_comboFloor); DDX_Control(pDX, IDC_COMBO_EAVES, m_comboEaves); DDX_Control(pDX, IDC_EDIT1_WINDOWHEIGHT, m_ctrlWindowHeight); DDX_Control(pDX, IDC_EDIT_WINDOWWIDTH, m_ctrlWindowWidth); DDX_Control(pDX, IDC_EDIT_WALLWIDTH, m_ctrlWallWidth); DDX_Control(pDX, IDC_EDIT_WALLTHICKNESS, m_ctrlWallThickness); DDX_Control(pDX, IDC_EDIT_WALLHEIGHT, m_ctrlWallHeight); DDX_Control(pDX, IDC_EDIT_SLOPETHICKNESS, m_ctrlSlopeThickness); DDX_Control(pDX, IDC_EDIT_SLOPEHEIGHT, m_ctrlSlopeHeight); DDX_Control(pDX, IDC_EDIT_SLOPEGRADE, m_ctrlSlopeGrade); DDX_Control(pDX, IDC_EDIT_EXTENDHILL, m_ctrlExtendHill); DDX_Control(pDX, IDC_EDIT_EXTENDEAVES, m_ctrlExtendEaves); DDX_Text(pDX, IDC_EDIT_EXTENDEAVES, m_sExtendEaves); DDX_Text(pDX, IDC_EDIT_EXTENDHILL, m_sExtendHill); DDX_Text(pDX, IDC_EDIT_SLOPEGRADE, m_sSlopeGrade); DDX_Text(pDX, IDC_EDIT_SLOPEHEIGHT, m_sSlopeHeight); DDX_Text(pDX, IDC_EDIT_SLOPETHICKNESS, m_sSlopeThickness); DDX_Text(pDX, IDC_EDIT_WALLHEIGHT, m_sWallHeight); DDX_Text(pDX, IDC_EDIT_WALLTHICKNESS, m_sWallThickness); DDX_Text(pDX, IDC_EDIT_WALLWIDTH, m_sWallWidth); DDX_Text(pDX, IDC_EDIT_WINDOWWIDTH, m_sWindowWidth); DDX_Text(pDX, IDC_EDIT1_WINDOWHEIGHT, m_sWindowHeight); DDX_CBString(pDX, IDC_LABEL, m_csLabel); //}}AFX_DATA_MAP DDX_Text(pDX, IDC_EDIT1, m_sRoofMaterial); DDX_Text(pDX, IDC_EDIT2, m_sFloorMaterial); DDX_Text(pDX, IDC_EDIT3, m_sEavsMaterial); DDX_Text(pDX, IDC_EDIT12, m_sWallMaterial); DDX_Text(pDX, IDC_EDIT13, m_sGlassMaterial); DDX_Text(pDX, IDC_EDIT14, m_sWindowMaterial); } BEGIN_MESSAGE_MAP(CJLHCDlg, CDialog) ON_CBN_SELCHANGE(IDC_DORMERTYPE, OnSelchangeDormerType) ON_WM_PAINT() ON_BN_CLICKED(IDC_CHECK_SHOWWINDOW, OnCheckShowWindow) ON_EN_CHANGE(IDC_EDIT_SLOPEGRADE, OnChangeEditSlopeGrade) ON_EN_CHANGE(IDC_EDIT_WALLWIDTH, OnChangeEditWallWidth) ON_EN_CHANGE(IDC_EDIT_WINDOWWIDTH, OnChangeEditWindowWidth) END_MESSAGE_MAP() void GetLayerName(AcDbObjectId& id,CString& sName) { AcDbSymbolTableRecordPointer rcPt1(id,AcDb::kForRead); LPCTSTR pszName = NULL; rcPt1->getName(pszName); sName = pszName; } void CJLHCDlg::InitDormerLayer() { AcDbObjectId id3DRoof = KTSetting::InitLayer(_T("LAY_ROOF")); GetLayerName(id3DRoof,m_sRoof); AcDbObjectId id3DFloor = KTSetting::InitLayer(_T("LAY_FLOOR")); GetLayerName(id3DFloor,m_sFloor); AcDbObjectId id3DWall = KTSetting::InitLayer(_T("LAY_WALL")); GetLayerName(id3DWall,m_sWall); AcDbObjectId id3DEaves = KTSetting::InitLayer(_T("LAY_EAVES")); GetLayerName(id3DEaves,m_sEaves); AcDbObjectId id3DGlass = KTSetting::InitLayer(_T("LAY_3DGLASS")); GetLayerName(id3DGlass,m_sGlass); AcDbObjectId id3DWindow = KTSetting::InitLayer(_T("LAY_WIN")); GetLayerName(id3DWindow,m_sWindow); } void CJLHCDlg::OnSelchangeDormerType() { UpdateData(TRUE); UpdateWindow(); } void CJLHCDlg::OnPaint() { CPaintDC dc(this); // device context for painting CRect rcClip, rcImage; dc.GetClipBox(&rcClip); CWnd *pImageBox=GetDlgItem(IDC_IMAGE); if (pImageBox) { pImageBox->GetWindowRect(&rcImage); ScreenToClient(&rcImage); if (!rcImage.IntersectRect(&rcImage, &rcClip)) return; CDC *pDC=pImageBox->GetDC(); m_slideDc.SetDC(pDC); m_slideDc.Redraw(); m_slideDc.SetDC(NULL); pImageBox->ReleaseDC(pDC); } } static void GetCurDwgLayers(CStringArray& lstLayer) { AcDbLayerTable* pTbl = NULL; AcDbDatabase* pDb = acdbCurDwg(); if (pDb != NULL) { if ( Acad::eOk == pDb->getLayerTable(pTbl,AcDb::kForRead)) { AcDbLayerTableIterator* pIt = NULL; pTbl->newIterator(pIt); if (pIt != NULL) { for(pIt->start();!pIt->done();pIt->step()) { AcDbLayerTableRecord* pRec = NULL; pIt->getRecord(pRec,AcDb::kForRead); if (pRec != NULL) { const TCHAR* pszName = NULL; pRec->getName(pszName); if (pszName != NULL) { lstLayer.Add(pszName); } pRec->close(); } } delete pIt; } pTbl->close(); } } } BOOL CJLHCDlg::OnInitDialog() { CDialog::OnInitDialog(); SetWindowText(m_sTitle); CStringArray lstLayer; GetCurDwgLayers(lstLayer); CString sLayer; for(int i = 0;i < lstLayer.GetSize();i++) { sLayer = lstLayer.GetAt(i); m_comboWindow.AddString(lstLayer.GetAt(i)); if (m_sWindow.CompareNoCase(sLayer) == 0) { m_comboWindow.SetCurSel(i); } m_comboWall.AddString(lstLayer.GetAt(i)); if (m_sWall.CompareNoCase(sLayer) == 0) { m_comboWall.SetCurSel(i); } m_comboRoof.AddString(lstLayer.GetAt(i)); if (m_sRoof.CompareNoCase(sLayer) == 0) { m_comboRoof.SetCurSel(i); } m_comboGlass.AddString(lstLayer.GetAt(i)); if (m_sGlass.CompareNoCase(sLayer) == 0) { m_comboGlass.SetCurSel(i); } m_comboFloor.AddString(lstLayer.GetAt(i)); if (m_sFloor.CompareNoCase(sLayer) == 0) { m_comboFloor.SetCurSel(i); } m_comboEaves.AddString(lstLayer.GetAt(i)); if (m_sEaves.CompareNoCase(sLayer) == 0) { m_comboEaves.SetCurSel(i); } } if (m_bUseDefaultLabel) { m_csLabel = m_strDefaultlabel; } UpdateWindow(); UpdateData(FALSE); return TRUE; } //类型 void CJLHCDlg::SetDormerType(DormerParam::DormerType dormerType) { switch (dormerType) { case DormerParam::kSLOPE_TRIANGLE: m_nDormerType = 0; break; case DormerParam::kSLOPE_TWO: m_nDormerType = 1; break; case DormerParam::kSLOPE_THREE: m_nDormerType = 2; break; case DormerParam::kSLOPE_TRAPEZIA: m_nDormerType = 3; break; case DormerParam::kSLOPE_FLAT: m_nDormerType = 4; break; default: m_nDormerType = 1; } } DormerParam::DormerType CJLHCDlg::GetDormerType() const { DormerParam::DormerType dormerType=DormerParam::kSLOPE_TWO; switch(m_nDormerType) { case 0: dormerType = DormerParam::kSLOPE_TRIANGLE; break; case 1: dormerType = DormerParam::kSLOPE_TWO; break; case 2: dormerType = DormerParam::kSLOPE_THREE; break; case 3: dormerType = DormerParam::kSLOPE_TRAPEZIA; break; case 4: dormerType = DormerParam::kSLOPE_FLAT; break; default: dormerType = DormerParam::kSLOPE_TWO; } return dormerType; } void CJLHCDlg::GetDormerPar(DormerParam& dormerPar) const { //类型 dormerPar.m_dormerType = GetDormerType(); //墙 dormerPar.m_dWallHeight = _tstof(m_sWallHeight)-_tstof(m_sSlopeThickness); dormerPar.m_dWallWidth = _tstof(m_sWallWidth); dormerPar.m_dWallThickness = _tstof(m_sWallThickness); //窗 dormerPar.m_dWindowHeight = _tstof(m_sWindowHeight); dormerPar.m_dWindowWidth = _tstof(m_sWindowWidth); //坡 dormerPar.m_dSlopeGrade = _tstof(m_sSlopeGrade); dormerPar.m_dSlopeHeight = _tstof(m_sSlopeHeight); dormerPar.m_dSlopeThickness = _tstof(m_sSlopeThickness); //伸出长度 dormerPar.m_dExtendEaves = _tstof(m_sExtendEaves); dormerPar.m_dExtendHill = _tstof(m_sExtendHill); //图层 _tcscpy(dormerPar.m_sz3DEaves,m_sEaves); _tcscpy(dormerPar.m_sz3DFloor,m_sFloor); _tcscpy(dormerPar.m_sz3DGlass,m_sGlass); _tcscpy(dormerPar.m_sz3DRoof,m_sRoof); _tcscpy(dormerPar.m_sz3DWall,m_sWall); _tcscpy(dormerPar.m_sz3DWindow,m_sWindow); } void CJLHCDlg::SetDormerPar(const DormerParam& dormerPar) { //类型 SetDormerType(dormerPar.m_dormerType); //墙 m_sWallHeight.Format(_T("%d"),(int)(dormerPar.m_dWallHeight + dormerPar.m_dSlopeThickness)); m_sWallWidth.Format(_T("%d"),(int)(dormerPar.m_dWallWidth)); m_sWallThickness.Format(_T("%d"),(int)(dormerPar.m_dWallThickness)); //窗 m_sWindowHeight.Format(_T("%d"),(int)(dormerPar.m_dWindowHeight)); m_sWindowWidth.Format(_T("%d"),(int)(dormerPar.m_dWindowWidth)); //坡 m_sSlopeGrade.Format(_T("%.2f"),dormerPar.m_dSlopeGrade); m_sSlopeHeight.Format(_T("%d"),(int)(dormerPar.m_dSlopeHeight)); m_sSlopeThickness.Format(_T("%d"),(int)(dormerPar.m_dSlopeThickness)); //伸出长度 m_sExtendEaves.Format(_T("%d"),(int)(dormerPar.m_dExtendEaves)); m_sExtendHill.Format(_T("%d"),(int)(dormerPar.m_dExtendHill)); } void CJLHCDlg::SetShowWindow(BOOL bShow) { m_bShowWindow = bShow; } BOOL CJLHCDlg::IsShowWindow() const { return m_bShowWindow; } void CJLHCDlg::UpdateWindow() { switch(m_nDormerType) { case 0: m_ctrlSlopeGrade.EnableWindow(TRUE); m_ctrlSlopeHeight.EnableWindow(FALSE); m_ctrlWallHeight.EnableWindow(FALSE); m_ctrlWindowHeight.EnableWindow(FALSE); m_ctrlWindowWidth.EnableWindow(FALSE); m_ctrlExtendEaves.EnableWindow(FALSE); OpenSlide(_T("Arch(DMTRIANGLE)")); break; case 1: m_ctrlSlopeGrade.EnableWindow(TRUE); m_ctrlSlopeHeight.EnableWindow(FALSE); m_ctrlWallHeight.EnableWindow(TRUE); m_ctrlWindowHeight.EnableWindow(TRUE); m_ctrlWindowWidth.EnableWindow(TRUE); m_ctrlExtendEaves.EnableWindow(TRUE); OpenSlide(_T("Arch(DMDOUBLE)")); break; case 2: m_ctrlSlopeGrade.EnableWindow(TRUE); m_ctrlSlopeHeight.EnableWindow(FALSE); m_ctrlWallHeight.EnableWindow(TRUE); m_ctrlWindowHeight.EnableWindow(TRUE); m_ctrlWindowWidth.EnableWindow(TRUE); m_ctrlExtendEaves.EnableWindow(TRUE); OpenSlide(_T("Arch(DMTRISLOPE)")); break; case 3: m_ctrlSlopeGrade.EnableWindow(TRUE); m_ctrlSlopeHeight.EnableWindow(TRUE); m_ctrlWallHeight.EnableWindow(TRUE); m_ctrlWindowHeight.EnableWindow(TRUE); m_ctrlWindowWidth.EnableWindow(TRUE); m_ctrlExtendEaves.EnableWindow(TRUE); OpenSlide(_T("Arch(DMTRAP)")); break; case 4: m_ctrlSlopeGrade.EnableWindow(FALSE); m_ctrlSlopeHeight.EnableWindow(FALSE); m_ctrlWallHeight.EnableWindow(TRUE); m_ctrlWindowHeight.EnableWindow(TRUE); m_ctrlWindowWidth.EnableWindow(TRUE); m_ctrlExtendEaves.EnableWindow(TRUE); OpenSlide(_T("Arch(DMFLATWIN)")); break; default: m_ctrlSlopeGrade.EnableWindow(TRUE); m_ctrlSlopeHeight.EnableWindow(FALSE); m_ctrlWallHeight.EnableWindow(TRUE); m_ctrlWindowHeight.EnableWindow(TRUE); m_ctrlWindowWidth.EnableWindow(TRUE); m_ctrlExtendEaves.EnableWindow(TRUE); OpenSlide(_T("Arch(DMDOUBLE)")); } if (!m_bShowWindow) { m_ctrlWindowHeight.EnableWindow(FALSE); m_ctrlWindowWidth.EnableWindow(FALSE); } } static COLORREF GetAcadBackColor() { AcColorSettings setAcadColor; acedGetCurrentColors(&setAcadColor); return setAcadColor.dwGfxModelBkColor; } void CJLHCDlg::OpenSlide(LPCTSTR pszFilePath) { CWnd *pImageBox=GetDlgItem(IDC_IMAGE); if (pImageBox) { CDC *pDC=pImageBox->GetDC(); CRect rc; pImageBox->GetClientRect(&rc); m_slideDc.InitDC(pDC, rc, GetAcadBackColor()); m_slideDc.PaintSlide(pszFilePath); m_slideDc.SetDC(NULL); pImageBox->ReleaseDC(pDC); } } void CJLHCDlg::OnOK() { UpdateData(TRUE); if (_tstof(m_sWindowHeight) > _tstof(m_sWallHeight)) { AfxMessageBox(_T("窗的高度不能大于墙的高度!")); return; } if (_tstof(m_sWindowWidth) > _tstof(m_sWallWidth)-_tstof(m_sWallThickness)*2) { CString sTip; sTip.Format(_T("窗的宽度不能大于内墙之间的宽度%.1f!"),_tstof(m_sWallWidth)-_tstof(m_sWallThickness)*2); AfxMessageBox(sTip); return; } if (m_nDormerType==0 && _tstof(m_sSlopeGrade)<=0) { AfxMessageBox(_T("坡度必须大于零!")); return; } SET_CACHE(CJLHCDlg , %s %s %s %s %s %s %d %s %s %s %s %s %s %d %s %s %s %s %s %s %s %s %s %s %s , m_sRoofMaterial , m_sFloorMaterial , m_sEavsMaterial , m_sWallMaterial , m_sGlassMaterial , m_sWindowMaterial , m_nDormerType , m_sEaves , m_sFloor , m_sGlass , m_sRoof , m_sWall , m_sWindow , m_bShowWindow , m_sExtendEaves , m_sExtendHill , m_sSlopeGrade , m_sSlopeHeight , m_sSlopeThickness , m_sWallHeight , m_sWallThickness , m_sWallWidth , m_sWindowWidth , m_sWindowHeight , m_csLabel); CDialog::OnOK(); } void CJLHCDlg::OnCheckShowWindow() { UpdateData(TRUE); UpdateWindow(); } void CJLHCDlg::UpdateParameter() { UpdateData(TRUE); if (m_nDormerType==0) { m_sSlopeHeight.Format(_T("%d"),(int)(_tstof(m_sWallWidth)*_tstof(m_sSlopeGrade)/2)); m_sWallHeight = m_sSlopeHeight; m_sWindowHeight.Format(_T("%d"),(int)(_tstof(m_sWindowWidth)*_tstof(m_sSlopeGrade)/2)); } else if (m_nDormerType==1 || m_nDormerType==2 ) { m_sSlopeHeight.Format(_T("%d"),(int)(_tstof(m_sWallWidth)*_tstof(m_sSlopeGrade)/2)); } UpdateData(FALSE); } void CJLHCDlg::OnChangeEditSlopeGrade() { UpdateParameter(); } void CJLHCDlg::OnChangeEditWallWidth() { UpdateParameter(); } void CJLHCDlg::OnChangeEditWindowWidth() { UpdateParameter(); }