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 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 06/04/2010 Added this text. :-)
15 #include "actionmodifymoverotate.h"
17 #include "rs_commandevent.h"
18 #include "rs_dialogfactory.h"
19 #include "rs_preview.h"
21 ActionModifyMoveRotate::ActionModifyMoveRotate(
22 RS_EntityContainer & container, GraphicView & graphicView):
23 ActionInterface("Move and Rotate Entities", container, graphicView)
27 ActionModifyMoveRotate::~ActionModifyMoveRotate()
31 /*virtual*/ RS2::ActionType ActionModifyMoveRotate::rtti()
33 return RS2::ActionModifyMoveRotate;
36 void ActionModifyMoveRotate::init(int status)
38 ActionInterface::init(status);
41 void ActionModifyMoveRotate::trigger()
43 RS_DEBUG->print("ActionModifyMoveRotate::trigger()");
45 RS_Modification m(*container, graphicView);
50 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
53 void ActionModifyMoveRotate::mouseMoveEvent(QMouseEvent * e)
55 RS_DEBUG->print("ActionModifyMoveRotate::mouseMoveEvent begin");
57 if (getStatus() == SetReferencePoint || getStatus() == SetTargetPoint)
59 Vector mouse = snapPoint(e);
63 case SetReferencePoint:
64 data.referencePoint = mouse;
69 if (data.referencePoint.valid)
72 data.offset = targetPoint - data.referencePoint;
76 /* preview->addSelectionFrom(*container);
77 preview->rotate(data.referencePoint, data.angle);
78 preview->move(data.offset);*/
88 RS_DEBUG->print("ActionModifyMoveRotate::mouseMoveEvent end");
91 void ActionModifyMoveRotate::mouseReleaseEvent(QMouseEvent * e)
93 if (e->button() == Qt::LeftButton)
95 Vector ce(snapPoint(e));
98 else if (e->button() == Qt::RightButton)
102 init(getStatus() - 1);
106 void ActionModifyMoveRotate::coordinateEvent(Vector * e)
115 case SetReferencePoint:
116 data.referencePoint = pos;
117 setStatus(SetTargetPoint);
123 setStatus(ShowDialog);
124 data.offset = targetPoint - data.referencePoint;
126 if (RS_DIALOGFACTORY->requestMoveRotateDialog(data))
136 void ActionModifyMoveRotate::commandEvent(RS_CommandEvent * e)
138 QString c = e->getCommand().toLower();
140 if (checkCommand("help", c))
142 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + getAvailableCommands().join(", "));
148 case SetReferencePoint:
150 #warning "Bad comparison (in checkCommand -> rs_actioninterface)... !!! FIX !!!"
152 if (!c.isEmpty() && checkCommand("angle", c))
153 // if (c == checkCommand("angle", c))
158 lastStatus = (Status)getStatus();
166 double a = RS_Math::eval(c, &ok);
169 data.angle = RS_Math::deg2rad(a);
171 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
173 RS_DIALOGFACTORY->requestOptions(this, true, true);
174 setStatus(lastStatus);
180 QStringList ActionModifyMoveRotate::getAvailableCommands()
186 case SetReferencePoint:
188 cmd += command("angle");
198 void ActionModifyMoveRotate::showOptions()
200 //std::cout << "ActionModifyMoveRotate::showOptions()\n";
202 ActionInterface::showOptions();
204 RS_DIALOGFACTORY->requestOptions(this, true);
207 void ActionModifyMoveRotate::hideOptions()
209 //std::cout << "ActionModifyMoveRotate::hideOptions()\n";
211 ActionInterface::hideOptions();
213 RS_DIALOGFACTORY->requestOptions(this, false);
216 void ActionModifyMoveRotate::updateMouseButtonHints()
220 case SetReferencePoint:
221 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel"));
225 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify target point"), tr("Back"));
229 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter rotation angle:"), tr("Back"));
233 RS_DIALOGFACTORY->updateMouseWidget("", "");
238 void ActionModifyMoveRotate::updateMouseCursor()
240 graphicView->setMouseCursor(RS2::CadCursor);
243 void ActionModifyMoveRotate::updateToolBar()
247 case SetReferencePoint:
249 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
253 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
258 void ActionModifyMoveRotate::setAngle(double a)
263 double ActionModifyMoveRotate::getAngle()