// (C) 2011 Underground Software
// See the README and GPLv3 files for licensing and warranty information
//
-// JLH = James L. Hammons <jlhamm@acm.org>
+// JLH = James Hammons <jlhamm@acm.org>
//
// WHO WHEN WHAT
// --- ---------- ------------------------------------------------------------
// JLH 04/01/2011 Added constructor to allow derived objects to have empty
// constructor bodies, added state querying
// JLH 04/02/2001 Added static methods for global states (fixed angle, etc)
+//
#include "object.h"
+#include <stdlib.h>
// Initialize static variables
bool Object::fixedAngle = false;
bool Object::fixedLength = false;
QFont * Object::font = 0;
int Object::viewportHeight = 0;
+bool Object::deleteActive = false;
+bool Object::dimensionActive = false;
+bool Object::snapToGrid = true;
+//snapToPoints all well here?
+bool Object::ignoreClicks = false;
+bool Object::dontMove = false;
+bool Object::selectionInProgress = false;
+QRectF Object::selection;
-Object::Object(): position(Vector(0, 0)), parent(0), state(OSInactive), oldState(OSInactive),
- needUpdate(false), dimPoint1(0), dimPoint2(0)
+Object::Object(): position(Vector(0, 0)), parent(0), type(OTObject),
+ state(OSInactive), oldState(OSInactive), needUpdate(false)
+ //, attachedDimension(0)
{
}
+
Object::Object(Vector v, Object * passedInParent/*= 0*/): position(v), parent(passedInParent),
- state(OSInactive), oldState(OSInactive), needUpdate(false), dimPoint1(0), dimPoint2(0)
+ state(OSInactive), oldState(OSInactive), needUpdate(false)//, attachedDimension(0)
{
}
+
Object::~Object()
{
+printf("Object: Destroyed!\n");
+ for(uint i=0; i<connected.size(); i++)
+ connected[i].object->DisconnectAll(this);
}
-/*virtual*/ void Object::Draw(QPainter *)
+
+/*virtual*/ void Object::Draw(Painter *)
{
}
+
/*virtual*/ Vector Object::Center(void)
{
return Vector();
}
+
/*virtual*/ bool Object::Collided(Vector)
{
return false;
}
+
/*virtual*/ void Object::PointerMoved(Vector)
{
}
+
/*virtual*/ void Object::PointerReleased(void)
{
}
+
/*virtual*/ bool Object::NeedsUpdate(void)
{
return needUpdate;
}
+
+/*virtual*/ bool Object::HitTest(Point)
+{
+ return false;
+}
+
+
// This is intended to be overridden by the Container class, for object morphing
/*virtual*/ void Object::Transmute(Object *, Object *)
{
}
+
+/*virtual*/ Object * Object::GetParent(void)
+{
+ return parent;
+}
+
+
+/*virtual*/ void Object::Add(Object *)
+{
+}
+
+
+// This returns a pointer to the point passed in, if it coincides. Otherwise returns NULL.
+/*virtual*/ Vector * Object::GetPointAt(Vector)
+{
+ return 0;
+}
+
+
+// This is meant for writing object data to a file.
+/*virtual*/ void Object::Enumerate(FILE *)
+{
+}
+
+
+/*virtual*/ Object * Object::Copy(void)
+{
+ return new Object(position, parent);
+}
+
+
+// This returns a point on the object at 'parameter', which is between 0 and 1.
+// Default is to return the object's position.
+/*virtual*/ Vector Object::GetPointAtParameter(double)
+{
+ return position;
+}
+
+
+// Since these functions are pretty much non-object specific, we can implement
+// them here. :-)
+/*virtual*/ void Object::Connect(Object * obj, double parameter)
+{
+ connected.push_back(Connection(obj, parameter));
+}
+
+
+/*virtual*/ void Object::Disconnect(Object * obj, double parameter)
+{
+ for(uint i=0; i<connected.size(); i++)
+ {
+ if (connected[i].object == obj && connected[i].t == parameter)
+ {
+ connected.erase(connected.begin() + i);
+ return;
+ }
+ }
+}
+
+
+/*virtual*/ void Object::DisconnectAll(Object * obj)
+{
+ // 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++;
+ }
+}
+
+
+/*virtual*/ QRectF Object::Extents(void)
+{
+ // Generic object returns an empty rect...
+ return QRectF();
+}
+
+
+#if 0
+/*virtual*/ ObjectType Object::Type(void)
+{
+ return OTObject;
+}
+#endif
+
+
+/*virtual*/ void Object::Translate(Vector amount)
+{
+ position += amount;
+}
+
+
+/*virtual*/ void Object::Rotate(Vector, double)
+{
+}
+
+
+/*virtual*/ void Object::Scale(Vector, double)
+{
+}
+
+
ObjectState Object::GetState(void)
{
return state;
}
+
+void Object::Reparent(Object * newParent)
+{
+ parent = newParent;
+}
+
+
+/*Dimension * Object::GetAttachedDimension(void)
+{
+ return attachedDimension;
+}*/
+
+
// Class methods...
void Object::SetFixedAngle(bool state/*= true*/)
fixedAngle = state;
}
+
void Object::SetFixedLength(bool state/*= true*/)
{
fixedLength = state;
}
+
void Object::SetFont(QFont * f)
{
font = f;
}
+
void Object::SetViewportHeight(int height)
{
viewportHeight = height;
}
+
+
+void Object::SetDeleteActive(bool state/*= true*/)
+{
+ deleteActive = state;
+}
+
+
+void Object::SetDimensionActive(bool state/*= true*/)
+{
+ dimensionActive = state;
+}
+
+
+void Object::SetSnapMode(bool state/*= true*/)
+{
+ snapToGrid = state;
+}