1 // rs_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 "rs_actiondrawlineparallelthrough.h"
17 #include "rs_creation.h"
18 #include "rs_dialogfactory.h"
19 #include "rs_graphicview.h"
20 #include "rs_preview.h"
22 RS_ActionDrawLineParallelThrough::RS_ActionDrawLineParallelThrough(
23 RS_EntityContainer & container, RS_GraphicView & graphicView):
24 RS_PreviewActionInterface("Draw Parallels", container, graphicView)
30 coord = Vector(false);
33 RS_ActionDrawLineParallelThrough::~RS_ActionDrawLineParallelThrough()
37 /*virtual*/ RS2::ActionType RS_ActionDrawLineParallelThrough::rtti()
39 return RS2::ActionDrawLineParallelThrough;
42 void RS_ActionDrawLineParallelThrough::trigger()
44 RS_PreviewActionInterface::trigger();
49 RS_Creation creation(container, graphicView);
50 RS_Entity * e = creation.createParallelThrough(coord, number, entity);
53 RS_DEBUG->print("RS_ActionDrawLineParallelThrough::trigger:"
54 " No parallels added\n");
58 void RS_ActionDrawLineParallelThrough::mouseMoveEvent(QMouseEvent * e)
60 RS_DEBUG->print("RS_ActionDrawLineParallelThrough::mouseMoveEvent begin");
65 entity = catchEntity(e, RS2::ResolveAll);
69 RS_Creation creation(preview, NULL, false);
70 creation.createParallelThrough(coord,
80 //Vector(graphicView->toGraphX(e->x()),
81 // graphicView->toGraphY(e->y()));
85 RS_Creation creation(preview, NULL, false);
86 creation.createParallelThrough(coord,
98 RS_DEBUG->print("RS_ActionDrawLineParallelThrough::mouseMoveEvent end");
101 void RS_ActionDrawLineParallelThrough::mouseReleaseEvent(QMouseEvent * e)
103 // if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton)
104 if (e->button() == Qt::LeftButton)
109 entity = catchEntity(e, RS2::ResolveAll);
113 entity->setHighlighted(true);
114 graphicView->drawEntity(entity);
122 Vector ce(snapPoint(e));
123 coordinateEvent(&ce);
131 // else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton)
132 else if (e->button() == Qt::RightButton)
139 entity->setHighlighted(false);
140 graphicView->drawEntity(entity);
144 init(getStatus() - 1);
148 void RS_ActionDrawLineParallelThrough::coordinateEvent(Vector * e)
167 void RS_ActionDrawLineParallelThrough::updateMouseButtonHints()
172 RS_DIALOGFACTORY->updateMouseWidget(tr("Select entity"), tr("Cancel"));
176 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify through point"), tr("Back"));
180 RS_DIALOGFACTORY->updateMouseWidget(tr("Number:"), tr("Back"));
184 RS_DIALOGFACTORY->updateMouseWidget("", "");
189 void RS_ActionDrawLineParallelThrough::showOptions()
191 RS_ActionInterface::showOptions();
193 RS_DIALOGFACTORY->requestOptions(this, true);
194 updateMouseButtonHints();
197 void RS_ActionDrawLineParallelThrough::hideOptions()
199 RS_ActionInterface::hideOptions();
201 RS_DIALOGFACTORY->requestOptions(this, false);
204 void RS_ActionDrawLineParallelThrough::commandEvent(RS_CommandEvent * e)
206 QString c = e->getCommand().toLower();
208 if (checkCommand("help", c))
210 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
211 + getAvailableCommands().join(", "));
220 if (checkCommand("number", c))
225 lastStatus = (Status)getStatus();
226 setStatus(SetNumber);
232 int n = c.toInt(&ok);
236 if (n > 0 && n < 100)
239 RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. "
243 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
244 RS_DIALOGFACTORY->requestOptions(this, true, true);
245 setStatus(lastStatus);
254 QStringList RS_ActionDrawLineParallelThrough::getAvailableCommands()
261 cmd += command("number");
271 void RS_ActionDrawLineParallelThrough::updateMouseCursor()
273 graphicView->setMouseCursor(RS2::CadCursor);
276 void RS_ActionDrawLineParallelThrough::updateToolBar()
278 if (getStatus() == SetPos && !isFinished())
279 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
281 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
284 int RS_ActionDrawLineParallelThrough::getNumber()
289 void RS_ActionDrawLineParallelThrough::setNumber(int n)