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 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 06/04/2010 Added this text. :-)
17 #include "actiondrawlineparallelthrough.h"
19 #include "rs_commandevent.h"
20 #include "rs_creation.h"
21 #include "rs_dialogfactory.h"
22 #include "graphicview.h"
23 #include "rs_preview.h"
25 ActionDrawLineParallelThrough::ActionDrawLineParallelThrough(
26 RS_EntityContainer & container, GraphicView & graphicView):
27 ActionInterface("Draw Parallels", container, graphicView)
33 coord = Vector(false);
36 ActionDrawLineParallelThrough::~ActionDrawLineParallelThrough()
40 /*virtual*/ RS2::ActionType ActionDrawLineParallelThrough::rtti()
42 return RS2::ActionDrawLineParallelThrough;
45 void ActionDrawLineParallelThrough::trigger()
47 ActionInterface::trigger();
52 RS_Creation creation(container, graphicView);
53 RS_Entity * e = creation.createParallelThrough(coord, number, entity);
56 RS_DEBUG->print("ActionDrawLineParallelThrough::trigger:"
57 " No parallels added\n");
61 void ActionDrawLineParallelThrough::mouseMoveEvent(QMouseEvent * e)
63 RS_DEBUG->print("ActionDrawLineParallelThrough::mouseMoveEvent begin");
68 entity = catchEntity(e, RS2::ResolveAll);
77 // RS_Creation creation(preview, NULL, false);
78 // creation.createParallelThrough(coord, number, entity);
88 RS_DEBUG->print("ActionDrawLineParallelThrough::mouseMoveEvent end");
91 void ActionDrawLineParallelThrough::mouseReleaseEvent(QMouseEvent * e)
93 if (e->button() == Qt::LeftButton)
98 entity = catchEntity(e, RS2::ResolveAll);
102 entity->setHighlighted(true);
103 graphicView->drawEntity(entity);
111 Vector ce(snapPoint(e));
112 coordinateEvent(&ce);
120 else if (e->button() == Qt::RightButton)
127 entity->setHighlighted(false);
128 graphicView->drawEntity(entity);
132 init(getStatus() - 1);
136 void ActionDrawLineParallelThrough::coordinateEvent(Vector * e)
155 void ActionDrawLineParallelThrough::updateMouseButtonHints()
160 RS_DIALOGFACTORY->updateMouseWidget(tr("Select entity"), tr("Cancel"));
164 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify through point"), tr("Back"));
168 RS_DIALOGFACTORY->updateMouseWidget(tr("Number:"), tr("Back"));
172 RS_DIALOGFACTORY->updateMouseWidget("", "");
177 void ActionDrawLineParallelThrough::showOptions()
179 ActionInterface::showOptions();
180 RS_DIALOGFACTORY->requestOptions(this, true);
181 updateMouseButtonHints();
184 void ActionDrawLineParallelThrough::hideOptions()
186 ActionInterface::hideOptions();
187 RS_DIALOGFACTORY->requestOptions(this, false);
190 void ActionDrawLineParallelThrough::commandEvent(RS_CommandEvent * e)
192 QString c = e->getCommand().toLower();
194 if (checkCommand("help", c))
196 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
197 + getAvailableCommands().join(", "));
206 if (checkCommand("number", c))
211 lastStatus = (Status)getStatus();
212 setStatus(SetNumber);
219 int n = c.toInt(&ok);
223 if (n > 0 && n < 100)
226 RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. "
230 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
231 RS_DIALOGFACTORY->requestOptions(this, true, true);
232 setStatus(lastStatus);
241 QStringList ActionDrawLineParallelThrough::getAvailableCommands()
248 cmd += command("number");
258 void ActionDrawLineParallelThrough::updateMouseCursor()
260 graphicView->setMouseCursor(RS2::CadCursor);
263 void ActionDrawLineParallelThrough::updateToolBar()
265 if (getStatus() == SetPos && !isFinished())
266 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
268 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
271 int ActionDrawLineParallelThrough::getNumber()
276 void ActionDrawLineParallelThrough::setNumber(int n)