// SprinklerByFreeDlg.cpp : implementation file // #include "stdafx.h" #include "AcDbObjectPtr.h" #include "DbPipe.h" #include "DbEquipment.h" #include "layerdef.h" #include "SprinklerByFreeDlg.h" #include "SprinklerByLineDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif //************************************************************************** // 任意喷头 //************************************************************************** extern AcDbObjectId InitLayer(const TCHAR *szLayer, AcDbDatabase *pDb = NULL); void SprinklerByFree() { int nOsMode=0; xg_getvar(_T("OSMODE"), &nOsMode); nOsMode &= ~0x4000; nOsMode |= OS_INT|OS_NEA|OS_CEN|OS_PER; XPushVar vOsMode(_T("OSMODE"), nOsMode); XPoint ptStart, ptEnd; CString csDwb = g_csDwbPath + _T("TwtSys"); XString xsTmp, xsTmp2, xsTmp3, xsTmp4, xsTmp5, xsTmp6, xsTmp7, xsTmp2d, xsTmp3d; XString xsTmp8, xsTmp9, xsTmp10;//zxl 2011.12.19 add 增加水喷雾喷头 const TCHAR *szBlkName = NULL; if(GlobalFunc::LoadDwbBlock(csDwb, _T("00000125"), xsTmp) != RTNORM) return; if(GlobalFunc::LoadDwbBlock(csDwb, _T("00000128"), xsTmp2) != RTNORM) return; if(GlobalFunc::LoadDwbBlock(csDwb, _T("00000131"), xsTmp6) != RTNORM) return; if (GlobalFunc::LoadDwbBlock(csDwb, _T("00000283"), XString()) != RTNORM) // cet 2011.2.28 add 剖切时需要的图块 { return; } if (GlobalFunc::LoadDwbBlock(csDwb, _T("00000529"), xsTmp8) != RTNORM)//zxl 2011.12.19 add 增加水喷雾喷头 { return; } if (GlobalFunc::LoadDwbBlock(csDwb, _T("00000540"), xsTmp9) != RTNORM) // cet 2013.1.5 add 增加直立型水幕 { return; } if (GlobalFunc::LoadDwbBlock(csDwb, _T("00000541"), xsTmp10) != RTNORM) // cet 2013.1.5 add 增加下垂型水幕 { return; } if(g_Option::instance().g_bBlk3D) { if(GlobalFunc::LoadDwbBlock(csDwb, _T("00000365"), xsTmp3) != RTNORM) return; if(GlobalFunc::LoadDwbBlock(csDwb, _T("00000366"), xsTmp4) != RTNORM) return; if(GlobalFunc::LoadDwbBlock(csDwb, _T("00000367"), xsTmp5) != RTNORM) return; if(GlobalFunc::LoadDwbBlock(csDwb, _T("00000417"), xsTmp7) != RTNORM) return; } CString m_csSysBlk1 = _T("TWTSYS(00000283)"); CString m_csSysBlk2 = _T("TWTSYS(00000130)"); CString m_csSysBlk3 = _T("TWTSYS(00000530)");//水喷雾 系统 zxl 2011.12.19 add CSprinklerByFreeDlg dlg(acedGetAcadFrame()); { CTemporaryResourceOverride vTemp; dlg.Create(IDD_SPRINKLER_FREE, acedGetAcadFrame()); dlg.ShowWindow(SW_SHOW); acedGetAcadDwgView()->SetFocus(); } GlobalFunc::InitPipeLayer(LAY_PIPE_SPRINKLE); InitLayer(LAY_EQUIP_SPRINKLE); Entity entLast; if(ads_getpoint(NULL, _T("\n请点取参考点<退出>:"), ptStart) != RTNORM){ dlg.DestroyWindow(); return; } int iPipeType = 0; //上喷 XPointList lstPt; double nDist = 0; double nEle(0); double dLockAng(-1); dlg.UpdateData(); ptStart = GlobalFunc::Ucs2Wcs(ptStart); Entity entLastWell; Entity entEq = GlobalFunc::GetEquipmentByPt(ptStart, int(g_Option::instance().g_nSprinklerRadius), LAY_EQUIP_SPRINKLE); if(!!entEq){ OPENOBJ_BEGIN(entEq, AcDb::kForRead, CDbEquipment, pEquip); if(pEquip){ AcDbObjectId id = pEquip->GetBlock2d(); OPENOBJ_BEGIN(id, AcDb::kForRead, AcDbBlockTableRecord, pRecord); if(pRecord){ pRecord->getName(szBlkName); } OPENOBJ_END(); if(_tcsicmp(xsTmp, szBlkName) == 0 || _tcsicmp(xsTmp2, szBlkName) == 0){ ptStart = pEquip->GetLocation(); nEle = ptStart.z / 1000; if(_tcsicmp(xsTmp, szBlkName) == 0) iPipeType = !pEquip->IsHidePipe(); else if(_tcsicmp(xsTmp2, szBlkName) == 0) iPipeType = 2; int num = pEquip->GetInterfaceNum(); if(pEquip->GetInterfaceNum() == 1){ CPipeInterface face; pEquip->GetInterface(0, face); AcDbObjectId PipeId = face.m_idPipe; OPENOBJ_BEGIN(PipeId, AcDb::kForRead, CDbPipe, pPipeOld); if(pPipeOld){ nDist = pPipeOld->Length(); if(!GlobalFunc::DocGetMeterUnitDraw()) nDist = nDist * 1000; dLockAng = ads_angle(pPipeOld->GetStartPoint(), pPipeOld->GetEndPoint()); dlg.m_bLockAng = TRUE; } OPENOBJ_END(); } } } OPENOBJ_END(); entLastWell = entEq; dlg.m_nPipeEle = nEle; dlg.m_nDist = nDist; dlg.m_iType = iPipeType; if(nDist > 0) dlg.m_iMode = 1; dlg.UpdateData(FALSE); } else{ if(dlg.m_iType == 0){ xsTmp2d = xsTmp; // cet 2010.9.9 modify 二维三维显示不对应 // xsTmp3d = xsTmp3; xsTmp3d = xsTmp4; } else if(dlg.m_iType == 1){ xsTmp2d = xsTmp; // cet 2010.9.9 modify 二维三维显示不对应 // xsTmp3d = xsTmp4; xsTmp3d = xsTmp3; } else if(dlg.m_iType == 2){ xsTmp2d = xsTmp2; xsTmp3d = xsTmp5; } else if(dlg.m_iType == 3){ xsTmp2d = xsTmp6; xsTmp3d = xsTmp7; } else if (dlg.m_iType == 4)//zxl 2011.12.19 add 增加水喷雾喷头 { xsTmp2d = xsTmp8; xsTmp3d = xsTmp3; } else if (dlg.m_iType == 5) // cet 2013.1.5 add 增加直立型水幕 { xsTmp2d = xsTmp9; xsTmp3d = xsTmp4; } else if (dlg.m_iType == 6) // cet 2013.1.5 add 增加下垂型水幕 { xsTmp2d = xsTmp10; xsTmp3d = xsTmp3; } double nElevation(0), nRotate2(0); int iPipeIdx(0); Entity entWire = GlobalFunc::GetPipeByPt(ptStart, nElevation, iPipeIdx); if(!!entWire){ XPoint pt3, pt4; GlobalFunc::GetPipePoint(entWire, pt3, pt4); nRotate2 = ads_angle(pt3, pt4); } ptStart.z = dlg.m_nPipeEle * 1000; CDbEquipment *pEquip = new CDbEquipment; pEquip->SetBlock2d(GlobalFunc::GetBlkIdByName(xsTmp2d)); pEquip->SetSysBlock(m_csSysBlk1); if(dlg.m_iType == 1){ pEquip->SetHidePipe(FALSE);//下喷 pEquip->SetPipeLength(-250); } else if(dlg.m_iType == 3){ pEquip->SetHidePipe(TRUE);//侧喷 pEquip->SetPipeLength(-250); pEquip->SetSysBlock(m_csSysBlk2); } else if (dlg.m_iType == 4)//zxl 2011.12.19 add 增加水喷雾喷头 { pEquip->SetHidePipe(TRUE); pEquip->SetPipeLength(-250); pEquip->SetSysBlock(m_csSysBlk3); } else if (dlg.m_iType == 5) // cet 2013.1.5 add 增加直立型水幕 { pEquip->SetHidePipe(TRUE); pEquip->SetPipeLength(250); pEquip->SetSysBlock(_T("TWTSYS(00000542)")); } else if (dlg.m_iType == 6) // cet 2013.1.5 add 增加下垂型水幕 { pEquip->SetHidePipe(TRUE); pEquip->SetPipeLength(-250); pEquip->SetSysBlock(_T("TWTSYS(00000542)")); } else{ pEquip->SetHidePipe(TRUE); pEquip->SetPipeLength(250); } pEquip->SetBlock3d(GlobalFunc::GetBlkIdByName(xsTmp3d)); pEquip->SetLocation(ptStart); pEquip->SetAngle(nRotate2); pEquip->SetNumber(_T("CIRCLE-1")); pEquip->SetScale(g_Option::instance().g_nSprinklerRadius); pEquip->setLayer(LAY_EQUIP_SPRINKLE); pEquip->setColor(AcCmColor()); //随层 GlobalFunc::AddToCurrentSpace(pEquip, Adesk::kTrue); entLastWell.GetLast(); } lstPt.NewAppend(ptStart); while(1){ dlg.UpdateData(); nDist = dlg.m_nDist; TSprinklerJig jig(&dlg, ptStart); if(dlg.m_bLockAng) jig.m_nLockAng = dLockAng; jig.m_iPipeType = iPipeType; jig.m_nDist = nDist; jig.SetPrompt(_T("\n请输入喷头插入点[回退(U))/选取行向线(F)]<退出>:")); int nKeyIndex; jig.SetKeyword(_T("U F R")); int nRetCode = jig.DoIt(&nKeyIndex); dlg.UpdateData(); if(nRetCode == RTNORM){ ptEnd = jig.GetPickPoint(); SHads_command(RTSTR, _T(".UNDO"), RTSTR, _T("MARK"), RTNONE); // Make a undo mark dlg.UpdateData(); if(dlg.m_iType == 0){ xsTmp2d = xsTmp; // cet 2010.9.9 modify 二维三维显示不对应 // xsTmp3d = xsTmp3; xsTmp3d = xsTmp4; } else if(dlg.m_iType == 1){ xsTmp2d = xsTmp; // cet 2010.9.9 modify 二维三维显示不对应 // xsTmp3d = xsTmp4; xsTmp3d = xsTmp3; } else if(dlg.m_iType == 2){ xsTmp2d = xsTmp2; xsTmp3d = xsTmp5; } else if(dlg.m_iType == 3){ xsTmp2d = xsTmp6; xsTmp3d = xsTmp7; } else if (dlg.m_iType == 4)//zxl 2011.12.19 add 增加水喷雾喷头 { xsTmp2d = xsTmp8; xsTmp3d = xsTmp3; } else if (dlg.m_iType == 5) // cet 2013.1.5 add 增加直立型水幕 { xsTmp2d = xsTmp9; xsTmp3d = xsTmp4; } else if (dlg.m_iType == 6) // cet 2013.1.5 add 增加下垂型水幕 { xsTmp2d = xsTmp10; xsTmp3d = xsTmp3; } ptEnd.z = dlg.m_nPipeEle * 1000; CDbEquipment *pEquip = new CDbEquipment; pEquip->SetBlock2d(GlobalFunc::GetBlkIdByName(xsTmp2d)); pEquip->SetSysBlock(m_csSysBlk1); if(dlg.m_iType == 1){ pEquip->SetHidePipe(FALSE);//下喷 pEquip->SetPipeLength(-250); } else if(dlg.m_iType == 3){ pEquip->SetHidePipe(TRUE);//侧喷 pEquip->SetPipeLength(-250); pEquip->SetSysBlock(m_csSysBlk2); } else if (dlg.m_iType == 4)//zxl 2011.12.19 add 增加水喷雾喷头 { pEquip->SetHidePipe(TRUE); pEquip->SetPipeLength(-250); pEquip->SetSysBlock(m_csSysBlk3); } else if (dlg.m_iType == 5) // cet 2013.1.5 add 增加直立型水幕 { pEquip->SetHidePipe(TRUE); pEquip->SetPipeLength(250); pEquip->SetSysBlock(_T("TWTSYS(00000542)")); } else if (dlg.m_iType == 6) // cet 2013.1.5 add 增加下垂型水幕 { pEquip->SetHidePipe(TRUE); pEquip->SetPipeLength(-250); pEquip->SetSysBlock(_T("TWTSYS(00000542)")); } else{ pEquip->SetHidePipe(TRUE); pEquip->SetPipeLength(250); } double nAng = ads_angle(ptStart, ptEnd); if(!!entLastWell){ OPENOBJ_BEGIN(entLastWell, AcDb::kForWrite, CDbEquipment, pEquip2); if(pEquip2){ pEquip2->SetAngle(nAng); } OPENOBJ_END(); } pEquip->SetBlock3d(GlobalFunc::GetBlkIdByName(xsTmp3d)); pEquip->SetLocation(ptEnd); pEquip->SetAngle(nAng); pEquip->SetNumber(_T("CIRCLE-1")); pEquip->SetScale(g_Option::instance().g_nSprinklerRadius); pEquip->setLayer(LAY_EQUIP_SPRINKLE); pEquip->setColor(AcCmColor()); //随层 GlobalFunc::AddToCurrentSpace(pEquip, Adesk::kTrue); entLastWell.GetLast(); if(dlg.m_bDrawCir){ Entity entLast; entLast.GetLast(); GlobalFunc::WriteXdata(entLast, _T("HYDRANT_RADIUS"), dlg.m_csRadius); } if(dlg.m_bLinkPipe && (lstPt.Length() > 0 || !!entEq) ){ CDbPipe *pPipe = new CDbPipe; ptStart.z = dlg.m_nPipeEle * 1000; ptEnd.z = dlg.m_nPipeEle * 1000; pPipe->SetStartPoint(ptStart); pPipe->SetEndPoint(ptEnd); pPipe->setLayer(LAY_PIPE_SPRINKLE); pPipe->setLinetype(GlobalFunc::GetPipeWireLayLineType(LAY_PIPE_SPRINKLE)); pPipe->SetPipeWeight(g_Option::instance().g_nPipeWidth[8]); pPipe->SetDnDiameter(g_Option::instance().g_iDefaultPipeDn); pPipe->SetModelType(TPipeSys::kModel); pPipe->SetSysType(TPipeSys::kSprinkle); pPipe->SetRadius(g_Option::instance().g_nPipeRadius[8]); pPipe->setColor(AcCmColor()); //随层 GlobalFunc::AddToCurrentSpace(pPipe, Adesk::kTrue); } dLockAng = ads_angle(ptStart, ptEnd); ptStart = ptEnd; lstPt.NewAppend(ptStart); continue; } else if(nRetCode == RTKWORD){ if(nKeyIndex == 0){ int len = lstPt.Length(); if(len == 1) continue; //最后一个, 不能再退了 SHads_command(RTSTR, _T("UNDO"), RTSTR, _T("BACK"), RTNONE); lstPt.Remove(len - 1); XPoint ptTemp = *lstPt[len - 2]; jig.SetStartPoint(ptTemp); ptStart = ptTemp; } else if(nKeyIndex == 1){ double s_angle(0); int err_value=GlobalFunc::get_line_angle(s_angle); if(err_value == RTNORM){ dLockAng = s_angle; dlg.m_bLockAng = TRUE; dlg.UpdateData(FALSE); } } continue; } else{ break; } } SHads_command(RTNONE); dlg.DestroyWindow(); return; } ///////////////////////////////////////////////////////////////////////////// // CSprinklerByFreeDlg dialog int CSprinklerByFreeDlg::m_iType = 1; double CSprinklerByFreeDlg::m_nPipeEle = 0; BOOL CSprinklerByFreeDlg::m_bLinkPipe = TRUE; double CSprinklerByFreeDlg::m_nDist = 0; int CSprinklerByFreeDlg::m_iMode = 0; IMPLEMENT_DYNAMIC(CSprinklerByFreeDlg, CDialog) CSprinklerByFreeDlg::CSprinklerByFreeDlg(CWnd* pParent /*=NULL*/) : CDialog(CSprinklerByFreeDlg::IDD, pParent) { //{{AFX_DATA_INIT(CSprinklerByFreeDlg) m_bDrawCir = TRUE; m_csRadius = _T("2.12"); m_bLockAng = FALSE; //}}AFX_DATA_INIT } void CSprinklerByFreeDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CSprinklerByFreeDlg) DDX_Control(pDX, IDC_EDIT_DIST, m_editDist); DDX_Control(pDX, IDC_EDIT_ELE, m_editEle); DDX_Check(pDX, IDC_CHECK_DRAW, m_bDrawCir); DDX_CBString(pDX, IDC_COMBO_RADIUS, m_csRadius); DDX_Check(pDX, IDC_CHECK_LOCKANG, m_bLockAng); DDX_Check(pDX, IDC_CHECK_LINK, m_bLinkPipe); DDX_Radio(pDX, IDC_RADIO_POS1, m_iType); DDX_Text(pDX, IDC_EDIT_ELE, m_nPipeEle); DDX_Radio(pDX, IDC_RADIO_MODE1, m_iMode); DDX_Text(pDX, IDC_EDIT_DIST, m_nDist); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CSprinklerByFreeDlg, CDialog) //{{AFX_MSG_MAP(CSprinklerByFreeDlg) ON_WM_CLOSE() ON_BN_CLICKED(IDC_CHECK_LINK, OnCheckLink) ON_BN_CLICKED(IDC_RADIO_MODE1, OnRadioMode1) ON_BN_CLICKED(IDC_RADIO_MODE2, OnRadioMode2) ON_EN_KILLFOCUS(IDC_EDIT_DIST, OnKillfocusEditDist) ON_BN_CLICKED(IDC_CHECK_DRAW, OnCheckDraw) ON_BN_CLICKED(IDC_CHECK_LOCKANG, OnCheckLockang) ON_EN_KILLFOCUS(IDC_EDIT_ELE, OnKillfocusEditEle) ON_CBN_KILLFOCUS(IDC_COMBO_RADIUS, OnKillfocusComboRadius) ON_MESSAGE(WM_ACAD_KEEPFOCUS, onAcadKeepFocus) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CSprinklerByFreeDlg message handlers LONG_PTR CSprinklerByFreeDlg::onAcadKeepFocus(UINT_PTR, LONG_PTR) { POINT pt; ::GetCursorPos(&pt); CRect rect; GetWindowRect(&rect); if (!(rect.PtInRect(pt))) { return FALSE; } return TRUE; } void CSprinklerByFreeDlg::OnClose() { CDialog::OnClose(); acedPostCommand(_T("\33\33")); } void CSprinklerByFreeDlg::OnCheckLink() { UpdateData(); // CWnd *pWnd = GetDlgItem(IDC_EDIT_ELE); // if(m_bLinkPipe) // pWnd->EnableWindow(TRUE); // else // pWnd->EnableWindow(FALSE); } void CSprinklerByFreeDlg::OnRadioMode1() { UpdateData(); m_iMode = 0; CWnd *pWnd = GetDlgItem(IDC_EDIT_DIST); pWnd->EnableWindow(FALSE); m_nDist = 0; UpdateData(FALSE); GlobalFunc::PostCommand(_T("R "), false); } void CSprinklerByFreeDlg::OnRadioMode2() { UpdateData(); CWnd *pWnd = GetDlgItem(IDC_EDIT_DIST); pWnd->EnableWindow(TRUE); m_nDist = 3000; UpdateData(FALSE); GlobalFunc::PostCommand(_T("R "), false); } void CSprinklerByFreeDlg::OnKillfocusEditDist() { GlobalFunc::PostCommand(_T("R "), false); double dData = m_nDist; CString sText; m_editDist.GetWindowText(sText); m_nDist = _tstof(sText); if (m_nDist <= 0) { m_nDist = dData; UpdateData(FALSE); acedGetAcadDwgView()->SetFocus(); m_editDist.SetFocus(); m_editDist.SetSel(0, -1); } } BOOL CSprinklerByFreeDlg::OnInitDialog() { CDialog::OnInitDialog(); m_editEle.SetDataType(CRealEdit::eReal); m_editDist.SetDataType(CRealEdit::eReal); CWnd *pWnd = GetDlgItem(IDC_EDIT_DIST); if(m_iMode == 0) pWnd->EnableWindow(FALSE); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CSprinklerByFreeDlg::OnCheckDraw() { UpdateData(); CWnd *pWnd1 = GetDlgItem(IDC_COMBO_RADIUS); pWnd1->EnableWindow(m_bDrawCir); } void CSprinklerByFreeDlg::OnCheckLockang() { GlobalFunc::PostCommand(_T("R "), false); } void CSprinklerByFreeDlg::OnKillfocusEditEle() { double dData = m_nPipeEle; CString sText; m_editEle.GetWindowText(sText); m_nPipeEle = _tstof(sText); if (sText.IsEmpty() || !GlobalFunc::IsStrAllNum(sText)) { m_nPipeEle = dData; UpdateData(FALSE); acedGetAcadDwgView()->SetFocus(); m_editEle.SetFocus(); m_editEle.SetSel(0, -1); } } void CSprinklerByFreeDlg::OnKillfocusComboRadius() { CString csData = m_csRadius; CEdit *pWnd = (CEdit *)GetDlgItem(IDC_COMBO_RADIUS); if (pWnd == NULL) { return; } CString sText; pWnd->GetWindowText(sText); double dNewData = _tstof(sText); if (dNewData <= 0 || !GlobalFunc::IsStrAllNum(sText)) { m_csRadius = csData; UpdateData(FALSE); acedGetAcadDwgView()->SetFocus(); pWnd->SetFocus(); pWnd->SetSel(0, -1); } }