]> Shamusworld >> Repos - architektonas/blob - src/actions/actionmodifydeletefree.cpp
Bugfixes related to removing Snapper class.
[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 "dialogfactory.h"
20 #include "graphicview.h"
21 #include "modification.h"
22 #include "polyline.h"
23 #include "undo.h"
24
25 ActionModifyDeleteFree::ActionModifyDeleteFree(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                 EntityContainer * parent = e2->getParent();
49
50                 if (parent)
51                 {
52                         if (parent->rtti() == RS2::EntityPolyline)
53                         {
54                                 if (parent->getId() == polyline->getId())
55                                 {
56 #warning "!!! Old rendering path need upgrade !!!"
57 #if 0
58                                         // deletes whole polyline on screen:
59                                         graphicView->deleteEntity((Entity *)polyline);
60 #endif
61
62                                         // splits up the polyline in the container:
63                                         Polyline * pl1;
64                                         Polyline * pl2;
65                                         Modification m(*container);
66                                         m.splitPolyline(*polyline, *e1, v1, *e2, v2, &pl1, &pl2);
67
68                                         if (document)
69                                         {
70                                                 document->startUndoCycle();
71                                                 document->addUndoable(polyline);
72                                                 document->addUndoable(pl1);
73                                                 document->addUndoable(pl2);
74                                                 document->endUndoCycle();
75                                         }
76
77                                         // draws the new polylines on the screen:
78                                         graphicView->drawEntity((Entity *)pl1);
79                                         graphicView->drawEntity((Entity *)pl2);
80
81                                         init();
82
83                                         DIALOGFACTORY->updateSelectionWidget(
84                                                 container->countSelected());
85                                 }
86                                 else
87                                         DIALOGFACTORY->commandMessage(tr("Entities not in the same polyline."));
88                         }
89                         else
90                                 DIALOGFACTORY->commandMessage(tr("Parent of second entity is not a polyline"));
91                 }
92                 else
93                         DIALOGFACTORY->commandMessage(tr("Parent of second entity is NULL"));
94         }
95         else
96                 DIALOGFACTORY->commandMessage(tr("One of the chosen entities is NULL"));
97 }
98
99 void ActionModifyDeleteFree::mouseReleaseEvent(QMouseEvent * e)
100 {
101         if (e->button() == Qt::RightButton)
102                 init(getStatus() - 1);
103         else
104         {
105                 switch (getStatus())
106                 {
107                 case 0:
108                         v1 = snapPoint(e);
109 //                      e1 = getKeyEntity();
110                         e1 = graphicView->GetSnapperEntity();
111
112                         if (e1)
113                         {
114                                 EntityContainer * parent = e1->getParent();
115
116                                 if (parent)
117                                 {
118                                         if (parent->rtti() == RS2::EntityPolyline)
119                                         {
120                                                 polyline = (Polyline *)parent;
121                                                 setStatus(1);
122                                         }
123                                         else
124                                                 DIALOGFACTORY->commandMessage(
125                                                         tr("Parent of first entity is not a polyline"));
126                                 }
127                                 else
128                                         DIALOGFACTORY->commandMessage(
129                                                 tr("Parent of first entity is NULL"));
130                         }
131                         else
132                                 DIALOGFACTORY->commandMessage(
133                                         tr("First entity is NULL"));
134
135                         break;
136
137                 case 1:
138                         v2 = snapPoint(e);
139 //                      e2 = getKeyEntity();
140                         e2 = graphicView->GetSnapperEntity();
141
142                         if (e2)
143                                 trigger();
144                         else
145                                 DIALOGFACTORY->commandMessage(tr("Second entity is NULL"));
146
147                         break;
148                 }
149         }
150 }
151
152 void ActionModifyDeleteFree::updateMouseButtonHints()
153 {
154         switch (getStatus())
155         {
156         case 0:
157                 DIALOGFACTORY->updateMouseWidget(tr("Specify first break point "
158                         "on a polyline"), tr("Cancel"));
159                 break;
160
161         case 1:
162                 DIALOGFACTORY->updateMouseWidget(tr("Specify second break point "
163                         "on the same polyline"), tr("Back"));
164                 break;
165
166         default:
167                 DIALOGFACTORY->updateMouseWidget("", "");
168                 break;
169         }
170 }