]> Shamusworld >> Repos - architektonas/blobdiff - src/object.cpp
Trim tool now works for Lines, but inaccurate.
[architektonas] / src / object.cpp
index 197fa8d0f63c202d07f0a9c38183d65cb01eab92..2e85bf2d3e57c0b9666099dfb81a5a796d2692ac 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "object.h"
 #include <stdlib.h>
+#include <math.h>
 
 // Initialize static variables
 bool Object::fixedAngle = false;
@@ -29,17 +30,22 @@ bool Object::snapToGrid = true;
 //snapToPoints all well here?
 bool Object::ignoreClicks = false;
 bool Object::dontMove = false;
+bool Object::selectionInProgress = false;
+QRectF Object::selection;
+double Object::gridSpacing;
+int Object::currentLayer = 0;
 
 
 Object::Object(): position(Vector(0, 0)), parent(0), type(OTObject),
-       state(OSInactive), oldState(OSInactive), needUpdate(false)
+       state(OSInactive), layer(0), oldState(OSInactive), needUpdate(false)
        //, attachedDimension(0)
 {
 }
 
 
-Object::Object(Vector v,  Object * passedInParent/*= 0*/): position(v), parent(passedInParent),
-       state(OSInactive), oldState(OSInactive), needUpdate(false)//, attachedDimension(0)
+Object::Object(Vector v,  Object * passedInParent/*= 0*/): position(v),
+       parent(passedInParent), state(OSInactive), layer(0), oldState(OSInactive),
+       needUpdate(false)//, attachedDimension(0)
 {
 }
 
@@ -69,8 +75,9 @@ printf("Object: Destroyed!\n");
 }
 
 
-/*virtual*/ void Object::PointerMoved(Vector)
+/*virtual*/ bool Object::PointerMoved(Vector)
 {
+       return false;
 }
 
 
@@ -85,6 +92,12 @@ printf("Object: Destroyed!\n");
 }
 
 
+/*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 *)
 {
@@ -133,17 +146,31 @@ printf("Object: Destroyed!\n");
 // 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)
 {
-       for(uint i=0; i<connected.size(); i++)
+       std::vector<Connection>::iterator i;
+
+       for(i=connected.begin(); i!=connected.end(); i++)
        {
-               if (connected[i].object == obj && connected[i].t == parameter)
+               if (((*i).object == obj) && ((*i).t == parameter))
                {
-                       connected.erase(connected.begin() + i);
+                       connected.erase(i);
                        return;
                }
        }
@@ -152,14 +179,12 @@ printf("Object: Destroyed!\n");
 
 /*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();)
+       std::vector<Connection>::iterator i;
+
+       for(i=connected.begin(); i!=connected.end(); )
        {
-               // 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);
+               if ((*i).object == obj)
+                       connected.erase(i);
                else
                        i++;
        }
@@ -181,6 +206,39 @@ printf("Object: Destroyed!\n");
 #endif
 
 
+/*virtual*/ void Object::Translate(Vector amount)
+{
+       position += amount;
+}
+
+
+/*virtual*/ void Object::Rotate(Point, double)
+{
+}
+
+
+/*virtual*/ void Object::Scale(Point, double)
+{
+}
+
+
+/*virtual*/ void Object::Mirror(Point, Point)
+{
+}
+
+
+/*virtual*/ void Object::Save(void)
+{
+       oldPosition = position;
+}
+
+
+/*virtual*/ void Object::Restore(void)
+{
+       position = oldPosition;
+}
+
+
 ObjectState Object::GetState(void)
 {
        return state;
@@ -241,3 +299,25 @@ void Object::SetSnapMode(bool state/*= true*/)
 {
        snapToGrid = state;
 }
+
+
+//
+// This looks strange, but it's really quite simple: We want a point that's
+// more than half-way to the next grid point to snap there while conversely we
+// want a point that's less than half-way to to the next grid point then snap
+// to the one before it. So we add half of the grid spacing to the point, then
+// divide by it so that we can remove the fractional part, then multiply it
+// back to get back to the correct answer.
+//
+Vector Object::SnapPointToGrid(Vector point)
+{
+       point += gridSpacing / 2.0;             // *This* adds to Z!!!
+       point /= gridSpacing;
+       point.x = floor(point.x);//need to fix this for negative numbers...
+       point.y = floor(point.y);
+       point.z = 0;                                    // Make *sure* Z doesn't go anywhere!!!
+       point *= gridSpacing;
+       return point;
+}
+
+