1 // actiondrawspline.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/04/2010 Added this text. :-)
17 #include "actiondrawspline.h"
19 #include "commandevent.h"
22 #include "dialogfactory.h"
23 #include "graphicview.h"
26 ActionDrawSpline::ActionDrawSpline(EntityContainer & container, GraphicView & graphicView):
27 ActionInterface("Draw splines", container, graphicView)
30 #warning "!!! Need to port setAutoDelete() behaviour from Qt3 to Qt4 !!!"
31 // history.setAutoDelete(true);
32 data = SplineData(3, false);
33 //bHistory.setAutoDelete(true);
36 ActionDrawSpline::~ActionDrawSpline()
40 /*virtual*/ RS2::ActionType ActionDrawSpline::rtti()
42 return RS2::ActionDrawSpline;
45 void ActionDrawSpline::reset()
48 //start = Vector(false);
53 void ActionDrawSpline::init(int status)
55 ActionInterface::init(status);
60 void ActionDrawSpline::trigger()
62 ActionInterface::trigger();
68 spline->setLayerToActive();
69 spline->setPenToActive();
71 container->addEntity(spline);
76 document->startUndoCycle();
77 document->addUndoable(spline);
78 document->endUndoCycle();
83 Vector r = graphicView->getRelativeZero();
84 graphicView->moveRelativeZero(Vector(0.0, 0.0));
85 graphicView->drawEntity(spline);
86 graphicView->moveRelativeZero(r);
88 DEBUG->print("ActionDrawSpline::trigger(): spline added: %d", spline->getId());
94 void ActionDrawSpline::mouseMoveEvent(QMouseEvent * e)
96 DEBUG->print("ActionDrawSpline::mouseMoveEvent begin");
98 Vector mouse = snapPoint(e);
100 if (getStatus() == SetNextPoint && spline)
105 Spline * tmpSpline = (Spline *)spline->clone();
106 tmpSpline->addControlPoint(mouse);
108 // preview->addEntity(tmpSpline);
110 QList<Vector> cpts = tmpSpline->getControlPoints();
111 QList<Vector>::iterator it;
113 // for(it=cpts.begin(); it!=cpts.end(); it+)
114 // preview->addEntity(new Point(preview, PointData(*it)));
119 DEBUG->print("ActionDrawSpline::mouseMoveEvent end");
122 void ActionDrawSpline::mouseReleaseEvent(QMouseEvent * e)
124 if (e->button() == Qt::LeftButton)
126 Vector ce(snapPoint(e));
127 coordinateEvent(&ce);
129 else if (e->button() == Qt::RightButton)
131 if (getStatus() == SetNextPoint)
137 init(getStatus() - 1);
141 void ActionDrawSpline::coordinateEvent(Vector * e)
152 history.append(new Vector(mouse));
156 spline = new Spline(container, data);
157 spline->addControlPoint(mouse);
160 setStatus(SetNextPoint);
161 graphicView->moveRelativeZero(mouse);
162 updateMouseButtonHints();
166 graphicView->moveRelativeZero(mouse);
167 history.append(new Vector(mouse));
171 spline->addControlPoint(mouse);
178 updateMouseButtonHints();
186 void ActionDrawSpline::commandEvent(CommandEvent * e)
188 QString c = e->getCommand().toLower();
193 if (checkCommand("help", c))
195 DIALOGFACTORY->commandMessage(msgAvailableCommands()
196 + getAvailableCommands().join(", "));
203 if (checkCommand("undo", c))
206 updateMouseButtonHints();
217 QStringList ActionDrawSpline::getAvailableCommands()
227 if (history.count() >= 2)
228 cmd += command("undo");
230 if (history.count() >= 3)
231 cmd += command("close");
242 void ActionDrawSpline::updateMouseButtonHints()
247 DIALOGFACTORY->updateMouseWidget(tr("Specify first control point"),
255 if (history.count() >= 3)
257 msg += COMMANDS->command("close");
261 if (history.count() >= 2)
262 msg += COMMANDS->command("undo");
264 if (history.count() >= 2)
265 DIALOGFACTORY->updateMouseWidget(
266 tr("Specify next control point or [%1]").arg(msg),
269 DIALOGFACTORY->updateMouseWidget(
270 tr("Specify next control point"),
276 DIALOGFACTORY->updateMouseWidget("", "");
281 void ActionDrawSpline::showOptions()
283 ActionInterface::showOptions();
284 DIALOGFACTORY->requestOptions(this, true);
287 void ActionDrawSpline::hideOptions()
289 ActionInterface::hideOptions();
290 DIALOGFACTORY->requestOptions(this, false);
293 void ActionDrawSpline::updateMouseCursor()
295 graphicView->setMouseCursor(RS2::CadCursor);
298 void ActionDrawSpline::updateToolBar()
301 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
303 DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
306 void ActionDrawSpline::undo()
308 if (history.count() > 1)
310 history.removeLast();
316 //point = *history.last();
321 spline->removeLastControlPoint();
322 Vector * v = history.last();
325 graphicView->moveRelativeZero(*v);
327 graphicView->redraw();
331 DIALOGFACTORY->commandMessage(
332 tr("Cannot undo: Not enough entities defined yet."));
335 void ActionDrawSpline::setDegree(int deg)
340 spline->setDegree(deg);
343 int ActionDrawSpline::getDegree()
348 void ActionDrawSpline::setClosed(bool c)
353 spline->setClosed(c);
356 bool ActionDrawSpline::isClosed()