LibreCAD
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dimangular.cpp
Go to the documentation of this file.
2 
3 
4 using namespace lc;
5 using namespace entity;
6 
8  geo::Coordinate const& definitionPoint,
9  geo::Coordinate const& middleOfText,
10  TextConst::AttachmentPoint const& attachmentPoint,
11  double textAngle,
12  double const lineSpacingFactor,
13  TextConst::LineSpacingStyle const& lineSpacingStyle,
14  std::string const& explicitValue,
15  geo::Coordinate const& defLine11,
16  geo::Coordinate const& defLine12,
17  geo::Coordinate const& defLine21,
18  geo::Coordinate const& defLine22,
19  const Layer_CSPtr layer,
20  const MetaInfo_CSPtr metaInfo,
21  const Block_CSPtr block) :
22  CADEntity(layer, metaInfo, block),
23  Dimension(definitionPoint, middleOfText, attachmentPoint, textAngle, lineSpacingFactor, lineSpacingStyle, explicitValue),
24  _defLine11(defLine11),
25  _defLine12(defLine12),
26  _defLine21(defLine21),
27  _defLine22(defLine22) {
28 
29 }
30 
31 
32 DimAngular::DimAngular(const DimAngular_CSPtr other, bool sameID) :
33  CADEntity(other, sameID),
34  Dimension(*other),
35  _defLine11(other->_defLine11),
36  _defLine12(other->_defLine12),
37  _defLine21(other->_defLine21),
38  _defLine22(other->_defLine22) {
39 }
40 
41 DimAngular_SPtr DimAngular::dimAuto(
42  geo::Coordinate const& center,
43  geo::Coordinate const& p1,
44  geo::Coordinate const& p2,
45  std::string const& explicitValue,
46  const Layer_CSPtr layer,
47  const MetaInfo_CSPtr metaInfo,
48  const Block_CSPtr block) {
49  geo::Coordinate middletext(p1.mid(p2));
50 
51  return std::make_shared<DimAngular>(center,
52  middletext,
53  TextConst::AttachmentPoint::Top_center,
54  0.,
55  0.,
56  TextConst::LineSpacingStyle::AtLeast,
58  center,
59  p1,
60  center,
61  p2,
62  layer,
63  metaInfo,
64  block
65  );
66 }
67 
68 
69 CADEntity_CSPtr DimAngular::move(const geo::Coordinate& offset) const {
70  auto newDimAngular = std::make_shared<DimAngular>(this->definitionPoint() + offset, this->middleOfText() + offset, this->attachmentPoint(), this->textAngle(), this->lineSpacingFactor(), this->lineSpacingStyle(), this->explicitValue(), this->_defLine11 + offset, this->_defLine12 + offset, this->_defLine21 + offset, this->_defLine22 + offset, this->layer(), this->metaInfo());
71  newDimAngular->setID(this->id());
72  return newDimAngular;
73 }
74 
75 CADEntity_CSPtr DimAngular::copy(const geo::Coordinate& offset) const {
76  auto newDimAngular = std::make_shared<DimAngular>(this->definitionPoint() + offset, this->middleOfText() + offset, this->attachmentPoint(), this->textAngle(), this->lineSpacingFactor(), this->lineSpacingStyle(), this->explicitValue(), this->_defLine11 + offset, this->_defLine12 + offset, this->_defLine21 + offset, this->_defLine22 + offset, this->layer(), this->metaInfo());
77  return newDimAngular;
78 }
79 
80 CADEntity_CSPtr DimAngular::rotate(const geo::Coordinate& rotation_center, const double rotation_angle) const {
81  auto newDimAngular = std::make_shared<DimAngular>(this->definitionPoint().rotate(rotation_center, rotation_angle),
82  this->middleOfText().rotate(rotation_center, rotation_angle), this->attachmentPoint(), this->textAngle(), this->lineSpacingFactor(), this->lineSpacingStyle(), this->explicitValue(), this->_defLine11.rotate(rotation_center, rotation_angle), this->_defLine12.rotate(rotation_center, rotation_angle), this->_defLine21.rotate(rotation_center, rotation_angle), this->_defLine22.rotate(rotation_center, rotation_angle), this->layer(), this->metaInfo());
83  return newDimAngular;
84 }
85 
86 CADEntity_CSPtr DimAngular::scale(const geo::Coordinate& scale_center, const geo::Coordinate& scale_factor) const {
87  auto newDimAngular = std::make_shared<DimAngular>(this->definitionPoint().scale(scale_center, scale_factor),
88  this->middleOfText().scale(scale_center, scale_factor), this->attachmentPoint(), this->textAngle(), this->lineSpacingFactor(), this->lineSpacingStyle(), this->explicitValue(), this->_defLine11.scale(scale_center, scale_factor), this->_defLine12.scale(scale_center, scale_factor), this->_defLine21.scale(scale_center, scale_factor), this->_defLine22.scale(scale_center, scale_factor), this->layer(), this->metaInfo());
89  return newDimAngular;
90 }
91 
92 CADEntity_CSPtr DimAngular::mirror(const geo::Coordinate& axis1, const geo::Coordinate& axis2) const {
93  auto newDimAngular = std::make_shared<DimAngular>(this->definitionPoint().mirror(axis1,axis2),
94  this->middleOfText().mirror(axis1,axis2), this->attachmentPoint(), this->textAngle(), this->lineSpacingFactor(), this->lineSpacingStyle(), this->explicitValue(), this->_defLine11.mirror(axis1,axis2), this->_defLine12.mirror(axis1,axis2), this->_defLine21.mirror(axis1,axis2), this->_defLine22.mirror(axis1,axis2), this->layer(), this->metaInfo());
95  return newDimAngular;
96 }
97 
99  // TODO create proper bounding box for DimAngular
100  return geo::Area(this->middleOfText(), 0., 0.);
101 }
102 
103 CADEntity_CSPtr DimAngular::modify(Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo, Block_CSPtr block) const {
104  auto newDimAngular = std::make_shared<DimAngular>(
105  this->definitionPoint(),
106  this->middleOfText(),
107  this->attachmentPoint(),
108  this->textAngle(),
109  this->lineSpacingFactor(),
110  this->lineSpacingStyle(),
111  this->explicitValue(),
112  this->_defLine11,
113  this->_defLine12,
114  this->_defLine21,
115  this->_defLine22,
116  layer,
117  metaInfo,
118  block
119  );
120 
121  return newDimAngular;
122 }
123 
125  return _defLine11;
126 }
127 
129  return _defLine12;
130 }
131 
133  return _defLine21;
134 }
135 
137  return _defLine22;
138 }
139 
140 std::map<unsigned int, geo::Coordinate> DimAngular::dragPoints() const {
141  std::map<unsigned int, geo::Coordinate> dragPoints;
142 
143  dragPoints[0] = definitionPoint();
144  dragPoints[1] = middleOfText();
145  dragPoints[2] = _defLine11;
146  dragPoints[3] = _defLine12;
147  dragPoints[4] = _defLine21;
148  dragPoints[5] = _defLine22;
149 
150  return dragPoints;
151 }
152 
153 
154 CADEntity_CSPtr DimAngular::setDragPoints(std::map<unsigned int, lc::geo::Coordinate> dragPoints) const {
155  try {
156  auto newEntity = std::make_shared<DimAngular>(dragPoints.at(0),
157  dragPoints.at(1),
158  attachmentPoint(),
159  textAngle(),
162  explicitValue(),
163  dragPoints.at(2),
164  dragPoints.at(3),
165  dragPoints.at(4),
166  dragPoints.at(5),
167  layer(),
168  metaInfo());
169  newEntity->setID(id());
170  return newEntity;
171  }
172  catch(std::out_of_range& e) {
173  return shared_from_this();
174  }
175 }
Coordinate mirror(const Coordinate &axis1, const Coordinate &axis2) const
mirror a coordinate
geo::Coordinate defLine21() const
Definition: dimangular.cpp:132
virtual CADEntity_CSPtr rotate(const geo::Coordinate &rotation_center, const double rotation_angle) const override
rotate, rotate operation
Definition: dimangular.cpp:80
DimAngular(geo::Coordinate const &definitionPoint, geo::Coordinate const &middleOfText, TextConst::AttachmentPoint const &attachmentPoint, double textAngle, double const lineSpacingFactor, TextConst::LineSpacingStyle const &lineSpacingStyle, std::string const &explicitValue, geo::Coordinate const &_defLine11, geo::Coordinate const &_defLine12, geo::Coordinate const &_defLine21, geo::Coordinate const &_defLine22, const Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo=nullptr, const Block_CSPtr block=nullptr)
Definition: dimangular.cpp:7
virtual CADEntity_CSPtr setDragPoints(std::map< unsigned int, lc::geo::Coordinate > dragPoints) const override
Return modified entity.
Definition: dimangular.cpp:154
Coordinate mid(const Coordinate &other) const
virtual CADEntity_CSPtr modify(Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo, Block_CSPtr block) const override
modify Return a new entity with the same ID bit with possible modified metainfo and/pr layer informat...
Definition: dimangular.cpp:103
const geo::Coordinate _defLine21
Definition: dimangular.h:97
TextConst::LineSpacingStyle lineSpacingStyle() const
Definition: dimension.cpp:91
const geo::Coordinate & definitionPoint() const noexcept
move, moves by an offset
Definition: dimension.cpp:71
const geo::Coordinate _defLine22
Definition: dimangular.h:98
geo::Coordinate defLine12() const
Definition: dimangular.cpp:128
std::string explicitValue() const
Definition: dimension.cpp:95
Layer_CSPtr layer() const
layer return the layer this entity is placed on
Definition: cadentity.cpp:29
virtual CADEntity_CSPtr mirror(const geo::Coordinate &axis1, const geo::Coordinate &axis2) const override
Definition: dimangular.cpp:92
static DimAngular_SPtr dimAuto(geo::Coordinate const &center, geo::Coordinate const &p1, geo::Coordinate const &p2, std::string const &explicitValue, const Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo=nullptr, const Block_CSPtr block=nullptr)
Definition: dimangular.cpp:41
geo::Coordinate defLine11() const
Definition: dimangular.cpp:124
Coordinate scale(const double &scale_factor) const
MetaInfo_CSPtr metaInfo() const
Definition: cadentity.h:123
const geo::Coordinate & middleOfText() const noexcept
Definition: dimension.cpp:75
TextConst::AttachmentPoint const & attachmentPoint() const
Definition: dimension.cpp:83
Definition: cadentity.h:12
const geo::Coordinate _defLine11
Definition: dimangular.h:95
Coordinate rotate(const Coordinate &angleVector) const
rotate around (0.,0.) with a given angle vector
virtual const geo::Area boundingBox() const override
boundingBox of the entity
Definition: dimangular.cpp:98
double lineSpacingFactor() const
Definition: dimension.cpp:87
Block_CSPtr block() const
Return the current entity block.
Definition: cadentity.cpp:33
virtual CADEntity_CSPtr copy(const geo::Coordinate &offset) const override
copy, copies by an offset
Definition: dimangular.cpp:75
const geo::Coordinate _defLine12
Definition: dimangular.h:96
double textAngle() const
Definition: dimension.cpp:79
virtual std::map< unsigned int, lc::geo::Coordinate > dragPoints() const override
Get all points of the entity that can be dragged.
Definition: dimangular.cpp:140
virtual CADEntity_CSPtr scale(const geo::Coordinate &scale_center, const geo::Coordinate &scale_factor) const override
scale, scales the entity
Definition: dimangular.cpp:86
virtual CADEntity_CSPtr move(const geo::Coordinate &offset) const override
move, moves by an offset
Definition: dimangular.cpp:69
geo::Coordinate defLine22() const
Definition: dimangular.cpp:136