Files
gjm 164968b62e chore
把非utf8-bom编码的cpp/h文件改为 utf8 bom 编码, msvc识别utf8编码时,如果不是bom格式的,会使用当前cp_oem来解码.
2026-10-04 00:04:20 +08:00

1748 lines
41 KiB
C++

#include "stdafx.h"
#include "TImpSpecEquipment.h"
#include "TDbInterfaceRecord.h"
#include "TDbXDataMap.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
TImpSpecEquipment::TImpSpecEquipment()
{
m_pXDataMap = NULL;
m_pOwnerEnt = NULL;
}
TImpSpecEquipment::~TImpSpecEquipment()
{
}
void TImpSpecEquipment::Destroy()
{
delete this;
}
void TImpSpecEquipment::SetData(const TDbXDataMap* pMap)
{
m_pXDataMap->CopyFrom(pMap);
}
BOOL TImpSpecEquipment::GetInterface(int nIndex,TInterface& pipeInterface) const
{
CString sIntf;
int nPos = 0,nCount = 0;
AcGeMatrix3d xform;
xform.setToIdentity();
if (m_pXDataMap != NULL)
{
m_pXDataMap->GetAt(KEY_XFORM,xform);
}
while(TRUE)
{
if (m_pXDataMap != NULL && m_pXDataMap->GetAt(KEY_INTF,nIndex,sIntf))
{
nCount += 1;
}
else
{
break;
}
if (nPos == nIndex)
{
//解析
//接口定义 (vt),(pt),(Descr),L(D),W,nType
// (10,10,10),(200,200,200),("xxxx"),50,0,0 //圆接口
CString sScript;
m_pXDataMap->GetAt(KEY_INTF,nPos,sScript);
int nIndex = sScript.Find(_T(')'),0);
int nIndex1 = sScript.Find(_T('('),0);
if (nIndex1 == 0 && nIndex != -1)
{
CString sDir = sScript.Mid(nIndex1 + 1,nIndex - nIndex1 - 1);
AcGeVector3d vtDir;
if (!StringToAcGeVector3d(sDir,vtDir))
{
return FALSE;
}
nIndex = sScript.Find(_T('('),nIndex);
if (nIndex == -1) return FALSE;
nIndex1 = sScript.Find(_T(')'),nIndex);
CString sPt;
AcGePoint3d ptGe;
if (nIndex != -1 && nIndex1 != -1)
{
sPt = sScript.Mid(nIndex + 1,nIndex1 - nIndex - 1);
}
else
{
return FALSE;
}
StringToAcGePoint3d(sPt,ptGe);
ptGe.transformBy(xform);
vtDir.transformBy(xform);
pipeInterface.SetPosition(ptGe);
pipeInterface.SetOutDir(vtDir);
nIndex = sScript.Find(_T('('),nIndex1);
nIndex1 = sScript.Find(_T(')'),nIndex);
if (nIndex == -1 || nIndex1 == -1)
return FALSE;
CString sDescr = sScript.Mid(nIndex + 1,nIndex1 - nIndex - 1);
pipeInterface.SetDescr(sDescr);
CString sSize = sScript.Mid(nIndex1 + 1);
sSize.TrimLeft(_T(','));
CStringArray arSize;
Script2StringArray(sSize,_T(','),arSize);
if (arSize.GetSize() == 3)
{
double dSize = _ttof(arSize.GetAt(0));
double dSize1 = _ttof(arSize.GetAt(1));
pipeInterface.SetSize(dSize,dSize1);
short nType = _ttoi(arSize.GetAt(2));
pipeInterface.SetType(nType);
}
return TRUE;
}
break;
}
nIndex += 1;
}
return FALSE;
}
BOOL TImpSpecEquipment::GetInterface(const AcGePoint3d& ptCon,TInterface& pipeInterface) const
{
TInterface intf;
int nCount = GetInterfaceCount();
for (int i = 0;i < nCount;i++)
{
GetInterface(i,intf);
if (intf.GetPosition().distanceTo(ptCon) < 1.e-3)
{
return TRUE;
}
}
return FALSE;
}
BOOL TImpSpecEquipment::HasInterface(const AcGePoint3d& ptCon,const AcGeVector3d& vtDir)
{
TInterface intf;
if (GetInterface(ptCon,intf))
{
if (vtDir.isParallelTo(intf.GetOutDir()))
{
return TRUE;
}
}
return FALSE;
}
int TImpSpecEquipment::GetInterfaceCount() const
{
CString sIntf;
int nIndex = 0,nCount = 0;
while(TRUE)
{
if (m_pXDataMap != NULL && m_pXDataMap->GetAt(KEY_INTF,nIndex,sIntf))
{
nCount += 1;
}
else
{
break;
}
nIndex += 1;
}
return nCount;
}
BOOL TImpSpecEquipment::SetInterfaceRelation(const AcGePoint3d& ptConnect,const AcDbObjectId& idConnect)
{
return FALSE;
}
BOOL TImpSpecEquipment::RemoveInterfaceRelation(const AcGePoint3d& ptConnect,const AcDbObjectId& idConnect)
{
return FALSE;
}
BOOL TImpSpecEquipment::NotifyInterfaceToModify(const TInterfaceModifyMsg& iModiMsg,TInterfaceModifyMsgs& iModiMsgs)
{
return FALSE;
}
TDbXDataMap* TImpSpecEquipment::GetSpecialtyData()
{
return m_pXDataMap;
}
Acad::ErrorStatus TImpSpecEquipment::setNormal(const AcGeVector3d& vtNorm)
{
return Acad::eOk;
}
Acad::ErrorStatus TImpSpecEquipment::copyFrom(const TImpSpecEquipment* pSrc)
{
m_pXDataMap->CopyFrom(pSrc->m_pXDataMap);
return Acad::eOk;
}
AcGeVector3d TImpSpecEquipment::normal() const
{
AcGeVector3d vt = AcGeVector3d::kZAxis;
if (m_pXDataMap != NULL)
{
m_pXDataMap->GetAt(KEY_NORMAL,vt);
}
return vt;
}
BOOL TImpSpecEquipment::MakeCurves(TComplexCurve& cplCurve) const
{
return FALSE;
}
BOOL TImpSpecEquipment::GetCurvesInSide(TComplexCurve& compCurve) const
{
return FALSE;
}
AcDbPolyline* TImpSpecEquipment::MakePolyCurve() const
{
return NULL;
}
BOOL TImpSpecEquipment::MakePolyCurveFaces(AcDbVoidPtrArray& arFaces)
{
return FALSE;
}
void TImpSpecEquipment::GetKindName(CString& sName)
{
sName = _T("TCH_sEEQUIPMENT");
}
BOOL TImpSpecEquipment::GetGeomExtentsEdge(TComplexCurve& crLoop)
{
return FALSE;
}
TDb::Position TImpSpecEquipment::ExplainGripIndex(int nIndex) const
{
return TDb::eStart;
}
Acad::ErrorStatus TImpSpecEquipment::GetGripText(int i, CString &cs) const
{
return Acad::eOk;
}
void TImpSpecEquipment::GetTips(CMapStringToString& mapLable2Tip) const
{
}
Acad::ErrorStatus TImpSpecEquipment::ExplodeOrDraw3d(XExplodeDraw &mode) const
{
if (m_pXDataMap == NULL) return Acad::eOk;
//1.获取基本放置信息
AcGeMatrix3d xform;
m_pXDataMap->GetAt(KEY_XFORM,xform);
CString sScript;
int nIndex = 0,nGsMark = 1;
TDbXDataMap xDataMap;
while(TRUE)
{
xDataMap.Empty();
if (m_pXDataMap->GetAt(KEY_BODY,nIndex,xDataMap))
{
//长方体 面 L x W x H + 中心点pt + entry[4] 坐标系
if (xDataMap.GetAt(KEY_BOX,sScript))
{
ExplodeOrDraw3d_Box(sScript,xform,mode,nGsMark);
}
//圆锥体 面 R x h + 中心点pt + entry[4] 坐标系
if (xDataMap.GetAt(KEY_CONE,sScript))
{
ExplodeOrDraw3d_Cone(sScript,xform,mode,nGsMark);
}
//圆台 R x r x h + 中心点pt + entry[4] 坐标系
if (xDataMap.GetAt(KEY_ECONE,sScript))
{
ExplodeOrDraw3d_ECone(sScript,xform,mode,nGsMark);
}
//圆柱面 r x h + 中心点pt + entry[4] 坐标系
if (xDataMap.GetAt(KEY_CYLN,sScript))
{
ExplodeOrDraw3d_Cyln(sScript,xform,mode,nGsMark);
}
//四边形台柱 L1,W1 L2,W2, H + 中心点pt + entry[4] 坐标系
if (xDataMap.GetAt(KEY_DUCTR,sScript))
{
ExplodeOrDraw3d_Ductr(sScript,xform,mode,nGsMark);
}
//半椭球封头 R,r (r=h),+ 中心点pt + entry[4] 坐标系
if (xDataMap.GetAt(KEY_HELB,sScript))//半椭球封头
{
ExplodeOrDraw3d_Helb(sScript,xform,mode,nGsMark);
}
//半球体面 R,+ 中心点pt + entry[4] 坐标系
if (xDataMap.GetAt(KEY_HESP,sScript))//半球体面
{
ExplodeOrDraw3d_Hesp(sScript,xform,mode,nGsMark);
}
nGsMark += 1;
}
else
{
break;
}
nIndex += 1;
}
return Acad::eOk;
}
BOOL TImpSpecEquipment::StringToAcGeVector3d(CString& sText,AcGeVector3d& vt) const
{
//x,y,z
AcGePoint3d ptGe;
if (StringToAcGePoint3d(sText,ptGe))
{
vt = ptGe.asVector();
return TRUE;
}
return FALSE;
}
BOOL TImpSpecEquipment::StringToAcGePoint3d(CString& sText,AcGePoint3d& ptGe) const
{
//x,y,z
CString sX,sY,sZ;
int nFr = sText.Find(_T(","),0);
if (nFr != -1)
{
CString sTemp;
sX = sText.Mid(0,nFr);
if (nFr + 1 < sText.GetLength())
{
sTemp = sText.Mid(nFr + 1);
sText = sTemp;
nFr = sText.Find(_T(","),0);
if (nFr != -1)
{
sY = sText.Mid(0,nFr);
if (nFr + 1 < sText.GetLength())
{
sZ = sText.Mid(nFr + 1);
ptGe.set(_ttof(sX),_ttof(sY),_ttof(sZ));
return TRUE;
}
}
}
}
return FALSE;
}
BOOL TImpSpecEquipment::Script2StringArray(const CString& sScript,TCHAR tSpace,CStringArray& arTexts) const
{
//x,y,z,d,a
int nPos = -1,nStart = 0;
CString sText;
while(TRUE)
{
nPos = sScript.Find(tSpace,nStart);
if (nPos != -1)
{
sText = sScript.Mid(nStart,nPos - nStart);
arTexts.Add(sText);
nStart = nPos + 1;
}
else
{
if (nStart < sScript.GetLength())
{
sText = sScript.Mid(nStart);
arTexts.Add(sText);
break;
}
else
{
break;
}
}
}
return arTexts.GetSize() > 0;
}
BOOL TImpSpecEquipment::ExplodeOrDraw3d_Box(CString& sScript,const AcGeMatrix3d& xform,XExplodeDraw &mode,int nGsMark) const
{
//长方体 面 L x W x H ,中心点pt + 坐标系
//200,200,300,(10,10,12.5),(x,y,z),(x,y,z),(x,y,z)
int nIndex = sScript.Find(_T("("),0);
if (nIndex != -1)
{
//1. 尺寸
CString sLWH = sScript.Mid(0,nIndex);
sLWH.TrimRight(_T(","));
int nPos1 = sLWH.Find(_T(','),0);
int nPos2 = sLWH.ReverseFind(_T(','));
if (nPos1 == -1 || nPos2 == -1)
{
return FALSE;
}
CString sL,sW,sH;
sL = sLWH.Mid(0,nPos1);
sW = sLWH.Mid(nPos1 + 1,nPos2 - nPos1 - 1);
sH = sLWH.Mid(nPos2 + 1);
double dL = _ttof(sL);
double dW = _ttof(sW);
double dH = _ttof(sH);
//2.中心点
nPos2 = sScript.Find(_T(')'));
if (nPos2 == -1) return FALSE;
CString sPt = sScript.Mid(nIndex + 1,nPos2 - nIndex - 1);
AcGePoint3d ptGeCen;
if (!StringToAcGePoint3d(sPt,ptGeCen))
{
return FALSE;
}
//3.坐标系
//(x,y,z),(x,y,z),(x,y,z)
CString sCoord = sScript.Mid(nPos2 + 1);
sCoord.TrimLeft(_T('('));
sCoord.TrimRight(_T(')'));
sCoord.Replace(_T('('),_T(' '));
sCoord.Replace(_T(')'),_T(' '));
sCoord.TrimLeft();
sCoord.TrimRight();
sCoord.TrimLeft(_T(','));
CStringArray arTexts;
Script2StringArray(sCoord,_T(','),arTexts);
if (arTexts.GetSize() != 9)
return FALSE;
AcGeVector3d vtL,vtW,vtH;
vtL.set(_ttof(arTexts.GetAt(0)),_ttof(arTexts.GetAt(1)),_ttof(arTexts.GetAt(2)));
vtW.set(_ttof(arTexts.GetAt(3)),_ttof(arTexts.GetAt(4)),_ttof(arTexts.GetAt(5)));
vtH.set(_ttof(arTexts.GetAt(6)),_ttof(arTexts.GetAt(7)),_ttof(arTexts.GetAt(8)));
vtL.normalize();
vtW.normalize();
vtH.normalize();
//4.画BOX
AcGePoint3d ptGeFace[4];
//4.1 上
ptGeFace[0] = ptGeCen;
ptGeFace[0] += dH * vtH;
ptGeFace[0] += dL * 0.5 * vtL;
ptGeFace[0] -= dW * 0.5 * vtW;
ptGeFace[1] = ptGeFace[0] + dW * vtW;
ptGeFace[2] = ptGeFace[1] - dL * vtL;
ptGeFace[3] = ptGeFace[2] - dW * vtW;
//再变换到当前位置
AcDbFace face;
for (int i = 0;i < 4;i++)
{
ptGeFace[i].transformBy(xform);
face.setVertexAt(i,ptGeFace[i]);
}
mode.SetSelectionMarker(nGsMark);
mode.DrawEntity(face);
//4.2 下
ptGeFace[0] = ptGeCen;
ptGeFace[0] += dL * 0.5 * vtL;
ptGeFace[0] -= dW * 0.5 * vtW;
ptGeFace[1] = ptGeFace[0] + dW * vtW;
ptGeFace[2] = ptGeFace[1] - dL * vtL;
ptGeFace[3] = ptGeFace[2] - dW * vtW;
for (i = 0;i < 4;i++)
{
ptGeFace[i].transformBy(xform);
face.setVertexAt(i,ptGeFace[i]);
}
mode.SetSelectionMarker(nGsMark);
mode.DrawEntity(face);
//4.3 前
ptGeFace[0] = ptGeCen;
ptGeFace[0] += dW * 0.5 * vtW;
ptGeFace[0] += dH * vtH;
ptGeFace[0] += dL * 0.5 * vtL;
ptGeFace[1] = ptGeFace[0] - dH * vtH;
ptGeFace[2] = ptGeFace[1] - dL * vtL;
ptGeFace[3] = ptGeFace[2] + dH * vtH;
for (i = 0;i < 4;i++)
{
ptGeFace[i].transformBy(xform);
face.setVertexAt(i,ptGeFace[i]);
}
mode.SetSelectionMarker(nGsMark);
mode.DrawEntity(face);
//4.4 后
ptGeFace[0] = ptGeCen;
ptGeFace[0] -= dW * 0.5 * vtW;
ptGeFace[0] += dH * vtH;
ptGeFace[0] += dL * 0.5 * vtL;
ptGeFace[1] = ptGeFace[0] - dH * vtH;
ptGeFace[2] = ptGeFace[1] - dL * vtL;
ptGeFace[3] = ptGeFace[2] + dH * vtH;
for (i = 0;i < 4;i++)
{
ptGeFace[i].transformBy(xform);
face.setVertexAt(i,ptGeFace[i]);
}
mode.SetSelectionMarker(nGsMark);
mode.DrawEntity(face);
//4.5 右
ptGeFace[0] = ptGeCen;
ptGeFace[0] += dL * 0.5 * vtL;
ptGeFace[0] += dH * vtH;
ptGeFace[0] -= dW * 0.5 * vtW;
ptGeFace[1] = ptGeFace[0] - dH * vtH;
ptGeFace[2] = ptGeFace[1] + dW * vtW;
ptGeFace[3] = ptGeFace[2] + dH * vtH;
for (i = 0;i < 4;i++)
{
ptGeFace[i].transformBy(xform);
face.setVertexAt(i,ptGeFace[i]);
}
mode.SetSelectionMarker(nGsMark);
mode.DrawEntity(face);
//4.6 左
ptGeFace[0] = ptGeCen;
ptGeFace[0] -= dL * 0.5 * vtL;
ptGeFace[0] += dH * vtH;
ptGeFace[0] -= dW * 0.5 * vtW;
ptGeFace[1] = ptGeFace[0] - dH * vtH;
ptGeFace[2] = ptGeFace[1] + dW * vtW;
ptGeFace[3] = ptGeFace[2] + dH * vtH;
for (i = 0;i < 4;i++)
{
ptGeFace[i].transformBy(xform);
face.setVertexAt(i,ptGeFace[i]);
}
mode.SetSelectionMarker(nGsMark);
mode.DrawEntity(face);
return TRUE;
}
return FALSE;
}
BOOL TImpSpecEquipment::ExplodeOrDraw3d_Cone(CString& sScript,const AcGeMatrix3d& xform,XExplodeDraw &mode,int nGsMark) const
{
//圆锥体面 R,h,(中心点pt),(中心向量)
// 500,400,(10,10,10),(0,0,1)
int nIndex = sScript.Find(_T('('),0);
if (nIndex != -1)
{
CString sRh;
sRh = sScript.Mid(0,nIndex);
sRh.TrimRight(_T(','));
sRh.TrimLeft();
CStringArray arTexts;
Script2StringArray(sRh,_T(','),arTexts);
if (arTexts.GetSize() != 2)
return FALSE;
double dR = _ttof(arTexts.GetAt(0));
double dH = _ttof(arTexts.GetAt(1));
CString sPt;
int nPos2 = sScript.Find(_T(')'),0);
if (nPos2 != -1)
{
sPt = sScript.Mid(nIndex + 1,nPos2 - nIndex - 1);
AcGePoint3d ptGeCen;
if (!StringToAcGePoint3d(sPt,ptGeCen))
return FALSE;
CString sVt;
nIndex = sScript.Find(_T('('),nPos2 + 1);
sVt = sScript.Mid(nIndex);
sVt.TrimLeft(_T('('));
sVt.TrimRight(_T(')'));
AcGeVector3d vtH;
if (!StringToAcGeVector3d(sVt,vtH))
return FALSE;
vtH.normalize();
AcGePoint3d ptGe[3];
ptGe[0] = ptGeCen;
ptGe[1] = ptGeCen + dH * vtH;
AcGeVector3d vtX = vtH.perpVector();
vtX.normalize();
ptGe[2] = ptGeCen + dR * vtX;
AcDbCircle cir;
cir.setCenter(ptGeCen);
cir.setRadius(dR);
cir.setNormal(vtH);
AcGeCircArc3d geCir(ptGeCen,vtH,dR);
AcGePoint3dArray points;
points.setPhysicalLength(41);
geCir.getSamplePoints(41,points);
AcDbFace face;
for (int i = 0;i <= 38;i++)
{
face.setVertexAt(0,points.at(i));
face.setVertexAt(1,points.at(i + 1));
face.setVertexAt(2,ptGe[1]);
face.setVertexAt(3,points.at(i));
mode.SetSelectionMarker(nGsMark);
mode.DrawEntity(face);
face.setVertexAt(0,points.at(i));
face.setVertexAt(1,points.at(i + 1));
face.setVertexAt(2,ptGe[0]);
face.setVertexAt(3,points.at(i));
mode.SetSelectionMarker(nGsMark);
mode.DrawEntity(face);
if (i == 38)
{
face.setVertexAt(0,points.at(i));
face.setVertexAt(1,points.at(0));
face.setVertexAt(2,ptGe[1]);
face.setVertexAt(3,points.at(i));
mode.SetSelectionMarker(nGsMark);
mode.DrawEntity(face);
face.setVertexAt(0,points.at(i));
face.setVertexAt(1,points.at(0));
face.setVertexAt(2,ptGe[0]);
face.setVertexAt(3,points.at(i));
mode.SetSelectionMarker(nGsMark);
mode.DrawEntity(face);
break;
}
}
return TRUE;
}
}
return FALSE;
}
BOOL TImpSpecEquipment::ExplodeOrDraw3d_ECone(CString& sScript,const AcGeMatrix3d& xform,XExplodeDraw &mode,int nGsMark) const
{
//圆台 R,r,h,(中心点pt),(中心向量)
// 500,400,300,(10,10,10),(0,0,1)
int nIndex = sScript.Find(_T('('),0);
if (nIndex != -1)
{
CString sRh;
sRh = sScript.Mid(0,nIndex);
sRh.TrimRight(_T(','));
sRh.TrimLeft();
CStringArray arTexts;
Script2StringArray(sRh,_T(','),arTexts);
if (arTexts.GetSize() != 3)
return FALSE;
double dR = _ttof(arTexts.GetAt(0));
double dr = _ttof(arTexts.GetAt(1));
double dH = _ttof(arTexts.GetAt(2));
CString sPt;
int nPos2 = sScript.Find(_T(')'),0);
if (nPos2 != -1)
{
sPt = sScript.Mid(nIndex + 1,nPos2 - nIndex - 1);
AcGePoint3d ptGeCen;
if (!StringToAcGePoint3d(sPt,ptGeCen))
return FALSE;
CString sVt;
nIndex = sScript.Find(_T('('),nPos2 + 1);
sVt = sScript.Mid(nIndex);
sVt.TrimLeft(_T('('));
sVt.TrimRight(_T(')'));
AcGeVector3d vtH;
if (!StringToAcGeVector3d(sVt,vtH))
return FALSE;
vtH.normalize();
AcGePoint3d ptGe[2];
ptGe[0] = ptGeCen;
ptGe[1] = ptGeCen + dH * vtH;
AcDbCircle cir;
cir.setCenter(ptGeCen);
cir.setRadius(dR);
cir.setNormal(vtH);
AcGeCircArc3d geCirB(ptGeCen,vtH,dR);
AcGePoint3dArray pointsB;
pointsB.setPhysicalLength(41);
geCirB.getSamplePoints(41,pointsB);
AcGeCircArc3d geCirT(ptGe[1],vtH,dr);
AcGePoint3dArray pointsT;
pointsT.setPhysicalLength(41);
geCirT.getSamplePoints(41,pointsT);
AcDbFace face;
for (int i = 0;i <= 38;i++)
{
face.setVertexAt(0,pointsB.at(i));
face.setVertexAt(1,pointsB.at(i + 1));
face.setVertexAt(2,pointsT.at(i + 1));
face.setVertexAt(3,pointsT.at(i));
mode.SetSelectionMarker(nGsMark);
mode.DrawEntity(face);
face.setVertexAt(0,pointsB.at(i));
face.setVertexAt(1,pointsB.at(i + 1));
face.setVertexAt(2,ptGe[0]);
face.setVertexAt(3,pointsB.at(i));
mode.SetSelectionMarker(nGsMark);
mode.DrawEntity(face);
face.setVertexAt(0,pointsT.at(i));
face.setVertexAt(1,pointsT.at(i + 1));
face.setVertexAt(2,ptGe[1]);
face.setVertexAt(3,pointsT.at(i));
mode.SetSelectionMarker(nGsMark);
mode.DrawEntity(face);
if (i == 38)
{
face.setVertexAt(0,pointsB.at(i));
face.setVertexAt(1,pointsB.at(0));
face.setVertexAt(2,pointsT.at(0));
face.setVertexAt(3,pointsT.at(i));
mode.SetSelectionMarker(nGsMark);
mode.DrawEntity(face);
face.setVertexAt(0,pointsB.at(i));
face.setVertexAt(1,pointsB.at(0));
face.setVertexAt(2,ptGe[0]);
face.setVertexAt(3,pointsB.at(i));
mode.SetSelectionMarker(nGsMark);
mode.DrawEntity(face);
face.setVertexAt(0,pointsT.at(i));
face.setVertexAt(1,pointsT.at(0));
face.setVertexAt(2,ptGe[1]);
face.setVertexAt(3,pointsT.at(i));
mode.SetSelectionMarker(nGsMark);
mode.DrawEntity(face);
break;
}
}
return TRUE;
}
}
return FALSE;
}
BOOL TImpSpecEquipment::ExplodeOrDraw3d_Cyln(CString& sScript,const AcGeMatrix3d& xform,XExplodeDraw &mode,int nGsMark) const
{
//圆柱面 r,h,(中心点pt),(中心向量)
// 500,400,(10,10,10),(0,0,1)
int nIndex = sScript.Find(_T('('),0);
if (nIndex != -1)
{
CString sRh;
sRh = sScript.Mid(0,nIndex);
sRh.TrimRight(_T(','));
sRh.TrimLeft();
CStringArray arTexts;
Script2StringArray(sRh,_T(','),arTexts);
if (arTexts.GetSize() != 2)
return FALSE;
double dR = _ttof(arTexts.GetAt(0));
double dr = dR;
double dH = _ttof(arTexts.GetAt(1));
CString sPt;
int nPos2 = sScript.Find(_T(')'),0);
if (nPos2 != -1)
{
sPt = sScript.Mid(nIndex + 1,nPos2 - nIndex - 1);
AcGePoint3d ptGeCen;
if (!StringToAcGePoint3d(sPt,ptGeCen))
return FALSE;
CString sVt;
nIndex = sScript.Find(_T('('),nPos2 + 1);
sVt = sScript.Mid(nIndex);
sVt.TrimLeft(_T('('));
sVt.TrimRight(_T(')'));
AcGeVector3d vtH;
if (!StringToAcGeVector3d(sVt,vtH))
return FALSE;
vtH.normalize();
AcGePoint3d ptGe[2];
ptGe[0] = ptGeCen;
ptGe[1] = ptGeCen + dH * vtH;
AcDbCircle cir;
cir.setCenter(ptGeCen);
cir.setRadius(dR);
cir.setNormal(vtH);
AcGeCircArc3d geCirB(ptGeCen,vtH,dR);
AcGePoint3dArray pointsB;
pointsB.setPhysicalLength(41);
geCirB.getSamplePoints(41,pointsB);
AcGeCircArc3d geCirT(ptGe[1],vtH,dr);
AcGePoint3dArray pointsT;
pointsT.setPhysicalLength(41);
geCirT.getSamplePoints(41,pointsT);
AcDbFace face;
for (int i = 0;i <= 38;i++)
{
face.setVertexAt(0,pointsB.at(i));
face.setVertexAt(1,pointsB.at(i + 1));
face.setVertexAt(2,pointsT.at(i + 1));
face.setVertexAt(3,pointsT.at(i));
mode.SetSelectionMarker(nGsMark);
mode.DrawEntity(face);
face.setVertexAt(0,pointsB.at(i));
face.setVertexAt(1,pointsB.at(i + 1));
face.setVertexAt(2,ptGe[0]);
face.setVertexAt(3,pointsB.at(i));
mode.SetSelectionMarker(nGsMark);
mode.DrawEntity(face);
face.setVertexAt(0,pointsT.at(i));
face.setVertexAt(1,pointsT.at(i + 1));
face.setVertexAt(2,ptGe[1]);
face.setVertexAt(3,pointsT.at(i));
mode.SetSelectionMarker(nGsMark);
mode.DrawEntity(face);
if (i == 38)
{
face.setVertexAt(0,pointsB.at(i));
face.setVertexAt(1,pointsB.at(0));
face.setVertexAt(2,pointsT.at(0));
face.setVertexAt(3,pointsT.at(i));
mode.SetSelectionMarker(nGsMark);
mode.DrawEntity(face);
face.setVertexAt(0,pointsB.at(i));
face.setVertexAt(1,pointsB.at(0));
face.setVertexAt(2,ptGe[0]);
face.setVertexAt(3,pointsB.at(i));
mode.SetSelectionMarker(nGsMark);
mode.DrawEntity(face);
face.setVertexAt(0,pointsT.at(i));
face.setVertexAt(1,pointsT.at(0));
face.setVertexAt(2,ptGe[1]);
face.setVertexAt(3,pointsT.at(i));
mode.SetSelectionMarker(nGsMark);
mode.DrawEntity(face);
break;
}
}
return TRUE;
}
}
return FALSE;
}
BOOL TImpSpecEquipment::ExplodeOrDraw3d_Ductr(CString& sScript,const AcGeMatrix3d& xform,XExplodeDraw &mode,int nGsMark) const
{
//四边形台柱 L1,W1,L2,W2,H,(中心点pt),(x,y,z),(x,y,z),(x,y,z)坐标系
int nIndex = sScript.Find(_T('('),0);
if (nIndex != -1)
{
CString sSize = sScript.Mid(0,nIndex);
CStringArray arSizes;
Script2StringArray(sSize,_T(','),arSizes);
if (arSizes.GetSize() != 5)
{
return FALSE;
}
double dL1 = _ttof(arSizes.GetAt(0));
double dW1 = _ttof(arSizes.GetAt(1));
double dL2 = _ttof(arSizes.GetAt(2));
double dW2 = _ttof(arSizes.GetAt(3));
double dH = _ttof(arSizes.GetAt(4));
int nPos = sScript.Find(_T(')'),nIndex);
CString sText = sScript.Mid(nIndex + 1,nPos - nIndex -1);
AcGePoint3d ptGeCen;
if (!StringToAcGePoint3d(sText,ptGeCen))
return FALSE;
nIndex = sScript.Find(_T('('),nPos);
if (nIndex == -1) return FALSE;
CString sCoord = sScript.Mid(nIndex);
sCoord.TrimLeft(_T('('));
sCoord.TrimRight(_T(')'));
sCoord.Replace(_T('('),_T(' '));
sCoord.Replace(_T(')'),_T(' '));
sCoord.TrimLeft();
sCoord.TrimRight();
sCoord.TrimLeft(_T(','));
CStringArray arTexts;
Script2StringArray(sCoord,_T(','),arTexts);
if (arTexts.GetSize() != 9)
return FALSE;
AcGeVector3d vtL,vtW,vtH;
vtL.set(_ttof(arTexts.GetAt(0)),_ttof(arTexts.GetAt(1)),_ttof(arTexts.GetAt(2)));
vtW.set(_ttof(arTexts.GetAt(3)),_ttof(arTexts.GetAt(4)),_ttof(arTexts.GetAt(5)));
vtH.set(_ttof(arTexts.GetAt(6)),_ttof(arTexts.GetAt(7)),_ttof(arTexts.GetAt(8)));
vtL.normalize();
vtW.normalize();
vtH.normalize();
//4.画BOX
AcGePoint3d ptGeFace[4];
//4.1 上
ptGeFace[0] = ptGeCen;
ptGeFace[0] += dH * vtH;
ptGeFace[0] += dL2 * 0.5 * vtL;
ptGeFace[0] -= dW2 * 0.5 * vtW;
ptGeFace[1] = ptGeFace[0] + dW2 * vtW;
ptGeFace[2] = ptGeFace[1] - dL2 * vtL;
ptGeFace[3] = ptGeFace[2] - dW2 * vtW;
//再变换到当前位置
AcDbFace face;
for (int i = 0;i < 4;i++)
{
ptGeFace[i].transformBy(xform);
face.setVertexAt(i,ptGeFace[i]);
}
mode.SetSelectionMarker(nGsMark);
mode.DrawEntity(face);
//4.2 下
ptGeFace[0] = ptGeCen;
ptGeFace[0] += dL1 * 0.5 * vtL;
ptGeFace[0] -= dW1 * 0.5 * vtW;
ptGeFace[1] = ptGeFace[0] + dW1 * vtW;
ptGeFace[2] = ptGeFace[1] - dL1 * vtL;
ptGeFace[3] = ptGeFace[2] - dW1 * vtW;
for (i = 0;i < 4;i++)
{
ptGeFace[i].transformBy(xform);
face.setVertexAt(i,ptGeFace[i]);
}
mode.SetSelectionMarker(nGsMark);
mode.DrawEntity(face);
//4.3 左
ptGeFace[0] = ptGeCen;
ptGeFace[0] += dH * vtH;
ptGeFace[0] += dW2 * 0.5 * vtW;
ptGeFace[0] += dL2 * 0.5 * vtL;
ptGeFace[1] = ptGeFace[0] - dW2 * vtW;
ptGeFace[2] = ptGeCen;
ptGeFace[2] += dL1 * 0.5 * vtL;
ptGeFace[2] -= dW1 * 0.5 * vtW;
ptGeFace[3] = ptGeFace[2] + dW1 * vtW;
for (i = 0;i < 4;i++)
{
ptGeFace[i].transformBy(xform);
face.setVertexAt(i,ptGeFace[i]);
}
mode.SetSelectionMarker(nGsMark);
mode.DrawEntity(face);
//4.4 右
ptGeFace[0] = ptGeCen;
ptGeFace[0] += dH * vtH;
ptGeFace[0] += dW2 * 0.5 * vtW;
ptGeFace[0] -= dL2 * 0.5 * vtL;
ptGeFace[1] = ptGeFace[0] - dW2 * vtW;
ptGeFace[2] = ptGeCen;
ptGeFace[2] -= dL1 * 0.5 * vtL;
ptGeFace[2] -= dW1 * 0.5 * vtW;
ptGeFace[3] = ptGeFace[2] + dW1 * vtW;
for (i = 0;i < 4;i++)
{
ptGeFace[i].transformBy(xform);
face.setVertexAt(i,ptGeFace[i]);
}
mode.SetSelectionMarker(nGsMark);
mode.DrawEntity(face);
//4.5 前
ptGeFace[0] = ptGeCen;
ptGeFace[0] += dH * vtH;
ptGeFace[0] += dW2 * 0.5 * vtW;
ptGeFace[0] -= dL2 * 0.5 * vtL;
ptGeFace[1] = ptGeFace[0] + dL2 * vtL;
ptGeFace[2] = ptGeCen;
ptGeFace[2] += dW1 * 0.5 * vtW;
ptGeFace[2] += dL1 * 0.5 * vtL;
ptGeFace[3] = ptGeFace[2] - dL1 * vtL;
for (i = 0;i < 4;i++)
{
ptGeFace[i].transformBy(xform);
face.setVertexAt(i,ptGeFace[i]);
}
mode.SetSelectionMarker(nGsMark);
mode.DrawEntity(face);
//4.6 后
ptGeFace[0] = ptGeCen;
ptGeFace[0] += dH * vtH;
ptGeFace[0] -= dW2 * 0.5 * vtW;
ptGeFace[0] -= dL2 * 0.5 * vtL;
ptGeFace[1] = ptGeFace[0] + dL2 * vtL;
ptGeFace[2] = ptGeCen;
ptGeFace[2] -= dW1 * 0.5 * vtW;
ptGeFace[2] += dL1 * 0.5 * vtL;
ptGeFace[3] = ptGeFace[2] - dL1 * vtL;
for (i = 0;i < 4;i++)
{
ptGeFace[i].transformBy(xform);
face.setVertexAt(i,ptGeFace[i]);
}
mode.SetSelectionMarker(nGsMark);
mode.DrawEntity(face);
return TRUE;
}
return FALSE;
}
BOOL TImpSpecEquipment::ExplodeOrDraw3d_Helb(CString& sScript,const AcGeMatrix3d& xform,XExplodeDraw &mode,int nGsMark) const
{
//半椭球封头 R,h,(中心点pt),(中心向量)
//500,300,(10,10,10),(0,0,1)
int nIndex = sScript.Find(_T('('),0);
if (nIndex != -1)
{
CString sRh = sScript.Mid(0,nIndex - 1);
CStringArray arRh;
Script2StringArray(sRh,_T(','),arRh);
if (arRh.GetSize() != 2)
return FALSE;
double dR = _ttof(arRh.GetAt(0));
double dh = _ttof(arRh.GetAt(1));
CString sPt;
int nPos = sScript.Find(_T(')'),nIndex);
if (nPos == -1)
return FALSE;
sPt = sScript.Mid(nIndex + 1,nPos - nIndex - 1);
AcGePoint3d ptGeCen;
if (!StringToAcGePoint3d(sPt,ptGeCen))
return FALSE;
nPos = sScript.Find(_T('('),nPos);
if (nPos == -1)
return FALSE;
CString sVt = sScript.Mid(nPos);
sVt.TrimLeft(_T('('));
sVt.TrimRight(_T(')'));
AcGeVector3d vt;
if (!StringToAcGeVector3d(sVt,vt))
{
return FALSE;
}
AcGeVector3d vtNorm = vt.perpVector();
vtNorm.normalize();
AcGeEllipArc3d elArc;
AcGeVector3d vtMaj,vtMin;
vtMaj = vt.crossProduct(vtNorm);
vtMin = vt;
elArc.set(ptGeCen,vtMaj,vtMin,dR,dh,0,PI / 2.0);
AcGePoint3dArray arPts;
arPts.setPhysicalLength(30);
elArc.getSamplePoints(30,arPts);
AcDbLine line(ptGeCen,ptGeCen + 100 * vt);
AcGePoint3d ptGe,ptGeOrig;
AcGePoint3dArray arPts2;
AcDbFace face;
//按10度每一旋转
for (int j = 0;j < 36;j++)
{
arPts2.setLogicalLength(0);
for (int i = 0;i < arPts.length();i++)
{
ptGe = arPts.at(i);
line.getClosestPointTo(ptGe,ptGeOrig,Adesk::kTrue);
ptGe.rotateBy(PI / 18.0,vt,ptGeOrig);
arPts2.append(ptGe);
}
//创建面
for (int n = 0;n < arPts2.length() - 1;n++)
{
face.setVertexAt(0,arPts.at(n));
face.setVertexAt(1,arPts2.at(n));
face.setVertexAt(2,arPts2.at(n+1));
face.setVertexAt(3,arPts.at(n+1));
mode.DrawEntity(face);
}
//上次调换
arPts.setLogicalLength(0);
arPts.append(arPts2);
}
return TRUE;
}
return FALSE;
}
BOOL TImpSpecEquipment::ExplodeOrDraw3d_Hesp(CString& sScript,const AcGeMatrix3d& xform,XExplodeDraw &mode,int nGsMark) const
{
//球缺面封头 R,h,(中心点pt),(中心向量)
//500,300,(10,10,10),(0,0,1)
int nIndex = sScript.Find(_T('('),0);
if (nIndex != -1)
{
CString sRh = sScript.Mid(0,nIndex - 1);
CStringArray arRh;
Script2StringArray(sRh,_T(','),arRh);
if (arRh.GetSize() != 2)
return FALSE;
double dR = _ttof(arRh.GetAt(0));
double dh = _ttof(arRh.GetAt(1));
if (dh - dR > 1.e-10)
return FALSE;
CString sPt;
int nPos = sScript.Find(_T(')'),nIndex);
if (nPos == -1)
return FALSE;
sPt = sScript.Mid(nIndex + 1,nPos - nIndex - 1);
AcGePoint3d ptGeCen;
if (!StringToAcGePoint3d(sPt,ptGeCen))
return FALSE;
nPos = sScript.Find(_T('('),nPos);
if (nPos == -1)
return FALSE;
CString sVt = sScript.Mid(nPos);
sVt.TrimLeft(_T('('));
sVt.TrimRight(_T(')'));
AcGeVector3d vt;
if (!StringToAcGeVector3d(sVt,vt))
{
return FALSE;
}
AcGeVector3d vtNorm = vt.perpVector();
vtNorm.normalize();
double dStaAng = PI / 2.0 - acos((dR - dh) / dR);
AcGeVector3d vtRef = vt.crossProduct(vtNorm);
AcGeCircArc3d Arc;
Arc.set(ptGeCen,vtNorm,vtRef,dR,dStaAng,PI / 2.0);
AcGePoint3dArray arPts;
arPts.setPhysicalLength(30);
Arc.getSamplePoints(30,arPts);
AcDbLine line(ptGeCen,ptGeCen + 100 * vt);
AcGePoint3d ptGe,ptGeOrig;
AcGePoint3dArray arPts2;
AcDbFace face;
//按10度每一旋转
for (int j = 0;j < 36;j++)
{
arPts2.setLogicalLength(0);
for (int i = 0;i < arPts.length();i++)
{
ptGe = arPts.at(i);
line.getClosestPointTo(ptGe,ptGeOrig,Adesk::kTrue);
ptGe.rotateBy(PI / 18.0,vt,ptGeOrig);
arPts2.append(ptGe);
}
//创建面
for (int n = 0;n < arPts2.length() - 1;n++)
{
face.setVertexAt(0,arPts.at(n));
face.setVertexAt(1,arPts2.at(n));
face.setVertexAt(2,arPts2.at(n+1));
face.setVertexAt(3,arPts.at(n+1));
mode.SetSelectionMarker(nGsMark);
mode.DrawEntity(face);
}
//上次调换
arPts.setLogicalLength(0);
arPts.append(arPts2);
}
return TRUE;
}
return FALSE;
}
Acad::ErrorStatus TImpSpecEquipment::ExplodeOrDrawBlock2d(XExplodeDraw &mode) const
{
return Acad::eOk;
}
Acad::ErrorStatus TImpSpecEquipment::ExplodeOrDrawText2d(XExplodeDraw &mode) const
{
return Acad::eOk;
}
Acad::ErrorStatus TImpSpecEquipment::ExplodeOrDraw2d(XExplodeDraw &mode) const
{
return Acad::eOk;
}
void TImpSpecEquipment::list() const
{
}
Acad::ErrorStatus TImpSpecEquipment::transformBy(const AcGeMatrix3d& xform)
{
return Acad::eOk;
}
Acad::ErrorStatus TImpSpecEquipment::getStretchPoints(AcGePoint3dArray& stretchPoints) const
{
return Acad::eOk;
}
Acad::ErrorStatus TImpSpecEquipment::moveGripPointsAt(const AcDbIntArray& indices,
const AcGeVector3d& offset)
{
return Acad::eOk;
}
Acad::ErrorStatus TImpSpecEquipment::moveStretchPointsAt(const AcDbIntArray& indices,
const AcGeVector3d& offset)
{
return Acad::eOk;
}
Acad::ErrorStatus TImpSpecEquipment::intersectWith(const AcDbEntity* pEnt,
AcDb::Intersect intType,
const AcGePlane& projPlane,
AcGePoint3dArray& points,
INT_PTR thisGsMarker,
INT_PTR otherGsMarker) const
{
return Acad::eOk;
}
Acad::ErrorStatus TImpSpecEquipment::intersectWith(const AcDbEntity* pEnt,
AcDb::Intersect intType,
AcGePoint3dArray& points,
INT_PTR thisGsMarker,
INT_PTR otherGsMarker) const
{
return Acad::eOk;
}
Acad::ErrorStatus TImpSpecEquipment::getOsnapPoints(AcDb::OsnapMode osnapMode,
INT_PTR gsSelectionMark,
const AcGePoint3d& pickPoint,
const AcGePoint3d& lastPoint,
const AcGeMatrix3d& viewXform,
AcGePoint3dArray& snapPoints,
AcDbIntArray& geomIds) const
{
// change by hh 2011-07-12 支持捕捉设备上所有的点。大部分设备均可用同样
// 的方法来处理,不需要该功能或其他不同需求时,请在子类中重写该函数
AcDbVoidPtrArray arEnts, arBlocks;
XExplodeStream mode(arEnts);
ExplodeOrDrawBlock2d(mode);
for(int i = 0; i < arEnts.length(); i++)
{
AcDbObject* pObj = (AcDbObject*)arEnts[i];
if(NULL == pObj)
continue;
AcDbBlockReference* pBloclRef = AcDbBlockReference::cast(pObj);
if(NULL == pBloclRef)
{
AcDbEntity* pEntity = AcDbEntity::cast(pObj);
if(NULL != pEntity)
{
pEntity->getOsnapPoints(osnapMode, gsSelectionMark,
pickPoint, lastPoint, viewXform, snapPoints, geomIds);
pEntity->close();
}
}
else
{
pBloclRef->explode(arBlocks);
pBloclRef->close();
for(int j = 0; j < arBlocks.length(); j++)
{
AcDbObject* pObjSub = (AcDbObject*)arBlocks[j];
if(NULL == pObjSub)
continue;
AcDbEntity *pEntSub = AcDbEntity::cast(pObjSub);
if(NULL != pEntSub)
{
pEntSub->getOsnapPoints(osnapMode, gsSelectionMark, pickPoint, lastPoint,
viewXform, snapPoints, geomIds);
pEntSub->close();
}
delete pObjSub;
}
arBlocks.setLogicalLength(0);
}
delete pObj;
}
return Acad::eOk;
}
Acad::ErrorStatus TImpSpecEquipment::getGripPoints(AcGePoint3dArray& gripPoints,
AcDbIntArray& osnapModes,
AcDbIntArray& geomIds) const
{
return Acad::eOk;
}
Acad::ErrorStatus TImpSpecEquipment::getGeomExtents(AcDbExtents& extents) const
{
return Acad::eOk;
}
Acad::ErrorStatus TImpSpecEquipment::getClassID(CLSID* pClsid) const
{
return Acad::eOk;
}
Acad::ErrorStatus TImpSpecEquipment::explode(AcDbVoidPtrArray& entitySet) const
{
return Acad::eOk;
}
BOOL TImpSpecEquipment::MakesureInterfaceValidate(const AcDbObjectId& id,const AcGePoint3d& ptCon,const AcGeVector3d& vtDir,TInterface& pipeInterface) const
{
//到命名对象字典中找;
BOOL bSuccess = FALSE;
// add by hh 2011-08-09 接口记录从字典移动到数据库中
TDbInterfaceRecord* pIntfRec = TAuxTools::GetIntfPtrFromDB();
if(NULL != pIntfRec)
{
if (pIntfRec->Find(ptCon,vtDir,m_pOwnerEnt->objectId(),pipeInterface))
{
if (pipeInterface.GetConnectObject().asOldId() == id.asOldId())
{
bSuccess = TRUE;
}
}
pIntfRec->close();
return bSuccess;
}
// add end
AcDbDictionary* pNamedDict = NULL;
if (Acad::eOk == acdbCurDwg()->getNamedObjectsDictionary(pNamedDict,AcDb::kForRead))
{
AcDbDictionary* pDict = NULL;
if (Acad::eOk == pNamedDict->getAt(KEY_IRECORD,(AcDbObject*&)pDict,AcDb::kForRead))
{
pNamedDict->close();
TDbInterfaceRecord* pInterfaceRec = NULL;
if (Acad::eOk == pDict->getAt(KEY_IRECORD,(AcDbObject*&)pInterfaceRec,AcDb::kForRead))
{
pDict->close();
if (pInterfaceRec->Find(ptCon,vtDir,m_pOwnerEnt->objectId(),pipeInterface))
{
if (pipeInterface.GetConnectObject().asOldId() == id.asOldId())
{
bSuccess = TRUE;
}
}
pInterfaceRec->close();
}
else
{
pDict->close();
}
}
else
{
pNamedDict->close();
}
}
return bSuccess;
}
BOOL TImpSpecEquipment::MakesureInterfaceValidate(const AcDbObjectId& id,const AcGePoint3d& ptCon,const AcGeVector3d& vtDir) const
{
//到命名对象字典中找;
BOOL bSuccess = FALSE;
// add by hh 2011-08-09 接口记录从字典移动到数据库中
TDbInterfaceRecord* pIntfRec = TAuxTools::GetIntfPtrFromDB();
if(NULL != pIntfRec)
{
TInterface pipeInterface;
if (pIntfRec->Find(ptCon,vtDir,m_pOwnerEnt->objectId(),pipeInterface))
{
if (pipeInterface.GetConnectObject().asOldId() == id.asOldId())
{
bSuccess = TRUE;
}
}
pIntfRec->close();
return bSuccess;
}
// add end
AcDbDictionary* pNamedDict = NULL;
if (Acad::eOk == acdbCurDwg()->getNamedObjectsDictionary(pNamedDict,AcDb::kForRead))
{
AcDbDictionary* pDict = NULL;
if (Acad::eOk == pNamedDict->getAt(KEY_IRECORD,(AcDbObject*&)pDict,AcDb::kForRead))
{
pNamedDict->close();
TDbInterfaceRecord* pInterfaceRec = NULL;
if (Acad::eOk == pDict->getAt(KEY_IRECORD,(AcDbObject*&)pInterfaceRec,AcDb::kForRead))
{
pDict->close();
TInterface pipeInterface;
if (pInterfaceRec->Find(ptCon,vtDir,m_pOwnerEnt->objectId(),pipeInterface))
{
if (pipeInterface.GetConnectObject().asOldId() == id.asOldId())
{
bSuccess = TRUE;
}
}
pInterfaceRec->close();
}
else
{
pDict->close();
}
}
else
{
pNamedDict->close();
}
}
return bSuccess;
}
BOOL TImpSpecEquipment::FindConnect(const AcGePoint3d& ptGePos,const AcGeVector3d& vtDir,const AcDbObjectId& idOwner,AcDbObjectId& idInterface)
{
//到命名对象字典中找;
BOOL bSuccess = FALSE;
// add by hh 2011-08-09 接口记录从字典移动到数据库中
TDbInterfaceRecord* pIntfRec = TAuxTools::GetIntfPtrFromDB();
if(NULL != pIntfRec)
{
TInterface iInterface;
if (pIntfRec->PairFind(ptGePos,vtDir,idOwner,iInterface))
{
idInterface = iInterface.GetConnectObject();
bSuccess = TRUE;
}
pIntfRec->close();
return bSuccess;
}
// add end
AcDbDictionary* pNamedDict = NULL;
if (Acad::eOk == acdbCurDwg()->getNamedObjectsDictionary(pNamedDict,AcDb::kForRead))
{
AcDbDictionary* pDict = NULL;
if (Acad::eOk == pNamedDict->getAt(KEY_IRECORD,(AcDbObject*&)pDict,AcDb::kForRead))
{
pNamedDict->close();
TDbInterfaceRecord* pInterfaceRec = NULL;
if (Acad::eOk == pDict->getAt(KEY_IRECORD,(AcDbObject*&)pInterfaceRec,AcDb::kForRead))
{
pDict->close();
TInterface iInterface;
if (pInterfaceRec->PairFind(ptGePos,vtDir,idOwner,iInterface))
{
idInterface = iInterface.GetConnectObject();
bSuccess = TRUE;
}
pInterfaceRec->close();
}
else
{
pDict->close();
}
}
else
{
pNamedDict->close();
}
}
return bSuccess;
}
BOOL TImpSpecEquipment::OPMInfo(LPCTSTR pszName, TDb::OPMInfo* pInfo)
{
return FALSE;
}
BOOL TImpSpecEquipment::IsValid(TDbXDataMap* pXMap)
{
return FALSE;
}
BOOL TImpSpecEquipment::IsParallelToZ() const
{
// 获得法向量
AcGeVector3d vtNor;
m_pXDataMap->GetAt(HVAC_Normal, vtNor);
// 获得UCS坐标Z向量
AcDbDatabase* pDb = acdbCurDwg();
AcGeVector3d vtZAxis(pDb->ucsxdir().crossProduct(pDb->ucsydir()));
return vtNor.isParallelTo(vtZAxis);
}
BOOL TImpSpecEquipment::IsParallelToY() const
{
// 获得法向量
AcGeVector3d vtNor;
m_pXDataMap->GetAt(HVAC_Normal, vtNor);
AcDbDatabase* pDb = acdbCurDwg();
return vtNor.isParallelTo(pDb->ucsydir());
}
BOOL TImpSpecEquipment::IsParallelToX() const
{
// 获得法向量
AcGeVector3d vtNor;
m_pXDataMap->GetAt(HVAC_Normal, vtNor);
AcDbDatabase* pDb = acdbCurDwg();
return vtNor.isParallelTo(pDb->ucsxdir());
}
void TImpSpecEquipment::OnSubErase( Adesk::Boolean erasing )
{
}
LRESULT TImpSpecEquipment::UserCall( long i,LPVOID pData )
{
return 0l;
}
int TImpSpecEquipment::GetXBaseShell(TXShell& xShell)
{
return 0;
}
int TImpSpecEquipment::GetBodyBox(AcDbExtents& ext) const
{
return 0;
}
CString TImpSpecEquipment::GetXml(const AcGeMatrix3d& mat) const
{
return _T("");
}
bool TImpSpecEquipment::GetSection(const AcDbFace &face, const AcGeVector3d &vtPlaneSecDir,
std::vector<TObjSectionRecord> &sectionRecord, AcDbVoidPtrArray& arFillPtrs) const
{
// change by hh 2013-03-25 暖通标准版ID从6改成15
// if(6 != g_nProductId && 5 != g_nProductId) // 以下处理仅限暖通使用
if(15 != g_nProductId && 5 != g_nProductId)
return false;
if(NULL == m_pXDataMap)
return false;
// 基本参数
AcDbObjectId idObj = m_pOwnerEnt->objectId();
AcDbObjectId idLayer = m_pOwnerEnt->layerId();
TGGeSectionPlane section_pln(face, vtPlaneSecDir); // 构造一个辅助剖面
AcDbObjectId idBlock2d, idBlock3d;
m_pXDataMap->GetAt(KEY_Part2D, idBlock2d);
m_pXDataMap->GetAt(KEY_Part3D, idBlock3d);
if(idBlock2d != idBlock3d)
{
// 法向量
AcGeVector3d vtNor;
m_pXDataMap->GetAt(HVAC_Normal, vtNor);
// 主方向
AcGeVector3d vtMain;
m_pXDataMap->GetAt(KEY_MainDir, vtMain);
// 中心点
AcGePoint3d ptCenter;
m_pXDataMap->GetAt(KEY_StartPoint, ptCenter);
// 取得图块尺寸
AcGeVector3d vtBlkSize;
m_pXDataMap->GetAt(KEY_Scale3D, vtBlkSize);
vtBlkSize.x = 1 / vtBlkSize.x;
vtBlkSize.y = 1 / vtBlkSize.y;
vtBlkSize.z = 1 / vtBlkSize.z;
// 长宽高
double dLength = 0, dWidth = 0, dHeight = 0;
m_pXDataMap->GetAt(KEY_Length, dLength);
m_pXDataMap->GetAt(KEY_Width, dWidth);
m_pXDataMap->GetAt(KEY_Thick, dHeight);
// 取得投影图块ID
AcGeScale3d scale(dLength / vtBlkSize.x, dWidth / vtBlkSize.y, dHeight / vtBlkSize.z); // 原始比例
AcDbObjectId idProj = TAuxTools::GetProjBlockId(idBlock3d, vtNor, vtMain, vtPlaneSecDir, scale);
if(AcDbObjectId::kNull == idProj)
return false;
AcGePlane plane = section_pln.AsAcGePlane();
AcGePoint3d ptTemp = ptCenter.orthoProject(plane);
double dDist = ptTemp.distanceTo(ptCenter);
// 计算最大点和最小点
AcDbExtents extBlock;
GetBodyBox(extBlock);
AcGePoint3d ptMin = extBlock.minPoint().orthoProject(plane);
AcGePoint3d ptMax = extBlock.maxPoint().orthoProject(plane);
BlockRefInfo info(idProj, scale, ptTemp, dDist * (-1), ptMax, ptMin);
TSectionFill *pFill = new TSectionFill(info, idLayer);
arFillPtrs.append(pFill);
}
else
{
TImpSpecEquipment* pThis = (TImpSpecEquipment*)this;
TXShell xFace;
if(!pThis->GetXBaseShell(xFace)) // GetXBaseShell为非const函数,使用代理方式调用
return false;
double dElevation = 0;
AcDbFace* pFace = NULL;
for(int i = 0; i < xFace.GetCount(); i++)
{
if(NULL == (pFace = xFace.GetFace(i)))
continue;
TGGeSectionPlane pln(*pFace, vtPlaneSecDir);
TGGePoly2D poly;
dElevation = SectionUtility::Projection_plane2plane(section_pln, pln, poly);
if(!!poly) // add by hh 2011-03-11 增加投影后的Poly2D有效型判断
sectionRecord.push_back(TObjSectionRecord(idObj, idLayer, TObjSectionRecord::eTCH_DBHEQUIPMENT, dElevation, poly));
delete pFace;
}
}
return true;
}
Acad::ErrorStatus TImpSpecEquipment::GetExtents(TADSGePoint3d &ptLow, TADSGePoint3d &ptUp) const
{
// change by hh 2013-03-25 暖通标准版ID从6改成15
// if(6 != g_nProductId && 5 != g_nProductId) // 以下处理仅限暖通使用
if(15 != g_nProductId && 5 != g_nProductId)
return Acad::eNotImplementedYet;
AcDbExtents ext;
if(!GetBodyBox(ext))
return Acad::eNotImplementedYet;
ptLow = ext.minPoint();
ptUp = ext.maxPoint();
return Acad::eOk;
}
BOOL TImpSpecEquipment::GetBlockComplexCurve(TComplexCurve& comCurve) const
{
return FALSE;
}
// add by hh 2014-08-06 支持设备与水管遮挡
Acad::ErrorStatus TImpSpecEquipment::GetClipBoundary(TGGePoly2D& poly)const
{
return Acad::eNotImplementedYet;
}
bool TImpSpecEquipment::IsMeClip() const
{
return false;
}
bool TImpSpecEquipment::IsClipMe(const TEntityBase* pEnt)const//ok是否被裁剪
{
return false;
}