Panda3D
fltInfo.cxx
1 // Filename: fltInfo.cxx
2 // Created by: drose (05Sep01)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "fltInfo.h"
16 
17 #include "fltHeader.h"
18 #include "indent.h"
19 #include "pystub.h"
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: FltInfo::Constructor
23 // Access: Public
24 // Description:
25 ////////////////////////////////////////////////////////////////////
26 FltInfo::
27 FltInfo() {
28  set_program_brief("describe the contents of a MultiGen .flt file");
29  set_program_description
30  ("This program reads a MultiGen OpenFlight (.flt) file and reports "
31  "some interesting things about its contents.");
32 
33  clear_runlines();
34  add_runline("[opts] input.flt");
35 
36  add_option
37  ("ls", "", 0,
38  "List the hierarchy in the flt file.",
39  &FltInfo::dispatch_none, &_list_hierarchy);
40 }
41 
42 
43 ////////////////////////////////////////////////////////////////////
44 // Function: FltInfo::run
45 // Access: Public
46 // Description:
47 ////////////////////////////////////////////////////////////////////
48 void FltInfo::
49 run() {
50  PT(FltHeader) header = new FltHeader(_path_replace);
51 
52  nout << "Reading " << _input_filename << "\n";
53  FltError result = header->read_flt(_input_filename);
54  if (result != FE_ok) {
55  nout << "Unable to read: " << result << "\n";
56  exit(1);
57  }
58 
59  if (header->check_version()) {
60  nout << "Version is " << header->get_flt_version() / 100.0 << "\n";
61  }
62 
63  if (_list_hierarchy) {
64  list_hierarchy(header, 0);
65  }
66 }
67 
68 ////////////////////////////////////////////////////////////////////
69 // Function: FltInfo::list_hierarchy
70 // Access: Protected
71 // Description: Recursively lists the flt file's hierarchy in a
72 // meaningful way.
73 ////////////////////////////////////////////////////////////////////
74 void FltInfo::
75 list_hierarchy(FltRecord *record, int indent_level) {
76  // Maybe in the future we can do something fancier here.
77  record->write(cout, indent_level);
78 }
79 
80 
81 ////////////////////////////////////////////////////////////////////
82 // Function: FltInfo::handle_args
83 // Access: Protected, Virtual
84 // Description:
85 ////////////////////////////////////////////////////////////////////
86 bool FltInfo::
87 handle_args(ProgramBase::Args &args) {
88  if (args.empty()) {
89  nout << "You must specify the .flt file to read on the command line.\n";
90  return false;
91 
92  } else if (args.size() != 1) {
93  nout << "You must specify only one .flt file to read on the command line.\n";
94  return false;
95  }
96 
97  _input_filename = args[0];
98 
99  return true;
100 }
101 
102 
103 int main(int argc, char *argv[]) {
104  // A call to pystub() to force libpystub.so to be linked in.
105  pystub();
106 
107  FltInfo prog;
108  prog.parse_command_line(argc, argv);
109  prog.run();
110  return 0;
111 }
virtual void parse_command_line(int argc, char **argv)
Dispatches on each of the options on the command line, and passes the remaining parameters to handle_...
This is the first bead in the file, the top of the bead hierarchy, and the primary interface to readi...
Definition: fltHeader.h:48
The base class for all kinds of records in a MultiGen OpenFlight file.
Definition: fltRecord.h:40
A program to read a flt file and report interesting things about it.
Definition: fltInfo.h:29
virtual void write(ostream &out, int indent_level=0) const
Writes a multiple-line description of the record and all of its children.
Definition: fltRecord.cxx:372