1115 lines
26 KiB
C++
1115 lines
26 KiB
C++
#include "StdAfx.h"
|
|
#include "StdArx.h"
|
|
#include "AecDbEwPipe.h"
|
|
#include "AecDbWall.h"
|
|
#include "AecDbColumn.h"
|
|
#include "uiiado.h"
|
|
#include "CoreTools.h"
|
|
#include "AecDbObjXDataMap.h"
|
|
#include "KTModelLayoutXData.h"
|
|
#include "AecPipeJig.h"
|
|
#include "KTCadUtility.h"
|
|
#include "KTCADUtilityEx.h"
|
|
#include "AecPipeSupport.h"
|
|
#include "PipelineTools.h"
|
|
#include "AecPipeLine.h"
|
|
#include "DJGXDlg.h"
|
|
#include "EReducerDlg.h"
|
|
#include "AECStatusRecord.h"
|
|
#include "KTCADSysVar.h"
|
|
#include "AecDbEwPipeDim.h"
|
|
#include "KTSetting.h"
|
|
#include "dbtable.h"
|
|
|
|
#define DXF_PIPE_ONLY _T("AEC_EWPIPE")
|
|
#define DXF_FITTING_ONLY _T("AEC_DBEWFIT")
|
|
#define DXF_PIPE_FITTING_EQUI _T("AEC_EWPIPE,AEC_DBEWFIT,AEC_DBWEQUIPMENT")
|
|
#define DXF_PIPE_FITTING _T("AEC_EWPIPE,AEC_DBEWFIT")
|
|
#define DXF_WALL_ONLY _T("AEC_DBWALL,AEC_DBCOLMN")
|
|
|
|
BOOL DLLIMPEXP GetDocScale(double &dPScale);
|
|
|
|
#define INIT_DB_AND_CURR_SYS(db)\
|
|
CUIISQLiteServer db;\
|
|
do {\
|
|
if (!PipelineTools::getSqliteDB(_T("Plumbing.db"), db))\
|
|
{\
|
|
AfxMessageBox(_T("未找到数据库文件Plumbing.db,请重新安装!"));\
|
|
return;\
|
|
}\
|
|
} while(false)
|
|
|
|
|
|
#define INIT_DB_AND_CURR_SYS_BOOL(db)\
|
|
CUIISQLiteServer db;\
|
|
do {\
|
|
if (!PipelineTools::getSqliteDB(_T("Plumbing.db"), db))\
|
|
{\
|
|
AfxMessageBox(_T("未找到数据库文件Plumbing.db,请重新安装!"));\
|
|
return false;\
|
|
}\
|
|
} while(false)
|
|
|
|
|
|
extern bool DLLIMPEXP GetPipeNetNodes(const AcDbObjectId & id1, AcDbObjectIdArray & arNetIds, BOOL bTeeStop, BOOL bCrossStop,BOOL bReducerStop);
|
|
DLLIMPEXP bool GetDoubleClickEnt(LPCTSTR pszCmd, AcDbObjectId & id);
|
|
extern bool DLLIMPEXP PickGripMessage(GripMessage & msg);
|
|
extern void DLLIMPEXP PushGripMessage(GripMessage &);
|
|
|
|
void PL_DJGXCmd()
|
|
{
|
|
if (!CoreTools::hasCSSZ(true)) return;
|
|
AecDbObjXDataMap xDataMap;
|
|
if (!KTModelLayoutXData::ReadModelXData(KT_PIPEINIT, xDataMap))
|
|
{
|
|
acedAlert(_T("\n系统没有初始化!请运行初始化命令!"));
|
|
return;
|
|
}
|
|
|
|
CString dbPath = FilePath::GetSysDir();
|
|
dbPath += _T("\\Plumbing.db");
|
|
|
|
CUIISQLiteServer * pADOServer = new CUIISQLiteServer;
|
|
if (!pADOServer->InitADOServer(dbPath))
|
|
{
|
|
AfxMessageBox(_T("数据库驱动加载数据库Plumbing.db失败!"));
|
|
return;
|
|
}
|
|
|
|
TDbPipeJig jig;
|
|
jig.SetAdoDb(pADOServer);
|
|
jig.DoItSpec(WPipe::eNoneApp);
|
|
|
|
DELETE_PTR(pADOServer);
|
|
|
|
CoreTools::refreshGraphics();
|
|
}
|
|
|
|
void PL_JBQQCmd()
|
|
{
|
|
ads_name ent1, ent2;
|
|
|
|
INIT_DB_AND_CURR_SYS(sqlDb);
|
|
|
|
struct resbuf* pRb = acutBuildList(RTDXF0, DXF_PIPE_ONLY, 0);
|
|
int nRes = CKTCadUtility::SelectEntity(_T("\n选择主管线:"), ent1, pRb);
|
|
if (nRes == RTNORM)
|
|
{
|
|
nRes = CKTCadUtility::SelectEntity(_T("\n指定支管线:"), ent2, pRb);
|
|
acutRelRb(pRb);
|
|
if (nRes == RTNORM)
|
|
{
|
|
AcDbObjectId id1;
|
|
acdbGetObjectId(id1, ent1);
|
|
|
|
AcDbObjectId id2;
|
|
acdbGetObjectId(id2, ent2);
|
|
|
|
AcDbEntity* pEnt1 = NULL;
|
|
if (Acad::eOk == acdbOpenAcDbEntity(pEnt1, id1, AcDb::kForWrite))
|
|
{
|
|
AecDbEwPipe* pPipeMaj = AecDbEwPipe::cast(pEnt1);
|
|
if (pPipeMaj != NULL)
|
|
{
|
|
AcDbEntity* pEnt2 = NULL;
|
|
if (Acad::eOk == acdbOpenAcDbEntity(pEnt2, id2, AcDb::kForWrite))
|
|
{
|
|
AecDbEwPipe* pPipeMin = AecDbEwPipe::cast(pEnt2);
|
|
CString sLayer1 = pEnt1->layer();
|
|
CString sLayer2 = pEnt2->layer();
|
|
|
|
if (pPipeMin != NULL)
|
|
{
|
|
AcGeLine3d ln1(pPipeMaj->StartPoint(), pPipeMaj->EndPoint());
|
|
AcGeLine3d ln2(pPipeMin->StartPoint(), pPipeMin->EndPoint());
|
|
AcGeTol tol;
|
|
tol.setEqualPoint(10e-4);
|
|
tol.setEqualVector(10e-4);
|
|
AcGePoint3d ptMid, ptTemp1, ptTemp2;
|
|
if (ln1.intersectWith(ln2, ptMid, tol)) //相交
|
|
{
|
|
WPipe::PipeParam param1, param2,param;
|
|
memset(¶m1,0,sizeof(WPipe::PipeParam));
|
|
memset(¶m2,0,sizeof(WPipe::PipeParam));
|
|
|
|
AecDbObjXDataMap* pXDataMap1 = pPipeMaj->GetSpecialtyData();
|
|
AecDbObjXDataMap* pXDataMap2 = pPipeMin->GetSpecialtyData();
|
|
|
|
TDbPipeSupport::XData2PipeParam(¶m1, pXDataMap1);
|
|
TDbPipeSupport::XData2PipeParam(¶m2, pXDataMap2);
|
|
|
|
if (param1.m_dDN < param2.m_dDN)
|
|
{
|
|
memcpy(¶m, ¶m1, sizeof(WPipe::PipeParam));
|
|
memcpy(¶m1, ¶m2, sizeof(WPipe::PipeParam));
|
|
memcpy(¶m2, ¶m, sizeof(WPipe::PipeParam));
|
|
|
|
AecDbEwPipe *pPipe = NULL;
|
|
pPipe = pPipeMaj;
|
|
pPipeMaj = pPipeMin;
|
|
pPipeMin = pPipe;
|
|
}
|
|
|
|
//pipeline工具
|
|
TDbPipeJig jig;
|
|
jig.SetAdoDb(&sqlDb);
|
|
TDbPipeLine pipeline(&jig);
|
|
pipeline.SetPipeParam(¶m1);
|
|
|
|
pipeline.AddRPorHP(pPipeMaj, pPipeMin, ptMid);
|
|
}
|
|
else
|
|
{
|
|
acutPrintf(_T("\n两管线不在同一平面!无法加补强圈!"));
|
|
}
|
|
}
|
|
pEnt2->close();
|
|
}
|
|
}
|
|
pEnt1->close();
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
acutRelRb(pRb);
|
|
}
|
|
}
|
|
|
|
//管嘴对共直线,2个管嘴
|
|
typedef struct InfLinePair
|
|
{
|
|
int nValid;
|
|
AecInterface inf0;
|
|
AecInterface inf1;
|
|
}INFPAIR;
|
|
|
|
bool GiveInSpaceOnMove(AcDbObjectId &id, AecInterface &infLast, const AcGeVector3d &vtMove)
|
|
{
|
|
bool bStop = false;
|
|
AecInterface inf0, inf1;
|
|
|
|
AcGeMatrix3d xMove;
|
|
xMove.setToTranslation(vtMove);
|
|
|
|
AcDbEntity *pEnt1 = NULL;
|
|
if (Acad::eOk == acdbOpenAcDbEntity(pEnt1, id, AcDb::kForWrite))
|
|
{
|
|
//设备,管线,管件
|
|
AecDbEwEquipment *pEqu = AecDbEwEquipment::cast(pEnt1);
|
|
if (pEqu != NULL)
|
|
{
|
|
if (pEqu->GetInterfaceCount() == 2)
|
|
{
|
|
pEqu->GetInterface(0, inf0);
|
|
pEqu->GetInterface(1, inf1);
|
|
|
|
if (inf0.ptPos.distanceTo(infLast.ptPos) < 1.e-2)
|
|
{
|
|
infLast = inf1;
|
|
pEqu->TransformBy(xMove);
|
|
}
|
|
else if (inf1.ptPos.distanceTo(infLast.ptPos) < 1.e-2)
|
|
{
|
|
infLast.ptPos = inf0.ptPos;
|
|
pEqu->TransformBy(xMove);
|
|
}
|
|
}
|
|
}
|
|
|
|
AecDbEwPipe *pPipe = AecDbEwPipe::cast(pEnt1);
|
|
if (pPipe != NULL)
|
|
{
|
|
pPipe->GetInterface(0, inf0);
|
|
pPipe->GetInterface(1, inf1);
|
|
|
|
if (inf0.ptPos.distanceTo(infLast.ptPos) < 1.e-2)
|
|
{
|
|
inf0.ptPos += vtMove;
|
|
pPipe->SetStartPoint(inf0.ptPos);
|
|
|
|
//infLast.ptPos = inf1.ptPos;
|
|
bStop = true;
|
|
}
|
|
else if (inf1.ptPos.distanceTo(infLast.ptPos) < 1.e-2)
|
|
{
|
|
inf1.ptPos += vtMove;
|
|
pPipe->SetEndPoint(inf1.ptPos);
|
|
|
|
//infLast.ptPos = inf0.ptPos;
|
|
bStop = true;
|
|
}
|
|
}
|
|
|
|
AecDbEwFitting *pEwFit = AecDbEwFitting::cast(pEnt1);
|
|
if (pEwFit != NULL)
|
|
{
|
|
if (pEwFit->GetInterfaceCount() == 1)
|
|
{
|
|
bStop = true;
|
|
pEwFit->GetInterface(0, inf0);
|
|
if (inf0.ptPos.distanceTo(infLast.ptPos) < 1.e-2)
|
|
{
|
|
pEwFit->TransformBy(xMove);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
int nType = 0;
|
|
pEwFit->GetSpecialtyData(AcDb::kForRead)->GetAt(KEY_RUNTIME, nType);
|
|
EFittingType eTypeR = (EFittingType)nType;
|
|
if (eTypeR == eElbow)
|
|
{
|
|
//弯头定位,不可移动
|
|
bStop = true;
|
|
pEnt1->close();
|
|
return bStop;
|
|
}
|
|
|
|
pEwFit->GetInterface(0, inf0);
|
|
pEwFit->GetInterface(1, inf1);
|
|
|
|
if (inf0.ptPos.distanceTo(infLast.ptPos) < 1.e-2)
|
|
{
|
|
pEwFit->TransformBy(xMove);
|
|
infLast.ptPos = inf1.ptPos;
|
|
}
|
|
else if (inf1.ptPos.distanceTo(infLast.ptPos) < 1.e-2)
|
|
{
|
|
pEwFit->TransformBy(xMove);
|
|
infLast.ptPos = inf0.ptPos;
|
|
}
|
|
}
|
|
}
|
|
pEnt1->close();
|
|
}
|
|
|
|
return bStop;
|
|
}
|
|
|
|
//让出位置,引起更改传递,inf 的反向让开
|
|
bool EquGiveInSpace(AcDbObjectId &id, AcDbObjectId &idBreak, double dL, AecInterface &inf, AcGeVector3d &vtGiveIn)
|
|
{
|
|
AcGeVector3d vtMove = inf.vtDir;
|
|
vtMove.normalize();
|
|
vtMove *= dL;
|
|
vtGiveIn = vtMove;
|
|
|
|
//获取id位置的一条直链
|
|
AcDbObjectIdArray arIds;
|
|
GetPipeNetNodes(id, arIds, TRUE, TRUE,TRUE);
|
|
arIds.remove(idBreak);
|
|
|
|
AcArray<InfLinePair> arLnInfPairs;
|
|
|
|
AecInterface inf0, inf1;
|
|
InfLinePair lnInfPair;
|
|
|
|
//由于ARX规则,实体不可以在一个命令中打开256次,
|
|
//所以先一次提取出管嘴序列
|
|
|
|
AcDbObjectId idT;
|
|
AcDbEntity *pEnt1 = NULL;
|
|
for (int i = 0; i < arIds.length(); i++)
|
|
{
|
|
idT = arIds.at(i);
|
|
if (Acad::eOk == acdbOpenAcDbEntity(pEnt1, idT, AcDb::kForRead))
|
|
{
|
|
//设备,管线,管件
|
|
AecDbEwEquipment *pEqu = AecDbEwEquipment::cast(pEnt1);
|
|
if (pEqu != NULL)
|
|
{
|
|
lnInfPair.nValid = 0;
|
|
if (pEqu->GetInterface(0, inf0))
|
|
{
|
|
if (inf0.vtDir.isParallelTo(inf.vtDir))
|
|
{
|
|
lnInfPair.inf0 = inf0;
|
|
lnInfPair.nValid += 1;
|
|
}
|
|
}
|
|
|
|
if (pEqu->GetInterface(1, inf1))
|
|
{
|
|
if (inf1.vtDir.isParallelTo(inf.vtDir))
|
|
{
|
|
lnInfPair.inf1 = inf1;
|
|
lnInfPair.nValid += 1;
|
|
}
|
|
}
|
|
|
|
if (lnInfPair.nValid > 0)
|
|
{
|
|
arLnInfPairs.append(lnInfPair);
|
|
}
|
|
}
|
|
|
|
AecDbEwPipe *pPipe = AecDbEwPipe::cast(pEnt1);
|
|
if (pPipe != NULL)
|
|
{
|
|
pPipe->GetInterface(0, inf0);
|
|
pPipe->GetInterface(1, inf1);
|
|
|
|
lnInfPair.nValid = 0;
|
|
if (inf0.vtDir.isParallelTo(inf.vtDir))
|
|
{
|
|
lnInfPair.inf0 = inf0;
|
|
lnInfPair.nValid += 1;
|
|
}
|
|
|
|
if (inf1.vtDir.isParallelTo(inf.vtDir))
|
|
{
|
|
lnInfPair.inf1 = inf1;
|
|
lnInfPair.nValid += 1;
|
|
}
|
|
if (lnInfPair.nValid > 0)
|
|
{
|
|
arLnInfPairs.append(lnInfPair);
|
|
}
|
|
}
|
|
|
|
AecDbEwFitting *pEwFit = AecDbEwFitting::cast(pEnt1);
|
|
if (pEwFit != NULL)
|
|
{
|
|
//弯头不可以传递
|
|
int nType = 0;
|
|
pEwFit->GetSpecialtyData(AcDb::kForRead)->GetAt(KEY_RUNTIME, nType);
|
|
|
|
EFittingType eTypeL = (EFittingType)nType;
|
|
if (eTypeL == eElbow)
|
|
{
|
|
pEnt1->close();
|
|
continue;
|
|
}
|
|
|
|
lnInfPair.nValid = 0;
|
|
if (pEwFit->GetInterface(0, inf0))
|
|
{
|
|
if (inf0.vtDir.isParallelTo(inf.vtDir))
|
|
{
|
|
lnInfPair.inf0 = inf0;
|
|
lnInfPair.nValid += 1;
|
|
}
|
|
}
|
|
|
|
if (pEwFit->GetInterface(1, inf1))
|
|
{
|
|
if (inf1.vtDir.isParallelTo(inf.vtDir))
|
|
{
|
|
lnInfPair.inf1 = inf1;
|
|
lnInfPair.nValid += 1;
|
|
}
|
|
}
|
|
if (lnInfPair.nValid > 0)
|
|
{
|
|
arLnInfPairs.append(lnInfPair);
|
|
}
|
|
}
|
|
pEnt1->close();
|
|
}
|
|
}
|
|
|
|
//线性传递改变
|
|
double dDis1 = 0, dDis2 = 0;
|
|
AecInterface infLast = inf;
|
|
for (int i = 0; i < arLnInfPairs.length(); i++)
|
|
{
|
|
InfLinePair &lnPair = arLnInfPairs.at(i);
|
|
|
|
if (lnPair.nValid == 2)
|
|
{
|
|
dDis1 = lnPair.inf0.ptPos.distanceTo(infLast.ptPos);
|
|
dDis2 = lnPair.inf1.ptPos.distanceTo(infLast.ptPos);
|
|
|
|
if (dDis1 < 1.e-2 || dDis2 < 1.e-2)//吻合
|
|
{
|
|
//infLast为原infLast的对侧
|
|
if (GiveInSpaceOnMove(lnPair.inf0.idOwner, infLast, vtMove))
|
|
{
|
|
//如果停止,一般传递到管子
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
arLnInfPairs.removeAt(i);
|
|
i = -1;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dDis1 = lnPair.inf0.ptPos.distanceTo(infLast.ptPos);
|
|
if (dDis1 < 1.e-2)//吻合
|
|
{
|
|
if (GiveInSpaceOnMove(lnPair.inf0.idOwner, infLast, vtMove))
|
|
{
|
|
//如果停止,一般传递到管子
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
arLnInfPairs.removeAt(i);
|
|
i = -1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool GetOtherInf(AecInterface& inf, AcDbObjectId& id2)
|
|
{
|
|
ads_name ss, ent;
|
|
|
|
//在本点选
|
|
TCHAR szBuf[256];
|
|
struct resbuf eb1;
|
|
eb1.restype = 0;
|
|
_tcscpy(szBuf, DXF_PIPE_FITTING_EQUI);
|
|
eb1.resval.rstring = szBuf;
|
|
eb1.rbnext = NULL;
|
|
|
|
ads_point pt,ptC[2], ptWCS;
|
|
acdbWcs2Ucs(asDblArray(inf.ptPos), pt, false);
|
|
|
|
ads_point_set(pt, ptC[0]);
|
|
ads_point_set(pt, ptC[1]);
|
|
acdbUcs2Wcs(pt, ptWCS, false);
|
|
|
|
ptC[0][X] -= CoreTools::PixelToWcs(10);
|
|
ptC[0][Y] -= CoreTools::PixelToWcs(10);
|
|
ptC[1][X] += CoreTools::PixelToWcs(10);
|
|
ptC[1][Y] += CoreTools::PixelToWcs(10);
|
|
|
|
int nRes = acedSSGet(_T("C"), ptC[0], ptC[1], &eb1, ss);
|
|
if (nRes != RTNORM)
|
|
return false;
|
|
|
|
Adesk::Int32 lLen = 0;
|
|
acedSSLength(ss, &lLen);
|
|
if (lLen == 2)
|
|
{
|
|
AcDbObjectId id;
|
|
for (int i = 0;i <lLen;i++)
|
|
{
|
|
acedSSName(ss, i, ent);
|
|
acdbGetObjectId(id, ent);
|
|
|
|
if (id != id2)
|
|
{
|
|
id2 = id;
|
|
acedSSFree(ss);
|
|
return true;
|
|
}
|
|
|
|
}
|
|
}
|
|
acedSSFree(ss);
|
|
return false;
|
|
}
|
|
|
|
//让出位置,引起更改传递
|
|
bool FitGiveInSpace(AcDbObjectId &id, AcDbObjectId &idBreak, double dL, AecInterface &inf, AcGeVector3d &vtGiveIn)
|
|
{
|
|
return EquGiveInSpace(id, idBreak, dL, inf, vtGiveIn);
|
|
}
|
|
|
|
void PL_MBCmdImp(BOOL bIsMB)
|
|
{
|
|
ads_point pt, pt2;
|
|
ads_name ent;
|
|
|
|
//选择管线
|
|
INIT_DB_AND_CURR_SYS(sqlDb);
|
|
|
|
struct resbuf *pRb = acutBuildList(RTDXF0, DXF_FITTING_ONLY, 0);
|
|
int nRes = CKTCadUtility::SelectEntity(_T("\n请选择法兰实体:"), ent, pRb, pt);
|
|
if (nRes == RTNORM)
|
|
{
|
|
AcDbObjectId id1;
|
|
acdbGetObjectId(id1, ent);
|
|
|
|
AcDbEntity *pEnt1 = NULL;
|
|
if (Acad::eOk == acdbOpenAcDbEntity(pEnt1, id1, AcDb::kForRead))
|
|
{
|
|
CString sLevel;
|
|
double dDn = 0.0;
|
|
WPipe::PipeParam *pParam = NULL;
|
|
|
|
AecMInterfaces *pMInf = NULL;
|
|
AecDbEwFitting *pFit = AecDbEwFitting::cast(pEnt1);
|
|
if (pFit != NULL)
|
|
{
|
|
pFit->GetAt(PIPE_LEVEL, sLevel);
|
|
pFit->GetAt(PIPE_DN, dDn);
|
|
pFit->GetPipeParam();
|
|
pParam = pFit->GetPipeParam();
|
|
pMInf = dynamic_cast<AecMInterfaces *>(pFit);
|
|
|
|
//阀门位置不动
|
|
/*AecDbEwEquipment *pEqu = AecDbEwEquipment::cast(pEnt1);
|
|
if (pEqu != NULL)
|
|
{
|
|
pEqu->GetAt(PIPE_LEVEL, sLevel);
|
|
pEqu->GetAt(PIPE_DN, dDn);
|
|
pMInf = dynamic_cast<AecMInterfaces *>(pEqu);
|
|
}*/
|
|
|
|
acdbUcs2Wcs(pt, pt2, false);
|
|
if (pMInf != NULL)
|
|
{
|
|
AecInterface inf;
|
|
pMInf->GetInterface(1, inf);//sta
|
|
|
|
AcGePoint3d ptOn = inf.ptPos;
|
|
AcGeVector3d vtDir = inf.vtDir;
|
|
vtDir.normalize();
|
|
|
|
AecDbObjXDataMap xData;
|
|
if (TDbPipeSupport::QuerySBFlange(&sqlDb, dDn, pParam->m_dPress, &xData))
|
|
{
|
|
double dSpaceL = 0.0;
|
|
xData.GetAt(PIPE_THICK, dSpaceL);
|
|
|
|
AcDbObjectId idBr;
|
|
AcGeVector3d vtGiveIn;
|
|
|
|
inf.vtDir.normalize();
|
|
inf.vtDir.negate();
|
|
|
|
AcGePoint3d ptSta, ptEnd;
|
|
pFit->GetAt(KEY_START, ptSta);
|
|
|
|
//让出位置
|
|
//ptSta += inf.vtDir * dSpaceL;
|
|
//pFit->SetAt(KEY_START, ptSta);
|
|
//pFit->ReCreateDraw2d();
|
|
//pFit->ReCreateDraw3d();
|
|
|
|
AcDbObjectId idBreak;
|
|
AcGeVector3d vtGiven;
|
|
inf.vtDir.negate();
|
|
|
|
//获取对侧管件或阀门
|
|
AcDbObjectId id2 = id1;
|
|
//GetOtherInf(inf, id2);
|
|
|
|
FitGiveInSpace(id1, idBreak, dSpaceL, inf, vtGiven);
|
|
|
|
//移到正中
|
|
ptOn += inf.vtDir * 0.5 * dSpaceL;
|
|
|
|
//pipeline工具
|
|
TDbPipeJig jig;
|
|
jig.SetAdoDb(&sqlDb);
|
|
TDbPipeLine pipeline(&jig);
|
|
pipeline.SetPipeParam(pParam);
|
|
pipeline.AddSBFlange(sLevel, dDn, ptOn, vtDir, bIsMB);
|
|
}
|
|
else
|
|
{
|
|
CString sTip;
|
|
sTip.Format(_T("\n没有查询到公称直径%d等级%s的盲板数据"), (int)(dDn + 0.5), sLevel);
|
|
acutPrintf(sTip);
|
|
}
|
|
|
|
delete pParam;
|
|
}
|
|
}
|
|
pEnt1->close();
|
|
}
|
|
}
|
|
acutRelRb(pRb);
|
|
}
|
|
|
|
void PL_BZMBCmd()
|
|
{
|
|
PL_MBCmdImp(0);
|
|
}
|
|
|
|
void PL_FZCBCmd()
|
|
{
|
|
PL_MBCmdImp(1);
|
|
}
|
|
|
|
static BOOL IsGSFMaterial(LPCTSTR pszMertial)
|
|
{
|
|
CString sMertial = pszMertial;
|
|
//目前只能按照材质判断
|
|
if (sMertial.Find(_T("衬塑")) != -1 ||
|
|
sMertial.Find(_T("HG/T 20538")) != -1)
|
|
{
|
|
return TRUE;
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
static BOOL IsSRPEMaterial(LPCTSTR pszMertial)
|
|
{
|
|
CString sMertial = pszMertial;
|
|
|
|
//目前只能按照材质判断
|
|
if (sMertial.Find(_T("钢骨架")) != -1 ||
|
|
sMertial.Find(_T("CJ/T 123")) != -1)
|
|
{
|
|
return TRUE;
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
void PL_BJWTCmd()
|
|
{
|
|
INIT_DB_AND_CURR_SYS(sqlDb);
|
|
//选择位置,如果该位置
|
|
ads_point pt;
|
|
int nRes = acedGetPoint(NULL, _T("\n请拾取管道或设备元件的接口点:"), pt);
|
|
if (nRes == RTNORM)
|
|
{
|
|
TCHAR szKey[131] = {};
|
|
acedInitGet(RSG_OTHER, _T("L V"));
|
|
|
|
nRes = acedGetKword(_T("\n请选择弯头类型[90度弯头(L)/45度弯头(V)]<L>:"), szKey);
|
|
if (nRes == RTCAN)
|
|
return;
|
|
|
|
double dSweepAngle = PI / 2.0;
|
|
if (_tcscmp(szKey, _T("L")) == 0)
|
|
dSweepAngle = PI / 2.0;
|
|
|
|
if (_tcscmp(szKey, _T("V")) == 0)
|
|
dSweepAngle = PI / 4.0;
|
|
|
|
//在本点选
|
|
ads_name ss, ent;
|
|
ads_point ptC[2];
|
|
ads_point_set(pt, ptC[0]);
|
|
ads_point_set(pt, ptC[1]);
|
|
|
|
ptC[0][X] -= CoreTools::PixelToWcs(10);
|
|
ptC[0][Y] -= CoreTools::PixelToWcs(10);
|
|
ptC[1][X] += CoreTools::PixelToWcs(10);
|
|
ptC[1][Y] += CoreTools::PixelToWcs(10);
|
|
|
|
struct resbuf *pRb = acutBuildList(RTDXF0, DXF_PIPE_FITTING_EQUI, 0);
|
|
nRes = acedSSGet(_T("C"), ptC[0], ptC[1], pRb, ss);
|
|
acutRelRb(pRb);
|
|
if (nRes == RTNORM)
|
|
{
|
|
Adesk::Int32 lLen = 0;
|
|
acedSSLength(ss, &lLen);
|
|
if (lLen == 0)
|
|
{
|
|
acutPrintf(_T("\n没有选择到管线,管件或设备元件,请重新执行命令!"));
|
|
return;
|
|
}
|
|
|
|
acedSSName(ss, 0, ent);
|
|
AcDbObjectId id;
|
|
acdbGetObjectId(id, ent);
|
|
acedSSFree(ss);
|
|
|
|
AcGePoint3d ptGe;
|
|
ads_point ptw;
|
|
acdbUcs2Wcs(pt, ptw, false);
|
|
ptGe = asPnt3d(ptw);
|
|
AecInterface inf;
|
|
inf.dSize1 = -1.0;
|
|
inf.dSize2 = -1.0;
|
|
|
|
WPipe::PipeParam param;
|
|
double dPre = 1.0;//待定???
|
|
double dGast = 0.0;
|
|
double dL = 0.0;
|
|
bool bIsEqu = false;
|
|
CString sMat;
|
|
|
|
AcDbEntity *pEnt = NULL;
|
|
if (Acad::eOk == acdbOpenAcDbEntity(pEnt, id, AcDb::kForRead))
|
|
{
|
|
AecMInterfaces *pInf(NULL);
|
|
AecDbEwPipe *pPipe(NULL);
|
|
AecDbEwFitting *pFit(NULL);
|
|
AecDbEwEquipment *pEqu(NULL);
|
|
|
|
AecDbObjXDataMap *pXDataMap(NULL);
|
|
AecDbObjXDataMap xd;
|
|
xd.SetAt(PIPE_ELBOWANG, dSweepAngle);
|
|
|
|
pPipe = AecDbEwPipe::cast(pEnt);
|
|
pFit = AecDbEwFitting::cast(pEnt);
|
|
pEqu = AecDbEwEquipment::cast(pEnt);
|
|
|
|
if (pPipe != NULL)
|
|
{
|
|
pInf = pPipe;
|
|
pXDataMap = pPipe->GetSpecialtyData(AcDb::kForRead);
|
|
dGast = pPipe->GetGasketThick();
|
|
|
|
//查询衬塑
|
|
pPipe->GetAt(PIPE_MATERIAL, sMat);
|
|
WPipe::PipeParam * pParam = pPipe->GetPipeParam();
|
|
|
|
if (IsGSFMaterial(pParam->szMertial))
|
|
{
|
|
//结构长度
|
|
TDbPipeSupport::QueryElbowL(&sqlDb, pParam->m_dDN, dL, pParam->m_dRRatio, pParam->m_nConnectType, pParam->szLevel,&xd);
|
|
}
|
|
delete pParam;
|
|
}
|
|
|
|
if (pFit != NULL)
|
|
{
|
|
pInf = pFit;
|
|
pXDataMap = pFit->GetSpecialtyData(AcDb::kForRead);
|
|
dGast = pFit->GetGasketThick();
|
|
|
|
WPipe::PipeParam *pParam = pFit->GetPipeParam();
|
|
if (IsGSFMaterial(pParam->szMertial))
|
|
{
|
|
//结构长度
|
|
TDbPipeSupport::QueryElbowL(&sqlDb, pParam->m_dDN, dL, pParam->m_dRRatio, pParam->m_nConnectType, pParam->szLevel,&xd);
|
|
}
|
|
delete pParam;
|
|
}
|
|
|
|
if (pEqu != NULL)
|
|
{
|
|
pInf = pEqu;
|
|
pXDataMap = pEqu->GetSpecialtyData(AcDb::kForRead);
|
|
param.m_dRRatio = 1.5;
|
|
|
|
//弹出界面选择...
|
|
}
|
|
|
|
if (pInf != NULL)
|
|
{
|
|
CString sLayer = pEnt->layer();
|
|
//MakesureLaySysByLayer(&sqlDb, sLayer, sCurrSys);
|
|
|
|
TDbPipeSupport::XData2PipeParam(¶m, pXDataMap);
|
|
|
|
//找最近的接口
|
|
double dDis = 0.0, dDisMin = 0.0;
|
|
int nNearPos = -1;
|
|
for (int i = 0; i < pInf->GetInterfaceCount(); i++)
|
|
{
|
|
pInf->GetInterface(i, inf);
|
|
dDis = inf.ptPos.distanceTo(ptGe);
|
|
if (i == 0)
|
|
{
|
|
dDisMin = dDis;
|
|
nNearPos = i;
|
|
}
|
|
else
|
|
{
|
|
if (dDis - dDisMin < 1.e-6)
|
|
{
|
|
nNearPos = i;
|
|
dDisMin = dDis;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (nNearPos > -1)
|
|
{
|
|
pInf->GetInterface(nNearPos, inf);
|
|
}
|
|
|
|
double dSize1(inf.dSize1), dSize2(inf.dSize2);
|
|
if (dSize1 < 1.e-3)
|
|
{
|
|
pEnt->close();
|
|
return;
|
|
}
|
|
|
|
AcGeVector3d vtDir = inf.vtDir;
|
|
AcGePoint3d ptHit = inf.ptPos;
|
|
ads_point ptdir, ptRes, ptRes2;
|
|
acdbWcs2Ucs(asDblArray(ptHit), ptdir, false);
|
|
|
|
acedInitGet(RSG_OTHER, _T("U D"));
|
|
nRes = acedGetPoint(ptdir, _T("\n选择弯头的出口方向或另外管线末端[向上(U)/向下(D)]:"), ptRes);
|
|
|
|
AcGeVector3d vtMin;
|
|
if (nRes == RTNORM)
|
|
{
|
|
acdbUcs2Wcs(ptRes, ptRes2, false);
|
|
ptRes2[Z] = ptHit.z;
|
|
vtMin = asPnt3d(ptRes2) - ptHit;
|
|
}
|
|
else if (nRes == RTKWORD)
|
|
{
|
|
TCHAR szKey[3];
|
|
acedGetInput(szKey);
|
|
if (_tcsicmp(_T("U"), szKey) == 0)
|
|
{
|
|
vtMin = AcGeVector3d::kZAxis;
|
|
}
|
|
else if (_tcsicmp(_T("D"), szKey) == 0)
|
|
{
|
|
vtMin = -AcGeVector3d::kZAxis;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
pEnt->close();
|
|
return;
|
|
}
|
|
|
|
//根据90 45 确定出口方向
|
|
if (fabs(dSweepAngle - PI / 2.0) < 1.e-1)
|
|
{
|
|
vtMin = vtMin.orthoProject(vtDir);
|
|
vtMin.normalize();
|
|
}
|
|
else//45度
|
|
{
|
|
vtMin = vtMin.orthoProject(vtDir);
|
|
vtMin.normalize();
|
|
vtDir.normalize();
|
|
|
|
AcGeVector3d vtM = vtDir + vtMin;
|
|
vtM.normalize();
|
|
vtMin = vtM;
|
|
}
|
|
|
|
if (IsGSFMaterial(param.szMertialFit))
|
|
{
|
|
_tcscpy(param.szODSn, _T("GSF"));//
|
|
}
|
|
|
|
if (IsSRPEMaterial(param.szMertialFit))
|
|
{
|
|
_tcscpy(param.szODSn, _T("SRPE"));//
|
|
}
|
|
|
|
param.m_nRadioOn = TRUE;//按结构长度计算
|
|
WPipe::PipeParam param1;
|
|
memcpy(¶m1, ¶m, sizeof(WPipe::PipeParam));
|
|
|
|
//添加变径
|
|
CAcModuleResourceOverride myResources;
|
|
CEReducerDlg redDlg;
|
|
redDlg.Set(&sqlDb, ¶m, vtDir);
|
|
param.m_vtECCen.set(0.0, 0.0, 0.0);
|
|
int nRes = redDlg.DoModal();
|
|
if (nRes == IDOK)
|
|
{
|
|
//结构长度
|
|
param1.m_dInterfaceL3 = param.m_dInterfaceL3;
|
|
|
|
if (_tcscmp(szKey, _T("V")) == 0)
|
|
{
|
|
WPipe::PipeParam *pParam = ¶m;
|
|
if (IsGSFMaterial(pParam->szMertialFit))
|
|
{
|
|
TDbPipeSupport::Query45ElbowL(&sqlDb, __max(param1.m_dDN, param.m_dDN), dL, pParam->m_dRRatio, pParam->m_nConnectType, pParam->szLevel, pParam->szODSn,&xd);
|
|
param1.m_dInterfaceL3 = dL;
|
|
param.m_dInterfaceL3 = dL;
|
|
}
|
|
else
|
|
{
|
|
TDbPipeSupport::QueryRElbowL(&sqlDb, __max(param1.m_dDN, param.m_dDN),__min(param1.m_dDN, param.m_dDN), dL,pParam->m_dRRatio, pParam->m_nConnectType, pParam->szLevel,&xd);
|
|
param1.m_dInterfaceL3 = dL;
|
|
param.m_dInterfaceL3 = dL;
|
|
}
|
|
}
|
|
|
|
TDbPipeJig jig;
|
|
jig.SetAdoDb(&sqlDb);
|
|
TDbPipeLine pipeLine(&jig);
|
|
pipeLine.SetInitDataMapPartFrom(pXDataMap);
|
|
pipeLine.SetPipeParam(¶m1);
|
|
|
|
inf.vtDir.normalize();
|
|
inf.ptPos += inf.vtDir * 0.5 * dGast;
|
|
|
|
pipeLine.PushInterface(inf);
|
|
|
|
AECStatusRecord rec;
|
|
rec.SetAcquirePoint(inf.ptPos);
|
|
|
|
if (pipeLine.AddReduceElbow(&rec, ¶m, vtDir, vtMin))
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|
|
pEnt->close();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
extern AECDLLIMPEXP bool SetDoubleClickEnt(LPCTSTR pszCmd, AcDbObjectId &id);
|
|
extern AECDLLIMPEXP bool GetDoubleClickEntNoReset(LPCTSTR pszCmd, AcDbObjectId &id);
|
|
void DBL_AEC_EWPIPE_SPEC()
|
|
{
|
|
AcDbObjectId id;
|
|
bool bIsOk = GetDoubleClickEntNoReset(_T("DBL_AEC_EWPIPE"), id);
|
|
|
|
if (bIsOk && id.isValid())
|
|
{
|
|
AcGePoint3d ptS;
|
|
AcGePoint3d ptE;
|
|
AcGeVector3d vt;
|
|
|
|
WPipe::PipeParam *pParam = NULL;
|
|
AcDbEntity *pEnt = NULL;
|
|
if (Acad::eOk == acdbOpenAcDbEntity(pEnt, id, AcDb::kForRead))
|
|
{
|
|
AecDbEwPipe *pPipe = AecDbEwPipe::cast(pEnt);
|
|
if (pPipe != NULL)
|
|
{
|
|
pParam = pPipe->GetPipeParam();
|
|
ptS = pPipe->StartPoint();
|
|
ptE = pPipe->EndPoint();
|
|
vt = ptE - ptS;
|
|
}
|
|
pEnt->close();
|
|
}
|
|
|
|
if (pParam != NULL)
|
|
{
|
|
if (pParam->nPIPCmd == 0 || _tcslen(pParam->szLevel) == 0)
|
|
{
|
|
SetDoubleClickEnt(_T("DBL_AEC_EWPIPE"), id);
|
|
acedPostCommand(_T("DBL_AEC_EWPIPE "));
|
|
return;
|
|
}
|
|
|
|
CString dbPath = FilePath::GetSysDir();
|
|
dbPath += _T("\\Plumbing.db");
|
|
|
|
CUIISQLiteServer *pADOServer = new CUIISQLiteServer;
|
|
if (!pADOServer->InitADOServer(dbPath))
|
|
{
|
|
AfxMessageBox(_T("数据库驱动加载数据库Plumbing.db失败!"));
|
|
return;
|
|
}
|
|
|
|
bool bIsXElPipe = false;
|
|
double dElOld = pParam->m_dEl;
|
|
|
|
AcGeLine3d ln(ptS, vt);
|
|
if (!ln.isParallelTo(AcGePlane::kXYPlane))
|
|
{
|
|
bIsXElPipe = true;
|
|
}
|
|
|
|
CAcModuleResourceOverride myResources;
|
|
|
|
CDJGXDlg drawCnfgDLg;
|
|
drawCnfgDLg.SetDbServer(pADOServer);
|
|
drawCnfgDLg.EnableLoadLast(FALSE);
|
|
drawCnfgDLg.SetShowParam(pParam);
|
|
drawCnfgDLg.LockEl(bIsXElPipe);//锁定标高
|
|
|
|
int nRes = drawCnfgDLg.DoModal();
|
|
if (nRes == IDOK)
|
|
{
|
|
WPipe::PipeParam param;
|
|
memset(¶m, 0, sizeof(WPipe::PipeParam));
|
|
drawCnfgDLg.GetPipeParam(¶m);
|
|
|
|
if (Acad::eOk == acdbOpenAcDbEntity(pEnt, id, AcDb::kForWrite))
|
|
{
|
|
AecDbEwPipe *pPipe = AecDbEwPipe::cast(pEnt);
|
|
if (pPipe != NULL)
|
|
{
|
|
pPipe->SetPipeParam(¶m);
|
|
// 不需要更新图层信息,设置管线系统时自动更新
|
|
//pPipe->SetLayerByXDataMap();
|
|
|
|
if (fabs(param.m_dEl - dElOld) > 1.e-2)//标高改动
|
|
{
|
|
//更新自身关联的套管.因为消息传递的处理是 //排除自身
|
|
//见 AecEwEditorReactor::TransformAssocInfMsg
|
|
//2023-6-1
|
|
AcGeVector3d vtOffset(0, 0, param.m_dEl - dElOld);
|
|
AcGeMatrix3d xM;
|
|
xM.setToTranslation(vtOffset);
|
|
pPipe->TransformHole(xM);
|
|
}
|
|
}
|
|
pEnt->close();
|
|
|
|
if (fabs(param.m_dEl - dElOld) > 1.e-2)//标高改动
|
|
{
|
|
//发送管口改动消息
|
|
AcGeVector3d vtOffset(0, 0, param.m_dEl - dElOld);
|
|
|
|
GripMessage msg;
|
|
//reset
|
|
msg.nSegindex = -1;
|
|
msg.nType = -1;
|
|
msg.idHost.setNull();
|
|
msg.pParam = 0;
|
|
msg.nData = -1;
|
|
_tcscpy(msg.szLockId, _T("0"));//锁定id,如果有
|
|
msg.fData = 0;
|
|
msg.nSegindex = 0;
|
|
msg.nSubSegIndex = 0;
|
|
msg.vtOffset.set(0, 0, 0);
|
|
msg.ptGrip.set(0, 0, 0);
|
|
|
|
msg.nType = eMid;
|
|
msg.nData = -1;
|
|
msg.idHost = id;
|
|
msg.vtOffset = vtOffset;
|
|
|
|
PushGripMessage(msg);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
DELETE_PTR(pParam);
|
|
}
|
|
}
|
|
|
|
void PP_TESTCmd()
|
|
{
|
|
AcDbVoidPtrArray arCurPtrs, arCurPtrs2,arRegnPtrs;
|
|
|
|
AcDbCircle *pCir = new AcDbCircle;
|
|
pCir->setCenter(AcGePoint3d(1000, 1000, 0));
|
|
pCir->setNormal(AcGeVector3d::kXAxis);
|
|
pCir->setRadius(259.0);
|
|
|
|
AcDbCircle *pCir2 = new AcDbCircle;
|
|
pCir2->setCenter(AcGePoint3d(1000, 1000, 0));
|
|
pCir2->setNormal(AcGeVector3d::kXAxis);
|
|
pCir2->setRadius(200.0);
|
|
|
|
arCurPtrs.append(pCir);
|
|
AcDbRegion *pRegion = NULL;
|
|
if (Acad::eOk == AcDbRegion::createFromCurves(arCurPtrs, arRegnPtrs))
|
|
{
|
|
pRegion = (AcDbRegion *)arRegnPtrs.first();
|
|
arRegnPtrs.removeAll();
|
|
|
|
arCurPtrs2.append(pCir2);
|
|
if (Acad::eOk == AcDbRegion::createFromCurves(arCurPtrs2, arRegnPtrs))
|
|
{
|
|
AcDbRegion *pRegionIn = (AcDbRegion *)arRegnPtrs.first();
|
|
arRegnPtrs.removeAll();
|
|
|
|
if (pRegion->booleanOper(AcDb::kBoolSubtract, pRegionIn) == Acad::eOk)
|
|
{
|
|
AcDbLine ln(AcGePoint3d(1000, 1000, 0), AcGePoint3d(80000, 1000, 0));
|
|
AcDb3dSolid *pSo = new AcDb3dSolid;
|
|
if (Acad::eOk == pSo->extrudeAlongPath(pRegion, &ln))
|
|
{
|
|
CoreTools::AddToModelSpace(pSo);
|
|
}
|
|
}
|
|
delete pRegion;
|
|
}
|
|
}
|
|
delete pCir;
|
|
delete pCir2;
|
|
}
|
|
|
|
|