]> Shamusworld >> Repos - architektonas/blob - src/actions/actionmodifymirror.cpp
Bugfixes related to removing Snapper class.
[architektonas] / src / actions / actionmodifymirror.cpp
1 // actionmodifymirror.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 "actionmodifymirror.h"
18
19 #include "debug.h"
20 #include "dialogfactory.h"
21 #include "preview.h"
22
23 ActionModifyMirror::ActionModifyMirror(EntityContainer & container, GraphicView & graphicView):
24         ActionInterface("Mirror Entities", container, graphicView)
25 {
26 }
27
28 ActionModifyMirror::~ActionModifyMirror()
29 {
30 }
31
32 void ActionModifyMirror::init(int status)
33 {
34         ActionInterface::init(status);
35 }
36
37 void ActionModifyMirror::trigger()
38 {
39         DEBUG->print("ActionModifyMirror::trigger()");
40
41         Modification m(*container, graphicView);
42         m.mirror(data);
43
44         if (DIALOGFACTORY)
45                 DIALOGFACTORY->updateSelectionWidget(container->countSelected());
46 }
47
48 void ActionModifyMirror::mouseMoveEvent(QMouseEvent * e)
49 {
50         DEBUG->print("ActionModifyMirror::mouseMoveEvent begin");
51
52         if (getStatus() == SetAxisPoint1 || getStatus() == SetAxisPoint2)
53         {
54                 Vector mouse = snapPoint(e);
55
56                 switch (getStatus())
57                 {
58                 case SetAxisPoint1:
59                         axisPoint1 = mouse;
60                         break;
61
62                 case SetAxisPoint2:
63
64                         if (axisPoint1.valid)
65                         {
66                                 axisPoint2 = mouse;
67
68 //                              deletePreview();
69 //                              clearPreview();
70 /*                              preview->addSelectionFrom(*container);
71                                 preview->mirror(axisPoint1, axisPoint2);
72                                 preview->addEntity(new Line(preview,LineData(axisPoint1, axisPoint2)));*/
73 //                              drawPreview();
74                                 graphicView->preview.clear();
75                                 graphicView->preview.addSelectionFrom(*container);
76                                 graphicView->preview.mirror(axisPoint1, axisPoint2);
77                                 graphicView->preview.addEntity(new Line(&(graphicView->preview), LineData(axisPoint1, axisPoint2)));
78                                 graphicView->redraw();
79                         }
80                         break;
81
82                 default:
83                         break;
84                 }
85
86                 graphicView->redraw();
87         }
88
89         DEBUG->print("ActionModifyMirror::mouseMoveEvent end");
90 }
91
92 void ActionModifyMirror::mouseReleaseEvent(QMouseEvent * e)
93 {
94         if (e->button() == Qt::LeftButton)
95         {
96                 Vector ce(snapPoint(e));
97                 coordinateEvent(&ce);
98         }
99         else if (e->button() == Qt::RightButton)
100         {
101 //              deletePreview();
102 //              deleteSnapper();
103                 init(getStatus() - 1);
104                 graphicView->redraw();  //hm.
105         }
106 }
107
108 void ActionModifyMirror::coordinateEvent(Vector * e)
109 {
110         if (!e)
111                 return;
112
113         Vector mouse = *e;
114
115         switch (getStatus())
116         {
117         case SetAxisPoint1:
118                 axisPoint1 = mouse;
119                 setStatus(SetAxisPoint2);
120                 graphicView->moveRelativeZero(mouse);
121                 break;
122
123         case SetAxisPoint2:
124                 axisPoint2 = mouse;
125                 setStatus(ShowDialog);
126                 graphicView->moveRelativeZero(mouse);
127
128                 if (DIALOGFACTORY)
129                 {
130                         if (DIALOGFACTORY->requestMirrorDialog(data))
131                         {
132                                 data.axisPoint1 = axisPoint1;
133                                 data.axisPoint2 = axisPoint2;
134 //                              deletePreview();
135 //                              clearPreview();
136                                 trigger();
137                                 finish();
138                                 graphicView->redraw();  //hm.
139                         }
140                 }
141                 break;
142
143         default:
144                 break;
145         }
146 }
147
148 void ActionModifyMirror::updateMouseButtonHints()
149 {
150         if (DIALOGFACTORY)
151         {
152                 switch (getStatus())
153                 {
154                 /*case Select:
155                     DIALOGFACTORY->updateMouseWidget(tr("Pick entities to move"),
156                                                    tr("Cancel"));
157                     break;*/
158                 case SetAxisPoint1:
159                         DIALOGFACTORY->updateMouseWidget(
160                                 tr("Specify first point of mirror line"), tr("Cancel"));
161                         break;
162
163                 case SetAxisPoint2:
164                         DIALOGFACTORY->updateMouseWidget(
165                                 tr("Specify second point of mirror line"), tr("Back"));
166                         break;
167
168                 default:
169                         DIALOGFACTORY->updateMouseWidget("", "");
170                         break;
171                 }
172         }
173 }
174
175 void ActionModifyMirror::updateMouseCursor()
176 {
177         graphicView->setMouseCursor(RS2::CadCursor);
178 }
179
180 void ActionModifyMirror::updateToolBar()
181 {
182         if (DIALOGFACTORY)
183         {
184                 switch (getStatus())
185                 {
186                 case SetAxisPoint1:
187                 case SetAxisPoint2:
188                         DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
189                         break;
190
191                 default:
192                         DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
193                         break;
194                 }
195         }
196 }