Debian Codegraph @

lib/database/src/so/elements/SoOverrideElement.c++

raw
1 /*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37 /*
38 * Copyright (C) 1995-96 Silicon Graphics, Inc.
39 *
40 _______________________________________________________________________
41 ______________ S I L I C O N G R A P H I C S I N C . ____________
42 |
43 | $Revision: 1.1.1.1 $
44 |
45 | Classes:
46 | SoOverrideElement
47 |
48 | Author(s) : Roger Chickering
49 |
50 ______________ S I L I C O N G R A P H I C S I N C . ____________
51 _______________________________________________________________________
52 */
53
54 #include <Inventor/elements/SoOverrideElement.h>
55 #include <Inventor/elements/SoShapeStyleElement.h>
56
57 SO_ELEMENT_SOURCE(SoOverrideElement);
58
59 ////////////////////////////////////////////////////////////////////////
60 //
61 // Description:
62 // Initializes element. All flags are initialized to FALSE (0).
63 //
64 // Use: public
65
66 void
67 SoOverrideElement::init(SoState *)
68 //
69 ////////////////////////////////////////////////////////////////////////
70 {
71 flags = 0;
72 }
73
74 ////////////////////////////////////////////////////////////////////////
75 //
76 // Description:
77 // Pushes element, copying flags from previous top instance.
78 //
79 // Use: public
80 void
81 SoOverrideElement::push(SoState *state)
82 //
83 ////////////////////////////////////////////////////////////////////////
84 {
85 SoOverrideElement *elt = (SoOverrideElement *)getNextInStack();
86
87 flags = elt->flags;
88 elt->capture(state); // Capture previous element
89 }
90
91 ////////////////////////////////////////////////////////////////////////
92 //
93 // Description:
94 // Create a copy of this instance suitable for calling matches()
95 // on.
96 //
97 // Use: protected
98
99 SoElement *
100 SoOverrideElement::copyMatchInfo() const
101 //
102 ////////////////////////////////////////////////////////////////////////
103 {
104 SoOverrideElement *result =
105 (SoOverrideElement *)getTypeId().createInstance();
106
107 result->flags = flags;
108
109 return result;
110 }
111 /////////////////////////////////////////////////////////////////////////
112 //
113 // Description: set diffuseColorOverride (plus set shapeStyle)
114 //
115 //
116 // Use: static, public.
117 /////////////////////////////////////////////////////////////////////////
118 void
119 SoOverrideElement::setDiffuseColorOverride(SoState *state, SoNode *,
120 SbBool override)
121 {
122 SoOverrideElement *elt =
123 (SoOverrideElement *)getElement(state, classStackIndex);
124 if (elt != NULL) {
125 if (override){
126 elt->flags |= DIFFUSE_COLOR;
127 SoShapeStyleElement::setOverrides(state, TRUE);
128 }
129 else {
130 elt->flags &= ~DIFFUSE_COLOR;
131 if (!(elt->flags & MATERIAL_BINDING))
132 SoShapeStyleElement::setOverrides(state, FALSE);
133 }
134 }
135 }
136
137 /////////////////////////////////////////////////////////////////////////
138 //
139 // Description: set transparencyOverride (plus set shapeStyle)
140 // This is same as diffuse color override
141 //
142 // Use: static, public.
143 /////////////////////////////////////////////////////////////////////////
144 void
145 SoOverrideElement::setTransparencyOverride(SoState *state, SoNode *,
146 SbBool override)
147 {
148 SoOverrideElement *elt =
149 (SoOverrideElement *)getElement(state, classStackIndex);
150 if (elt != NULL) {
151 if (override){
152 elt->flags |= TRANSPARENCY;
153 SoShapeStyleElement::setOverrides(state, TRUE);
154 }
155 else {
156 elt->flags &= ~TRANSPARENCY;
157 if (!(elt->flags & MATERIAL_BINDING))
158 SoShapeStyleElement::setOverrides(state, FALSE);
159 }
160 }
161 }
162 /////////////////////////////////////////////////////////////////////////
163 //
164 // Description: set Material Binding Override (plus set shapeStyle)
165 //
166 //
167 // Use: static, public.
168 /////////////////////////////////////////////////////////////////////////
169 void
170 SoOverrideElement::setMaterialBindingOverride(SoState *state, SoNode *,
171 SbBool override)
172 {
173 SoOverrideElement *elt =
174 (SoOverrideElement *)getElement(state, classStackIndex);
175 if (elt != NULL) {
176 if (override){
177 elt->flags |= MATERIAL_BINDING;
178 SoShapeStyleElement::setOverrides(state, TRUE);
179 }
180 else {
181 elt->flags &= ~MATERIAL_BINDING;
182 if (!(elt->flags & (DIFFUSE_COLOR|TRANSPARENCY)))
183 SoShapeStyleElement::setOverrides(state, FALSE);
184 }
185 }
186 }
187 ////////////////////////////////////////////////////////////////////////
188 //
189 // Description:
190 // Returns TRUE if elements match
191 //
192 // Use: public
193
194 SbBool
195 SoOverrideElement::matches(const SoElement *elt) const
196 //
197 ////////////////////////////////////////////////////////////////////////
198 {
199 return (flags == ((const SoOverrideElement *) elt)->flags);
200 }
201
202 ////////////////////////////////////////////////////////////////////////
203 //
204 // Description:
205 // Prints element for debugging.
206 //
207 // Use: public
208 //
209 ////////////////////////////////////////////////////////////////////////
210
211 #ifdef DEBUG
212 void
213 SoOverrideElement::print(FILE *fp) const
214 {
215 pFlag(fp, "AMBIENT_COLOR", AMBIENT_COLOR);
216 pFlag(fp, "COLOR_INDEX", COLOR_INDEX);
217 pFlag(fp, "COMPLEXITY", COMPLEXITY);
218 pFlag(fp, "COMPLEXITY_TYPE", COMPLEXITY_TYPE);
219 pFlag(fp, "CREASE_ANGLE", CREASE_ANGLE);
220 pFlag(fp, "DIFFUSE_COLOR", DIFFUSE_COLOR);
221 pFlag(fp, "DRAW_STYLE", DRAW_STYLE);
222 pFlag(fp, "EMISSIVE_COLOR", EMISSIVE_COLOR);
223 pFlag(fp, "FONT_NAME", FONT_NAME);
224 pFlag(fp, "FONT_SIZE", FONT_SIZE);
225 pFlag(fp, "LIGHT_MODEL", LIGHT_MODEL);
226 pFlag(fp, "LINE_PATTERN", LINE_PATTERN);
227 pFlag(fp, "LINE_WIDTH", LINE_WIDTH);
228 pFlag(fp, "POINT_SIZE", POINT_SIZE);
229 pFlag(fp, "PICK_STYLE", PICK_STYLE);
230 pFlag(fp, "SHAPE_HINTS", SHAPE_HINTS);
231 pFlag(fp, "SHININESS", SHININESS);
232 pFlag(fp, "SPECULAR_COLOR", SPECULAR_COLOR);
233 pFlag(fp, "TRANSPARENCY", TRANSPARENCY);
234 putc('\n', fp);
235 }
236 #else /* DEBUG */
237 void
238 SoOverrideElement::print(FILE *) const
239 {
240 }
241 #endif /* DEBUG */
242
243 void
244 SoOverrideElement::pFlag(FILE *fp, const char *flagName, int flagBit) const
245 {
246 if (flags & flagBit)
247 fprintf(fp, "%s\t", flagName);
248 }