Panda3D
|
00001 // Filename: vrmlNode.cxx 00002 // Created by: drose (23Jun99) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // PANDA 3D SOFTWARE 00006 // Copyright (c) Carnegie Mellon University. All rights reserved. 00007 // 00008 // All use of this software is subject to the terms of the revised BSD 00009 // license. You should have received a copy of this license along 00010 // with this source code in a file named "LICENSE." 00011 //////////////////////////////////////////////////////////////////// 00012 00013 #include "vrmlNode.h" 00014 #include "vrmlParser.h" 00015 00016 #include "indent.h" 00017 #include "pnotify.h" 00018 00019 VrmlNode:: 00020 VrmlNode(const VrmlNodeType *type) { 00021 _type = type; 00022 _use_count = 0; 00023 } 00024 00025 VrmlNode:: 00026 ~VrmlNode() { 00027 } 00028 00029 00030 const VrmlFieldValue &VrmlNode:: 00031 get_value(const char *field_name) const { 00032 Fields::const_iterator fi; 00033 for (fi = _fields.begin(); fi != _fields.end(); ++fi) { 00034 if (strcmp((*fi)._type->name, field_name) == 0) { 00035 return ((*fi)._value); 00036 } 00037 } 00038 00039 // That field was not defined. Get the default value. 00040 const VrmlNodeType::NameTypeRec *field = _type->hasField(field_name); 00041 if (field != NULL) { 00042 return field->dflt; 00043 } 00044 00045 cerr << "No such field defined for type " << _type->getName() << ": " 00046 << field_name << "\n"; 00047 exit(1); 00048 // Just to make the compiler happy. 00049 static VrmlFieldValue zero; 00050 return zero; 00051 } 00052 00053 void VrmlNode:: 00054 output(ostream &out, int indent_level) const { 00055 out << _type->getName() << " {\n"; 00056 Fields::const_iterator fi; 00057 for (fi = _fields.begin(); fi != _fields.end(); ++fi) { 00058 indent(out, indent_level + 2) << (*fi)._type->name << " "; 00059 output_value(out, (*fi)._value, (*fi)._type->type, indent_level + 2) << "\n"; 00060 } 00061 indent(out, indent_level) << "}"; 00062 } 00063 00064 00065 void Declaration:: 00066 output(ostream &out, int indent) const { 00067 VrmlFieldValue v; 00068 v._sfnode = _node; 00069 output_value(out, v, SFNODE, indent); 00070 } 00071 00072 ostream &operator << (ostream &out, const VrmlScene &scene) { 00073 VrmlScene::const_iterator si; 00074 for (si = scene.begin(); si != scene.end(); ++si) { 00075 out << (*si) << "\n"; 00076 } 00077 00078 return out; 00079 }