Panda3D
|
00001 // Filename: xFileNode.h 00002 // Created by: drose (03Oct04) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef XFILENODE_H 00016 #define XFILENODE_H 00017 00018 #include "pandatoolbase.h" 00019 #include "typedObject.h" 00020 #include "referenceCount.h" 00021 #include "pointerTo.h" 00022 #include "namable.h" 00023 #include "pnotify.h" 00024 #include "pvector.h" 00025 #include "pmap.h" 00026 #include "luse.h" 00027 00028 class XFile; 00029 class WindowsGuid; 00030 class XFileParseDataList; 00031 class XFileDataDef; 00032 class XFileDataObject; 00033 class XFileDataNode; 00034 class XFileDataNodeTemplate; 00035 class Filename; 00036 00037 //////////////////////////////////////////////////////////////////// 00038 // Class : XFileNode 00039 // Description : A single node of an X file. This may be either a 00040 // template or a data node. 00041 //////////////////////////////////////////////////////////////////// 00042 class XFileNode : public TypedObject, public Namable, 00043 virtual public ReferenceCount { 00044 public: 00045 XFileNode(XFile *x_file, const string &name); 00046 virtual ~XFileNode(); 00047 00048 INLINE XFile *get_x_file() const; 00049 00050 INLINE int get_num_children() const; 00051 INLINE XFileNode *get_child(int n) const; 00052 XFileNode *find_child(const string &name) const; 00053 int find_child_index(const string &name) const; 00054 int find_child_index(const XFileNode *child) const; 00055 XFileNode *find_descendent(const string &name) const; 00056 00057 INLINE int get_num_objects() const; 00058 INLINE XFileDataNode *get_object(int n) const; 00059 00060 virtual bool has_guid() const; 00061 virtual const WindowsGuid &get_guid() const; 00062 00063 virtual bool is_template_def() const; 00064 virtual bool is_reference() const; 00065 virtual bool is_object() const; 00066 virtual bool is_standard_object(const string &template_name) const; 00067 00068 void add_child(XFileNode *node); 00069 virtual void clear(); 00070 00071 virtual void write_text(ostream &out, int indent_level) const; 00072 00073 typedef pmap<const XFileDataDef *, XFileDataObject *> PrevData; 00074 00075 virtual bool repack_data(XFileDataObject *object, 00076 const XFileParseDataList &parse_data_list, 00077 PrevData &prev_data, 00078 size_t &index, size_t &sub_index) const; 00079 00080 virtual bool fill_zero_data(XFileDataObject *object) const; 00081 00082 virtual bool matches(const XFileNode *other) const; 00083 00084 // The following methods can be used to create instances of the 00085 // standard template objects. These definitions match those defined 00086 // in standardTemplates.x in this directory (and compiled into the 00087 // executable). 00088 XFileDataNode *add_Mesh(const string &name); 00089 XFileDataNode *add_MeshNormals(const string &name); 00090 XFileDataNode *add_MeshVertexColors(const string &name); 00091 XFileDataNode *add_MeshTextureCoords(const string &name); 00092 XFileDataNode *add_MeshMaterialList(const string &name); 00093 XFileDataNode *add_Material(const string &name, const LColor &face_color, 00094 double power, const LRGBColor &specular_color, 00095 const LRGBColor &emissive_color); 00096 XFileDataNode *add_TextureFilename(const string &name, 00097 const Filename &filename); 00098 XFileDataNode *add_Frame(const string &name); 00099 XFileDataNode *add_FrameTransformMatrix(const LMatrix4d &mat); 00100 00101 public: 00102 static string make_nice_name(const string &str); 00103 00104 protected: 00105 XFile *_x_file; 00106 00107 typedef pvector< PT(XFileNode) > Children; 00108 Children _children; 00109 00110 typedef pvector<XFileDataNode *> Objects; 00111 Objects _objects; 00112 00113 typedef pmap<string, int> ChildrenByName; 00114 ChildrenByName _children_by_name; 00115 00116 public: 00117 static TypeHandle get_class_type() { 00118 return _type_handle; 00119 } 00120 static void init_type() { 00121 TypedObject::init_type(); 00122 ReferenceCount::init_type(); 00123 register_type(_type_handle, "XFileNode", 00124 TypedObject::get_class_type(), 00125 ReferenceCount::get_class_type()); 00126 } 00127 virtual TypeHandle get_type() const { 00128 return get_class_type(); 00129 } 00130 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00131 00132 private: 00133 static TypeHandle _type_handle; 00134 00135 friend class XFileDataNodeReference; 00136 }; 00137 00138 #include "xFileNode.I" 00139 00140 #endif 00141 00142 00143