periFig.c

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------
00002  *    Graphic library
00003  *    Copyright (C) 1998-2001 Enpc/Jean-Philippe Chancelier
00004  *    jpc@cermics.enpc.fr 
00005  --------------------------------------------------------------------------*/
00006 
00007 /*----------------------BEGIN----------------------
00008 \def\encadre#1{\paragraph{}\fbox{\begin{minipage}[t]{15cm}#1 \end{minipage}}}
00009 \section{A Fig Driver}
00010 ---------------------------------------------------*/
00011 
00012 #include <stdio.h>
00013 #include <math.h>
00014 #include <string.h>
00015 
00016 #ifdef __STDC__
00017 #include <stdlib.h>
00018 #endif
00019 
00020 #include "machine.h"
00021 
00022 
00023 #if defined(_MSC_VER)
00024 #define CoordModePrevious 1
00025 #define CoordModeOrigin 0
00026 #define GXclear 0
00027 #define GXand 1
00028 #define GXandReverse 2
00029 #define GXcopy 3
00030 #define GXandInverted 4
00031 #define GXnoop 5
00032 #define GXxor 6
00033 #define GXor 7
00034 #define GXnor 8
00035 #define GXequiv 9
00036 #define GXinvert 10
00037 #define GXorReverse 11
00038 #define GXcopyInverted 12
00039 #define GXorInverted 13
00040 #define GXnand 14
00041 #define GXset 15
00042 #endif
00043 
00044 #include "math_graphics.h"
00045 #include "periFig.h"
00046 #include "color.h"
00047 #include "bcg.h" /* NG */
00048 #include "clipping.h"
00049 #include "sciprint.h"
00050 #include "periScreen.h"
00051 
00052 
00053 #include "MALLOC.h" /* MALLOC */
00054 
00055 struct BCG  ScilabGCXfig ;
00056 
00057 static BOOL ScilabGCXfig_is_initialized = FALSE;
00058 
00059 #define WHITE 7
00060 #define BLACK 0
00061 
00062 void C2F(Write2VectXfig)(integer *vx, integer *vy, integer n, integer flag); 
00063 void C2F(WriteGenericXfig)(char *string, integer nobj, integer sizeobj, integer *vx, integer *vy, integer sizev, integer flag, integer *fvect);
00064 void C2F(InitScilabGCXfig)(integer *v1, integer *v2, integer *v3, integer *v4);
00065 void C2F(setforegroundXfig)(integer *num, integer *v2, integer *v3, integer *v4);
00066 void C2F(ScilabGCGetorSetXfig)(char *str, integer flag, integer *verbose, integer *x1, integer *x2, integer *x3, integer *x4, integer *x5, integer *x6, double *dx1);
00067 void C2F(setbackgroundXfig)(integer *num, integer *v2, integer *v3, integer *v4);
00068 void C2F(set_cXfig)(integer i);
00069 void C2F(idfromnameXfig) (char *name1, integer *num);
00070 void C2F(getdashXfig)(integer *verbose, integer *value, integer *narg, double *dummy);
00071 
00072 /* NG beg */
00073 void C2F(setscilabFigureXfig)(integer *v1,integer *v2,integer *v3,integer *v4,integer *v5,integer *v6,double *figure);
00074 void C2F(getscilabFigureXfig)(integer *verbose, integer *x,integer *narg, double *figure);
00075 void C2F(setscilabVersionXfig)(integer *vers, integer *v2, integer *v3, integer *v4);
00076 void C2F(getscilabVersionXfig)(integer *verbose, integer *vers, integer *narg, double *dummy);
00077 void C2F(setscilabxgcXfig)(integer *v1, integer *v2, integer *v3, integer *v4); 
00078 void C2F(getscilabxgcXfig)(integer *verbose, integer *x,integer *narg, double *dummy);
00079 /* NG end */
00080 
00081 extern void getcolordef( integer * screenc ) ;
00082 extern void setcolordef( integer   screenc ) ;
00083 
00084 static void 
00085 C2F(analyze_pointsXfig) (integer n, integer *vx, integer *vy,
00086                          integer onemore);
00087 
00088 static void C2F(displaysymbolsXfig) (char *str, integer *n, integer *vx, integer *vy);
00089 static int C2F(FigQueryFont)(char *name);
00090 static void set_dash_or_color (int dash,int *l_style,int *style_val,int *color);
00091 
00092 #define Char2Int(x)   ( x & 0x000000ff )
00093 static double *vdouble = 0; /* used when a double argument is needed */
00096 #define FONTNUMBER 11
00097 #define FONTMAXSIZE 6
00098 #define SYMBOLNUMBER 10
00099 integer FontsListXfig_[FONTNUMBER][FONTMAXSIZE];
00100 struct SciFontInfo { integer ok;
00101                   char fname[21];} FontInfoTabXfig_[FONTNUMBER];
00103 static integer  xfig_font[]= { 12,32,0,1,2,3,16,17,18,19,0};
00104 static char *sizeXfig_[] = { "08" ,"10","12","14","18","24"};
00105 static integer  isizeXfig_[] = { 8,10,12,14,18,24};
00106 
00107 #if defined(__GNUC__) || defined(_MSC_VER)|| defined(__EDG__)
00108 static FILE *file= (FILE *) 0;
00109 #define FPRINTF(x) ( file != (FILE*) 0) ?  fprintf x  : 0 
00110 #else 
00111 static FILE *file= stdout ;
00112 #define FPRINTF(x) fprintf x  
00113 #endif
00114 
00115 static void C2F(FileInitXfig) __PARAMS((void));
00116 static void C2F(FileInitFromScreenXfig) __PARAMS((void));
00117 static void set_dash  __PARAMS((int dash,int *l_style,int *_val));
00118 static void set_color  __PARAMS((int c,int *color));
00119 
00120 
00123 /*-----------------------------------------------------
00124 \encadre{General routines}
00125 -----------------------------------------------------*/
00126 
00129 void C2F(xselgraphicXfig)(char *v1, integer *v2, integer *v3, integer *v4, integer *v5, integer *v6, integer *v7, double *dx1, double *dx2, double *dx3, double *dx4)
00130 {}
00131 
00134 void C2F(xendgraphicXfig)(void)
00135 {
00136   if (file != stdout && file != (FILE*) 0) {
00137     fclose(file);
00138     file=stdout;
00139   }
00140   ScilabGCXfig_is_initialized = FALSE;
00141 }
00142 
00143 void C2F(xendXfig)(char *v1, integer *v2, integer *v3, integer *v4, integer *v5, integer *v6, integer *v7, double *dx1, double *dx2, double *dx3, double *dx4)
00144 {
00145   C2F(xendgraphicXfig)();
00146 }
00147 
00148 
00152 void C2F(clearwindowXfig)(char *v1, integer *v2, integer *v3, integer *v4, integer *v5, integer *v6, integer *v7, double *dx1, double *dx2, double *dx3, double *dx4)
00153 {
00154   /* F.Leray : I add a rectangle with  background color*/
00155   integer i = 1;
00156   int zero = 0, col;
00157   integer vects[4], narg;
00158   double dv;
00159   
00160   if ( ScilabGCXfig_is_initialized == FALSE ) {
00161     sciprint("xinit must be called before any action \r\n");
00162     return;
00163   }
00164   
00165   vects[0]= zero;
00166   vects[1]= zero;
00167   C2F(getwindowdimXfig)(&zero,&vects[2],&narg,&dv);
00168 
00169   col = ScilabGCXfig.NumBackground+1;
00170   
00171   C2F(drawrectanglesXfig)("",vects,&col,&i,PI0,PI0,PI0,PD0,PD0,PD0,PD0);    
00172   
00173 }
00174 
00177 void C2F(viderbuffXfig)(void)
00178 {}
00179 
00183 static int prec_fact =16;
00184 
00185 void C2F(getwindowdimXfig)(integer *verbose, integer *x, integer *narg, double *dummy)
00186 {     
00187   *narg = 2;
00188   x[0]= 600*prec_fact;
00189   x[1]= 424*prec_fact;
00190   if (*verbose == 1) 
00191     sciprint("\n CWindow dim :%d,%d\r\n",(int)x[0],(int)x[1]);
00192 } 
00193 
00196 void C2F(setwindowdimXfig)(integer *x, integer *y, integer *v3, integer *v4)
00197 {
00198 }
00199 
00202 void C2F(getwindowposXfig)(integer *verbose, integer *x, integer *narg, double *dummy)
00203 {
00204   *narg = 2;
00205   x[0]= x[1]=0;
00206   if (*verbose == 1) 
00207     sciprint("\n CWindow position :%d,%d\r\n",(int)x[0],(int)x[1]);
00208  }
00209 
00212 void C2F(setwindowposXfig)(integer *x, integer *y, integer *v3, integer *v4)
00213 {
00214 }
00215 
00216 
00219 void C2F(xclickXfig)(char *str, integer *ibutton, integer *xx1, integer *yy1, integer *v5, integer *v6, integer *v7, double *dx1, double *dx2, double *dx3, double *dx4)
00220 { }
00221 
00224 void C2F(xclick_anyXfig)(char *str, integer *ibutton, integer *xx1, integer *yy1, integer *v5, integer *v6, integer *v7, double *dx1, double *dx2, double *dx3, double *dx4)
00225 { }
00226 
00227 void C2F(xgetmouseXfig)(char *str, integer *ibutton, integer *xx1, integer *yy1, integer *v5, integer *v6, integer *v7, double *dx1, double *dx2, double *dx3, double *dx4)
00228 { }
00229 
00232 void C2F(clearareaXfig)(char *str, integer *x, integer *y, integer *w, integer *h, integer *v6, integer *v7, double *dx1, double *dx2, double *dx3, double *dx4)
00233 {
00234   FPRINTF((file,"# %d %d %d %d clearzone\n",(int)*x,(int)*y,(int)*w,(int)*h));
00235 }
00236 
00237 /*------------------------------------------------
00238 \encadre{Functions to modify the graphic state}
00239 -------------------------------------------------*/
00240 
00243 void C2F(setcurwinXfig)(integer *intnum, integer *v2, integer *v3, integer *v4)
00244 {
00245   ScilabGCXfig.CurWindow = *intnum;
00246 }
00247 
00250 void C2F(getcurwinXfig)(integer *verbose, integer *intnum, integer *narg, double *dummy)
00251 {
00252   *narg =1 ;
00253   *intnum = ScilabGCXfig.CurWindow ;
00254   if (*verbose == 1) 
00255     sciprint("\nJust one graphic page at a time ");
00256 }
00257 
00260 void C2F(setclipXfig)(integer *x, integer *y, integer *w, integer *h)
00261 {
00262   if ( ScilabGCXfig_is_initialized == FALSE ) {
00263     sciprint("xinit must be called before any action \r\n");
00264     return;
00265   }
00266 
00267   ScilabGCXfig.ClipRegionSet = 1;
00268   ScilabGCXfig.CurClipRegion[0]= *x;
00269   ScilabGCXfig.CurClipRegion[1]= *y;
00270   ScilabGCXfig.CurClipRegion[2]= *w;
00271   ScilabGCXfig.CurClipRegion[3]= *h;
00272   FPRINTF((file,"# %d %d %d %d setclipzone\n",(int)*x,(int)*y,(int)*w,(int)*h));
00273 }
00274 
00275 
00278 void C2F(unsetclipXfig)(integer *v1, integer *v2, integer *v3, integer *v4)
00279 {
00280   
00281   if ( ScilabGCXfig_is_initialized == FALSE ) {
00282     sciprint("xinit must be called before any action \r\n");
00283     return;
00284   }
00285   
00286   ScilabGCXfig.ClipRegionSet = 0;
00287   ScilabGCXfig.CurClipRegion[0]= -1;
00288   ScilabGCXfig.CurClipRegion[1]= -1;
00289   ScilabGCXfig.CurClipRegion[2]= 200000;
00290   ScilabGCXfig.CurClipRegion[3]= 200000;
00291   FPRINTF((file,"# %d %d %d %d setclipzone\n",-1,-1,200000,200000));
00292 }
00293 
00296 void C2F(getclipXfig)(integer *verbose, integer *x, integer *narg, double *dummy)
00297 {
00298   x[0] = ScilabGCXfig.ClipRegionSet;
00299   if ( x[0] == 1)
00300     {
00301       *narg = 5;
00302       x[1] =ScilabGCXfig.CurClipRegion[0];
00303       x[2] =ScilabGCXfig.CurClipRegion[1];
00304       x[3] =ScilabGCXfig.CurClipRegion[2];
00305       x[4] =ScilabGCXfig.CurClipRegion[3];
00306     }
00307   else *narg = 1;
00308   if (*verbose == 1)
00309     {
00310       if (ScilabGCXfig.ClipRegionSet == 1)
00311         sciprint("\nThere's a Clip Region :x:%d,y:%d,w:%d,h:%d\r\n",
00312                  ScilabGCXfig.CurClipRegion[0],
00313                  ScilabGCXfig.CurClipRegion[1],
00314                  ScilabGCXfig.CurClipRegion[2],
00315                  ScilabGCXfig.CurClipRegion[3]);
00316       else 
00317         sciprint("\nNo Clip Region");
00318     }
00319 }
00320 
00321 /*----------------------------------------------------------
00322 \encadre{For the drawing functions dealing with vectors of 
00323  points, the following routine is used to select the mode 
00324  absolute or relative }
00325  Absolute mode if *num==0, relative mode if *num != 0
00326 ------------------------------------------------------------*/
00327 
00328 void C2F(absourelXfig)(integer *num, integer *v2, integer *v3, integer *v4)
00329 {
00330   if (*num == 0 )
00331     ScilabGCXfig.CurVectorStyle =  CoordModeOrigin;
00332   else 
00333     ScilabGCXfig.CurVectorStyle =  CoordModePrevious ;
00334 }
00335 
00338 void C2F(getabsourelXfig)(integer *verbose, integer *num, integer *narg, double *dummy)
00339 {
00340   *narg = 1;
00341   *num = ScilabGCXfig.CurVectorStyle  ;
00342   if (*verbose == 1) 
00343     {
00344       if (ScilabGCXfig.CurVectorStyle == CoordModeOrigin)
00345         sciprint("\nTrace Absolu");
00346       else 
00347         sciprint("\nTrace Relatif");
00348     }
00349 }
00350 
00351 
00355 void C2F(setalufunctionXfig)(char *string)
00356 {     
00357   integer value;
00358   
00359   if ( ScilabGCXfig_is_initialized == FALSE ) {
00360     sciprint("xinit must be called before any action \r\n");
00361     return;
00362   }
00363 
00364   C2F(idfromnameXfig)(string,&value);
00365   if ( value != -1)
00366     {ScilabGCXfig.CurDrawFunction = value;
00367      FPRINTF((file,"# %d setalufunction\n",(int)value));
00368       }
00369 }
00370 
00373 struct alinfo { 
00374   char *name;
00375   char id;
00376   char *info;} AluStrucXfig_[] =
00377 { 
00378   {"GXclear" ,GXclear," 0 "},
00379   {"GXand" ,GXand," src AND dst "},
00380   {"GXandReverse" ,GXandReverse," src AND NOT dst "},
00381   {"GXcopy" ,GXcopy," src "},
00382   {"GXandInverted" ,GXandInverted," NOT src AND dst "},
00383   {"GXnoop" ,GXnoop," dst "},
00384   {"GXxor" ,GXxor," src XOR dst "},
00385   {"GXor" ,GXor," src OR dst "},
00386   {"GXnor" ,GXnor," NOT src AND NOT dst "},
00387   {"GXequiv" ,GXequiv," NOT src XOR dst "},
00388   {"GXinvert" ,GXinvert," NOT dst "},
00389   {"GXorReverse" ,GXorReverse," src OR NOT dst "},
00390   {"GXcopyInverted" ,GXcopyInverted," NOT src "},
00391   {"GXorInverted" ,GXorInverted," NOT src OR dst "},
00392   {"GXnand" ,GXnand," NOT src OR NOT dst "},
00393   {"GXset" ,GXset," 1 "}
00394 };
00395 
00396 void C2F(idfromnameXfig)(char *name1, integer *num)
00397 {integer i;
00398  *num = -1;
00399  for ( i =0 ; i < 16;i++)
00400    if (strcmp(AluStrucXfig_[i].name,name1)== 0) 
00401      *num=AluStrucXfig_[i].id;
00402  if (*num == -1 ) 
00403    {
00404      sciprint("\n Use the following keys :");
00405      for ( i=0 ; i < 16 ; i++)
00406        {
00407          sciprint("\nkey %s ",AluStrucXfig_[i].name);
00408          sciprint("-> %s\r\n",AluStrucXfig_[i].info);
00409        }
00410    }
00411 }
00412 
00413 
00414 void C2F(setalufunction1Xfig)(integer *num, integer *v2, integer *v3, integer *v4)
00415 {     
00416   integer value;
00417 
00418   if ( ScilabGCXfig_is_initialized == FALSE ) {
00419     sciprint("xinit must be called before any action \r\n");
00420     return;
00421   }
00422 
00423   value=AluStrucXfig_[Min(16,Max(0,*num))].id;
00424   if ( value != -1)
00425     {
00426       ScilabGCXfig.CurDrawFunction = value;
00427       /* to be done */
00428     }
00429 }
00430 
00433 void C2F(getalufunctionXfig)(integer *verbose, integer *value, integer *narg, double *dummy)
00434 { 
00435   *narg =1 ;
00436   *value = ScilabGCXfig.CurDrawFunction ;
00437    if (*verbose ==1 ) 
00438      { 
00439        sciprint("\nThe Alufunction is %s",AluStrucXfig_[*value].name);
00440        sciprint("-> <%s>\r\n", AluStrucXfig_[*value].info);
00441      }
00442 }
00443 
00447 void C2F(setthicknessXfig)(integer *value, integer *v2, integer *v3, integer *v4)
00448 { 
00449   ScilabGCXfig.CurLineWidth =Max(1, *value);
00450   FPRINTF((file,"# %d Thickness\n",(int)Max(1L,*value)));
00451 }
00452 
00455 void C2F(getthicknessXfig)(integer *verbose, integer *value, integer *narg, double *dummy)
00456 {
00457   *narg =1 ;
00458   *value = ScilabGCXfig.CurLineWidth ;
00459   if (*verbose ==1 ) 
00460     sciprint("\nLine Width:%d\r\n", ScilabGCXfig.CurLineWidth ) ;
00461 }
00462      
00463 /*-------------------------------------------------
00464 \encadre{To set grey level for filing areas.
00465   from black (*num =0 ) to white 
00466   you must use the get function to get the id of 
00467   the white pattern }
00468 ----------------------------------------------------*/
00469 
00470 void C2F(setpatternXfig)(integer *num, integer *v2, integer *v3, integer *v4)
00471 { integer i ; 
00472   if (  ScilabGCXfig.CurColorStatus ==1) 
00473     {
00474       i= Max(0,Min(*num-1,ScilabGCXfig.Numcolors+1));
00475       ScilabGCXfig.CurColor = i ;
00476       C2F(set_cXfig)(i);
00477     }
00478   else 
00479     {
00480       i= Max(0,Min(*num-1,GREYNUMBER-1));
00481       ScilabGCXfig.CurPattern = i;
00482       if (i ==0)
00483         FPRINTF((file,"# fillsolid\n"));
00484       else 
00485         FPRINTF((file,"# %d Setgray\n",(int)i));
00486     }
00487 }
00488 
00491 void C2F(getpatternXfig)(integer *verbose, integer *num, integer *narg, double *dummy)
00492 { 
00493   *narg=1;
00494   if ( ScilabGCXfig.CurColorStatus ==1) 
00495     {
00496       *num = ScilabGCXfig.CurColor+1 ;
00497       if (*verbose == 1) 
00498         sciprint("\n Color : %d\r\n",
00499                  ScilabGCXfig.CurPattern);
00500     }
00501   else 
00502     {
00503       *num = ScilabGCXfig.CurPattern +1;
00504       if (*verbose == 1) 
00505         sciprint("\n Pattern : %d\r\n",
00506                  ScilabGCXfig.CurPattern);
00507     }
00508 }
00509 
00512 void C2F(getlastXfig)(integer *verbose, integer *num, integer *narg, double *dummy)
00513 {
00514   *num = ScilabGCXfig.IDLastPattern +1 ;
00515   if (*verbose==1)
00516     sciprint("\n Id of White Pattern %d\r\n",(int)*num);
00517   *narg=1;
00518 }
00519 
00520 
00526 #define MAXDASH 6
00527 
00528 /* solid dash dotted dash-dot dash-dot-dot dash-dot-dot-dot   */
00529 static integer DashTab[MAXDASH]      = {0,1,1,2,2,2} ;
00530 static integer DashTabStyle[MAXDASH] = {0,2,4,2,4,8} ;
00531 
00532 
00533 /* old version of setdashXfig retained for compatibility */
00534 
00535 void C2F(set_dash_or_color_Xfig)(integer *value, integer *v2, integer *v3, integer *v4)
00536 {
00537   integer maxdash = MAXDASH ;
00538   integer l3 ;
00539 
00540   if ( ScilabGCXfig_is_initialized == FALSE ) {
00541     sciprint("xinit must be called before any action \r\n");
00542     return;
00543   }
00544   
00545   if ( ScilabGCXfig.CurColorStatus ==1) 
00546     {
00547       int i;
00548       i= Max(0,Min(*value-1,ScilabGCXfig.Numcolors+1));
00549       ScilabGCXfig.CurColor =i;
00550       C2F(set_cXfig)(i);
00551     }
00552   else
00553     {
00554       l3 = Max(0,Min(maxdash-1,(*value)-1));
00555       ScilabGCXfig.CurDashStyle = l3;
00556     }
00557 }
00558 
00559 void C2F(setdashXfig)(integer *value, integer *v2, integer *v3, integer *v4)
00560 {
00561   integer maxdash = MAXDASH ;
00562   integer l3 ;
00563 
00564   if ( ScilabGCXfig_is_initialized == FALSE ) {
00565     sciprint("xinit must be called before any action \r\n");
00566     return;
00567   }
00568 
00569   l3 = Max(0,Min(maxdash-1,(*value)-1));
00570   ScilabGCXfig.CurDashStyle = l3;
00571 }
00572 
00573 void C2F(set_dash_and_color_Xfig)(integer *value, integer *v2, integer *v3, integer *v4)
00574 {
00575   if ( ScilabGCXfig_is_initialized == FALSE ) {
00576     sciprint("xinit must be called before any action \r\n");
00577     return;
00578   }
00579 
00580   C2F(setdashXfig)(value, v2, v3, v4); 
00581   C2F(setpatternXfig)(value+6, v2, v3, v4);
00582 }
00583 
00584 /* style arguments sets either dash style either color */
00585 void C2F(set_line_style_Xfig)(integer *value, integer *v2, integer *v3, integer *v4)
00586 {
00587   integer j; 
00588 
00589   if ( ScilabGCXfig_is_initialized == FALSE ) {
00590     sciprint("xinit must be called before any action \r\n");
00591     return;
00592   }
00593   
00594   if (ScilabGCXfig.CurColorStatus == 0) {
00595     C2F(setdashXfig)(value,PI0,PI0,PI0);
00596     C2F(setpatternXfig)((j=1,&j),PI0,PI0,PI0);
00597   }
00598   else {
00599     j= ScilabGCXfig.CurDashStyle + 1;
00600     C2F(setdashXfig)(&j,PI0,PI0,PI0);
00601     C2F(setpatternXfig)(value,PI0,PI0,PI0);
00602   }
00603 }
00604 
00607 /* old version of getdashXfig retained for compatibility */
00608 
00609 void C2F(get_dash_or_color_Xfig)(integer *verbose, integer *value, integer *narg, double *dummy)
00610 {
00611   *narg =1 ;
00612 
00613   if ( ScilabGCXfig_is_initialized == FALSE ) {
00614     sciprint("xinit must be called before any action \r\n");
00615     return;
00616   }
00617   
00618   if ( ScilabGCXfig.CurColorStatus ==1) 
00619     {
00620       *value=ScilabGCXfig.CurColor + 1;
00621       if (*verbose == 1) sciprint("Color %d",(int)*value);
00622       return;
00623     }
00624 
00625   C2F(getdashXfig)(verbose, value+1, narg,dummy);
00626   *narg=*narg+1;
00627     
00628 }
00629 
00630 void C2F(getdashXfig)(integer *verbose, integer *value, integer *narg, double *dummy)
00631 {
00632   integer i;
00633   
00634   if ( ScilabGCXfig_is_initialized == FALSE ) {
00635     sciprint("xinit must be called before any action \r\n");
00636     return;
00637   }
00638   
00639   i=ScilabGCXfig.CurDashStyle;
00640 
00641   *narg = 3;
00642   value[0]=i+1;
00643   value[1]=DashTab[i];
00644   value[2]=DashTabStyle[i];
00645   if (*verbose ==1 ) 
00646     {
00647       sciprint("\nDash Style %d.",(int) *value);
00648       sciprint("%d %d ",(int)value[1],(int)value[2]);
00649       sciprint(">\n");
00650     }
00651  
00652 }
00653 void C2F(get_dash_and_color_Xfig)(integer *verbose, integer *value, integer *narg, double *dummy)
00654 {
00655   /*may be improved replacing 6 by narg */
00656   
00657   if ( ScilabGCXfig_is_initialized == FALSE ) {
00658     sciprint("xinit must be called before any action \r\n");
00659     return;
00660   }
00661   
00662   C2F(getdashXfig)(verbose, value, narg,dummy);
00663   C2F(getpatternXfig)(verbose, value+6, narg,dummy);
00664   *narg = 6;
00665 }
00666 
00667 
00668 void C2F(usecolorXfig)(integer *num, integer *v2, integer *v3, integer *v4)
00669 {
00670   integer i;
00671   
00672   if ( ScilabGCXfig_is_initialized == FALSE ) {
00673     sciprint("xinit must be called before any action \r\n");
00674     return;
00675   }
00676   
00677   i =  Min(Max(*num,0),1);
00678   if (  ScilabGCXfig.CurColorStatus != (int) i) 
00679     {
00680       if (ScilabGCXfig.CurColorStatus == 1) 
00681         {
00682           /* je passe de Couleur a n&b */
00683           /* remise des couleurs a vide */
00684           ScilabGCXfig.CurColorStatus = 1;
00685           C2F(setpatternXfig)((i=1,&i),PI0,PI0,PI0);
00686           /* passage en n&b */
00687           ScilabGCXfig.CurColorStatus = 0;
00688           i= ScilabGCXfig.CurPattern+1;
00689           C2F(setpatternXfig)(&i,PI0,PI0,PI0);
00690           i= ScilabGCXfig.CurDashStyle+1;
00691           C2F(setdashXfig)(&i,PI0,PI0,PI0);
00692           ScilabGCXfig.IDLastPattern = GREYNUMBER - 1;
00693         }
00694       else 
00695         {
00696           /* je passe en couleur */
00697           /* remise a zero des patterns et dash */
00698           /* remise des couleurs a vide */
00699           ScilabGCXfig.CurColorStatus = 0;
00700           C2F(setpatternXfig)((i=1,&i),PI0,PI0,PI0);
00701           C2F(setdashXfig)((i=1,&i),PI0,PI0,PI0);
00702           /* passage en couleur  */
00703           ScilabGCXfig.CurColorStatus = 1;
00704           i= ScilabGCXfig.CurColor+1;
00705           C2F(setpatternXfig)(&i,PI0,PI0,PI0);
00706           ScilabGCXfig.IDLastPattern = ScilabGCXfig.Numcolors -1;
00707         }
00708     }
00709 }
00710 
00711 
00712 void C2F(getusecolorXfig)(integer *verbose, integer *num, integer *narg, double *dummy)
00713 {
00714 
00715   if ( ScilabGCXfig_is_initialized == FALSE ) {
00716     sciprint("xinit must be called before any action \r\n");
00717     return;
00718   }
00719  
00720   *num = ScilabGCXfig.CurColorStatus;
00721 
00722   if (*verbose == 1) 
00723     sciprint("\n Use color %d\r\n",(int)*num);
00724   *narg=1;
00725 }
00726 
00727 
00728 /*******************************************************
00729  * Setting the colormap
00730  * Attention :
00731  *   cette fonction n'est utilis'ee que si l''on est sous
00732  *   le peripherique Xfig et que l'on appelle
00733  *   explicitement xset("colormap",....)
00734  * ds le cas usuel comme cette fonction n'est pas
00735  * enregistree ds Rec.c elle ne doit pas etre appellee
00736  ******************************************************/
00737 void setcolormapgXfig(struct  BCG *Xgc,integer *v1,integer *v2, double *a, integer *v3);/* NG */
00738 
00739 void C2F(setgccolormapXfig)(struct BCG *Xgc,integer m, double *a, integer *v3)
00740 {
00741   int i,mm;
00742 
00743   if ( ScilabGCXfig_is_initialized == FALSE ) {
00744     sciprint("xinit must be called before any action \r\n");
00745     return;
00746   }
00747  
00748   sciprint("Warning : you will have to move the colors definition\n");
00749   sciprint(" at the top of the xfig file \n");
00750 
00751   /* Checking RGB values */
00752   for (i = 0; i < m; i++) {
00753     if (a[i] < 0 || a[i] > 1 || a[i+m] < 0 || a[i+m] > 1 ||
00754         a[i+2*m] < 0 || a[i+2*m]> 1) {
00755       sciprint("RGB values must be between 0 and 1\n");
00756       *v3 = 1;
00757       return;
00758     }
00759   }
00760   Xgc->Numcolors = m;
00761   Xgc->IDLastPattern = m - 1;
00762   Xgc->NumForeground = m;
00763   Xgc->NumBackground = m + 1;
00764   for ( i=0; i < m ; i++)
00765     {
00766       unsigned short ur,ug,ub;
00767       ur = (unsigned short) (255.0*a[i]);
00768       ug = (unsigned short) (255.0*a[i+m]);
00769       ub = (unsigned short) (255.0*a[i+2*m]);
00770       FPRINTF((file,"0 %d #%02x%02x%02x \n",32+i,ur,ug,ub));
00771     }
00772   FPRINTF((file,"0 %d #%02x%02x%02x \n",32+m,0,0,0));
00773   FPRINTF((file,"0 %d #%02x%02x%02x \n",32+m+1,255,255,255));
00774   C2F(usecolorXfig)((i=1,&i) ,PI0,PI0,PI0);
00775   C2F(setalufunction1Xfig)((i=3,&i),PI0,PI0,PI0);
00776   C2F(setpatternXfig)((i=Xgc->NumForeground+1,&i),PI0,PI0,PI0);  
00777   C2F(setforegroundXfig)((i=Xgc->NumForeground+1,&i),PI0,PI0,PI0);
00778   C2F(setbackgroundXfig)((i=Xgc->NumForeground+2,&i),PI0,PI0,PI0);
00779 
00780 
00781   /* -------------------------------------------------------- */
00782   /* store the colormap for the get command too */
00783   /* F.Leray 04.10.05 */
00784   FREE(Xgc->Red);
00785   FREE(Xgc->Green);
00786   FREE(Xgc->Blue);
00787   
00788   /* don't forget black and white */
00789   mm = m;
00790   if (!(Xgc->Red = (float *) MALLOC(mm*sizeof(float)))) {
00791     sciprint("XgcAllocColors: unable to alloc\n");
00792     return;
00793   }
00794   if (!(Xgc->Green = (float *) MALLOC(mm*sizeof(float)))) {
00795     sciprint("XgcAllocColors: unable to alloc\n");
00796     FREE(Xgc->Red);
00797     return;
00798   }
00799   if (!(Xgc->Blue = (float *) MALLOC(mm*sizeof(float)))) {
00800     sciprint("XgcAllocColors: unable to alloc\n");
00801     FREE(Xgc->Red);
00802     FREE(Xgc->Green);
00803     return;
00804   }
00805   
00806   for(i=0;i<m;i++){
00807     Xgc->Red[i] = (float)a[i];
00808     Xgc->Green[i] = (float)a[i+m];
00809     Xgc->Blue[i] = (float)a[i+2*m]; 
00810   }
00811   /* -------------------------------------------------------- */
00812     
00813 }
00814 
00815 void C2F(getcolormapsizeXfig)(integer *v1, integer *v2, integer *v3, double *val)
00816 {
00817   if ( ScilabGCXfig_is_initialized == FALSE ) {
00818     sciprint("xinit must be called before any action \r\n");
00819     *v3 = 1;
00820     return;
00821   }
00822 
00823   *v2 = ScilabGCXfig.Numcolors;
00824 }
00825 
00826 /* F.Leray 22.11.05: get the current colormap */
00827 
00828 void C2F(getcolormapXfig)(integer *v1, integer *v2, integer *v3, double *val)
00829 {
00830   int m;
00831   int i;
00832   *v3 = 0;
00833   
00834   if ( ScilabGCXfig_is_initialized == FALSE ) {
00835     sciprint("xinit must be called before any action \r\n");
00836     *v3 = 1;
00837     return;
00838   }
00839   
00840   
00841   m = ScilabGCXfig.Numcolors;
00842 
00843   for (i = 0; i < m; i++) {
00844     val[i] = (double)ScilabGCXfig.Red[i];
00845     val[i+m] = (double)ScilabGCXfig.Green[i];
00846     val[i+2*m] = (double)ScilabGCXfig.Blue[i];
00847   }
00848 }
00849 
00850 
00851 void C2F(setcolormapXfig)(integer *v1, integer *v2, integer *v3, integer *v4, integer *v5, integer *v6, double *a)
00852 {
00853  
00854   int m;
00855 
00856   *v3 = 0;
00857 
00858   if ( ScilabGCXfig_is_initialized == FALSE ) {
00859     sciprint("xinit must be called before any action \r\n");
00860     *v3 = 1;
00861     return;
00862   }
00863  
00864   sciprint("Warning : you will have to move the colors definition\n");
00865   sciprint(" at the top of the xfig file \n");
00866   if (*v2 != 3 ||  *v1 < 0) {
00867     sciprint("Colormap must be a m x 3 array \n");
00868     *v3 = 1;
00869     return;
00870   }
00871   m = *v1;
00872   C2F(setgccolormapXfig)(&ScilabGCXfig, m, a, v3);
00873 }
00874 
00875 /* add *v3 (OUT) to know if colormap allocation has succeeded: */
00876 /* 0: succeed */
00877 /* 1: failed */
00878 /* NG beg*/
00879 void setcolormapgXfig(struct  BCG *Xgc,integer *m,integer *v2, double *a, integer *v3) /* NG */
00880 {
00881 
00882   C2F(setgccolormapXfig)(Xgc,*m, a, v3);
00883 }
00884 
00885 void C2F(set_cXfig)(integer i)
00886 {
00887   integer j;
00888 
00889   if ( ScilabGCXfig_is_initialized == FALSE ) {
00890     sciprint("xinit must be called before any action \r\n");
00891     return;
00892   }
00893 
00894   j=Max(Min(i,ScilabGCXfig.Numcolors+1),0);
00895   ScilabGCXfig.CurColor=j;
00896   FPRINTF((file,"# %d Setcolor\n",(int)i));
00897 }
00898 
00901 void C2F(setbackgroundXfig)(integer *num, integer *v2, integer *v3, integer *v4)
00902 { 
00903   
00904   if ( ScilabGCXfig_is_initialized == FALSE ) {
00905     sciprint("xinit must be called before any action \r\n");
00906     return;
00907   }
00908   
00909   if (ScilabGCXfig.CurColorStatus == 1) 
00910     {
00911       ScilabGCXfig.NumBackground = Max(0,Min(*num - 1,ScilabGCXfig.Numcolors+1));
00912     }
00913 }
00914 
00915 void C2F(getbackgroundXfig)(integer *verbose, integer *num, integer *narg, double *dummy)
00916 { 
00917   *narg=1;
00918   
00919   if ( ScilabGCXfig_is_initialized == FALSE ) {
00920     sciprint("xinit must be called before any action \r\n");
00921     return;
00922   }
00923   
00924   if ( ScilabGCXfig.CurColorStatus == 1 ) 
00925     {
00926       *num = ScilabGCXfig.NumBackground + 1;
00927     }
00928   else 
00929     {
00930       *num = 1;
00931     }
00932   if (*verbose == 1) 
00933     sciprint("\n Background : %d\r\n",*num);
00934 }
00935 
00936 
00939 void C2F(setforegroundXfig)(integer *num, integer *v2, integer *v3, integer *v4)
00940 { 
00941   
00942   if ( ScilabGCXfig_is_initialized == FALSE ) {
00943     sciprint("xinit must be called before any action \r\n");
00944     return;
00945   }
00946   
00947   if (ScilabGCXfig.CurColorStatus == 1) 
00948     {
00949       ScilabGCXfig.NumForeground = Max(0,Min(*num - 1,ScilabGCXfig.Numcolors+1));
00950     }
00951 }
00952 
00953 void C2F(getforegroundXfig)(integer *verbose, integer *num, integer *narg, double *dummy)
00954 { 
00955   *narg=1;
00956 
00957   if ( ScilabGCXfig_is_initialized == FALSE ) {
00958     sciprint("xinit must be called before any action \r\n");
00959     return;
00960   }
00961 
00962   if ( ScilabGCXfig.CurColorStatus == 1 ) 
00963     {
00964       *num = ScilabGCXfig.NumForeground + 1;
00965     }
00966   else 
00967     {
00968       *num = ScilabGCXfig.IDLastPattern + 1;
00969     }
00970   if (*verbose == 1) 
00971     sciprint("\n Foreground : %d\r\n",*num);
00972 }
00973 
00976 void C2F(sethidden3dXfig)(integer *num, integer *v2, integer *v3, integer *v4)
00977 { 
00978   if ( ScilabGCXfig_is_initialized == FALSE ) {
00979     sciprint("xinit must be called before any action \r\n");
00980     return;
00981   }
00982 
00983   if (ScilabGCXfig.CurColorStatus == 1) 
00984     {
00985       /* es: Max(0,... -> Max(-1,... */
00986       /* S Mottelet: Max(-1,... -> Max(-2,...  to take into account the value -1 */
00987       ScilabGCXfig.NumHidden3d = Max(-2,Min(*num - 1,ScilabGCXfig.Numcolors + 1));
00988     }
00989 }
00990 
00991 void C2F(gethidden3dXfig)(integer *verbose, integer *num, integer *narg, double *dummy)
00992 { 
00993   *narg=1;
00994 
00995  if ( ScilabGCXfig_is_initialized == FALSE ) {
00996     sciprint("xinit must be called before any action \r\n");
00997     return;
00998   }
00999 
01000   if ( ScilabGCXfig.CurColorStatus == 1 ) 
01001     {
01002       *num = ScilabGCXfig.NumHidden3d + 1;
01003     }
01004   else 
01005     {
01006       *num = 1; 
01007     }
01008   if (*verbose == 1) 
01009     sciprint("\n Hidden3d : %d\r\n",*num);
01010 }
01011 
01012 
01013 
01016 /* void C2F(xsetfontXfig)(integer *fontid, integer *fontsize, integer *v3, integer *v4) */
01017 /* { integer i,fsiz; */
01018 /*   i = Min(FONTNUMBER-1,Max(*fontid,0)); */
01019 /*   fsiz = Min(FONTMAXSIZE-1,Max(*fontsize,0)); */
01020 /*   if ( FontInfoTabXfig_[i].ok !=1 ) */
01021 /*     sciprint("\n Sorry This Font is Not available\n"); */
01022 /*   else  */
01023 /*    { */
01024 /*      ScilabGCXfig.FontId = i; */
01025 /*      ScilabGCXfig.FontSize = fsiz; */
01026 /*      FPRINTF((file,"#/%s findfont %d scalefont setfont\n", */
01027 /*                   FontInfoTabXfig_[i].fname, */
01028 /*           (int)isizeXfig_[fsiz]*prec_fact)); */
01029 /*    } */
01030 /* } */
01031 
01032 void C2F(xsetfontXfig)(integer *fontid, integer *fontsize, integer *v3, integer *v4)
01033 { 
01034   integer i,fsiz;
01035 
01036   if ( ScilabGCXfig_is_initialized == FALSE ) {
01037     sciprint("xinit must be called before any action \r\n");
01038     return;
01039   }
01040 
01041   i = Min(FONTNUMBER-1,Max(*fontid,0));
01042   fsiz = Min(FONTMAXSIZE-1,Max(*fontsize,0));
01043 
01044   if ( FontInfoTabXfig_[i].ok !=1 )
01045     {
01046       /* currently this case occurs only when i=FONTNUMBER-1 */
01047       sciprint("\n Sorry This Font is Not available: use default font (Times)\n");
01048       i = 2;
01049     }
01050   ScilabGCXfig.FontId = i;
01051   ScilabGCXfig.FontSize = fsiz;
01052   FPRINTF((file,"#/%s findfont %d scalefont setfont\n",
01053            FontInfoTabXfig_[i].fname,
01054            (int)isizeXfig_[fsiz]*prec_fact));
01055 }
01056 
01059 void C2F(xgetfontXfig)(integer *verbose, integer *font, integer *nargs, double *dummy)
01060 {
01061   *nargs=2;
01062 
01063   if ( ScilabGCXfig_is_initialized == FALSE ) {
01064     sciprint("xinit must be called before any action \r\n");
01065     return;
01066   }
01067 
01068   font[0]= ScilabGCXfig.FontId ;
01069   font[1] =ScilabGCXfig.FontSize ;
01070   if (*verbose == 1) 
01071     {
01072       sciprint("\nFontId : %d ",ScilabGCXfig.FontId );
01073       sciprint("--> %s at size",
01074              FontInfoTabXfig_[ScilabGCXfig.FontId].fname);
01075       sciprint("%s pts\r\n",sizeXfig_[ScilabGCXfig.FontSize]);
01076     }
01077 }
01078 
01081 void C2F(setcursymbolXfig)(integer *number, integer *size, integer *v3, integer *v4)
01082 { 
01083   if ( ScilabGCXfig_is_initialized == FALSE ) {
01084     sciprint("xinit must be called before any action \r\n");
01085     return;
01086   }
01087 
01088   ScilabGCXfig.CurHardSymb =
01089     Max(Min(SYMBOLNUMBER-1,*number),0);
01090   ScilabGCXfig.CurHardSymbSize = 
01091     Max(Min(FONTMAXSIZE-1,*size),0);
01092 ;}
01093 
01096 void C2F(getcursymbolXfig)(integer *verbose, integer *symb, integer *narg, double *dummy)
01097 {
01098   *narg =2 ;
01099 
01100   if ( ScilabGCXfig_is_initialized == FALSE ) {
01101     sciprint("xinit must be called before any action \r\n");
01102     return;
01103   }
01104 
01105   symb[0] = ScilabGCXfig.CurHardSymb ;
01106   symb[1] = ScilabGCXfig.CurHardSymbSize ;
01107   if (*verbose == 1) 
01108   {
01109     sciprint("\nMark : %d",ScilabGCXfig.CurHardSymb);
01110     sciprint("at size %s pts\r\n",
01111           sizeXfig_[ScilabGCXfig.CurHardSymbSize]);
01112   }
01113 }
01114 
01115 
01116 /*--------------------------------------------------------
01117 \encadre{general routines accessing the  set<> or get<>
01118  routines } 
01119 -------------------------------------------------------*/
01120 
01121 void C2F(semptyXfig)(integer *verbose, integer *v2, integer *v3, integer *v4)
01122 {
01123   if ( *verbose ==1 ) sciprint("\n No operation ");
01124 }
01125 
01126 void C2F(gemptyXfig)(integer *verbose, integer *v2, integer *v3, double *dummy)
01127 {
01128   if ( *verbose ==1 ) sciprint("\n No operation ");
01129 }
01130 
01131 
01132 
01133 #define NUMSETFONC 32 /* NG */
01134 
01135 struct bgc { char *name ;
01136              void  (*setfonc )() ;
01137              void  (*getfonc )() ;}
01138   ScilabGCTabXfig_[] = {
01139    {"alufunction",C2F(setalufunction1Xfig),C2F(getalufunctionXfig)},
01140    {"background",C2F(setbackgroundXfig),C2F(getbackgroundXfig)},
01141    {"clipoff",C2F(unsetclipXfig),C2F(getclipXfig)},
01142    {"clipping",C2F(setclipXfig),C2F(getclipXfig)},
01143    {"cmap_size",C2F(semptyXfig),C2F(getcolormapsizeXfig)},
01144    {"color",C2F(setpatternXfig),C2F(getpatternXfig)},
01145    {"colormap",C2F(setcolormapXfig),C2F(getcolormapXfig)},
01146    {"dashes",C2F(set_dash_or_color_Xfig),C2F(set_dash_or_color_Xfig)},
01147    {"default",C2F(InitScilabGCXfig), C2F(gemptyXfig)},
01148    {"figure",C2F(setscilabFigureXfig),C2F(getscilabFigureXfig)},/* NG */
01149    {"font",C2F(xsetfontXfig),C2F(xgetfontXfig)},
01150    {"foreground",C2F(setforegroundXfig),C2F(getforegroundXfig)},
01151    {"gc",C2F(semptyXfig),C2F(getscilabxgcXfig)},/* NG */
01152    {"gccolormap",C2F(setgccolormapXfig),C2F(gemptyXfig)},/* NG */
01153    {"hidden3d",C2F(sethidden3dXfig),C2F(gethidden3dXfig)},
01154    {"lastpattern",C2F(semptyXfig),C2F(getlastXfig)},
01155    {"line mode",C2F(absourelXfig),C2F(getabsourelXfig)},
01156    {"line style",C2F(setdashXfig),C2F(getdashXfig)},
01157    {"mark",C2F(setcursymbolXfig),C2F(getcursymbolXfig)},
01158    {"pattern",C2F(setpatternXfig),C2F(getpatternXfig)},
01159    {"pixmap",C2F(semptyXfig),C2F(gemptyXfig)},
01160    {"thickness",C2F(setthicknessXfig),C2F(getthicknessXfig)},
01161    {"use color",C2F(usecolorXfig),C2F(getusecolorXfig)},
01162    {"viewport",C2F(semptyXfig),C2F(gemptyXfig)},
01163    {"wdim",C2F(setwindowdimXfig),C2F(getwindowdimXfig)},
01164    {"white",C2F(semptyXfig),C2F(getlastXfig)},
01165    {"window",C2F(setcurwinXfig),C2F(getcurwinXfig)},
01166    {"wpdim",C2F(semptyXfig),C2F(gemptyXfig)},
01167    {"wpos",C2F(setwindowposXfig),C2F(getwindowposXfig)},
01168    {"wresize",C2F(semptyXfig),C2F(gemptyXfig)},
01169    {"wshow",C2F(semptyXfig),C2F(gemptyXfig)},
01170    {"wwpc",C2F(semptyXfig),C2F(gemptyXfig)},
01171  };
01172 
01173 
01174 
01175 #ifdef lint
01176 
01177 /* pour forcer lint a verifier ca */
01178 
01179 static
01180 test(str,flag,verbose,x1,x2,x3,x4,x5)
01181      char str[];
01182      integer flag ;
01183      integer  *verbose,*x1,*x2,*x3,*x4,*x5;
01184 { 
01185   double *dv;
01186   C2F(setalufunction1Xfig)(x1,x2,x3,x4);C2F(getalufunctionXfig)(verbose,x1,x2,dv);
01187   C2F(setclipXfig)(x1,x2,x3,x4);C2F(getclipXfig)(verbose,x1,x2,dv);
01188   C2F(setdashXfig)(x1,x2,x3,x4);C2F(getdashXfig)(verbose,x1,x2,dv);
01189   ScilabGCXfig_is_initialized = TRUE; /* add the flag ScilabGCXfig_is_initialized to test if xinit has been called */
01190   C2F(InitScilabGCXfig)(x1,x2,x3,x4); C2F(gemptyXfig)(verbose,x1,x2,dv);
01191   C2F(xsetfontXfig)(x1,x2,x3,x4);C2F(xgetfontXfig)(verbose,x1,x2,dv);
01192   C2F(absourelXfig)(x1,x2,x3,x4);C2F(getabsourelXfig)(verbose,x1,x2,dv);
01193   C2F(setcursymbolXfig)(x1,x2,x3,x4);C2F(getcursymbolXfig)(verbose,x1,x2,dv);
01194   C2F(setpatternXfig)(x1,x2,x3,x4);C2F(getpatternXfig)(verbose,x1,x2,dv);
01195   C2F(setthicknessXfig)(x1,x2,x3,x4);C2F(getthicknessXfig)(verbose,x1,x2,dv);
01196   C2F(usecolorXfig)(x1,x2,x3,x4);C2F(gemptyXfig)(verbose,x1,x2,dv);
01197   C2F(setwindowdimXfig)(x1,x2,x3,x4);C2F(getwindowdimXfig)(verbose,x1,x2,dv);
01198   C2F(semptyXfig)(x1,x2,x3,x4);C2F(getlastXfig)(verbose,x1,x2,dv);
01199   C2F(setcurwinXfig)(x1,x2,x3,x4);C2F(getcurwinXfig)(verbose,x1,x2,dv);
01200   C2F(setwindowposXfig)(x1,x2,x3,x4);getwindowposXfig(verbose,x1,x2,dv);
01201   
01202 }
01203 
01204 #endif 
01205 
01206 
01207 void C2F(scilabgcgetXfig)(char *str, integer *verbose, integer *x1, integer *x2, integer *x3, integer *x4, integer *x5, double *dx1, double *dx2, double *dx3, double *dx4)
01208 {
01209   int x6=0;
01210   C2F(ScilabGCGetorSetXfig)(str,(integer)1L,verbose,x1,x2,x3,x4,x5,&x6,dx1);
01211 }
01212 
01213 void C2F(scilabgcsetXfig)(char *str, integer *x2, integer *x3, integer *x4, integer *x5, integer *x6, integer *x7, double *dx1, double *dx2, double *dx3, double *dx4)
01214 {
01215  integer verbose ;
01216  verbose = 0 ;
01217  C2F(ScilabGCGetorSetXfig)(str,(integer)0L,&verbose,x2,x3,x4,x5,x6,x7,dx1);
01218 }
01219 
01220 void C2F(ScilabGCGetorSetXfig)(char *str, integer flag, integer *verbose, integer *x1, integer *x2, integer *x3, integer *x4, integer *x5, integer *x6, double *dx1)
01221 { integer i ;
01222   for (i=0; i < NUMSETFONC ; i++)
01223      {
01224        integer j;
01225        j = strcmp(str,ScilabGCTabXfig_[i].name);
01226        if ( j == 0 ) 
01227          { if (*verbose == 1)
01228              sciprint("\nGetting Info on %s\r\n",str);
01229            if (flag == 1)
01230              (ScilabGCTabXfig_[i].getfonc)(verbose,x1,x2,dx1);
01231            else 
01232              (ScilabGCTabXfig_[i].setfonc)(x1,x2,x3,x4,x5,x6,dx1);
01233            return;}
01234        else 
01235          { if ( j <= 0)
01236              {
01237                sciprint("\nUnknow Postscript operator <%s>\r\n",str);
01238                *x1=1;*x2=0;
01239                return;
01240              }
01241          }
01242      }
01243   sciprint("\n Unknow Postscript operator <%s>\r\n",str);
01244   *x1=1;*x2=0;
01245 }
01246 
01247 /*-----------------------------------------------------------
01248 \encadre{Functions for drawing}
01249 -----------------------------------------------------------*/
01250 
01251 
01252 
01253 /*----------------------------------------------------
01254 \encadre{display of a string
01255  at (x,y) position whith angle (alpha). Angles in degree
01256  positive when clockwise. If *flag ==1 a framed  box is added 
01257  around the string.}
01258 -----------------------------------------------------*/
01259 
01260 void C2F(displaystringXfig)(char *string, integer *x, integer *y, integer *v1, integer *flag, integer *v6, integer *v7, double *angle, double *dv2, double *dv3, double *dv4)
01261 {    
01262   integer rect[4], font=-1,font_flag=2;
01263   integer verbose=0,Dnarg,Dvalue1[10];
01264   int pen_color;
01265 
01266   if ( ScilabGCXfig_is_initialized == FALSE ) {
01267     sciprint("xinit must be called before any action \r\n");
01268     return;
01269   }
01270 
01271   C2F(boundingboxXfig)(string,x,y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
01272   if (string[0]== '$') 
01273     {
01274       font=-1;
01275       font_flag=2;
01276     }
01277   else 
01278     {
01279       font =  xfig_font[ScilabGCXfig.FontId];
01280       font_flag= 4; 
01281     };
01282   C2F(getpatternXfig)(&verbose,Dvalue1,&Dnarg,vdouble);
01283   
01284 
01285   C2F(getpatternXfig)(&verbose,Dvalue1,&Dnarg,vdouble);
01286   set_color(Dvalue1[0],&pen_color);
01287   FPRINTF((file,"4 0 %d 0 0 %d %d %5.2f %d %5.2f %5.2f %d %d %s\\001\n",
01288           pen_color,
01289           (int)font,
01290           (int)isizeXfig_[ScilabGCXfig.FontSize],
01291           -(M_PI/180.0)*(*angle),
01292           (int)font_flag,
01293           (double) rect[3],
01294           (double) rect[2],
01295           (int)*x,
01296           (int)*y,
01297           string));
01298   if ( *flag == 1) 
01299     {
01300       rect[0]=rect[0]-4;rect[2]=rect[2]+6;
01301       C2F(drawrectangleXfig)(string,rect,rect+1,rect+2,rect+3,PI0,PI0,PD0,PD0,PD0,PD0);
01302     }
01303 }
01304 
01305 integer bsizeXfig_[6][4]= {{ 0, -7,  463, 9  },
01306                            { 0, -9,  574, 12 },
01307                            { 0, -11, 674, 14 },
01308                            { 0, -12, 779, 15 },
01309                            { 0, -15, 972, 19 },
01310                            { 0, -20,1341, 26 }};
01311 
01314 void C2F(boundingboxXfig)(char *string, integer *x, integer *y, integer *rect, integer *v5, integer *v6, integer *v7, double *dx1, double *dx2, double *dx3, double *dx4)
01315 {integer verbose,nargs,font[2];
01316  verbose=0;
01317 
01318  C2F(xgetfontXfig)(&verbose,font,&nargs,vdouble);
01319  rect[0]= (int)(*x+bsizeXfig_[font[1]][0]*((double) prec_fact));
01320  rect[1]= (int)(*y+bsizeXfig_[font[1]][1]*((double) prec_fact));
01321  rect[2]= (int)(((double)prec_fact)*(bsizeXfig_[font[1]][2]/100.0)*((double)strlen(string)));
01322  rect[3]= (int)(bsizeXfig_[font[1]][3]*((double) prec_fact));
01323 }
01324 
01331 int symb_xw[FONTMAXSIZE][SYMBOLNUMBER]={
01332   {15,75,60,90,90,90,90,90,90,90},
01333   {30,75,75,105,75,105,105,105,75,105},
01334   {15,75,75,135,90,135,135,135,105,135},
01335   {30,105,105,135,105,165,150,165,120,150},
01336   {30,120,135,195,135,210,195,195,135,195},
01337   {45,150,150,255,195,270,255,270,195,255}
01338 };
01339 
01340 int symb_yh[FONTMAXSIZE][SYMBOLNUMBER]={
01341   {30,75,75,90,90,90,90,90,90,90},
01342   {30,90,90,120,105,105,105,105,105,105},
01343   {45,105,105,150,90,110,120,135,110,135},
01344   {45,120,120,150,105,165,135,160,125,150},
01345   {60,150,150,210,135,195,165,195,165,195},
01346   {90,180,195,270,180,270,230,270,195,270}
01347 };
01348 
01349 
01355 void C2F(boundingboxXfigM)(char *string, integer *x, integer *y, integer *rect, integer *v5, integer *v6, integer *v7, double *dx1, double *dx2, double *dx3, double *dx4)
01356 {
01357   integer verbose,nargs,font[2];
01358   verbose=0;
01359   C2F(xgetfontXfig)(&verbose,font,&nargs,vdouble);
01360   rect[0]= (int)(*x+bsizeXfig_[font[1]][0]*((double) prec_fact));
01361   rect[1]= (int)(*y+bsizeXfig_[font[1]][1]*((double) prec_fact));
01362   rect[2]= (int)(symb_xw[ScilabGCXfig.CurHardSymbSize][ScilabGCXfig.CurHardSymb]);
01363   rect[3]= (int)(symb_yh[ScilabGCXfig.CurHardSymbSize][ScilabGCXfig.CurHardSymb]);
01364 }
01365 
01366 
01367 
01371 void C2F(drawlineXfig)(integer *x1, integer *yy1, integer *x2, integer *y2)
01372 {  
01373   if ( ScilabGCXfig_is_initialized == FALSE ) {
01374     sciprint("xinit must be called before any action \r\n");
01375     return;
01376   }
01377   
01378   FPRINTF((file,"# %d %d %d %d L\n",(int)*x1,(int)*yy1,(int)*x2,(int)*y2));
01379 }
01380 
01389 void C2F(drawsegmentsXfig)(char *str, integer *vx, integer *vy, integer *n, integer *style, integer *iflag, integer *v7, double *dx1, double *dx2, double *dx3, double *dx4)
01390 {
01391   integer NDvalue,i;
01392   int l_style,style_val,pen_color,fill_color,areafill;
01393   integer verbose=0,Dnarg,Dvalue[10],Dvalue1[10];
01394 
01395   if ( ScilabGCXfig_is_initialized == FALSE ) {
01396     sciprint("xinit must be called before any action \r\n");
01397     return;
01398   }
01399 
01400   /* store the current values */
01401 
01402   /* F.Leray 08.03.04 Init. here for Dvalue[0]: Pb here what is the correct value for Dvalue[0] ?? */
01403   Dvalue[0] = 1;
01404 
01405   for ( i =0 ; i < *n/2 ; i++)
01406     {
01407       if ( (int) *iflag == 0) 
01408         NDvalue=(*style < 0) ? Dvalue[0] : *style;
01409       else
01410         NDvalue=(int) style[i];
01411 
01412 
01414       set_color(NDvalue,&pen_color);
01415       C2F(getdashXfig)(&verbose,Dvalue1,&Dnarg,vdouble);
01416       set_dash(Dvalue1[0],&l_style,&style_val);
01417 
01418       areafill = -1;
01419       fill_color = WHITE;
01420       FPRINTF((file,"# Object : %d %s -<%d>- \n", (int)i,"segments", ScilabGCXfig.CurPattern));
01421       FPRINTF((file,"2 1 %d %d %d %d 0 0 -1 %d.000 0 0 0 0 0 2\n",
01422               l_style,
01423               ScilabGCXfig.CurLineWidth*prec_fact/16,
01424               pen_color,fill_color,
01425               style_val
01426               ));
01427       FPRINTF((file," %d %d %d %d \n",
01428               (int)vx[2*i], (int)vy[2*i], (int)vx[2*i+1], (int)vy[2*i+1]));
01429     }
01430 }
01431 
01437 void C2F(drawarrowsXfig)(char *str, integer *vx, integer *vy, integer *n, integer *as, integer *style, integer *iflag, double *dx1, double *dx2, double *dx3, double *dx4)
01438 {
01439   int i;
01440   int l_style,style_val,pen_color,fill_color,areafill;
01441   integer verbose=0,Dnarg,Dvalue[10],Dvalue1[10],NDvalue;
01442 
01443   if ( ScilabGCXfig_is_initialized == FALSE ) {
01444     sciprint("xinit must be called before any action \r\n");
01445     return;
01446   }
01447 
01448   /* store the current values */
01449   C2F(getdashXfig)(&verbose,Dvalue,&Dnarg,vdouble);
01450   for ( i = 0 ; i < *n/2 ; i++)
01451     {
01452       if ( (int) *iflag == 0) 
01453         NDvalue=(*style < 0) ? Dvalue[0] : *style;
01454       else
01455         NDvalue=(int) style[i];
01456 
01457 
01458       set_color(NDvalue,&pen_color);
01459       C2F(getdashXfig)(&verbose,Dvalue1,&Dnarg,vdouble);
01460            set_dash(Dvalue1[0],&l_style,&style_val);
01462       areafill = -1;
01463       fill_color = WHITE;
01464       FPRINTF((file,"# Object : %d %s -<%d>-\n", (int)i,"arrows", ScilabGCXfig.CurPattern));
01465       FPRINTF((file,"2 1 %d %d %d %d 0 0 -1 %d.000 0 0 0 1 0 2\n",
01466               l_style,
01467               ScilabGCXfig.CurLineWidth*prec_fact/16,
01468               pen_color,fill_color,
01469               style_val
01470               ));
01471       FPRINTF((file,"    0 0 %d %d %d\n",
01472               (int)(1*prec_fact/16), (int)(3*prec_fact), (int) (6*prec_fact)));
01473       FPRINTF((file," %d %d %d %d \n",
01474               (int)vx[2*i], (int)vy[2*i], (int)vx[2*i+1], (int)vy[2*i+1]));
01475     }
01476 }
01477 
01480 void C2F(drawrectangleXfig)(char *str, integer *x, integer *y, integer *width, integer *height, integer *v6, integer *v7, double *dx1, double *dx2, double *dx3, double *dx4)
01481 { 
01482   integer i = 1;
01483   integer fvect[1] ;
01484   integer vects[4];
01485   vects[0]= *x;vects[1]= *y;vects[2]= *width;
01486   vects[3]= *height;
01487   fvect[0] = 0;
01488   
01489   if ( ScilabGCXfig_is_initialized == FALSE ) {
01490     sciprint("xinit must be called before any action \r\n");
01491     return;
01492   }
01493   
01494   C2F(drawrectanglesXfig)(str,vects,fvect,&i,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
01495 }
01496 
01499 void C2F(fillrectangleXfig)(char *str, integer *x, integer *y, integer *width, integer *height, integer *v6, integer *v7, double *dx1, double *dx2, double *dx3, double *dx4)
01500 { 
01501   integer i = 1;
01502   integer vects[4],verb=0,cpat,num;
01503 
01504   if ( ScilabGCXfig_is_initialized == FALSE ) {
01505     sciprint("xinit must be called before any action \r\n");
01506     return;
01507   }
01508 
01509   vects[0]= *x;vects[1]= *y;vects[2]= *width;
01510   vects[3]= *height ; 
01511   C2F(getpatternXfig)(&verb,&cpat,&num,vdouble);
01512   C2F(drawrectanglesXfig)(str,vects,&cpat,&i,PI0,PI0,PI0,PD0,PD0,PD0,PD0);    
01513 }
01514 
01522 void C2F(drawrectanglesXfig)(char *str, integer *vects, integer *fillvect, integer *n, integer *v5, integer *v6, integer *v7, double *dx1, double *dx2, double *dx3, double *dx4)
01523 {
01524   integer cpat,verb,num;
01525   verb=0;
01526 
01527   if ( ScilabGCXfig_is_initialized == FALSE ) {
01528     sciprint("xinit must be called before any action \r\n");
01529     return;
01530   }
01531 
01532   C2F(getpatternXfig)(&verb,&cpat,&num,vdouble);
01533   C2F(WriteGenericXfig)("drawbox",*n,(integer)4L,vects,vects,4*(*n),(integer)0L,fillvect);
01534   C2F(setpatternXfig)(&(cpat),PI0,PI0,PI0);
01535 }
01536 
01537 
01542 /* old version no more used because it allows only full ellipse */
01543 void C2F(fillarcsXfig_old)(char *str, integer *vects, integer *fillvect, integer *n, integer *v5, integer *v6, integer *v7, double *dx1, double *dx2, double *dx3, double *dx4)
01544 {
01545   integer cpat,verb,num;
01546   verb=0;
01547 
01548   if ( ScilabGCXfig_is_initialized == FALSE ) {
01549     sciprint("xinit must be called before any action \r\n");
01550     return;
01551   }
01552 
01553 
01554   C2F(getpatternXfig)(&verb,&cpat,&num,vdouble);
01555   C2F(WriteGenericXfig)("drawarc",*n,(integer)6L,vects,vects,6*(*n),(integer)0L,fillvect);
01556   C2F(setpatternXfig)(&(cpat),PI0,PI0,PI0);
01557 }
01558 
01559 void C2F(fillarcsXfig)(char *str, integer *vects, integer *fillvect, integer *n, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
01560 {
01561   integer verbose=0,Dnarg,pat;
01562   int i,i6;
01563 
01564   if ( ScilabGCXfig_is_initialized == FALSE ) {
01565     sciprint("xinit must be called before any action \r\n");
01566     return;
01567   }
01568 
01569   /* store the current values */
01570   C2F(getpatternXfig)(&verbose,&pat,&Dnarg,vdouble);
01571   for ( i=0 ; i < *n ; i++) 
01572     {
01574       C2F(setpatternXfig)(&fillvect[i],PI0,PI0,PI0);
01575       i6=6*i;
01576       C2F(fillarcXfig)(str,&(vects[i6]),&(vects[i6+1]),&(vects[i6+2]),
01577                       &(vects[i6+3]),&(vects[i6+4]),&(vects[i6+5]) ,dv1, dv2, dv3, dv4);
01578 
01579     }
01580   C2F(setpatternXfig)(&pat,PI0,PI0,PI0);
01581 }
01582 
01583 
01591 /* Old definition no more used because it allows only full ellipse */
01592 void C2F(drawarcsXfig_old)(char *str, integer *vects, integer *style, integer *n, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
01593 {
01594   integer verbose=0,Dnarg,Dvalue[10];
01595   /* store the current values */
01596 
01597   if ( ScilabGCXfig_is_initialized == FALSE ) {
01598     sciprint("xinit must be called before any action \r\n");
01599     return;
01600   }
01601 
01602   C2F(getdashXfig)(&verbose,Dvalue,&Dnarg,vdouble);
01603   C2F(WriteGenericXfig)("Rdrawarc",*n,(integer)6L,vects,vects,6*(*n),(integer)0L,style);
01604   C2F(setdashXfig)( Dvalue,PI0,PI0,PI0);
01605 }
01606 
01607 void C2F(drawarcsXfig)(char *str, integer *vects, integer *style, integer *n, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
01608 {
01609   integer verbose=0,Dnarg,Dvalue[10],NDvalue;
01610   int i,i6;
01611 
01612   if ( ScilabGCXfig_is_initialized == FALSE ) {
01613     sciprint("xinit must be called before any action \r\n");
01614     return;
01615   }
01616 
01617   /* store the current values */
01618   C2F(get_dash_and_color_Xfig)(&verbose,Dvalue,&Dnarg,vdouble);
01619   for ( i=0 ; i < *n ; i++) 
01620     {
01622       NDvalue = style[i];
01623       C2F(set_line_style_Xfig)(&NDvalue,PI0,PI0,PI0);
01624       i6=6*i;
01625       C2F(drawarcXfig)(str,vects+i6,vects+(i6+1),vects+(i6+2),vects+(i6+3),
01626                       vects+(i6+4),vects+(i6+5) , dv1, dv2, dv3, dv4);
01627     }
01628   C2F(set_dash_and_color_Xfig)( Dvalue,PI0,PI0,PI0);
01629 }
01630 
01631 
01635 /*  Old definition no more used  because it allows only full ellipse */
01636 
01637 void C2F(drawarcXfig_old)(char *str, integer *x, integer *y, integer *width, integer *height, integer *angle1, integer *angle2, double *dx1, double *dx2, double *dx3, double *dx4)
01638 { 
01639   integer i =1;
01640   integer fvect[1] ;
01641   integer vects[6];
01642 
01643   if ( ScilabGCXfig_is_initialized == FALSE ) {
01644     sciprint("xinit must be called before any action \r\n");
01645     return;
01646   }
01647 
01648   vects[0]= *x;vects[1]= *y;vects[2]= *width;
01649   vects[3]= *height;vects[4]= *angle1;vects[5]= *angle2;
01650   fvect[0] = ScilabGCXfig.IDLastPattern  +2;
01651   C2F(fillarcsXfig)(str,vects,fvect,&i,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
01652 }
01653 
01654 void C2F(drawarcXfig)(char *str, integer *x, integer *y, integer *width, integer *height, integer *angle1, integer *angle2, double *dv1, double *dv2, double *dv3, double *dv4)
01655 { 
01656   integer vx[365],vy[365],k,n;
01657   float alpha,fact= (float) 0.01745329251994330,w,h;
01658   integer close = 0;  
01659 
01660   if ( ScilabGCXfig_is_initialized == FALSE ) {
01661     sciprint("xinit must be called before any action \r\n");
01662     return;
01663   }
01664 
01665   w = (float) ((*width)/2.0);
01666   h = (float) ((*height)/2.0);
01667   n=Min((*angle2/64),360);
01668   for (k = 0; k < n; ++k) {
01669     alpha=((*angle1/64)+k)*fact;
01670     vx[k] = (integer) (*x + w*(cos(alpha)+1.0));
01671     vy[k] = (integer) (*y + h*(-sin(alpha)+1.0));}
01672     
01673   /* Fix bug 1737 : if n==360 we want a closed circle */
01674   if(n == 360) close = 1;
01675 
01676   C2F(drawClippedPolylineXfig)(str, &n, vx, vy, &close, PI0, PI0, dv1, dv2, dv3, dv4);
01677 }
01678 
01679 
01683 /* Old definition commented out because it allows only full ellipse */
01684 void C2F(fillarcXfig_old)(char *str, integer *x, integer *y, integer *width, integer *height, integer *angle1, integer *angle2, double *dx1, double *dx2, double *dx3, double *dx4)
01685 { 
01686   integer i =1;
01687   integer verb=0,cpat,num ;
01688   integer vects[6];
01689 
01690   if ( ScilabGCXfig_is_initialized == FALSE ) {
01691     sciprint("xinit must be called before any action \r\n");
01692     return;
01693   }
01694 
01695   vects[0]= *x;vects[1]= *y;vects[2]= *width;
01696   vects[3]= *height;vects[4]= *angle1;vects[5]= *angle2;
01697   C2F(getpatternXfig)(&verb,&cpat,&num,vdouble);
01698   C2F(fillarcsXfig)(str,vects,&cpat,&i,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
01699  }
01700 
01701 void C2F(fillarcXfig)(char *str, integer *x, integer *y, integer *width, integer *height, integer *angle1, integer *angle2, double *dv1, double *dv2, double *dv3, double *dv4)
01702 { 
01703   integer vx[365],vy[365],k,k0,kmax,n;
01704   float alpha,fact= (float) 0.01745329251994330,w,h;
01705   integer close = 1;
01706 
01707   if ( ScilabGCXfig_is_initialized == FALSE ) {
01708     sciprint("xinit must be called before any action \r\n");
01709     return;
01710   }
01711 
01712   n=Min((*angle2/64),360);
01713 
01714   w = (float) ((*width)/2.0);
01715   h = (float) ((*height)/2.0);
01716   k0 = 0;
01717   kmax = n-1;
01718 
01719   if (n != 360) {
01720   vx[0] = (integer) (*x + w);
01721   vy[0] = (integer) (*y + h);
01722   k0 = 1;
01723   kmax = n;}
01724 
01725   for (k = k0; k <= kmax; ++k) {
01726     alpha=((*angle1/64)+k)*fact;
01727     vx[k] = (integer) (*x + w*(cos(alpha)+1.0));
01728     vy[k] = (integer) (*y + h*(-sin(alpha)+1.0));}
01729   if (n != 360) {
01730   n++;
01731   vx[n] = (integer) (*x + ((*width)/2.0));
01732   vy[n] = (integer) (*y + ((*height)/2.0)); 
01733   n++;
01734   }
01735   C2F(fillpolylineXfig)(str, &n, vx, vy, &close, PI0, PI0, dv1, dv2, dv3, dv4);
01736  }
01737 
01738 
01739 
01740 
01744 void C2F(drawpolymarkXfig)(char *str, integer *n, integer *vx, integer *vy, integer *v5, integer *v6, integer *v7, double *dx1, double *dx2, double *dx3, double *dx4)
01745 { 
01746   integer keepid,keepsize,  i=1, sz;
01747   
01748   if ( ScilabGCXfig_is_initialized == FALSE ) {
01749     sciprint("xinit must be called before any action \r\n");
01750     return;
01751   }
01752   
01753   sz=ScilabGCXfig.CurHardSymbSize;
01754   keepid =  ScilabGCXfig.FontId;
01755   keepsize= ScilabGCXfig.FontSize;
01756   C2F(xsetfontXfig)(&i,&sz,PI0,PI0);
01757   C2F(displaysymbolsXfig)(str,n,vx,vy);
01758   C2F(xsetfontXfig)(&keepid,&keepsize,PI0,PI0);
01759 }
01760 
01761 char symb_listXfig_[] = {
01762   /*
01763      0x2e : . alors que 0xb7 est un o plein trop gros 
01764      ., +,X,*,diamond(filled),diamond,triangle up,triangle down,trefle,circle*/
01765   (char)0x2e,(char)0x2b,(char)0xb4,(char)0xc5,(char)0xa8,
01766   (char)0xe0,(char)0x44,(char)0xd1,(char)0xa7,(char)0x4f};
01767 
01768 static void C2F(displaysymbolsXfig)(char *str, integer *n, integer *vx, integer *vy)
01769 {
01770   integer fvect[1];
01771   
01772   if ( ScilabGCXfig_is_initialized == FALSE ) {
01773     sciprint("xinit must be called before any action \r\n");
01774     return;
01775   }
01776   
01777   fvect[0] =      ScilabGCXfig.CurPattern;
01778   if ( ScilabGCXfig.CurVectorStyle !=  CoordModeOrigin)
01779     FPRINTF((file,"#/absolu false def\n"));
01780   FPRINTF((file,"#HardMark 0 16#%x put\n",
01781       Char2Int( symb_listXfig_[ScilabGCXfig.CurHardSymb])));
01782   C2F(WriteGenericXfig)("drawpolymark",(integer)1L,(*n)*2,vx,vy,*n,(integer)1L,fvect);
01783   FPRINTF((file,"#/absolu true def\n"));
01784 }
01785 
01791 void C2F(drawpolylinesXfig)(char *str, integer *vectsx, integer *vectsy, integer *drawvect, integer *n, integer *p, integer *v7, double *dx1, double *dx2, double *dx3, double *dx4)
01792 { integer verbose ,symb[2],Mnarg,Dnarg,Dvalue[10],NDvalue,i,close;
01793   verbose =0 ;
01794 
01795   if ( ScilabGCXfig_is_initialized == FALSE ) {
01796     sciprint("xinit must be called before any action \r\n");
01797     return;
01798   }
01799 
01800   /* store the current values */
01801   C2F(getcursymbolXfig)(&verbose,symb,&Mnarg,vdouble);
01802   C2F(get_dash_and_color_Xfig)(&verbose,Dvalue,&Dnarg,vdouble);
01803   for (i=0 ; i< *n ; i++)
01804     {
01805       if (drawvect[i] <= 0)
01806         { 
01807           NDvalue = - drawvect[i] ;
01808           C2F(setcursymbolXfig)(&NDvalue,symb+1,PI0,PI0);
01809           C2F(setdashXfig)(Dvalue,PI0,PI0,PI0);
01810          
01811           C2F(drawpolymarkXfig)(str,p,vectsx+(*p)*i,vectsy+(*p)*i,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
01812         }
01813       else 
01814         {
01815           C2F(set_line_style_Xfig)(drawvect+i,PI0,PI0,PI0);
01816           close = 0;
01817           C2F(drawClippedPolylineXfig)(str,p,vectsx+(*p)*i,vectsy+(*p)*i,&close,PI0,PI0,PD0,PD0,PD0,PD0);
01818         }
01819     }
01821   C2F(set_dash_and_color_Xfig)(Dvalue,PI0,PI0,PI0);
01822   C2F(setcursymbolXfig)(symb,symb+1,PI0,PI0);
01823 }
01824 /*----------------------------------------------------------------------------------*/
01825 /* for the fig driver we need to know if we have at least three distincts points
01826    for polygons and 2 for lines */
01827 static BOOL checkPolygon( integer *polyX, integer *polyY, integer length )
01828 {
01829   
01830   
01831   if ( length <= 2 )
01832   {
01833     return TRUE ;
01834   }
01835   else
01836   {
01837     int i, j   ;
01838     int nbDiff = 0 ;
01839     /* real polygon */
01840     for ( i = 0 ; i < length ; i++ )
01841     {
01842       for ( j = i + 1 ; j < length ; j++ )
01843       {
01844         if ( polyX[j] != polyX[i] || polyY[j] != polyY[i] )
01845         {
01846           nbDiff++ ;
01847           if ( nbDiff >= 3 )
01848           {
01849             /* 3 distincts points have been found */
01850             return TRUE ;
01851           }
01852         }
01853       }
01854     }
01855   }
01856   return FALSE ;
01857 }
01858 /*----------------------------------------------------------------------------------*/
01859 
01860 /*----------------------------------------------------------------------------------*/
01861 /* for the fig driver we need to know if we have at least three distincts points */
01862 /* for each polygon */
01863 static BOOL checkPolygons( integer *polyX, integer *polyY, integer polyLength, integer nbPoly )
01864 {
01865   int   i                ;
01866   int * curPolyX = polyX ;
01867   int * curPolyY = polyY ;
01868   for ( i = 0 ; i < nbPoly ; i++ )
01869   {
01870     /* check every pairs of points in the polygon */
01871     if ( !checkPolygon( curPolyX, curPolyY, polyLength ) )
01872     {
01873       return FALSE ;
01874     }
01875     /* get the pointer on the next polygon */
01876     curPolyX += polyLength ;
01877     curPolyY += polyLength ;
01878   }
01879   return TRUE ;
01880 }
01881 
01882 
01883 
01884 /*----------------------------------------------------------------------------------*/
01885 
01889 /*  if fillvect[i] == 0 draw the boundaries with current color 
01890     if fillvect[i] > 0  draw the boundaries with current color 
01891     then fill with pattern fillvect[i]
01892     if fillvect[i] < 0  fill with pattern - fillvect[i]
01893 */
01894 
01895 
01896 void C2F(fillpolylinesXfig)(char *str, integer *vectsx, integer *vectsy, integer *fillvect, integer *n, integer *p, integer *v7, double *dx1, double *dx2, double *dx3, double *dx4)
01897 {
01898   integer cpat,verb,num;
01899   verb=0;
01900 
01901   if ( ScilabGCXfig_is_initialized == FALSE ) {
01902     sciprint("xinit must be called before any action \r\n");
01903     return;
01904   }
01905 
01906   /* check if every polygon is not flat */
01907   if ( !checkPolygons( vectsx, vectsy, *p, *n ) )
01908   {
01909     return ;
01910   }
01911 
01912   if ( ScilabGCXfig.CurVectorStyle !=  CoordModeOrigin )
01913   {
01914     FPRINTF( (file,"#/absolu false def\n") ) ;
01915   }
01916   C2F(getpatternXfig)(&verb,&cpat,&num,vdouble);
01917   C2F(WriteGenericXfig)("drawpoly",*n,(*p)*2,vectsx,vectsy,(*p)*(*n),(integer)1L,
01918                         fillvect);
01919   C2F(setpatternXfig)(&(cpat),PI0,PI0,PI0);
01920   FPRINTF((file,"#/absolu true def\n"));
01921 }
01922 
01923 /*
01924  * same as drawpolylineXfig but don't perform clipping
01925  */
01926 
01927 void C2F(drawClippedPolylineXfig)(char *str, integer *n, integer *vx, integer *vy, integer *closeflag, integer *v6, integer *v7, double *dx1, double *dx2, double *dx3, double *dx4)
01928 { 
01929   integer i=1,fvect=0;
01930   integer *vxtmp = NULL;
01931   integer *vytmp = NULL;
01932   int j;
01933 
01934   if ( ScilabGCXfig_is_initialized == FALSE ) {
01935     sciprint("xinit must be called before any action \r\n");
01936     return;
01937   }
01938 
01939   if((vxtmp=MALLOC(((*n)+1)*sizeof(integer)))==0){
01940     sciprint("Can not allocate vxtmp while exporting to Fig\n");
01941     return;
01942   }
01943   
01944   if((vytmp=MALLOC(((*n)+1)*sizeof(integer)))==0){
01945     sciprint("Can not allocate vxtmp while exporting to Fig\n");
01946     return;
01947   }
01948 
01949   
01950   for( j = 0 ; j < (*n ) ; j++ )
01951   {
01952     vxtmp[j] = vx[j];
01953     vytmp[j] = vy[j];
01954   }
01955   
01956   vxtmp[(*n)] = vx[0];
01957   vytmp[(*n)] = vy[0];
01958 
01959   if (*closeflag == 1 ){
01960     int nb = (*n)+1;
01961     FPRINTF((file,"#/closeflag true def\n"));
01962     if (ScilabGCXfig.ClipRegionSet ==1 )
01963       {
01964         C2F(analyze_pointsXfig)(nb, vxtmp, vytmp, *closeflag);
01965       }
01966     else     
01967     C2F(fillpolylinesXfig)(str,vxtmp,vytmp,&fvect,&i,&nb,PI0,PD0,PD0,PD0,PD0);
01968   }
01969   else {
01970     FPRINTF((file,"#/closeflag false def\n"));
01971     if (ScilabGCXfig.ClipRegionSet ==1 )
01972       {
01973         C2F(analyze_pointsXfig)(*n, vx, vy, *closeflag);
01974       }
01975     else 
01976     C2F(fillpolylinesXfig)(str,vx,vy,&fvect,&i,n,PI0,PD0,PD0,PD0,PD0);
01977   }
01978 
01979   FREE(vxtmp); vxtmp = NULL;
01980   FREE(vytmp); vytmp = NULL;
01981 
01982   /*   if (*closeflag == 1 ) */
01983   /*     FPRINTF((file,"#/closeflag true def\n")); */
01984   /*   else  */
01985   /*     FPRINTF((file,"#/closeflag false def\n")); */
01986   /*   if (ScilabGCXfig.ClipRegionSet ==1 ) */
01987   /*     { */
01988   /*       C2F(analyze_pointsXfig)(*n, vx, vy, *closeflag); */
01989   /*     } */
01990   /*   else  */
01991   /*     C2F(fillpolylinesXfig)(str,vx,vy,&fvect,&i,n,PI0,PD0,PD0,PD0,PD0); */
01992 }
01993 
01994 
01998 /* F.Leray */
01999 /* closeflag is emulated adding starting points at the end of *vx and *vy */
02000 
02001 void C2F(drawpolylineXfig)(char *str, integer *n, integer *vx, integer *vy, integer *closeflag, integer *v6, integer *v7, double *dx1, double *dx2, double *dx3, double *dx4)
02002 { 
02003   integer i=1,fvect=0;
02004   integer *vxtmp = NULL;
02005   integer *vytmp = NULL;
02006   int j;
02007 
02008   if ( ScilabGCXfig_is_initialized == FALSE ) {
02009     sciprint("xinit must be called before any action \r\n");
02010     return;
02011   }
02012 
02013   if((vxtmp=MALLOC(((*n)+1)*sizeof(integer)))==0){
02014     sciprint("Can not allocate vxtmp while exporting to Fig\n");
02015     return;
02016   }
02017   
02018   if((vytmp=MALLOC(((*n)+1)*sizeof(integer)))==0){
02019     sciprint("Can not allocate vxtmp while exporting to Fig\n");
02020     return;
02021   }
02022 
02023   
02024   for( j = 0 ; j < (*n ) ; j++ )
02025   {
02026     vxtmp[j] = vx[j];
02027     vytmp[j] = vy[j];
02028   }
02029   
02030   vxtmp[(*n)] = vx[0];
02031   vytmp[(*n)] = vy[0];
02032 
02033   if (*closeflag == 1 ){
02034     int nb = (*n)+1;
02035     FPRINTF((file,"#/closeflag true def\n"));
02036     C2F(fillpolylinesXfig)(str,vxtmp,vytmp,&fvect,&i,&nb,PI0,PD0,PD0,PD0,PD0);
02037   }
02038   else {
02039     FPRINTF((file,"#/closeflag false def\n"));
02040     C2F(fillpolylinesXfig)(str,vx,vy,&fvect,&i,n,PI0,PD0,PD0,PD0,PD0);
02041   }
02042 
02043   FREE(vxtmp); vxtmp = NULL;
02044   FREE(vytmp); vytmp = NULL;
02045 
02046   /*   if (*closeflag == 1 ) */
02047   /*     FPRINTF((file,"#/closeflag true def\n")); */
02048   /*   else  */
02049   /*     FPRINTF((file,"#/closeflag false def\n")); */
02050   /*   if (ScilabGCXfig.ClipRegionSet ==1 ) */
02051   /*     { */
02052   /*       C2F(analyze_pointsXfig)(*n, vx, vy, *closeflag); */
02053   /*     } */
02054   /*   else  */
02055   /*     C2F(fillpolylinesXfig)(str,vx,vy,&fvect,&i,n,PI0,PD0,PD0,PD0,PD0); */
02056 }
02057 
02060 void C2F(fillpolylineXfig)(char *str, integer *n, integer *vx, integer *vy, integer *closeareaflag, integer *v6, integer *v7, double *dx1, double *dx2, double *dx3, double *dx4)
02061 {
02062   integer i = 1;
02063   integer cpat,verb=0,num;
02064 
02065   if ( ScilabGCXfig_is_initialized == FALSE ) {
02066     sciprint("xinit must be called before any action \r\n");
02067     return;
02068   }
02069 
02070   C2F(getpatternXfig)(&verb,&cpat,&num,vdouble);
02072   cpat = -cpat;
02073 /*   C2F(analyze_pointsXfigForFilling)(*n, vx, vy, 1, cpat); */
02074   C2F(fillpolylinesXfig)(str,vx,vy,&cpat,&i,n,PI0,PD0,PD0,PD0,PD0);
02075 }
02076  
02077 /*-----------------------------------------------------
02078 \encadre{Routine for initialisation}
02079 ------------------------------------------------------*/
02080 
02081 
02082 void C2F(initgraphicXfig)(char *string, integer *v2, integer *v3, integer *v4, integer *v5, integer *v6, integer *v7, double *dx1, double *dx2, double *dx3, double *dx4)
02083 { 
02084   char string1[50];
02085   static integer EntryCounter = 0;
02086   integer fnum;
02087   *v3 = 0;
02088   if (EntryCounter >= 1) C2F(xendgraphicXfig)();
02089   strcpy(string1,string);
02090   file=fopen(string1,"w");
02091   if (file == 0) 
02092     {
02093       /*sciprint("Can't open file %s, I'll use stdout\r\n",string1);*/
02094       file = stdout;
02095       *v3 = 1;
02096       return;
02097     }
02098   if (EntryCounter == 0)
02099     { 
02100       fnum=0;      C2F(loadfamilyXfig)("Courier",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02101       fnum=1;      C2F(loadfamilyXfig)("Symbol",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02102       fnum=2;      C2F(loadfamilyXfig)("Times-Roman",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
02103       fnum=3;      C2F(loadfamilyXfig)("Times-Italic",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02104       fnum=4;      C2F(loadfamilyXfig)("Times-Bold",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
02105       fnum=5;      C2F(loadfamilyXfig)("Times-BoldItalic",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02106       fnum=6;      C2F(loadfamilyXfig)("Helvetica",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02107       fnum=7;      C2F(loadfamilyXfig)("Helvetica-Oblique",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02108       fnum=8;      C2F(loadfamilyXfig)("Helvetica-Bold",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02109       fnum=9;      C2F(loadfamilyXfig)("Helvetica-BoldOblique",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02110     }
02111   C2F(FileInitXfig)();
02112   ScilabGCXfig.CurWindow =EntryCounter;
02113   EntryCounter =EntryCounter +1;
02114 }
02115 
02116 static void C2F(FileInitXfig)(void)
02117 {
02118   int m;
02119   integer x[2],verbose,narg;
02120   verbose = 0; 
02121   C2F(getwindowdimXfig)(&verbose,x,&narg,vdouble);
02122   FPRINTF((file,"#FIG 3.1\nPortrait\nCenter\nInches\n1200 2\n"));
02123   ScilabGCXfig_is_initialized = TRUE; /* add the flag ScilabGCXfig_is_initialized to test if xinit has been called */
02124   C2F(InitScilabGCXfig)(PI0,PI0,PI0,PI0);
02125 
02127   m = DEFAULTNUMCOLORS;
02128   ScilabGCXfig.Numcolors = m;
02129   ScilabGCXfig.IDLastPattern = m - 1;
02130   ScilabGCXfig.NumForeground = m;
02131   ScilabGCXfig.NumBackground = m + 1;
02132   FPRINTF((file,"0 %d #%02x%02x%02x \n",32+m,0,0,0));
02133   FPRINTF((file,"0 %d #%02x%02x%02x \n",32+m+1,255,255,255));
02134   
02135 /*     } */
02136 
02137   FPRINTF((file,"2 2 0 0 -1 -1 0 0 -1 0.000 0 0 0 0 0 5\n"));
02138   FPRINTF((file," %d %d %d %d %d %d %d %d %d %d \n",
02139            0,0,(int)x[0],0,(int)x[0],(int)x[1],0,(int)x[1],0,0));
02140 }
02141 
02142 /*--------------------------------------------------------
02143 \encadre{Initialisation of the graphic context. Used also 
02144 to come back to the default graphic state}
02145 ---------------------------------------------------------*/
02146 
02147 void C2F(InitScilabGCXfig)(integer *v1, integer *v2, integer *v3, integer *v4)
02148 { integer i,j,col;
02149   ScilabGCXfig.IDLastPattern = GREYNUMBER - 1; 
02150   ScilabGCXfig.CurLineWidth=1 ;
02151   i=1;
02152   C2F(setthicknessXfig)(&i,PI0,PI0,PI0);
02153   C2F(setalufunctionXfig)("GXcopy");
02155   i=j= -1;
02156   C2F(unsetclipXfig)(PI0,PI0,PI0,PI0);
02157   C2F(setdashXfig)((i=0,&i),PI0,PI0,PI0);
02158   C2F(xsetfontXfig)((i=2,&i),(j=1,&j),PI0,PI0);
02159   C2F(setcursymbolXfig)((i=0,&i),(j=0,&j),PI0,PI0);
02161   ScilabGCXfig.CurVectorStyle = CoordModeOrigin ;
02162   /* initialisation des pattern dash par defaut en n&b */
02163   ScilabGCXfig.CurColorStatus =0;
02164   C2F(setpatternXfig)((i=1,&i),PI0,PI0,PI0);
02165   C2F(setdashXfig)((i=1,&i),PI0,PI0,PI0);
02166   C2F(sethidden3dXfig)((i=1,&i),PI0,PI0,PI0);
02167   /* initialisation de la couleur par defaut */ 
02168   ScilabGCXfig.Numcolors = DEFAULTNUMCOLORS;
02169   ScilabGCXfig.CurColorStatus = 1 ;
02170   C2F(setpatternXfig)((i=1,&i),PI0,PI0,PI0);
02171   C2F(setforegroundXfig)((i=ScilabGCXfig.NumForeground+1,&i),PI0,PI0,PI0);
02172   C2F(setbackgroundXfig)((i=ScilabGCXfig.NumForeground+2,&i),PI0,PI0,PI0);
02173   C2F(sethidden3dXfig)((i=4,&i),PI0,PI0,PI0);
02174   /* Choix du mode par defaut (decide dans initgraphic_ */
02175   getcolordef(&col);
02179   ScilabGCXfig.mafigure = (sciPointObj *)NULL;
02180   ScilabGCXfig.CurColorStatus = (col == 1) ? 0: 1;
02181   C2F(usecolorXfig)(&col,PI0,PI0,PI0);
02182   if (col == 1) ScilabGCXfig.IDLastPattern = ScilabGCXfig.Numcolors - 1;
02183   strcpy(ScilabGCXfig.CurNumberDispFormat,"%-5.2g");
02184 }
02185 
02186 
02187 /*-------------------------------------------------------
02188 \encadre{Check if a specified family of font exist in 
02189 Postscript }
02190 -------------------------------------------------------*/
02191 
02192 void C2F(loadfamilyXfig)(char *name, integer *j, integer *v3, integer *v4, integer *v5, integer *v6, integer *v7, double *dx1, double *dx2, double *dx3, double *dx4)
02193 { 
02194   integer i ;
02195   for ( i = 0; i < FONTMAXSIZE ; i++)
02196     {
02197       FontsListXfig_[*j][i] = C2F(FigQueryFont)(name);
02198     }
02199   if  (FontsListXfig_[*j][0] == 0 )
02200           sciprint("\n unknown font family : %s\r\n",name);
02201   else 
02202     {FontInfoTabXfig_[*j].ok = 1;
02203      strcpy(FontInfoTabXfig_[*j].fname,name) ;}
02204 }
02205 
02206 void C2F(queryfamilyXfig)(char *name, integer *j, integer *v3, integer *v4, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
02207 { 
02208   integer i ;
02209   name[0]='\0';
02210   for (i=0;i<FONTNUMBER;i++) {
02211     strcat(name,FontInfoTabXfig_[i].fname);
02212     v3[i]=strlen(FontInfoTabXfig_[i].fname);
02213   }
02214   *j=FONTNUMBER;
02215 }
02216 /*--------------------------------------------
02217 \encadre{always answer ok. Must be Finished}
02218 ---------------------------------------------*/
02219 
02220 static int C2F(FigQueryFont)(char *name)
02221 { return(1);}
02222 
02223 
02224 /*------------------------------------------------------
02225   \encadre{Draw an axis whith a slope of alpha degree (clockwise)
02226   . Along the axis marks are set in the direction ( alpha + pi/2), in the 
02227   following way :
02228   \begin{itemize}
02229   \item   $n=<n1,n2>$,
02230   \begin{verbatim}
02231   |            |           |
02232   |----|---|---|---|---|---|
02233   <-----n1---->                 
02234   <-------------n2-------->
02235   \end{verbatim}
02236   $n1$and $n2$ are integer numbers for interval numbers.
02237   \item $size=<dl,r,coeff>$. $dl$ distance in points between 
02238   two marks, $r$ size in points of small mark, $r*coeff$ 
02239   size in points of big marks. (they are doubleing points numbers)
02240   \item $init$. Initial pointeger $<x,y>$. 
02241   \end{itemize}
02242   }
02243   -------------------------------------------------------------*/
02244 
02245 void C2F(drawaxisXfig)(char *str, integer *alpha, integer *nsteps, integer *v2, integer *initpoint, integer *v6, integer *v7, double *size, double *dx2, double *dx3, double *dx4)
02246 { integer i;
02247   int l_style,style_val,pen_color;
02248   double xi,yi,xf,yf;
02249   double cosal,sinal;
02250   integer verbose=0,Dnarg,Dvalue1[10];
02251 
02252   if ( ScilabGCXfig_is_initialized == FALSE ) {
02253     sciprint("xinit must be called before any action \r\n");
02254     return;
02255   }
02256 
02257   C2F(getdashXfig)(&verbose,Dvalue1,&Dnarg,vdouble);
02258   set_dash_or_color(Dvalue1[0],&l_style,&style_val,&pen_color);
02259   FPRINTF((file,"# Begin Axis \n"));
02260   if ( *alpha == 90 )
02261     {cosal = 0.0 ; sinal =1.0 ;}
02262   else 
02263    {
02264      if ( *alpha == -90 )
02265        {cosal = 0.0 ; sinal = -1.0 ;}
02266      else 
02267        {
02268          cosal= cos( M_PI * (*alpha)/180.0);
02269          sinal= sin( M_PI * (*alpha)/180.0);
02270        }
02271    }
02272   for (i=0; i <= nsteps[0]*nsteps[1]; i++)
02273     { xi = initpoint[0]+i*size[0]*cosal;
02274       yi = initpoint[1]+i*size[0]*sinal;
02275       xf = xi - ( size[1]*sinal);
02276       yf = yi + ( size[1]*cosal);
02277       FPRINTF((file,"2 1 0 %d %d %d 0 0 -1 0.000 0 0 0 0 0 2\n",
02278               ScilabGCXfig.CurLineWidth*prec_fact/16,
02279               pen_color,
02280               pen_color
02281               ));
02282       FPRINTF((file," %d %d %d %d \n",(int)xi, (int)yi,  (int)  xf, (int)yf));
02283     }
02284   for (i=0; i <= nsteps[1]; i++)
02285     { xi = initpoint[0]+i*nsteps[0]*size[0]*cosal;
02286       yi = initpoint[1]+i*nsteps[0]*size[0]*sinal;
02287       xf = xi - ( size[1]*size[2]*sinal);
02288       yf = yi + ( size[1]*size[2]*cosal);
02289       FPRINTF((file,"2 1 0 %d %d %d 0 0 -1 0.000 0 0 0 0 0 2\n",
02290               ScilabGCXfig.CurLineWidth*prec_fact/16,
02291               pen_color,
02292               pen_color
02293               ));
02294       FPRINTF((file," %d %d %d %d \n", (int)xi, (int) yi, (int)xf, (int)yf));
02295     }
02296   xi = initpoint[0]; yi= initpoint[1];
02297   xf = initpoint[0]+ nsteps[0]*nsteps[1]*size[0]*cosal;
02298   yf = initpoint[1]+ nsteps[0]*nsteps[1]*size[0]*sinal;
02299   FPRINTF((file,"2 1 0 %d %d %d 0 0 -1 0.000 0 0 0 0 0 2\n",
02300           ScilabGCXfig.CurLineWidth*prec_fact/16,
02301           pen_color,
02302           pen_color));
02303   FPRINTF((file," %d %d %d %d \n",  (int)xi,  (int)yi, (int) xf, (int)yf));
02304   FPRINTF((file,"# End Of Axis \n"));
02305 }
02306 
02307 /*------------------------------------------------------------------------------------------*/
02311 void C2F(getFontMaxSizeXfig)(char *str, integer * sizeMin, integer *sizeMax, integer *v1, integer *v2, integer *v3, integer *v4, double *dx1, double *dx2, double *dx3, double *dx4)
02312 {
02313   *sizeMin = 0 ;
02314   *sizeMax = FONTMAXSIZE ;
02315 }
02316 /*------------------------------------------------------------------------------------------*/
02317 
02318 /*-----------------------------------------------------
02319 \encadre{Display numbers z[i] at location (x[i],y[i])
02320   with a slope alpha[i] (see displaystring_), if flag==1
02321   add a box around the string.
02322 -----------------------------------------------------*/
02323 void C2F(displaynumbersXfig)(char *str, integer *x, integer *y, integer *v1, integer *v2, integer *n, integer *flag, double *z, double *alpha, double *dx3, double *dx4)
02324 { integer i ;
02325   char buf[20];
02326 
02327   if ( ScilabGCXfig_is_initialized == FALSE ) {
02328     sciprint("xinit must be called before any action \r\n");
02329     return;
02330   }
02331 
02332   for (i=0 ; i< *n ; i++)
02333     { 
02334       sprintf(buf,ScilabGCXfig.CurNumberDispFormat,z[i]);
02335       C2F(displaystringXfig)(buf,&(x[i]),&(y[i]),PI0,flag,PI0,PI0,&(alpha[i]),PD0,PD0,PD0);
02336     }
02337 }
02338 
02339 /*-------------------------------------------------------
02340 \encadre{General routine for generating Postscript Code 
02341 to deal with Vectors. The difficulty is that the size 
02342 of vectors is limited by Postscript, so the routine 
02343 must check size and cut into pieces big objects}
02344 \begin{verbatim}
02345   clear (string) sizeobj [fvect[0],...,fvect[nobj]]
02346   (si flag=1)  [ vx[0] vy[0] vx[1] vy[1] ...... vx[sizev] vy[sizev]]
02347   (si flag=0)  [ vx[0] vx[1] ..... vx[sizev] ] dogrey 
02348 \end{verbatim}
02349 ----------------------------------------------------------*/
02350 
02351 
02352 /*****************************************************************************
02353  * give the correct pattern for xfig 0=white-> 20=black 
02354  * from our pattern coding 0=black    ScilabGCXfig.IDLastPattern=white 
02355  *  we use xfig as follows : 
02356  *  when use_color == 1 we use the 32 standard colors of xfig with 20 ( full saturation )
02357  *  as fill area 
02358  *  when use_color == 0 we use the white color + areafill from 0 to 20 to generate 
02359  *  shades of gray 
02360  * XXXXXX : xset("colormap") must be implemented 
02361  *******************************************************************************/
02362 
02363 #define AREAF(x) Max(0,Min(20,(int) (20.0*((double) x) /((double) GREYNUMBER -1 ))))
02364 
02365 void set_pattern_or_color(int pat, int *areafill, int *color)
02366 {
02367   if ( ScilabGCXfig_is_initialized == FALSE ) {
02368     sciprint("xinit must be called before any action \r\n");
02369     return;
02370   }
02371 
02372   if (  ScilabGCXfig.CurColorStatus == 1) 
02373     {
02374       int m;
02375       *color = pat-1 ; 
02376       if (  CheckColormap(&m) == 1) 
02377         {
02380           *color += 32;
02381         }
02382       else 
02383         {
02384           /* special case for B&white in the default colormap */
02385           if ( *color == 32 ) 
02386             {
02387               *color = DEFAULTBLACK;
02388             }
02389           else if ( *color == 33 ) 
02390             {
02391               *color = DEFAULTWHITE;
02392             }
02393         }
02394       *areafill = 20 ; 
02395     }
02396   else 
02397     {
02398       *color = WHITE ; 
02399       *areafill = AREAF(pat-1); 
02400     }
02401 }
02402 
02403 
02404 
02405 static void set_color(int c, int *color)
02406 {
02407   int m;
02408 
02409   if ( ScilabGCXfig_is_initialized == FALSE ) {
02410     sciprint("xinit must be called before any action \r\n");
02411     return;
02412   }
02413 
02414   if (  ScilabGCXfig.CurColorStatus == 0) {
02415     *color=0;
02416     return;
02417   }
02418   *color = c-1 ; 
02419   if (  CheckColormap(&m) == 1) 
02420     {
02423       *color += 32;
02424     }
02425   else 
02426     {
02427       /* special case for B&white in the default colormap */
02428       if ( *color == 32 ) 
02429         {
02430           *color = DEFAULTBLACK;
02431         }
02432       else if ( *color == 33 ) 
02433         {
02434           *color = DEFAULTWHITE;
02435         }
02436     }
02437 }
02438 
02439 static void set_dash(int dash, int *l_style, int *style_val)
02440 {
02441   int i;
02442   i = Max(Min(MAXDASH -1,dash-1),0);
02443   *l_style = DashTab[i];
02444   *style_val = DashTabStyle[i];
02445 }
02446 
02447 static void set_dash_or_color(int dash, int *l_style, int *style_val, int *color)
02448 {
02449   int j;  
02450 
02451   if ( ScilabGCXfig_is_initialized == FALSE ) {
02452     sciprint("xinit must be called before any action \r\n");
02453     return;
02454   }
02455 
02456   if (  ScilabGCXfig.CurColorStatus == 1) 
02457     {
02458       j= ScilabGCXfig.CurDashStyle + 1;
02459       set_dash(j,l_style,style_val);
02460       set_color(dash,color);
02461       *l_style = 0 ;
02462       *style_val=0;
02463     }
02464   else 
02465     {
02466       set_dash(dash,l_style,style_val);
02467       *color = BLACK;
02468     }
02469 }
02470 
02471 
02472 #define PERLINE 15
02473 
02474 #define FORMATNUM "%d "
02475 
02476 void C2F(WriteGenericXfig)(char *string, integer nobj, integer sizeobj, integer *vx, integer *vy, integer sizev, integer flag, integer *fvect)
02477 { 
02478   integer i;
02479   integer verb=0,cpat,num;
02480   integer verbose=0,Dnarg,Dvalue[10],Dvalue1[10];
02481   integer lg,type=1 ;
02482   integer areafill,fill_color,pen_color,l_style,style_val;
02483 
02484   if ( ScilabGCXfig_is_initialized == FALSE ) {
02485     sciprint("xinit must be called before any action \r\n");
02486     return;
02487   }
02488 
02489   C2F(getdashXfig)(&verb,Dvalue,&Dnarg,vdouble);
02490   C2F(getpatternXfig)(&verb,&cpat,&num,vdouble);
02491   if ( nobj==0|| sizeobj==0) return;
02492   
02493   if ( strcmp(string,"drawpoly") == 0 )
02494   {
02495     for ( i = 0 ; i < nobj ; i++ )
02496     {
02497       lg = sizeobj / 2 ;
02498 
02499       if ( fvect[i] < 0 )
02500       {
02503         set_pattern_or_color( - fvect[i], &areafill, &fill_color ) ;
02504         l_style = 0;
02505         style_val = 0;
02506         pen_color = fill_color;
02507         type = 3;
02508       }
02509       else if ( fvect[i] == 0 )
02510       {
02512         set_color(cpat,&pen_color);
02513         set_dash(Dvalue[0],&l_style,&style_val);
02514         areafill=-1;
02515         fill_color = WHITE;
02516       }
02517       else 
02519       { 
02520         set_pattern_or_color(fvect[i],&areafill,&fill_color);
02521         set_color(cpat,&pen_color);
02522         set_dash(Dvalue[0],&l_style,&style_val);
02523         /*set_dash_or_color(Dvalue[0],&l_style,&style_val,&pen_color);*/
02524         type=3;
02525       }
02526       
02527       FPRINTF((file,"# Object : %d %s -<pat:%d,areafill=%d,white=%d>- \n", (int)i,string,
02528                (int)fvect[i],
02529                (int)areafill,
02530                ScilabGCXfig.IDLastPattern));
02531       FPRINTF((file,"2 %d %d %d %d %d 0 0 %d %d.00 0 0 -1 0 0 %d\n",
02532                (int)type,l_style, ScilabGCXfig.CurLineWidth*prec_fact/16,
02533                pen_color,fill_color,areafill,style_val, (int)lg
02534                 ));
02535 
02536       /* debug info.*/
02537       /*   printf("# Object : %d %s -<pat:%d,areafill=%d,white=%d>- \n", (int)i,string, */
02538 /*               (int)fvect[i], */
02539 /*               (int)areafill, */
02540 /*               ScilabGCXfig.IDLastPattern); */
02541 /*        printf("2 %d %d %d %d %d 0 0 %d %d.00 0 0 -1 0 0 %d\n", */
02542 /*               (int)type,l_style, ScilabGCXfig.CurLineWidth*prec_fact/16, */
02543 /*               pen_color,fill_color,areafill,style_val, (int)lg); */
02544 /*        fflush(NULL); */
02545       C2F(Write2VectXfig)(&vx[i*lg],&vy[i*lg],lg,flag);
02546     }
02547   }
02548   else 
02549   if ( strcmp(string,"drawbox")==0)
02550     {
02551       for ( i =0 ; i < nobj ; i++)
02552         {
02553           integer deb;
02554           if (fvect[i] < 0  )
02555             {
02557               set_dash(Dvalue[0],&l_style,&style_val);
02558               set_color( -fvect[i],&pen_color);
02559               /*set_dash_or_color( -fvect[i],&l_style,&style_val,&pen_color);*/
02560               areafill = -1;
02561               fill_color = WHITE;
02562             }
02563           else    if (fvect[i] == 0  )
02564             {
02566               set_dash(Dvalue[0],&l_style,&style_val);
02567               set_color(cpat,&pen_color);
02568               /*set_dash_or_color(Dvalue[0],&l_style,&style_val,&pen_color);*/
02569               areafill = -1;
02570               fill_color = WHITE;
02571             }
02572           else 
02573             {
02575               set_pattern_or_color(fvect[i],&areafill,&fill_color);
02576               pen_color = fill_color;
02577               l_style = 0;
02578               style_val = 0;
02579               type = 3;
02580             }
02581           FPRINTF((file,"# Object : %d %s -<%d>- \n", (int)i,string, (int)fvect[i]));
02582           FPRINTF((file,"2 2 %d %d %d %d 0 0 %d %d.000 0 0 0 0 0 5\n",
02583                   l_style, ScilabGCXfig.CurLineWidth*prec_fact/16,
02584                   pen_color,fill_color,areafill,style_val));
02585           deb=i*sizeobj;
02586           FPRINTF((file," %d %d %d %d %d %d %d %d %d %d \n",
02587                   (int)vx[deb]                , (int)vx[1+deb],
02588                   (int)vx[deb]+ (int)vx[2+deb], (int)vx[1+deb],
02589                   (int)vx[deb]+ (int)vx[2+deb], (int)vx[1+deb]+ (int)vx[3+deb],
02590                   (int)vx[deb]                , (int)vx[1+deb]+ (int)vx[3+deb],
02591                   (int)vx[deb]                , (int)vx[1+deb]));
02592         }
02593     }
02594   else if ( strcmp(string,"drawsegs")==0)      
02595     {
02597     }
02598   else if ( strcmp(string,"drawarrows")==0)      
02599     {
02601     }
02602   else if ( strcmp(string,"drawarc")==0)      
02603     {
02604       for ( i = 0 ; i < nobj ; i++)
02605         {
02606           if (fvect[i] > ScilabGCXfig.IDLastPattern+1 )
02607             {
02609               set_dash_or_color(Dvalue[0],&l_style,&style_val,&pen_color);
02610               areafill = -1;
02611               fill_color = WHITE;
02612             }
02613           else 
02614             {
02616               set_pattern_or_color(fvect[i],&areafill,&fill_color);
02617               pen_color = fill_color;
02618               l_style = 0;
02619               style_val = 0;
02620               type = 3;
02621             }
02622           FPRINTF((file,"# Object : %d %s -<%d>-\n", (int)i,string, (int)fvect[0]));
02623           FPRINTF((file,
02624                   "1 2 %d %d %d %d 0 0 %d %d.000 1 0.00 %d %d %d %d %d %d %d %d \n",
02625                   l_style,
02626                   ScilabGCXfig.CurLineWidth*prec_fact/16,
02627                   pen_color,fill_color,areafill,style_val,
02628                   (int)vx[6*i]+ (int)vx[6*i+2]/2, 
02629                   (int)vx[6*i+1]+ (int)vx[6*i+3]/2,
02630                   (int)vx[6*i+2]/2, (int)vx[6*i+3]/2,
02631                   (int)vx[6*i]+ (int)vx[6*i+2]/2, (int)vx[6*i+1],
02632                   (int)vx[6*i]+ (int)vx[6*i+2]/2, (int)vx[6*i+1]));
02633         }
02634     }
02635   else if ( strcmp(string,"Rdrawarc")==0)      
02636     {
02637       /* store the current values */
02638       for ( i = 0 ; i < nobj ; i++)
02639         {
02640           /*C2F(setdashXfig)(&fvect[i],PI0,PI0,PI0);*/
02641 
02642           set_dash(Dvalue[0],&l_style,&style_val);
02643           set_color(fvect[i],&pen_color);
02644 
02646           /*C2F(getdashXfig)(&verbose,Dvalue1,&Dnarg,vdouble);
02647             set_dash_or_color(Dvalue1[0],&l_style,&style_val,&pen_color);*/
02648           areafill = -1;
02649           fill_color = WHITE;
02650           FPRINTF((file,"# Object : %d %s -<%d>-\n", (int)i,string, (int)fvect[0]));
02651           FPRINTF((file,
02652                   "1 2 %d %d %d %d 0 0 %d %d.000 1 0.00 %d %d %d %d %d %d %d %d \n",
02653                   l_style,
02654                   (int) (ScilabGCXfig.CurLineWidth*prec_fact/16),
02655                   pen_color,fill_color,
02656                   areafill, 
02657                   style_val,
02658                   (int) (vx[6*i]+vx[6*i+2]/2), 
02659                   (int) (vx[6*i+1]+vx[6*i+3]/2),
02660                   (int) (vx[6*i+2]/2), (int) (vx[6*i+3]/2),
02661                   (int) (vx[6*i]+ vx[6*i+2]/2), (int)vx[6*i+1],
02662                   (int) (vx[6*i]+ vx[6*i+2]/2), (int)vx[6*i+1]));
02663         }
02664       /*C2F(setdashXfig)( Dvalue,PI0,PI0,PI0);*/
02665     }
02666   else if ( strcmp(string,"drawpolymark")==0)      
02667     {
02668       integer rect[4],x=0,y=0;
02669       C2F(getpatternXfig)(&verbose,Dvalue1,&Dnarg,vdouble);
02670       set_color(Dvalue1[0],&pen_color);
02671       l_style=0;style_val=0,
02672       C2F(boundingboxXfigM)("x",&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
02673       FPRINTF((file,"# Object : %d %s -<%d>- \n", (int)0,string, (int)fvect[0]));
02674       for ( i =0 ; i < sizev ; i++)
02675         {
02676           flag = 1;
02677           if ( ScilabGCXfig.ClipRegionSet == 1 ) 
02678             {
02679               if ( vx[i] > ScilabGCXfig.CurClipRegion[0] 
02680                    +ScilabGCXfig.CurClipRegion[2]
02681                    || vx[i] <  ScilabGCXfig.CurClipRegion[0] 
02682                    || vy[i] > ScilabGCXfig.CurClipRegion[1] 
02683                    +ScilabGCXfig.CurClipRegion[3]
02684                    || vy[i] < ScilabGCXfig.CurClipRegion[1] )
02685                 flag = 0;
02686             }
02687           
02689           if ( flag == 1) 
02690           FPRINTF((file,"4 1 %d 0 0 %d %d %5.2f %d %5.2f %5.2f %d %d \\%o\\001\n",
02691                   pen_color,
02692                   32, /* Postscript font */
02693                   (int)isizeXfig_[ScilabGCXfig.FontSize], 
02694                   0.0,
02695                   4,  
02696                   (double) rect[3],
02697                   (double) rect[2],
02698                   (int)vx[i],
02699                   (int)vy[i] + rect[3]/2,
02700                   Char2Int( symb_listXfig_[ScilabGCXfig.CurHardSymb])
02701                   ));
02702 
02703         }
02704     }
02705   else
02706     sciprint("Can't translate %s\r\n",string);
02707 }
02708 
02709 void C2F(Write2VectXfig)(integer *vx, integer *vy, integer n, integer flag)
02710 {
02711   
02712   integer i,k;
02713   
02714   i=0;     
02715   while( i < n )
02716     {
02717       k=0;
02718       while ( k < PERLINE && i < n )
02719         {
02720           FPRINTF((file,FORMATNUM,(int) vx[i]));
02721           if (flag == 1) 
02722             {FPRINTF((file,FORMATNUM,(int) vy[i]));
02723               k += 2;i++;}
02724           else 
02725             {k++;i++;}
02726         }
02727       FPRINTF((file,"\n"));
02728     }
02729 }
02730 
02731 
02732 /************************************************************
02733  * Clipping functions for XFig 
02734  ************************************************************/
02735 
02736 static void C2F(analyze_pointsXfig)(integer n, integer *vx, integer *vy, integer onemore)
02737 {
02738   SClipRegion clipping = getClipRegion( &ScilabGCXfig ) ;
02739 
02740   C2F(clipPolyLine)( n, vx, vy, onemore, &clipping ) ;
02741 }
02742 
02743 
02744 /* NG beg */
02745 void C2F(setscilabFigureXfig)(integer *v1,integer *v2,integer *v3,integer *v4,integer *v5,integer *v6,double *figure)
02746 {
02747  figure=(double *)ScilabGCXfig.mafigure;
02748 }
02749 
02750 void C2F(getscilabFigureXfig)(integer *verbose, integer *x,integer *narg, double *figure)
02751 {   
02752   figure=(double *)ScilabGCXfig.mafigure;
02753 }
02754 void C2F(setscilabVersionXfig)(integer *vers, integer *v2, integer *v3, integer *v4)
02755 {
02756   /*ScilabGCXfig.graphicsversion=*vers;*/
02757 }
02758 
02759 void C2F(getscilabVersionXfig)(integer *verbose, integer *vers, integer *narg, double *dummy)
02760 {   
02761   *vers = 0 ;
02762 }
02763 void C2F(getscilabxgcXfig)(integer *verbose, integer *x,integer *narg, double *dummy)
02764 {   
02765  double **XGC;
02766  XGC=(double **)dummy;
02767  *XGC= (double *)&ScilabGCXfig;
02768 }
02769 void C2F(setscilabxgcXfig)(integer *v1, integer *v2, integer *v3, integer *v4)
02770 {}
02771 /* NG end */
02772 
02773 
02774 /* 2 routines used only by a call to xinitfromscreen to perform the colormap selection */
02775 /* directly from the screen */
02776 
02777 void C2F(initgraphicfromscreenXfig)(char *string, integer *v2, integer *v3, integer *v4, integer *v5, integer *v6, integer *v7, double *dx1, double *dx2, double *dx3, double *dx4)
02778 { 
02779   static integer EntryCounter = 0;
02780   integer fnum;
02781   *v3 = 0;
02782   if (EntryCounter >= 1) C2F(xendgraphicXfig)();
02783   file=fopen(string,"w");
02784   if (file == 0) 
02785     {
02786       /*sciprint("Can't open file %s, I'll use stdout\r\n",string1);*/
02787       file = stdout;
02788       *v3 = 1;
02789       return;
02790     }
02791   if (EntryCounter == 0)
02792     { 
02793       fnum=0;      C2F(loadfamilyXfig)("Courier",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02794       fnum=1;      C2F(loadfamilyXfig)("Symbol",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02795       fnum=2;      C2F(loadfamilyXfig)("Times-Roman",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
02796       fnum=3;      C2F(loadfamilyXfig)("Times-Italic",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02797       fnum=4;      C2F(loadfamilyXfig)("Times-Bold",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
02798       fnum=5;      C2F(loadfamilyXfig)("Times-BoldItalic",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02799       fnum=6;      C2F(loadfamilyXfig)("Helvetica",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02800       fnum=7;      C2F(loadfamilyXfig)("Helvetica-Oblique",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02801       fnum=8;      C2F(loadfamilyXfig)("Helvetica-Bold",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02802       fnum=9;      C2F(loadfamilyXfig)("Helvetica-BoldOblique",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02803     }
02804   C2F(FileInitFromScreenXfig)();
02805   ScilabGCXfig.CurWindow =EntryCounter;
02806   EntryCounter =EntryCounter +1;
02807 }
02808 
02809 static void C2F(FileInitFromScreenXfig)(void)
02810 {
02811   int m;
02812   integer x[2],verbose,narg;
02813   verbose = 0; 
02814   C2F(getwindowdimXfig)(&verbose,x,&narg,vdouble);
02815   FPRINTF((file,"#FIG 3.1\nPortrait\nCenter\nInches\n1200 2\n"));
02816   ScilabGCXfig_is_initialized = TRUE; /* add the flag ScilabGCXfig_is_initialized to test if xinit has been called */
02817   C2F(InitScilabGCXfig)(PI0,PI0,PI0,PI0);
02818   if (  CheckColormap(&m) == 1) 
02819     { 
02820       int i;
02821       float r,g,b;
02822       ScilabGCXfig.Numcolors = m;
02823       ScilabGCXfig.NumForeground = m;
02824       ScilabGCXfig.NumBackground = m + 1;
02825 
02826       if (ScilabGCXfig.CurColorStatus == 1) 
02827         {
02828           ScilabGCXfig.IDLastPattern = ScilabGCXfig.Numcolors - 1;
02829         }
02830       for ( i=0; i < m ; i++)
02831         {
02832           unsigned short ur,ug,ub;
02833           get_r(i,&r);
02834           get_g(i,&g);
02835           get_b(i,&b);
02836           ur = (unsigned short) (65535.0*r);
02837           ug = (unsigned short) (65535.0*g);
02838           ub = (unsigned short) (65535.0*b); 
02839           ur = ur >> 8 ;
02840           ug = ug >> 8 ;        
02841           ub = ub >> 8 ; 
02842           FPRINTF((file,"0 %d #%02x%02x%02x\n",32+i,ur,ug,ub));
02843         }
02844       FPRINTF((file,"0 %d #%02x%02x%02x \n",32+m,0,0,0));
02845       FPRINTF((file,"0 %d #%02x%02x%02x \n",32+m+1,255,255,255));
02846     }
02847   else 
02848     {
02850       m = DEFAULTNUMCOLORS;
02851       ScilabGCXfig.Numcolors = m;
02852       ScilabGCXfig.IDLastPattern = m - 1;
02853       ScilabGCXfig.NumForeground = m;
02854       ScilabGCXfig.NumBackground = m + 1;
02855       FPRINTF((file,"0 %d #%02x%02x%02x \n",32+m,0,0,0));
02856       FPRINTF((file,"0 %d #%02x%02x%02x \n",32+m+1,255,255,255));
02857     }
02858 
02859   FPRINTF((file,"2 2 0 0 -1 -1 0 0 -1 0.000 0 0 0 0 0 5\n"));
02860   FPRINTF((file," %d %d %d %d %d %d %d %d %d %d \n",
02861           0,0,(int)x[0],0,(int)x[0],(int)x[1],0,(int)x[1],0,0));
02862 }

Generated on Sun Mar 4 15:03:52 2007 for Scilab [trunk] by  doxygen 1.5.1