943 lines
25 KiB
C++
943 lines
25 KiB
C++
#include "stdafx.h"
|
|
#include "dbobjptr.h"
|
|
#include "AcDbObjectPtr.h"
|
|
#include "DbPipe.h"
|
|
#include "HDbEquipment.h"
|
|
#include "PipePrototype.h"
|
|
#include "AecDbMText.h"
|
|
#include "globalFunc.h"
|
|
#include "globaldefine.h"
|
|
|
|
namespace
|
|
{
|
|
|
|
}
|
|
|
|
ACRX_DXF_DEFINE_MEMBERS(CHDbEquipment, CDbPipeNode, AcDb::kDHL_CURRENT,
|
|
AcDb::kMReleaseCurrent, 1, AEC_ZT_HEQUIPMENT,
|
|
"ATS_HEQUIPMENT图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com");
|
|
|
|
const Adesk::UInt8 CHDbEquipment::g_nVersion = 1;
|
|
|
|
|
|
CHDbEquipment::CHDbEquipment():
|
|
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 CHDbEquipment::AddInterface(XString sName, const XPoint& ptLoc, const XVector3D& vt)
|
|
{
|
|
assertWriteEnabled();
|
|
for (int i=0; i<m_lstInterface.Length(); i++)
|
|
{
|
|
CPipeInterface &iFace = *m_lstInterface[i];
|
|
if (_tcsicmp(sName, iFace.m_sSysLabel) == 0)
|
|
return;
|
|
}
|
|
|
|
CPipeInterface iFace;
|
|
iFace.m_faceType = CPipeInterface::kBoundry;
|
|
iFace.m_sSysLabel = sName;
|
|
iFace.m_ptLocation = ptLoc;
|
|
iFace.m_vtLocation = vt;
|
|
CDbPipeNode::AddInterface(iFace);
|
|
}
|
|
|
|
CPipeInterface* CHDbEquipment::FindInterface(XString sName)
|
|
{
|
|
for (int i=0; i<m_lstInterface.Length(); i++)
|
|
{
|
|
CPipeInterface *pFace = m_lstInterface[i];
|
|
if (_tcsicmp(sName, pFace->m_sSysLabel) == 0)
|
|
return pFace;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
BOOL CHDbEquipment::RemoveInterface(XString sName)
|
|
{
|
|
for (int i=0; i<m_lstInterface.Length(); i++)
|
|
{
|
|
CPipeInterface *pFace = m_lstInterface[i];
|
|
if (_tcsicmp(sName, pFace->m_sSysLabel) == 0) {
|
|
m_lstInterface.Remove();
|
|
return TRUE;
|
|
}
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
void CHDbEquipment::CopyPropertiesFrom(AcDbEntity *pSrc, unsigned gMatchFlag)
|
|
{
|
|
assertWriteEnabled();
|
|
CDbPipeNode::CopyPropertiesFrom(pSrc, gMatchFlag);
|
|
CLabelStyle::CopyPropertiesFrom(pSrc, gMatchFlag);
|
|
CHDbEquipment *pEqu = CHDbEquipment::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 CHDbEquipment::subGetClassID(CLSID* pClsid) const
|
|
//{
|
|
// return Acad::eOk;
|
|
//}
|
|
|
|
Acad::ErrorStatus
|
|
CHDbEquipment::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 = CDbPipeNode::subGetOsnapPoints(osnapMode, gsSelectionMark, ptPick, lastPoint,
|
|
viewXform, snapPoints, geomIds);
|
|
return es;
|
|
}
|
|
|
|
// 从DWG读入数据:
|
|
Acad::ErrorStatus CHDbEquipment::dwgInFields(AcDbDwgFiler* pFiler)
|
|
{
|
|
assertWriteEnabled();
|
|
|
|
Acad::ErrorStatus es = CDbPipeNode::dwgInFields(pFiler);
|
|
if (es != Acad::eOk)
|
|
return es;
|
|
es = CLabelStyle::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);
|
|
GlobalFunc::ReadString(pFiler, m_sLabel);
|
|
//pFiler->readItem(&m_bDrawLabel);
|
|
GlobalFunc::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 CHDbEquipment::dwgOutFields(AcDbDwgFiler* pFiler) const
|
|
{
|
|
assertReadEnabled();
|
|
Acad::ErrorStatus es = CDbPipeNode::dwgOutFields(pFiler);
|
|
if (es != Acad::eOk)
|
|
return es;
|
|
es = CLabelStyle::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);
|
|
GlobalFunc::FilerWrite(pFiler, m_bDrawLabel);
|
|
pFiler->writeItem(m_dSysAngle);
|
|
pFiler->writeItem((Adesk::UInt8)m_modelType);
|
|
return pFiler->filerStatus();
|
|
}
|
|
|
|
Acad::ErrorStatus CHDbEquipment::dxfInFields(AcDbDxfFiler* pFiler)
|
|
{
|
|
assertWriteEnabled();
|
|
Acad::ErrorStatus es = Acad::eOk;
|
|
es = CDbPipeNode::dxfInFields(pFiler);
|
|
if (es != Acad::eOk)
|
|
return es;
|
|
es = CLabelStyle::dxfInFields(pFiler);
|
|
if (es != Acad::eOk)
|
|
return es;
|
|
|
|
if (!pFiler->atSubclassData(_T("CHDbEquipment"))) {
|
|
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 CHDbEquipment::dxfOutFields(AcDbDxfFiler* pFiler) const
|
|
{
|
|
Acad::ErrorStatus es = Acad::eOk;
|
|
es = CDbPipeNode::dxfOutFields(pFiler);
|
|
assert(es == Acad::eOk);
|
|
es = CLabelStyle::dxfOutFields(pFiler);
|
|
assert(es == Acad::eOk);
|
|
es = pFiler->writeItem(AcDb::kDxfSubclass, _T("CHDbEquipment"));
|
|
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;
|
|
GlobalFunc::GetBlkNameById(m_idBlock2d, sBlkName, sDesName);
|
|
pFiler->writeString(AcDb::kDxfXTextString, (const TCHAR*)sBlkName);
|
|
return es;
|
|
}
|
|
|
|
AcGeScale3d CHDbEquipment::GetInsert2dScale() const
|
|
{
|
|
assertReadEnabled();
|
|
AcGeScale3d scale(1);
|
|
|
|
double x = 0, y = 0;
|
|
GlobalFunc::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 CHDbEquipment::GetInsert3dScale() const
|
|
{
|
|
assertReadEnabled();
|
|
AcGeScale3d scale(1);
|
|
double x=0,y=0,z=0;
|
|
// GetInsertExtend(m_idBlock2d,x,y,z); // mcl modify
|
|
GlobalFunc::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 CHDbEquipment::Draw2d(AcGiDraw &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 CHDbEquipment:: _ExplodeOrDraw2d(AcGiDraw &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 CPipeInterface &iFace=m_lstInterface[i];
|
|
if(!iFace.m_idPipe.isValid()) {
|
|
XPoint ptDir=iFace.m_ptLocation+iFace.m_vtLocation;
|
|
DrawLine(dc, XLine(iFace.m_ptLocation,ptDir));
|
|
//dc << XLine(iFace.m_ptLocation,ptDir);
|
|
}
|
|
}
|
|
|
|
if(m_bDrawLabel) // 绘制标注
|
|
DrawLabelText(dc);
|
|
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus CHDbEquipment::DrawSystem(AcGiDraw &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;
|
|
DrawLine(dc, XLine(*poly1[i],*poly2[i]));
|
|
//dc << XLine(*poly1[i],*poly2[i]);
|
|
}
|
|
DrawPoly2D(dc, poly1);
|
|
DrawPoly2D(dc, poly2);
|
|
//dc << poly1 << poly2;
|
|
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus CHDbEquipment::DrawLabelText(AcGiDraw &dc) const
|
|
{
|
|
AcDbObjectId idLayerOld=dc.GetLayerId();
|
|
if(m_idLabelLayer.isValid())
|
|
dc.SetLayer(m_idLabelLayer);
|
|
|
|
AecXDbMText text;
|
|
text.setPropertiesFrom(this);
|
|
text.setLayer(m_idLabelLayer);
|
|
text.SetStyleId(m_idTextStyle);
|
|
text.SetText((const TCHAR*)m_sLabel);
|
|
text.SetHeight(m_dTextHeight);
|
|
text.SetAlignment(AcGiDraw::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);
|
|
DrawLine(dc, XLine(ptLabel,ptLabel2));
|
|
DrawLine(dc, XLine(ptLabel,ptLabelOut));
|
|
//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 CHDbEquipment::Draw3d(AcGiDraw &dc) const
|
|
{
|
|
if (IsSysType())
|
|
return DrawSystem(dc, FALSE);
|
|
|
|
if (!m_idBlock3d.isValid())
|
|
return _ExplodeOrDraw2d(dc, FALSE);
|
|
|
|
AcGeScale3d scale = GetInsert3dScale();
|
|
XVector3D vtNormal(0, 0, 1);
|
|
if (fabs(m_vtDirection.z) > 1.0E-6)
|
|
{ // 非水平面,计算法向
|
|
vtNormal = GlobalFunc::operator*(XVector3D(1, 0, 0), m_vtDirection);
|
|
//vtNormal = XVector3D(1, 0, 0)*m_vtDirection;
|
|
vtNormal.Normalize();
|
|
}
|
|
XPoint ptLoc = GlobalFunc::Wcs2Ecs(m_ptLocation, vtNormal);
|
|
double nRotEcs = ads_angle(XPoint(),m_vtDirection); // 计算ECS下的转角
|
|
DrawBlock(dc, m_idBlock3d, ptLoc, scale, nRotEcs);
|
|
|
|
//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 = GlobalFunc::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 CPipeInterface &iFace = m_lstInterface[i];
|
|
if (!iFace.m_idPipe.isValid()) {
|
|
XPoint ptDir = iFace.m_ptLocation + iFace.m_vtLocation;
|
|
DrawLine(dc, XLine(iFace.m_ptLocation, ptDir));
|
|
//dc << XLine(iFace.m_ptLocation, ptDir);
|
|
}
|
|
}
|
|
return Acad::eOk;
|
|
}
|
|
|
|
void CHDbEquipment::GetTips(DList<ObjInfoUnit> &info) const
|
|
{
|
|
CString sBlkName,sDesName;
|
|
if(GlobalFunc::GetBlkNameById(m_idBlock2d,sBlkName,sDesName) && !sDesName.IsEmpty()) {
|
|
info.Append(new ObjInfoUnit(_T("对象名称"), (const TCHAR*)sDesName));
|
|
}
|
|
if(m_modelType==TPipeSys::kModel) {
|
|
for(int i=0; i<m_lstInterface.Length(); i++) {
|
|
const CPipeInterface& 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 ObjInfoUnit((const TCHAR*)sLabel,_T("完成")));
|
|
else
|
|
info.Append(new ObjInfoUnit((const TCHAR*)sLabel,_T("未连")));
|
|
}
|
|
}
|
|
}
|
|
|
|
int CHDbEquipment::GetGripNumber() const
|
|
{
|
|
int nNodeGrip=CDbPipeNode::GetGripNumber();
|
|
if(!m_bDrawLabel || m_ptLocation==m_ptLabel)
|
|
return nNodeGrip+1;
|
|
if(IsOutLabel() && m_ptLocation!=m_ptLabelOut)
|
|
return nNodeGrip+3;
|
|
return nNodeGrip+2;
|
|
}
|
|
|
|
int CHDbEquipment::GetStretchNumber() const
|
|
{
|
|
return GetGripNumber();
|
|
}
|
|
|
|
Acad::ErrorStatus CHDbEquipment::GetGripText(int idx, CString &cs) const
|
|
{
|
|
Acad::ErrorStatus es=Acad::eOk;
|
|
//es=CDbPipeNode::GetGripText(idx,cs);
|
|
//if(es!=Acad::eOk) return es;
|
|
if(idx>=0 && idx<m_lstInterface.Length()) {
|
|
const CPipeInterface& iFace=m_lstInterface[idx];
|
|
CString csLabel = (LPCTSTR)TString(iFace.m_sSysLabel); // sg modify
|
|
cs = _T("移动") + csLabel;
|
|
}
|
|
|
|
int nNodeGrip=CDbPipeNode::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
|
|
CHDbEquipment::subGetGripPoints(AcGePoint3dArray& gripPoints,
|
|
AcDbIntArray& osnapModes,
|
|
AcDbIntArray& geomIds) const
|
|
{
|
|
assertReadEnabled();
|
|
Acad::ErrorStatus es=Acad::eOk;
|
|
es=CDbPipeNode::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
|
|
CHDbEquipment::subGetStretchPoints(AcGePoint3dArray & stretchPoints) const
|
|
{
|
|
assertReadEnabled();
|
|
Acad::ErrorStatus es=Acad::eOk;
|
|
es=CDbPipeNode::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
|
|
CHDbEquipment::subMoveGripPointsAt(const AcDbIntArray& indices,
|
|
const AcGeVector3d& offset)
|
|
{
|
|
assertWriteEnabled();
|
|
Acad::ErrorStatus es=Acad::eOk;
|
|
es = CDbPipeNode::subMoveGripPointsAt(indices,offset);
|
|
if (es != Acad::eOk)
|
|
return es;
|
|
es = MoveGSPointsAt(indices, offset);
|
|
return es;
|
|
}
|
|
|
|
Acad::ErrorStatus CHDbEquipment::subMoveStretchPointsAt(const AcDbIntArray& indices,
|
|
const AcGeVector3d& offset)
|
|
{
|
|
assertWriteEnabled();
|
|
Acad::ErrorStatus es = Acad::eOk;
|
|
|
|
BOOL bNode = TRUE;
|
|
int nStretch = CDbPipeNode::GetStretchNumber();
|
|
int nCount = indices.length();
|
|
for (int i=0; i<nCount; i++)
|
|
{
|
|
if (indices[i]==nStretch) {
|
|
bNode = FALSE;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if(bNode)
|
|
es=CDbPipeNode::subMoveStretchPointsAt(indices,offset);
|
|
if(es!=Acad::eOk)
|
|
return es;
|
|
|
|
es=MoveGSPointsAt(indices,offset);
|
|
return es;
|
|
}
|
|
|
|
Acad::ErrorStatus
|
|
CHDbEquipment::MoveGSPointsAt(const AcDbIntArray& indices,
|
|
const AcGeVector3d& offset)
|
|
{
|
|
AcGeMatrix3d mat;
|
|
mat.setToTranslation(offset);
|
|
BOOL bOutLabel=IsOutLabel();
|
|
int nNodeGrip=CDbPipeNode::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++) {
|
|
CPipeInterface &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
|
|
CHDbEquipment::subTransformBy(const AcGeMatrix3d& xform)
|
|
{
|
|
assertWriteEnabled();
|
|
CDbPipeNode::subTransformBy(xform);
|
|
CLabelStyle::subTransformBy(xform);
|
|
m_ptLocation.TransformBy(xform);
|
|
m_ptLabel.TransformBy(xform);
|
|
m_ptLabelOut.TransformBy(xform);
|
|
((AcGeVector3d &)m_vtDirection).transformBy(xform);
|
|
GlobalFunc::ScaleTransform(xform,m_dSizeX);
|
|
GlobalFunc::ScaleTransform(xform,m_dSizeY);
|
|
GlobalFunc::ScaleTransform(xform,m_dSizeZ);
|
|
|
|
if (GlobalFunc::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 CHDbEquipment::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++)
|
|
{
|
|
CPipeInterface &iFace = *m_lstInterface[i];
|
|
XPoint &ptLocation = iFace.m_ptLocation;
|
|
XVector3D &vtLocation = iFace.m_vtLocation;
|
|
((AcGePoint3d &)ptLocation).mirror(plane);
|
|
((AcGeVector3d &)vtLocation).mirror(vt);
|
|
}
|
|
}
|
|
|
|
void CHDbEquipment::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++)
|
|
{
|
|
CPipeInterface &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 CHDbEquipment::GetExtents(XPoint &ptLow, XPoint &ptUp) const
|
|
{
|
|
Acad::ErrorStatus es=Acad::eOk;
|
|
es = CDbPipeNode::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 CHDbEquipment::CanLinkSide(const AcDbObjectId &idPipe, int nPos) const
|
|
{
|
|
BOOL bRet = FALSE;
|
|
OPENOBJ_BEGIN(idPipe, AcDb::kForRead, CDbPipePrototype, 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 CPipeInterface &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 CHDbEquipment::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++)
|
|
{
|
|
CPipeInterface &iFace = *m_lstInterface[i];
|
|
|
|
// 验证原有的管段
|
|
OPENOBJ_BEGIN(iFace.m_idPipe, AcDb::kForRead, CDbPipePrototype, 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, CDbPipePrototype, 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 CHDbEquipment::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++)
|
|
{
|
|
CPipeInterface &iFace = *m_lstInterface[i];
|
|
if (iFace.m_ptLocation != XPoint()) {
|
|
iFace.m_ptLocation.TransformBy(mat);
|
|
}
|
|
}
|
|
m_ptLocation = pt;
|
|
}
|
|
|
|
void CHDbEquipment::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++)
|
|
{
|
|
CPipeInterface &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 CHDbEquipment::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++)
|
|
{
|
|
CPipeInterface &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) {
|
|
//CHDbEquipment::rxInit();
|
|
//CHDbEquipment::InitMatchProtocol(TRUE);
|
|
}
|
|
else {
|
|
//CHDbEquipment::InitMatchProtocol(FALSE);
|
|
//deleteAcRxClass(CHDbEquipment::desc());
|
|
}
|
|
}
|