00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "vrmlTrans.h"
00016 #include "parse_vrml.h"
00017 #include "pystub.h"
00018
00019
00020
00021
00022
00023
00024 VRMLTrans::
00025 VRMLTrans() :
00026 WithOutputFile(true, true, false)
00027 {
00028
00029
00030 _preferred_extension = ".wrl";
00031
00032 set_program_description
00033 ("This program reads a VRML 2.0 file (.wrl) and writes an "
00034 "essentially equivalent .wrl file. It is primarily useful for "
00035 "debugging the VRML parser that is part of the Pandatool library.");
00036
00037 clear_runlines();
00038 add_runline("[opts] input.wrl > output.wrl");
00039 add_runline("[opts] input.wrl output.wrl");
00040 add_runline("[opts] -o output.wrl input.wrl");
00041
00042 add_option
00043 ("o", "filename", 0,
00044 "Specify the filename to which the resulting .wrl file will be written. "
00045 "If this option is omitted, the last parameter name is taken to be the "
00046 "name of the output file.",
00047 &VRMLTrans::dispatch_filename, &_got_output_filename, &_output_filename);
00048 }
00049
00050
00051
00052
00053
00054
00055
00056 void VRMLTrans::
00057 run() {
00058 nout << "Reading " << _input_filename << "\n";
00059
00060 VrmlScene *scene = parse_vrml(_input_filename);
00061 if (scene == (VrmlScene *)NULL) {
00062 nout << "Unable to read.\n";
00063 exit(1);
00064 }
00065
00066 get_output() << *scene << "\n";
00067 }
00068
00069
00070
00071
00072
00073
00074
00075 bool VRMLTrans::
00076 handle_args(ProgramBase::Args &args) {
00077 if (!check_last_arg(args, 1)) {
00078 return false;
00079 }
00080
00081 if (args.empty()) {
00082 nout << "You must specify the .wrl file to read on the command line.\n";
00083 return false;
00084
00085 } else if (args.size() != 1) {
00086 nout << "You must specify only one .wrl file to read on the command line.\n";
00087 return false;
00088 }
00089
00090 _input_filename = args[0];
00091
00092 return true;
00093 }
00094
00095
00096 int main(int argc, char *argv[]) {
00097
00098 pystub();
00099
00100 VRMLTrans prog;
00101 prog.parse_command_line(argc, argv);
00102 prog.run();
00103 return 0;
00104 }