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_creation.h"
18 #include "rs_dialogfactory.h"
19 #include "rs_graphicview.h"
20 #include "rs_preview.h"
22 RS_ActionDrawLineBisector::RS_ActionDrawLineBisector(RS_EntityContainer & container, RS_GraphicView & graphicView):
23 RS_PreviewActionInterface("Draw Bisectors", container, graphicView)
30 coord1 = Vector(false);
31 coord2 = Vector(false);
32 lastStatus = SetLine1;
35 RS_ActionDrawLineBisector::~RS_ActionDrawLineBisector()
39 /*virtual*/ RS2::ActionType RS_ActionDrawLineBisector::rtti()
41 return RS2::ActionDrawLineBisector;
44 void RS_ActionDrawLineBisector::trigger()
46 RS_PreviewActionInterface::trigger();
48 //if (bisector!=NULL) {
49 RS_Creation creation(container, graphicView);
50 creation.createBisector(coord1,
56 /*RS_Entity* newEntity = NULL;
58 newEntity = new RS_Line(container,
61 if (newEntity!=NULL) {
62 newEntity->setLayerToActive();
63 newEntity->setPenToActive();
64 container->addEntity(newEntity);
68 document->startUndoCycle();
69 document->addUndoable(newEntity);
70 document->endUndoCycle();
72 graphicView->drawEntity(newEntity);
80 RS_DEBUG->print("RS_ActionDrawLineBisector::trigger:"
85 void RS_ActionDrawLineBisector::mouseMoveEvent(QMouseEvent * e)
87 RS_DEBUG->print("RS_ActionDrawLineBisector::mouseMoveEvent begin");
89 Vector mouse = Vector(graphicView->toGraphX(e->x()),
90 graphicView->toGraphY(e->y()));
99 RS_Entity * en = catchEntity(e, RS2::ResolveAll);
101 if (en != NULL && en->rtti() == RS2::EntityLine)
103 line2 = (RS_Line *)en;
108 RS_Creation creation(preview, NULL, false);
109 creation.createBisector(coord1,
124 RS_DEBUG->print("RS_ActionDrawLineBisector::mouseMoveEvent end");
127 void RS_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()));
144 RS_Entity * en = catchEntity(e, RS2::ResolveAll);
146 if (en != NULL && en->rtti() == RS2::EntityLine)
147 line1 = (RS_Line *)en;
161 void RS_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 RS_ActionDrawLineBisector::getAvailableCommands()
233 cmd += command("length");
234 cmd += command("number");
244 void RS_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 RS_ActionDrawLineBisector::showOptions()
276 RS_ActionInterface::showOptions();
278 RS_DIALOGFACTORY->requestOptions(this, true);
281 void RS_ActionDrawLineBisector::hideOptions()
283 RS_ActionInterface::hideOptions();
285 RS_DIALOGFACTORY->requestOptions(this, false);
288 void RS_ActionDrawLineBisector::updateMouseCursor()
290 graphicView->setMouseCursor(RS2::CadCursor);
293 void RS_ActionDrawLineBisector::updateToolBar()
295 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
298 void RS_ActionDrawLineBisector::setLength(double l)
303 double RS_ActionDrawLineBisector::getLength()
308 void RS_ActionDrawLineBisector::setNumber(int n)
313 int RS_ActionDrawLineBisector::getNumber()