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

A line that can be put in a drawing. More...

#include <line.h>

Inheritance diagram for lc::entity::Line:
Collaboration diagram for lc::entity::Line:

Public Member Functions

 Line (const geo::Coordinate &start, const geo::Coordinate &end, const Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo=nullptr, const Block_CSPtr block=nullptr)
 Construct a new line. More...
 
 Line (const geo::Vector &vector, const Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo=nullptr, const Block_CSPtr block=nullptr)
 Construct a new line. More...
 
 Line (const Line_CSPtr other, bool sameID=false)
 
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...
 
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...
 
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 line 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...
 
virtual void accept (GeoEntityVisitor &v) const override
 
virtual void dispatch (EntityDispatch &ed) const override
 
- 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
 
- Public Member Functions inherited from lc::geo::Vector
 Vector (const Coordinate &start, const Coordinate &end)
 
 Vector (const Vector &v)
 
const Coordinate start () const
 
const Coordinate end () const
 
Vectoroperator= (const Vector &v)
 
const Coordinate nearestPointOnPath (const Coordinate &coord) const
 
const Coordinate nearestPointOnEntity (const Coordinate &coord) const
 
double Angle1 () const
 
double Angle2 () const
 
const maths::Equation equation () const
 
- Public Member Functions inherited from lc::geo::Base
virtual ~Base ()=default
 

Private Member Functions

 Line (const builder::LineBuilder &builder)
 

Friends

class builder::LineBuilder
 

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

A line that can be put in a drawing.

A line is a graphics line item that can be put on a drawing using a CreateEntity operation.

See also
CreateEntities::append
Author
R. van Twisk
Date
2012-04-16

Definition at line 28 of file line.h.

Constructor & Destructor Documentation

Line::Line ( const geo::Coordinate start,
const geo::Coordinate end,
const Layer_CSPtr  layer,
const MetaInfo_CSPtr  metaInfo = nullptr,
const Block_CSPtr  block = nullptr 
)

Construct a new line.

Parameters
start,endCoordinate the line should start and end from
metaTypesA list of metatypes associated with this line
See also
Color
LineWidth
MetaType

Definition at line 9 of file line.cpp.

13  :
15  geo::Vector(start, end) {
16 }
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
Block_CSPtr block() const
Return the current entity block.
Definition: cadentity.cpp:33
Line::Line ( const geo::Vector vector,
const Layer_CSPtr  layer,
const MetaInfo_CSPtr  metaInfo = nullptr,
const Block_CSPtr  block = nullptr 
)

Construct a new line.

Parameters
vectorCoordinate the line should start and end from
metaTypesA list of metatypes associated with this line
See also
Color
LineWidth
MetaType

Definition at line 18 of file line.cpp.

21  :
23  geo::Vector(vector) {
24 }
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
Block_CSPtr block() const
Return the current entity block.
Definition: cadentity.cpp:33
Line::Line ( const Line_CSPtr  other,
bool  sameID = false 
)

Definition at line 26 of file line.cpp.

26  : CADEntity(other, sameID), geo::Vector(other->start(), other->end()) {
27 }
Line::Line ( const builder::LineBuilder builder)
private

Definition at line 29 of file line.cpp.

29  :
30  CADEntity(builder),
31  geo::Vector(builder.start(), builder.end()) {
32 }
const geo::Coordinate & end() const
Get line end.
Definition: line.cpp:24
const geo::Coordinate & start() const
Get line start.
Definition: line.cpp:15

Member Function Documentation

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

Reimplemented from lc::entity::CADEntity.

Definition at line 118 of file line.h.

118 { v.visit(*this); }
const geo::Area Line::boundingBox ( ) const
overridevirtual

boundingBox of the entity

Returns
geo::Area area

Implements lc::entity::CADEntity.

Definition at line 115 of file line.cpp.

115  {
116  return geo::Area(start(), end());
117 }
const Coordinate end() const
Definition: geovector.h:23
const Coordinate start() const
Definition: geovector.h:20
CADEntity_CSPtr Line::copy ( const geo::Coordinate offset) const
overridevirtual

copy, copies line by an offset

Parameters
geo::Coordinateoffset
Returns
CADEntity_CSPtr copied entity

Implements lc::entity::CADEntity.

Definition at line 75 of file line.cpp.

75  {
76  auto newLine = std::make_shared<Line>(this->start() + offset,
77  this->end() + offset,
78  layer(),
79  metaInfo(),
80  block());
81  return newLine;
82 }
const Coordinate end() const
Definition: geovector.h:23
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
Block_CSPtr block() const
Return the current entity block.
Definition: cadentity.cpp:33
const Coordinate start() const
Definition: geovector.h:20
virtual void lc::entity::Line::dispatch ( EntityDispatch ed) const
inlineoverridevirtual

Implements lc::entity::CADEntity.

Definition at line 120 of file line.h.

120  {
121  ed.visit(shared_from_this());
122  }
std::map< unsigned int, lc::geo::Coordinate > Line::dragPoints ( ) const
overridevirtual

Get all points of the entity that can be dragged.

Returns
Map of points

Implements lc::Draggable.

Definition at line 132 of file line.cpp.

132  {
133  std::map<unsigned int, lc::geo::Coordinate> points;
134 
135  points[0] = start();
136  points[1] = end();
137 
138  return points;
139 }
const Coordinate end() const
Definition: geovector.h:23
const Coordinate start() const
Definition: geovector.h:20
CADEntity_CSPtr Line::mirror ( const geo::Coordinate axis1,
const geo::Coordinate axis2 
) const
overridevirtual

Implements lc::entity::CADEntity.

Definition at line 104 of file line.cpp.

