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_commandevent.h"
18 #include "rs_creation.h"
19 #include "rs_dialogfactory.h"
20 #include "graphicview.h"
21 #include "rs_preview.h"
23 RS_ActionDrawLineParallelThrough::RS_ActionDrawLineParallelThrough(
24 RS_EntityContainer & container, GraphicView & graphicView):
25 RS_PreviewActionInterface("Draw Parallels", container, graphicView)
31 coord = Vector(false);
34 RS_ActionDrawLineParallelThrough::~RS_ActionDrawLineParallelThrough()
38 /*virtual*/ RS2::ActionType RS_ActionDrawLineParallelThrough::rtti()
40 return RS2::ActionDrawLineParallelThrough;
43 void RS_ActionDrawLineParallelThrough::trigger()
45 RS_PreviewActionInterface::trigger();
50 RS_Creation creation(container, graphicView);
51 RS_Entity * e = creation.createParallelThrough(coord, number, entity);
54 RS_DEBUG->print("RS_ActionDrawLineParallelThrough::trigger:"
55 " No parallels added\n");
59 void RS_ActionDrawLineParallelThrough::mouseMoveEvent(QMouseEvent * e)
61 RS_DEBUG->print("RS_ActionDrawLineParallelThrough::mouseMoveEvent begin");
66 entity = catchEntity(e, RS2::ResolveAll);
70 RS_Creation creation(preview, NULL, false);
71 creation.createParallelThrough(coord,
81 //Vector(graphicView->toGraphX(e->x()),
82 // graphicView->toGraphY(e->y()));
86 RS_Creation creation(preview, NULL, false);
87 creation.createParallelThrough(coord,
99 RS_DEBUG->print("RS_ActionDrawLineParallelThrough::mouseMoveEvent end");
102 void RS_ActionDrawLineParallelThrough::mouseReleaseEvent(QMouseEvent * e)
104 // if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton)
105 if (e->button() == Qt::LeftButton)
110 entity = catchEntity(e, RS2::ResolveAll);
114 entity->setHighlighted(true);
115 graphicView->drawEntity(entity);
123 Vector ce(snapPoint(e));
124 coordinateEvent(&ce);
132 // else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton)
133 else if (e->button() == Qt::RightButton)
140 entity->setHighlighted(false);
141 graphicView->drawEntity(entity);
145 init(getStatus() - 1);
149 void RS_ActionDrawLineParallelThrough::coordinateEvent(Vector * e)
168 void RS_ActionDrawLineParallelThrough::updateMouseButtonHints()
173 RS_DIALOGFACTORY->updateMouseWidget(tr("Select entity"), tr("Cancel"));
177 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify through point"), tr("Back"));
181 RS_DIALOGFACTORY->updateMouseWidget(tr("Number:"), tr("Back"));
185 RS_DIALOGFACTORY->updateMouseWidget("", "");
190 void RS_ActionDrawLineParallelThrough::showOptions()
192 RS_ActionInterface::showOptions();
194 RS_DIALOGFACTORY->requestOptions(this, true);
195 updateMouseButtonHints();
198 void RS_ActionDrawLineParallelThrough::hideOptions()
200 RS_ActionInterface::hideOptions();
202 RS_DIALOGFACTORY->requestOptions(this, false);
205 void RS_ActionDrawLineParallelThrough::commandEvent(RS_CommandEvent * e)
207 QString c = e->getCommand().toLower();
209 if (checkCommand("help", c))
211 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
212 + getAvailableCommands().join(", "));
221 if (checkCommand("number", c))
226 lastStatus = (Status)getStatus();
227 setStatus(SetNumber);
233 int n = c.toInt(&ok);
237 if (n > 0 && n < 100)
240 RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. "
244 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
245 RS_DIALOGFACTORY->requestOptions(this, true, true);
246 setStatus(lastStatus);
255 QStringList RS_ActionDrawLineParallelThrough::getAvailableCommands()
262 cmd += command("number");
272 void RS_ActionDrawLineParallelThrough::updateMouseCursor()
274 graphicView->setMouseCursor(RS2::CadCursor);
277 void RS_ActionDrawLineParallelThrough::updateToolBar()
279 if (getStatus() == SetPos && !isFinished())
280 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
282 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
285 int RS_ActionDrawLineParallelThrough::getNumber()
290 void RS_ActionDrawLineParallelThrough::setNumber(int n)