-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
cadentity.h
140 lines (118 loc) · 4.88 KB
/
cadentity.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#pragma once
#include "cad/const.h"
#include "cad/base/id.h"
#include "cad/base/metainfo.h"
#include "cad/base/visitor.h"
#include "cad/interface/metatype.h"
#include "cad/meta/layer.h"
#include "cad/geometry/geoarea.h"
namespace lc {
namespace entity {
/**
*Class that all CAD entities must inherit
*
*/
class CADEntity : public ID, virtual public Visitable {
public:
CADEntity() {
}
/*!
* \brief Default CADEntity Constructor.
* \sa lc::ID
* \sa lc::MetaInfo
*/
CADEntity(Layer_CSPtr _layer);
/*!
* \brief CADEntity Constructor
*
* \param metaTypes A list of metatypes associated with this line
* \sa lc::Color
* \sa lc::LineWidth
* \sa lc::MetaType
*/
CADEntity(Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo);
CADEntity(CADEntity_CSPtr cadEntity, bool sameID);
CADEntity(CADEntity_CSPtr cadEntity);
virtual ~CADEntity() = default;
/*!
* \brief Function for Move
*
* \param offset the offset by which entity is to be moved
* \return CADEntity std::shared_ptr
*/
virtual CADEntity_CSPtr move(const geo::Coordinate &offset) const = 0;
/*!
* \brief Function for Copy
*
* \param offset the offset by which entity is to be copied
* \return CADEntity std::shared_ptr
*/
virtual CADEntity_CSPtr copy(const geo::Coordinate &offset) const = 0;
/*!
* \brief Function implementation for rotate.
*
* \param angle angle by which the entity is to be rotated.
* \return CADEntity std::shared_ptr
*/
virtual CADEntity_CSPtr rotate(const geo::Coordinate &rotation_center,
const double rotation_angle) const = 0;
/*!
* \brief Function implementation for Scale.
*
* \param scale_center
* \param scale_factor
* \return CADEntity std::shared_ptr
*/
virtual CADEntity_CSPtr scale(const geo::Coordinate &scale_center,
const geo::Coordinate &scale_factor) const = 0;
virtual CADEntity_CSPtr mirror(const geo::Coordinate& axis1,
const geo::Coordinate& axis2) const = 0;
/**
* @brief boundingBox
* Return the bounding box of this entity.
* This should be as tight around the entity as possible but care should be taken that this routine
* is also as fast as possible. in essense, favor speed over tightness.
* This routine will in generally be used during testing if entities cross for example to find snap points
* and to build relationships of tree for example using quad trees
* @return geo::Area
*/
virtual const geo::Area boundingBox() const = 0;
/**
* @brief modify
* Return a new entity with the same ID bit with possible modified metainfo and/pr layer information
* #return new entity with same ID
*/
virtual CADEntity_CSPtr modify(Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo) const = 0;
/*!
* \brief layer
* return the layer this entity is placed on
* \return Layer_CSPtr
*/
Layer_CSPtr layer() const;
/**
* Retreive meta information back from this entity
* returns nullptr when the specific meta info wasn't found
* example: auto metaData = myEntity.metaInfo<lc::MetaColor>(lc::MetaInfo::_COLOR);
*/
template<typename T>
const std::shared_ptr<const T> metaInfo(std::string metaName) const {
if (_metaInfo && (_metaInfo->find(metaName) != _metaInfo->end())) {
auto a=_metaInfo->at(metaName);
auto b=std::dynamic_pointer_cast<const T>(a);
return b;
}
return nullptr;
}
MetaInfo_CSPtr metaInfo() const {
return _metaInfo;
}
virtual void accept(GeoEntityVisitor &v) const override { v.visit(*this); }
virtual void dispatch(EntityDispatch &) const = 0;
private:
Layer_CSPtr _layer;
MetaInfo_CSPtr _metaInfo;
};
using CADEntity_SPtr = std::shared_ptr<CADEntity>;
using CADEntity_CSPtr = std::shared_ptr<const CADEntity>;
}
}