1 // rs_actiondrawlineparallel.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_actiondrawlineparallel.h"
17 #include "rs_actiondrawlineparallelthrough.h"
19 #include "rs_creation.h"
20 #include "rs_dialogfactory.h"
21 #include "rs_graphicview.h"
22 #include "rs_preview.h"
24 RS_ActionDrawLineParallel::RS_ActionDrawLineParallel(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw Parallels",
25 container, graphicView)
31 coord = Vector(false);
34 RS_ActionDrawLineParallel::~RS_ActionDrawLineParallel()
38 /*virtual*/ RS2::ActionType RS_ActionDrawLineParallel::rtti()
40 return RS2::ActionDrawLineParallel;
43 void RS_ActionDrawLineParallel::trigger()
45 RS_PreviewActionInterface::trigger();
47 RS_Creation creation(container, graphicView);
48 RS_Entity * e = creation.createParallel(coord, distance, number, entity);
51 RS_DEBUG->print("RS_ActionDrawLineParallel::trigger: No parallels added\n");
54 void RS_ActionDrawLineParallel::mouseMoveEvent(QMouseEvent * e)
56 RS_DEBUG->print("RS_ActionDrawLineParallel::mouseMoveEvent begin");
57 coord = Vector(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y()));
58 entity = catchEntity(e, RS2::ResolveAll);
66 RS_Creation creation(preview, NULL, false);
67 creation.createParallel(coord, distance, number, entity);
76 RS_DEBUG->print("RS_ActionDrawLineParallel::mouseMoveEvent end");
79 void RS_ActionDrawLineParallel::mouseReleaseEvent(QMouseEvent * e)
81 // if (RS2::qtToRsButtonState(e->button())==RS2::RightButton)
82 if (e->button() == Qt::RightButton)
83 init(getStatus() - 1);
88 void RS_ActionDrawLineParallel::updateMouseButtonHints()
90 if (RS_DIALOGFACTORY != NULL)
95 RS_DIALOGFACTORY->updateMouseWidget(
96 tr("Specify Distance <%1> or select entity or [%2]")
97 .arg(distance).arg(RS_COMMANDS->command("through")),
102 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter number:"), "");
106 RS_DIALOGFACTORY->updateMouseWidget("", "");
112 void RS_ActionDrawLineParallel::showOptions()
114 RS_ActionInterface::showOptions();
116 if (RS_DIALOGFACTORY != NULL)
117 RS_DIALOGFACTORY->requestOptions(this, true);
119 updateMouseButtonHints();
122 void RS_ActionDrawLineParallel::hideOptions()
124 RS_ActionInterface::hideOptions();
126 if (RS_DIALOGFACTORY != NULL)
127 RS_DIALOGFACTORY->requestOptions(this, false);
130 void RS_ActionDrawLineParallel::commandEvent(RS_CommandEvent * e)
132 QString c = e->getCommand().toLower();
134 if (checkCommand("help", c))
136 if (RS_DIALOGFACTORY != NULL)
137 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
138 + getAvailableCommands().join(", "));
146 if (checkCommand("through", c))
149 graphicView->setCurrentAction(new RS_ActionDrawLineParallelThrough(*container,
152 else if (checkCommand("number", c))
157 setStatus(SetNumber);
162 double d = RS_Math::eval(c, &ok);
164 if (ok && d > 1.0e-10)
166 else if (RS_DIALOGFACTORY != NULL)
167 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
170 if (RS_DIALOGFACTORY != NULL)
171 RS_DIALOGFACTORY->requestOptions(this, true, true);
173 updateMouseButtonHints();
174 //setStatus(SetEntity);
181 int n = c.toInt(&ok);
185 if (n > 0 && n < 100)
187 else if (RS_DIALOGFACTORY != NULL)
188 RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. Try 1..99"));
191 else if (RS_DIALOGFACTORY != NULL)
192 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
195 if (RS_DIALOGFACTORY != NULL)
196 RS_DIALOGFACTORY->requestOptions(this, true, true);
198 setStatus(SetEntity);
207 QStringList RS_ActionDrawLineParallel::getAvailableCommands()
214 cmd += command("number");
215 cmd += command("through");
225 void RS_ActionDrawLineParallel::updateMouseCursor()
227 graphicView->setMouseCursor(RS2::CadCursor);
230 void RS_ActionDrawLineParallel::updateToolBar()
232 if (RS_DIALOGFACTORY != NULL)
233 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
236 double RS_ActionDrawLineParallel::getDistance()
241 void RS_ActionDrawLineParallel::setDistance(double d)
246 int RS_ActionDrawLineParallel::getNumber()
251 void RS_ActionDrawLineParallel::setNumber(int n)