Panda3D
 All Classes Functions Variables Enumerations
vrmlTrans.cxx
1 // Filename: vrmlTrans.cxx
2 // Created by: drose (01Oct04)
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 "vrmlTrans.h"
16 #include "parse_vrml.h"
17 #include "pystub.h"
18 
19 ////////////////////////////////////////////////////////////////////
20 // Function: VRMLTrans::Constructor
21 // Access: Public
22 // Description:
23 ////////////////////////////////////////////////////////////////////
24 VRMLTrans::
25 VRMLTrans() :
26  WithOutputFile(true, true, false)
27 {
28  // Indicate the extension name we expect the user to supply for
29  // output files.
30  _preferred_extension = ".wrl";
31 
32  set_program_brief("reads and writes VRML 2.0 files");
33  set_program_description
34  ("This program reads a VRML 2.0 file (.wrl) and writes an "
35  "essentially equivalent .wrl file. It is primarily useful for "
36  "debugging the VRML parser that is part of the Pandatool library.");
37 
38  clear_runlines();
39  add_runline("[opts] input.wrl > output.wrl");
40  add_runline("[opts] input.wrl output.wrl");
41  add_runline("[opts] -o output.wrl input.wrl");
42 
43  add_option
44  ("o", "filename", 0,
45  "Specify the filename to which the resulting .wrl file will be written. "
46  "If this option is omitted, the last parameter name is taken to be the "
47  "name of the output file.",
48  &VRMLTrans::dispatch_filename, &_got_output_filename, &_output_filename);
49 }
50 
51 
52 ////////////////////////////////////////////////////////////////////
53 // Function: VRMLTrans::run
54 // Access: Public
55 // Description:
56 ////////////////////////////////////////////////////////////////////
57 void VRMLTrans::
58 run() {
59  nout << "Reading " << _input_filename << "\n";
60 
61  VrmlScene *scene = parse_vrml(_input_filename);
62  if (scene == (VrmlScene *)NULL) {
63  nout << "Unable to read.\n";
64  exit(1);
65  }
66 
67  get_output() << *scene << "\n";
68 }
69 
70 
71 ////////////////////////////////////////////////////////////////////
72 // Function: VRMLTrans::handle_args
73 // Access: Protected, Virtual
74 // Description:
75 ////////////////////////////////////////////////////////////////////
76 bool VRMLTrans::
77 handle_args(ProgramBase::Args &args) {
78  if (!check_last_arg(args, 1)) {
79  return false;
80  }
81 
82  if (args.empty()) {
83  nout << "You must specify the .wrl file to read on the command line.\n";
84  return false;
85 
86  } else if (args.size() != 1) {
87  nout << "You must specify only one .wrl file to read on the command line.\n";
88  return false;
89  }
90 
91  _input_filename = args[0];
92 
93  return true;
94 }
95 
96 
97 int main(int argc, char *argv[]) {
98  // A call to pystub() to force libpystub.so to be linked in.
99  pystub();
100 
101  VRMLTrans prog;
102  prog.parse_command_line(argc, argv);
103  prog.run();
104  return 0;
105 }
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_...
A program to read a VRML file and output an essentially similar VRML file.
Definition: vrmlTrans.h:29
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:39
This is the bare functionality (intended to be inherited from along with ProgramBase or some derivati...
ostream & get_output()
Returns an output stream that corresponds to the user&#39;s intended egg file output–either stdout...