2917 lines
83 KiB
C++
2917 lines
83 KiB
C++
#include "stdafx.h"
|
||
#include <DbPolyMesh.h>
|
||
#include "DbFlangeFitting.h"
|
||
#include "DbDoubleLinePipe.h"
|
||
#include "PipeTools.h"
|
||
#include "GlobalFunction.h"
|
||
#include "TGripImp.h"
|
||
|
||
CString g_sCurrentCmd; // 当前执行命令 cet 2012.11.16 add
|
||
|
||
extern XArc GetFilletArc(XLine &l1, XLine &l2, double nRadius, XPoint &ptTmp1, XPoint &ptTmp2);
|
||
//extern XArc GetFilletArc2(XLine &l1, XLine &l2, double nRadius, XPoint &ptTmp1, XPoint &ptTmp2);
|
||
extern void DrawWeight(XExplodeDraw &dc,double dWeight,XCurveSegment &seg,int nColorIndex, double nScale);
|
||
extern Acad::ErrorStatus DrawPolyMesh(XPoint ptS, XPoint ptE, double nRadius, XExplodeDraw &dc);
|
||
|
||
Adesk::Boolean acedPostCommand(const TCHAR * );
|
||
|
||
XArc GetFilletArc(XLine &l1, XLine &l2, double nRadius)
|
||
{
|
||
XPoint pt1, pt2;
|
||
return GetFilletArc(l1,l2,nRadius,pt1, pt2);
|
||
}
|
||
|
||
XArc GetFilletArc2(XLine &l1, XLine &l2, double nRadius, XPoint &ptTmp1, XPoint &ptTmp2)
|
||
{
|
||
XPoint ptInt, pt1, pt2, pt3, pt4, ptCen;
|
||
XPoint pt5, pt6;
|
||
l1.SetLineFlag(0);
|
||
l2.SetLineFlag(0);
|
||
int ret = l1.Intersection(&l2, ptInt);
|
||
double nDist1 = ads_distance(ptInt, l1.GetStartPoint());
|
||
double nDist2 = ads_distance(ptInt, l1.GetEndPoint());
|
||
if(nDist1 < nDist2){
|
||
pt1 = l1.EndPoint();
|
||
pt5 = l1.StartPoint();
|
||
}
|
||
else{
|
||
pt1 = l1.StartPoint();
|
||
pt5 = l1.EndPoint();
|
||
}
|
||
|
||
nDist1 = ads_distance(ptInt, l2.GetStartPoint());
|
||
nDist2 = ads_distance(ptInt, l2.GetEndPoint());
|
||
if(nDist1 < nDist2){
|
||
pt2 = l2.EndPoint();
|
||
pt6 = l2.StartPoint();
|
||
}
|
||
else{
|
||
pt2 = l2.StartPoint();
|
||
pt6 = l2.EndPoint();
|
||
}
|
||
AT_cal_fillet(pt1, ptInt, pt2, nRadius, pt3, ptCen, pt4);
|
||
l1.SetLineFlag(1);
|
||
l2.SetLineFlag(1);
|
||
//如果弧端点在直线上,把弧端点改为直线端点
|
||
int flag1 = pt3&l1;
|
||
int flag2 = pt4&l2;
|
||
if(flag1 == 3){
|
||
pt3 = pt5;
|
||
}
|
||
if(flag2 == 3){
|
||
pt4 = pt6;
|
||
}
|
||
ptTmp1 = pt3;
|
||
ptTmp2 = pt4;
|
||
double nAng1 = CT_std_angle(ads_angle(ptCen, pt3) - ads_angle(ptCen, pt4));
|
||
double nAng2 = CT_std_angle(ads_angle(ptCen, pt4) - ads_angle(ptCen, pt3));
|
||
XArc arc1(pt4, pt3, nAng1);
|
||
XArc arc2(pt3, pt4, nAng2);
|
||
if(arc1.GetLength() > arc2.GetLength())
|
||
return arc2;
|
||
else
|
||
return arc1;
|
||
}
|
||
|
||
//BOOL IsParallelLine(XLine &l1, XLine &l2)
|
||
//{
|
||
// AcGeVector3d vt1 = XVector3D(l1.EndPoint() - l1.StartPoint()).AsAcGeVector3d();
|
||
// AcGeVector3d vt2 = XVector3D(l2.EndPoint() - l2.StartPoint()).AsAcGeVector3d();
|
||
// if(vt1.isParallelTo(vt2)==Adesk::kTrue) //平行
|
||
// return TRUE;
|
||
// else if(vt1.isCodirectionalTo(vt2)==Adesk::kTrue) //相反
|
||
// return TRUE;
|
||
// return FALSE;
|
||
//}
|
||
|
||
|
||
//////////////////////////////////////////////////////////////////////
|
||
// Construction/Destruction
|
||
//////////////////////////////////////////////////////////////////////
|
||
|
||
TWT_GRIPAPPDATA TDbFlangeFitting::s_gripAppData[GRIP_MAXNUM_DBPIPE_FITTING];
|
||
|
||
ACRX_DXF_DEFINE_MEMBERS(ATSFlangeFitting, ATSPipTeFitting, AcDb::kDHL_CURRENT,
|
||
AcDb::kMReleaseCurrent, 1, ATS_FLANGE,
|
||
"ATS_FLANGE图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com");
|
||
IMPLEMENT_TENTBASE(TDbFlangeFitting);
|
||
const Adesk::UInt8 TDbFlangeFitting::g_nVersion = 2;
|
||
|
||
TDbFlangeFitting::TDbFlangeFitting()
|
||
{
|
||
}
|
||
|
||
TDbFlangeFitting::~TDbFlangeFitting()
|
||
{
|
||
|
||
}
|
||
|
||
Acad::ErrorStatus TDbFlangeFitting::subGetClassID(CLSID* pClsid) const
|
||
{
|
||
// *pClsid = CLSID_ComPipe;
|
||
return Acad::eOk;
|
||
}
|
||
|
||
void TDbFlangeFitting::CopyPropertiesFrom(AcDbEntity *pSrc,unsigned gMatchFlag)
|
||
{
|
||
assertWriteEnabled();
|
||
TDbPipeFitting::CopyPropertiesFrom(pSrc, gMatchFlag);
|
||
}
|
||
|
||
Acad::ErrorStatus
|
||
TDbFlangeFitting::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;
|
||
// cet 2012.11.12 modify 打开捕捉后,很难用于绘制,故作此修改
|
||
// if( osnapMode == AcDb::kOsModeIns ||
|
||
// osnapMode == AcDb::kOsModeNode) {
|
||
// snapPoints.append(m_ptLocation);
|
||
// }
|
||
// es=TDbPipeFitting::subGetOsnapPoints(osnapMode,gsSelectionMark,
|
||
// ptPick,lastPoint,viewXform,snapPoints,geomIds);
|
||
snapPoints.append(m_ptLocation);
|
||
return es;
|
||
}
|
||
|
||
// 从DWG读入数据:
|
||
Acad::ErrorStatus TDbFlangeFitting::dwgInFields(AcDbDwgFiler* pFiler)
|
||
{
|
||
assertWriteEnabled();
|
||
|
||
Acad::ErrorStatus es = TDbPipeFitting::dwgInFields(pFiler);
|
||
if(es != Acad::eOk) return es;
|
||
Adesk::UInt8 nVer;
|
||
pFiler->readItem(&nVer);
|
||
if(nVer>g_nVersion) {// Version is too new
|
||
return Acad::eMakeMeProxy;
|
||
}
|
||
if(nVer > 1)
|
||
pFiler->readItem(&m_idDoteLayer);
|
||
else
|
||
m_idDoteLayer = ::InitLayer(_T("0"), database());
|
||
|
||
return pFiler->filerStatus();
|
||
}
|
||
|
||
Acad::ErrorStatus TDbFlangeFitting::dwgOutFields(AcDbDwgFiler* pFiler) const
|
||
{
|
||
assertReadEnabled();
|
||
Acad::ErrorStatus es = TDbPipeFitting::dwgOutFields(pFiler);
|
||
if(es != Acad::eOk) return es;
|
||
|
||
pFiler->writeItem(g_nVersion);
|
||
pFiler->writeItem(m_idDoteLayer);
|
||
|
||
return pFiler->filerStatus();
|
||
}
|
||
|
||
Acad::ErrorStatus TDbFlangeFitting::dxfInFields(AcDbDxfFiler* pFiler)
|
||
{
|
||
assertWriteEnabled();
|
||
Acad::ErrorStatus es=Acad::eOk;
|
||
es=TDbPipeFitting::dxfInFields(pFiler);
|
||
if(es!=Acad::eOk) return es;
|
||
|
||
if (!pFiler->atSubclassData(_T("TDbFlangeFitting"))) {
|
||
return Acad::eBadDxfSequence;
|
||
}
|
||
|
||
return pFiler->filerStatus();
|
||
}
|
||
|
||
Acad::ErrorStatus TDbFlangeFitting::dxfOutFields(AcDbDxfFiler* pFiler) const
|
||
{
|
||
Acad::ErrorStatus es=Acad::eOk;
|
||
es=TDbPipeFitting::dxfOutFields(pFiler);
|
||
assert(es==Acad::eOk);
|
||
es=pFiler->writeItem(AcDb::kDxfSubclass,_T("TDbFlangeFitting"));
|
||
assert(es==Acad::eOk);
|
||
|
||
return es;
|
||
}
|
||
|
||
BOOL TDbFlangeFitting::IsHidePipe() const
|
||
{
|
||
if(m_lstInterface.Length() > 1){
|
||
for(int i=0; i<m_lstInterface.Length(); i++) {
|
||
const TPipeInterface &iFace=m_lstInterface[i];
|
||
XVector3D vt=iFace.m_vtLocation;
|
||
//sr 070420
|
||
// if(fabs(vt.x)<1.0E-6 && fabs(vt.y)<1.0E-6 && vt.z < 0) { //垂直向下的管线
|
||
// return FALSE;
|
||
// }
|
||
// else if(fabs(vt.x)<1.0E-6 && fabs(vt.y)<1.0E-6 && vt.z > 0){
|
||
// AcDbObjectId nextPipeId = iFace.m_idPipe;
|
||
// OPENOBJ_BEGIN(nextPipeId, AcDb::kForRead, TDbDoubleLinePipe, pPipe);
|
||
// if(pPipe){
|
||
// if(pPipe->GetFlange() != 0)
|
||
// return FALSE;//垂直向上的管线,但是不是法兰连接
|
||
// }
|
||
// OPENOBJ_END();
|
||
// }
|
||
}
|
||
return TRUE;
|
||
}
|
||
return FALSE;
|
||
}
|
||
|
||
double TDbFlangeFitting::GetWidth(const TDbPipePrototype* pPipe) const
|
||
{
|
||
double nDist = ((TDbDoubleLinePipe*)pPipe)->GetWidth();
|
||
double nFlangeThick = ((TDbDoubleLinePipe*)pPipe)->GetFlangeThick();
|
||
if(m_lstInterface.Length() > 2){
|
||
// cet 2012.11.6 modify 三通四通存在变径时,宽度大小取不带变径管线宽度最大值
|
||
/*
|
||
for(int i=0; i<m_lstInterface.Length(); i++) {
|
||
const TPipeInterface &iFace=m_lstInterface[i];
|
||
AcDbObjectId nextPipeId = iFace.m_idPipe;
|
||
OPENOBJ_BEGIN(nextPipeId, AcDb::kForRead, TDbDoubleLinePipe, pPipe);
|
||
if(pPipe){
|
||
double nDist2 = pPipe->GetWidth();
|
||
if(nDist2 > nDist)
|
||
nDist = nDist2;
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
*/
|
||
XPoint ptS = pPipe->StartPoint();
|
||
XPoint ptE = pPipe->EndPoint();
|
||
AcDbObjectId id;
|
||
int nNum = GetInterfaceNum();
|
||
if (ptS.Distance(m_ptLocation) < 0.001 && ((TDbDoubleLinePipe*)pPipe)->IsLinkReducing(0)
|
||
|| ptE.Distance(m_ptLocation) < 0.001 && ((TDbDoubleLinePipe*)pPipe)->IsLinkReducing(1))
|
||
{
|
||
AcGeVector3d vtPipe = ptE - ptS, vtTemp;
|
||
AcGeTol tol;
|
||
tol.setEqualVector(0.001);
|
||
for (int i = 0; i < nNum; i++)
|
||
{
|
||
const TPipeInterface &face = GetInterface(i);
|
||
if (pPipe->objectId() == face.m_idPipe)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
OPENOBJ_BEGIN(face.m_idPipe, AcDb::kForRead, TDbDoubleLinePipe, pDbPipe);
|
||
if (pDbPipe != NULL)
|
||
{
|
||
vtTemp = pDbPipe->StartPoint() - pDbPipe->EndPoint();
|
||
if (vtTemp.isParallelTo(vtPipe, tol))
|
||
{
|
||
id = face.m_idPipe;
|
||
nDist = pDbPipe->GetWidth();
|
||
nFlangeThick = pDbPipe->GetFlangeThick();
|
||
break;
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
}
|
||
|
||
for (int i = 0; i < nNum; i++)
|
||
{
|
||
const TPipeInterface &face = GetInterface(i);
|
||
// 排出连接变径的管线
|
||
if (pPipe->objectId() == face.m_idPipe || id == face.m_idPipe)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
OPENOBJ_BEGIN(face.m_idPipe, AcDb::kForRead, TDbDoubleLinePipe, pDbPipe);
|
||
if (pDbPipe != NULL)
|
||
{
|
||
ptS = pDbPipe->StartPoint();
|
||
ptE = pDbPipe->EndPoint();
|
||
if (ptS.Distance(m_ptLocation) < 0.001 && !pDbPipe->IsLinkReducing(0)
|
||
|| ptE.Distance(m_ptLocation) < 0.001 && !pDbPipe->IsLinkReducing(1))
|
||
{
|
||
double nDist2 = pDbPipe->GetWidth();
|
||
if(nDist2 > nDist)
|
||
{
|
||
nDist = nDist2;
|
||
}
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
|
||
nDist = nDist * 1.2; //三四通固定长度,没有按曲率
|
||
if(((TDbDoubleLinePipe*)pPipe)->GetFlange() == 0)
|
||
nDist += nFlangeThick*2;
|
||
// cet 2012.10.19 add 支持米单位
|
||
if (DocGetCurMeterUnitDraw())
|
||
{
|
||
nDist *= 0.001;
|
||
}
|
||
return nDist;
|
||
}
|
||
|
||
if(m_lstInterface.Length() != 2)
|
||
return 0;
|
||
double nDist1(0), nDist2(0);
|
||
XPoint pt5, pt6, ptOut1, ptOut2;
|
||
TPipeInterface face1, face2;
|
||
GetInterface(0, face1);
|
||
GetInterface(1, face2);
|
||
|
||
nDist1 = nDist;
|
||
Midpoint(pPipe->StartPoint(), pPipe->EndPoint(), ptOut1);
|
||
AcDbObjectId idOther = NULL;
|
||
if(face1.m_idPipe == pPipe->objectId())
|
||
idOther = face2.m_idPipe;
|
||
else
|
||
idOther = face1.m_idPipe;
|
||
|
||
OPENOBJ_BEGIN(idOther, AcDb::kForRead, TDbDoubleLinePipe, pPipe1);
|
||
if(pPipe1){
|
||
nDist2 = pPipe1->GetWidth();
|
||
Midpoint(pPipe1->StartPoint(), pPipe1->EndPoint(), ptOut2);
|
||
}
|
||
OPENOBJ_END();
|
||
double nRadius = nDist1 > nDist2 ? nDist1 : nDist2;
|
||
CString csRate = GetNumber();
|
||
double nRate = _tstof(csRate);
|
||
if(nRate < 0.1)
|
||
nRate = 1;
|
||
nRadius = nRadius * nRate;
|
||
|
||
// cet 2012.10.19 add 支持米单位
|
||
if (DocGetCurMeterUnitDraw())
|
||
{
|
||
nFlangeThick *= 0.001;
|
||
nRadius *= 0.001;
|
||
nDist *= 0.001;
|
||
}
|
||
|
||
// nRadius = nRadius * ((TDbDoubleLinePipe*)pPipe)->GetRate();
|
||
if(IsParallelLine(XLine(m_ptLocation, ptOut1), XLine(m_ptLocation, ptOut2))){
|
||
nRadius = nRadius/2;
|
||
if(((TDbDoubleLinePipe*)pPipe)->GetFlange() == 0)
|
||
nRadius += nFlangeThick*2;
|
||
return nRadius;
|
||
}
|
||
|
||
if(fabs(ptOut2.z - ptOut1.z) < 0.001){//水平的弯头
|
||
XLine l1(m_ptLocation, ptOut1), l2(m_ptLocation, ptOut2);
|
||
XArc arc4 = GetFilletArc(l1, l2, nRadius, pt5, pt6);
|
||
XPoint ptLoc = m_ptLocation;
|
||
int ret = pt5&(*pPipe);
|
||
if(ret == PR_INSIDE)
|
||
nDist = ads_distance(ptLoc, pt5);
|
||
else
|
||
nDist = ads_distance(ptLoc, pt6);
|
||
}
|
||
else
|
||
nDist = nRadius;
|
||
|
||
if(((TDbDoubleLinePipe*)pPipe)->GetFlange() == 0)
|
||
nDist += nFlangeThick*2;
|
||
|
||
return nDist;
|
||
}
|
||
|
||
bool TDbFlangeFitting::GetWidth( const AcDbObjectId &idPipe, double &dWidth, double &dFangleDn, double &dFlangeThick, double *pDn) const
|
||
{
|
||
bool bRet = false;
|
||
int nNum = GetInterfaceNum();
|
||
AcGeVector3d vtPipe;
|
||
for (int i = 0; i < nNum; i++)
|
||
{
|
||
const TPipeInterface &face = GetInterface(i);
|
||
if (face.m_idPipe == idPipe)
|
||
{
|
||
vtPipe = face.m_vtLocation;
|
||
break;
|
||
}
|
||
}
|
||
|
||
AcGeVector3d vtDir;
|
||
AcGeTol tol;
|
||
tol.setEqualVector(0.001);
|
||
TDbDoubleLinePipe *pPipe = NULL;
|
||
for (i = 0; i < nNum; i++)
|
||
{
|
||
const TPipeInterface &face = GetInterface(i);
|
||
if (face.m_idPipe == idPipe)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
acdbOpenObject(pPipe, face.m_idPipe, AcDb::kForRead);
|
||
if (pPipe != NULL)
|
||
{
|
||
vtDir = pPipe->StartPoint() - pPipe->EndPoint();
|
||
if (vtDir.isParallelTo(vtPipe, tol))
|
||
{
|
||
bRet = true;
|
||
dWidth = pPipe->GetWidth();
|
||
dFangleDn = pPipe->GetFlangeDn();
|
||
dFlangeThick = pPipe->GetFlangeThick();
|
||
if (pDn != NULL)
|
||
{
|
||
*pDn = pPipe->GetDnDiameter();
|
||
}
|
||
pPipe->close();
|
||
break;
|
||
}
|
||
pPipe->close();
|
||
}
|
||
}
|
||
return bRet;
|
||
}
|
||
|
||
void TDbFlangeFitting::DrawFlange(const XPoint ptEnd, double nAngOut, double nDn, double nThick, XExplodeDraw &dc) const
|
||
{
|
||
XPoint p11, p22, p33, p44, ptMid;
|
||
ads_polar(ptEnd, nAngOut+PI/2, nDn/2, p11);
|
||
ads_polar(ptEnd, nAngOut-PI/2, nDn/2, p22);
|
||
dc << XLine(p11, p22);
|
||
ads_polar(p11, nAngOut, nThick, p33);
|
||
dc << XLine(p11, p33);
|
||
ads_polar(p22, nAngOut, nThick, p44);
|
||
dc << XLine(p22, p44);
|
||
dc << XLine(p33, p44);
|
||
//第二个法兰
|
||
ads_polar(p33, nAngOut, nThick, p11);
|
||
dc << XLine(p11, p33);
|
||
ads_polar(p44, nAngOut, nThick, p22);
|
||
dc << XLine(p22, p44);
|
||
dc << XLine(p11, p22);
|
||
ptMid = XLine(p11, p22).MidPoint();
|
||
|
||
|
||
//法兰连接,要多画一段中心线,穿过法兰
|
||
XCurveSegment segCenter;
|
||
segCenter = XLine(ptEnd, ptMid);
|
||
DrawCenterLine(dc, segCenter);
|
||
|
||
// AcDbObjectId idLayerOld=dc.GetLayerId();
|
||
// AcDbObjectId idDoteLayer=m_idDoteLayer;
|
||
// if(idDoteLayer.isValid())
|
||
// dc.SetLayer(idDoteLayer);
|
||
// dc.SetColorLayer(colorIndex(), idDoteLayer);
|
||
// dc << XLine(ptEnd, ptMid);
|
||
// dc.SetLayer(idLayerOld);
|
||
// dc.SetColorLayer(colorIndex(), idLayerOld);
|
||
}
|
||
|
||
void TDbFlangeFitting::DrawFlange( const XPoint &ptEnd, const AcGeVector3d &vtDir, double dDn, double dThick, XExplodeDraw &dc ) const
|
||
{
|
||
AcGeVector3d vt = vtDir;
|
||
vt.normalize();
|
||
vt.rotateBy(PI / 2, AcGeVector3d::kZAxis);
|
||
AcGeVector3d vt2 = vtDir;
|
||
vt2.normalize();
|
||
|
||
XPoint pt1 = ptEnd + vt * dDn * 0.5;
|
||
XPoint pt2 = ptEnd - vt * dDn * 0.5;
|
||
dc << XLine(pt1, pt2);
|
||
|
||
XPoint pt3 = pt1 + vt2 * dThick;
|
||
XPoint pt4 = pt2 + vt2 * dThick;
|
||
dc << XLine(pt3, pt4);
|
||
|
||
XPoint pt5 = pt3 + vt2 * dThick;
|
||
XPoint pt6 = pt4 + vt2 * dThick;
|
||
dc << XLine(pt5, pt6);
|
||
|
||
dc << XLine(pt1, pt5);
|
||
dc << XLine(pt2, pt6);
|
||
|
||
XCurveSegment segCenter;
|
||
segCenter = XLine(ptEnd, ptEnd + vt2 * dThick * 2);
|
||
DrawCenterLine(dc, segCenter);
|
||
}
|
||
|
||
void TDbFlangeFitting::DrawLine(const const XLine &line, XExplodeDraw &dc) const
|
||
{
|
||
XCurveSegment seg;
|
||
seg = line;
|
||
if (IsPsLineWeight(this->database())) {
|
||
TPipeInterface face1;
|
||
GetInterface(0, face1);
|
||
double nWeight(0);
|
||
OPENOBJ_BEGIN(face1.m_idPipe, AcDb::kForRead, TDbDoubleLinePipe, pPipe);
|
||
if(pPipe){
|
||
nWeight = pPipe->GetPipeWeight();
|
||
}
|
||
OPENOBJ_END();
|
||
double dWeight = GetPScale()*nWeight;
|
||
// cet 2012.10.19 modify 支持米单位
|
||
if (DocGetCurMeterUnitDraw())
|
||
{
|
||
dWeight = GetPScale() * nWeight * 0.1;
|
||
}
|
||
DrawWeight(dc, dWeight, seg, colorIndex(), linetypeScale());
|
||
} else {
|
||
dc << line;
|
||
}
|
||
|
||
}
|
||
|
||
|
||
void TDbFlangeFitting::DrawArc(const XArc &arc, XExplodeDraw &dc, XPointList &lstPt) const
|
||
{
|
||
if(!arc)
|
||
return;
|
||
|
||
XCurveSegment seg;
|
||
seg = arc;
|
||
int iNum = 3;
|
||
double nEndAng = arc.GetEndAngle();
|
||
double nStartAng = arc.GetStarAngle();
|
||
if(fabs(nEndAng - PI*2) < 0.00001)
|
||
nEndAng -= PI*2;
|
||
if(fabs(nStartAng - PI*2) < 0.00001)
|
||
nStartAng -= PI*2;
|
||
|
||
double nAng = nEndAng - nStartAng;
|
||
nAng = nAng / PI * 180;
|
||
if(nAng < 89.999 && nAng > 45.001)
|
||
iNum --;
|
||
else if(nAng < 44.999 && nAng > 0)
|
||
iNum --;
|
||
else if(nAng < 134.999 && nAng > 90.001)
|
||
iNum ++;
|
||
else if(nAng > 135)
|
||
iNum ++;
|
||
AcDbCurve *pCurve=seg.AsAcDbCurve();
|
||
if(pCurve == NULL)
|
||
return;
|
||
double nStartParm(0), nEndParm(0);
|
||
pCurve->getStartParam(nStartParm);
|
||
pCurve->getEndParam(nEndParm);
|
||
double nStep = (nEndParm - nStartParm)/iNum;
|
||
double nParm = nStartParm - nStep/2;
|
||
AcGePoint3d ptTmp1, ptTmp2;
|
||
pCurve->getStartPoint(ptTmp1);
|
||
for(int i=0;i<iNum+1;i++){
|
||
if(i == iNum)
|
||
nParm += nStep/2;
|
||
else
|
||
nParm += nStep;
|
||
pCurve->getPointAtParam(nParm, ptTmp2);
|
||
lstPt.NewAppend(XPoint(ptTmp2));
|
||
XCurveSegment seg2;
|
||
seg2 = XLine(XPoint(ptTmp1), XPoint(ptTmp2), 1);
|
||
if (IsPsLineWeight(this->database())) {
|
||
TPipeInterface face1;
|
||
GetInterface(0, face1);
|
||
double nWeight(0);
|
||
OPENOBJ_BEGIN(face1.m_idPipe, AcDb::kForRead, TDbDoubleLinePipe, pPipe);
|
||
if(pPipe){
|
||
nWeight = pPipe->GetPipeWeight();
|
||
}
|
||
OPENOBJ_END();
|
||
double dWeight = GetPScale()*nWeight;
|
||
DrawWeight(dc, dWeight, seg2, colorIndex(), linetypeScale());
|
||
} else {
|
||
dc << seg2;
|
||
}
|
||
ptTmp1 = ptTmp2;
|
||
}
|
||
pCurve->close();
|
||
return;
|
||
|
||
}
|
||
|
||
|
||
|
||
void TDbFlangeFitting::DrawArc(const XArc &arc, XExplodeDraw &dc) const
|
||
{
|
||
XCurveSegment seg;
|
||
seg = arc;
|
||
if (IsPsLineWeight(this->database())) {
|
||
TPipeInterface face1;
|
||
GetInterface(0, face1);
|
||
double nWeight(0);
|
||
OPENOBJ_BEGIN(face1.m_idPipe, AcDb::kForRead, TDbDoubleLinePipe, pPipe);
|
||
if(pPipe){
|
||
nWeight = pPipe->GetPipeWeight();
|
||
}
|
||
OPENOBJ_END();
|
||
double dWeight = GetPScale()*nWeight;
|
||
DrawWeight(dc, dWeight, seg, colorIndex(), linetypeScale());
|
||
} else {
|
||
dc << arc;
|
||
}
|
||
}
|
||
|
||
|
||
//绘制垂直弯头
|
||
Acad::ErrorStatus TDbFlangeFitting::DrawElbowVer(XExplodeDraw &dc) const
|
||
{
|
||
Acad::ErrorStatus es=Acad::eOk;
|
||
TPipeInterface face1, face2;
|
||
GetInterface(0, face1);
|
||
XPoint ptOut1, ptOut2, pt5;
|
||
GetInterface(1, face2);
|
||
int iMode1 = 0, iMode2 = 0;
|
||
double nFlangeDn1(0), nFlangeThick1(0), nFlangeDn2(0), nFlangeThick2(0);
|
||
double nDist1(0), nDist2(0), dWidth1(0), dWidth2(0);
|
||
OPENOBJ_BEGIN(face1.m_idPipe, AcDb::kForRead, TDbDoubleLinePipe, pPipe);
|
||
if(pPipe){
|
||
nDist1 = pPipe->GetWidth();
|
||
iMode1 = pPipe->GetFlange();
|
||
nFlangeDn1 = pPipe->GetFlangeDn();
|
||
nFlangeThick1 = pPipe->GetFlangeThick();
|
||
ptOut1 = m_ptLocation == pPipe->EndPoint() ? pPipe->StartPoint() : pPipe->EndPoint();
|
||
dWidth1 = GetWidth(pPipe);
|
||
}
|
||
OPENOBJ_END();
|
||
OPENOBJ_BEGIN(face2.m_idPipe, AcDb::kForRead, TDbDoubleLinePipe, pPipe);
|
||
if(pPipe){
|
||
iMode2 = pPipe->GetFlange();
|
||
nFlangeDn2 = pPipe->GetFlangeDn();
|
||
nFlangeThick2 = pPipe->GetFlangeThick();
|
||
nDist2 = pPipe->GetWidth();
|
||
ptOut2 = m_ptLocation == pPipe->EndPoint() ? pPipe->StartPoint() : pPipe->EndPoint();
|
||
dWidth2 = GetWidth(pPipe);
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
// cet 2012.10.19 add 支持米单位
|
||
if (DocGetCurMeterUnitDraw())
|
||
{
|
||
nDist1 *= 0.001;
|
||
nFlangeDn1 *= 0.001;
|
||
nFlangeThick1 *= 0.001;
|
||
nDist2 *= 0.001;
|
||
nFlangeDn2 *= 0.001;
|
||
nFlangeThick2 *= 0.001;
|
||
}
|
||
|
||
XVector3D vt1=face1.m_vtLocation;
|
||
XVector3D vt2=face2.m_vtLocation;
|
||
double nAngOut1 = ads_angle(XPoint(), face1.m_vtLocation);
|
||
double nAngOut2 = ads_angle(XPoint(), face2.m_vtLocation);
|
||
|
||
AcDbObjectId idLayerOld=dc.GetLayerId();
|
||
AcDbObjectId idDoteLayer=m_idDoteLayer;
|
||
|
||
//出现扣弯的时候,绘制1个平面方向的法兰
|
||
if(fabs(vt1.x)<1.0E-6 && fabs(vt1.y)<1.0E-6)
|
||
{
|
||
double dDist3(0);
|
||
ads_polar(m_ptLocation, nAngOut2, dWidth2, pt5);
|
||
if(iMode2 == 0 && (fabs(vt2.x)>1.0E-6 || fabs(vt2.y)>1.0E-6)){
|
||
DrawFlange(pt5, nAngOut2, nFlangeDn2, nFlangeThick2, dc);
|
||
dDist3 = nFlangeDn1/2.0;
|
||
}
|
||
XLine line(m_ptLocation, pt5);
|
||
XCurveSegment seg, segUp, segDown, segUp2, segDown2;
|
||
if(ptOut1.z < ptOut2.z){ //上弯头
|
||
seg = line;
|
||
}
|
||
else{ //下弯头
|
||
XPoint ptMid;
|
||
//cet 2012.3.20 moidfy 角度设置错误
|
||
//ads_polar(m_ptLocation, nAngOut1, dDist3, ptMid);
|
||
ads_polar(m_ptLocation, nAngOut2, dDist3, ptMid);
|
||
XLine line2(ptMid, pt5);
|
||
seg = line2;
|
||
}
|
||
|
||
|
||
DrawCenterLine(dc, seg);
|
||
|
||
// if(idDoteLayer.isValid())
|
||
// dc.SetLayer(idDoteLayer);
|
||
// dc.SetColorLayer(colorIndex(), idDoteLayer);
|
||
// dc << seg;
|
||
// dc.SetLayer(idLayerOld);
|
||
// dc.SetColorLayer(colorIndex(), idLayerOld);
|
||
|
||
segUp = seg.Offset(nDist2/2, LS_FINITE);
|
||
segDown = seg.Offset(-nDist2/2, LS_FINITE);
|
||
|
||
segUp2 = seg.Offset(nDist1/2, LS_FINITE);
|
||
segDown2 = seg.Offset(-nDist1/2, LS_FINITE);
|
||
|
||
if(ptOut1.z < ptOut2.z || iMode2 == 1){ //上弯头
|
||
// DrawLine(XLine(segUp2.GetStartPoint(), segUp.GetEndPoint()), dc);
|
||
// DrawLine(XLine(segDown2.GetStartPoint(), segDown.GetEndPoint()), dc);
|
||
XLine line;
|
||
line.SetPoints(segUp2.GetStartPoint(), segUp.GetEndPoint());
|
||
ModifyLine(line, face1.m_idPipe);
|
||
DrawLine(line, dc);
|
||
line.SetPoints(segDown2.GetStartPoint(), segDown.GetEndPoint());
|
||
ModifyLine(line, face1.m_idPipe);
|
||
DrawLine(line, dc);
|
||
// dc << XLine(segUp2.StartPoint(), segUp.EndPoint());
|
||
// dc << XLine(segDown2.StartPoint(), segDown.EndPoint());
|
||
}
|
||
else{ //下弯头
|
||
DrawLine(segUp, dc);
|
||
DrawLine(segDown, dc);
|
||
// dc << segUp;
|
||
// dc << segDown;
|
||
}
|
||
|
||
return Acad::eOk;
|
||
}
|
||
|
||
if(fabs(vt2.x)<1.0E-6 && fabs(vt2.y)<1.0E-6)
|
||
{
|
||
ads_polar(m_ptLocation, nAngOut1, dWidth1, pt5);
|
||
double dDist3(0);
|
||
if(iMode1 == 0 && (fabs(vt1.x)>1.0E-6 || fabs(vt1.y)>1.0E-6)){
|
||
DrawFlange(pt5, nAngOut1, nFlangeDn1, nFlangeThick1, dc);
|
||
dDist3 = nFlangeDn2/2.0;
|
||
}
|
||
XLine line(m_ptLocation, pt5);
|
||
XCurveSegment seg, segUp, segDown, segUp2, segDown2;
|
||
if(ptOut1.z > ptOut2.z){ //上弯头
|
||
seg = line;
|
||
}
|
||
else{ //下弯头
|
||
XPoint ptMid;
|
||
ads_polar(m_ptLocation, nAngOut1, dDist3, ptMid);
|
||
XLine line2(ptMid, pt5);
|
||
seg = line2;
|
||
}
|
||
|
||
DrawCenterLine(dc, seg);
|
||
|
||
// if(idDoteLayer.isValid())
|
||
// dc.SetLayer(idDoteLayer);
|
||
// dc.SetColorLayer(colorIndex(), idDoteLayer);
|
||
// dc << seg;
|
||
// dc.SetLayer(idLayerOld);
|
||
// dc.SetColorLayer(colorIndex(), idLayerOld);
|
||
segUp = seg.Offset(nDist1/2, LS_FINITE);
|
||
segDown = seg.Offset(-nDist1/2, LS_FINITE);
|
||
|
||
segUp2 = seg.Offset(nDist2/2, LS_FINITE);
|
||
segDown2 = seg.Offset(-nDist2/2, LS_FINITE);
|
||
|
||
if(ptOut1.z > ptOut2.z || iMode1 == 1){ //上弯头
|
||
//cet 2011.11.9 modify
|
||
//DrawLine(XLine(segUp2.GetStartPoint(), segUp.GetEndPoint()), dc);
|
||
//DrawLine(XLine(segDown2.GetStartPoint(), segDown.GetEndPoint()), dc);
|
||
XLine line;
|
||
line.SetPoints(segUp2.GetStartPoint(), segUp.GetEndPoint());
|
||
ModifyLine(line, face2.m_idPipe);
|
||
DrawLine(line, dc);
|
||
line.SetPoints(segDown2.GetStartPoint(), segDown.GetEndPoint());
|
||
ModifyLine(line, face2.m_idPipe);
|
||
DrawLine(line, dc);
|
||
}
|
||
else{ //下弯头
|
||
DrawLine(segUp, dc);
|
||
DrawLine(segDown, dc);
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
return es;
|
||
}
|
||
|
||
//绘制弯头,变径
|
||
Acad::ErrorStatus TDbFlangeFitting::DrawElbow(XExplodeDraw &dc) const
|
||
{
|
||
|
||
Acad::ErrorStatus es=Acad::eOk;
|
||
double nDist=400;
|
||
double nDist1(0), nDist2(0);
|
||
double dDist1(0), dDist2(0);
|
||
double nFlangeDn1(0), nFlangeThick1(0), nFlangeDn2(0), nFlangeThick2(0);
|
||
int iMode1 = 0, iMode2 = 0;
|
||
|
||
XPoint ptOut1, ptOut2, pt3, pt4, pt5, pt6, pt7, pt8, pt9, pt10, ptInt1, ptInt2, ptInt3, ptInt4;
|
||
TPipeInterface face1, face2;
|
||
GetInterface(0, face1);
|
||
GetInterface(1, face2);
|
||
|
||
|
||
double nAngOut1 = ads_angle(XPoint(), face1.m_vtLocation);
|
||
double nAngOut2 = ads_angle(XPoint(), face2.m_vtLocation);
|
||
CString csRate = GetNumber();
|
||
double nRate = _tstof(csRate);
|
||
if(nRate < 0.1)
|
||
nRate = 1;
|
||
|
||
|
||
OPENOBJ_BEGIN(face1.m_idPipe, AcDb::kForRead, TDbDoubleLinePipe, pPipe);
|
||
if(pPipe){
|
||
dDist1 = GetWidth(pPipe);
|
||
nDist1 = pPipe->GetWidth();
|
||
iMode1 = pPipe->GetFlange();
|
||
nFlangeDn1 = pPipe->GetFlangeDn();
|
||
nFlangeThick1 = pPipe->GetFlangeThick();
|
||
ptOut1 = m_ptLocation == pPipe->EndPoint() ? pPipe->StartPoint() : pPipe->EndPoint();
|
||
if(pPipe->GetFlange() == 0)
|
||
{
|
||
// cet 2012.11.16 modify
|
||
// dDist1 = dDist1 - nFlangeThick1*2;
|
||
if (!DocGetCurMeterUnitDraw())
|
||
{
|
||
dDist1 = dDist1 - nFlangeThick1 * 2;
|
||
}
|
||
else
|
||
{
|
||
dDist1 = dDist1 - nFlangeThick1 * 2 * 0.001;
|
||
}
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
OPENOBJ_BEGIN(face2.m_idPipe, AcDb::kForRead, TDbDoubleLinePipe, pPipe);
|
||
if(pPipe){
|
||
dDist2 = GetWidth(pPipe);
|
||
iMode2 = pPipe->GetFlange();
|
||
nFlangeDn2 = pPipe->GetFlangeDn();
|
||
nFlangeThick2 = pPipe->GetFlangeThick();
|
||
nDist2 = pPipe->GetWidth();
|
||
ptOut2 = m_ptLocation == pPipe->EndPoint() ? pPipe->StartPoint() : pPipe->EndPoint();
|
||
if(pPipe->GetFlange() == 0)
|
||
{
|
||
// cet 2012.11.16 modify
|
||
// dDist2 = dDist2 - nFlangeThick2*2;
|
||
if (!DocGetCurMeterUnitDraw())
|
||
{
|
||
dDist2 = dDist2 - nFlangeThick2 * 2;
|
||
}
|
||
else
|
||
{
|
||
dDist2 = dDist2 - nFlangeThick2 * 2 * 0.001;
|
||
}
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
// cet 2012.10.19 add 支持米单位
|
||
if (DocGetCurMeterUnitDraw())
|
||
{
|
||
nFlangeDn1 *= 0.001;
|
||
nFlangeThick1 *= 0.001;
|
||
nDist1 *= 0.001;
|
||
nFlangeDn2 *= 0.001;
|
||
nFlangeThick2 *= 0.001;
|
||
nDist2 *= 0.001;
|
||
}
|
||
|
||
XVector3D vt1=face1.m_vtLocation;
|
||
XVector3D vt2=face2.m_vtLocation;
|
||
|
||
//出现扣弯的时候,绘制1个平面方向的法兰
|
||
if(fabs(vt1.x)<1.0E-6 && fabs(vt1.y)<1.0E-6) {
|
||
if(iMode2 == 0 && (fabs(vt2.x)>1.0E-6 || fabs(vt2.y)>1.0E-6)){
|
||
ads_polar(m_ptLocation, nAngOut2, nDist2, pt5);
|
||
DrawFlange(pt5, nAngOut2, nFlangeDn2, nFlangeThick2, dc);
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
if(fabs(vt2.x)<1.0E-6 && fabs(vt2.y)<1.0E-6) {
|
||
if(iMode1 == 0 && (fabs(vt1.x)>1.0E-6 || fabs(vt1.y)>1.0E-6)){
|
||
ads_polar(m_ptLocation, nAngOut1, nDist2, pt5);
|
||
DrawFlange(pt5, nAngOut1, nFlangeDn1, nFlangeThick1, dc);
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
|
||
|
||
AcDbObjectId idLayerOld=dc.GetLayerId();
|
||
AcDbObjectId idDoteLayer=m_idDoteLayer;
|
||
double nRadiusOld = nDist1 > nDist2 ? nDist1 : nDist2;
|
||
double nRadius = nRadiusOld * nRate;
|
||
|
||
//绘制变径
|
||
if(IsParallelLine(XLine(m_ptLocation, ptOut1), XLine(m_ptLocation, ptOut2))){
|
||
ads_polar(m_ptLocation, nAngOut1, dDist1, pt5);
|
||
ads_polar(m_ptLocation, nAngOut2, dDist2, pt6);
|
||
|
||
XCurveSegment segCenter;
|
||
segCenter = XLine(pt5, pt6);
|
||
DrawCenterLine(dc, segCenter);
|
||
|
||
// if(idDoteLayer.isValid())
|
||
// dc.SetLayer(idDoteLayer);
|
||
// dc.SetColorLayer(colorIndex(), idDoteLayer);
|
||
// dc << XLine(pt5, pt6);
|
||
// dc.SetLayer(idLayerOld);
|
||
// dc.SetColorLayer(colorIndex(), idLayerOld);
|
||
|
||
ads_polar(pt5, nAngOut1-PI/2, nDist1/2, pt7);
|
||
ads_polar(pt5, nAngOut1+PI/2, nDist1/2, pt8);
|
||
ads_polar(pt6, nAngOut2-PI/2, nDist2/2, pt9);
|
||
ads_polar(pt6, nAngOut2+PI/2, nDist2/2, pt10);
|
||
XPoint p11, p22, p33, p44;
|
||
if(iMode1 == 1) //焊接连接
|
||
dc << XLine(pt7, pt8, 1);
|
||
else //法兰连接
|
||
DrawFlange(pt5, nAngOut1, nFlangeDn1, nFlangeThick1, dc);
|
||
if(iMode2 == 1) //焊接连接
|
||
dc << XLine(pt9, pt10, 1);
|
||
else //法兰连接
|
||
DrawFlange(pt6, nAngOut2, nFlangeDn2, nFlangeThick2, dc);
|
||
|
||
//绘制边线
|
||
DrawLine(XLine(pt8, pt9, 1), dc);
|
||
DrawLine(XLine(pt7, pt10, 1), dc);
|
||
|
||
return es;
|
||
}
|
||
//绘制中心弧
|
||
XLine _l1(m_ptLocation, ptOut1), _l2(m_ptLocation, ptOut2);
|
||
XArc arc4 = GetFilletArc(_l1, _l2, nRadius, pt5, pt6);
|
||
|
||
XCurveSegment segCenter;
|
||
segCenter = arc4;
|
||
DrawCenterLine(dc, segCenter);
|
||
|
||
// if(idDoteLayer.isValid())
|
||
// dc.SetLayer(idDoteLayer);
|
||
// dc.SetColorLayer(colorIndex(), idDoteLayer);
|
||
// dc << arc4;
|
||
// dc.SetLayer(idLayerOld);
|
||
// dc.SetColorLayer(colorIndex(), idLayerOld);
|
||
|
||
ads_polar(pt5, nAngOut1-PI/2, nDist1/2, pt7);
|
||
ads_polar(pt5, nAngOut1+PI/2, nDist1/2, pt8);
|
||
ads_polar(pt6, nAngOut2-PI/2, nDist2/2, pt9);
|
||
ads_polar(pt6, nAngOut2+PI/2, nDist2/2, pt10);
|
||
XPoint p11, p22, p33, p44;
|
||
if(iMode1 == 1) //焊接连接
|
||
dc << XLine(pt7, pt8, 1);
|
||
else //法兰连接
|
||
DrawFlange(pt5, nAngOut1, nFlangeDn1, nFlangeThick1, dc);
|
||
if(iMode2 == 1) //焊接连接
|
||
dc << XLine(pt9, pt10, 1);
|
||
else //法兰连接
|
||
DrawFlange(pt6, nAngOut2, nFlangeDn2, nFlangeThick2, dc);
|
||
|
||
//绘制2边弧
|
||
XPoint ptm1, ptm2, ptm3, ptm4;
|
||
XLine lineDote1(m_ptLocation, ptOut1);
|
||
XLine lineDote2(m_ptLocation, ptOut2);
|
||
|
||
XLine l1 = lineDote1.Offset(nDist1/2);
|
||
XLine l2 = lineDote1.Offset(-nDist1/2);
|
||
XLine l3 = lineDote2.Offset(nDist2/2);
|
||
XLine l4 = lineDote2.Offset(-nDist2/2);
|
||
|
||
ptm1 = l1.MidPoint();
|
||
ptm2 = l2.MidPoint();
|
||
ptm3 = l3.MidPoint();
|
||
ptm4 = l4.MidPoint();
|
||
//判断哪2边是外圆,哪2边是内圆。 看看2管夹角是否大于PI
|
||
AcGeVector3d vtNormal(0,0,1);
|
||
AcGeVector3d vt3 = lineDote1.Direction3d().AsAcGeVector3d();
|
||
AcGeVector3d vt4 = lineDote2.Direction3d().AsAcGeVector3d();
|
||
double nAngle = vt3.angleTo(vt4,vtNormal);
|
||
|
||
|
||
XPointList lstPt1, lstPt2;
|
||
double nRadiusIn = nRadius - nRadiusOld/2;
|
||
double nRadiusOut = nRadius + nRadiusOld/2;
|
||
|
||
//临时创建4跟线, 从中点到实际管线的端点
|
||
XLine lineTmp1(pt7, ptm1);
|
||
XLine lineTmp2(pt8, ptm2);
|
||
XLine lineTmp3(pt9, ptm3);
|
||
XLine lineTmp4(pt10, ptm4);
|
||
|
||
if(nAngle > PI){
|
||
XArc arc5 = GetFilletArc2(lineTmp1, lineTmp4, nRadiusIn, pt5, pt6);
|
||
if(pt5 != pt7)
|
||
DrawLine(XLine(pt5, pt7, 1), dc);
|
||
if(pt10 != pt6)
|
||
DrawLine(XLine(pt10, pt6, 1), dc);
|
||
DrawArc(arc5, dc, lstPt1);
|
||
XArc arc6 = GetFilletArc2(lineTmp2, lineTmp3, nRadiusOut, pt5, pt6);
|
||
DrawArc(arc6, dc, lstPt2);
|
||
if(pt5 != pt8)
|
||
DrawLine(XLine(pt5, pt8, 1), dc);
|
||
if(pt6 != pt9)
|
||
DrawLine(XLine(pt6, pt9, 1), dc);
|
||
}
|
||
else if(nAngle < PI){//2-3 1-4
|
||
XArc arc5 = GetFilletArc2(lineTmp2, lineTmp3, nRadiusIn, pt5, pt6);
|
||
if(pt5 != pt8)
|
||
DrawLine(XLine(pt5, pt8, 1), dc);
|
||
if(pt9 != pt6)
|
||
DrawLine(XLine(pt9, pt6, 1), dc);
|
||
DrawArc(arc5, dc, lstPt1);
|
||
XArc arc6 = GetFilletArc2(lineTmp1, lineTmp4, nRadiusOut, pt5, pt6);
|
||
DrawArc(arc6, dc, lstPt2);
|
||
if(pt5 != pt7)
|
||
DrawLine(XLine(pt5, pt7, 1), dc);
|
||
if(pt6 != pt10)
|
||
DrawLine(XLine(pt6, pt10, 1), dc);
|
||
}
|
||
|
||
|
||
//绘制弧的折断线
|
||
int len3 = lstPt1.Length() < lstPt2.Length() ? lstPt1.Length() : lstPt2.Length();
|
||
for(int n=0;n<len3;n++){
|
||
XPoint pt11 = *lstPt1[n];
|
||
XPoint pt22 = *lstPt2[n];
|
||
dc << XLine(pt11, pt22, 1);
|
||
}
|
||
return es;
|
||
}
|
||
|
||
|
||
//绘制弯头,变径 弧形弯头
|
||
Acad::ErrorStatus TDbFlangeFitting::DrawElbow2(XExplodeDraw &dc) const
|
||
{
|
||
Acad::ErrorStatus es=Acad::eOk;
|
||
double nDist=400;
|
||
double nDist1(0), nDist2(0);
|
||
double dDist1(0), dDist2(0);
|
||
double nFlangeDn1(0), nFlangeThick1(0), nFlangeDn2(0), nFlangeThick2(0);
|
||
int iMode1 = 0, iMode2 = 0;
|
||
|
||
XPoint ptOut1, ptOut2, pt3, pt4, pt5, pt6, pt7, pt8, pt9, pt10, ptInt1, ptInt2, ptInt3, ptInt4;
|
||
TPipeInterface face1, face2;
|
||
GetInterface(0, face1);
|
||
GetInterface(1, face2);
|
||
|
||
CString csRate = GetNumber();
|
||
double nRate = _tstof(csRate);
|
||
|
||
double nAngOut1 = ads_angle(XPoint(), face1.m_vtLocation);
|
||
double nAngOut2 = ads_angle(XPoint(), face2.m_vtLocation);
|
||
|
||
OPENOBJ_BEGIN(face1.m_idPipe, AcDb::kForRead, TDbDoubleLinePipe, pPipe);
|
||
if(pPipe){
|
||
dDist1 = GetWidth(pPipe);
|
||
nDist1 = pPipe->GetWidth();
|
||
iMode1 = pPipe->GetFlange();
|
||
nFlangeDn1 = pPipe->GetFlangeDn();
|
||
nFlangeThick1 = pPipe->GetFlangeThick();
|
||
Midpoint(pPipe->StartPoint(), pPipe->EndPoint(), ptOut1);
|
||
// cet 2012.11.16 modify
|
||
// dDist1 = dDist1 - nFlangeThick1*2;
|
||
if (!DocGetCurMeterUnitDraw())
|
||
{
|
||
dDist1 = dDist1 - nFlangeThick1 * 2;
|
||
}
|
||
else
|
||
{
|
||
dDist1 = dDist1 - nFlangeThick1 * 2 * 0.001;
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
OPENOBJ_BEGIN(face2.m_idPipe, AcDb::kForRead, TDbDoubleLinePipe, pPipe);
|
||
if(pPipe){
|
||
dDist2 = GetWidth(pPipe);
|
||
nDist2 = pPipe->GetWidth();
|
||
iMode2 = pPipe->GetFlange();
|
||
nFlangeDn2 = pPipe->GetFlangeDn();
|
||
nFlangeThick2 = pPipe->GetFlangeThick();
|
||
Midpoint(pPipe->StartPoint(), pPipe->EndPoint(), ptOut2);
|
||
// cet 2012.11.16 modify
|
||
// dDist2 = dDist2 - nFlangeThick2*2;
|
||
if (!DocGetCurMeterUnitDraw())
|
||
{
|
||
dDist2 = dDist2 - nFlangeThick2 * 2;
|
||
}
|
||
else
|
||
{
|
||
dDist2 = dDist2 - nFlangeThick2 * 2 * 0.001;
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
// cet 2012.10.19 add 支持米单位
|
||
if (DocGetCurMeterUnitDraw())
|
||
{
|
||
nFlangeDn1 *= 0.001;
|
||
nFlangeThick1 *= 0.001;
|
||
nDist1 *= 0.001;
|
||
nFlangeDn2 *= 0.001;
|
||
nFlangeThick2 *= 0.001;
|
||
nDist2 *= 0.001;
|
||
}
|
||
|
||
|
||
XVector3D vt1=face1.m_vtLocation;
|
||
XVector3D vt2=face2.m_vtLocation;
|
||
|
||
//出现扣弯的时候,绘制1个平面方向的法兰
|
||
if(fabs(vt1.x)<1.0E-6 && fabs(vt1.y)<1.0E-6) {
|
||
if(iMode2 == 0 && (fabs(vt2.x)>1.0E-6 || fabs(vt2.y)>1.0E-6)){
|
||
ads_polar(m_ptLocation, nAngOut2, nDist2, pt5);
|
||
DrawFlange(pt5, nAngOut2, nFlangeDn2, nFlangeThick2, dc);
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
if(fabs(vt2.x)<1.0E-6 && fabs(vt2.y)<1.0E-6) {
|
||
if(iMode1 == 0 && (fabs(vt1.x)>1.0E-6 || fabs(vt1.y)>1.0E-6)){
|
||
ads_polar(m_ptLocation, nAngOut1, nDist2, pt5);
|
||
DrawFlange(pt5, nAngOut1, nFlangeDn1, nFlangeThick1, dc);
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
|
||
|
||
AcDbObjectId idLayerOld=dc.GetLayerId();
|
||
AcDbObjectId idDoteLayer=::InitLayer(_T("0"));
|
||
double nRadius = nDist1 > nDist2 ? nDist1 : nDist2;
|
||
double nRadiusOld = nRadius; // cet 2015.8.21 add 原始半径大小
|
||
nRadius = nRadius * nRate;
|
||
|
||
//绘制变径
|
||
if(IsParallelLine(XLine(m_ptLocation, ptOut1), XLine(m_ptLocation, ptOut2))){
|
||
ads_polar(m_ptLocation, nAngOut1, dDist1, pt5);
|
||
ads_polar(m_ptLocation, nAngOut2, dDist2, pt6);
|
||
|
||
XCurveSegment segCenter;
|
||
segCenter = XLine(pt5, pt6);
|
||
DrawCenterLine(dc, segCenter);
|
||
|
||
// if(idDoteLayer.isValid())
|
||
// dc.SetLayer(idDoteLayer);
|
||
// dc.SetColorLayer(colorIndex(), idDoteLayer);
|
||
// dc << XLine(pt5, pt6);
|
||
// dc.SetLayer(idLayerOld);
|
||
// dc.SetColorLayer(colorIndex(), idLayerOld);
|
||
|
||
ads_polar(pt5, nAngOut1-PI/2, nDist1/2, pt7);
|
||
ads_polar(pt5, nAngOut1+PI/2, nDist1/2, pt8);
|
||
ads_polar(pt6, nAngOut2-PI/2, nDist2/2, pt9);
|
||
ads_polar(pt6, nAngOut2+PI/2, nDist2/2, pt10);
|
||
XPoint p11, p22, p33, p44;
|
||
if(iMode1 == 1) //焊接连接
|
||
dc << XLine(pt7, pt8, 1);
|
||
else //法兰连接
|
||
DrawFlange(pt5, nAngOut1, nFlangeDn1, nFlangeThick1, dc);
|
||
if(iMode2 == 1) //焊接连接
|
||
dc << XLine(pt9, pt10, 1);
|
||
else //法兰连接
|
||
DrawFlange(pt6, nAngOut2, nFlangeDn2, nFlangeThick2, dc);
|
||
|
||
//绘制边线
|
||
DrawLine(XLine(pt8, pt9, 1), dc);
|
||
DrawLine(XLine(pt7, pt10, 1), dc);
|
||
|
||
return es;
|
||
}
|
||
//绘制中心弧
|
||
XLine _l1(m_ptLocation, ptOut1), _l2(m_ptLocation, ptOut2);
|
||
XArc arc4 = GetFilletArc(_l1, _l2, nRadius, pt5, pt6);
|
||
XCurveSegment segCenter;
|
||
segCenter = arc4;
|
||
DrawCenterLine(dc, segCenter);
|
||
|
||
// if(idDoteLayer.isValid())
|
||
// dc.SetLayer(idDoteLayer);
|
||
// dc.SetColorLayer(colorIndex(), idDoteLayer);
|
||
// dc << arc4;
|
||
// dc.SetLayer(idLayerOld);
|
||
// dc.SetColorLayer(colorIndex(), idLayerOld);
|
||
|
||
ads_polar(pt5, nAngOut1-PI/2, nDist1/2, pt7);
|
||
ads_polar(pt5, nAngOut1+PI/2, nDist1/2, pt8);
|
||
ads_polar(pt6, nAngOut2-PI/2, nDist2/2, pt9);
|
||
ads_polar(pt6, nAngOut2+PI/2, nDist2/2, pt10);
|
||
XPoint p11, p22, p33, p44;
|
||
if(iMode1 == 1) //焊接连接
|
||
dc << XLine(pt7, pt8, 1);
|
||
else //法兰连接
|
||
DrawFlange(pt5, nAngOut1, nFlangeDn1, nFlangeThick1, dc);
|
||
if(iMode2 == 1) //焊接连接
|
||
dc << XLine(pt9, pt10, 1);
|
||
else //法兰连接
|
||
DrawFlange(pt6, nAngOut2, nFlangeDn2, nFlangeThick2, dc);
|
||
|
||
//绘制2边弧
|
||
XPoint ptm1, ptm2, ptm3, ptm4;
|
||
XLine l1 = XLine(m_ptLocation, ptOut1).Offset(nDist1/2);
|
||
XLine l2 = XLine(m_ptLocation, ptOut1).Offset(-nDist1/2);
|
||
XLine l3 = XLine(m_ptLocation, ptOut2).Offset(nDist2/2);
|
||
XLine l4 = XLine(m_ptLocation, ptOut2).Offset(-nDist2/2);
|
||
ptm1 = l1.MidPoint();
|
||
ptm2 = l2.MidPoint();
|
||
ptm3 = l3.MidPoint();
|
||
ptm4 = l4.MidPoint();
|
||
l1.SetLineFlag(1);
|
||
l2.SetLineFlag(1);
|
||
l3.SetLineFlag(1);
|
||
l4.SetLineFlag(1);
|
||
int ret2 = l1.Intersection(&l4, ptInt2);
|
||
int ret3 = l2.Intersection(&l3, ptInt3);
|
||
// cet 2015.8.21 add 计算内外经大小
|
||
double nRadiusIn = nRadius - nRadiusOld / 2;
|
||
double nRadiusOut = nRadius + nRadiusOld / 2;
|
||
if(ret2 == 1){
|
||
XArc arc5 = GetFilletArc(l1, l4, nRadiusIn, pt5, pt6); // cet 2015.8.21 modify 半径计算错误
|
||
if(pt5 != pt7)
|
||
DrawLine(XLine(pt5, pt7, 1), dc);
|
||
if(pt10 != pt6)
|
||
DrawLine(XLine(pt10, pt6, 1), dc);
|
||
DrawArc(arc5, dc);
|
||
l2.SetLineFlag(0);
|
||
l3.SetLineFlag(0);
|
||
int ret5 = l2.Intersection(&l3, ptInt4);
|
||
XLine _l1(ptInt4, ptm2), _l2(ptInt4, ptm3);
|
||
XArc arc6 = GetFilletArc(_l1, _l2, nRadiusOut, pt5, pt6); // cet 2015.8.21 modify 半径计算错误
|
||
DrawArc(arc6, dc);
|
||
if(pt5 != pt8)
|
||
DrawLine(XLine(pt5, pt8, 1), dc);
|
||
if(pt6 != pt9)
|
||
DrawLine(XLine(pt6, pt9, 1), dc);
|
||
}
|
||
else if(ret3 == 1){//2-3 1-4
|
||
XArc arc5 = GetFilletArc(l2, l3, nRadiusIn, pt5, pt6); // cet 2015.8.21 modify 半径计算错误
|
||
if(pt5 != pt8)
|
||
DrawLine(XLine(pt5, pt8, 1), dc);
|
||
if(pt9 != pt6)
|
||
DrawLine(XLine(pt9, pt6, 1), dc);
|
||
DrawArc(arc5, dc);
|
||
l1.SetLineFlag(0);
|
||
l4.SetLineFlag(0);
|
||
int ret5 = l1.Intersection(&l4, ptInt4);
|
||
XLine _l3(ptInt4, ptm1), _l4(ptInt4, ptm4);
|
||
XArc arc6 = GetFilletArc(_l3, _l4, nRadiusOut, pt5, pt6); // cet 2015.8.21 modify 半径计算错误
|
||
DrawArc(arc6, dc);
|
||
if(pt5 != pt7)
|
||
DrawLine(XLine(pt5, pt7, 1), dc);
|
||
if(pt6 != pt10)
|
||
DrawLine(XLine(pt6, pt10, 1), dc);
|
||
}
|
||
|
||
|
||
|
||
return es;
|
||
}
|
||
|
||
//堵头
|
||
Acad::ErrorStatus TDbFlangeFitting::DrawTerminal(XExplodeDraw &dc) const
|
||
{
|
||
Acad::ErrorStatus es=Acad::eOk;
|
||
double nDist=400;
|
||
double nFlangeDn(0), nFlangeThick(0);
|
||
int iMode = 0;
|
||
TPipeInterface face;
|
||
GetInterface(0, face);
|
||
AcDbObjectId nextPipeId = face.m_idPipe;
|
||
OPENOBJ_BEGIN(nextPipeId, AcDb::kForRead, TDbDoubleLinePipe, pPipe);
|
||
if(pPipe){
|
||
nDist = pPipe->GetWidth();
|
||
iMode = pPipe->GetFlange();
|
||
nFlangeDn = pPipe->GetFlangeDn();
|
||
nFlangeThick = pPipe->GetFlangeThick();
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
// cet 2012.10.19 add 支持米单位
|
||
if (DocGetCurMeterUnitDraw())
|
||
{
|
||
nDist *= 0.001;
|
||
nFlangeDn *= 0.001;
|
||
nFlangeThick *= 0.001;
|
||
}
|
||
|
||
XVector3D vt=face.m_vtLocation;
|
||
if(fabs(vt.x)<1.0E-6 && fabs(vt.y)<1.0E-6) { //垂直管线
|
||
return Acad::eOk;
|
||
}
|
||
|
||
vt.Normalize();
|
||
vt *= nDist;
|
||
double nAngOut=ads_angle(XPoint(), vt);
|
||
XPoint pt1, pt2, pt3, pt4;
|
||
if(iMode == 1){ //焊接连接
|
||
ads_polar(m_ptLocation, nAngOut+PI/2, nDist/2, pt1);
|
||
ads_polar(m_ptLocation, nAngOut-PI/2, nDist/2, pt2);
|
||
dc << XLine(pt1, pt2);
|
||
}
|
||
else{ //法兰连接
|
||
ads_polar(m_ptLocation, nAngOut+PI/2, nFlangeDn/2, pt1);
|
||
ads_polar(m_ptLocation, nAngOut-PI/2, nFlangeDn/2, pt2);
|
||
dc << XLine(pt1, pt2);
|
||
ads_polar(pt1, nAngOut, -nFlangeThick, pt3);
|
||
dc << XLine(pt1, pt3);
|
||
ads_polar(pt2, nAngOut, -nFlangeThick, pt4);
|
||
dc << XLine(pt2, pt4);
|
||
dc << XLine(pt3, pt4);
|
||
}
|
||
return es;
|
||
}
|
||
|
||
|
||
//绘制中心线
|
||
void TDbFlangeFitting::DrawCenterLine(XExplodeDraw &dc,XCurveSegment &seg) const
|
||
{
|
||
if(_tcsicmp(dc.Desc(), XExplodeStream::Descriptor())==0) { //另存旧版,炸开 2图层
|
||
AcDbObjectId idLayerOld=dc.GetLayerId();
|
||
AcDbObjectId idDoteLayer=m_idDoteLayer;
|
||
if(idDoteLayer.isValid())
|
||
dc.SetLayer(idDoteLayer);
|
||
dc.SetColorLayer(colorIndex(), idDoteLayer);
|
||
|
||
dc << seg;
|
||
|
||
dc.SetLayer(idLayerOld);
|
||
dc.SetColorLayer(colorIndex(), idLayerOld);
|
||
}
|
||
else{ //自定义实体 1个图层
|
||
AcDbObjectId idLineTypeOld = dc.GetLineTypeId();
|
||
int iColorOld = dc.GetColor();
|
||
AcDbObjectId idLineType = NULL;
|
||
OPENOBJ_BEGIN(m_idDoteLayer,AcDb::kForRead,AcDbLayerTableRecord,pLayer);
|
||
if(pLayer){
|
||
idLineType = pLayer->linetypeObjectId();
|
||
AcCmColor Color = pLayer->color();
|
||
int iColIdx = Color.colorIndex();
|
||
dc.SetColor(iColIdx);
|
||
dc.SetLineType(idLineType);
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
dc << seg;
|
||
|
||
dc.SetLineType(idLineTypeOld);
|
||
dc.SetColor(iColorOld);
|
||
}
|
||
}
|
||
|
||
//三通四通
|
||
Acad::ErrorStatus TDbFlangeFitting::DrawCorner(XExplodeDraw &dc) const
|
||
{
|
||
Acad::ErrorStatus es=Acad::eOk;
|
||
DList<XLine> lstLine;
|
||
DList<XLine> lstSort;
|
||
for(int i=0; i<m_lstInterface.Length(); i++) {
|
||
int iMode = 0;
|
||
double nFlangeDn(0), nFlangeThick(0);
|
||
const TPipeInterface &iFace=m_lstInterface[i];
|
||
AcDbObjectId nextPipeId = iFace.m_idPipe;
|
||
double nDist=400;
|
||
double nDist2=400;
|
||
bool bLinkReducing = false; // 管线是否连接变径 cet 2012.11.2 add
|
||
OPENOBJ_BEGIN(nextPipeId, AcDb::kForRead, TDbDoubleLinePipe, pPipe);
|
||
if(pPipe){
|
||
nDist = pPipe->GetWidth();
|
||
nDist2 = GetWidth(pPipe);
|
||
nFlangeDn = pPipe->GetFlangeDn();
|
||
iMode = pPipe->GetFlange();
|
||
nFlangeThick = pPipe->GetFlangeThick();
|
||
if(iMode == 0)
|
||
{
|
||
// cet 2012.10.19 modify 支持米单位
|
||
// nDist2 = nDist2 - nFlangeThick*2;
|
||
if (DocGetCurMeterUnitDraw())
|
||
{
|
||
nDist2 = nDist2 - nFlangeThick * 2 * 0.001;
|
||
}
|
||
else
|
||
{
|
||
nDist2 = nDist2 - nFlangeThick*2;
|
||
}
|
||
}
|
||
|
||
// cet 2012.11.2 add 是否连接变径
|
||
if (m_ptLocation.Distance(pPipe->StartPoint()) < 0.001)
|
||
{
|
||
bLinkReducing = pPipe->IsLinkReducing(0);
|
||
}
|
||
else
|
||
{
|
||
bLinkReducing = pPipe->IsLinkReducing(1);
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
// cet 2012.11.2 add 绘制变径
|
||
if (bLinkReducing)
|
||
{
|
||
double dWidth = 0.0;
|
||
double dFlangeDn = 0.0;
|
||
double dFlangeThick = 0.0;
|
||
if (GetWidth(nextPipeId, dWidth, dFlangeDn, dFlangeThick))
|
||
{
|
||
double dLen = dWidth > nDist ? dWidth : nDist;
|
||
double dMeter = 1.0;
|
||
if (DocGetCurMeterUnitDraw())
|
||
{
|
||
dMeter = 0.001;
|
||
}
|
||
AcGeVector3d vtDir = iFace.m_vtLocation;
|
||
vtDir.normalize();
|
||
XPoint ptS = m_ptLocation + vtDir * nDist2;
|
||
XPoint ptE = ptS + vtDir * dLen * dMeter;
|
||
XCurveSegment segCenter;
|
||
segCenter = XLine(ptS, ptE);
|
||
DrawCenterLine(dc, segCenter);
|
||
|
||
AcGeVector3d vtNor = vtDir;
|
||
vtNor.rotateBy(PI / 2, AcGeVector3d::kZAxis);
|
||
if (iMode == 1)
|
||
{
|
||
dc << XLine(ptE + vtNor * nDist /2 * dMeter, ptE - vtNor * nDist / 2 * dMeter );
|
||
XPoint pt1 = ptS + vtNor * dWidth * 0.5 * dMeter;
|
||
XPoint pt2 = ptE + vtNor * nDist * 0.5 * dMeter;
|
||
DrawLine(XLine(pt1, pt2), dc);
|
||
|
||
XPoint pt3 = ptS - vtNor * dWidth * 0.5 * dMeter;
|
||
XPoint pt4 = ptE - vtNor * nDist * 0.5 * dMeter;
|
||
DrawLine(XLine(pt3, pt4), dc);
|
||
}
|
||
else
|
||
{
|
||
DrawFlange(ptE, vtDir, nFlangeDn * dMeter, nFlangeThick * dMeter, dc);
|
||
XPoint pt1 = ptS + vtNor * dWidth * 0.5 * dMeter + vtDir * dFlangeThick * 2 * dMeter;
|
||
XPoint pt2 = ptE + vtNor * nDist * 0.5 * dMeter;
|
||
DrawLine(XLine(pt1, pt2), dc);
|
||
|
||
XPoint pt3 = ptS - vtNor * dWidth * 0.5 * dMeter + vtDir * dFlangeThick * 2 * dMeter;
|
||
XPoint pt4 = ptE - vtNor * nDist * 0.5 * dMeter;
|
||
DrawLine(XLine(pt3, pt4), dc);
|
||
}
|
||
|
||
nDist = dWidth;
|
||
nFlangeDn = dFlangeDn;
|
||
nFlangeThick = dFlangeThick;
|
||
}
|
||
}
|
||
|
||
// cet 2012.10.19 add 支持米单位
|
||
if (DocGetCurMeterUnitDraw())
|
||
{
|
||
nDist *= 0.001;
|
||
nFlangeDn *= 0.001;
|
||
nFlangeThick *= 0.001;
|
||
}
|
||
|
||
XVector3D vt=iFace.m_vtLocation;
|
||
vt.Normalize();
|
||
vt *= nDist2;
|
||
XPoint pt = m_ptLocation + vt;
|
||
|
||
if(pt.Distance2d(m_ptLocation)>_distSnap) { //接口不是垂直方向
|
||
pt.z=0;
|
||
double nAngOut=ads_angle(XPoint(), vt);
|
||
XPoint pt1, pt2;
|
||
ads_polar(pt, nAngOut+PI/2, nDist/2, pt1);
|
||
ads_polar(pt, nAngOut-PI/2, nDist/2, pt2);
|
||
if(iMode == 1) //焊接连接
|
||
dc << XLine(pt1, pt2, 1);
|
||
else //法兰连接
|
||
DrawFlange(pt, nAngOut, nFlangeDn, nFlangeThick, dc);
|
||
lstLine.Append(new XLine(pt1, pt2, 0));
|
||
}
|
||
|
||
//绘制中心线
|
||
XCurveSegment segCenter;
|
||
segCenter = XLine(m_ptLocation, pt);
|
||
DrawCenterLine(dc, segCenter);
|
||
|
||
// AcDbObjectId idLayerOld=dc.GetLayerId();
|
||
// AcDbObjectId idDoteLayer=m_idDoteLayer;
|
||
// if(idDoteLayer.isValid())
|
||
// dc.SetLayer(idDoteLayer);
|
||
// dc.SetColorLayer(colorIndex(), idDoteLayer);
|
||
// dc << XLine(m_ptLocation, pt);
|
||
// dc.SetLayer(idLayerOld);
|
||
// dc.SetColorLayer(colorIndex(), idLayerOld);
|
||
|
||
}
|
||
|
||
//绘制每个管子的连接线,其延长线与旁边管子延长线的交点
|
||
//思路:
|
||
//首先,建立lstLine(焊接链表),然后根据节点到焊接中心的角度进行排序,得到lstSort
|
||
//然后,把lstSort前后2节点取出来,按管线反方向创建延长线,
|
||
//用前节点的起始点引出的延长线 和 后节点终点引出的延长线 求交点
|
||
//如果有交点(四通,弯三通),绘制交点-节点
|
||
//没有交点(直三通),绘制节点-节点
|
||
while(lstLine.Length() > 0){
|
||
double nAngFinal = -1;
|
||
XLine line1;
|
||
int len = lstLine.Length();
|
||
int idx(0);
|
||
for(int i=0;i<len;i++){
|
||
XLine line2 = *lstLine[i];
|
||
XPoint ptMid;
|
||
ptMid = line2.MidPoint();
|
||
double nAng = ads_angle(m_ptLocation, ptMid);
|
||
if(nAngFinal > nAng || nAngFinal < 0){
|
||
nAngFinal = nAng;
|
||
line1 = line2;
|
||
idx = i;
|
||
}
|
||
}
|
||
lstLine.Remove(idx);
|
||
lstSort.Append(new XLine(line1));
|
||
}
|
||
int len = lstSort.Length();
|
||
XPoint ptInt;
|
||
for(i=0;i<len;i++){
|
||
XLine line1 = *lstSort[i];
|
||
XLine line2;
|
||
if(i == (len - 1))//最后一个节点找第一个节点
|
||
line2 = *lstSort[0];
|
||
else
|
||
line2 = *lstSort[i+1];
|
||
XPoint pt1, pt2;
|
||
ads_polar(line1.GetStartPoint(), line1.Direction()-PI/2, line1.GetLength(), pt1);
|
||
ads_polar(line2.GetEndPoint(), line2.Direction()-PI/2, line2.GetLength(), pt2);
|
||
XLine l1(line1.GetStartPoint(), pt1, 0);
|
||
XLine l2(line2.GetEndPoint(), pt2, 0);
|
||
int ret = l1.Intersection(&l2, ptInt);
|
||
if(ret == 0)
|
||
DrawLine(XLine(line1.GetStartPoint(), line2.GetEndPoint()), dc);
|
||
else{
|
||
DrawLine(XLine(line1.GetStartPoint(), ptInt), dc);
|
||
DrawLine(XLine(line2.GetEndPoint(), ptInt), dc);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
return es;
|
||
}
|
||
|
||
//三通四通 第二种画法
|
||
//无缝弯头 的情况
|
||
Acad::ErrorStatus TDbFlangeFitting::DrawCorner2(XExplodeDraw &dc) const
|
||
{
|
||
Acad::ErrorStatus es=Acad::eOk;
|
||
DList<XLine> lstLine;
|
||
DList<XLine> lstSort;
|
||
double dRadius(0);
|
||
BOOL bIsEqDn = TRUE;
|
||
for(int i=0; i<m_lstInterface.Length(); i++) {
|
||
int iMode = 0;
|
||
double nFlangeDn(0), nFlangeThick(0);
|
||
const TPipeInterface &iFace=m_lstInterface[i];
|
||
AcDbObjectId nextPipeId = iFace.m_idPipe;
|
||
double nDist=400;
|
||
double nDist2=400;
|
||
bool bLinkReducing = false; // 管线是否连接变径 cet 2012.11.2 add
|
||
OPENOBJ_BEGIN(nextPipeId, AcDb::kForRead, TDbDoubleLinePipe, pPipe);
|
||
if(pPipe){
|
||
nDist = pPipe->GetWidth();
|
||
if(i == 0)
|
||
dRadius = nDist;
|
||
else if(fabs(nDist - dRadius) > 0.01)
|
||
bIsEqDn = FALSE;
|
||
|
||
nDist2 = GetWidth(pPipe);
|
||
nFlangeDn = pPipe->GetFlangeDn();
|
||
iMode = pPipe->GetFlange();
|
||
nFlangeThick = pPipe->GetFlangeThick();
|
||
if(iMode == 0)
|
||
{
|
||
//nDist2 = nDist2 - nFlangeThick*2;
|
||
if (DocGetCurMeterUnitDraw())
|
||
{
|
||
nDist2 = nDist2 - nFlangeThick * 2 * 0.001;
|
||
}
|
||
else
|
||
{
|
||
nDist2 = nDist2 - nFlangeThick * 2;
|
||
}
|
||
}
|
||
|
||
// cet 2012.11.2 add 是否连接变径
|
||
if (m_ptLocation.Distance(pPipe->StartPoint()) < 0.001)
|
||
{
|
||
bLinkReducing = pPipe->IsLinkReducing(0);
|
||
}
|
||
else
|
||
{
|
||
bLinkReducing = pPipe->IsLinkReducing(1);
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
// cet 2012.11.2 add 绘制变径
|
||
if (bLinkReducing)
|
||
{
|
||
double dWidth = 0.0;
|
||
double dFlangeDn = 0.0;
|
||
double dFlangeThick = 0.0;
|
||
if (GetWidth(nextPipeId, dWidth, dFlangeDn, dFlangeThick))
|
||
{
|
||
double dMeter = 1.0;
|
||
if (DocGetCurMeterUnitDraw())
|
||
{
|
||
dMeter = 0.001;
|
||
}
|
||
double dLen = dWidth > nDist ? dWidth : nDist;
|
||
AcGeVector3d vtDir = iFace.m_vtLocation;
|
||
vtDir.normalize();
|
||
XPoint ptS = m_ptLocation + vtDir * nDist2;
|
||
XPoint ptE = ptS + vtDir * dLen * dMeter;
|
||
XCurveSegment segCenter;
|
||
segCenter = XLine(ptS, ptE);
|
||
DrawCenterLine(dc, segCenter);
|
||
|
||
AcGeVector3d vtNor = vtDir;
|
||
vtNor.rotateBy(PI / 2, AcGeVector3d::kZAxis);
|
||
if (iMode == 1)
|
||
{
|
||
dc << XLine(ptE + vtNor * nDist / 2 * dMeter, ptE - vtNor * nDist / 2 * dMeter );
|
||
XPoint pt1 = ptS + vtNor * dWidth * 0.5 * dMeter;
|
||
XPoint pt2 = ptE + vtNor * nDist * 0.5 * dMeter;
|
||
DrawLine(XLine(pt1, pt2), dc);
|
||
|
||
XPoint pt3 = ptS - vtNor * dWidth * 0.5 * dMeter;
|
||
XPoint pt4 = ptE - vtNor * nDist * 0.5 * dMeter;
|
||
DrawLine(XLine(pt3, pt4), dc);
|
||
}
|
||
else
|
||
{
|
||
DrawFlange(ptE, vtDir, nFlangeDn * dMeter, nFlangeThick * dMeter, dc);
|
||
XPoint pt1 = ptS + vtNor * dWidth * 0.5 * dMeter + vtDir * dFlangeThick * 2 * dMeter;
|
||
XPoint pt2 = ptE + vtNor * nDist * 0.5 * dMeter;
|
||
DrawLine(XLine(pt1, pt2), dc);
|
||
|
||
XPoint pt3 = ptS - vtNor * dWidth * 0.5 * dMeter + vtDir * dFlangeThick * 2 * dMeter;
|
||
XPoint pt4 = ptE - vtNor * nDist * 0.5 * dMeter;
|
||
DrawLine(XLine(pt3, pt4), dc);
|
||
}
|
||
|
||
nDist = dWidth;
|
||
nFlangeDn = dFlangeDn;
|
||
nFlangeThick = dFlangeThick;
|
||
}
|
||
}
|
||
|
||
// cet 2012.10.19 add 支持米单位
|
||
if (DocGetCurMeterUnitDraw())
|
||
{
|
||
nDist *= 0.001;
|
||
dRadius *= 0.001;
|
||
nFlangeDn *= 0.001;
|
||
nFlangeThick *= 0.001;
|
||
}
|
||
|
||
XVector3D vt=iFace.m_vtLocation;
|
||
vt.Normalize();
|
||
vt *= nDist2;
|
||
XPoint pt = m_ptLocation + vt;
|
||
|
||
if(pt.Distance2d(m_ptLocation)>_distSnap) { //接口不是垂直方向
|
||
pt.z=0;
|
||
double nAngOut=ads_angle(XPoint(), vt);
|
||
XPoint pt1, pt2;
|
||
ads_polar(pt, nAngOut+PI/2, nDist/2, pt1);
|
||
ads_polar(pt, nAngOut-PI/2, nDist/2, pt2);
|
||
|
||
if(iMode == 0)
|
||
DrawFlange(pt, nAngOut, nFlangeDn, nFlangeThick, dc);
|
||
|
||
lstLine.Append(new XLine(pt1, pt2, 0));
|
||
}
|
||
|
||
//绘制中心线
|
||
XCurveSegment segCenter;
|
||
segCenter = XLine(m_ptLocation, pt);
|
||
DrawCenterLine(dc, segCenter);
|
||
|
||
// AcDbObjectId idLayerOld=dc.GetLayerId();
|
||
// AcDbObjectId idDoteLayer=m_idDoteLayer;
|
||
// if(idDoteLayer.isValid())
|
||
// dc.SetLayer(idDoteLayer);
|
||
// dc.SetColorLayer(colorIndex(), idDoteLayer);
|
||
// dc << XLine(m_ptLocation, pt);
|
||
// dc.SetLayer(idLayerOld);
|
||
// dc.SetColorLayer(colorIndex(), idLayerOld);
|
||
|
||
}
|
||
|
||
//绘制每个管子的连接线,其延长线与旁边管子延长线的交点
|
||
//思路:
|
||
//首先,建立lstLine(焊接链表),然后根据节点到焊接中心的角度进行排序,得到lstSort
|
||
//然后,把lstSort前后2节点取出来,按管线反方向创建延长线,
|
||
//用前节点的起始点引出的延长线 和 后节点终点引出的延长线 求交点
|
||
//如果有交点(四通,弯三通),绘制交点-节点
|
||
//没有交点(直三通),绘制节点-节点
|
||
while(lstLine.Length() > 0){
|
||
double nAngFinal = -1;
|
||
XLine line1;
|
||
int len = lstLine.Length();
|
||
int idx(0);
|
||
for(int i=0;i<len;i++){
|
||
XLine line2 = *lstLine[i];
|
||
XPoint ptMid;
|
||
ptMid = line2.MidPoint();
|
||
double nAng = ads_angle(m_ptLocation, ptMid);
|
||
if(nAngFinal > nAng || nAngFinal < 0){
|
||
nAngFinal = nAng;
|
||
line1 = line2;
|
||
idx = i;
|
||
}
|
||
}
|
||
lstLine.Remove(idx);
|
||
lstSort.Append(new XLine(line1));
|
||
}
|
||
int len = lstSort.Length();
|
||
XPoint ptInt;
|
||
XPointList lstPt;
|
||
for(i=0;i<len;i++){
|
||
XLine line1 = *lstSort[i];
|
||
XLine line2;
|
||
if(i == (len - 1))//最后一个节点找第一个节点
|
||
line2 = *lstSort[0];
|
||
else
|
||
line2 = *lstSort[i+1];
|
||
XPoint pt1, pt2;
|
||
ads_polar(line1.GetStartPoint(), line1.Direction()-PI/2, line1.GetLength(), pt1);
|
||
ads_polar(line2.GetEndPoint(), line2.Direction()-PI/2, line2.GetLength(), pt2);
|
||
XLine l1(line1.GetStartPoint(), pt1, 0);
|
||
XLine l2(line2.GetEndPoint(), pt2, 0);
|
||
int ret = l1.Intersection(&l2, ptInt);
|
||
if(ret == 0)
|
||
DrawLine(XLine(line1.GetStartPoint(), line2.GetEndPoint()), dc);
|
||
else{
|
||
DrawLine(XLine(line1.GetStartPoint(), ptInt), dc);
|
||
DrawLine(XLine(line2.GetEndPoint(), ptInt), dc);
|
||
lstPt.NewAppend(ptInt);
|
||
}
|
||
}
|
||
//以上和普通三通四通情况一样
|
||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||
//以下绘制连接部分
|
||
len = lstPt.Length();
|
||
|
||
if(bIsEqDn){//如果所连管线都是等直径的,直接连中点
|
||
for(int l=0;l<len;l++){
|
||
XPoint pt1 = *lstPt[l];
|
||
DrawLine(XLine(m_ptLocation, pt1), dc);
|
||
}
|
||
}
|
||
else{
|
||
if(len == 2){//直三通
|
||
XPoint pt1 = *lstPt[0];
|
||
XPoint pt2 = *lstPt[1];
|
||
double nAng1 = CT_std_angle(ads_angle(m_ptLocation, pt1) - ads_angle(m_ptLocation, pt2));
|
||
double nAng2 = CT_std_angle(ads_angle(m_ptLocation, pt2) - ads_angle(m_ptLocation, pt1));
|
||
XArc arc1(pt1, pt2, nAng1);
|
||
XArc arc2(pt2, pt1, nAng2);
|
||
if(arc1.GetLength() > arc2.GetLength())
|
||
DrawArc(arc2, dc);
|
||
else
|
||
DrawArc(arc1, dc);
|
||
}
|
||
else if(len == 4){
|
||
//找到最细的1根管线所对于的2个交点,并找到另外2个交点,绘制凹进去的弧线
|
||
double dShortDist(-1);
|
||
XPoint pt1, pt2, pt3, pt4;
|
||
for(int l=0;l<len;l++){
|
||
XPoint ptTmp1 = *lstPt[l];
|
||
XPoint ptTmp2;
|
||
if(l == (len - 1))//最后一个节点找第一个节点
|
||
ptTmp2 = *lstPt[0];
|
||
else
|
||
ptTmp2 = *lstPt[l+1];
|
||
double dDist = ads_distance(ptTmp1, ptTmp2);
|
||
if(dShortDist < 0 || dShortDist > dDist){
|
||
dShortDist = dDist;
|
||
pt1 = ptTmp1;
|
||
pt2 = ptTmp2;
|
||
|
||
int idx1=(l+2)%4;
|
||
int idx2=(l+3)%4;
|
||
pt3 = *lstPt[idx1];
|
||
pt4 = *lstPt[idx2];
|
||
}
|
||
}
|
||
|
||
double nAng1 = CT_std_angle(ads_angle(m_ptLocation, pt1) - ads_angle(m_ptLocation, pt2));
|
||
double nAng2 = CT_std_angle(ads_angle(m_ptLocation, pt2) - ads_angle(m_ptLocation, pt1));
|
||
XArc arc1(pt1, pt2, nAng1);
|
||
XArc arc2(pt2, pt1, nAng2);
|
||
if(arc1.GetLength() > arc2.GetLength())
|
||
DrawArc(arc2, dc);
|
||
else
|
||
DrawArc(arc1, dc);
|
||
|
||
nAng1 = CT_std_angle(ads_angle(m_ptLocation, pt3) - ads_angle(m_ptLocation, pt4));
|
||
nAng2 = CT_std_angle(ads_angle(m_ptLocation, pt4) - ads_angle(m_ptLocation, pt3));
|
||
XArc arc3(pt3, pt4, nAng1);
|
||
XArc arc4(pt4, pt3, nAng2);
|
||
if(arc3.GetLength() > arc4.GetLength())
|
||
DrawArc(arc4, dc);
|
||
else
|
||
DrawArc(arc3, dc);
|
||
|
||
}
|
||
}
|
||
|
||
return es;
|
||
}
|
||
|
||
Acad::ErrorStatus TDbFlangeFitting::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;
|
||
}
|
||
Acad::ErrorStatus es=Acad::eOk;
|
||
int nElbowType = GetElbowType(this->database());
|
||
if(m_lstInterface.Length() == 1){ //堵头
|
||
return DrawTerminal(dc);
|
||
}
|
||
else if(m_lstInterface.Length() == 2){ //弯头
|
||
//先考虑垂直弯头
|
||
TPipeInterface face1, face2;
|
||
GetInterface(0, face1);
|
||
GetInterface(1, face2);
|
||
XVector3D vt1=face1.m_vtLocation;
|
||
XVector3D vt2=face2.m_vtLocation;
|
||
|
||
if(fabs(vt1.x)<1.0E-6 && fabs(vt1.y)<1.0E-6 || fabs(vt2.x)<1.0E-6 && fabs(vt2.y)<1.0E-6)
|
||
{
|
||
return DrawElbowVer(dc);
|
||
}
|
||
//再考虑水平弯头
|
||
if(nElbowType == 0)
|
||
return DrawElbow(dc);
|
||
else if(nElbowType == 1)
|
||
return DrawElbow2(dc);
|
||
}
|
||
else{ //三/四通
|
||
if(nElbowType == 0)
|
||
return DrawCorner(dc);
|
||
else if(nElbowType == 1)
|
||
return DrawCorner2(dc);
|
||
}
|
||
return es;
|
||
}
|
||
|
||
Acad::ErrorStatus TDbFlangeFitting::ExplodeOrDraw3d(XExplodeDraw &dc) const
|
||
{
|
||
Acad::ErrorStatus es=Acad::eOk;
|
||
// es=TDbPipeFitting::ExplodeOrDraw3d(dc);
|
||
|
||
AcGePoint3d pt(m_ptLocation.x,m_ptLocation.y,m_ptLocation.z);
|
||
dc.DrawEntity(AcDbPoint(pt));
|
||
//SR ADD 2005-6-10
|
||
int num = GetInterfaceNum();
|
||
if(num > 2)
|
||
Draw3dOther(dc);
|
||
else if(num == 2)
|
||
Draw3dElbow(dc);
|
||
|
||
|
||
// return es;
|
||
|
||
XPoint ptS, ptE, pt1, pt2;
|
||
double nFlangeDn(0), nDn(0), nThick(0);
|
||
// cet 2012.11.5 add
|
||
double dMeter = 1.0;
|
||
if (DocGetCurMeterUnitDraw())
|
||
{
|
||
dMeter = 0.001;
|
||
}
|
||
|
||
for(int i=0;i<num;i++){
|
||
int iMode = 0;
|
||
TPipeInterface face;
|
||
GetInterface(i, face);
|
||
AcDbObjectId nextPipeId = face.m_idPipe;
|
||
double nDist=400;
|
||
bool bLinkReducing = false; // 管线是否连接变径 cet 2012.11.5 add
|
||
double dLen = 0.0; // cet 2012.11.5 add
|
||
OPENOBJ_BEGIN(nextPipeId, AcDb::kForRead, TDbDoubleLinePipe, pPipe);
|
||
if(pPipe){
|
||
ptS = pPipe->StartPoint();
|
||
ptE = pPipe->EndPoint();
|
||
nDn = pPipe->GetDnDiameter();
|
||
nFlangeDn = pPipe->GetFlangeDn();
|
||
nThick = pPipe->GetFlangeThick();
|
||
iMode = pPipe->GetFlange();
|
||
|
||
nDist = GetWidth(pPipe);
|
||
double nFlangeThick = pPipe->GetFlangeThick();
|
||
// cet 2012.10.19 modify 支持米单位
|
||
// nDist = nDist - nFlangeThick*2;
|
||
if (DocGetCurMeterUnitDraw())
|
||
{
|
||
nDist = nDist - nFlangeThick * 2 * 0.001;
|
||
}
|
||
else
|
||
{
|
||
nDist = nDist - nFlangeThick * 2;
|
||
}
|
||
|
||
// cet 2012.11.2 add 是否连接变径
|
||
if (m_ptLocation.Distance(pPipe->StartPoint()) < 0.001)
|
||
{
|
||
bLinkReducing = pPipe->IsLinkReducing(0);
|
||
}
|
||
else
|
||
{
|
||
bLinkReducing = pPipe->IsLinkReducing(1);
|
||
}
|
||
dLen = pPipe->GetWidth();
|
||
}
|
||
OPENOBJ_END();
|
||
if(iMode != 0)
|
||
continue;
|
||
|
||
// cet 2012.11.5 add
|
||
if (bLinkReducing)
|
||
{
|
||
double dWidth = 0.0;
|
||
double dFlangeDn = 0.0;
|
||
double dFlangeThick = 0.0;
|
||
if (GetWidth(nextPipeId, dWidth, dFlangeDn, dFlangeThick))
|
||
{
|
||
// 变径法兰
|
||
AcGeVector3d vt;
|
||
if (m_ptLocation == ptS)
|
||
{
|
||
vt = ptE - ptS;
|
||
}
|
||
else
|
||
{
|
||
vt = ptS - ptE;
|
||
}
|
||
vt.normalize();
|
||
|
||
if (dLen < dWidth)
|
||
{
|
||
dLen = dWidth;
|
||
}
|
||
dLen *= dMeter;
|
||
XPoint pt3 = m_ptLocation + vt * (nDist + dLen);
|
||
XPoint pt4 = pt3 + vt * nThick * 2 * dMeter;
|
||
DrawPolyMesh(pt3, pt4, nFlangeDn / 2 * dMeter, dc);
|
||
|
||
nDist = nDist + (nThick - dFlangeThick) * 2 * dMeter;
|
||
nThick = dFlangeThick;
|
||
nFlangeDn = dFlangeDn;
|
||
}
|
||
}
|
||
|
||
// cet 2012.10.19 add 支持米单位
|
||
if (DocGetCurMeterUnitDraw())
|
||
{
|
||
nDn *= 0.001;
|
||
nFlangeDn *= 0.001;
|
||
nThick *= 0.001;
|
||
}
|
||
XVector3D vtDir;
|
||
if(m_ptLocation == ptS)
|
||
vtDir = XVector3D(ptE - ptS);
|
||
else
|
||
vtDir = XVector3D(ptS - ptE);
|
||
|
||
vtDir.Normalize();
|
||
vtDir.Scale(nDist);
|
||
pt1 = m_ptLocation;
|
||
if(num == 1)
|
||
pt1 = m_ptLocation;
|
||
else
|
||
pt1 += vtDir;
|
||
|
||
vtDir.Normalize();
|
||
vtDir.Scale(nThick);
|
||
pt2 = pt1;
|
||
|
||
//cet 2010.1.6 del
|
||
//当num == 1(堵头)时, pt2点坐标位置不对
|
||
// if(num == 1)
|
||
// pt2 -= vtDir;
|
||
// else
|
||
// pt2 += vtDir;
|
||
|
||
//cet 2010.1.6 add
|
||
//修改pt2坐标
|
||
pt2 += vtDir;
|
||
|
||
DrawPolyMesh(pt1, pt2, nFlangeDn/2, dc);
|
||
if(num == 1)
|
||
break;
|
||
// cet 2012.10.19 del 弯头一侧的法兰分离
|
||
// vtDir.Normalize();
|
||
// pt2 += vtDir;
|
||
vtDir.Normalize();
|
||
vtDir.Scale(nThick);
|
||
pt1 = pt2;
|
||
pt1 += vtDir;
|
||
DrawPolyMesh(pt1, pt2, nFlangeDn/2, dc);
|
||
}
|
||
return es;
|
||
}
|
||
|
||
|
||
// 绘制三维弯头
|
||
Acad::ErrorStatus TDbFlangeFitting::Draw3dElbow(XExplodeDraw &dc) const
|
||
{
|
||
XPoint ptS1, ptE1, ptS2, ptE2, pt1, pt2, pt3, pt4;
|
||
double nDn1(0), nDn2(0);
|
||
double nDist1(0), nDist2(0);
|
||
BOOL bIsVer1(FALSE), bIsVer2(FALSE);
|
||
TPipeSys::SysType sys1 = TPipeSys::kUnknownSys;
|
||
TPipeSys::SysType sys2 = TPipeSys::kUnknownSys;
|
||
for(int i=0;i<2;i++){
|
||
TPipeInterface face;
|
||
GetInterface(i, face);
|
||
|
||
AcDbObjectId nextPipeId = face.m_idPipe;
|
||
OPENOBJ_BEGIN(nextPipeId, AcDb::kForRead, TDbDoubleLinePipe, pPipe);
|
||
if(pPipe){
|
||
if(pPipe->GetModelType() == TPipeSys::kSystem)
|
||
return Acad::eOk;
|
||
if(i == 0){
|
||
nDist1 = GetWidth(pPipe);
|
||
ptS1 = pPipe->StartPoint();
|
||
ptE1 = pPipe->EndPoint();
|
||
nDn1 = pPipe->GetDnDiameter();
|
||
sys1 = face.m_sysType;
|
||
bIsVer1 = pPipe->IsVertical();
|
||
// cet 2018.2.2 moidfy 通过文件查询外径,对实体绘制效率影响较大
|
||
// nDn1 = GetPipeOutDByDn(pPipe->GetMaterial(), nDn1);
|
||
nDn1 = pPipe->OuterDn();
|
||
}
|
||
else{
|
||
nDist2 = GetWidth(pPipe);
|
||
ptS2 = pPipe->StartPoint();
|
||
ptE2 = pPipe->EndPoint();
|
||
nDn2 = pPipe->GetDnDiameter();
|
||
sys2 = face.m_sysType;
|
||
bIsVer2 = pPipe->IsVertical();
|
||
// cet 2018.2.2 moidfy 通过文件查询外径,对实体绘制效率影响较大
|
||
// nDn2 = GetPipeOutDByDn(pPipe->GetMaterial(), nDn2);
|
||
nDn2 = pPipe->OuterDn();
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
|
||
// cet 2012.10.19 add 支持米单位
|
||
if (DocGetCurMeterUnitDraw())
|
||
{
|
||
nDn1 *= 0.001;
|
||
nDn2 *= 0.001;
|
||
}
|
||
|
||
if(sys1 != sys2 && bIsVer1 && bIsVer2)
|
||
return Acad::eOk;
|
||
//转半径
|
||
nDn1 = nDn1 / 2;
|
||
nDn2 = nDn2 / 2;
|
||
|
||
XVector3D vtDir1, vtDir2;
|
||
if(m_ptLocation == ptS1){
|
||
XVector3D vtDir(ptE1 - ptS1);
|
||
vtDir1 = vtDir;
|
||
}
|
||
else{
|
||
XVector3D vtDir(ptS1 - ptE1);
|
||
vtDir1 = vtDir;
|
||
}
|
||
vtDir1.Normalize();
|
||
|
||
vtDir1.Scale(nDist1);
|
||
pt1 = m_ptLocation;
|
||
pt1 += vtDir1;
|
||
pt3 = pt1;
|
||
pt3 += vtDir1;
|
||
if(m_ptLocation == ptS2){
|
||
XVector3D vtDir(ptE2 - ptS2);
|
||
vtDir2 = vtDir;
|
||
}
|
||
else{
|
||
XVector3D vtDir(ptS2 - ptE2);
|
||
vtDir2 = vtDir;
|
||
}
|
||
vtDir2.Normalize();
|
||
vtDir2.Scale(nDist2);
|
||
pt2 = m_ptLocation;
|
||
pt2 += vtDir2;
|
||
pt4 = pt2;
|
||
pt4 += vtDir2;
|
||
|
||
AcGeVector3d v1 = vtDir1.AsAcGeVector3d();
|
||
AcGeVector3d v2 = vtDir2.AsAcGeVector3d();
|
||
AcGeVector3d v3 = v1.crossProduct(v2);
|
||
AcGeMatrix3d mat;
|
||
mat.setToWorldToPlane(v3);
|
||
v3.normalize();
|
||
double nAngTotal = v1.angleTo(v2);
|
||
nAngTotal -= PI;
|
||
nAngTotal = nAngTotal * -1;
|
||
XPoly2D polyPath;//路径
|
||
if(v3 != AcGeVector3d(0, 0, 0)){
|
||
pt1.TransformBy(mat);
|
||
pt2.TransformBy(mat);
|
||
pt3.TransformBy(mat);
|
||
pt4.TransformBy(mat);
|
||
}
|
||
else
|
||
v3 = AcGeVector3d(0, 0, 1);
|
||
|
||
polyPath.AppendNode(pt1, -nAngTotal);
|
||
polyPath.AppendNode(pt2);
|
||
if(polyPath.IsSelfIntersect())
|
||
return Acad::eOk;
|
||
|
||
|
||
XPoly2D *polyShape1=new XPoly2D(1);
|
||
XCircle cir2(pt3, nDn1);
|
||
XCurveSegment seg2;
|
||
seg2 = cir2;
|
||
seg2.AsPoly2D(*polyShape1);
|
||
// cet 2012.10.19 modify 支持米单位
|
||
// if(polyShape1->IsSelfIntersect()||polyShape1->Area()<0.1)
|
||
// return Acad::eOk;
|
||
double dArea = 0.1;
|
||
if (DocGetCurMeterUnitDraw())
|
||
{
|
||
dArea *= 0.001;
|
||
}
|
||
if(polyShape1->IsSelfIntersect() || polyShape1->Area() < dArea)
|
||
return Acad::eOk;
|
||
|
||
XPoly2D *polyShape2=new XPoly2D(1);
|
||
XCircle cir3(pt4, nDn2);
|
||
XCurveSegment seg3;
|
||
seg3 = cir3;
|
||
seg3.AsPoly2D(*polyShape2);
|
||
// cet 2012.10.19 modify 支持米单位
|
||
// if(polyShape2->IsSelfIntersect()||polyShape2->Area()<0.1)
|
||
// return Acad::eOk;
|
||
if(polyShape2->IsSelfIntersect() || polyShape2->Area() < dArea)
|
||
return Acad::eOk;
|
||
|
||
DList<XPoly2D> lstShapePloy;
|
||
DList<XPoint> lstShapeBase;
|
||
lstShapePloy.Append(polyShape1);
|
||
lstShapePloy.Append(polyShape2);
|
||
lstShapeBase.Append(new XPoint(pt3));
|
||
lstShapeBase.Append(new XPoint(pt4));
|
||
|
||
TDbPolyMesh cvMesh;
|
||
cvMesh.setPropertiesFrom(this);
|
||
cvMesh.SetNormal(v3);//法向
|
||
cvMesh.SetBasePoly(polyPath);
|
||
cvMesh.SetAllShapePolys(lstShapePloy);
|
||
cvMesh.SetAllShapeBases(lstShapeBase); //指定基点
|
||
if(dc.IsFullExplode())
|
||
cvMesh.ExplodeOrDraw3d(dc);
|
||
else
|
||
dc.DrawEntity(cvMesh);
|
||
|
||
return Acad::eOk;
|
||
}
|
||
|
||
|
||
|
||
// 绘制三维 三通,四通
|
||
Acad::ErrorStatus TDbFlangeFitting::Draw3dOther(XExplodeDraw &dc) const
|
||
{
|
||
XPoint ptS, ptE, pt1, pt2;
|
||
double nDn(0);
|
||
int num = GetInterfaceNum();
|
||
for(int i=0;i<num;i++){
|
||
TPipeInterface face;
|
||
GetInterface(i, face);
|
||
AcDbObjectId nextPipeId = face.m_idPipe;
|
||
double nDist=400;
|
||
bool bLinkReducing = false; // 管线是否连接变径 cet 2012.11.5 add
|
||
int nMateral = -1; // cet 2012.11.5 add
|
||
int nFlangeType = 0; // cet 2012.11.5 add
|
||
double nFlangeThick = 0.0; // cet 2012.11.5 add
|
||
OPENOBJ_BEGIN(nextPipeId, AcDb::kForRead, TDbDoubleLinePipe, pPipe);
|
||
if(pPipe){
|
||
|
||
ptS = pPipe->StartPoint();
|
||
ptE = pPipe->EndPoint();
|
||
nDn = pPipe->GetDnDiameter();
|
||
// cet 2018.2.2 moidfy 通过文件查询外径,对实体绘制效率影响较大
|
||
// nDn = GetPipeOutDByDn(pPipe->GetMaterial(), nDn);
|
||
nDn = pPipe->OuterDn();
|
||
nDist = GetWidth(pPipe);
|
||
/*double*/ nFlangeThick = pPipe->GetFlangeThick(); // cet 2012.11.5 modify
|
||
if(pPipe->GetFlange() == 0)
|
||
{
|
||
// cet 2012.10.19 moidfy 支持米单位
|
||
//nDist = nDist - nFlangeThick*2;
|
||
if (DocGetCurMeterUnitDraw())
|
||
{
|
||
nDist = nDist - nFlangeThick * 2 * 0.001;
|
||
}
|
||
else
|
||
{
|
||
nDist = nDist - nFlangeThick * 2;
|
||
}
|
||
}
|
||
|
||
// cet 2012.11.5 add 是否连接变径
|
||
if (m_ptLocation.Distance(pPipe->StartPoint()) < 0.001)
|
||
{
|
||
bLinkReducing = pPipe->IsLinkReducing(0);
|
||
}
|
||
else
|
||
{
|
||
bLinkReducing = pPipe->IsLinkReducing(1);
|
||
}
|
||
nMateral = pPipe->GetMaterial();
|
||
nFlangeType = pPipe->GetFlange();
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
// cet 2012.11.5 add 绘制变径
|
||
if (bLinkReducing)
|
||
{
|
||
double dWidth = 0.0;
|
||
double dFlangeDn = 0.0;
|
||
double dFlangeThick = 0.0;
|
||
double dPipeDn = 0.0;
|
||
if (GetWidth(nextPipeId, dWidth, dFlangeDn, dFlangeThick, &dPipeDn))
|
||
{
|
||
// cet 2018.2.2 modify 通过文件查询外径,对实体绘制效率影响较大
|
||
// nDn = GetPipeOutDByDn(nMateral, dPipeDn);
|
||
nDn = GetPipeOutDByDn(nextPipeId);
|
||
DrawReducing3d(nextPipeId, dc);
|
||
if (nFlangeType == 0)
|
||
{
|
||
if (DocGetCurMeterUnitDraw())
|
||
{
|
||
nDist = nDist + (nFlangeThick - dFlangeThick) * 2 * 0.001;
|
||
}
|
||
else
|
||
{
|
||
nDist = nDist + (nFlangeThick - dFlangeThick) * 2;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// cet 2012.10.19 add 支持米单位
|
||
if (DocGetCurMeterUnitDraw())
|
||
{
|
||
nDn *= 0.001;
|
||
}
|
||
|
||
XVector3D vtDir;
|
||
if(m_ptLocation == ptS)
|
||
vtDir = XVector3D(ptE - ptS);
|
||
else
|
||
vtDir = XVector3D(ptS - ptE);
|
||
vtDir.Normalize();
|
||
vtDir.Scale(nDist);
|
||
pt1 = m_ptLocation;
|
||
pt1 += vtDir;
|
||
DrawPolyMesh(m_ptLocation, pt1, nDn/2, dc);
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
void TDbFlangeFitting::ModifyLine(XLine &line, const AcDbObjectId &idPipe) const
|
||
{
|
||
// 寻找立管连接的另一个弯头
|
||
TDbDoubleLinePipe *pPipe = NULL;
|
||
acdbOpenObject(pPipe, idPipe, AcDb::kForRead);
|
||
if (pPipe == NULL)
|
||
{
|
||
return;
|
||
}
|
||
|
||
AcDbObjectId id1 = pPipe->GetNode(0);
|
||
AcDbObjectId id2 = pPipe->GetNode(1);
|
||
if (id1 == objectId())
|
||
{
|
||
id1= id2;
|
||
}
|
||
pPipe->close();
|
||
|
||
// 找到另一个弯头连接的非立管
|
||
TDbFlangeFitting *pFitting = NULL;
|
||
acdbOpenObject(pFitting, id1, AcDb::kForRead);
|
||
if (pFitting == NULL)
|
||
{
|
||
return;
|
||
}
|
||
|
||
if (pFitting->GetInterfaceNum() != 2 || pFitting->m_ptLocation.z < m_ptLocation.z)
|
||
{
|
||
pFitting->close();
|
||
return;
|
||
}
|
||
|
||
TPipeInterface face1, face2;
|
||
pFitting->GetInterface(0, face1);
|
||
pFitting->GetInterface(1, face2);
|
||
pFitting->close();
|
||
if (face1.m_idPipe == idPipe)
|
||
{
|
||
id1 = face2.m_idPipe;
|
||
}
|
||
else if (face2.m_idPipe == idPipe)
|
||
{
|
||
id1 = face1.m_idPipe;
|
||
}
|
||
else
|
||
{
|
||
return;
|
||
}
|
||
|
||
// 打开找到的双线管
|
||
acdbOpenObject(pPipe, id1, AcDb::kForRead);
|
||
if (pPipe == NULL)
|
||
{
|
||
return;
|
||
}
|
||
|
||
double dWidth = pPipe->GetWidth();
|
||
// 双线管中线
|
||
XLine lineMid(pPipe->GetStartPoint(), pPipe->GetEndPoint(), LS_FINITE);
|
||
pPipe->close();
|
||
// 双线管边线
|
||
XPoint ptS = lineMid.StartPoint();
|
||
XPoint ptE = lineMid.EndPoint();
|
||
AcGeVector3d vt = lineMid.StartPoint() - lineMid.EndPoint();
|
||
vt.z = 0.0;
|
||
vt.normalize();
|
||
vt.rotateBy(PI / 2, AcGeVector3d::kZAxis);
|
||
XLine line1(ptS + vt * dWidth * 0.5, ptE + vt * dWidth * 0.5);
|
||
XLine line2(ptS - vt * dWidth * 0.5, ptE - vt * dWidth * 0.5);
|
||
|
||
line.StartPoint().z = 0.0;
|
||
line.EndPoint().z = 0.0;
|
||
line1.StartPoint().z = 0.0;
|
||
line1.EndPoint().z = 0.0;
|
||
line2.StartPoint().z = 0.0;
|
||
line2.EndPoint().z = 0.0;
|
||
lineMid.StartPoint().z = 0.0;
|
||
lineMid.EndPoint().z = 0.0;
|
||
|
||
// 求交
|
||
line.SetLineFlag(LS_FINITE);
|
||
line1.SetLineFlag(LS_FINITE);
|
||
line2.SetLineFlag(LS_FINITE);
|
||
XPoint pt1, pt2;
|
||
line.Intersection(&line1, pt1);
|
||
line.Intersection(&line2, pt2);
|
||
if (!!pt1 && !pt2 || !pt1 && !!pt2)
|
||
{
|
||
if (!pt1 && !!pt2)
|
||
{
|
||
pt1 = pt2;
|
||
}
|
||
|
||
XPoint pt;
|
||
line.SetLineFlag(LS_INFINITE);
|
||
lineMid.SetLineFlag(LS_INFINITE);
|
||
line.Intersection(&lineMid, pt);
|
||
if (!!pt)
|
||
{
|
||
if (pt.Distance2d(line.StartPoint()) > pt.Distance2d(line.EndPoint()))
|
||
{
|
||
line.SetEndPoint(pt1);
|
||
}
|
||
else
|
||
{
|
||
line.SetStartPoint(pt1);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void TDbFlangeFitting::DrawReducing3d( const AcDbObjectId &idPipe, XExplodeDraw &dc ) const
|
||
{
|
||
// 与idPipe平行的管线
|
||
AcDbObjectId id;
|
||
int nNum = GetInterfaceNum();
|
||
AcGeVector3d vtPipe;
|
||
for (int i = 0; i < nNum; i++)
|
||
{
|
||
const TPipeInterface &face = GetInterface(i);
|
||
if (face.m_idPipe == idPipe)
|
||
{
|
||
vtPipe = face.m_vtLocation;
|
||
break;
|
||
}
|
||
}
|
||
|
||
AcGeVector3d vtDir;
|
||
AcGeTol tol;
|
||
tol.setEqualVector(0.001);
|
||
TDbDoubleLinePipe *pPipe = NULL;
|
||
for (i = 0; i < nNum; i++)
|
||
{
|
||
const TPipeInterface &face = GetInterface(i);
|
||
if (face.m_idPipe == idPipe)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
acdbOpenObject(pPipe, face.m_idPipe, AcDb::kForRead);
|
||
if (pPipe != NULL)
|
||
{
|
||
vtDir = pPipe->StartPoint() - pPipe->EndPoint();
|
||
pPipe->close();
|
||
if (vtDir.isParallelTo(vtPipe, tol))
|
||
{
|
||
id = face.m_idPipe;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (id.isNull())
|
||
{
|
||
return;
|
||
}
|
||
|
||
XPoint ptS1, ptE1, ptS2, ptE2, pt1, pt2;
|
||
double nDn1(0), nDn2(0);
|
||
double nDist1(0), nDist2(0);
|
||
double dFlangeThick1(0.0), dFlangeThick2(0.0);
|
||
double dLen1(0.0), dLen2(0.0);
|
||
BOOL bIsVer1(FALSE), bIsVer2(FALSE);
|
||
OPENOBJ_BEGIN(idPipe, AcDb::kForRead, TDbDoubleLinePipe, pPipe);
|
||
if(pPipe != NULL)
|
||
{
|
||
dLen1 = pPipe->GetWidth();
|
||
nDist1 = GetWidth(pPipe);
|
||
ptS1 = pPipe->StartPoint();
|
||
ptE1 = pPipe->EndPoint();
|
||
nDn1 = pPipe->GetDnDiameter();
|
||
bIsVer1 = pPipe->IsVertical();
|
||
// cet 2018.2.2 modify 通过文件查询外径,对实体绘制效率影响较大
|
||
// nDn1 = GetPipeOutDByDn(pPipe->GetMaterial(), nDn1);
|
||
nDn1 = pPipe->OuterDn();
|
||
dFlangeThick1 = pPipe->GetFlangeThick();
|
||
if(pPipe->GetFlange() != 0)
|
||
{
|
||
dFlangeThick1 = 0.0;
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbDoubleLinePipe, pPipe);
|
||
if(pPipe != NULL)
|
||
{
|
||
dLen2 = pPipe->GetWidth();
|
||
nDist2 = GetWidth(pPipe);
|
||
ptS2 = pPipe->StartPoint();
|
||
ptE2 = pPipe->EndPoint();
|
||
nDn2 = pPipe->GetDnDiameter();
|
||
bIsVer2 = pPipe->IsVertical();
|
||
// cet 2018.2.2 modify 通过文件查询外径,对实体绘制效率影响较大
|
||
// nDn2 = GetPipeOutDByDn(pPipe->GetMaterial(), nDn2);
|
||
nDn2 = pPipe->OuterDn();
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
// cet 2012.10.19 add 支持米单位
|
||
if (DocGetCurMeterUnitDraw())
|
||
{
|
||
nDn1 *= 0.001;
|
||
nDn2 *= 0.001;
|
||
dFlangeThick1 *= 0.001;
|
||
}
|
||
|
||
//转半径
|
||
nDn1 = nDn1 / 2;
|
||
nDn2 = nDn2 / 2;
|
||
|
||
AcGeVector3d vtDir1, vtDir2;
|
||
if(m_ptLocation == ptS1)
|
||
{
|
||
XVector3D vtDir(ptE1 - ptS1);
|
||
vtDir1 = vtDir;
|
||
}
|
||
else
|
||
{
|
||
XVector3D vtDir(ptS1 - ptE1);
|
||
vtDir1 = vtDir;
|
||
}
|
||
vtDir1.normalize();
|
||
|
||
pt1 = m_ptLocation;
|
||
pt1 += vtDir1 * nDist1;
|
||
pt2 = pt1;
|
||
// 需要法兰时留出法兰宽度
|
||
double dLen = dLen1 > dLen2 ? dLen1 - dFlangeThick1 *2 : dLen2 - dFlangeThick1 * 2;
|
||
if (DocGetCurMeterUnitDraw())
|
||
{
|
||
dLen *= 0.001;
|
||
}
|
||
pt2 += vtDir1 * dLen;
|
||
if(m_ptLocation == ptS2)
|
||
{
|
||
XVector3D vtDir(ptE2 - ptS2);
|
||
vtDir2 = vtDir;
|
||
}
|
||
else
|
||
{
|
||
XVector3D vtDir(ptS2 - ptE2);
|
||
vtDir2 = vtDir;
|
||
}
|
||
vtDir2.normalize();
|
||
|
||
AcGeVector3d v1 = vtDir1/*.AsAcGeVector3d()*/;
|
||
AcGeVector3d v2 = vtDir2/*.AsAcGeVector3d()*/;
|
||
AcGeVector3d v3 = v1.crossProduct(v2);
|
||
AcGeMatrix3d mat;
|
||
mat.setToWorldToPlane(v3);
|
||
v3.normalize();
|
||
XPoly2D polyPath;//路径
|
||
if(v3 != AcGeVector3d(0, 0, 0))
|
||
{
|
||
pt1.TransformBy(mat);
|
||
pt2.TransformBy(mat);
|
||
}
|
||
else
|
||
{
|
||
v3 = AcGeVector3d(0, 0, 1);
|
||
}
|
||
|
||
polyPath.AppendNode(pt1);
|
||
polyPath.AppendNode(pt2);
|
||
if(polyPath.IsSelfIntersect())
|
||
return;
|
||
|
||
XPoly2D *polyShape1=new XPoly2D(1);
|
||
XCircle cir2(pt1, nDn2);
|
||
XCurveSegment seg2;
|
||
seg2 = cir2;
|
||
seg2.AsPoly2D(*polyShape1);
|
||
double dArea = 0.1;
|
||
if (DocGetCurMeterUnitDraw())
|
||
{
|
||
dArea *= 0.001;
|
||
}
|
||
if(polyShape1->IsSelfIntersect() || polyShape1->Area() < dArea)
|
||
return;
|
||
|
||
XPoly2D *polyShape2=new XPoly2D(1);
|
||
XCircle cir3(pt2, nDn1);
|
||
XCurveSegment seg3;
|
||
seg3 = cir3;
|
||
seg3.AsPoly2D(*polyShape2);
|
||
if(polyShape2->IsSelfIntersect() || polyShape2->Area() < dArea)
|
||
return;
|
||
|
||
DList<XPoly2D> lstShapePloy;
|
||
DList<XPoint> lstShapeBase;
|
||
lstShapePloy.Append(polyShape1);
|
||
lstShapePloy.Append(polyShape2);
|
||
lstShapeBase.Append(new XPoint(pt1));
|
||
lstShapeBase.Append(new XPoint(pt2));
|
||
|
||
TDbPolyMesh cvMesh;
|
||
cvMesh.setPropertiesFrom(this);
|
||
cvMesh.SetNormal(v3);//法向
|
||
cvMesh.SetBasePoly(polyPath);
|
||
cvMesh.SetAllShapePolys(lstShapePloy);
|
||
cvMesh.SetAllShapeBases(lstShapeBase); //指定基点
|
||
if(dc.IsFullExplode())
|
||
cvMesh.ExplodeOrDraw3d(dc);
|
||
else
|
||
dc.DrawEntity(cvMesh);
|
||
|
||
dc << XLine(pt1, pt2);
|
||
}
|
||
|
||
void TDbFlangeFitting::UpdateLinkage( const XPoint &ptAt, TPipeSys::SysType st, const DList<AcDbObjectId> &idPipes )
|
||
{
|
||
TDbPipeFitting::UpdateLinkage(ptAt, st, idPipes);
|
||
// 剔除不必要的变径
|
||
int nNum = GetInterfaceNum();
|
||
XPoint ptS, ptE;
|
||
AcGeVector3d vt1, vt2;
|
||
AcGeTol tol;
|
||
tol.setEqualVector(0.001);
|
||
// 三通 四通 剔除共线等径管线变径
|
||
bool bFind = false; // 是否找到与之共线的管线
|
||
std::vector<AcDbObjectId> vecCheckedIds;
|
||
for (int i = 0; i < nNum && nNum > 2; i++)
|
||
{
|
||
bFind = false;
|
||
const TPipeInterface &face = GetInterface(i);
|
||
if (std::find(vecCheckedIds.begin(), vecCheckedIds.end(), face.m_idPipe) != vecCheckedIds.end())
|
||
{
|
||
continue;
|
||
}
|
||
|
||
OPENOBJ_BEGIN(face.m_idPipe, AcDb::kForWrite, TDbDoubleLinePipe, pDbPipe);
|
||
if (pDbPipe != NULL)
|
||
{
|
||
ptS = pDbPipe->StartPoint();
|
||
ptE = pDbPipe->EndPoint();
|
||
if (ptS.Distance(m_ptLocation) < 0.001 && pDbPipe->IsLinkReducing(0)
|
||
|| ptE.Distance(m_ptLocation) < 0.001 && pDbPipe->IsLinkReducing(1))
|
||
{
|
||
vt1 = ptS - ptE;
|
||
// 如果有与之共线的管线管径相同,剔除变径
|
||
for(int j = 0; j < nNum; j++)
|
||
{
|
||
const TPipeInterface &face2 = GetInterface(j);
|
||
if (std::find(vecCheckedIds.begin(), vecCheckedIds.end(), face2.m_idPipe) != vecCheckedIds.end())
|
||
{
|
||
continue;
|
||
}
|
||
|
||
OPENOBJ_BEGIN(face2.m_idPipe, AcDb::kForWrite, TDbDoubleLinePipe, pDbPipe2);
|
||
if (pDbPipe2 != NULL)
|
||
{
|
||
vt2 = pDbPipe2->StartPoint() - pDbPipe2->EndPoint();
|
||
if (vt1.isParallelTo(vt2, tol))
|
||
{
|
||
vecCheckedIds.push_back(face.m_idPipe);
|
||
vecCheckedIds.push_back(face2.m_idPipe);
|
||
bFind = true;
|
||
}
|
||
|
||
// 共线等径
|
||
if (vt1.isParallelTo(vt2, tol) && fabs(pDbPipe->GetDnDiameter() - pDbPipe2->GetDnDiameter()) < 0.001)
|
||
{
|
||
// fitting在起点处
|
||
if (ptS.Distance(m_ptLocation) < 0.001)
|
||
{
|
||
pDbPipe->SetLinkReducing(0, false);
|
||
}
|
||
else // fitting在终点处
|
||
{
|
||
pDbPipe->SetLinkReducing(1, false);
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
|
||
// 没有与之共线的管线,并且管线本身有变径
|
||
if (!bFind)
|
||
{
|
||
// fitting在起点处且存在变径
|
||
if (ptS.Distance(m_ptLocation) < 0.001 && pDbPipe->IsLinkReducing(0))
|
||
{
|
||
pDbPipe->SetLinkReducing(0, false);
|
||
}
|
||
else if (ptE.Distance(m_ptLocation) < 0.001 && pDbPipe->IsLinkReducing(1)) // fitting在终点处且存在变径
|
||
{
|
||
pDbPipe->SetLinkReducing(1, false);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
|
||
// 弯通 堵头 剔除变径
|
||
for(int j = 0; j < nNum && nNum < 3; j++)
|
||
{
|
||
const TPipeInterface &face2 = GetInterface(j);
|
||
OPENOBJ_BEGIN(face2.m_idPipe, AcDb::kForWrite, TDbDoubleLinePipe, pDbPipe2);
|
||
if (pDbPipe2 != NULL)
|
||
{
|
||
// fitting在起点处
|
||
if (m_ptLocation.Distance(pDbPipe2->StartPoint()) < 0.001)
|
||
{
|
||
if (pDbPipe2->IsLinkReducing(0))
|
||
{
|
||
pDbPipe2->SetLinkReducing(0, false);
|
||
}
|
||
}
|
||
else if (pDbPipe2->IsLinkReducing(1)) // fitting在终点处
|
||
{
|
||
pDbPipe2->SetLinkReducing(1, false);
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
|
||
// cet 2012.11.16 add 执行以下命令时自动更新变径
|
||
if (g_sCurrentCmd.CompareNoCase(_T("GRIP_STRETCH")) == 0 || g_sCurrentCmd.CompareNoCase(_T("MOVE")) == 0
|
||
|| g_sCurrentCmd.CompareNoCase(_T("pasteclip")) == 0)
|
||
{
|
||
UpdateFlangeFitting();
|
||
}
|
||
}
|
||
|
||
void TDbFlangeFitting::UpdateFlangeFitting()
|
||
{
|
||
int nNum = GetInterfaceNum();
|
||
if (nNum < 3)
|
||
{
|
||
return;
|
||
}
|
||
AcGeVector3d vtPipe1, vtPipe2;
|
||
AcGeTol tol;
|
||
tol.setEqualVector(0.001);
|
||
std::vector<AcDbObjectId> vecIds;
|
||
std::vector<AcDbObjectId>::iterator it;
|
||
int nSide1 = 0, nSide2 = 0;
|
||
for (int k = 0; k < nNum; ++k)
|
||
{
|
||
const TPipeInterface &face = GetInterface(k);
|
||
it = std::find(vecIds.begin(), vecIds.end(), face.m_idPipe);
|
||
if (it != vecIds.end())
|
||
{
|
||
continue;
|
||
}
|
||
vecIds.push_back(face.m_idPipe);
|
||
OPENOBJ_BEGIN(face.m_idPipe, AcDb::kForWrite, TDbDoubleLinePipe, pPipe1);
|
||
if (pPipe1 != NULL)
|
||
{
|
||
if (m_ptLocation.Distance(pPipe1->StartPoint()) < 0.001)
|
||
{
|
||
nSide1 = 0;
|
||
}
|
||
else
|
||
{
|
||
nSide1 = 1;
|
||
}
|
||
|
||
// 不处理已变径管线
|
||
if (pPipe1->IsLinkReducing(nSide1))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
vtPipe1 = pPipe1->StartPoint() - pPipe1->EndPoint();
|
||
for(int h = 0; h < nNum; ++h)
|
||
{
|
||
const TPipeInterface &face2 = GetInterface(h);
|
||
it = std::find(vecIds.begin(), vecIds.end(), face2.m_idPipe);
|
||
if (it != vecIds.end())
|
||
{
|
||
continue;
|
||
}
|
||
|
||
OPENOBJ_BEGIN(face2.m_idPipe, AcDb::kForWrite, TDbDoubleLinePipe, pPipe2);
|
||
if (pPipe2 != NULL)
|
||
{
|
||
if (m_ptLocation.Distance(pPipe2->StartPoint()) < 0.001)
|
||
{
|
||
nSide2 = 0;
|
||
}
|
||
else
|
||
{
|
||
nSide2 = 1;
|
||
}
|
||
// 不处理已变径管线
|
||
if (pPipe2->IsLinkReducing(nSide2))
|
||
{
|
||
vecIds.push_back(face2.m_idPipe);
|
||
continue;
|
||
}
|
||
|
||
vtPipe2 = pPipe2->StartPoint() - pPipe2->EndPoint();
|
||
// 共线
|
||
if (vtPipe1.isParallelTo(vtPipe2, tol))
|
||
{
|
||
vecIds.push_back(face2.m_idPipe);
|
||
// 等径不需要变径
|
||
if (fabs(pPipe1->GetDnDiameter() - pPipe2->GetDnDiameter()) < 0.001)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if (pPipe1->GetDnDiameter() > pPipe2->GetDnDiameter())
|
||
{
|
||
pPipe2->SetLinkReducing(nSide2, true);
|
||
}
|
||
else
|
||
{
|
||
pPipe1->SetLinkReducing(nSide1, true);
|
||
}
|
||
}
|
||
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
}
|
||
|
||
#if ADS > 15
|
||
Acad::ErrorStatus TDbFlangeFitting::subGetGripPoints( AcDbGripDataPtrArray& grips, const double curViewUnitSize, const int gripSize, const AcGeVector3d& curViewDir, const int bitflags ) const
|
||
{
|
||
assertReadEnabled();
|
||
AcDbIntArray osnapModes;
|
||
AcDbIntArray geomIds;
|
||
AcGePoint3dArray gripPoints;
|
||
Acad::ErrorStatus eSta = subGetGripPoints(gripPoints,osnapModes,geomIds);
|
||
CString sGripTip;
|
||
for (int i = 0;i < gripPoints.length() && i < GRIP_MAXNUM_DBPIPE_FITTING; i++)
|
||
{
|
||
bool bCmd = false;
|
||
ExplainGripIndex(i, bCmd, sGripTip);
|
||
s_gripAppData[i].nIndex = i;
|
||
s_gripAppData[i].sGripTip = sGripTip;
|
||
AcDbGripData *pGripData = new AcDbGripData;
|
||
pGripData->setAppData((void*)&s_gripAppData[i]);
|
||
pGripData->setGripPoint(gripPoints.at(i));
|
||
// 命令夹点重绘夹点样式
|
||
if (bCmd)
|
||
{
|
||
pGripData->setWorldDraw(GripCback::WorldDrawfunc);
|
||
}
|
||
pGripData->setToolTipFunc(GripCback::GripToolTipFunc);
|
||
grips.append(pGripData);
|
||
}
|
||
return eSta;
|
||
}
|
||
|
||
Acad::ErrorStatus TDbFlangeFitting::subMoveGripPointsAt( const AcDbVoidPtrArray& appData, const AcGeVector3d& offset, const int bitflags )
|
||
{
|
||
assertWriteEnabled();
|
||
AcDbIntArray arIndex;
|
||
int nSize = appData.length();
|
||
for (int i = 0;i < nSize; i++)
|
||
{
|
||
TWT_GRIPAPPDATA *pAppData = (TWT_GRIPAPPDATA*)appData.at(i);
|
||
if (pAppData != NULL)
|
||
{
|
||
arIndex.append(pAppData->nIndex);
|
||
}
|
||
}
|
||
Acad::ErrorStatus eSta = subMoveGripPointsAt(arIndex, offset);
|
||
return eSta;
|
||
}
|
||
|
||
#endif
|
||
|
||
Acad::ErrorStatus TDbFlangeFitting::subGetGripPoints( AcGePoint3dArray& gripPoints, AcDbIntArray& osnapModes, AcDbIntArray& geomIds ) const
|
||
{
|
||
gripPoints.append(m_ptLocation);
|
||
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus TDbFlangeFitting::subMoveGripPointsAt( const AcDbIntArray& indices, const AcGeVector3d& offset )
|
||
{
|
||
if (indices.length() == 1)
|
||
{
|
||
AcDbObjectId id;
|
||
double dDn = 0;
|
||
int nNum = GetInterfaceNum();
|
||
for(int i = 0; i < nNum; i++)
|
||
{
|
||
const TPipeInterface &face = GetInterface(i);
|
||
OPENOBJ_BEGIN(face.m_idPipe, AcDb::kForRead, TDbDoubleLinePipe, pPipe);
|
||
if (pPipe != NULL)
|
||
{
|
||
if (i != 0)
|
||
{
|
||
if (dDn > pPipe->GetDnDiameter())
|
||
{
|
||
dDn = pPipe->GetDnDiameter();
|
||
id = face.m_idPipe;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
id = face.m_idPipe;
|
||
dDn = pPipe->GetDnDiameter();
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
|
||
SetGripCmdData(m_ptLocation, id);
|
||
acedPostCommand(_T("\3\3hsxg\n"));
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus TDbFlangeFitting::GetGripText( int idx, CString &cs ) const
|
||
{
|
||
if (idx == 0)
|
||
{
|
||
cs = _T("启动绘制");
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
void TDbFlangeFitting::ExplainGripIndex( int nIndex, bool &bCmd, CString &sTip ) const
|
||
{
|
||
bCmd = false;
|
||
sTip.Empty();
|
||
if (nIndex == 0)
|
||
{
|
||
bCmd = true;
|
||
sTip = _T("启动绘制");
|
||
}
|
||
}
|
||
|
||
|
||
////////////////////////////////////////////////////////////////////////
|
||
|
||
void InitDbFlangeFitting(BOOL bTrue)
|
||
{
|
||
if(bTrue) {
|
||
TDbFlangeFitting::rxInit();
|
||
TDbFlangeFitting::InitMatchProtocol(TRUE);
|
||
} else {
|
||
deleteAcRxClass(TDbFlangeFitting::desc());
|
||
TDbFlangeFitting::InitMatchProtocol(FALSE);
|
||
}
|
||
}
|