1 // 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 "actiondrawlineparallel.h"
17 #include "actiondrawlineparallelthrough.h"
18 #include "rs_commandevent.h"
20 #include "rs_creation.h"
21 #include "rs_dialogfactory.h"
22 #include "graphicview.h"
23 #include "rs_preview.h"
25 ActionDrawLineParallel::ActionDrawLineParallel(RS_EntityContainer & container,
26 GraphicView & graphicView): ActionInterface("Draw Parallels",
27 container, graphicView)
33 coord = Vector(false);
36 ActionDrawLineParallel::~ActionDrawLineParallel()
40 /*virtual*/ RS2::ActionType ActionDrawLineParallel::rtti()
42 return RS2::ActionDrawLineParallel;
45 void ActionDrawLineParallel::trigger()
47 ActionInterface::trigger();
49 RS_Creation creation(container, graphicView);
50 RS_Entity * e = creation.createParallel(coord, distance, number, entity);
53 RS_DEBUG->print("ActionDrawLineParallel::trigger: No parallels added\n");
56 void ActionDrawLineParallel::mouseMoveEvent(QMouseEvent * e)
58 RS_DEBUG->print("ActionDrawLineParallel::mouseMoveEvent begin");
59 coord = Vector(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y()));
60 entity = catchEntity(e, RS2::ResolveAll);
68 // RS_Creation creation(preview, NULL, false);
69 // creation.createParallel(coord, distance, number, entity);
78 RS_DEBUG->print("ActionDrawLineParallel::mouseMoveEvent end");
81 void ActionDrawLineParallel::mouseReleaseEvent(QMouseEvent * e)
83 if (e->button() == Qt::RightButton)
84 init(getStatus() - 1);
89 void ActionDrawLineParallel::updateMouseButtonHints()
91 if (RS_DIALOGFACTORY != NULL)
96 RS_DIALOGFACTORY->updateMouseWidget(
97 tr("Specify Distance <%1> or select entity or [%2]")
98 .arg(distance).arg(RS_COMMANDS->command("through")),
103 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter number:"), "");
107 RS_DIALOGFACTORY->updateMouseWidget("", "");
113 void ActionDrawLineParallel::showOptions()
115 ActionInterface::showOptions();
117 if (RS_DIALOGFACTORY != NULL)
118 RS_DIALOGFACTORY->requestOptions(this, true);
120 updateMouseButtonHints();
123 void ActionDrawLineParallel::hideOptions()
125 ActionInterface::hideOptions();
127 if (RS_DIALOGFACTORY != NULL)
128 RS_DIALOGFACTORY->requestOptions(this, false);
131 void ActionDrawLineParallel::commandEvent(RS_CommandEvent * e)
133 QString c = e->getCommand().toLower();
135 if (checkCommand("help", c))
137 if (RS_DIALOGFACTORY != NULL)
138 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
139 + getAvailableCommands().join(", "));
147 if (checkCommand("through", c))
150 graphicView->setCurrentAction(new ActionDrawLineParallelThrough(*container,
153 else if (checkCommand("number", c))
158 setStatus(SetNumber);
163 double d = RS_Math::eval(c, &ok);
165 if (ok && d > 1.0e-10)
167 else if (RS_DIALOGFACTORY != NULL)
168 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
171 if (RS_DIALOGFACTORY != NULL)
172 RS_DIALOGFACTORY->requestOptions(this, true, true);
174 updateMouseButtonHints();
175 //setStatus(SetEntity);
182 int n = c.toInt(&ok);
186 if (n > 0 && n < 100)
188 else if (RS_DIALOGFACTORY != NULL)
189 RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. Try 1..99"));
192 else if (RS_DIALOGFACTORY != NULL)
193 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
196 if (RS_DIALOGFACTORY != NULL)
197 RS_DIALOGFACTORY->requestOptions(this, true, true);
199 setStatus(SetEntity);
208 QStringList ActionDrawLineParallel::getAvailableCommands()
215 cmd += command("number");
216 cmd += command("through");
226 void ActionDrawLineParallel::updateMouseCursor()
228 graphicView->setMouseCursor(RS2::CadCursor);
231 void ActionDrawLineParallel::updateToolBar()
233 if (RS_DIALOGFACTORY != NULL)
234 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
237 double ActionDrawLineParallel::getDistance()
242 void ActionDrawLineParallel::setDistance(double d)
247 int ActionDrawLineParallel::getNumber()
252 void ActionDrawLineParallel::setNumber(int n)