337 lines
11 KiB
C++
337 lines
11 KiB
C++
#ifndef _SECTIONSTRUCTDEF_H_
|
|
#define _SECTIONSTRUCTDEF_H_
|
|
|
|
#include "gebndpln.h"
|
|
#include <vector>
|
|
#include <algorithm>
|
|
#include "geray3d.h"
|
|
#include "XPoly2D.h"
|
|
#include "SectionStructDef.h"
|
|
|
|
// Section工程所封装的 面 对象
|
|
class GEOAPI XSectionPlane
|
|
{
|
|
public:
|
|
XSectionPlane();
|
|
XSectionPlane(const XSectionPlane& plane);
|
|
XSectionPlane(const AcGePoint3d &pt0, const AcGePoint3d &pt1, const AcGePoint3d &pt2, const AcGePoint3d &pt3, const AcGeVector3d &vt);
|
|
XSectionPlane(const AcGePoint3d &pt0, const AcGePoint3d &pt1, const AcGePoint3d &pt2, const AcGeVector3d &vt);
|
|
XSectionPlane(const AcDbFace &face, const AcGeVector3d &vt);
|
|
XSectionPlane(const XPoly2D &poly, const AcGeVector3d &vt)
|
|
: m_poly(poly), m_bPoly(true), m_vtNormal(vt){}
|
|
~XSectionPlane(){};
|
|
|
|
// 以下三个函数 只在 XSectionPlane 为标准面时有效
|
|
void set(const AcGePoint3d &pt0, const AcGePoint3d &pt1, const AcGePoint3d &pt2, const AcGePoint3d &pt3);
|
|
void set(const AcGePoint3d &pt0, const AcGePoint3d &pt1, const AcGePoint3d &pt2);
|
|
void set(int nIdx, const AcGePoint3d &pt);
|
|
// end
|
|
|
|
void set(const XSectionPlane& plane);
|
|
|
|
// 以下三个函数 只在 XSectionPlane 为标准面时有效
|
|
AcGePoint3d get(int nIdx) const;
|
|
void get(AcGePoint3d &pt0, AcGePoint3d &pt1, AcGePoint3d &pt2, AcGePoint3d &pt3) const;
|
|
void get(AcGePoint3d &pt0, AcGePoint3d &pt1, AcGePoint3d &pt2) const;
|
|
// end
|
|
|
|
/*
|
|
pt0___________pt1
|
|
| |
|
|
|___________|
|
|
pt3 pt2
|
|
|
|
nIdx | start | end |
|
|
0 | pt0 | pt1 |
|
|
1 | pt1 | pt2 |
|
|
2 | pt2 | pt3 |
|
|
3 | pt3 | pt0 |
|
|
*/
|
|
AcGeLineSeg3d get_seg(int nIdx) const;
|
|
void get_seg(AcGeLineSeg3d &seg01, AcGeLineSeg3d &seg12, AcGeLineSeg3d &seg23, AcGeLineSeg3d &seg30) const;
|
|
|
|
// 以下三个函数 只在 XSectionPlane 为标准面时有效
|
|
AcGePlane AsAcGePlane() const;
|
|
AcGeBoundedPlane AsAcGeBoundedPlane() const;
|
|
void AsAcDbFace(AcDbFace &fa) const;
|
|
// end
|
|
|
|
// 判断 segment 与 plane 的四条边是否有交点
|
|
bool intersect_with_segment(const AcGeLineSeg3d &in_seg, std::vector<AcGePoint3d> &arPts) const;
|
|
// 判断 ray 与 plane 的四条边是否有交点
|
|
bool intersect_with_ray(AcGeRay3d &in_ray, std::vector<AcGePoint3d> &arPts) const;
|
|
|
|
AcGeVector3d normal() const {return m_vtNormal;}
|
|
void set_normal(const AcGeVector3d &vt){m_vtNormal = vt;}
|
|
|
|
XSectionPlane& operator = (const XSectionPlane &face);
|
|
|
|
double Distance(const XSectionPlane &plane) const;
|
|
|
|
XPoly2D GetPoly() const;
|
|
void SetPoly(const XPoly2D &poly){m_poly = poly;}
|
|
|
|
bool IsPoly() const {return m_bPoly;}
|
|
void SetIsPoly(const bool bPoly){m_bPoly = bPoly;}
|
|
|
|
int GetSegmentCount() const ;
|
|
|
|
bool IsOn(const AcGePoint3d &pt, const bool b3D = false) const;
|
|
|
|
private:
|
|
AcGePoint3d m_pt0, m_pt1, m_pt2, m_pt3;
|
|
AcGeVector3d m_vtNormal;
|
|
XPoly2D m_poly;
|
|
bool m_bPoly;
|
|
};
|
|
|
|
typedef std::vector<XSectionPlane> XSectionSolid;
|
|
|
|
class GEOAPI ObjSectionRecord // 每个实体,被分解为多个ObjSectionRecord对象
|
|
{
|
|
public:
|
|
|
|
enum SectionType
|
|
{
|
|
eAEC_ELEVTION,// 地面线专用
|
|
eAEC_WALL,
|
|
eAEC_CORNER_WINDOW,
|
|
eAEC_COLUMN,
|
|
eAEC_OPENING,
|
|
eAEC_TRENCH,
|
|
e3DFACE,
|
|
eAEC_TESTSECTIONPLANE,
|
|
eAEC_TESTSECTIONLINE,
|
|
eAEC_PIPE,
|
|
eAEC_PIPEVALVE,
|
|
eAEC_DBHVACDUCT,
|
|
eAEC_DBHEQUIPMENT,
|
|
eAEC_DBHFITTING,
|
|
eAEC_RADIATOR,
|
|
eAEC_CABLETRY,
|
|
eAEC_EEQUIPMENT,
|
|
eAEC_EFITTING,
|
|
eAEC_EQUIPMENT,
|
|
eAEC_DOUBLELINEPIPE,
|
|
eAEC_FLANGE,
|
|
eAEC_PUMP,
|
|
eAEC_PIPEFITTING,
|
|
eAEC_VPIPEDIM,
|
|
};
|
|
|
|
ObjSectionRecord(): m_nSectionPos(0), m_eEntity(eAEC_WALL), m_arLines(0), m_dElevation(0.){m_iD.setNull();m_layerID.setNull();}
|
|
|
|
ObjSectionRecord(const AcDbObjectId &id, const AcDbObjectId &layerid, const SectionType type, const double &elevation,
|
|
const XPoly2D &poly, const int pos = 0);
|
|
|
|
ObjSectionRecord(const ObjSectionRecord &record);
|
|
|
|
ObjSectionRecord & operator = (const ObjSectionRecord &record);
|
|
|
|
void TransFormBy(AcGeMatrix3d mat);
|
|
|
|
bool operator < (const ObjSectionRecord &record) const;
|
|
|
|
bool operator > (const ObjSectionRecord &record) const;
|
|
|
|
bool operator >= (const double & dEle) const;
|
|
bool operator <= (const double & dEle) const;
|
|
|
|
void SetSectionLinesElevation(const double &elev);
|
|
|
|
void SetElevation(const double &dEle){m_dElevation = dEle;}
|
|
double GetElevation() const {return m_dElevation;}
|
|
|
|
void SetID(const AcDbObjectId &id){m_iD = id;}
|
|
AcDbObjectId GetID() const {return m_iD;}
|
|
|
|
void SetSectionPos(const int &pos){m_nSectionPos = pos;}
|
|
int GetsectionPos() const {return m_nSectionPos;}
|
|
|
|
void SetEntityType(SectionType type){m_eEntity = type;}
|
|
SectionType GetEntityType() const {return m_eEntity;}
|
|
|
|
// bSetSectionLine 变量如果为真,则将m_polyOriginal赋值为poly后,并利用 ConvertPoly2Line() 函数将 m_arLines 添充
|
|
void SetOriginalPoly(const XPoly2D &poly, const bool bSetSectionLine = true);
|
|
const XPoly2D& GetOriginalPoly() const {return m_polyOriginal;}
|
|
void SetOriginalPolyElevation(const double &ele) {m_polyOriginal.SetElevation(ele);}
|
|
|
|
void SetSectionLines(const std::vector<std::pair<int, XLine> > &lines);
|
|
void GetSectionLines(std::vector<std::pair<int, XLine> > &lines)const;
|
|
std::vector<std::pair<int, XLine> >& GetSectionLines(){return m_arLines;}
|
|
|
|
void SetLayerID(const AcDbObjectId &layerid){m_layerID = layerid;}
|
|
AcDbObjectId GetLayerID(){return m_layerID;}
|
|
|
|
Acad::ErrorStatus dwgInFields (AcDbDwgFiler *pFiler);
|
|
|
|
Acad::ErrorStatus dwgOutFields(AcDbDwgFiler *pFiler) const;
|
|
|
|
void ConverPolyLine2Line();// 以 m_polyOriginal 为原型添充到 m_arLines
|
|
|
|
void ConverPolyLine2CoverPoly(); // 算出被遮挡的曲线
|
|
|
|
void SetHideSecitonLines(std::vector<std::pair<int, XLine> > &lines);
|
|
std::vector<std::pair<int, XLine> >& GetHideSectionLines(){return m_arHideLines;}
|
|
|
|
AcGePoint3d GetMaxPt(){return m_ptMax;}
|
|
AcGePoint3d GetMinPt(){return m_ptMin;}
|
|
|
|
private:
|
|
|
|
void GetExtents();
|
|
|
|
private:
|
|
AcDbSoftPointerId m_iD;
|
|
AcDbSoftPointerId m_layerID;
|
|
XPoly2D m_polyOriginal; //原始曲线
|
|
int m_nSectionPos;
|
|
SectionType m_eEntity;
|
|
std::vector<std::pair<int, XLine> > m_arLines; // 经过遮挡运算后的曲线
|
|
std::vector<std::pair<int, XLine> > m_arHideLines; // 经过遮挡运算后被隐藏的曲线
|
|
double m_dElevation; // 距投影面的距离
|
|
AcGePoint3d m_ptMax; // 外接矩形的最大点
|
|
AcGePoint3d m_ptMin; // 外接矩形的最小点
|
|
};
|
|
|
|
|
|
struct GEOAPI SectionInfo // 保存 投影面的几何信息 和 参加运算的实体id
|
|
{
|
|
std::vector<AcDbObjectId> m_arObjID; // 参加运算的实体id
|
|
AcGePoint3d m_ptS; // 投影面起点
|
|
AcGePoint3d m_ptE; // 投影面终点
|
|
AcGeVector3d m_vecDir; // 投影方向
|
|
XSectionPlane m_SectionFace; // 投影面
|
|
AcGePoint2d m_Height; // 投影面的高(Z方向) x 顶高, y 底高
|
|
CString m_sName; // 投影面的序号
|
|
};
|
|
|
|
struct GEOAPI BlockRefInfo
|
|
{
|
|
AcDbSoftPointerId m_idBlock;
|
|
AcDbSoftPointerId m_idBlockClone; // 此ID 由 m_idBlock 深度克隆而来
|
|
AcGeScale3d m_Scale;
|
|
AcGePoint3d m_ptPos; // 投影后的插入点
|
|
double m_dHeight; // 距投影面的距离 负值
|
|
AcGePoint3d m_ptMax, m_ptMin; // 图形块投影后的范围
|
|
|
|
BlockRefInfo(const AcDbObjectId &id, const AcGeScale3d &scale,
|
|
const AcGePoint3d &pt, const double &height,
|
|
const AcGePoint3d &ptMax, const AcGePoint3d &ptMin)
|
|
: m_idBlock(id), m_Scale(scale), m_ptPos(pt),
|
|
m_dHeight(height), m_ptMax(ptMax), m_ptMin(ptMin){}
|
|
|
|
BlockRefInfo(const BlockRefInfo &block) : m_idBlock(block.m_idBlock),
|
|
m_idBlockClone(block.m_idBlockClone), m_Scale(block.m_Scale),
|
|
m_ptPos(block.m_ptPos), m_dHeight(block.m_dHeight), m_ptMax(block.m_ptMax),
|
|
m_ptMin(block.m_ptMin){}
|
|
|
|
BlockRefInfo()
|
|
: m_Scale(AcGeScale3d(0., 0., 0.)),
|
|
m_ptPos(AcGePoint3d(0., 0., 0.)), m_dHeight(0.),
|
|
m_ptMax(m_ptPos), m_ptMin(m_ptPos){m_idBlock.setNull();m_idBlockClone.setNull();}
|
|
|
|
BlockRefInfo & operator = (const BlockRefInfo &block)
|
|
{
|
|
if(this != &block)
|
|
{
|
|
m_idBlock = block.m_idBlock;
|
|
m_idBlockClone = block.m_idBlockClone;
|
|
m_Scale = block.m_Scale;
|
|
m_ptPos = block.m_ptPos;
|
|
m_ptMax = block.m_ptMax;
|
|
m_ptMin = block.m_ptMin;
|
|
m_dHeight = block.m_dHeight;
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
bool operator < (const BlockRefInfo &block) const
|
|
{
|
|
return m_dHeight < block.m_dHeight;
|
|
}
|
|
|
|
Acad::ErrorStatus dwgInFields (AcDbDwgFiler *pFiler);
|
|
|
|
Acad::ErrorStatus dwgOutFields(AcDbDwgFiler *pFiler) const;
|
|
|
|
XPoly2D ToPoly2D();
|
|
|
|
void TransformBy(const AcGeMatrix3d &mat);
|
|
|
|
void InitCoverBlockID();
|
|
};
|
|
|
|
class GEOAPI XSectionFill
|
|
{
|
|
public:
|
|
XSectionFill(){}; // 默认构造,最好不用,省得少加参数
|
|
|
|
XSectionFill(const XSectionFill &fill)
|
|
:m_BlockRef(fill.m_BlockRef), m_Segments(fill.m_Segments),
|
|
m_bBlock(m_bBlock), m_bCoverBlock(fill.m_bCoverBlock),
|
|
m_dElevtion(fill.m_dElevtion), m_layerID(fill.m_layerID){}
|
|
|
|
XSectionFill(const std::vector<XLine> &segs, const double &ele, const AcDbObjectId &layerid)
|
|
: m_Segments(segs), m_bBlock(false), m_bCoverBlock(false),
|
|
m_dElevtion(ele), m_layerID(layerid){} // 添充线构造函数
|
|
|
|
XSectionFill(const BlockRefInfo &block, const AcDbObjectId &layerid)
|
|
: m_BlockRef(block), m_bBlock(true), m_bCoverBlock(false),
|
|
m_dElevtion(0.), m_layerID(layerid){} // 图形块构造函数
|
|
|
|
~XSectionFill(){};
|
|
|
|
XSectionFill& operator = (const XSectionFill &fill);
|
|
|
|
public:
|
|
// 串行化
|
|
Acad::ErrorStatus dwgInFields (AcDbDwgFiler *pFiler);
|
|
Acad::ErrorStatus dwgOutFields(AcDbDwgFiler *pFiler) const;
|
|
Acad::ErrorStatus dxfInFields (AcDbDxfFiler *pFiler);
|
|
Acad::ErrorStatus dxfOutFields(AcDbDxfFiler *pFiler) const;
|
|
|
|
// 是否是图形块
|
|
bool IsBlockRef() const {return m_bBlock;}
|
|
bool SetBlockRef(const bool block){return m_bBlock = block;}
|
|
|
|
// 图块信息
|
|
void GetBlockRefInfo(BlockRefInfo &block) const{block = m_BlockRef;}
|
|
BlockRefInfo& GetBlockRefInfo(){return m_BlockRef;}
|
|
void SetBlockRefInfo(const BlockRefInfo &block){m_BlockRef = block;}
|
|
|
|
// 添充线
|
|
std::vector<XLine>& GetSegments(){return m_Segments;}
|
|
void SetSegments(const std::vector<XLine>& segs){m_Segments.assign(segs.begin(), segs.end());}
|
|
|
|
std::vector<XLine>& GetHideSegments(){return m_HideSegments;}
|
|
void SetHideSegments(const std::vector<XLine>& segs){m_HideSegments.assign(segs.begin(), segs.end());}
|
|
|
|
void TransformBy(const AcGeMatrix3d &mat);
|
|
|
|
AcDbObjectId GetBlockRefID(){return m_bCoverBlock ? m_BlockRef.m_idBlockClone : m_BlockRef.m_idBlock;}
|
|
|
|
void SetBlockCover(const bool bCover){m_bCoverBlock = bCover;}
|
|
|
|
void SetElevation(const double &ele){m_dElevtion = ele;}
|
|
double GetElevation(){return m_dElevtion;}
|
|
|
|
void InsertLine(const XLine &line){m_Segments.push_back(line);}
|
|
|
|
void SetLayer(const AcDbObjectId &id){m_layerID = id;}
|
|
AcDbObjectId GetLayer(){return m_layerID;}
|
|
|
|
void InitBlockCoverId();
|
|
|
|
private:
|
|
BlockRefInfo m_BlockRef; // 图形块信息
|
|
std::vector<XLine> m_Segments; // 处理前保存原始添充线集合,处理后保存遮挡运算后的集合
|
|
std::vector<XLine> m_HideSegments; // 保存被遮挡的添充线
|
|
bool m_bBlock; // 是否是图形块
|
|
bool m_bCoverBlock; // 图形块是否被遮挡? true 被遮挡
|
|
double m_dElevtion; // 添充线距投影面的距离 负值
|
|
AcDbSoftPointerId m_layerID; // 添充线所在图层的ID
|
|
};
|
|
|
|
#endif
|