src/widgets \
src/forms
+DEPENDPATH = \
+ fparser \
+ dxflib/include \
+ src/mainapp \
+ src/actions \
+ src/base \
+ src/widgets \
+ src/forms
+
HEADERS = \
fparser/fparser.hh
// Who When What
// --- ---------- -----------------------------------------------------------
// JLH 06/03/2010 Added this text. :-)
+// JLH 09/17/2010 Fixed preview/snapper rendering.
//
#include "actiondrawarc.h"
container->addEntity(arc);
// upd. undo list:
- if (document != NULL)
+ if (document)
{
document->startUndoCycle();
document->addUndoable(arc);
document->endUndoCycle();
}
- deleteSnapper();
- graphicView->moveRelativeZero(Vector(0.0, 0.0));
- graphicView->drawEntity(arc);
graphicView->moveRelativeZero(arc->getCenter());
- drawSnapper();
-
+ graphicView->redraw(); //hm.
setStatus(SetCenter);
reset();
if (data.center.valid)
{
data.radius = data.center.distanceTo(mouse);
- deletePreview();
- clearPreview();
-// preview->addEntity(new Circle(preview, CircleData(data.center, data.radius)));
- drawPreview();
+ graphicView->preview.clear();
+ graphicView->preview.addEntity(new Circle(&(graphicView->preview), CircleData(data.center, data.radius)));
}
break;
else
data.angle2 = Math::correctAngle(data.angle1 + M_PI / 3);
- deletePreview();
- clearPreview();
-// preview->addEntity(new Arc(preview, data));
- drawPreview();
+ graphicView->preview.clear();
+ graphicView->preview.addEntity(new Arc(&(graphicView->preview), data));
break;
case SetAngle2:
data.angle2 = data.center.angleTo(mouse);
- deletePreview();
- clearPreview();
-// preview->addEntity(new Arc(preview, data));
- drawPreview();
+ graphicView->preview.clear();
+ graphicView->preview.addEntity(new Arc(&(graphicView->preview), data));
break;
case SetIncAngle:
data.angle2 = data.angle1 + data.center.angleTo(mouse);
- deletePreview();
- clearPreview();
-// preview->addEntity(new Arc(preview, data));
- drawPreview();
+ graphicView->preview.clear();
+ graphicView->preview.addEntity(new Arc(&(graphicView->preview), data));
break;
case SetChordLength:
if (fabs(x / (2 * data.radius)) <= 1.0)
{
data.angle2 = data.angle1 + asin(x / (2 * data.radius)) * 2;
- deletePreview();
- clearPreview();
-// preview->addEntity(new Arc(preview, data));
- drawPreview();
+ graphicView->preview.clear();
+ graphicView->preview.addEntity(new Arc(&(graphicView->preview), data));
}
}
- break;
+ break;
default:
break;
}
+ graphicView->redraw();
DEBUG->print("ActionDrawArc::mouseMoveEvent end");
}
}
else if (e->button() == Qt::RightButton)
{
- deletePreview();
- deleteSnapper();
+// deletePreview();
+// deleteSnapper();
init(getStatus() - 1);
+ graphicView->redraw(); //hm.
}
}
switch (getStatus())
{
- case SetRadius: {
+ case SetRadius:
+ {
bool ok;
double r = Math::eval(c, &ok);
- if (ok == true)
+ if (ok)
{
data.radius = r;
setStatus(SetAngle1);
}
- else if (DIALOGFACTORY != NULL)
+ else if (DIALOGFACTORY)
DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
-
}
- break;
+ break;
- case SetAngle1: {
+ case SetAngle1:
+ {
bool ok;
double a = Math::eval(c, &ok);
- if (ok == true)
+ if (ok)
{
data.angle1 = Math::deg2rad(a);
setStatus(SetAngle2);
}
- else if (DIALOGFACTORY != NULL)
+ else if (DIALOGFACTORY)
DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
-
}
- break;
+ break;
case SetAngle2:
bool ok;
double a = Math::eval(c, &ok);
- if (ok == true)
+ if (ok)
{
data.angle2 = Math::deg2rad(a);
trigger();
}
- else if (DIALOGFACTORY != NULL)
+ else if (DIALOGFACTORY)
DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
-
}
break;
- case SetIncAngle: {
+ case SetIncAngle:
+ {
bool ok;
double a = Math::eval(c, &ok);
- if (ok == true)
+ if (ok)
{
data.angle2 = data.angle1 + Math::deg2rad(a);
trigger();
}
- else if (DIALOGFACTORY != NULL)
+ else if (DIALOGFACTORY)
DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
-
}
- break;
+ break;
- case SetChordLength: {
+ case SetChordLength:
+ {
bool ok;
double l = Math::eval(c, &ok);
- if (ok == true)
+ if (ok)
{
if (fabs(l / (2 * data.radius)) <= 1.0)
{
data.angle2 = data.angle1 + asin(l / (2 * data.radius)) * 2;
trigger();
}
- else if (DIALOGFACTORY != NULL)
- DIALOGFACTORY->commandMessage(
- tr("Not a valid chord length"));
+ else if (DIALOGFACTORY)
+ DIALOGFACTORY->commandMessage(tr("Not a valid chord length"));
}
- else if (DIALOGFACTORY != NULL)
+ else if (DIALOGFACTORY)
DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
-
}
- break;
+ break;
default:
break;
void ActionDrawArc::updateMouseButtonHints()
{
- if (DIALOGFACTORY != NULL)
+ if (DIALOGFACTORY)
{
switch (getStatus())
{
// Who When What
// --- ---------- -----------------------------------------------------------
// JLH 06/03/2010 Added this text. :-)
+// JLH 09/17/2010 Fixed preview/snapper rendering.
//
#include "actiondrawarc3p.h"
container->addEntity(arc);
// upd. undo list:
- if (document != NULL)
+ if (document)
{
document->startUndoCycle();
document->addUndoable(arc);
document->endUndoCycle();
}
- deleteSnapper();
- graphicView->moveRelativeZero(Vector(0.0, 0.0));
- graphicView->drawEntity(arc);
+// deleteSnapper();
+// graphicView->moveRelativeZero(Vector(0.0, 0.0));
+// graphicView->drawEntity(arc);
graphicView->moveRelativeZero(arc->getEndpoint());
- drawSnapper();
-
+// drawSnapper();
+ graphicView->redraw();
setStatus(SetPoint1);
reset();
}
if (point1.valid && point2.valid && point3.valid)
{
Arc arc(NULL, data);
- bool suc = arc.createFrom3P(point1, point2, point3);
+ bool success = arc.createFrom3P(point1, point2, point3);
- if (suc)
+ if (success)
data = arc.getData();
}
}
// clearPreview();
// preview->addEntity(line);
// drawPreview();
+ graphicView->preview.clear();
+ graphicView->preview.addEntity(new Line(&(graphicView->preview), LineData(point1, point2)));
}
break;
// clearPreview();
// preview->addEntity(arc);
// drawPreview();
+ graphicView->preview.clear();
+ graphicView->preview.addEntity(new Arc(&(graphicView->preview), data));
}
break;
default:
break;
}
+
+ graphicView->redraw();
}
void ActionDrawArc3P::mouseReleaseEvent(QMouseEvent * e)
}
else if (e->button() == Qt::RightButton)
{
- deletePreview();
- deleteSnapper();
+// deletePreview();
+// deleteSnapper();
init(getStatus() - 1);
+ graphicView->redraw();
}
}
// Who When What
// --- ---------- -----------------------------------------------------------
// JLH 06/03/2010 Added this text. :-)
+// JLH 09/17/2010 Fixed preview/snapper rendering.
//
#include "actiondrawarctangential.h"
#include "graphicview.h"
#include "preview.h"
-ActionDrawArcTangential::ActionDrawArcTangential(EntityContainer & container, GraphicView & graphicView): ActionInterface("Draw arcs tangential",
- container, graphicView)
+ActionDrawArcTangential::ActionDrawArcTangential(EntityContainer & container, GraphicView & graphicView):
+ ActionInterface("Draw arcs tangential", container, graphicView)
{
reset();
}
container->addEntity(arc);
// upd. undo list:
- if (document != NULL)
+ if (document)
{
document->startUndoCycle();
document->addUndoable(arc);
document->endUndoCycle();
}
- deleteSnapper();
- graphicView->moveRelativeZero(Vector(0.0, 0.0));
- graphicView->drawEntity(arc);
+// deleteSnapper();
+// graphicView->moveRelativeZero(Vector(0.0, 0.0));
+// graphicView->drawEntity(arc);
graphicView->moveRelativeZero(arc->getCenter());
- drawSnapper();
-
+// drawSnapper();
+ graphicView->redraw(); //hm.
setStatus(SetBaseEntity);
reset();
}
void ActionDrawArcTangential::preparePreview()
{
- if (baseEntity != NULL && point.valid)
+ if (baseEntity && point.valid)
{
Vector startPoint;
double direction;
// clearPreview();
// preview->addEntity(arc);
// drawPreview();
+ graphicView->preview.clear();
+ graphicView->preview.addEntity(new Arc(&(graphicView->preview), data));
+ graphicView->redraw();
}
break;
Vector coord = graphicView->toGraph(e->x(), e->y());
Entity * entity = catchEntity(coord, RS2::ResolveAll);
- if (entity != NULL)
+ if (entity)
{
if (entity->isAtomic())
{
}
else if (e->button() == Qt::RightButton)
{
- deletePreview();
- deleteSnapper();
+// deletePreview();
+ // deleteSnapper();
init(getStatus() - 1);
+ graphicView->redraw(); //hm.
}
}
{
DEBUG->print("ActionDrawLine::ActionDrawLine");
reset();
- //hm.
-// graphicView.snapper.SetContainer(&container);
-// graphicView.snapper.SetGraphicView(&graphicView);
-// graphicView.snapper.SetVisible();
-// graphicView.preview.SetVisible();
DEBUG->print("ActionDrawLine::ActionDrawLine: OK");
+//printf("ActionDrawLine(): preview is%s visible, snapper is%s visible...\n", (graphicView.preview.Visible() ? "" : " NOT"), (graphicView.snapper.Visible() ? "" : " NOT"));
}
ActionDrawLine::~ActionDrawLine()
DEBUG->print("ActionDrawLine::mouseMoveEvent begin");
DEBUG->print("ActionDrawLine::mouseMoveEvent: snap point");
- Vector mouse = graphicView->snapper.snapPoint(e);
+// Vector mouse = graphicView->snapper.snapPoint(e);
+ Vector mouse = graphicView->SnapPoint(e);
DEBUG->print("ActionDrawLine::mouseMoveEvent: snap point: OK");
if (getStatus() == SetEndpoint && data.startpoint.valid)
#endif
}
+//OK, snapper & preview are set as NOT visible... why???
+//becuz other things are created in the meantime which turn this stuff off, treating
+//it like it isn't a shared resource which it is...
+//printf("ActionDrawLine::mouseMoveEvent(): preview is%s visible, snapper is%s visible...\n", (graphicView->preview.Visible() ? "" : " NOT"), (graphicView->snapper.Visible() ? "" : " NOT"));
//hm. [ok, this works. :-D]
graphicView->redraw();
DEBUG->print("ActionDrawLine::mouseMoveEvent end");
{
if (e->button() == Qt::LeftButton)
{
- Vector ce(graphicView->snapper.snapPoint(e));
+// Vector ce(graphicView->snapper.snapPoint(e));
+ Vector ce(graphicView->SnapPoint(e));
coordinateEvent(&ce);
}
else if (e->button() == Qt::RightButton)
{
-// if (getStatus() == 0)
-// {
-// graphicView->snapper.SetVisible(false);
-// graphicView->preview.SetVisible(false);
-// }
-
init(getStatus() - 1);
}
//hm. [Seems to work OK.]
- graphicView->preview.clear(); // Remove entities from container
- graphicView->redraw();
+ //shouldn't need this...
+// graphicView->preview.clear(); // Remove entities from container
+// graphicView->redraw();
}
void ActionDrawLine::coordinateEvent(Vector * e)
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()
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:
virtual RS2::ActionType rtti();
virtual void trigger();
- virtual void mouseMoveEvent(QMouseEvent * e);
- virtual void mousePressEvent(QMouseEvent * e);
- virtual void mouseReleaseEvent(QMouseEvent * e);
+ virtual void mouseMoveEvent(QMouseEvent *);
+ virtual void mousePressEvent(QMouseEvent *);
+ virtual void mouseReleaseEvent(QMouseEvent *);
+ virtual void coordinateEvent(Vector *);
virtual void updateMouseButtonHints();
virtual void updateMouseCursor();
virtual void updateToolBar();
protected:
Vector vertex;
+ Vector startPoint;
Polyline * polyline;
/** Start point of the series of lines. Used for close function. */
Vector start;
{
axisPoint2 = mouse;
- deletePreview();
- clearPreview();
+// deletePreview();
+// clearPreview();
/* preview->addSelectionFrom(*container);
preview->mirror(axisPoint1, axisPoint2);
preview->addEntity(new Line(preview,LineData(axisPoint1, axisPoint2)));*/
- drawPreview();
+// drawPreview();
+ graphicView->preview.clear();
+ graphicView->preview.addSelectionFrom(*container);
+ graphicView->preview.mirror(axisPoint1, axisPoint2);
+ graphicView->preview.addEntity(new Line(&(graphicView->preview), LineData(axisPoint1, axisPoint2)));
+ graphicView->redraw();
}
break;
default:
break;
}
+
+ graphicView->redraw();
}
DEBUG->print("ActionModifyMirror::mouseMoveEvent end");
}
else if (e->button() == Qt::RightButton)
{
- deletePreview();
- deleteSnapper();
+// deletePreview();
+// deleteSnapper();
init(getStatus() - 1);
+ graphicView->redraw(); //hm.
}
}
{
data.axisPoint1 = axisPoint1;
data.axisPoint2 = axisPoint2;
- deletePreview();
- clearPreview();
+// deletePreview();
+// clearPreview();
trigger();
finish();
+ graphicView->redraw(); //hm.
}
}
break;
break;*/
case SetAxisPoint1:
DIALOGFACTORY->updateMouseWidget(
- tr("Specify first point of mirror line"),
- tr("Cancel"));
+ tr("Specify first point of mirror line"), tr("Cancel"));
break;
case SetAxisPoint2:
DIALOGFACTORY->updateMouseWidget(
- tr("Specify second point of mirror line"),
- tr("Back"));
+ tr("Specify second point of mirror line"), tr("Back"));
break;
default:
void ActionModifyMirror::updateToolBar()
{
- if (DIALOGFACTORY != NULL)
+ if (DIALOGFACTORY)
{
switch (getStatus())
{
// Who When What
// --- ---------- -----------------------------------------------------------
// JLH 05/22/2010 Added this text. :-)
+// JLH 09/17/2010 Fixed preview/snapper rendering somewhat. Some bugs remain.
//
#include "actionmodifytrim.h"
* @param both Trim both entities.
*/
ActionModifyTrim::ActionModifyTrim(EntityContainer & container,
- GraphicView & graphicView, bool both): ActionInterface("Trim Entity",
- container, graphicView)
+ GraphicView & graphicView, bool b):
+ ActionInterface("Trim Entity", container, graphicView),
+ limitEntity(NULL), limitCoord(false), trimEntity(NULL), trimCoord(false),
+ both(b)
{
- trimEntity = NULL;
- trimCoord = Vector(false);
- limitEntity = NULL;
- limitCoord = Vector(false);
- this->both = both;
+// trimEntity = NULL;
+// trimCoord = Vector(false);
+// limitEntity = NULL;
+// limitCoord = Vector(false);
+// this->both = both;
}
ActionModifyTrim::~ActionModifyTrim()
if (trimEntity && trimEntity->isAtomic() && limitEntity)
{
Modification m(*container, graphicView);
- m.trim(trimCoord, (AtomicEntity *)trimEntity,
- limitCoord, limitEntity, both);
+ m.trim(trimCoord, (AtomicEntity *)trimEntity, limitCoord, limitEntity,
+ both);
trimEntity = NULL;
if (both)
{
limitEntity->setHighlighted(false);
- graphicView->drawEntity(limitEntity);
+// graphicView->drawEntity(limitEntity);
setStatus(ChooseLimitEntity);
+ graphicView->redraw(); //hm.
}
else
setStatus(ChooseTrimEntity);
if (limitEntity)
{
limitEntity->setHighlighted(true);
- graphicView->drawEntity(limitEntity);
+// graphicView->drawEntity(limitEntity);
setStatus(ChooseTrimEntity);
+ graphicView->redraw(); //hm.
}
break;
trimCoord = mouse;
trimEntity = se;
- if (trimEntity != NULL && trimEntity->isAtomic())
+ if (trimEntity && trimEntity->isAtomic())
trigger();
break;
}
else if (e->button() == Qt::RightButton)
{
- deletePreview();
- deleteSnapper();
+// deletePreview();
+// deleteSnapper();
- if (limitEntity != NULL)
+ if (limitEntity)
{
limitEntity->setHighlighted(false);
- graphicView->drawEntity(limitEntity);
+// graphicView->drawEntity(limitEntity);
}
+
init(getStatus() - 1);
+ graphicView->redraw(); //hm.
}
}
{
DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
}
-
delete polyline;
}
+/*virtual*/ RS2::ActionType ActionPolylineAdd::rtti()
+{
+ return RS2::ActionPolylineAdd;
+}
+
ActionPolylineAdd(EntityContainer & container, GraphicView & graphicView);
~ActionPolylineAdd();
+ virtual RS2::ActionType rtti();
// virtual void init(int status = 0);
// virtual void trigger();
// virtual void mouseMoveEvent(QMouseEvent * e);
delete polyline;
}
+/*virtual*/ RS2::ActionType ActionPolylineAppend::rtti()
+{
+ return RS2::ActionPolylineAppend;
+}
+
ActionPolylineAppend(EntityContainer & container, GraphicView & graphicView);
~ActionPolylineAppend();
+ virtual RS2::ActionType rtti();
// virtual void init(int status = 0);
// virtual void trigger();
// virtual void mouseMoveEvent(QMouseEvent * e);
delete polyline;
}
+/*virtual*/ RS2::ActionType ActionPolylineDel::rtti()
+{
+ return RS2::ActionPolylineDel;
+}
+
ActionPolylineDel(EntityContainer & container, GraphicView & graphicView);
~ActionPolylineDel();
+ virtual RS2::ActionType rtti();
// virtual void init(int status = 0);
// virtual void trigger();
// virtual void mouseMoveEvent(QMouseEvent * e);
delete polyline;
}
+/*virtual*/ RS2::ActionType ActionPolylineDelBetween::rtti()
+{
+ return RS2::ActionPolylineDelBetween;
+}
+
ActionPolylineDelBetween(EntityContainer & container, GraphicView & graphicView);
~ActionPolylineDelBetween();
+ virtual RS2::ActionType rtti();
// virtual void init(int status = 0);
// virtual void trigger();
// virtual void mouseMoveEvent(QMouseEvent * e);
delete polyline;
}
+/*virtual*/ RS2::ActionType ActionPolylineTrim::rtti()
+{
+ return RS2::ActionPolylineTrim;
+}
+
ActionPolylineTrim(EntityContainer & container, GraphicView & graphicView);
~ActionPolylineTrim();
+ virtual RS2::ActionType rtti();
// virtual void init(int status = 0);
// virtual void trigger();
// virtual void mouseMoveEvent(QMouseEvent * e);
#include "commands.h"
#include "debug.h"
+#include "dialogfactory.h"
#include "entitycontainer.h"
#include "graphicview.h"
+#include "grid.h"
+
+/*
+I think what's needed here is for the constructor to save the state of the snapper
+and to restore it in the destructor. This, of course, assumes that the actions are
+created and used in a certain order, perhaps that needs enforcement? Dunno, but worth
+a try as suspend() and resume() seem to fuck it up badly.
+*/
/**
* Constructor.
* note that an action belongs to this view.
*/
ActionInterface::ActionInterface(const char * name, EntityContainer & ec,
- GraphicView & gv): graphicView(&gv), container(&ec)
+ GraphicView & gv): graphicView(&gv), container(&ec),
+// snapperVisibility(false), previewVisibility(false), suspendCount(0)
+//hm.
+ snapperVisibility(true), previewVisibility(true), suspendCount(0)
{
DEBUG->print("ActionInterface::ActionInterface: Setting up action: \"%s\"", name);
// Document pointer will be used for undo / redo
document = ec.getDocument();
+ // \o/ \o/ \o/ BY GRABTHAR'S HAMMER, IT HAS BEEN EXPUNGED!!! \o/ \o/ \o/
// This is here until I can figure out a better way to contain all of this
// circular referential nonsense that exists in this codebase. It will be
// expunged, by Grabthar's Hammer!
- graphicView->snapper.SetContainer(container);
- graphicView->snapper.SetGraphicView(graphicView); // <-- THIS is what I mean! INSANE!
+// graphicView->snapper.SetContainer(container);
+// graphicView->snapper.SetGraphicView(graphicView); // <-- THIS is what I mean! INSANE!
// Not all actions use these. Perhaps we need to pass params to the contructor
// in order to set these? Setting the default to true for both?
- graphicView->snapper.SetVisible();
+// graphicView->snapper.SetVisible();
+ graphicView->SetSnapperVisible();
graphicView->preview.SetVisible();
DEBUG->print("ActionInterface::ActionInterface: Setting up action: \"%s\": OK", name);
+printf("ActionInterface::ActionInterface() [%08X]\n", this);
}
/**
// would be pure virtual now:
// hideOptions();
//JLH: Only it isn't pure virtual...
+printf("ActionInterface::~ActionInterface() [%08X]\n", this);
}
/**
}
else // status < 0, e.g. this action is finished
{
- graphicView->snapper.SetVisible(false);
+// graphicView->snapper.SetVisible(false);
+ graphicView->SetSnapperVisible(false);
graphicView->preview.SetVisible(false);
graphicView->preview.clear();
+ graphicView->redraw(); //hm.
}
}
* of progress and decreases when the user goes one
* step back (i.e. presses the right mouse button).
*/
-void ActionInterface::setStatus(int status)
+void ActionInterface::setStatus(int value)
{
- this->status = status;
+ status = value;
if (status < 0)
{
// Snapper::finish(); // Sets Snapper::finished = true
// I think this is where we want to update the screen...
// graphicView->redraw();
+ // hm.
+// graphicView->snapper.SetVisible(false);
+ graphicView->SetSnapperVisible(false);
+ graphicView->preview.SetVisible(false);
+// graphicView->preview.clear();
+ graphicView->redraw(); //hm.
DEBUG->print("ActionInterface::finish: OK");
}
predecessor = p;
}
+#if 0
+Here is a problem. suspend() and resume() don't do what they should:
+The problem is that Actions are modifying a shared resource though it's acting
+as if it were not. Case in point below: ActionZoomPan sets the snapper/preview
+visibility to FALSE and then EventHandler calls suspend() here, which queries
+the graphicView to see what its state is. We need to fix this...!
+
+This ties into the problem where we have GraphicView pointers scattered all
+over the place. We need to fix that too!
+#endif
/**
* Suspends this action while another action takes place.
*/
void ActionInterface::suspend()
{
+#if 0
+printf("ActionInterface::suspend(%i): [%08X] ", ++suspendCount, this);
// Maybe this is where we need to save the state of the snapper
// & preview objects???
// graphicView->setMouseCursor(RS2::ArrowCursor);
// Snapper::suspend();
+ snapperVisibility = graphicView->snapper.Visible();
+ previewVisibility = graphicView->preview.Visible();
+printf("snapperVisibility = %s, previewVisibility = %s...\n", (snapperVisibility ? "true" : "FALSE"), (previewVisibility ? "true" : "FALSE"));
+#endif
}
/**
*/
void ActionInterface::resume()
{
+#if 0
+if (suspendCount == 0)
+ printf("!!! RESUME BEFORE SUSPEND !!!\n");
+printf("ActionInterface::resume(%i): [%08X] ", suspendCount, this);
updateMouseCursor();
updateToolBar();
// Snapper::resume();
+ graphicView->snapper.SetVisible(snapperVisibility);
+ graphicView->preview.SetVisible(previewVisibility);
+printf("snapperVisibility = %s, previewVisibility = %s...\n", (snapperVisibility ? "true" : "FALSE"), (previewVisibility ? "true" : "FALSE"));
+#endif
}
/**
// this one. May go away in the future.
Vector ActionInterface::snapPoint(QMouseEvent * e)
{
- return graphicView->snapper.snapPoint(e);
+// return graphicView->snapper.snapPoint(e);
+ return graphicView->SnapPoint(e);
}
Entity * ActionInterface::catchEntity(QMouseEvent * e, RS2::ResolveLevel level/*= RS2::ResolveNone*/)
{
- return graphicView->snapper.catchEntity(e, level);
+ return graphicView->CatchEntity(e, level);
}
Entity * ActionInterface::catchEntity(Vector v, RS2::ResolveLevel level/*= RS2::ResolveNone*/)
{
- return graphicView->snapper.catchEntity(v, level);
+ return graphicView->CatchEntity(v, level);
}
#warning "!!! Dummy functions need to be deleted once all actions no longer use these !!!"
* corner (status 0), and selecting the second corner (status 1).
*/
int status;
+ bool snapperVisibility;
+ bool previewVisibility;
+ int suspendCount;
protected:
/** Action name. Used internally for debugging */
QString name;
-
/**
* This flag is set when the action has terminated and can be deleted.
*/
bool finished;
-
/**
* Pointer to the graphic is this container is a graphic. NULL otherwise
*/
Drawing * graphic;
-
/**
* Pointer to the document (graphic or block) or NULL.
*/
Document * document;
-
/**
* Predecessor of this action or NULL.
*/
ActionInterface * predecessor;
-
+ // hm.
GraphicView * graphicView;
EntityContainer * container;
};
{
DEBUG->print("EventHandler::~EventHandler");
- if (defaultAction != NULL)
+ if (defaultAction)
{
defaultAction->finish();
delete defaultAction;
}
}
+#if 0
+Small problem with this approach: Resumes can happen before suspend actions!
+This can wreak havoc with things like snapper/preview states and the like...
+
+Actually, this stuff seems to be pretty useless. Not sure what is accomplished
+by this crap. The only thing I can think of is that it would cause a preview
+to be removed if the mouse goes out of the drawing window, could be a legit
+purpose but this seems too retarded for that. Why wouldn't you just code that
+into GraphicView itself and be done with it?
+#endif
/**
* Called by GraphicView
*/
void EventHandler::mouseLeaveEvent()
{
+#if 0
if (actionIndex >= 0 && currentActions[actionIndex]
&& !currentActions[actionIndex]->isFinished())
{
defaultAction->suspend();
//DEBUG->print("currently no action defined");
}
+#endif
}
/**
*/
void EventHandler::mouseEnterEvent()
{
+#if 0
if (actionIndex >= 0 && currentActions[actionIndex]
&& !currentActions[actionIndex]->isFinished())
{
if (defaultAction)
defaultAction->resume();
}
+#endif
}
/**
{
DEBUG->print("EventHandler::cleanUp");
- int o = 0; // old index
- int n = 0; // new index
+ int oldIndex = 0; // old index
+ int newIndex = 0; // new index
int resume = 0; // index of action to resume
bool doResume = false; // do we need to resume an action
actionIndex = -1;
do
{
- // search first used action (o)
- while (currentActions[o] == NULL && o < RS_MAXACTIONS)
- o++;
+ // Search first used action (oldIndex)
+ while (currentActions[oldIndex] == NULL && oldIndex < RS_MAXACTIONS)
+ oldIndex++;
- // delete action if it is finished
- if (o < RS_MAXACTIONS && currentActions[o] != NULL
- && currentActions[o]->isFinished())
+ // Delete action if it is finished
+ if (oldIndex < RS_MAXACTIONS && currentActions[oldIndex] != NULL
+ && currentActions[oldIndex]->isFinished())
{
- delete currentActions[o];
- currentActions[o] = NULL;
+ delete currentActions[oldIndex];
+ currentActions[oldIndex] = NULL;
doResume = true;
}
- // move a running action up in the stack
- if (o < RS_MAXACTIONS && currentActions[o] != NULL)
+ // Move a running action up in the stack
+ if (oldIndex < RS_MAXACTIONS && currentActions[oldIndex] != NULL)
{
- if (n != o)
+ if (newIndex != oldIndex)
{
- currentActions[n] = currentActions[o];
- resume = n;
- currentActions[o] = NULL;
+ currentActions[newIndex] = currentActions[oldIndex];
+ resume = newIndex;
+ currentActions[oldIndex] = NULL;
}
else
{
- if (o < RS_MAXACTIONS)
- o++;
+ if (oldIndex < RS_MAXACTIONS)
+ oldIndex++;
}
- actionIndex = n;
+ actionIndex = newIndex;
- if (n < RS_MAXACTIONS - 1)
- n++;
+ if (newIndex < RS_MAXACTIONS - 1)
+ newIndex++;
}
}
- while (o < RS_MAXACTIONS);
+ while (oldIndex < RS_MAXACTIONS);
debugActions();
// Who When What
// --- ---------- -----------------------------------------------------------
// JLH 05/21/2010 Added this text. :-)
+// JLH 10/18/2010 Commented out all functions in preparation for deprecating
+// this class.
//
#include "snapper.h"
Snapper::Snapper(EntityContainer & c, GraphicView & gv):
container(&c), graphicView(&gv), finished(false)
{
+#if 0
init();
+#endif
}
Snapper::Snapper(void):
container(NULL), graphicView(NULL), finished(false)
{
+#if 0
init();
+#endif
}
/**
*/
void Snapper::init()
{
+#if 0
if (graphicView)
{
snapMode = graphicView->getDefaultSnapMode();
// Sanity check
if (snapRange < 2)
snapRange = 20;
+#endif
}
void Snapper::finish()
{
+#if 0
finished = true;
+#endif
}
//bleh
void Snapper::SetContainer(EntityContainer * c)
{
+#if 0
container = c;
+#endif
}
//bleh
void Snapper::SetGraphicView(GraphicView * v)
{
+#if 0
graphicView = v;
+#endif
}
/**
* @return Pointer to the entity which was the key entity for the last
* successful snapping action. If the snap mode is "end point" the key entity
- * is the entity whos end point was caught. If the snap mode didn't require an
+ * is the entity whose end point was caught. If the snap mode didn't require an
* entity (e.g. free, grid) this method will return NULL.
*/
Entity * Snapper::getKeyEntity()
{
+#if 0
return keyEntity;
+#endif
+ return NULL;
}
/** Sets a new snap mode. */
void Snapper::setSnapMode(RS2::SnapMode snapMode)
{
+#if 0
this->snapMode = snapMode;
+#endif
}
/** Sets a new snap restriction. */
void Snapper::setSnapRestriction(RS2::SnapRestriction snapRes)
{
+#if 0
this->snapRes = snapRes;
+#endif
}
RS2::SnapMode Snapper::getSnapMode(void)
{
+#if 0
return snapMode;
+#endif
+ return RS2::SnapFree;
}
RS2::SnapRestriction Snapper::getSnapRestriction(void)
{
+#if 0
return snapRes;
+#endif
+ return RS2::RestrictNothing;
}
/**
*/
void Snapper::setSnapRange(int r)
{
+#if 0
snapRange = r;
+#endif
}
+#if 0
+This should get moved into GraphicView...
+#endif
/**
* Snap to a coordinate in the drawing using the current snap mode.
*
*/
Vector Snapper::snapPoint(QMouseEvent * e)
{
+#if 0
DEBUG->print("Snapper::snapPoint");
snapSpot = Vector(false);
DEBUG->print("Snapper::snapPoint: OK");
return snapCoord;
+#endif
+ return Vector(false);
}
/**
*/
Vector Snapper::snapFree(Vector coord)
{
+#if 0
keyEntity = NULL;
return coord;
+#endif
+ return Vector(false);
}
/**
*/
Vector Snapper::snapEndpoint(Vector coord)
{
+#if 0
Vector vec(false);
vec = container->getNearestEndpoint(coord, NULL);
return vec;
+#endif
+ return Vector(false);
}
/**
*/
Vector Snapper::snapGrid(Vector coord)
{
+#if 0
DEBUG->print("Snapper::snapGrid begin");
Vector vec(false);
DEBUG->print("Snapper::snapGrid end");
return vec;
+#endif
+ return Vector(false);
}
/**
*/
Vector Snapper::snapOnEntity(Vector coord)
{
+#if 0
Vector vec(false);
vec = container->getNearestPointOnEntity(coord, true, NULL, &keyEntity);
return vec;
+#endif
+ return Vector(false);
}
/**
*/
Vector Snapper::snapCenter(Vector coord)
{
+#if 0
Vector vec(false);
vec = container->getNearestCenter(coord, NULL);
return vec;
+#endif
+ return Vector(false);
}
/**
*/
Vector Snapper::snapMiddle(Vector coord)
{
+#if 0
Vector vec(false);
vec = container->getNearestMiddle(coord, NULL);
return vec;
+#endif
+ return Vector(false);
}
/**
*/
Vector Snapper::snapDist(Vector coord)
{
+#if 0
Vector vec(false);
vec = container->getNearestDist(distance, coord, NULL);
return vec;
+#endif
+ return Vector(false);
}
/**
*/
Vector Snapper::snapIntersection(Vector coord)
{
+#if 0
Vector vec(false);
vec = container->getNearestIntersection(coord, NULL);
return vec;
+#endif
+ return Vector(false);
}
/**
*/
Vector Snapper::restrictOrthogonal(Vector coord)
{
+#if 0
Vector rz = graphicView->getRelativeZero();
Vector ret(coord);
ret = retx;
return ret;
+#endif
+ return Vector(false);
}
/**
*/
Vector Snapper::restrictHorizontal(Vector coord)
{
+#if 0
Vector rz = graphicView->getRelativeZero();
return Vector(coord.x, rz.y);
+#endif
+ return Vector(false);
}
/**
*/
Vector Snapper::restrictVertical(Vector coord)
{
+#if 0
Vector rz = graphicView->getRelativeZero();
return Vector(rz.x, coord.y);
+#endif
+ return Vector(false);
}
/**
*/
Entity * Snapper::catchEntity(const Vector & pos, RS2::ResolveLevel level)
{
+#if 0
DEBUG->print("Snapper::catchEntity");
- // set default distance for points inside solids
+ // Set default distance for points inside solids
double dist = graphicView->toGraphDX(snapRange) * 0.9;
-
Entity * entity = container->getNearestEntity(pos, &dist, level);
-
int idx = -1;
if (entity && entity->getParent())
if (entity && dist <= graphicView->toGraphDX(snapRange))
{
- // highlight:
+ // Highlight:
DEBUG->print("Snapper::catchEntity: found: %d", idx);
return entity;
}
- else
- {
- DEBUG->print("Snapper::catchEntity: not found");
- return NULL;
- }
+// else
+// {
+ DEBUG->print("Snapper::catchEntity: not found");
+ return NULL;
+// }
- DEBUG->print("Snapper::catchEntity: OK");
+// DEBUG->print("Snapper::catchEntity: OK");
+#endif
+ return NULL;
}
/**
*/
Entity * Snapper::catchEntity(QMouseEvent * e, RS2::ResolveLevel level)
{
- return catchEntity(Vector(graphicView->toGraphX(e->x()),
+#if 0
+ return catchEntity(Vector(graphicView->toGraphX(e->x()),
graphicView->toGraphY(e->y())), level);
+#endif
+ return NULL;
}
+#if 0
+I think that these suspend() & resume() functions are not used anymore...
+#endif
/**
* Suspends this snapper while another action takes place.
*/
/*virtual*/ void Snapper::suspend()
{
+#if 0
#warning "!!! This may need to have SetVisibility() called !!!"
// deleteSnapper();
snapSpot = snapCoord = Vector(false);
+#endif
}
/**
*/
/*virtual*/ void Snapper::resume()
{
+#if 0
#warning "!!! This may need to have SetVisibility() called !!!"
// drawSnapper();
+#endif
}
/**
*/
/*virtual*/ void Snapper::hideOptions()
{
+#if 0
if (snapMode == RS2::SnapDist && DIALOGFACTORY)
DIALOGFACTORY->requestSnapDistOptions(distance, false);
+#endif
}
/**
*/
/*virtual*/ void Snapper::showOptions()
{
+#if 0
if (snapMode == RS2::SnapDist && DIALOGFACTORY)
DIALOGFACTORY->requestSnapDistOptions(distance, true);
+#endif
}
void Snapper::SetVisible(bool visibility/*= true*/)
{
+#if 0
visible = visibility;
+#endif
}
bool Snapper::Visible(void)
{
+#if 0
return visible;
+#endif
}
/*
*/
void Snapper::Draw(GraphicView * view, PaintInterface * painter)
{
+#if 0
if (finished || !snapSpot.valid || !snapCoord.valid)
return;
//hm, I don't like graphicView kicking around in here, especially since it now
//lives inside GraphicView... How to !!! FIX !!!?
//We'll pass it in for now...
-// if (snapCoord.valid)
-// {
// Snap point (need to make sure the brush is NULL!)
// painter->setPen(Pen(Color(0, 127, 255), RS2::Width00, RS2::DashLine));
painter->setPen(Pen(Color(255, 127, 0), RS2::Width00, RS2::DashLine));
painter->drawLine(Vector(view->toGuiX(snapCoord.x), 0),
Vector(view->toGuiX(snapCoord.x), view->getHeight()));
}
-// }
- if (/*snapCoord.valid &&*/ snapCoord != snapSpot)
+ if (snapCoord != snapSpot)
{
painter->drawLine(view->toGui(snapSpot) + Vector(-5, 0),
view->toGui(snapSpot) + Vector(-1, 4));
painter->drawLine(view->toGui(snapSpot) + Vector(0, -5),
view->toGui(snapSpot) + Vector(-4, -1));
}
+#endif
}
PolylineOptions::PolylineOptions(QToolBar * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
QWidget(parent, flags), action(NULL),
- bClose(new QToolButton(this)),
- bUndo(new QToolButton(this))
+ closeButton(new QToolButton(this)),
+ undoButton(new QToolButton(this)),
+ arcCheckBox(new QCheckBox(this)),
+ radiusLabel(new QLabel(this)),
+ radiusEdit(new QLineEdit(this))
{
QHBoxLayout * layout = new QHBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
- bClose->setText(tr("Close"));
- bUndo->setText(tr("Undo"));
+ closeButton->setText(tr("Close"));
+ undoButton->setText(tr("Undo"));
+ arcCheckBox->setText(tr("Arc"));
+ radiusLabel->setText(tr("Radius:"));
- layout->addWidget(bClose);
- layout->addWidget(bUndo);
+ layout->addWidget(closeButton);
+ layout->addWidget(undoButton);
+ layout->addWidget(arcCheckBox);
+ layout->addWidget(radiusLabel);
+ layout->addWidget(radiusEdit);
- connect(bClose, SIGNAL(clicked()), this, SLOT(close()));
- connect(bUndo, SIGNAL(clicked()), this, SLOT(undo()));
+ connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
+ connect(undoButton, SIGNAL(clicked()), this, SLOT(undo()));
// We need to add the widget (this thing) to the toolbar passed in. Otherwise,
// nothing will show up on the screen. :-)
ActionDrawPolyline * action;
private:
- QToolButton * bClose;
- QToolButton * bUndo;
+ QToolButton * closeButton;
+ QToolButton * undoButton;
+ QCheckBox * arcCheckBox;
+ QLabel * radiusLabel;
+ QLineEdit * radiusEdit;
};
#endif // __POLYLINEOPTIONS_H__
simulationSmooth = false;
simulationRapid = false;
simulationRunning = false;
+
+ // Snapper settings...
+ snapEntity = NULL;
+ snapSpot = Vector(false);
+ snapCoord = Vector(false);
+ snapperVisible = false;
+ snapDistance = 1.0;
+
+ settings.beginGroup("Snap");
+ snapRange = settings.value("Range", 20).toInt();
+ settings.endGroup();
+ settings.beginGroup("Appearance");
+ showCrosshairs = settings.value("ShowCrosshairs", true).toBool();
+ settings.endGroup();
+
+ // Sanity check for snapRange
+ if (snapRange < 2)
+ snapRange = 20;
}
/**
x1 = toGuiX(l->getStartpoint().x);
x2 = toGuiX(l->getEndpoint().x);
- if (x1 > 0.0 && x1 < (double)getWidth() || x2 > 0.0 && x2 < (double)getWidth())
+ if ((x1 > 0.0 && x1 < (double)getWidth())
+ || (x2 > 0.0 && x2 < (double)getWidth()))
{
minY = std::min(minY, l->getStartpoint().y);
minY = std::min(minY, l->getEndpoint().y);
/**
* Draws the entities. If painter is NULL a new painter will
- * be created and destroyed.
+ * be created and destroyed. [NB: Not any more, we don't let the programmer try
+ * to outsmart the toolkit anymore. :-P
*/
void GraphicView::drawIt()
{
{
return simulationRapid;
}
+
+/**
+ * Catches an entity which is close to the given position 'pos'.
+ *
+ * @param pos A graphic coordinate.
+ * @param level The level of resolving for iterating through the entity
+ * container
+ * @return Pointer to the entity or NULL.
+ */
+Entity * GraphicView::CatchEntity(const Vector & pos, RS2::ResolveLevel level)
+{
+ DEBUG->print("GraphicView::CatchEntity");
+
+ // Set default distance for points inside solids
+ double dist = toGraphDX(snapRange) * 0.9;
+ Entity * entity = container->getNearestEntity(pos, &dist, level);
+
+ // DEBUGGING INFO
+ int idx = -1;
+
+ if (entity && entity->getParent())
+ idx = entity->getParent()->findEntity(entity);
+ // END DEBUGGING INFO
+
+ if (entity && dist <= toGraphDX(snapRange))
+ {
+ // Highlight:
+ DEBUG->print("GraphicView::CatchEntity: found: idx=%d", idx);
+ return entity;
+ }
+
+ DEBUG->print("GraphicView::CatchEntity: not found");
+ return NULL;
+}
+
+/**
+ * Catches an entity which is close to the mouse cursor.
+ *
+ * @param e A mouse event.
+ * @param level The level of resolving for iterating through the entity
+ * container
+ * @return Pointer to the entity or NULL.
+ */
+Entity * GraphicView::CatchEntity(QMouseEvent * e, RS2::ResolveLevel level)
+{
+ return CatchEntity(Vector(toGraphX(e->x()), toGraphY(e->y())), level);
+}
+
+/**
+ * Snap to a coordinate in the drawing using the current snap mode.
+ *
+ * @param e A mouse event.
+ * @return The coordinates of the point or an invalid vector.
+ */
+Vector GraphicView::SnapPoint(QMouseEvent * e)
+{
+ DEBUG->print("GraphicView::SnapPoint");
+ /*Vector*/ snapSpot = Vector(false);
+
+ if (!e)
+ {
+ DEBUG->print(Debug::D_WARNING, "GraphicView::SnapPoint: QMouseEvent is NULL");
+ return snapSpot;
+ }
+
+ Vector mouseCoord = toGraph(e->x(), e->y());
+
+// switch (snapMode)
+ switch (defaultSnapMode)
+ {
+ case RS2::SnapFree:
+// snapSpot = snapFree(mouseCoord);
+ snapEntity = NULL;
+ snapSpot = mouseCoord;
+ break;
+
+ case RS2::SnapEndpoint:
+// snapSpot = snapEndpoint(mouseCoord);
+ snapSpot = container->getNearestEndpoint(mouseCoord, NULL);
+ break;
+
+ case RS2::SnapGrid:
+ snapSpot = SnapGrid(mouseCoord);
+ break;
+
+ case RS2::SnapOnEntity:
+// snapSpot = snapOnEntity(mouseCoord);
+ snapSpot = container->getNearestPointOnEntity(mouseCoord, true, NULL, &snapEntity);
+ break;
+
+ case RS2::SnapCenter:
+// snapSpot = snapCenter(mouseCoord);
+ snapSpot = container->getNearestCenter(mouseCoord, NULL);
+ break;
+
+ case RS2::SnapMiddle:
+// snapSpot = snapMiddle(mouseCoord);
+ snapSpot = container->getNearestMiddle(mouseCoord, NULL);
+ break;
+
+ case RS2::SnapDist:
+// snapSpot = snapDist(mouseCoord);
+ snapSpot = container->getNearestDist(snapDistance, mouseCoord, NULL);
+ break;
+
+ case RS2::SnapIntersection:
+// snapSpot = snapIntersection(mouseCoord);
+ snapSpot = container->getNearestIntersection(mouseCoord, NULL);
+ break;
+
+ default:
+ break;
+ }
+
+ // This is declared here because I really, really hate extraneous braces in
+ // my switch statements. :-P
+ Vector relZero = getRelativeZero();
+ Vector restrictX = Vector(relZero.x, snapSpot.y);
+ Vector restrictY = Vector(snapSpot.x, relZero.y);
+// Vector snapCoord;
+ // Handle snap restrictions that can be activated in addition to the ones above:
+// switch (snapRes)
+ switch (defaultSnapRes)
+ {
+ case RS2::RestrictOrthogonal:
+//// snapCoord = restrictOrthogonal(snapSpot);
+// rz = graphicView->getRelativeZero();
+// retx = Vector(rz.x, snapSpot.y);
+// rety = Vector(snapSpot.x, rz.y);
+ snapCoord = (restrictX.distanceTo(snapSpot) < restrictY.distanceTo(snapSpot) ?
+ restrictX : restrictY);
+ break;
+ case RS2::RestrictHorizontal:
+//// snapCoord = restrictHorizontal(snapSpot);
+// rz = graphicView->getRelativeZero();
+// snapCoord = Vector(snapSpot.x, rz.y);
+ snapCoord = restrictY;
+ break;
+ case RS2::RestrictVertical:
+//// snapCoord = restrictVertical(snapSpot);
+// rz = graphicView->getRelativeZero();
+// snapCoord = Vector(rz.x, snapSpot.y);
+ snapCoord = restrictX;
+ break;
+ default:
+ case RS2::RestrictNothing:
+ snapCoord = snapSpot;
+ break;
+ }
+
+ if (DIALOGFACTORY)
+ DIALOGFACTORY->updateCoordinateWidget(snapCoord, snapCoord - relZero);
+
+ DEBUG->print("GraphicView::SnapPoint: OK");
+
+ return snapCoord;
+}
+
+/**
+ * Snaps to a grid point.
+ *
+ * @param coord The mouse coordinate.
+ * @return The coordinates of the point or an invalid vector.
+ */
+Vector GraphicView::SnapGrid(Vector coord)
+{
+ DEBUG->print("GraphicView::snapGrid begin");
+
+ Vector vec(false);
+ double dist = 0.0;
+
+ DEBUG->print("GraphicView::snapGrid 001");
+
+ if (grid)
+ {
+ DEBUG->print("GraphicView::snapGrid 002");
+ Vector * pts = grid->getPoints();
+ DEBUG->print("GraphicView::snapGrid 003");
+ int closest = -1;
+ dist = 32000.00;
+ DEBUG->print("GraphicView::snapGrid 004");
+
+ for(int i=0; i<grid->count(); ++i)
+ {
+ double d = pts[i].distanceTo(coord);
+
+ if (d < dist)
+ {
+ closest = i;
+ dist = d;
+ }
+ }
+
+ DEBUG->print("GraphicView::snapGrid 005");
+
+ if (closest >= 0)
+ vec = pts[closest];
+
+ DEBUG->print("GraphicView::snapGrid 006");
+ }
+
+ snapEntity = NULL;
+
+ DEBUG->print("GraphicView::snapGrid end");
+
+ return vec;
+}
+
+void GraphicView::DrawSnapper(PaintInterface * painter)
+{
+//Is "finished" used at all? Seems it's used only in ActionInterface, and it's commented out
+// if (finished || !snapSpot.valid || !snapCoord.valid)
+ if (!snapSpot.valid || !snapCoord.valid)
+#if 1
+{
+printf("DrawSnapper: snapSpot=%s, snapCoord=%s...\n", (snapSpot.valid ? "valid" : "INVALID"), (snapCoord.valid ? "valid" : "INVALID"));
+#endif
+ return;
+#if 1
+}
+#endif
+
+ // Snap point (need to make sure the brush is NULL!)
+// painter->setPen(Pen(Color(0, 127, 255), RS2::Width00, RS2::DashLine));
+ painter->setPen(Pen(Color(255, 127, 0), RS2::Width00, RS2::DashLine));
+ painter->drawCircle(toGui(snapCoord), 4);
+
+ // Crosshairs
+ if (showCrosshairs)
+ {
+ painter->setPen(Pen(Color(0, 255, 255), RS2::Width00, RS2::DashLine));
+ painter->drawLine(Vector(0, toGuiY(snapCoord.y)),
+ Vector(getWidth(), toGuiY(snapCoord.y)));
+ painter->drawLine(Vector(toGuiX(snapCoord.x), 0),
+ Vector(toGuiX(snapCoord.x), getHeight()));
+ }
+
+ // Cursor
+ if (snapCoord != snapSpot)
+ {
+ painter->drawLine(toGui(snapSpot) + Vector(-5, 0), toGui(snapSpot) + Vector(-1, 4));
+ painter->drawLine(toGui(snapSpot) + Vector(0, 5), toGui(snapSpot) + Vector(4, 1));
+ painter->drawLine(toGui(snapSpot) + Vector(5, 0), toGui(snapSpot) + Vector(1, -4));
+ painter->drawLine(toGui(snapSpot) + Vector(0, -5), toGui(snapSpot) + Vector(-4, -1));
+ }
+}
+
+void GraphicView::SetSnapperVisible(bool visibility/*= true*/)
+{
+ snapperVisible = visibility;
+}
+
+bool GraphicView::SnapperVisible(void)
+{
+ return snapperVisible;
+}
+
+#if 0
+/*
+only place this is called is in ActionInterface. And its only function is to
+have it not drawn anymore. But, the GraphicView seems to draw it anyway... So
+some other approach is needed...
+*/
+void Snapper::finish()
+{
+ finished = true;
+}
+
+/**
+ * @return Pointer to the entity which was the key entity for the last
+ * successful snapping action. If the snap mode is "end point" the key entity
+ * is the entity whose end point was caught. If the snap mode didn't require an
+ * entity (e.g. free, grid) this method will return NULL.
+ */
+Entity * Snapper::getKeyEntity()
+{
+ return keyEntity;
+}
+
+/** Sets a new snap mode. */
+void Snapper::setSnapMode(RS2::SnapMode snapMode)
+{
+ this->snapMode = snapMode;
+}
+
+/** Sets a new snap restriction. */
+void Snapper::setSnapRestriction(RS2::SnapRestriction snapRes)
+{
+ this->snapRes = snapRes;
+}
+
+RS2::SnapMode Snapper::getSnapMode(void)
+{
+ return snapMode;
+}
+
+RS2::SnapRestriction Snapper::getSnapRestriction(void)
+{
+ return snapRes;
+}
+
+/**
+ * Sets the snap range in pixels for catchEntity().
+ *
+ * @see catchEntity()
+ */
+void Snapper::setSnapRange(int r)
+{
+ snapRange = r;
+}
+
+#if 0
+I think that these suspend() & resume() functions are not used anymore...
+#endif
+/**
+ * Suspends this snapper while another action takes place.
+ */
+/*virtual*/ void Snapper::suspend()
+{
+#warning "!!! This may need to have SetVisibility() called !!!"
+// deleteSnapper();
+ snapSpot = snapCoord = Vector(false);
+}
+
+/**
+ * Resumes this snapper after it has been suspended.
+ */
+/*virtual*/ void Snapper::resume()
+{
+#warning "!!! This may need to have SetVisibility() called !!!"
+// drawSnapper();
+}
+
+/**
+ * Hides the snapper options.
+ */
+/*virtual*/ void Snapper::hideOptions()
+{
+ if (snapMode == RS2::SnapDist && DIALOGFACTORY)
+ DIALOGFACTORY->requestSnapDistOptions(distance, false);
+}
+
+/**
+ * Shows the snapper options.
+ */
+/*virtual*/ void Snapper::showOptions()
+{
+ if (snapMode == RS2::SnapDist && DIALOGFACTORY)
+ DIALOGFACTORY->requestSnapDistOptions(distance, true);
+}
+#endif
void setSimulationRapid(bool r);
bool getSimulationRapid();
+ Entity * CatchEntity(const Vector &, RS2::ResolveLevel level = RS2::ResolveNone);
+ Entity * CatchEntity(QMouseEvent *, RS2::ResolveLevel level = RS2::ResolveNone);
+ Vector SnapPoint(QMouseEvent *);
+ Vector SnapGrid(Vector);
+ void DrawSnapper(PaintInterface *);
+ void SetSnapperVisible(bool visibility = true);
+ bool SnapperVisible(void);
+
protected:
EntityContainer * container;
EventHandler * eventHandler;
int mx; //!< Last known mouse cursor position
int my; //!< Last known mouse cursor position
PaintInterface * painter;
- Color background; //! background color (any color)
- Color foreground; //! foreground color (black or white)
+ Color background; //! background color (any color)
+ Color foreground; //! foreground color (black or white)
Color gridColor; //! grid color
Color metaGridColor; //! meta grid color
Color selectedColor; //! selected color
- Color highlightedColor; //! highlighted color
+ Color highlightedColor; //! highlighted color
Grid * grid; //! Grid
/**
* Current default snap mode for this graphic view. Used for new
*/
RS2::SnapRestriction defaultSnapRes;
RS2::DrawingMode drawingMode;
-
/**
* Delete mode. If true, all drawing actions will delete in background color
* instead.
*/
bool deleteMode;
bool simulationRunning; //! If true, the simulation is currectly running
+ double snapDistance; //! Manually set snap distance
+ Entity * snapEntity; //! Entity to snap to (if any)
+ Vector snapSpot;
+ Vector snapCoord;
+ bool snapperVisible; //! Snapper visibility
+ int snapRange;
+ bool showCrosshairs; //! Snapper crosshair visibility
private:
int updateEnabled;
// Draw the snapper first, because we want to be able to see the preview on
// top of this...
- if (snapper.Visible())
- snapper.Draw(this, painter);
+// if (snapper.Visible())
+// snapper.Draw(this, painter);
+ // Actually, this code can go into drawIt() instead of here...
+ if (snapperVisible)
+ DrawSnapper(painter);
if (preview.Visible())
preview.Draw(this, painter);