2069 lines
58 KiB
C++
2069 lines
58 KiB
C++
// HydrantPlanDlg.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "DbEquipment.h"
|
|
#include "XBlock.h"
|
|
|
|
#include "HydrantPlanDlg.h"
|
|
#include "SelectBlkDlg.h"
|
|
#include "ProtectRadiusDlg.h"
|
|
#include "DbFireExtinguisher.h"
|
|
#include "AcDbObjectPtr.h"
|
|
#include "globalfunc.h"
|
|
#include "PickEntSet.h"
|
|
#include "RBGroups.h"
|
|
#include "layerdef.h"
|
|
#include "TRegProperty.h"
|
|
#include "DbfTools.h"
|
|
#include "TBlockEdJig.h"
|
|
#include "ADSGePointDir2d.h"
|
|
#include "DbPipe.h"
|
|
#include "GeCurveInline.h"
|
|
#include "AecDbDimension.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
//#ifdef _WIN64
|
|
#include"TGAs.h"
|
|
//#endif
|
|
|
|
extern AcDbObjectId InitDimStyle(TDimStyle ds);
|
|
extern CString GetLayerNames(const TCHAR * szTgSubName);
|
|
extern AcDbObjectId InitLayer(const TCHAR *szLayer, AcDbDatabase *pDb = NULL);
|
|
|
|
namespace
|
|
{
|
|
CString BlockName2SldName(const TCHAR *szBlkName)
|
|
{
|
|
CString csTk, csRecord, csRet;
|
|
GlobalFunc::SplitBlkStr(szBlkName, csTk, csRecord);
|
|
csRet.Format(_T("%s(%s)"), csTk, csRecord);
|
|
return csRet;
|
|
}
|
|
}
|
|
|
|
//***************************************************************************************************
|
|
// 保护半径
|
|
//***************************************************************************************************
|
|
|
|
//void UnionPoly(DList<XPoly2D> &lstPolyThis)
|
|
//{
|
|
// if(lstPolyThis.Length() >1){
|
|
// XPoly2D poly1 = *lstPolyThis[0];
|
|
// DList<XPoly2D> lstPolyThis3;
|
|
// lstPolyThis3.Append(new XPoly2D(poly1));
|
|
// DList<XPoly2D> lstPolyThis4;
|
|
// for(int nn=1;nn<lstPolyThis.Length();nn++){
|
|
// XPoly2D poly5 = *lstPolyThis[nn];
|
|
// lstPolyThis4.Append(new XPoly2D(poly5));
|
|
// }
|
|
// lstPolyThis.Reset();
|
|
// GlobalFunc::Union(lstPolyThis3, lstPolyThis4, lstPolyThis);
|
|
// }
|
|
//}
|
|
|
|
//pLine线选择范围内的设备 zxl 2011.10.18 add
|
|
static void GetEquipmentFromPline(PickSet &ss, const resbuf* rbMask = NULL)
|
|
{
|
|
Entity entPoly;
|
|
RBList rbMask2(RTDXF0, _T("LWPOLYLINE"), 8, _T("*"), NULL);
|
|
if (GlobalFunc::SelectEntity(_T("\n请选择闭合PLINE:<退出>"), entPoly, rbMask2) == RTNORM)
|
|
{
|
|
XPoly2D poly(entPoly);
|
|
poly.TransUCS(RBGroups(0), RBGroups(1));
|
|
|
|
RBList rbFence = poly.Fence();
|
|
|
|
XPoint ptLow, ptUp;
|
|
poly.GetExtend(ptLow, ptUp);
|
|
GlobalFunc::AssureInCurrentView(GlobalFunc::Ucs2Wcs(ptLow), GlobalFunc::Ucs2Wcs(ptUp));
|
|
|
|
ss.Get(_T("CP"), rbFence, NULL, rbMask);
|
|
|
|
CString sNot;
|
|
sNot.Format(_T("\n共得到%d个设备"),ss.Length());
|
|
acutPrintf(sNot);
|
|
}
|
|
}
|
|
|
|
void ShowProtectRadius()
|
|
{
|
|
RBList rbMask = ads_buildlist( -4, _T("<or"),
|
|
-4, _T("<and"), RTDXF0, _T("AEC_ZT_EQUIPMENT"), 8, LAY_EQUIP_SPRINKLE, -4, _T("and>"),
|
|
-4, _T("<and"), RTDXF0, _T("AEC_ZT_EQUIPMENT"), 8, LAY_EQUIP_HYDRANT, -4, _T("and>"),
|
|
-4, _T("<and"), RTDXF0, _T("AEC_ZT_EQUIPMENT"), 8, LAY_EQ_FIRE, -4, _T("and>"), //支持消防附件 zxl 2011.10.20 add
|
|
-4, _T("<and"), RTDXF0, _T("AEC_ZT_EQUIPMENT"), 8, LAY_TWT_EXTINGUISHER, -4, _T("and>"), // 支持灭火器 cet 2013.4.22 add
|
|
-4, _T("or>"), NULL);
|
|
|
|
PickSet ss(SS_FREE), ssDel(SS_FREE), ssFire(SS_FREE), ssHydrant(SS_FREE), ssSprinkle(SS_FREE);
|
|
TCHAR cRet;
|
|
int ret(0);
|
|
while (true)//添加循环,控制用户交互 zxl 2011.10.20 add
|
|
{
|
|
INITGET_BEG(0, _T("P R"));
|
|
ret = GlobalFunc::SelectEntities(_T("\n请选择要显示的消火栓、灭火器或喷头范围{选取闭合PLINE(P)/修改保护半径(R)}:<整张图>"), ss, rbMask, _T("P R"), cRet);
|
|
INITGET_END();
|
|
|
|
// zxl 2011.12.01 modify
|
|
// INITGET_BEG(0, _T("P R S"));
|
|
// ret = GlobalFunc::SelectEntities(_T("\n请选择要显示的消火栓或灭火器[选取闭合PLINE(P)/修改保护半径(R)/显示喷头保护半径(S)]:<整张图>"), ss, rbMask, _T("P R S"), cRet);
|
|
// INITGET_END();
|
|
|
|
// if(ret == RTKWORD){
|
|
// if(cRet == _T('R')){
|
|
// PickSet ssSel(SS_FREE);
|
|
// if(GlobalFunc::SelectEntities(_T("\n请选择要修改的消防设备<退出>:"), ssSel, rbMask) != RTNORM)
|
|
// return;
|
|
// double nNew(0);
|
|
// ads_getreal(_T("\n请输入新的保护半径(m)<退出>"), &nNew);
|
|
// if(nNew <0.001)
|
|
// return;
|
|
// long len = ssSel.Length();
|
|
// for(long j=0;j<len;j++){
|
|
// Entity entTmp = ssSel[j];
|
|
// GlobalFunc::WriteXdata(entTmp, _T("HYDRANT_RADIUS"), XString(_T("%.2f"), nNew));
|
|
// }
|
|
// return;
|
|
// }
|
|
// else if(cRet == _T('S'))
|
|
// {
|
|
// RBList rbMask2 = ads_buildlist( -4, _T("<or"),
|
|
// -4, _T("<and"), RTDXF0, _T("AEC_ZT_EQUIPMENT"), 8, LAY_EQ_FIRE, -4, _T("and>"), //添加消防附件 zxl 2011.10.18 add
|
|
// -4, _T("<and"), RTDXF0, _T("AEC_ZT_EQUIPMENT"), 8, LAY_EQUIP_SPRINKLE, -4, _T("and>"),
|
|
// -4, _T("<and"), RTDXF0, _T("AEC_ZT_EQUIPMENT"), 8, LAY_EQUIP_HYDRANT, -4, _T("and>"),
|
|
// -4, _T("or>"), NULL);
|
|
// // if(GlobalFunc::SelectEntities(_T("\n请选择要显示的消火栓或灭火器或喷头:<退出>"), ss, rbMask2) != RTNORM)
|
|
// // return;
|
|
//
|
|
// //增加pline线选取功能 zxl 2011.10.18 modify
|
|
// TCHAR cRets;
|
|
// int nRet(0);
|
|
// INITGET_BEG(0, _T("P"));
|
|
// nRet = GlobalFunc::SelectEntities(_T("\n请选择要显示的消火栓或灭火器或喷头[闭合PLINE选取(P)]:<退出>"), ss, rbMask2, _T("P"), cRets);
|
|
// INITGET_END();
|
|
// if (cRets == _T('P'))
|
|
// {
|
|
// GetEquipmentFromPline(ss, rbMask2);
|
|
// }
|
|
// else if (nRet != RTNORM)
|
|
// {
|
|
// return;
|
|
// }
|
|
// }
|
|
// else // zxl 2011.10.18 add
|
|
// {
|
|
// GetEquipmentFromPline(ss, rbMask);
|
|
// }
|
|
// }
|
|
|
|
if (ret == RTKWORD)
|
|
{
|
|
if (cRet == _T('P'))
|
|
{
|
|
GetEquipmentFromPline(ss, rbMask);
|
|
}
|
|
else if (cRet == _T('R'))
|
|
{
|
|
PickSet ssSel(SS_FREE);
|
|
if(GlobalFunc::SelectEntities(_T("\n请选择要修改的消防设备<退出>:"), ssSel, rbMask) != RTNORM)
|
|
return;
|
|
double nNew(0);
|
|
ads_getreal(_T("\n请输入新的保护半径(m)<退出>"), &nNew);
|
|
if(nNew <0.001)
|
|
return;
|
|
long len = ssSel.Length();
|
|
for(long j=0;j<len;j++)
|
|
{
|
|
Entity entTmp = ssSel[j];
|
|
GlobalFunc::WriteXdata(entTmp, _T("HYDRANT_RADIUS"), XString(_T("%.2f"), nNew));
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
else if (ret == RTCAN)//zxl 2011.11.30 add 支持ESC退出
|
|
{
|
|
return;
|
|
}
|
|
else if(ret != RTNORM)
|
|
{
|
|
ss.Get(_T("X"), NULL, NULL, rbMask);
|
|
break;
|
|
}
|
|
if (ss.Length() > 0)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
// cet 2012.6.4 add 断管符号
|
|
AcDbObjectId id = GlobalFunc::GetBlockIdFromString(_T("$TwtSys$00000132"));
|
|
//zxl 2011.12.01 modify 单独显示消火栓、灭火器、喷头的保护半径
|
|
for (long l = 0; l < ss.Length(); l++)
|
|
{
|
|
Entity entTmp = ss[l];
|
|
XPoint ptEqLoc;
|
|
OPENOBJ_BEGIN(entTmp, AcDb::kForRead, CDbEquipment, pEquip);
|
|
if(pEquip)
|
|
{
|
|
// cet 2012.6.4 add 断管符号除外
|
|
if (id == pEquip->GetBlock2d())
|
|
{
|
|
continue;
|
|
}
|
|
|
|
CString sLayer = pEquip->layer();
|
|
if (sLayer.Compare(LAY_EQUIP_SPRINKLE) == 0)
|
|
{
|
|
ssSprinkle += entTmp;
|
|
}
|
|
else if (sLayer.Compare(LAY_EQUIP_HYDRANT) == 0)
|
|
{
|
|
ssHydrant += entTmp;
|
|
}
|
|
else if (sLayer.Compare(LAY_TWT_EXTINGUISHER) == 0)
|
|
{
|
|
ssFire += entTmp;
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
// 支持灭火器 cet 2013.4.22 add
|
|
if (entTmp.Is(_T("INSERT")))
|
|
{
|
|
ssFire += entTmp;
|
|
}
|
|
}
|
|
|
|
CProtectRadiusDlg dlg;
|
|
dlg.Create(IDD_PROTECT_RADIUS);
|
|
int iIndex = 0;
|
|
int nType = 0;
|
|
double dUint(1);
|
|
if(!GlobalFunc::DocGetMeterUnitDraw())
|
|
dUint = 1000;
|
|
g_Option::instance().adsout << _T("红色是喷淋保护范围,白色是消火栓或灭火器保护范围!");
|
|
while(true)
|
|
{
|
|
PickSet ssSel(SS_FREE);
|
|
if (iIndex > 0)//初次进入循环顺序显示保护半径
|
|
{
|
|
PickSet ss;
|
|
dlg.m_bModify = false;
|
|
dlg.UpdateData(TRUE);
|
|
ret = GlobalFunc::SelectEntities(_T(""),ss, rbMask);
|
|
nType = dlg.m_nShowType;
|
|
|
|
if (ret == RTERROR && dlg.m_bModify)
|
|
{
|
|
if (nType == 0)
|
|
{
|
|
ssSel += ssHydrant;
|
|
}
|
|
else if (nType == 1)
|
|
{
|
|
ssSel += ssFire;
|
|
}
|
|
else if (nType == 2)
|
|
{
|
|
ssSel += ssSprinkle;
|
|
}
|
|
else if (nType == 4)
|
|
{
|
|
dlg.ShowWindow(FALSE);
|
|
break;
|
|
}
|
|
else if(nType == 3)
|
|
{
|
|
ssDel.Erase();
|
|
dlg.DestroyWindow();
|
|
PickSet ssSel(SS_FREE);
|
|
if(GlobalFunc::SelectEntities(_T("\n请选择要修改的消防设备<退出>:"), ssSel, rbMask) != RTNORM)
|
|
return;
|
|
double nNew(0);
|
|
ads_getreal(_T("\n请输入新的保护半径(m)<退出>"), &nNew);
|
|
if(nNew < 0.001)
|
|
return;
|
|
long len = ssSel.Length();
|
|
for(long j=0;j<len;j++)
|
|
{
|
|
Entity entTmp = ssSel[j];
|
|
GlobalFunc::WriteXdata(entTmp, _T("HYDRANT_RADIUS"), XString(_T("%.2f"), nNew));
|
|
OPENOBJ_BEGIN(entTmp, AcDb::kForWrite, CDbFireExtinguisher, pFire);
|
|
if(pFire != NULL)
|
|
{
|
|
pFire->SetProtectRadius(nNew);
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
break;
|
|
}
|
|
ssDel.Erase();
|
|
}
|
|
else if (ret != RTNORM)
|
|
{
|
|
ssDel.Erase();
|
|
dlg.DestroyWindow();
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
iIndex++;
|
|
ssSel += ssHydrant;
|
|
dlg.m_nShowType = 0;
|
|
if (ssHydrant.Length() == 0)
|
|
{
|
|
ssSel += ssFire;
|
|
dlg.m_nShowType = 1;
|
|
if (ssFire.Length() == 0)
|
|
{
|
|
ssSel += ssSprinkle;
|
|
dlg.m_nShowType = 2;
|
|
}
|
|
}
|
|
dlg.ShowWindow(TRUE);
|
|
dlg.UpdateData(FALSE);
|
|
nType = dlg.m_nShowType;
|
|
}
|
|
|
|
DList<XPoly2D> lstPoly1;
|
|
int itype = -1;
|
|
long len = ssSel.Length();
|
|
for(long i=0;i<len;i++)
|
|
{
|
|
Entity entTmp = ssSel[i];
|
|
CString csCir = GlobalFunc::ReadXdata(entTmp, _T("HYDRANT_RADIUS"));
|
|
|
|
//设置消防附件保护半径 zxl 2011.10.18 add
|
|
if(csCir == _T(""))
|
|
{
|
|
csCir = _T("12");
|
|
}
|
|
|
|
if(csCir != _T(""))
|
|
{
|
|
XPoint ptEqLoc;
|
|
// cet 2013.4.22 modify 支持灭火器
|
|
// OPENOBJ_BEGIN(entTmp, AcDb::kForRead, CDbEquipment, pEquip);
|
|
// if(pEquip)
|
|
// {
|
|
// ptEqLoc = pEquip->GetLocation();
|
|
// }
|
|
// OPENOBJ_END();
|
|
if (entTmp.Is(_T("AEC_ZT_EQUIPMENT")))
|
|
{
|
|
OPENOBJ_BEGIN(entTmp, AcDb::kForRead, CDbEquipment, pEquip);
|
|
if(pEquip != NULL)
|
|
{
|
|
ptEqLoc = pEquip->GetLocation();
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
// 支持灭火器新实体 zxl 2014.02.10 add
|
|
OPENOBJ_BEGIN(entTmp, AcDb::kForRead, CDbFireExtinguisher, pFire);
|
|
if(pFire != NULL)
|
|
{
|
|
double dRadius = pFire->GetProtectRadius();
|
|
csCir.Format(_T("%.0f"), dRadius);
|
|
double dScale = pFire->GetScale();
|
|
if (pFire->GetScaleType() == 0)
|
|
{
|
|
dScale *= (pFire->GetPScale() / 100);
|
|
}
|
|
AcGeScale3d scale(dScale);
|
|
double dWidth = 0.0, dHeight = 0.0;
|
|
AcGePoint3d ptIns = AcGePoint3d::kOrigin;
|
|
AcDbBlockReference blkRef(ptIns, pFire->GetBlock2d());
|
|
blkRef.setScaleFactors(scale);
|
|
AcDbExtents extent;
|
|
blkRef.getGeomExtents(extent);
|
|
AcGePoint3d ptMin = extent.minPoint();
|
|
AcGePoint3d ptMax = extent.maxPoint();
|
|
dWidth = ptMax.x - ptMin.x;
|
|
dHeight = ptMax.y - ptMin.y;
|
|
|
|
//插入点
|
|
ptIns = pFire->GetLocation();
|
|
AcGePoint3dArray arrPts;
|
|
if (pFire->GetLayType() == 0) // 按数量进行布置并标注规格
|
|
{
|
|
// 图块出入点
|
|
int nMod = pFire->GetNum() % 2;
|
|
if (nMod == 1) // 奇数个灭火器
|
|
{
|
|
arrPts.append(ptIns);
|
|
}
|
|
|
|
int nNum = pFire->GetNum();
|
|
nNum /= 2;
|
|
AcGeVector3d vtDir = AcGeVector3d::kXAxis;
|
|
vtDir.rotateBy(pFire->GetAngle(), AcGeVector3d::kZAxis);
|
|
double dDist = 0.0;
|
|
for (int i = 0; i < nNum; ++i)
|
|
{
|
|
if (i == 0 && nMod == 0)
|
|
{
|
|
dDist += dWidth * 0.5;
|
|
}
|
|
else
|
|
{
|
|
dDist += dWidth;
|
|
}
|
|
arrPts.append(ptIns + vtDir * dDist);
|
|
arrPts.append(ptIns - vtDir * dDist);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
arrPts.append(ptIns);
|
|
}
|
|
|
|
for (int i = 0; i < arrPts.length(); i++)
|
|
{
|
|
XPoint pt = arrPts[i];
|
|
XCircle cir2(pt, _tstof(csCir)*dUint);
|
|
XCurveSegment seg;
|
|
seg = cir2;
|
|
XPoly2D poly;
|
|
seg.AsPoly2D(poly);
|
|
lstPoly1.Append(new XPoly2D(poly));
|
|
cir2.Make();
|
|
Entity entCir2;
|
|
entCir2.GetLast();
|
|
if(GlobalFunc::IsSprinkler(entTmp)){
|
|
entCir2.SetData(62, 1);
|
|
entCir2.Modify();
|
|
}
|
|
ssDel += entCir2;
|
|
}
|
|
continue;
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
else if (entTmp.Is(_T("INSERT")))
|
|
{
|
|
OPENOBJ_BEGIN(entTmp, AcDb::kForRead, AcDbBlockReference, pRef);
|
|
if(pRef != NULL)
|
|
{
|
|
ptEqLoc = pRef->position();
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
else
|
|
{
|
|
continue;
|
|
}
|
|
|
|
XCircle cir2(ptEqLoc, _tstof(csCir)*dUint);
|
|
|
|
XCurveSegment seg;
|
|
seg = cir2;
|
|
XPoly2D poly;
|
|
seg.AsPoly2D(poly);
|
|
lstPoly1.Append(new XPoly2D(poly));
|
|
cir2.Make();
|
|
Entity entCir2;
|
|
entCir2.GetLast();
|
|
if(GlobalFunc::IsSprinkler(entTmp)){
|
|
entCir2.SetData(62, 1);
|
|
entCir2.Modify();
|
|
}
|
|
ssDel += entCir2;
|
|
}
|
|
}
|
|
// zxl 2011.12.02 add 添加进度条
|
|
acedSetStatusBarProgressMeter(_T("计算中..."), 0, lstPoly1.Length() - 1);
|
|
for(int m=0;m<lstPoly1.Length()-1;m++)
|
|
{
|
|
acedSetStatusBarProgressMeterPos( m + 1 );
|
|
XPoly2D rPoly1 = *lstPoly1[m];
|
|
for(int n=1;n<lstPoly1.Length();n++)
|
|
{
|
|
XPoly2D rPoly2 = *lstPoly1[n];
|
|
if(m == n)
|
|
continue;
|
|
DList<XPoly2D> lstPoly2, lstPoly3,lstDest;
|
|
lstPoly2.Append(new XPoly2D(rPoly1));
|
|
lstPoly3.Append(new XPoly2D(rPoly2));
|
|
|
|
/*Intersect(lstPoly3, lstPoly2, lstDest);
|
|
for(int j=0;j<lstDest.Length();j++)
|
|
{
|
|
XPoly2D rPoly = *lstDest[j];
|
|
AcDbHatch *pHatch = GlobalFunc::NewHatchFromPoly2D(rPoly, _T("ANSI31"), dlg.m_dScale * 20 * GlobalFunc::DocGetPScale());
|
|
if(!pHatch)
|
|
continue;
|
|
GlobalFunc::AddToModelSpace(pHatch,Adesk::kTrue);
|
|
Entity entCir2;
|
|
entCir2.GetLast();
|
|
ssDel += entCir2;
|
|
}*/
|
|
}
|
|
}
|
|
acedRestoreStatusBar();
|
|
}
|
|
dlg.DestroyWindow();
|
|
}
|
|
|
|
|
|
BOOL GetBlkRecordMidPt(const TCHAR* szBlkName, double nScale, XPoint &pt, BOOL bMirror, double nInsBlkRotate)
|
|
{
|
|
AcDbBlockReference *pBlkRef = new AcDbBlockReference();
|
|
AcDbBlockTable* pBlockTable = NULL;
|
|
AcDbObjectId recordId = NULL;
|
|
acdbCurDwg()->getBlockTable(pBlockTable, AcDb::kForRead);
|
|
#if ARX > 24
|
|
if(Acad::eOk != pBlockTable->getAt(szBlkName, recordId)){
|
|
#else
|
|
if(Acad::eOk != pBlockTable->getAt(szBlkName, recordId, AcDb::kForRead)){
|
|
#endif
|
|
pBlockTable->close();
|
|
delete pBlkRef;
|
|
return FALSE;
|
|
}
|
|
pBlockTable->close();
|
|
pBlkRef->setBlockTableRecord(recordId);
|
|
pBlkRef->setPosition(pt);
|
|
pBlkRef->setRotation(nInsBlkRotate);
|
|
if(bMirror)
|
|
pBlkRef->setScaleFactors(AcGeScale3d(-nScale, nScale, 1));
|
|
else
|
|
pBlkRef->setScaleFactors(AcGeScale3d(nScale, nScale, 1));
|
|
AcDbExtents extents;
|
|
pBlkRef->getGeomExtents(extents);
|
|
AcGePoint3d pMax = extents.maxPoint();
|
|
AcGePoint3d pMin = extents.minPoint();
|
|
XPoint ptCen;
|
|
ptCen[0] = (pMax[0] + pMin[0]) / 2;
|
|
ptCen[1] = (pMax[1] + pMin[1]) / 2;
|
|
ptCen[2] = 0;
|
|
|
|
AcGeMatrix3d mat;
|
|
mat.setToTranslation(AcGeVector3d(ptCen[0] - pt[0], ptCen[1] - pt[1], 0));
|
|
pt.TransformBy(mat);
|
|
delete pBlkRef;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
//***************************************************************************************************
|
|
// 连消火栓
|
|
//***************************************************************************************************
|
|
|
|
//***************************************************************************************************
|
|
// 替换消火栓 2007-2-28 SR 取消命令
|
|
//***************************************************************************************************
|
|
void ReplaceHydrant()
|
|
{
|
|
RBList rbMask(RTDXF0, _T("AEC_ZT_EQUIPMENT"), 8, LAY_EQUIP_HYDRANT, NULL);
|
|
Entity ent;
|
|
PickSet ss(SS_FREE);
|
|
if(GlobalFunc::SelectEntities(_T("\n请选择需要替换的消火栓<退出>:"), ss, rbMask) != RTNORM)
|
|
return;
|
|
ent = ss[0L];
|
|
XPoint ptLoc;
|
|
CString csBlkName, csSldName;
|
|
OPENOBJ_BEGIN(ent, AcDb::kForRead, CDbEquipment, pEquip);
|
|
if(pEquip){
|
|
ptLoc = pEquip->GetLocation();
|
|
AcDbObjectId id = pEquip->GetBlock2d();
|
|
csBlkName = GlobalFunc::GetBlkNameById(id);
|
|
}
|
|
OPENOBJ_END();
|
|
if(!ptLoc)
|
|
return;
|
|
csSldName = BlockName2SldName(csBlkName);
|
|
CPoint ptDwgView;
|
|
int cvport=0;
|
|
VERIFY(xg_getvar(_T("CVPORT"), &cvport)==RTNORM);
|
|
acedCoordFromWorldToPixel(cvport, ptLoc, ptDwgView);
|
|
acedGetAcadDwgView()->ClientToScreen(&ptDwgView);
|
|
CTemporaryResourceOverride vTemp;
|
|
CSelectBlkDlg dlg;
|
|
dlg.m_csTkName = _T("TWTSYS");
|
|
if(_tcsicmp(csBlkName, _T("$TwtSys$00000383")) == 0 || _tcsicmp(csBlkName, _T("$TwtSys$00000386")) == 0 || _tcsicmp(csBlkName, _T("$ATTACHMENT$00000086")) == 0 || _tcsicmp(csBlkName, _T("$ATTACHMENT$00000087")) == 0)
|
|
dlg.m_csType = _T("消火栓");
|
|
else
|
|
dlg.m_csType = _T("平面消火栓");
|
|
dlg.m_ptBase = ptDwgView;
|
|
dlg.m_staticSlide.m_csCurRecord = csSldName;
|
|
if(dlg.DoModal() == IDOK){
|
|
CString csRet = dlg.m_staticSlide.m_csCurRecord;
|
|
XString xsTKName, xsRocord;
|
|
GlobalFunc::SplitSlbName(csRet, xsTKName, xsRocord);
|
|
XString xsBlk;
|
|
GlobalFunc::LoadDwbBlock(xsTKName, xsRocord, xsBlk);
|
|
AcDbObjectId recordId = GlobalFunc::GetBlkIdByName(xsBlk);
|
|
for(long i=0;i<ss.Length();i++){
|
|
Entity entTmp = ss[i];
|
|
OPENOBJ_BEGIN(entTmp, AcDb::kForWrite, CDbEquipment, pEquip);
|
|
if(pEquip){
|
|
XPoint ptMid = pEquip->GetInsert();
|
|
GetBlkRecordMidPt(xsBlk, pEquip->GetScale(), ptMid, pEquip->IsMirrorByY(), pEquip->GetAngle());
|
|
pEquip->SetBlock2d(recordId);
|
|
pEquip->SetLocation(ptMid);
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
}
|
|
}
|
|
|
|
//***************************************************************************************************
|
|
// 系统消火栓
|
|
//***************************************************************************************************
|
|
|
|
//***************************************************************************************************
|
|
// 编辑雨水斗
|
|
//***************************************************************************************************
|
|
// cet 2010.10.27 add
|
|
|
|
//***************************************************************************************************
|
|
// 翻转消火栓
|
|
//***************************************************************************************************
|
|
void ReversalHydrant()
|
|
{
|
|
RBList rbMask(RTDXF0, _T("AEC_ZT_EQUIPMENT"), 8, LAY_EQUIP_HYDRANT, NULL);
|
|
Entity ent;
|
|
XPushVar<int> vOsMode3(_T("OSMODE"), 0);
|
|
if(GlobalFunc::SelectEntity(_T("\n请选择要翻转的消火栓:<退出>"), ent, rbMask) == RTNORM){
|
|
XPoint ptCen, pt1, pt2;
|
|
ent.GetExtend(pt1, pt2);
|
|
XLine line(pt1, pt2, 1);
|
|
line.MidPoint(ptCen);
|
|
XPoint ptUcs = GlobalFunc::Wcs2Ucs(ptCen);
|
|
SHads_command(RTSTR,_T("_rotate"), RTENAME, (TLong_ptr*)ent, RTSTR, _T(""), RT3DPOINT, &ptUcs, RTREAL, 180.0, RTNONE);
|
|
}
|
|
|
|
}
|
|
|
|
//***************************************************************************************************
|
|
// 编辑消火栓
|
|
//***************************************************************************************************
|
|
int EditHydrant(AcDbObjectId id)
|
|
{
|
|
if(!id)
|
|
return RTERROR;
|
|
CTemporaryResourceOverride vTemp;
|
|
CHydrantPlanDlg dlg(1);
|
|
ads_name ent;
|
|
acdbGetAdsName(ent, id);
|
|
dlg.m_csRadius = GlobalFunc::ReadXdata(ent, _T("HYDRANT_RADIUS"));
|
|
const TCHAR *szBlkName = NULL;
|
|
CString csDwb = g_csDwbPath + _T("TwtSys");
|
|
XString xsTmp6, xsTmp7;
|
|
|
|
OPENOBJ_BEGIN(id, AcDb::kForRead, CDbEquipment, pEquip);
|
|
if(pEquip){
|
|
double nLen = pEquip->GetPipeLength();
|
|
if(nLen > 0)
|
|
dlg.m_iMode = 0;
|
|
else
|
|
dlg.m_iMode = 1;
|
|
OPENOBJ_BEGIN(pEquip->GetBlock2d(), AcDb::kForRead, AcDbBlockTableRecord, pRecord);
|
|
if(pRecord){
|
|
pRecord->getName(szBlkName);
|
|
}
|
|
OPENOBJ_END();
|
|
dlg.m_csInsBlkName = szBlkName;
|
|
XPoint ptLoc = pEquip->GetLocation();
|
|
dlg.m_dEle = ptLoc.z / 1000;
|
|
dlg.SetScale(pEquip->GetScale(), pEquip->GetYScale());
|
|
}
|
|
OPENOBJ_END();
|
|
if(dlg.DoModal() != IDOK)
|
|
return 1;
|
|
|
|
if(g_Option::instance().g_bBlk3D){
|
|
if(GlobalFunc::LoadDwbBlock(csDwb, _T("00000441"), xsTmp6) != RTNORM)
|
|
return 1;
|
|
if(GlobalFunc::LoadDwbBlock(csDwb, _T("00000442"), xsTmp7) != RTNORM)
|
|
return 1;
|
|
}
|
|
|
|
OPENOBJ_BEGIN(id, AcDb::kForWrite, CDbEquipment, pEquip);
|
|
if(pEquip){
|
|
pEquip->SetScale(dlg.m_dScaleX);
|
|
pEquip->SetYScale(dlg.m_dScaleY);
|
|
|
|
pEquip->SetBlock2d(GlobalFunc::GetBlkIdByName(dlg.m_csInsBlkName));
|
|
if(_tcsicmp(dlg.m_csInsBlkName, szBlkName) != 0)
|
|
pEquip->SetSysBlock(dlg.m_csSysBlk);
|
|
XPoint ptLoc = pEquip->GetLocation();
|
|
pEquip->SetAutoScale(dlg.m_bAutoScale);
|
|
ptLoc.z = dlg.m_dEle*1000;
|
|
pEquip->SetLocation(ptLoc);
|
|
if(dlg.m_bMirrorByX){
|
|
pEquip->MirrorByY(!pEquip->IsMirrorByY());
|
|
}
|
|
if(dlg.m_iMode == 0){
|
|
pEquip->SetPipeLength(250);//上
|
|
pEquip->SetBlock3d(GlobalFunc::GetBlockIdFromString(xsTmp6));
|
|
}
|
|
else{
|
|
pEquip->SetPipeLength(0); //平
|
|
pEquip->SetBlock3d(GlobalFunc::GetBlockIdFromString(xsTmp7));
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
GlobalFunc::WriteXdata(ent, _T("HYDRANT_RADIUS"), dlg.m_csRadius);
|
|
if(dlg.m_bMirrorByY){
|
|
Entity entTmp = ent;
|
|
GlobalFunc::DocGetPickFirst().Free();
|
|
GlobalFunc::DocGetPickFirst() += entTmp;
|
|
ReversalHydrant();
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
void EditHydrantCmd()
|
|
{
|
|
GlobalFunc::DocGetPickFirst().Free();
|
|
RBList rbMask(RTDXF0, _T("AEC_ZT_EQUIPMENT"), 8, LAY_EQUIP_HYDRANT, NULL);
|
|
PickSet ss(SS_FREE);
|
|
if(GlobalFunc::SelectEntities(_T("\n请选择要修改的消火栓<退出>"), ss, rbMask) != RTNORM)
|
|
return;
|
|
long len = ss.Length();
|
|
if(len < 1)
|
|
return;
|
|
|
|
CTemporaryResourceOverride vTemp;
|
|
CHydrantPlanDlg dlg(1);
|
|
dlg.m_csInsBlkName = _T("");
|
|
dlg.m_iMode = -1;
|
|
|
|
if(dlg.DoModal() != IDOK)
|
|
return;
|
|
|
|
CString csDwb = g_csDwbPath + _T("TwtSys");
|
|
XString xsTmp6, xsTmp7;
|
|
if(g_Option::instance().g_bBlk3D){
|
|
if(GlobalFunc::LoadDwbBlock(csDwb, _T("00000441"), xsTmp6) != RTNORM)
|
|
return;
|
|
if(GlobalFunc::LoadDwbBlock(csDwb, _T("00000442"), xsTmp7) != RTNORM)
|
|
return;
|
|
}
|
|
XPushVar<int> vOsMode(_T("OSMODE"), 0);
|
|
for(long i=0;i<len;i++){
|
|
Entity entTmp = ss[i];
|
|
|
|
OPENOBJ_BEGIN(entTmp, AcDb::kForWrite, CDbEquipment, pEquip);
|
|
if(pEquip){
|
|
if(dlg.m_dScaleX > 0.1 && dlg.m_dScaleY > 0.1){
|
|
pEquip->SetScale(dlg.m_dScaleX);
|
|
pEquip->SetYScale(dlg.m_dScaleY);
|
|
}
|
|
AcDbObjectId idRec = GlobalFunc::GetBlkIdByName(dlg.m_csInsBlkName);
|
|
if(idRec != NULL){
|
|
pEquip->SetBlock2d(idRec);
|
|
pEquip->SetSysBlock(dlg.m_csSysBlk);
|
|
}
|
|
|
|
pEquip->SetAutoScale(dlg.m_bAutoScale);
|
|
XPoint ptLoc = pEquip->GetLocation();
|
|
ptLoc.z = dlg.m_dEle*1000;
|
|
pEquip->SetLocation(ptLoc);
|
|
if(dlg.m_bMirrorByX){
|
|
pEquip->MirrorByY(!pEquip->IsMirrorByY());
|
|
}
|
|
if(dlg.m_iMode == 0){
|
|
pEquip->SetPipeLength(250);//上
|
|
pEquip->SetBlock3d(GlobalFunc::GetBlockIdFromString(xsTmp6));
|
|
}
|
|
else if(dlg.m_iMode == 1){
|
|
pEquip->SetPipeLength(0); //平
|
|
pEquip->SetBlock3d(GlobalFunc::GetBlockIdFromString(xsTmp7));
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
GlobalFunc::WriteXdata(entTmp, _T("HYDRANT_RADIUS"), dlg.m_csRadius);
|
|
if(dlg.m_bMirrorByY){//黑白翻转
|
|
XPoint ptCen, pt1, pt2;
|
|
entTmp.GetExtend(pt1, pt2);
|
|
XLine line(pt1, pt2, 1);
|
|
line.MidPoint(ptCen);
|
|
ptCen.z = 0;
|
|
XPoint ptUcs = GlobalFunc::Wcs2Ucs(ptCen);
|
|
SHads_command(RTSTR,_T("_rotate"), RTENAME, (TLong_ptr*)entTmp, RTSTR, _T(""), RT3DPOINT, &ptUcs, RTREAL, 180.0, RTNONE);
|
|
}
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
|
|
//***************************************************************************************************
|
|
// 平面消火栓
|
|
//***************************************************************************************************
|
|
|
|
// 两条线相互投影,取共有的长度
|
|
void GetShortCurve(XCurveSegment &curve1, XCurveSegment &curve2)
|
|
{
|
|
XPoint ptS1 = curve1.GetStartPoint();
|
|
XPoint ptS2 = curve2.GetStartPoint();
|
|
XPoint ptE1 = curve1.GetEndPoint();
|
|
XPoint ptE2 = curve2.GetEndPoint();
|
|
|
|
XPoint pt;
|
|
if (curve1.PathDistance(ptS2) < 0.001 && curve2.PathDistance(ptS1) > 0.001)
|
|
{
|
|
curve2.ProjectToMe(ptS1, pt);
|
|
curve2.SetStartPoint(pt);
|
|
}
|
|
else if (curve1.PathDistance(ptS2) > 0.001 && curve2.PathDistance(ptS1) < 0.001)
|
|
{
|
|
curve1.ProjectToMe(ptS2, pt);
|
|
curve1.SetStartPoint(pt);
|
|
}
|
|
|
|
if (curve1.PathDistance(ptE2, 0) > 0.001 && curve2.PathDistance(ptE1, 0) < 0.001)
|
|
{
|
|
curve1.ProjectToMe(ptE2, pt);
|
|
curve1.SetEndPoint(pt);
|
|
}
|
|
else if (curve1.PathDistance(ptE2, 0) < 0.001 && curve2.PathDistance(ptE1, 0) > 0.001)
|
|
{
|
|
curve2.ProjectToMe(ptE1, pt);
|
|
curve2.SetEndPoint(pt);
|
|
}
|
|
}
|
|
|
|
XCurveSegment GetOtherWallSegByPt(XPoint ptPick, Entity entWall, AcGeMatrix3d mat)
|
|
{
|
|
XCurveSegment seg;
|
|
|
|
return seg;
|
|
}
|
|
|
|
bool IsEntInBlk(Entity ent, Entity entBlk)
|
|
{
|
|
AcDbObjectId idEnt;
|
|
acdbGetObjectId(idEnt, ent);
|
|
OPENOBJ_BEGIN(entBlk, AcDb::kForRead, AcDbBlockReference, pEnt);
|
|
if(pEnt != NULL)
|
|
{
|
|
XPoint ptIns;
|
|
AcDbObjectId idRecord = pEnt->blockTableRecord();
|
|
OPENOBJ_BEGIN(idRecord,AcDb::kForRead,AcDbBlockTableRecord,pRec);
|
|
if (pRec != NULL)
|
|
{
|
|
AcDbBlockTableRecordIterator *pIter = NULL;
|
|
pRec->newIterator(pIter);
|
|
|
|
if (pIter != NULL)
|
|
{
|
|
for (pIter->start();!pIter->done();pIter->step())
|
|
{
|
|
AcDbObjectId id;
|
|
pIter->getEntityId(id);
|
|
if (id == idEnt)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
delete pIter;
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
OPENOBJ_END();
|
|
return false;
|
|
}
|
|
|
|
//选取外部参照上1根曲线
|
|
XCurveSegment GetExternalBlockSeg2(Entity &entBlk, XPoint &ptPick, AcGeMatrix3d &mat)
|
|
{
|
|
XBlock myBlock(entBlk);
|
|
if(!myBlock.m_bInitSuccess)
|
|
return XCurveSegment();
|
|
|
|
mat = myBlock.GetMatrix3d();
|
|
XCurveSegment seg;
|
|
XPoint ptResult;
|
|
ads_name ent;
|
|
ads_matrix xformres;
|
|
resbuf* refstkres;
|
|
while (1) {
|
|
refstkres = NULL;
|
|
//直接选择子实体
|
|
int result = acedNEntSelP(_T("\n外部参照!请继续选择外部参照上墙线<退出>: "), ent, ptResult, 0, xformres, &refstkres);
|
|
if (refstkres != NULL)
|
|
acutRelRb(refstkres);
|
|
|
|
if (result == RTNORM) {
|
|
Entity entTemp = ent;
|
|
entBlk = ent;
|
|
ptResult = GlobalFunc::Ucs2Wcs(ptResult);
|
|
if(entTemp.Is(_T("LINE"))){
|
|
ptPick = ptResult;
|
|
XCurveSegment seg2(entTemp);
|
|
AcGePoint3d ptStart = seg2.StartPoint();
|
|
ptStart = ptStart.transformBy(*(AcGeMatrix3d*)xformres);
|
|
AcGePoint3d ptEnd = seg2.EndPoint();
|
|
ptEnd = ptEnd.transformBy(*(AcGeMatrix3d*)xformres);
|
|
XLine line(asDblArray(ptStart), asDblArray(ptEnd), 1);
|
|
seg = line;
|
|
return seg;
|
|
}
|
|
else if(entTemp.Is(_T("LWPOLYLINE"))){// zxl 2014.01.15 add 支持外部参照的PLINE线
|
|
ptPick = ptResult;
|
|
OPENOBJ_BEGIN(entTemp, AcDb::kForRead, AcDbPolyline, pLine);
|
|
if(pLine) {
|
|
ptPick = ptResult;
|
|
double dDist = 0.0;
|
|
for (int i = 0; i < pLine->numVerts(); i++)
|
|
{
|
|
XCurveSegment segNew;
|
|
AcGePoint3d ptStart;
|
|
pLine->getPointAt(i, ptStart);
|
|
ptStart = ptStart.transformBy(*(AcGeMatrix3d*)xformres);
|
|
AcGePoint3d ptEnd;
|
|
pLine->getPointAt(i + 1, ptEnd);
|
|
// zxl 2014.02.10 add
|
|
if (pLine->isClosed() && i == pLine->numVerts() - 1)
|
|
{
|
|
pLine->getPointAt(0, ptEnd);
|
|
}
|
|
ptEnd = ptEnd.transformBy(*(AcGeMatrix3d*)xformres);
|
|
XLine line(asDblArray(ptStart), asDblArray(ptEnd), 1);
|
|
segNew = line;
|
|
double dDistNew = segNew.GetDist2Me(ptPick);
|
|
if (i == 0 || fabs(dDistNew) < fabs(dDist))
|
|
{
|
|
dDist = dDistNew;
|
|
seg = segNew;
|
|
}
|
|
}
|
|
return seg;
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
}
|
|
else
|
|
break;
|
|
}
|
|
return seg;
|
|
}
|
|
|
|
XCurveSegment GetEntitySegByPt(XPoint &ptPick, Entity &entWall, AcGeMatrix3d &mat)
|
|
{
|
|
XCurveSegment seg;
|
|
if(entWall.Is(_T("INSERT")) && GlobalFunc::IsExternalBlock(entWall)){
|
|
seg = GetExternalBlockSeg2(entWall, ptPick, mat);// seg = GetBlkPickSeg(entWall, ptPick);
|
|
seg.ProjectToMe(ptPick, ptPick);
|
|
if(!seg)
|
|
return seg;
|
|
}
|
|
else if(entWall.Is(_T("LWPOLYLINE"))){
|
|
double dAngle;
|
|
seg = GlobalFunc::GetSegByPt(XPoly2D(entWall), ptPick, dAngle);
|
|
}
|
|
else
|
|
seg = XCurveSegment(entWall);
|
|
return seg;
|
|
}
|
|
|
|
bool IsHydrantNear2Seg(Entity &ent, XCurveSegment seg)
|
|
{
|
|
bool bRet = false;
|
|
double dLenMin = 0.0, dLenMax = 0.0, dLenMid = 0.0;
|
|
seg.SetElevation(0.0);
|
|
OPENOBJ_BEGIN(ent, AcDb::kForRead, CDbEquipment, pEquip);
|
|
if(pEquip != NULL)
|
|
{
|
|
AcDbVoidPtrArray entSet;
|
|
pEquip->explode(entSet);
|
|
for(int i=0;i<1;i++)
|
|
{
|
|
AcDbEntity *pEnt = (AcDbEntity *)entSet[i];
|
|
AcDbBlockReference *pBlkRef = NULL;
|
|
if(pBlkRef = AcDbBlockReference::cast(pEnt))
|
|
{
|
|
XPoint ptIns;
|
|
AcGeScale3d scRef;
|
|
AcDbVoidPtrArray entSet2;
|
|
AcDbObjectId idRecord = pBlkRef->blockTableRecord();
|
|
OPENOBJ_BEGIN(idRecord,AcDb::kForRead,AcDbBlockTableRecord,pRec);
|
|
if (pRec != NULL)
|
|
{
|
|
AcDbBlockTableRecordIterator *pIter = NULL;
|
|
pRec->newIterator(pIter);
|
|
|
|
if (pIter != NULL)
|
|
{
|
|
AcDbObjectId idEnt;
|
|
for (pIter->start();!pIter->done();pIter->step())
|
|
{
|
|
pIter->getEntityId(idEnt);
|
|
AcDbEntity *pEnt1 = NULL;
|
|
acdbOpenObject(pEnt1, idEnt, AcDb::kForWrite);
|
|
AcDbBlockReference *pBlkRef1 = NULL;
|
|
if (pBlkRef1 = AcDbBlockReference::cast(pEnt1))
|
|
{
|
|
ptIns = pBlkRef->position();
|
|
scRef = pBlkRef->scaleFactors();
|
|
double dRotat = pBlkRef->rotation();
|
|
|
|
AcDbBlockReference *pBlkRef2 = (AcDbBlockReference *)pBlkRef1->clone();
|
|
pBlkRef2->setScaleFactors(scRef);
|
|
AcGeVector3d vt = ptIns - XPoint();
|
|
AcGeMatrix3d mat;
|
|
mat.setToTranslation(vt);
|
|
pBlkRef2->transformBy(mat);
|
|
pBlkRef2->setRotation(dRotat);
|
|
|
|
pBlkRef2->explode(entSet2);
|
|
if (pBlkRef2 != NULL)
|
|
{
|
|
delete pBlkRef2;
|
|
pBlkRef2 = NULL;
|
|
}
|
|
}
|
|
pEnt1->close();
|
|
}
|
|
delete pIter;
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
int len = entSet2.length();
|
|
if (len == 0)
|
|
{
|
|
pBlkRef->explode(entSet2);
|
|
}
|
|
len = entSet2.length();
|
|
for(int j=0;j<len;j++)
|
|
{
|
|
AcDbEntity *pEnt2 = (AcDbEntity *)entSet2[j];
|
|
AcDbLine *pLine = NULL;
|
|
if(pLine = AcDbLine::cast(pEnt2))
|
|
{
|
|
XPoint pS = pLine->startPoint();
|
|
XPoint pE = pLine->endPoint();
|
|
pS.z = 0;
|
|
pE.z = 0;
|
|
XPoint ptMid;
|
|
Midpoint(pS, pE, ptMid);
|
|
double dLenS = seg.GetDist2Me(pS);
|
|
double dLenE = seg.GetDist2Me(pE);
|
|
double dLenM = seg.GetDist2Me(ptMid);
|
|
if (fabs(seg.GetBulge()) < 0.001 && fabs(dLenE) < 0.001 && fabs(dLenS) < 0.001)
|
|
{
|
|
bRet = true;
|
|
}
|
|
else if (fabs(seg.GetBulge()) > 0.001 && fabs(dLenM) < 0.001)
|
|
{
|
|
bRet = true;
|
|
}
|
|
}
|
|
}
|
|
GlobalFunc::ReleaseEntSet(entSet2);
|
|
}
|
|
|
|
}
|
|
GlobalFunc::ReleaseEntSet(entSet);
|
|
}
|
|
OPENOBJ_END();
|
|
return bRet;
|
|
}
|
|
|
|
XPoint GetNearestEntPt(XPoint ptPick, XCurveSegment seg)
|
|
{
|
|
XPoint ptS = seg.GetStartPoint();
|
|
XPoint ptE = seg.GetEndPoint();
|
|
|
|
RBList rbMask(RTDXF0, _T("AEC_ZT_EQUIPMENT"), 8, LAY_EQUIP_HYDRANT, NULL);
|
|
PickSet ss(SS_FREE);
|
|
XPoint ptUcs = GlobalFunc::Wcs2Ucs(ptPick);
|
|
|
|
// 设置外包框大小
|
|
int nLen = 0.0;
|
|
double dLen1 = ptPick.Distance2d(ptS);
|
|
double dLen2 = ptPick.Distance2d(ptE);
|
|
nLen = dLen1 > dLen2 ? dLen1 : dLen2;
|
|
double dLenMin = dLen1 > dLen2 ? dLen2 : dLen1;
|
|
XPoint ptRet = dLen1 > dLen2 ? ptE : ptS;
|
|
|
|
GlobalFunc::GetPointPickSet(ptUcs, ss, rbMask, nLen);
|
|
for (long i = 0; i < ss.Length(); i++)
|
|
{
|
|
Entity ent = ss[i];
|
|
XPoint pt1;
|
|
OPENOBJ_BEGIN(ent, AcDb::kForRead, CDbEquipment, pEquip);
|
|
if(pEquip)
|
|
{
|
|
pt1 = pEquip->GetLocation();
|
|
seg.ProjectToMe(pt1, pt1);
|
|
if (IsHydrantNear2Seg(ent, seg) && pt1.Distance2d(ptPick) < dLenMin)
|
|
{
|
|
ptRet = pt1;
|
|
dLenMin = pt1.Distance2d(ptPick);
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
return ptRet;
|
|
}
|
|
|
|
void InsPlanHydrant()
|
|
{
|
|
int nOsMode=0;
|
|
xg_getvar(_T("OSMODE"), &nOsMode);
|
|
nOsMode &= ~0x4000;
|
|
nOsMode |= OS_INT|OS_NEA;
|
|
XPushVar<int> vOsMode(_T("OSMODE"), nOsMode);
|
|
CString csDwb = g_csDwbPath + _T("TwtSys");
|
|
XString xsTmp1, xsTmp6, xsTmp7, xsTmp0;
|
|
if(GlobalFunc::LoadDwbBlock(csDwb, _T("00000434"), xsTmp1) != RTNORM)
|
|
return;
|
|
xsTmp0 = xsTmp1;
|
|
|
|
if(g_Option::instance().g_bBlk3D){
|
|
if(GlobalFunc::LoadDwbBlock(csDwb, _T("00000441"), xsTmp6) != RTNORM)
|
|
return;
|
|
if(GlobalFunc::LoadDwbBlock(csDwb, _T("00000442"), xsTmp7) != RTNORM)
|
|
return;
|
|
}
|
|
CHydrantPlanDlg dlg(0, acedGetAcadFrame());
|
|
if(dlg.m_csInsBlkName == _T(""))
|
|
dlg.m_csInsBlkName = xsTmp1;
|
|
else{
|
|
CString csTKName, csRocord;
|
|
GlobalFunc::SplitBlkStr(dlg.m_csInsBlkName, csTKName, csRocord);
|
|
GlobalFunc::LoadDwbBlock(csTKName, csRocord, xsTmp1);
|
|
}
|
|
|
|
|
|
{
|
|
CTemporaryResourceOverride vTemp;
|
|
dlg.Create(IDD_HYDRANT_PLAN, acedGetAcadFrame());
|
|
dlg.ShowWindow(SW_SHOW);
|
|
acedGetAcadDwgView()->SetFocus();
|
|
}
|
|
|
|
|
|
InitLayer(LAY_EQUIP_HYDRANT);
|
|
g_Option::instance().g_nInsBlkRotate = 0;
|
|
|
|
RBList rbMask = ads_buildlist( -4, _T("<or"), RTDXF0, _T("INSERT"), RTDXF0, _T("LWPOLYLINE"), RTDXF0, _T("LINE"), RTDXF0, _T("ARC"), RTDXF0, _T("ATS_WALL"), RTDXF0, _T("ATS_COLUMN"),
|
|
-4, _T("or>"), NULL);
|
|
|
|
PickSet ssAll(SS_FREE);
|
|
RBList rbMask2(RTDXF0, _T("AEC_ZT_EQUIPMENT"), 8, LAY_EQUIP_HYDRANT, NULL);
|
|
ssAll.Get(_T("X"),NULL,NULL, rbMask2);
|
|
PickSet ssDel(SS_FREE);
|
|
std::map<XPoint,double> mapData; // cet 2010.6.23 add
|
|
ssDel.IncludeBegin();
|
|
for(long j=0;j<ssAll.Length();j++)
|
|
{
|
|
Entity entTmp = ssAll[j];
|
|
XPoint ptPick;
|
|
CString csRadius = GlobalFunc::ReadXdata(entTmp, _T("HYDRANT_RADIUS"));
|
|
OPENOBJ_BEGIN(entTmp, AcDb::kForRead, CDbEquipment, pEquip);
|
|
if(pEquip){
|
|
ptPick = pEquip->GetLocation();
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
// cet 2010.6.23 add
|
|
mapData.insert(std::make_pair(ptPick,_tstof(csRadius)*1000));
|
|
if (!dlg.IsShowCircle())
|
|
{
|
|
continue;
|
|
}
|
|
|
|
XCircle cir(ptPick, _tstof(csRadius)*1000);
|
|
cir.Make();
|
|
}
|
|
ssDel.IncludeEnd();
|
|
|
|
|
|
|
|
XPoint ptPick;
|
|
Entity entWall;
|
|
BOOL bFree = TRUE;
|
|
// cet 2010.6.23 del
|
|
// while(GlobalFunc::SelectEntity1(0.3, _T("\n请拾取布置消火栓的外部参照、墙线、柱子、直线、弧线 <退出>"), entWall, ptPick, rbMask) == RTNORM){
|
|
// cet 2010.6.23 add
|
|
PickSet ssNew(SS_FREE); // 保存新插入的保护圆
|
|
// 对话框选择布置方式 郑晓龙2014.01.10 modify
|
|
double dMeter = 1000.0;
|
|
if (GlobalFunc::DocGetMeterUnitDraw())
|
|
{
|
|
dMeter = 1.0;
|
|
}
|
|
bool bRet = false;
|
|
bool bBlk = false;
|
|
while(!bRet)
|
|
{
|
|
dlg.UpdateData(TRUE);
|
|
if (dlg.m_iPlanType == 0)
|
|
{
|
|
int nRet(0);
|
|
if (!bBlk)
|
|
{
|
|
INITGET_BEG(0, _T("R "));
|
|
nRet = GlobalFunc::SelectEntity1(0.3, _T("\n请拾取布置消火栓的外部参照、直线、弧线 <退出>"), entWall, ptPick, rbMask);
|
|
INITGET_END();
|
|
if (nRet != RTNORM && nRet != RTKWORD)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
ssDel.Erase();
|
|
ssDel.Free();
|
|
dlg.UpdateData();
|
|
if (dlg.IsShowCircle())
|
|
{
|
|
std::map<XPoint,double>::iterator it;
|
|
for(it = mapData.begin(); it != mapData.end(); it++)
|
|
{
|
|
XCircle cir((*it).first, (*it).second);
|
|
cir.Make();
|
|
Entity entCir;
|
|
entCir.GetLast();
|
|
ssDel += entCir;
|
|
}
|
|
}
|
|
|
|
if (nRet == RTKWORD)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
ptPick = GlobalFunc::Ucs2Wcs(ptPick);
|
|
bFree = FALSE;
|
|
dlg.UpdateData();
|
|
g_Option::instance().g_csInsBlkName = dlg.m_csInsBlkName;
|
|
|
|
if(entWall.Is(_T("INSERT")) && GlobalFunc::IsExternalBlock(entWall))
|
|
{
|
|
bBlk = true;
|
|
}
|
|
Entity entBlk = entWall;
|
|
|
|
XCurveSegment seg; // 得到点所在的线段
|
|
AcGeMatrix3d mat;
|
|
seg = GetEntitySegByPt(ptPick, entWall, mat);
|
|
if(!seg)
|
|
break;
|
|
entWall = entBlk;
|
|
|
|
g_Option::instance().g_nInsBlkRotate = GlobalFunc::GetInsRotate(ptPick, seg);
|
|
|
|
AcGeVector3d vect;
|
|
vect.x = cos(g_Option::instance().g_nInsBlkRotate);
|
|
vect.y = sin(g_Option::instance().g_nInsBlkRotate);
|
|
vect.z = 0;
|
|
BOOL m_bMirror = FALSE;
|
|
double nScale = 1;
|
|
// if(g_bEquipByScale)
|
|
// nScale = GlobalFunc::DocGetPScale()/100;
|
|
|
|
BOOL bCancel = FALSE;
|
|
double nWidth(0), nHeight(0);
|
|
double dScaleX(0), dScaleY(0);
|
|
|
|
XCircle cir(ptPick, _tstof(dlg.m_csRadius)*1000);
|
|
cir.Make();
|
|
Entity entCir;
|
|
entCir.GetLast();
|
|
// ssDel+= entCir; // cet 2010.6.23 del
|
|
ssNew += entCir; // cet 2010.6.23 add
|
|
|
|
|
|
while(1){
|
|
dlg.UpdateData();
|
|
dlg.GetScale(dScaleX, dScaleY);
|
|
|
|
double dScaleMater = dlg.m_bAutoScale ? GlobalFunc::DocGetPScale() / 100 : 1;
|
|
GlobalFunc::GetBlkRecordWidth(xsTmp0, dScaleX * dScaleMater, dScaleY * dScaleMater, nWidth, nHeight);
|
|
// TBlockEdJig jig(g_Option::instance().g_csInsBlkName, ptPick, 1, vect, nWidth*GlobalFunc::DocGetPScale()/100.0 + dlg.m_iDist);
|
|
TBlockEdJig jig(g_Option::instance().g_csInsBlkName, ptPick, 1, vect, nWidth + dlg.m_iDist);
|
|
jig.m_nSacle = dScaleX * dScaleMater;
|
|
jig.m_nSacleY = dScaleY * dScaleMater;
|
|
// jig.m_nSacle = dScaleX*(GlobalFunc::DocGetPScale()/100.0);
|
|
// jig.m_nSacleY = dScaleY*(GlobalFunc::DocGetPScale()/100.0);
|
|
jig.SetPrompt(_T("\n请指定附件的插入方向<完成>:"));
|
|
int nKeyIndex = 0;
|
|
int nRetCode = jig.DoIt(&nKeyIndex);
|
|
if(nRetCode == RTNORM){
|
|
if(jig.m_iQuadrant == 2 || jig.m_iQuadrant == 3){
|
|
g_Option::instance().g_nInsBlkRotate += PI;
|
|
}
|
|
if(jig.m_iQuadrant == 1 || jig.m_iQuadrant == 3){
|
|
m_bMirror = TRUE;
|
|
}
|
|
ptPick = jig.m_ptRetIns;
|
|
break;
|
|
}
|
|
else{
|
|
bCancel = TRUE;
|
|
ssNew -= entCir; // cet 2010.7.9 add 当前消火栓布置取消时其保护半径应删除
|
|
entCir.Erase(); // cet 2010.7.9 add
|
|
break;
|
|
}
|
|
}
|
|
// entCir.Erase();
|
|
|
|
if(bCancel){
|
|
continue;
|
|
}
|
|
|
|
dlg.UpdateData();
|
|
dlg.GetScale(dScaleX, dScaleY);
|
|
|
|
CDbEquipment *pEquip = new CDbEquipment;
|
|
pEquip->SetBlock2d(GlobalFunc::GetBlkIdByName(g_Option::instance().g_csInsBlkName));
|
|
pEquip->SetInsert(ptPick);
|
|
pEquip->SetHidePipe(TRUE);
|
|
pEquip->SetScale(dScaleX);
|
|
pEquip->SetYScale(dScaleY);
|
|
pEquip->SetAutoScale(dlg.m_bAutoScale);
|
|
pEquip->MirrorByY(m_bMirror);
|
|
double dAngle = g_Option::instance().g_nInsBlkRotate;
|
|
pEquip->SetAngle(dAngle);
|
|
if(dlg.m_iMode == 0){
|
|
pEquip->SetPipeLength(250);//上
|
|
pEquip->SetBlock3d(GlobalFunc::GetBlockIdFromString(xsTmp6));
|
|
}
|
|
else
|
|
pEquip->SetBlock3d(GlobalFunc::GetBlockIdFromString(xsTmp7));
|
|
pEquip->SetSysBlock((const TCHAR*)dlg.m_csSysBlk);
|
|
pEquip->setLayer(LAY_EQUIP_HYDRANT);
|
|
pEquip->setColor(AcCmColor()); //随层
|
|
pEquip->SetLocation(ptPick);
|
|
AcDbObjectId id = GlobalFunc::AddToCurrentSpace(pEquip, Adesk::kTrue);
|
|
Entity entLast;
|
|
entLast.GetLast();
|
|
GlobalFunc::WriteXdata(entLast, _T("HYDRANT_RADIUS"), dlg.m_csRadius);
|
|
}
|
|
else if (dlg.m_iPlanType == 1)
|
|
{
|
|
// if(bFree){ //任意布置
|
|
// PickSet ssAll(SS_FREE);
|
|
// RBList rbMask2(RTDXF0, _T("AEC_ZT_EQUIPMENT"), 8, LAY_EQUIP_HYDRANT, NULL);
|
|
// ssAll.Get(_T("X"),NULL,NULL, rbMask2);
|
|
// PickSet ssDel(SS_FREE);
|
|
// ssDel.IncludeBegin();
|
|
// for(long j=0;j<ssAll.Length();j++)
|
|
// {
|
|
// Entity entTmp = ssAll[j];
|
|
// XPoint ptPick;
|
|
// CString csRadius = GlobalFunc::ReadXdata(entTmp, _T("HYDRANT_RADIUS"));
|
|
// OPENOBJ_BEGIN(entTmp, AcDb::kForRead, CDbEquipment, pEquip);
|
|
// if(pEquip){
|
|
// ptPick = pEquip->GetLocation();
|
|
// }
|
|
// OPENOBJ_END();
|
|
//
|
|
// XCircle cir(ptPick, _tstof(csRadius)*1000);
|
|
// cir.Make();
|
|
// }
|
|
// ssDel.IncludeEnd();
|
|
|
|
XPoint ptIns;
|
|
double nScale = 1;
|
|
InitLayer(LAY_TWT_GULLY);
|
|
xg_getvar(_T("VIEWCTR"), ptIns);
|
|
ptIns = GlobalFunc::Ucs2Wcs(ptIns);
|
|
|
|
BOOL bMirror = FALSE;
|
|
while(1){
|
|
dlg.UpdateData();
|
|
// cet 2010.6.23 add
|
|
ssDel.Erase();
|
|
ssDel.Free();
|
|
if (dlg.IsShowCircle())
|
|
{
|
|
std::map<XPoint,double>::iterator it;
|
|
for(it = mapData.begin(); it != mapData.end(); it++)
|
|
{
|
|
XCircle cir((*it).first, (*it).second);
|
|
cir.Make();
|
|
Entity entCir;
|
|
entCir.GetLast();
|
|
ssDel += entCir;
|
|
}
|
|
}
|
|
|
|
double dScaleX(0), dScaleY(0);
|
|
dlg.GetScale(dScaleX, dScaleY);
|
|
g_Option::instance().g_csInsBlkName = dlg.m_csInsBlkName;
|
|
double dScaleMater = dlg.m_bAutoScale ? GlobalFunc::DocGetPScale() / 100 : 1;
|
|
|
|
//支持预览保护圆 2009-4-2
|
|
TBlockExJig jig(g_Option::instance().g_csInsBlkName, ptIns, dScaleX * dScaleMater, dScaleY * dScaleMater, _tstof(dlg.m_csRadius)*1000);
|
|
// jig.SetRadius(_tstof(dlg.m_csRadius)*1000);
|
|
// jig.m_nSacle = dScaleX;
|
|
// jig.m_nSacleY = dScaleY;
|
|
// jig.m_nSacle = dScaleX*(GlobalFunc::DocGetPScale()/100.0);
|
|
// jig.m_nSacleY = dScaleY*(GlobalFunc::DocGetPScale()/100.0);
|
|
jig.SetPrompt(_T("\n请点取消火栓插入点[90度旋转(A)/左右翻转(F)]:<退出>"));
|
|
jig.SetKeyword(_T("A F R"));
|
|
int nKeyIndex = 0;
|
|
// jig.m_bReversal = bMirror;
|
|
jig.SetReversal(bMirror);
|
|
int ret = jig.DoIt(&nKeyIndex);
|
|
if(ret == RTKWORD){
|
|
if(nKeyIndex == 0)
|
|
g_Option::instance().g_nInsBlkRotate += PI/2;
|
|
else if(nKeyIndex == 1)
|
|
bMirror = !bMirror;
|
|
else
|
|
break;
|
|
continue;
|
|
}
|
|
else if(ret != RTNORM)
|
|
{
|
|
bRet = true;
|
|
break;
|
|
}
|
|
ptIns = jig.GetPickPoint();
|
|
XPoint ptMid = ptIns;
|
|
// GetBlkRecordMidPt(g_Option::instance().g_csInsBlkName, nScale, ptMid, bMirror, g_Option::instance().g_nInsBlkRotate);
|
|
dlg.UpdateData();
|
|
CDbEquipment *pEquip = new CDbEquipment;
|
|
pEquip->SetBlock2d(GlobalFunc::GetBlkIdByName(g_Option::instance().g_csInsBlkName));
|
|
pEquip->SetScale(dScaleX);
|
|
pEquip->SetYScale(dScaleY);
|
|
pEquip->SetAutoScale(dlg.m_bAutoScale);
|
|
|
|
pEquip->SetInsert(ptIns);
|
|
pEquip->SetHidePipe(TRUE);
|
|
pEquip->MirrorByY(bMirror);
|
|
double nAngle = GlobalFunc::Ucs2Wcs(g_Option::instance().g_nInsBlkRotate);
|
|
pEquip->SetAngle(nAngle);
|
|
if(dlg.m_iMode == 0){
|
|
pEquip->SetPipeLength(250);//上
|
|
pEquip->SetBlock3d(GlobalFunc::GetBlockIdFromString(xsTmp6));
|
|
}
|
|
else
|
|
pEquip->SetBlock3d(GlobalFunc::GetBlockIdFromString(xsTmp7));
|
|
|
|
pEquip->SetSysBlock((const TCHAR*)dlg.m_csSysBlk);
|
|
pEquip->setLayer(LAY_EQUIP_HYDRANT);
|
|
pEquip->setColor(AcCmColor()); //随层
|
|
pEquip->SetLocation(ptMid);
|
|
AcDbObjectId id = GlobalFunc::AddToCurrentSpace(pEquip, Adesk::kTrue);
|
|
Entity entLast;
|
|
entLast.GetLast();
|
|
GlobalFunc::WriteXdata(entLast, _T("HYDRANT_RADIUS"), dlg.m_csRadius);
|
|
|
|
XCircle cir(ptIns, _tstof(dlg.m_csRadius)*1000);
|
|
cir.Make();
|
|
Entity entCir;
|
|
entCir.GetLast();
|
|
// ssDel+= entCir; // cet 2010.6.23 del
|
|
ssNew += entCir; // cet 2010.6.23 add
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
int nRet(0);
|
|
if (!bBlk)
|
|
{
|
|
INITGET_BEG(0, _T("R "));
|
|
nRet = GlobalFunc::SelectEntity1(0.3, _T("\n请拾取布置消火栓的外部参照、直线、弧线 <退出>"), entWall, ptPick, rbMask);
|
|
INITGET_END();
|
|
if (nRet != RTNORM && nRet != RTKWORD)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
ssDel.Erase();
|
|
ssDel.Free();
|
|
dlg.UpdateData();
|
|
if (dlg.IsShowCircle())
|
|
{
|
|
std::map<XPoint,double>::iterator it;
|
|
for(it = mapData.begin(); it != mapData.end(); it++)
|
|
{
|
|
XCircle cir((*it).first, (*it).second);
|
|
cir.Make();
|
|
Entity entCir;
|
|
entCir.GetLast();
|
|
ssDel += entCir;
|
|
}
|
|
}
|
|
|
|
if (nRet == RTKWORD)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
ptPick = GlobalFunc::Ucs2Wcs(ptPick);
|
|
bFree = FALSE;
|
|
dlg.UpdateData();
|
|
g_Option::instance().g_csInsBlkName = dlg.m_csInsBlkName;
|
|
|
|
if(entWall.Is(_T("INSERT")) && GlobalFunc::IsExternalBlock(entWall))
|
|
{
|
|
bBlk = true;
|
|
}
|
|
Entity entBlk = entWall;
|
|
|
|
XCurveSegment seg;
|
|
AcGeMatrix3d mat;
|
|
seg = GetEntitySegByPt(ptPick, entWall, mat);
|
|
if(!seg)
|
|
break;
|
|
|
|
XPoint ptRet = GetNearestEntPt(ptPick, seg);
|
|
if (entWall.Is(_T("ATS_WALL")))
|
|
{
|
|
XCurveSegment seg2;
|
|
seg2 = GetOtherWallSegByPt(ptPick, entWall, mat);
|
|
XPoint ptPick2;
|
|
seg2.ProjectToMe(ptPick, ptPick2);
|
|
XPoint ptRet2 = GetNearestEntPt(ptPick2, seg2);
|
|
seg.ProjectToMe(ptRet2, ptRet2);
|
|
if (ads_distance(ptRet2, ptPick) < ads_distance(ptRet, ptPick))
|
|
{
|
|
ptRet = ptRet2;
|
|
}
|
|
}
|
|
entWall = entBlk;
|
|
|
|
double dLenPick = seg.PathDistance(ptPick);
|
|
double dLenRet = seg.PathDistance(ptRet);
|
|
ADSGePointDir2d pt;
|
|
double dBulge = seg.GetBulge();
|
|
double dDst = dlg.m_dByDist * dMeter;
|
|
if (fabs(dBulge) > 0.001)// 弧线时重新计算距离,使两点之间的直线距离为dDst
|
|
{
|
|
XCircle cir = seg.GetCircle();
|
|
double r = cir.GetRadius();
|
|
dDst = 2 * r * asin(dDst/2/r);
|
|
}
|
|
|
|
if (dLenRet == 0.0)
|
|
{
|
|
if (ptRet.Distance2d(seg.GetStartPoint()) < 1)
|
|
{
|
|
seg.Polar(dDst, pt);
|
|
}
|
|
else
|
|
{
|
|
seg.Polar(seg.GetLength() - dDst, pt);
|
|
}
|
|
}
|
|
else if (dLenPick > dLenRet)
|
|
{
|
|
seg.Polar(dLenRet + dDst, pt);
|
|
}
|
|
else
|
|
{
|
|
seg.Polar(dLenRet - dDst, pt);
|
|
}
|
|
ptPick = pt.AsAcGePoint3d();
|
|
double dLenS = seg.PathDistance(ptPick, 1);
|
|
double dLenE = seg.PathDistance(ptPick, 0);
|
|
if (dLenS < 0.0 || dLenE < 0.0)// 布置点不在线上
|
|
{
|
|
continue;
|
|
}
|
|
g_Option::instance().g_nInsBlkRotate = GlobalFunc::GetInsRotate(ptPick, seg);
|
|
|
|
AcGeVector3d vect;
|
|
vect.x = cos(g_Option::instance().g_nInsBlkRotate);
|
|
vect.y = sin(g_Option::instance().g_nInsBlkRotate);
|
|
vect.z = 0;
|
|
BOOL m_bMirror = FALSE;
|
|
double nScale = 1;
|
|
|
|
BOOL bCancel = FALSE;
|
|
double nWidth(0), nHeight(0);
|
|
double dScaleX(0), dScaleY(0);
|
|
XCircle cir(ptPick, _tstof(dlg.m_csRadius)*1000);
|
|
cir.Make();
|
|
Entity entCir;
|
|
entCir.GetLast();
|
|
ssNew += entCir;
|
|
|
|
while(1)
|
|
{
|
|
dlg.UpdateData();
|
|
dlg.GetScale(dScaleX, dScaleY);
|
|
double dScaleMater = dlg.m_bAutoScale ? GlobalFunc::DocGetPScale() / 100 : 1;
|
|
|
|
GlobalFunc::GetBlkRecordWidth(xsTmp0, dScaleX * dScaleMater, dScaleY * dScaleMater, nWidth, nHeight);
|
|
TBlockEdJig jig(g_Option::instance().g_csInsBlkName, ptPick, 1, vect, nWidth + dlg.m_iDist);
|
|
jig.m_nSacle = dScaleX * dScaleMater;
|
|
jig.m_nSacleY = dScaleY* dScaleMater;
|
|
jig.SetPrompt(_T("\n请指定附件的插入方向<完成>:"));
|
|
int nKeyIndex = 0;
|
|
int nRetCode = jig.DoIt(&nKeyIndex);
|
|
if(nRetCode == RTNORM)
|
|
{
|
|
if(jig.m_iQuadrant == 2 || jig.m_iQuadrant == 3){
|
|
g_Option::instance().g_nInsBlkRotate += PI;
|
|
}
|
|
if(jig.m_iQuadrant == 1 || jig.m_iQuadrant == 3){
|
|
m_bMirror = TRUE;
|
|
}
|
|
ptPick = jig.m_ptRetIns;
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
bCancel = TRUE;
|
|
ssNew -= entCir;
|
|
entCir.Erase();
|
|
break;
|
|
}
|
|
}
|
|
|
|
if(bCancel)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
dlg.UpdateData();
|
|
dlg.GetScale(dScaleX, dScaleY);
|
|
|
|
CDbEquipment *pEquip = new CDbEquipment;
|
|
pEquip->SetBlock2d(GlobalFunc::GetBlkIdByName(g_Option::instance().g_csInsBlkName));
|
|
pEquip->SetInsert(ptPick);
|
|
pEquip->SetHidePipe(TRUE);
|
|
pEquip->SetScale(dScaleX);
|
|
pEquip->SetYScale(dScaleY);
|
|
pEquip->SetAutoScale(dlg.m_bAutoScale);
|
|
pEquip->MirrorByY(m_bMirror);
|
|
double dAngle = g_Option::instance().g_nInsBlkRotate;
|
|
pEquip->SetAngle(dAngle);
|
|
if(dlg.m_iMode == 0)
|
|
{
|
|
pEquip->SetPipeLength(250);
|
|
pEquip->SetBlock3d(GlobalFunc::GetBlockIdFromString(xsTmp6));
|
|
}
|
|
else
|
|
pEquip->SetBlock3d(GlobalFunc::GetBlockIdFromString(xsTmp7));
|
|
pEquip->SetSysBlock((const TCHAR*)dlg.m_csSysBlk);
|
|
pEquip->setLayer(LAY_EQUIP_HYDRANT);
|
|
pEquip->setColor(AcCmColor());
|
|
pEquip->SetLocation(ptPick);
|
|
AcDbObjectId id = GlobalFunc::AddToCurrentSpace(pEquip, Adesk::kTrue);
|
|
Entity entLast;
|
|
entLast.GetLast();
|
|
GlobalFunc::WriteXdata(entLast, _T("HYDRANT_RADIUS"), dlg.m_csRadius);
|
|
}
|
|
}
|
|
ssDel.Erase();
|
|
ssNew.Erase(); // cet2010.6.23 add
|
|
g_Option::instance().g_nInsBlkRotate = 0;
|
|
dlg.DestroyWindow();
|
|
}
|
|
|
|
IMPLEMENT_DYNAMIC(CHydrantPlanDlg, CDialog)
|
|
|
|
BOOL CHydrantPlanDlg::m_bWndChkRadius = FALSE;
|
|
int CHydrantPlanDlg::m_iMode = 0;
|
|
CString CHydrantPlanDlg::m_csOldDim = _T("700*200");
|
|
CString CHydrantPlanDlg::m_csInsBlkName = _T("");
|
|
CString CHydrantPlanDlg::m_csSysBlk = _T("");
|
|
BOOL CHydrantPlanDlg::m_bAutoScale = FALSE;
|
|
CString CHydrantPlanDlg::m_csRadius = _T("28"); // cet 2010.7.22 add 记忆半径
|
|
int CHydrantPlanDlg::m_iPlanType = 0;
|
|
|
|
CHydrantPlanDlg::CHydrantPlanDlg(int iMode, CWnd* pParent /*=NULL*/)
|
|
: CDialog(CHydrantPlanDlg::IDD, pParent), m_spinDist(50)
|
|
{
|
|
//{{AFX_DATA_INIT(CHydrantPlanDlg)
|
|
m_iDist = 0;
|
|
m_bMirrorByX = FALSE;
|
|
m_bMirrorByY = FALSE;
|
|
m_dEle = 1.1;
|
|
m_iDim = -1;
|
|
m_dByDist = 3.0;
|
|
//}}AFX_DATA_INIT
|
|
m_csSysBlk1 = _T("TWTSYS(00000386)");
|
|
m_csSysBlk2 = _T("TWTSYS(00000383)");
|
|
// m_csSysBlk = m_csSysBlk1;
|
|
m_iOpenMode = iMode;
|
|
m_dScaleX = 0;
|
|
m_dScaleY = 0;
|
|
}
|
|
|
|
|
|
void CHydrantPlanDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CHydrantPlanDlg)
|
|
DDX_Control(pDX, IDC_EDIT_BYDIST, m_edtByDist);
|
|
DDX_Control(pDX, IDC_LIST_DN, m_listDim);
|
|
DDX_Control(pDX, IDC_SPIN_DIST, m_spinDist);
|
|
DDX_Text(pDX, IDC_EDIT_DIST, m_iDist);
|
|
DDV_MinMaxInt(pDX, m_iDist, -100, 1000);
|
|
DDX_Check(pDX, IDC_CHECK_LR, m_bMirrorByX);
|
|
DDX_Check(pDX, IDC_CHECK_UD, m_bMirrorByY);
|
|
DDX_Text(pDX, IDC_EDIT_ELE, m_dEle);
|
|
DDX_LBIndex(pDX, IDC_LIST_DN, m_iDim);
|
|
DDX_Text(pDX, IDC_EDIT_BYDIST, m_dByDist);
|
|
DDV_MinMaxDouble(pDX, m_dByDist, 0., 10000000000.);
|
|
DDX_CBString(pDX, IDC_COMBO_RADIUS, m_csRadius);
|
|
DDX_Radio(pDX, IDC_RADIO_MODE1, m_iMode);
|
|
DDX_Check(pDX, IDC_CHECK_AUTOSCALE, m_bAutoScale);
|
|
DDX_Check(pDX, IDC_CHECK_RADIUS, m_bWndChkRadius);
|
|
DDX_Radio(pDX, IDC_RADIO_BYLINE, m_iPlanType);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CHydrantPlanDlg, CDialog)
|
|
//{{AFX_MSG_MAP(CHydrantPlanDlg)
|
|
ON_WM_PAINT()
|
|
ON_WM_CLOSE()
|
|
ON_BN_CLICKED(IDC_BUTTON_CALC, OnButtonCalc)
|
|
ON_BN_CLICKED(IDC_RADIO_MODE1, OnRadioMode1)
|
|
ON_BN_CLICKED(IDC_RADIO_MODE2, OnRadioMode2)
|
|
ON_BN_CLICKED(IDC_PREVIEW, OnPreview)
|
|
ON_BN_CLICKED(IDC_BUTTON_DIM, OnButtonDim)
|
|
ON_LBN_SELCHANGE(IDC_LIST_DN, OnSelchangeListDn)
|
|
ON_BN_CLICKED(IDC_CHECK_RADIUS, OnCheckRadius)
|
|
ON_BN_CLICKED(IDC_RADIO_BYDIST, OnRadioBydist)
|
|
ON_BN_CLICKED(IDC_RADIO_BYLINE, OnRadioByline)
|
|
ON_BN_CLICKED(IDC_RADIO_BYUSER, OnRadioByuser)
|
|
ON_EN_KILLFOCUS(IDC_EDIT_BYDIST, OnKillfocusEditBydist)
|
|
ON_BN_CLICKED(IDC_CHECK_AUTOSCALE, OnCheckAutoscale)
|
|
ON_MESSAGE(WM_ACAD_KEEPFOCUS, onAcadKeepFocus)
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CHydrantPlanDlg message handlers
|
|
|
|
LONG_PTR CHydrantPlanDlg::onAcadKeepFocus(UINT_PTR, LONG_PTR)
|
|
{
|
|
POINT pt;
|
|
::GetCursorPos(&pt);
|
|
CRect rect;
|
|
GetWindowRect(&rect);
|
|
if (!(rect.PtInRect(pt)))
|
|
{
|
|
return FALSE;
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CHydrantPlanDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
m_spinDist.SetRange(0,1000);
|
|
OpenSlide();
|
|
if(m_iOpenMode == 0){
|
|
CRect rect;
|
|
this->GetWindowRect(&rect);
|
|
rect.bottom -= 80;
|
|
//this->MoveWindow(&rect);
|
|
}
|
|
else{
|
|
CWnd *pWnd1 = GetDlgItem(IDC_EDIT_DIST);
|
|
CWnd *pWnd2 = GetDlgItem(IDC_SPIN_DIST);
|
|
CWnd *pWnd3 = GetDlgItem(IDC_BUTTON_CALC);
|
|
pWnd1->EnableWindow(FALSE);
|
|
pWnd2->EnableWindow(FALSE);
|
|
pWnd3->EnableWindow(FALSE);
|
|
|
|
CWnd *pWnd4 = GetDlgItem(IDC_RADIO_BYLINE);
|
|
CWnd *pWnd5 = GetDlgItem(IDC_RADIO_BYUSER);
|
|
CWnd *pWnd6 = GetDlgItem(IDC_RADIO_BYDIST);
|
|
pWnd4->EnableWindow(FALSE);
|
|
pWnd5->EnableWindow(FALSE);
|
|
pWnd6->EnableWindow(FALSE);
|
|
UpdateData(FALSE);
|
|
}
|
|
ResetDim();
|
|
if(m_iOpenMode == 1){
|
|
CString csText;
|
|
csText.Format(_T("%.0f*%.0f"), m_dScaleX, m_dScaleY);
|
|
int idx = m_listDim.FindString(0, csText);
|
|
if(idx > -1){
|
|
m_iDim = idx;
|
|
}
|
|
else{
|
|
m_listDim.AddString(csText);
|
|
m_iDim = m_listDim.GetCount()-1;
|
|
}
|
|
UpdateData(FALSE);
|
|
}
|
|
else{
|
|
int idx = m_listDim.FindString(0, m_csOldDim);
|
|
if(idx > -1)
|
|
m_iDim = idx;
|
|
else
|
|
m_iDim = 0;
|
|
UpdateData(FALSE);
|
|
}
|
|
if(m_csSysBlk == _T(""))
|
|
m_csSysBlk = m_csSysBlk1;
|
|
|
|
TRegProperty regProp(_T("SoftWare\\SHANGHUASOFT\\2023"), _T("SHS-WTConfig"));
|
|
regProp.SetTopRootKey(HKEY_CURRENT_USER);
|
|
if (!regProp.GetValue(_T("HydrantPlanByDist"), m_dByDist))
|
|
{
|
|
m_dByDist = 3;
|
|
}
|
|
|
|
if (!regProp.GetValue(_T("HydrantPlanType"), m_iPlanType))
|
|
{
|
|
m_iPlanType = 0;
|
|
}
|
|
UpdateData(FALSE);
|
|
InitEditStatus();
|
|
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
|
}
|
|
|
|
void CHydrantPlanDlg::InitEditStatus()
|
|
{
|
|
UpdateData(TRUE);
|
|
CWnd *pWnd = GetDlgItem(IDC_EDIT_BYDIST);
|
|
if (m_iPlanType == 2 && m_iOpenMode == 0)
|
|
{
|
|
pWnd->EnableWindow(TRUE);
|
|
}
|
|
else
|
|
{
|
|
pWnd->EnableWindow(FALSE);
|
|
}
|
|
}
|
|
|
|
void CHydrantPlanDlg::OnPaint()
|
|
{
|
|
CPaintDC dc(this); // device context for painting
|
|
OpenSlide();
|
|
}
|
|
|
|
void CHydrantPlanDlg::OnClose()
|
|
{
|
|
CDialog::OnClose();
|
|
acedPostCommand(_T("\33\33"));
|
|
}
|
|
|
|
void CHydrantPlanDlg::OpenSlide()
|
|
{
|
|
UpdateData(TRUE);
|
|
CWnd *pImageBox = GetDlgItem(IDC_PREVIEW);
|
|
CString csTKName, csRocord;
|
|
CString csSlb;
|
|
GlobalFunc::SplitBlkStr(m_csInsBlkName, csTKName, csRocord);
|
|
csSlb.Format(_T("%s(%s)"), csTKName, csRocord);
|
|
|
|
GlobalFunc::DrawSlide((const TCHAR*)csSlb, pImageBox);
|
|
}
|
|
|
|
void CHydrantPlanDlg::OnButtonCalc()
|
|
{
|
|
CDialog::OnClose();
|
|
|
|
void HydrantCalc();
|
|
HydrantCalc();
|
|
}
|
|
|
|
|
|
void CHydrantPlanDlg::OnRadioMode1()
|
|
{
|
|
GlobalFunc::PostCommand(_T("R "), false);
|
|
}
|
|
|
|
void CHydrantPlanDlg::OnRadioMode2()
|
|
{
|
|
GlobalFunc::PostCommand(_T("R "), false);
|
|
}
|
|
|
|
void CHydrantPlanDlg::OnSelchangeListDn()
|
|
{
|
|
UpdateData(TRUE);
|
|
m_listDim.GetText(m_iDim, m_csOldDim);
|
|
GlobalFunc::PostCommand(_T("R "), false);
|
|
|
|
}
|
|
|
|
void CHydrantPlanDlg::OnPreview()
|
|
{
|
|
UpdateData();
|
|
|
|
CTemporaryResourceOverride vTemp;
|
|
CSelectBlkDlg dlg;
|
|
dlg.m_csTkName = _T("TWTSYS");
|
|
dlg.m_csType = _T("平面消火栓");
|
|
CWnd *pWnd = GetDlgItem(IDC_PREVIEW);
|
|
CRect rect;
|
|
dlg.m_staticSlide.m_csCurRecord = m_csSysBlk1;
|
|
pWnd->GetWindowRect(&rect);
|
|
dlg.m_ptBase = rect.TopLeft();
|
|
if(dlg.DoModal() == IDOK){
|
|
CString csRet = dlg.m_staticSlide.m_csCurRecord;
|
|
CString csDes = dlg.m_staticSlide.m_csCurDesName;
|
|
if(csDes.Find(_T("双")) > -1){
|
|
m_csSysBlk = m_csSysBlk2;
|
|
}
|
|
else{
|
|
m_csSysBlk = m_csSysBlk1;
|
|
}
|
|
|
|
XString xsTKName, xsRocord;
|
|
GlobalFunc::SplitSlbName(csRet, xsTKName, xsRocord);
|
|
acDocManager->lockDocument(curDoc(),AcAp::kWrite,NULL,NULL,true);
|
|
XString xsBlk;
|
|
GlobalFunc::LoadDwbBlock(xsTKName, xsRocord, xsBlk);
|
|
m_csInsBlkName = xsBlk;
|
|
acDocManager->unlockDocument(curDoc());
|
|
OpenSlide();
|
|
}
|
|
GlobalFunc::PostCommand(_T("R "), false);
|
|
}
|
|
|
|
extern int InvokeDataStore(int iMode, LPCTSTR psz);
|
|
void CHydrantPlanDlg::OnButtonDim()
|
|
{
|
|
InvokeDataStore(41, _T("消火栓尺寸"));
|
|
ResetDim();
|
|
m_iDim = 0;
|
|
UpdateData(FALSE);
|
|
|
|
}
|
|
|
|
void CHydrantPlanDlg::ResetDim()
|
|
{
|
|
m_listDim.ResetContent();
|
|
|
|
CodeBase db;
|
|
int Number;
|
|
CString csType, csValue, csRemark;
|
|
XString fullFile;
|
|
if(!GlobalFunc::FindFile(_T("DataStore.dbf"), fullFile)) {
|
|
AfxMessageBox(_T("对不起,没有发现DataStore.dbf文件!"));
|
|
return;
|
|
}
|
|
DbfTable *pTable = db.Open(fullFile);
|
|
if(!pTable) {
|
|
AfxMessageBox(_T("DataStore.dbf文件出错!"));
|
|
return;
|
|
}
|
|
pTable->MoveFirst();
|
|
while(!pTable->IsEOF()) {
|
|
GET_FIELD(pTable, _T("TypeNumber"), Number);
|
|
GET_FIELD(pTable, _T("TypeName"), csType);
|
|
GET_FIELD(pTable, _T("TypeValue"), csValue);
|
|
GET_FIELD(pTable, _T("REMARK"), csRemark);
|
|
if(csType == _T("消火栓尺寸") && Number == 41){
|
|
m_listDim.AddString(csValue);
|
|
}
|
|
pTable->MoveNext();
|
|
}
|
|
|
|
// m_iDim = 0;
|
|
// UpdateData(FALSE);
|
|
|
|
}
|
|
|
|
void CHydrantPlanDlg::GetScale(double &dX, double &dY)
|
|
{
|
|
UpdateData(TRUE);
|
|
CString csText;
|
|
m_listDim.GetText(m_iDim, csText);
|
|
int idx = csText.Find(_T("*"));
|
|
CString csLeft, csRight;
|
|
csLeft = csText.Left(idx);
|
|
csRight = csText.Right(csText.GetLength() - idx - 1);
|
|
dX = _tstof(csLeft);
|
|
dY = _tstof(csRight);
|
|
}
|
|
|
|
void CHydrantPlanDlg::SetScale(double dX, double dY)
|
|
{
|
|
m_dScaleX = dX;
|
|
m_dScaleY = dY;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHydrantPlanDlg::OnOK()
|
|
{
|
|
UpdateData(TRUE);
|
|
CString csText;
|
|
m_listDim.GetText(m_iDim, csText);
|
|
int idx = csText.Find(_T("*"));
|
|
CString csLeft, csRight;
|
|
csLeft = csText.Left(idx);
|
|
csRight = csText.Right(csText.GetLength() - idx - 1);
|
|
m_dScaleX = _tstof(csLeft);
|
|
m_dScaleY = _tstof(csRight);
|
|
|
|
CDialog::OnOK();
|
|
}
|
|
|
|
|
|
void CHydrantPlanDlg::OnCheckRadius()
|
|
{
|
|
GlobalFunc::PostCommand(_T("R "), false);
|
|
}
|
|
|
|
void CHydrantPlanDlg::OnRadioBydist()
|
|
{
|
|
InitEditStatus();
|
|
GlobalFunc::PostCommand(_T("R "), false);
|
|
acedGetAcadDwgView()->SetFocus();
|
|
}
|
|
|
|
void CHydrantPlanDlg::OnRadioByline()
|
|
{
|
|
InitEditStatus();
|
|
GlobalFunc::PostCommand(_T("R "), false);
|
|
acedGetAcadDwgView()->SetFocus();
|
|
}
|
|
|
|
void CHydrantPlanDlg::OnRadioByuser()
|
|
{
|
|
InitEditStatus();
|
|
GlobalFunc::PostCommand(_T("R "), false);
|
|
acedGetAcadDwgView()->SetFocus();
|
|
}
|
|
|
|
BOOL CHydrantPlanDlg::DestroyWindow()
|
|
{
|
|
UpdateData(TRUE);
|
|
TRegProperty regProp(_T("SoftWare\\SHANGHUASOFT\\2023"), _T("SHS-WTConfig"));
|
|
regProp.SetTopRootKey(HKEY_CURRENT_USER);
|
|
regProp.SetValue(_T("HydrantPlanByDist"), m_dByDist);
|
|
regProp.SetValue(_T("HydrantPlanType"), m_iPlanType);
|
|
return CDialog::DestroyWindow();
|
|
}
|
|
|
|
void CHydrantPlanDlg::OnKillfocusEditBydist()
|
|
{
|
|
double dData = m_dByDist;
|
|
CString sText;
|
|
m_edtByDist.GetWindowText(sText);
|
|
m_dByDist = _tstof(sText);
|
|
if (m_dByDist <= 0 || !GlobalFunc::IsStrAllNum(sText))
|
|
{
|
|
m_dByDist = dData;
|
|
UpdateData(FALSE);
|
|
acedGetAcadDwgView()->SetFocus();
|
|
m_edtByDist.SetFocus();
|
|
m_edtByDist.SetSel(0, -1);
|
|
}
|
|
}
|
|
|
|
void CHydrantPlanDlg::OnCheckAutoscale()
|
|
{
|
|
UpdateData(TRUE);
|
|
GlobalFunc::PostCommand(_T("R "), false);
|
|
acedGetAcadDwgView()->SetFocus();
|
|
}
|