ActionDrawPolyline::ActionDrawPolyline(EntityContainer & container,
GraphicView & graphicView):
- ActionInterface("Draw polyline", container, graphicView)
+ ActionInterface("Draw polyline", container, graphicView), vertex(false), polyline(NULL)
{
- vertex = Vector(false);
- polyline = NULL;
+// vertex = Vector(false);
}
ActionDrawPolyline::~ActionDrawPolyline()
delete polyline;
}
+/*virtual*/ RS2::ActionType ActionDrawPolyline::rtti()
+{
+ return RS2::ActionDrawPolyline;
+}
+
void ActionDrawPolyline::trigger()
{
if (polyline)
{
container->addEntity(polyline);
-// deleteSnapper();
if (document)
{
DEBUG->print("ActionDrawPolyline::trigger(): polyline added: %d", polyline->getId());
polyline = NULL;
+ graphicView->redraw(); //hm.
}
}
void ActionDrawPolyline::mouseMoveEvent(QMouseEvent * e)
{
+#if 0
if (vertex.valid && polyline)
{
Vector v = snapPoint(e);
vertex = v;
DEBUG->print("ActionDrawPolyline::mouseMoveEvent(): line added: %d", ent->getId());
}
+#else
+ Vector mouse = graphicView->snapper.snapPoint(e);
+
+ if (getStatus() == SetNextPoint && startPoint.valid)
+ {
+ // We have to draw a line or arc depending on the state of the "Arc"
+ // checkbox.
+ // We'll start with lines...
+ graphicView->preview.clear();
+ Line * line = new Line(&(graphicView->preview), LineData(startPoint, mouse));
+
+ if (polyline)
+ graphicView->preview.addEntity(polyline);
+
+ graphicView->preview.addEntity(line);
+ }
+
+ graphicView->redraw(); //hm.
+#endif
+
+#if 0
+ Vector mouse = graphicView->snapper.snapPoint(e);
+ DEBUG->print("ActionDrawLine::mouseMoveEvent: snap point: OK");
+
+ if (getStatus() == SetEndpoint && data.startpoint.valid)
+ {
+ DEBUG->print("ActionDrawLine::mouseMoveEvent: update preview");
+ // This is lame. Creating a new Line every time the endpoint moves.
+ // Surely we can alter the line entity inside the preview, no?
+#if 0
+ graphicView->preview.clear(); // Remove entities from the container
+ Line * line = new Line(&(graphicView->preview), LineData(data.startpoint, mouse));
+ graphicView->preview.addEntity(line);
+#else
+ // We can assume there's only one line in there, can't we?
+ Line * line = (Line *)graphicView->preview.firstEntity(RS2::ResolveNone);
+
+ if (line)
+ {
+ line->setEndpoint(mouse);
+ }
+ else
+ {
+ line = new Line(&(graphicView->preview), LineData(data.startpoint, mouse));
+ graphicView->preview.addEntity(line);
+ }
+#endif
+ }
+
+ //hm. [ok, this works. :-D]
+ graphicView->redraw();
+#endif
}
void ActionDrawPolyline::mousePressEvent(QMouseEvent * e)
{
if (e->button() == Qt::LeftButton)
{
- vertex = snapPoint(e);
- polyline = new Polyline(container, PolylineData(vertex, vertex, 0));
- polyline->setLayerToActive();
- polyline->setPenToActive();
+// vertex = snapPoint(e);
+// polyline = new Polyline(container, PolylineData(vertex, vertex, 0));
+// polyline->setLayerToActive();
+// polyline->setPenToActive();
}
}
{
if (e->button() == Qt::LeftButton)
{
- vertex = Vector(false);
- trigger();
+ Vector ce(graphicView->snapper.snapPoint(e));
+ coordinateEvent(&ce);
+
+//let's try this...
+ if (!polyline)
+ {
+//printf("ActionDrawPolyline::mouseReleaseEvent(): Creating polyline...\n");
+ polyline = new Polyline(container, PolylineData(ce, ce, 0));
+// vertex = snapPoint(e);
+// polyline = new Polyline(container, PolylineData(vertex, vertex, 0));
+ polyline->setLayerToActive();
+ polyline->setPenToActive();
+ }
+ else
+ {
+//printf("ActionDrawPolyline::mouseReleaseEvent(): Adding vertex to polyline...\n");
+ Entity * ent = polyline->addVertex(ce);
+ ent->setLayerToActive();
+ ent->setPenToActive();
+ }
}
else if (e->button() == Qt::RightButton)
{
+#if 0
if (polyline)
{
delete polyline;
polyline = NULL;
}
+#else
+// if (getStatus() == SetFirstPoint)
+//ANY right button should trigger (? what about adding twice? won't happen)
+ trigger(); // this will set the polyline to NULL once added to the container
+#endif
-// deleteSnapper();
init(getStatus() - 1);
graphicView->redraw(); //hm.
}
}
+void ActionDrawPolyline::coordinateEvent(Vector * coordinate)
+{
+ DEBUG->print("ActionDrawPolyline::coordinateEvent");
+
+ if (!coordinate)
+ {
+ DEBUG->print("ActionDrawPolyline::coordinateEvent: event was NULL");
+ return;
+ }
+
+// Vector mouse = *e;
+
+ switch (getStatus())
+ {
+ case SetFirstPoint:
+ startPoint = *coordinate;
+// ClearHistory();
+// history.append(new Vector(mouse));
+// start = data.startpoint;
+ setStatus(SetNextPoint);
+ graphicView->moveRelativeZero(*coordinate);
+// trigger();
+ updateMouseButtonHints();
+ break;
+
+ case SetNextPoint:
+// data.endpoint = mouse;
+// history.append(new Vector(mouse));
+// startPoint = endPoint;
+ startPoint = *coordinate;
+// trigger();
+ updateMouseButtonHints();
+ break;
+
+ default:
+ break;
+ }
+
+ DEBUG->print("ActionDrawPolyline::coordinateEvent: OK");
+}
+
void ActionDrawPolyline::updateMouseButtonHints()
{
switch (getStatus())
{
- case 0:
- DIALOGFACTORY->updateMouseWidget(tr("Click and drag to draw a line"), tr("Cancel"));
+ case SetFirstPoint:
+ DIALOGFACTORY->updateMouseWidget(tr("Set first point"), tr("Cancel"));
+ break;
+
+ case SetNextPoint:
+ DIALOGFACTORY->updateMouseWidget(tr("Set next point"), tr("Back"));
break;
default:
DIALOGFACTORY->requestToolBar(RS2::ToolBarPolylines);
}
+void ActionDrawPolyline::showOptions()
+{
+ DEBUG->print("ActionDrawPolyline::showOptions");
+ ActionInterface::showOptions();
+ DIALOGFACTORY->requestOptions(this, true);
+ DEBUG->print("ActionDrawPolyline::showOptions: OK");
+}
+
+void ActionDrawPolyline::hideOptions()
+{
+ ActionInterface::hideOptions();
+ DIALOGFACTORY->requestOptions(this, false);
+}
+
void ActionDrawPolyline::close()
{
#if 0