354 lines
11 KiB
C++
354 lines
11 KiB
C++
// DbDuctTapered.cpp: implementation of the TDbDuctTapered class.
|
|
//
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#include "stdafx.h"
|
|
#include "DbDuctTapered.h"
|
|
#include "PipeTools.h"
|
|
#include "GlobalFunction.h"
|
|
|
|
extern void DrawWeight(XExplodeDraw &dc,double dWeight,XCurveSegment &seg,int nColorIndex, double nScale);
|
|
|
|
ACRX_DXF_DEFINE_MEMBERS(ATSDuctTapered, ATSEntity, AcDb::kDHL_CURRENT,
|
|
AcDb::kMReleaseCurrent, 1, ATS_DUCTTAPERED,
|
|
"ATS_DUCTTAPERED图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com");
|
|
IMPLEMENT_TENTBASE(TDbDuctTapered);
|
|
const Adesk::UInt8 TDbDuctTapered::g_nVersion = 1;
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Construction/Destruction
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
TDbDuctTapered::TDbDuctTapered()
|
|
{
|
|
m_nPipeWeight = 0.5;
|
|
}
|
|
|
|
void TDbDuctTapered::CopyPropertiesFrom(AcDbEntity *pSrc,unsigned gMatchFlag)
|
|
{
|
|
assertWriteEnabled();
|
|
TDbEntity::CopyPropertiesFrom(pSrc, gMatchFlag);
|
|
}
|
|
|
|
Acad::ErrorStatus TDbDuctTapered::subGetClassID(CLSID* pClsid) const
|
|
{
|
|
// *pClsid = CLSID_ComEquipment;
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus
|
|
TDbDuctTapered::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_ptStart);
|
|
snapPoints.append(m_ptEnd);
|
|
}
|
|
es=TDbEntity::subGetOsnapPoints(osnapMode,gsSelectionMark,
|
|
ptPick,lastPoint,viewXform,snapPoints,geomIds);
|
|
|
|
return es;
|
|
}
|
|
|
|
// 从DWG读入数据:
|
|
Acad::ErrorStatus TDbDuctTapered::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_ptStart);
|
|
pFiler->readItem((AcGePoint3d *)&m_ptEnd);
|
|
pFiler->readItem((AcGeVector3d *)&m_vtLocation);
|
|
pFiler->readItem(&m_nStartWidth);
|
|
pFiler->readItem(&m_nEndWidth);
|
|
pFiler->readItem(&m_nPipeWeight);
|
|
|
|
|
|
return pFiler->filerStatus();
|
|
}
|
|
|
|
Acad::ErrorStatus TDbDuctTapered::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_ptStart);
|
|
pFiler->writeItem((const AcGePoint3d &)m_ptEnd);
|
|
pFiler->writeItem((const AcGeVector3d &)m_vtLocation);
|
|
pFiler->writeItem(m_nStartWidth);
|
|
pFiler->writeItem(m_nEndWidth);
|
|
pFiler->writeItem(m_nPipeWeight);
|
|
|
|
|
|
return pFiler->filerStatus();
|
|
}
|
|
|
|
|
|
Acad::ErrorStatus TDbDuctTapered::dxfInFields(AcDbDxfFiler* pFiler)
|
|
{
|
|
assertWriteEnabled();
|
|
Acad::ErrorStatus es=Acad::eOk;
|
|
es=TDbEntity::dxfInFields(pFiler);
|
|
return es;
|
|
}
|
|
|
|
Acad::ErrorStatus TDbDuctTapered::dxfOutFields(AcDbDxfFiler* pFiler) const
|
|
{
|
|
Acad::ErrorStatus es=Acad::eOk;
|
|
es=TDbEntity::dxfOutFields(pFiler);
|
|
return es;
|
|
}
|
|
|
|
// Active when being rotated, scaled, moved, etc.
|
|
Acad::ErrorStatus
|
|
TDbDuctTapered::subTransformBy(const AcGeMatrix3d& xform)
|
|
{
|
|
assertWriteEnabled();
|
|
m_ptStart.TransformBy(xform);
|
|
m_ptEnd.TransformBy(xform);
|
|
Acad::ErrorStatus es=Acad::eOk;
|
|
return es;
|
|
|
|
}
|
|
|
|
// 取得所有的夹点
|
|
Acad::ErrorStatus
|
|
TDbDuctTapered::subGetGripPoints(AcGePoint3dArray& gripPoints,
|
|
AcDbIntArray& osnapModes,
|
|
AcDbIntArray& geomIds) const
|
|
{
|
|
assertReadEnabled();
|
|
gripPoints.append(m_ptStart);
|
|
gripPoints.append(m_ptEnd);
|
|
return Acad::eOk;
|
|
|
|
}
|
|
|
|
// stretch points is diffrent from grep points, with no midpoint included
|
|
Acad::ErrorStatus
|
|
TDbDuctTapered::subGetStretchPoints(AcGePoint3dArray & stretchPoints) const
|
|
{
|
|
assertReadEnabled();
|
|
stretchPoints.append(m_ptStart);
|
|
stretchPoints.append(m_ptEnd);
|
|
return Acad::eOk;
|
|
}
|
|
|
|
|
|
|
|
// 功能: 夹点操作
|
|
Acad::ErrorStatus
|
|
TDbDuctTapered::subMoveGripPointsAt(const AcDbIntArray& indices, const AcGeVector3d& offset)
|
|
{
|
|
assertWriteEnabled();
|
|
AcGeMatrix3d mat;
|
|
AcGeVector3d vtOffset=offset;
|
|
vtOffset.z=0;
|
|
mat.setToTranslation(vtOffset);
|
|
int nCount=indices.length();
|
|
if(nCount!=1){
|
|
m_ptStart.TransformBy(mat);
|
|
m_ptEnd.TransformBy(mat);
|
|
}
|
|
int idx = indices[0];
|
|
double nAng = ads_angle(XPoint(), m_vtLocation);
|
|
if(idx == 0){
|
|
XPoint ptTmp = m_ptStart;
|
|
ptTmp.TransformBy(mat);
|
|
XVector3D vt = m_ptStart - ptTmp;
|
|
vt.Normalize();
|
|
XVector3D vt2 = vt;
|
|
vt2.Reverse();
|
|
if(vt == m_vtLocation || vt2 == m_vtLocation)
|
|
m_ptStart.TransformBy(mat);
|
|
else if(m_nStartWidth < m_nEndWidth){
|
|
XPoint p1, p2, ptTmpStart;
|
|
ads_polar(m_ptEnd, nAng, -GetLength(), ptTmpStart);
|
|
ads_polar(ptTmpStart, -PI/2, m_nEndWidth/2, p1);
|
|
ads_polar(ptTmpStart, PI/2, m_nEndWidth/2, p2);
|
|
|
|
double nDist1 = ads_distance(ptTmp, ptTmpStart);
|
|
double nDist2 = ads_distance(ptTmp, p1);
|
|
double nDist3 = ads_distance(ptTmp, p2);
|
|
if(nDist1 < nDist2 && nDist1 < nDist3){ //居中
|
|
m_ptStart = ptTmpStart;
|
|
}
|
|
else if(nDist2 < nDist1 && nDist2 < nDist3){
|
|
ads_polar(p1, PI/2, m_nStartWidth/2, m_ptStart);
|
|
}
|
|
else if(nDist3 < nDist1 && nDist3 < nDist2){
|
|
ads_polar(p2, -PI/2, m_nStartWidth/2, m_ptStart);
|
|
}
|
|
|
|
}
|
|
}
|
|
else if(idx == 1){
|
|
XPoint ptTmp = m_ptEnd;
|
|
ptTmp.TransformBy(mat);
|
|
XVector3D vt = ptTmp - m_ptEnd;
|
|
vt.Normalize();
|
|
XVector3D vt2 = vt;
|
|
vt2.Reverse();
|
|
if(vt == m_vtLocation || vt2 == m_vtLocation)
|
|
m_ptEnd.TransformBy(mat);
|
|
else if(m_nStartWidth > m_nEndWidth){
|
|
XPoint p1, p2, ptTmpEnd;
|
|
ads_polar(m_ptStart, nAng, GetLength(), ptTmpEnd);
|
|
ads_polar(ptTmpEnd, -PI/2, m_nStartWidth/2, p1);
|
|
ads_polar(ptTmpEnd, PI/2, m_nStartWidth/2, p2);
|
|
double nDist1 = ads_distance(ptTmp, ptTmpEnd);
|
|
double nDist2 = ads_distance(ptTmp, p1);
|
|
double nDist3 = ads_distance(ptTmp, p2);
|
|
if(nDist1 < nDist2 && nDist1 < nDist3){ //居中
|
|
m_ptEnd = ptTmpEnd;
|
|
}
|
|
else if(nDist2 < nDist1 && nDist2 < nDist3){
|
|
ads_polar(p1, PI/2, m_nEndWidth/2, m_ptEnd);
|
|
}
|
|
else if(nDist3 < nDist1 && nDist3 < nDist2){
|
|
ads_polar(p2, -PI/2, m_nEndWidth/2, m_ptEnd);
|
|
}
|
|
}
|
|
}
|
|
Acad::ErrorStatus es=Acad::eOk;
|
|
return es;
|
|
}
|
|
|
|
|
|
// 功能: 夹点进行Stretch操作
|
|
Acad::ErrorStatus TDbDuctTapered::subMoveStretchPointsAt(const AcDbIntArray& indices,
|
|
const AcGeVector3d& offset)
|
|
{
|
|
assertWriteEnabled();
|
|
Acad::ErrorStatus es=Acad::eOk;
|
|
return es;
|
|
}
|
|
|
|
double TDbDuctTapered::GetLength()
|
|
{
|
|
double nPipeLength(0);
|
|
double nAng = ads_angle(XPoint(), m_vtLocation);
|
|
|
|
XCurveSegment seg, seg1, seg2;
|
|
XPoint pt1, pt2, pt3, pt4;
|
|
|
|
ads_polar(m_ptStart, nAng-PI/2, m_nStartWidth/2, pt1);
|
|
ads_polar(m_ptStart, nAng+PI/2, m_nStartWidth/2, pt2);
|
|
|
|
ads_polar(m_ptEnd, nAng-PI/2, m_nEndWidth/2, pt3);
|
|
ads_polar(m_ptEnd, nAng+PI/2, m_nEndWidth/2, pt4);
|
|
|
|
seg1 = XLine(pt1, pt3, 1);
|
|
seg2 = XLine(pt2, pt4, 1);
|
|
|
|
if(fabs(seg1.GetLength() - seg2.GetLength()) < 0.1 )//中间对齐
|
|
nPipeLength = seg1.GetLength();
|
|
else if((seg1.GetLength() - seg2.GetLength()) > 1)
|
|
nPipeLength = seg2.GetLength();
|
|
else
|
|
nPipeLength = seg1.GetLength();
|
|
return nPipeLength;
|
|
}
|
|
|
|
Acad::ErrorStatus TDbDuctTapered::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;
|
|
}
|
|
XPoint ptTmpS, ptTmpE, pt1, pt2, pt3, pt4;
|
|
double nAng = ads_angle(XPoint(), m_vtLocation);
|
|
double nPipeLength(0);
|
|
|
|
|
|
XCurveSegment seg, seg1, seg2;
|
|
//绘制2边线
|
|
ads_polar(m_ptStart, nAng-PI/2, m_nStartWidth/2, pt1);
|
|
ads_polar(m_ptStart, nAng+PI/2, m_nStartWidth/2, pt2);
|
|
dc << XLine(pt1, pt2, 1);
|
|
ads_polar(m_ptEnd, nAng-PI/2, m_nEndWidth/2, pt3);
|
|
ads_polar(m_ptEnd, nAng+PI/2, m_nEndWidth/2, pt4);
|
|
dc << XLine(pt3, pt4, 1);
|
|
seg1 = XLine(pt1, pt3, 1);
|
|
seg2 = XLine(pt2, pt4, 1);
|
|
|
|
|
|
if (g_bPipeWeight) {
|
|
double dWeight = GetPScale()*m_nPipeWeight;
|
|
DrawWeight(dc, dWeight, seg1, colorIndex(), linetypeScale());
|
|
DrawWeight(dc, dWeight, seg2, colorIndex(), linetypeScale());
|
|
} else {
|
|
dc << seg1;
|
|
dc << seg2;
|
|
}
|
|
|
|
//绘制中心线
|
|
if(fabs(seg1.GetLength() - seg2.GetLength()) < 0.1 )//中间对齐
|
|
nPipeLength = seg1.GetLength();
|
|
else if((seg1.GetLength() - seg2.GetLength()) > 1)
|
|
nPipeLength = seg2.GetLength();
|
|
else
|
|
nPipeLength = seg1.GetLength();
|
|
|
|
if(m_nStartWidth > m_nEndWidth){
|
|
ads_polar(m_ptEnd, nAng, -nPipeLength, ptTmpS);
|
|
ptTmpE = m_ptEnd;
|
|
}
|
|
else{
|
|
ads_polar(m_ptStart, nAng, nPipeLength, ptTmpE);
|
|
ptTmpS = m_ptStart;
|
|
}
|
|
|
|
XLine line(ptTmpS, ptTmpE, 1);
|
|
seg = line;
|
|
|
|
AcDbObjectId idLayerOld = dc.GetLayerId();
|
|
AcDbObjectId idDoteLayer/* = InitLayer(LAYER_DUCT_DOTE)*/;
|
|
if(idDoteLayer.isValid())
|
|
dc.SetLayer(idDoteLayer);
|
|
dc.SetColorLayer(colorIndex(), idDoteLayer);
|
|
dc << seg;
|
|
dc.SetLayer(idLayerOld);
|
|
dc.SetColorLayer(colorIndex(), idLayerOld);
|
|
|
|
return Acad::eOk;
|
|
}
|
|
|
|
void TDbDuctTapered::GetTips(DList<TObjInfoUnit> &info) const
|
|
{
|
|
info.Append(new TObjInfoUnit(_T("对象类型"), _T("风管变径")));
|
|
}
|
|
|
|
|
|
void InitDbDuctTapered(BOOL bTrue)
|
|
{
|
|
if(bTrue) {
|
|
TDbDuctTapered::rxInit();
|
|
TDbDuctTapered::InitMatchProtocol(TRUE);
|
|
} else {
|
|
TDbDuctTapered::InitMatchProtocol(FALSE);
|
|
deleteAcRxClass(TDbDuctTapered::desc());
|
|
}
|
|
}
|