Panda3D

vrmlTrans.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 vrmlTrans.cxx
10 * @author drose
11 * @date 2004-10-01
12 */
13
14 #include "vrmlTrans.h"
15 #include "parse_vrml.h"
16
17 /**
18 *
19 */
20 VRMLTrans::
21 VRMLTrans() :
22 WithOutputFile(true, true, false)
23 {
24 // Indicate the extension name we expect the user to supply for output
25 // files.
26 _preferred_extension = ".wrl";
27
28 set_program_brief("reads and writes VRML 2.0 files");
29 set_program_description
30 ("This program reads a VRML 2.0 file (.wrl) and writes an "
31 "essentially equivalent .wrl file. It is primarily useful for "
32 "debugging the VRML parser that is part of the Pandatool library.");
33
34 clear_runlines();
35 add_runline("[opts] input.wrl > output.wrl");
36 add_runline("[opts] input.wrl output.wrl");
37 add_runline("[opts] -o output.wrl input.wrl");
38
39 add_option
40 ("o", "filename", 0,
41 "Specify the filename to which the resulting .wrl file will be written. "
42 "If this option is omitted, the last parameter name is taken to be the "
43 "name of the output file.",
44 &VRMLTrans::dispatch_filename, &_got_output_filename, &_output_filename);
45 }
46
47
48 /**
49 *
50 */
51 void VRMLTrans::
52 run() {
53 nout << "Reading " << _input_filename << "\n";
54
55 VrmlScene *scene = parse_vrml(_input_filename);
56 if (scene == nullptr) {
57 nout << "Unable to read.\n";
58 exit(1);
59 }
60
61 get_output() << *scene << "\n";
62 }
63
64
65 /**
66 *
67 */
68 bool VRMLTrans::
69 handle_args(ProgramBase::Args &args) {
70 if (!check_last_arg(args, 1)) {
71 return false;
72 }
73
74 if (args.empty()) {
75 nout << "You must specify the .wrl file to read on the command line.\n";
76 return false;
77
78 } else if (args.size() != 1) {
79 nout << "You must specify only one .wrl file to read on the command line.\n";
80 return false;
81 }
82
83 _input_filename = args[0];
84
85 return true;
86 }
87
88
89 int main(int argc, char *argv[]) {
90 VRMLTrans prog;
91 prog.parse_command_line(argc, argv);
92 prog.run();
93 return 0;
94 }
ProgramBase::parse_command_line
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_...
Definition: programBase.cxx:286
VRMLTrans
A program to read a VRML file and output an essentially similar VRML file.
Definition: vrmlTrans.h:26
WithOutputFile
This is the bare functionality (intended to be inherited from along with ProgramBase or some derivati...
Definition: withOutputFile.h:29
WithOutputFile::get_output
std::ostream & get_output()
Returns an output stream that corresponds to the user's intended egg file output–either stdout,...
Definition: withOutputFile.cxx:50
pdeque< std::string >
pvector
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:42
parse_vrml
VrmlScene * parse_vrml(Filename filename)
Reads the named VRML file and returns a corresponding VrmlScene, or NULL if there is a parse error.
Definition: parse_vrml.cxx:86
parse_vrml.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
vrmlTrans.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.