1 // actiondrawlinebisector.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/03/2010 Added this text. :-)
15 #include "actiondrawlinebisector.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 ActionDrawLineBisector::ActionDrawLineBisector(RS_EntityContainer & container, GraphicView & graphicView):
24 ActionInterface("Draw Bisectors", container, graphicView)
31 coord1 = Vector(false);
32 coord2 = Vector(false);
33 lastStatus = SetLine1;
36 ActionDrawLineBisector::~ActionDrawLineBisector()
40 /*virtual*/ RS2::ActionType ActionDrawLineBisector::rtti()
42 return RS2::ActionDrawLineBisector;
45 void ActionDrawLineBisector::trigger()
47 ActionInterface::trigger();
49 //if (bisector!=NULL) {
50 RS_Creation creation(container, graphicView);
51 creation.createBisector(coord1,
57 /*RS_Entity* newEntity = NULL;
59 newEntity = new RS_Line(container,
62 if (newEntity!=NULL) {
63 newEntity->setLayerToActive();
64 newEntity->setPenToActive();
65 container->addEntity(newEntity);
69 document->startUndoCycle();
70 document->addUndoable(newEntity);
71 document->endUndoCycle();
73 graphicView->drawEntity(newEntity);
81 RS_DEBUG->print("ActionDrawLineBisector::trigger:"
86 void ActionDrawLineBisector::mouseMoveEvent(QMouseEvent * e)
88 RS_DEBUG->print("ActionDrawLineBisector::mouseMoveEvent begin");
90 Vector mouse = Vector(graphicView->toGraphX(e->x()),
91 graphicView->toGraphY(e->y()));
101 RS_Entity * en = catchEntity(e, RS2::ResolveAll);
103 if (en && en->rtti() == RS2::EntityLine)
105 // line2 = (RS_Line *)en;
110 // RS_Creation creation(preview, NULL, false);
111 // creation.createBisector(coord1, coord2, length, number, line1, line2);
121 RS_DEBUG->print("ActionDrawLineBisector::mouseMoveEvent end");
124 void ActionDrawLineBisector::mouseReleaseEvent(QMouseEvent * e)
126 if (e->button() == Qt::RightButton)
130 init(getStatus() - 1);
134 Vector mouse = Vector(graphicView->toGraphX(e->x()),
135 graphicView->toGraphY(e->y()));
142 RS_Entity * en = catchEntity(e, RS2::ResolveAll);
144 if (en != NULL && en->rtti() == RS2::EntityLine)
145 line1 = (RS_Line *)en;
159 void ActionDrawLineBisector::commandEvent(RS_CommandEvent * e)
161 QString c = e->getCommand().toLower();
163 if (checkCommand("help", c))
165 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
166 + getAvailableCommands().join(", "));
174 lastStatus = (Status)getStatus();
176 if (checkCommand("length", c))
181 setStatus(SetLength);
183 else if (checkCommand("number", c))
188 setStatus(SetNumber);
194 double l = RS_Math::eval(c, &ok);
199 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
200 RS_DIALOGFACTORY->requestOptions(this, true, true);
201 setStatus(lastStatus);
207 int n = (int)RS_Math::eval(c, &ok);
212 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
213 RS_DIALOGFACTORY->requestOptions(this, true, true);
214 setStatus(lastStatus);
223 QStringList ActionDrawLineBisector::getAvailableCommands()
231 cmd += command("length");
232 cmd += command("number");
242 void ActionDrawLineBisector::updateMouseButtonHints()
247 RS_DIALOGFACTORY->updateMouseWidget(tr("Select first line"),
252 RS_DIALOGFACTORY->updateMouseWidget(tr("Select second line"),
257 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter bisector length:"),
262 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter number of bisectors:"),
267 RS_DIALOGFACTORY->updateMouseWidget("", "");
272 void ActionDrawLineBisector::showOptions()
274 ActionInterface::showOptions();
276 RS_DIALOGFACTORY->requestOptions(this, true);
279 void ActionDrawLineBisector::hideOptions()
281 ActionInterface::hideOptions();
283 RS_DIALOGFACTORY->requestOptions(this, false);
286 void ActionDrawLineBisector::updateMouseCursor()
288 graphicView->setMouseCursor(RS2::CadCursor);
291 void ActionDrawLineBisector::updateToolBar()
293 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
296 void ActionDrawLineBisector::setLength(double l)
301 double ActionDrawLineBisector::getLength()
306 void ActionDrawLineBisector::setNumber(int n)
311 int ActionDrawLineBisector::getNumber()