Panda3D

fltInfo.cxx

00001 // Filename: fltInfo.cxx
00002 // Created by:  drose (05Sep01)
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 #include "fltInfo.h"
00016 
00017 #include "fltHeader.h"
00018 #include "indent.h"
00019 #include "pystub.h"
00020 
00021 ////////////////////////////////////////////////////////////////////
00022 //     Function: FltInfo::Constructor
00023 //       Access: Public
00024 //  Description:
00025 ////////////////////////////////////////////////////////////////////
00026 FltInfo::
00027 FltInfo() {
00028   set_program_description
00029     ("This program reads a MultiGen OpenFlight (.flt) file and reports "
00030      "some interesting things about its contents.");
00031 
00032   clear_runlines();
00033   add_runline("[opts] input.flt");
00034 
00035   add_option
00036     ("ls", "", 0,
00037      "List the hierarchy in the flt file.",
00038      &FltInfo::dispatch_none, &_list_hierarchy);
00039 }
00040 
00041 
00042 ////////////////////////////////////////////////////////////////////
00043 //     Function: FltInfo::run
00044 //       Access: Public
00045 //  Description:
00046 ////////////////////////////////////////////////////////////////////
00047 void FltInfo::
00048 run() {
00049   PT(FltHeader) header = new FltHeader(_path_replace);
00050 
00051   nout << "Reading " << _input_filename << "\n";
00052   FltError result = header->read_flt(_input_filename);
00053   if (result != FE_ok) {
00054     nout << "Unable to read: " << result << "\n";
00055     exit(1);
00056   }
00057 
00058   if (header->check_version()) {
00059     nout << "Version is " << header->get_flt_version() / 100.0 << "\n";
00060   }
00061 
00062   if (_list_hierarchy) {
00063     list_hierarchy(header, 0);
00064   }
00065 }
00066 
00067 ////////////////////////////////////////////////////////////////////
00068 //     Function: FltInfo::list_hierarchy
00069 //       Access: Protected
00070 //  Description: Recursively lists the flt file's hierarchy in a
00071 //               meaningful way.
00072 ////////////////////////////////////////////////////////////////////
00073 void FltInfo::
00074 list_hierarchy(FltRecord *record, int indent_level) {
00075   // Maybe in the future we can do something fancier here.
00076   record->write(cout, indent_level);
00077 }
00078 
00079 
00080 ////////////////////////////////////////////////////////////////////
00081 //     Function: FltInfo::handle_args
00082 //       Access: Protected, Virtual
00083 //  Description:
00084 ////////////////////////////////////////////////////////////////////
00085 bool FltInfo::
00086 handle_args(ProgramBase::Args &args) {
00087   if (args.empty()) {
00088     nout << "You must specify the .flt file to read on the command line.\n";
00089     return false;
00090 
00091   } else if (args.size() != 1) {
00092     nout << "You must specify only one .flt file to read on the command line.\n";
00093     return false;
00094   }
00095 
00096   _input_filename = args[0];
00097 
00098   return true;
00099 }
00100 
00101 
00102 int main(int argc, char *argv[]) {
00103   // A call to pystub() to force libpystub.so to be linked in.
00104   pystub();
00105 
00106   FltInfo prog;
00107   prog.parse_command_line(argc, argv);
00108   prog.run();
00109   return 0;
00110 }
 All Classes Functions Variables Enumerations