15 #include "vrmlNodeType.h" 17 #include "vrmlParser.h" 32 output_array(ostream &out,
const MFArray *mf,
33 int type,
int indent_level,
int items_per_row) {
38 MFArray::const_iterator mi;
40 for (mi = mf->begin(); mi != mf->end(); ++mi) {
43 indent(out, indent_level + 2);
45 output_value(out, (*mi), type, indent_level + 2);
46 if (++col >= items_per_row) {
53 indent(out, indent_level) <<
"]";
63 return out << (value._sfbool ?
"TRUE" :
"FALSE");
67 return out << value._sffloat;
70 return out << value._sfint32;
75 for (
const char *p = value._sfstring; *p !=
'\0'; p++) {
86 return out << value._sfvec[0] <<
" " << value._sfvec[1];
90 return out << value._sfvec[0] <<
" " << value._sfvec[1] <<
" " 94 return out << value._sfvec[0] <<
" " << value._sfvec[1] <<
" " 95 << value._sfvec[2] <<
" " << value._sfvec[3];
98 switch (value._sfnode._type) {
99 case SFNodeRef::T_null:
100 return out <<
"NULL";
102 case SFNodeRef::T_unnamed:
103 nassertr(value._sfnode._p !=
nullptr, out);
104 value._sfnode._p->output(out,
indent);
107 case SFNodeRef::T_def:
108 out <<
"DEF " << value._sfnode._name <<
" ";
109 value._sfnode._p->output(out,
indent);
112 case SFNodeRef::T_use:
113 return out <<
"USE " << value._sfnode._name;
115 return out <<
"(invalid)";
118 return out <<
"(image)";
121 return output_array(out, value._mf, SFCOLOR,
indent, 1);
124 return output_array(out, value._mf, SFFLOAT,
indent, 5);
127 return output_array(out, value._mf, SFINT32,
indent, 10);
130 return output_array(out, value._mf, SFROTATION,
indent, 1);
133 return output_array(out, value._mf, SFSTRING,
indent, 1);
136 return output_array(out, value._mf, SFVEC2F,
indent, 1);
139 return output_array(out, value._mf, SFVEC3F,
indent, 1);
142 return output_array(out, value._mf, SFNODE,
indent, 1);
145 return out <<
"(unknown)";
148 VrmlNodeType::VrmlNodeType(
const char *nm)
150 nassertv(nm !=
nullptr);
154 VrmlNodeType::~VrmlNodeType()
159 plist<NameTypeRec*>::iterator i;
161 for (i = eventIns.begin(); i != eventIns.end(); i++) {
166 for (i = eventOuts.begin(); i != eventOuts.end(); i++) {
171 for (i = fields.begin(); i != fields.end(); i++) {
181 if (find(_type->getName()) !=
nullptr) {
182 std::cerr <<
"PROTO " << _type->getName() <<
" already defined\n";
185 typeList.push_front(_type);
194 VrmlNodeType::pushNameSpace()
196 typeList.push_front(
nullptr);
200 VrmlNodeType::popNameSpace()
204 for (i = typeList.begin(); i != typeList.end();) {
207 typeList.pop_front();
209 if (nodeType ==
nullptr) {
223 VrmlNodeType::find(
const char *_name)
227 for (i = typeList.begin(); i != typeList.end(); i++) {
229 if (nt !=
nullptr && strcmp(nt->getName(),_name) == 0) {
237 VrmlNodeType::addEventIn(
const char *name,
int type,
240 add(eventIns, name, type, dflt);
243 VrmlNodeType::addEventOut(
const char *name,
int type,
246 add(eventOuts, name, type, dflt);
249 VrmlNodeType::addField(
const char *name,
int type,
252 add(fields, name, type, dflt);
255 VrmlNodeType::addExposedField(
const char *name,
int type,
259 add(fields, name, type, dflt);
260 sprintf(tmp,
"set_%s", name);
261 add(eventIns, tmp, type, dflt);
262 sprintf(tmp,
"%s_changed", name);
263 add(eventOuts, tmp, type, dflt);
270 NameTypeRec *r =
new NameTypeRec;
271 r->name = strdup(name);
273 if (dflt !=
nullptr) {
276 memset(&r->dflt, 0,
sizeof(r->dflt));
282 VrmlNodeType::hasEventIn(
const char *name)
const 284 return has(eventIns, name);
288 VrmlNodeType::hasEventOut(
const char *name)
const 290 return has(eventOuts, name);
294 VrmlNodeType::hasField(
const char *name)
const 296 return has(fields, name);
300 VrmlNodeType::hasExposedField(
const char *name)
const 305 const NameTypeRec *base, *set_name, *name_changed;
307 base = has(fields, name);
309 sprintf(tmp,
"set_%s\n", name);
310 nassertr(strlen(tmp) < 1000,
nullptr);
311 set_name = has(eventIns, tmp);
313 sprintf(tmp,
"%s_changed\n", name);
314 nassertr(strlen(tmp) < 1000,
nullptr);
315 name_changed = has(eventOuts, tmp);
317 if (base ==
nullptr || set_name ==
nullptr || name_changed ==
nullptr) {
321 if (base->type != set_name->type || base->type != name_changed->type) {
331 plist<NameTypeRec*>::const_iterator i;
332 for (i = recs.begin(); i != recs.end(); i++) {
333 if (strcmp((*i)->name, name) == 0)
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.