LibreCAD
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dimaligned.cpp
Go to the documentation of this file.
1 #include <map>
3 
4 
5 using namespace lc;
6 using namespace entity;
7 
8 DimAligned::DimAligned(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& definitionPoint2,
16  geo::Coordinate const& definitionPoint3,
17  const Layer_CSPtr layer,
18  const MetaInfo_CSPtr metaInfo,
19  const Block_CSPtr block):
20  CADEntity(layer, metaInfo, block),
21  Dimension(definitionPoint, middleOfText, attachmentPoint, textAngle, lineSpacingFactor, lineSpacingStyle, explicitValue),
22  _definitionPoint2(definitionPoint2),
23  _definitionPoint3(definitionPoint3) {
24 
25 }
26 
27 
28 DimAligned::DimAligned(const DimAligned_CSPtr other, bool sameID) :
29  CADEntity(other, sameID),
30  Dimension(*other),
31  _definitionPoint2(other->_definitionPoint2),
32  _definitionPoint3(other->_definitionPoint3) {
33 }
34 
35 DimAligned_SPtr DimAligned::dimAuto(geo::Coordinate const& p1,
36  geo::Coordinate const& p2,
37  geo::Coordinate const& middleOfText,
38  std::string const& explicitValue,
39  const Layer_CSPtr layer,
40  const MetaInfo_CSPtr metaInfo,
41  const Block_CSPtr block) {
42  auto nearestPoint = geo::Vector(p1, p2).nearestPointOnPath(middleOfText);
43  auto distance = nearestPoint.distanceTo(middleOfText);
44 
45  geo::Coordinate dir;
46  if(((p2.x() - p1.x()) * (middleOfText.y() - p1.y()) - (p2.y() - p1.y()) * (middleOfText.x() - p1.x())) >= 0) {
47  dir = (p2 - p1).rotate(0.5 * M_PI);
48  }
49  else {
50  dir = (p2 - p1).rotate(-0.5 * M_PI);
51  }
52 
53  geo::Coordinate p0 = p2.move(dir, distance);
54 
55  return std::make_shared<DimAligned>(p0,
57  TextConst::AttachmentPoint::Top_center,
58  0.,
59  0.,
60  TextConst::LineSpacingStyle::AtLeast,
62  p1,
63  p2,
64  layer,
65  metaInfo,
66  block
67  );
68 }
69 
70 
71 
72 CADEntity_CSPtr DimAligned::move(const geo::Coordinate& offset) const {
73  auto newDimAligned = std::make_shared<DimAligned>(this->definitionPoint() + offset, this->middleOfText() + offset, this->attachmentPoint(), this->textAngle(), this->lineSpacingFactor(), this->lineSpacingStyle(), this->explicitValue(), this->_definitionPoint2 + offset, this->_definitionPoint3 + offset, this->layer(), this->metaInfo());
74  newDimAligned->setID(this->id());
75  return newDimAligned;
76 }
77 
78 CADEntity_CSPtr DimAligned::copy(const geo::Coordinate& offset) const {
79  auto newDimAligned = std::make_shared<DimAligned>(this->definitionPoint() + offset, this->middleOfText() + offset, this->attachmentPoint(), this->textAngle(), this->lineSpacingFactor(), this->lineSpacingStyle(), this->explicitValue(), this->_definitionPoint2 + offset, this->_definitionPoint3 + offset, this->layer(), this->metaInfo());
80  return newDimAligned;
81 }
82 
83 CADEntity_CSPtr DimAligned::rotate(const geo::Coordinate& rotation_center, const double rotation_angle) const {
84  auto newDimAligned = std::make_shared<DimAligned>(this->definitionPoint().rotate(rotation_center, rotation_angle),
85  this->middleOfText().rotate(rotation_center, rotation_angle), this->attachmentPoint(), this->textAngle(), this->lineSpacingFactor(), this->lineSpacingStyle(), this->explicitValue(), this->_definitionPoint2.rotate(rotation_center, rotation_angle), this->_definitionPoint3.rotate(rotation_center, rotation_angle), this->layer(), this->metaInfo());
86  return newDimAligned;
87 }
88 
89 CADEntity_CSPtr DimAligned::scale(const geo::Coordinate& scale_center, const geo::Coordinate& scale_factor) const {
90  auto newDimAligned = std::make_shared<DimAligned>(this->definitionPoint().scale(scale_center, scale_factor),
91  this->middleOfText().scale(scale_center, scale_factor), this->attachmentPoint(), this->textAngle(), this->lineSpacingFactor(), this->lineSpacingStyle(), this->explicitValue(), this->_definitionPoint2.scale(scale_center, scale_factor), this->_definitionPoint3.scale(scale_center, scale_factor), this->layer(), this->metaInfo());
92  return newDimAligned;
93 }
94 
95 CADEntity_CSPtr DimAligned::mirror(const geo::Coordinate& axis1,
96  const geo::Coordinate& axis2) const {
97 
98  auto newDimAligned = std::make_shared<DimAligned>(this->definitionPoint().mirror(axis1, axis2),
99  this->middleOfText().mirror(axis1, axis2), this->attachmentPoint(), this->textAngle(), this->lineSpacingFactor(), this->lineSpacingStyle(), this->explicitValue(), this->_definitionPoint2.mirror(axis1, axis2), this->_definitionPoint3.mirror(axis1, axis2), this->layer(), this->metaInfo());
100  return newDimAligned;
101 }
102 
104  // TODO create proper bounding box for DimAligned
105  return geo::Area(this->middleOfText(), 0., 0.);
106 }
107 
108 CADEntity_CSPtr DimAligned::modify(Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo, Block_CSPtr block) const {
109  auto newDimAligned = std::make_shared<DimAligned>(
110  this->definitionPoint(),
111  this->middleOfText(),
112  this->attachmentPoint(),
113  this->textAngle(),
114  this->lineSpacingFactor(),
115  this->lineSpacingStyle(),
116  this->explicitValue(),
117  this->_definitionPoint2,
118  this->_definitionPoint3,
119  layer,
120  metaInfo,
121  block
122  );
123 
124  return newDimAligned;
125 }
126 
128  return _definitionPoint2;
129 }
131  return _definitionPoint3;
132 }
133 
134 std::map<unsigned int, geo::Coordinate> DimAligned::dragPoints() const {
135  std::map<unsigned int, geo::Coordinate> dragPoints;
136 
137  dragPoints[0] = definitionPoint();
138  dragPoints[1] = middleOfText();
139  dragPoints[2] = _definitionPoint2;
140  dragPoints[3] = _definitionPoint3;
141 
142  return dragPoints;
143 }
144 
145 
146 CADEntity_CSPtr DimAligned::setDragPoints(std::map<unsigned int, lc::geo::Coordinate> dragPoints) const {
147  try {
148  auto newEntity = std::make_shared<DimAligned>(dragPoints.at(0),
149  dragPoints.at(1),
150  attachmentPoint(),
151  textAngle(),
154  explicitValue(),
155  dragPoints.at(2),
156  dragPoints.at(3),
157  layer(),
158  metaInfo());
159  newEntity->setID(id());
160  return newEntity;
161  }
162  catch(std::out_of_range& e) {
163  return shared_from_this();
164  }
165 }
166 
Coordinate mirror(const Coordinate &axis1, const Coordinate &axis2) const
mirror a coordinate
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: dimaligned.cpp:108
const geo::Coordinate _definitionPoint2
Definition: dimaligned.h:93
double x() const
Returns x of Coordinate.
Definition: geocoordinate.h:26
TextConst::LineSpacingStyle lineSpacingStyle() const
Definition: dimension.cpp:91
const geo::Coordinate & definitionPoint() const noexcept
move, moves by an offset
Definition: dimension.cpp:71
static DimAligned_SPtr dimAuto(geo::Coordinate const &p1, geo::Coordinate const &p2, geo::Coordinate const &middleOfText, std::string const &explicitValue, const Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo=nullptr, const Block_CSPtr block=nullptr)
Definition: dimaligned.cpp:35
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
const geo::Coordinate & definitionPoint3() const noexcept
Definition: dimaligned.cpp:130
const geo::Coordinate & definitionPoint2() const noexcept
Definition: dimaligned.cpp:127
double y() const
Returns y of Coordinate.
Definition: geocoordinate.h:34
Coordinate scale(const double &scale_factor) const
virtual CADEntity_CSPtr mirror(const geo::Coordinate &axis1, const geo::Coordinate &axis2) const override
Definition: dimaligned.cpp:95
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
virtual CADEntity_CSPtr move(const geo::Coordinate &offset) const override
move, moves by an offset
Definition: dimaligned.cpp:72
virtual const geo::Area boundingBox() const override
boundingBox of the entity
Definition: dimaligned.cpp:103
Coordinate rotate(const Coordinate &angleVector) const
rotate around (0.,0.) with a given angle vector
virtual CADEntity_CSPtr copy(const geo::Coordinate &offset) const override
copy, copies by an offset
Definition: dimaligned.cpp:78
Coordinate move(const Coordinate &direction, double d) const
const Coordinate nearestPointOnPath(const Coordinate &coord) const
Definition: geovector.h:39
double lineSpacingFactor() const
Definition: dimension.cpp:87
Block_CSPtr block() const
Return the current entity block.
Definition: cadentity.cpp:33
#define M_PI
Definition: const.h:16
virtual CADEntity_CSPtr rotate(const geo::Coordinate &rotation_center, const double rotation_angle) const override
rotate, rotate operation
Definition: dimaligned.cpp:83
virtual CADEntity_CSPtr setDragPoints(std::map< unsigned int, lc::geo::Coordinate > dragPoints) const override
Return modified entity.
Definition: dimaligned.cpp:146
virtual CADEntity_CSPtr scale(const geo::Coordinate &scale_center, const geo::Coordinate &scale_factor) const override
scale, scales the entity
Definition: dimaligned.cpp:89
double textAngle() const
Definition: dimension.cpp:79
const geo::Coordinate _definitionPoint3
Definition: dimaligned.h:94
virtual std::map< unsigned int, lc::geo::Coordinate > dragPoints() const override
Get all points of the entity that can be dragged.
Definition: dimaligned.cpp:134
double distanceTo(const geo::Coordinate &c) const
DimAligned(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 &definitionPoint2, geo::Coordinate const &definitionPoint3, const Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo=nullptr, const Block_CSPtr block=nullptr)
DimAligned, DimAligned constructor with metatypes.
Definition: dimaligned.cpp:8