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_dialogfactory.h"
18 #include "rs_preview.h"
20 RS_ActionModifyMoveRotate::RS_ActionModifyMoveRotate(
21 RS_EntityContainer & container, RS_GraphicView & graphicView):
22 RS_PreviewActionInterface("Move and Rotate Entities", container, graphicView)
26 RS_ActionModifyMoveRotate::~RS_ActionModifyMoveRotate()
30 /*virtual*/ RS2::ActionType RS_ActionModifyMoveRotate::rtti()
32 return RS2::ActionModifyMoveRotate;
35 void RS_ActionModifyMoveRotate::init(int status)
37 RS_ActionInterface::init(status);
40 void RS_ActionModifyMoveRotate::trigger()
42 RS_DEBUG->print("RS_ActionModifyMoveRotate::trigger()");
44 RS_Modification m(*container, graphicView);
49 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
52 void RS_ActionModifyMoveRotate::mouseMoveEvent(QMouseEvent * e)
54 RS_DEBUG->print("RS_ActionModifyMoveRotate::mouseMoveEvent begin");
56 if (getStatus() == SetReferencePoint || getStatus() == SetTargetPoint)
58 Vector mouse = snapPoint(e);
62 case SetReferencePoint:
63 data.referencePoint = mouse;
68 if (data.referencePoint.valid)
71 data.offset = targetPoint - data.referencePoint;
75 preview->addSelectionFrom(*container);
76 preview->rotate(data.referencePoint, data.angle);
77 preview->move(data.offset);
87 RS_DEBUG->print("RS_ActionModifyMoveRotate::mouseMoveEvent end");
90 void RS_ActionModifyMoveRotate::mouseReleaseEvent(QMouseEvent * e)
92 if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
94 Vector ce(snapPoint(e));
97 else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
101 init(getStatus() - 1);
105 void RS_ActionModifyMoveRotate::coordinateEvent(Vector * e)
114 case SetReferencePoint:
115 data.referencePoint = pos;
116 setStatus(SetTargetPoint);
122 setStatus(ShowDialog);
123 data.offset = targetPoint - data.referencePoint;
125 if (RS_DIALOGFACTORY->requestMoveRotateDialog(data))
135 void RS_ActionModifyMoveRotate::commandEvent(RS_CommandEvent * e)
137 QString c = e->getCommand().toLower();
139 if (checkCommand("help", c))
141 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + getAvailableCommands().join(", "));
147 case SetReferencePoint:
149 #warning "Bad comparison (in checkCommand -> rs_actioninterface)... !!! FIX !!!"
151 if (!c.isEmpty() && checkCommand("angle", c))
152 // if (c == checkCommand("angle", c))
157 lastStatus = (Status)getStatus();
165 double a = RS_Math::eval(c, &ok);
168 data.angle = RS_Math::deg2rad(a);
170 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
172 RS_DIALOGFACTORY->requestOptions(this, true, true);
173 setStatus(lastStatus);
179 QStringList RS_ActionModifyMoveRotate::getAvailableCommands()
185 case SetReferencePoint:
187 cmd += command("angle");
197 void RS_ActionModifyMoveRotate::showOptions()
199 //std::cout << "RS_ActionModifyMoveRotate::showOptions()\n";
201 RS_ActionInterface::showOptions();
203 RS_DIALOGFACTORY->requestOptions(this, true);
206 void RS_ActionModifyMoveRotate::hideOptions()
208 //std::cout << "RS_ActionModifyMoveRotate::hideOptions()\n";
210 RS_ActionInterface::hideOptions();
212 RS_DIALOGFACTORY->requestOptions(this, false);
215 void RS_ActionModifyMoveRotate::updateMouseButtonHints()
219 case SetReferencePoint:
220 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel"));
224 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify target point"), tr("Back"));
228 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter rotation angle:"), tr("Back"));
232 RS_DIALOGFACTORY->updateMouseWidget("", "");
237 void RS_ActionModifyMoveRotate::updateMouseCursor()
239 graphicView->setMouseCursor(RS2::CadCursor);
242 void RS_ActionModifyMoveRotate::updateToolBar()
246 case SetReferencePoint:
248 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
252 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
257 void RS_ActionModifyMoveRotate::setAngle(double a)
262 double RS_ActionModifyMoveRotate::getAngle()