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