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 // 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 05/22/2010 Added this text. :-)
15 // JLH 08/19/2010 Fix rendering for new (correct) rendering path
18 #include "actiondrawlineparallel.h"
20 #include "actiondrawlineparallelthrough.h"
21 #include "commandevent.h"
25 #include "dialogfactory.h"
26 #include "graphicview.h"
29 ActionDrawLineParallel::ActionDrawLineParallel(EntityContainer & container,
30 GraphicView & graphicView):
31 ActionInterface("Draw Parallels", container, graphicView),
32 parallel(NULL), distance(1.0), number(1), coord(Vector(false)), entity(NULL)
34 graphicView.SetSnapperVisible(false);
37 ActionDrawLineParallel::~ActionDrawLineParallel()
41 /*virtual*/ RS2::ActionType ActionDrawLineParallel::rtti()
43 return RS2::ActionDrawLineParallel;
46 void ActionDrawLineParallel::trigger()
48 ActionInterface::trigger();
49 Creation creation(container, graphicView);
50 Entity * e = creation.createParallel(coord, distance, number, entity);
53 DEBUG->print("ActionDrawLineParallel::trigger: No parallels added\n");
55 graphicView->preview.clear();
56 graphicView->redraw();
59 void ActionDrawLineParallel::mouseMoveEvent(QMouseEvent * e)
61 DEBUG->print("ActionDrawLineParallel::mouseMoveEvent begin");
62 coord = Vector(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y()));
63 entity = catchEntity(e, RS2::ResolveAll);
72 Creation creation(preview, NULL, false);
73 creation.createParallel(coord, distance, number, entity);
76 graphicView->preview.clear();
77 Creation creation(&(graphicView->preview), NULL, false);
78 creation.createParallel(coord, distance, number, entity);
79 graphicView->redraw();
88 DEBUG->print("ActionDrawLineParallel::mouseMoveEvent end");
91 void ActionDrawLineParallel::mouseReleaseEvent(QMouseEvent * e)
93 if (e->button() == Qt::RightButton)
94 init(getStatus() - 1);
99 void ActionDrawLineParallel::updateMouseButtonHints()
106 DIALOGFACTORY->updateMouseWidget(
107 tr("Specify Distance <%1> or select entity or [%2]")
108 .arg(distance).arg(COMMANDS->command("through")),
113 DIALOGFACTORY->updateMouseWidget(tr("Enter number:"), "");
117 DIALOGFACTORY->updateMouseWidget("", "");
123 void ActionDrawLineParallel::showOptions()
125 ActionInterface::showOptions();
128 DIALOGFACTORY->requestOptions(this, true);
130 updateMouseButtonHints();
133 void ActionDrawLineParallel::hideOptions()
135 ActionInterface::hideOptions();
138 DIALOGFACTORY->requestOptions(this, false);
141 void ActionDrawLineParallel::commandEvent(CommandEvent * e)
143 QString c = e->getCommand().toLower();
145 if (checkCommand("help", c))
148 DIALOGFACTORY->commandMessage(msgAvailableCommands()
149 + getAvailableCommands().join(", "));
157 if (checkCommand("through", c))
160 graphicView->setCurrentAction(new ActionDrawLineParallelThrough(*container,
163 else if (checkCommand("number", c))
168 setStatus(SetNumber);
173 double d = Math::eval(c, &ok);
175 if (ok && d > 1.0e-10)
177 else if (DIALOGFACTORY)
178 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
181 if (DIALOGFACTORY != NULL)
182 DIALOGFACTORY->requestOptions(this, true, true);
184 updateMouseButtonHints();
185 //setStatus(SetEntity);
193 int n = c.toInt(&ok);
197 if (n > 0 && n < 100)
199 else if (DIALOGFACTORY)
200 DIALOGFACTORY->commandMessage(tr("Not a valid number. Try 1..99"));
202 else if (DIALOGFACTORY)
203 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
206 DIALOGFACTORY->requestOptions(this, true, true);
208 setStatus(SetEntity);
217 QStringList ActionDrawLineParallel::getAvailableCommands()
224 cmd += command("number");
225 cmd += command("through");
235 void ActionDrawLineParallel::updateMouseCursor()
237 graphicView->setMouseCursor(RS2::CadCursor);
240 void ActionDrawLineParallel::updateToolBar()
243 DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
246 double ActionDrawLineParallel::getDistance()
251 void ActionDrawLineParallel::setDistance(double d)
256 int ActionDrawLineParallel::getNumber()
261 void ActionDrawLineParallel::setNumber(int n)