1 // actionmodifymoverotate.cpp
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 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 06/04/2010 Added this text. :-)
17 #include "actionmodifymoverotate.h"
19 #include "rs_commandevent.h"
20 #include "rs_dialogfactory.h"
21 #include "rs_preview.h"
23 ActionModifyMoveRotate::ActionModifyMoveRotate(
24 RS_EntityContainer & container, GraphicView & graphicView):
25 ActionInterface("Move and Rotate Entities", container, graphicView)
29 ActionModifyMoveRotate::~ActionModifyMoveRotate()
33 /*virtual*/ RS2::ActionType ActionModifyMoveRotate::rtti()
35 return RS2::ActionModifyMoveRotate;
38 void ActionModifyMoveRotate::init(int status)
40 ActionInterface::init(status);
43 void ActionModifyMoveRotate::trigger()
45 RS_DEBUG->print("ActionModifyMoveRotate::trigger()");
47 RS_Modification m(*container, graphicView);
52 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
55 void ActionModifyMoveRotate::mouseMoveEvent(QMouseEvent * e)
57 RS_DEBUG->print("ActionModifyMoveRotate::mouseMoveEvent begin");
59 if (getStatus() == SetReferencePoint || getStatus() == SetTargetPoint)
61 Vector mouse = snapPoint(e);
65 case SetReferencePoint:
66 data.referencePoint = mouse;
71 if (data.referencePoint.valid)
74 data.offset = targetPoint - data.referencePoint;
78 /* preview->addSelectionFrom(*container);
79 preview->rotate(data.referencePoint, data.angle);
80 preview->move(data.offset);*/
90 RS_DEBUG->print("ActionModifyMoveRotate::mouseMoveEvent end");
93 void ActionModifyMoveRotate::mouseReleaseEvent(QMouseEvent * e)
95 if (e->button() == Qt::LeftButton)
97 Vector ce(snapPoint(e));
100 else if (e->button() == Qt::RightButton)
104 init(getStatus() - 1);
108 void ActionModifyMoveRotate::coordinateEvent(Vector * e)
117 case SetReferencePoint:
118 data.referencePoint = pos;
119 setStatus(SetTargetPoint);
125 setStatus(ShowDialog);
126 data.offset = targetPoint - data.referencePoint;
128 if (RS_DIALOGFACTORY->requestMoveRotateDialog(data))
138 void ActionModifyMoveRotate::commandEvent(RS_CommandEvent * e)
140 QString c = e->getCommand().toLower();
142 if (checkCommand("help", c))
144 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + getAvailableCommands().join(", "));
150 case SetReferencePoint:
152 #warning "Bad comparison (in checkCommand -> rs_actioninterface)... !!! FIX !!!"
154 if (!c.isEmpty() && checkCommand("angle", c))
155 // if (c == checkCommand("angle", c))
160 lastStatus = (Status)getStatus();
168 double a = RS_Math::eval(c, &ok);
171 data.angle = RS_Math::deg2rad(a);
173 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
175 RS_DIALOGFACTORY->requestOptions(this, true, true);
176 setStatus(lastStatus);
182 QStringList ActionModifyMoveRotate::getAvailableCommands()
188 case SetReferencePoint:
190 cmd += command("angle");
200 void ActionModifyMoveRotate::showOptions()
202 //std::cout << "ActionModifyMoveRotate::showOptions()\n";
204 ActionInterface::showOptions();
206 RS_DIALOGFACTORY->requestOptions(this, true);
209 void ActionModifyMoveRotate::hideOptions()
211 //std::cout << "ActionModifyMoveRotate::hideOptions()\n";
213 ActionInterface::hideOptions();
215 RS_DIALOGFACTORY->requestOptions(this, false);
218 void ActionModifyMoveRotate::updateMouseButtonHints()
222 case SetReferencePoint:
223 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel"));
227 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify target point"), tr("Back"));
231 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter rotation angle:"), tr("Back"));
235 RS_DIALOGFACTORY->updateMouseWidget("", "");
240 void ActionModifyMoveRotate::updateMouseCursor()
242 graphicView->setMouseCursor(RS2::CadCursor);
245 void ActionModifyMoveRotate::updateToolBar()
249 case SetReferencePoint:
251 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
255 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
260 void ActionModifyMoveRotate::setAngle(double a)
265 double ActionModifyMoveRotate::getAngle()