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