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. :-)
17 #include "actiondrawlineparallel.h"
19 #include "actiondrawlineparallelthrough.h"
20 #include "rs_commandevent.h"
22 #include "rs_creation.h"
24 #include "rs_dialogfactory.h"
25 #include "graphicview.h"
26 #include "rs_preview.h"
28 ActionDrawLineParallel::ActionDrawLineParallel(RS_EntityContainer & container,
29 GraphicView & graphicView): ActionInterface("Draw Parallels",
30 container, graphicView)
36 coord = Vector(false);
39 ActionDrawLineParallel::~ActionDrawLineParallel()
43 /*virtual*/ RS2::ActionType ActionDrawLineParallel::rtti()
45 return RS2::ActionDrawLineParallel;
48 void ActionDrawLineParallel::trigger()
50 ActionInterface::trigger();
52 RS_Creation creation(container, graphicView);
53 RS_Entity * e = creation.createParallel(coord, distance, number, entity);
56 RS_DEBUG->print("ActionDrawLineParallel::trigger: No parallels added\n");
59 void ActionDrawLineParallel::mouseMoveEvent(QMouseEvent * e)
61 RS_DEBUG->print("ActionDrawLineParallel::mouseMoveEvent begin");
62 coord = Vector(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y()));
63 entity = catchEntity(e, RS2::ResolveAll);
71 // RS_Creation creation(preview, NULL, false);
72 // creation.createParallel(coord, distance, number, entity);
81 RS_DEBUG->print("ActionDrawLineParallel::mouseMoveEvent end");
84 void ActionDrawLineParallel::mouseReleaseEvent(QMouseEvent * e)
86 if (e->button() == Qt::RightButton)
87 init(getStatus() - 1);
92 void ActionDrawLineParallel::updateMouseButtonHints()
94 if (RS_DIALOGFACTORY != NULL)
99 RS_DIALOGFACTORY->updateMouseWidget(
100 tr("Specify Distance <%1> or select entity or [%2]")
101 .arg(distance).arg(RS_COMMANDS->command("through")),
106 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter number:"), "");
110 RS_DIALOGFACTORY->updateMouseWidget("", "");
116 void ActionDrawLineParallel::showOptions()
118 ActionInterface::showOptions();
120 if (RS_DIALOGFACTORY != NULL)
121 RS_DIALOGFACTORY->requestOptions(this, true);
123 updateMouseButtonHints();
126 void ActionDrawLineParallel::hideOptions()
128 ActionInterface::hideOptions();
130 if (RS_DIALOGFACTORY != NULL)
131 RS_DIALOGFACTORY->requestOptions(this, false);
134 void ActionDrawLineParallel::commandEvent(RS_CommandEvent * e)
136 QString c = e->getCommand().toLower();
138 if (checkCommand("help", c))
140 if (RS_DIALOGFACTORY != NULL)
141 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
142 + getAvailableCommands().join(", "));
150 if (checkCommand("through", c))
153 graphicView->setCurrentAction(new ActionDrawLineParallelThrough(*container,
156 else if (checkCommand("number", c))
161 setStatus(SetNumber);
166 double d = RS_Math::eval(c, &ok);
168 if (ok && d > 1.0e-10)
170 else if (RS_DIALOGFACTORY != NULL)
171 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
174 if (RS_DIALOGFACTORY != NULL)
175 RS_DIALOGFACTORY->requestOptions(this, true, true);
177 updateMouseButtonHints();
178 //setStatus(SetEntity);
185 int n = c.toInt(&ok);
189 if (n > 0 && n < 100)
191 else if (RS_DIALOGFACTORY != NULL)
192 RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. Try 1..99"));
195 else if (RS_DIALOGFACTORY != NULL)
196 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
199 if (RS_DIALOGFACTORY != NULL)
200 RS_DIALOGFACTORY->requestOptions(this, true, true);
202 setStatus(SetEntity);
211 QStringList ActionDrawLineParallel::getAvailableCommands()
218 cmd += command("number");
219 cmd += command("through");
229 void ActionDrawLineParallel::updateMouseCursor()
231 graphicView->setMouseCursor(RS2::CadCursor);
234 void ActionDrawLineParallel::updateToolBar()
236 if (RS_DIALOGFACTORY != NULL)
237 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
240 double ActionDrawLineParallel::getDistance()
245 void ActionDrawLineParallel::setDistance(double d)
250 int ActionDrawLineParallel::getNumber()
255 void ActionDrawLineParallel::setNumber(int n)