]> Shamusworld >> Repos - architektonas/blob - src/object.cpp
8f9377bf7345624c61acffb6b9de11735a4ec656
[architektonas] / src / object.cpp
1 //
2 // object.cpp: Base class for all CAD objects
3 //
4 // Part of the Architektonas Project
5 // (C) 2011 Underground Software
6 // See the README and GPLv3 files for licensing and warranty information
7 //
8 // JLH = James Hammons <jlhamm@acm.org>
9 //
10 // WHO  WHEN        WHAT
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)
16 //
17
18 #include "object.h"
19
20 // Initialize static variables
21 bool Object::fixedAngle = false;
22 bool Object::fixedLength = false;
23 QFont * Object::font = 0;
24 int Object::viewportHeight = 0;
25 bool Object::deleteActive = false;
26 bool Object::dimensionActive = false;
27 bool Object::snapToGrid = true;
28
29
30 Object::Object(): position(Vector(0, 0)), parent(0), state(OSInactive), oldState(OSInactive),
31         needUpdate(false), attachedDimension(0)
32 {
33 }
34
35
36 Object::Object(Vector v,  Object * passedInParent/*= 0*/): position(v), parent(passedInParent),
37         state(OSInactive), oldState(OSInactive), needUpdate(false), attachedDimension(0)
38 {
39 }
40
41
42 Object::~Object()
43 {
44 }
45
46
47 /*virtual*/ void Object::Draw(Painter *)
48 {
49 }
50
51
52 /*virtual*/ Vector Object::Center(void)
53 {
54         return Vector();
55 }
56
57
58 /*virtual*/ bool Object::Collided(Vector)
59 {
60         return false;
61 }
62
63
64 /*virtual*/ void Object::PointerMoved(Vector)
65 {
66 }
67
68
69 /*virtual*/ void Object::PointerReleased(void)
70 {
71 }
72
73
74 /*virtual*/ bool Object::NeedsUpdate(void)
75 {
76         return needUpdate;
77 }
78
79
80 // This is intended to be overridden by the Container class, for object morphing
81 /*virtual*/ void Object::Transmute(Object *, Object *)
82 {
83 }
84
85
86 /*virtual*/ Object * Object::GetParent(void)
87 {
88         return parent;
89 }
90
91
92 /*virtual*/ void Object::Add(Object *)
93 {
94 }
95
96
97 // This returns a pointer to the point passed in, if it coincides. Otherwise returns NULL.
98 /*virtual*/ Vector * Object::GetPointAt(Vector)
99 {
100         return 0;
101 }
102
103
104 // This is meant for writing object data to a file.
105 /*virtual*/ void Object::Enumerate(FILE *)
106 {
107 }
108
109
110 /*virtual*/ Object * Object::Copy(void)
111 {
112         return new Object(position, parent);
113 }
114
115
116 ObjectState Object::GetState(void)
117 {
118         return state;
119 }
120
121
122 void Object::Reparent(Object * newParent)
123 {
124         parent = newParent;
125 }
126
127
128 Dimension * Object::GetAttachedDimension(void)
129 {
130         return attachedDimension;
131 }
132
133
134 // Class methods...
135
136 void Object::SetFixedAngle(bool state/*= true*/)
137 {
138         fixedAngle = state;
139 }
140
141
142 void Object::SetFixedLength(bool state/*= true*/)
143 {
144         fixedLength = state;
145 }
146
147
148 void Object::SetFont(QFont * f)
149 {
150         font = f;
151 }
152
153
154 void Object::SetViewportHeight(int height)
155 {
156         viewportHeight = height;
157 }
158
159
160 void Object::SetDeleteActive(bool state/*= true*/)
161 {
162         deleteActive = state;
163 }
164
165
166 void Object::SetDimensionActive(bool state/*= true*/)
167 {
168         dimensionActive = state;
169 }
170
171
172 void Object::SetSnapMode(bool state/*= true*/)
173 {
174         snapToGrid = state;
175 }