Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

pandatool/src/imagebase/imageWriter.cxx

Go to the documentation of this file.
00001 // Filename: imageWriter.cxx
00002 // Created by:  drose (19Jun00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include "imageWriter.h"
00020 
00021 ////////////////////////////////////////////////////////////////////
00022 //     Function: ImageWriter::Constructor
00023 //       Access: Public
00024 //  Description: Image-writing type programs *must* specify their
00025 //               output file using -o.
00026 ////////////////////////////////////////////////////////////////////
00027 ImageWriter::
00028 ImageWriter(bool allow_last_param) :
00029   WithOutputFile(allow_last_param, false, true)
00030 {
00031   clear_runlines();
00032   if (_allow_last_param) {
00033     add_runline("[opts] outputimage");
00034   }
00035   add_runline("[opts] -o outputimage");
00036 
00037   string o_description;
00038   if (_allow_last_param) {
00039     o_description =
00040       "Specify the filename to which the resulting image file will be written.  "
00041       "If this option is omitted, the last parameter name is taken to be the "
00042       "name of the output file.";
00043   } else {
00044     o_description =
00045       "Specify the filename to which the resulting image file will be written.";
00046   }
00047 
00048   add_option
00049     ("o", "filename", 50, o_description,
00050      &ImageWriter::dispatch_filename, &_got_output_filename, &_output_filename);
00051 }
00052 
00053 
00054 ////////////////////////////////////////////////////////////////////
00055 //     Function: ImageWriter::write_image
00056 //       Access: Public
00057 //  Description: Writes the generated to the user's specified output
00058 //               filename.
00059 ////////////////////////////////////////////////////////////////////
00060 void ImageWriter::
00061 write_image(const PNMImage &image) {
00062   if (!image.write(get_output_filename())) {
00063     nout << "Unable to write output image to " 
00064          << get_output_filename() << "\n";
00065     exit(1);
00066   }
00067 }
00068 
00069 ////////////////////////////////////////////////////////////////////
00070 //     Function: ImageWriter::handle_args
00071 //       Access: Protected, Virtual
00072 //  Description: Does something with the additional arguments on the
00073 //               command line (after all the -options have been
00074 //               parsed).  Returns true if the arguments are good,
00075 //               false otherwise.
00076 ////////////////////////////////////////////////////////////////////
00077 bool ImageWriter::
00078 handle_args(ProgramBase::Args &args) {
00079   if (!check_last_arg(args, 0)) {
00080     return false;
00081   }
00082 
00083   if (!args.empty()) {
00084     nout << "Unexpected arguments on command line:\n";
00085     Args::const_iterator ai;
00086     for (ai = args.begin(); ai != args.end(); ++ai) {
00087       nout << (*ai) << " ";
00088     }
00089     nout << "\r";
00090     return false;
00091   }
00092 
00093   return true;
00094 }

Generated on Fri May 2 03:20:05 2003 for Panda-Tool by doxygen1.3