Panda3D
fltTrans.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 fltTrans.cxx
10  * @author drose
11  * @date 2001-04-11
12  */
13 
14 #include "fltTrans.h"
15 
16 #include "fltHeader.h"
17 
18 /**
19  *
20  */
21 FltTrans::
22 FltTrans() :
23  WithOutputFile(true, false, true)
24 {
25  // Indicate the extension name we expect the user to supply for output
26  // files.
27  _preferred_extension = ".flt";
28 
29  set_program_brief("apply various operations to a MultiGen .flt file");
30  set_program_description
31  ("This program reads a MultiGen OpenFlight (.flt) file and writes an "
32  "essentially equivalent .flt file, to the file specified with -o (or "
33  "as the second parameter). Some simple operations may be performed.");
34 
35  clear_runlines();
36  add_runline("[opts] input.flt output.flt");
37  add_runline("[opts] -o output.flt input.flt");
38 
39  add_path_replace_options();
40  add_path_store_options();
41 
42  add_option
43  ("v", "version", 0,
44  "Upgrade (or downgrade) the flt file to the indicated version. This "
45  "may not be completely correct for all version-to-version combinations.",
46  &FltTrans::dispatch_double, &_got_new_version, &_new_version);
47 
48  add_option
49  ("o", "filename", 0,
50  "Specify the filename to which the resulting .flt file will be written. "
51  "If this option is omitted, the last parameter name is taken to be the "
52  "name of the output file.",
53  &FltTrans::dispatch_filename, &_got_output_filename, &_output_filename);
54 }
55 
56 
57 /**
58  *
59  */
60 void FltTrans::
61 run() {
62  if (_got_new_version) {
63  int new_version = (int)floor(_new_version * 100.0 + 0.5);
64  if (new_version < FltHeader::min_flt_version() ||
65  new_version > FltHeader::max_flt_version()) {
66  nout << "Cannot write flt files of version " << new_version / 100.0
67  << ". This program only understands how to write flt files between version "
68  << FltHeader::min_flt_version() / 100.0 << " and "
69  << FltHeader::max_flt_version() / 100.0 << ".\n";
70  exit(1);
71  }
72  }
73 
74  PT(FltHeader) header = new FltHeader(_path_replace);
75 
76  nout << "Reading " << _input_filename << "\n";
77  FltError result = header->read_flt(_input_filename);
78  if (result != FE_ok) {
79  nout << "Unable to read: " << result << "\n";
80  exit(1);
81  }
82 
83  if (header->check_version()) {
84  nout << "Version is " << header->get_flt_version() / 100.0 << "\n";
85  }
86 
87  if (_got_new_version) {
88  int new_version = (int)floor(_new_version * 100.0 + 0.5);
89  header->set_flt_version(new_version);
90  }
91 
92  header->apply_converted_filenames();
93 
94  result = header->write_flt(get_output());
95  if (result != FE_ok) {
96  nout << "Unable to write: " << result << "\n";
97  exit(1);
98  }
99 
100  nout << "Successfully written.\n";
101 }
102 
103 
104 /**
105  *
106  */
107 bool FltTrans::
108 handle_args(ProgramBase::Args &args) {
109  if (!check_last_arg(args, 1)) {
110  return false;
111  }
112 
113  if (args.empty()) {
114  nout << "You must specify the .flt file to read on the command line.\n";
115  return false;
116 
117  } else if (args.size() != 1) {
118  nout << "You must specify only one .flt file to read on the command line.\n";
119  return false;
120  }
121 
122  _input_filename = args[0];
123 
124  return true;
125 }
126 
127 
128 int main(int argc, char *argv[]) {
129  FltTrans prog;
130  prog.parse_command_line(argc, argv);
131  prog.run();
132  return 0;
133 }
A program to read a flt file and write an equivalent flt file, possibly performing some minor operati...
Definition: fltTrans.h:26
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_...
static int max_flt_version()
Returns the latest flt version number that this codebase is known to support (times 100).
Definition: fltHeader.cxx:345
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the first bead in the file, the top of the bead hierarchy, and the primary interface to readi...
Definition: fltHeader.h:44
static int min_flt_version()
Returns the earliest flt version number that this codebase supports (times 100).
Definition: fltHeader.cxx:335
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the bare functionality (intended to be inherited from along with ProgramBase or some derivati...
std::ostream & get_output()
Returns an output stream that corresponds to the user's intended egg file output–either stdout,...