]> Shamusworld >> Repos - architektonas/blob - src/actions/actionmodifydeletefree.cpp
Removed useless *Listener class and references.
[architektonas] / src / actions / actionmodifydeletefree.cpp
1 // actionmodifydeletefree.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 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
9 //
10 // JLH = James L. Hammons <jlhamm@acm.org>
11 //
12 // Who  When        What
13 // ---  ----------  -----------------------------------------------------------
14 // JLH  06/04/2010  Added this text. :-)
15 //
16
17 #include "actionmodifydeletefree.h"
18
19 #include "rs_dialogfactory.h"
20 #include "graphicview.h"
21 #include "rs_modification.h"
22 #include "rs_polyline.h"
23 #include "rs_undo.h"
24
25 ActionModifyDeleteFree::ActionModifyDeleteFree(RS_EntityContainer & container,
26         GraphicView & graphicView):
27         ActionInterface("Delete Entities Freehand", container, graphicView)
28 {
29 }
30
31 ActionModifyDeleteFree::~ActionModifyDeleteFree()
32 {
33 }
34
35 void ActionModifyDeleteFree::init(int status)
36 {
37         ActionInterface::init(status);
38         polyline = NULL;
39         e1 = e2 = NULL;
40         v1 = v2 = Vector(false);
41 //      setSnapMode(RS2::SnapOnEntity);
42 }
43
44 void ActionModifyDeleteFree::trigger()
45 {
46         if (e1 && e2)
47         {
48                 RS_EntityContainer * parent = e2->getParent();
49
50                 if (parent)
51                 {
52                         if (parent->rtti() == RS2::EntityPolyline)
53                         {
54                                 if (parent->getId() == polyline->getId())
55                                 {
56                                         // deletes whole polyline on screen:
57                                         graphicView->deleteEntity((RS_Entity *)polyline);
58
59                                         // splits up the polyline in the container:
60                                         RS_Polyline * pl1;
61                                         RS_Polyline * pl2;
62                                         RS_Modification m(*container);
63                                         m.splitPolyline(*polyline, *e1, v1, *e2, v2, &pl1, &pl2);
64
65                                         if (document)
66                                         {
67                                                 document->startUndoCycle();
68                                                 document->addUndoable(polyline);
69                                                 document->addUndoable(pl1);
70                                                 document->addUndoable(pl2);
71                                                 document->endUndoCycle();
72                                         }
73
74                                         // draws the new polylines on the screen:
75                                         graphicView->drawEntity((RS_Entity *)pl1);
76                                         graphicView->drawEntity((RS_Entity *)pl2);
77
78                                         init();
79
80                                         RS_DIALOGFACTORY->updateSelectionWidget(
81                                                 container->countSelected());
82                                 }
83                                 else
84                                         RS_DIALOGFACTORY->commandMessage(tr("Entities not in the same polyline."));
85                         }
86                         else
87                                 RS_DIALOGFACTORY->commandMessage(tr("Parent of second entity is not a polyline"));
88                 }
89                 else
90                         RS_DIALOGFACTORY->commandMessage(tr("Parent of second entity is NULL"));
91         }
92         else
93                 RS_DIALOGFACTORY->commandMessage(tr("One of the chosen entities is NULL"));
94 }
95
96 void ActionModifyDeleteFree::mouseReleaseEvent(QMouseEvent * e)
97 {
98         if (e->button() == Qt::RightButton)
99                 init(getStatus() - 1);
100         else
101         {
102                 switch (getStatus())
103                 {
104                 case 0:
105                         v1 = snapPoint(e);
106 //                      e1 = getKeyEntity();
107                         e1 = graphicView->snapper.getKeyEntity();
108
109                         if (e1)
110                         {
111                                 RS_EntityContainer * parent = e1->getParent();
112
113                                 if (parent)
114                                 {
115                                         if (parent->rtti() == RS2::EntityPolyline)
116                                         {
117                                                 polyline = (RS_Polyline *)parent;
118                                                 setStatus(1);
119                                         }
120                                         else
121                                                 RS_DIALOGFACTORY->commandMessage(
122                                                         tr("Parent of first entity is not a polyline"));
123                                 }
124                                 else
125                                         RS_DIALOGFACTORY->commandMessage(
126                                                 tr("Parent of first entity is NULL"));
127                         }
128                         else
129                                 RS_DIALOGFACTORY->commandMessage(
130                                         tr("First entity is NULL"));
131
132                         break;
133
134                 case 1:
135                         v2 = snapPoint(e);
136 //                      e2 = getKeyEntity();
137                         e2 = graphicView->snapper.getKeyEntity();
138
139                         if (e2)
140                                 trigger();
141                         else
142                                 RS_DIALOGFACTORY->commandMessage(tr("Second entity is NULL"));
143
144                         break;
145                 }
146         }
147 }
148
149 void ActionModifyDeleteFree::updateMouseButtonHints()
150 {
151         switch (getStatus())
152         {
153         case 0:
154                 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first break point "
155                         "on a polyline"), tr("Cancel"));
156                 break;
157
158         case 1:
159                 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second break point "
160                         "on the same polyline"), tr("Back"));
161                 break;
162
163         default:
164                 RS_DIALOGFACTORY->updateMouseWidget("", "");
165                 break;
166         }
167 }