1558 lines
45 KiB
C++
1558 lines
45 KiB
C++
// DbPump.cpp: implementation of the TDbPump class.
|
|
//
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#include "stdafx.h"
|
|
#include "DbPump.h"
|
|
#include "DbPipe.h"
|
|
#include "dbray.h"
|
|
|
|
// 根据块id和 旋转角度dAngle 创建新的块
|
|
AcDbObjectId CreateNewBlkRecord(const AcDbObjectId &idBlk, double dAngle, const CString &strNewName)
|
|
{
|
|
AcDbObjectId idBlock;
|
|
AcDbBlockTable *pBlkTbl = NULL;
|
|
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl, AcDb::kForWrite);
|
|
if (pBlkTbl != NULL)
|
|
{
|
|
if (pBlkTbl->has(strNewName)) // 块存在
|
|
{
|
|
pBlkTbl->getAt(strNewName, idBlock);
|
|
}
|
|
else
|
|
{
|
|
AcDbBlockTableRecord *pNewRec = new AcDbBlockTableRecord;
|
|
pNewRec->setName(strNewName);
|
|
pBlkTbl->add(idBlock, pNewRec);
|
|
AcDbBlockReference *pRef = new AcDbBlockReference(AcGePoint3d::kOrigin, idBlk);
|
|
AcGeMatrix3d mat;
|
|
mat.setToRotation(dAngle, AcGeVector3d::kZAxis, AcGePoint3d::kOrigin);
|
|
pRef->transformBy(mat);
|
|
AcDbVoidPtrArray ptrArr;
|
|
pRef->explode(ptrArr);
|
|
for (int i = 0; i < ptrArr.length(); i++)
|
|
{
|
|
AcDbEntity *pEnt = (AcDbEntity*)ptrArr[i];
|
|
AcDbEntity *pNewEnt = (AcDbEntity*)pEnt->clone();
|
|
if(pNewEnt != NULL)
|
|
{
|
|
pNewRec->appendAcDbEntity(pNewEnt);
|
|
pNewEnt->close();
|
|
}
|
|
}
|
|
delete pRef;
|
|
pNewRec->close();
|
|
}
|
|
|
|
pBlkTbl->close();
|
|
}
|
|
|
|
return idBlock;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Construction/Destruction
|
|
//////////////////////////////////////////////////////////////////////
|
|
ACRX_DXF_DEFINE_MEMBERS(ATSPump, ATSEquipment, AcDb::kDHL_CURRENT,
|
|
AcDb::kMReleaseCurrent, 1, ATS_PUMP,
|
|
"ATS_PUMP图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com");
|
|
IMPLEMENT_TENTBASE(TDbPump);
|
|
|
|
const Adesk::UInt8 TDbPump::g_nVersion = 2;
|
|
extern Acad::ErrorStatus DrawPolyMesh(XPoint ptS, XPoint ptE, double nRadius, XExplodeDraw &dc);
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Construction/Destruction
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
TDbPump::TDbPump()
|
|
{
|
|
m_visibility=TPipeSys::kVisible;
|
|
m_bHidePipe = TRUE;
|
|
m_nQ = 0; // 流量
|
|
m_nRaise = 0; // 扬程
|
|
m_nPower = 0; // 功率
|
|
m_nLength = 1; // 基座长
|
|
m_nWidth = 1; // 基座宽
|
|
m_nHeight = 1; // 基座高
|
|
m_sSpec = _T(""); // 型号
|
|
SetEquipmentType(3); // cet 2014.12.2 设备类型
|
|
}
|
|
|
|
void TDbPump::CopyPropertiesFrom(AcDbEntity *pSrc,unsigned gMatchFlag)
|
|
{
|
|
assertWriteEnabled();
|
|
TDbEquipment::CopyPropertiesFrom(pSrc, gMatchFlag);
|
|
}
|
|
|
|
Acad::ErrorStatus TDbPump::subGetClassID(CLSID* pClsid) const
|
|
{
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus
|
|
TDbPump::subGetOsnapPoints(AcDb::OsnapMode osnapMode,
|
|
INT_PTR gsSelectionMark,
|
|
const AcGePoint3d& ptPick,
|
|
const AcGePoint3d& lastPoint,
|
|
const AcGeMatrix3d& viewXform,
|
|
AcGePoint3dArray& snapPoints,
|
|
AcDbIntArray& geomIds) const
|
|
{
|
|
Acad::ErrorStatus es=Acad::eOk;
|
|
es=TDbEquipment::subGetOsnapPoints(osnapMode,gsSelectionMark,
|
|
ptPick,lastPoint,viewXform,snapPoints,geomIds);
|
|
|
|
if (osnapMode == AcDb::kOsModeIns || osnapMode == AcDb::kOsModeCen)
|
|
{
|
|
snapPoints.append(m_ptLocation);
|
|
}
|
|
|
|
AcDbVoidPtrArray arEnts;
|
|
AcDbVoidPtrArray arBlocks;
|
|
AcDbBlockReference *pBlock = NULL;
|
|
|
|
this->explode(arEnts);
|
|
//第一次炸碎成图块
|
|
for (int j = 0; j < arEnts.length(); ++j)
|
|
{
|
|
pBlock = AcDbBlockReference::cast((AcDbEntity*)arEnts[j]);
|
|
if (pBlock != NULL)
|
|
break;
|
|
}
|
|
|
|
if (pBlock != NULL)
|
|
{
|
|
//第二次炸碎图块
|
|
pBlock->explode(arBlocks);
|
|
for (int i = 0; i < arBlocks.length(); ++i)
|
|
{
|
|
AcDbEntity *pEnt = (AcDbEntity*)arBlocks[i];
|
|
pEnt->getOsnapPoints(osnapMode, gsSelectionMark, ptPick, lastPoint,
|
|
viewXform, snapPoints, geomIds);
|
|
}
|
|
}
|
|
|
|
ReleaseEntSet(arEnts);
|
|
ReleaseEntSet(arBlocks);
|
|
|
|
// snapPoints.append(m_ptLocation);
|
|
return es;
|
|
}
|
|
|
|
// 从DWG读入数据:
|
|
Acad::ErrorStatus TDbPump::dwgInFields(AcDbDwgFiler* pFiler)
|
|
{
|
|
assertWriteEnabled();
|
|
Acad::ErrorStatus es = TDbEquipment::dwgInFields(pFiler);
|
|
if(es != Acad::eOk) return es;
|
|
Adesk::UInt8 nVer;
|
|
pFiler->readItem(&nVer);
|
|
ReadString(pFiler, m_sSpec);
|
|
ReadString(pFiler, m_sBlockFront);
|
|
ReadString(pFiler, m_sBlockLeft);
|
|
ReadString(pFiler, m_sSpare);
|
|
pFiler->readItem(&m_nQ);
|
|
pFiler->readItem(&m_nRaise);
|
|
pFiler->readItem(&m_nPower);
|
|
pFiler->readItem(&m_nLength);
|
|
pFiler->readItem(&m_nWidth);
|
|
pFiler->readItem(&m_nSpare);
|
|
return pFiler->filerStatus();
|
|
}
|
|
|
|
Acad::ErrorStatus TDbPump::dwgOutFields(AcDbDwgFiler* pFiler) const
|
|
{
|
|
assertReadEnabled();
|
|
Acad::ErrorStatus es = TDbEquipment::dwgOutFields(pFiler);
|
|
if(es != Acad::eOk) return es;
|
|
pFiler->writeItem(g_nVersion);
|
|
pFiler->writeItem((const TCHAR *)m_sSpec);
|
|
pFiler->writeItem((const TCHAR *)m_sBlockFront);
|
|
pFiler->writeItem((const TCHAR *)m_sBlockLeft);
|
|
pFiler->writeItem((const TCHAR *)m_sSpare);
|
|
pFiler->writeItem(m_nQ);
|
|
pFiler->writeItem(m_nRaise);
|
|
pFiler->writeItem(m_nPower);
|
|
pFiler->writeItem(m_nLength);
|
|
pFiler->writeItem(m_nWidth);
|
|
pFiler->writeItem(m_nSpare);
|
|
return pFiler->filerStatus();
|
|
}
|
|
|
|
Acad::ErrorStatus TDbPump::dxfInFields(AcDbDxfFiler* pFiler)
|
|
{
|
|
assertWriteEnabled();
|
|
Acad::ErrorStatus es=Acad::eOk;
|
|
es=TDbEquipment::dxfInFields(pFiler);
|
|
return es;
|
|
}
|
|
|
|
Acad::ErrorStatus TDbPump::dxfOutFields(AcDbDxfFiler* pFiler) const
|
|
{
|
|
Acad::ErrorStatus es=Acad::eOk;
|
|
es=TDbEquipment::dxfOutFields(pFiler);
|
|
return es;
|
|
}
|
|
|
|
Acad::ErrorStatus TDbPump::subGetGripPoints(AcGePoint3dArray& gripPoints,
|
|
AcDbIntArray& osnapModes,
|
|
AcDbIntArray& geomIds) const
|
|
{
|
|
assertReadEnabled();
|
|
Acad::ErrorStatus es = Acad::eOk;
|
|
// es = TDbPipeNode::getGripPoints(gripPoints, osnapModes, geomIds); // cet 2010.5.14 del
|
|
es = TDbPipeNode::subGetGripPoints(gripPoints, osnapModes, geomIds); // cet 2010.5.14 add
|
|
if(es != Acad::eOk)
|
|
{
|
|
return es;
|
|
}
|
|
|
|
gripPoints.append((AcGePoint3d)m_ptInsert);
|
|
gripPoints.append((AcGePoint3d)m_ptLocation);
|
|
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus TDbPump::subMoveGripPointsAt(const AcDbIntArray& indices,
|
|
const AcGeVector3d& offset)
|
|
{
|
|
assertWriteEnabled();
|
|
Acad::ErrorStatus es = Acad::eOk;
|
|
|
|
if (indices.length() == 2)
|
|
{
|
|
TDbEquipment::subMoveGripPointsAt(indices,offset); // cet 2016.4.7 modify 拖动中心点崩溃
|
|
AcGeMatrix3d mat;
|
|
mat.setToTranslation(offset);
|
|
|
|
for (int i = 0; i < m_lstInterface.Length(); ++i)
|
|
{
|
|
m_lstInterface[i]->m_ptLocation.TransformBy(mat);
|
|
}
|
|
}
|
|
|
|
es = MoveGSPointsAt(indices, offset);
|
|
|
|
return es;
|
|
}
|
|
|
|
Acad::ErrorStatus TDbPump::GetGripText(int idx, CString &cs) const
|
|
{
|
|
Acad::ErrorStatus es = Acad::eOk;
|
|
|
|
CString sDes;
|
|
if(idx >= 0 && idx < m_lstInterface.Length())
|
|
{
|
|
const TPipeInterface& iFace = m_lstInterface[idx];
|
|
CString csLabel = TString(iFace.m_sSysLabel).cs();
|
|
cs = _T("接口") + csLabel;
|
|
|
|
if (iFace.m_idPipe.isValid() && !iFace.m_idPipe.isErased())
|
|
sDes = _T("(已连接管线)");
|
|
else
|
|
sDes = _T("(无管连接)");
|
|
|
|
cs += sDes;
|
|
}
|
|
else
|
|
{
|
|
cs = _T("移动设备");
|
|
}
|
|
|
|
return es;
|
|
}
|
|
|
|
Acad::ErrorStatus TDbPump::MoveGSPointsAt(const AcDbIntArray& indices,
|
|
const AcGeVector3d& offset)
|
|
{
|
|
AcGeMatrix3d mat;
|
|
mat.setToTranslation(offset);
|
|
int nNodeGrip = TDbPipeNode::GetGripNumber();
|
|
int nThisGrip = GetGripNumber();
|
|
int nCount = indices.length();
|
|
for(int i = 0; i < nCount; i++)
|
|
{
|
|
if(indices[i] >= nThisGrip)
|
|
{
|
|
continue;
|
|
}
|
|
if(indices[i] == nNodeGrip)
|
|
{
|
|
m_ptLocation.TransformBy(mat);
|
|
for(int j = 0; j < m_lstInterface.Length(); j++)
|
|
{
|
|
TPipeInterface &iFace = *m_lstInterface[j];
|
|
iFace.m_ptLocation.TransformBy(mat);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus TDbPump::ExplodeOrDraw3d(XExplodeDraw &dc) const
|
|
{
|
|
//AcGeScale3d scale(1, 1, 1); // cet 2009.12.17 del
|
|
AcGeScale3d scale(m_nLength, m_nWidth, m_nLength); // cet 2009.12.17 add
|
|
OPENOBJ_BEGIN(m_idBlock3d, AcDb::kForRead, AcDbBlockTableRecord, pBlock);
|
|
if(pBlock) {
|
|
XVector3D vtNormal(0,0,1);
|
|
if(fabs(m_vtDirection.z)>1.0E-6) { //非水平面,计算法向
|
|
vtNormal = XVector3D(1,0,0)*m_vtDirection;
|
|
vtNormal.Normalize();
|
|
}
|
|
XPoint ptLoc=Wcs2Ecs(m_ptLocation, vtNormal);
|
|
double nRotEcs = ads_angle(XPoint(),m_vtDirection); //计算ECS下的转角
|
|
|
|
AcDbBlockReference insert(ptLoc, m_idBlock3d);
|
|
insert.setRotation(nRotEcs);
|
|
insert.setScaleFactors(scale);
|
|
if(_tcscmp(dc.Desc(), XAcGiViewDraw::Descriptor())==0) {
|
|
AcGeMatrix3d mat=insert.blockTransform();
|
|
AcGiGeometry *geom=((XAcGiViewDraw &)dc).GetCommonDraw()->rawGeometry();
|
|
geom->pushModelTransform(mat);
|
|
geom->draw(pBlock);
|
|
geom->popModelTransform();
|
|
DrawPipeInterface(dc); //cet add 2009.12.15
|
|
} else if(_tcscmp(dc.Desc(), XExplodeStream::Descriptor())==0)
|
|
{
|
|
((XExplodeStream &)dc).Append((AcDbEntity *)insert.clone());
|
|
}
|
|
} else {
|
|
return Acad::eInvalidInput;
|
|
}
|
|
OPENOBJ_END();
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus TDbPump::ExplodeOrDraw2d(XExplodeDraw &dc) const
|
|
{
|
|
// cet 2016.10.17 add 图层关闭时,实体不显示,不进行绘制(打印时,也不会绘制)
|
|
AcDbLayerTableRecordPointer player(this->layerId(), AcDb::kForRead);
|
|
if (player.openStatus() == Acad::eOk && player->isOff())
|
|
{
|
|
return Acad::eOk;
|
|
}
|
|
if(!m_idBlock2d.isValid())
|
|
return Acad::eInvalidInput;
|
|
|
|
AcGeScale3d scale(m_nLength, m_nWidth, m_nHeight);
|
|
|
|
if(fabs(m_vtDirection.x)<1.0E-6 && fabs(m_vtDirection.y)<1.0E-6)
|
|
return Acad::eOk; //垂直设备
|
|
|
|
OPENOBJ_BEGIN(m_idBlock2d, AcDb::kForRead, AcDbBlockTableRecord, pBlock);
|
|
if(pBlock) {
|
|
XPoint ptInsert=m_ptInsert;
|
|
// cet 2011.8.29 modify
|
|
// double dAngle = ads_angle(XPoint(),m_vtDirection);
|
|
double dAngle = ads_angle(XPoint(),Wcs2Ucs(m_vtDirection, TRUE));
|
|
dAngle = Ucs2Wcs(dAngle);
|
|
|
|
// BOOL bNewMethod=(g_nAcadVer>15.0001 && g_bMakeBlock);
|
|
// sg add 091105,强制打印时,不使用新方法
|
|
// if (_tcscmp(dc.Desc(), XAcGiViewDraw::Descriptor())==0 && dc.IsPlotGeneration())
|
|
// bNewMethod = FALSE;
|
|
|
|
// dc.DrawBlock(*pBlock,ptInsert,scale,dAngle,bNewMethod);
|
|
|
|
dc.DrawBlock(*pBlock,ptInsert,scale,dAngle,TRUE);
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
draw2Line(dc); //绘制二维水泵的法栏
|
|
|
|
return Acad::eOk;
|
|
}
|
|
|
|
double TDbPump::GetWidth(const TDbPipePrototype* pPipe) const
|
|
{
|
|
AcGeScale3d scale(m_nLength, m_nWidth, m_nHeight);
|
|
double dWidth=m_nWidth/2;
|
|
|
|
if(m_idBlock2d.isValid()) {// 二维图块
|
|
AcDbExtents extents;
|
|
AcDbBlockReference insert(AcGePoint3d(0,0,0), m_idBlock2d);
|
|
insert.setScaleFactors(scale);
|
|
if(insert.geomExtentsBestFit(extents)==Acad::eOk) {
|
|
XPoint ptMax = extents.maxPoint();
|
|
XPoint ptMin = extents.minPoint();
|
|
dWidth = (ptMax.x-ptMin.x)/2;// 第一次求得的宽度值
|
|
|
|
if(pPipe!=NULL && pPipe->Is(CURVE_LINE)) { // 仅考虑直线管段
|
|
XPoint ptPosition = insert.position();
|
|
XPoint ptPlus = m_ptInsert-ptPosition;
|
|
|
|
XPoint ptLocation=m_ptLocation;
|
|
XRectAngle rect(ptMin+ptPlus,ptMax+ptPlus);
|
|
XLine line=(XLine)*pPipe;
|
|
|
|
double dAngle=CT_std_angle(ads_angle(XPoint(),m_vtDirection));
|
|
if(fabs(dAngle)>1.0E-6) {
|
|
ads_matrix mat;
|
|
m_ptInsert.GetRotationMatrix(-dAngle,mat);
|
|
line.TransformBy(mat);
|
|
ptLocation.TransformBy(mat);
|
|
}
|
|
|
|
rect.SetElevation(0);
|
|
line.SetElevation(0);
|
|
ptLocation.z=0;
|
|
|
|
int nFlag = ptLocation▭
|
|
if(nFlag != PR_INSIDE) {
|
|
dWidth = 0;
|
|
} else {
|
|
XPoint ptIntersect;
|
|
if(rect.Intersection(line,ptIntersect)){
|
|
dWidth=ptLocation.Distance(ptIntersect);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return dWidth;
|
|
}
|
|
|
|
void TDbPump::GetTips(DList<TObjInfoUnit> &info) const
|
|
{
|
|
info.Append(new TObjInfoUnit(_T("对象类型"), _T("水泵")));
|
|
|
|
info.Append(new TObjInfoUnit(_T("水泵型号"), m_sSpec));
|
|
info.Append(new TObjInfoUnit(_T("进水管标高"), XString(_T("%.3f"), m_nPower)));
|
|
info.Append(new TObjInfoUnit(_T("出水管标高"), XString(_T("%.3f"), m_nSpare)));
|
|
|
|
}
|
|
|
|
// 判断节点是否可以连接管段. nPos: 0--start; 1--end
|
|
BOOL TDbPump::CanLinkSide(const AcDbObjectId &idPipe, int nPos) const
|
|
{
|
|
//cet 2009.12.11 del
|
|
// BOOL bRet=FALSE;
|
|
// OPENOBJ_BEGIN(idPipe, AcDb::kForRead, TDbPipePrototype, pPipe);
|
|
// if(pPipe) {
|
|
// XPoint ptRef = nPos? pPipe->EndPoint() : pPipe->StartPoint();
|
|
// ptRef.z = 0;
|
|
// XPoint ptLoc=GetLocation();
|
|
// ptLoc.z = 0;
|
|
// if(ptRef.Distance(ptLoc)<PS_SNAP)
|
|
// bRet = TRUE;
|
|
// }
|
|
// OPENOBJ_END();
|
|
// return bRet;
|
|
|
|
//cet 2009.12.11 add
|
|
//得到管线
|
|
BOOL bRet=FALSE;
|
|
XPoint ptS, ptE;
|
|
TDbPipePrototype *pPipe = NULL;
|
|
acdbOpenObject(pPipe, idPipe, AcDb::kForRead);
|
|
if(pPipe)
|
|
{
|
|
ptS = pPipe->StartPoint();
|
|
ptE = pPipe->EndPoint();
|
|
BOOL bVertical = pPipe->IsVertical(); // cet 2010.7.22 add
|
|
pPipe->close();
|
|
|
|
if (bVertical) // cet 2010.7.22 add 不处理立管情况
|
|
{
|
|
return FALSE;
|
|
}
|
|
|
|
ptS.z = 0;
|
|
ptE.z = 0;
|
|
XPoint ptRef = nPos? ptE : ptS;
|
|
|
|
for (int i = 0; i < m_lstInterface.Length(); ++i)
|
|
{
|
|
XPoint ptFit = GetILocation(i);
|
|
ptFit.z = 0;
|
|
if (ptRef.Distance(ptFit)<PS_SNAP)
|
|
{
|
|
bRet = TRUE;
|
|
}
|
|
}
|
|
|
|
if (!bRet)
|
|
{
|
|
XLine line(ptS, ptE);
|
|
line.SetLineFlag(1);
|
|
|
|
//求得炸碎的实体
|
|
AcArray<XCurveSegment, AcArrayObjectCopyReallocator<XCurveSegment> > arSegs;
|
|
GetExplodeCurves(this->objectId(),arSegs);
|
|
|
|
//判断是否连接
|
|
XPoint ptCon;
|
|
bRet = CheckIsConnect(ptRef,arSegs,line,ptCon);
|
|
}
|
|
}
|
|
|
|
return bRet;
|
|
}
|
|
|
|
|
|
// 对st类型的接口进行重新连接
|
|
void TDbPump::UpdateLinkage(const XPoint &ptAt,
|
|
TPipeSys::SysType st,
|
|
const DList<AcDbObjectId> &idPipes)
|
|
{
|
|
//cet 2009.12.11 del
|
|
// assertWriteEnabled();
|
|
// RemoveInterface(st);
|
|
// XPoint ptLoc = m_ptLocation;
|
|
// ptLoc.z = 0;
|
|
// double nRadius = GetScale() * GetPScale();
|
|
// for(int i=0; i<idPipes.Length(); i++) {
|
|
// const AcDbObjectId &id=idPipes[i];
|
|
// OPENOBJ_BEGIN(id, AcDb::kForRead, TDbPipe, pPipe);
|
|
// if(pPipe) {
|
|
// TPipeInterface iFace;
|
|
// iFace.m_sysType = st;
|
|
// iFace.m_faceType = TPipeInterface::kNodeLocation;
|
|
// iFace.m_idPipe = id;
|
|
// XPoint ptS, ptE;
|
|
// ptS = pPipe->StartPoint();
|
|
// ptE = pPipe->EndPoint();
|
|
// ptS.z = 0;
|
|
// ptE.z = 0;
|
|
// double nDist1 = ptLoc.Distance(ptS);
|
|
// double nDist2 = ptLoc.Distance(ptE);
|
|
// if(nDist1<PS_SNAP) {
|
|
// iFace.m_ptLocation = pPipe->StartPoint();
|
|
// AcGeVector3d vt;
|
|
// pPipe->getFirstDeriv(pPipe->StartPoint(), vt);
|
|
// iFace.m_vtLocation = vt;
|
|
// AddInterface(iFace);
|
|
// } else if(nDist2<PS_SNAP) {
|
|
// iFace.m_ptLocation = pPipe->EndPoint();
|
|
// AcGeVector3d vt;
|
|
// pPipe->getFirstDeriv(pPipe->EndPoint(), vt);
|
|
// iFace.m_vtLocation = XVector3D(-vt[0], -vt[1], -vt[2]);
|
|
// AddInterface(iFace);
|
|
// }
|
|
// }
|
|
// OPENOBJ_END();
|
|
// }
|
|
|
|
// cet 2010.3.10 add 移动水泵或水管时,重新判断连接情况
|
|
if (idPipes.Length() == 0)
|
|
{
|
|
for (int i = 0; i < m_lstInterface.Length(); ++i)
|
|
{
|
|
if (m_lstInterface[i]->m_idPipe.isValid() && !m_lstInterface[i]->m_idPipe.isErased())
|
|
{
|
|
if (!CanLinkSide(m_lstInterface[i]->m_idPipe, 0) && !CanLinkSide(m_lstInterface[i]->m_idPipe, 1))
|
|
{
|
|
m_lstInterface[i]->m_idPipe.setNull();
|
|
}
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
|
|
//cet 2009.12.11 add
|
|
UpdateInterface();
|
|
XPoint ptFit;
|
|
|
|
for (int j = 0; j < idPipes.Length(); ++j)
|
|
{
|
|
for (int i = 0; i < m_lstInterface.Length(); ++i)
|
|
{
|
|
OPENOBJ_BEGIN(idPipes[j], AcDb::kForRead, TDbPipePrototype, pPipe);
|
|
if (pPipe != NULL)
|
|
{
|
|
ptFit = GetILocation(i);
|
|
|
|
XPoint ptPipeS,ptPipeE;
|
|
ptPipeS = pPipe->StartPoint();
|
|
ptPipeE = pPipe->EndPoint();
|
|
ptPipeS.z = 0;
|
|
ptPipeE.z = 0;
|
|
ptFit.z = 0;
|
|
AcGeVector3d vtDir1 = ptFit - ptPipeE;
|
|
AcGeVector3d vtDir2 = ptFit - ptPipeS;
|
|
//判断连接点是否有管子
|
|
if (vtDir1.isParallelTo(vtDir2) || vtDir1.isZeroLength() || vtDir2.isZeroLength())
|
|
{
|
|
if (ptFit.Distance(ptPipeS) <= ptPipeE.Distance(ptPipeS) + _DIST_SNAP
|
|
&& ptFit.Distance(ptPipeE) <= ptPipeS.Distance(ptPipeE) + _DIST_SNAP)
|
|
{
|
|
TPipeInterface &iFace = *m_lstInterface[i];
|
|
iFace.m_sysType = pPipe->GetSysType();
|
|
iFace.m_idPipe = pPipe->objectId();
|
|
iFace.m_faceType = TPipeInterface::kNodeLocation;
|
|
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
XLine line(pPipe->GetStartPoint(),pPipe->GetEndPoint());
|
|
|
|
//求得炸碎的实体
|
|
AcArray<XCurveSegment, AcArrayObjectCopyReallocator<XCurveSegment> > arSegs;
|
|
GetExplodeCurves(this,arSegs);
|
|
//判断是否连接
|
|
XPoint ptCon;
|
|
line.SetLineFlag(1);
|
|
line.StartPoint().z = 0;
|
|
line.EndPoint().z = 0;
|
|
|
|
BOOL bRet1 = CheckIsConnect(pPipe->StartPoint(),arSegs,line,ptCon);
|
|
BOOL bRet2 = CheckIsConnect(pPipe->EndPoint(),arSegs,line,ptCon);
|
|
if (bRet1 || bRet2)
|
|
{
|
|
int nIndex = GetFreeInterfaceIndex();
|
|
if (nIndex < 0)
|
|
{
|
|
//没有空闲的接口则增加新的接口
|
|
if (!FindInterfaceByPt(ptCon))
|
|
{
|
|
CString sCount;
|
|
sCount.Format(_T("%d"),m_lstInterface.Length()+1);
|
|
|
|
TPipeInterface iFace;
|
|
iFace.m_faceType = TPipeInterface::kBoundry;
|
|
iFace.m_sSysLabel = sCount;
|
|
ptCon.z = pPipe->StartPoint().z;
|
|
iFace.m_ptLocation = ptCon;
|
|
iFace.m_vtLocation = m_vtDirection;
|
|
AddInterface(iFace);
|
|
|
|
FindInterface(sCount)->m_idPipe = pPipe->objectId();
|
|
FindInterface(sCount)->m_sysType = pPipe->GetSysType();
|
|
FindInterface(sCount)->m_faceType = TPipeInterface::kNodeLocation;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//移动空闲接口到合适位置
|
|
m_lstInterface[nIndex]->m_idPipe = pPipe->objectId();
|
|
m_lstInterface[nIndex]->m_sysType = pPipe->GetSysType();
|
|
m_lstInterface[nIndex]->m_faceType = TPipeInterface::kNodeLocation;
|
|
ptCon.z = pPipe->StartPoint().z;
|
|
m_lstInterface[nIndex]->m_ptLocation = ptCon;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
}
|
|
|
|
AcGeMatrix3d mat(AcGeVector3d(0,0,0));
|
|
transformBy(mat);
|
|
}
|
|
|
|
|
|
void InitDbPump(BOOL bTrue)
|
|
{
|
|
if(bTrue) {
|
|
TDbPump::rxInit();
|
|
TDbPump::InitMatchProtocol(TRUE);
|
|
} else {
|
|
TDbPump::InitMatchProtocol(FALSE);
|
|
deleteAcRxClass(TDbPump::desc());
|
|
}
|
|
}
|
|
|
|
//得到炸碎的实体
|
|
void TDbPump::GetExplodeCurves(const AcDbObjectId &id,AcArray<XCurveSegment, AcArrayObjectCopyReallocator<XCurveSegment> > &arCurves) const
|
|
{
|
|
AcDbVoidPtrArray arEnts;
|
|
AcDbVoidPtrArray arBlocks;
|
|
AcDbBlockReference *pBlock = NULL;
|
|
AcDbEntity *pEntPump = NULL;
|
|
acdbOpenAcDbEntity(pEntPump, id, AcDb::kForRead);
|
|
if (pEntPump != NULL)
|
|
{
|
|
//第一次炸碎成图块
|
|
pEntPump->explode(arEnts);
|
|
for (int j = 0; j < arEnts.length(); ++j)
|
|
{
|
|
pBlock = AcDbBlockReference::cast((AcDbEntity*)arEnts[j]);
|
|
if (pBlock != NULL)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
//第二次炸开图块
|
|
if (pBlock != NULL)
|
|
{
|
|
pBlock->explode(arBlocks);
|
|
for (int i =0; i < arBlocks.length(); ++i)
|
|
{
|
|
AcDbEntity *pEnt = (AcDbEntity*)arBlocks[i];
|
|
if (pEnt != NULL)
|
|
{
|
|
AcDbLine *pLine = NULL;
|
|
AcDbArc *pArc = NULL;
|
|
AcDbCircle *pCir = NULL;
|
|
XCurveSegment seg;
|
|
if(pLine = AcDbLine::cast(pEnt))
|
|
{
|
|
XLine line(XPoint(pLine->startPoint()), XPoint(pLine->endPoint()));
|
|
seg = line;
|
|
arCurves.append(seg);
|
|
}
|
|
else if(pArc = AcDbArc::cast(pEnt))
|
|
{
|
|
AcGePoint3d ptStart, ptEnd;
|
|
pArc->getStartPoint(ptStart);
|
|
pArc->getEndPoint(ptEnd);
|
|
double dAng(0), dLen(0);
|
|
pArc->getDistAtPoint(ptEnd, dLen);
|
|
dAng = dLen / pArc->radius();
|
|
XArc arc(XPoint(ptStart), XPoint(ptStart), dAng);
|
|
seg = arc;
|
|
arCurves.append(seg);
|
|
}
|
|
else if(pCir = AcDbCircle::cast(pEnt))
|
|
{
|
|
AcGePoint3d ptCen = pCir->center();
|
|
XCircle cir(XPoint(ptCen), pCir->radius());
|
|
seg = cir;
|
|
arCurves.append(seg);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
pEntPump->close();
|
|
}
|
|
|
|
ReleaseEntSet(arBlocks);
|
|
ReleaseEntSet(arEnts);
|
|
}
|
|
|
|
|
|
void TDbPump::GetExplodeCurves(AcDbEntity *pEntPump,AcArray<XCurveSegment, AcArrayObjectCopyReallocator<XCurveSegment> > &arCurves) const
|
|
{
|
|
if (pEntPump != NULL)
|
|
{
|
|
AcDbVoidPtrArray arEnts;
|
|
AcDbVoidPtrArray arBlocks;
|
|
AcDbBlockReference *pBlock = NULL;
|
|
|
|
//第一次炸碎成图块
|
|
pEntPump->explode(arEnts);
|
|
for (int j = 0; j < arEnts.length(); ++j)
|
|
{
|
|
pBlock = AcDbBlockReference::cast((AcDbEntity*)arEnts[j]);
|
|
if (pBlock != NULL)
|
|
{
|
|
break;
|
|
|
|
}
|
|
}
|
|
|
|
//第二次炸开图块
|
|
if (pBlock != NULL)
|
|
{
|
|
pBlock->explode(arBlocks);
|
|
for (int i =0; i < arBlocks.length(); ++i)
|
|
{
|
|
AcDbEntity *pEnt = (AcDbEntity*)arBlocks[i];
|
|
if (pEnt != NULL)
|
|
{
|
|
AcDbLine *pLine = NULL;
|
|
AcDbArc *pArc = NULL;
|
|
AcDbCircle *pCir = NULL;
|
|
XCurveSegment seg;
|
|
if(pLine = AcDbLine::cast(pEnt))
|
|
{
|
|
XLine line(XPoint(pLine->startPoint()), XPoint(pLine->endPoint()));
|
|
seg = line;
|
|
arCurves.append(seg);
|
|
}
|
|
else if(pArc = AcDbArc::cast(pEnt))
|
|
{
|
|
AcGePoint3d ptStart, ptEnd;
|
|
pArc->getStartPoint(ptStart);
|
|
pArc->getEndPoint(ptEnd);
|
|
double dAng(0), dLen(0);
|
|
pArc->getDistAtPoint(ptEnd, dLen);
|
|
dAng = dLen / pArc->radius();
|
|
XArc arc(XPoint(ptStart), XPoint(ptStart), dAng);
|
|
seg = arc;
|
|
arCurves.append(seg);
|
|
}
|
|
else if(pCir = AcDbCircle::cast(pEnt))
|
|
{
|
|
AcGePoint3d ptCen = pCir->center();
|
|
XCircle cir(XPoint(ptCen), pCir->radius());
|
|
seg = cir;
|
|
arCurves.append(seg);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
ReleaseEntSet(arBlocks);
|
|
ReleaseEntSet(arEnts);
|
|
}
|
|
}
|
|
|
|
//判断是否连接
|
|
BOOL TDbPump::CheckIsConnect(const XPoint &pt, const AcArray<XCurveSegment, AcArrayObjectCopyReallocator<XCurveSegment> > &arSegs, const XLine &line,XPoint &ptCon) const
|
|
{
|
|
BOOL bTrue = FALSE;
|
|
XCurveSegment seg;
|
|
XPoint pt1, pt2;
|
|
//找到管线与实体交点,并判断交点是否在实体表面
|
|
for (int i = 0; i < arSegs.length(); ++i)
|
|
{
|
|
seg = arSegs[i];
|
|
seg.SetLineFlag(1); //在不延长实体条件下,求交点
|
|
seg.StartPoint().z = 0;
|
|
seg.EndPoint().z = 0;
|
|
if (seg.Intersection(line, pt1, pt2) == 1)
|
|
{
|
|
if (pt1.Distance2d(pt) < 1E-3)
|
|
{
|
|
bTrue = TRUE;
|
|
ptCon = pt1;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return bTrue;
|
|
}
|
|
|
|
//得到空闲的接口序号
|
|
int TDbPump::GetFreeInterfaceIndex() const
|
|
{
|
|
int nIndex = -1;
|
|
for (int i = 0; i < m_lstInterface.Length(); ++i)
|
|
{
|
|
if (!m_lstInterface[i].m_idPipe.isValid() || m_lstInterface[i].m_idPipe.isErased())
|
|
{
|
|
nIndex = i;
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
OPENOBJ_BEGIN(m_lstInterface[i].m_idPipe, AcDb::kForRead, TDbPipePrototype, pPipe);
|
|
if(pPipe)
|
|
{
|
|
if (pPipe->StartPoint().Distance2d(m_lstInterface[i].m_ptLocation) > 1e-3
|
|
&& pPipe->EndPoint().Distance2d(m_lstInterface[i].m_ptLocation) > 1e-3)
|
|
{
|
|
nIndex = i;
|
|
break;
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
}
|
|
|
|
return nIndex;
|
|
}
|
|
|
|
//是否找到接口
|
|
bool TDbPump::FindInterfaceByPt(const AcGePoint3d &pt)
|
|
{
|
|
bool bFind = FALSE;
|
|
for (int i = 0; i < m_lstInterface.Length(); ++i)
|
|
{
|
|
if (pt.distanceTo(m_lstInterface[i]->m_ptLocation) < 1e-3)
|
|
{
|
|
bFind = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return bFind;
|
|
}
|
|
|
|
TPipeInterface* TDbPump::FindInterface(XString sName)
|
|
{
|
|
for (int i=0; i<m_lstInterface.Length(); i++)
|
|
{
|
|
TPipeInterface *pFace = m_lstInterface[i];
|
|
if (_tcsicmp(sName, pFace->m_sSysLabel) == 0)
|
|
{
|
|
return pFace;
|
|
}
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
void TDbPump::DrawPipeInterface(XExplodeDraw &dc) const
|
|
{
|
|
TDbPipe *pPipe = NULL;
|
|
XPoint ptS, ptE, ptMid, ptIns;
|
|
AcGeVector3d vtr;
|
|
double dRadius = 0.0;
|
|
|
|
for (int i = 0; i < m_lstInterface.Length(); i++)
|
|
{
|
|
if (!m_lstInterface[i].m_idPipe.isErased() &&
|
|
m_lstInterface[i].m_idPipe.isValid())
|
|
{
|
|
acdbOpenObject(pPipe, m_lstInterface[i].m_idPipe, AcDb::kForRead);
|
|
if (pPipe != NULL)
|
|
{
|
|
ptS = pPipe->StartPoint();
|
|
ptE = pPipe->EndPoint();
|
|
|
|
ptIns = m_lstInterface[i].m_ptLocation;
|
|
ptIns.z = ptS.z;
|
|
ptMid = pPipe->MidPoint();
|
|
vtr = ptMid - ptIns;
|
|
vtr.normalize();
|
|
|
|
dRadius = pPipe->GetDnDiameter();
|
|
DrawPolyMesh(ptIns + vtr * 25, ptIns - vtr * 80, dRadius/2 + dRadius / 5, dc);
|
|
DrawPolyMesh(ptIns + vtr * 20, ptIns + vtr * 50, dRadius, dc);
|
|
|
|
pPipe->close();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void TDbPump::UpdateInterface()
|
|
{
|
|
TDbPipe *pPipe = NULL;
|
|
for (int i = 0; i < m_lstInterface.Length(); i++)
|
|
{
|
|
acdbOpenObject(pPipe, m_lstInterface[i]->m_idPipe, AcDb::kForRead);
|
|
if (pPipe != NULL)
|
|
{
|
|
XPoint ptTemp = m_lstInterface[i]->m_ptLocation;
|
|
ptTemp.z = pPipe->StartPoint().z;
|
|
m_lstInterface[i]->m_ptLocation = ptTemp;
|
|
|
|
pPipe->close();
|
|
}
|
|
}
|
|
}
|
|
|
|
// cet 2009.12.18 del
|
|
// void TDbPump::draw2Line(XExplodeDraw &dc) const
|
|
// {
|
|
// if(_tcscmp(dc.Desc(), XAcGiViewDraw::Descriptor()) == 0)
|
|
// {
|
|
// AcGiGeometry *geom=((XAcGiViewDraw &)dc).GetCommonDraw()->rawGeometry();
|
|
// AcDbObjectId id2d = GetBlock2d();
|
|
// if (geom != NULL && id2d.isValid())
|
|
// {
|
|
// AcGeScale3d scale(m_nLength, m_nWidth, m_nLength);
|
|
// AcDbBlockReference insert(m_ptLocation, m_idBlock2d);
|
|
// insert.setScaleFactors(scale);
|
|
//
|
|
// AcDbExtents extents;
|
|
// if(insert.geomExtentsBestFit(extents) == Acad::eOk)
|
|
// {
|
|
// XPoint ptMax = extents.maxPoint();
|
|
// XPoint ptMin = extents.minPoint();
|
|
//
|
|
// XPoint ptInter1,ptInter2;
|
|
// AcGeVector3d vtDir = AcGeVector3d::kXAxis;
|
|
// AcGePoint3d ptPosT = m_ptLocation;
|
|
// ptPosT.z = 0;
|
|
//
|
|
// AcDbPolyline polyLine;
|
|
// AcGePoint3d pt1 = ptMin;
|
|
// AcGePoint3d pt2 = pt1 + vtDir * m_nLength;
|
|
// AcGePoint3d pt3 = ptMax;
|
|
// AcGePoint3d pt4 = pt3 - vtDir * m_nLength;
|
|
// polyLine.addVertexAt(0, pt1.convert2d(AcGePlane::kXYPlane));
|
|
// polyLine.addVertexAt(1, pt2.convert2d(AcGePlane::kXYPlane));
|
|
// polyLine.addVertexAt(2, pt3.convert2d(AcGePlane::kXYPlane));
|
|
// polyLine.addVertexAt(3, pt4.convert2d(AcGePlane::kXYPlane));
|
|
// polyLine.addVertexAt(4, pt1.convert2d(AcGePlane::kXYPlane));
|
|
//
|
|
// AcDbRay ray;
|
|
// ray.setUnitDir(AcGeVector3d::kXAxis);
|
|
// ray.setBasePoint(m_ptLocation);
|
|
// AcGePoint3dArray arPts;
|
|
// AcGePoint3dArray arptResult;
|
|
// polyLine.intersectWith(&ray, AcDb::kExtendArg, arPts);
|
|
// if (arPts.length() == 2)
|
|
// {
|
|
// arptResult.append(arPts[0]);
|
|
// arptResult.append(arPts[1]);
|
|
// }
|
|
//
|
|
// arPts.setLogicalLength(0);
|
|
// ray.setUnitDir(AcGeVector3d::kYAxis);
|
|
// polyLine.intersectWith(&ray, AcDb::kExtendArg, arPts);
|
|
// if (arPts.length() == 2)
|
|
// {
|
|
// arptResult.append(arPts[0]);
|
|
// arptResult.append(arPts[1]);
|
|
// }
|
|
//
|
|
// if (arptResult.length() == 4)
|
|
// {
|
|
// //炸开图块
|
|
// AcDbVoidPtrArray arEnts;
|
|
// insert.explode(arEnts);
|
|
// AcDbCircle *pCir1 = NULL, *pCir2 = NULL;
|
|
// AcDbCircle *pCir = NULL;
|
|
// int d = arEnts.length();
|
|
// for (int i = 0; i < arEnts.length(); i++)
|
|
// {
|
|
// pCir = AcDbCircle::cast((AcDbEntity*)arEnts[i]);
|
|
// if (pCir != NULL)
|
|
// {
|
|
// if (pCir1 == NULL)
|
|
// {
|
|
// pCir1 = pCir;
|
|
// continue;
|
|
// }
|
|
// else
|
|
// {
|
|
// pCir2 = pCir;
|
|
// break;
|
|
// }
|
|
// }
|
|
// }
|
|
//
|
|
// if (pCir1 == NULL || pCir2 == NULL)
|
|
// {
|
|
// return;
|
|
// }
|
|
//
|
|
// if (pCir1->radius() > pCir2->radius())
|
|
// {
|
|
// pCir = pCir1;
|
|
// }
|
|
// else
|
|
// {
|
|
// pCir = pCir2;
|
|
// }
|
|
//
|
|
// if (pCir == NULL)
|
|
// {
|
|
// return;
|
|
// }
|
|
//
|
|
// AcDbCircle cir(pCir->center(), pCir->normal(), pCir->radius());
|
|
// ReleaseEntSet(arEnts);
|
|
// for (i = 0; i < 4; i++)
|
|
// {
|
|
// for (int j = 0; j < m_lstInterface.Length(); j++)
|
|
// {
|
|
// if (m_lstInterface[j].m_idPipe.isValid() && !m_lstInterface[j].m_idPipe.isErased())
|
|
// {
|
|
// TDbPipe *pPipe = NULL;
|
|
// acdbOpenObject(pPipe, m_lstInterface[j].m_idPipe, AcDb::kForRead);
|
|
// if (pPipe == NULL)
|
|
// {
|
|
// continue;
|
|
// }
|
|
// AcGePoint3d ptS, ptE ;
|
|
// XPoint ptLocation;
|
|
// ptLocation = m_lstInterface[j].m_ptLocation;
|
|
// ptS = pPipe->StartPoint();
|
|
// ptE = pPipe->EndPoint();
|
|
// ptLocation.z = 0;
|
|
// ptS.z = 0;
|
|
// ptE.z = 0;
|
|
// pPipe->close();
|
|
//
|
|
// AcGeVector3d vtr1 = ptS - ptE;
|
|
// AcGeVector3d vtr2 = ptLocation - m_ptLocation ;
|
|
// if (ptLocation.Distance(arptResult[i]) < 1e-3 && vtr1.isParallelTo(vtr2))
|
|
// {
|
|
// AcGeVector3d vtr = vtr2;
|
|
// vtr = vtr.rotateBy(PI / 2, AcGeVector3d::kZAxis);
|
|
// vtr.normalize();
|
|
//
|
|
// AcDbRay ray;
|
|
// double dDist = 25;
|
|
// ray.setBasePoint(m_ptLocation + vtr * dDist);
|
|
// ray.setUnitDir(vtr2.normalize());
|
|
//
|
|
// arPts.setLogicalLength(0);
|
|
// cir.intersectWith(&ray, AcDb::kOnBothOperands, arPts);
|
|
// if (arPts.length() == 1)
|
|
// {
|
|
// AcGePoint3d ptS1 = arPts[0];
|
|
// AcGePoint3d ptE1 = ptLocation + vtr * dDist;
|
|
//
|
|
// vtr = vtr2;
|
|
// vtr = vtr.rotateBy(-PI / 2, AcGeVector3d::kZAxis);
|
|
// ray.setBasePoint(m_ptLocation + vtr * dDist);
|
|
//
|
|
// arPts.setLogicalLength(0);
|
|
// cir.intersectWith(&ray, AcDb::kOnBothOperands, arPts);
|
|
// if (arPts.length() == 1)
|
|
// {
|
|
// AcGePoint3d ptS2 = arPts[0];
|
|
// AcGePoint3d ptE2 = ptLocation + vtr * dDist;
|
|
// AcGePoint3d arPt[2];
|
|
// arPt[0] = ptS1;
|
|
// arPt[1] = ptE1;
|
|
// geom->polyline(2, arPt, &AcGeVector3d::kZAxis);
|
|
// arPt[0] = ptS2;
|
|
// arPt[1] = ptE2;
|
|
// geom->polyline(2, arPt, &AcGeVector3d::kZAxis);
|
|
// }
|
|
// }
|
|
//
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
//
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// cet 2009.12.18 add
|
|
void TDbPump::draw2Line(XExplodeDraw &dc) const
|
|
{
|
|
if(_tcscmp(dc.Desc(), XAcGiViewDraw::Descriptor()) == 0)
|
|
{
|
|
AcGiGeometry *geom=((XAcGiViewDraw &)dc).GetCommonDraw()->rawGeometry();
|
|
if (geom != NULL)
|
|
{
|
|
AcGePoint3dArray arptResult;
|
|
GetBlk2dBorderMidPt(arptResult);
|
|
|
|
if (arptResult.length() == 4)
|
|
{
|
|
AcDbCircle *pCir = GetExplodeCircle();
|
|
|
|
if (pCir == NULL)
|
|
{
|
|
return;
|
|
}
|
|
|
|
AcGePoint3d ptCenter = pCir->center();
|
|
ptCenter.z = 0;
|
|
AcDbCircle cir(ptCenter, pCir->normal(), pCir->radius());
|
|
delete pCir;
|
|
pCir = NULL;
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
for (int j = 0; j < m_lstInterface.Length(); j++)
|
|
{
|
|
if (m_lstInterface[j].m_idPipe.isValid() && !m_lstInterface[j].m_idPipe.isErased())
|
|
{
|
|
TDbPipe *pPipe = NULL;
|
|
acdbOpenObject(pPipe, m_lstInterface[j].m_idPipe, AcDb::kForRead);
|
|
if (pPipe == NULL)
|
|
{
|
|
continue;
|
|
}
|
|
AcGePoint3d ptS, ptE ;
|
|
XPoint ptLocation;
|
|
AcGePoint3d ptIns = m_ptLocation;
|
|
ptLocation = m_lstInterface[j].m_ptLocation;
|
|
ptS = pPipe->StartPoint();
|
|
ptE = pPipe->EndPoint();
|
|
ptIns.z = 0;
|
|
ptLocation.z = 0;
|
|
ptS.z = 0;
|
|
ptE.z = 0;
|
|
pPipe->close();
|
|
|
|
AcGeVector3d vtr1 = ptS - ptE;
|
|
AcGeVector3d vtr2 = ptLocation - ptIns ;
|
|
AcGePoint3d pt = arptResult[i];
|
|
if (ptLocation.Distance(arptResult[i]) < 1e-3 && vtr1.isParallelTo(vtr2))
|
|
{
|
|
AcGeVector3d vtr = vtr2;
|
|
vtr = vtr.rotateBy(PI / 2, AcGeVector3d::kZAxis);
|
|
vtr.normalize();
|
|
|
|
AcDbRay ray;
|
|
double dDist = 0.0;
|
|
if (vtr2.isParallelTo(AcGeVector3d::kXAxis))
|
|
{
|
|
dDist = m_nLength / 16;
|
|
}
|
|
else
|
|
|
|
{
|
|
dDist = m_nWidth / 16;
|
|
}
|
|
ray.setBasePoint(ptIns + vtr * dDist);
|
|
ray.setUnitDir(vtr2.normalize());
|
|
|
|
AcGePoint3dArray arPts;
|
|
arPts.setLogicalLength(0);
|
|
cir.intersectWith(&ray, AcDb::kOnBothOperands, arPts);
|
|
if (arPts.length() == 1)
|
|
{
|
|
AcGePoint3d ptS1 = arPts[0];
|
|
AcGePoint3d ptE1 = ptLocation + vtr * dDist;
|
|
|
|
vtr = vtr2;
|
|
vtr = vtr.rotateBy(-PI / 2, AcGeVector3d::kZAxis);
|
|
ray.setBasePoint(ptIns + vtr * dDist);
|
|
|
|
arPts.setLogicalLength(0);
|
|
cir.intersectWith(&ray, AcDb::kOnBothOperands, arPts);
|
|
if (arPts.length() == 1)
|
|
{
|
|
AcGePoint3d ptS2 = arPts[0];
|
|
AcGePoint3d ptE2 = ptLocation + vtr * dDist;
|
|
AcGePoint3d arPt[2];
|
|
arPt[0] = ptS1;
|
|
arPt[1] = ptE1;
|
|
geom->polyline(2, arPt, &AcGeVector3d::kZAxis);
|
|
arPt[0] = ptS2;
|
|
arPt[1] = ptE2;
|
|
geom->polyline(2, arPt, &AcGeVector3d::kZAxis);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void TDbPump::GetBlk2dBorderMidPt(AcGePoint3dArray &arptResult) const
|
|
{
|
|
AcDbObjectId id2d = GetBlock2d();
|
|
if (id2d.isValid())
|
|
{
|
|
AcGeScale3d scale(m_nLength, m_nWidth, m_nLength);
|
|
AcDbBlockReference insert(m_ptLocation, m_idBlock2d);
|
|
insert.setScaleFactors(scale);
|
|
|
|
AcDbExtents extents;
|
|
if(insert.geomExtentsBestFit(extents) == Acad::eOk)
|
|
{
|
|
XPoint ptMax = extents.maxPoint();
|
|
XPoint ptMin = extents.minPoint();
|
|
|
|
// cet 2011.9.3 add 调整代码以支持ucs
|
|
double dAngle = GetAngle();
|
|
AcGeMatrix3d mat;
|
|
mat.setToRotation(dAngle, AcGeVector3d::kZAxis, m_ptLocation);
|
|
ptMin.TransformBy(mat);
|
|
ptMax.TransformBy(mat);
|
|
ptMax.z = 0.0;
|
|
ptMin.z = 0.0;
|
|
|
|
XPoint ptInter1,ptInter2;
|
|
AcGeVector3d vtDir = AcGeVector3d::kXAxis;
|
|
vtDir.rotateBy(Ucs2Wcs(0.0), AcGeVector3d::kZAxis); // cet 2011.9.3 add 调整代码以支持ucs
|
|
|
|
AcDbPolyline polyLine;
|
|
AcGePoint3d pt1 = ptMin;
|
|
AcGePoint3d pt2 = pt1 + vtDir * m_nLength;
|
|
AcGePoint3d pt3 = ptMax;
|
|
AcGePoint3d pt4 = pt3 - vtDir * m_nLength;
|
|
polyLine.addVertexAt(0, pt1.convert2d(AcGePlane::kXYPlane));
|
|
polyLine.addVertexAt(1, pt2.convert2d(AcGePlane::kXYPlane));
|
|
polyLine.addVertexAt(2, pt3.convert2d(AcGePlane::kXYPlane));
|
|
polyLine.addVertexAt(3, pt4.convert2d(AcGePlane::kXYPlane));
|
|
polyLine.addVertexAt(4, pt1.convert2d(AcGePlane::kXYPlane));
|
|
|
|
AcDbRay ray;
|
|
ray.setUnitDir(vtDir); // cet 2011.9.3 modify 调整代码以支持ucs
|
|
XPoint ptBase = m_ptLocation;
|
|
ptBase.z = 0;
|
|
ray.setBasePoint(ptBase);
|
|
AcGePoint3dArray arPts;
|
|
polyLine.intersectWith(&ray, AcDb::kExtendArg, arPts);
|
|
arptResult.setLogicalLength(0);
|
|
if (arPts.length() == 2)
|
|
{
|
|
arptResult.append(arPts[0]);
|
|
arptResult.append(arPts[1]);
|
|
}
|
|
|
|
arPts.setLogicalLength(0);
|
|
vtDir.rotateBy(PI/2, AcGeVector3d::kZAxis);
|
|
ray.setUnitDir(vtDir); // cet 2011.9.3 modify 调整代码以支持ucs
|
|
polyLine.intersectWith(&ray, AcDb::kExtendArg, arPts);
|
|
if (arPts.length() == 2)
|
|
{
|
|
arptResult.append(arPts[0]);
|
|
arptResult.append(arPts[1]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
AcDbCircle* TDbPump::GetExplodeCircle() const
|
|
{
|
|
//炸开图块
|
|
AcDbObjectId id2d = GetBlock2d();
|
|
if (id2d.isValid())
|
|
{
|
|
AcGeScale3d scale(m_nLength, m_nWidth, m_nLength);
|
|
AcDbBlockReference insert(m_ptLocation, m_idBlock2d);
|
|
insert.setScaleFactors(scale);
|
|
AcDbVoidPtrArray arEnts;
|
|
insert.explode(arEnts);
|
|
AcDbCircle *pCir1 = NULL, *pCir2 = NULL;
|
|
AcDbCircle *pCir = NULL;
|
|
int d = arEnts.length();
|
|
for (int i = 0; i < arEnts.length(); i++)
|
|
{
|
|
pCir = AcDbCircle::cast((AcDbEntity*)arEnts[i]);
|
|
if (pCir != NULL)
|
|
{
|
|
if (pCir1 == NULL)
|
|
{
|
|
pCir1 = pCir;
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
pCir2 = pCir;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (pCir1 == NULL || pCir2 == NULL)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
if (pCir1->radius() > pCir2->radius())
|
|
{
|
|
pCir = pCir1;
|
|
}
|
|
else
|
|
{
|
|
pCir = pCir2;
|
|
}
|
|
|
|
AcDbCircle *pCircle = new AcDbCircle(pCir->center(), pCir->normal(), pCir->radius());
|
|
ReleaseEntSet(arEnts);
|
|
|
|
return pCircle;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
|
|
bool TDbPump::GetSection(const AcDbFace &face, const AcGeVector3d& vtPlaneSecDir,
|
|
std::vector<TObjSectionRecord> §ionRecords,
|
|
AcDbVoidPtrArray& arFillPtrs) const
|
|
{
|
|
// 求线与投影面的最短距离
|
|
TGGeSectionPlane section_pln(face, vtPlaneSecDir);
|
|
AcGePlane plane = section_pln.AsAcGePlane();
|
|
AcGePoint3d pt = m_ptLocation;
|
|
pt = pt.project(plane, vtPlaneSecDir);
|
|
double dDist = pt.distanceTo(m_ptLocation);
|
|
|
|
XPoint pt1, pt2;
|
|
AcGePoint3d ptMin, ptMax;
|
|
ptMin = m_ptLocation + AcGeVector3d::kXAxis * m_nLength * 0.5 + AcGeVector3d::kYAxis * m_nWidth * 0.5;
|
|
ptMax = m_ptLocation - AcGeVector3d::kXAxis * m_nLength * 0.5 - AcGeVector3d::kYAxis * m_nWidth * 0.5;
|
|
ptMin = pt1;
|
|
ptMax = pt2;
|
|
ptMin = ptMin.orthoProject(plane);
|
|
ptMax = ptMax.orthoProject(plane);
|
|
|
|
XString xsBlk;
|
|
XString xsTKName, xsRocord;
|
|
SplitSlbName(_T("PUMP(00000046)"), xsTKName, xsRocord);
|
|
LoadDwbBlock(xsTKName, xsRocord, xsBlk);
|
|
AcDbObjectId idBlock;
|
|
AcDbBlockTable *pBlkTbl = NULL;
|
|
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl, AcDb::kForRead);
|
|
if (pBlkTbl != NULL)
|
|
{
|
|
pBlkTbl->getAt(xsBlk, idBlock);
|
|
pBlkTbl->close();
|
|
}
|
|
|
|
if (idBlock.isValid())
|
|
{
|
|
BlockRefInfo info(idBlock, AcGeScale3d(m_nLength, m_nWidth, m_nHeight), pt, dDist * (-1), ptMax, ptMin);
|
|
TSectionFill *pFill = new TSectionFill(info, layerId());
|
|
arFillPtrs.append(pFill);
|
|
}
|
|
|
|
// 管线与泵的接口图块
|
|
for (int i = 0; i < m_lstInterface.Length(); i++)
|
|
{
|
|
if (!m_lstInterface[i].m_idPipe.isErased() && m_lstInterface[i].m_idPipe.isValid())
|
|
{
|
|
// 检查管线是否与剖面生成方向平行或垂直
|
|
TDbPipe *pPipe = NULL;
|
|
Acad::ErrorStatus st = acdbOpenObject(pPipe, m_lstInterface[i].m_idPipe, AcDb::kForRead);
|
|
if (pPipe != NULL)
|
|
{
|
|
AcGePoint3d ptS, ptE;
|
|
ptS = pPipe->StartPoint();
|
|
ptE = pPipe->EndPoint();
|
|
ptS.z = 0;
|
|
ptE.z = 0;
|
|
|
|
AcGePoint3d ptTemp = m_ptLocation;
|
|
ptTemp.z += pPipe->StartPoint().z; //确定相对剖面水泵水泵接口Y坐标值
|
|
AcGeVector3d vtr = ptE - ptS;
|
|
if (vtr.isPerpendicularTo(vtPlaneSecDir)) // 管线与剖面方向垂直
|
|
{
|
|
if (vtr.isParallelTo(AcGeVector3d::kXAxis))
|
|
{
|
|
if (vtPlaneSecDir.isCodirectionalTo(AcGeVector3d::kYAxis))
|
|
{
|
|
if (vtr.isCodirectionalTo(AcGeVector3d::kXAxis)) // 管线与X轴方向相同
|
|
{
|
|
SplitSlbName(_T("PUMP(00000060)"), xsTKName, xsRocord);
|
|
LoadDwbBlock(xsTKName, xsRocord, xsBlk);
|
|
ptTemp += AcGeVector3d::kXAxis * m_nLength / 2; //确定相对剖面水泵插入点水泵接口坐标位置
|
|
ptTemp = ptTemp.project(plane, vtPlaneSecDir);
|
|
|
|
AcDbObjectId id = GetBlockIdFromString(_T("$pump$00000060"));
|
|
BlockRefInfo info(id, AcGeScale3d(m_nLength, m_nWidth, 1), ptTemp, dDist * (-1), ptMax, ptMin);
|
|
TSectionFill *pFill = new TSectionFill(info, layerId());
|
|
arFillPtrs.append(pFill);
|
|
|
|
}
|
|
else// 管线与X轴方向相反
|
|
{
|
|
SplitSlbName(_T("PUMP(00000060)"), xsTKName, xsRocord);
|
|
LoadDwbBlock(xsTKName, xsRocord, xsBlk);
|
|
ptTemp += -AcGeVector3d::kXAxis * m_nLength / 2;
|
|
ptTemp = ptTemp.project(plane, vtPlaneSecDir);
|
|
|
|
AcDbObjectId idBlk = GetBlockIdFromString(_T("$pump$00000060"));
|
|
AcDbObjectId id = CreateNewBlkRecord(idBlk, PI, _T("00000060-2"));
|
|
if (id.isValid())
|
|
{
|
|
BlockRefInfo info(id, AcGeScale3d(m_nLength, m_nWidth, 1), ptTemp, dDist * (-1), ptMax, ptMin);
|
|
TSectionFill *pFill = new TSectionFill(info, layerId());
|
|
arFillPtrs.append(pFill);
|
|
}
|
|
}
|
|
}
|
|
else if (vtPlaneSecDir.isCodirectionalTo(-AcGeVector3d::kYAxis))
|
|
{
|
|
if (vtr.isCodirectionalTo(AcGeVector3d::kXAxis)) // 管线与X轴方向相同
|
|
{
|
|
SplitSlbName(_T("PUMP(00000060)"), xsTKName, xsRocord);
|
|
LoadDwbBlock(xsTKName, xsRocord, xsBlk);
|
|
ptTemp += AcGeVector3d::kXAxis * m_nLength / 2;
|
|
ptTemp = ptTemp.project(plane, vtPlaneSecDir);
|
|
|
|
AcDbObjectId idBlk = GetBlockIdFromString(_T("$pump$00000060"));
|
|
AcDbObjectId id = CreateNewBlkRecord(idBlk, PI, _T("00000060-2"));
|
|
if (id.isValid())
|
|
{
|
|
BlockRefInfo info(id, AcGeScale3d(m_nLength, m_nWidth, 1), ptTemp, dDist * (-1), ptMax, ptMin);
|
|
TSectionFill *pFill = new TSectionFill(info, layerId());
|
|
arFillPtrs.append(pFill);
|
|
}
|
|
}
|
|
else// 管线与剖面方向相反
|
|
{
|
|
SplitSlbName(_T("PUMP(00000060)"), xsTKName, xsRocord);
|
|
LoadDwbBlock(xsTKName, xsRocord, xsBlk);
|
|
ptTemp += -AcGeVector3d::kXAxis * m_nLength / 2;
|
|
ptTemp = ptTemp.project(plane, vtPlaneSecDir);
|
|
|
|
AcDbObjectId id = GetBlockIdFromString(_T("$pump$00000060"));
|
|
BlockRefInfo info(id, AcGeScale3d(m_nLength, m_nWidth, 1), ptTemp, dDist * (-1), ptMax, ptMin);
|
|
TSectionFill *pFill = new TSectionFill(info, layerId());
|
|
arFillPtrs.append(pFill);
|
|
}
|
|
}
|
|
}
|
|
else if (vtr.isParallelTo(AcGeVector3d::kYAxis))
|
|
{
|
|
if (vtPlaneSecDir.isCodirectionalTo(AcGeVector3d::kXAxis))
|
|
{
|
|
if (vtr.isCodirectionalTo(AcGeVector3d::kYAxis)) // 管线与X轴方向相同
|
|
{
|
|
SplitSlbName(_T("PUMP(00000060)"), xsTKName, xsRocord);
|
|
LoadDwbBlock(xsTKName, xsRocord, xsBlk);
|
|
ptTemp += AcGeVector3d::kYAxis * m_nLength /2;
|
|
ptTemp = ptTemp.project(plane, vtPlaneSecDir);
|
|
|
|
AcDbObjectId idBlk = GetBlockIdFromString(_T("$pump$00000060"));
|
|
AcDbObjectId id = CreateNewBlkRecord(idBlk, PI, _T("00000060-2"));
|
|
if (id.isValid())
|
|
{
|
|
BlockRefInfo info(id, AcGeScale3d(m_nLength, m_nWidth, 1), ptTemp, dDist * (-1), ptMax, ptMin);
|
|
TSectionFill *pFill = new TSectionFill(info, layerId());
|
|
arFillPtrs.append(pFill);
|
|
}
|
|
}
|
|
else// 管线与X轴方向相反
|
|
{
|
|
SplitSlbName(_T("PUMP(00000060)"), xsTKName, xsRocord);
|
|
LoadDwbBlock(xsTKName, xsRocord, xsBlk);
|
|
ptTemp += -AcGeVector3d::kYAxis * m_nLength /2;
|
|
ptTemp = ptTemp.project(plane, vtPlaneSecDir);
|
|
|
|
AcDbObjectId id = GetBlockIdFromString(_T("$pump$00000060"));
|
|
BlockRefInfo info(id, AcGeScale3d(m_nLength, m_nWidth, 1), ptTemp, dDist * (-1), ptMax, ptMin);
|
|
TSectionFill *pFill = new TSectionFill(info, layerId());
|
|
arFillPtrs.append(pFill);
|
|
}
|
|
}
|
|
else if (vtPlaneSecDir.isCodirectionalTo(-AcGeVector3d::kXAxis))
|
|
{
|
|
if (vtr.isCodirectionalTo(AcGeVector3d::kYAxis)) // 管线与Y轴方向相同
|
|
{
|
|
SplitSlbName(_T("PUMP(00000060)"), xsTKName, xsRocord);
|
|
LoadDwbBlock(xsTKName, xsRocord, xsBlk);
|
|
ptTemp += AcGeVector3d::kYAxis * m_nLength /2;
|
|
ptTemp = ptTemp.project(plane, vtPlaneSecDir);
|
|
|
|
AcDbObjectId id = GetBlockIdFromString(_T("$pump$00000060"));
|
|
BlockRefInfo info(id, AcGeScale3d(m_nLength, m_nWidth, 1), ptTemp, dDist * (-1), ptMax, ptMin);
|
|
TSectionFill *pFill = new TSectionFill(info, layerId());
|
|
arFillPtrs.append(pFill);
|
|
}
|
|
else if (vtr.isCodirectionalTo(-AcGeVector3d::kYAxis))// 管线与Y轴方向相反
|
|
{
|
|
SplitSlbName(_T("PUMP(00000060)"), xsTKName, xsRocord);
|
|
LoadDwbBlock(xsTKName, xsRocord, xsBlk);
|
|
ptTemp += -AcGeVector3d::kYAxis * m_nLength /2;
|
|
ptTemp = ptTemp.project(plane, vtPlaneSecDir);
|
|
|
|
AcDbObjectId idBlk = GetBlockIdFromString(_T("$pump$00000060"));
|
|
AcDbObjectId id = CreateNewBlkRecord(idBlk, PI, _T("00000060-2"));
|
|
if (id.isValid())
|
|
{
|
|
BlockRefInfo info(id, AcGeScale3d(m_nLength, m_nWidth, 1), ptTemp, dDist * (-1), ptMax, ptMin);
|
|
TSectionFill *pFill = new TSectionFill(info, layerId());
|
|
arFillPtrs.append(pFill);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
else if (vtr.isParallelTo(vtPlaneSecDir)) // 管线与剖面方向平行
|
|
{
|
|
SplitSlbName(_T("PUMP(00000061)"), xsTKName, xsRocord);
|
|
LoadDwbBlock(xsTKName, xsRocord, xsBlk);
|
|
ptTemp = ptTemp.project(plane, vtPlaneSecDir);
|
|
|
|
AcDbObjectId id = GetBlockIdFromString(_T("$pump$00000061"));
|
|
BlockRefInfo info(id, AcGeScale3d(m_nLength, m_nWidth, 1), ptTemp, dDist * (-1), ptMax, ptMin);
|
|
TSectionFill *pFill = new TSectionFill(info, layerId());
|
|
arFillPtrs.append(pFill);
|
|
}
|
|
|
|
pPipe->close();
|
|
}
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|