// RectHoleDlg.cpp : implementation file // #include "stdafx.h" #include "resource.h" #include "RectHoleDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CRectHoleDlg dialog //IMPLEMENT_DYNAMIC(CRectHoleDlg, CInsertOpeningDlg) // add by xly on 110216 初始化静态变量 BOOL CRectHoleDlg::m_bIsPassWall = TRUE; CString CRectHoleDlg::m_csHoleDepth = _T("200"); bool CRectHoleDlg::m_bIsHasPassWall = false; int CRectHoleDlg::m_nHasPassWallNums = 0; CRectHoleDlg::CRectHoleDlg(CWnd* pParent /*=NULL*/) : CInsertOpeningDlg(CRectHoleDlg::IDD, pParent) { m_nWidth=1500; m_nHeight=1800; m_nSill=800; m_nHoleStyle=0; // 0, 1, 2 //{{AFX_DATA_INIT(CRectHoleDlg) //}}AFX_DATA_INIT } #define KEEP_LABEL_PROP \ int __nWid = (int)m_nWidth; \ int __nHei = (int)m_nHeight #define CHECK_LABEL_PROP_CHANGE \ { \ bool bSame = (__nWid == (int)m_nWidth) && \ (__nHei == (int)m_nHeight) ; \ if (!bSame) InvalidateOldLabel();\ } void CRectHoleDlg::DoDataExchange(CDataExchange* pDX) { KEEP_LABEL_PROP; CInsertOpeningDlg::DoDataExchange(pDX); //{{AFX_DATA_MAP(CRectHoleDlg) DDX_CBString(pDX, IDC_CMB_HOLEDEPTH, m_csHoleDepth); DDX_Check(pDX, IDC_CHK_PASSWALL, m_bIsPassWall); //}}AFX_DATA_MAP CHECK_LABEL_PROP_CHANGE; } BEGIN_MESSAGE_MAP(CRectHoleDlg, CInsertOpeningDlg) //{{AFX_MSG_MAP(CRectHoleDlg) ON_WM_PAINT() ON_WM_SETCURSOR() ON_BN_CLICKED(IDC_HOLE_STYLE, OnHoleStyle) ON_BN_CLICKED(IDC_CHK_PASSWALL, OnClickPassWall)// add by xly on 110216 点击穿透墙体控件 //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CRectHoleDlg message handlers BOOL CRectHoleDlg::OnInitDialog() { CInsertOpeningDlg::OnInitDialog(); m_nHoleStyle; InitComboxes(); ShowHoleStyle(TRUE); // add by xly on 110113 已有洞口插入灰显 m_toolbar.EnableButton(ID_HASHOLE_INSERT, FALSE); // add by xly on 110216 当穿透墙体被选择时,洞深不可用 GetDlgItem(IDC_CMB_HOLEDEPTH)->EnableWindow(!m_bIsPassWall); // add by xly on 110301 增加变量记录是否不穿透,但是厚度大于墙体厚度 m_bIsHasPassWall = false; m_nHasPassWallNums = 0; return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CRectHoleDlg::ShowHoleStyle(BOOL bReLoad) { XString sFile(256); // modify by xly on 110216 8.5需求增加穿透墙体的设置 //sFile << _T("TArch(HoleST") << (m_nHoleStyle+1) << _T(")"); if(m_bIsPassWall) { sFile << _T("TArch(HoleST") << (m_nHoleStyle+1) << _T(")"); } else { sFile << _T("TArch(HoleSU") << (m_nHoleStyle+1) << _T(")"); } //if (FindFile(sFile, sFilePath)) { CWnd *pImageBox=GetDlgItem(IDC_HOLE_STYLE); if (pImageBox) { CDC *pDC=pImageBox->GetDC(); if (bReLoad) { CRect rc; pImageBox->GetClientRect(&rc); m_slideDc.InitDC(pDC, rc, GetAcadBackColor()); m_slideDc.PaintSlide(sFile); } else { m_slideDc.SetDC(pDC); m_slideDc.Redraw(); } m_slideDc.SetDC(NULL); pImageBox->ReleaseDC(pDC); } //} } BOOL CRectHoleDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) { CWnd *pImageBox=GetDlgItem(IDC_HOLE_STYLE); if (pWnd && pImageBox && (pWnd->m_hWnd==pImageBox->m_hWnd)) { CAcModuleResourceOverride vTemp; HCURSOR hIcon = AfxGetApp()->LoadCursor( IDC_CUR_PICK ); SetCursor( hIcon ); return TRUE; } return CInsertOpeningDlg::OnSetCursor(pWnd, nHitTest, message); } void CRectHoleDlg::OnPaint() { CPaintDC dc(this); // device context for painting CRect rcClip, rcImage; dc.GetClipBox(&rcClip); CWnd *pImageBox=GetDlgItem(IDC_HOLE_STYLE); if (pImageBox) { pImageBox->GetWindowRect(&rcImage); ScreenToClient(&rcImage); if (!rcImage.IntersectRect(&rcImage, &rcClip)) return; ShowHoleStyle(FALSE); } // Do not call CDialog::OnPaint() for painting messages } void CRectHoleDlg::OnHoleStyle() { m_nHoleStyle++; if (m_nHoleStyle>3) m_nHoleStyle=0; ShowHoleStyle(TRUE); } void CRectHoleDlg::InitComboxes() { // 宽度系列 2400 CString csItem; // sg modify 101125,根据8.5需求,增加洞宽默认值 // int widthArray[]={1500, 1800, 2100, 2400, 2700, 3000, 3300, 3600}; int widthArray[]={600, 900, 1200, 1500, 1800, 2100, 2400, 2700, 3000, 3300, 3600}; for(int i=0; iGetWidth(4); // 获得洞深 double dHoleDepth = _ttol(m_csHoleDepth); if (dWallWith>dHoleDepth) { // 设置洞深 op.SetThickness(dHoleDepth); } else { // 设置穿透 op.m_nOpStyle &= ~OPS_NOT_BORE; // modify by xly on 110301 修改多一次输出的错误 //acutPrintf(_T("\n注意:墙厚小于洞深,请重新设置参数!")); m_bIsHasPassWall = true; } } OPENOBJ_END(); } if (m_nHoleStyle==0) { op.m_nOpStyle &= ~ OPS_HOLE_FLAG1; op.m_nOpStyle &= ~ OPS_HOLE_FLAG2; op.m_nOpStyle &= ~ OPS_ATHIGH; } else if (m_nHoleStyle==1) { op.m_nOpStyle |= OPS_HOLE_FLAG1; op.m_nOpStyle &= ~OPS_HOLE_FLAG2; op.m_nOpStyle &= ~ OPS_ATHIGH; } else if (m_nHoleStyle==2) { op.m_nOpStyle &= ~OPS_HOLE_FLAG1; op.m_nOpStyle |= OPS_HOLE_FLAG2; op.m_nOpStyle &= ~ OPS_ATHIGH; } else { op.m_nOpStyle |= OPS_HOLE_FLAG1; op.m_nOpStyle |= OPS_HOLE_FLAG2; op.m_nOpStyle |= OPS_ATHIGH; } op.SetLabel(GetAutoLabel(&op)); } // sg add 110906,本函数主要是用来更新子类中特有的属性,比如,矩形洞更新洞口深度数据,子类可重载 int CRectHoleDlg::ModifySpecialProperty(TDbOpening &op) { UpdateData(TRUE); if (m_bIsPassWall)// 穿透墙体 { op.m_nOpStyle &= ~OPS_NOT_BORE; } else { op.m_nOpStyle |= OPS_NOT_BORE; // 获得洞所在墙体的厚度 AcDbObjectId idWall = op.GetWallId(); double dWallWith(0.0); OPENOBJ_BEGIN(idWall, AcDb::kForRead, TDbWall, pWall); if (pWall) { dWallWith = pWall->GetWidth(4); // 获得洞深 double dHoleDepth = _ttol(m_csHoleDepth); if (dWallWith>dHoleDepth) { // 设置洞深 op.SetThickness(dHoleDepth); } else { // 设置穿透 op.m_nOpStyle &= ~OPS_NOT_BORE; m_bIsHasPassWall = true; } } OPENOBJ_END(); } if (m_nHoleStyle==0) { op.m_nOpStyle &= ~ OPS_HOLE_FLAG1; op.m_nOpStyle &= ~ OPS_HOLE_FLAG2; op.m_nOpStyle &= ~ OPS_ATHIGH; } else if (m_nHoleStyle==1) { op.m_nOpStyle |= OPS_HOLE_FLAG1; op.m_nOpStyle &= ~OPS_HOLE_FLAG2; op.m_nOpStyle &= ~ OPS_ATHIGH; } else if (m_nHoleStyle==2) { op.m_nOpStyle &= ~OPS_HOLE_FLAG1; op.m_nOpStyle |= OPS_HOLE_FLAG2; op.m_nOpStyle &= ~ OPS_ATHIGH; } else { op.m_nOpStyle |= OPS_HOLE_FLAG1; op.m_nOpStyle |= OPS_HOLE_FLAG2; op.m_nOpStyle |= OPS_ATHIGH; } return 1; } int CRectHoleDlg::ObjToDlg(TDbOpening* pOpening) { CInsertOpeningDlg::ObjToDlg(pOpening); if (pOpening->m_nOpStyle&OPS_NOT_BORE)// 不穿透 { m_bIsPassWall = FALSE; } else { m_bIsPassWall = TRUE; GetDlgItem(IDC_CMB_HOLEDEPTH)->EnableWindow(FALSE); } double dHoleDepth = pOpening->GetThickness(); CString strTemp; m_csHoleDepth.Format(_T("%.0f"), dHoleDepth); //显示幻灯片 if (!(pOpening->m_nOpStyle&OPS_HOLE_FLAG1) && !(pOpening->m_nOpStyle&OPS_HOLE_FLAG2)) { m_nHoleStyle=0; } else if ((pOpening->m_nOpStyle&OPS_HOLE_FLAG1) && !(pOpening->m_nOpStyle&OPS_HOLE_FLAG2)) { m_nHoleStyle=1; } else if (!(pOpening->m_nOpStyle&OPS_HOLE_FLAG1) && (pOpening->m_nOpStyle&OPS_HOLE_FLAG2)) { m_nHoleStyle=2; } else { m_nHoleStyle=3; } ShowHoleStyle(TRUE); UpdateData(FALSE); return 1; } /////////////////////////////////////////////////////////// // 根据给定的门窗, 设置对话框参数 BOOL CRectHoleDlg::SetDlgParamFrom(const TDbOpening &op) { if (!CInsertOpeningDlg::SetDlgParamFrom(op)) return FALSE; // add by xly on 110216 8.5需求修改矩形洞,增加是否穿透墙体设置 if (op.m_nOpStyle&OPS_NOT_BORE)// 不穿透 { m_bIsPassWall = FALSE; } else { m_bIsPassWall = TRUE; } // if (!this->m_bModeless) { // 此时对话框还没有创建.lgh add. if ((op.m_nOpStyle & OPS_NOT_BORE) != 0) m_csHoleDepth.Format(_T("%d"), (int)(op.GetThickness()+0.5)); } if (!(op.m_nOpStyle&OPS_HOLE_FLAG1) && !(op.m_nOpStyle&OPS_HOLE_FLAG2)) m_nHoleStyle=0; else if ((op.m_nOpStyle&OPS_HOLE_FLAG1) && !(op.m_nOpStyle&OPS_HOLE_FLAG2)) m_nHoleStyle=1; else if (!(op.m_nOpStyle&OPS_HOLE_FLAG1) && (op.m_nOpStyle&OPS_HOLE_FLAG2)) m_nHoleStyle=2; else m_nHoleStyle=3; return TRUE; } // 用对话框上的参数更新实体数据 BOOL CRectHoleDlg::ModifyOpeningWithDlgParam(TDbOpening &op) { if (CInsertOpeningDlg::ModifyOpeningWithDlgParam(op)) { // add by xly on 110216 8.5需求修改矩形洞,增加是否穿透墙体设置 if (m_bModeless)//绘制矩形洞 { if (GetDlgItem(IDC_CHK_HOLEDEPTH)->IsWindowEnabled()) { if (m_bIsPassWall)// 穿透墙体 { op.m_nOpStyle &= ~OPS_NOT_BORE; } else { op.m_nOpStyle |= OPS_NOT_BORE; // 获得洞所在墙体的厚度 AcDbObjectId idWall = op.GetWallId(); double dWallWith(0.0); OPENOBJ_BEGIN(idWall, AcDb::kForRead, TDbWall, pWall); if (pWall) { dWallWith = pWall->GetWidth(4); // 获得洞深 double dHoleDepth = _ttol(m_csHoleDepth); if (dWallWith>dHoleDepth) { // 设置洞深 op.SetThickness(dHoleDepth); } else { // 设置穿透 op.m_nOpStyle &= ~OPS_NOT_BORE; m_nHasPassWallNums++; } } OPENOBJ_END(); } } } else// 编辑矩形洞 { if (m_bIsPassWall)// 穿透墙体 { op.m_nOpStyle &= ~OPS_NOT_BORE; } else { op.m_nOpStyle |= OPS_NOT_BORE; // 获得洞所在墙体的厚度 AcDbObjectId idWall = op.GetWallId(); double dWallWith(0.0); OPENOBJ_BEGIN(idWall, AcDb::kForRead, TDbWall, pWall); if (pWall) { dWallWith = pWall->GetWidth(4); // 获得洞深 double dHoleDepth = _ttol(m_csHoleDepth); if (dWallWith>dHoleDepth) { // 设置洞深 op.SetThickness(dHoleDepth); } else { // 设置穿透 op.m_nOpStyle &= ~OPS_NOT_BORE; } } OPENOBJ_END(); } } if (m_nHoleStyle==0) { op.m_nOpStyle &= ~ OPS_HOLE_FLAG1; op.m_nOpStyle &= ~ OPS_HOLE_FLAG2; op.m_nOpStyle &= ~ OPS_ATHIGH; } else if (m_nHoleStyle==1) { op.m_nOpStyle |= OPS_HOLE_FLAG1; op.m_nOpStyle &= ~OPS_HOLE_FLAG2; op.m_nOpStyle &= ~ OPS_ATHIGH; } else if (m_nHoleStyle==2) { op.m_nOpStyle &= ~OPS_HOLE_FLAG1; op.m_nOpStyle |= OPS_HOLE_FLAG2; op.m_nOpStyle &= ~ OPS_ATHIGH; } else { op.m_nOpStyle |= OPS_HOLE_FLAG1; op.m_nOpStyle |= OPS_HOLE_FLAG2; op.m_nOpStyle |= OPS_ATHIGH; } return TRUE; } return FALSE; } // 从注册表读入参数 BOOL CRectHoleDlg::ReadParamFromRegistry() { if (!CInsertOpeningDlg::ReadParamFromRegistry()) return FALSE; XString sRegSubLoc, sRegLoc(1024); BOOL bOk=GetRegLocation(sRegSubLoc); if (!bOk) return FALSE; sRegLoc << ::GetRegLocation() << _T("\\Settings") ; CRegProperty regProp(sRegLoc, sRegSubLoc); regProp.SetTopRootKey(HKEY_CURRENT_USER); if (!regProp.GetValue(_T("HoleStyle"), m_nHoleStyle)) return FALSE; return TRUE; } // 把最近的参数写入注册表 BOOL CRectHoleDlg::WriteParamToRegistry() const { if (!CInsertOpeningDlg::WriteParamToRegistry()) return FALSE; XString sRegSubLoc, sRegLoc(1024); BOOL bOk=GetRegLocation(sRegSubLoc); if (!bOk) return FALSE; sRegLoc << ::GetRegLocation() << _T("\\Settings") ; CRegProperty regProp(sRegLoc, sRegSubLoc); regProp.SetTopRootKey(HKEY_CURRENT_USER); regProp.SetValue(_T("HoleStyle"), m_nHoleStyle); return TRUE; } // add by xly on 110216 点击穿透墙体控件 void CRectHoleDlg::OnClickPassWall() { UpdateData(TRUE); GetDlgItem(IDC_CMB_HOLEDEPTH)->EnableWindow(!m_bIsPassWall); ShowHoleStyle(TRUE); UpdateData(FALSE); } // add by xly on 110216 8.5需求修改矩形洞,增加洞深 BOOL CRectHoleDlg::InitParamList(DList &lstParam) const { lstParam.Append(new XOpeningParam(IDC_LABEL, _T("编号"))); lstParam.Append(new XOpeningParam(IDC_WIDTH, _T("宽度"))); lstParam.Append(new XOpeningParam(IDC_HEIGHT, _T("高度"))); lstParam.Append(new XOpeningParam(IDC_SILL, _T("底高"))); lstParam.Append(new XOpeningParam(IDC_CHK_HOLEDEPTH, _T("洞深"))); return TRUE; } ////////////////////////////// // Command: 插洞 // 必须在WCS下 void InsHole() { }