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;
29 //snapToPoints all well here?
30 bool Object::ignoreClicks = false;
31 bool Object::dontMove = false;
32 bool Object::selectionInProgress = false;
33 QRectF Object::selection;
36 Object::Object(): position(Vector(0, 0)), parent(0), type(OTObject),
37 state(OSInactive), oldState(OSInactive), needUpdate(false)
38 //, attachedDimension(0)
43 Object::Object(Vector v, Object * passedInParent/*= 0*/): position(v), parent(passedInParent),
44 state(OSInactive), oldState(OSInactive), needUpdate(false)//, attachedDimension(0)
51 printf("Object: Destroyed!\n");
52 for(uint i=0; i<connected.size(); i++)
53 connected[i].object->DisconnectAll(this);
57 /*virtual*/ void Object::Draw(Painter *)
62 /*virtual*/ Vector Object::Center(void)
68 /*virtual*/ bool Object::Collided(Vector)
74 /*virtual*/ void Object::PointerMoved(Vector)
79 /*virtual*/ void Object::PointerReleased(void)
84 /*virtual*/ bool Object::NeedsUpdate(void)
90 /*virtual*/ bool Object::HitTest(Point)
96 // This is intended to be overridden by the Container class, for object morphing
97 /*virtual*/ void Object::Transmute(Object *, Object *)
102 /*virtual*/ Object * Object::GetParent(void)
108 /*virtual*/ void Object::Add(Object *)
113 // This returns a pointer to the point passed in, if it coincides. Otherwise returns NULL.
114 /*virtual*/ Vector * Object::GetPointAt(Vector)
120 // This is meant for writing object data to a file.
121 /*virtual*/ void Object::Enumerate(FILE *)
126 /*virtual*/ Object * Object::Copy(void)
128 return new Object(position, parent);
132 // This returns a point on the object at 'parameter', which is between 0 and 1.
133 // Default is to return the object's position.
134 /*virtual*/ Vector Object::GetPointAtParameter(double)
140 // Since these functions are pretty much non-object specific, we can implement
142 /*virtual*/ void Object::Connect(Object * obj, double parameter)
144 connected.push_back(Connection(obj, parameter));
148 /*virtual*/ void Object::Disconnect(Object * obj, double parameter)
150 for(uint i=0; i<connected.size(); i++)
152 if (connected[i].object == obj && connected[i].t == parameter)
154 connected.erase(connected.begin() + i);
161 /*virtual*/ void Object::DisconnectAll(Object * obj)
163 // According the std::vector docs, only items at position i and beyond are
164 // invalidated, everything before i is still valid. So we use that here.
165 for(uint i=0; i<connected.size();)
167 // If we found our object, erase it from the vector but don't advance
168 // the iterator. Otherwise, advance the iterator. :-)
169 if (connected[i].object == obj)
170 connected.erase(connected.begin() + i);
177 /*virtual*/ QRectF Object::Extents(void)
179 // Generic object returns an empty rect...
185 /*virtual*/ ObjectType Object::Type(void)
192 ObjectState Object::GetState(void)
198 void Object::Reparent(Object * newParent)
204 /*Dimension * Object::GetAttachedDimension(void)
206 return attachedDimension;
212 void Object::SetFixedAngle(bool state/*= true*/)
218 void Object::SetFixedLength(bool state/*= true*/)
224 void Object::SetFont(QFont * f)
230 void Object::SetViewportHeight(int height)
232 viewportHeight = height;
236 void Object::SetDeleteActive(bool state/*= true*/)
238 deleteActive = state;
242 void Object::SetDimensionActive(bool state/*= true*/)
244 dimensionActive = state;
248 void Object::SetSnapMode(bool state/*= true*/)