Modelib: Fichier source de PsFile.h

Page principale | Liste des namespaces | Hiérarchie des classes | Liste alphabétique | Liste des classes | Liste des fichiers | Membres de namespace | Membres de classe | Membres de fichier

# PsFile.h

Aller à la documentation de ce fichier.

    00001 /*
    00002     Copyright (c) 2005, Quentin Lequy and Romain Gaucher
    00003     All rights reserved.
    00004
    00005     Redistribution and use in source and binary forms, with or
    00006     without modification, are permitted provided that the following
    00007     conditions are met:
    00008
    00009         * Redistributions of source code must retain the above copyright
    00010           notice, this list of conditions and the following disclaimer.
    00011
    00012         * Redistributions in binary form must reproduce the above copyright
    00013           notice, this list of conditions and the following disclaimer in the
    00014           documentation and/or other materials provided with the distribution.
    00015
    00016         * Neither the name of Quentin Lequy or Romain Gaucher nor the names
    00017           of its contributors may be used to endorse or promote products
    00018           derived from this software without specific prior written permission.
    00019
    00020     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    00021     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    00022     IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    00023     ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    00024     LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    00025     DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    00026     SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
    00027     AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    00028     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    00029     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00030 */
    00031
    00032 #ifndef __PSFILE_H
    00033 #define __PSFILE_H
    00034
    00035 #include "Model.h"
    00036 #include <iostream>
    00037 #include <fstream>
    00038 #include <string>
    00039 #include <stdexcept>
    00040
    00041 namespace Modelib {
    00042
    00049 class PSFile
    00050 {
    00051     std::string   nom;
    00052     std::ofstream psfile;
    00053
    00054     double hmin, hmax;
    00055     double vmin, vmax;
    00056     double xmin, xmax, xscale;
    00057     double ymin, ymax, yscale;
    00058
    00059     protected:
    00060
    00061     void aux_rectangle(
    00062     double xlo, double xhi,
    00063     double ylo, double yhi,
    00064     double gray,
    00065     char *op
    00066   );
    00067
    00068     void aux_polygon(
    00069     double x[], double y[],
    00070     int npoints,
    00071     double gray,
    00072     char *op
    00073   );
    00074
    00075     void aux_circle(
    00076     double xc, double yc, double radius,
    00077     double gray,
    00078     char *op
    00079   );
    00080
    00081     void aux_lune(
    00082     double xc, double yc, double radius, double tilt,
    00083     double gray,
    00084     char *op
    00085   );
    00086
    00087     void define_procs();
    00088     void define_caption_procs();
    00089
    00090     void save_scales(
    00091     double xmin, double xmax,
    00092     double ymin, double ymax,
    00093     double hmin, double hmax,
    00094     double vmin, double vmax
    00095   );
    00096
    00097     void setup_page_state( int xn, int yn);
    00098     void setup_caption_data();
    00099     void aux_end_page();
    00100
    00101     public:
    00102
    00103         PSFile() {};
    00104         PSFile(const std::string& _nom) : nom(_nom)
    00105         {
    00106             psfile.open(nom.c_str());
    00107             if(!psfile.is_open())
    00108              throw runtime_error("PSFile::PSFile() : I/O Error");
    00109         begin_document ();
    00110         begin_page(1,40,320,0,640, 20,300,750,750, 16 ,1);
    00111         }
    00112
    00113         ~PSFile()
    00114         {
    00115         end_page();
    00116         end_document(1);
    00117             psfile.close();
    00118         }
    00119
    00120         void close() {psfile.close();};
    00121
    00140         void begin_figure (
    00141             double xmin, double xmax,
    00142             double ymin, double ymax,
    00143
    00144             double hmin, double hmax,
    00145             double vmin, double vmax,
    00146
    00147             int xn, int yn
    00148     );
    00149
    00152         void end_figure ();
    00153
    00167         void begin_document ();
    00168
    00181         void begin_page(
    00182             int page,
    00183             double xmin, double xmax,
    00184             double ymin, double ymax,
    00185
    00186             double hmin, double hmax,
    00187             double vmin, double vmax,
    00188
    00189             int xn, int yn
    00190         );
    00191
    00194         void end_page();
    00195
    00199         void end_document (int npages);
    00200
    00204         void begin_section (char *title);
    00205
    00209         void end_section ();
    00210
    00215         void set_pen (
    00216         double gray,
    00217         double width,
    00218         double dashlength,
    00219         double dashspace
    00220     );
    00221
    00225         void draw_segment(
    00226         double xa, double ya,
    00227         double xb, double yb
    00228     );
    00229
    00233         void draw_curve(
    00234         double xa, double ya,
    00235         double xb, double yb,
    00236         double xc, double yc,
    00237         double xd, double yd
    00238     );
    00239
    00243         void draw_rectangle(
    00244         double xlo, double xhi,
    00245         double ylo, double yhi
    00246     );
    00247
    00251         void fill_rectangle(
    00252         double xlo, double xhi,
    00253         double ylo, double yhi,
    00254         double gray
    00255     );
    00256
    00261         void fill_and_draw_rectangle(
    00262         double xlo, double xhi,
    00263         double ylo, double yhi,
    00264         double gray
    00265     );
    00266
    00270         void fill_circle(
    00271         double xc, double yc, double radius,
    00272         double gray
    00273     );
    00274
    00278         void draw_circle(
    00279         double xc, double yc, double radius
    00280     );
    00281
    00286         void fill_and_draw_circle(
    00287         double xc, double yc, double radius,
    00288         double gray
    00289       );
    00290
    00295         void fill_and_draw_lune(
    00296         double xc, double yc, double radius, double tilt,
    00297         double gray
    00298     );
    00299
    00303         void fill_polygon(
    00304         double x[], double y[],
    00305         int n,
    00306         double gray
    00307     );
    00308
    00313         void draw_polygon(
    00314         double x[], double y[],
    00315         int n
    00316     );
    00317
    00322         void fill_and_draw_polygon(
    00323         double x[], double y[],
    00324         int n,
    00325         double gray
    00326     );
    00327
    00331         void fill_triangle(
    00332         double xa, double ya,
    00333         double xb, double yb,
    00334         double xc, double yc,
    00335         double gray
    00336     );
    00337
    00342         void fill_grid_cell(int xi, int yi, double gray);
    00343
    00348         void draw_coord_line (char axis, double coord);
    00349
    00353         void draw_grid_lines();
    00354
    00358     void set_label_font(char *font, float size);
    00359
    00367         void put_label(
    00368         char *text,
    00369         double x, double y,
    00370         float xalign, float yalign
    00371     );
    00372
    00377         void draw_frame ();
    00378
    00379
    00384         void add_caption(char *txt);
    00385
    00386
    00393         void put_text(char *text, char *newline);
    00394
    00398         PSFile& operator<<(const std::string& str)
    00399         {
    00400             add_caption(const_cast<char*>(str.c_str()));
    00401             return (*this);
    00402         }
    00403
    00404         PSFile& operator<<(const Model& m);
    00405 };
    00406
    00407 }
    00408
    00409 #endif