Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

pandatool/src/eggbase/eggBase.cxx

Go to the documentation of this file.
00001 // Filename: eggBase.cxx
00002 // Created by:  drose (14Feb00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include "eggBase.h"
00020 
00021 #include "eggGroupNode.h"
00022 #include "eggTexture.h"
00023 #include "eggFilenameNode.h"
00024 #include "eggComment.h"
00025 #include "dcast.h"
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //     Function: EggBase::Constructor
00029 //       Access: Public
00030 //  Description:
00031 ////////////////////////////////////////////////////////////////////
00032 EggBase::
00033 EggBase() {
00034   add_option
00035     ("cs", "coordinate-system", 80,
00036      "Specify the coordinate system to operate in.  This may be one of "
00037      "'y-up', 'z-up', 'y-up-left', or 'z-up-left'.",
00038      &EggBase::dispatch_coordinate_system,
00039      &_got_coordinate_system, &_coordinate_system);
00040 
00041   _coordinate_system = CS_yup_right;
00042 }
00043 
00044 ////////////////////////////////////////////////////////////////////
00045 //     Function: EggBase::as_reader
00046 //       Access: Public, Virtual
00047 //  Description: Returns this object as an EggReader pointer, if it is
00048 //               in fact an EggReader, or NULL if it is not.
00049 //
00050 //               This is intended to work around the C++ limitation
00051 //               that prevents downcasts past virtual inheritance.
00052 //               Since both EggReader and EggWriter inherit virtually
00053 //               from EggBase, we need functions like this to downcast
00054 //               to the appropriate pointer.
00055 ////////////////////////////////////////////////////////////////////
00056 EggReader *EggBase::
00057 as_reader() {
00058   return (EggReader *)NULL;
00059 }
00060 
00061 ////////////////////////////////////////////////////////////////////
00062 //     Function: EggBase::as_writer
00063 //       Access: Public, Virtual
00064 //  Description: Returns this object as an EggWriter pointer, if it is
00065 //               in fact an EggWriter, or NULL if it is not.
00066 //
00067 //               This is intended to work around the C++ limitation
00068 //               that prevents downcasts past virtual inheritance.
00069 //               Since both EggReader and EggWriter inherit virtually
00070 //               from EggBase, we need functions like this to downcast
00071 //               to the appropriate pointer.
00072 ////////////////////////////////////////////////////////////////////
00073 EggWriter *EggBase::
00074 as_writer() {
00075   return (EggWriter *)NULL;
00076 }
00077 
00078 ////////////////////////////////////////////////////////////////////
00079 //     Function: EggBase::convert_paths
00080 //       Access: Public, Static
00081 //  Description: Recursively walks the egg hierarchy.  Any filenames
00082 //               encountered are replaced according to the indicated
00083 //               PathReplace.
00084 ////////////////////////////////////////////////////////////////////
00085 void EggBase::
00086 convert_paths(EggNode *node, PathReplace *path_replace,
00087               const DSearchPath &additional_path) {
00088   if (node->is_of_type(EggTexture::get_class_type())) {
00089     EggTexture *egg_tex = DCAST(EggTexture, node);
00090     Filename fullpath = 
00091       path_replace->match_path(egg_tex->get_filename(), additional_path);
00092     egg_tex->set_filename(path_replace->store_path(fullpath));
00093     egg_tex->set_fullpath(fullpath);
00094 
00095     if (egg_tex->has_alpha_filename()) {
00096       Filename alpha_fullpath = 
00097         path_replace->match_path(egg_tex->get_alpha_filename(), additional_path);
00098       egg_tex->set_alpha_filename(path_replace->store_path(alpha_fullpath));
00099       egg_tex->set_alpha_fullpath(alpha_fullpath);
00100     }
00101 
00102   } else if (node->is_of_type(EggFilenameNode::get_class_type())) {
00103     EggFilenameNode *egg_fnode = DCAST(EggFilenameNode, node);
00104 
00105     Filename fullpath = 
00106       path_replace->match_path(egg_fnode->get_filename(), additional_path);
00107     egg_fnode->set_filename(path_replace->store_path(fullpath));
00108     egg_fnode->set_fullpath(fullpath);
00109 
00110   } else if (node->is_of_type(EggGroupNode::get_class_type())) {
00111     EggGroupNode *egg_group = DCAST(EggGroupNode, node);
00112     EggGroupNode::const_iterator ci;
00113     for (ci = egg_group->begin(); ci != egg_group->end(); ++ci) {
00114       convert_paths(*ci, path_replace, additional_path);
00115     }
00116   }
00117 }
00118 
00119 ////////////////////////////////////////////////////////////////////
00120 //     Function: EggBase::post_command_line
00121 //       Access: Protected, Virtual
00122 //  Description:
00123 ////////////////////////////////////////////////////////////////////
00124 bool EggBase::
00125 post_command_line() {
00126   if (_got_coordinate_system) {
00127     _data.set_coordinate_system(_coordinate_system);
00128   }
00129 
00130   return ProgramBase::post_command_line();
00131 }
00132 
00133 
00134 ////////////////////////////////////////////////////////////////////
00135 //     Function: EggBase::append_command_comment
00136 //       Access: Protected
00137 //  Description: Inserts a comment into the beginning of the indicated
00138 //               egg file corresponding to the command line that
00139 //               invoked this program.
00140 //
00141 //               Normally this function is called automatically when
00142 //               appropriate by EggWriter, and it's not necessary to
00143 //               call it explicitly.
00144 ////////////////////////////////////////////////////////////////////
00145 void EggBase::
00146 append_command_comment(EggData &data) {
00147   append_command_comment(data, get_exec_command());
00148 }
00149 
00150 ////////////////////////////////////////////////////////////////////
00151 //     Function: EggBase::append_command_comment
00152 //       Access: Protected, Static
00153 //  Description: Inserts a comment into the beginning of the indicated
00154 //               egg file corresponding to the command line that
00155 //               invoked this program.
00156 //
00157 //               Normally this function is called automatically when
00158 //               appropriate by EggWriter, and it's not necessary to
00159 //               call it explicitly.
00160 ////////////////////////////////////////////////////////////////////
00161 void EggBase::
00162 append_command_comment(EggData &data, const string &comment) {
00163   data.insert(data.begin(), new EggComment("", comment));
00164 }

Generated on Fri May 2 03:18:34 2003 for Panda-Tool by doxygen1.3