2 // object.cpp: Base class for all CAD objects
4 // Part of the Architektonas Project
5 // (C) 2011 Underground Software
6 // See the README and GPLv3 files for licensing and warranty information
8 // JLH = James Hammons <jlhamm@acm.org>
11 // --- ---------- ------------------------------------------------------------
12 // JLH 03/22/2011 Created this file
13 // JLH 04/01/2011 Added constructor to allow derived objects to have empty
14 // constructor bodies, added state querying
15 // JLH 04/02/2001 Added static methods for global states (fixed angle, etc)
21 // Initialize static variables
22 bool Object::fixedAngle = false;
23 bool Object::fixedLength = false;
24 QFont * Object::font = 0;
25 int Object::viewportHeight = 0;
26 bool Object::deleteActive = false;
27 bool Object::dimensionActive = false;
28 bool Object::snapToGrid = true;
31 Object::Object(): position(Vector(0, 0)), parent(0), state(OSInactive), oldState(OSInactive),
32 needUpdate(false)//, attachedDimension(0)
37 Object::Object(Vector v, Object * passedInParent/*= 0*/): position(v), parent(passedInParent),
38 state(OSInactive), oldState(OSInactive), needUpdate(false)//, attachedDimension(0)
45 printf("Object: Destroyed!\n");
46 for(uint i=0; i<connected.size(); i++)
47 connected[i].object->DisconnectAll(this);
51 /*virtual*/ void Object::Draw(Painter *)
56 /*virtual*/ Vector Object::Center(void)
62 /*virtual*/ bool Object::Collided(Vector)
68 /*virtual*/ void Object::PointerMoved(Vector)
73 /*virtual*/ void Object::PointerReleased(void)
78 /*virtual*/ bool Object::NeedsUpdate(void)
84 // This is intended to be overridden by the Container class, for object morphing
85 /*virtual*/ void Object::Transmute(Object *, Object *)
90 /*virtual*/ Object * Object::GetParent(void)
96 /*virtual*/ void Object::Add(Object *)
101 // This returns a pointer to the point passed in, if it coincides. Otherwise returns NULL.
102 /*virtual*/ Vector * Object::GetPointAt(Vector)
108 // This is meant for writing object data to a file.
109 /*virtual*/ void Object::Enumerate(FILE *)
114 /*virtual*/ Object * Object::Copy(void)
116 return new Object(position, parent);
120 // This returns a point on the object at 'parameter', which is between 0 and 1.
121 // Default is to return the object's position.
122 /*virtual*/ Vector Object::GetPointAtParameter(double)
128 // Since these functions are pretty much non-object specific, we can implement
130 /*virtual*/ void Object::Connect(Object * obj, double parameter)
132 connected.push_back(Connection(obj, parameter));
136 /*virtual*/ void Object::Disconnect(Object * obj, double parameter)
138 for(uint i=0; i<connected.size(); i++)
140 if (connected[i].object == obj && connected[i].t == parameter)
142 connected.erase(connected.begin() + i);
149 /*virtual*/ void Object::DisconnectAll(Object * obj)
151 // According the std::vector docs, only items at position i and beyond are
152 // invalidated, everything before i is still valid. So we use that here.
153 for(uint i=0; i<connected.size();)
155 // If we found our object, erase it from the vector but don't advance
156 // the iterator. Otherwise, advance the iterator. :-)
157 if (connected[i].object == obj)
158 connected.erase(connected.begin() + i);
165 ObjectState Object::GetState(void)
171 void Object::Reparent(Object * newParent)
177 /*Dimension * Object::GetAttachedDimension(void)
179 return attachedDimension;
185 void Object::SetFixedAngle(bool state/*= true*/)
191 void Object::SetFixedLength(bool state/*= true*/)
197 void Object::SetFont(QFont * f)
203 void Object::SetViewportHeight(int height)
205 viewportHeight = height;
209 void Object::SetDeleteActive(bool state/*= true*/)
211 deleteActive = state;
215 void Object::SetDimensionActive(bool state/*= true*/)
217 dimensionActive = state;
221 void Object::SetSnapMode(bool state/*= true*/)