1 // rs_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 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 05/22/2010 Added this text. :-)
15 #include "rs_actiondrawlineparallel.h"
17 #include "rs_actiondrawlineparallelthrough.h"
18 #include "rs_commandevent.h"
20 #include "rs_creation.h"
21 #include "rs_dialogfactory.h"
22 #include "graphicview.h"
23 #include "rs_preview.h"
25 RS_ActionDrawLineParallel::RS_ActionDrawLineParallel(RS_EntityContainer & container, GraphicView & graphicView): RS_PreviewActionInterface("Draw Parallels",
26 container, graphicView)
32 coord = Vector(false);
35 RS_ActionDrawLineParallel::~RS_ActionDrawLineParallel()
39 /*virtual*/ RS2::ActionType RS_ActionDrawLineParallel::rtti()
41 return RS2::ActionDrawLineParallel;
44 void RS_ActionDrawLineParallel::trigger()
46 RS_PreviewActionInterface::trigger();
48 RS_Creation creation(container, graphicView);
49 RS_Entity * e = creation.createParallel(coord, distance, number, entity);
52 RS_DEBUG->print("RS_ActionDrawLineParallel::trigger: No parallels added\n");
55 void RS_ActionDrawLineParallel::mouseMoveEvent(QMouseEvent * e)
57 RS_DEBUG->print("RS_ActionDrawLineParallel::mouseMoveEvent begin");
58 coord = Vector(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y()));
59 entity = catchEntity(e, RS2::ResolveAll);
67 RS_Creation creation(preview, NULL, false);
68 creation.createParallel(coord, distance, number, entity);
77 RS_DEBUG->print("RS_ActionDrawLineParallel::mouseMoveEvent end");
80 void RS_ActionDrawLineParallel::mouseReleaseEvent(QMouseEvent * e)
82 // if (RS2::qtToRsButtonState(e->button())==RS2::RightButton)
83 if (e->button() == Qt::RightButton)
84 init(getStatus() - 1);
89 void RS_ActionDrawLineParallel::updateMouseButtonHints()
91 if (RS_DIALOGFACTORY != NULL)
96 RS_DIALOGFACTORY->updateMouseWidget(
97 tr("Specify Distance <%1> or select entity or [%2]")
98 .arg(distance).arg(RS_COMMANDS->command("through")),
103 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter number:"), "");
107 RS_DIALOGFACTORY->updateMouseWidget("", "");
113 void RS_ActionDrawLineParallel::showOptions()
115 RS_ActionInterface::showOptions();
117 if (RS_DIALOGFACTORY != NULL)
118 RS_DIALOGFACTORY->requestOptions(this, true);
120 updateMouseButtonHints();
123 void RS_ActionDrawLineParallel::hideOptions()
125 RS_ActionInterface::hideOptions();
127 if (RS_DIALOGFACTORY != NULL)
128 RS_DIALOGFACTORY->requestOptions(this, false);
131 void RS_ActionDrawLineParallel::commandEvent(RS_CommandEvent * e)
133 QString c = e->getCommand().toLower();
135 if (checkCommand("help", c))
137 if (RS_DIALOGFACTORY != NULL)
138 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
139 + getAvailableCommands().join(", "));
147 if (checkCommand("through", c))
150 graphicView->setCurrentAction(new RS_ActionDrawLineParallelThrough(*container,
153 else if (checkCommand("number", c))
158 setStatus(SetNumber);
163 double d = RS_Math::eval(c, &ok);
165 if (ok && d > 1.0e-10)
167 else if (RS_DIALOGFACTORY != NULL)
168 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
171 if (RS_DIALOGFACTORY != NULL)
172 RS_DIALOGFACTORY->requestOptions(this, true, true);
174 updateMouseButtonHints();
175 //setStatus(SetEntity);
182 int n = c.toInt(&ok);
186 if (n > 0 && n < 100)
188 else if (RS_DIALOGFACTORY != NULL)
189 RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. Try 1..99"));
192 else if (RS_DIALOGFACTORY != NULL)
193 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
196 if (RS_DIALOGFACTORY != NULL)
197 RS_DIALOGFACTORY->requestOptions(this, true, true);
199 setStatus(SetEntity);
208 QStringList RS_ActionDrawLineParallel::getAvailableCommands()
215 cmd += command("number");
216 cmd += command("through");
226 void RS_ActionDrawLineParallel::updateMouseCursor()
228 graphicView->setMouseCursor(RS2::CadCursor);
231 void RS_ActionDrawLineParallel::updateToolBar()
233 if (RS_DIALOGFACTORY != NULL)
234 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
237 double RS_ActionDrawLineParallel::getDistance()
242 void RS_ActionDrawLineParallel::setDistance(double d)
247 int RS_ActionDrawLineParallel::getNumber()
252 void RS_ActionDrawLineParallel::setNumber(int n)