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 "commandevent.h"
22 #include "dialogfactory.h"
23 #include "graphicview.h"
26 ActionDrawLineBisector::ActionDrawLineBisector(EntityContainer & container,
27 GraphicView & graphicView):
28 ActionInterface("Draw Bisectors", container, graphicView),
29 bisector(NULL), line1(NULL), line2(NULL), length(10.0), number(1),
30 coord1(Vector(false)), coord2(Vector(false)), lastStatus(SetLine1)
32 graphicView.SetSnapperVisible(false);
35 ActionDrawLineBisector::~ActionDrawLineBisector()
39 /*virtual*/ RS2::ActionType ActionDrawLineBisector::rtti()
41 return RS2::ActionDrawLineBisector;
44 void ActionDrawLineBisector::trigger()
46 ActionInterface::trigger();
47 Creation creation(container, graphicView);
48 creation.createBisector(coord1, coord2, length, number, line1, line2);
49 graphicView->redraw();
52 void ActionDrawLineBisector::mouseMoveEvent(QMouseEvent * e)
54 DEBUG->print("ActionDrawLineBisector::mouseMoveEvent begin");
56 Vector mouse = Vector(graphicView->toGraphX(e->x()),
57 graphicView->toGraphY(e->y()));
67 Entity * en = catchEntity(e, RS2::ResolveAll);
69 if (en && en->rtti() == RS2::EntityLine)
72 graphicView->preview.clear();
73 Creation creation(&(graphicView->preview), NULL, false);
74 creation.createBisector(coord1, coord2, length, number, line1, line2);
83 graphicView->redraw();
84 DEBUG->print("ActionDrawLineBisector::mouseMoveEvent end");
87 void ActionDrawLineBisector::mouseReleaseEvent(QMouseEvent * e)
89 if (e->button() == Qt::RightButton)
93 init(getStatus() - 1);
97 Vector mouse = Vector(graphicView->toGraphX(e->x()),
98 graphicView->toGraphY(e->y()));
105 Entity * en = catchEntity(e, RS2::ResolveAll);
107 if (en && en->rtti() == RS2::EntityLine)
124 void ActionDrawLineBisector::commandEvent(CommandEvent * e)
126 QString c = e->getCommand().toLower();
128 if (checkCommand("help", c))
130 DIALOGFACTORY->commandMessage(msgAvailableCommands()
131 + getAvailableCommands().join(", "));
139 lastStatus = (Status)getStatus();
141 if (checkCommand("length", c))
146 setStatus(SetLength);
148 else if (checkCommand("number", c))
153 setStatus(SetNumber);
161 double l = Math::eval(c, &ok);
166 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
168 DIALOGFACTORY->requestOptions(this, true, true);
169 setStatus(lastStatus);
176 int n = (int)Math::eval(c, &ok);
181 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
183 DIALOGFACTORY->requestOptions(this, true, true);
184 setStatus(lastStatus);
193 QStringList ActionDrawLineBisector::getAvailableCommands()
201 cmd += command("length");
202 cmd += command("number");
212 void ActionDrawLineBisector::updateMouseButtonHints()
217 DIALOGFACTORY->updateMouseWidget(tr("Select first line"), tr("Cancel"));
221 DIALOGFACTORY->updateMouseWidget(tr("Select second line"), tr("Back"));
225 DIALOGFACTORY->updateMouseWidget(tr("Enter bisector length:"), tr("Back"));
229 DIALOGFACTORY->updateMouseWidget(tr("Enter number of bisectors:"), tr("Back"));
233 DIALOGFACTORY->updateMouseWidget("", "");
238 void ActionDrawLineBisector::showOptions()
240 ActionInterface::showOptions();
241 DIALOGFACTORY->requestOptions(this, true);
244 void ActionDrawLineBisector::hideOptions()
246 ActionInterface::hideOptions();
247 DIALOGFACTORY->requestOptions(this, false);
250 void ActionDrawLineBisector::updateMouseCursor()
252 graphicView->setMouseCursor(RS2::CadCursor);
255 void ActionDrawLineBisector::updateToolBar()
257 DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
260 void ActionDrawLineBisector::setLength(double l)
265 double ActionDrawLineBisector::getLength()
270 void ActionDrawLineBisector::setNumber(int n)
275 int ActionDrawLineBisector::getNumber()