LibreCAD
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lc::entity::LWPolyline Class Reference

#include <lwpolyline.h>

Inheritance diagram for lc::entity::LWPolyline:
Collaboration diagram for lc::entity::LWPolyline:

Public Member Functions

 LWPolyline (const std::vector< LWVertex2D > &vertex, double width, double elevation, double tickness, bool closed, geo::Coordinate const &extrusionDirection, const Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo=nullptr, const Block_CSPtr block=nullptr)
 
 LWPolyline (const LWPolyline_CSPtr other, bool sameID=false)
 
double width () const
 
double elevation () const
 
double tickness () const
 
geo::Coordinate const & extrusionDirection () const
 
std::vector< LWVertex2D > const & vertex () const
 
bool closed () const
 
virtual std::vector
< EntityCoordinate
snapPoints (const geo::Coordinate &coord, const SimpleSnapConstrain &constrain, double minDistanceToSnap, int maxNumberOfSnapPoints) const override
 Find a number of snap points the line has available This function returns a ordered list, closest to coord and can return multiple snap points. More...
 
virtual geo::Coordinate nearestPointOnPath (const geo::Coordinate &coord) const override
 Find the nearest point on the path for this entity for the coordinate coord The path of a entity that it can possibly take. More...
 
std::tuple< geo::Coordinate,
std::shared_ptr< const
geo::Vector >, std::shared_ptr
< const geo::Arc > > 
nearestPointOnPath2 (const geo::Coordinate &coord) const
 
virtual CADEntity_CSPtr move (const geo::Coordinate &offset) const override
 move, moves by an offset More...
 
virtual CADEntity_CSPtr copy (const geo::Coordinate &offset) const override
 copy, copies by an offset More...
 
virtual CADEntity_CSPtr rotate (const geo::Coordinate &rotation_center, const double rotation_angle) const override
 rotate, rotate operation More...
 
virtual CADEntity_CSPtr scale (const geo::Coordinate &scale_center, const geo::Coordinate &scale_factor) const override
 scale, scales the entity More...
 
virtual CADEntity_CSPtr mirror (const geo::Coordinate &axis1, const geo::Coordinate &axis2) const override
 
virtual const geo::Area boundingBox () const override
 boundingBox of the entity More...
 
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 information #return new entity with same ID More...
 
std::vector< CADEntity_CSPtr >
const 
asEntities () const
 
virtual void accept (GeoEntityVisitor &v) const override
 
virtual void dispatch (EntityDispatch &ed) const override
 
virtual std::map< unsigned int,
lc::geo::Coordinate
dragPoints () const override
 Get all points of the entity that can be dragged. More...
 
virtual CADEntity_CSPtr setDragPoints (std::map< unsigned int, lc::geo::Coordinate > dragPoints) const override
 Return modified entity. More...
 
- Public Member Functions inherited from lc::entity::CADEntity
 CADEntity ()
 
 CADEntity (Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo=nullptr, const Block_CSPtr block=nullptr)
 CADEntity Constructor. More...
 
 CADEntity (CADEntity_CSPtr cadEntity, bool sameID)
 
 CADEntity (CADEntity_CSPtr cadEntity)
 
virtual ~CADEntity ()=default
 
Layer_CSPtr layer () const
 layer return the layer this entity is placed on More...
 
template<typename T >
const std::shared_ptr< const T > metaInfo (std::string metaName) const
 
MetaInfo_CSPtr metaInfo () const
 
Block_CSPtr block () const
 Return the current entity block. More...
 
- Public Member Functions inherited from lc::ID
 ID ()
 Default constructor, provides a new unique ID to each entity. More...
 
 ID (ID_DATATYPE)
 
virtual ~ID ()=default
 
ID_DATATYPE id () const
 returns the ID of the entity More...
 
bool operator== (const ID &id) const
 
void setID (ID_DATATYPE id)
 
- Public Member Functions inherited from lc::Visitable
virtual ~Visitable ()=default
 

