Actions.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 #include <stdio.h>
00008 #include <string.h>
00009 
00010 #include "math_graphics.h"
00011 #include "GetProperty.h"
00012 #include "SetProperty.h"
00013 #include "DrawObjects.h"
00014 #include "Xcall1.h"
00015 #include "WindowList.h"
00016 #include "MALLOC.h"
00017 #include "Xcall1.h"
00018 #include "sciprint.h"
00019 #include "periScreen.h"
00020 
00021 extern int xinitxend_flag;
00022 
00023 /********************************************************
00024  * the functions in this file are called from 
00025  * callback ( see jpc_SGraph.c ) for the XWindow version 
00026  * Nov 1998 : we must be sure that during the evaluation of 
00027  *            scig_xxx an other function scig_yyy won't be 
00028  *            run. This is possible since during the execution of 
00029  *            one scig_xxx function a sciprint can be performed 
00030  *            and it will lead to an event check which can 
00031  *            produce a call to an other scig_yyy function 
00032  *            flag scig_buzy  is used to check for that 
00033  *            
00034  ********************************************************/
00035 extern int sciSwitchWindow  __PARAMS((int *winnum));/* NG */
00036 extern void sciGetIdFigure __PARAMS((int *vect, int *id, int *iflag));/* NG */
00037 extern int C2F(syncexec)(char *str, int *ns, int *ierr, int *seq, long int str_len) ;
00038 #if !defined(_MSC_VER)
00039 extern int WithBackingStore();
00040 #endif
00041 static int scig_buzy = 0;
00042 
00043 int I3dRotation(void) ;
00044 
00045 typedef int (*Scig_handler) __PARAMS((int));
00046 
00047 void reset_scig_handler(void);
00048 int scig_handler_none(int win_num);
00049 
00050 /********************************************************
00051  * A handler which can be dynamically set to custiomize 
00052  * action of scig_xxx functions 
00053  ********************************************************/
00054 
00055 int scig_handler_none(int win_num) {
00056         return win_num;
00057 };
00058 
00059 Scig_handler scig_handler = scig_handler_none;
00060 
00061 
00062 /********************************************************
00063  * Basic Replay : redraw recorded graphics 
00064  ********************************************************/
00065 
00066 void scig_replay(integer win_num)
00067 {
00068   /* Modification Allan CORNET Mai 2004 */
00069   integer verb=0,cur,pix,na,backing;
00070   char name[4];
00071   if ( scig_buzy  == 1 ) return ;
00072   scig_buzy =1;
00073   GetDriver1(name,PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
00074   C2F(dr)("xget","window",&verb,&cur,&na,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
00075   C2F(dr)("xset","window",&win_num,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00076   C2F(dr)("xget","pixmap",&verb,&pix,&na,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
00077 
00078 #if defined(_MSC_VER)
00079   backing = 0;
00080 #else
00081   backing = WithBackingStore();
00082 #endif
00083   if (backing) 
00084     {
00085       C2F(dr)("xset","wshow",PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);    
00086     }
00087   else 
00088     {
00089       if (pix == 0) 
00090         {
00091           if ( (GetDriver()) != 'R') C2F(SetDriver)("Rec",PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
00092           C2F(dr)("xclear","v",PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00093           sciRedrawFigure();
00094           C2F(dr)("xset","wshow",PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00095         }
00096       else
00097         {
00098           C2F(dr)("xset","wshow",PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);    
00099         }
00100     }
00101 
00102   C2F(dr)("xset","window",&cur,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00103   C2F(dr)("xsetdr",name, PI0, PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00104   scig_buzy = 0;
00105 }
00106 
00107 
00108 void scig_erase(integer win_num)
00109 {
00110   integer verb=0,cur,na;
00111   char name[4];
00112   if ( scig_buzy  == 1 ) return ;
00113   scig_buzy =1;
00114   GetDriver1(name,PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
00115   if ( (GetDriver()) !='R') 
00116     C2F(SetDriver)("Rec",PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
00117   C2F(dr)("xget","window",&verb,&cur,&na,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
00118   C2F(dr)("xset","window",&win_num,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00119   sciXbasc() ;
00120   C2F(dr)("xclear","v",PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00121   C2F(dr)("xstart","v",&win_num,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00122   C2F(dr)("xset","window",&cur,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00123   C2F(dr)("xsetdr",name, PI0, PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00124   scig_buzy = 0;
00125 }
00126 
00127 
00128 
00129 int scig_2dzoom(integer win_num)
00130 {
00131   char name[4];
00132   int ret;
00133   integer verb=0,cur,na;
00134 
00135   if ( scig_buzy  == 1 ) return 0; ;
00136   scig_buzy =1;
00137   GetDriver1(name,PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
00138 
00139   C2F(dr)("xget","window",&verb,&cur,&na,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
00140   C2F(dr)("xset","window",&win_num,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00141   ret=zoom();
00142   if (cur != win_num)
00143           C2F(dr)("xset","window",&cur,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00144   C2F(dr)("xsetdr",name, PI0, PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00145 
00146   scig_buzy = 0;
00147   return ret;
00148 }
00149 
00150 void scig_unzoom(integer win_num)
00151 {
00152   integer verb=0,cur,na;
00153   char name[4];
00154   if ( scig_buzy  == 1 ) return ;
00155   scig_buzy =1;
00156   GetDriver1(name,PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
00157   C2F(dr)("xget","window",&verb,&cur,&na,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
00158   C2F(dr)("xset","window",&win_num,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00159   unzoom();
00160   if (cur != win_num)
00161         C2F(dr)("xset","window",&cur,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00162   C2F(dr)("xsetdr",name, PI0, PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00163   scig_buzy = 0;
00164 }
00165 
00166 int scig_3drot(integer win_num)
00167 {
00168   integer verb=0,cur,na,ret;
00169   char name[4];
00170   if ( scig_buzy  == 1 ) return 0;
00171   scig_buzy =1;
00172   GetDriver1(name,PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
00173 
00174   C2F(dr)("xget","window",&verb,&cur,&na,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
00175   C2F(dr)("xset","window",&win_num,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00176   ret=I3dRotation();
00177   if (cur != win_num)
00178         C2F(dr)("xset","window",&cur,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00179   C2F(dr)("xsetdr",name, PI0, PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00180   scig_buzy = 0;
00181   return ret;
00182 }
00183 
00184 void scig_sel(integer win_num)
00185 {
00186   char c ;
00187   int v=1;
00188   if ((c=GetDriver())=='R' || c == 'X' || c == 'W')
00189     {
00190       C2F(dr)("xset","window",&win_num,&v,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00191       sciSwitchWindow(&win_num) ;
00192     }
00193 }
00194 
00195 void scig_loadsg(int win_num, char *filename)
00196 {
00197   integer verb = 0 ;
00198   int cur = 0 ;
00199   int narg = 0 ;
00200   int ierr = 0 ;
00201   int seq = 1 ;
00202   char * macroCall = NULL ;
00203   /* the sting is "xload('(1)')" where (1) is filemame */
00204   /* Consequently we have 9 fixed character and two variable strings. */
00205   int macroCallLength = 9 + strlen(filename) ;
00206 
00207   if ( scig_buzy  == 1 ) { return ; }
00208   scig_buzy  = 1 ;
00209 
00210   C2F(dr)("xget","window",&verb,&cur,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00211   C2F(dr)("xset","window",&win_num,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00212   
00213   macroCall = MALLOC( (macroCallLength+1) * sizeof(char) ) ; /* +1 for the \0 terminating character */
00214   sprintf(macroCall,"xload('%s')",filename);
00215 
00216   C2F(syncexec)(macroCall,&macroCallLength,&ierr,&seq, macroCallLength );
00217 
00218   FREE( macroCall ) ;
00219   if(ierr != 0) { sciprint("Wrong plot file : %s\r\n",filename) ; }
00220 
00221   C2F(dr)("xset","window",&cur,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00222   scig_buzy = 0;
00223 }
00224 
00225 void scig_savesg( int win_num, char * filename )
00226 {
00227   integer ierr ;
00228   integer seq = 1 ;
00229   char * macroCall = NULL ;
00230 
00231   /* the sting is "xsave('(1)',(2))" where (1) is filemame and (2) the string */
00232   /* corresponding of win_num. Consequently we have 10 fixed character and two variable strings. */
00233   int macroCallLength = 10 + strlen(filename) + GET_NB_DIGITS(win_num) ;
00234 
00235   macroCall = MALLOC( (macroCallLength+1) * sizeof(char) ) ; /* +1 for the \0 terminating character */
00236 
00237   sprintf( macroCall, "xsave('%s',%d)", filename, win_num ) ; /* call xsave macro */
00238   C2F(syncexec)(macroCall,&macroCallLength,&ierr,&seq, macroCallLength );
00239   FREE( macroCall ) ;
00240 }
00241 
00242 /********************************************************
00243 * Basic Replay : expose graphics i.e 
00244 * if we have a pixmap we can perform a wshow 
00245 * else we perform a sgig_replay 
00246 ********************************************************/
00247 
00248 void scig_expose(integer win_num)
00249 {
00250   integer verb=0,cur,pix,na,backing;
00251   char name[4];
00252   if ( scig_buzy  == 1 ) return ;
00253   scig_buzy =1;
00254   GetDriver1(name,PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
00255   C2F(dr)("xget","window",&verb,&cur,&na,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
00256   C2F(dr)("xset","window",&win_num,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00257   C2F(dr)("xget","pixmap",&verb,&pix,&na,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
00258 
00259 #if defined(_MSC_VER)
00260   backing = 0;
00261 #else
00262   backing = WithBackingStore();
00263 #endif
00264   if (backing) 
00265   {
00266     /* only used whith X11 were pixmap mode can be used for backing store 
00267     * we are here in a case where the pixmap is used for backing store 
00268     */
00269     C2F(dr)("xset","wshow",PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);    
00270   }
00271   else 
00272   {
00273     if (pix == 0) 
00274     {
00275       if ( (GetDriver()) != 'R') 
00276         C2F(SetDriver)("Rec",PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
00277       C2F(dr)("xclear","v",PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
00278       sciRedrawFigure();
00279       C2F(dr)("xset","wshow",PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00280     }
00281     else
00282     {
00283       C2F(dr)("xset","wshow",PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);    
00284     }
00285   }
00286   C2F(dr)("xset","window",&cur,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00287   C2F(dr)("xsetdr",name, PI0, PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00288   scig_buzy = 0;
00289 }
00290 
00291 /********************************************************
00292 * Redraw graphic window win_num  after resizing 
00293 ********************************************************/
00294 
00295 void scig_resize(integer win_num)
00296 {
00297   integer verb=0,cur,na,pix,backing;
00298   char name[4];
00299   if ( scig_buzy  == 1 ) return ;
00300   scig_buzy =1;
00301   GetDriver1(name,PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
00302   if ( (GetDriver()) !='R') 
00303     C2F(SetDriver)("Rec",PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
00304   C2F(dr)("xget","window",&verb,&cur,&na,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
00305   C2F(dr)("xset","window",&win_num,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00306   C2F(dr)("xget","pixmap",&verb,&pix,&na,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
00307   CPixmapResize1();
00308   C2F(dr)("xclear","v",PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);    
00309 #if defined(_MSC_VER)
00310   backing = 0;
00311 #else
00312   backing = WithBackingStore();
00313 #endif
00314   sciRedrawFigure();
00315   if (backing && pix!=1 ) C2F(dr)("xset","wshow",PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00316 
00317   C2F(dr)("xset","window",&cur,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00318   C2F(dr)("xsetdr",name, PI0, PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00319   scig_buzy = 0;
00320 }
00321 
00322 /********************************************************
00323 * graphic Window raise 
00324 ********************************************************/
00325 
00326 void scig_raise(integer win_num)
00327 {
00328 
00329   int cur,n,na,verb=0,iflag=0;
00330 
00331   sciGetIdFigure (PI0,&n,&iflag);
00332   if ( n > 0 )
00333   {
00334     C2F(dr)("xget","window",&verb,&cur,&na,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00335     if (win_num != cur) 
00336     {
00337       C2F(dr)("xset","window",&win_num,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00338       sciSwitchWindow(&win_num);
00339       C2F(dr)("xselect","v",PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00340       C2F(dr)("xset","window",&cur,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00341     }
00342     else
00343     {
00344       C2F(dr)("xselect","v",PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00345     }
00346   }
00347   else
00348   { 
00349     C2F(dr)("xset","window",&win_num,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00350     sciSwitchWindow(&win_num);
00351   }
00352 }

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