1 // rs_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 "rs_actionmodifymoverotate.h"
17 #include "rs_commandevent.h"
18 #include "rs_dialogfactory.h"
19 #include "rs_preview.h"
21 RS_ActionModifyMoveRotate::RS_ActionModifyMoveRotate(
22 RS_EntityContainer & container, GraphicView & graphicView):
23 RS_PreviewActionInterface("Move and Rotate Entities", container, graphicView)
27 RS_ActionModifyMoveRotate::~RS_ActionModifyMoveRotate()
31 /*virtual*/ RS2::ActionType RS_ActionModifyMoveRotate::rtti()
33 return RS2::ActionModifyMoveRotate;
36 void RS_ActionModifyMoveRotate::init(int status)
38 RS_ActionInterface::init(status);
41 void RS_ActionModifyMoveRotate::trigger()
43 RS_DEBUG->print("RS_ActionModifyMoveRotate::trigger()");
45 RS_Modification m(*container, graphicView);
50 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
53 void RS_ActionModifyMoveRotate::mouseMoveEvent(QMouseEvent * e)
55 RS_DEBUG->print("RS_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("RS_ActionModifyMoveRotate::mouseMoveEvent end");
91 void RS_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 RS_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 RS_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 RS_ActionModifyMoveRotate::getAvailableCommands()
186 case SetReferencePoint:
188 cmd += command("angle");
198 void RS_ActionModifyMoveRotate::showOptions()
200 //std::cout << "RS_ActionModifyMoveRotate::showOptions()\n";
202 RS_ActionInterface::showOptions();
204 RS_DIALOGFACTORY->requestOptions(this, true);
207 void RS_ActionModifyMoveRotate::hideOptions()
209 //std::cout << "RS_ActionModifyMoveRotate::hideOptions()\n";
211 RS_ActionInterface::hideOptions();
213 RS_DIALOGFACTORY->requestOptions(this, false);
216 void RS_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 RS_ActionModifyMoveRotate::updateMouseCursor()
240 graphicView->setMouseCursor(RS2::CadCursor);
243 void RS_ActionModifyMoveRotate::updateToolBar()
247 case SetReferencePoint:
249 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
253 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
258 void RS_ActionModifyMoveRotate::setAngle(double a)
263 double RS_ActionModifyMoveRotate::getAngle()