From 92c8661cef41f1109908bf645c0a171e34680183 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Tue, 19 Oct 2010 03:36:43 +0000 Subject: [PATCH] In the middle of removing Snapper class/fixing snapper rendering... --- architektonas.pro | 9 + src/actions/actiondrawarc.cpp | 99 +++--- src/actions/actiondrawarc3p.cpp | 28 +- src/actions/actiondrawarctangential.cpp | 29 +- src/actions/actiondrawline.cpp | 27 +- src/actions/actiondrawpolyline.cpp | 146 ++++++++- src/actions/actiondrawpolyline.h | 8 +- src/actions/actionmodifymirror.cpp | 31 +- src/actions/actionmodifytrim.cpp | 40 ++- src/actions/actionpolylineadd.cpp | 5 + src/actions/actionpolylineadd.h | 1 + src/actions/actionpolylineappend.cpp | 5 + src/actions/actionpolylineappend.h | 1 + src/actions/actionpolylinedel.cpp | 5 + src/actions/actionpolylinedel.h | 1 + src/actions/actionpolylinedelbetween.cpp | 5 + src/actions/actionpolylinedelbetween.h | 1 + src/actions/actionpolylinetrim.cpp | 5 + src/actions/actionpolylinetrim.h | 1 + src/base/actioninterface.cpp | 69 ++++- src/base/actioninterface.h | 9 +- src/base/eventhandler.cpp | 60 ++-- src/base/snapper.cpp | 118 ++++++- src/forms/polylineoptions.cpp | 24 +- src/forms/polylineoptions.h | 7 +- src/mainapp/graphicview.cpp | 375 ++++++++++++++++++++++- src/mainapp/graphicview.h | 22 +- src/widgets/qg_graphicview.cpp | 7 +- 28 files changed, 928 insertions(+), 210 deletions(-) diff --git a/architektonas.pro b/architektonas.pro index 417a853..a4c73df 100644 --- a/architektonas.pro +++ b/architektonas.pro @@ -27,6 +27,15 @@ INCLUDEPATH += \ src/widgets \ src/forms +DEPENDPATH = \ + fparser \ + dxflib/include \ + src/mainapp \ + src/actions \ + src/base \ + src/widgets \ + src/forms + HEADERS = \ fparser/fparser.hh diff --git a/src/actions/actiondrawarc.cpp b/src/actions/actiondrawarc.cpp index a833e58..3a92e6f 100644 --- a/src/actions/actiondrawarc.cpp +++ b/src/actions/actiondrawarc.cpp @@ -12,6 +12,7 @@ // Who When What // --- ---------- ----------------------------------------------------------- // JLH 06/03/2010 Added this text. :-) +// JLH 09/17/2010 Fixed preview/snapper rendering. // #include "actiondrawarc.h" @@ -62,19 +63,15 @@ void ActionDrawArc::trigger() 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(); @@ -97,10 +94,8 @@ void ActionDrawArc::mouseMoveEvent(QMouseEvent * e) 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; @@ -112,26 +107,20 @@ void ActionDrawArc::mouseMoveEvent(QMouseEvent * e) 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: @@ -141,18 +130,17 @@ void ActionDrawArc::mouseMoveEvent(QMouseEvent * e) 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"); } @@ -165,9 +153,10 @@ void ActionDrawArc::mouseReleaseEvent(QMouseEvent * e) } else if (e->button() == Qt::RightButton) { - deletePreview(); - deleteSnapper(); +// deletePreview(); +// deleteSnapper(); init(getStatus() - 1); + graphicView->redraw(); //hm. } } @@ -251,35 +240,35 @@ void ActionDrawArc::commandEvent(CommandEvent * e) 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: @@ -292,53 +281,51 @@ void ActionDrawArc::commandEvent(CommandEvent * e) 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; @@ -354,7 +341,7 @@ QStringList ActionDrawArc::getAvailableCommands() void ActionDrawArc::updateMouseButtonHints() { - if (DIALOGFACTORY != NULL) + if (DIALOGFACTORY) { switch (getStatus()) { diff --git a/src/actions/actiondrawarc3p.cpp b/src/actions/actiondrawarc3p.cpp index 77ed90f..46eeb37 100644 --- a/src/actions/actiondrawarc3p.cpp +++ b/src/actions/actiondrawarc3p.cpp @@ -12,6 +12,7 @@ // Who When What // --- ---------- ----------------------------------------------------------- // JLH 06/03/2010 Added this text. :-) +// JLH 09/17/2010 Fixed preview/snapper rendering. // #include "actiondrawarc3p.h" @@ -61,19 +62,19 @@ void ActionDrawArc3P::trigger() 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(); } @@ -88,9 +89,9 @@ void ActionDrawArc3P::preparePreview() 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(); } } @@ -116,6 +117,8 @@ void ActionDrawArc3P::mouseMoveEvent(QMouseEvent * e) // clearPreview(); // preview->addEntity(line); // drawPreview(); + graphicView->preview.clear(); + graphicView->preview.addEntity(new Line(&(graphicView->preview), LineData(point1, point2))); } break; @@ -131,12 +134,16 @@ void ActionDrawArc3P::mouseMoveEvent(QMouseEvent * e) // 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) @@ -148,9 +155,10 @@ void ActionDrawArc3P::mouseReleaseEvent(QMouseEvent * e) } else if (e->button() == Qt::RightButton) { - deletePreview(); - deleteSnapper(); +// deletePreview(); +// deleteSnapper(); init(getStatus() - 1); + graphicView->redraw(); } } diff --git a/src/actions/actiondrawarctangential.cpp b/src/actions/actiondrawarctangential.cpp index f1691fc..a8a16c6 100644 --- a/src/actions/actiondrawarctangential.cpp +++ b/src/actions/actiondrawarctangential.cpp @@ -12,6 +12,7 @@ // Who When What // --- ---------- ----------------------------------------------------------- // JLH 06/03/2010 Added this text. :-) +// JLH 09/17/2010 Fixed preview/snapper rendering. // #include "actiondrawarctangential.h" @@ -22,8 +23,8 @@ #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(); } @@ -68,26 +69,26 @@ void ActionDrawArcTangential::trigger() 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; @@ -129,6 +130,9 @@ void ActionDrawArcTangential::mouseMoveEvent(QMouseEvent * e) // clearPreview(); // preview->addEntity(arc); // drawPreview(); + graphicView->preview.clear(); + graphicView->preview.addEntity(new Arc(&(graphicView->preview), data)); + graphicView->redraw(); } break; @@ -149,7 +153,7 @@ void ActionDrawArcTangential::mouseReleaseEvent(QMouseEvent * e) Vector coord = graphicView->toGraph(e->x(), e->y()); Entity * entity = catchEntity(coord, RS2::ResolveAll); - if (entity != NULL) + if (entity) { if (entity->isAtomic()) { @@ -184,9 +188,10 @@ void ActionDrawArcTangential::mouseReleaseEvent(QMouseEvent * e) } else if (e->button() == Qt::RightButton) { - deletePreview(); - deleteSnapper(); +// deletePreview(); + // deleteSnapper(); init(getStatus() - 1); + graphicView->redraw(); //hm. } } diff --git a/src/actions/actiondrawline.cpp b/src/actions/actiondrawline.cpp index a0be6db..8bc0bb1 100644 --- a/src/actions/actiondrawline.cpp +++ b/src/actions/actiondrawline.cpp @@ -29,12 +29,8 @@ ActionDrawLine::ActionDrawLine(EntityContainer & container, GraphicView & graphi { 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() @@ -97,7 +93,8 @@ void ActionDrawLine::mouseMoveEvent(QMouseEvent * e) 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) @@ -125,6 +122,10 @@ void ActionDrawLine::mouseMoveEvent(QMouseEvent * e) #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"); @@ -134,23 +135,19 @@ void ActionDrawLine::mouseReleaseEvent(QMouseEvent * e) { 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) diff --git a/src/actions/actiondrawpolyline.cpp b/src/actions/actiondrawpolyline.cpp index 03925ab..65a7270 100644 --- a/src/actions/actiondrawpolyline.cpp +++ b/src/actions/actiondrawpolyline.cpp @@ -21,10 +21,9 @@ 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() @@ -43,7 +42,6 @@ void ActionDrawPolyline::trigger() if (polyline) { container->addEntity(polyline); -// deleteSnapper(); if (document) { @@ -54,11 +52,13 @@ void ActionDrawPolyline::trigger() 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); @@ -73,16 +73,68 @@ void ActionDrawPolyline::mouseMoveEvent(QMouseEvent * 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(); } } @@ -90,29 +142,97 @@ void ActionDrawPolyline::mouseReleaseEvent(QMouseEvent * e) { 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: diff --git a/src/actions/actiondrawpolyline.h b/src/actions/actiondrawpolyline.h index 171e5ea..b344c57 100644 --- a/src/actions/actiondrawpolyline.h +++ b/src/actions/actiondrawpolyline.h @@ -27,9 +27,10 @@ class ActionDrawPolyline: public ActionInterface 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(); @@ -40,6 +41,7 @@ class ActionDrawPolyline: public ActionInterface protected: Vector vertex; + Vector startPoint; Polyline * polyline; /** Start point of the series of lines. Used for close function. */ Vector start; diff --git a/src/actions/actionmodifymirror.cpp b/src/actions/actionmodifymirror.cpp index 786aeeb..c0cf0e7 100644 --- a/src/actions/actionmodifymirror.cpp +++ b/src/actions/actionmodifymirror.cpp @@ -65,18 +65,25 @@ void ActionModifyMirror::mouseMoveEvent(QMouseEvent * e) { 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"); @@ -91,9 +98,10 @@ void ActionModifyMirror::mouseReleaseEvent(QMouseEvent * e) } else if (e->button() == Qt::RightButton) { - deletePreview(); - deleteSnapper(); +// deletePreview(); +// deleteSnapper(); init(getStatus() - 1); + graphicView->redraw(); //hm. } } @@ -123,10 +131,11 @@ void ActionModifyMirror::coordinateEvent(Vector * e) { data.axisPoint1 = axisPoint1; data.axisPoint2 = axisPoint2; - deletePreview(); - clearPreview(); +// deletePreview(); +// clearPreview(); trigger(); finish(); + graphicView->redraw(); //hm. } } break; @@ -148,14 +157,12 @@ void ActionModifyMirror::updateMouseButtonHints() 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: @@ -172,7 +179,7 @@ void ActionModifyMirror::updateMouseCursor() void ActionModifyMirror::updateToolBar() { - if (DIALOGFACTORY != NULL) + if (DIALOGFACTORY) { switch (getStatus()) { diff --git a/src/actions/actionmodifytrim.cpp b/src/actions/actionmodifytrim.cpp index efbc6a0..f11d064 100644 --- a/src/actions/actionmodifytrim.cpp +++ b/src/actions/actionmodifytrim.cpp @@ -12,6 +12,7 @@ // 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" @@ -24,14 +25,16 @@ * @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() @@ -53,16 +56,17 @@ void ActionModifyTrim::trigger() 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); @@ -113,8 +117,9 @@ void ActionModifyTrim::mouseReleaseEvent(QMouseEvent * e) if (limitEntity) { limitEntity->setHighlighted(true); - graphicView->drawEntity(limitEntity); +// graphicView->drawEntity(limitEntity); setStatus(ChooseTrimEntity); + graphicView->redraw(); //hm. } break; @@ -122,7 +127,7 @@ void ActionModifyTrim::mouseReleaseEvent(QMouseEvent * e) trimCoord = mouse; trimEntity = se; - if (trimEntity != NULL && trimEntity->isAtomic()) + if (trimEntity && trimEntity->isAtomic()) trigger(); break; @@ -132,15 +137,17 @@ void ActionModifyTrim::mouseReleaseEvent(QMouseEvent * e) } 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. } } @@ -183,4 +190,3 @@ void ActionModifyTrim::updateToolBar() { DIALOGFACTORY->requestToolBar(RS2::ToolBarModify); } - diff --git a/src/actions/actionpolylineadd.cpp b/src/actions/actionpolylineadd.cpp index 6188943..436f5c2 100644 --- a/src/actions/actionpolylineadd.cpp +++ b/src/actions/actionpolylineadd.cpp @@ -33,3 +33,8 @@ ActionPolylineAdd::~ActionPolylineAdd() delete polyline; } +/*virtual*/ RS2::ActionType ActionPolylineAdd::rtti() +{ + return RS2::ActionPolylineAdd; +} + diff --git a/src/actions/actionpolylineadd.h b/src/actions/actionpolylineadd.h index 630be49..471340d 100644 --- a/src/actions/actionpolylineadd.h +++ b/src/actions/actionpolylineadd.h @@ -16,6 +16,7 @@ class ActionPolylineAdd: public ActionInterface ActionPolylineAdd(EntityContainer & container, GraphicView & graphicView); ~ActionPolylineAdd(); + virtual RS2::ActionType rtti(); // virtual void init(int status = 0); // virtual void trigger(); // virtual void mouseMoveEvent(QMouseEvent * e); diff --git a/src/actions/actionpolylineappend.cpp b/src/actions/actionpolylineappend.cpp index 8a936f8..528ec93 100644 --- a/src/actions/actionpolylineappend.cpp +++ b/src/actions/actionpolylineappend.cpp @@ -33,3 +33,8 @@ ActionPolylineAppend::~ActionPolylineAppend() delete polyline; } +/*virtual*/ RS2::ActionType ActionPolylineAppend::rtti() +{ + return RS2::ActionPolylineAppend; +} + diff --git a/src/actions/actionpolylineappend.h b/src/actions/actionpolylineappend.h index 0921402..c51bf13 100644 --- a/src/actions/actionpolylineappend.h +++ b/src/actions/actionpolylineappend.h @@ -16,6 +16,7 @@ class ActionPolylineAppend: public ActionInterface ActionPolylineAppend(EntityContainer & container, GraphicView & graphicView); ~ActionPolylineAppend(); + virtual RS2::ActionType rtti(); // virtual void init(int status = 0); // virtual void trigger(); // virtual void mouseMoveEvent(QMouseEvent * e); diff --git a/src/actions/actionpolylinedel.cpp b/src/actions/actionpolylinedel.cpp index 078e57b..af4be0b 100644 --- a/src/actions/actionpolylinedel.cpp +++ b/src/actions/actionpolylinedel.cpp @@ -33,3 +33,8 @@ ActionPolylineDel::~ActionPolylineDel() delete polyline; } +/*virtual*/ RS2::ActionType ActionPolylineDel::rtti() +{ + return RS2::ActionPolylineDel; +} + diff --git a/src/actions/actionpolylinedel.h b/src/actions/actionpolylinedel.h index 3c7d78d..b940b98 100644 --- a/src/actions/actionpolylinedel.h +++ b/src/actions/actionpolylinedel.h @@ -16,6 +16,7 @@ class ActionPolylineDel: public ActionInterface ActionPolylineDel(EntityContainer & container, GraphicView & graphicView); ~ActionPolylineDel(); + virtual RS2::ActionType rtti(); // virtual void init(int status = 0); // virtual void trigger(); // virtual void mouseMoveEvent(QMouseEvent * e); diff --git a/src/actions/actionpolylinedelbetween.cpp b/src/actions/actionpolylinedelbetween.cpp index 09b096a..6c9eff4 100644 --- a/src/actions/actionpolylinedelbetween.cpp +++ b/src/actions/actionpolylinedelbetween.cpp @@ -33,3 +33,8 @@ ActionPolylineDelBetween::~ActionPolylineDelBetween() delete polyline; } +/*virtual*/ RS2::ActionType ActionPolylineDelBetween::rtti() +{ + return RS2::ActionPolylineDelBetween; +} + diff --git a/src/actions/actionpolylinedelbetween.h b/src/actions/actionpolylinedelbetween.h index dd8f7ae..ae25e5d 100644 --- a/src/actions/actionpolylinedelbetween.h +++ b/src/actions/actionpolylinedelbetween.h @@ -16,6 +16,7 @@ class ActionPolylineDelBetween: public ActionInterface ActionPolylineDelBetween(EntityContainer & container, GraphicView & graphicView); ~ActionPolylineDelBetween(); + virtual RS2::ActionType rtti(); // virtual void init(int status = 0); // virtual void trigger(); // virtual void mouseMoveEvent(QMouseEvent * e); diff --git a/src/actions/actionpolylinetrim.cpp b/src/actions/actionpolylinetrim.cpp index ea12e6f..884cfef 100644 --- a/src/actions/actionpolylinetrim.cpp +++ b/src/actions/actionpolylinetrim.cpp @@ -33,3 +33,8 @@ ActionPolylineTrim::~ActionPolylineTrim() delete polyline; } +/*virtual*/ RS2::ActionType ActionPolylineTrim::rtti() +{ + return RS2::ActionPolylineTrim; +} + diff --git a/src/actions/actionpolylinetrim.h b/src/actions/actionpolylinetrim.h index b1d82c1..d88ec3e 100644 --- a/src/actions/actionpolylinetrim.h +++ b/src/actions/actionpolylinetrim.h @@ -16,6 +16,7 @@ class ActionPolylineTrim: public ActionInterface ActionPolylineTrim(EntityContainer & container, GraphicView & graphicView); ~ActionPolylineTrim(); + virtual RS2::ActionType rtti(); // virtual void init(int status = 0); // virtual void trigger(); // virtual void mouseMoveEvent(QMouseEvent * e); diff --git a/src/base/actioninterface.cpp b/src/base/actioninterface.cpp index 92b7745..17d1da9 100644 --- a/src/base/actioninterface.cpp +++ b/src/base/actioninterface.cpp @@ -20,8 +20,17 @@ #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. @@ -35,7 +44,10 @@ * 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); @@ -50,17 +62,20 @@ ActionInterface::ActionInterface(const char * name, EntityContainer & ec, // 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); } /** @@ -71,6 +86,7 @@ ActionInterface::ActionInterface(const char * name, EntityContainer & ec, // would be pure virtual now: // hideOptions(); //JLH: Only it isn't pure virtual... +printf("ActionInterface::~ActionInterface() [%08X]\n", this); } /** @@ -112,9 +128,11 @@ void ActionInterface::init(int status/*= 0*/) } 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. } } @@ -208,9 +226,9 @@ QStringList ActionInterface::getAvailableCommands() * 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) { @@ -295,6 +313,12 @@ void ActionInterface::finish() // 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"); } @@ -307,15 +331,31 @@ void ActionInterface::setPredecessor(ActionInterface * p) 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 } /** @@ -323,9 +363,17 @@ void ActionInterface::suspend() */ 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 } /** @@ -373,17 +421,18 @@ QString ActionInterface::msgAvailableCommands() // 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 !!!" diff --git a/src/base/actioninterface.h b/src/base/actioninterface.h index a88ee89..5ae1d6b 100644 --- a/src/base/actioninterface.h +++ b/src/base/actioninterface.h @@ -81,31 +81,30 @@ class ActionInterface: public QObject * 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; }; diff --git a/src/base/eventhandler.cpp b/src/base/eventhandler.cpp index a8b6417..d8d8f2b 100644 --- a/src/base/eventhandler.cpp +++ b/src/base/eventhandler.cpp @@ -45,7 +45,7 @@ EventHandler::~EventHandler() { DEBUG->print("EventHandler::~EventHandler"); - if (defaultAction != NULL) + if (defaultAction) { defaultAction->finish(); delete defaultAction; @@ -164,11 +164,22 @@ void EventHandler::mouseMoveEvent(QMouseEvent * e) } } +#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()) { @@ -180,6 +191,7 @@ void EventHandler::mouseLeaveEvent() defaultAction->suspend(); //DEBUG->print("currently no action defined"); } +#endif } /** @@ -187,6 +199,7 @@ void EventHandler::mouseLeaveEvent() */ void EventHandler::mouseEnterEvent() { +#if 0 if (actionIndex >= 0 && currentActions[actionIndex] && !currentActions[actionIndex]->isFinished()) { @@ -197,6 +210,7 @@ void EventHandler::mouseEnterEvent() if (defaultAction) defaultAction->resume(); } +#endif } /** @@ -584,8 +598,8 @@ void EventHandler::cleanUp() { 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; @@ -594,41 +608,41 @@ void EventHandler::cleanUp() 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(); diff --git a/src/base/snapper.cpp b/src/base/snapper.cpp index 24aaebf..28e600a 100644 --- a/src/base/snapper.cpp +++ b/src/base/snapper.cpp @@ -12,6 +12,8 @@ // 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" @@ -31,13 +33,17 @@ 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 } /** @@ -52,6 +58,7 @@ Snapper::~Snapper() */ void Snapper::init() { +#if 0 if (graphicView) { snapMode = graphicView->getDefaultSnapMode(); @@ -74,56 +81,76 @@ void Snapper::init() // 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; } /** @@ -133,9 +160,14 @@ RS2::SnapRestriction Snapper::getSnapRestriction(void) */ 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. * @@ -144,6 +176,7 @@ void Snapper::setSnapRange(int r) */ Vector Snapper::snapPoint(QMouseEvent * e) { +#if 0 DEBUG->print("Snapper::snapPoint"); snapSpot = Vector(false); @@ -217,6 +250,8 @@ Vector Snapper::snapPoint(QMouseEvent * e) DEBUG->print("Snapper::snapPoint: OK"); return snapCoord; +#endif + return Vector(false); } /** @@ -227,8 +262,11 @@ Vector Snapper::snapPoint(QMouseEvent * e) */ Vector Snapper::snapFree(Vector coord) { +#if 0 keyEntity = NULL; return coord; +#endif + return Vector(false); } /** @@ -239,10 +277,13 @@ Vector Snapper::snapFree(Vector coord) */ Vector Snapper::snapEndpoint(Vector coord) { +#if 0 Vector vec(false); vec = container->getNearestEndpoint(coord, NULL); return vec; +#endif + return Vector(false); } /** @@ -253,6 +294,7 @@ Vector Snapper::snapEndpoint(Vector coord) */ Vector Snapper::snapGrid(Vector coord) { +#if 0 DEBUG->print("Snapper::snapGrid begin"); Vector vec(false); @@ -295,6 +337,8 @@ Vector Snapper::snapGrid(Vector coord) DEBUG->print("Snapper::snapGrid end"); return vec; +#endif + return Vector(false); } /** @@ -305,10 +349,13 @@ Vector Snapper::snapGrid(Vector coord) */ Vector Snapper::snapOnEntity(Vector coord) { +#if 0 Vector vec(false); vec = container->getNearestPointOnEntity(coord, true, NULL, &keyEntity); return vec; +#endif + return Vector(false); } /** @@ -319,10 +366,13 @@ Vector Snapper::snapOnEntity(Vector coord) */ Vector Snapper::snapCenter(Vector coord) { +#if 0 Vector vec(false); vec = container->getNearestCenter(coord, NULL); return vec; +#endif + return Vector(false); } /** @@ -333,10 +383,13 @@ Vector Snapper::snapCenter(Vector coord) */ Vector Snapper::snapMiddle(Vector coord) { +#if 0 Vector vec(false); vec = container->getNearestMiddle(coord, NULL); return vec; +#endif + return Vector(false); } /** @@ -347,10 +400,13 @@ Vector Snapper::snapMiddle(Vector coord) */ Vector Snapper::snapDist(Vector coord) { +#if 0 Vector vec(false); vec = container->getNearestDist(distance, coord, NULL); return vec; +#endif + return Vector(false); } /** @@ -361,10 +417,13 @@ Vector Snapper::snapDist(Vector coord) */ Vector Snapper::snapIntersection(Vector coord) { +#if 0 Vector vec(false); vec = container->getNearestIntersection(coord, NULL); return vec; +#endif + return Vector(false); } /** @@ -376,6 +435,7 @@ Vector Snapper::snapIntersection(Vector coord) */ Vector Snapper::restrictOrthogonal(Vector coord) { +#if 0 Vector rz = graphicView->getRelativeZero(); Vector ret(coord); @@ -388,6 +448,8 @@ Vector Snapper::restrictOrthogonal(Vector coord) ret = retx; return ret; +#endif + return Vector(false); } /** @@ -399,9 +461,12 @@ Vector Snapper::restrictOrthogonal(Vector coord) */ Vector Snapper::restrictHorizontal(Vector coord) { +#if 0 Vector rz = graphicView->getRelativeZero(); return Vector(coord.x, rz.y); +#endif + return Vector(false); } /** @@ -413,9 +478,12 @@ Vector Snapper::restrictHorizontal(Vector coord) */ Vector Snapper::restrictVertical(Vector coord) { +#if 0 Vector rz = graphicView->getRelativeZero(); return Vector(rz.x, coord.y); +#endif + return Vector(false); } /** @@ -428,13 +496,12 @@ Vector Snapper::restrictVertical(Vector coord) */ 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()) @@ -442,17 +509,19 @@ Entity * Snapper::catchEntity(const Vector & pos, RS2::ResolveLevel level) 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; } /** @@ -465,18 +534,26 @@ Entity * Snapper::catchEntity(const Vector & pos, RS2::ResolveLevel level) */ 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 } /** @@ -484,8 +561,10 @@ Entity * Snapper::catchEntity(QMouseEvent * e, RS2::ResolveLevel level) */ /*virtual*/ void Snapper::resume() { +#if 0 #warning "!!! This may need to have SetVisibility() called !!!" // drawSnapper(); +#endif } /** @@ -493,8 +572,10 @@ Entity * Snapper::catchEntity(QMouseEvent * e, RS2::ResolveLevel level) */ /*virtual*/ void Snapper::hideOptions() { +#if 0 if (snapMode == RS2::SnapDist && DIALOGFACTORY) DIALOGFACTORY->requestSnapDistOptions(distance, false); +#endif } /** @@ -502,18 +583,24 @@ Entity * Snapper::catchEntity(QMouseEvent * e, RS2::ResolveLevel level) */ /*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 } /* @@ -524,14 +611,13 @@ GraphicView class... What to do? */ 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)); @@ -546,9 +632,8 @@ void Snapper::Draw(GraphicView * view, PaintInterface * painter) 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)); @@ -559,4 +644,5 @@ void Snapper::Draw(GraphicView * view, PaintInterface * painter) painter->drawLine(view->toGui(snapSpot) + Vector(0, -5), view->toGui(snapSpot) + Vector(-4, -1)); } +#endif } diff --git a/src/forms/polylineoptions.cpp b/src/forms/polylineoptions.cpp index bdc194e..36ecd6f 100644 --- a/src/forms/polylineoptions.cpp +++ b/src/forms/polylineoptions.cpp @@ -24,20 +24,28 @@ 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. :-) diff --git a/src/forms/polylineoptions.h b/src/forms/polylineoptions.h index fa4ecfd..98d0f07 100644 --- a/src/forms/polylineoptions.h +++ b/src/forms/polylineoptions.h @@ -23,8 +23,11 @@ class PolylineOptions: public QWidget ActionDrawPolyline * action; private: - QToolButton * bClose; - QToolButton * bUndo; + QToolButton * closeButton; + QToolButton * undoButton; + QCheckBox * arcCheckBox; + QLabel * radiusLabel; + QLineEdit * radiusEdit; }; #endif // __POLYLINEOPTIONS_H__ diff --git a/src/mainapp/graphicview.cpp b/src/mainapp/graphicview.cpp index 4c8ba10..5b633b2 100644 --- a/src/mainapp/graphicview.cpp +++ b/src/mainapp/graphicview.cpp @@ -77,6 +77,24 @@ GraphicView::GraphicView(): background(), foreground() 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; } /** @@ -919,7 +937,8 @@ void GraphicView::zoomAutoY(bool axis) 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); @@ -1176,7 +1195,8 @@ void GraphicView::drawWindow(Vector v1, Vector v2) /** * 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() { @@ -2329,3 +2349,354 @@ bool GraphicView::getSimulationRapid() { 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; icount(); ++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 diff --git a/src/mainapp/graphicview.h b/src/mainapp/graphicview.h index 863b7d6..e4cd758 100644 --- a/src/mainapp/graphicview.h +++ b/src/mainapp/graphicview.h @@ -207,18 +207,26 @@ Having this class derive from that one *might* make sense... *Maybe*. Not sure. 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 @@ -231,13 +239,19 @@ Having this class derive from that one *might* make sense... *Maybe*. Not sure. */ 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; diff --git a/src/widgets/qg_graphicview.cpp b/src/widgets/qg_graphicview.cpp index 9ddec0f..6b4e1fb 100644 --- a/src/widgets/qg_graphicview.cpp +++ b/src/widgets/qg_graphicview.cpp @@ -825,8 +825,11 @@ of VectorWorks & etc. as well... // 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); -- 2.37.2