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