]> Shamusworld >> Repos - architektonas/blob - src/actions/actionmodifymirror.cpp
Initial removal of unnecessary rs_ prefixes from files.
[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(RS_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         RS_DEBUG->print("ActionModifyMirror::trigger()");
40
41         RS_Modification m(*container, graphicView);
42         m.mirror(data);
43
44         if (RS_DIALOGFACTORY)
45                 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
46 }
47
48 void ActionModifyMirror::mouseMoveEvent(QMouseEvent * e)
49 {
50         RS_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 RS_Line(preview,RS_LineData(axisPoint1, axisPoint2)));*/
73                                 drawPreview();
74                         }
75                         break;
76
77                 default:
78                         break;
79                 }
80         }
81
82         RS_DEBUG->print("ActionModifyMirror::mouseMoveEvent end");
83 }
84
85 void ActionModifyMirror::mouseReleaseEvent(QMouseEvent * e)
86 {
87         if (e->button() == Qt::LeftButton)
88         {
89                 Vector ce(snapPoint(e));
90                 coordinateEvent(&ce);
91         }
92         else if (e->button() == Qt::RightButton)
93         {
94                 deletePreview();
95                 deleteSnapper();
96                 init(getStatus() - 1);
97         }
98 }
99
100 void ActionModifyMirror::coordinateEvent(Vector * e)
101 {
102         if (!e)
103                 return;
104
105         Vector mouse = *e;
106
107         switch (getStatus())
108         {
109         case SetAxisPoint1:
110                 axisPoint1 = mouse;
111                 setStatus(SetAxisPoint2);
112                 graphicView->moveRelativeZero(mouse);
113                 break;
114
115         case SetAxisPoint2:
116                 axisPoint2 = mouse;
117                 setStatus(ShowDialog);
118                 graphicView->moveRelativeZero(mouse);
119
120                 if (RS_DIALOGFACTORY)
121                 {
122                         if (RS_DIALOGFACTORY->requestMirrorDialog(data))
123                         {
124                                 data.axisPoint1 = axisPoint1;
125                                 data.axisPoint2 = axisPoint2;
126                                 deletePreview();
127                                 clearPreview();
128                                 trigger();
129                                 finish();
130                         }
131                 }
132                 break;
133
134         default:
135                 break;
136         }
137 }
138
139 void ActionModifyMirror::updateMouseButtonHints()
140 {
141         if (RS_DIALOGFACTORY)
142         {
143                 switch (getStatus())
144                 {
145                 /*case Select:
146                     RS_DIALOGFACTORY->updateMouseWidget(tr("Pick entities to move"),
147                                                    tr("Cancel"));
148                     break;*/
149                 case SetAxisPoint1:
150                         RS_DIALOGFACTORY->updateMouseWidget(
151                                 tr("Specify first point of mirror line"),
152                                 tr("Cancel"));
153                         break;
154
155                 case SetAxisPoint2:
156                         RS_DIALOGFACTORY->updateMouseWidget(
157                                 tr("Specify second point of mirror line"),
158                                 tr("Back"));
159                         break;
160
161                 default:
162                         RS_DIALOGFACTORY->updateMouseWidget("", "");
163                         break;
164                 }
165         }
166 }
167
168 void ActionModifyMirror::updateMouseCursor()
169 {
170         graphicView->setMouseCursor(RS2::CadCursor);
171 }
172
173 void ActionModifyMirror::updateToolBar()
174 {
175         if (RS_DIALOGFACTORY != NULL)
176         {
177                 switch (getStatus())
178                 {
179                 case SetAxisPoint1:
180                 case SetAxisPoint2:
181                         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
182                         break;
183
184                 default:
185                         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
186                         break;
187                 }
188         }
189 }