Private Member Functions

void generateEntities ()
 Generate entities of the polyline. More...
 

Private Attributes

const std::vector< LWVertex2D_vertex
 
const double _width
 
const double _elevation
 
const double _tickness
 
const bool _closed
 
const geo::Coordinate _extrusionDirection
 
std::vector< CADEntity_CSPtr > _entities
 

Additional Inherited Members

- Static Public Member Functions inherited from lc::Snapable
static void remove_ifDistanceGreaterThen (std::vector< EntityCoordinate > &points, const geo::Coordinate &reference, const double distance)
 
static void snapPointsCleanup (std::vector< EntityCoordinate > &points, const geo::Coordinate &reference, const unsigned int maxNumberOfSnapPoints, const double minDistanceToSnap)
 
- Static Public Attributes inherited from lc::ID
static std::atomic< ID_DATATYPE__idCounter
 
- Protected Member Functions inherited from lc::entity::CADEntity
 CADEntity (const lc::builder::CADEntityBuilder &builder)
 

Detailed Description

Lightweight polyline

Definition at line 86 of file lwpolyline.h.

Constructor & Destructor Documentation

LWPolyline::LWPolyline ( const std::vector< LWVertex2D > &  vertex,
double  width,
double  elevation,
double  tickness,
bool  closed,
geo::Coordinate const &  extrusionDirection,
const Layer_CSPtr  layer,
const MetaInfo_CSPtr  metaInfo = nullptr,
const Block_CSPtr  block = nullptr 
)

LWPolyline Constructor

Parameters
widthof the vertex on each entity
elevationof the polyline
ticknessof the polyline
extrusionDirectionof the polyline
vertexentries of the polyline
layer
metaInfo

Definition at line 15 of file lwpolyline.cpp.

23  :
25  _vertex(vertex),
26  _width(width),
29  _closed(closed),
31 
33 
34 }
geo::Coordinate const & extrusionDirection() const
Definition: lwpolyline.h:125
double elevation() const
Definition: lwpolyline.h:117
std::vector< LWVertex2D > const & vertex() const
Definition: lwpolyline.h:129
Layer_CSPtr layer() const
layer return the layer this entity is placed on
Definition: cadentity.cpp:29
double width() const
Definition: lwpolyline.h:113
MetaInfo_CSPtr metaInfo() const
Definition: cadentity.h:123
const double _width
Definition: lwpolyline.h:153
const double _tickness
Definition: lwpolyline.h:155
const geo::Coordinate _extrusionDirection
Definition: lwpolyline.h:157
bool closed() const
Definition: lwpolyline.h:133
double tickness() const
Definition: lwpolyline.h:121
const double _elevation
Definition: lwpolyline.h:154
Block_CSPtr block() const
Return the current entity block.
Definition: cadentity.cpp:33
const std::vector< LWVertex2D > _vertex
Definition: lwpolyline.h:152
void generateEntities()
Generate entities of the polyline.
Definition: lwpolyline.cpp:126
LWPolyline::LWPolyline ( const LWPolyline_CSPtr  other,
bool  sameID = false 
)

Definition at line 36 of file lwpolyline.cpp.

36  : CADEntity(other, sameID),
37  _vertex(other->_vertex),
38  _width(other->_width),
39  _elevation(other->_elevation),
40  _tickness(other->_tickness),
41  _closed(other->_closed),
42  _extrusionDirection(other->_extrusionDirection) {
44 }
const double _width
Definition: lwpolyline.h:153
const double _tickness
Definition: lwpolyline.h:155
const geo::Coordinate _extrusionDirection
Definition: lwpolyline.h:157
const double _elevation
Definition: lwpolyline.h:154
const std::vector< LWVertex2D > _vertex
Definition: lwpolyline.h:152
void generateEntities()
Generate entities of the polyline.
Definition: lwpolyline.cpp:126

Member Function Documentation

virtual void lc::entity::LWPolyline::accept ( GeoEntityVisitor v) const
inlineoverridevirtual

