{
}
+
+// 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);
+}
+
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;
#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)
// 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)
{
/*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)
if (point2.object)
endpoint = point2.object->GetPointAtParameter(point2.t);
+#endif
painter->SetPen(QPen(Qt::magenta, 2.0, Qt::DotLine));
}
+/*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...
#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);
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 *);
// 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
}
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;
{
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);
}
}
}
// Make sure the Dimension is connected to us...
Connect(dimension, 0);
Connect(dimension, 1.0);
+
+ dimension->position = position;
+ dimension->endpoint = endpoint;
}
// 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++)
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(); )
else
i++;
}
-#endif
}