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

955 lines
23 KiB
C++

#include "StdAfx.h"
#include "math.h"
#include "TList.h"
#include <list>
#include "TGGeCurveInline.h"
#include "SectionStructDef.h"
#include "SectionUtility.h"
#include <functional>
#define ISWINDOW(entity) ((entity == eTCH_OPENING) || (entity == eTCH_CORNER_WINDOW)) ? true : false
namespace
{
Acad::ErrorStatus DwgInFields(TGGeLine &seg, AcDbDwgFiler *pFiler )
{
Adesk::Int32 nVer = 0;
pFiler->readInt32(&nVer);
if (nVer >= 1)
{
AcGePoint3d ptS, ptE;
pFiler->readItem(&ptS);
pFiler->readItem(&ptE);
seg.SetStartPoint(asDblArray(ptS));
seg.SetEndPoint(asDblArray(ptE));
}
return pFiler->filerStatus();
}
Acad::ErrorStatus DwgOutFields(const TGGeLine &seg, AcDbDwgFiler *pFiler )
{
Adesk::Int32 nVer = 1;
pFiler->writeInt32(nVer);
pFiler->writeItem(seg.GetStartPoint().AsAcGePoint3d());
pFiler->writeItem(seg.GetEndPoint().AsAcGePoint3d());
return pFiler->filerStatus();
}
Acad::ErrorStatus DwgInFields(TGGeCurveSegment &seg, AcDbDwgFiler *pFiler )
{
Adesk::Int32 nVer = 0;
pFiler->readInt32(&nVer);
if (nVer >= 1)
{
double dBulge = 0.;
AcGePoint3d ptS, ptE;
pFiler->readItem(&dBulge);
pFiler->readItem(&ptS);
pFiler->readItem(&ptE);
seg.SetBulge(dBulge);
seg.SetStartPoint(asDblArray(ptS));
seg.SetEndPoint(asDblArray(ptE));
}
return pFiler->filerStatus();
}
Acad::ErrorStatus DwgOutFields(const TGGeCurveSegment &seg, AcDbDwgFiler *pFiler )
{
Adesk::Int32 nVer = 1;
pFiler->writeInt32(nVer);
pFiler->writeItem(seg.GetBulge());
pFiler->writeItem(seg.GetStartPoint().AsAcGePoint3d());
pFiler->writeItem(seg.GetEndPoint().AsAcGePoint3d());
return pFiler->filerStatus();
}
Acad::ErrorStatus DwgInFields(std::pair<int, TGGeLine> &line, AcDbDwgFiler *pFiler )
{
Adesk::Int32 nVer = 0;
pFiler->readInt32(&nVer);
if (nVer >= 1)
{
Adesk::Int32 nPart = 0;
pFiler->readInt32(&nPart);
AcGePoint3d ptS, ptE;
pFiler->readItem(&ptS);
pFiler->readItem(&ptE);
line = std::make_pair((int)nPart, TGGeLine(asDblArray(ptS), asDblArray(ptE), LS_FINITE));
}
return pFiler->filerStatus();
}
Acad::ErrorStatus DwgInFields( TGGePoly2D &poly, AcDbDwgFiler *pFiler )
{
Adesk::Int32 nVer = 0;
pFiler->readInt32(&nVer);
if (nVer >= 1)
{
AcGePoint3d pt;
double dBulge = 0.;
Adesk::Int32 nCount = 0;
pFiler->readInt32(&nCount);
for (int i = 0;i < nCount; ++i)
{
pFiler->readItem(&pt);
pFiler->readItem(&dBulge);
poly.AppendNode(pt, dBulge);
}
}
return pFiler->filerStatus();
}
Acad::ErrorStatus DwgOutFields( const std::pair<int, TGGeLine> &line, AcDbDwgFiler *pFiler )
{
Adesk::Int32 nVer = 1, nPart = line.first;
pFiler->writeInt32(nVer);
pFiler->writeInt32(nPart);
pFiler->writeItem(line.second.GetStartPoint().AsAcGePoint3d());
pFiler->writeItem(line.second.GetEndPoint().AsAcGePoint3d());
return pFiler->filerStatus();
}
Acad::ErrorStatus DwgOutFields( const TGGePoly2D &poly, AcDbDwgFiler *pFiler )
{
Adesk::Int32 nVer = 1;
pFiler->writeInt32(nVer);
Adesk::Int32 nCount = poly.Length();
pFiler->writeInt32(nCount);
for (int i = 0; i < nCount; ++i)
{
pFiler->writeItem(poly[i].AsAcGePoint3d());
pFiler->writeItem(poly.GetBulge(i));
}
return pFiler->filerStatus();
}
Acad::ErrorStatus DxfInFields( std::pair<int, TGGeLine> &line, AcDbDxfFiler *pFiler )
{
Adesk::Int8 nVer = 0;
resbuf rb;
AcGePoint3d ptS, ptE;
do
{
pFiler->readItem(&rb);
if (rb.restype == AcDb::kDxfInt32)
nVer = (Adesk::Int8)rb.resval.rlong;
else
break;
int nPart = 0;
if (nVer >= 1)
{
pFiler->readItem(&rb);
if (rb.restype == AcDb::kDxfInt32)
nPart = (Adesk::Int8)rb.resval.rlong;
else
break;
pFiler->readItem(&rb);
if (rb.restype == AcDb::kDxfXCoord)
ptS = asPnt3d(rb.resval.rpoint);
else
break;
pFiler->readItem(&rb);
if (rb.restype == AcDb::kDxfXCoord+1)
ptE = asPnt3d(rb.resval.rpoint);
else
break;
}
line = (std::make_pair(nPart, TGGeLine(asDblArray(ptS), asDblArray(ptE), LS_FINITE)));
return pFiler->filerStatus();
} while (false);
pFiler->pushBackItem();
return pFiler->filerStatus();
}
Acad::ErrorStatus DxfInFields( TGGePoly2D &poly, AcDbDxfFiler *pFiler )
{
Adesk::Int8 nVer = 0;
resbuf rb;
AcGePoint3d ptS, ptE;
do
{
pFiler->readItem(&rb);
if (rb.restype == AcDb::kDxfInt32)
nVer = (Adesk::Int8)rb.resval.rlong;
else
break;
if (nVer >= 1)
{
int nCount = 0;
pFiler->readItem(&rb);
if (rb.restype == AcDb::kDxfInt32)
nCount = (Adesk::Int8)rb.resval.rlong;
else
break;
AcGePoint3d pt;
double dBulge = 0.;
for (int i = 0; i < nCount; ++i)
{
pFiler->readItem(&rb);
if (rb.restype == AcDb::kDxfXCoord)
pt = asPnt3d(rb.resval.rpoint);
else
break;
pFiler->readItem(&rb);
if (rb.restype == AcDb::kDxfReal)
dBulge = rb.resval.rreal;
else
break;
poly.AppendNode(pt, dBulge);
}
}
return pFiler->filerStatus();
} while (false);
pFiler->pushBackItem();
return pFiler->filerStatus();
}
Acad::ErrorStatus DxfOutFields( const std::pair<int, TGGeLine> &line, AcDbDxfFiler *pFiler )
{
Adesk::Int32 nVer = 1, nPart = line.first;
pFiler->writeInt32(AcDb::kDxfInt32, nVer); // write version
pFiler->writeInt32(AcDb::kDxfInt32, nPart);
pFiler->writeItem(AcDb::kDxfXCoord, line.second.GetStartPoint().AsAcGePoint3d());
pFiler->writeItem(AcDb::kDxfXCoord+1, line.second.GetEndPoint().AsAcGePoint3d());
return pFiler->filerStatus();
}
Acad::ErrorStatus DxfOutFields( const TGGePoly2D &poly, AcDbDxfFiler *pFiler )
{
Adesk::Int32 nVer = 1;
pFiler->writeInt32(AcDb::kDxfInt32, nVer); // write version
pFiler->writeInt32(AcDb::kDxfInt32, poly.Length());
for (int i = 0; i < poly.Length(); ++i)
{
pFiler->writeItem(AcDb::kDxfXCoord, poly[i].AsAcGePoint3d());
pFiler->writeItem(AcDb::kDxfReal, poly.GetBulge(i));
}
return pFiler->filerStatus();
}
}
TGGeSectionPlane::TGGeSectionPlane()
: m_pt0(0., 0., 0.), m_pt1(0., 0., 0.), m_pt2(0., 0., 0.), m_pt3(0., 0., 0.), m_vtNormal(0., 0., 0.), m_bPoly(false){}
TGGeSectionPlane::TGGeSectionPlane( const AcGePoint3d &pt0, const AcGePoint3d &pt1, const AcGePoint3d &pt2, const AcGePoint3d &pt3, const AcGeVector3d &vt )
: m_pt0(pt0), m_pt1(pt1), m_pt2(pt2), m_pt3(pt3), m_vtNormal(vt), m_bPoly(false){}
TGGeSectionPlane::TGGeSectionPlane( const AcGePoint3d &pt0, const AcGePoint3d &pt1, const AcGePoint3d &pt2, const AcGeVector3d &vt )
: m_pt0(pt0), m_pt1(pt1), m_pt2(pt2), m_pt3(pt0), m_vtNormal(vt), m_bPoly(false){}
TGGeSectionPlane::TGGeSectionPlane( const TGGeSectionPlane& plane )
: m_pt0(plane.m_pt0), m_pt1(plane.m_pt1), m_pt2(plane.m_pt2),
m_pt3(plane.m_pt3), m_vtNormal(plane.m_vtNormal), m_bPoly(plane.m_bPoly), m_poly(plane.m_poly){}
TGGeSectionPlane::TGGeSectionPlane( const AcDbFace &face, const AcGeVector3d &vt )
: m_vtNormal(vt), m_bPoly(false)
{
face.getVertexAt(0, m_pt0);
face.getVertexAt(1, m_pt1);
face.getVertexAt(2, m_pt2);
face.getVertexAt(3, m_pt3);
}
void TGGeSectionPlane::set( const AcGePoint3d &pt0, const AcGePoint3d &pt1, const AcGePoint3d &pt2, const AcGePoint3d &pt3 )
{
if (!m_bPoly)
{
m_pt0 = pt0;
m_pt1 = pt1;
m_pt2 = pt2;
m_pt3 = pt3;
}
}
void TGGeSectionPlane::set( const AcGePoint3d &pt0, const AcGePoint3d &pt1, const AcGePoint3d &pt2 )
{
if (!m_bPoly)
{
m_pt0 = pt0;
m_pt1 = pt1;
m_pt2 = pt2;
m_pt3 = pt0;
}
}
void TGGeSectionPlane::set( int nIdx, const AcGePoint3d &pt )
{
if (!m_bPoly)
{
if (0 == nIdx)
m_pt0 = pt;
else if (1 == nIdx)
m_pt1 = pt;
else if (2 == nIdx)
m_pt2 = pt;
else if (3 == nIdx)
m_pt3 = pt;
}
}
void TGGeSectionPlane::set( const TGGeSectionPlane& plane )
{
if (!m_bPoly)
set(plane.get(0), plane.get(1), plane.get(2), plane.get(3));
else
{
m_bPoly = true;
m_poly = plane.m_poly;
}
}
AcGePoint3d TGGeSectionPlane::get( int nIdx) const
{
if (!m_bPoly)
{
if (0 == nIdx)
return m_pt0;
else if (1 == nIdx)
return m_pt1;
else if (2 == nIdx)
return m_pt2;
else
return m_pt3;
}
else
{
if (nIdx < m_poly.Length())
return m_poly[nIdx];
}
return AcGePoint3d::kOrigin;
}
void TGGeSectionPlane::get( AcGePoint3d &pt0, AcGePoint3d &pt1, AcGePoint3d &pt2, AcGePoint3d &pt3 ) const
{
if (!m_bPoly)
{
pt0 = m_pt0;
pt1 = m_pt1;
pt2 = m_pt2;
pt3 = m_pt3;
}
}
void TGGeSectionPlane::get( AcGePoint3d &pt0, AcGePoint3d &pt1, AcGePoint3d &pt2 ) const
{
if (!m_bPoly)
{
pt0 = m_pt0;
pt1 = m_pt1;
pt2 = m_pt2;
}
}
TGGeSectionPlane& TGGeSectionPlane::operator=( const TGGeSectionPlane &face )
{
if (this != &face)
{
if (!face.m_bPoly)
{
face.get(m_pt0, m_pt1, m_pt2, m_pt3);
}
else
{
m_poly = face.m_poly;
m_bPoly = true;
}
}
return *this;
}
AcGePlane TGGeSectionPlane::AsAcGePlane() const
{
return AcGePlane(m_pt0, m_pt1, m_pt2);
}
AcGeBoundedPlane TGGeSectionPlane::AsAcGeBoundedPlane() const
{
return AcGeBoundedPlane(m_pt0, m_pt1, m_pt2);
}
AcGeLineSeg3d TGGeSectionPlane::get_seg( int nIdx ) const
{
if (!m_bPoly)
{
if (0 == nIdx)
return AcGeLineSeg3d(m_pt0, m_pt1);
else if (1 == nIdx)
return AcGeLineSeg3d(m_pt1, m_pt2);
else if (2 == nIdx)
return AcGeLineSeg3d(m_pt2, m_pt3);
else
return AcGeLineSeg3d(m_pt3, m_pt0);
}
else
{
TGGeCurveSegment seg;
if (nIdx < SectionUtility::GetCountOfSegmentForPoly(m_poly)/*m_poly.TotalSegments()*/)
{
/*m_poly.Nth(nIdx, seg);*/
TGGeCurveSegment seg = SectionUtility::GetSegmentOfPoly(m_poly, nIdx);
return AcGeLineSeg3d(seg.GetStartPoint().AsAcGePoint3d(), seg.GetEndPoint().AsAcGePoint3d());
}
return AcGeLineSeg3d();
}
}
bool TGGeSectionPlane::intersect_with_segment( const AcGeLineSeg3d &in_seg, std::vector<AcGePoint3d> &arPts ) const
{
bool bRet = false;
arPts.clear();
AcGeLineSeg3d seg;
AcGePoint3d pt;
int nSegCount = GetSegmentCount();
for (int i = 0; i < nSegCount; ++i)
{
seg = get_seg(i);
if (in_seg.intersectWith(seg, pt))
{
if (std::find(arPts.begin(), arPts.end(), pt) == arPts.end())
arPts.push_back(pt);
bRet = true;
}
}
return bRet;
}
bool TGGeSectionPlane::intersect_with_ray( AcGeRay3d &in_ray, std::vector<AcGePoint3d> &arPts ) const
{
bool bRet = false;
arPts.clear();
AcGeLineSeg3d seg;
AcGePoint3d pt;
int nSegCount = GetSegmentCount();
for (int i = 0; i < nSegCount; ++i)
{
seg = get_seg(i);
if (in_ray.intersectWith(seg, pt))
{
if (std::find(arPts.begin(), arPts.end(), pt) == arPts.end())
arPts.push_back(pt);
bRet = true;
}
}
return bRet;
}
void TGGeSectionPlane::AsAcDbFace(AcDbFace &fa) const
{
fa.setVertexAt(0, m_pt0);
fa.setVertexAt(1, m_pt1);
fa.setVertexAt(2, m_pt2);
fa.setVertexAt(3, m_pt3);
}
double TGGeSectionPlane::Distance( const TGGeSectionPlane &plane ) const
{
AcGePlane pln = AsAcGePlane();
std::list<double> arDists;
AcGePoint3d pt, ptOrt;
int nSegCount = GetSegmentCount();
for (int i = 0; i < nSegCount; ++i)
{
pt = plane.get(i);
ptOrt = pt.orthoProject(pln);
AcGeVector3d vec = pt - ptOrt;
if (vec.dotProduct(m_vtNormal) > 0)
arDists.push_back(pt.distanceTo(ptOrt)*-1);
else
arDists.push_back(0.);
}
arDists.sort(std::greater<double>());
return (arDists.size() > 0) ? arDists.front() : 0.;
}
int TGGeSectionPlane::GetSegmentCount() const
{
if (!m_bPoly)
return 4;
else
{
if (m_poly.IsClosed())
return m_poly.Length();
else
return m_poly.Length() - 1;
}
}
TGGePoly2D TGGeSectionPlane::GetPoly() const
{
TGGePoly2D poly;
if (m_bPoly)
{
poly = m_poly;
}
else
{
poly.AppendNode(m_pt0);
poly.AppendNode(m_pt1);
poly.AppendNode(m_pt2);
poly.AppendNode(m_pt3);
poly.SetClosed();
}
return poly;
}
bool TGGeSectionPlane::IsOn(const AcGePoint3d &pt, const bool b3D) const
{
TGGePoly2D poly = GetPoly();
AcGePoint3d _tmpPT(pt);
if (b3D)
{
AcGeMatrix3d mat;
mat = SectionUtility::GetCoordSystem(m_vtNormal);
_tmpPT.transformBy(mat);
poly.TransformBy(mat);
poly.SetElevation(0.);
_tmpPT.z = 0.;
}
if (PR_OUTSIDE != (_tmpPT & poly))
return true;
else
return false;
}
TObjSectionRecord & TObjSectionRecord::operator=( const TObjSectionRecord &record )
{
if (this != &record)
{
m_iD = record.m_iD;
m_layerID = record.m_layerID;
m_polyOriginal = record.m_polyOriginal;
m_nSectionPos = record.m_nSectionPos;
m_eEntity = record.m_eEntity;
m_dElevation = record.m_dElevation;
m_arLines = record.m_arLines;
m_arHideLines = record.m_arHideLines;
m_ptMin = record.m_ptMin;
m_ptMax = record.m_ptMax;
}
return *this;
}
void TObjSectionRecord::TransFormBy( AcGeMatrix3d mat )
{
for (size_t i = 0; i < m_arLines.size(); ++i)
{
TGGeLine &line = m_arLines[i].second;
ads_matrix matrix;
memcpy(matrix, &mat, sizeof(ads_matrix));
line.TransformBy(matrix);
}
for (i = 0; i < m_arHideLines.size(); ++i)
{
TGGeLine &line = m_arHideLines[i].second;
ads_matrix matrix;
memcpy(matrix, &mat, sizeof(ads_matrix));
line.TransformBy(matrix);
}
m_polyOriginal.TransformBy(mat);
m_ptMax.transformBy(mat);
m_ptMin.transformBy(mat);
}
bool TObjSectionRecord::operator<( const TObjSectionRecord &record ) const
{
if (EQUAL(m_dElevation, record.m_dElevation))
{
if (ISWINDOW(m_eEntity) && (record.m_eEntity == eTCH_WALL))
return true;
if (ISWINDOW(record.m_eEntity) && (m_eEntity == eTCH_WALL))
return false;
}
return m_dElevation < record.m_dElevation;
}
bool TObjSectionRecord::operator>( const TObjSectionRecord &record ) const
{
if (EQUAL(m_dElevation, record.m_dElevation))
{
if (ISWINDOW(m_eEntity) && (record.m_eEntity == eTCH_WALL))
return false;
if (ISWINDOW(record.m_eEntity) && (m_eEntity == eTCH_WALL))
return true;
}
return m_dElevation > record.m_dElevation;
}
bool TObjSectionRecord::operator>=( const double & dEle ) const
{
return m_dElevation > dEle;
}
bool TObjSectionRecord::operator<=( const double & dEle ) const
{
return m_dElevation < dEle;
}
void TObjSectionRecord::SetSectionLinesElevation( const double &elev )
{
for (size_t i = 0; i < m_arLines.size(); ++i)
{
TGGeLine &line = m_arLines[i].second;
TADSGePoint3d pt = line.GetStartPoint();
pt.z = elev;
line.SetStartPoint(pt);
pt = line.GetEndPoint();
pt.z = elev;
line.SetEndPoint(pt);
}
}
void TObjSectionRecord::SetOriginalPoly( const TGGePoly2D &poly, const bool bSetSectionLine /*= false*/ )
{
m_polyOriginal = poly;
if (poly.Length())
{
if (bSetSectionLine)
ConverPolyLine2Line();
GetExtents();
}
}
void TObjSectionRecord::GetSectionLines( std::vector<std::pair<int, TGGeLine> > &lines ) const
{
lines.clear();
lines.assign(m_arLines.begin(), m_arLines.end());
}
TObjSectionRecord::TObjSectionRecord( const AcDbObjectId &id, const AcDbObjectId &layerid,
const SectionType type, const double &elevation,
const TGGePoly2D &poly, const int pos /*= 0*/ )
: m_iD(id), m_eEntity(type), m_dElevation(elevation),
m_polyOriginal(poly), m_nSectionPos(pos), m_layerID(layerid)
{
if (poly.Length())
{
ConverPolyLine2Line();
GetExtents();
}
}
TObjSectionRecord::TObjSectionRecord( const TObjSectionRecord &record )
{
m_iD = record.m_iD;
m_layerID = record.m_layerID;
m_polyOriginal = record.m_polyOriginal;
m_nSectionPos = record.m_nSectionPos;
m_eEntity = record.m_eEntity;
m_dElevation = record.m_dElevation;
m_arLines = record.m_arLines;
m_arHideLines = record.m_arHideLines;
m_ptMax = record.m_ptMax;
m_ptMin = record.m_ptMin;
}
void TObjSectionRecord::SetSectionLines( const std::vector<std::pair<int, TGGeLine> > &lines )
{
m_arLines.clear();
m_arLines.assign(lines.begin(), lines.end());
}
Acad::ErrorStatus TObjSectionRecord::dwgInFields( AcDbDwgFiler *pFiler )
{
Adesk::Int32 nVer = 0;
pFiler->readInt32(&nVer); // read version
if (nVer >= 1)
{
DwgInFields(m_polyOriginal, pFiler);
Adesk::Int32 nCount = 0;
pFiler->readInt32(&nCount);
std::vector<std::pair<int, TGGeLine> > artmp1(nCount);
for (int i = 0; i < nCount; ++i)
DwgInFields(artmp1[i], pFiler);
m_arLines.swap(artmp1);
pFiler->readItem(&m_nSectionPos);
pFiler->readItem(&m_dElevation);
pFiler->readItem((int*)(&m_eEntity));
pFiler->readSoftPointerId(&m_layerID);
pFiler->readSoftPointerId(&m_iD);
nCount = 0;
pFiler->readInt32(&nCount);
std::vector<std::pair<int, TGGeLine> > artmp2(nCount);
for (i = 0; i < nCount; ++i)
DwgInFields(artmp2[i], pFiler);
m_arHideLines.swap(artmp2);
pFiler->readItem(&m_ptMax);
pFiler->readItem(&m_ptMin);
}
return pFiler->filerStatus();
}
Acad::ErrorStatus TObjSectionRecord::dwgOutFields( AcDbDwgFiler *pFiler ) const
{
Adesk::Int32 nVer = 1;
pFiler->writeInt32(nVer); // write version
DwgOutFields(m_polyOriginal, pFiler);
Adesk::Int32 nCount = (Adesk::Int32)m_arLines.size();
pFiler->writeInt32(nCount);
for (int i = 0; i < nCount; ++i)
DwgOutFields(m_arLines[i], pFiler);
pFiler->writeItem(m_nSectionPos);
pFiler->writeItem(m_dElevation);
pFiler->writeItem((int)m_eEntity);
pFiler->writeSoftPointerId(m_layerID);
pFiler->writeSoftPointerId(m_iD);
nCount = (Adesk::Int32)m_arHideLines.size();
pFiler->writeInt32(nCount);
for (i = 0; i < nCount; ++i)
DwgOutFields(m_arHideLines[i], pFiler);
pFiler->writeItem(m_ptMax);
pFiler->writeItem(m_ptMin);
return pFiler->filerStatus();
}
void TObjSectionRecord::ConverPolyLine2Line()
{
double *pBulge = new double[m_polyOriginal.Length()];
memset(pBulge, 0, m_polyOriginal.Length()*sizeof(double));
m_polyOriginal.SetBulges(TDPtrList<double>(pBulge, m_polyOriginal.Length()));
delete [] pBulge;
pBulge = NULL;
m_arLines.clear();
for (int i = 0; i < SectionUtility::GetCountOfSegmentForPoly(m_polyOriginal)/*m_polyOriginal.TotalSegments()*/; ++i)
{
TGGeCurveSegment seg = SectionUtility::GetSegmentOfPoly(m_polyOriginal, i);
// m_polyOriginal.Nth(i, seg);
TGGeLine line(LS_FINITE);
line.SetStartPoint(seg.GetStartPoint());
line.SetEndPoint(seg.GetEndPoint());
m_arLines.push_back(std::make_pair(i, line));
}
}
void TObjSectionRecord::ConverPolyLine2CoverPoly()
{
m_arHideLines.clear();
for (int i = 0; i < SectionUtility::GetCountOfSegmentForPoly(m_polyOriginal)/*m_polyOriginal.TotalSegments()*/; ++i)
{
TGGeCurveSegment seg = SectionUtility::GetSegmentOfPoly(m_polyOriginal, i);
// m_polyOriginal.Nth(i, seg);
AcGeLine3d line(seg.GetStartPoint().AsAcGePoint3d(), seg.GetEndPoint().AsAcGePoint3d());
double dS = line.paramOf(seg.GetStartPoint().AsAcGePoint3d());
double dE = line.paramOf(seg.GetEndPoint().AsAcGePoint3d());
TGGeLine line2;
if (SectionUtility::GetLine(m_arLines, i, line2))
{
double d1 = line.paramOf(line2.GetStartPoint().AsAcGePoint3d());
double d2 = line.paramOf(line2.GetEndPoint().AsAcGePoint3d());
if ((EQUALA(d1, dS) && EQUALA(d2, dE)) || (EQUALA(d1, dE) && EQUALA(d2, dS))) // 完全没被遮挡
continue;
std::list<double> list_para;
list_para.push_back(dS);
list_para.push_back(dE);
list_para.push_back(d1);
list_para.push_back(d2);
list_para.sort();
double s1 = list_para.front();
list_para.pop_front();
double s2 = list_para.front();
list_para.pop_front();
double s3 = list_para.front();
list_para.pop_front();
double s4 = list_para.front();
list_para.pop_front();
if (!EQUALA(s1, s2))
{
AcGePoint3d pt1 = line.evalPoint(s1), pt2 = line.evalPoint(s2);
m_arHideLines.push_back(std::make_pair(i, TGGeLine(asDblArray(pt1), asDblArray(pt2), LS_FINITE)));
}
if (!EQUALA(s3, s4))
{
AcGePoint3d pt1 = line.evalPoint(s3), pt2 = line.evalPoint(s4);
m_arHideLines.push_back(std::make_pair(i, TGGeLine(asDblArray(pt1), asDblArray(pt2), LS_FINITE)));
}
}
else // 这段线完全被遮挡
{
m_arHideLines.push_back(std::make_pair(i, seg));
}
}
}
void TObjSectionRecord::SetHideSecitonLines( std::vector<std::pair<int, TGGeLine> > &lines )
{
m_arHideLines.assign(lines.begin(), lines.end());
}
void TObjSectionRecord::GetExtents()
{
ads_point pLow, pUp;
m_polyOriginal.GetExtend(pLow, pUp);
m_ptMax = asPnt3d(pUp);
m_ptMin = asPnt3d(pLow);
}
Acad::ErrorStatus BlockRefInfo::dwgInFields( AcDbDwgFiler *pFiler )
{
Adesk::Int32 nVer = 0;
pFiler->readInt32(&nVer); // read version
if (nVer >= 1)
{
pFiler->readItem(&m_idBlock);
pFiler->readScale3d(&m_Scale);
pFiler->readPoint3d(&m_ptPos);
pFiler->readItem(&m_idBlockClone);
pFiler->readItem(&m_dHeight);
pFiler->readPoint3d(&m_ptMax);
pFiler->readPoint3d(&m_ptMin);
}
return pFiler->filerStatus();
}
Acad::ErrorStatus BlockRefInfo::dwgOutFields( AcDbDwgFiler *pFiler ) const
{
Adesk::Int32 nVer = 1;
pFiler->writeInt32(nVer);
pFiler->writeItem(m_idBlock);
pFiler->writeScale3d(m_Scale);
pFiler->writePoint3d(m_ptPos);
pFiler->writeItem(m_idBlockClone);
pFiler->writeItem(m_dHeight);
pFiler->writePoint3d(m_ptMax);
pFiler->writePoint3d(m_ptMin);
return pFiler->filerStatus();
}
TGGePoly2D BlockRefInfo::ToPoly2D()
{
AcGePoint3d pt2(m_ptMin.x, m_ptMax.y, 0.), pt3(m_ptMax.x, m_ptMin.y, 0.);
TGGePoly2D poly;
poly.AppendNode(m_ptMax);
poly.AppendNode(pt2);
poly.AppendNode(m_ptMin);
poly.AppendNode(pt3);
poly.AppendNode(m_ptMax);
poly.SetClosed();
return poly;
}
void BlockRefInfo::TransformBy( const AcGeMatrix3d &mat )
{
//m_vtDir.transformBy(mat);
m_ptPos.transformBy(mat);
m_ptMax.transformBy(mat);
m_ptMin.transformBy(mat);
}
void BlockRefInfo::InitCoverBlockID()
{
if (!m_idBlockClone.isValid())
m_idBlockClone = SectionUtility::CloneAndResetLineTypeForBlockTableRecord(m_idBlock, _T("DASH"));
}
Acad::ErrorStatus TSectionFill::dwgInFields( AcDbDwgFiler *pFiler )
{
Adesk::Int32 nVer = 0;
pFiler->readInt32(&nVer); // read version
if (nVer >= 1)
{
m_BlockRef.dwgInFields(pFiler);
Adesk::Int32 nCount = 0;
pFiler->readInt32(&nCount);
std::vector<TGGeLine> tmp(nCount);
for (int i = 0; i < nCount; ++i)
DwgInFields(tmp[i], pFiler);
m_Segments.swap(tmp);
pFiler->readBool(&m_bBlock);
pFiler->readBool(&m_bCoverBlock);
pFiler->readDouble(&m_dElevtion);
pFiler->readSoftPointerId(&m_layerID);
}
return pFiler->filerStatus();
}
Acad::ErrorStatus TSectionFill::dwgOutFields( AcDbDwgFiler *pFiler ) const
{
Adesk::Int32 nVer = 1;
pFiler->writeInt32(nVer);
m_BlockRef.dwgOutFields(pFiler);
pFiler->writeInt32((Adesk::Int32)m_Segments.size());
for (size_t i = 0; i < m_Segments.size(); ++i)
DwgOutFields(m_Segments[i], pFiler);
pFiler->writeBool(m_bBlock);
pFiler->writeBool(m_bCoverBlock);
pFiler->writeDouble(m_dElevtion);
pFiler->writeSoftPointerId(m_layerID);
return pFiler->filerStatus();
}
void TSectionFill::TransformBy(const AcGeMatrix3d &mat)
{
ads_matrix matrix;
if (m_bBlock)
{
m_BlockRef.TransformBy(mat);
}
else
{
for (size_t i = 0; i < m_Segments.size(); ++i)
{
TGGeLine &line = m_Segments[i];
memcpy(matrix, &mat, sizeof(ads_matrix));
line.TransformBy(matrix);
}
}
}
void TSectionFill::InitBlockCoverId()
{
if (m_bBlock)
{
m_BlockRef.InitCoverBlockID();
}
}
TSectionFill& TSectionFill::operator = ( const TSectionFill &fill )
{
if (this != &fill)
{
m_BlockRef = fill.m_BlockRef;
m_Segments = fill.m_Segments;
m_HideSegments = fill.m_HideSegments;
m_bBlock = fill.m_bBlock;
m_bCoverBlock = fill.m_bCoverBlock;
m_dElevtion = fill.m_dElevtion;
m_layerID = fill.m_layerID;
}
return *this;
}