~ubuntu-branches/ubuntu/hoary/scilab/hoary

« back to all changes in this revision

Viewing changes to routines/graphics/Plo2d.c

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2005-01-09 22:58:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050109225821-473xr8vhgugxxx5j
Tags: 3.0-12
changed configure.in to build scilab's own malloc.o, closes: #255869

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*------------------------------------------------------------------------
2
2
 *    Graphic library
3
 
 *    Copyright (C) 1998-2000 Enpc/Jean-Philippe Chancelier
4
 
 *    jpc@cereve.enpc.fr 
 
3
 *    Copyright (C) 1998-2001 Enpc/Jean-Philippe Chancelier
 
4
 *    jpc@cermics.enpc.fr 
5
5
 --------------------------------------------------------------------------*/
6
6
 
7
7
#include <string.h> /* in case of dbmalloc use */
17
17
#include "../sparse/spConfig.h"
18
18
#endif
19
19
 
 
20
#include "Entities.h"
 
21
 
20
22
/*--------------------------------------------------------------------
21
23
 *  C2F(plot2d)(x,y,n1,n2,style,strflag,legend,brect,aaint,lstr1,lstr2)
22
24
 *  
114
116
  integer closeflag=0,n=2,vx[2],vy[2],i,j;
115
117
  double pas;
116
118
  integer verbose=0,narg,xz[10];
117
 
  /* Recording command */
118
 
  if (GetDriver()=='R') StoreGrid("xgrid",style);
119
 
  /* changes dash style if necessary */
