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 "rs_commandevent.h"
21 #include "rs_dialogfactory.h"
22 #include "graphicview.h"
23 #include "rs_preview.h"
25 ActionDrawSpline::ActionDrawSpline(RS_EntityContainer & container, GraphicView & graphicView):
26 ActionInterface("Draw splines", container, graphicView)
29 #warning "!!! Need to port setAutoDelete() behaviour from Qt3 to Qt4 !!!"
30 // history.setAutoDelete(true);
31 data = RS_SplineData(3, false);
32 //bHistory.setAutoDelete(true);
35 ActionDrawSpline::~ActionDrawSpline()
39 /*virtual*/ RS2::ActionType ActionDrawSpline::rtti()
41 return RS2::ActionDrawSpline;
44 void ActionDrawSpline::reset()
47 //start = Vector(false);
52 void ActionDrawSpline::init(int status)
54 ActionInterface::init(status);
59 void ActionDrawSpline::trigger()
61 ActionInterface::trigger();
67 spline->setLayerToActive();
68 spline->setPenToActive();
70 container->addEntity(spline);
75 document->startUndoCycle();
76 document->addUndoable(spline);
77 document->endUndoCycle();
82 Vector r = graphicView->getRelativeZero();
83 graphicView->moveRelativeZero(Vector(0.0, 0.0));
84 graphicView->drawEntity(spline);
85 graphicView->moveRelativeZero(r);
87 RS_DEBUG->print("ActionDrawSpline::trigger(): spline added: %d", spline->getId());
93 void ActionDrawSpline::mouseMoveEvent(QMouseEvent * e)
95 RS_DEBUG->print("ActionDrawSpline::mouseMoveEvent begin");
97 Vector mouse = snapPoint(e);
99 if (getStatus() == SetNextPoint && spline)
104 RS_Spline * tmpSpline = (RS_Spline *)spline->clone();
105 tmpSpline->addControlPoint(mouse);
107 // preview->addEntity(tmpSpline);
109 QList<Vector> cpts = tmpSpline->getControlPoints();
110 QList<Vector>::iterator it;
112 // for(it=cpts.begin(); it!=cpts.end(); it+)
113 // preview->addEntity(new RS_Point(preview, RS_PointData(*it)));
118 RS_DEBUG->print("ActionDrawSpline::mouseMoveEvent end");
121 void ActionDrawSpline::mouseReleaseEvent(QMouseEvent * e)
123 if (e->button() == Qt::LeftButton)
125 Vector ce(snapPoint(e));
126 coordinateEvent(&ce);
128 else if (e->button() == Qt::RightButton)
130 if (getStatus() == SetNextPoint)
136 init(getStatus() - 1);
140 void ActionDrawSpline::coordinateEvent(Vector * e)
151 history.append(new Vector(mouse));
155 spline = new RS_Spline(container, data);
156 spline->addControlPoint(mouse);
159 setStatus(SetNextPoint);
160 graphicView->moveRelativeZero(mouse);
161 updateMouseButtonHints();
165 graphicView->moveRelativeZero(mouse);
166 history.append(new Vector(mouse));
170 spline->addControlPoint(mouse);
177 updateMouseButtonHints();
185 void ActionDrawSpline::commandEvent(RS_CommandEvent * e)
187 QString c = e->getCommand().toLower();
192 if (checkCommand("help", c))
194 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
195 + getAvailableCommands().join(", "));
202 if (checkCommand("undo", c))
205 updateMouseButtonHints();
216 QStringList ActionDrawSpline::getAvailableCommands()
226 if (history.count() >= 2)
227 cmd += command("undo");
229 if (history.count() >= 3)
230 cmd += command("close");
241 void ActionDrawSpline::updateMouseButtonHints()
246 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first control point"),
254 if (history.count() >= 3)
256 msg += RS_COMMANDS->command("close");
260 if (history.count() >= 2)
261 msg += RS_COMMANDS->command("undo");
263 if (history.count() >= 2)
264 RS_DIALOGFACTORY->updateMouseWidget(
265 tr("Specify next control point or [%1]").arg(msg),
268 RS_DIALOGFACTORY->updateMouseWidget(
269 tr("Specify next control point"),
275 RS_DIALOGFACTORY->updateMouseWidget("", "");
280 void ActionDrawSpline::showOptions()
282 ActionInterface::showOptions();
283 RS_DIALOGFACTORY->requestOptions(this, true);
286 void ActionDrawSpline::hideOptions()
288 ActionInterface::hideOptions();
289 RS_DIALOGFACTORY->requestOptions(this, false);
292 void ActionDrawSpline::updateMouseCursor()
294 graphicView->setMouseCursor(RS2::CadCursor);
297 void ActionDrawSpline::updateToolBar()
300 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
302 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
305 void ActionDrawSpline::undo()
307 if (history.count() > 1)
309 history.removeLast();
315 //point = *history.last();
320 spline->removeLastControlPoint();
321 Vector * v = history.last();
324 graphicView->moveRelativeZero(*v);
326 graphicView->redraw();
330 RS_DIALOGFACTORY->commandMessage(
331 tr("Cannot undo: Not enough entities defined yet."));
334 void ActionDrawSpline::setDegree(int deg)
339 spline->setDegree(deg);
342 int ActionDrawSpline::getDegree()
347 void ActionDrawSpline::setClosed(bool c)
352 spline->setClosed(c);
355 bool ActionDrawSpline::isClosed()