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

#include <entitybuilder.h>

Inheritance diagram for lc::operation::EntityBuilder:
Collaboration diagram for lc::operation::EntityBuilder:

Public Member Functions

 EntityBuilder (Document_SPtr document)
 Builder constructor. More...
 
EntityBuilderappendEntity (entity::CADEntity_CSPtr cadEntity)
 append entity to the stack More...
 
EntityBuilderappendOperation (Base_SPtr operation)
 Append operation to the stack. More...
 
virtual void undo () const
 Undo a given operation. More...
 
virtual void redo () const
 Redo a given operation. More...
 
void processStack ()
 Apply the operations Apply operations on the entities without updating the document, and clear the stack. More...
 
- Public Member Functions inherited from lc::operation::DocumentOperation
 DocumentOperation (Document_SPtr document, const std::string &description)
 
Document_SPtr document () const
 
virtual void execute ()
 execute this operation More...
 
virtual ~DocumentOperation ()
 
- Public Member Functions inherited from lc::operation::Undoable
 Undoable (const std::string &text)
 Name of this operartion. More...
 
virtual ~Undoable ()
 
virtual std::string text ()
 Name of the operation. More...
 

Protected Member Functions

virtual void processInternal ()
 

Private Attributes

std::vector< Base_SPtr > _stack
 
std::vector
< entity::CADEntity_CSPtr > 
_workingBuffer
 
std::vector
< entity::CADEntity_CSPtr > 
_entitiesThatWhereUpdated
 
std::vector
< entity::CADEntity_CSPtr > 
_entitiesThatNeedsRemoval
 

Friends

class lc::operation::Base
 

Detailed Description

Definition at line 15 of file entitybuilder.h.

Constructor & Destructor Documentation

EntityBuilder::EntityBuilder ( Document_SPtr  document)

Builder constructor.

Parameters
documentto apply operations

Definition at line 8 of file entitybuilder.cpp.

8  :
9  DocumentOperation(document, "EntityBuilder") {
10 }
DocumentOperation(Document_SPtr document, const std::string &description)

Member Function Documentation

EntityBuilder * EntityBuilder::appendEntity ( entity::CADEntity_CSPtr  cadEntity)

append entity to the stack

Parameters
cadEntity
Returns
EntityOperation

Definition at line 12 of file entitybuilder.cpp.

12  {
13  _workingBuffer.push_back(cadEntity);
14  return this;
15 }
std::vector< entity::CADEntity_CSPtr > _workingBuffer
Definition: entitybuilder.h:53
EntityBuilder * EntityBuilder::appendOperation ( Base_SPtr  operation)

Append operation to the stack.

Parameters
operation
Returns
EntityOperation

Definition at line 17 of file entitybuilder.cpp.

17  {
18  _stack.push_back(operation);
19  return this;
20 }
std::vector< Base_SPtr > _stack
Definition: entitybuilder.h:52
void EntityBuilder::processInternal ( )
protectedvirtual

This function gets called when an operation starts and when the document is locked for you so you can do your work

Implements lc::operation::DocumentOperation.

Definition at line 22 of file entitybuilder.cpp.

22  {
23  processStack();
24 
25  auto ec = document()->entityContainer();
26 
27  // Build a buffer with all entities we need to remove during a undo cycle
28  for (auto entity : _workingBuffer) {
29  auto org = ec.entityByID(entity->id());
30 
31  if (org.get() != nullptr) {
32  _entitiesThatWhereUpdated.push_back(org);
33  }
34  }
35 
36  // Remove entities
37  for (auto entity : _entitiesThatNeedsRemoval) {
38  document()->removeEntity(entity);
39  }
40 
41  // Add/Update all entities in the document
42  for (auto entity : _workingBuffer) {
43  document()->insertEntity(entity);
44  }
45 }
std::vector< entity::CADEntity_CSPtr > _workingBuffer
Definition: entitybuilder.h:53
std::vector< entity::CADEntity_CSPtr > _entitiesThatNeedsRemoval
Definition: entitybuilder.h:56
std::vector< entity::CADEntity_CSPtr > _entitiesThatWhereUpdated
Definition: entitybuilder.h:55
void processStack()
Apply the operations Apply operations on the entities without updating the document, and clear the stack.
void EntityBuilder::processStack ( )

