00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "xs2file.h"
00011 #include "stack-c.h"
00012 #include "Xcall1.h"
00013 #include "GetProperty.h"
00014 #include "SetProperty.h"
00015 #include "periScreen.h"
00016 #include "graphicSession.h"
00017 #include "DrawObjects.h"
00018 #include "ColorMapManagement.h"
00019 #include "MALLOC.h"
00020 #include "CurrentObjectsManagement.h"
00021
00022
00023 int xs2file( char * fname, char * dr, unsigned long fname_len, unsigned long dr_len )
00024 {
00025 integer m1,n1,l1,m2,n2,l2,m3,n3,l3,flagx = -1,iwin;
00026 CheckRhs(2,3);
00027
00028
00029 GetRhsVar(1,"d",&m1,&n1,&l1) ;
00030 CheckScalar(1,m1,n1) ;
00031 iwin = (integer) *stk(l1) ;
00032
00033 GetRhsVar(2,"c",&m2,&n2,&l2);
00034
00035 if ( Rhs >= 3 )
00036 {
00037 GetRhsVar(3,"d",&m3,&n3,&l3) ;
00038 CheckScalar(3,m3,n3) ;
00039 flagx = (integer) *stk(l3) ;
00040 }
00041
00042 C2F(xg2psofig)(cstk(l2),&m2,&iwin,&flagx,dr,bsiz,dr_len);
00043 LhsVar(1)=0;
00044 return 0;
00045 }
00046
00047 int scig_toPs( integer win_num, integer colored, char * bufname, char * driver )
00048 {
00049 char name[4];
00050 integer ierr;
00051 integer verb=0,cur,na ;
00052 int save_xinitxend_flag = isGraphicSessionOpened();
00053 sciPointObj * curFig = sciGetCurrentFigure ();
00054 integer bg ;
00055 double * curColorMap = NULL ;
00056 double * bwColorMap = NULL ;
00057 int colorMapSize = sciGetNumColors( curFig ) ;
00058
00059 ierr = 0;
00060 GetDriver1(name,PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
00061 C2F(dr)("xget","window",&verb,&cur,&na,PI0,PI0,PI0,PD0,PD0,PD0,PD0,5L,7L);
00062 C2F(dr)("xset","window",&win_num,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,5L,7L);
00063
00064 if( curFig == (sciPointObj *) NULL )
00065 {
00066 Scierror(999,"No current graphic window %d found for exporting to %s\r\n",win_num,driver);
00067 C2F(dr)("xsetdr",name, PI0, PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00068 C2F(dr)("xset","window",&cur,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00069
00070 if(GetDriverId() == 1) { SwitchWindow(&cur); }
00071 return ierr;
00072 }
00073
00074 C2F(dr)("xget","background",&verb,&bg,&na,PI0,PI0,PI0,PD0,PD0,PD0,PD0,5L,11L);
00075
00076 bg = sciGetBackground(curFig);
00077 C2F(dr)("xsetdr",driver,PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00078
00079 C2F(dr)("xinit2",bufname,&win_num,&ierr,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00080
00081 if (ierr != 0)
00082 {
00083 C2F(dr)("xsetdr",name, PI0, PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00084 C2F(dr)("xset","window",&cur,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00085
00086 SwitchWindow(&cur);
00087 return ierr ;
00088 }
00089
00090 sciSetCurrentFigure(curFig);
00091
00092 if ( colored == 0 )
00093 {
00094
00095 curColorMap = MALLOC( 3 * colorMapSize * sizeof(double) ) ;
00096 bwColorMap = MALLOC( 3 * colorMapSize * sizeof(double) ) ;
00097 sciGetColormap( curFig, curColorMap ) ;
00098 convertColorMap2BW( bwColorMap, curColorMap, colorMapSize ) ;
00099 sciSetColormap( curFig, bwColorMap, colorMapSize, 3 ) ;
00100 FREE( bwColorMap ) ;
00101 bwColorMap = NULL ;
00102 }
00103
00104 C2F(dr)("xset","background",&bg,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,5L,7L);
00105 closeGraphicSession() ;
00106 sciDrawObj(curFig);
00107
00108
00109 C2F(dr)("xend","v",PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00110 if ( save_xinitxend_flag )
00111 {
00112 openGraphicSession() ;
00113 }
00114 else
00115 {
00116 closeGraphicSession() ;
00117 }
00118 C2F(dr)("xsetdr",name, PI0, PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00119
00120 if ( colored == 0 )
00121 {
00122 sciSetColormap( curFig, curColorMap, colorMapSize, 3 ) ;
00123 FREE( curColorMap ) ;
00124 curColorMap = NULL ;
00125 }
00126
00127
00128 C2F(dr)("xset","window",&cur,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00129
00130 SwitchWindow(&cur);
00131 return ierr;
00132 }
00133
00134 int C2F(xg2psofig)(char *fname, integer *len, integer *iwin, integer *color, char *driver, long int l1, long int l2)
00135 {
00136 int sc;
00137 if ( *color == -1 )
00138 getcolordef(&sc);
00139 else
00140 sc= *color;
00141
00142 return scig_toPs(*iwin,sc,fname,driver);
00143 }
00144