1 // actiondrawlineparallelthrough.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 "actiondrawlineparallelthrough.h"
17 #include "rs_commandevent.h"
18 #include "rs_creation.h"
19 #include "rs_dialogfactory.h"
20 #include "graphicview.h"
21 #include "rs_preview.h"
23 ActionDrawLineParallelThrough::ActionDrawLineParallelThrough(
24 RS_EntityContainer & container, GraphicView & graphicView):
25 ActionInterface("Draw Parallels", container, graphicView)
31 coord = Vector(false);
34 ActionDrawLineParallelThrough::~ActionDrawLineParallelThrough()
38 /*virtual*/ RS2::ActionType ActionDrawLineParallelThrough::rtti()
40 return RS2::ActionDrawLineParallelThrough;
43 void ActionDrawLineParallelThrough::trigger()
45 ActionInterface::trigger();
50 RS_Creation creation(container, graphicView);
51 RS_Entity * e = creation.createParallelThrough(coord, number, entity);
54 RS_DEBUG->print("ActionDrawLineParallelThrough::trigger:"
55 " No parallels added\n");
59 void ActionDrawLineParallelThrough::mouseMoveEvent(QMouseEvent * e)
61 RS_DEBUG->print("ActionDrawLineParallelThrough::mouseMoveEvent begin");
66 entity = catchEntity(e, RS2::ResolveAll);
75 // RS_Creation creation(preview, NULL, false);
76 // creation.createParallelThrough(coord, number, entity);
86 RS_DEBUG->print("ActionDrawLineParallelThrough::mouseMoveEvent end");
89 void ActionDrawLineParallelThrough::mouseReleaseEvent(QMouseEvent * e)
91 if (e->button() == Qt::LeftButton)
96 entity = catchEntity(e, RS2::ResolveAll);
100 entity->setHighlighted(true);
101 graphicView->drawEntity(entity);
109 Vector ce(snapPoint(e));
110 coordinateEvent(&ce);
118 else if (e->button() == Qt::RightButton)
125 entity->setHighlighted(false);
126 graphicView->drawEntity(entity);
130 init(getStatus() - 1);
134 void ActionDrawLineParallelThrough::coordinateEvent(Vector * e)
153 void ActionDrawLineParallelThrough::updateMouseButtonHints()
158 RS_DIALOGFACTORY->updateMouseWidget(tr("Select entity"), tr("Cancel"));
162 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify through point"), tr("Back"));
166 RS_DIALOGFACTORY->updateMouseWidget(tr("Number:"), tr("Back"));
170 RS_DIALOGFACTORY->updateMouseWidget("", "");
175 void ActionDrawLineParallelThrough::showOptions()
177 ActionInterface::showOptions();
178 RS_DIALOGFACTORY->requestOptions(this, true);
179 updateMouseButtonHints();
182 void ActionDrawLineParallelThrough::hideOptions()
184 ActionInterface::hideOptions();
185 RS_DIALOGFACTORY->requestOptions(this, false);
188 void ActionDrawLineParallelThrough::commandEvent(RS_CommandEvent * e)
190 QString c = e->getCommand().toLower();
192 if (checkCommand("help", c))
194 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
195 + getAvailableCommands().join(", "));
204 if (checkCommand("number", c))
209 lastStatus = (Status)getStatus();
210 setStatus(SetNumber);
217 int n = c.toInt(&ok);
221 if (n > 0 && n < 100)
224 RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. "
228 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
229 RS_DIALOGFACTORY->requestOptions(this, true, true);
230 setStatus(lastStatus);
239 QStringList ActionDrawLineParallelThrough::getAvailableCommands()
246 cmd += command("number");
256 void ActionDrawLineParallelThrough::updateMouseCursor()
258 graphicView->setMouseCursor(RS2::CadCursor);
261 void ActionDrawLineParallelThrough::updateToolBar()
263 if (getStatus() == SetPos && !isFinished())
264 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
266 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
269 int ActionDrawLineParallelThrough::getNumber()
274 void ActionDrawLineParallelThrough::setNumber(int n)