1 /****************************************************************************
2 ** $Id: rs_actionmodifymoverotate.cpp 1161 2004-12-09 23:10:09Z andrew $
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
6 ** This file is part of the qcadlib Library project.
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.
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.
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.
20 ** See http://www.ribbonsoft.com for further details.
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
25 **********************************************************************/
27 #include "rs_actionmodifymoverotate.h"
29 #include "rs_snapper.h"
31 RS_ActionModifyMoveRotate::RS_ActionModifyMoveRotate(
32 RS_EntityContainer& container, RS_GraphicView& graphicView):
33 RS_PreviewActionInterface("Move and Rotate Entities", container, graphicView)
37 QAction * RS_ActionModifyMoveRotate::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/)
39 QAction * action = new QAction(tr("M&ove and Rotate"), 0);
40 // QAction* action = new QAction(tr("Move and Rotate"), tr("M&ove and Rotate"),
41 // QKeySequence(), NULL);
42 action->setStatusTip(tr("Move and Rotate Entities"));
46 void RS_ActionModifyMoveRotate::init(int status)
48 RS_ActionInterface::init(status);
51 void RS_ActionModifyMoveRotate::trigger()
53 RS_DEBUG->print("RS_ActionModifyMoveRotate::trigger()");
55 RS_Modification m(*container, graphicView);
60 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
63 void RS_ActionModifyMoveRotate::mouseMoveEvent(QMouseEvent * e)
65 RS_DEBUG->print("RS_ActionModifyMoveRotate::mouseMoveEvent begin");
67 if (getStatus() == SetReferencePoint || getStatus() == SetTargetPoint)
70 Vector mouse = snapPoint(e);
73 case SetReferencePoint:
74 data.referencePoint = mouse;
78 if (data.referencePoint.valid)
81 data.offset = targetPoint-data.referencePoint;
85 preview->addSelectionFrom(*container);
86 preview->rotate(data.referencePoint, data.angle);
87 preview->move(data.offset);
97 RS_DEBUG->print("RS_ActionModifyMoveRotate::mouseMoveEvent end");
100 void RS_ActionModifyMoveRotate::mouseReleaseEvent(QMouseEvent * e)
102 if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
104 RS_CoordinateEvent ce(snapPoint(e));
105 coordinateEvent(&ce);
107 else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
111 init(getStatus() - 1);
115 void RS_ActionModifyMoveRotate::coordinateEvent(RS_CoordinateEvent * e)
120 Vector pos = e->getCoordinate();
124 case SetReferencePoint:
125 data.referencePoint = pos;
126 setStatus(SetTargetPoint);
132 setStatus(ShowDialog);
133 data.offset = targetPoint - data.referencePoint;
134 if (RS_DIALOGFACTORY->requestMoveRotateDialog(data))
146 void RS_ActionModifyMoveRotate::commandEvent(RS_CommandEvent * e)
148 QString c = e->getCommand().toLower();
150 if (checkCommand("help", c))
152 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + getAvailableCommands().join(", "));
158 case SetReferencePoint:
160 #warning "Bad comparison (in checkCommand -> rs_actioninterface)... !!! FIX !!!"
161 if (!c.isEmpty() && checkCommand("angle", c))
162 // if (c == checkCommand("angle", c))
167 lastStatus = (Status)getStatus();
175 double a = RS_Math::eval(c, &ok);
178 data.angle = RS_Math::deg2rad(a);
180 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
182 RS_DIALOGFACTORY->requestOptions(this, true, true);
183 setStatus(lastStatus);
189 QStringList RS_ActionModifyMoveRotate::getAvailableCommands()
195 case SetReferencePoint:
197 cmd += command("angle");
207 void RS_ActionModifyMoveRotate::showOptions()
209 //std::cout << "RS_ActionModifyMoveRotate::showOptions()\n";
211 RS_ActionInterface::showOptions();
213 RS_DIALOGFACTORY->requestOptions(this, true);
216 void RS_ActionModifyMoveRotate::hideOptions()
218 //std::cout << "RS_ActionModifyMoveRotate::hideOptions()\n";
220 RS_ActionInterface::hideOptions();
222 RS_DIALOGFACTORY->requestOptions(this, false);
225 void RS_ActionModifyMoveRotate::updateMouseButtonHints()
229 case SetReferencePoint:
230 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel"));
233 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify target point"), tr("Back"));
236 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter rotation angle:"), tr("Back"));
239 RS_DIALOGFACTORY->updateMouseWidget("", "");
244 void RS_ActionModifyMoveRotate::updateMouseCursor()
246 graphicView->setMouseCursor(RS2::CadCursor);
249 void RS_ActionModifyMoveRotate::updateToolBar()
253 case SetReferencePoint:
255 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
258 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);