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

#include <layerops.h>

Inheritance diagram for lc::operation::RemoveLayer:
Collaboration diagram for lc::operation::RemoveLayer:

Public Member Functions

 RemoveLayer (std::shared_ptr< Document > document, const Layer_CSPtr layer)
 
virtual void undo () const
 Undo a given operation. More...
 
virtual void redo () const
 Redo a given operation. 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

Layer_CSPtr _layer
 
std::vector
< entity::CADEntity_CSPtr > 
_entities
 

Detailed Description

Remove layer from document

Definition at line 32 of file layerops.h.

Constructor & Destructor Documentation

RemoveLayer::RemoveLayer ( std::shared_ptr< Document document,
const Layer_CSPtr  layer 
)

RemoveLayer

Definition at line 30 of file layerops.cpp.

30  :
31  DocumentOperation(document, "RemoveLayer"),
32  _layer(layer) {
33 
34  if(layer->name() == "0") {
35  throw "Layer 0 cannot be removed";
36  }
37 
38 }
DocumentOperation(Document_SPtr document, const std::string &description)

Member Function Documentation

void RemoveLayer::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 40 of file layerops.cpp.

40  {
41  auto le = document()->entityContainer().entitiesByLayer(_layer).asVector();
42  _entities.insert(_entities.end(), le.begin(), le.end());
43 
44  for (auto i : _entities) {
45  document()->removeEntity(i);
46  }
47 
48  document()->removeDocumentMetaType(_layer);
49 }
std::vector< entity::CADEntity_CSPtr > _entities
Definition: layerops.h:46
void RemoveLayer::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 59 of file layerops.cpp.

59  {
60  for (auto i : _entities) {
61  document()->removeEntity(i);
62  }
63 
64  document()->removeDocumentMetaType(_layer);
65 }
std::vector< entity::CADEntity_CSPtr > _entities
Definition: layerops.h:46
void RemoveLayer::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 51 of file layerops.cpp.

51  {
52  document()->addDocumentMetaType(_layer);
53 
54  for (auto i : _entities) {
55  document()->insertEntity(i);
56  }
57 }
std::vector< entity::CADEntity_CSPtr > _entities
Definition: layerops.h:46

Member Data Documentation

std::vector<entity::CADEntity_CSPtr> lc::operation::RemoveLayer::_entities
private

Definition at line 46 of file layerops.h.

Layer_CSPtr lc::operation::RemoveLayer::_layer
private

Definition at line 45 of file layerops.h.


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