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 "commandevent.h"
21 #include "dialogfactory.h"
24 ActionModifyMoveRotate::ActionModifyMoveRotate(
25 EntityContainer & container, GraphicView & graphicView):
26 ActionInterface("Move and Rotate Entities", container, graphicView)
30 ActionModifyMoveRotate::~ActionModifyMoveRotate()
34 /*virtual*/ RS2::ActionType ActionModifyMoveRotate::rtti()
36 return RS2::ActionModifyMoveRotate;
39 void ActionModifyMoveRotate::init(int status)
41 ActionInterface::init(status);
44 void ActionModifyMoveRotate::trigger()
46 DEBUG->print("ActionModifyMoveRotate::trigger()");
48 Modification m(*container, graphicView);
53 DIALOGFACTORY->updateSelectionWidget(container->countSelected());
56 void ActionModifyMoveRotate::mouseMoveEvent(QMouseEvent * e)
58 DEBUG->print("ActionModifyMoveRotate::mouseMoveEvent begin");
60 if (getStatus() == SetReferencePoint || getStatus() == SetTargetPoint)
62 Vector mouse = snapPoint(e);
66 case SetReferencePoint:
67 data.referencePoint = mouse;
72 if (data.referencePoint.valid)
75 data.offset = targetPoint - data.referencePoint;
79 /* preview->addSelectionFrom(*container);
80 preview->rotate(data.referencePoint, data.angle);
81 preview->move(data.offset);*/
91 DEBUG->print("ActionModifyMoveRotate::mouseMoveEvent end");
94 void ActionModifyMoveRotate::mouseReleaseEvent(QMouseEvent * e)
96 if (e->button() == Qt::LeftButton)
98 Vector ce(snapPoint(e));
101 else if (e->button() == Qt::RightButton)
105 init(getStatus() - 1);
109 void ActionModifyMoveRotate::coordinateEvent(Vector * e)
118 case SetReferencePoint:
119 data.referencePoint = pos;
120 setStatus(SetTargetPoint);
126 setStatus(ShowDialog);
127 data.offset = targetPoint - data.referencePoint;
129 if (DIALOGFACTORY->requestMoveRotateDialog(data))
139 void ActionModifyMoveRotate::commandEvent(CommandEvent * e)
141 QString c = e->getCommand().toLower();
143 if (checkCommand("help", c))
145 DIALOGFACTORY->commandMessage(msgAvailableCommands() + getAvailableCommands().join(", "));
151 case SetReferencePoint:
153 #warning "Bad comparison (in checkCommand -> rs_actioninterface)... !!! FIX !!!"
155 if (!c.isEmpty() && checkCommand("angle", c))
156 // if (c == checkCommand("angle", c))
161 lastStatus = (Status)getStatus();
169 double a = Math::eval(c, &ok);
172 data.angle = Math::deg2rad(a);
174 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
176 DIALOGFACTORY->requestOptions(this, true, true);
177 setStatus(lastStatus);
183 QStringList ActionModifyMoveRotate::getAvailableCommands()
189 case SetReferencePoint:
191 cmd += command("angle");
201 void ActionModifyMoveRotate::showOptions()
203 //std::cout << "ActionModifyMoveRotate::showOptions()\n";
205 ActionInterface::showOptions();
207 DIALOGFACTORY->requestOptions(this, true);
210 void ActionModifyMoveRotate::hideOptions()
212 //std::cout << "ActionModifyMoveRotate::hideOptions()\n";
214 ActionInterface::hideOptions();
216 DIALOGFACTORY->requestOptions(this, false);
219 void ActionModifyMoveRotate::updateMouseButtonHints()
223 case SetReferencePoint:
224 DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel"));
228 DIALOGFACTORY->updateMouseWidget(tr("Specify target point"), tr("Back"));
232 DIALOGFACTORY->updateMouseWidget(tr("Enter rotation angle:"), tr("Back"));
236 DIALOGFACTORY->updateMouseWidget("", "");
241 void ActionModifyMoveRotate::updateMouseCursor()
243 graphicView->setMouseCursor(RS2::CadCursor);
246 void ActionModifyMoveRotate::updateToolBar()
250 case SetReferencePoint:
252 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
256 DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
261 void ActionModifyMoveRotate::setAngle(double a)
266 double ActionModifyMoveRotate::getAngle()