+
+
+/*virtual*/ bool Dimension::HitTest(Point point)
+{
+ hitPoint1 = hitPoint2 = false;
+// Vector lineSegment(position, endpoint);
+ Vector v1(position, point);
+ Vector v2(endpoint, point);
+// double t = Geometry::ParameterOfLineAndPoint(position, endpoint, point);
+// double distance;
+
+// if (t < 0.0)
+// distance = v1.Magnitude();
+// else if (t > 1.0)
+// distance = v2.Magnitude();
+// else
+ // distance = ?Det?(ls, v1) / |ls|
+// distance = fabs((lineSegment.x * v1.y - v1.x * lineSegment.y)
+// / lineSegment.Magnitude());
+
+ if ((v1.Magnitude() * Painter::zoom) < 8.0)
+ hitPoint1 = true;
+ else if ((v2.Magnitude() * Painter::zoom) < 8.0)
+ hitPoint2 = true;
+
+ return (hitPoint1 || hitPoint2 ? true : false);
+}
+
+
+void Dimension::SaveHitState(void)
+{
+ oldHitPoint1 = hitPoint1;
+ oldHitPoint2 = hitPoint2;
+// oldHitLine = hitLine;
+}
+
+
+bool Dimension::HitStateChanged(void)
+{
+ if ((hitPoint1 != oldHitPoint1) || (hitPoint2 != oldHitPoint2))
+ return true;
+
+ return false;
+}
+
+
+/*virtual*/ void Dimension::Enumerate(FILE * file)
+{
+ fprintf(file, "DIMENSION %i (%lf,%lf) (%lf,%lf) %i\n", layer, position.x, position.y, endpoint.x, endpoint.y, type);
+}
+
+
+/*virtual*/ Object * Dimension::Copy(void)
+{
+#warning "!!! This doesn't take care of attached Dimensions !!!"
+/*
+This is a real problem. While having a pointer in the Dimension to this line's points
+is fast & easy, it creates a huge problem when trying to replicate an object like this.
+
+Maybe a way to fix that then, is to have reference numbers instead of pointers. That
+way, if you copy them, ... you might still have problems. Because you can't be sure if
+a copy will be persistant or not, you then *definitely* do not want them to have the
+same reference number.
+*/
+
+ Dimension * d = new Dimension(position, endpoint, dimensionType, parent);
+ d->size = size;
+ return d;
+}
+
+
+// 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.object = NULL;
+ else if (point2.object == obj && point2.t == param)
+ point2.object = NULL;
+}
+
+
+/*virtual*/ void Dimension::DisconnectAll(Object * obj)
+{
+ if (point1.object == obj)
+ point1.object = NULL;
+
+ if (point2.object == obj)
+ point2.object = NULL;
+}
+
+
+/*virtual*/ QRectF Dimension::Extents(void)
+{
+ Point p1 = position;
+ Point p2 = endpoint;
+
+ if (point1.object)
+ p1 = point1.object->GetPointAtParameter(point1.t);
+
+ if (point2.object)
+ p2 = point2.object->GetPointAtParameter(point2.t);
+
+ return QRectF(QPointF(p1.x, p1.y), QPointF(p2.x, p2.y));
+}
+
+
+#if 0
+/*virtual*/ ObjectType Dimension::Type(void)
+{
+ return OTDimension;
+}
+#endif
+
+
+void Dimension::FlipSides(void)
+{
+#if 0
+ Vector tmp = position;
+ position = endpoint;
+ endpoint = tmp;
+#else
+ 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;
+}
+