LibreCAD
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
text.cpp
Go to the documentation of this file.
1 #include "text.h"
2 #include <algorithm>
3 #include "cad/geometry/geoarea.h"
4 
5 
6 using namespace lc;
7 using namespace entity;
8 
9 Text::Text(const geo::Coordinate& insertion_point,
10  const std::string text_value,
11  const double height,
12  const double angle,
13  const std::string style,
14  const TextConst::DrawingDirection textgeneration,
15  const TextConst::HAlign halign,
16  const TextConst::VAlign valign,
17  const Layer_CSPtr layer,
18  const MetaInfo_CSPtr metaInfo,
19  const Block_CSPtr block) :
20  CADEntity(layer, metaInfo, block),
21  _insertion_point(insertion_point),
22  _text_value(text_value),
23  _height(height),
24  _angle(angle),
25  _style(style),
26  _textgeneration(textgeneration),
27  _valign(valign),
28  _halign(halign) {
29 }
30 
31 Text::Text(const Text_CSPtr& other, bool sameID) : CADEntity(other, sameID),
32  _insertion_point(other->_insertion_point),
33  _text_value(other->_text_value),
34  _height(other->_height),
35  _angle(other->_angle),
36  _style(other->_style),
37  _textgeneration(other->_textgeneration),
38  _valign(other->_valign),
39  _halign(other->_halign) {
40 }
41 
42 CADEntity_CSPtr Text::move(const geo::Coordinate& offset) const {
43  auto newText = std::make_shared<Text>(this->_insertion_point + offset,
44  this->_text_value,
45  this->_height,
46  this->_angle,
47  this->_style,
48  this->_textgeneration,
49  this->_halign,
50  this->_valign,
51  layer(),
52  metaInfo());
53  newText->setID(this->id());
54  return newText;
55 }
56 
57 CADEntity_CSPtr Text::copy(const geo::Coordinate& offset) const {
58  auto newText = std::make_shared<Text>(
59  this->_insertion_point + offset,
60  this->_text_value,
61  this->_height,
62  this->_angle,
63  this->_style,
64  this->_textgeneration,
65  this->_halign,
66  this->_valign,
67  layer(),
68  metaInfo());
69  newText->setID(this->id());
70  return newText;
71 }
72 
73 CADEntity_CSPtr Text::rotate(const geo::Coordinate& rotation_center, const double rotation_angle) const {
74  auto newText = std::make_shared<Text>(
75  this->_insertion_point.rotate(rotation_center, rotation_angle),
76  this->_text_value,
77  this->_height,
78  this->_angle,
79  this->_style,
80  this->_textgeneration,
81  this->_halign,
82  this->_valign,
83  layer(),
84  metaInfo());
85  return newText;
86 }
87 
88 CADEntity_CSPtr Text::scale(const geo::Coordinate& scale_center, const geo::Coordinate& scale_factor) const {
89  auto newText = std::make_shared<Text>(
90  this->_insertion_point.scale(scale_center, scale_factor),
91  this->_text_value,
92  this->_height * std::sqrt(scale_factor.x() * scale_factor.y()), // Does this make sense?
93  this->_angle,
94  this->_style,
95  this->_textgeneration,
96  this->_halign,
97  this->_valign,
98  this->layer(),
99  this->metaInfo());
100  newText->setID(this->id());
101  return newText;
102 }
103 
105  // TODO create bounding box for text
106  return geo::Area(geo::Coordinate(0., 0.), geo::Coordinate(0., 0.));
107 }
108 
109 CADEntity_CSPtr Text::modify(Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo, Block_CSPtr block) const {
110  auto newText = std::make_shared<Text>(
111  this->_insertion_point,
112  this->_text_value,
113  this->_height,
114  this->_angle,
115  this->_style,
116  this->_textgeneration,
117  this->_halign,
118  this->_valign,
119  layer,
120  metaInfo,
121  block
122  );
123  newText->setID(this->id());
124 
125  return newText;
126 }
127 
128 std::map<unsigned int, lc::geo::Coordinate> Text::dragPoints() const {
129  std::map<unsigned int, geo::Coordinate> dragPoints;
130 
131  dragPoints[0] = _insertion_point;
132 
133  return dragPoints;
134 }
135 
136 CADEntity_CSPtr Text::setDragPoints(std::map<unsigned int, lc::geo::Coordinate> dragPoints) const {
137  try {
138  auto newEntity = std::make_shared<Text>(dragPoints.at(0), text_value(), height(), angle(), style(), textgeneration(), halign(), valign(), layer(), metaInfo());
139  newEntity->setID(id());
140  return newEntity;
141  }
142  catch(std::out_of_range& e) {
143  return shared_from_this();
144  }
145 }
std::string const & style() const
Definition: text.h:70
double x() const
Returns x of Coordinate.
Definition: geocoordinate.h:26
const TextConst::HAlign _halign
Definition: text.h:55
virtual CADEntity_CSPtr copy(const geo::Coordinate &offset) const override
copy, copies line by an offset
Definition: text.cpp:57
double height() const
Definition: text.h:86
virtual CADEntity_CSPtr setDragPoints(std::map< unsigned int, lc::geo::Coordinate > dragPoints) const override
Return modified entity.
Definition: text.cpp:136
const TextConst::VAlign _valign
Definition: text.h:54
Layer_CSPtr layer() const
layer return the layer this entity is placed on
Definition: cadentity.cpp:29
double y() const
Returns y of Coordinate.
Definition: geocoordinate.h:34
Coordinate scale(const double &scale_factor) const
const std::string _style
Definition: text.h:52
virtual const geo::Area boundingBox() const override
boundingBox of the entity
Definition: text.cpp:104
virtual CADEntity_CSPtr scale(const geo::Coordinate &scale_center, const geo::Coordinate &scale_factor) const override
scale, scales the entity
Definition: text.cpp:88
const TextConst::DrawingDirection _textgeneration
Definition: text.h:53
MetaInfo_CSPtr metaInfo() const
Definition: cadentity.h:123
std::string const & text_value() const
Definition: text.h:62
const geo::Coordinate _insertion_point
Definition: text.h:48
Definition: cadentity.h:12
double const angle() const
Definition: text.h:66
Text(const geo::Coordinate &insertion_point, const std::string text_value, const double height, const double angle, const std::string style, const TextConst::DrawingDirection textgeneration, const TextConst::HAlign halign, const TextConst::VAlign valign, const Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo=nullptr, const Block_CSPtr block=nullptr)
Text, default constructor.
Definition: text.cpp:9
Coordinate rotate(const Coordinate &angleVector) const
rotate around (0.,0.) with a given angle vector
virtual std::map< unsigned int, lc::geo::Coordinate > dragPoints() const override
Get all points of the entity that can be dragged.
Definition: text.cpp:128
const double _angle
Definition: text.h:51
virtual CADEntity_CSPtr rotate(const geo::Coordinate &rotation_center, const double rotation_angle) const override
rotate, rotate operation
Definition: text.cpp:73
const double _height
Definition: text.h:50
Block_CSPtr block() const
Return the current entity block.
Definition: cadentity.cpp:33
TextConst::VAlign const & valign() const
Definition: text.h:78
TextConst::HAlign const & halign() const
Definition: text.h:82
const std::string _text_value
Definition: text.h:49
TextConst::DrawingDirection const & textgeneration() const
Definition: text.h:74
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: text.cpp:109
virtual CADEntity_CSPtr move(const geo::Coordinate &offset) const override
move, moves by an offset
Definition: text.cpp:42