-// rs_actiondrawspline.cpp
+// actiondrawspline.cpp
//
// Part of the Architektonas Project
// Originally part of QCad Community Edition by Andrew Mustun
// JLH 06/04/2010 Added this text. :-)
//
-#include "rs_actiondrawspline.h"
+#include "actiondrawspline.h"
#include "rs_commandevent.h"
#include "commands.h"
#include "graphicview.h"
#include "rs_preview.h"
-RS_ActionDrawSpline::RS_ActionDrawSpline(RS_EntityContainer & container, GraphicView & graphicView):
- RS_PreviewActionInterface("Draw splines", container, graphicView)
+ActionDrawSpline::ActionDrawSpline(RS_EntityContainer & container, GraphicView & graphicView):
+ ActionInterface("Draw splines", container, graphicView)
{
reset();
#warning "!!! Need to port setAutoDelete() behaviour from Qt3 to Qt4 !!!"
//bHistory.setAutoDelete(true);
}
-RS_ActionDrawSpline::~RS_ActionDrawSpline()
+ActionDrawSpline::~ActionDrawSpline()
{
}
-/*virtual*/ RS2::ActionType RS_ActionDrawSpline::rtti()
+/*virtual*/ RS2::ActionType ActionDrawSpline::rtti()
{
return RS2::ActionDrawSpline;
}
-void RS_ActionDrawSpline::reset()
+void ActionDrawSpline::reset()
{
spline = NULL;
//start = Vector(false);
//bHistory.clear();
}
-void RS_ActionDrawSpline::init(int status)
+void ActionDrawSpline::init(int status)
{
- RS_PreviewActionInterface::init(status);
+ ActionInterface::init(status);
reset();
}
-void RS_ActionDrawSpline::trigger()
+void ActionDrawSpline::trigger()
{
- RS_PreviewActionInterface::trigger();
+ ActionInterface::trigger();
if (spline == NULL)
return;
// add the entity
- //RS_Spline* spline = new RS_Spline(container, data);
spline->setLayerToActive();
spline->setPenToActive();
spline->update();
graphicView->drawEntity(spline);
graphicView->moveRelativeZero(r);
drawSnapper();
- RS_DEBUG->print("RS_ActionDrawSpline::trigger(): spline added: %d", spline->getId());
+ RS_DEBUG->print("ActionDrawSpline::trigger(): spline added: %d", spline->getId());
spline = NULL;
//history.clear();
}
-void RS_ActionDrawSpline::mouseMoveEvent(QMouseEvent * e)
+void ActionDrawSpline::mouseMoveEvent(QMouseEvent * e)
{
- RS_DEBUG->print("RS_ActionDrawSpline::mouseMoveEvent begin");
+ RS_DEBUG->print("ActionDrawSpline::mouseMoveEvent begin");
Vector mouse = snapPoint(e);
- if (getStatus() == SetNextPoint && spline != NULL /*&& point.valid*/)
+ if (getStatus() == SetNextPoint && spline)
{
deletePreview();
clearPreview();
RS_Spline * tmpSpline = (RS_Spline *)spline->clone();
tmpSpline->addControlPoint(mouse);
tmpSpline->update();
- preview->addEntity(tmpSpline);
+// preview->addEntity(tmpSpline);
QList<Vector> cpts = tmpSpline->getControlPoints();
QList<Vector>::iterator it;
- for(it = cpts.begin(); it != cpts.end(); ++it)
- preview->addEntity(new RS_Point(preview, RS_PointData(*it)));
+// for(it=cpts.begin(); it!=cpts.end(); it+)
+// preview->addEntity(new RS_Point(preview, RS_PointData(*it)));
drawPreview();
}
- RS_DEBUG->print("RS_ActionDrawSpline::mouseMoveEvent end");
+ RS_DEBUG->print("ActionDrawSpline::mouseMoveEvent end");
}
-void RS_ActionDrawSpline::mouseReleaseEvent(QMouseEvent * e)
+void ActionDrawSpline::mouseReleaseEvent(QMouseEvent * e)
{
if (e->button() == Qt::LeftButton)
{
}
}
-void RS_ActionDrawSpline::coordinateEvent(Vector * e)
+void ActionDrawSpline::coordinateEvent(Vector * e)
{
- if (e == NULL)
+ if (!e)
return;
Vector mouse = *e;
switch (getStatus())
{
case SetStartpoint:
- //data.startpoint = mouse;
- //point = mouse;
history.clear();
history.append(new Vector(mouse));
- if (spline == NULL)
+ if (!spline)
{
spline = new RS_Spline(container, data);
spline->addControlPoint(mouse);
}
- //bHistory.clear();
- //bHistory.append(new double(0.0));
- //start = mouse;
setStatus(SetNextPoint);
graphicView->moveRelativeZero(mouse);
updateMouseButtonHints();
case SetNextPoint:
graphicView->moveRelativeZero(mouse);
- //point = mouse;
history.append(new Vector(mouse));
- //bHistory.append(new double(0.0));
- if (spline != NULL)
+ if (spline)
{
- //graphicView->deleteEntity(spline);
spline->addControlPoint(mouse);
- //spline->setEndpoint(mouse);
- //if (spline->count()==1) {
- //spline->setLayerToActive();
- //spline->setPenToActive();
- //container->addEntity(spline);
- //}
deletePreview();
clearPreview();
deleteSnapper();
- //graphicView->drawEntity(spline);
drawSnapper();
}
- //trigger();
- //data.startpoint = data.endpoint;
updateMouseButtonHints();
- //graphicView->moveRelativeZero(mouse);
break;
default:
}
}
-void RS_ActionDrawSpline::commandEvent(RS_CommandEvent * e)
+void ActionDrawSpline::commandEvent(RS_CommandEvent * e)
{
QString c = e->getCommand().toLower();
switch (getStatus())
{
case SetStartpoint:
-
if (checkCommand("help", c))
{
RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
+ getAvailableCommands().join(", "));
return;
}
+
break;
case SetNextPoint:
- /*if (checkCommand("close", c)) {
- close();
- updateMouseButtonHints();
- return;
- }*/
-
if (checkCommand("undo", c))
{
undo();
updateMouseButtonHints();
return;
}
+
break;
default:
}
}
-QStringList RS_ActionDrawSpline::getAvailableCommands()
+QStringList ActionDrawSpline::getAvailableCommands()
{
QStringList cmd;
break;
case SetNextPoint:
-
if (history.count() >= 2)
cmd += command("undo");
-
if (history.count() >= 3)
cmd += command("close");
+
break;
default:
return cmd;
}
-void RS_ActionDrawSpline::updateMouseButtonHints()
+void ActionDrawSpline::updateMouseButtonHints()
{
switch (getStatus())
{
tr("Cancel"));
break;
- case SetNextPoint: {
+ case SetNextPoint:
+ {
QString msg = "";
if (history.count() >= 3)
tr("Specify next control point"),
tr("Back"));
}
- break;
+ break;
default:
RS_DIALOGFACTORY->updateMouseWidget("", "");
}
}
-void RS_ActionDrawSpline::showOptions()
+void ActionDrawSpline::showOptions()
{
- RS_ActionInterface::showOptions();
-
+ ActionInterface::showOptions();
RS_DIALOGFACTORY->requestOptions(this, true);
}
-void RS_ActionDrawSpline::hideOptions()
+void ActionDrawSpline::hideOptions()
{
- RS_ActionInterface::hideOptions();
-
+ ActionInterface::hideOptions();
RS_DIALOGFACTORY->requestOptions(this, false);
}
-void RS_ActionDrawSpline::updateMouseCursor()
+void ActionDrawSpline::updateMouseCursor()
{
graphicView->setMouseCursor(RS2::CadCursor);
}
-void RS_ActionDrawSpline::updateToolBar()
+void ActionDrawSpline::updateToolBar()
{
if (!isFinished())
RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
else
- //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSplines);
RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
}
-/*
- void RS_ActionDrawSpline::close() {
- if (history.count()>2 && start.valid) {
- //data.endpoint = start;
- //trigger();
- if (spline!=NULL) {
- Vector e(spline->getStartpoint());
- coordinateEvent(&e);
- }
- trigger();
- setStatus(SetStartpoint);
- graphicView->moveRelativeZero(start);
- } else {
- RS_DIALOGFACTORY->commandMessage(
- tr("Cannot close sequence of lines: "
- "Not enough entities defined yet."));
- }
- }
- */
-
-void RS_ActionDrawSpline::undo()
+void ActionDrawSpline::undo()
{
if (history.count() > 1)
{
history.removeLast();
- //bHistory.removeLast();
deletePreview();
clearPreview();
- //graphicView->setCurrentAction(
- // new RS_ActionEditUndo(true, *container, *graphicView));
- if (history.last() != NULL)
+ if (history.last())
{
//point = *history.last();
}
- if (spline != NULL)
+ if (spline)
{
spline->removeLastControlPoint();
Vector * v = history.last();
- if (v != NULL)
+ if (v)
graphicView->moveRelativeZero(*v);
+
graphicView->redraw();
}
}
else
RS_DIALOGFACTORY->commandMessage(
- tr("Cannot undo: "
- "Not enough entities defined yet."));
+ tr("Cannot undo: Not enough entities defined yet."));
}
-void RS_ActionDrawSpline::setDegree(int deg)
+void ActionDrawSpline::setDegree(int deg)
{
data.degree = deg;
- if (spline != NULL)
+ if (spline)
spline->setDegree(deg);
}
-int RS_ActionDrawSpline::getDegree()
+int ActionDrawSpline::getDegree()
{
return data.degree;
}
-void RS_ActionDrawSpline::setClosed(bool c)
+void ActionDrawSpline::setClosed(bool c)
{
data.closed = c;
- if (spline != NULL)
+ if (spline)
spline->setClosed(c);
}
-bool RS_ActionDrawSpline::isClosed()
+bool ActionDrawSpline::isClosed()
{
return data.closed;
}
-
-// EOF