]> Shamusworld >> Repos - architektonas/blobdiff - src/dimension.cpp
Fixes to accomodate object connections.
[architektonas] / src / dimension.cpp
index ad2ffcbe38a08bd88fbbc85ea8333060306862d1..d2aeaf699b84fdd4e109cd641cbf70d1ebd5fa1c 100644 (file)
@@ -26,6 +26,7 @@ Dimension::Dimension(Vector p1, Vector p2, DimensionType dt/*= DTLinear*/ ,Objec
 }
 
 
+#if 0
 // This is bad, p1 & p2 could be NULL, causing much consternation...
 Dimension::Dimension(Vector * p1, Vector * p2, DimensionType dt/*= DTLinear*/ , Object * p/*= NULL*/):
        Object(*p1, p), endpoint(*p2),
@@ -33,6 +34,17 @@ Dimension::Dimension(Vector * p1, Vector * p2, DimensionType dt/*= DTLinear*/ ,
        length(p2->Magnitude()), type(dt), point1(p1), point2(p2)
 {
 }
+#endif
+
+
+// This is bad, p1 & p2 could be NULL, causing much consternation...
+Dimension::Dimension(Connection p1, Connection p2, DimensionType dt/*= DTLinear*/ , Object * p/*= NULL*/):
+/*     Object(p1.object->GetPointForParameter(p1.t), p),
+       endpoint(p2.object->GetPointForParameter(p2.t)),*/
+       dragging(false), draggingHandle1(false), draggingHandle2(false),
+       /*length(p2->Magnitude()),*/length(0), type(dt), point1(p1), point2(p2)
+{
+}
 
 
 Dimension::~Dimension()
@@ -44,11 +56,19 @@ Dimension::~Dimension()
 {
        // 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 0
        if (point1)
                position = *point1;
 
        if (point2)
                endpoint = *point2;
+#else
+       if (point1.object)
+               position = point1.object->GetPointAtParameter(point1.t);
+
+       if (point2.object)
+               endpoint = point2.object->GetPointAtParameter(point2.t);
+#endif
 
        if (state == OSSelected)
                painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
@@ -327,6 +347,7 @@ about keeping track of old states...
 }
 
 
+#if 0
 void Dimension::SetPoint1(Vector * v)
 {
        point1 = v;
@@ -339,8 +360,85 @@ void Dimension::SetPoint2(Vector * v)
        point2 = v;
        needUpdate = true;
 }
+#endif
+
+
+/*virtual*/ void Dimension::Enumerate(FILE * file)
+{
+       fprintf(file, "DIMENSION (%lf,%lf) (%lf,%lf) %i\n", position.x, position.y, endpoint.x, endpoint.y, type);
+}
+
+
+// Dimensions are special: they contain exactly *two* points. Here, we check
+// only for zero/non-zero in returning the correct points.
+/*virtual*/ Vector Dimension::GetPointAtParameter(double parameter)
+{
+       if (parameter == 0)
+               return position;
+
+       return endpoint;
+}
+
+
+/*virtual*/ void Dimension::Connect(Object * obj, double param)
+{
+       // There are four possibilities here...
+       // The param is only looking for 0 or 1 here.
+       if (point1.object == NULL && point2.object == NULL)
+       {
+               point1.object = obj;
+               point1.t = param;
+       }
+       else if (point1.object == NULL && point2.object != NULL)
+       {
+               if (point2.t == param)
+                       point2.object = obj;
+               else
+               {
+                       point1.object = obj;
+                       point1.t = param;
+               }
+       }
+       else if (point1.object != NULL && point2.object == NULL)
+       {
+               if (point1.t == param)
+                       point1.object = obj;
+               else
+               {
+                       point2.object = obj;
+                       point2.t = param;
+               }
+       }
+       else if (point1.object != NULL && point2.object != NULL)
+       {
+               if (point1.t == param)
+                       point1.object = obj;
+               else
+                       point2.object = obj;
+       }
+}
 
 
+/*virtual*/ void Dimension::Disconnect(Object * obj, double param)
+{
+       if (point1.object == obj && point1.t == param)
+               point1 = NULL;
+       else if (point2.object == obj && point2.t == param)
+               point2 = NULL;
+}
+
+
+/*virtual*/ void Dimension::DisconnectAll(Object * obj)
+{
+       if (point1.object == obj)
+               point1 = NULL;
+
+       if (point2.object == obj)
+               point2 = NULL;
+}
+
+
+#if 0
 Vector Dimension::GetPoint1(void)
 {
        return position;
@@ -351,6 +449,7 @@ Vector Dimension::GetPoint2(void)
 {
        return endpoint;
 }
+#endif
 
 
 void Dimension::FlipSides(void)
@@ -360,16 +459,16 @@ void Dimension::FlipSides(void)
        position = endpoint;
        endpoint = tmp;
 #else
-       Vector * tmp = point1;
+       Connection tmp = point1;
        point1 = point2;
        point2 = tmp;
+//     double tmp = point1.t;
+//     point1.t = point2.t;
+//     point2.t = tmp;
+//     Object * tmp = point1.object;
+//     point1.object = point2.object;
+//     point2.object = tmp;
 #endif
        needUpdate = true;
 }
 
-
-/*virtual*/ void Dimension::Enumerate(FILE * file)
-{
-       fprintf(file, "DIMENSION (%lf,%lf) (%lf,%lf) %i\n", position.x, position.y, endpoint.x, endpoint.y, type);
-}
-