1 // rs_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 "rs_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 RS_ActionDrawLineBisector::RS_ActionDrawLineBisector(RS_EntityContainer & container, GraphicView & graphicView):
24 RS_PreviewActionInterface("Draw Bisectors", container, graphicView)
31 coord1 = Vector(false);
32 coord2 = Vector(false);
33 lastStatus = SetLine1;
36 RS_ActionDrawLineBisector::~RS_ActionDrawLineBisector()
40 /*virtual*/ RS2::ActionType RS_ActionDrawLineBisector::rtti()
42 return RS2::ActionDrawLineBisector;
45 void RS_ActionDrawLineBisector::trigger()
47 RS_PreviewActionInterface::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("RS_ActionDrawLineBisector::trigger:"
86 void RS_ActionDrawLineBisector::mouseMoveEvent(QMouseEvent * e)
88 RS_DEBUG->print("RS_ActionDrawLineBisector::mouseMoveEvent begin");
90 Vector mouse = Vector(graphicView->toGraphX(e->x()),
91 graphicView->toGraphY(e->y()));
100 RS_Entity * en = catchEntity(e, RS2::ResolveAll);
102 if (en != NULL && en->rtti() == RS2::EntityLine)
104 line2 = (RS_Line *)en;
109 RS_Creation creation(preview, NULL, false);
110 creation.createBisector(coord1,
125 RS_DEBUG->print("RS_ActionDrawLineBisector::mouseMoveEvent end");
128 void RS_ActionDrawLineBisector::mouseReleaseEvent(QMouseEvent * e)
130 if (e->button() == Qt::RightButton)
134 init(getStatus() - 1);
138 Vector mouse = Vector(graphicView->toGraphX(e->x()),
139 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 RS_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 RS_ActionDrawLineBisector::getAvailableCommands()
234 cmd += command("length");
235 cmd += command("number");
245 void RS_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 RS_ActionDrawLineBisector::showOptions()
277 RS_ActionInterface::showOptions();
279 RS_DIALOGFACTORY->requestOptions(this, true);
282 void RS_ActionDrawLineBisector::hideOptions()
284 RS_ActionInterface::hideOptions();
286 RS_DIALOGFACTORY->requestOptions(this, false);
289 void RS_ActionDrawLineBisector::updateMouseCursor()
291 graphicView->setMouseCursor(RS2::CadCursor);
294 void RS_ActionDrawLineBisector::updateToolBar()
296 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
299 void RS_ActionDrawLineBisector::setLength(double l)
304 double RS_ActionDrawLineBisector::getLength()
309 void RS_ActionDrawLineBisector::setNumber(int n)
314 int RS_ActionDrawLineBisector::getNumber()