]> Shamusworld >> Repos - architektonas/commitdiff
Fixed duplicate Connection issue.
authorShamus Hammons <jlhamm@acm.org>
Wed, 5 Feb 2014 15:04:55 +0000 (09:04 -0600)
committerShamus Hammons <jlhamm@acm.org>
Wed, 5 Feb 2014 15:04:55 +0000 (09:04 -0600)
src/connection.cpp
src/connection.h
src/dimension.cpp
src/dimension.h
src/line.cpp
src/object.cpp

index 2dd8e2466e5e77b6d132c72acc9726f4efb64d24..7170c460c6d983e897711e8f0cb573c3d65b86d4 100644 (file)
@@ -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);
+}
+
index 485c4c0550d9e6b5a4435aa067630fa718a3e199..09ce49922c54aa8e1d7d53007bcf327a39961e8d 100644 (file)
@@ -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;
index c9777e50bd673688bc5d06dee646c6a4753cd19d..b3f1e7f3d915d0392c37abe7c2d01b8826b13b95 100644 (file)
@@ -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...
index 32aa2857c3582ee1786faaa70b7f62baf0210c29..ca146bb4a48abd184e9343b52c58c8d3aa0e6592 100644 (file)
@@ -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 *);
index 060868562a8299c3d335bb849f3657d4a0d7417c..8fc9b9c83f3e764940dc07dece9a67457f73a3cb 100644 (file)
@@ -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<Connection>::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;
 }
 
 
index ca065dcdc77832daa41192d3d7496739d68a193e..09d52bf3357b02165410e82e4200877421eddb7e 100644 (file)
@@ -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<Connection>::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<connected.size(); i++)
-       {
-               if (connected[i].object == obj && connected[i].t == parameter)
-               {
-                       connected.erase(connected.begin() + i);
-                       return;
-               }
-       }
-#else
        std::vector<Connection>::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<connected.size();)
-       {
-               // If we found our object, erase it from the vector but don't advance
-               // the iterator. Otherwise, advance the iterator. :-)
-               if (connected[i].object == obj)
-                       connected.erase(connected.begin() + i);
-               else
-                       i++;
-       }
-#else
        std::vector<Connection>::iterator i;
 
        for(i=connected.begin(); i!=connected.end(); )
@@ -199,7 +187,6 @@ printf("Object: Destroyed!\n");
                else
                        i++;
        }
-#endif
 }