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

pandatool/src/fltprogs/fltTrans.cxx

Go to the documentation of this file.
00001 // Filename: fltTrans.cxx
00002 // Created by:  drose (11Apr01)
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 "fltTrans.h"
00020 
00021 #include <fltHeader.h>
00022 
00023 ////////////////////////////////////////////////////////////////////
00024 //     Function: FltTrans::Constructor
00025 //       Access: Public
00026 //  Description:
00027 ////////////////////////////////////////////////////////////////////
00028 FltTrans::
00029 FltTrans() :
00030   WithOutputFile(true, false, true)
00031 {
00032   // Indicate the extension name we expect the user to supply for
00033   // output files.
00034   _preferred_extension = ".flt";
00035 
00036   set_program_description
00037     ("This program reads a MultiGen OpenFlight (.flt) file and writes an "
00038      "essentially equivalent .flt file, to the file specified with -o (or "
00039      "as the second parameter).  Some simple operations may be performed.");
00040 
00041   clear_runlines();
00042   add_runline("[opts] input.flt output.flt");
00043   add_runline("[opts] -o output.flt input.flt");
00044 
00045   add_path_replace_options();
00046   add_path_store_options();
00047 
00048   add_option
00049     ("v", "version", 0,
00050      "Upgrade (or downgrade) the flt file to the indicated version.  This "
00051      "may not be completely correct for all version-to-version combinations.",
00052      &FltTrans::dispatch_double, &_got_new_version, &_new_version);
00053 
00054   add_option
00055     ("o", "filename", 0,
00056      "Specify the filename to which the resulting .flt file will be written.  "
00057      "If this option is omitted, the last parameter name is taken to be the "
00058      "name of the output file.",
00059      &FltTrans::dispatch_filename, &_got_output_filename, &_output_filename);
00060 }
00061 
00062 
00063 ////////////////////////////////////////////////////////////////////
00064 //     Function: FltTrans::run
00065 //       Access: Public
00066 //  Description:
00067 ////////////////////////////////////////////////////////////////////
00068 void FltTrans::
00069 run() {
00070   if (_got_new_version) {
00071     int new_version = (int)floor(_new_version * 100.0 + 0.5);
00072     if (new_version < FltHeader::min_flt_version() ||
00073         new_version > FltHeader::max_flt_version()) {
00074       nout << "Cannot write flt files of version " << new_version / 100.0
00075            << ".  This program only understands how to write flt files between version "
00076            << FltHeader::min_flt_version() / 100.0 << " and "
00077            << FltHeader::max_flt_version() / 100.0 << ".\n";
00078       exit(1);
00079     }
00080   }
00081 
00082   PT(FltHeader) header = new FltHeader(_path_replace);
00083 
00084   nout << "Reading " << _input_filename << "\n";
00085   FltError result = header->read_flt(_input_filename);
00086   if (result != FE_ok) {
00087     nout << "Unable to read: " << result << "\n";
00088     exit(1);
00089   }
00090 
00091   if (header->check_version()) {
00092     nout << "Version is " << header->get_flt_version() / 100.0 << "\n";
00093   }
00094 
00095   if (_got_new_version) {
00096     int new_version = (int)floor(_new_version * 100.0 + 0.5);
00097     header->set_flt_version(new_version);
00098   }
00099 
00100   header->apply_converted_filenames();
00101 
00102   result = header->write_flt(get_output());
00103   if (result != FE_ok) {
00104     nout << "Unable to write: " << result << "\n";
00105     exit(1);
00106   }
00107 
00108   nout << "Successfully written.\n";
00109 }
00110 
00111 
00112 ////////////////////////////////////////////////////////////////////
00113 //     Function: FltTrans::handle_args
00114 //       Access: Protected, Virtual
00115 //  Description:
00116 ////////////////////////////////////////////////////////////////////
00117 bool FltTrans::
00118 handle_args(ProgramBase::Args &args) {
00119   if (!check_last_arg(args, 1)) {
00120     return false;
00121   }
00122 
00123   if (args.empty()) {
00124     nout << "You must specify the .flt file to read on the command line.\n";
00125     return false;
00126 
00127   } else if (args.size() != 1) {
00128     nout << "You must specify only one .flt file to read on the command line.\n";
00129     return false;
00130   }
00131 
00132   _input_filename = args[0];
00133 
00134   return true;
00135 }
00136 
00137 
00138 int main(int argc, char *argv[]) {
00139   FltTrans prog;
00140   prog.parse_command_line(argc, argv);
00141   prog.run();
00142   return 0;
00143 }

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