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

1066 lines
23 KiB
C++

#include "stdafx.h"
const Adesk::UInt8 TDbNetshelf::g_nVersion = 1;
ACRX_DXF_DEFINE_MEMBERS(ATSNetshelf, ATSEntity, AcDb::kDHL_CURRENT,
AcDb::kMReleaseCurrent, 1, ATS_NETSHELF, "ATS_NETSHELF图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com");
IMPLEMENT_TENTBASE(TDbNetshelf);
static void RemoveAll(DList<XPoint>& lstPoint,const XPoint& ptDest)
{
for (int i=0; i<lstPoint.Length(); i++) {
if (ptDest == *lstPoint[i]) {
lstPoint.Remove();
i--;
}
}
}
TDbNetshelf::TDbNetshelf():
m_dRadiusSphere(_AS_SYS_UNIT(50)),
m_dRadiusPole(_AS_SYS_UNIT(25)),
m_bMonoAdded(TRUE)
{
//默认图层:当前层
XString sCurLayer;
xg_getvar(_T("CLAYER"), (TCHAR*)sCurLayer);
m_idLayerSphere=
GetLayerIdFromString((const TCHAR*)sCurLayer);
}
TDbNetshelf::~TDbNetshelf()
{
}
BOOL TDbNetshelf::IsValid() const
{
assertReadEnabled();
if(!TDbEntity::IsValid())
return FALSE;
BOOL bRet=m_dRadiusSphere>1.0E-3 &&
m_dRadiusPole>1.0E-3 &&
m_lstPole.Length()>0;
return bRet;
}
void TDbNetshelf::SetLayerSphere(AcDbObjectId idLayer)
{
assertWriteEnabled();
m_idLayerSphere = idLayer;
}
void TDbNetshelf::SetLayerSphere(CString sLayer)
{
assertWriteEnabled();
if (sLayer.IsEmpty()) {
XString sCurLayer;
xg_getvar(_T("CLAYER"), (TCHAR*)sCurLayer);
m_idLayerSphere=GetLayerIdFromString((const TCHAR*)sCurLayer);
}
else {
m_idLayerSphere=InitLayer(sLayer,FALSE);
}
}
void TDbNetshelf::SetRadiusSphere(double dRadius)
{
assertWriteEnabled();
m_dRadiusSphere = dRadius;
}
void TDbNetshelf::SetRadiusPole(double dRadius)
{
assertWriteEnabled();
m_dRadiusPole = dRadius;
}
void TDbNetshelf::SetMonoAdded(BOOL bFlag)
{
assertWriteEnabled();
m_bMonoAdded = bFlag;
}
BOOL TDbNetshelf::IsMonoAdded() const
{
assertReadEnabled();
return m_bMonoAdded;
}
double TDbNetshelf::GetRadiusSphere() const
{
assertReadEnabled();
return m_dRadiusSphere;
}
double TDbNetshelf::GetRadiusPole() const
{
assertReadEnabled();
return m_dRadiusPole;
}
AcDbObjectId TDbNetshelf::GetLayerSphere() const
{
assertReadEnabled();
return m_idLayerSphere;
}
CString TDbNetshelf::GetSphereLayer() const
{
assertReadEnabled();
CString sLayer=GetSymbolName(m_idLayerSphere).cs();
return sLayer;
}
void TDbNetshelf::SetLayer(CString sLayer)
{
assertWriteEnabled();
if (sLayer.IsEmpty()) {
XString sCurLayer;
xg_getvar(_T("CLAYER"), (TCHAR*)sCurLayer);
AcDbObjectId idLayer=
GetLayerIdFromString((const TCHAR*)sCurLayer);
setLayer(idLayer);
}
else {
AcDbObjectId idLayer=InitLayer(sLayer,FALSE);
setLayer(idLayer);
}
}
CString TDbNetshelf::GetLayer() const
{
assertReadEnabled();
CString sLayer=GetSymbolName(layerId()).cs();
return sLayer;
}
BOOL TDbNetshelf::IsExit(const XLine& line) const
{
assertReadEnabled();
int nCount = m_lstPole.Length();
for (int i=0; i<nCount; i++) {
if (/*line.flag==m_lstPole[i].flag &&*/
((line.StartPoint()==m_lstPole[i].StartPoint() &&
line.EndPoint()==m_lstPole[i].EndPoint()) ||
(line.StartPoint()==m_lstPole[i].EndPoint() &&
line.EndPoint()==m_lstPole[i].StartPoint())))
return TRUE;
}
return FALSE;
}
BOOL TDbNetshelf::IsMonoNode(const XPoint& ptVertex) const
{
assertReadEnabled();
int nCount = m_lstMono.Length();
for (int i=0; i<nCount; i++) {
if (ptVertex == m_lstMono[i])
return TRUE;
}
return FALSE;
}
BOOL TDbNetshelf::IsMultiNode(const XPoint& ptVertex) const
{
assertReadEnabled();
int nCount = m_lstMulti.Length();
for (int i=0; i<nCount; i++) {
if (ptVertex == m_lstMulti[i])
return TRUE;
}
return FALSE;
}
BOOL TDbNetshelf::AddPole(const XLine& line)
{
assertWriteEnabled();
if (line.GetLength()<1.0E-3)
return FALSE;
if (IsExit(line))
return FALSE;
m_lstPole.Append(new XLine(line));
AddNode(line.StartPoint());
AddNode(line.EndPoint());
return TRUE;
}
void TDbNetshelf::AddNode(const XPoint& ptNode)
{
BOOL bMulti = IsMultiNode(ptNode);
BOOL bMono = IsMonoNode(ptNode);
if (!bMono && !bMulti) {
m_lstMono.NewAppend(ptNode);
}
else if (bMono && !bMulti) {
m_lstMono.Remove();
m_lstMulti.NewAppend(ptNode);
}
else if (bMono && bMulti) {
m_lstMono.Remove();
}
}
void TDbNetshelf::DelNode(const XPoint& ptNode)
{
//处理单甩节点
int nCount = m_lstMono.Length();
for (int i=0; i<nCount; i++) {
XPoint& ptTemp=*m_lstMono[i];
if (ptTemp == ptNode) {
m_lstMono.Remove();
return;
}
}
//处理公共节点
int nNum=0;
nCount = m_lstPole.Length();
for (i=0; i<nCount; i++) {
XLine& lineTemp=*m_lstPole[i];
XPoint& ptTemp1=lineTemp.StartPoint();
if (ptTemp1 == ptNode) {
nNum++;
if (nNum>=2) break;
}
else {
XPoint& ptTemp2=lineTemp.EndPoint();
if (ptTemp2 == ptNode) {
nNum++;
if (nNum>=2) break;
}
}
}
if (nNum == 1) {
m_lstMono.NewAppend(ptNode);
int nCount = m_lstMulti.Length();
for (int i=0; i<nCount; i++) {
if (*m_lstMulti[i] == ptNode) {
m_lstMulti.Remove();
break;
}
}
}
}
BOOL TDbNetshelf::DelPole(const XLine& line)
{
assertWriteEnabled();
BOOL bRet = FALSE;
int nCount = m_lstPole.Length();
for (int i=0; i<nCount; i++) {
XLine& lineTemp=*m_lstPole[i];
if (/*line.flag==m_lstPole[i].flag &&*/
((line.StartPoint()==lineTemp.StartPoint() &&
line.EndPoint()==lineTemp.EndPoint()) ||
(line.StartPoint()==lineTemp.EndPoint() &&
line.EndPoint()==lineTemp.StartPoint()))) {
m_lstPole.Remove();
bRet = TRUE;
break;
}
}
if (!bRet) {
return bRet;
}
//删除节点
DelNode(line.StartPoint());
DelNode(line.EndPoint());
return bRet;
}
void TDbNetshelf::ProcessNetshelf(const DList<XLine>& lstLine,
const BOOL bRemoveSame)
{
assertWriteEnabled();
m_lstPole.Reset();
m_lstMono.Reset();
m_lstMulti.Reset();
//杆
int nCount = lstLine.Length();
for (int i=0; i<nCount; i++) {
m_lstPole.Append(new XLine(lstLine[i]));
}
//去出相同的line
if (bRemoveSame) {
for (int i=0; i<m_lstPole.Length()-1; i++) {
XLine& line = *m_lstPole[i];
for (int j=i+1; j<m_lstPole.Length(); j++) {
if (/*line.flag==m_lstPole[i]->flag &&*/
((line.StartPoint()==m_lstPole[j]->StartPoint() &&
line.EndPoint()==m_lstPole[j]->EndPoint()) ||
(line.StartPoint()==m_lstPole[j]->EndPoint() &&
line.EndPoint()==m_lstPole[j]->StartPoint()))) {
m_lstPole.Remove();
j--;
}
}
}
}
//节点
nCount = m_lstPole.Length();
for (i=0; i<nCount; i++) {
AddNode(m_lstPole[i]->StartPoint());
AddNode(m_lstPole[i]->EndPoint());
}
}
const XPointList& TDbNetshelf::GetMonoNode() const
{
assertReadEnabled();
return m_lstMono;
}
const XPointList& TDbNetshelf::GetMultiNode() const
{
assertReadEnabled();
return m_lstMulti;
}
const DList<XLine>& TDbNetshelf::GetPole() const
{
assertReadEnabled();
return m_lstPole;
}
// 提供对格式刷的支持
void TDbNetshelf::CopyPropertiesFrom(AcDbEntity *pSrcEntity, unsigned gMatchFlag)
{
assertWriteEnabled();
TDbEntity::CopyPropertiesFrom(pSrcEntity, gMatchFlag);
TDbNetshelf *pSrc=TDbNetshelf::cast(pSrcEntity);
if(pSrc) {
if(database()==NULL||
pSrcEntity->database()==NULL||
database()==pSrcEntity->database())//add by whl on 060317
{
m_idLayerSphere=pSrc->m_idLayerSphere;
}
m_bMonoAdded=pSrc->m_bMonoAdded;
m_dRadiusSphere=pSrc->m_dRadiusSphere;
m_dRadiusPole=pSrc->m_dRadiusPole;
}
}
Acad::ErrorStatus
TDbNetshelf::subGetClassID(CLSID* pClsid) const
{
return Acad::eOk;
}
// 从DWG读入数据:
Acad::ErrorStatus TDbNetshelf::dwgInFields (AcDbDwgFiler* pFiler)
{
assertWriteEnabled();
Acad::ErrorStatus es=Acad::eOk;
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(&m_idLayerSphere);
//网架参数
pFiler->readItem(&m_dRadiusSphere);
pFiler->readItem(&m_dRadiusPole);
pFiler->readItem(&m_bMonoAdded);
Adesk::UInt16 nCount=0;
//杆
m_lstPole.Reset();
pFiler->readItem(&nCount);
for(Adesk::UInt16 i=0; i<nCount; i++) {
XPoint ptStart;
pFiler->readItem(&(AcGePoint3d &)ptStart);
m_lstPole.Append(new XLine(ptStart,XPoint(0,0,0)));
}
assert(m_lstPole.Length()==nCount);
for(i=0; i<nCount; i++) {
XLine& line=*m_lstPole[i];
XPoint& ptEnd=line.EndPoint();
pFiler->readItem(&(AcGePoint3d &)ptEnd);
}
//单甩节点
m_lstMono.Reset();
pFiler->readItem(&nCount);
for(i=0; i<nCount; i++) {
XPoint* pPtTemp = new XPoint;
pFiler->readItem((AcGePoint3d *)pPtTemp);
m_lstMono.Append(pPtTemp);
}
//公用节点
m_lstMulti.Reset();
pFiler->readItem(&nCount);
for(i=0; i<nCount; i++) {
XPoint* pPtTemp = new XPoint;
pFiler->readItem((AcGePoint3d *)pPtTemp);
m_lstMulti.Append(pPtTemp);
}
return pFiler->filerStatus();
}
Acad::ErrorStatus TDbNetshelf::dwgOutFields(AcDbDwgFiler* pFiler) const
{
assertReadEnabled();
Acad::ErrorStatus es = Acad::eOk;
//del by xlc on 100416
//R18平台在进行编辑时删除最后一根杆件后返回Acad::eInvalidInput时程序崩溃退出
//低平台在图形导出时崩溃
// if (!IsValid())
// {
// return Acad::eInvalidInput;
// }
es = TDbEntity::dwgOutFields(pFiler);
if(es != Acad::eOk) return es;
pFiler->writeItem(g_nVersion);
//图层
pFiler->writeItem(m_idLayerSphere);
//网架参数
pFiler->writeItem(m_dRadiusSphere);
pFiler->writeItem(m_dRadiusPole);
pFiler->writeItem(m_bMonoAdded);
Adesk::UInt16 nCount=0;
//杆
nCount = m_lstPole.Length();
pFiler->writeItem(nCount);
for(Adesk::UInt16 i=0; i<nCount; i++) {
pFiler->writeItem((AcGePoint3d &)m_lstPole[i].StartPoint());
}
for(i=0; i<nCount; i++) {
pFiler->writeItem((AcGePoint3d &)m_lstPole[i].EndPoint());
}
//单甩节点
nCount = m_lstMono.Length();
pFiler->writeItem(nCount);
for(i=0; i<nCount; i++) {
pFiler->writeItem((AcGePoint3d &)m_lstMono[i]);
}
//公用节点
nCount = m_lstMulti.Length();
pFiler->writeItem(nCount);
for(i=0; i<nCount; i++) {
pFiler->writeItem((AcGePoint3d &)m_lstMulti[i]);
}
return pFiler->filerStatus();
}
Acad::ErrorStatus TDbNetshelf::dxfInFields (AcDbDxfFiler* pFiler)
{
assertWriteEnabled();
Acad::ErrorStatus es = Acad::eOk;
es = TDbEntity::dxfInFields(pFiler);
if(es!=Acad::eOk)
return es;
if (!pFiler->atSubclassData(_T("TDbNetshelf"))) {
return Acad::eBadDxfSequence;
}
m_lstPole.Reset();
m_lstMono.Reset();
m_lstMulti.Reset();
resbuf rb;
DList<XPoint> lstStart;
DList<XPoint> lstEnd;
while ((es == Acad::eOk)
&& ((es = pFiler->readResBuf(&rb)) == Acad::eOk)) {
switch (rb.restype) {
case AcDb::kDxfHardPointerId+0:
acdbGetObjectId(m_idLayerSphere,rb.resval.rlname);
break;
case AcDb::kDxfXReal+0:
m_dRadiusSphere=rb.resval.rreal;
break;
case AcDb::kDxfXReal+1:
m_dRadiusPole=rb.resval.rreal;
break;
case AcDb::kDxfBool+0:
m_bMonoAdded=rb.resval.rint;
break;
case AcDb::kDxfXCoord+0:
lstStart.Append(new XPoint(rb.resval.rpoint));
break;
case AcDb::kDxfXCoord+1:
lstEnd.Append(new XPoint(rb.resval.rpoint));
break;
case AcDb::kDxfXCoord+2:
m_lstMono.Append(new XPoint(rb.resval.rpoint));
break;
case AcDb::kDxfXCoord+3:
m_lstMulti.Append(new XPoint(rb.resval.rpoint));
break;
default:
pFiler->pushBackItem();
es = Acad::eEndOfFile;
break;
}
}
if (es != Acad::eEndOfFile)
return Acad::eInvalidResBuf;
int nCount = lstStart.Length();
if(nCount<=0 || nCount!=lstEnd.Length()) {
pFiler->setError(_T("\nError DXF group code: 10, 11"));
return Acad::eMissingDxfField;
}
for (int i=0; i<nCount; i++) {
m_lstPole.Append(new XLine(*lstStart[i],*lstEnd[i]));
}
return pFiler->filerStatus();
}
Acad::ErrorStatus TDbNetshelf::dxfOutFields(AcDbDxfFiler* pFiler) const
{
assertReadEnabled();
Acad::ErrorStatus es = Acad::eOk;
if (!IsValid())
return Acad::eInvalidInput;
es = TDbEntity::dxfOutFields(pFiler);
assert(es == Acad::eOk);
es = pFiler->writeItem(AcDb::kDxfSubclass,_T("TDbNetshelf"));
assert(es == Acad::eOk);
//图层
pFiler->writeObjectId(AcDb::kDxfHardPointerId+0,m_idLayerSphere);
//网架参数
pFiler->writeDouble(AcDb::kDxfXReal+0,m_dRadiusSphere);
pFiler->writeDouble(AcDb::kDxfXReal+1,m_dRadiusPole);
pFiler->writeBoolean(AcDb::kDxfBool+0,m_bMonoAdded);
//杆
int nCount = m_lstPole.Length();
for(int i=0; i<nCount; i++) {
pFiler->writePoint3d(AcDb::kDxfXCoord+0,m_lstPole[i].StartPoint());
}
for(i=0; i<nCount; i++) {
pFiler->writePoint3d(AcDb::kDxfXCoord+1,m_lstPole[i].EndPoint());
}
//单甩节点
nCount = m_lstMono.Length();
for(i=0; i<nCount; i++) {
pFiler->writePoint3d(AcDb::kDxfXCoord+2,m_lstMono[i]);
}
//公用节点
nCount = m_lstMulti.Length();
for(i=0; i<nCount; i++) {
pFiler->writePoint3d(AcDb::kDxfXCoord+3,m_lstMulti[i]);
}
assert(es == Acad::eOk);
return pFiler->filerStatus();
}
Acad::ErrorStatus
TDbNetshelf::subGetOsnapPoints(AcDb::OsnapMode osnapMode,
INT_PTR gsSelectionMark,
const AcGePoint3d& ptPick,
const AcGePoint3d& lastPoint,
const AcGeMatrix3d& viewXform,
AcGePoint3dArray& snapPoints,
AcDbIntArray& geomIds) const
{
assertReadEnabled();
if( osnapMode==AcDb::kOsModeCen ||
osnapMode==AcDb::kOsModeNode
) {
int nCount = m_lstMulti.Length();
for (int i=0; i<nCount; i++) {
snapPoints.append(m_lstMulti[i].AsAcGePoint3d());
}
nCount = m_lstMono.Length();
for (i=0; i<nCount; i++) {
snapPoints.append(m_lstMono[i].AsAcGePoint3d());
}
return Acad::eOk;
}
Acad::ErrorStatus es =
TDbEntity::subGetOsnapPoints(osnapMode, gsSelectionMark,
ptPick, lastPoint, viewXform, snapPoints, geomIds);
return es;
}
Acad::ErrorStatus
TDbNetshelf::subGetGripPoints(AcGePoint3dArray& gripPoints,
AcDbIntArray& osnapModes,
AcDbIntArray& geomIds) const
{
assertReadEnabled();
//单甩节点
for(int i=0; i<m_lstMono.Length(); i++){
gripPoints.append(m_lstMono[i]);
}
//公用节点
for(i=0; i<m_lstMulti.Length(); i++){
gripPoints.append(m_lstMulti[i]);
}
return Acad::eOk;
}
Acad::ErrorStatus TDbNetshelf::GetGripText(int idx, CString &cs) const
{
assertReadEnabled();
int nMono = m_lstMono.Length();
int nMulti = m_lstMulti.Length() + nMono;
if (idx>=0 && idx<nMono) {
cs = _T("移动单甩节点");
}
else if (idx>=nMono && idx<nMulti) {
cs = _T("移动公用节点");
}
else {
return Acad::eInvalidIndex;
}
return Acad::eOk;
}
Acad::ErrorStatus
TDbNetshelf::subMoveGripPointsAt(const AcDbIntArray& indices,
const AcGeVector3d& offset)
{
assertWriteEnabled();
int nMono = m_lstMono.Length();
int nMulti = m_lstMulti.Length()+nMono;
for (int i=0; i<indices.length();i++) {
int idx = indices[i];
if(idx>=0 && idx<nMono) {//单甩节点
XPoint& ptOffset = *m_lstMono[idx];
MovePoleGripPoints(ptOffset,offset);
ptOffset += offset;
RegulateNode(ptOffset);
}
else if (idx>=nMono && idx<nMulti) {//公用节点
XPoint& ptOffset = *m_lstMulti[idx-nMono];
MovePoleGripPoints(ptOffset,offset);
ptOffset += offset;
RegulateNode(ptOffset);
}
}
return Acad::eOk;
}
void TDbNetshelf::RegulateNode(const XPoint& ptDest)
{
if (IsMonoNode(ptDest)) {//单甩节点
if (IsMultiNode(ptDest)) {
m_lstMono.Remove();
}
else {
int nCount = m_lstMono.Length();
for (int nPrevious=0,nNum=0,i=0; i<nCount; i++) {
if (ptDest == *m_lstMono[i]) {
nNum++;
if(nNum>1) {
m_lstMono.Remove();
//此处不真正删除点,只是将单节点给双节点链表
int nOldDelFlag = m_lstMono.GetDelFlag();
XPoint& ptMove = *m_lstMono[nPrevious];
m_lstMono.SetDelFlag(0);
m_lstMono.Remove(nPrevious);
m_lstMulti.Append(&ptMove);
m_lstMono.SetDelFlag(nOldDelFlag);
break;
}
nPrevious=i;
}
}
}
}
else if (IsMultiNode(ptDest)) {//公用节点
int nCount = m_lstMulti.Length();
for (int nNum=0,i=0; i<nCount; i++) {
if (ptDest == *m_lstMulti[i]) {
nNum++;
if(nNum>1) {
m_lstMulti.Remove();
break;
}
}
}
}
}
Acad::ErrorStatus
TDbNetshelf::MovePoleGripPoints(const XPoint& ptDest,
const AcGeVector3d& offset)
{
int nCount = m_lstPole.Length();
for (int i=0; i<nCount; i++) {
XLine& line = *m_lstPole[i];
XPoint& ptStart = line.StartPoint();
if (ptStart == ptDest) {
ptStart += offset;
}
XPoint& ptEnd = line.EndPoint();
if (ptEnd == ptDest) {
ptEnd += offset;
}
if (line.GetLength()<_DIST_SNAP) {
m_lstPole.Remove();
}
}
return Acad::eOk;
}
Acad::ErrorStatus TDbNetshelf::subTransformBy(const AcGeMatrix3d& xform)
{
assertWriteEnabled();
Acad::ErrorStatus es = Acad::eOk;
es = TDbEntity::subTransformBy(xform);
if (es != Acad::eOk) return es;
ads_matrix mat;
AsAdsMatrix(xform,mat);
m_lstMono.TransUCS(mat);
m_lstMulti.TransUCS(mat);
int nCount = m_lstPole.Length();
for (int i=0; i<nCount; i++) {
XLine& line = *m_lstPole[i];
line.TransformBy(mat);
}
return Acad::eOk;
}
Acad::ErrorStatus TDbNetshelf::ExplodeOrDraw2d(XExplodeDraw &dc) const
{
assertReadEnabled();
Acad::ErrorStatus es=Acad::eOk;
if (!IsValid())
return Acad::eNotApplicable;
int nCount = m_lstPole.Length();
for (int i=0; i<nCount; i++) {
XLine ln=m_lstPole[i];
ln.SetElevation(0.0);
dc << ln;
}
return es;
}
// 绘制3d的显示
Acad::ErrorStatus
TDbNetshelf::ExplodeOrDraw3d(XExplodeDraw &dc) const
{
assertReadEnabled();
Acad::ErrorStatus es=Acad::eOk;
if (!IsValid())
return Acad::eNotApplicable;
if(g_bOsnapExpl) {
int nCount = m_lstPole.Length();
for (int i=0; i<nCount; i++) {
dc << m_lstPole[i];
}
} else {
DrawPole3D(dc);//杆
dc.SetColorLayer(colorIndex(), m_idLayerSphere);
DrawSphere3D(dc);//球
//dc.RestoreProperties(vProp.m_prop);
}
return es;
}
Acad::ErrorStatus TDbNetshelf::DrawSphere3D(XExplodeDraw &dc) const
{
Acad::ErrorStatus es=Acad::eOk;
int nDiv = GetSphereDivNum();
int nLat = nDiv/2;
int nLong= nDiv;
nLat = int(nLat/2)*2+1;//确保奇数
nLong = int(nLong/2)*2+2;//确保偶数
XPoint *pPtArray=NULL;
pPtArray = new XPoint[nLat*nLong];
if (pPtArray == NULL) {
return Acad::eOutOfMemory;
}
//单甩节点
if (m_bMonoAdded) {
int nCount = m_lstMono.Length();
for (int i=0; i<nCount; i++) {
if (GetSphereMesh(pPtArray,m_lstMono[i],nLat,nLong)) {
dc.DrawMesh(nLat,nLong,(AcGePoint3d *)pPtArray);
XPoly2D polyTemp1(1);
XPoly2D polyTemp2(1);
for(int j=0; j<nLong-1; j++) {
polyTemp1.AppendNode(pPtArray[j]);
}
dc.DrawShell(polyTemp1);
for(j=0; j<nLong-1; j++) {
int nIndex = (nLat-1)*nLong+j;
polyTemp2.AppendNode(pPtArray[nIndex]);
}
dc.DrawShell(polyTemp2);
}
}
}
//公共节点
int nCount = m_lstMulti.Length();
for (int i=0; i<nCount; i++) {
if (GetSphereMesh(pPtArray,m_lstMulti[i],nLat,nLong)) {
dc.DrawMesh(nLat,nLong,(AcGePoint3d *)pPtArray);
XPoly2D polyTemp1(1);
XPoly2D polyTemp2(1);
for(int j=0; j<nLong-1; j++) {
polyTemp1.AppendNode(pPtArray[j]);
}
dc.DrawShell(polyTemp1);
for(j=0; j<nLong-1; j++) {
int nIndex = (nLat-1)*nLong+j;
polyTemp2.AppendNode(pPtArray[nIndex]);
}
dc.DrawShell(polyTemp2);
}
}
delete []pPtArray;
return es;
}
Acad::ErrorStatus TDbNetshelf::DrawPole3D(XExplodeDraw &dc) const
{
Acad::ErrorStatus es=Acad::eOk;
int nDiv = GetPoleDivNum();
nDiv++;
XPoint *pPtArray=NULL;
pPtArray = new XPoint[2*nDiv];
if (pPtArray == NULL) {
return Acad::eOutOfMemory;
}
int nCount = m_lstPole.Length();
for (int i=0; i<nCount; i++) {
if (GetPoleMesh(pPtArray,m_lstPole[i],nDiv)) {
dc.DrawMesh(2,nDiv,(AcGePoint3d *)pPtArray);
XPoly2D polyTemp1(1);
XPoly2D polyTemp2(1);
for(int j=0; j<nDiv-1; j++) {
polyTemp1.AppendNode(pPtArray[j]);
}
dc.DrawShell(polyTemp1);
int nUp = nDiv*2-1;
for(j=nDiv; j<nUp; j++) {
polyTemp2.AppendNode(pPtArray[j]);
}
dc.DrawShell(polyTemp2);
}
}
delete []pPtArray;
return es;
}
BOOL TDbNetshelf::GetPoleMesh(XPoint*& pPtArray,
const XLine& line,const int nCol) const
{
if (nCol<4 || m_dRadiusSphere<m_dRadiusPole) {
return FALSE;
}
double dSub = sqrt(m_dRadiusSphere*m_dRadiusSphere-
m_dRadiusPole*m_dRadiusPole);
double dDistance = ads_distance(line.StartPoint(),line.EndPoint());
if (dDistance<=0 && dDistance<dSub*2) {
return FALSE;
}
//起点和终点和方向
XPoint ptStart(line.StartPoint());
XPoint ptEnd(line.EndPoint());
AcGeVector3d vtDirection(line.EndPoint().x-line.StartPoint().x,
line.EndPoint().y-line.StartPoint().y,
line.EndPoint().z-line.StartPoint().z);
XVector3D vtSub(vtDirection);
double dScale=dSub/dDistance;
vtSub *= dScale;
if (!(!m_bMonoAdded && IsMonoNode(ptStart))) {
ptStart += vtSub;
}
if (!(!m_bMonoAdded && IsMonoNode(ptEnd))) {
ptEnd -= vtSub;
}
//旋转参数
AcGeVector3d vtNormal(0,0,1);
AcGeVector3d vtRotateAxis = vtNormal.crossProduct(vtDirection);
double dRotateAngle = vtNormal.angleTo(vtDirection, vtRotateAxis);
for (int i=0; i<nCol-1; i++) {
double dAngle = PI*2*i/(nCol-1);
AcGePoint3d ptStartTemp(m_dRadiusPole*sin(dAngle),
m_dRadiusPole*cos(dAngle),0);
AcGePoint3d ptEndTemp=ptStartTemp;
ptStartTemp += ptStart;
ptEndTemp += ptEnd;
ptStartTemp.rotateBy(dRotateAngle, vtRotateAxis, ptStart);
ptEndTemp.rotateBy(dRotateAngle, vtRotateAxis, ptEnd);
pPtArray[i]=ptStartTemp;
pPtArray[nCol+i]=ptEndTemp;
}
pPtArray[nCol-1] = pPtArray[0];
pPtArray[2*nCol-1] = pPtArray[nCol];
return TRUE;
}
BOOL TDbNetshelf::GetSphereMesh(XPoint*& pPtArray,
const XPoint& ptCenter,
const int nLat,
const int nLong) const
{
if (m_dRadiusSphere<1.0E-3 ||
nLat<3 || nLong<4)
return FALSE;
for(int i=0,n=-nLat/2; n<=nLat/2; n++, i++) {
double nLatAng=(double)(PI/nLat*n);
double z = (double)(m_dRadiusSphere*sin(nLatAng));
double xy= (double)(m_dRadiusSphere*cos(nLatAng));
int nLatNum = i*nLong;
for(int j=0,m=-(nLong-1)/2; m<=(nLong-1)/2; m++, j++) {
double nLongAng=(double)(2.0*PI/(nLong-1)*m-PI);
double x=(double)(xy*cos(nLongAng));
double y=(double)(xy*sin(nLongAng));
int nIndex = nLatNum+j;
pPtArray[nIndex].x = x+ptCenter.x;
pPtArray[nIndex].y = y+ptCenter.y;
pPtArray[nIndex].z = z+ptCenter.z;
}
pPtArray[nLatNum+nLong-1] = pPtArray[nLatNum];
}
return TRUE;
}
int TDbNetshelf::GetSphereDivNum() const
{
extern double g_nCirDeviation;
extern int GetCirDivNum(double r, double h);
int nDiv = TchExport::GetCirDivNum(m_dRadiusSphere,_AS_SYS_UNIT(TchGeLib::g_nCirDeviation));
if (nDiv < 3) {
nDiv = 3;
}
return nDiv;
}
int TDbNetshelf::GetPoleDivNum() const
{
extern double g_nCirDeviation;
extern int GetCirDivNum(double r, double h);
int nDiv = TchExport::GetCirDivNum(m_dRadiusPole,_AS_SYS_UNIT(TchGeLib::g_nCirDeviation));
if (nDiv < 3) {
nDiv = 3;
}
return nDiv;
}
void TDbNetshelf::GetTips(DList<TObjInfoUnit> &lstInfo) const
{
assertReadEnabled();
lstInfo.Append(new TObjInfoUnit(_T("对象类型"), _T("网架")));
}
void InitDbNetshelf(BOOL bTrue)
{
if(bTrue) {
TDbNetshelf::rxInit();
acrxBuildClassHierarchy();
TDbNetshelf::InitMatchProtocol(TRUE);
} else {
TDbNetshelf::InitMatchProtocol(FALSE);
deleteAcRxClass(TDbNetshelf::desc());
}
}