LibreCAD
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dimdiametric.cpp
Go to the documentation of this file.
2 
3 using namespace lc;
4 using namespace entity;
5 
7  geo::Coordinate const& middleOfText,
8  TextConst::AttachmentPoint const& attachmentPoint,
9  double angle,
10  double const lineSpacingFactor,
11  TextConst::LineSpacingStyle const& lineSpacingStyle,
12  std::string const& explicitValue,
13  geo::Coordinate const& definitionPoint2,
14  const double leader,
15  const Layer_CSPtr layer,
16  const MetaInfo_CSPtr metaInfo,
17  const Block_CSPtr block) :
18  CADEntity(layer, metaInfo, block),
19  Dimension(definitionPoint, middleOfText, attachmentPoint, angle, lineSpacingFactor, lineSpacingStyle, explicitValue),
20  _leader(leader),
21  _definitionPoint2(definitionPoint2) {
22 
23 }
24 
26  TextConst::AttachmentPoint const& attachmentPoint,
27  double const lineSpacingFactor,
28  TextConst::LineSpacingStyle const& lineSpacingStyle,
29  std::string const& explicitValue,
30  geo::Coordinate const& definitionPoint2,
31  const double leader,
32  const Layer_CSPtr layer,
33  const MetaInfo_CSPtr metaInfo,
34  const Block_CSPtr block) :
35  CADEntity(layer, metaInfo, block),
36  Dimension(definitionPoint, definitionPoint.mid(definitionPoint2), attachmentPoint, 0., lineSpacingFactor, lineSpacingStyle, explicitValue),
37  _leader(leader),
38  _definitionPoint2(definitionPoint2) {
39 }
40 
41 DimDiametric::DimDiametric(const DimDiametric_CSPtr other, bool sameID) :
42  CADEntity(other, sameID),
43  Dimension(*other),
44  _leader(other->_leader),
45  _definitionPoint2(other->definitionPoint2()) {
46 
47 }
48 
49 CADEntity_CSPtr DimDiametric::move(const geo::Coordinate& offset) const {
50  auto newDimDiametric = std::make_shared<DimDiametric>(this->definitionPoint() + offset, this->middleOfText() + offset, this->attachmentPoint(), this->textAngle(), this->lineSpacingFactor(), this->lineSpacingStyle(), this->explicitValue(), this->_definitionPoint2 + offset, this->_leader, this->layer(), this->metaInfo());
51  newDimDiametric->setID(this->id());
52  return newDimDiametric;
53 }
54 
55 CADEntity_CSPtr DimDiametric::copy(const geo::Coordinate& offset) const {
56  auto newDimDiametric = std::make_shared<DimDiametric>(this->definitionPoint() + offset, this->middleOfText() + offset, this->attachmentPoint(), this->textAngle(), this->lineSpacingFactor(), this->lineSpacingStyle(), this->explicitValue(), this->_definitionPoint2 + offset, this->_leader, this->layer(), this->metaInfo());
57  return newDimDiametric;
58 }
59 
60 CADEntity_CSPtr DimDiametric::rotate(const geo::Coordinate& rotation_center, const double rotation_angle) const {
61  auto newDimDiametric = std::make_shared<DimDiametric>(this->definitionPoint().rotate(rotation_center, rotation_angle),
62  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->_leader, this->layer(), this->metaInfo());
63  return newDimDiametric;
64 }
65 
66 CADEntity_CSPtr DimDiametric::scale(const geo::Coordinate& scale_center, const geo::Coordinate& scale_factor) const {
67  auto newDimDiametric = std::make_shared<DimDiametric>(this->definitionPoint().scale(scale_center, scale_factor),
68  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->_leader, this->layer(), this->metaInfo());
69  return newDimDiametric;
70 }
71 
72 CADEntity_CSPtr DimDiametric::mirror(const geo::Coordinate& axis1, const geo::Coordinate& axis2) const {
73  auto newDimDiametric = std::make_shared<DimDiametric>(this->definitionPoint().mirror(axis1, axis2),
74  this->middleOfText().mirror(axis1, axis2), this->attachmentPoint(), this->textAngle(), this->lineSpacingFactor(), this->lineSpacingStyle(), this->explicitValue(), this->_definitionPoint2.mirror(axis1, axis2), this->_leader, this->layer(), this->metaInfo());
75  return newDimDiametric;
76 }
77 
79  // TODO create proper bounding box for DimLinear
80  return geo::Area(this->middleOfText(), 0., 0.);
81 }
82 
83 CADEntity_CSPtr DimDiametric::modify(Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo, Block_CSPtr block) const {
84  auto newDimDiametric = std::make_shared<DimDiametric>(
85  this->definitionPoint(),
86  this->middleOfText(),
87  this->attachmentPoint(),
88  this->textAngle(),
89  this->lineSpacingFactor(),
90  this->lineSpacingStyle(),
91  this->explicitValue(),
92  this->_definitionPoint2,
93  this->_leader,
94  layer,
95  metaInfo,
96  block
97  );
98 
99  return newDimDiametric;
100 }
101 
102 double DimDiametric::leader() const {
103  return _leader;
104 }
105 
107  return _definitionPoint2;
108 }
109 
110 std::map<unsigned int, geo::Coordinate> DimDiametric::dragPoints() const {
111  std::map<unsigned int, geo::Coordinate> dragPoints;
112 
113  dragPoints[0] = definitionPoint();
114  dragPoints[1] = middleOfText();
115  dragPoints[2] = _definitionPoint2;
116 
117  return dragPoints;
118 }
119 
120 
121 CADEntity_CSPtr DimDiametric::setDragPoints(std::map<unsigned int, lc::geo::Coordinate> dragPoints) const {
122  try {
123  auto newEntity = std::make_shared<DimDiametric>(dragPoints.at(0),
124  dragPoints.at(1),
125  attachmentPoint(),
126  textAngle(),
129  explicitValue(),
130  dragPoints.at(2),
131  leader(),
132  layer(),
133  metaInfo());
134  newEntity->setID(id());
135  return newEntity;
136  }
137  catch(std::out_of_range& e) {
138  return shared_from_this();
139  }
140 }
Coordinate mirror(const Coordinate &axis1, const Coordinate &axis2) const
mirror a coordinate
virtual CADEntity_CSPtr setDragPoints(std::map< unsigned int, lc::geo::Coordinate > dragPoints) const override
Return modified entity.
virtual CADEntity_CSPtr move(const geo::Coordinate &offset) const override
move, moves by an offset
TextConst::LineSpacingStyle lineSpacingStyle() const
Definition: dimension.cpp:91
const geo::Coordinate & definitionPoint() const noexcept
move, moves by an offset
Definition: dimension.cpp:71
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
Coordinate scale(const double &scale_factor) const
const geo::Coordinate _definitionPoint2
Definition: dimdiametric.h:104
MetaInfo_CSPtr metaInfo() const
Definition: cadentity.h:123
virtual CADEntity_CSPtr mirror(const geo::Coordinate &axis1, const geo::Coordinate &axis2) const override
virtual CADEntity_CSPtr scale(const geo::Coordinate &scale_center, const geo::Coordinate &scale_factor) const override
scale, scales the entity
const geo::Coordinate & middleOfText() const noexcept
Definition: dimension.cpp:75
virtual std::map< unsigned int, lc::geo::Coordinate > dragPoints() const override
Get all points of the entity that can be dragged.
TextConst::AttachmentPoint const & attachmentPoint() const
Definition: dimension.cpp:83
Definition: cadentity.h:12
Coordinate rotate(const Coordinate &angleVector) const
rotate around (0.,0.) with a given angle vector
virtual CADEntity_CSPtr rotate(const geo::Coordinate &rotation_center, const double rotation_angle) const override
rotate, rotate operation
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
DimDiametric(geo::Coordinate const &definitionPoint, geo::Coordinate const &middleOfText, TextConst::AttachmentPoint const &attachmentPoint, double angle, double const lineSpacingFactor, TextConst::LineSpacingStyle const &lineSpacingStyle, std::string const &explicitValue, geo::Coordinate const &definitionPoint2, const double leader, const Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo=nullptr, const Block_CSPtr block=nullptr)
DimDiametric.
Definition: dimdiametric.cpp:6
geo::Coordinate definitionPoint2() const
virtual const geo::Area boundingBox() const override
boundingBox of the entity
double textAngle() const
Definition: dimension.cpp:79
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...