From 565c33c91ea355528145ba94b31b2e44309d0834 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Wed, 5 Feb 2014 09:04:55 -0600 Subject: [PATCH] Fixed duplicate Connection issue. --- src/connection.cpp | 14 ++++++++++++++ src/connection.h | 3 +++ src/dimension.cpp | 17 +++++++++++++++-- src/dimension.h | 5 +++++ src/line.cpp | 21 +++++++++++++++------ src/object.cpp | 39 +++++++++++++-------------------------- 6 files changed, 65 insertions(+), 34 deletions(-) diff --git a/src/connection.cpp b/src/connection.cpp index 2dd8e24..7170c46 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -26,3 +26,17 @@ Connection::~Connection() { } + +// Check for equality +bool Connection::operator==(Connection const c) +{ + return (object == c.object) && (t == c.t); +} + + +// Check for inequality +bool Connection::operator!=(Connection const c) +{ + return (object != c.object) || (t != c.t); +} + diff --git a/src/connection.h b/src/connection.h index 485c4c0..09ce499 100644 --- a/src/connection.h +++ b/src/connection.h @@ -12,6 +12,9 @@ class Connection Connection(Object * o = 0, double param = 0); ~Connection(); + bool operator==(Connection const c); // Check for equality + bool operator!=(Connection const c); // Check for inequality + public: Object * object; double t; diff --git a/src/dimension.cpp b/src/dimension.cpp index c9777e5..b3f1e7f 100644 --- a/src/dimension.cpp +++ b/src/dimension.cpp @@ -20,7 +20,7 @@ #include "painter.h" -Dimension::Dimension(Vector p1, Vector p2, DimensionType dt/*= DTLinear*/ ,Object * p/*= NULL*/): +Dimension::Dimension(Vector p1, Vector p2, DimensionType dt/*= DTLinear*/, Object * p/*= NULL*/): Object(p1, p), endpoint(p2), dragging(false), draggingHandle1(false), draggingHandle2(false), length(p2.Magnitude()), dimensionType(dt), size(0.25), point1(NULL), point2(NULL) @@ -31,7 +31,7 @@ Dimension::Dimension(Vector p1, Vector p2, DimensionType dt/*= DTLinear*/ ,Objec // This is bad, p1 & p2 could be NULL, causing much consternation... -Dimension::Dimension(Connection p1, Connection p2, DimensionType dt/*= DTLinear*/ , Object * p/*= NULL*/): +Dimension::Dimension(Connection p1, Connection p2, DimensionType dt/*= DTLinear*/, Object * p/*= NULL*/): dragging(false), draggingHandle1(false), draggingHandle2(false), length(0), dimensionType(dt), size(0.25), point1(p1), point2(p2) { @@ -61,6 +61,7 @@ all objects move as a unified whole. /*virtual*/ void Dimension::Draw(Painter * painter) { +#if 0 // If there are valid Vector pointers in here, use them to update the internal // positions. Otherwise, we just use the internal positions by default. if (point1.object) @@ -68,6 +69,7 @@ all objects move as a unified whole. if (point2.object) endpoint = point2.object->GetPointAtParameter(point2.t); +#endif painter->SetPen(QPen(Qt::magenta, 2.0, Qt::DotLine)); @@ -402,6 +404,17 @@ same reference number. } +/*virtual*/ void Dimension::MovePointAtParameter(double parameter, Vector v) +{ + if (parameter == 0) + position += v; + else if (parameter == 1.0) + endpoint += v; + else + {} // Not sure how to handle this case :-P +} + + /*virtual*/ void Dimension::Connect(Object * obj, double param) { // There are four possibilities here... diff --git a/src/dimension.h b/src/dimension.h index 32aa285..ca146bb 100644 --- a/src/dimension.h +++ b/src/dimension.h @@ -4,10 +4,14 @@ #include "connection.h" #include "object.h" +class Line; + enum DimensionType { DTLinear, DTLinearVert, DTLinearHorz, DTRadial, DTDiametric, DTCircumferential, DTAngular, DTLeader }; class Dimension: public Object { + friend class Line; + public: Dimension(Vector, Vector, DimensionType dt = DTLinear, Object * p = 0); Dimension(Connection, Connection, DimensionType dt = DTLinear, Object * p = 0); @@ -22,6 +26,7 @@ class Dimension: public Object virtual void Enumerate(FILE *); virtual Object * Copy(void); virtual Vector GetPointAtParameter(double parameter); + virtual void MovePointAtParameter(double parameter, Vector); virtual void Connect(Object *, double); virtual void Disconnect(Object *, double); virtual void DisconnectAll(Object *); diff --git a/src/line.cpp b/src/line.cpp index 0608685..8fc9b9c 100644 --- a/src/line.cpp +++ b/src/line.cpp @@ -52,6 +52,16 @@ Line::~Line() // connect to this dimension object at this point, instead of just becoming // detached. #endif +//actually not true, we know the object pointer and parameter! +//actuall, the Object base class does this for us...! +#if 0 + std::vector::iterator i; + + for(i=connected.begin(); i!=connected.end(); i++) + { + (*i).object->Disconnect(this, (*i).t); + } +#endif } @@ -306,14 +316,8 @@ a dimension only) Draw() function... :-/ if (selectionInProgress) { // Check for whether or not the rect contains this line -#if 0 - if (selection.normalized().contains(Extents())) -#else -// if (selection.normalized().contains(position.x, position.y) -// && selection.normalized().contains(endpoint.x, endpoint.y)) if (selection.contains(position.x, position.y) && selection.contains(endpoint.x, endpoint.y)) -#endif state = OSSelected; else state = OSInactive; @@ -353,6 +357,8 @@ a dimension only) Draw() function... :-/ { if ((*i).object->type == OTLine) ((Line *)((*i).object))->MovePointAtParameter((*i).t, delta); + else if ((*i).object->type == OTDimension) + ((Dimension *)((*i).object))->MovePointAtParameter((*i).t, delta); } } } @@ -652,6 +658,9 @@ void Line::SetDimensionOnLine(Dimension * dimension/*= NULL*/) // Make sure the Dimension is connected to us... Connect(dimension, 0); Connect(dimension, 1.0); + + dimension->position = position; + dimension->endpoint = endpoint; } diff --git a/src/object.cpp b/src/object.cpp index ca065dc..09d52bf 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -145,22 +145,24 @@ printf("Object: Destroyed!\n"); // them here. :-) /*virtual*/ void Object::Connect(Object * obj, double parameter) { - connected.push_back(Connection(obj, parameter)); + // Check to see if this connection is already in our list... + Connection c(obj, parameter); + std::vector::iterator i; + + for(i=connected.begin(); i!=connected.end(); i++) + { + // Bail out if this connection is already present... + if (*i == c) + return; + } + + // Connection is a new one, add it in... + connected.push_back(c); } /*virtual*/ void Object::Disconnect(Object * obj, double parameter) { -#if 0 - for(uint i=0; i::iterator i; for(i=connected.begin(); i!=connected.end(); i++) @@ -171,25 +173,11 @@ printf("Object: Destroyed!\n"); return; } } -#endif } /*virtual*/ void Object::DisconnectAll(Object * obj) { -#if 0 - // According the std::vector docs, only items at position i and beyond are - // invalidated, everything before i is still valid. So we use that here. - for(uint i=0; i::iterator i; for(i=connected.begin(); i!=connected.end(); ) @@ -199,7 +187,6 @@ printf("Object: Destroyed!\n"); else i++; } -#endif } -- 2.37.2