Reimplemented from lc::entity::CADEntity.

Definition at line 213 of file lwpolyline.h.

213 { v.visit(*this); }
std::vector< CADEntity_CSPtr > const LWPolyline::asEntities ( ) const

Return a vector of entities for this polyline The vector will contain entity::vector and entity::Arc items

Definition at line 299 of file lwpolyline.cpp.

299  {
300  return _entities;
301 }
std::vector< CADEntity_CSPtr > _entities
Definition: lwpolyline.h:158
const geo::Area LWPolyline::boundingBox ( ) const
overridevirtual

boundingBox of the entity

Returns
geo::Area area

Implements lc::entity::CADEntity.

Definition at line 92 of file lwpolyline.cpp.

92  {
93  if(_entities.size() == 0) {
94  return geo::Area();
95  }
96 
97  auto it = _entities.begin();
98  geo::Area area = (*it)->boundingBox();
99  it++;
100 
101  while(it != _entities.end()) {
102  area = area.merge((*it)->boundingBox());
103  it++;
104  }
105 
106  return area;
107 }
Area merge(const Area &other) const
merge two area's and expand if required to largest containing area
Definition: geoarea.h:156
std::vector< CADEntity_CSPtr > _entities
Definition: lwpolyline.h:158
bool lc::entity::LWPolyline::closed ( ) const
inline

Definition at line 133 of file lwpolyline.h.

133  {
134  return _closed;
135  }
CADEntity_CSPtr LWPolyline::copy ( const geo::Coordinate offset) const
overridevirtual

copy, copies by an offset

Parameters
geo::Coordinateoffset
Returns
CADEntity_CSPtr copied entity

Implements lc::entity::CADEntity.

Definition at line 57 of file lwpolyline.cpp.

