LibreCAD
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
layerops.cpp
Go to the documentation of this file.
1 #include "layerops.h"
3 
4 using namespace lc;
5 using namespace operation;
6 
7 /********************************************************************************************************/
9 /********************************************************************************************************/
10 AddLayer::AddLayer(std::shared_ptr<Document> document, const Layer_CSPtr layer) :
11  DocumentOperation(document, "AddLayer"),
12  _layer(layer) {
13 }
14 
16  document()->addDocumentMetaType(_layer);
17 }
18 
19 void AddLayer::undo() const {
20  document()->removeDocumentMetaType(_layer);
21 }
22 
23 void AddLayer::redo() const {
24  document()->addDocumentMetaType(_layer);
25 }
26 
27 /********************************************************************************************************/
29 /********************************************************************************************************/
30 RemoveLayer::RemoveLayer(std::shared_ptr<Document> document, const Layer_CSPtr layer) :
31  DocumentOperation(document, "RemoveLayer"),
32  _layer(layer) {
33 
34  if(layer->name() == "0") {
35  throw "Layer 0 cannot be removed";
36  }
37 
38 }
39 
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 }
50 
51 void RemoveLayer::undo() const {
52  document()->addDocumentMetaType(_layer);
53 
54  for (auto i : _entities) {
55  document()->insertEntity(i);
56  }
57 }
58 
59 void RemoveLayer::redo() const {
60  for (auto i : _entities) {
61  document()->removeEntity(i);
62  }
63 
64  document()->removeDocumentMetaType(_layer);
65 }
66 
67 
68 /********************************************************************************************************/
70 /********************************************************************************************************/
71 ReplaceLayer::ReplaceLayer(std::shared_ptr<Document> document, const Layer_CSPtr oldLayer, const Layer_CSPtr newLayer) :
72  DocumentOperation(document, "ReplaceLayer"),
73  _oldLayer(oldLayer),
74  _newLayer(newLayer) {
75 }
76 
78  auto le = document()->entityContainer().entitiesByLayer(_oldLayer).asVector();
79 
80  for (auto i : le) {
81  document()->removeEntity(i);
82  document()->insertEntity(i->modify(_newLayer, i->metaInfo(), i->block()));
83  }
84 
85  document()->removeDocumentMetaType(_oldLayer);
86  document()->addDocumentMetaType(_newLayer);
87 }
88 
89 void ReplaceLayer::undo() const {
90 }
91 
92 void ReplaceLayer::redo() const {
93 }
std::vector< entity::CADEntity_CSPtr > _entities
Definition: layerops.h:46
virtual void undo() const
Undo a given operation.
Definition: layerops.cpp:51
Layer_CSPtr _layer
Definition: layerops.h:26
RemoveLayer(std::shared_ptr< Document > document, const Layer_CSPtr layer)
Definition: layerops.cpp:30
virtual void redo() const
Redo a given operation.
Definition: layerops.cpp:23
virtual void processInternal()
Definition: layerops.cpp:40
AddLayer(std::shared_ptr< Document > document, const Layer_CSPtr layer)
Definition: layerops.cpp:10
virtual void redo() const
Redo a given operation.
Definition: layerops.cpp:92
ReplaceLayer(std::shared_ptr< Document > document, const Layer_CSPtr oldLayer, const Layer_CSPtr newLayer)
Definition: layerops.cpp:71
Definition: cadentity.h:12
virtual void processInternal()
Definition: layerops.cpp:77
virtual void processInternal()
Definition: layerops.cpp:15
virtual void undo() const
Undo a given operation.
Definition: layerops.cpp:19
virtual void undo() const
Undo a given operation.
Definition: layerops.cpp:89
virtual void redo() const
Redo a given operation.
Definition: layerops.cpp:59