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