Apply the operations Apply operations on the entities without updating the document, and clear the stack.

Definition at line 71 of file entitybuilder.cpp.

71  {
72  std::vector<entity::CADEntity_CSPtr> entitySet;
73 
74  for (auto it = _stack.begin(); it != _stack.end(); ++it) {
75  // Get looping stack, we currently support only one single loop!!
76  std::vector<Base_SPtr> stack(_stack.begin(), it);
77  entitySet = (*it)->process(document(), entitySet, _workingBuffer, _entitiesThatNeedsRemoval, stack);
78  }
79 
80  _stack.clear();
81 
82  _workingBuffer.insert(_workingBuffer.end(), entitySet.begin(), entitySet.end());
83 }
std::vector< entity::CADEntity_CSPtr > _workingBuffer
Definition: entitybuilder.h:53
std::vector< entity::CADEntity_CSPtr > _entitiesThatNeedsRemoval
Definition: entitybuilder.h:56
std::vector< Base_SPtr > _stack
Definition: entitybuilder.h:52
void EntityBuilder::redo ( ) const
virtual

Redo a given operation.

This can get called if we want to redo a operation. Redo is usually called after an undo operation. If in the undo operation entities where removed, it needs to get added again. it doesn't have to do any re.calculation but just remember what entities have been added or removed.

Implements lc::operation::Undoable.

Definition at line 61 of file entitybuilder.cpp.

61  {
62  for (auto entity : _entitiesThatNeedsRemoval) {
63  document()->removeEntity(entity);
64  }
65 
66  for (auto entity : _workingBuffer) {
67  document()->insertEntity(entity);
68  }
69 }
std::vector< entity::CADEntity_CSPtr > _workingBuffer
Definition: entitybuilder.h:53
std::vector< entity::CADEntity_CSPtr > _entitiesThatNeedsRemoval
Definition: entitybuilder.h:56
void EntityBuilder::undo ( ) const
virtual

Undo a given operation.

For any operation that means for example when it added entities to the document it now needs to remove all created entities on the document. When the operation added a layer or block, it will call functions to remove that block

Implements lc::operation::Undoable.

Definition at line 47 of file entitybuilder.cpp.

47  {
48  for (auto entity : _workingBuffer) {
49  document()->removeEntity(entity);
50  }
51 
52  for (auto entity : _entitiesThatWhereUpdated) {
53  document()->insertEntity(entity);
54  }
55 
56  for (auto entity : _entitiesThatNeedsRemoval) {
57  document()->insertEntity(entity);
58  }
59 }
std::vector< entity::CADEntity_CSPtr > _workingBuffer
Definition: entitybuilder.h:53
std::vector< entity::CADEntity_CSPtr > _entitiesThatNeedsRemoval
Definition: entitybuilder.h:56
std::vector< entity::CADEntity_CSPtr > _entitiesThatWhereUpdated
Definition: entitybuilder.h:55

Friends And Related Function Documentation

friend class lc::operation::Base
friend

Definition at line 16 of file entitybuilder.h.

Member Data Documentation

std::vector<entity::CADEntity_CSPtr> lc::operation::EntityBuilder::_entitiesThatNeedsRemoval
private

Definition at line 56 of file entitybuilder.h.

std::vector<entity::CADEntity_CSPtr> lc::operation::EntityBuilder::_entitiesThatWhereUpdated
private

Definition at line 55 of file entitybuilder.h.

std::vector<Base_SPtr> lc::operation::EntityBuilder::_stack
private

Definition at line 52 of file entitybuilder.h.

std::vector<entity::CADEntity_CSPtr> lc::operation::EntityBuilder::_workingBuffer
private

Definition at line 53 of file entitybuilder.h.


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