00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "PSDev.h"
00027 #include "string.h"
00028 #include "math.h"
00029 #include "compatibility.hh"
00030 #include <iostream>
00031
00032 using namespace std;
00033
00034 static int gFileNum = 0;
00035
00036 static char * addFileNum(const char* fname)
00037 {
00038 char f[256];
00039 char s[256];
00040 int i;
00041
00042
00043 for (i=0; (fname[i] != 0) && (fname[i] != '.'); i++) {
00044 f[i] = fname[i];
00045 }
00046 f[i] = 0;
00047
00048
00049 snprintf(s, 255, "%s-%d.ps", f, ++gFileNum);
00050
00051 return strdup(s);
00052 }
00053
00054 PSDev::PSDev(const char* ficName, double largeur, double hauteur)
00055 {
00056 if ((fic_repr = fopen(addFileNum(ficName),"w+")) == NULL) {
00057
00058 cout<<"Impossible de creer ou d'ouvrir "<<ficName<<endl;
00059 }
00060
00061 if(largeur<hauteur)
00062 largeur=hauteur;
00063
00064 fprintf(fic_repr,"%%!PS-Adobe-3.0 \n");
00065
00066 fprintf(fic_repr,"%%%%BoundingBox: 0 0 450 %d\n",(int)floor((hauteur*450/largeur)+1));
00067
00068 fprintf(fic_repr,"/unit {%f mul} def\n\n",450/largeur);
00069 fprintf(fic_repr,"0 %f unit translate\n",hauteur);
00070 fprintf(fic_repr,"1 -1 scale\n\n");
00071 fprintf(fic_repr,"0.6 unit setlinewidth\n");
00072
00073 fprintf(fic_repr,"/Times-Roman findfont %% Get the basic font for text\n");
00074
00075 fprintf(fic_repr,"10 unit scalefont %% Scale the font to 10 units\n");
00076 fprintf(fic_repr,"setfont %% Make it the current font\n\n");
00077 }
00078
00079 PSDev::~PSDev()
00080 {
00081 fprintf(fic_repr,"showpage\n");
00082 fclose(fic_repr);
00083 }
00084
00085 void PSDev::rect(double x,double y,double l,double h, const char*, const char*)
00086 {
00087 fprintf(fic_repr,"gsave\n");
00088 fprintf(fic_repr,"newpath\n");
00089
00090 fprintf(fic_repr,"1.0 unit setlinewidth\n");
00091 fprintf(fic_repr,"%f unit %f unit moveto\n",x,y);
00092 fprintf(fic_repr,"0 unit %f unit rlineto\n",h);
00093 fprintf(fic_repr,"%f unit 0 unit rlineto\n",l);
00094 fprintf(fic_repr,"0 unit %f unit rlineto\n",-h);
00095 fprintf(fic_repr,"closepath\n");
00096 fprintf(fic_repr,"stroke\n");
00097 fprintf(fic_repr,"grestore\n");
00098 }
00099
00100 void PSDev::rond(double x,double y,double rayon)
00101 {
00102 fprintf(fic_repr,"gsave\n");
00103 fprintf(fic_repr,"newpath\n");
00104 fprintf(fic_repr,"%f unit %f unit %f unit 0 360 arc\n",x,y,rayon);
00105 fprintf(fic_repr,"fill\n");
00106 fprintf(fic_repr,"grestore\n");
00107 }
00108
00109 void PSDev::fleche(double x,double y,double rotation,int sens)
00110 {
00111 if(sens == 1)
00112 {
00113 fprintf(fic_repr,"gsave\n");
00114 fprintf(fic_repr,"newpath\n");
00115 fprintf(fic_repr,"0.3 setgray\n");
00116 fprintf(fic_repr,"%f unit %f unit moveto\n",x,y);
00117 fprintf(fic_repr,"%f rotate\n",rotation);
00118 fprintf(fic_repr,"%f unit %f unit rlineto\n",(double)-4,(double)-2);
00119 fprintf(fic_repr,"%f rotate\n",(double)-rotation);
00120 fprintf(fic_repr,"%f unit %f unit moveto\n",x,y);
00121 fprintf(fic_repr,"%f rotate\n",rotation);
00122 fprintf(fic_repr,"%f unit %f unit rlineto\n",(double)-4,(double)+2);
00123 fprintf(fic_repr,"closepath\n");
00124 fprintf(fic_repr,"stroke\n");
00125 fprintf(fic_repr,"grestore\n");
00126 }
00127 else
00128 {
00129 fprintf(fic_repr,"gsave\n");
00130 fprintf(fic_repr,"newpath\n");
00131 fprintf(fic_repr,"0.3 setgray\n");
00132 fprintf(fic_repr,"%f unit %f unit moveto\n",x,y);
00133 fprintf(fic_repr,"%f rotate\n",rotation);
00134 fprintf(fic_repr,"%f unit %f unit rlineto\n",(double)4,(double)-2);
00135 fprintf(fic_repr,"%f rotate\n",(double)-rotation);
00136 fprintf(fic_repr,"%f unit %f unit moveto\n",x,y);
00137 fprintf(fic_repr,"%f rotate\n",rotation);
00138 fprintf(fic_repr,"%f unit %f unit rlineto\n",(double)4,(double)+2);
00139 fprintf(fic_repr,"closepath\n");
00140 fprintf(fic_repr,"stroke\n");
00141 fprintf(fic_repr,"grestore\n");
00142 }
00143 }
00144
00145 void PSDev::carre(double x,double y,double cote)
00146 {
00147 fprintf(fic_repr,"gsave\n");
00148 fprintf(fic_repr,"newpath\n");
00149 fprintf(fic_repr,"0.3 setgray\n");
00150 fprintf(fic_repr,"%f unit %f unit moveto\n",x-cote/2,y);
00151 fprintf(fic_repr,"0 unit %f unit rlineto\n",-cote);
00152 fprintf(fic_repr,"%f unit 0 unit rlineto\n",cote);
00153 fprintf(fic_repr,"0 unit %f unit rlineto\n",cote);
00154 fprintf(fic_repr,"closepath\n");
00155 fprintf(fic_repr,"stroke\n");
00156 fprintf(fic_repr,"grestore\n");
00157 }
00158
00159 void PSDev::trait(double x1,double y1,double x2,double y2)
00160 {
00161 fprintf(fic_repr,"gsave\n");
00162 fprintf(fic_repr,"0.3 setgray\n");
00163 fprintf(fic_repr,"newpath\n");
00164 fprintf(fic_repr,"%f unit %f unit moveto\n",x1,y1);
00165 fprintf(fic_repr,"%f unit %f unit lineto\n",x2,y2);
00166 fprintf(fic_repr,"stroke\n");
00167 fprintf(fic_repr,"grestore\n");
00168 }
00169
00170 void PSDev::dasharray(double x1,double y1,double x2,double y2)
00171 {
00172 fprintf(fic_repr,"gsave\n");
00173 fprintf(fic_repr,"newpath\n");
00174 fprintf(fic_repr,"0.6 setgray\n");
00175 fprintf(fic_repr,"0.8 unit setlinewidth\n");
00176 fprintf(fic_repr,"%f unit %f unit moveto\n",x1,y1);
00177 fprintf(fic_repr,"%f unit %f unit lineto\n",x2,y2);
00178 fprintf(fic_repr,"stroke\n");
00179 fprintf(fic_repr,"grestore\n");
00180 }
00181
00182 void PSDev::text(double x,double y,const char* nom)
00183 {
00184 fprintf(fic_repr,"newpath\n");
00185
00186 fprintf(fic_repr,"%f unit %f unit moveto\n",(x-0)-(strlen(nom)-1)*3.8,y+2);
00187 fprintf(fic_repr,"gsave\n");
00188 fprintf(fic_repr,"1 -1 scale\n\n");
00189 fprintf(fic_repr,"(%s) show\n",nom);
00190 fprintf(fic_repr,"grestore\n");
00191 }
00192
00193 void PSDev::label(double x,double y,const char* label)
00194 {
00195 fprintf(fic_repr,"gsave\n");
00196 fprintf(fic_repr,"/Times-Roman findfont %% Get the basic font for text\n");
00197 fprintf(fic_repr,"7 unit scalefont %% Scale the font to 10 points\n");
00198 fprintf(fic_repr,"setfont %% Make it the current font\n\n");
00199 fprintf(fic_repr,"newpath\n");
00200 fprintf(fic_repr,"%f unit %f unit moveto\n",(x+2),y+1.2);
00201 fprintf(fic_repr,"1 -1 scale\n");
00202 fprintf(fic_repr,"(%s) show\n",label);
00203 fprintf(fic_repr,"grestore\n");
00204 }
00205
00206 void PSDev::markSens(double x,double y,int sens)
00207 {
00208 if (sens==1)
00209 {
00210 fprintf(fic_repr,"newpath\n");
00211 fprintf(fic_repr,"%f unit %f unit moveto\n",x,y+4);
00212 fprintf(fic_repr,"%f unit %f unit rlineto\n",(double)4,(double)-4);
00213 fprintf(fic_repr,"closepath\n");
00214 }
00215 else
00216 {
00217 fprintf(fic_repr,"newpath\n");
00218 fprintf(fic_repr,"%f unit %f unit moveto\n",x,y-4);
00219 fprintf(fic_repr,"%f unit %f unit rlineto\n",(double)-4,(double)4);
00220 fprintf(fic_repr,"closepath\n");
00221 }
00222 fprintf(fic_repr,"stroke\n");
00223 }
00224
00225 void PSDev::Error(const char* message, const char* reason,int nb_error,double x,double y,double largeur)
00226 {
00227 fprintf(fic_repr,"gsave\n");
00228 fprintf(fic_repr,"/Times-Roman findfont %% Get the basic font for text\n");
00229 fprintf(fic_repr,"17 unit scalefont %% Scale the font to 10 points\n");
00230 fprintf(fic_repr,"setfont %% Make it the current font\n\n");
00231 fprintf(fic_repr,"newpath\n");
00232 fprintf(fic_repr,"%f unit %f unit moveto\n",(x-8)-(strlen(message)-1)*3.8,y-10);
00233 fprintf(fic_repr,"1 -1 scale\n");
00234 fprintf(fic_repr,"(%s) show\n",message);
00235 fprintf(fic_repr,"1 -1 scale\n");
00236 fprintf(fic_repr,"%f unit %f unit moveto\n",(x-8)-(strlen(reason)-1)*3.8,y+10);
00237 fprintf(fic_repr,"1 -1 scale\n");
00238 fprintf(fic_repr,"(%s) show\n",reason);
00239 fprintf(fic_repr,"grestore\n");
00240
00241 }
00242
00243