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"
23 #include "rs_dialogfactory.h"
24 #include "graphicview.h"
25 #include "rs_preview.h"
27 ActionDrawLineParallel::ActionDrawLineParallel(RS_EntityContainer & container,
28 GraphicView & graphicView): ActionInterface("Draw Parallels",
29 container, graphicView)
35 coord = Vector(false);
38 ActionDrawLineParallel::~ActionDrawLineParallel()
42 /*virtual*/ RS2::ActionType ActionDrawLineParallel::rtti()
44 return RS2::ActionDrawLineParallel;
47 void ActionDrawLineParallel::trigger()
49 ActionInterface::trigger();
51 RS_Creation creation(container, graphicView);
52 RS_Entity * e = creation.createParallel(coord, distance, number, entity);
55 RS_DEBUG->print("ActionDrawLineParallel::trigger: No parallels added\n");
58 void ActionDrawLineParallel::mouseMoveEvent(QMouseEvent * e)
60 RS_DEBUG->print("ActionDrawLineParallel::mouseMoveEvent begin");
61 coord = Vector(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y()));
62 entity = catchEntity(e, RS2::ResolveAll);
70 // RS_Creation creation(preview, NULL, false);
71 // creation.createParallel(coord, distance, number, entity);
80 RS_DEBUG->print("ActionDrawLineParallel::mouseMoveEvent end");
83 void ActionDrawLineParallel::mouseReleaseEvent(QMouseEvent * e)
85 if (e->button() == Qt::RightButton)
86 init(getStatus() - 1);
91 void ActionDrawLineParallel::updateMouseButtonHints()
93 if (RS_DIALOGFACTORY != NULL)
98 RS_DIALOGFACTORY->updateMouseWidget(
99 tr("Specify Distance <%1> or select entity or [%2]")
100 .arg(distance).arg(RS_COMMANDS->command("through")),
105 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter number:"), "");
109 RS_DIALOGFACTORY->updateMouseWidget("", "");
115 void ActionDrawLineParallel::showOptions()
117 ActionInterface::showOptions();
119 if (RS_DIALOGFACTORY != NULL)
120 RS_DIALOGFACTORY->requestOptions(this, true);
122 updateMouseButtonHints();
125 void ActionDrawLineParallel::hideOptions()
127 ActionInterface::hideOptions();
129 if (RS_DIALOGFACTORY != NULL)
130 RS_DIALOGFACTORY->requestOptions(this, false);
133 void ActionDrawLineParallel::commandEvent(RS_CommandEvent * e)
135 QString c = e->getCommand().toLower();
137 if (checkCommand("help", c))
139 if (RS_DIALOGFACTORY != NULL)
140 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
141 + getAvailableCommands().join(", "));
149 if (checkCommand("through", c))
152 graphicView->setCurrentAction(new ActionDrawLineParallelThrough(*container,
155 else if (checkCommand("number", c))
160 setStatus(SetNumber);
165 double d = RS_Math::eval(c, &ok);
167 if (ok && d > 1.0e-10)
169 else if (RS_DIALOGFACTORY != NULL)
170 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
173 if (RS_DIALOGFACTORY != NULL)
174 RS_DIALOGFACTORY->requestOptions(this, true, true);
176 updateMouseButtonHints();
177 //setStatus(SetEntity);
184 int n = c.toInt(&ok);
188 if (n > 0 && n < 100)
190 else if (RS_DIALOGFACTORY != NULL)
191 RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. Try 1..99"));
194 else if (RS_DIALOGFACTORY != NULL)
195 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
198 if (RS_DIALOGFACTORY != NULL)
199 RS_DIALOGFACTORY->requestOptions(this, true, true);
201 setStatus(SetEntity);
210 QStringList ActionDrawLineParallel::getAvailableCommands()
217 cmd += command("number");
218 cmd += command("through");
228 void ActionDrawLineParallel::updateMouseCursor()
230 graphicView->setMouseCursor(RS2::CadCursor);
233 void ActionDrawLineParallel::updateToolBar()
235 if (RS_DIALOGFACTORY != NULL)
236 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
239 double ActionDrawLineParallel::getDistance()
244 void ActionDrawLineParallel::setDistance(double d)
249 int ActionDrawLineParallel::getNumber()
254 void ActionDrawLineParallel::setNumber(int n)