]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actionmodifymirror.cpp
1f45971b3269091688d5cd623a90613d746aa5fe
[architektonas] / src / actions / rs_actionmodifymirror.cpp
1 /****************************************************************************
2 ** $Id: rs_actionmodifymirror.cpp 1161 2004-12-09 23:10:09Z andrew $
3 **
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
5 **
6 ** This file is part of the qcadlib Library project.
7 **
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
12 **
13 ** Licensees holding valid qcadlib Professional Edition licenses may use
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
16 **
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 **
20 ** See http://www.ribbonsoft.com for further details.
21 **
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
23 ** not clear to you.
24 **
25 **********************************************************************/
26
27 #include "rs_actionmodifymirror.h"
28
29 #include "rs_snapper.h"
30
31 RS_ActionModifyMirror::RS_ActionModifyMirror(RS_EntityContainer& container,
32         RS_GraphicView& graphicView):
33         RS_PreviewActionInterface("Mirror Entities", container, graphicView)
34 {
35 }
36
37 QAction * RS_ActionModifyMirror::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/)
38 {
39         QAction * action = new QAction(tr("&Mirror"), 0);
40 //      QAction* action = new QAction(tr("Mirror"), tr("&Mirror"),
41 //                                                                      QKeySequence(), NULL);
42         action->setStatusTip(tr("Mirror Entities"));
43         return action;
44 }
45
46 void RS_ActionModifyMirror::init(int status)
47 {
48     RS_ActionInterface::init(status);
49 }
50
51 void RS_ActionModifyMirror::trigger()
52 {
53
54     RS_DEBUG->print("RS_ActionModifyMirror::trigger()");
55
56     RS_Modification m(*container, graphicView);
57     m.mirror(data);
58
59     if (RS_DIALOGFACTORY!=NULL) {
60         RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
61     }
62 }
63
64
65
66 void RS_ActionModifyMirror::mouseMoveEvent(QMouseEvent* e) {
67     RS_DEBUG->print("RS_ActionModifyMirror::mouseMoveEvent begin");
68
69     if (getStatus()==SetAxisPoint1 ||
70             getStatus()==SetAxisPoint2) {
71
72         Vector mouse = snapPoint(e);
73         switch (getStatus()) {
74         case SetAxisPoint1:
75             axisPoint1 = mouse;
76             break;
77
78         case SetAxisPoint2:
79             if (axisPoint1.valid) {
80                 axisPoint2 = mouse;
81
82                 deletePreview();
83                 clearPreview();
84                 preview->addSelectionFrom(*container);
85                 preview->mirror(axisPoint1, axisPoint2);
86
87                 preview->addEntity(new RS_Line(preview,
88                                                RS_LineData(axisPoint1,
89                                                            axisPoint2)));
90
91                 drawPreview();
92             }
93             break;
94
95         default:
96             break;
97         }
98     }
99
100     RS_DEBUG->print("RS_ActionModifyMirror::mouseMoveEvent end");
101 }
102
103
104
105 void RS_ActionModifyMirror::mouseReleaseEvent(QMouseEvent* e) {
106     if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
107         RS_CoordinateEvent ce(snapPoint(e));
108         coordinateEvent(&ce);
109
110     } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
111         deletePreview();
112         deleteSnapper();
113         init(getStatus()-1);
114     }
115 }
116
117
118
119 void RS_ActionModifyMirror::coordinateEvent(RS_CoordinateEvent* e) {
120     if (e==NULL) {
121         return;
122     }
123
124     Vector mouse = e->getCoordinate();
125
126         switch (getStatus()) {
127         case SetAxisPoint1:
128             axisPoint1 = mouse;
129             setStatus(SetAxisPoint2);
130                 graphicView->moveRelativeZero(mouse);
131             break;
132
133         case SetAxisPoint2:
134             axisPoint2 = mouse;
135             setStatus(ShowDialog);
136                 graphicView->moveRelativeZero(mouse);
137             if (RS_DIALOGFACTORY!=NULL) {
138                 if (RS_DIALOGFACTORY->requestMirrorDialog(data)) {
139                     data.axisPoint1 = axisPoint1;
140                     data.axisPoint2 = axisPoint2;
141                     deletePreview();
142                     clearPreview();
143                     trigger();
144                     finish();
145                 }
146             }
147             break;
148
149         default:
150             break;
151         }
152 }
153
154
155
156 void RS_ActionModifyMirror::updateMouseButtonHints() {
157     if (RS_DIALOGFACTORY!=NULL) {
158         switch (getStatus()) {
159             /*case Select:
160                 RS_DIALOGFACTORY->updateMouseWidget(tr("Pick entities to move"),
161                                                tr("Cancel"));
162                 break;*/
163         case SetAxisPoint1:
164             RS_DIALOGFACTORY->updateMouseWidget(
165                 tr("Specify first point of mirror line"),
166                 tr("Cancel"));
167             break;
168         case SetAxisPoint2:
169             RS_DIALOGFACTORY->updateMouseWidget(
170                 tr("Specify second point of mirror line"),
171                 tr("Back"));
172             break;
173         default:
174             RS_DIALOGFACTORY->updateMouseWidget("", "");
175             break;
176         }
177     }
178 }
179
180
181
182 void RS_ActionModifyMirror::updateMouseCursor() {
183     graphicView->setMouseCursor(RS2::CadCursor);
184 }
185
186
187
188 void RS_ActionModifyMirror::updateToolBar() {
189     if (RS_DIALOGFACTORY!=NULL) {
190         switch (getStatus()) {
191         case SetAxisPoint1:
192         case SetAxisPoint2:
193             RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
194             break;
195         default:
196             RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
197             break;
198         }
199     }
200 }
201
202
203 // EOF