120
 
  C2F(dr)("xget","color",&verbose,xz,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
121
 
  C2F(dr)("xset","color",style,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
122
 
  /** Get current scale **/
123
 
  pas = ((double) Cscale.WIRect1[2]) / ((double) Cscale.Waaint1[1]);
124
 
  /** x-axis grid (i.e vertical lines ) */
125
 
  for ( i=0 ; i < Cscale.Waaint1[1]; i++)
 
119
  if (version_flag() == 0)
126
120
    {
 
121
      sciPointObj *psubwin;
 
122
      psubwin = sciGetSelectedSubWin (sciGetCurrentFigure ());
 
123
      for (i=0 ; i<3 ; i++) /**DJ.Abdmouche 2003**/
 
124
        pSUBWIN_FEATURE (psubwin)->grid[i] = *style;
 
125
      sciDrawObj(psubwin);
 
126
      return(0);
 
127
    }
 
128
  else
 
129
    {   /* Recording command */
 
130
      if (GetDriver()=='R') StoreGrid("xgrid",style);
 
131
 
 
132
      /* changes dash style if necessary */
 
133
      C2F(dr)("xget","color",&verbose,xz,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
 
134
      C2F(dr)("xset","color",style,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
 
135
      /** Get current scale **/
 
136
      pas = ((double) Cscale.WIRect1[2]) / ((double) Cscale.Waaint1[1]);
 
137
      /** x-axis grid (i.e vertical lines ) */
 
138
      for ( i=0 ; i < Cscale.Waaint1[1]; i++)
 
139
        {
127
140
      vy[0]=Cscale.WIRect1[1];
128
141
      vy[1]=Cscale.WIRect1[1]+Cscale.WIRect1[3];
129
142
      vx[0]=vx[1]= Cscale.WIRect1[0] + inint( ((double) i)*pas);
138
151
              C2F(dr)("xlines","void",&n, vx, vy,&closeflag,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
139
152
            }
140
153
        }
141
 
    }
142
 
  /** y-axis grid (i.e horizontal lines ) **/
143
 
  pas = ((double) Cscale.WIRect1[3]) / ((double) Cscale.Waaint1[3]);
144
 
  for ( i=0 ; i < Cscale.Waaint1[3]; i++)
145
 
    {
146
 
      vx[0]=Cscale.WIRect1[0];
 
154
        }
 
155
      /** y-axis grid (i.e horizontal lines ) **/
 
156
      pas = ((double) Cscale.WIRect1[3]) / ((double) Cscale.Waaint1[3]);
 
157
      for ( i=0 ; i < Cscale.Waaint1[3]; i++)
 
158
        {
 
159
          vx[0]=Cscale.WIRect1[0];
147
160
      vx[1]=Cscale.WIRect1[0]+Cscale.WIRect1[2];
148
161
      vy[0]=vy[1]= Cscale.WIRect1[1] + inint( ((double) i)*pas);
149
162
      if (i!=0)  C2F(dr)("xlines","void",&n, vx, vy,&closeflag,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
154
167
          for (j= jinit; j < 10 ; j++)
155
168
            {
156
169
              vy[0]=vy[1]= Cscale.WIRect1[1] + inint( ((double) i+1)*pas)- inint(log10(((double)j))*pas);
157
 
               C2F(dr)("xlines","void",&n, vx, vy,&closeflag,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
 
170
              C2F(dr)("xlines","void",&n, vx, vy,&closeflag,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
158
171
            }
159
172
        }
 
173
        }
 
174
      C2F(dr)("xset","color",xz,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
160
175
    }
161
 
  C2F(dr)("xset","color",xz,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
162
176
  return(0);
163
177
}
164
178
 
169
183
 * output : FRect,aaint,strflag are modified 
170
184
 *----------------------------------------------------*/
171
185
 
 
186
 
172
187
void update_frame_bounds(cflag, xf, x, y, n1, n2, aaint, strflag, FRect)
173
188
     int cflag;
174
189
     char *xf;
184
199
  int size_x = (cflag == 1) ? (*n1) : (*n1)*(*n2) ;
185
200
  int size_y = (cflag == 1) ? (*n2) : (*n1)*(*n2) ;
186
201
  char c;
 
202
 
 
203
  
 
204
  sciPointObj *subwindowtmp; /* NG */
 
205
 
187
206
  if ((int)strlen(strflag) < 2) return ;
188
207
  /* 
189
208
   * min,max using brect or x,y according to flags 
198
217
      if ( (int)strlen(xf) < 1) c='g' ; else c=xf[0];
199
218
      switch ( c )
200
219
        {
201
 
        case 'e' : xmin= 1.0 ; xmax = (*n2);break;
202
 
        case 'o' : xmax= Maxi(x,(*n2)); xmin= Mini(x,(*n2)); break;
203
 
        case 'g' :
204
 
        default: xmax= Maxi(x, size_x); xmin= Mini(x, size_x); break;
 
220
        case 'e' : xmin= 1.0 ; xmax = (*n2);break; /* F.Leray obsolete ??*/
 
221
        case 'o' : xmax= Maxi(x,(*n2)); xmin= Mini(x,(*n2)); break; /* F.Leray obsolete ??*/
 
222
        case 'g' : /* F.Leray obsolete ??*/
 
223
          /* F.Leray : look for the min/max inside the x/y vector of size size_x/size-y*/
 
224
        default: xmax= Maxi(x, size_x); xmin= Mini(x, size_x); break; /* for x*/
205
225
        }
206
 
      ymin=  Mini(y, size_y); ymax=  Maxi(y,size_y);
 
226
      ymin=  Mini(y, size_y); ymax=  Maxi(y,size_y); /* for y*/
207
227
      /* back to default values for  x=[] and y = [] */
208
228
      if ( ymin == LARGEST_REAL ) { ymin = 0; ymax = 10.0 ;} 
209
229
      if ( xmin == LARGEST_REAL ) { xmin = 0; xmax = 10.0 ;} 
210
230
      break;
211
231
    }
212
232
 
 
233
  
 
234
  /* BLOCK that moved is HERE F.Leray 20.04.04 */
 
235
  /* FRect gives the plotting boundaries xmin,ymin,xmax,ymax */
 
236
  if (version_flag() == 0) 
 
237
    {/*update A.Djalel for new graphics auto scaling*/
 
238
      subwindowtmp = sciGetSelectedSubWin(sciGetCurrentFigure()); /**DJ.Abdmouche 2003**/
 
239
 
 
240
      
 
241
      if ((pSUBWIN_FEATURE (subwindowtmp)->axes.limits[1] !=0 )  || (pSUBWIN_FEATURE (subwindowtmp)->axes.limits[3] !=0 ))
 
242
        {  
 
243
          xmin=(double) Min(pSUBWIN_FEATURE (subwindowtmp)->axes.limits[1],xmin);
 
244
          xmax=(double) Max(pSUBWIN_FEATURE (subwindowtmp)->axes.limits[3],xmax);
 
245
        }
 
246
      pSUBWIN_FEATURE (subwindowtmp)->axes.limits[1]=xmin;
 
247
      pSUBWIN_FEATURE (subwindowtmp)->axes.limits[3]=xmax;
 
248
      
 
249
      if ((pSUBWIN_FEATURE (subwindowtmp)->axes.limits[2] !=0 )  || (pSUBWIN_FEATURE (subwindowtmp)->axes.limits[4] !=0 ))
 
250
        {  
 
251
          ymin=(double) Min(pSUBWIN_FEATURE (subwindowtmp)->axes.limits[2],ymin);
 
252
          ymax=(double) Max(pSUBWIN_FEATURE (subwindowtmp)->axes.limits[4],ymax);
 
253
        }
 
254
      pSUBWIN_FEATURE (subwindowtmp)->axes.limits[2]=ymin;
 
255
      pSUBWIN_FEATURE (subwindowtmp)->axes.limits[4]=ymax;
 
256
 
 
257
    }
 
258
 
 
259
 
213
260
  /*
214
261
   * modify computed min,max if isoview requested 
215
262
   */
217
264
  if ( strflag[1] == '3' || strflag[1] == '4')
218
265
    {
219
266
      /* code added by S. Mottelet 11/7/2000 */
220
 
      double FRect[4],WRect[4],ARect[4];
221
 
      char logscale[4];      
 
267
      double FFRect[4],WRect[4],ARect[4];
 
268
      /*char logscale[4]; */ /*   F.Leray 24.03.04      */
 
269
      char logscale[2]; 
222
270
      /* end of added code by S. Mottelet 11/7/2000 */
223
271
      
224
 
      int verbose=0,wdim[2],narg;
 
272
      int verbose=0,wdim[2],narg; /* verbose set to 1 F.Leray 05.04.04 AND reset to 0 07.04.04*/
225
273
      C2F(dr)("xget","wdim",&verbose,wdim,&narg, PI0, PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
226
274
      hx=xmax-xmin;
227
275
      hy=ymax-ymin;
228
276
 
229
277
      /* code added by S. Mottelet 11/7/2000 */
230
 
      getscale2d(WRect,FRect,logscale,ARect);
 
278
      getscale2d(WRect,FFRect,logscale,ARect);
231
279
 
232
280
      wdim[0]=linint((double)wdim[0] * WRect[2]);
233
281
      wdim[1]=linint((double)wdim[1] * WRect[3]);
234
282
      /* end of added code by S. Mottelet 11/7/2000 */
235
283
 
 
284
    
 
285
 
236
286
      if ( hx/(double)wdim[0]  <hy/(double) wdim[1] ) 
237
287
        {
238
288
          hx1=wdim[0]*hy/wdim[1];
255
305
        {
256
306
          xmax=ceil(log10(xmax));  xmin=floor(log10(xmin));
257
307
        }
258
 
      else 
 
308
      else
259
309
        {
260
310
          Scistring("Warning: Can't use Log on X-axis xmin is negative \n");
261
311
          xmax= 1; xmin= 0;
267
317
  if ((int)strlen(xf) >=3  && xf[2]=='l' && (int)strlen(strflag) >= 2 && strflag[1] != '0')
268
318
    {
269
319
      /* y axis */
270
 
      if ( ymin > 0 ) 
 
320
      if ( ymin > 0 )
271
321
        {
272
322
          ymax= ceil(log10(ymax)); ymin= floor(log10(ymin));
273
323
        }
274
 
      else 
 
324
      else
275
325
        {
276
326
          Scistring(" Can't use Log on y-axis ymin is negative \n");
277
327
          ymax= 1; ymin= 0;
279
329
      aaint[2]=1;aaint[3]=inint(ymax-ymin);
280
330
    }
281
331
  
282
 
  /* FRect gives the plotting boundaries xmin,ymin,xmax,ymax */
 
332
  /* MOVE OF THE BLOCK on axes.limits affectation */
283
333
 
284
334
  FRect[0]=xmin;FRect[1]=ymin;FRect[2]=xmax;FRect[3]=ymax;
285
335
 
299
349
              Scistring("Warning: you cannot use automatic rescale if you switch from log to normal or normal to log \n");
300
350
            }
301
351
          else 
302
 
            {
303
 
              FRect[0] = Min(FRect[0],Cscale.frect[0]);
304
 
              FRect[1] = Min(FRect[1],Cscale.frect[1]);
305
 
              FRect[2] = Max(FRect[2],Cscale.frect[2]);
306
 
              FRect[3] = Max(FRect[3],Cscale.frect[3]);
 
352
            { 
 
353
              if (version_flag() != 0){
 
354
                FRect[0] = Min(FRect[0],Cscale.frect[0]);
 
355
                FRect[1] = Min(FRect[1],Cscale.frect[1]);
 
356
                FRect[2] = Max(FRect[2],Cscale.frect[2]);
 
357
                FRect[3] = Max(FRect[3],Cscale.frect[3]);
 
358
              }
 
359
              else{ /*dj2003*/
 
360
                subwindowtmp = sciGetSelectedSubWin(sciGetCurrentFigure()); /* rajout F.Leray*/
 
361
                FRect[0] = Min(FRect[0],pSUBWIN_FEATURE (subwindowtmp)->FRect[0]);
 
362
                FRect[1] = Min(FRect[1],pSUBWIN_FEATURE (subwindowtmp)->FRect[1]);
 
363
                FRect[2] = Max(FRect[2],pSUBWIN_FEATURE (subwindowtmp)->FRect[2]);
 
364
                FRect[3] = Max(FRect[3],pSUBWIN_FEATURE (subwindowtmp)->FRect[3]);
 
365
              }
307
366
              if ( FRect[0] < Cscale.frect[0] 
308
367
                   || FRect[1] < Cscale.frect[1] 
309
368
                   || FRect[2] > Cscale.frect[2] 
310
369
                   || FRect[3] > Cscale.frect[3] )
311
 
                redraw = 1;
 
370
                redraw = 1; 
 
371
              /* F.Leray 15.04.04 */
 
372
              /* Here the redraw and the computed FRect will be used below */
 
373
              /* in Tape_ReplayNewScale1(" ",&ww,flag,PI0,aaint,PI0,PI0,FRect,PD0,PD0,PD0);*/
 
374
              /* in this case (if (strflag[1] == '7' || strflag[1] == '8' )), */
 
375
              /* we also recomput FRect */
312
376
            }
313
377
        }
314
378
      /* and we force flag back to 5  */
324
388
        case '6' : strflag[1]='5';break;
325
389
        }
326
390
    }
327
 
          
328
 
  if ( (int)strlen(strflag) >=2 && ( strflag[1]=='5' || strflag[1]=='6' ))
 
391
    if ( (int)strlen(strflag) >=2 && ( strflag[1]=='5' || strflag[1]=='6' ))
329
392
    {
330
393
      /* recherche automatique des bornes et graduations */
331
 
      Gr_Rescale(&xf[1],FRect,Xdec,Ydec,&(aaint[0]),&(aaint[2]));
332
 
      Gr_Rescale(&xf[1],FRect,Xdec,Ydec,&(aaint[0]),&(aaint[2]));
 
394
      Gr_Rescale(&xf[1],FRect,Xdec,Ydec,&(aaint[0]),&(aaint[2])); /* F.Leray 15.04.04 Here we change the value of FRect */
 
395
    }
 
396
    else {
 
397
      Xdec[0]=inint(FRect[0]);Xdec[1]=inint(FRect[2]);Xdec[2]=0;
 
398
      Ydec[0]=inint(FRect[1]);Ydec[1]=inint(FRect[3]);Ydec[2]=0;
333
399
    }
334
400
  
335
401
  /* Update the current scale */
 
402
  set_scale("tftttf",NULL,FRect,aaint,xf+1,NULL); 
 
403
/* NG beg */ 
 
404
  if (version_flag() == 0){
 
405
    subwindowtmp = sciGetSelectedSubWin(sciGetCurrentFigure()); 
 
406
    if (!(sciGetZooming(subwindowtmp))){
 
407
     pSUBWIN_FEATURE (subwindowtmp)->FRect[0]   = FRect[0];
 
408
     pSUBWIN_FEATURE (subwindowtmp)->FRect[1]   = FRect[1];
 
409
     pSUBWIN_FEATURE (subwindowtmp)->FRect[2]   = FRect[2];
 
410
     pSUBWIN_FEATURE (subwindowtmp)->FRect[3]   = FRect[3];}
 
411
    else { 
 
412
     pSUBWIN_FEATURE (subwindowtmp)->FRect_kp[0]   = FRect[0];
 
413
     pSUBWIN_FEATURE (subwindowtmp)->FRect_kp[1]   = FRect[1];
 
414
     pSUBWIN_FEATURE (subwindowtmp)->FRect_kp[2]   = FRect[2];
 
415
     pSUBWIN_FEATURE (subwindowtmp)->FRect_kp[3]   = FRect[3];}
 
416
  }
 
417
  /* NG end*/
336
418
 
337
 
  set_scale("tftttf",NULL,FRect,aaint,xf+1,NULL);
338
419
 
339
420
  /* Should be added to set_scale */
340
421
 
341
422
  for (i=0; i < 3 ; i++ ) Cscale.xtics[i] = Xdec[i];
342
423
  for (i=0; i < 3 ; i++ ) Cscale.ytics[i] = Ydec[i];
343
424
  Cscale.xtics[3] = aaint[1];
344
 
  Cscale.ytics[3] = aaint[3];
345
 
 
346
 
  /* Changing back min,max and aaint if using log scaling X axis */
 
425
  Cscale.ytics[3] = aaint[3]; 
 
426
  /* NG beg */ 
 
427
  if (version_flag() == 0){
 
428
    subwindowtmp = sciGetSelectedSubWin(sciGetCurrentFigure()); 
 
429
    for (i=0 ; i<4 ; i++)
 
430
      {  
 
431
        pSUBWIN_FEATURE (subwindowtmp)->axes.xlim[i]=Cscale.xtics[i]; 
 
432
        pSUBWIN_FEATURE (subwindowtmp)->axes.ylim[i]=Cscale.ytics[i];
 
433
      } 
 
434
    }
 
435
  /* NG end */ 
 
436
  /* Changing back min,max and aaint if using log scaling X axis */  /* F.Leray 15.04.04 WHY NOT MAKE set_scale after this change ??? */
347
437
  if ((int)strlen(xf) >= 2 && xf[1]=='l' && (int)strlen(strflag) >= 2 && strflag[1] != '0')
348
438
    {
349
439
      FRect[0]=exp10(xmin);FRect[2]=exp10(xmax);
353
443
    {
354
444
      FRect[1]= exp10(ymin);FRect[3]= exp10(ymax);
355
445
    }
 
446
 
 
447
 
356
448
  /* Redraw other graphics */
357
449
  if ( redraw )
358
450
    {
361
453
      /* Redraw previous graphics with new Scale */
362
454
      integer ww,verbose=0,narg;
363
455
      GetDriver1(driver,PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
364
 
      if (strcmp("Rec",driver) != 0) 
365
 
        {
366
 
          Scistring("Auto rescale only works with the rec driver\n" );
367
 
          return;
368
 
        }
369
 
      C2F(dr1)("xget","window",&verbose,&ww,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
370
 
      C2F(SetDriver)("X11",PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
371
 
      C2F(dr1)("xclear","v",PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
372
 
      Tape_ReplayNewScale1(" ",&ww,flag,PI0,aaint,PI0,PI0,FRect,PD0,PD0,PD0);
 
456
 
 
457
      if (version_flag() != 0) /* F.Leray*/
 
458
          {
 
459
                if (strcmp("Rec",driver) != 0) 
 
460
                {       
 
461
                  Scistring("Auto rescale only works with the rec driver\n" );
 
462
                  return;
 
463
                }
 
464
                C2F(dr1)("xget","window",&verbose,&ww,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
 
465
                C2F(SetDriver)("X11",PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
 
466
                C2F(dr1)("xclear","v",PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
 
467
                Tape_ReplayNewScale1(" ",&ww,flag,PI0,aaint,PI0,PI0,FRect,PD0,PD0,PD0);
 
468
          }
 
469
          else
 
470
          {
 
471
            sciDrawObj(subwindowtmp);
 
472
      } 
 
473
 
373
474
      C2F(SetDriver)(driver,PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
374
475
    }
375
476
}
476
577
}
477
578
 
478
579
 
479
 
 
480
 
 
481
 
 
482
 
 
483
 
 
484
 
 
485
 
 
486
 
 
487
 
 
488
 
 
489