Files
envi-code/SourceCode/Code2026/EarthWormCmd/AecPipeLineTool.cpp
T
2026-09-28 15:28:50 +08:00

1900 lines
43 KiB
C++

#include "stdafx.h"
#include "AecPipeLineTool.h"
#include "AecDbObjXDataMap.h"
#include "AecDbEwPipe.h"
#include "AecDbEwFitting.h"
#include "uiiado.h"
#include "UITools.h"
#include "AecDb3dRoadAxisLine.h"
#ifndef Plumbing_DB
#define Plumbing_DB _T("\\Plumbing.db")
#endif
extern void SortPoints(AcGePoint3dArray& points,AcDbCurve* pLine);
extern AcGePoint3d MidPoint(const AcGePoint3d& pt1,const AcGePoint3d& pt2);
extern Acad::ErrorStatus AddToModelSpace(AcDbEntity* pEnt,AcDbDatabase* pDb ,bool bClose );
double AecPipeLineTool::m_dRRato = 0.5;
AecPipeLineTool::AecPipeLineTool(void)
{
}
AecPipeLineTool::~AecPipeLineTool(void)
{
}
bool AecPipeLineTool::CreatePipe(AecDbEwPipe* pPipe,const AcGePoint3dArray& arPtsPath,AcDbVoidPtrArray& arPipePtrs,AcDbVoidPtrArray& arFittPtrs)
{
AecDb3dRoadAxisLine* pALine = new AecDb3dRoadAxisLine;
double dD = 0.0,dRatio =1.5;
pPipe->GetSpecialtyData()->GetAt(PIPE_DN,dD);
pPipe->GetSpecialtyData()->GetAt(PIPE_RATIO,dRatio);
if (m_dRRato > 1.0)
dRatio = m_dRRato;
if ( pALine->Create3dRoadAxisLine(dD,dRatio,arPtsPath) )
{
AecDbObjXDataMap* pMap = pPipe->GetSpecialtyData();
AecDbEwPipe* pPipeNew = NULL;
AecDbEwFitting* pElbow = NULL;
AcDbCurve* pCurve = NULL;
for (int i = 0;i < pALine->GetCurveSegCount();i++)
{
pCurve = pALine->GetCurveSeg(i);
AcDbLine* pLn = AcDbLine::cast(pCurve);
if (pLn != NULL)
{
pPipeNew = CreatePipe(pMap,pLn->startPoint(),pLn->endPoint());
if (pPipeNew != NULL)
{
arPipePtrs.append(pPipeNew);
}
}
AcDbArc* pArc = AcDbArc::cast(pCurve);
if (pArc != NULL)
{
pElbow = CreateElbow(pMap,pArc,dRatio);
if (pElbow != NULL)
{
arFittPtrs.append(pElbow);
}
}
}
}
DELETE_PTR(pALine);
return !arPipePtrs.isEmpty();
}
bool AecPipeLineTool::ElbowJoinHere(AecDbEwPipe* pPipe1,AecDbEwPipe* pPipe2)
{
if (pPipe1 == NULL || pPipe2 == NULL)
return false;
AcGePoint3d pt0 = pPipe1->StartPoint();
AcGePoint3d pt1 = pPipe1->EndPoint();
AcGePoint3d pt2 = pPipe2->StartPoint();
AcGePoint3d pt3 = pPipe2->EndPoint();
//首先约定管线是首尾连接
double dDist1= pt1.distanceTo(pt2);
if (dDist1 < 5.0)
return true;
dDist1 = pt3.distanceTo(pt0);
if (dDist1 < 5.0)
return true;
return false;
}
AecDbEwFitting* AecPipeLineTool::CreateElbow(AecDbObjXDataMap* pMap,AcDbArc* pArc,double dRRato)
{
if (pArc != NULL)
{
double dSta = 0.0;
double dEnd = 0.0;
pArc->getStartParam(dSta);
pArc->getEndParam(dEnd);
AcGeVector3d vtMaj,vtMin;
pArc->getFirstDeriv(dSta,vtMaj);
pArc->getFirstDeriv(dEnd,vtMin);
AcGePoint3d ptSta,ptEnd;
pArc->getStartPoint(ptSta);
pArc->getEndPoint(ptEnd);
AcDbXline ln1,ln2;
ln1.setBasePoint(ptSta);
ln1.setUnitDir(vtMaj);
ln2.setBasePoint(ptEnd);
ln2.setUnitDir(vtMin);
AcGePoint3dArray arPts;
ln1.intersectWith(&ln2,AcDb::kOnBothOperands,arPts);
if (!arPts.isEmpty())
{
AcGePoint3d ptMid = arPts.first();
vtMaj = ptSta - ptMid;
vtMin = ptEnd - ptMid;
AecDbEwFitting* pElbow = CreateElbow(pMap,vtMaj,vtMin,ptMid,dRRato);
if (pElbow != NULL)
{
return pElbow;
}
}
}
return NULL;
}
bool AecPipeLineTool::QueryTeeData(double dDn,double dDn2,double& dLen1,double& dLen2)
{
CUIISQLiteServer dbSQLite;
CString path = FilePath::GetSysDir() + Plumbing_DB;
if (!dbSQLite.InitADOServer(path))
{
AfxMessageBox(CString(_T("数据库初始化失败,请检查 sys")) + Plumbing_DB + _T("文件是否存在."));
return FALSE;
}
//查询三通尺寸
int nDn1 = (int)(dDn + 0.1);
int nDn2 = (int)(dDn2 + 0.1);
if (nDn1 < nDn2)//交换
{
acutPrintf(_T("\n三通主进口公称直径必须大于等于分支口公称直径!"));
return false;
}
CString sSQL;
sSQL.Format(_T("select [长度L],[长度S] from AecTeeData where [公称直径L]=%d AND [公称直径S]=%d"),nDn1,nDn2);
CStringArray arVals;
dbSQLite.GetSelData(sSQL,arVals);
if (arVals.IsEmpty())
{
//再从AecTeeData中查找
sSQL.Format(_T("select [结构长度] from AecTeeTData where [公称直径]=%d"),nDn1);
dbSQLite.GetSelData(sSQL,arVals);
if (arVals.IsEmpty())
{
sSQL.Format(_T("\n查不到公称直径为 %d 的三通结构尺寸!"),nDn1);
acutPrintf(sSQL);
return false;
}
else
{
dLen1 = AS_MUNIT(_ttof(arVals.GetAt(0)));
}
arVals.RemoveAll();
sSQL.Format(_T("select [结构长度] from AecTeeTData where [公称直径]=%d"),nDn2);
dbSQLite.GetSelData(sSQL,arVals);
if (arVals.IsEmpty())
{
sSQL.Format(_T("\n查不到公称直径为 %d 的三通结构尺寸!"),nDn2);
acutPrintf(sSQL);
return false;
}
else
{
dLen2 = AS_MUNIT(_ttof(arVals.GetAt(0)));
}
}
else
{
if (arVals.GetSize() >= 2)
{
dLen1 = AS_MUNIT(_ttof(arVals.GetAt(0)));
dLen2 = AS_MUNIT(_ttof(arVals.GetAt(1)));
}
}
return true;
}
AecDbEwPipe* AecPipeLineTool::CreatePipe(AecDbObjXDataMap* pMap,const AcGePoint3d& pt2,const AcGePoint3d& pt3)
{
AecDbEwPipe* pPipeNew = new AecDbEwPipe;
pPipeNew->GetSpecialtyData()->CopyFrom(pMap);
pPipeNew->SetBaseCurve(pt2,pt3);
double dDn = 0.0,dt = 0.0;
pMap->GetAt(PIPE_DN,dDn);
pMap->GetAt(PIPE_THICK,dt);
pPipeNew->SetSection(dDn,0.0);
return pPipeNew;
}
AecDbEwPipe* AecPipeLineTool::BreakPipe(AecDbEwPipe* pPipe1,AcGePoint3d& pt22,double dLen )
{
AcGePoint3d pt2;
pPipe1->getClosestPointTo(pt22,pt2,Adesk::kTrue);
if (pt22.distanceTo(pt2) < 1.e-3)//pt2落在pipe1上
{
AecInterface inf;
pPipe1->GetInterface(1,inf);
AcGeVector3d vtDir = inf.vtDir;//sta-->end
vtDir.normalize();
AcGePoint3d ptSta = pt22 - vtDir * 0.5 * dLen;
AcGePoint3d ptEnd = pt22 + vtDir * 0.5 * dLen;
pPipe1->SetEndPoint(ptSta);
AecDbEwPipe* pNewPipe = new AecDbEwPipe;
pNewPipe->GetSpecialtyData()->CopyFrom(pPipe1->GetSpecialtyData());
pNewPipe->SetBaseCurve(ptEnd,inf.ptPos);
double dDn = 0.0;
pPipe1->GetSpecialtyData()->GetAt(PIPE_DN,dDn);
pNewPipe->SetSection(dDn,0.0);
return pNewPipe;
}
return NULL;
}
AecDbEwPipe* AecPipeLineTool::PointOnPipeConnect(AecDbObjXDataMap* pMap,const AcGePoint3d& pt2,const AcGePoint3d& pt3,AecDbEwPipe* pPipe1,AecDbEwFitting*& pTee,AecDbEwPipe*& pPipeNew)
{
AcGePoint3d ptNewSta = pt2;
double dLen1 = 0.0,dLen2 = 0.0,dDn = 0.0,dDn1 = 0.0;
pMap->GetAt(PIPE_DN,dDn);
pPipe1->GetSpecialtyData()->GetAt(PIPE_DN,dDn1);
AcGePoint3d pt22;
pPipe1->getClosestPointTo(pt2,pt22,Adesk::kTrue);
if (pt22.distanceTo(pt2) < 1.e-3)//pt2落在pipe1上
{
if ( QueryTeeData(AS_M2MM(dDn1),AS_M2MM(dDn),dLen1,dLen2) )
{
double dInterfaceL = 0.0;
pPipe1->GetSpecialtyData()->GetAt(PIPE_INTERFACEL,dInterfaceL);
if (dInterfaceL > 1.e-3)//法兰管
{
dLen1 += dInterfaceL;
dLen2 += dInterfaceL;
}
AecInterface inf1;
pPipe1->GetInterface(1,inf1);
AcGeVector3d vtPipe1 = inf1.vtDir;
AcGeVector3d vtMin = pt3 - pt2;
pTee = new AecDbEwFitting;
pTee->GetSpecialtyData()->CopyFrom(pPipe1->GetSpecialtyData());
pTee->GetSpecialtyData()->SetAt(KEY_RUNTIME,eTee);
pTee->GetSpecialtyData()->SetAt(PIPE_DN,dDn1);
pTee->GetSpecialtyData()->SetAt(PIPE_TDN,dDn);
pTee->GetSpecialtyData()->SetAt(KEY_FITSRV,KEY_FITWPIPE);
pTee->GetSpecialtyData()->SetAt(KEY_MAJBR,vtPipe1);
pTee->GetSpecialtyData()->SetAt(KEY_MINBR,vtMin);
pTee->GetSpecialtyData()->SetAt(KEY_MID,pt22);
AcGeVector3d vtNro = vtMin.crossProduct(vtPipe1);
pTee->GetSpecialtyData()->SetAt(KEY_NORMAL,vtNro);
pTee->GetSpecialtyData()->SetAt(KEY_L,2.0 * dLen1 );
pTee->GetSpecialtyData()->SetAt(KEY_T,dLen2 );
AecInterface inf2;
pTee->GetInterface(2,inf2);
pPipeNew = CreatePipe(pMap,inf2.ptPos,pt3);
CopyPipeLayerAndLineTypeFromTo(pPipe1,pPipeNew);
return BreakPipe(pPipe1,pt22,2.0 * dLen1);
}
}
AcGePoint3d pt33;
pPipe1->getClosestPointTo(pt3,pt33,Adesk::kTrue);
if (pt3.distanceTo(pt33) < 1.e-3)//pt2落在pipe1上
{
if ( QueryTeeData(AS_M2MM(dDn1),AS_M2MM(dDn),dLen1,dLen2) )
{
double dInterfaceL = 0.0;
pPipe1->GetSpecialtyData()->GetAt(PIPE_INTERFACEL,dInterfaceL);
if (dInterfaceL > 1.e-3)//法兰管
{
dLen1 += dInterfaceL;
dLen2 += dInterfaceL;
}
AecInterface inf1;
pPipe1->GetInterface(1,inf1);
AcGeVector3d vtPipe1 = inf1.vtDir;
AcGeVector3d vtMin = pt2 - pt3;
pTee = new AecDbEwFitting;
pTee->GetSpecialtyData()->CopyFrom(pPipe1->GetSpecialtyData());
pTee->GetSpecialtyData()->SetAt(KEY_RUNTIME,eTee);
pTee->GetSpecialtyData()->SetAt(PIPE_DN,dDn1);
pTee->GetSpecialtyData()->SetAt(PIPE_TDN,dDn);
pTee->GetSpecialtyData()->SetAt(KEY_FITSRV,KEY_FITWPIPE);
pTee->GetSpecialtyData()->SetAt(KEY_MAJBR,vtPipe1);
pTee->GetSpecialtyData()->SetAt(KEY_MINBR,vtMin);
pTee->GetSpecialtyData()->SetAt(KEY_MID,pt33);
AcGeVector3d vtNro = vtMin.crossProduct(vtPipe1);
pTee->GetSpecialtyData()->SetAt(KEY_NORMAL,vtNro);
pTee->GetSpecialtyData()->SetAt(KEY_L,2.0 * dLen1 );
pTee->GetSpecialtyData()->SetAt(KEY_T,dLen2 );
AecInterface inf2;
pTee->GetInterface(2,inf2);
pPipeNew = CreatePipe(pMap,inf2.ptPos,pt2);
CopyPipeLayerAndLineTypeFromTo(pPipe1,pPipeNew);
return BreakPipe(pPipe1,pt33,2.0 * dLen1);
}
}
return NULL;
}
//创建管子时 自动判断连接是否加三通
AecDbEwPipe* AecPipeLineTool::CreatePipe(AecDbObjXDataMap* pMap,const AcGePoint3d& pt2,const AcGePoint3d& pt3,AecDbEwPipe* pPipe1,AecDbEwPipe* pPipe2,int nWeldType,AecDbEwFitting*& pTee,AecDbEwPipe*& pPipeOther)
{
//取最小
pPipeOther = NULL;
if (nWeldType == 1)//焊接连接
{
return CreatePipe(pMap,pt2,pt3);
}
AecDbEwPipe* pPipeNew = NULL;
//可能 和1 产生三通
if (pPipe1 != NULL && NULL != ( pPipeOther = PointOnPipeConnect(pMap,pt2,pt3,pPipe1,pTee,pPipeNew) ) )
{
return pPipeNew;
}
//可能 和2 产生三通
if (pPipe2 != NULL && NULL != ( pPipeOther = PointOnPipeConnect(pMap,pt2,pt3,pPipe2,pTee,pPipeNew) ) )
{
return pPipeNew;
}
return CreatePipe(pMap,pt2,pt3);
}
//创建弯头,vtMaj为背向管嘴的方向
AecDbEwFitting* AecPipeLineTool::CreateElbow(AecDbObjXDataMap* pMap,const AcGeVector3d& vtMaj,const AcGeVector3d& vtMin,const AcGePoint3d& ptMid,double dRRato)
{
AcGeVector3d vtMaj2 = vtMaj;
vtMaj2.negate();
AecDbEwFitting* pFit = new AecDbEwFitting;
pFit->GetSpecialtyData()->CopyFrom(pMap);
double dSweepAngle = vtMin.angleTo(vtMaj2);
AcGeVector3d vtNorm = vtMaj2.crossProduct(vtMin);
pFit->GetSpecialtyData()->SetAt(KEY_RUNTIME,eElbow);
pFit->GetSpecialtyData()->SetAt(PIPE_RATIO,dRRato);
pFit->GetSpecialtyData()->SetAt(PIPE_ELBOWANG,dSweepAngle);
pFit->GetSpecialtyData()->SetAt(KEY_FITSRV,KEY_FITWPIPE);
pFit->GetSpecialtyData()->SetAt(KEY_MAJBR,vtMaj2);
pFit->GetSpecialtyData()->SetAt(KEY_MINBR,vtMin);
pFit->GetSpecialtyData()->SetAt(KEY_NORMAL,vtNorm);
pFit->GetSpecialtyData()->SetAt(KEY_MID,ptMid);
return pFit;
}
AecDbEwFitting* AecPipeLineTool::CreateElbow(AecDbEwPipe* pPipe1,AecDbEwPipe* pPipe2,double dRRato)
{
if (pPipe1 == NULL || pPipe2 == NULL)
return NULL;
AcDbCurve* pCrv1 = pPipe1->GetBaseCurve();
AcDbCurve* pCrv2 = pPipe2->GetBaseCurve();
if (pCrv1->isKindOf(AcDbArc::desc()) || pCrv2->isKindOf(AcDbArc::desc()))
{
return NULL;
}
AcGeVector3d vt1 = pPipe1->EndPoint() - pPipe1->StartPoint();
AcGeVector3d vt2 = pPipe2->EndPoint() - pPipe2->StartPoint();
vt1.normalize();vt2.normalize();
AcGePoint3d ptSta1,ptEnd1;
ptSta1 = pPipe1->StartPoint();
ptEnd1 = pPipe1->EndPoint();
if (vt1.dotProduct(vt2) < -1.e-10)//方向相反
{
//修改pipe1的方向 reverse
pPipe1->SetStartPoint(ptEnd1);
pPipe1->SetEndPoint(ptSta1);
}
//角度非常小的情况下
AcGePoint3d ptMid;
AcGeTol tol;
tol.setEqualPoint(1.e-2);
tol.setEqualVector(1.e-2);
if (vt1.isParallelTo(vt2,tol))
{
ptMid = MidPoint(pPipe1->EndPoint(),pPipe2->StartPoint());
pPipe1->SetEndPoint(ptMid);
pPipe2->SetStartPoint(ptMid);
return NULL;
}
AcGePoint3dArray arPts;
AecInterface inf1,inf2;
AecInterface inf3,inf4;
arPts.removeAll();
AcGePlane plan;
AcGeVector3d vtNorm = vt2.crossProduct(vt1);
plan.set(ptEnd1,vtNorm);
pCrv1->intersectWith(pCrv2,AcDb::kExtendBoth,plan,arPts);
if (arPts.length() == 1)
{
ptMid = arPts.first();
//如果很小的角度,直接连接
double dAng = vt2.angleTo(vt1);
if (dAng - PI / 18.0 < 1.e-3 || dAng - 0.94 * PI > 1.e-3 )
{
pPipe1->SetEndPoint(ptMid);
pPipe2->SetStartPoint(ptMid);
DELETE_PTR(pCrv1);
DELETE_PTR(pCrv2);
return NULL;
}
pPipe1->GetInterface(1,inf1);
pPipe2->GetInterface(0,inf2);
AecDbEwFitting* pElbow = AecPipeLineTool::CreateElbow(pPipe1->GetSpecialtyData(),inf1.vtDir.negate(),inf2.vtDir.negate(),ptMid,dRRato);
if (pElbow != NULL)
{
pElbow->GetInterface(0,inf3);
pElbow->GetInterface(1,inf4);
if (inf3.vtDir.isParallelTo(inf1.vtDir) )
{
pPipe1->SetEndPoint(inf3.ptPos);
pPipe2->SetStartPoint(inf4.ptPos);
}
else
{
pPipe1->SetEndPoint(inf4.ptPos);
pPipe2->SetStartPoint(inf3.ptPos);
}
DELETE_PTR(pCrv1);
DELETE_PTR(pCrv2);
return pElbow;
}
}
DELETE_PTR(pCrv1);
DELETE_PTR(pCrv2);
return NULL;
}
bool AecPipeLineTool::GetIntersectPoint2(AcDbCurve* pCrv1,AcDbCurve* pCrv2,AcGePoint3d& pt2,const AcGePlane& plan)
{
if (pCrv1 == NULL || pCrv2 == NULL)
return false;
AcDbCurve* pProCrv1 = NULL;
AcDbCurve* pProCrv2 = NULL;
if (pCrv1 != NULL && pCrv2 != NULL)
{
pCrv1->getOrthoProjectedCurve(plan,pProCrv1);
pCrv2->getOrthoProjectedCurve(plan,pProCrv2);
if (pProCrv1 != NULL && pProCrv2 != NULL)
{
AcGePoint3dArray arPts;
pProCrv1->intersectWith(pProCrv2,AcDb::kOnBothOperands,arPts);
if (arPts.length() == 1)
{
DELETE_PTR(pProCrv1);
DELETE_PTR(pProCrv2);
pt2 = arPts.first();
return true;
}
else
{
//不实际相交,计算出延长相交点,返回false
pProCrv1->intersectWith(pProCrv2,AcDb::kExtendBoth,arPts);
if (arPts.length() == 1)
{
DELETE_PTR(pProCrv1);
DELETE_PTR(pProCrv2);
pt2 = arPts.first();
return false;
}
}
}
}
return false;
}
bool AecPipeLineTool::GetIntersectPoint(AecDbEwPipe* pPipe1,AecDbEwPipe* pPipe2,AcGePoint3d& pt2)
{
AecInterface inf0,inf2;
pPipe1->GetInterface(0,inf0);
pPipe2->GetInterface(1,inf2);
AcGeVector3d vtNorm = inf0.vtDir.crossProduct(inf2.vtDir);
AcGePlane plan;
plan.set(inf0.ptPos,vtNorm);
AcDbCurve* pCrv1 = pPipe1->GetBaseCurve();
AcDbCurve* pCrv2 = pPipe2->GetBaseCurve();
bool bRelt = GetIntersectPoint2(pCrv1,pCrv2,pt2,plan);
if (!bRelt)
{
acutPrintf(_T("\n选择的两个对象没有交集,管线连接失败!"));
}
DELETE_PTR(pCrv1);
DELETE_PTR(pCrv2);
return bRelt;
}
bool AecPipeLineTool::ConnectPipe1(AecDbEwPipe* pPipe1,AecDbEwPipe* pPipe2,int nWeldType,AcDbVoidPtrArray& arPipePtrs,AcDbVoidPtrArray& arFittPtrs)
{
if (pPipe1 == NULL || pPipe2 == NULL)
return false;
AecInterface inf0,inf2;
pPipe1->GetInterface(0,inf0);
pPipe2->GetInterface(1,inf2);
AcGePoint3d ptInt,pt1,pt3;
if (inf0.vtDir.isParallelTo(inf2.vtDir))//平行
{
//如果是共线
AcGeVector3d vtDir02 = inf2.ptPos - inf0.ptPos;
if (vtDir02.isParallelTo(inf0.vtDir))
{
//并且直径相同
double dDn1 = 0.0,dDn2 = 0.0;
pPipe1->GetSpecialtyData()->GetAt(PIPE_DN,dDn1);
pPipe2->GetSpecialtyData()->GetAt(PIPE_DN,dDn2);
if (fabs(dDn1 - dDn2) < 1.e-3)
{
//合成一根管子
AecInterface inf1;
pPipe1->GetInterface(1,inf1);
AecInterface inf3;
pPipe2->GetInterface(0,inf3);
AcGePoint3dArray arPts;
arPts.append(inf0.ptPos);
arPts.append(inf1.ptPos);
arPts.append(inf2.ptPos);
arPts.append(inf3.ptPos);
AcDbLine ln;
ln.setStartPoint(inf0.ptPos);
ln.setEndPoint(inf1.ptPos);
SortPoints(arPts,&ln);
pPipe1->SetStartPoint(arPts.first());
pPipe1->SetEndPoint(arPts.last());
pPipe2->GetSpecialtyData()->SetAt(_T("erase"),TRUE);
return true;
}
else
{
return false;
}
}
else
{
//取共有中点
AecInterface inf1,inf3;
pPipe1->GetInterface(1,inf1);
pPipe2->GetInterface(0,inf3);
AcDbLine ln(inf0.ptPos,inf1.ptPos);
ln.getClosestPointTo(inf2.ptPos,pt1,Adesk::kTrue);
ln.getClosestPointTo(inf3.ptPos,pt3,Adesk::kTrue);
AcGePoint3dArray arPts;
arPts.append(inf0.ptPos);
arPts.append(pt1);
arPts.append(pt3);
arPts.append(inf1.ptPos);
SortPoints(arPts,&ln);
if (arPts.at(1).distanceTo(arPts.at(2)) < 1.e-1)
{
//重合
return false;
}
ptInt = MidPoint(arPts.at(1),arPts.at(2));
}
}
else
{
double dDn1 = 0.0,dDn2 = 0.0,dt = 0.0;
pPipe1->GetSpecialtyData()->GetAt(PIPE_DN,dDn1);
pPipe2->GetSpecialtyData()->GetAt(PIPE_DN,dDn2);
AecDbObjXDataMap* pMap1 = pPipe1->GetSpecialtyData();
AecDbObjXDataMap* pMap2 = pPipe2->GetSpecialtyData();
//取最小
AecDbObjXDataMap* pMap = (dDn1 - dDn2 > 1.e-2) ? pMap2 : pMap1;
if ( !GetIntersectPoint(pPipe1,pPipe2,ptInt) )
{
pPipe2->getClosestPointTo(ptInt,pt3,Adesk::kTrue);
pPipe1->getClosestPointTo(ptInt,pt1,Adesk::kTrue);
double dParam = 0.0;
if (Acad::eOk == pPipe2->getParamAtPoint(pt3,dParam))//pipe2 上不延长,pipe1延长
{
}
else//pipe2 延长,互换为 pipe1延长
{
AecDbEwPipe* pPipeTmp = pPipe1;
pPipe1 = pPipe2;
pPipe2 = pPipeTmp;
AcGePoint3d ptTmp = pt1;
pt1 = pt3;
pt3 = ptTmp;
}
AcGeVector3d vtMaj = pPipe1->EndPoint() - pt1;
vtMaj.normalize();
AcGeVector3d vtMin = pt3 - pt1;
vtMin.normalize();
double dRRato = 1.5;
pMap2->GetAt(PIPE_RATIO,dRRato);
if (dRRato < 1.e-1)
{
dRRato = 1.5;
}
if (m_dRRato > 1.0)
dRRato = m_dRRato;
AecDbEwFitting* pElbow = CreateElbow(pMap,vtMaj,vtMin,pt1,dRRato);
if (pElbow != NULL)
{
arFittPtrs.append(pElbow);
AecInterface inf1,inf2;
pElbow->GetInterface(0,inf1);
pElbow->GetInterface(1,inf2);
AcGePoint3d pt1,pt31;
if (inf1.vtDir.isParallelTo(vtMaj))
{
pt1 = inf1.ptPos;
pt31 = inf2.ptPos;
}
else
{
pt1 = inf2.ptPos;
pt31 = inf1.ptPos;
}
AcGePoint3d ptEnd = pPipe1->EndPoint();
AcGePoint3d ptSta = pPipe1->StartPoint();
if (pt1.distanceTo(ptSta) < pt1.distanceTo(ptEnd))
{
pPipe1->SetStartPoint(pt1);
}
else
{
pPipe1->SetEndPoint(pt1);
}
AecDbEwPipe* pPipeNew = CreatePipe(pMap,pt3,pt31);
if (pPipeNew != NULL)
{
arPipePtrs.append(pPipeNew);
}
}
return true;
}
}
AecDbObjXDataMap* pMap2 = pPipe2->GetSpecialtyData();
//if (nWeldType == 1)//焊接连接
{
//最小直径管
pPipe2->getClosestPointTo(ptInt,pt3,Adesk::kTrue);
pPipe1->getClosestPointTo(ptInt,pt1,Adesk::kTrue);
//AecDbEwPipe* pPipeNew = CreatePipe(pMap2,pt2,pt3);
AecDbEwPipe* pPipeOther = NULL;
AecDbEwFitting* pNewTee = NULL;
AecDbEwPipe* pPipeNew = CreatePipe(pMap2,pt1,pt3,pPipe1,pPipe2,nWeldType,pNewTee,pPipeOther);
if (nWeldType == 1)
{
if (pPipeNew != NULL)
{
CopyPipeLayerAndLineTypeFromTo(pPipe1,pPipeNew);
arPipePtrs.append(pPipeNew);
return true;
}
}
if (pPipeOther != NULL)
{
arPipePtrs.append(pPipeOther);
}
if (pNewTee != NULL)
{
arFittPtrs.append(pNewTee);
}
if (pPipeNew != NULL && pNewTee != NULL)
{
pPipeOther = NULL;
pNewTee->GetInterface(2,inf2);
pNewTee = NULL;
AecDbEwPipe* pPipeNew2 = CreatePipe(pMap2,inf2.ptPos,pt3,pPipe1,pPipe2,nWeldType,pNewTee,pPipeOther);
if (pPipeNew2 != NULL)
{
CopyPipeLayerAndLineTypeFromTo(pPipe1,pPipeNew2);
arPipePtrs.append(pPipeNew2);
}
if (pPipeOther != NULL)
{
arPipePtrs.append(pPipeOther);
}
if (pNewTee != NULL)
{
arFittPtrs.append(pNewTee);
}
}
}
return true;
}
bool AecPipeLineTool::ConnectPipe2(AecDbEwPipe* pPipe1,AecDbEwPipe* pPipe2,int nWeldType,int nOffsetDir,double dOffset,AcDbVoidPtrArray& arPipePtrs,AcDbVoidPtrArray& arFittPtrs)
{
if (pPipe1 == NULL || pPipe2 == NULL)
return false;
AecInterface inf0,inf2;
pPipe1->GetInterface(0,inf0);
pPipe2->GetInterface(1,inf2);
AcGePoint3d pt2;
pPipe2->getClosestPointTo(inf0.ptPos,pt2,Adesk::kTrue);
if (pt2.distanceTo(inf0.ptPos) < 1.e-1)
{
acutPrintf(_T("\n两管距离太近!无法连接"));
return false;
}
if (inf0.vtDir.isParallelTo(inf2.vtDir))//平行
{
//直接连接
return ConnectPipe1(pPipe1,pPipe2,nWeldType,arPipePtrs,arFittPtrs);
}
else
{
//求交
AcGePoint3d ptInt,pt1,pt2;
if ( !GetIntersectPoint(pPipe1,pPipe2,ptInt) )
{
return false;
}
pPipe1->getClosestPointTo(ptInt,pt1,Adesk::kTrue);
pPipe2->getClosestPointTo(ptInt,pt2,Adesk::kTrue);
AcGeVector3d vtZ = pt2 - pt1;
AcGeVector3d vtZbk = vtZ;
vtZ.normalize();
AcGeVector3d vtMove = pPipe1->EndPoint() - pPipe1->StartPoint();
vtMove.normalize();
vtMove *= dOffset;
int nDir = nOffsetDir == 0 ? 1 : -1;
vtMove *= nDir;
pt1 += vtMove;
//if (nWeldType == 1) //焊接
{
AecDbObjXDataMap* pMap2 = pPipe2->GetSpecialtyData();
//取曲率半径
double dRRato = 1.5;
pMap2->GetAt(PIPE_RATIO,dRRato);
if (dRRato < 1.e-1)
{
dRRato = 1.5;
}
if (m_dRRato > 1.0)
dRRato = m_dRRato;
double dt = 0.0;
double dDn = 0.0;
double dDist = vtZbk.length();
pMap2->GetAt(PIPE_DN,dDn);
pMap2->GetAt(PIPE_THICK,dt);
dDist -= dRRato * 0.5 * dDn;
if ( dDist < 1.e-1)
{
//距离太小,只能直连
return ConnectPipe1(pPipe1,pPipe2,nWeldType,arPipePtrs,arFittPtrs);
}
AcGePoint3d ptEnd = pt1 + vtZ * dDist;
/*
AecDbEwPipe* pPipeNew = CreatePipe(pMap2,pt1,ptEnd);
if (pPipeNew != NULL)
{
arPipePtrs.append(pPipeNew);
}*/
AecDbEwPipe* pPipeOther = NULL;
AecDbEwFitting* pNewTee = NULL;
AecDbEwPipe* pPipeNew = CreatePipe(pMap2,pt1,ptEnd,pPipe1,pPipe2,nWeldType,pNewTee,pPipeOther);
if (pPipeNew != NULL)
{
CopyPipeLayerAndLineTypeFromTo(pPipe1,pPipeNew);
arPipePtrs.append(pPipeNew);
}
if (pPipeOther != NULL)
{
arPipePtrs.append(pPipeOther);
}
if (pNewTee != NULL)
{
arFittPtrs.append(pNewTee);
}
//创建弯头
AcGePoint3d ptE = pt1 + vtZbk;
AcGePoint3d ptE1;
pPipe2->getClosestPointTo(ptE,ptE1,Adesk::kTrue);
AcGeVector3d vtMaj = ptE1 - ptE;
vtMaj.normalize();
AecDbEwFitting* pElbow = CreateElbow(pMap2,vtMaj,vtZ.negate(),ptE,dRRato);
if (pElbow != NULL)
{
arFittPtrs.append(pElbow);
}
ptEnd = ptE + vtMaj * dRRato * 0.5 * dDn;
/*pPipeNew = CreatePipe(pMap2,ptE1,ptEnd);
if (pPipeNew != NULL)
{
arPipePtrs.append(pPipeNew);
}*/
pPipeOther = NULL;
pNewTee = NULL;
pPipeNew = CreatePipe(pMap2,ptE1,ptEnd,pPipe1,pPipe2,nWeldType,pNewTee,pPipeOther);
if (pPipeNew != NULL)
{
CopyPipeLayerAndLineTypeFromTo(pPipe1,pPipeNew);
arPipePtrs.append(pPipeNew);
}
if (pPipeOther != NULL)
{
arPipePtrs.append(pPipeOther);
}
if (pNewTee != NULL)
{
arFittPtrs.append(pNewTee);
}
}
}
return true;
}
bool AecPipeLineTool::ConnectPipe3(AecDbEwPipe* pPipe1,AecDbEwPipe* pPipe2,int nWeldType,double dZSWeepAngle,int nOffsetDir,double dOffset,AcDbVoidPtrArray& arPipePtrs,AcDbVoidPtrArray& arFittPtrs)
{
if (pPipe1 == NULL || pPipe2 == NULL)
return false;
AecInterface inf0,inf2;
pPipe1->GetInterface(0,inf0);
pPipe2->GetInterface(1,inf2);
AcGePoint3d pt2;
pPipe2->getClosestPointTo(inf0.ptPos,pt2,Adesk::kTrue);
if (pt2.distanceTo(inf0.ptPos) < 1.e-1)
{
acutPrintf(_T("\n两管距离太近!无法连接"));
return false;
}
if (inf0.vtDir.isParallelTo(inf2.vtDir))//平行
{
//直接连接
return ConnectPipe1(pPipe1,pPipe2,nWeldType,arPipePtrs,arFittPtrs);
}
else
{
//求交
AcGePoint3d ptInt,pt1,pt2;
if ( !GetIntersectPoint(pPipe1,pPipe2,ptInt) )
{
return false;
}
pPipe1->getClosestPointTo(ptInt,pt1,Adesk::kTrue);
pPipe2->getClosestPointTo(ptInt,pt2,Adesk::kTrue);
AcGeVector3d vtZ = pt2 - pt1;
AcGeVector3d vtMove = pPipe1->EndPoint() - pPipe1->StartPoint();
vtMove.normalize();
vtMove *= dOffset;
int nDir = nOffsetDir == 0 ? 1 : -1;
vtMove *= nDir;
AcGePoint3d ptFr = pt1 + vtMove;
//弯头中心点
AcGePoint3d ptMid = ptFr + 0.5 * vtZ;
AcGePoint3d pt22;
pPipe2->getClosestPointTo(ptMid,pt22,Adesk::kTrue);
double dDn1 = 0.0,dDn2 = 0.0,dt = 0.0;
pPipe1->GetSpecialtyData()->GetAt(PIPE_DN,dDn1);
pPipe2->GetSpecialtyData()->GetAt(PIPE_DN,dDn2);
AecDbObjXDataMap* pMap1 = pPipe1->GetSpecialtyData();
AecDbObjXDataMap* pMap2 = pPipe2->GetSpecialtyData();
//取最小
AecDbObjXDataMap* pMap = (dDn1 - dDn2 > 1.e-2) ? pMap2 : pMap1;
//取曲率半径
double dRRato = 1.5;
pMap->GetAt(PIPE_RATIO,dRRato);
if (dRRato < 1.e-1)
{
dRRato = 1.5;
}
if (m_dRRato > 1.0)
dRRato = m_dRRato;
AcGeVector3d vtMin = pt22 - ptMid;
AecDbEwFitting* pElbow = CreateElbow(pMap,-vtZ,vtMin,ptMid,dRRato);
if (pElbow != NULL)
{
arFittPtrs.append(pElbow);
//创建两个直管
AecInterface inf1,inf3;
pElbow->GetInterface(0,inf1);
pElbow->GetInterface(1,inf3);
if (inf1.vtDir.isParallelTo(vtZ))
{
/*AecDbEwPipe* pPipeNew = CreatePipe(pMap,ptFr,inf1.ptPos);
if (pPipeNew != NULL)
{
arPipePtrs.append(pPipeNew);
}*/
AecDbEwPipe* pPipeOther = NULL;
AecDbEwFitting* pNewTee = NULL;
AecDbEwPipe* pPipeNew = CreatePipe(pMap,ptFr,inf1.ptPos,pPipe1,pPipe2,nWeldType,pNewTee,pPipeOther);
if (pPipeNew != NULL)
{
CopyPipeLayerAndLineTypeFromTo(pPipe1,pPipeNew);
arPipePtrs.append(pPipeNew);
}
if (pPipeOther != NULL)
{
arPipePtrs.append(pPipeOther);
}
if (pNewTee != NULL)
{
arFittPtrs.append(pNewTee);
}
/*pPipeNew = CreatePipe(pMap,inf3.ptPos,pt22);
if (pPipeNew != NULL)
{
arPipePtrs.append(pPipeNew);
}*/
pPipeOther = NULL;
pPipeNew = NULL;
pNewTee = NULL;
pPipeNew = CreatePipe(pMap,inf3.ptPos,pt22,pPipe1,pPipe2,nWeldType,pNewTee,pPipeOther);
if (pPipeNew != NULL)
{
CopyPipeLayerAndLineTypeFromTo(pPipe1,pPipeNew);
arPipePtrs.append(pPipeNew);
}
if (pPipeOther != NULL)
{
arPipePtrs.append(pPipeOther);
}
if (pNewTee != NULL)
{
arFittPtrs.append(pNewTee);
}
}
else
{
/*AecDbEwPipe* pPipeNew = CreatePipe(pMap,ptFr,inf3.ptPos);
if (pPipeNew != NULL)
{
arPipePtrs.append(pPipeNew);
}
*/
AecDbEwPipe* pPipeOther = NULL;
AecDbEwFitting* pNewTee = NULL;
AecDbEwPipe* pPipeNew = CreatePipe(pMap,ptFr,inf3.ptPos,pPipe1,pPipe2,nWeldType,pNewTee,pPipeOther);
if (pPipeNew != NULL)
{
CopyPipeLayerAndLineTypeFromTo(pPipe1,pPipeNew);
arPipePtrs.append(pPipeNew);
}
if (pPipeOther != NULL)
{
arPipePtrs.append(pPipeOther);
}
if (pNewTee != NULL)
{
arFittPtrs.append(pNewTee);
}
/*
pPipeNew = CreatePipe(pMap,inf1.ptPos,pt22);
if (pPipeNew != NULL)
{
arPipePtrs.append(pPipeNew);
}*/
pPipeOther = NULL;
pPipeNew = NULL;
pNewTee = NULL;
pPipeNew = CreatePipe(pMap,inf1.ptPos,pt22,pPipe1,pPipe2,nWeldType,pNewTee,pPipeOther);
if (pPipeNew != NULL)
{
CopyPipeLayerAndLineTypeFromTo(pPipe1,pPipeNew);
arPipePtrs.append(pPipeNew);
}
if (pPipeOther != NULL)
{
arPipePtrs.append(pPipeOther);
}
if (pNewTee != NULL)
{
arFittPtrs.append(pNewTee);
}
}
}
}
return true;
}
bool AecPipeLineTool::ConnectPipe4(AecDbEwPipe* pPipe1,AecDbEwPipe* pPipe2,int nWeldType,int nOffsetDir,double dOffset,double dTopSpace,AcDbVoidPtrArray& arPipePtrs,AcDbVoidPtrArray& arFittPtrs)
{
if (pPipe1 == NULL || pPipe2 == NULL)
return false;
AecInterface inf0,inf2;
pPipe1->GetInterface(0,inf0);
pPipe2->GetInterface(1,inf2);
AcGePoint3d pt2;
pPipe2->getClosestPointTo(inf0.ptPos,pt2,Adesk::kTrue);
if (pt2.distanceTo(inf0.ptPos) < 1.e-1)
{
acutPrintf(_T("\n两管距离太近!无法连接"));
return false;
}
if (inf0.vtDir.isParallelTo(inf2.vtDir))//平行
{
//直接连接
return ConnectPipe1(pPipe1,pPipe2,nWeldType,arPipePtrs,arFittPtrs);
}
else
{
double dDn1 = 0.0,dDn2 = 0.0,dt = 0.0;
pPipe1->GetSpecialtyData()->GetAt(PIPE_DN,dDn1);
pPipe2->GetSpecialtyData()->GetAt(PIPE_DN,dDn2);
AecDbObjXDataMap* pMap1 = pPipe1->GetSpecialtyData();
AecDbObjXDataMap* pMap2 = pPipe2->GetSpecialtyData();
//取最小
AecDbObjXDataMap* pMap = (dDn1 - dDn2 > 1.e-2) ? pMap2 : pMap1;
//取曲率半径
double dRRato = 1.5;
pMap->GetAt(PIPE_RATIO,dRRato);
if (dRRato < 1.e-1)
{
dRRato = 1.5;
}
if (m_dRRato > 1.0)
dRRato = m_dRRato;
AcGePoint3d pt00,pt11;
pPipe1->getStartPoint(pt00);
pPipe2->getStartPoint(pt11);
//求交
AcGePoint3d ptInt,pt1,pt2;
if ( !GetIntersectPoint(pPipe1,pPipe2,ptInt) )
{
return false;
}
pPipe1->getClosestPointTo(ptInt,pt1,Adesk::kTrue);
pPipe2->getClosestPointTo(ptInt,pt2,Adesk::kTrue);
AcGeVector3d vtZ = pt2 - pt1;
AcGeVector3d vtMove = pPipe1->EndPoint() - pPipe1->StartPoint();
vtMove.normalize();
vtMove *= dOffset;
int nDir = nOffsetDir == 0 ? 1 : -1;
vtMove *= nDir;
AcGePoint3d ptFr = pt1 + vtMove;
AcGeVector3d vtZn = vtZ;
vtZn.normalize();
AcGePoint3d ptTo = ptFr + vtZ;
AcGePoint3d ptE;
pPipe2->getClosestPointTo(ptTo,ptE);
AcGeVector3d vtMin = ptE - ptTo;
ptTo += vtZn * dTopSpace;
//创建两个90弯头
AcGePoint3d ptMid = ptTo;
AcGeVector3d vtMaj = vtZn.negate();
AecDbEwFitting* pElbow = CreateElbow(pMap,vtMaj,vtMin,ptMid,dRRato);
if (pElbow != NULL)
{
//LEFT
arFittPtrs.append(pElbow);
AecInterface infE1,infE2;
pElbow->GetInterface(0,infE1);
pElbow->GetInterface(1,infE2);
AcGePoint3d ptHSta;
AcGePoint3d ptEnd;
if (infE1.vtDir.isParallelTo(vtZn))
{
ptEnd = infE1.ptPos;
ptHSta = infE2.ptPos;
}
else
{
ptEnd = infE2.ptPos;
ptHSta = infE1.ptPos;
}
/*
AecDbEwPipe* pPipe = CreatePipe(pMap,ptFr,ptEnd);
if (pPipe != NULL)
{
arPipePtrs.append(pPipe);
}*/
AecDbEwPipe* pPipeOther = NULL;
AecDbEwFitting* pNewTee = NULL;
AecDbEwPipe* pPipeNew = CreatePipe(pMap,ptFr,ptEnd,pPipe1,pPipe2,nWeldType,pNewTee,pPipeOther);
if (pPipeNew != NULL)
{
CopyPipeLayerAndLineTypeFromTo(pPipe1,pPipeNew);
arPipePtrs.append(pPipeNew);
}
if (pPipeOther != NULL)
{
arPipePtrs.append(pPipeOther);
}
if (pNewTee != NULL)
{
arFittPtrs.append(pNewTee);
}
//Right
vtZn.negate();
AcGePoint3d ptMid2 = ptE + dTopSpace * vtZn;
AcGeVector3d vtMaj2 = vtMin;
vtMaj2.negate();
AcGeVector3d vtMin2 = vtMaj;
pElbow = CreateElbow(pMap,vtMaj2,vtMin2,ptMid2,dRRato);
if (pElbow != NULL)
{
arFittPtrs.append(pElbow);
//水平管子
AcGePoint3d ptVSta;
AcGePoint3d ptHEnd;
pElbow->GetInterface(0,infE1);
pElbow->GetInterface(1,infE2);
if (infE1.vtDir.isParallelTo(vtZn))
{
ptHEnd = infE2.ptPos;
ptVSta = infE1.ptPos;
}
else
{
ptHEnd = infE1.ptPos;
ptVSta = infE2.ptPos;
}
pPipeNew = CreatePipe(pMap,ptHSta,ptHEnd);
if (pPipeNew != NULL)
{
CopyPipeLayerAndLineTypeFromTo(pPipe1,pPipeNew);
arPipePtrs.append(pPipeNew);
}
/*
pPipe = CreatePipe(pMap,ptVSta,ptE);
if (pPipe != NULL)
{
arPipePtrs.append(pPipe);
}*/
pPipeOther = NULL;
pPipeNew = NULL;
pNewTee = NULL;
pPipeNew = CreatePipe(pMap,ptVSta,ptE,pPipe1,pPipe2,nWeldType,pNewTee,pPipeOther);
if (pPipeNew != NULL)
{
CopyPipeLayerAndLineTypeFromTo(pPipe1,pPipeNew);
arPipePtrs.append(pPipeNew);
}
if (pPipeOther != NULL)
{
arPipePtrs.append(pPipeOther);
}
if (pNewTee != NULL)
{
arFittPtrs.append(pNewTee);
}
}
}
}
return true;
}
bool AecPipeLineTool::ConnectPipe(AecDbEwPipe* pPipe1,AecDbEwPipe* pPipe2,int nType,int nWeldType,int nOffsetDir,
double dOffset,double dTopSpace,double dZSWeepAngle,double dRRato,
AcDbVoidPtrArray& arPipePtrs,AcDbVoidPtrArray& arFittPtrs)
{
if (pPipe1 == NULL || pPipe2 == NULL)
return false;
m_dRRato = dRRato;
double dDn1 = 0.0,dDn2 = 0.0;
pPipe1->GetSpecialtyData()->GetAt(PIPE_DN,dDn1);
pPipe2->GetSpecialtyData()->GetAt(PIPE_DN,dDn2);
AecDbEwPipe* pPipe11,* pPipe22 = NULL;
pPipe11 = (dDn1 - dDn2 > -1.e-10) ? pPipe1 : pPipe2;
pPipe22 = (pPipe11 == pPipe1) ? pPipe2 : pPipe1;
bool bSuess = false;
switch(nType)
{
case 0://立管直连
{
bSuess = ConnectPipe1(pPipe11,pPipe22,nWeldType,arPipePtrs,arFittPtrs);
break;
}
case 1://侧向连接
{
bSuess = ConnectPipe2(pPipe11,pPipe22,nWeldType,nOffsetDir,dOffset,arPipePtrs,arFittPtrs);
break;
}
case 2://斜弯连接
{
bSuess = ConnectPipe3(pPipe11,pPipe22,nWeldType,dZSWeepAngle,nOffsetDir,dOffset,arPipePtrs,arFittPtrs);
break;
}
case 3://上弯连接
{
bSuess = ConnectPipe4(pPipe11,pPipe22,nWeldType,nOffsetDir,dOffset,dTopSpace,arPipePtrs,arFittPtrs);
break;
}
default:
break;
}
return bSuess ;
}
bool AecPipeLineTool::PipeExit(AecDbEwPipe* pPipeMaj,double dOD,double dDn,double dt,int nWeldType,const AecInterface& infTo,AcDbVoidPtrArray& arPipePtrs,AcDbVoidPtrArray& arFittPtrs)
{
//测试infto
AcDbXline* pRay = new AcDbXline;
pRay->setBasePoint(infTo.ptPos);
pRay->setUnitDir(infTo.vtDir);
pRay->setColorIndex(1);
/*AddToModelSpace(pRay,NULL,true);*/
AecDbObjXDataMap* pMap = new AecDbObjXDataMap;
pMap->CopyFrom(pPipeMaj->GetSpecialtyData());
double dRato = 1.5;
pPipeMaj->GetSpecialtyData()->GetAt(PIPE_RATIO,dRato);
if (dRato < 1.0)
dRato = 1.5;
if (m_dRRato > 1.0)
dRato = m_dRRato;
pMap->SetAt(PIPE_DN,dDn);
pMap->SetAt(PIPE_OD,dOD);
pMap->SetAt(PIPE_THICK,dt);
AcDbCurve* pCurve1 = pPipeMaj->GetBaseCurve();
AecInterface inf0,inf2;
pPipeMaj->GetInterface(0,inf0);
pPipeMaj->GetInterface(1,inf2);
AcGeVector3d vtNorm = infTo.vtDir.crossProduct(inf2.vtDir);
AcGePlane plan;
plan.set(inf0.ptPos,vtNorm);
AcGePoint3d ptMid;
AcGePoint3d ptInt;
AcGeVector3d vtMaj,vtMin;
AecDbEwFitting* pFitting = NULL;
if (inf0.vtDir.isParallelTo(infTo.vtDir))//平行
{
pCurve1->getClosestPointTo(infTo.ptPos,ptInt,Adesk::kTrue);
AcGeVector3d vtT = ptInt - infTo.ptPos;
AcGeVector3d vtT2 = vtT.orthoProject(AcGeVector3d::kZAxis);
//只处理平行XY面的特殊情况
AcGeLine3d ln3d;
ln3d.set(infTo.ptPos,infTo.vtDir);
AcGeLine3d ln3d2;
ln3d2.set(inf0.ptPos,inf0.vtDir);
if (AcGePlane::kXYPlane.isParallelTo( ln3d ) &&
AcGePlane::kXYPlane.isParallelTo( ln3d2))
{
vtMaj = vtT2;
vtMin = infTo.vtDir;
ptMid = infTo.ptPos - infTo.vtDir * dRato * 0.5 * dDn;
pFitting = CreateElbow(pMap,vtMaj,vtMin,ptMid,dRato);
if (pFitting != NULL)
{
arFittPtrs.append(pFitting);
}
AecInterface inf11,inf13,infT;
pFitting->GetInterface(0,inf11);
pFitting->GetInterface(1,inf13);
AcDbXline xln;
if (inf11.vtDir.isParallelTo(vtMaj))
{
xln.setBasePoint(inf11.ptPos);
}
else
{
xln.setBasePoint(inf13.ptPos);
pFitting->GetInterface(1,inf11);
pFitting->GetInterface(0,inf13);
}
xln.setUnitDir(vtMaj);
AcGePoint3d ptMid2;
pCurve1->getClosestPointTo(ptMid,ptMid2,Adesk::kTrue);
AcGePoint3d ptMid3;
xln.getClosestPointTo(ptMid2,ptMid3);
//创建弯头
vtMaj.negate();
vtMin = ptMid2 - ptMid3;
vtMin.normalize();
pFitting = CreateElbow(pMap,vtMaj,vtMin,ptMid3,dRato);
if (pFitting != NULL)
{
arFittPtrs.append(pFitting);
}
AecInterface inf21,inf23;
pFitting->GetInterface(0,inf21);
pFitting->GetInterface(1,inf23);
if (inf21.vtDir.isParallelTo(inf11.vtDir))
{
AecDbEwPipe* pPipeNew2 = CreatePipe(pMap,inf21.ptPos,inf11.ptPos);
if (pPipeNew2 != NULL)
{
CopyPipeLayerAndLineTypeFromTo(pPipeMaj,pPipeNew2);
arPipePtrs.append(pPipeNew2);
}
pPipeNew2 = CreatePipe(pMap,inf23.ptPos,ptMid2);
if (pPipeNew2 != NULL)
{
CopyPipeLayerAndLineTypeFromTo(pPipeMaj,pPipeNew2);
arPipePtrs.append(pPipeNew2);
}
}
else if(inf23.vtDir.isParallelTo(inf11.vtDir))
{
AecDbEwPipe* pPipeNew2 = CreatePipe(pMap,inf23.ptPos,inf11.ptPos);
if (pPipeNew2 != NULL)
{
CopyPipeLayerAndLineTypeFromTo(pPipeMaj,pPipeNew2);
arPipePtrs.append(pPipeNew2);
}
pPipeNew2 = CreatePipe(pMap,inf21.ptPos,ptMid2);
if (pPipeNew2 != NULL)
{
CopyPipeLayerAndLineTypeFromTo(pPipeMaj,pPipeNew2);
arPipePtrs.append(pPipeNew2);
}
}
return true;
}
double dOffset = dRato * 2.0 * dDn;
ptInt -= dOffset * infTo.vtDir;
}
else
{
if (!GetIntersectPoint2(pCurve1,pRay,ptInt,plan) )
{
return false;
}
}
pRay->getClosestPointTo(ptInt,ptMid,Adesk::kTrue);
AcGePoint3d ptFr;
pPipeMaj->getClosestPointTo(ptInt,ptFr,Adesk::kTrue);
//先创建一弯头
vtMaj = ptFr - ptMid;
vtMin = infTo.vtDir;
pFitting = CreateElbow(pMap,vtMaj,vtMin,ptMid,dRato);
if (pFitting != NULL)
{
arFittPtrs.append(pFitting);
}
AecInterface inf1,inf3;
pFitting->GetInterface(0,inf1);
pFitting->GetInterface(1,inf3);
AcGePoint3d ptVFr = inf1.ptPos;
AcGePoint3d ptTo = inf3.ptPos;
if (inf1.vtDir.isParallelTo(vtMaj))
{
ptTo = inf1.ptPos;
ptVFr = inf3.ptPos;
}
AecDbEwPipe* pPipeOther = NULL;
AecDbEwFitting* pTee = NULL;
AecDbEwPipe* pPipeNew = CreatePipe(pMap,ptTo,ptFr,pPipeMaj,NULL,nWeldType,pTee,pPipeOther);
if (pPipeNew != NULL)
{
CopyPipeLayerAndLineTypeFromTo(pPipeMaj,pPipeNew);
arPipePtrs.append(pPipeNew);
}
if (pPipeOther != NULL)
{
arPipePtrs.append(pPipeOther);
}
if (pTee != NULL)
{
arFittPtrs.append(pTee);
}
//创建竖管
ptTo = infTo.ptPos;
double dDis1 = ptTo.distanceTo(ptVFr);
double dDis2 = ptMid.distanceTo(ptVFr);
AcGeVector3d vt1 = ptTo - ptMid;
AcGeVector3d vt2 = ptVFr - ptMid;
if ( !vt1.isCodirectionalTo(vt2) )
{
//elbow 改向
int nPos = arFittPtrs.find(pFitting);
if (nPos != -1)
{
arFittPtrs.removeAt(nPos);
DELETE_PTR(pFitting);
}
vtMin.negate();
pFitting = CreateElbow(pMap,vtMaj,vtMin,ptMid,dRato);
if (pFitting != NULL)
{
arFittPtrs.append(pFitting);
pFitting->GetInterface(0,inf1);
pFitting->GetInterface(1,inf3);
ptVFr = inf1.ptPos;
if (inf1.vtDir.isParallelTo(vtMaj))
{
ptVFr = inf3.ptPos;
}
}
}
pPipeNew = CreatePipe(pMap,ptVFr,ptTo);
if (pPipeNew != NULL)
{
CopyPipeLayerAndLineTypeFromTo(pPipeMaj,pPipeNew);
arPipePtrs.append(pPipeNew);
}
DELETE_PTR(pCurve1);
DELETE_PTR(pRay);
DELETE_PTR(pMap);
return !arPipePtrs.isEmpty();
}
bool AecPipeLineTool::UShapeAoid(AecDbEwPipe* pPipe,AcGeVector3d& vtOffset,double dFrom,double dL,double dVSpace,double dAngle,double dAngleB,AcDbVoidPtrArray& arPipePtrs,AcDbVoidPtrArray& arFittPtrs)
{
if (pPipe == NULL) return false;
double dLen = pPipe->EndPoint().distanceTo(pPipe->StartPoint());
if (dFrom + dL - dLen > -1.e-10)
{
acutPrintf(_T("原管线避让超出总长,创建U型避让失败!"));
return false;
}
AcGeVector3d vtPipe = pPipe->EndPoint() - pPipe->StartPoint();
vtPipe.normalize();
AcGePoint3d ptFr = pPipe->StartPoint() + vtPipe * dFrom;
AcGePoint3d ptMid = ptFr + vtPipe * 0.5 * dL;
AecDbEwPipe* pPipeNew = AecPipeLineTool::BreakPipe(pPipe,ptMid,dL);
if (pPipeNew != NULL)
{
arPipePtrs.append(pPipeNew);
}
double dRAngle = dAngle * PI / 180.0;
double dRAngleB = dAngleB * PI / 180.0;
AcGeVector3d vtMaj = vtPipe;
vtMaj.negate();
AcGeVector3d vtMin = vtPipe;
AcGeVector3d vtNorm = vtOffset.crossProduct(vtPipe);
vtMin.rotateBy(-dRAngle,vtNorm);
if (vtMin.dotProduct(vtOffset) < -1.e-10)
vtMin.negate();
double dRatio = 1.5;
pPipe->GetSpecialtyData()->GetAt(PIPE_RATIO,dRatio);
if (m_dRRato > 1.0)
dRatio = m_dRRato;
double dDN = 0.0;
pPipe->GetSpecialtyData()->GetAt(PIPE_DN,dDN);
double dR = dRatio * 0.5 * dDN;
double dLx = dR * tan(dRAngle / 2.0);
AcGePoint3d ptMidE = ptFr + vtPipe * dLx;
AecDbObjXDataMap* pMap = pPipe->GetSpecialtyData();
AecDbEwFitting* pElbow1 = CreateElbow(pMap,vtMaj,vtMin,ptMidE,dRatio);
if (pElbow1 != NULL)
{
arFittPtrs.append(pElbow1);
}
vtOffset.normalize();
AcGePoint3d ptMid2 = ptMid + vtOffset * dVSpace;
AcDbXline xLn1;
xLn1.setBasePoint(ptMid2);
xLn1.setUnitDir(vtPipe);
AcDbXline xln2;
xln2.setBasePoint(ptMidE);
xln2.setUnitDir(vtMin);
AcGePoint3dArray arPts;
xLn1.intersectWith(&xln2,AcDb::kOnBothOperands,arPts);
if (!arPts.isEmpty())
{
AcGePoint3d ptMid3 = arPts.first();
vtMaj = vtMin;
vtMaj.negate();
vtMin = vtPipe;
vtMin.normalize();
AecDbEwFitting* pElbow2 = CreateElbow(pMap,vtMaj,vtMin,ptMid3,dRatio);
if (pElbow2 != NULL)
{
arFittPtrs.append(pElbow2);
}
AecInterface inf0,inf1;
pElbow1->GetInterface(0,inf0);
pElbow1->GetInterface(1,inf1);
AcGePoint3d ptFr1 = inf0.ptPos;
if (vtMaj.isParallelTo(inf1.vtDir))
ptFr1 = inf1.ptPos;
pElbow2->GetInterface(0,inf0);
pElbow2->GetInterface(1,inf1);
AcGePoint3d ptFr3 = inf1.ptPos;
AcGePoint3d ptTo1 = inf0.ptPos;
if (vtMaj.isParallelTo(inf1.vtDir))
{
ptTo1 = inf1.ptPos;
ptFr3 = inf0.ptPos;
}
AecDbEwPipe* pPipeL = CreatePipe(pMap,ptFr1,ptTo1);
if (pPipeL != NULL)
{
arPipePtrs.append(pPipeL);
}
//镜像
if ( fabs(dAngle - dAngleB) < 1.e-3)
{
AcGeLine3d ln;
ln.set(ptMid2,vtOffset);
AcGeMatrix3d xformMirror;
xformMirror.setToMirroring(ln);
AecDbEwFitting* pElbowR1 = (AecDbEwFitting*)pElbow1->clone();
if (pElbowR1 != NULL)
{
pElbowR1->TransformBy(xformMirror);
arFittPtrs.append(pElbowR1);
}
AecDbEwFitting* pElbowR2 = (AecDbEwFitting*)pElbow2->clone();
if (pElbowR2 != NULL)
{
pElbowR2->TransformBy(xformMirror);
arFittPtrs.append(pElbowR2);
}
AecDbEwPipe* pPipeR = (AecDbEwPipe*)pPipeL->clone();
if (pPipeR != NULL)
{
pPipeR->TransformBy(xformMirror);
arPipePtrs.append(pPipeR);
}
//中间管子
pElbow2->GetInterface(0,inf0);
pElbow2->GetInterface(1,inf1);
ptFr1 = inf0.ptPos;
if (vtPipe.isParallelTo(inf1.vtDir))
{
ptFr1 = inf1.ptPos;
}
ptTo1 = ptFr1;
ptTo1.transformBy(xformMirror);
AecDbEwPipe* pPipeOff = CreatePipe(pMap,ptFr1,ptTo1);
if (pPipeOff != NULL)
{
arPipePtrs.append(pPipeOff);
}
}
else
{
AcGePoint3d ptMidE2 = ptMid + vtPipe * 0.5 * dL;
dLx = dR * tan(dRAngleB / 2.0);
AcGePoint3d ptFr2 = ptMidE2;
ptMidE2 -= vtPipe * dLx;
vtMin = vtPipe;
vtMin.rotateBy(-PI+dRAngleB,vtNorm);
if (vtMin.dotProduct(vtOffset) < -1.e-10)
vtMin.negate();
vtMaj = vtPipe;
AecDbEwFitting* pElbow3 = CreateElbow(pMap,vtMaj,vtMin,ptMidE2,dRatio);
if (pElbow3 != NULL)
{
arFittPtrs.append(pElbow3);
}
pElbow3->GetInterface(0,inf0);
pElbow3->GetInterface(1,inf1);
AcGePoint3d ptTmp;
if (inf0.vtDir.isParallelTo(vtPipe))
{
vtMin = inf1.vtDir;
ptTmp = inf1.ptPos;
}
else
{
vtMin = inf0.vtDir;
ptTmp = inf0.ptPos;
}
vtMin.negate();
AcDbXline xl1;
xl1.setBasePoint(ptFr3);
xl1.setUnitDir(vtPipe);
AcDbXline xl2;
xl2.setBasePoint(ptTmp);
xl2.setUnitDir(vtMin);
arPts.removeAll();
xl1.intersectWith(&xl2,AcDb::kOnBothOperands,arPts);
if (!arPts.isEmpty())
{
AcGePoint3d ptMidE3 = arPts.first();
AcDbCircle* pCir3 = new AcDbCircle(ptMidE3,AcGeVector3d::kZAxis,0.5);
pCir3->setColorIndex(2);
AddToModelSpace(pCir3,NULL,true);
vtMaj = vtPipe;
vtMaj.negate();
AecDbEwFitting* pElbow4 = CreateElbow(pMap,vtMaj,vtMin,ptMidE3,dRatio);
if (pElbow4 != NULL)
{
arFittPtrs.append(pElbow4);
}
pElbow4->GetInterface(0,inf0);
pElbow4->GetInterface(1,inf1);
AcGePoint3d ptTmpFr;
AcGePoint3d ptTo2;
if (inf0.vtDir.isParallelTo(vtMin))
{
ptTmpFr = inf0.ptPos;
ptTo2 = inf1.ptPos;
}
else
{
ptTmpFr = inf1.ptPos;
ptTo2 = inf0.ptPos;
}
AecDbEwPipe* pPipeL1 = CreatePipe(pMap,ptFr3,ptTo2);
if (pPipeL1 != NULL)
{
arPipePtrs.append(pPipeL1);
}
AecDbEwPipe* pPipeL2 = CreatePipe(pMap,ptTmpFr,ptTmp);
if (pPipeL2 != NULL)
{
arPipePtrs.append(pPipeL2);
}
}
}
}
return !arPipePtrs.isEmpty();
}
void AecPipeLineTool::CopyPipeLayerAndLineTypeFromTo(AecDbEwPipe* pPipe1,AecDbEwPipe* pPipe2)
{
if (pPipe1 == NULL || pPipe2 == NULL)
return;
pPipe2->SetSingleLayer(pPipe1->GetSingleLayer());
pPipe2->SetDoubleLayer(pPipe1->GetDoubleLayer());
pPipe2->setLayer(pPipe1->layerId());
pPipe2->setLinetype(pPipe1->linetypeId());
}