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 // 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 06/03/2010 Added this text. :-)
17 #include "actiondrawlinebisector.h"
19 #include "rs_commandevent.h"
20 #include "rs_creation.h"
21 #include "rs_dialogfactory.h"
22 #include "graphicview.h"
23 #include "rs_preview.h"
25 ActionDrawLineBisector::ActionDrawLineBisector(RS_EntityContainer & container, GraphicView & graphicView):
26 ActionInterface("Draw Bisectors", container, graphicView)
33 coord1 = Vector(false);
34 coord2 = Vector(false);
35 lastStatus = SetLine1;
38 ActionDrawLineBisector::~ActionDrawLineBisector()
42 /*virtual*/ RS2::ActionType ActionDrawLineBisector::rtti()
44 return RS2::ActionDrawLineBisector;
47 void ActionDrawLineBisector::trigger()
49 ActionInterface::trigger();
51 //if (bisector!=NULL) {
52 RS_Creation creation(container, graphicView);
53 creation.createBisector(coord1,
59 /*RS_Entity* newEntity = NULL;
61 newEntity = new RS_Line(container,
64 if (newEntity!=NULL) {
65 newEntity->setLayerToActive();
66 newEntity->setPenToActive();
67 container->addEntity(newEntity);
71 document->startUndoCycle();
72 document->addUndoable(newEntity);
73 document->endUndoCycle();
75 graphicView->drawEntity(newEntity);
83 RS_DEBUG->print("ActionDrawLineBisector::trigger:"
88 void ActionDrawLineBisector::mouseMoveEvent(QMouseEvent * e)
90 RS_DEBUG->print("ActionDrawLineBisector::mouseMoveEvent begin");
92 Vector mouse = Vector(graphicView->toGraphX(e->x()),
93 graphicView->toGraphY(e->y()));
103 RS_Entity * en = catchEntity(e, RS2::ResolveAll);
105 if (en && en->rtti() == RS2::EntityLine)
107 // line2 = (RS_Line *)en;
112 // RS_Creation creation(preview, NULL, false);
113 // creation.createBisector(coord1, coord2, length, number, line1, line2);
123 RS_DEBUG->print("ActionDrawLineBisector::mouseMoveEvent end");
126 void ActionDrawLineBisector::mouseReleaseEvent(QMouseEvent * e)
128 if (e->button() == Qt::RightButton)
132 init(getStatus() - 1);
136 Vector mouse = Vector(graphicView->toGraphX(e->x()),
137 graphicView->toGraphY(e->y()));
144 RS_Entity * en = catchEntity(e, RS2::ResolveAll);
146 if (en != NULL && en->rtti() == RS2::EntityLine)
147 line1 = (RS_Line *)en;
161 void ActionDrawLineBisector::commandEvent(RS_CommandEvent * e)
163 QString c = e->getCommand().toLower();
165 if (checkCommand("help", c))
167 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
168 + getAvailableCommands().join(", "));
176 lastStatus = (Status)getStatus();
178 if (checkCommand("length", c))
183 setStatus(SetLength);
185 else if (checkCommand("number", c))
190 setStatus(SetNumber);
196 double l = RS_Math::eval(c, &ok);
201 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
202 RS_DIALOGFACTORY->requestOptions(this, true, true);
203 setStatus(lastStatus);
209 int n = (int)RS_Math::eval(c, &ok);
214 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
215 RS_DIALOGFACTORY->requestOptions(this, true, true);
216 setStatus(lastStatus);
225 QStringList ActionDrawLineBisector::getAvailableCommands()
233 cmd += command("length");
234 cmd += command("number");
244 void ActionDrawLineBisector::updateMouseButtonHints()
249 RS_DIALOGFACTORY->updateMouseWidget(tr("Select first line"),
254 RS_DIALOGFACTORY->updateMouseWidget(tr("Select second line"),
259 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter bisector length:"),
264 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter number of bisectors:"),
269 RS_DIALOGFACTORY->updateMouseWidget("", "");
274 void ActionDrawLineBisector::showOptions()
276 ActionInterface::showOptions();
278 RS_DIALOGFACTORY->requestOptions(this, true);
281 void ActionDrawLineBisector::hideOptions()
283 ActionInterface::hideOptions();
285 RS_DIALOGFACTORY->requestOptions(this, false);
288 void ActionDrawLineBisector::updateMouseCursor()
290 graphicView->setMouseCursor(RS2::CadCursor);
293 void ActionDrawLineBisector::updateToolBar()
295 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
298 void ActionDrawLineBisector::setLength(double l)
303 double ActionDrawLineBisector::getLength()
308 void ActionDrawLineBisector::setNumber(int n)
313 int ActionDrawLineBisector::getNumber()