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

#include <insert.h>

Inheritance diagram for lc::entity::Insert:
Collaboration diagram for lc::entity::Insert:

Public Member Functions

 Insert (Insert_CSPtr other, bool sameID=false)
 
 ~Insert ()
 
const Block_CSPtr & displayBlock () const
 
const geo::Coordinateposition () const
 
const Document_SPtr & document () const
 
CADEntity_CSPtr move (const geo::Coordinate &offset) const override
 Function for Move. More...
 
CADEntity_CSPtr copy (const geo::Coordinate &offset) const override
 Function for Copy. More...
 
CADEntity_CSPtr rotate (const geo::Coordinate &rotation_center, const double rotation_angle) const override
 Function implementation for rotate. More...
 
CADEntity_CSPtr scale (const geo::Coordinate &scale_center, const geo::Coordinate &scale_factor) const override
 Function implementation for Scale. More...
 
CADEntity_CSPtr mirror (const geo::Coordinate &axis1, const geo::Coordinate &axis2) const override
 
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...
 
const geo::Area boundingBox () const override
 boundingBox Return the bounding box of this entity. This should be as tight around the entity as possible but care should be taken that this routine is also as fast as possible. in essence, favor speed over tightness. This routine will in generally be used during testing if entities cross for example to find snap points and to build relationships of tree for example using quad trees More...
 
void dispatch (EntityDispatch &dispatch) const override
 
std::map< unsigned int,
geo::Coordinate
dragPoints () const override
 Get all points of the entity that can be dragged. More...
 
CADEntity_CSPtr setDragPoints (std::map< unsigned int, lc::geo::Coordinate > dragPoints) const override
 Return modified entity. More...
 