57  {
58  std::vector<LWVertex2D> newVertex;
59  for (auto vertex : _vertex) {
60  newVertex.emplace_back(vertex.location() + offset, vertex.bulge(), vertex.startWidth(), vertex.endWidth());
61  }
62  auto newEntity = std::make_shared<LWPolyline>(newVertex, width(), elevation(), tickness(), closed(),
64  return newEntity;
65 }
geo::Coordinate const & extrusionDirection() const
Definition: lwpolyline.h:125
double elevation() const
Definition: lwpolyline.h:117
std::vector< LWVertex2D > const & vertex() const
Definition: lwpolyline.h:129
Layer_CSPtr layer() const
layer return the layer this entity is placed on
Definition: cadentity.cpp:29
double width() const
Definition: lwpolyline.h:113
MetaInfo_CSPtr metaInfo() const
Definition: cadentity.h:123
bool closed() const
Definition: lwpolyline.h:133
double tickness() const
Definition: lwpolyline.h:121
const std::vector< LWVertex2D > _vertex
Definition: lwpolyline.h:152
virtual void lc::entity::LWPolyline::dispatch ( EntityDispatch ed) const
inlineoverridevirtual

Implements lc::entity::CADEntity.

Definition at line 215 of file lwpolyline.h.

215  {
216  ed.visit(shared_from_this());
217  }
std::map< unsigned int, lc::geo::Coordinate > LWPolyline::dragPoints ( ) const
overridevirtual

Get all points of the entity that can be dragged.

Returns
Map of points

Implements lc::Draggable.

Definition at line 267 of file lwpolyline.cpp.

267  {
268  std::map<unsigned int, geo::Coordinate> dragPoints;
269  unsigned int i = 0;
270 
271  for(auto vertex : _vertex) {
272  dragPoints[i] = vertex.location();
273  i++;
274  }
275 
276  return dragPoints;
277 }
std::vector< LWVertex2D > const & vertex() const
Definition: lwpolyline.h:129
virtual std::map< unsigned int, lc::geo::Coordinate > dragPoints() const override
Get all points of the entity that can be dragged.
Definition: lwpolyline.cpp:267
const std::vector< LWVertex2D > _vertex
Definition: lwpolyline.h:152
double lc::entity::LWPolyline::elevation ( ) const
inline

Definition at line 117 of file lwpolyline.h.

117  {
118  return _elevation;
119  }
const double _elevation
Definition: lwpolyline.h:154
geo::Coordinate const& lc::entity::LWPolyline::extrusionDirection ( ) const
inline

Definition at line 125 of file lwpolyline.h.

125  {
126  return _extrusionDirection;
127  }
const geo::Coordinate _extrusionDirection
Definition: lwpolyline.h:157
void LWPolyline::generateEntities ( )
private

Generate entities of the polyline.

Definition at line 126 of file lwpolyline.cpp.

126  {
127  auto itr = _vertex.begin();
128  auto lastPoint = itr;
129  itr++;
130  while (itr != vertex().end()) {
131  if (lastPoint->bulge() != 0.) {
132  _entities.push_back(std::make_shared<const Arc>(
133  geo::Arc::createArcBulge(lastPoint->location(), itr->location(), lastPoint->bulge()),
134  layer(),
135  metaInfo(),
136  block()
137  ));
138  }
139  else {
140  _entities.push_back(std::make_shared<const Line>(lastPoint->location(), itr->location(), layer(), metaInfo(), block()));
141  }
142  lastPoint = itr;
143  itr++;
144  }
145 
146  if (_closed) {
147  auto firstP = _vertex.begin();
148  if (lastPoint->bulge() != 0.) {
149  _entities.push_back(std::make_shared<const Arc>(
150  geo::Arc::createArcBulge(lastPoint->location(), firstP->location(), lastPoint->bulge()),
151  layer(),
152  metaInfo(),
153  block()
154  ));
155  }
156  else {
157  _entities.push_back(std::make_shared<const Line>(lastPoint->location(), firstP->location(), layer(), metaInfo(), block()));
158  }
159  }
160 }
std::vector< LWVertex2D > const & vertex() const
Definition: lwpolyline.h:129
Layer_CSPtr layer() const
layer return the layer this entity is placed on
Definition: cadentity.cpp:29
static Arc createArcBulge(const Coordinate &p1, const Coordinate &p2, const double bulge)
Definition: geoarc.cpp:51
MetaInfo_CSPtr metaInfo() const
Definition: cadentity.h:123
std::vector< CADEntity_CSPtr > _entities
Definition: lwpolyline.h:158
Block_CSPtr block() const
Return the current entity block.
Definition: cadentity.cpp:33
const std::vector< LWVertex2D > _vertex
Definition: lwpolyline.h:152
virtual CADEntity_CSPtr lc::entity::LWPolyline::mirror ( const geo::Coordinate axis1,
const geo::Coordinate axis2 
) const
inlineoverridevirtual

Implements lc::entity::CADEntity.

Definition at line 193 of file lwpolyline.h.

194  {
195  return NULL; // TODO: no return statement, not implemented in lwpolyline.cpp
196  }
CADEntity_CSPtr LWPolyline::modify ( Layer_CSPtr  layer,
const MetaInfo_CSPtr  metaInfo,
Block_CSPtr  block 
) const
overridevirtual

modify Return a new entity with the same ID bit with possible modified metainfo and/pr layer information #return new entity with same ID

Implements lc::entity::CADEntity.

Definition at line 109 of file lwpolyline.cpp.

109  {
110  auto newEntity = std::make_shared<LWPolyline>(
111  _vertex,
112  _width,
113  _elevation,
114  _tickness,
115  _closed,
117  layer,
118  metaInfo,
119  block
120  );
121  newEntity->setID(this->id());
122 
123  return newEntity;
124 }
Layer_CSPtr layer() const
layer return the layer this entity is placed on
Definition: cadentity.cpp:29
MetaInfo_CSPtr metaInfo() const
Definition: cadentity.h:123
const double _width
Definition: lwpolyline.h:153
const double _tickness
Definition: lwpolyline.h:155
const geo::Coordinate _extrusionDirection
Definition: lwpolyline.h:157
const double _elevation
Definition: lwpolyline.h:154
Block_CSPtr block() const
Return the current entity block.
Definition: cadentity.cpp:33
const std::vector< LWVertex2D > _vertex
Definition: lwpolyline.h:152
CADEntity_CSPtr LWPolyline::move ( const geo::Coordinate offset) const
overridevirtual

move, moves by an offset

Parameters
geo::Coordinateoffset
Returns
CADEntity_CSPtr moved entity

Implements lc::entity::CADEntity.

Definition at line 46 of file lwpolyline.cpp.

46  {
47  std::vector<LWVertex2D> newVertex;
48  for (auto vertex : _vertex) {
49  newVertex.emplace_back(vertex.location() + offset, vertex.bulge(), vertex.startWidth(), vertex.endWidth());
50  }
51  auto newEntity = std::make_shared<LWPolyline>(newVertex, width(), elevation(), tickness(), closed(),
53  newEntity->setID(this->id());
54  return newEntity;
55 }
geo::Coordinate const & extrusionDirection() const
Definition: lwpolyline.h:125
double elevation() const
Definition: lwpolyline.h:117
std::vector< LWVertex2D > const & vertex() const
Definition: lwpolyline.h:129
Layer_CSPtr layer() const
layer return the layer this entity is placed on
Definition: cadentity.cpp:29
double width() const
Definition: lwpolyline.h:113
MetaInfo_CSPtr metaInfo() const
Definition: cadentity.h:123
bool closed() const
Definition: lwpolyline.h:133
double tickness() const
Definition: lwpolyline.h:121
const std::vector< LWVertex2D > _vertex
Definition: lwpolyline.h:152
geo::Coordinate LWPolyline::nearestPointOnPath ( const geo::Coordinate coord) const
overridevirtual

Find the nearest point on the path for this entity for the coordinate coord The path of a entity that it can possibly take.

For example for any Arc the path is the full circle if the start/stop angle is 0 to 2*pi

Parameters
coordCoordinate to lookup the nearest coordinate from
See also
lc::entity::CADEntity

Implements lc::Snapable.

Definition at line 229 of file lwpolyline.cpp.

229  {
230  auto &&info = nearestPointOnPath2(coord);
231  return std::get<0>(info);
232 }
std::tuple< geo::Coordinate, std::shared_ptr< const geo::Vector >, std::shared_ptr< const geo::Arc > > nearestPointOnPath2(const geo::Coordinate &coord) const
Definition: lwpolyline.cpp:234
std::tuple< geo::Coordinate, std::shared_ptr< const geo::Vector >, std::shared_ptr< const geo::Arc > > LWPolyline::nearestPointOnPath2 ( const geo::Coordinate coord) const

Definition at line 234 of file lwpolyline.cpp.

235  {
236  const auto &&entities = asEntities();
237 
238  double minimumDistance = std::numeric_limits<double>::max();
239  std::shared_ptr<const geo::Vector> nearestVector = nullptr;
240  std::shared_ptr<const geo::Arc> nearestArc = nullptr;
241  geo::Coordinate nearestCoordinate;
242  for (auto &geoItem : entities) {
243  if (auto vector = std::dynamic_pointer_cast<const geo::Vector>(geoItem)) {
244  auto npoe = vector->nearestPointOnPath(coord);
245  auto thisDistance = npoe.distanceTo(coord);
246  if (thisDistance < minimumDistance) {
247  minimumDistance = thisDistance;
248  nearestCoordinate = npoe;
249  nearestVector = vector;
250  }
251  } else if (auto arc = std::dynamic_pointer_cast<const geo::Arc>(geoItem)) {
252  auto npoe = arc->nearestPointOnPath(coord);
253  auto thisDistance = npoe.distanceTo(coord);
254  if (thisDistance < minimumDistance) {
255  minimumDistance = thisDistance;
256  nearestCoordinate = npoe;
257  nearestArc = arc;
258  }
259  } else {
260  std::cerr << "Unknown entity found in LWPolyline during boundingBox generation" << std::endl;
261  }
262  }
263  return std::make_tuple(nearestCoordinate, nearestVector, nearestArc);
264 }
double distanceTo(const geo::Coordinate &c) const
std::vector< CADEntity_CSPtr > const asEntities() const
Definition: lwpolyline.cpp:299
CADEntity_CSPtr LWPolyline::rotate ( const geo::Coordinate rotation_center,
const double  rotation_angle 
) const
overridevirtual

rotate, rotate operation

Parameters
geo::Coordinaterotation_center
doublerotation_angle
Returns
CADEntity_CSPtr rotated entity

Implements lc::entity::CADEntity.

Definition at line 67 of file lwpolyline.cpp.

67  {
68  std::vector<LWVertex2D> newVertex;
69  for (auto vertex : _vertex) {
70  newVertex.emplace_back(vertex.location().rotate(rotation_center, rotation_angle), vertex.bulge(),
71  vertex.startWidth(), vertex.endWidth());
72  }
73  auto newEntity = std::make_shared<LWPolyline>(newVertex, width(), elevation(), tickness(), closed(),
75  return newEntity;
76 }
geo::Coordinate const & extrusionDirection() const
Definition: lwpolyline.h:125
double elevation() const
Definition: lwpolyline.h:117
std::vector< LWVertex2D > const & vertex() const
Definition: lwpolyline.h:129
Layer_CSPtr layer() const
layer return the layer this entity is placed on
Definition: cadentity.cpp:29
double width() const
Definition: lwpolyline.h:113
MetaInfo_CSPtr metaInfo() const
Definition: cadentity.h:123
bool closed() const
Definition: lwpolyline.h:133
double tickness() const
Definition: lwpolyline.h:121
const std::vector< LWVertex2D > _vertex
Definition: lwpolyline.h:152
CADEntity_CSPtr LWPolyline::scale ( const geo::Coordinate scale_center,
const geo::Coordinate scale_factor 
) const
overridevirtual

scale, scales the entity

Parameters
geo::Coordinatescale_center
doublescale_factor
Returns

Implements lc::entity::CADEntity.

Definition at line 78 of file lwpolyline.cpp.

78  {
79  std::vector<LWVertex2D> newVertex;
80  if (scale_factor.x() != scale_factor.y()) {
81  // TODO decide what to do with non-uniform scale factors
82  }
83  for (auto vertex : _vertex) {
84  newVertex.emplace_back(vertex.location().scale(scale_center, scale_factor), vertex.bulge() * scale_factor.x(),
85  vertex.startWidth(), vertex.endWidth());
86  }
87  auto newEntity = std::make_shared<LWPolyline>(newVertex, width(), elevation(), tickness(), closed(),
89  return newEntity;
90 }
geo::Coordinate const & extrusionDirection() const
Definition: lwpolyline.h:125
double x() const
Returns x of Coordinate.
Definition: geocoordinate.h:26
double elevation() const
Definition: lwpolyline.h:117
std::vector< LWVertex2D > const & vertex() const
Definition: lwpolyline.h:129
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
double width() const
Definition: lwpolyline.h:113
MetaInfo_CSPtr metaInfo() const
Definition: cadentity.h:123
bool closed() const
Definition: lwpolyline.h:133
double tickness() const
Definition: lwpolyline.h:121
const std::vector< LWVertex2D > _vertex
Definition: lwpolyline.h:152
CADEntity_CSPtr LWPolyline::setDragPoints ( std::map< unsigned int, lc::geo::Coordinate dragPoints) const
overridevirtual

Return modified entity.

Parameters
dragPointsModified points
Returns
New entity or same entity if an error occurred Return the new entity which corresponds to the given points. Points must be associated to the same number given in dragPoints().

Implements lc::Draggable.

Definition at line 280 of file lwpolyline.cpp.

280  {
281  try {
282  std::vector<LWVertex2D> newVertex;
283  unsigned int i = 0;
284 
285  for(auto vertex : _vertex) {
286  newVertex.push_back(LWVertex2D(dragPoints[i], vertex.bulge(), vertex.startWidth(), vertex.endWidth()));
287  i++;
288  }
289 
290  auto newEntity = std::make_shared<LWPolyline>(newVertex, width(), elevation(), tickness(), closed(), extrusionDirection(), layer(), metaInfo());
291  newEntity->setID(id());
292  return newEntity;
293  }
294  catch(std::out_of_range& e) {
295  return shared_from_this();
296  }
297 }
geo::Coordinate const & extrusionDirection() const
Definition: lwpolyline.h:125
double elevation() const
Definition: lwpolyline.h:117
std::vector< LWVertex2D > const & vertex() const
Definition: lwpolyline.h:129
Layer_CSPtr layer() const
layer return the layer this entity is placed on
Definition: cadentity.cpp:29
double width() const
Definition: lwpolyline.h:113
virtual std::map< unsigned int, lc::geo::Coordinate > dragPoints() const override
Get all points of the entity that can be dragged.
Definition: lwpolyline.cpp:267
MetaInfo_CSPtr metaInfo() const
Definition: cadentity.h:123
bool closed() const
Definition: lwpolyline.h:133
double tickness() const
Definition: lwpolyline.h:121
const std::vector< LWVertex2D > _vertex
Definition: lwpolyline.h:152
std::vector< EntityCoordinate > LWPolyline::snapPoints ( const geo::Coordinate coord,
const SimpleSnapConstrain simpleSnapConstrain,
double  minDistanceToSnap,
int  maxNumberOfSnapPoints 
) const
overridevirtual

Find a number of snap points the line has available This function returns a ordered list, closest to coord and can return multiple snap points.

Parameters
coordCoordinate to lookup the nearest coordinate from
minDistanceToSnapMinimum distance to the path to snap into. THis is a hint parameter and we should follow this, but it will be later filtered again
maxNumberOfSnapPointsMaximum number of snappoints that have to be looked up
See also
lc::EntityCoordinate

Implements lc::Snapable.

Definition at line 162 of file lwpolyline.cpp.

164  {
165  std::vector<EntityCoordinate> points;
166  if (constrain.constrain() & SimpleSnapConstrain::LOGICAL) {
167  const auto &&entities = asEntities();
168  for (auto &geoItem : entities) {
169  if (auto vector = std::dynamic_pointer_cast<const geo::Vector>(geoItem)) {
170  points.emplace_back(vector->start(), -1);
171  points.emplace_back(vector->end(), -2);
172  } else if (auto arc = std::dynamic_pointer_cast<const geo::Arc>(geoItem)) {
173  points.emplace_back(arc->startP(), -3);
174  points.emplace_back(arc->endP(), -4);
175  points.emplace_back(arc->center(), -5);
176 
177  // Add 4 coordinates
178  // Top Point
179  if (arc->isAngleBetween(.5 * M_PI)) {
180  const auto coord = arc->center() + lc::geo::Coordinate(0., arc->radius());
181  points.emplace_back(coord, 1);
182  }
183  // Right Point
184  if (arc->isAngleBetween(0)) {
185  const auto coord = arc->center() + lc::geo::Coordinate(arc->radius(), 0.);
186  points.emplace_back(coord, 2);
187  }
188  // Left Point
189  if (arc->isAngleBetween(M_PI)) {
190  const auto coord = arc->center() + lc::geo::Coordinate(-arc->radius(), 0.);
191  points.emplace_back(coord, 3);
192  }
193  // Bottom Point
194  if (arc->isAngleBetween(-.5 * M_PI)) {
195  const auto coord = arc->center() + lc::geo::Coordinate(0., -arc->radius());
196  points.emplace_back(coord, 4);
197  }
198  } else {
199  std::cerr << "Unknown entity found in LWPolyline during snapPoints generation" << std::endl;
200  }
201  }
202  }
203 
204  if (constrain.constrain() & SimpleSnapConstrain::ON_ENTITY) {
205  auto &&info = nearestPointOnPath2(coord);
206  geo::Coordinate npoe = std::get<0>(info);
207  if (auto &arc = std::get<2>(info)) {
208  const double a = (npoe - arc->center()).angle();
209  if (arc->isAngleBetween(a)) {
210  points.emplace_back(npoe, -6);
211  }
212  } else if (auto &vector = std::get<1>(info)) {
213  if (vector->nearestPointOnEntity(coord).distanceTo(coord) < minDistanceToSnap) {
214  points.emplace_back(npoe, -7);
215  }
216  }
217  }
218 
219  if (constrain.constrain() & SimpleSnapConstrain::ON_ENTITYPATH) {
220  geo::Coordinate npoe = nearestPointOnPath(coord);
221  points.emplace_back(npoe, -1);
222  }
223 
224  // Cleanup array of snappoints
225  Snapable::snapPointsCleanup(points, coord, maxNumberOfSnapPoints, minDistanceToSnap);
226  return points;
227 }
static const uint16_t LOGICAL
Definition: snapconstrain.h:22
static const uint16_t ON_ENTITYPATH
Definition: snapconstrain.h:19
virtual geo::Coordinate nearestPointOnPath(const geo::Coordinate &coord) const override
Find the nearest point on the path for this entity for the coordinate coord The path of a entity that...
Definition: lwpolyline.cpp:229
static const uint16_t ON_ENTITY
Definition: snapconstrain.h:18
static void snapPointsCleanup(std::vector< EntityCoordinate > &points, const geo::Coordinate &reference, const unsigned int maxNumberOfSnapPoints, const double minDistanceToSnap)
Definition: snapable.h:53
std::tuple< geo::Coordinate, std::shared_ptr< const geo::Vector >, std::shared_ptr< const geo::Arc > > nearestPointOnPath2(const geo::Coordinate &coord) const
Definition: lwpolyline.cpp:234
#define M_PI
Definition: const.h:16
std::vector< CADEntity_CSPtr > const asEntities() const
Definition: lwpolyline.cpp:299
double lc::entity::LWPolyline::tickness ( ) const
inline

Definition at line 121 of file lwpolyline.h.

121  {
122  return _tickness;
123  }
const double _tickness
Definition: lwpolyline.h:155
std::vector<LWVertex2D> const& lc::entity::LWPolyline::vertex ( ) const
inline

Definition at line 129 of file lwpolyline.h.

129  {
130  return _vertex;
131  }
const std::vector< LWVertex2D > _vertex
Definition: lwpolyline.h:152
double lc::entity::LWPolyline::width ( ) const
inline

Definition at line 113 of file lwpolyline.h.

113  {
114  return _width;
115  }
const double _width
Definition: lwpolyline.h:153

Member Data Documentation

const bool lc::entity::LWPolyline::_closed
private

Definition at line 156 of file lwpolyline.h.

const double lc::entity::LWPolyline::_elevation
private

Definition at line 154 of file lwpolyline.h.

std::vector<CADEntity_CSPtr> lc::entity::LWPolyline::_entities
private

Definition at line 158 of file lwpolyline.h.

const geo::Coordinate lc::entity::LWPolyline::_extrusionDirection
private

Definition at line 157 of file lwpolyline.h.

const double lc::entity::LWPolyline::_tickness
private

Definition at line 155 of file lwpolyline.h.

const std::vector<LWVertex2D> lc::entity::LWPolyline::_vertex
private

Definition at line 152 of file lwpolyline.h.

const double lc::entity::LWPolyline::_width
private

Definition at line 153 of file lwpolyline.h.


The documentation for this class was generated from the following files: