]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actionlayerstogglelock.cpp
Major refactoring of actions: Moved implementation from header files
[architektonas] / src / actions / rs_actionlayerstogglelock.cpp
1 // rs_actionlayerstogglelock.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // (C) 2010 Underground Software
7 //
8 // JLH = James L. Hammons <jlhamm@acm.org>
9 //
10 // Who  When        What
11 // ---  ----------  -----------------------------------------------------------
12 // JLH  06/04/2010  Added this text. :-)
13 //
14
15 #include "rs_actionlayerstogglelock.h"
16
17 #include "rs_graphicview.h"
18 #include "drawing.h"
19
20 RS_ActionLayersToggleLock::RS_ActionLayersToggleLock(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionInterface("Toggle Layer Visibility",
21                 container, graphicView)
22 {
23 }
24
25 RS_ActionLayersToggleLock::~RS_ActionLayersToggleLock()
26 {
27 }
28
29 void RS_ActionLayersToggleLock::trigger()
30 {
31         RS_DEBUG->print("toggle layer");
32
33         if (graphic != NULL)
34         {
35                 RS_Layer * layer = graphic->getActiveLayer();
36
37                 if (layer != NULL)
38                 {
39                         graphic->toggleLayerLock(layer);
40
41                         // deselect entities on locked layer:
42                         if (layer->isLocked())
43                                 for (RS_Entity * e = container->firstEntity(); e != NULL;
44                                      e = container->nextEntity())
45                                         if (e != NULL && e->isVisible() && e->getLayer() == layer)
46                                         {
47                                                 if (graphicView != NULL)
48                                                         graphicView->deleteEntity(e);
49
50                                                 e->setSelected(false);
51
52                                                 if (graphicView != NULL)
53                                                         graphicView->drawEntity(e);
54                                         }
55                 }
56         }
57
58         finish();
59 }
60
61 void RS_ActionLayersToggleLock::init(int status)
62 {
63         RS_ActionInterface::init(status);
64         trigger();
65 }
66