Files
envi-code/SourceCode/Code2026/tg_shs/shs_pipewire/HDbEquipment.cpp
T
2026-09-28 15:28:50 +08:00

916 lines
24 KiB
C++

#include "stdafx.h"
#include "DbPipe.h"
#include "HDbEquipment.h"
#include "PipePrototype.h"
#include "DbDuct.h" // sg add
ACRX_DXF_DEFINE_MEMBERS(ATSHDbEquipment, ATSPipeNode, AcDb::kDHL_CURRENT,
AcDb::kMReleaseCurrent, 1, ATS_HEQUIPMENT,
"ATS_HEQUIPMENT图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com");
IMPLEMENT_TENTBASE(THDbEquipment);
const Adesk::UInt8 THDbEquipment::g_nVersion = 1;
THDbEquipment::THDbEquipment():
m_nMirror(0), m_vtDirection(1,0,0), m_dSizeX(0), m_dSizeY(0), m_dSizeZ(0),
m_bDrawLabel(FALSE), m_modelType(TPipeSys::kModel), m_dSysAngle(PI/4)
{
m_visibility = TPipeSys::kVisible;
}
void THDbEquipment::AddInterface(XString sName, const XPoint& ptLoc, const XVector3D& vt)
{
assertWriteEnabled();
for (int i=0; i<m_lstInterface.Length(); i++)
{
TPipeInterface &iFace = *m_lstInterface[i];
if (_tcsicmp(sName, iFace.m_sSysLabel) == 0)
return;
}
TPipeInterface iFace;
iFace.m_faceType = TPipeInterface::kBoundry;
iFace.m_sSysLabel = sName;
iFace.m_ptLocation = ptLoc;
iFace.m_vtLocation = vt;
TDbPipeNode::AddInterface(iFace);
}
TPipeInterface* THDbEquipment::FindInterface(XString sName)
{
for (int i=0; i<m_lstInterface.Length(); i++)
{
TPipeInterface *pFace = m_lstInterface[i];
if (_tcsicmp(sName, pFace->m_sSysLabel) == 0)
return pFace;
}
return NULL;
}
BOOL THDbEquipment::RemoveInterface(XString sName)
{
for (int i=0; i<m_lstInterface.Length(); i++)
{
TPipeInterface *pFace = m_lstInterface[i];
if (_tcsicmp(sName, pFace->m_sSysLabel) == 0) {
m_lstInterface.Remove();
return TRUE;
}
}
return FALSE;
}
void THDbEquipment::CopyPropertiesFrom(AcDbEntity *pSrc, unsigned gMatchFlag)
{
assertWriteEnabled();
TDbPipeNode::CopyPropertiesFrom(pSrc, gMatchFlag);
TLabelStyle::CopyPropertiesFrom(pSrc, gMatchFlag);
THDbEquipment *pEqu = THDbEquipment::cast(pSrc);
if (pEqu != NULL) {
//m_dSizeX = pEqu->m_dSizeX;
//m_dSizeY = pEqu->m_dSizeY;
//m_dSizeZ = pEqu->m_dSizeZ;
//m_nMirror = pEqu->m_nMirror;
//m_idBlock2d = pEqu->m_idBlock2d;
//m_idBlock3d = pEqu->m_idBlock3d;
m_idLabelLayer = pEqu->m_idLabelLayer;
m_idLabelLayer = pEqu->m_idLabelLayer;
}
}
// sg add
Acad::ErrorStatus THDbEquipment::subGetClassID(CLSID* pClsid) const
{
return Acad::eOk;
}
Acad::ErrorStatus
THDbEquipment::subGetOsnapPoints(AcDb::OsnapMode osnapMode,
INT_PTR gsSelectionMark,
const AcGePoint3d& ptPick,
const AcGePoint3d& lastPoint,
const AcGeMatrix3d& viewXform,
AcGePoint3dArray& snapPoints,
AcDbIntArray& geomIds) const
{
assertReadEnabled();
Acad::ErrorStatus es=Acad::eOk;
if (osnapMode == AcDb::kOsModeIns || osnapMode == AcDb::kOsModeCen
|| osnapMode == AcDb::kOsModeNode) {
snapPoints.append(m_ptLocation);
}
es = TDbPipeNode::subGetOsnapPoints(osnapMode, gsSelectionMark, ptPick, lastPoint,
viewXform, snapPoints, geomIds);
return es;
}
// 从DWG读入数据:
Acad::ErrorStatus THDbEquipment::dwgInFields(AcDbDwgFiler* pFiler)
{
assertWriteEnabled();
Acad::ErrorStatus es = TDbPipeNode::dwgInFields(pFiler);
if (es != Acad::eOk)
return es;
es = TLabelStyle::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(&m_idBlock2d);
pFiler->readItem(&m_idBlock3d);
pFiler->readItem(&m_idLabelLayer);
pFiler->readItem((AcGePoint3d *)&m_ptLocation);
pFiler->readItem((AcGePoint3d *)&m_ptLabel);
pFiler->readItem((AcGePoint3d *)&m_ptLabelOut);
pFiler->readItem((AcGeVector3d *)&m_vtDirection);
pFiler->readItem(&m_dSizeX);
pFiler->readItem(&m_dSizeY);
pFiler->readItem(&m_dSizeZ);
pFiler->readItem(&m_nMirror);
ReadString(pFiler, m_sLabel);
//pFiler->readItem(&m_bDrawLabel);
FilerRead(pFiler, m_bDrawLabel);
pFiler->readItem(&m_dSysAngle);
Adesk::UInt8 nTemp = 0;
pFiler->readItem(&nTemp);
m_modelType = (TPipeSys::ModelType)nTemp;
return pFiler->filerStatus();
}
Acad::ErrorStatus THDbEquipment::dwgOutFields(AcDbDwgFiler* pFiler) const
{
assertReadEnabled();
Acad::ErrorStatus es = TDbPipeNode::dwgOutFields(pFiler);
if (es != Acad::eOk)
return es;
es = TLabelStyle::dwgOutFields(pFiler);
if (es != Acad::eOk)
return es;
pFiler->writeItem(g_nVersion);
pFiler->writeItem(m_idBlock2d);
pFiler->writeItem(m_idBlock3d);
pFiler->writeItem(m_idLabelLayer);
pFiler->writeItem((const AcGePoint3d &)m_ptLocation);
pFiler->writeItem((const AcGePoint3d &)m_ptLabel);
pFiler->writeItem((const AcGePoint3d &)m_ptLabelOut);
pFiler->writeItem((const AcGeVector3d &)m_vtDirection);
pFiler->writeItem(m_dSizeX);
pFiler->writeItem(m_dSizeY);
pFiler->writeItem(m_dSizeZ);
pFiler->writeItem(m_nMirror);
pFiler->writeItem((const TCHAR *)m_sLabel);
//pFiler->writeItem(m_bDrawLabel);
FilerWrite(pFiler, m_bDrawLabel);
pFiler->writeItem(m_dSysAngle);
pFiler->writeItem((Adesk::UInt8)m_modelType);
return pFiler->filerStatus();
}
Acad::ErrorStatus THDbEquipment::dxfInFields(AcDbDxfFiler* pFiler)
{
assertWriteEnabled();
Acad::ErrorStatus es = Acad::eOk;
es = TDbPipeNode::dxfInFields(pFiler);
if (es != Acad::eOk)
return es;
es = TLabelStyle::dxfInFields(pFiler);
if (es != Acad::eOk)
return es;
if (!pFiler->atSubclassData(_T("THDbEquipment"))) {
return Acad::eBadDxfSequence;
}
resbuf rb;
while((es==Acad::eOk) && ((es=pFiler->readResBuf(&rb))==Acad::eOk)) {
switch (rb.restype) {
case AcDb::kDxfXCoord:
m_ptLocation =rb.resval.rpoint;
break;
case AcDb::kDxfXReal:
m_dSizeX=rb.resval.rreal;
break;
case AcDb::kDxfXReal+1:
m_dSizeY=rb.resval.rreal;
break;
case AcDb::kDxfXReal+2:
m_dSizeZ=rb.resval.rreal;
break;
case AcDb::kDxfXTextString:
break;
default:
pFiler->pushBackItem();
es = Acad::eEndOfFile;
break;
}
}
if(es!=Acad::eEndOfFile)
return Acad::eInvalidResBuf;
return pFiler->filerStatus();
}
Acad::ErrorStatus THDbEquipment::dxfOutFields(AcDbDxfFiler* pFiler) const
{
Acad::ErrorStatus es = Acad::eOk;
es = TDbPipeNode::dxfOutFields(pFiler);
assert(es == Acad::eOk);
es = TLabelStyle::dxfOutFields(pFiler);
assert(es == Acad::eOk);
es = pFiler->writeItem(AcDb::kDxfSubclass, _T("THDbEquipment"));
assert(es==Acad::eOk);
pFiler->writePoint3d(AcDb::kDxfXCoord, m_ptLocation);
pFiler->writeDouble(AcDb::kDxfXReal, m_dSizeX);
pFiler->writeDouble(AcDb::kDxfXReal+1, m_dSizeY);
pFiler->writeDouble(AcDb::kDxfXReal+2, m_dSizeZ);
CString sBlkName, sDesName;
GetBlkNameById(m_idBlock2d, sBlkName, sDesName);
pFiler->writeString(AcDb::kDxfXTextString, (const TCHAR*)sBlkName);
return es;
}
AcGeScale3d THDbEquipment::GetInsert2dScale() const
{
assertReadEnabled();
AcGeScale3d scale(1);
double x = 0, y = 0;
GetInsertExtend(m_idBlock2d, x, y);
// double x = 1, y = 1;
if (x > 1.0E-3)
scale.sx *= m_dSizeX/x;
if (y > 1.0E-3)
scale.sy *= m_dSizeY/y;
if (IsMirrorByY())
scale.sx *= -1;
if (IsMirrorByX())
scale.sy *= -1;
return scale;
}
AcGeScale3d THDbEquipment::GetInsert3dScale() const
{
assertReadEnabled();
AcGeScale3d scale(1);
double x=0,y=0,z=0;
// GetInsertExtend(m_idBlock2d,x,y,z); // mcl modify
GetInsertExtend(m_idBlock3d,x,y,z);
if(x>1.0E-3)
scale.sx *= m_dSizeX/x;
if(y>1.0E-3)
scale.sy *= m_dSizeY/y;
if(z>1.0E-3)
scale.sz *= m_dSizeZ/z;
if(IsMirrorByY())
scale.sx *= -1;
if(IsMirrorByX())
scale.sy *= -1;
return scale;
}
Acad::ErrorStatus THDbEquipment::ExplodeOrDraw2d(XExplodeDraw &dc) const
{
// cet 2016.10.17 add 图层关闭时,实体不显示,不进行绘制(打印时,也不会绘制)
AcDbLayerTableRecordPointer player(this->layerId(), AcDb::kForRead);
if (player.openStatus() == Acad::eOk && player->isOff())
{
return Acad::eOk;
}
if(IsSysType())
return DrawSystem(dc);
return _ExplodeOrDraw2d(dc);
}
Acad::ErrorStatus THDbEquipment::
_ExplodeOrDraw2d(XExplodeDraw &dc,BOOL bZEqual0) const
{
if(!m_idBlock2d.isValid())
return Acad::eInvalidInput;
if(fabs(m_vtDirection.x)<1.0E-6 && fabs(m_vtDirection.y)<1.0E-6)
return Acad::eOk; //垂直设备
AcGeScale3d scale=GetInsert2dScale();
OPENOBJ_BEGIN(m_idBlock2d, AcDb::kForRead, AcDbBlockTableRecord, pBlock);
if(pBlock != NULL) {
XPoint ptLocation(m_ptLocation);
if(bZEqual0) ptLocation.z=0;
double dAngle = ads_angle(XPoint(),m_vtDirection);
dc.DrawBlock(*pBlock,ptLocation,scale,dAngle,TRUE);
}
OPENOBJ_END();
//绘制接口
for(int i=0; i<m_lstInterface.Length(); i++) {
const TPipeInterface &iFace=m_lstInterface[i];
if(!iFace.m_idPipe.isValid()) {
XPoint ptDir=iFace.m_ptLocation+iFace.m_vtLocation;
dc << XLine(iFace.m_ptLocation,ptDir);
}
}
if(m_bDrawLabel) // 绘制标注
DrawLabelText(dc);
return Acad::eOk;
}
Acad::ErrorStatus THDbEquipment::DrawSystem(XExplodeDraw &dc,BOOL bZEqual0) const
{
XPoint pt1,pt2,pt3,pt4;
double dSubY = sin(m_dSysAngle)*m_dSizeX/2;
double dSubX = cos(m_dSysAngle)*m_dSizeX/2;
pt1.x = m_ptLocation.x-m_dSizeY/2-dSubX;
pt1.y = m_ptLocation.y-dSubY;
pt2.x = m_ptLocation.x+m_dSizeY/2-dSubX;
pt2.y = m_ptLocation.y-dSubY;
pt3.x = m_ptLocation.x+m_dSizeY/2+dSubX;
pt3.y = m_ptLocation.y+dSubY;
pt4.x = m_ptLocation.x-m_dSizeY/2+dSubX;
pt4.y = m_ptLocation.y+dSubY;
XPoly2D poly1(1);
poly1.AppendNode(pt1);
poly1.AppendNode(pt2);
poly1.AppendNode(pt3);
poly1.AppendNode(pt4);
if(!bZEqual0)
poly1.SetElevation(m_ptLocation.z);
XPoly2D poly2(poly1);
for(int i=0; i<4; i++) {
poly1[i]->y += m_dSizeZ/2;
poly2[i]->y -= m_dSizeZ/2;
dc << XLine(*poly1[i],*poly2[i]);
}
dc << poly1 << poly2;
return Acad::eOk;
}
Acad::ErrorStatus THDbEquipment::DrawLabelText(XExplodeDraw &dc) const
{
AcDbObjectId idLayerOld=dc.GetLayerId();
if(m_idLabelLayer.isValid())
dc.SetLayer(m_idLabelLayer);
TDbMText text;
text.setPropertiesFrom(this);
text.setLayer(m_idLabelLayer);
text.SetStyleId(m_idTextStyle);
text.SetText((const TCHAR*)m_sLabel);
text.SetHeight(m_dTextHeight);
text.SetAlignment(XExplodeDraw::kLeft);
text.SetLineSpace(0.4*m_dTextHeight);
text.SetPageWidth(200*m_dTextHeight/3.5);
AcDbExtents extents;
if(text.getGeomExtents(extents)==Acad::eOk) {
XPoint ptMin=extents.minPoint();
XPoint ptMax=extents.maxPoint();
double x=ptMax.x-ptMin.x;
double y=ptMax.y-ptMin.y;
XPoint ptLabel=m_ptLabel;
ptLabel.z=0;
if(IsOutLabel()) { // 引出标注
double dDist = GetPScale()*m_dTextHeight/3;
XPoint ptMid(ptLabel.x+dDist,ptLabel.y+y+dDist,0);
text.SetLocation(ptMid);
XPoint ptLabelOut=m_ptLabelOut;
ptLabelOut.z=0;
XPoint ptLabel2(ptLabel.x+x+2*dDist,ptLabel.y,0);
dc << XLine(ptLabel,ptLabel2)
<< XLine(ptLabel,ptLabelOut);
} else { // 非引出标注
double dAngle=GetTextRotation();
XPoint ptMid=ptLabel;
ptMid.x -= x/2;
ptMid.y += y/2;
ads_matrix mat;
ptLabel.GetRotationMatrix(dAngle,mat);
ptMid.TransformBy(mat);
text.SetRotation(dAngle);
text.SetLocation(ptMid);
}
dc.DrawEntity(text);
}
dc.SetLayer(idLayerOld);
return Acad::eOk;
}
Acad::ErrorStatus THDbEquipment::ExplodeOrDraw3d(XExplodeDraw &dc) const
{
if (IsSysType())
return DrawSystem(dc, FALSE);
if (!m_idBlock3d.isValid())
return _ExplodeOrDraw2d(dc, FALSE);
AcGeScale3d scale = GetInsert3dScale();
OPENOBJ_BEGIN(m_idBlock3d, AcDb::kForRead, AcDbBlockTableRecord, pBlock);
if (pBlock != NULL) {
XVector3D vtNormal(0,0,1);
if (fabs(m_vtDirection.z)>1.0E-6) { // 非水平面,计算法向
vtNormal = XVector3D(1,0,0)*m_vtDirection;
vtNormal.Normalize();
}
XPoint ptLoc = Wcs2Ecs(m_ptLocation, vtNormal);
double nRotEcs = ads_angle(XPoint(),m_vtDirection); // 计算ECS下的转角
AcDbBlockReference insert(ptLoc, m_idBlock3d);
insert.setRotation(nRotEcs);
insert.setScaleFactors(scale);
if (_tcscmp(dc.Desc(), XAcGiViewDraw::Descriptor()) == 0) {
AcGeMatrix3d mat=insert.blockTransform();
AcGiGeometry *geom=((XAcGiViewDraw &)dc).GetCommonDraw()->rawGeometry();
geom->pushModelTransform(mat);
geom->draw(pBlock);
geom->popModelTransform();
}
else if (_tcscmp(dc.Desc(), XExplodeStream::Descriptor())==0) {
((XExplodeStream &)dc).Append((AcDbEntity *)insert.clone());
}
}
else {
return Acad::eInvalidInput;
}
OPENOBJ_END();
// 绘制接口
for (int i=0; i<m_lstInterface.Length(); i++)
{
const TPipeInterface &iFace = m_lstInterface[i];
if (!iFace.m_idPipe.isValid()) {
XPoint ptDir = iFace.m_ptLocation + iFace.m_vtLocation;
dc << XLine(iFace.m_ptLocation, ptDir);
}
}
return Acad::eOk;
}
void THDbEquipment::GetTips(DList<TObjInfoUnit> &info) const
{
CString sBlkName,sDesName;
if(GetBlkNameById(m_idBlock2d,sBlkName,sDesName) && !sDesName.IsEmpty()) {
info.Append(new TObjInfoUnit(_T("对象名称"), (const TCHAR*)sDesName));
}
if(m_modelType==TPipeSys::kModel) {
for(int i=0; i<m_lstInterface.Length(); i++) {
const TPipeInterface& iFace=m_lstInterface[i];
// XString sLabel=iFace.m_sSysLabel;
// sLabel << _T("连接");
CString sLabel=(const TCHAR*)iFace.m_sSysLabel;
sLabel+= _T("连接");
if(iFace.m_idPipe.isValid())
info.Append(new TObjInfoUnit((const TCHAR*)sLabel,_T("完成")));
else
info.Append(new TObjInfoUnit((const TCHAR*)sLabel,_T("未连")));
}
}
}
int THDbEquipment::GetGripNumber() const
{
int nNodeGrip=TDbPipeNode::GetGripNumber();
if(!m_bDrawLabel || m_ptLocation==m_ptLabel)
return nNodeGrip+1;
if(IsOutLabel() && m_ptLocation!=m_ptLabelOut)
return nNodeGrip+3;
return nNodeGrip+2;
}
int THDbEquipment::GetStretchNumber() const
{
return GetGripNumber();
}
Acad::ErrorStatus THDbEquipment::GetGripText(int idx, CString &cs) const
{
Acad::ErrorStatus es=Acad::eOk;
//es=TDbPipeNode::GetGripText(idx,cs);
//if(es!=Acad::eOk) return es;
if(idx>=0 && idx<m_lstInterface.Length()) {
const TPipeInterface& iFace=m_lstInterface[idx];
CString csLabel = TString(iFace.m_sSysLabel).cs(); // sg modify
cs = _T("移动") + csLabel;
}
int nNodeGrip=TDbPipeNode::GetGripNumber();
if(idx>=nNodeGrip && idx<GetGripNumber()) {
if(idx==nNodeGrip)
cs=_T("移动设备");
else if(idx==nNodeGrip+1)
cs=_T("移动标注点");
else if(IsOutLabel() && idx==nNodeGrip+2)
cs = _T("移动引注点");
}
return es;
}
Acad::ErrorStatus
THDbEquipment::subGetGripPoints(AcGePoint3dArray& gripPoints,
AcDbIntArray& osnapModes,
AcDbIntArray& geomIds) const
{
assertReadEnabled();
Acad::ErrorStatus es=Acad::eOk;
es=TDbPipeNode::subGetGripPoints(gripPoints,osnapModes,geomIds);
if(es!=Acad::eOk) return es;
gripPoints.append((AcGePoint3d)m_ptLocation);
if(m_bDrawLabel && m_ptLocation!=m_ptLabel) {
gripPoints.append((AcGePoint3d)m_ptLabel);
if(IsOutLabel() && m_ptLocation!=m_ptLabelOut)
gripPoints.append((AcGePoint3d)m_ptLabelOut);
}
return Acad::eOk;
}
Acad::ErrorStatus
THDbEquipment::subGetStretchPoints(AcGePoint3dArray & stretchPoints) const
{
assertReadEnabled();
Acad::ErrorStatus es=Acad::eOk;
es=TDbPipeNode::subGetStretchPoints(stretchPoints);
if(es!=Acad::eOk) return es;
stretchPoints.append((AcGePoint3d)m_ptLocation);
if(m_bDrawLabel && m_ptLocation!=m_ptLabel) {
stretchPoints.append((AcGePoint3d)m_ptLabel);
if(IsOutLabel() && m_ptLocation!=m_ptLabelOut)
stretchPoints.append((AcGePoint3d)m_ptLabelOut);
}
return Acad::eOk;
}
Acad::ErrorStatus
THDbEquipment::subMoveGripPointsAt(const AcDbIntArray& indices,
const AcGeVector3d& offset)
{
assertWriteEnabled();
Acad::ErrorStatus es=Acad::eOk;
es = TDbPipeNode::subMoveGripPointsAt(indices,offset);
if (es != Acad::eOk)
return es;
es = MoveGSPointsAt(indices, offset);
return es;
}
Acad::ErrorStatus THDbEquipment::subMoveStretchPointsAt(const AcDbIntArray& indices,
const AcGeVector3d& offset)
{
assertWriteEnabled();
Acad::ErrorStatus es = Acad::eOk;
BOOL bNode = TRUE;
int nStretch = TDbPipeNode::GetStretchNumber();
int nCount = indices.length();
for (int i=0; i<nCount; i++)
{
if (indices[i]==nStretch) {
bNode = FALSE;
break;
}
}
if(bNode)
es=TDbPipeNode::subMoveStretchPointsAt(indices,offset);
if(es!=Acad::eOk)
return es;
es=MoveGSPointsAt(indices,offset);
return es;
}
Acad::ErrorStatus
THDbEquipment::MoveGSPointsAt(const AcDbIntArray& indices,
const AcGeVector3d& offset)
{
AcGeMatrix3d mat;
mat.setToTranslation(offset);
BOOL bOutLabel=IsOutLabel();
int nNodeGrip=TDbPipeNode::GetGripNumber();
int nThisGrip=GetGripNumber();
int nCount = indices.length();
for(int i=0; i<nCount;i++) {
if(indices[i]>=nThisGrip)
continue;
if(indices[i]==nNodeGrip){
m_ptLocation.TransformBy(mat);
m_ptLabel.TransformBy(mat);
m_ptLabelOut.TransformBy(mat);
for(int j=0; j<m_lstInterface.Length(); j++) {
TPipeInterface &iFace=*m_lstInterface[j];
iFace.m_ptLocation.TransformBy(mat);
}
break;
}
else if(indices[i]==nNodeGrip+1) {
if(!bOutLabel) {
m_ptLabel.TransformBy(mat);
m_ptLabelOut.TransformBy(mat);
} else
m_ptLabel.TransformBy(mat);
}
else if(IsOutLabel() && indices[i]==nNodeGrip+2) {
m_ptLabelOut.TransformBy(mat);
}
}
if(m_ptLabel==m_ptLocation)
m_ptLabelOut = m_ptLocation;
return Acad::eOk;
}
Acad::ErrorStatus
THDbEquipment::subTransformBy(const AcGeMatrix3d& xform)
{
assertWriteEnabled();
TDbPipeNode::subTransformBy(xform);
TLabelStyle::subTransformBy(xform);
m_ptLocation.TransformBy(xform);
m_ptLabel.TransformBy(xform);
m_ptLabelOut.TransformBy(xform);
((AcGeVector3d &)m_vtDirection).transformBy(xform);
ScaleTransform(xform,m_dSizeX);
ScaleTransform(xform,m_dSizeY);
ScaleTransform(xform,m_dSizeZ);
if (IsMirrorMatrix(xform)) // sg add 2008-5-29
{
if (!IsMirrorByX())
{
m_nMirror |= MIRROR_XAXIS;
}
else
{
m_nMirror &= ~MIRROR_XAXIS;
}
double dAng = ads_angle(XPoint(), m_vtDirection);
SetAngle(dAng, FALSE);
}
return Acad::eOk;
}
void THDbEquipment::MirrorByX(BOOL bFlag)
{
assertWriteEnabled();
if (bFlag)
m_nMirror |= MIRROR_XAXIS;
else
m_nMirror &= ~MIRROR_XAXIS;
AcGeVector3d vt(m_vtDirection);
vt.rotateBy(PI/2,AcGeVector3d(0,0,1));
AcGePlane plane(m_ptLocation,vt);
for (int i=0; i<m_lstInterface.Length(); i++)
{
TPipeInterface &iFace = *m_lstInterface[i];
XPoint &ptLocation = iFace.m_ptLocation;
XVector3D &vtLocation = iFace.m_vtLocation;
((AcGePoint3d &)ptLocation).mirror(plane);
((AcGeVector3d &)vtLocation).mirror(vt);
}
}
void THDbEquipment::MirrorByY(BOOL bFlag)
{
assertWriteEnabled();
if (bFlag)
m_nMirror |= MIRROR_YAXIS;
else
m_nMirror &= ~MIRROR_YAXIS;
AcGePlane plane(m_ptLocation,m_vtDirection);
for (int i=0; i<m_lstInterface.Length(); i++)
{
TPipeInterface &iFace = *m_lstInterface[i];
XPoint &ptLocation = iFace.m_ptLocation;
XVector3D &vtLocation = iFace.m_vtLocation;
((AcGePoint3d &)ptLocation).mirror(plane);
((AcGeVector3d &)vtLocation).mirror(m_vtDirection);
}
}
Acad::ErrorStatus THDbEquipment::GetExtents(XPoint &ptLow, XPoint &ptUp) const
{
Acad::ErrorStatus es=Acad::eOk;
es = TDbPipeNode::GetExtents(ptLow, ptUp);
if (es == Acad::eOk) {
if (ptLow==XPoint() && ptUp==XPoint()) {
ptLow = m_ptLocation;
ptUp = m_ptLocation;
}
else {
ptLow = Min(ptLow, m_ptLocation);
ptUp = Max(ptUp, m_ptLocation);
}
}
return es;
}
// 判断节点是否可以连接管段. nPos: 0--start; 1--end
BOOL THDbEquipment::CanLinkSide(const AcDbObjectId &idPipe, int nPos) const
{
BOOL bRet = FALSE;
OPENOBJ_BEGIN(idPipe, AcDb::kForRead, TDbPipePrototype, pPipe);
if (pPipe != NULL) {
double dSnap = PS_SNAP;
const XPoint &ptRef = nPos? pPipe->EndPoint() : pPipe->StartPoint();
int nCount = m_lstInterface.Length();
for (int i=0; i<nCount; i++)
{
const TPipeInterface &iFace = m_lstInterface[i];
if (ptRef.Distance(iFace.m_ptLocation) < dSnap) {
AcGeVector3d vt;
pPipe->getFirstDeriv(ptRef, vt);
if (nPos)
vt.negate();
AcGeTol myTol;
myTol.setEqualVector(1.0E-6); // sg modify,扩大了容忍度
if (vt.isCodirectionalTo(iFace.m_vtLocation, myTol)) {
bRet = TRUE;
break;
}
}
}
}
OPENOBJ_END();
return bRet;
}
// 对st类型的接口进行重新连接
void THDbEquipment::UpdateLinkage(const XPoint &ptAt, TPipeSys::SysType st,
const DList<AcDbObjectId> &idPipes)
{
assertWriteEnabled();
double dSnap = PS_SNAP;
for (int i=0; i<m_lstInterface.Length(); i++)
{
TPipeInterface &iFace = *m_lstInterface[i];
// 验证原有的管段
OPENOBJ_BEGIN(iFace.m_idPipe, AcDb::kForRead, TDbPipePrototype, pPipe);
if (pPipe != NULL) {
if (iFace.m_ptLocation.Distance(pPipe->StartPoint()) < dSnap) {
AcGeVector3d vt;
pPipe->getFirstDeriv(pPipe->StartPoint(), vt);
if (vt.isCodirectionalTo(iFace.m_vtLocation)) {
iFace.m_sysType = pPipe->GetSysType();
// iFace.m_sSysLabel = pPipe->GetSysLabel();
continue;
}
}
else if (iFace.m_ptLocation.Distance(pPipe->EndPoint()) < dSnap) {
AcGeVector3d vt;
pPipe->getFirstDeriv(pPipe->EndPoint(),vt);
vt.negate();
if (vt.isCodirectionalTo(iFace.m_vtLocation)) {
iFace.m_sysType = pPipe->GetSysType();
// iFace.m_sSysLabel = pPipe->GetSysLabel();
continue;
}
}
else { // sg add
if (pPipe->isKindOf(TDbDuct::desc())) {
TDbDuct *pDuct = TDbDuct::cast(pPipe);
if (pDuct->FindEquipment(objectId())) {
iFace.m_sysType = pDuct->GetSysType();
continue;
}
}
}
}
OPENOBJ_END();
// 重新验证所有管线
iFace.m_idPipe = AcDbObjectId::kNull;
for (int j=0; j<idPipes.Length(); j++)
{
const AcDbObjectId &id = idPipes[j];
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbPipePrototype, pPipe);
if (pPipe != NULL) {
if (iFace.m_ptLocation.Distance(pPipe->StartPoint()) < dSnap) {
AcGeVector3d vt;
pPipe->getFirstDeriv(pPipe->StartPoint(), vt);
if (vt.isCodirectionalTo(iFace.m_vtLocation)) {
iFace.m_idPipe = id;
iFace.m_sysType = pPipe->GetSysType();
// iFace.m_sSysLabel = pPipe->GetSysLabel();
break;
}
}
else if (iFace.m_ptLocation.Distance(pPipe->EndPoint()) < dSnap) {
AcGeVector3d vt;
pPipe->getFirstDeriv(pPipe->EndPoint(), vt);
vt.negate();
if (vt.isCodirectionalTo(iFace.m_vtLocation)) {
iFace.m_idPipe = id;
iFace.m_sysType = pPipe->GetSysType();
// iFace.m_sSysLabel = pPipe->GetSysLabel();
break;
}
}
}
OPENOBJ_END();
}
}
}
void THDbEquipment::SetLocation(const XPoint &pt)
{
assertWriteEnabled();
if (m_ptLabelOut == m_ptLocation)
m_ptLabelOut = pt;
if (m_ptLabel==m_ptLocation)
m_ptLabel = pt;
ads_matrix mat;
m_ptLocation.GetMoveMatrix(pt, mat);
for (int i=0; i<m_lstInterface.Length(); i++)
{
TPipeInterface &iFace = *m_lstInterface[i];
if (iFace.m_ptLocation != XPoint()) {
iFace.m_ptLocation.TransformBy(mat);
}
}
m_ptLocation = pt;
}
void THDbEquipment::SetSize(double x, double y, double z, BOOL bApply)
{
assertWriteEnabled();
if (bApply && ( fabs(x-m_dSizeX)>1.0E-3 || fabs(y-m_dSizeY)>1.0E-3 ||
fabs(z-m_dSizeZ)>1.0E-3) ) {
ads_matrix mat;
double dScaleX = fabs(m_dSizeX)>1.0E-3 ? x/m_dSizeX : 1;
double dScaleY = fabs(m_dSizeY)>1.0E-3 ? y/m_dSizeY : 1;
double dScaleZ = fabs(m_dSizeZ)>1.0E-3 ? z/m_dSizeZ : 1;
m_ptLocation.GetScaleMatrix(dScaleX, dScaleY, dScaleZ, mat);
for (int i=0; i<m_lstInterface.Length(); i++)
{
TPipeInterface &iFace = *m_lstInterface[i];
iFace.m_ptLocation.TransformBy(mat);
}
// m_ptLabel.TransformBy(mat);
m_ptLabelOut.TransformBy(mat);
}
m_dSizeX = x;
m_dSizeY = y;
m_dSizeZ = z;
}
void THDbEquipment::SetDirection(const XVector3D &vt, BOOL bApply)
{
assertWriteEnabled();
double dAngle = ads_angle(XPoint(),vt);
if (bApply && fabs(dAngle-GetAngle())>1.0E-3) {
ads_matrix mat;
dAngle -= GetAngle();
m_ptLocation.GetRotationMatrix(dAngle, mat);
for (int i=0; i<m_lstInterface.Length(); i++)
{
TPipeInterface &iFace = *m_lstInterface[i];
iFace.m_ptLocation.TransformBy(mat);
((AcGeVector3d &)iFace.m_vtLocation).rotateBy(dAngle, AcGeVector3d(0,0,1));
}
m_ptLabelOut.TransformBy(mat);
m_ptLabel.TransformBy(mat);
}
m_vtDirection = vt;
}
void InitHDbEquipment(BOOL bTrue)
{
if (bTrue) {
THDbEquipment::rxInit();
THDbEquipment::InitMatchProtocol(TRUE);
}
else {
THDbEquipment::InitMatchProtocol(FALSE);
deleteAcRxClass(THDbEquipment::desc());
}
}