956 lines
23 KiB
C++
956 lines
23 KiB
C++
#include "StdAfx.h"
|
|
#include <functional>
|
|
#include "math.h"
|
|
#include "List.h"
|
|
#include <list>
|
|
#include "XCurveInline.h"
|
|
#include "SectionStructDef.h"
|
|
#include "SectionUtility.h"
|
|
|
|
#define ISWINDOW(entity) ((entity == eAEC_OPENING) || (entity == eAEC_CORNER_WINDOW)) ? true : false
|
|
|
|
namespace
|
|
{
|
|
Acad::ErrorStatus DwgInFields(XLine &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 XLine &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(XCurveSegment &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 XCurveSegment &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, XLine> &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, XLine(asDblArray(ptS), asDblArray(ptE), LS_FINITE));
|
|
}
|
|
return pFiler->filerStatus();
|
|
}
|
|
|
|
Acad::ErrorStatus DwgInFields( XPoly2D &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, XLine> &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 XPoly2D &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, XLine> &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, XLine(asDblArray(ptS), asDblArray(ptE), LS_FINITE)));
|
|
|
|
return pFiler->filerStatus();
|
|
} while (false);
|
|
|
|
pFiler->pushBackItem();
|
|
return pFiler->filerStatus();
|
|
}
|
|
|
|
Acad::ErrorStatus DxfInFields( XPoly2D &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, XLine> &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 XPoly2D &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();
|
|
}
|
|
|
|
}
|
|
|
|
XSectionPlane::XSectionPlane()
|
|
: 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){}
|
|
|
|
XSectionPlane::XSectionPlane( 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){}
|
|
|
|
XSectionPlane::XSectionPlane( 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){}
|
|
|
|
XSectionPlane::XSectionPlane( const XSectionPlane& 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){}
|
|
|
|
XSectionPlane::XSectionPlane( 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 XSectionPlane::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 XSectionPlane::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 XSectionPlane::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 XSectionPlane::set( const XSectionPlane& 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 XSectionPlane::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 XSectionPlane::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 XSectionPlane::get( AcGePoint3d &pt0, AcGePoint3d &pt1, AcGePoint3d &pt2 ) const
|
|
{
|
|
if (!m_bPoly)
|
|
{
|
|
pt0 = m_pt0;
|
|
pt1 = m_pt1;
|
|
pt2 = m_pt2;
|
|
}
|
|
}
|
|
|
|
XSectionPlane& XSectionPlane::operator=( const XSectionPlane &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 XSectionPlane::AsAcGePlane() const
|
|
{
|
|
return AcGePlane(m_pt0, m_pt1, m_pt2);
|
|
}
|
|
|
|
AcGeBoundedPlane XSectionPlane::AsAcGeBoundedPlane() const
|
|
{
|
|
return AcGeBoundedPlane(m_pt0, m_pt1, m_pt2);
|
|
}
|
|
|
|
AcGeLineSeg3d XSectionPlane::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
|
|
{
|
|
XCurveSegment seg;
|
|
if (nIdx < SectionUtility::GetCountOfSegmentForPoly(m_poly)/*m_poly.TotalSegments()*/)
|
|
{
|
|
/*m_poly.Nth(nIdx, seg);*/
|
|
XCurveSegment seg = SectionUtility::GetSegmentOfPoly(m_poly, nIdx);
|
|
return AcGeLineSeg3d(seg.GetStartPoint().AsAcGePoint3d(), seg.GetEndPoint().AsAcGePoint3d());
|
|
}
|
|
return AcGeLineSeg3d();
|
|
}
|
|
}
|
|
|
|
bool XSectionPlane::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 XSectionPlane::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 XSectionPlane::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 XSectionPlane::Distance( const XSectionPlane &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 XSectionPlane::GetSegmentCount() const
|
|
{
|
|
if (!m_bPoly)
|
|
return 4;
|
|
else
|
|
{
|
|
if (m_poly.IsClosed())
|
|
return m_poly.Length();
|
|
else
|
|
return m_poly.Length() - 1;
|
|
}
|
|
}
|
|
|
|
XPoly2D XSectionPlane::GetPoly() const
|
|
{
|
|
XPoly2D 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 XSectionPlane::IsOn(const AcGePoint3d &pt, const bool b3D) const
|
|
{
|
|
XPoly2D 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;
|
|
}
|
|
|
|
ObjSectionRecord & ObjSectionRecord::operator=( const ObjSectionRecord &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 ObjSectionRecord::TransFormBy( AcGeMatrix3d mat )
|
|
{
|
|
for (size_t i = 0; i < m_arLines.size(); ++i)
|
|
{
|
|
XLine &line = m_arLines[i].second;
|
|
ads_matrix matrix;
|
|
memcpy(matrix, &mat, sizeof(ads_matrix));
|
|
line.TransformBy(matrix);
|
|
}
|
|
|
|
for (size_t i = 0; i < m_arHideLines.size(); ++i)
|
|
{
|
|
XLine &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 ObjSectionRecord::operator<( const ObjSectionRecord &record ) const
|
|
{
|
|
if (EQUAL(m_dElevation, record.m_dElevation))
|
|
{
|
|
if (ISWINDOW(m_eEntity) && (record.m_eEntity == eAEC_WALL))
|
|
return true;
|
|
if (ISWINDOW(record.m_eEntity) && (m_eEntity == eAEC_WALL))
|
|
return false;
|
|
}
|
|
return m_dElevation < record.m_dElevation;
|
|
}
|
|
|
|
bool ObjSectionRecord::operator>( const ObjSectionRecord &record ) const
|
|
{
|
|
if (EQUAL(m_dElevation, record.m_dElevation))
|
|
{
|
|
if (ISWINDOW(m_eEntity) && (record.m_eEntity == eAEC_WALL))
|
|
return false;
|
|
if (ISWINDOW(record.m_eEntity) && (m_eEntity == eAEC_WALL))
|
|
return true;
|
|
}
|
|
return m_dElevation > record.m_dElevation;
|
|
}
|
|
|
|
bool ObjSectionRecord::operator>=( const double & dEle ) const
|
|
{
|
|
return m_dElevation > dEle;
|
|
}
|
|
|
|
bool ObjSectionRecord::operator<=( const double & dEle ) const
|
|
{
|
|
return m_dElevation < dEle;
|
|
}
|
|
|
|
void ObjSectionRecord::SetSectionLinesElevation( const double &elev )
|
|
{
|
|
for (size_t i = 0; i < m_arLines.size(); ++i)
|
|
{
|
|
XLine &line = m_arLines[i].second;
|
|
XPoint pt = line.GetStartPoint();
|
|
pt.z = elev;
|
|
line.SetStartPoint(pt);
|
|
pt = line.GetEndPoint();
|
|
pt.z = elev;
|
|
line.SetEndPoint(pt);
|
|
}
|
|
}
|
|
|
|
void ObjSectionRecord::SetOriginalPoly( const XPoly2D &poly, const bool bSetSectionLine /*= false*/ )
|
|
{
|
|
m_polyOriginal = poly;
|
|
if (poly.Length())
|
|
{
|
|
if (bSetSectionLine)
|
|
ConverPolyLine2Line();
|
|
GetExtents();
|
|
}
|
|
}
|
|
|
|
void ObjSectionRecord::GetSectionLines( std::vector<std::pair<int, XLine> > &lines ) const
|
|
{
|
|
lines.clear();
|
|
lines.assign(m_arLines.begin(), m_arLines.end());
|
|
}
|
|
|
|
ObjSectionRecord::ObjSectionRecord( const AcDbObjectId &id, const AcDbObjectId &layerid,
|
|
const SectionType type, const double &elevation,
|
|
const XPoly2D &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();
|
|
}
|
|
}
|
|
|
|
ObjSectionRecord::ObjSectionRecord( const ObjSectionRecord &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 ObjSectionRecord::SetSectionLines( const std::vector<std::pair<int, XLine> > &lines )
|
|
{
|
|
m_arLines.clear();
|
|
m_arLines.assign(lines.begin(), lines.end());
|
|
}
|
|
|
|
Acad::ErrorStatus ObjSectionRecord::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, XLine> > 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, XLine> > artmp2(nCount);
|
|
for (int 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 ObjSectionRecord::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 (int i = 0; i < nCount; ++i)
|
|
DwgOutFields(m_arHideLines[i], pFiler);
|
|
|
|
pFiler->writeItem(m_ptMax);
|
|
pFiler->writeItem(m_ptMin);
|
|
|
|
return pFiler->filerStatus();
|
|
}
|
|
|
|
void ObjSectionRecord::ConverPolyLine2Line()
|
|
{
|
|
double *pBulge = new double[m_polyOriginal.Length()];
|
|
memset(pBulge, 0, m_polyOriginal.Length()*sizeof(double));
|
|
DList<double> dd(pBulge, m_polyOriginal.Length());
|
|
m_polyOriginal.SetBulges(dd);
|
|
delete [] pBulge;
|
|
pBulge = NULL;
|
|
m_arLines.clear();
|
|
for (int i = 0; i < SectionUtility::GetCountOfSegmentForPoly(m_polyOriginal)/*m_polyOriginal.TotalSegments()*/; ++i)
|
|
{
|
|
XCurveSegment seg = SectionUtility::GetSegmentOfPoly(m_polyOriginal, i);
|
|
// m_polyOriginal.Nth(i, seg);
|
|
XLine line(LS_FINITE);
|
|
line.SetStartPoint(seg.GetStartPoint());
|
|
line.SetEndPoint(seg.GetEndPoint());
|
|
m_arLines.push_back(std::make_pair(i, line));
|
|
}
|
|
}
|
|
|
|
void ObjSectionRecord::ConverPolyLine2CoverPoly()
|
|
{
|
|
m_arHideLines.clear();
|
|
for (int i = 0; i < SectionUtility::GetCountOfSegmentForPoly(m_polyOriginal)/*m_polyOriginal.TotalSegments()*/; ++i)
|
|
{
|
|
XCurveSegment 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());
|
|
XLine 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, XLine(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, XLine(asDblArray(pt1), asDblArray(pt2), LS_FINITE)));
|
|
}
|
|
}
|
|
else // ��������ȫ���ڵ�
|
|
{
|
|
m_arHideLines.push_back(std::make_pair(i, seg));
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
void ObjSectionRecord::SetHideSecitonLines( std::vector<std::pair<int, XLine> > &lines )
|
|
{
|
|
m_arHideLines.assign(lines.begin(), lines.end());
|
|
}
|
|
|
|
void ObjSectionRecord::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();
|
|
}
|
|
|
|
XPoly2D BlockRefInfo::ToPoly2D()
|
|
{
|
|
AcGePoint3d pt2(m_ptMin.x, m_ptMax.y, 0.), pt3(m_ptMax.x, m_ptMin.y, 0.);
|
|
XPoly2D 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 XSectionFill::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<XLine> 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 XSectionFill::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 XSectionFill::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)
|
|
{
|
|
XLine &line = m_Segments[i];
|
|
memcpy(matrix, &mat, sizeof(ads_matrix));
|
|
line.TransformBy(matrix);
|
|
}
|
|
}
|
|
}
|
|
|
|
void XSectionFill::InitBlockCoverId()
|
|
{
|
|
if (m_bBlock)
|
|
{
|
|
m_BlockRef.InitCoverBlockID();
|
|
}
|
|
}
|
|
|
|
XSectionFill& XSectionFill::operator = ( const XSectionFill &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;
|
|
}
|