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"
22 #include "rs_dialogfactory.h"
23 #include "graphicview.h"
24 #include "rs_preview.h"
26 ActionDrawLineBisector::ActionDrawLineBisector(RS_EntityContainer & container, GraphicView & graphicView):
27 ActionInterface("Draw Bisectors", container, graphicView)
34 coord1 = Vector(false);
35 coord2 = Vector(false);
36 lastStatus = SetLine1;
39 ActionDrawLineBisector::~ActionDrawLineBisector()
43 /*virtual*/ RS2::ActionType ActionDrawLineBisector::rtti()
45 return RS2::ActionDrawLineBisector;
48 void ActionDrawLineBisector::trigger()
50 ActionInterface::trigger();
52 //if (bisector!=NULL) {
53 RS_Creation creation(container, graphicView);
54 creation.createBisector(coord1,
60 /*RS_Entity* newEntity = NULL;
62 newEntity = new RS_Line(container,
65 if (newEntity!=NULL) {
66 newEntity->setLayerToActive();
67 newEntity->setPenToActive();
68 container->addEntity(newEntity);
72 document->startUndoCycle();
73 document->addUndoable(newEntity);
74 document->endUndoCycle();
76 graphicView->drawEntity(newEntity);
84 RS_DEBUG->print("ActionDrawLineBisector::trigger:"
89 void ActionDrawLineBisector::mouseMoveEvent(QMouseEvent * e)
91 RS_DEBUG->print("ActionDrawLineBisector::mouseMoveEvent begin");
93 Vector mouse = Vector(graphicView->toGraphX(e->x()),
94 graphicView->toGraphY(e->y()));
104 RS_Entity * en = catchEntity(e, RS2::ResolveAll);
106 if (en && en->rtti() == RS2::EntityLine)
108 // line2 = (RS_Line *)en;
113 // RS_Creation creation(preview, NULL, false);
114 // creation.createBisector(coord1, coord2, length, number, line1, line2);
124 RS_DEBUG->print("ActionDrawLineBisector::mouseMoveEvent end");
127 void ActionDrawLineBisector::mouseReleaseEvent(QMouseEvent * e)
129 if (e->button() == Qt::RightButton)
133 init(getStatus() - 1);
137 Vector mouse = Vector(graphicView->toGraphX(e->x()),
138 graphicView->toGraphY(e->y()));
145 RS_Entity * en = catchEntity(e, RS2::ResolveAll);
147 if (en != NULL && en->rtti() == RS2::EntityLine)
148 line1 = (RS_Line *)en;
162 void ActionDrawLineBisector::commandEvent(RS_CommandEvent * e)
164 QString c = e->getCommand().toLower();
166 if (checkCommand("help", c))
168 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
169 + getAvailableCommands().join(", "));
177 lastStatus = (Status)getStatus();
179 if (checkCommand("length", c))
184 setStatus(SetLength);
186 else if (checkCommand("number", c))
191 setStatus(SetNumber);
197 double l = RS_Math::eval(c, &ok);
202 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
203 RS_DIALOGFACTORY->requestOptions(this, true, true);
204 setStatus(lastStatus);
210 int n = (int)RS_Math::eval(c, &ok);
215 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
216 RS_DIALOGFACTORY->requestOptions(this, true, true);
217 setStatus(lastStatus);
226 QStringList ActionDrawLineBisector::getAvailableCommands()
234 cmd += command("length");
235 cmd += command("number");
245 void ActionDrawLineBisector::updateMouseButtonHints()
250 RS_DIALOGFACTORY->updateMouseWidget(tr("Select first line"),
255 RS_DIALOGFACTORY->updateMouseWidget(tr("Select second line"),
260 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter bisector length:"),
265 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter number of bisectors:"),
270 RS_DIALOGFACTORY->updateMouseWidget("", "");
275 void ActionDrawLineBisector::showOptions()
277 ActionInterface::showOptions();
279 RS_DIALOGFACTORY->requestOptions(this, true);
282 void ActionDrawLineBisector::hideOptions()
284 ActionInterface::hideOptions();
286 RS_DIALOGFACTORY->requestOptions(this, false);
289 void ActionDrawLineBisector::updateMouseCursor()
291 graphicView->setMouseCursor(RS2::CadCursor);
294 void ActionDrawLineBisector::updateToolBar()
296 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
299 void ActionDrawLineBisector::setLength(double l)
304 double ActionDrawLineBisector::getLength()
309 void ActionDrawLineBisector::setNumber(int n)
314 int ActionDrawLineBisector::getNumber()