372 lines
11 KiB
C++
372 lines
11 KiB
C++
// DbDuctElbow.cpp: implementation of the TDbDuctElbow class.
|
|
//
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#include "stdafx.h"
|
|
#include "DbDuctElbow.h"
|
|
#include "PipeTools.h"
|
|
#include "DbDuct.h"
|
|
#include "GlobalFunction.h"
|
|
|
|
extern void DrawWeight(XExplodeDraw &dc,double dWeight,XCurveSegment &seg,int nColorIndex, double nScale);
|
|
|
|
ACRX_DXF_DEFINE_MEMBERS(ATSDuctElbow, ATSEntity, AcDb::kDHL_CURRENT,
|
|
AcDb::kMReleaseCurrent, 1, ATS_DUCTELBOW,
|
|
"ATS_DUCTELBOW图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com");
|
|
IMPLEMENT_TENTBASE(TDbDuctElbow);
|
|
|
|
const Adesk::UInt8 TDbDuctElbow::g_nVersion = 1;
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Construction/Destruction
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
TDbDuctElbow::TDbDuctElbow()
|
|
{
|
|
m_nPipeWeight = 0.5;
|
|
}
|
|
|
|
void TDbDuctElbow::CopyPropertiesFrom(AcDbEntity *pSrc,unsigned gMatchFlag)
|
|
{
|
|
assertWriteEnabled();
|
|
TDbEntity::CopyPropertiesFrom(pSrc, gMatchFlag);
|
|
}
|
|
|
|
Acad::ErrorStatus TDbDuctElbow::subGetClassID(CLSID* pClsid) const
|
|
{
|
|
// *pClsid = CLSID_ComElbow;
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus
|
|
TDbDuctElbow::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;
|
|
|
|
if( osnapMode == AcDb::kOsModeIns ||
|
|
osnapMode == AcDb::kOsModeCen ||
|
|
osnapMode == AcDb::kOsModeNode) {
|
|
snapPoints.append(m_ptLocation);
|
|
}
|
|
es=TDbEntity::subGetOsnapPoints(osnapMode,gsSelectionMark,
|
|
ptPick,lastPoint,viewXform,snapPoints,geomIds);
|
|
|
|
return es;
|
|
}
|
|
|
|
// 取得所有的夹点
|
|
Acad::ErrorStatus
|
|
TDbDuctElbow::subGetGripPoints(AcGePoint3dArray& gripPoints,
|
|
AcDbIntArray& osnapModes,
|
|
AcDbIntArray& geomIds) const
|
|
{
|
|
assertReadEnabled();
|
|
gripPoints.append(m_ptLocation);
|
|
return Acad::eOk;
|
|
}
|
|
|
|
// 功能: 夹点操作
|
|
Acad::ErrorStatus
|
|
TDbDuctElbow::subMoveGripPointsAt(const AcDbIntArray& indices, const AcGeVector3d& offset)
|
|
{
|
|
assertWriteEnabled();
|
|
AcGeMatrix3d mat;
|
|
AcGeVector3d vtOffset=offset;
|
|
vtOffset.z=0;
|
|
mat.setToTranslation(vtOffset);
|
|
m_ptLocation.TransformBy(mat);
|
|
Acad::ErrorStatus es=Acad::eOk;
|
|
return es;
|
|
}
|
|
|
|
// 从DWG读入数据:
|
|
Acad::ErrorStatus TDbDuctElbow::dwgInFields(AcDbDwgFiler* pFiler)
|
|
{
|
|
assertWriteEnabled();
|
|
|
|
Acad::ErrorStatus es = TDbEntity::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;
|
|
}
|
|
|
|
pFiler->readItem((AcGePoint3d *)&m_ptLocation);
|
|
pFiler->readItem((AcGeVector3d *)&m_vtLocation1);
|
|
pFiler->readItem((AcGeVector3d *)&m_vtLocation2);
|
|
pFiler->readItem(&m_nWidth1);
|
|
pFiler->readItem(&m_nWidth2);
|
|
|
|
return pFiler->filerStatus();
|
|
}
|
|
|
|
Acad::ErrorStatus TDbDuctElbow::dwgOutFields(AcDbDwgFiler* pFiler) const
|
|
{
|
|
assertReadEnabled();
|
|
Acad::ErrorStatus es = TDbEntity::dwgOutFields(pFiler);
|
|
if(es != Acad::eOk) return es;
|
|
|
|
pFiler->writeItem(g_nVersion);
|
|
|
|
pFiler->writeItem((const AcGePoint3d &)m_ptLocation);
|
|
pFiler->writeItem((const AcGeVector3d &)m_vtLocation1);
|
|
pFiler->writeItem((const AcGeVector3d &)m_vtLocation2);
|
|
pFiler->writeItem(m_nWidth1);
|
|
pFiler->writeItem(m_nWidth2);
|
|
|
|
return pFiler->filerStatus();
|
|
}
|
|
|
|
Acad::ErrorStatus TDbDuctElbow::dxfInFields(AcDbDxfFiler* pFiler)
|
|
{
|
|
assertWriteEnabled();
|
|
Acad::ErrorStatus es=Acad::eOk;
|
|
es=TDbEntity::dxfInFields(pFiler);
|
|
return es;
|
|
}
|
|
|
|
Acad::ErrorStatus TDbDuctElbow::dxfOutFields(AcDbDxfFiler* pFiler) const
|
|
{
|
|
Acad::ErrorStatus es=Acad::eOk;
|
|
es=TDbEntity::dxfOutFields(pFiler);
|
|
return es;
|
|
}
|
|
|
|
// Active when being rotated, scaled, moved, etc.
|
|
Acad::ErrorStatus
|
|
TDbDuctElbow::subTransformBy(const AcGeMatrix3d& xform)
|
|
{
|
|
assertWriteEnabled();
|
|
m_ptLocation.TransformBy(xform);
|
|
((AcGeVector3d &)m_vtLocation1).transformBy(xform);
|
|
((AcGeVector3d &)m_vtLocation2).transformBy(xform);
|
|
Acad::ErrorStatus es=Acad::eOk;
|
|
return es;
|
|
}
|
|
|
|
void TDbDuctElbow::GetNodePt(XPoint &ptNode1, XPoint &ptNode2)
|
|
{
|
|
double nAngOut1 = ads_angle(XPoint(), m_vtLocation1);
|
|
double nAngOut2 = ads_angle(XPoint(), m_vtLocation2);
|
|
XPoint ptCen, ptOut1, ptOut2;
|
|
ads_polar(m_ptLocation, nAngOut1, m_nWidth1*10, ptOut1);
|
|
ads_polar(m_ptLocation, nAngOut2, m_nWidth2*10, ptOut2);
|
|
AT_cal_fillet(ptOut1, m_ptLocation, ptOut2, m_nWidth1, ptNode1, ptCen, ptNode2);
|
|
}
|
|
|
|
void TDbDuctElbow::SetPipeId(AcDbObjectId id1, AcDbObjectId id2)
|
|
{
|
|
double nWidth1, nWidth2;
|
|
XPoint pt1, pt2, pt3, pt4, ptInt, ptOut1, ptOut2;
|
|
OPENOBJ_BEGIN(id1, AcDb::kForRead, TDbDuct, pPipe);
|
|
if(pPipe){
|
|
nWidth1 = pPipe->GetWidth();
|
|
pt1 = pPipe->StartPoint();
|
|
pt2 = pPipe->EndPoint();
|
|
}
|
|
OPENOBJ_END();
|
|
OPENOBJ_BEGIN(id2, AcDb::kForRead, TDbDuct, pPipe);
|
|
if(pPipe){
|
|
nWidth2 = pPipe->GetWidth();
|
|
pt3 = pPipe->StartPoint();
|
|
pt4 = pPipe->EndPoint();
|
|
}
|
|
OPENOBJ_END();
|
|
XLine l1(pt1, pt2, 1);
|
|
XLine l2(pt3, pt4, 1);
|
|
l1.SetLineFlag(1);
|
|
l2.SetLineFlag(1);
|
|
int ret = l1.Intersection(&l2, ptInt);
|
|
if(ret != 1)
|
|
return;
|
|
if(pt1 == ptInt)
|
|
ptOut1 = pt2;
|
|
else
|
|
ptOut1 = pt1;
|
|
|
|
if(pt3 == ptInt)
|
|
ptOut2 = pt4;
|
|
else
|
|
ptOut2 = pt3;
|
|
XVector3D vt1 = ptOut1 - ptInt;
|
|
XVector3D vt2 = ptOut2 - ptInt;
|
|
|
|
SetLocation(ptInt);
|
|
SetWidth1(nWidth1);
|
|
SetWidth2(nWidth2);
|
|
SetDirection1(vt1);
|
|
SetDirection2(vt2);
|
|
|
|
XPoint ptNode1, ptNode2;
|
|
GetNodePt(ptNode1, ptNode2);
|
|
int ret1 = ptNode1&l1;
|
|
if(ret1 == PR_INSIDE){
|
|
OPENOBJ_BEGIN(id1, AcDb::kForWrite, TDbDuct, pPipe);
|
|
if(pPipe){
|
|
if(pPipe->StartPoint() == ptOut1)
|
|
pPipe->SetEndPoint(ptNode1);
|
|
else
|
|
pPipe->SetStartPoint(ptNode1);
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
|
|
int ret2 = ptNode2&l2;
|
|
if(ret2 == PR_INSIDE){
|
|
OPENOBJ_BEGIN(id2, AcDb::kForWrite, TDbDuct, pPipe);
|
|
if(pPipe){
|
|
if(pPipe->StartPoint() == ptOut2)
|
|
pPipe->SetEndPoint(ptNode2);
|
|
else
|
|
pPipe->SetStartPoint(ptNode2);
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
XArc GetFilletArc(XLine &l1, XLine &l2, double nRadius, XPoint &ptTmp1, XPoint &ptTmp2)
|
|
{
|
|
|
|
|
|
XPoint ptInt, pt1, pt2, pt3, pt4, ptCen;
|
|
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();
|
|
else
|
|
pt1 = l1.StartPoint();
|
|
|
|
nDist1 = ads_distance(ptInt, l2.GetStartPoint());
|
|
nDist2 = ads_distance(ptInt, l2.GetEndPoint());
|
|
if(nDist1 < nDist2)
|
|
pt2 = l2.EndPoint();
|
|
else
|
|
pt2 = l2.StartPoint();
|
|
|
|
AT_cal_fillet(pt1, ptInt, pt2, nRadius, pt3, ptCen, pt4);
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
Acad::ErrorStatus TDbDuctElbow::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;
|
|
}
|
|
double nAngOut1 = ads_angle(XPoint(), m_vtLocation1);
|
|
double nAngOut2 = ads_angle(XPoint(), m_vtLocation2);
|
|
XPoint pt1, pt2, pt3, pt4, ptCen, pt5, pt6, ptOut1, ptOut2, pt8, pt7;
|
|
ads_polar(m_ptLocation, nAngOut1, m_nWidth1*10, ptOut1);
|
|
ads_polar(m_ptLocation, nAngOut2, m_nWidth2*10, ptOut2);
|
|
AcDbObjectId idLayerOld=dc.GetLayerId();
|
|
AcDbObjectId idDoteLayer/*=InitLayer(LAYER_DUCT_DOTE)*/;
|
|
if(idDoteLayer.isValid())
|
|
dc.SetLayer(idDoteLayer);
|
|
dc.SetColorLayer(colorIndex(), idDoteLayer);
|
|
XLine _l1(m_ptLocation, ptOut1), _l2(m_ptLocation, ptOut2);
|
|
XArc arc4 = GetFilletArc(_l1, _l2, m_nWidth1, pt3, pt4);
|
|
dc << arc4;
|
|
dc.SetLayer(idLayerOld);
|
|
dc.SetColorLayer(colorIndex(), idLayerOld);
|
|
|
|
ads_polar(pt3, nAngOut1-PI/2, m_nWidth1/2, pt1);
|
|
ads_polar(pt3, nAngOut1+PI/2, m_nWidth1/2, pt2);
|
|
dc << XLine(pt1, pt2, 1);
|
|
ads_polar(pt4, nAngOut2-PI/2, m_nWidth2/2, pt5);
|
|
ads_polar(pt4, nAngOut2+PI/2, m_nWidth2/2, pt6);
|
|
dc << XLine(pt5, pt6, 1);
|
|
|
|
XLine l1 = XLine(m_ptLocation, ptOut1).Offset(m_nWidth1/2);
|
|
XLine l2 = XLine(m_ptLocation, ptOut2).Offset(-m_nWidth2/2);
|
|
l1.SetLineFlag(1);
|
|
l2.SetLineFlag(1);
|
|
double nRadius;
|
|
if(l1.Intersection(&l2, ptCen) != 1)
|
|
nRadius = m_nWidth1 + m_nWidth1/2;
|
|
else
|
|
nRadius = m_nWidth1 - m_nWidth1/2;
|
|
|
|
XArc arc5 = GetFilletArc(l1, l2, nRadius, pt7, pt8);
|
|
if(fabs(m_nWidth1 - m_nWidth2) > 0.001){ //如果2段宽度不一样
|
|
XPoint ptMid;
|
|
arc5.MidPoint(ptMid);
|
|
arc5 = XArc(pt1, ptMid, pt6);
|
|
}
|
|
|
|
XCurveSegment seg1, seg2;
|
|
seg1 = arc5;
|
|
|
|
XLine l3 = XLine(m_ptLocation, ptOut1).Offset(-m_nWidth1/2);
|
|
XLine l4 = XLine(m_ptLocation, ptOut2).Offset(m_nWidth2/2);
|
|
l3.SetLineFlag(1);
|
|
l4.SetLineFlag(1);
|
|
|
|
if(l3.Intersection(&l4, ptCen) != 1)
|
|
nRadius = m_nWidth1 + m_nWidth1/2;
|
|
else
|
|
nRadius = m_nWidth1 - m_nWidth1/2;
|
|
|
|
XArc arc6 = GetFilletArc(l3, l4, nRadius, pt7, pt8);
|
|
if(fabs(m_nWidth1 - m_nWidth2) > 0.001){ //如果2段宽度不一样
|
|
XPoint ptMid;
|
|
arc6.MidPoint(ptMid);
|
|
arc6 = XArc(pt2, ptMid, pt5);
|
|
}
|
|
|
|
seg2 = arc6;
|
|
|
|
if (g_bPipeWeight) {
|
|
double dWeight = GetPScale()*m_nPipeWeight;
|
|
DrawWeight(dc, dWeight, seg1, colorIndex(), linetypeScale());
|
|
DrawWeight(dc, dWeight, seg2, colorIndex(), linetypeScale());
|
|
} else {
|
|
dc << arc5;
|
|
dc << arc6;
|
|
}
|
|
|
|
return Acad::eOk;
|
|
}
|
|
|
|
void TDbDuctElbow::GetTips(DList<TObjInfoUnit> &info) const
|
|
{
|
|
info.Append(new TObjInfoUnit(_T("对象类型"), _T("风管弯头")));
|
|
}
|
|
|
|
|
|
|
|
void InitDbDuctElbow(BOOL bTrue)
|
|
{
|
|
if(bTrue) {
|
|
TDbDuctElbow::rxInit();
|
|
TDbDuctElbow::InitMatchProtocol(TRUE);
|
|
} else {
|
|
TDbDuctElbow::InitMatchProtocol(FALSE);
|
|
deleteAcRxClass(TDbDuctElbow::desc());
|
|
}
|
|
}
|