1 // rs_actiondrawlinerelangle.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 05/22/2010 Added this text. :-)
15 #include "rs_actiondrawlinerelangle.h"
17 #include "rs_creation.h"
18 #include "rs_snapper.h"
20 RS_ActionDrawLineRelAngle::RS_ActionDrawLineRelAngle(
21 RS_EntityContainer& container,
22 RS_GraphicView& graphicView,
25 :RS_PreviewActionInterface("Draw Lines with relative angles",
26 container, graphicView) {
30 this->fixedAngle = fixedAngle;
35 QAction * RS_ActionDrawLineRelAngle::createGUIAction(RS2::ActionType type, QObject * /*parent*/)
37 QAction * action = NULL;
39 if (type == RS2::ActionDrawLineRelAngle)
41 action = new QAction(tr("R&elative angle"), 0);
42 // action = new QAction(tr("Relative angle"), tr("R&elative angle"),
43 // QKeySequence(), NULL);
44 action->setStatusTip(tr("Draw line with relative angle"));
46 else if (type == RS2::ActionDrawLineOrthogonal)
48 action = new QAction(tr("&Orthogonal"), 0);
49 // action = new QAction(tr("Orthogonal"), tr("&Orthogonal"),
50 // QKeySequence(), NULL);
51 action->setStatusTip(tr("Draw orthogonal line"));
57 void RS_ActionDrawLineRelAngle::trigger()
59 RS_PreviewActionInterface::trigger();
65 RS_Creation creation(container, graphicView);
66 creation.createLineRelAngle(pos,
73 RS_Entity* newEntity = NULL;
75 newEntity = new RS_Line(container,
78 if (newEntity!=NULL) {
79 newEntity->setLayerToActive();
80 newEntity->setPenToActive();
81 container->addEntity(newEntity);
85 document->startUndoCycle();
86 document->addUndoable(newEntity);
87 document->endUndoCycle();
90 graphicView->drawEntity(newEntity);
97 RS_DEBUG->print("RS_ActionDrawLineRelAngle::trigger:"
105 void RS_ActionDrawLineRelAngle::mouseMoveEvent(QMouseEvent* e) {
106 RS_DEBUG->print("RS_ActionDrawLineRelAngle::mouseMoveEvent begin");
108 Vector mouse(graphicView->toGraphX(e->x()),
109 graphicView->toGraphY(e->y()));
111 switch (getStatus()) {
113 entity = catchEntity(e, RS2::ResolveAll);
117 //length = graphicView->toGraphDX(graphicView->getWidth());
118 //Vector mouse = snapPoint(e);
121 /*RS_Creation creation(NULL, NULL);
122 RS_Line* l = creation.createLineRelAngle(mouse,
130 RS_Creation creation(preview, NULL, false);
131 creation.createLineRelAngle(pos,
142 line = (RS_Line*)l->clone();
146 preview->addEntity(l);
156 RS_DEBUG->print("RS_ActionDrawLineRelAngle::mouseMoveEvent end");
161 void RS_ActionDrawLineRelAngle::mouseReleaseEvent(QMouseEvent* e) {
163 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
164 switch (getStatus()) {
166 RS_Entity* en = catchEntity(e, RS2::ResolveAll);
168 (en->rtti()==RS2::EntityLine ||
169 en->rtti()==RS2::EntityArc ||
170 en->rtti()==RS2::EntityCircle)) {
173 entity->setHighlighted(true);
174 graphicView->drawEntity(entity);
182 RS_CoordinateEvent ce(snapPoint(e));
183 coordinateEvent(&ce);
190 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
195 entity->setHighlighted(false);
196 graphicView->drawEntity(entity);
204 void RS_ActionDrawLineRelAngle::coordinateEvent(RS_CoordinateEvent* e) {
209 switch (getStatus()) {
211 pos = e->getCoordinate();
222 void RS_ActionDrawLineRelAngle::commandEvent(RS_CommandEvent* e) {
223 QString c = e->getCommand().toLower();
225 if (checkCommand("help", c)) {
226 if (RS_DIALOGFACTORY!=NULL) {
227 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
228 + getAvailableCommands().join(", "));
233 switch (getStatus()) {
236 if (!fixedAngle && checkCommand("angle", c)) {
241 } else if (checkCommand("length", c)) {
245 setStatus(SetLength);
251 double a = RS_Math::eval(c, &ok);
253 angle = RS_Math::deg2rad(a);
255 if (RS_DIALOGFACTORY!=NULL) {
256 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
259 if (RS_DIALOGFACTORY!=NULL) {
260 RS_DIALOGFACTORY->requestOptions(this, true, true);
268 double l = RS_Math::eval(c, &ok);
272 if (RS_DIALOGFACTORY!=NULL) {
273 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
276 if (RS_DIALOGFACTORY!=NULL) {
277 RS_DIALOGFACTORY->requestOptions(this, true, true);
290 QStringList RS_ActionDrawLineRelAngle::getAvailableCommands() {
293 switch (getStatus()) {
297 cmd += command("angle");
299 cmd += command("length");
309 void RS_ActionDrawLineRelAngle::updateMouseButtonHints() {
310 if (RS_DIALOGFACTORY!=NULL) {
311 switch (getStatus()) {
313 RS_DIALOGFACTORY->updateMouseWidget(tr("Select base entity"),
317 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify position"),
321 RS_DIALOGFACTORY->updateMouseWidget("", "");
329 void RS_ActionDrawLineRelAngle::showOptions() {
330 RS_ActionInterface::showOptions();
332 if (RS_DIALOGFACTORY!=NULL) {
333 RS_DIALOGFACTORY->requestOptions(this, true);
339 void RS_ActionDrawLineRelAngle::hideOptions() {
340 RS_ActionInterface::hideOptions();
342 if (RS_DIALOGFACTORY!=NULL) {
343 RS_DIALOGFACTORY->requestOptions(this, false);
349 void RS_ActionDrawLineRelAngle::updateMouseCursor() {
350 graphicView->setMouseCursor(RS2::CadCursor);
355 void RS_ActionDrawLineRelAngle::updateToolBar() {
356 if (RS_DIALOGFACTORY!=NULL) {
358 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
360 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);