virtual std::vector
< EntityCoordinate
snapPoints (const geo::Coordinate &coord, const SimpleSnapConstrain &simpleSnapConstrain, 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...
 
- 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
 
virtual void accept (GeoEntityVisitor &v) const override
 
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
 

Protected Member Functions

 Insert (const builder::InsertBuilder &builder)
 
- Protected Member Functions inherited from lc::entity::CADEntity
 CADEntity (const lc::builder::CADEntityBuilder &builder)
 

Private Member Functions

void calculateBoundingBox ()
 
void on_addEntityEvent (const lc::AddEntityEvent &)
 
void on_removeEntityEvent (const lc::RemoveEntityEvent &)
 

Private Attributes

Document_SPtr _document
 
geo::Coordinate _position
 
Block_CSPtr _displayBlock
 
geo::Area _boundingBox
 

Friends

class builder::InsertBuilder
 

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
 

Detailed Description

Definition at line 12 of file insert.h.

Constructor & Destructor Documentation

Insert::Insert ( Insert_CSPtr  other,
bool  sameID = false 
)

Definition at line 6 of file insert.cpp.

6  :
7  CADEntity(other, sameID),
8  _document(other->_document),
9  _position(other->_position),
10  _displayBlock(other->_displayBlock) {
11 
13 
14  _document->addEntityEvent().connect<Insert, &Insert::on_addEntityEvent>(this);
15  _document->removeEntityEvent().connect<Insert, &Insert::on_removeEntityEvent>(this);
16 }
Block_CSPtr _displayBlock
Definition: insert.h:53
Insert(Insert_CSPtr other, bool sameID=false)
Definition: insert.cpp:6
Document_SPtr _document
Definition: insert.h:51
void calculateBoundingBox()
Definition: insert.cpp:133
geo::Coordinate _position
Definition: insert.h:52
void on_addEntityEvent(const lc::AddEntityEvent &)
Definition: insert.cpp:153
void on_removeEntityEvent(const lc::RemoveEntityEvent &)
Definition: insert.cpp:159
Insert::~Insert ( )

Definition at line 30 of file insert.cpp.

30  {
31  document()->addEntityEvent().disconnect<Insert, &Insert::on_addEntityEvent>(this);
32  document()->removeEntityEvent().disconnect<Insert, &Insert::on_removeEntityEvent>(this);
33 }
Insert(Insert_CSPtr other, bool sameID=false)
Definition: insert.cpp:6
const Document_SPtr & document() const
Definition: insert.cpp:129
void on_addEntityEvent(const lc::AddEntityEvent &)
Definition: insert.cpp:153
void on_removeEntityEvent(const lc::RemoveEntityEvent &)
Definition: insert.cpp:159
Insert::Insert ( const builder::InsertBuilder builder)
protected

Definition at line 18 of file insert.cpp.

18  :
19  CADEntity(builder),
20  _document(builder.document()),
21  _position(builder.coordinate()),
22  _displayBlock(builder.displayBlock()) {
23 
25 
26  _document->addEntityEvent().connect<Insert, &Insert::on_addEntityEvent>(this);
27  _document->removeEntityEvent().connect<Insert, &Insert::on_removeEntityEvent>(this);
28 }
const Block_CSPtr & displayBlock() const
Definition: insert.cpp:31
Block_CSPtr _displayBlock
Definition: insert.h:53
Insert(Insert_CSPtr other, bool sameID=false)
Definition: insert.cpp:6
Document_SPtr _document
Definition: insert.h:51
const geo::Coordinate & coordinate() const
Definition: insert.cpp:49
const Document_SPtr & document() const
Definition: insert.cpp:59
void calculateBoundingBox()
Definition: insert.cpp:133
geo::Coordinate _position
Definition: insert.h:52
void on_addEntityEvent(const lc::AddEntityEvent &)
Definition: insert.cpp:153
void on_removeEntityEvent(const lc::RemoveEntityEvent &)
Definition: insert.cpp:159

Member Function Documentation

const geo::Area Insert::boundingBox ( ) const
overridevirtual

boundingBox Return the bounding box of this entity. This should be as tight around the entity as possible but care should be taken that this routine is also as fast as possible. in essence, favor speed over tightness. This routine will in generally be used during testing if entities cross for example to find snap points and to build relationships of tree for example using quad trees

Returns
geo::Area

Implements lc::entity::CADEntity.

Definition at line 72 of file insert.cpp.

72  {
73  return _boundingBox;
74 }
geo::Area _boundingBox
Definition: insert.h:54
void Insert::calculateBoundingBox ( )
private

Definition at line 133 of file insert.cpp.

133  {
134  auto entities = _document->entitiesByBlock(_displayBlock).asVector();
135 
136  if(entities.empty()) {
138  return;
139  }
140 
141  auto offset = _position - displayBlock()->base();
142  auto it = entities.begin();
143 
144  _boundingBox = (*it)->move(offset)->boundingBox();
145  it++;
146 
147  while (it != entities.end()) {
148  _boundingBox = _boundingBox.merge((*it)->move(offset)->boundingBox());
149  it++;
150  }
151 }
Block_CSPtr _displayBlock
Definition: insert.h:53
Area merge(const Area &other) const
merge two area's and expand if required to largest containing area
Definition: geoarea.h:156
const Block_CSPtr & displayBlock() const
Definition: insert.cpp:35
Document_SPtr _document
Definition: insert.h:51
geo::Coordinate _position
Definition: insert.h:52
geo::Area _boundingBox
Definition: insert.h:54
CADEntity_CSPtr Insert::copy ( const geo::Coordinate offset) const
overridevirtual

Function for Copy.

Parameters
offsetthe offset by which entity is to be copied
Returns
CADEntity std::shared_ptr

Implements lc::entity::CADEntity.

Definition at line 50 of file insert.cpp.

50  {
51  auto newEntity = std::make_shared<Insert>(shared_from_this());
52  newEntity->_position = _position + offset;
53 
54  return newEntity;
55 }
geo::Coordinate _position
Definition: insert.h:52
void Insert::dispatch ( EntityDispatch dispatch) const
overridevirtual

Implements lc::entity::CADEntity.

Definition at line 87 of file insert.cpp.

87  {
88  //TODO
89 }
const Block_CSPtr & Insert::displayBlock ( ) const

Definition at line 35 of file insert.cpp.

35  {
36  return _displayBlock;
37 }
Block_CSPtr _displayBlock
Definition: insert.h:53
const Document_SPtr & Insert::document ( ) const

Definition at line 129 of file insert.cpp.

129  {
130  return _document;
131 }
Document_SPtr _document
Definition: insert.h:51
std::map< unsigned int, geo::Coordinate > entity::Insert::dragPoints ( ) const
overridevirtual

Get all points of the entity that can be dragged.

Returns
Map of points

Implements lc::Draggable.

Definition at line 91 of file insert.cpp.

91  {
92  auto result = std::map<unsigned int, geo::Coordinate>();
93 
94  result.insert(std::pair<unsigned int, geo::Coordinate>(0, _position));
95 
96  return result;
97 }
geo::Coordinate _position
Definition: insert.h:52
CADEntity_CSPtr Insert::mirror ( const geo::Coordinate axis1,
const geo::Coordinate axis2 
) const
overridevirtual

Implements lc::entity::CADEntity.

Definition at line 67 of file insert.cpp.

67  {
68  //TODO
69  return shared_from_this();
70 }
CADEntity_CSPtr Insert::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 76 of file insert.cpp.

76  {
77  auto builder = builder::InsertBuilder();
78 
79  builder.copy(shared_from_this());
80  builder.setLayer(layer);
81  builder.setMetaInfo(metaInfo);
82  builder.setBlock(block);
83 
84  return builder.build();
85 }
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
CADEntity_CSPtr Insert::move ( const geo::Coordinate offset) const
overridevirtual

Function for Move.

Parameters
offsetthe offset by which entity is to be moved
Returns
CADEntity std::shared_ptr

Implements lc::entity::CADEntity.

Definition at line 43 of file insert.cpp.

43  {
44  auto newEntity = std::make_shared<Insert>(shared_from_this(), true);
45  newEntity->_position = _position + offset;
46 
47  return newEntity;
48 }
geo::Coordinate _position
Definition: insert.h:52
geo::Coordinate Insert::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.

Reimplemented in lc::entity::CustomEntity.

Definition at line 125 of file insert.cpp.

125  {
126  return _position;
127 }
geo::Coordinate _position
Definition: insert.h:52
void Insert::on_addEntityEvent ( const lc::AddEntityEvent event)
private

Definition at line 153 of file insert.cpp.

153  {
154  if(event.entity()->block() == _displayBlock) {
156  }
157 }
Block_CSPtr _displayBlock
Definition: insert.h:53
void calculateBoundingBox()
Definition: insert.cpp:133
const entity::CADEntity_CSPtr entity() const
Returns the entity without cast.
void Insert::on_removeEntityEvent ( const lc::RemoveEntityEvent event)
private

Definition at line 159 of file insert.cpp.

159  {
160  if(event.entity()->block() == _displayBlock) {
162  }
163 }
entity::CADEntity_CSPtr entity() const
Returns the ID.
Block_CSPtr _displayBlock
Definition: insert.h:53
void calculateBoundingBox()
Definition: insert.cpp:133
const geo::Coordinate & Insert::position ( ) const

Definition at line 39 of file insert.cpp.

39  {
40  return _position;
41 }
geo::Coordinate _position
Definition: insert.h:52
CADEntity_CSPtr Insert::rotate ( const geo::Coordinate rotation_center,
const double  rotation_angle 
) const
overridevirtual

Function implementation for rotate.

Parameters
angleangle by which the entity is to be rotated.
Returns
CADEntity std::shared_ptr

Implements lc::entity::CADEntity.

Definition at line 57 of file insert.cpp.

57  {
58  //TODO
59  return shared_from_this();
60 }
CADEntity_CSPtr Insert::scale ( const geo::Coordinate scale_center,
const geo::Coordinate scale_factor 
) const
overridevirtual

Function implementation for Scale.

Parameters
scale_center
scale_factor
Returns
CADEntity std::shared_ptr

Implements lc::entity::CADEntity.

Definition at line 62 of file insert.cpp.

62  {
63  //TODO
64  return shared_from_this();
65 }
entity::CADEntity_CSPtr entity::Insert::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 99 of file insert.cpp.

99  {
100  try {
101  auto newEntity = std::make_shared<Insert>(shared_from_this(), true);
102  newEntity->_position = dragPoints.at(0);
103 
104  return newEntity;
105  }
106  catch(std::out_of_range& e) {
107  return shared_from_this();
108  }
109 }
std::map< unsigned int, geo::Coordinate > dragPoints() const override
Get all points of the entity that can be dragged.
Definition: insert.cpp:91
std::vector< lc::EntityCoordinate > entity::Insert::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.

Reimplemented in lc::entity::CustomEntity.

Definition at line 111 of file insert.cpp.

114  {
115  std::vector<EntityCoordinate> points;
116 
117  if (simpleSnapConstrain.constrain() & SimpleSnapConstrain::LOGICAL) {
118  points.emplace_back(_position, 0);
119  }
120 
121  Snapable::snapPointsCleanup(points, coord, maxNumberOfSnapPoints, minDistanceToSnap);
122  return points;
123 }
static const uint16_t LOGICAL
Definition: snapconstrain.h:22
static void snapPointsCleanup(std::vector< EntityCoordinate > &points, const geo::Coordinate &reference, const unsigned int maxNumberOfSnapPoints, const double minDistanceToSnap)
Definition: snapable.h:53
geo::Coordinate _position
Definition: insert.h:52
const uint16_t constrain() const
Definition: snapconstrain.h:47

Friends And Related Function Documentation

friend class builder::InsertBuilder
friend

Definition at line 13 of file insert.h.

Member Data Documentation

geo::Area lc::entity::Insert::_boundingBox
private

Definition at line 54 of file insert.h.

Block_CSPtr lc::entity::Insert::_displayBlock
private

Definition at line 53 of file insert.h.

Document_SPtr lc::entity::Insert::_document
private

Definition at line 51 of file insert.h.

geo::Coordinate lc::entity::Insert::_position
private

Definition at line 52 of file insert.h.


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