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