Debian Codegraph @

src/bin/geomutil/vrml2oogl/lib/QvTraverse.c++

raw
1 #include <QvElement.h>
2 #include <QvNodes.h>
3 #include <QvState.h>
4 #include <QvNode.h>
5 #include <QvUnknownNode.h>
6
7 //////////////////////////////////////////////////////////////////////////////
8 //
9 // Traversal code for all nodes. The default method (in QvNode) does
10 // nothing. Because traverse() is defined in the header for ALL node
11 // classes, each one has an implementation here.
12 //
13 //////////////////////////////////////////////////////////////////////////////
14
15 // For debugging
16 static int indent = 0;
17 static void
18 announce(const char *className)
19 {
20 for (int i = 0; i < indent; i++)
21 printf("\t");
22 printf("Traversing a %s\n", className);
23 }
24 #define ANNOUNCE(className) announce(QV__QUOTE(className))
25
26 #define DEFAULT_TRAVERSE(className) \
27 void \
28 className::traverse(QvState *) \
29 { \
30 ANNOUNCE(className); \
31 }
32
33 //////////////////////////////////////////////////////////////////////////////
34 //
35 // Groups.
36 //
37 //////////////////////////////////////////////////////////////////////////////
38
39 void
40 QvGroup::traverse(QvState *state)
41 {
42 ANNOUNCE(QvGroup);
43 indent++;
44 for (int i = 0; i < getNumChildren(); i++)
45 getChild(i)->traverse(state);
46 indent--;
47 }
48
49 void
50 QvLOD::traverse(QvState *state)
51 {
52 ANNOUNCE(QvLOD);
53 indent++;
54
55 // ??? In a real implementation, this would choose a child based
56 // ??? on the distance to the eye point.
57 if (getNumChildren() > 0)
58 getChild(0)->traverse(state);
59
60 indent--;
61 }
62
63 void
64 QvSeparator::traverse(QvState *state)
65 {
66 ANNOUNCE(QvSeparator);
67 state->push();
68 indent++;
69 for (int i = 0; i < getNumChildren(); i++)
70 getChild(i)->traverse(state);
71 indent--;
72 state->pop();
73 }
74
75 void
76 QvSwitch::traverse(QvState *state)
77 {
78 ANNOUNCE(QvSwitch);
79 indent++;
80
81 int which = whichChild.value;
82
83 if (which == QV_SWITCH_NONE)
84 ;
85
86 else if (which == QV_SWITCH_ALL)
87 for (int i = 0; i < getNumChildren(); i++)
88 getChild(i)->traverse(state);
89
90 else
91 if (which < getNumChildren())
92 getChild(which)->traverse(state);
93
94 indent--;
95 }
96
97 void
98 QvTransformSeparator::traverse(QvState *state)
99 {
100 ANNOUNCE(QvTransformSeparator);
101
102 // We need to "push" just the transformation stack. We'll
103 // accomplish this by just pushing a no-op transformation onto
104 // that stack. When we "pop", we'll restore that stack to its
105 // previous state.
106
107 QvElement *markerElt = new QvElement;
108 markerElt->data = this;
109 markerElt->type = QvElement::NoOpTransform;
110 state->addElement(QvState::TransformationIndex, markerElt);
111
112 indent++;
113 for (int i = 0; i < getNumChildren(); i++)
114 getChild(i)->traverse(state);
115 indent--;
116
117 // Now do the "pop"
118 while (state->getTopElement(QvState::TransformationIndex) != markerElt)
119 state->popElement(QvState::TransformationIndex);
120 }
121
122 //////////////////////////////////////////////////////////////////////////////
123 //
124 // Properties.
125 //
126 //////////////////////////////////////////////////////////////////////////////
127
128 #define DO_PROPERTY(className, stackIndex) \
129 void \
130 className::traverse(QvState *state) \
131 { \
132 ANNOUNCE(className); \
133 QvElement *elt = new QvElement; \
134 elt->data = this; \
135 state->addElement(QvState::stackIndex, elt); \
136 }
137
138 #define DO_TYPED_PROPERTY(className, stackIndex, eltType) \
139 void \
140 className::traverse(QvState *state) \
141 { \
142 ANNOUNCE(className); \
143 QvElement *elt = new QvElement; \
144 elt->data = this; \
145 elt->type = QvElement::eltType; \
146 state->addElement(QvState::stackIndex, elt); \
147 }
148
149 DO_PROPERTY(QvCoordinate3, Coordinate3Index)
150 DO_PROPERTY(QvFontStyle, FontStyleIndex)
151 DO_PROPERTY(QvMaterial, MaterialIndex)
152 DO_PROPERTY(QvMaterialBinding, MaterialBindingIndex)
153 DO_PROPERTY(QvNormal, NormalIndex)
154 DO_PROPERTY(QvNormalBinding, NormalBindingIndex)
155 DO_PROPERTY(QvShapeHints, ShapeHintsIndex)
156 DO_PROPERTY(QvTextureCoordinate2, TextureCoordinate2Index)
157 DO_PROPERTY(QvTexture2, Texture2Index)
158 DO_PROPERTY(QvTexture2Transform, Texture2TransformationIndex)
159
160 DO_TYPED_PROPERTY(QvDirectionalLight, LightIndex, DirectionalLight)
161 DO_TYPED_PROPERTY(QvPointLight, LightIndex, PointLight)
162 DO_TYPED_PROPERTY(QvSpotLight, LightIndex, SpotLight)
163
164 DO_TYPED_PROPERTY(QvOrthographicCamera, CameraIndex, OrthographicCamera)
165 DO_TYPED_PROPERTY(QvPerspectiveCamera, CameraIndex, PerspectiveCamera)
166
167 DO_TYPED_PROPERTY(QvTransform, TransformationIndex, Transform)
168 DO_TYPED_PROPERTY(QvRotation, TransformationIndex, Rotation)
169 DO_TYPED_PROPERTY(QvMatrixTransform, TransformationIndex, MatrixTransform)
170 DO_TYPED_PROPERTY(QvTranslation, TransformationIndex, Translation)
171 DO_TYPED_PROPERTY(QvScale, TransformationIndex, Scale)
172
173 //////////////////////////////////////////////////////////////////////////////
174 //
175 // Shapes.
176 //
177 //////////////////////////////////////////////////////////////////////////////
178
179 static void
180 printProperties(QvState *state)
181 {
182 printf("--------------------------------------------------------------\n");
183 state->print();
184 printf("--------------------------------------------------------------\n");
185 }
186
187 #define DO_SHAPE(className) \
188 void \
189 className::traverse(QvState *state) \
190 { \
191 ANNOUNCE(className); \
192 printProperties(state); \
193 }
194
195 DO_SHAPE(QvAsciiText)
196 DO_SHAPE(QvCone)
197 DO_SHAPE(QvCube)
198 DO_SHAPE(QvCylinder)
199 DO_SHAPE(QvIndexedFaceSet)
200 DO_SHAPE(QvIndexedLineSet)
201 DO_SHAPE(QvPointSet)
202 DO_SHAPE(QvSphere)
203
204 //////////////////////////////////////////////////////////////////////////////
205 //
206 // WWW-specific nodes.
207 //
208 //////////////////////////////////////////////////////////////////////////////
209
210 // ???
211 DEFAULT_TRAVERSE(QvWWWAnchor)
212 DEFAULT_TRAVERSE(QvWWWInline)
213
214 //////////////////////////////////////////////////////////////////////////////
215 //
216 // Default traversal methods. These nodes have no effects during traversal.
217 //
218 //////////////////////////////////////////////////////////////////////////////
219
220 DEFAULT_TRAVERSE(QvInfo)
221 DEFAULT_TRAVERSE(QvUnknownNode)
222
223 //////////////////////////////////////////////////////////////////////////////
224
225 #undef ANNOUNCE
226 #undef DEFAULT_TRAVERSE
227 #undef DO_PROPERTY
228 #undef DO_SHAPE
229 #undef DO_TYPED_PROPERTY