536 lines
13 KiB
C++
536 lines
13 KiB
C++
// HidePipeDlg.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
//#include "twtkernal.h"
|
|
#include "HidePipeDlg.h"
|
|
#include "DbDoubleLinePipe.h"
|
|
#include "DbPipeValve.h"
|
|
#include "DbEquipment.h"
|
|
#include "PipeWireMonitor.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
|
|
TValveReactor *pValveReactor = NULL;
|
|
std::vector<std::pair<IdGroup, int> > GetGroupIdConfig();
|
|
void SetGroupIdConfig(std::vector<std::pair<IdGroup, int> > vec);
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CHidePipeDlg dialog
|
|
|
|
Entity GetHeightestPipe(Entity ent, XPoint pt)
|
|
{
|
|
Entity entPipe = ent;
|
|
RBList rbMaskPipe(RTDXF0, _T("ATS_PIPE,ATS_DOUBLELINEPIPE"), NULL);
|
|
PickSet ss(SS_FREE);
|
|
XPoint ptUcs = Wcs2Ucs(pt);
|
|
GetPointPickSet(ptUcs, ss, rbMaskPipe, 5);
|
|
double len = ss.Length();
|
|
if (len < 2)
|
|
{
|
|
return entPipe;
|
|
}
|
|
|
|
XPoint ptS, ptE, ptM;
|
|
GetPipePoint(ent, ptS, ptE, ptM);
|
|
ptS.z = 0;
|
|
ptE.z = 0;
|
|
AcGeVector3d vt = ptS - ptE;
|
|
AcGeTol tol;
|
|
tol.setEqualVector(0.001);
|
|
double dEle = ptM.z;
|
|
for (long l = 0; l < len; l++)
|
|
{
|
|
GetPipePoint(ss[l], ptS, ptE, ptM);
|
|
ptS.z = 0;
|
|
ptE.z = 0;
|
|
AcGeVector3d vtFind = ptS - ptE;
|
|
if (vtFind.isParallelTo(vt, tol) && ptM.z > dEle)
|
|
{
|
|
dEle = ptM.z;
|
|
entPipe = ss[l];
|
|
}
|
|
}
|
|
return entPipe;
|
|
}
|
|
|
|
// 管线遮挡
|
|
extern CString GetValveLayBySys(TPipeSys::SysType sys);
|
|
extern CString GetEquipLayBySys(TPipeSys::SysType sys);
|
|
|
|
AcDbObjectId InsBlkByName(const TCHAR* szName, XPoint pt, double nAng, const TCHAR* szLayer, AcGeScale3d sc)
|
|
{
|
|
InitLayer(szLayer);
|
|
AcDbObjectId recordId = GetBlkIdByName(szName);
|
|
if(!recordId)
|
|
return recordId;
|
|
|
|
AcDbBlockReference *pRef = new AcDbBlockReference(pt, recordId);
|
|
pRef->setScaleFactors(sc);
|
|
pRef->setRotation(nAng);
|
|
pRef->setLayer(InitLayer(szLayer));
|
|
AcDbObjectId id = AddToCurrentSpace(pRef, Adesk::kTrue);
|
|
return id;
|
|
}
|
|
|
|
void HidePipeByEquipment()
|
|
{
|
|
CTemporaryResourceOverride vTemp;
|
|
CHidePipeDlg dlg;
|
|
dlg.Create(IDD_DIALOG_HIDEPIPE, acedGetAcadFrame());
|
|
dlg.ShowWindow(SW_SHOW);
|
|
acedGetAcadDwgView()->SetFocus();
|
|
|
|
Entity entPipe;
|
|
XPoint ptPick;
|
|
RBList rbMask(RTDXF0, _T("ATS_PIPE,ATS_DOUBLELINEPIPE"), NULL);
|
|
while (true)
|
|
{
|
|
if (acedGetPoint(NULL, _T("\n请选择插入点:<退出>"), ptPick) != RTNORM)
|
|
{
|
|
dlg.DestroyWindow();
|
|
return;
|
|
}
|
|
|
|
PickSet ss(SS_FREE);
|
|
GetPointPickSet(ptPick, ss, rbMask, 1);
|
|
ptPick = Ucs2Wcs(ptPick);
|
|
if (ss.Length() == 0)
|
|
{
|
|
continue;
|
|
}
|
|
entPipe = ss[0l];
|
|
entPipe = GetHeightestPipe(entPipe, ptPick);
|
|
|
|
CString csDwb = g_csDwbPath + _T("TWTSYS");
|
|
XString sTmp, sTmp2;
|
|
|
|
if(LoadDwbBlock(csDwb, _T("00000557"), sTmp) != RTNORM) //断线
|
|
return;
|
|
if(LoadDwbBlock(csDwb, _T("00000558"), sTmp2) != RTNORM) //双管断线
|
|
return;
|
|
|
|
TCHAR szLayer[256];
|
|
entPipe.GetData(8, szLayer);
|
|
Entity entLast;
|
|
OPENOBJ_BEGIN(entPipe, AcDb::kForRead, TDbPipe, pPipe);
|
|
if(pPipe && !pPipe->IsVertical())
|
|
{
|
|
pPipe->getClosestPointTo(ptPick, ptPick);
|
|
double nRotate = ads_angle(pPipe->GetStartPoint(), pPipe->GetEndPoint());
|
|
double dDn = pPipe->GetDnDiameter() * 100;
|
|
dDn = dDn / DocGetPScale();
|
|
if (DocGetMeterUnitDraw())
|
|
{
|
|
dDn = dDn / 1000.0;
|
|
}
|
|
|
|
AcDbObjectId idBlk;
|
|
double dScale = 0.0;
|
|
double dWidth = 0.0;
|
|
dlg.UpdateData(TRUE);
|
|
dScale = dlg.m_dDst * 0.1;
|
|
|
|
AcGePoint3d pt1, pt2;
|
|
AcGeVector3d vt = pPipe->GetStartPoint() - pPipe->GetEndPoint();
|
|
vt.normalize();
|
|
|
|
double dUnt = DocGetPScale() / 100;
|
|
CString csDwb = g_csDwbPath + _T("TwtSys");
|
|
XString xsTmp, xsTmp2;
|
|
if(LoadDwbBlock(csDwb, _T("00000132"), xsTmp) != RTNORM) //断线
|
|
return;
|
|
if(LoadDwbBlock(csDwb, _T("00000478"), xsTmp2) != RTNORM) //双线管断线
|
|
return;
|
|
|
|
TDbPipeValve *pValve = new TDbPipeValve;
|
|
AcDbObjectId idBlk1, idBlk2;
|
|
if(pPipe->isKindOf(TDbDoubleLinePipe::desc()))
|
|
{
|
|
dWidth = 2;
|
|
pt1 = ptPick + vt * dScale * dUnt * 500;
|
|
pt2 = ptPick - vt * dScale * dUnt * 500;
|
|
dDn *= dUnt;
|
|
dUnt *= 500;
|
|
dScale *= dUnt;
|
|
AcGeScale3d sc(dDn);
|
|
idBlk1 = InsBlkByName(xsTmp2, pt1, nRotate, pPipe->GetLayer(), sc);
|
|
idBlk2 = InsBlkByName(xsTmp2, pt2, nRotate, pPipe->GetLayer(), sc);
|
|
idBlk = GetBlkIdByName(sTmp2);
|
|
pValve->setLayer(InitLayer(LAY_EQUIP_VALVE));
|
|
}
|
|
else
|
|
{
|
|
dWidth = 1000;
|
|
pt1 = ptPick + vt * dScale * dWidth * dUnt / 2;
|
|
pt2 = ptPick - vt * dScale * dWidth * dUnt / 2;
|
|
AcGeScale3d sc(dUnt);
|
|
idBlk1 = InsBlkByName(xsTmp, pt1, nRotate, GetEquipLayBySys(pPipe->GetSysType()), sc);
|
|
idBlk2 = InsBlkByName(xsTmp, pt2, nRotate, GetEquipLayBySys(pPipe->GetSysType()), sc);
|
|
idBlk = GetBlkIdByName(sTmp);
|
|
pValve->setLayer(InitLayer(GetValveLayBySys(pPipe->GetSysType())));
|
|
}
|
|
|
|
pValve->SetBlock2d(idBlk);
|
|
pValve->SetLocation(ptPick);
|
|
pValve->SetWidth(dWidth);
|
|
pValve->SetScale(dScale);
|
|
pValve->setColor(AcCmColor()); //随层
|
|
pValve->SetDirection(vt);
|
|
pValve->SetSysType(pPipe->GetSysType());
|
|
pValve->SetPipeId(pPipe->id());
|
|
AcDbObjectId idNew = AddToCurrentSpace(pValve, Adesk::kTrue);
|
|
// 绑定三个id,如果其中一个执行删除操作,三个实体全部删除
|
|
IdGroup group;
|
|
group.idBlk1 = idBlk1;
|
|
group.idBlk2 = idBlk2;
|
|
group.idValve = idNew;
|
|
std::vector<std::pair<IdGroup, int> > vecId = GetGroupIdConfig();
|
|
vecId.push_back(std::make_pair(group, 1));
|
|
SetGroupIdConfig(vecId);
|
|
}
|
|
OPENOBJ_END();
|
|
TPipePerDocData *pData = GetCurPipeDocData();
|
|
pData->ApplyUpdates();
|
|
}
|
|
dlg.DestroyWindow();
|
|
}
|
|
|
|
int TValveReactor::m_nCount = 0;
|
|
// 建立命令的监测
|
|
void TValveReactor::Attach()
|
|
{
|
|
AcDbDatabase *pDb = curDoc()->database();
|
|
if(pValveReactor == NULL)
|
|
{
|
|
pValveReactor = new TValveReactor;
|
|
}
|
|
m_nCount++;
|
|
pDb->addReactor(pValveReactor);
|
|
}
|
|
|
|
// 除去命令的监测
|
|
void TValveReactor::Detach()
|
|
{
|
|
if(pValveReactor != NULL)
|
|
{
|
|
AcDbDatabase *pDb = curDoc()->database();
|
|
pDb->removeReactor(pValveReactor);
|
|
m_nCount--;
|
|
}
|
|
|
|
if (m_nCount == 0 && pValveReactor != NULL)
|
|
{
|
|
delete pValveReactor;
|
|
pValveReactor=NULL;
|
|
}
|
|
}
|
|
|
|
void TValveReactor::objectAppended(const AcDbDatabase* dwg, const AcDbObject* dbObj)
|
|
{
|
|
AcDbDatabaseReactor::objectAppended(dwg, dbObj);
|
|
}
|
|
|
|
void TValveReactor::objectErased(const AcDbDatabase* dwg, const AcDbObject* dbObj, Adesk::Boolean pErased)
|
|
{
|
|
XString sCmdNames;
|
|
xg_getvar(_T("CMDNAMES"), sCmdNames);
|
|
if( _tcsicmp(sCmdNames, _T("EXPLODE")) == 0)
|
|
return;
|
|
AcDbObjectId id = dbObj->id();
|
|
std::vector<std::pair<IdGroup, int> > vecId = GetGroupIdConfig();
|
|
std::vector<std::pair<IdGroup, int> >::iterator it = vecId.begin();
|
|
AcDbObjectId idBlk1, idBlk2, idValve;
|
|
for (; it != vecId.end(); it++)
|
|
{
|
|
if (it->second == 0 && pErased == 1)
|
|
{
|
|
continue;
|
|
}
|
|
idBlk1 = it->first.idBlk1;
|
|
idBlk2 = it->first.idBlk2;
|
|
idValve = it->first.idValve;
|
|
if (id == idBlk1 || id == idBlk2 || id == idValve)
|
|
{
|
|
if (pErased == 1 && it->second == 1)
|
|
{
|
|
it->second = 0;
|
|
SetGroupIdConfig(vecId);
|
|
if (!idBlk1.isErased())
|
|
{
|
|
Entity ent;
|
|
ads_name name;
|
|
acdbGetAdsName(name, idBlk1);
|
|
ent = name;
|
|
ent.Erase();
|
|
}
|
|
|
|
if (!idBlk2.isErased())
|
|
{
|
|
Entity ent;
|
|
ads_name name;
|
|
acdbGetAdsName(name, idBlk2);
|
|
ent = name;
|
|
ent.Erase();
|
|
}
|
|
|
|
if (!idValve.isErased())
|
|
{
|
|
Entity ent;
|
|
ads_name name;
|
|
acdbGetAdsName(name, idValve);
|
|
ent = name;
|
|
ent.Erase();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
it->second = 1;
|
|
SetGroupIdConfig(vecId);
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
ACRX_DXF_DEFINE_MEMBERS(TDbGroupIdConfig, AcDbObject,AcDb::kDHL_CURRENT,
|
|
AcDb::kMReleaseCurrent,1, TCH_GROUPIDCONFIG,TWT_KERNAL);
|
|
|
|
Acad::ErrorStatus TDbGroupIdConfig::dwgInFields (AcDbDwgFiler *pFiler)
|
|
{
|
|
Acad::ErrorStatus es=Acad::eOk;
|
|
es = AcDbObject::dwgInFields(pFiler);
|
|
if(es != Acad::eOk)
|
|
return es;
|
|
|
|
Adesk::UInt16 nNum;
|
|
pFiler->readItem(&nNum);
|
|
m_vecIdGroup.clear();
|
|
for (int i = 0; i < nNum; i++)
|
|
{
|
|
IdGroup group;
|
|
AcDbSoftPointerId id1, id2, id3;
|
|
pFiler->readItem(&id1);
|
|
pFiler->readItem(&id2);
|
|
pFiler->readItem(&id3);
|
|
group.idBlk1 = id1;
|
|
group.idBlk2 = id2;
|
|
group.idValve = id3;
|
|
m_vecIdGroup.push_back(std::make_pair(group, 1));
|
|
}
|
|
return es;
|
|
}
|
|
|
|
int GetVectorSize(std::vector<std::pair<IdGroup, int> > vec)
|
|
{
|
|
int nNum = 0;
|
|
std::vector<std::pair<IdGroup, int> >::const_iterator it = vec.begin();
|
|
for (; it != vec.end(); it++)
|
|
{
|
|
if (it->second == 0)
|
|
{
|
|
continue;
|
|
}
|
|
nNum++;
|
|
}
|
|
return nNum;
|
|
}
|
|
|
|
Acad::ErrorStatus TDbGroupIdConfig::dwgOutFields (AcDbDwgFiler *pFiler) const
|
|
{
|
|
Acad::ErrorStatus es=Acad::eOk;
|
|
es = AcDbObject::dwgOutFields(pFiler);
|
|
if(es != Acad::eOk)
|
|
return es;
|
|
|
|
Adesk::UInt16 nNum = GetVectorSize(m_vecIdGroup);
|
|
pFiler->writeItem(nNum);
|
|
std::vector<std::pair<IdGroup, int> >::const_iterator it = m_vecIdGroup.begin();
|
|
for (; it != m_vecIdGroup.end(); it++)
|
|
{
|
|
if (it->second == 0)
|
|
{
|
|
continue;
|
|
}
|
|
pFiler->writeItem((AcDbSoftPointerId)it->first.idBlk1);
|
|
pFiler->writeItem((AcDbSoftPointerId)it->first.idBlk2);
|
|
pFiler->writeItem((AcDbSoftPointerId)it->first.idValve);
|
|
}
|
|
return es;
|
|
}
|
|
|
|
void InitGroupIdConfig(BOOL bTrue)
|
|
{
|
|
if(bTrue)
|
|
{
|
|
TDbGroupIdConfig::rxInit();
|
|
}
|
|
else
|
|
{
|
|
deleteAcRxClass(TDbGroupIdConfig::desc());
|
|
}
|
|
}
|
|
|
|
std::vector<std::pair<IdGroup, int> > GetGroupIdConfig()
|
|
{
|
|
std::vector<std::pair<IdGroup, int> > vec;
|
|
Acad::ErrorStatus es=Acad::eOk;
|
|
AcDbDatabase *pDb = curDoc()->database();
|
|
|
|
AcDbDictionary* pRootDict=NULL;
|
|
es=pDb->getNamedObjectsDictionary(pRootDict,AcDb::kForRead);
|
|
assert(es==Acad::eOk);
|
|
|
|
AcDbObject* pObj;
|
|
es=pRootDict->getAt(_T("TWT_GROUPIDCONFIG"),pObj,AcDb::kForRead);
|
|
if (es==Acad::eOk)
|
|
{
|
|
TDbGroupIdConfig *pGroup = (TDbGroupIdConfig *)pObj;
|
|
if (pGroup != NULL)
|
|
{
|
|
vec = pGroup->GetGroup();
|
|
}
|
|
pObj->close();
|
|
}
|
|
else
|
|
{
|
|
if (pRootDict->upgradeOpen() == Acad::eOk)
|
|
{
|
|
TDbGroupIdConfig *pConfig = new TDbGroupIdConfig;
|
|
if (pConfig!=NULL)
|
|
{
|
|
AcDbObjectId idConfig;
|
|
es=pRootDict->setAt(_T("TWT_GROUPIDCONFIG"),pConfig,idConfig);
|
|
if (es==Acad::eOk)
|
|
{
|
|
pConfig->close();
|
|
}
|
|
else
|
|
{
|
|
delete pConfig;
|
|
}
|
|
}
|
|
pRootDict->downgradeOpen();
|
|
}
|
|
}
|
|
pRootDict->close();
|
|
return vec;
|
|
}
|
|
|
|
void SetGroupIdConfig(std::vector<std::pair<IdGroup, int> > vec)
|
|
{
|
|
TDbGroupIdConfig *pConfig=NULL;
|
|
//当前数据库
|
|
AcDbDatabase *pDb = curDoc()->database();
|
|
AcDb::OpenMode opMode = AcDb::kForWrite;
|
|
|
|
if (pDb!=NULL)
|
|
{
|
|
Acad::ErrorStatus es=Acad::eOk;
|
|
AcDbDictionary* pRootDict=NULL;
|
|
es=pDb->getNamedObjectsDictionary(pRootDict,AcDb::kForRead);
|
|
if (es==Acad::eOk)
|
|
{
|
|
AcDbObjectId idExist;
|
|
es=pRootDict->getAt(_T("TWT_GROUPIDCONFIG"), idExist);
|
|
if (es==Acad::eOk && !!idExist)
|
|
{
|
|
es=acdbOpenObject(pConfig, idExist, opMode);
|
|
if (pConfig != NULL)
|
|
{
|
|
pConfig->SetGroup(vec);
|
|
pConfig->close();
|
|
}
|
|
}
|
|
else if(opMode==AcDb::kForWrite)
|
|
{
|
|
if ((es = pRootDict->upgradeOpen()) == Acad::eOk)
|
|
{
|
|
pRootDict->assertWriteEnabled();
|
|
pConfig = new TDbGroupIdConfig;
|
|
if (pConfig!=NULL)
|
|
{
|
|
pConfig->SetGroup(vec);
|
|
AcDbObjectId idConfig;
|
|
es=pRootDict->setAt(_T("TWT_GROUPIDCONFIG"),pConfig,idConfig);
|
|
pConfig->close();
|
|
}
|
|
pRootDict->downgradeOpen();
|
|
}
|
|
}
|
|
pRootDict->close();
|
|
}
|
|
}
|
|
}
|
|
|
|
CHidePipeDlg::CHidePipeDlg(CWnd* pParent /*=NULL*/)
|
|
: CModelessDialog(CHidePipeDlg::IDD, pParent)
|
|
{
|
|
//{{AFX_DATA_INIT(CHidePipeDlg)
|
|
m_dDst = 20.0;
|
|
//}}AFX_DATA_INIT
|
|
}
|
|
|
|
void CHidePipeDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CModelessDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CHidePipeDlg)
|
|
DDX_Control(pDX, IDC_EDIT_DST, m_edtDst);
|
|
DDX_Text(pDX, IDC_EDIT_DST, m_dDst);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CHidePipeDlg, CModelessDialog)
|
|
//{{AFX_MSG_MAP(CHidePipeDlg)
|
|
ON_WM_DESTROY()
|
|
ON_EN_KILLFOCUS(IDC_EDIT_DST, OnKillfocusEditDst)
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CHidePipeDlg message handlers
|
|
|
|
BOOL CHidePipeDlg::OnInitDialog()
|
|
{
|
|
CModelessDialog::OnInitDialog();
|
|
CRegProperty reg(GetRegLocation(), _T("中冶焦耐"));
|
|
reg.SetTopRootKey(HKEY_CURRENT_USER);
|
|
if(!reg.GetValue(_T("BreakDst"), m_dDst))
|
|
{
|
|
m_dDst = 20;
|
|
}
|
|
UpdateData(FALSE);
|
|
return TRUE;
|
|
}
|
|
|
|
void CHidePipeDlg::OnDestroy()
|
|
{
|
|
CModelessDialog::OnDestroy();
|
|
|
|
UpdateData(TRUE);
|
|
CRegProperty reg(GetRegLocation(), _T("中冶焦耐"));
|
|
reg.SetTopRootKey(HKEY_CURRENT_USER);
|
|
reg.SetValue(_T("BreakDst"), m_dDst);
|
|
}
|
|
|
|
void CHidePipeDlg::OnKillfocusEditDst()
|
|
{
|
|
double dDist = m_dDst;
|
|
CString sText;
|
|
m_edtDst.GetWindowText(sText);
|
|
m_dDst = _tstof(sText);
|
|
if (m_dDst <= 0.0)
|
|
{
|
|
m_dDst = dDist;
|
|
UpdateData(FALSE);
|
|
m_edtDst.SetFocus();
|
|
m_edtDst.SetSel(0, -1);
|
|
}
|
|
}
|