105  {
106  auto newLine = std::make_shared<Line>(this->start().mirror(axis1, axis2),
107  this->end().mirror(axis1, axis2),
108  layer(),
109  metaInfo(),
110  block());
111  newLine->setID(this->id());
112  return newLine;
113 }
Coordinate mirror(const Coordinate &axis1, const Coordinate &axis2) const
mirror a coordinate
const Coordinate end() const
Definition: geovector.h:23
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
Block_CSPtr block() const
Return the current entity block.
Definition: cadentity.cpp:33
const Coordinate start() const
Definition: geovector.h:20
CADEntity_CSPtr Line::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 119 of file line.cpp.

119  {
120  auto newEntity = std::make_shared<Line>(
121  this->start(),
122  this->end(),
123  layer,
124  metaInfo,
125  block
126  );
127  newEntity->setID(this->id());
128 
129  return newEntity;
130 }
const Coordinate end() const
Definition: geovector.h:23
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
Block_CSPtr block() const
Return the current entity block.
Definition: cadentity.cpp:33
const Coordinate start() const
Definition: geovector.h:20
CADEntity_CSPtr Line::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 64 of file line.cpp.

64  {
65  auto newLine = std::make_shared<Line>(this->start() + offset,
66  this->end() + offset,
67  layer(),
68  metaInfo(),
69  block()
70  );
71  newLine->setID(this->id());
72  return newLine;
73 }
const Coordinate end() const
Definition: geovector.h:23
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
Block_CSPtr block() const
Return the current entity block.
Definition: cadentity.cpp:33
const Coordinate start() const
Definition: geovector.h:20
geo::Coordinate Line::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 60 of file line.cpp.

60  {
61  return geo::Vector::nearestPointOnPath(coord);
62 }
const Coordinate nearestPointOnPath(const Coordinate &coord) const
Definition: geovector.h:39
CADEntity_CSPtr Line::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 84 of file line.cpp.

84  {
85  auto newLine = std::make_shared<Line>(this->start().rotate(rotation_center, rotation_angle),
86  this->end().rotate(rotation_center, rotation_angle),
87  layer(),
88  metaInfo(),
89  block());
90  newLine->setID(this->id());
91  return newLine;
92 }
const Coordinate end() const
Definition: geovector.h:23
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
Coordinate rotate(const Coordinate &angleVector) const
rotate around (0.,0.) with a given angle vector
Block_CSPtr block() const
Return the current entity block.
Definition: cadentity.cpp:33
const Coordinate start() const
Definition: geovector.h:20
CADEntity_CSPtr Line::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 94 of file line.cpp.

94  {
95  auto newLine = std::make_shared<Line>(this->start().scale(scale_center, scale_factor),
96  this->end().scale(scale_center, scale_factor),
97  layer(),
98  metaInfo(),
99  block());
100  newLine->setID(this->id());
101  return newLine;
102 }
const Coordinate end() const
Definition: geovector.h:23
Layer_CSPtr layer() const
layer return the layer this entity is placed on
Definition: cadentity.cpp:29
Coordinate scale(const double &scale_factor) const
MetaInfo_CSPtr metaInfo() const
Definition: cadentity.h:123
Block_CSPtr block() const
Return the current entity block.
Definition: cadentity.cpp:33
const Coordinate start() const
Definition: geovector.h:20
CADEntity_CSPtr Line::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 141 of file line.cpp.

141  {
142  try {
143  auto newEntity = std::make_shared<Line>(dragPoints.at(0),
144  dragPoints.at(1),
145  layer(),
146  metaInfo(),
147  block()
148  );
149  newEntity->setID(this->id());
150  return newEntity;
151  }
152  catch(const std::out_of_range& e) {
153  //A point was not in the map, don't change the entity
154  return shared_from_this();
155  }
156 }
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
virtual std::map< unsigned int, lc::geo::Coordinate > dragPoints() const override
Get all points of the entity that can be dragged.
Definition: line.cpp:132
Block_CSPtr block() const
Return the current entity block.
Definition: cadentity.cpp:33
std::vector< EntityCoordinate > Line::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 34 of file line.cpp.

34  {
35  std::vector<EntityCoordinate> points;
36 
37  if (constrain.constrain() & SimpleSnapConstrain::LOGICAL) {
38  points.emplace_back(start(), 0);
39  points.emplace_back(end(), 1);
40  points.emplace_back(end().mid(start()), 1);
41  }
42 
43 
44  const geo::Coordinate npoe = nearestPointOnPath(coord);
45  if (constrain.constrain() & SimpleSnapConstrain::ON_ENTITYPATH) {
46  points.emplace_back(npoe, 2);
47  }
48 
49  if (constrain.constrain() & SimpleSnapConstrain::ON_ENTITY) {
50  if (this->nearestPointOnEntity(coord).distanceTo(coord)<minDistanceToSnap) {
51  points.emplace_back(npoe, 3);
52  }
53  }
54 
55  // Cleanup array of snappoints
56  Snapable::snapPointsCleanup(points, coord, maxNumberOfSnapPoints, minDistanceToSnap);
57  return points;
58 }
const Coordinate end() const
Definition: geovector.h:23
static const uint16_t LOGICAL
Definition: snapconstrain.h:22
const Coordinate nearestPointOnEntity(const Coordinate &coord) const
Definition: geovector.h:49
static const uint16_t ON_ENTITYPATH
Definition: snapconstrain.h:19
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
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: line.cpp:60
const Coordinate start() const
Definition: geovector.h:20
double distanceTo(const geo::Coordinate &c) const

Friends And Related Function Documentation

friend class builder::LineBuilder
friend

Definition at line 29 of file line.h.


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