da284867244880dc63e5daa1152af1b955d1fc17
[scilab.git] / scilab / modules / graphics / src / c / DrawObjects.c
1 /*------------------------------------------------------------------------
2  *    Graphic library 
3  *    Copyright INRIA
4  *    newGraph Library header
5  *    Matthieu PHILIPPE,   INRIA 2001-2002
6  *    Djalel ABDEMOUCHE,   INRIA 2002-2004
7  *    Fabrice Leray,       INRIA 2004-2006
8  *    Jean-Baptiste Silvy, INRIA 2006-xxxxdrawmerge
9  *    Comment:
10  *    This file contains all functions used to Draw the content of a window.
11  *    The main functions is sciDrawObj that draws the objects recursively.
12  ------------------------------------------------------------------------/-*/
13 #include <math.h>
14
15 #include <stdio.h> 
16 #include <string.h>
17 #include <stdlib.h>
18 #include <stdarg.h>
19 #include <time.h>
20
21 #include "Graphics.h"
22 #include "DrawObjects.h"
23 #include "GetProperty.h"
24 #include "bcg.h"
25 #include "SetProperty.h"
26 #include "BuildObjects.h"
27 #include "DestroyObjects.h"
28 #include "ObjectStructure.h"
29 #include "Axes.h"
30 #include "Xcall1.h"
31 #include "Champ.h"
32 #include "StringBox.h"
33 #include "handleDrawing/drawTextEntity.h"
34 #include "handleDrawing/drawFigureEntity.h"
35 #include "handleDrawing/drawSubWinEntity.h"
36 #include "handleDrawing/drawCompoundEntity.h"
37 #include "handleDrawing/drawLegendEntity.h"
38 #include "handleDrawing/drawFecEntity.h"
39 #include "handleDrawing/drawSegsEntity.h"
40 #include "handleDrawing/drawGrayplotEntity.h"
41 #include "handleDrawing/drawPolylineEntity.h"
42 #include "handleDrawing/drawArcEntity.h"
43 #include "handleDrawing/drawRectangleEntity.h"
44 #include "handleDrawing/drawAxesEntity.h"
45 #include "handleDrawing/drawMergeEntity.h"
46 #include "handleDrawing/drawSurfaceEntity.h"
47 #include "periScreen.h" /* to be removed */
48 #include "PloEch.h"
49 #include "axesScale.h"
50
51 #include "math_graphics.h"
52 #include "graphicSession.h"
53 #include "Format.h"
54 #include "axesScale.h"
55 #include "drawMarks.h"
56 #include "BasicAlgos.h"
57
58 #include "MALLOC.h" /* MALLOC */
59
60 #ifdef WITH_TK
61 #include "../../../tclsci/includes/GedManagement.h"
62 #endif
63
64 #if _MSC_VER
65 extern HDC TryToGetDC(HWND hWnd);
66 #endif
67
68 #define         round(a)        (int)(((a)<0.0)?(a)-.5:(a)+.5)
69
70 extern double C2F(dsort)();/*DJ.A merge*/ 
71 extern int scilab_shade(integer *polyx, integer *polyy, integer *fill, integer polysize, integer flag);
72 extern void xstringb_angle (char *string, integer x, integer y, integer w, integer h, double angle);
73 extern void xstringb_bbox (char *string, integer x, integer y, integer w, integer h, double angle, int *bbox);
74 #ifdef _MSC_VER
75 extern void Scistring (char *str);
76 #endif
77
78 void GradFixedlog( double minVal, double maxVal, double * ticks, int nbGrads );
79 int sciGetLogExponent( double minBound, double maxBound, double * expMin, double * expMax );
80
81 unsigned short defcolors[] = {
82   0,   0,   0, /* Black: DEFAULTBLACK */
83   0,   0, 255, /* Blue */
84   0, 255,   0, /* Green */
85   0, 255, 255, /* Cyan */
86   255,   0,   0, /* Red */
87   255,   0, 255, /* Magenta */
88   255,   255,   0, /* Yellow */
89   255, 255, 255, /* White: DEFAULTWHITE */
90   0,   0, 144, /* Blue4 */
91   0,   0, 176, /* Blue3 */
92   0,   0, 208, /* Blue2 */
93   135, 206, 255, /* LtBlue */
94   0, 144,   0, /* Green4 */
95   0, 176,   0, /* Green3 */
96   0, 208,   0, /* Green2 */
97   0, 144, 144, /* Cyan4 */
98   0, 176, 176, /* Cyan3 */
99   0, 208, 208, /* Cyan2 */
100   144,   0,   0, /* Red4 */
101   176,   0,   0, /* Red3 */
102   208,   0,   0, /* Red2 */
103   144,   0, 144, /* Magenta4 */
104   176,   0, 176, /* Magenta3 */
105   208,   0, 208, /* Magenta2 */
106   128,  48,   0, /* Brown4 */
107   160,  64,   0, /* Brown3 */
108   192,  96,   0, /* Brown2 */
109   255, 128, 128, /* Pink4 */
110   255, 160, 160, /* Pink3 */
111   255, 192, 192, /* Pink2 */
112   255, 224, 224, /* Pink */
113   255, 215,   0  /* Gold */
114 };
115
116 int cf_type = 1 ;
117
118 int get_cf_type(void)
119 {
120         return cf_type;
121 }
122
123 void set_cf_type(int val)
124 {
125         cf_type=val;
126 }
127
128
129
130 /**sciGetDC
131  * Returns the HDC of the figure window (not the parent)
132  */
133 #ifdef _MSC_VER
134 HDC        /* BCG Type priWin !! decommente par SS ???? */ 
135 sciGetDC (sciPointObj * pobj)
136 {
137   switch (sciGetEntityType (pobj))
138     {
139     case SCI_FIGURE:
140     case SCI_SUBWIN:
141       return (HDC)TryToGetDC (sciGetScilabXgc (pobj)->CWindow);
142       break;
143     default:
144       return sciGetDC (sciGetParent (pobj));
145       break;
146     }
147   return (HDC ) NULL;        /* Type HDC ! "periWin-bgc"*/
148 }
149 #endif
150
151
152 void sciRedrawFigure()
153 {
154   sciSetReplay (TRUE);
155   sciDrawObj (sciGetCurrentFigure ());
156   sciSetReplay (FALSE);
157    
158 }
159
160 void sciRedrawF(value)
161      int *value;   
162
163   sciPointObj *figure; 
164   integer cur,na,verb=0;
165   figure= (sciPointObj *) sciIsExistingFigure(value); 
166   /* F.Leray 13.04.04 : Test if returned sciPointObj* is NULL (means Figure has been destroyed) */
167
168   if(figure == (sciPointObj *)  NULL)
169     {
170       /* Do nothing */
171     }
172   else
173     {
174       C2F (dr) ("xget", "window",&verb,&cur,&na,PI0,PI0,PI0,PD0,PD0,PD0,PD0,4L,6L);
175       C2F (dr) ("xset", "window",value,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,4L,6L);
176       /* sciSetCurrentObj(figure); */ /*F.Leray 25.03.04*/
177       sciSetReplay (TRUE);
178       sciDrawObj (figure);
179       sciSetReplay (FALSE);
180       C2F (dr) ("xset", "window",&cur,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,4L,6L);
181     }
182 }
183
184 void sciXbasc()
185 {  
186   static sciPointObj *mafigure;
187   static sciPointObj *masousfen;  
188  
189   mafigure= (sciPointObj *) sciGetCurrentFigure(); 
190   DestroyAllGraphicsSons((sciPointObj *)mafigure);
191   
192    
193   if ((masousfen = ConstructSubWin (mafigure, 'o')) != NULL){
194     sciSetCurrentObj(masousfen);
195     sciSetOriginalSubWin (mafigure, masousfen);}
196   sciDrawObj(sciGetCurrentFigure ());      
197 }       
198
199 /* Completely destroy the handle hierearchy */
200 /* when switching from new to old figure_style */
201 /* see intgset.c */
202 void sciXClearFigure()
203 {  
204   static sciPointObj *mafigure;
205   struct BCG * XGC = (struct BCG*) NULL;
206   int v = 1, verb = 0;
207   double dv = 0.;
208
209   mafigure= (sciPointObj *) sciGetCurrentFigure(); 
210
211
212 #ifdef WITH_TK
213             /* close ged to prevent errors when using it */
214             sciDestroyGed( sciGetNum( mafigure ) ) ;
215 #endif
216
217   DestroyAllGraphicsSons((sciPointObj *)mafigure);
218   DestroyFigure (mafigure); 
219   C2F(dr)("xget","gc",&verb,&v,&v,&v,&v,&v,(double *)&XGC,&dv,&dv,&dv,5L,10L);
220   XGC->mafigure = (sciPointObj *) NULL;
221 }       
222
223 void sciXclear()
224 {
225   static sciPointObj *masousfen, *tmpsousfen;
226   sciSons *psonstmp; 
227      
228   tmpsousfen= (sciPointObj *) sciGetSelectedSubWin (sciGetCurrentFigure());
229   psonstmp = sciGetSons (sciGetCurrentFigure());
230   
231   while (psonstmp != (sciSons *) NULL)  
232     {  
233       if(sciGetEntityType (psonstmp->pointobj) == SCI_SUBWIN)
234         {
235           masousfen= (sciPointObj *)psonstmp->pointobj;
236           sciSetSelectedSubWin (masousfen);
237           sciSetdrawmode (FALSE); 
238         }
239       psonstmp = psonstmp->pnext;
240     }
241   sciSetSelectedSubWin (tmpsousfen);
242   sciDrawObj(sciGetCurrentFigure ());      
243 }
244
245 void sciXdraw()
246 {
247   static sciPointObj *masousfen, *tmpsousfen;
248   sciSons *psonstmp; 
249    
250   tmpsousfen= (sciPointObj *) sciGetSelectedSubWin (sciGetCurrentFigure ());
251   psonstmp = sciGetSons (sciGetCurrentFigure ());
252   
253   
254   while (psonstmp != (sciSons *) NULL)  
255     {  
256       if(sciGetEntityType (psonstmp->pointobj) == SCI_SUBWIN)
257         {
258           masousfen= (sciPointObj *)psonstmp->pointobj;
259           sciSetSelectedSubWin (masousfen);
260           sciSetdrawmode (TRUE); 
261         }
262       psonstmp = psonstmp->pnext;
263     }
264   sciSetSelectedSubWin (tmpsousfen); 
265   sciDrawObj(sciGetCurrentFigure ());
266            
267 }
268
269
270 /* update the scale and retrieve the bounding box of the axis */
271 void updateScale3d( sciPointObj * pobj    ,
272                     double        dbox[6] ,
273                     double        xbox[8] ,
274                     double        ybox[8] ,
275                     double        zbox[8]  )
276 {
277   int    flag     ;
278   int    i        ;
279   double xmmin    ;
280   double xmmax    ;
281   double ymmin    ;
282   double ymmax    ;
283   double wmax     ;
284   double hmax     ;
285   integer aaint[] = {2,10,2,10} ;
286   sciSubWindow * ppsubwin =  pSUBWIN_FEATURE (pobj);
287
288   sci_update_frame_bounds_3d( pobj ) ;
289        
290   dbox[0] =  ppsubwin->FRect[0] ; /*xmin*/
291   dbox[1] =  ppsubwin->FRect[2] ; /*xmax*/
292   dbox[2] =  ppsubwin->FRect[1] ; /*ymin*/
293   dbox[3] =  ppsubwin->FRect[3] ; /*ymax*/
294   dbox[4] =  ppsubwin->FRect[4] ; /*zmin*/
295   dbox[5] =  ppsubwin->FRect[5] ; /*zmax*/
296
297   if( ppsubwin->cube_scaling )
298   {
299     dbox[0] =  0.; 
300     dbox[1] =  1.;
301     dbox[2] =  0.;
302     dbox[3] =  1.;
303     dbox[4] =  0.;
304     dbox[5] =  1.;
305   }
306
307
308   /** changement de coordonnees 3d */
309   flag = ( ppsubwin->axes.flag[1] + 1 ) / 2 ; /* F.Leray Adding HERE 19.04.04 */
310
311   Cscale.alpha = ppsubwin->alpha ;
312   Cscale.theta = ppsubwin->theta ;
313       
314   /* update Cscale.m from the new viewing angles */
315   sciUpdateScaleAngles( ppsubwin->theta, ppsubwin->alpha ) ;
316       
317   for ( i = 0 ; i < 6 ; i++ ) 
318   { 
319     if ( flag == 0 )
320     { 
321       dbox[i] = Cscale.bbox1[i];
322     }
323     else
324     { 
325       Cscale.bbox1[i] = dbox[i];
326     }
327   }
328
329   /* get the vertices of the axes box */
330   sciGetAxisBox( dbox, xbox, ybox, zbox ) ;
331       
332   /** Calcul des echelles en fonction de la taille du dessin **/
333   if ( flag == 1 || flag == 3 ) /* ALL the expanded cases : flag[1] = 1 or 2 or 5 or 6 */
334   {
335     xmmin =  Mini(xbox,8L) ;
336     xmmax =  Maxi(xbox,8L) ; /* search for x Min/Max on all the edges (there are 8 edges that compose the box) F.Leray 13.10.04 */
337     ymmax = -Mini(ybox,8L) ; /* same thing on ybox vector ( 1) why - (minus) ? see 2) )*/
338     ymmin = -Maxi(ybox,8L);
339   }
340   
341   if ( flag == 2 || flag == 3 ) /* ALL the isometric cases : flag[1] = 3 or 4 or 5 or 6 */
342   {
343     int verbose = 0 ;
344     int narg        ;
345     int wdim[2]     ;
346     double FRect[4] ;
347     double WRect[4] ;
348     double ARect[4] ;
349     char   logf_[2]  ;
350     /* get current window size */
351     C2F(dr)("xget","wdim",&verbose,wdim,&narg, PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
352     getscale2d(WRect,FRect,logf_,ARect);
353     wmax=linint((double)wdim[0] * WRect[2]);
354     hmax=linint((double)wdim[1] * WRect[3]); 
355   }
356   
357   if ( flag == 2 ) /* the "NON expanded isometric" cases : flag[1] = 3 or 4 */
358   {
359     double R  ;
360     double xo ;
361     double yo ;
362     double zo ;
363     double dx ;
364     double dy ;
365     double dz ;
366     
367     /* radius and center of the sphere circumscribing the box */
368     dx = dbox[1] - dbox[0] ;
369     dy = dbox[3] - dbox[2] ;
370     dz = dbox[5] - dbox[4] ;
371     
372     R  = sqrt( dx*dx + dy*dy + dz*dz)/2;
373     xo = ( xbox[0] + xbox[6] ) / 2.0 ;
374     yo = ( ybox[0] + ybox[6] ) / 2.0 ;
375     zo = ( zbox[0] + zbox[6] ) / 2.0 ;
376     
377     xmmin=   xo - R ;
378     xmmax=   xo + R ;
379     ymmax=  -yo + R ;
380     ymmin=  -yo - R ;
381   }
382
383   if (flag==2 || flag==3)
384   {
385     double hx ;
386     double hy  ;
387     hx=xmmax-xmmin;
388     hy=ymmax-ymmin;
389     if ( hx/(double)wmax  < hy/(double)hmax ) 
390     {
391       double hx1 ;
392       hx1   = wmax * hy / hmax ;
393       xmmin = xmmin - ( hx1 - hx ) / 2.0 ;
394       xmmax = xmmax + ( hx1 - hx ) / 2.0 ;
395     }
396     else 
397     {
398       double hy1 ;
399       hy1 = hmax * hx / wmax ;
400       ymmin = ymmin - ( hy1 - hy ) / 2.0 ;
401       ymmax = ymmax + ( hy1 - hy ) / 2.0 ;
402     }
403   }
404
405   if (flag != 0 ) /* != using current 3D scale */
406   {
407     double FRect[4] ;
408     /* FRect = [Xmin,Ymin,Xmax,Ymax] */
409     FRect[0] =  xmmin ;
410     FRect[1] = -ymmax ;
411     FRect[2] =  xmmax ;
412     FRect[3] = -ymmin ; /* 2) ... (why - (minus) ? )*/
413     set_scale("tftttf",NULL,FRect,aaint,"nn",NULL);
414     Cscale.metric3d = flag; 
415   }
416 }
417
418
419 /**Nextind
420  * @author Djalel Abdemouche 10/2003
421  * Should be in Action.c file
422  */
423 void Nextind(integer ind1, integer *ind2, integer *ind3)
424 {
425   *ind2 = ind1+1;
426   *ind3 = ind1-1;
427   if (ind1 > 3)
428     {
429       if (*ind2 == 8) *ind2 = 4;
430       if (*ind3 == 3) *ind3 = 7;
431     }
432   else
433     {
434       if (*ind2 == 4) *ind2 = 0;
435       if (*ind3 == -1) *ind3 = 3;
436     }
437 }
438
439
440 /**Axes3dStrings2
441  * @author F.Leray 18.10.04
442  * Should be in Axes.c file
443  */
444 int Axes3dStrings2(integer *ixbox, integer *iybox, integer *xind)
445 {
446   integer verbose=0,narg,xz[2],fontid[2],fontsize_kp,color_kp,size;
447   integer iof,barlengthx = 0,barlengthy = 0, posi[2]; 
448   integer rect[4],flag=0,x=0,y=0;
449   double ang=0.0, bbox[6];
450   int fontsize=-1,textcolor=-1,ticscolor=-1;
451   int fontstyle=0; /* F.Leray 08.04.04 */
452   sciPointObj *psubwin = NULL;
453   sciSubWindow * ppsubwin = NULL;
454   int ns=2,iflag=0,gstyle,gridStyle=2,dash[6];
455   double xx[4],yy[4],zz[4],vxx1,vyy1,vzz1;
456   integer i,xm,ym,vx[2],vy[2],xg[2],yg[2],j;
457   integer fontid_old[2], textcolor_old;
458
459   int lastzindex = 0, lastxindex = 0, lastyindex = 0;
460   double xminval, yminval, zminval, xmaxval, ymaxval, zmaxval;
461   int nbtics = 0;
462   int nbsubtics = 0;
463
464   int logrect[4], XX = 0, YY = 0; /* see below */ /* ah ouais ou ca ? */
465   double angle=0.0;
466   
467   int constOffset[2] ; /* displacment of labels from the axes segments. */
468   int maxTicksLabelSize[2] ; /* for each axis the maximum size of ticks label */
469
470
471   psubwin= (sciPointObj *)sciGetSelectedSubWin (sciGetCurrentFigure ());
472   ppsubwin = pSUBWIN_FEATURE (psubwin);
473
474   /** le cot\'e gauche ( c'est tjrs un axe des Z **/
475   xz[0] = Cscale.WIRect1[2] ;
476   xz[1] = Cscale.WIRect1[2] ;
477   iof = (xz[0]+xz[1])/50;
478
479   ticscolor = sciGetForeground(psubwin);
480   textcolor=sciGetFontForeground(psubwin);
481
482   fontsize=sciGetFontDeciWidth(psubwin)/100;
483   fontstyle=sciGetFontStyle(psubwin);
484   
485   if(sciGetEntityType (psubwin) != SCI_SUBWIN) { 
486     sciprint("Impossible case\n");
487     return 0;
488   }
489   
490
491   bbox[0] =  xminval = pSUBWIN_FEATURE (psubwin)->FRect[0]; /*xmin*/
492   bbox[1] =  xmaxval = pSUBWIN_FEATURE (psubwin)->FRect[2]; /*xmax*/
493   bbox[2] =  yminval = pSUBWIN_FEATURE (psubwin)->FRect[1]; /*ymin*/
494   bbox[3] =  ymaxval = pSUBWIN_FEATURE (psubwin)->FRect[3]; /*ymax*/ 
495   bbox[4] =  zminval = pSUBWIN_FEATURE (psubwin)->FRect[4]; /*zmin*/
496   bbox[5] =  zmaxval = pSUBWIN_FEATURE (psubwin)->FRect[5]; /*zmax*/
497   
498   C2F(dr)("xget","font",&verbose,fontid,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
499
500   fontid[0]= fontstyle;
501   fontsize_kp = fontid[1] ;
502   if( fontsize == -1 ){ 
503     fontid[1]= 1;
504     C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
505   }
506   else {
507     fontid[1] = fontsize ;
508     C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
509   }
510   if ( textcolor != -1 || ticscolor != -1 ) 
511     C2F(dr)("xget","pattern",&verbose,&color_kp,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);    
512  
513   for (i=0; i<3 ; i++) {
514     xx[i]=pSUBWIN_FEATURE (psubwin)->axes.xlim[i];
515     yy[i]=pSUBWIN_FEATURE (psubwin)->axes.ylim[i];
516     zz[i]=pSUBWIN_FEATURE (psubwin)->axes.zlim[i];
517   } 
518
519   /* main title */ /* We fix the title always at the top */
520   rect[0]= Cscale.WIRect1[0] ;
521   rect[1]= Cscale.WIRect1[1] ;
522   rect[2]= Cscale.WIRect1[2] ;
523   rect[3]= Cscale.WIRect1[3]/6 ;
524   textcolor_old = textcolor;
525   fontid_old[0] = fontid[0];
526   fontid_old[1] = fontid[1];
527
528   constOffset[0] = Cscale.WIRect1[2] / 50 + 1 ;
529   constOffset[1] = Cscale.WIRect1[3] / 25 + 1 ;
530   
531   if( sciGetVisibility(ppsubwin->mon_title) )
532   {
533     /* get the pointer on the title */
534     sciLabel * ppLabel = pLABEL_FEATURE( ppsubwin->mon_title ) ;
535     
536     /* get position and orientation of the title */
537     if ( ppLabel->auto_rotation )
538     {
539       sciSetFontOrientation( ppsubwin->mon_title, 0 ) ;
540     }
541     
542     if ( ppLabel->auto_position )
543     {
544       /* same as in 2d */
545       int segmentStart[2] = { rect[0] + rect[2], rect[1] } ;
546       int segmentEnd[2]   = { rect[0]          , rect[1] } ;
547       computeLabelAutoPos( ppsubwin->mon_title, segmentStart, segmentEnd, constOffset ) ;
548     }
549     /* draw the label */
550     drawTextEntity( ppLabel->text ) ;
551   }
552   
553   textcolor = textcolor_old;
554   fontid[0] = fontid_old[0];
555   fontid[1] = fontid_old[1];
556
557   size = xz[0]>=xz[1] ? (integer) (xz[1]/50.0) : (integer) (xz[0]/50.0); 
558   
559   /* compute bounding of "10"  string used for log scale ON and auto_ticks ON */
560   C2F(dr)("xstringl","10",&XX,&YY,logrect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);   
561
562   /********************************************/
563   /* draw the axis line if axes_visible is on */
564   /********************************************/
565   {
566     int x2[5] ;
567     int two = 2 ;
568     int one = 1 ;
569     int verbose2 = 0 ;
570     int dash2[6] ;
571     int pat ;
572     int narg2 ;
573     x2[0] = sciGetForeground (psubwin);
574     x2[2] = sciGetLineWidth (psubwin) ;
575     x2[3] = sciGetLineStyle (psubwin);
576     x2[4] = 0;
577     C2F(dr)("xget","line style",&verbose2,dash2,&narg2,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); 
578     C2F(dr)("xget","pattern",&verbose2,&pat,&narg2,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
579     C2F (dr) ("xset", "dashes", x2, x2, x2+4, x2+4, x2+4,PI0,PD0,PD0,PD0,PD0, 5L, 6L);
580     C2F (dr) ("xset","foreground",x2,x2,x2+4,x2+4,x2+4,PI0,PD0,PD0,PD0,PD0,5L,4096); /* F.Leray 05.03.04 Useless too*/
581     C2F (dr) ("xset","thickness",x2+2,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
582     C2F (dr) ("xset", "line style", x2+3,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
583     if ( ppsubwin->axes.axes_visible[2] )
584     {
585       /* draw the line of the axis like in 2d */
586       /* the two bounds are (ixbox[2],iybox[2]) and (ixbox[2],iybox[2]) */
587       C2F(dr)("xpolys","v",&(ixbox[2]),&(iybox[2]),x2,&one,&two, PI0,PD0,PD0,PD0,PD0,0L,0L);
588     }
589     if ( ( xind[4]+xind[5] == 3) || ( xind[4]+xind[5] == 11 ) )
590     {
591       /* i copy this test but I don't know what it mean... jb Silvy 03/2006 */
592       if ( ppsubwin->axes.axes_visible[1] )
593       {
594         /* draw the line of the axis like in 2d */
595         /* the two bounds are (ixbox[3],iybox[3]) and (ixbox[3],iybox[3]) */
596         C2F(dr)("xpolys","v",&(ixbox[3]),&(iybox[3]),x2,&one,&two, PI0,PD0,PD0,PD0,PD0,0L,0L);
597       }
598       if ( ppsubwin->axes.axes_visible[0] )
599       {
600         /* draw the line of the axis like in 2d */
601         /* the two bounds are (ixbox[4],iybox[4]) and (ixbox[4],iybox[4]) */
602         C2F(dr)("xpolys","v",&(ixbox[4]),&(iybox[4]),x2,&one,&two, PI0,PD0,PD0,PD0,PD0,0L,0L);
603       }
604     }
605     else
606     {
607       if ( ppsubwin->axes.axes_visible[1] )
608       {
609         /* draw the line of the axis like in 2d */
610         /* the two bounds are (ixbox[3],iybox[3]) and (ixbox[3],iybox[3]) */
611         C2F(dr)("xpolys","v",&(ixbox[4]),&(iybox[4]),x2,&one,&two, PI0,PD0,PD0,PD0,PD0,0L,0L);
612       }
613       if ( ppsubwin->axes.axes_visible[0] )
614       {
615         /* draw the line of the axis like in 2d */
616         /* the two bounds are (ixbox[4],iybox[4]) and (ixbox[4],iybox[4]) */
617         C2F(dr)("xpolys","v",&(ixbox[3]),&(iybox[3]),x2,&one,&two, PI0,PD0,PD0,PD0,PD0,0L,0L);
618       }
619     }
620     C2F(dr)("xset","pattern",&pat,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
621     C2F(dr)("xset","line style",dash2,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
622   }  
623
624   /********************/
625   /*** le z scaling ***/ /* DISPLAY Z graduations */
626   /********************/
627
628
629   if (pSUBWIN_FEATURE (psubwin)->project[2]==1)
630     {
631       double fx,fy,fz; 
632       char c_format[5] ;
633
634       integer Ticsdir[2];
635       Ticsdir[0]=ixbox[3]-ixbox[4]; /* <=> en pixel direction/vecteur non norme(e)s des tics en x */
636       Ticsdir[1]=iybox[3]-iybox[4]; /* <=> idem pour y */
637       /* NB: for a default plot3d (simply calling plot3d in siclab console) */
638       /* Ticsdir[0] & Ticsdir[1] are negative : we do min - max here... */
639
640       BBoxToval(&fx,&fy,&fz,xind[3],bbox); /* xind[3] <=> en bas a gauche <=> zmin */
641       x=ixbox[2]-(xz[0]+xz[1])/20;
642       y=(iybox[3]+iybox[2])/2;
643   
644       /*       NumberFormat(str,((integer) zz[0]),((integer) zz[2])); */
645       
646       
647       if( !ppsubwin->axes.auto_ticks[2] )
648         {
649           /* we display the z tics specified by the user*/
650           nbtics = ppsubwin->axes.u_nzgrads;
651           nbsubtics = ppsubwin->axes.nbsubtics[2];
652
653           maxTicksLabelSize[0] = 0 ;
654           maxTicksLabelSize[1] = 0 ;
655           
656           for(i=0;i<nbtics;i++)
657             {
658               char *foo = ppsubwin->axes.u_zlabels[i]; 
659               double ztmp = ppsubwin->axes.u_zgrads[i];
660               
661               if(ztmp<zminval || ztmp>zmaxval) 
662                 {
663                   /*   sciprint("je rejete la valeur: %lf\n\n",xtmp); */
664                   continue; /* cas ou TL est ON et on a des graduations qui ne seront pas affichees de tte facon */
665                   /* donc autant ne pas aller plus loin dans l'algo... */
666                 }
667                   
668
669               /***************************************************************/
670               /************************* COMMON PART *************************/
671               /***************************************************************/
672               
673               if( ppsubwin->axes.reverse[2] )
674               {
675                 ztmp = InvAxis(ppsubwin->FRect[4],ppsubwin->FRect[5],ztmp);
676               }
677               
678               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&fy,&ztmp);
679               
680
681               vx[0]=xm;vy[0]=ym;
682
683               barlengthx= (integer) (( Ticsdir[0])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
684               barlengthy= (integer) (( Ticsdir[1])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
685               vx[1]=vx[0]+barlengthx;
686               vy[1]=vy[0]+barlengthy;
687                   
688               /* foo is set above with sprintf(foo,c_format,xtmp); */
689                   
690               C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); /* fix bug noticed by R.N. */
691               
692               /* get the size of ticks label */
693               C2F(dr)("xstringl",foo,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
694               maxTicksLabelSize[0] = Max( maxTicksLabelSize[0], rect[2] ) ;
695               maxTicksLabelSize[1] = Max( maxTicksLabelSize[1], rect[3] ) ;
696
697
698               posi[0] = inint( xm+2*barlengthx - rect[2]); 
699               posi[1]=inint( ym + 2*barlengthy + rect[3]/2);
700
701
702               if(ppsubwin->axes.axes_visible[2] == TRUE){
703                 C2F(dr)("xset","pattern",&textcolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
704                 C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
705                 C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&ang, PD0,PD0,PD0,0L,0L);
706                 C2F(dr)("xset","pattern",&ticscolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
707                 C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
708               }
709               /* grid to put here */
710               if ( ppsubwin->grid[2] > -1 && ppsubwin->axes.axes_visible[2] )
711                 {
712                   gstyle = pSUBWIN_FEATURE (psubwin)->grid[2];
713
714                   if((ppsubwin->logflags[2] =='l') && (i != nbtics-1))
715                     {
716                       double tmp[2];
717                       double pas=0;
718                       double * tmp_log_grads = (double *) NULL;
719                       
720                       
721                       double * grads = ppsubwin->axes.u_zgrads;
722                       
723                       tmp[0] = exp10(grads[i]);
724                       tmp[1] = exp10(grads[i+1]);
725                       pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
726                       
727                       if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
728                         sciprint("Error allocating tmp_log_grads\n");
729                         return -1;
730                       }
731                       
732                       for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
733                       
734                       for(j=0;j<nbsubtics;j++)
735                         {
736                           vzz1 = tmp_log_grads[j];
737                           
738                           if(vzz1<=zminval || vzz1>=zmaxval) continue;   
739                           
740                           if(ppsubwin->axes.reverse[2] == TRUE)
741                             vzz1 = InvAxis(ppsubwin->FRect[4],ppsubwin->FRect[5],vzz1);
742                                   
743                           ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&fy,&vzz1);
744                           
745                           /*  if ((ym != iybox[3]) && (ym != iybox[2])) */
746                           /*                        { */
747                           C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
748                           C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
749                           xg[0]= ixbox[3];yg[0]= ym;
750                           if (Ishidden(psubwin))
751                             {  xg[1]=ixbox[4];  yg[1]= iybox[4]- iybox[3]+ym;}
752                           else
753                             {xg[1]=ixbox[1];  yg[1]= iybox[1]- iybox[2]+ym;}
754                           C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
755                           xg[0]=xg[1];  ; xg[1] =ixbox[0];
756                           yg[0]=yg[1]; yg[1]= ym- iybox[3]+ iybox[5];
757                           C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
758                           C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
759                           /*   } */
760                         }
761                       FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
762                     }
763                   else
764                     { 
765                       if(ztmp>zminval && ztmp<zmaxval) 
766                         {
767                           C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
768                           C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
769                           xg[0]= ixbox[3];yg[0]= ym;
770                           if (Ishidden(psubwin))
771                             {  xg[1]=ixbox[4];  yg[1]= iybox[4]- iybox[3]+ym;}
772                           else
773                             {xg[1]=ixbox[1];  yg[1]= iybox[1]- iybox[2]+ym;}
774                           C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
775                           xg[0]=xg[1];  ; xg[1] =ixbox[0];
776                           yg[0]=yg[1]; yg[1]= ym- iybox[3]+ iybox[5];
777                           C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
778                           C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
779                         }
780                     }
781                 }
782                   
783               /* and subtics */
784               if(i != nbtics-1)
785                 {
786                   if(ppsubwin->logflags[2] =='l')
787                     {
788                       double tmp[2];
789                       double pas=0;
790                       double * tmp_log_grads = (double *) NULL;
791                       
792                       
793                       double * grads = ppsubwin->axes.u_zgrads;
794                       
795                       tmp[0] = exp10(grads[i]);
796                       tmp[1] = exp10(grads[i+1]);
797                       pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
798                       
799                       if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
800                         sciprint("Error allocating tmp_log_grads\n");
801                         return -1;
802                       }
803                       
804                       for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
805                       
806                       for(j=0;j<nbsubtics;j++)
807                         {
808                           vzz1 = tmp_log_grads[j];
809                           
810                           if(vzz1<zminval || vzz1>zmaxval) continue;
811                           
812                           if(ppsubwin->axes.reverse[2] == TRUE)
813                             vzz1 = InvAxis(ppsubwin->FRect[4],ppsubwin->FRect[5],vzz1);
814                           
815                           ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&fy,&vzz1);
816                           
817                           vx[0]=xm;vy[0]=ym;
818                           vx[1]= (integer) (vx[0]+barlengthx/2.0);
819                           vy[1]= (integer) (vy[0]+barlengthy/2.0);
820                           
821                           if(ppsubwin->axes.axes_visible[2] == TRUE)
822                             C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
823                         }
824                       FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
825                     } /* end NEW */
826                   else
827                     {
828                       double xtmp = ppsubwin->axes.u_zgrads[i];
829                       double dx = (ppsubwin->axes.u_zgrads[i+1] - ppsubwin->axes.u_zgrads[i]) / nbsubtics;
830                       for(j=0;j<nbsubtics;j++)
831                         {
832                           vzz1=xtmp+dx*j;
833                           
834                           if(vzz1<zminval || vzz1>zmaxval) continue;     
835                           
836                           if(ppsubwin->axes.reverse[2] == TRUE)
837                             vzz1 = InvAxis(ppsubwin->FRect[4],ppsubwin->FRect[5],vzz1);
838                           
839                           ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&fy,&vzz1);
840                           /*                  trans3d(psubwin,1,&xm,&ym,&fx,&fy,&vzz1); */
841                           
842                           
843                           vx[0]=xm;vy[0]=ym;
844                           vx[1]= (integer) (vx[0]+barlengthx/2.0);
845                           vy[1]= (integer) (vy[0]+barlengthy/2.0);
846                           
847                           if(ppsubwin->axes.axes_visible[2] == TRUE)
848                             C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
849                         }
850                     } 
851                 }
852               
853               /***************************************************************/
854               /************************* END OF COMMON PART ******************/
855               /***************************************************************/
856             }
857         }
858       else /* we display the computed tics */
859         {
860           AdaptGraduationsOnZ(x,y,size,Ticsdir,fontid,psubwin,zminval,zmaxval,fx,fy,0.);
861
862           lastzindex = ppsubwin->axes.nzgrads - 1;
863           
864           if(lastzindex == 0)
865             ChooseFormatForOneGrad(c_format,&(ppsubwin->axes.zgrads[0]));
866           else
867             ChoixFormatE(c_format,
868                          ppsubwin->axes.zgrads[0],
869                          ppsubwin->axes.zgrads[lastzindex],
870                          ((ppsubwin->axes.zgrads[lastzindex])-(ppsubwin->axes.zgrads[0]))/(lastzindex));
871           
872           nbtics = ppsubwin->axes.nzgrads;
873           nbsubtics = ppsubwin->axes.nbsubtics[2];
874
875           maxTicksLabelSize[0] = 0 ;
876           maxTicksLabelSize[1] = 0 ;
877           
878           for(i=0;i<nbtics;i++)
879             {
880               char foo[256]; 
881               double ztmp = ppsubwin->axes.zgrads[i];
882               
883               if(ztmp<zminval || ztmp>zmaxval) 
884                 {
885                   /*   sciprint("je rejete la valeur: %lf\n\n",xtmp); */
886                   continue; /* cas ou TL est ON et on a des graduations qui ne seront pas affichees de tte facon */
887                   /* donc autant ne pas aller plus loin dans l'algo... */
888                 }
889               
890               sprintf(foo,c_format,ztmp);
891
892               /***************************************************************/
893               /************************* COMMON PART *************************/
894               /***************************************************************/
895               if(ppsubwin->axes.reverse[2] == TRUE)
896                 ztmp = InvAxis(ppsubwin->FRect[4],ppsubwin->FRect[5],ztmp);
897   
898               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&fy,&ztmp);
899
900               /*              trans3d(psubwin,1,&xm,&ym,&fx,&fy,&ztmp); */
901
902
903               vx[0]=xm;vy[0]=ym;
904
905               barlengthx= (integer) (( Ticsdir[0])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
906               barlengthy= (integer) (( Ticsdir[1])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
907               vx[1]=vx[0]+barlengthx;
908               vy[1]=vy[0]+barlengthy;
909                   
910               /* foo is set above with sprintf(foo,c_format,xtmp); */
911               
912               C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); /* fix bug noticed by R.N. */
913               
914               /* get the size of ticks label */
915               C2F(dr)("xstringl",foo,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
916               maxTicksLabelSize[0] = Max( maxTicksLabelSize[0], rect[2] ) ;
917               maxTicksLabelSize[1] = Max( maxTicksLabelSize[1], rect[3] ) ;
918
919               posi[0] = inint( xm+2*barlengthx - rect[2]); 
920               posi[1]=inint( ym + 2*barlengthy + rect[3]/2);
921               
922               if(ppsubwin->axes.axes_visible[2] == TRUE){
923                 C2F(dr)("xset","pattern",&textcolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
924                 C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
925                 if ( ppsubwin->logflags[2] == 'l' )
926                   {
927                     int smallersize = fontid[1]-2;
928                     int old_rect10[4];
929 /*                  char str[2] = "xv"; */
930                     int posi10[2];
931                     
932                     posi10[0] = posi[0] - logrect[2];
933                     posi10[1] = posi[1] + logrect[3];
934
935                     C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
936                     C2F(dr)("xstring","10",(&posi10[0]),(&posi10[1]),PI0,&flag,PI0,PI0,&angle,PD0,PD0,PD0,0L,0L);
937
938                     C2F(dr)("xstringl","10",(&posi10[0]),(&posi10[1]),old_rect10,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
939                     
940                     posi[0] = old_rect10[0] + old_rect10[2];
941                     posi[1] = (int) (old_rect10[1] - old_rect10[3]*.1);
942
943                     C2F(dr)("xset","font",fontid,&smallersize,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
944                     C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&ang, PD0,PD0,PD0,0L,0L);
945                     
946                     /* put back the current fontid */
947                     C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
948                   }
949                 else{
950                   C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&ang, PD0,PD0,PD0,0L,0L);
951                 }
952                 
953                 C2F(dr)("xset","pattern",&ticscolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);   
954                 C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
955               }
956               /* grid to put here */
957               if ( ppsubwin->grid[2] > -1 && ppsubwin->axes.axes_visible[2] )
958                 {
959                   gstyle = pSUBWIN_FEATURE (psubwin)->grid[2];
960
961                   if((ppsubwin->logflags[2] =='l') && (i != nbtics-1))
962                     {
963                       double tmp[2];
964                       double pas=0;
965                       double * tmp_log_grads = (double *) NULL;
966                       
967                       
968                       double * grads = ppsubwin->axes.zgrads;
969                       
970                       tmp[0] = exp10(grads[i]);
971                       tmp[1] = exp10(grads[i+1]);
972                       pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
973                       
974                       if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
975                         sciprint("Error allocating tmp_log_grads\n");
976                         return -1;
977                       }
978                       
979                       for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
980                       
981                       for(j=0;j<nbsubtics;j++)
982                         {
983                           vzz1 = tmp_log_grads[j];
984                           
985                           if(vzz1<=zminval || vzz1>=zmaxval) continue;   
986
987                           if(ppsubwin->axes.reverse[2] == TRUE)
988                             vzz1 = InvAxis(ppsubwin->FRect[4],ppsubwin->FRect[5],vzz1);
989                           
990                           ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&fy,&vzz1);
991                           
992                           /*  if ((ym != iybox[3]) && (ym != iybox[2])) */
993                           /*                        { */
994                           C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
995                           C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
996                           xg[0]= ixbox[3];yg[0]= ym;
997                           if (Ishidden(psubwin))
998                             {  xg[1]=ixbox[4];  yg[1]= iybox[4]- iybox[3]+ym;}
999                           else
1000                             {xg[1]=ixbox[1];  yg[1]= iybox[1]- iybox[2]+ym;}
1001                           C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1002                           xg[0]=xg[1];  ; xg[1] =ixbox[0];
1003                           yg[0]=yg[1]; yg[1]= ym- iybox[3]+ iybox[5];
1004                           C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1005                           C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1006                           /*   } */
1007                         }
1008                       FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
1009                     }
1010                   else
1011                     {
1012                       if(ztmp>zminval && ztmp<zmaxval) 
1013                         {
1014                           C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1015                           C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1016                           xg[0]= ixbox[3];yg[0]= ym;
1017                           if (Ishidden(psubwin))
1018                             {  xg[1]=ixbox[4];  yg[1]= iybox[4]- iybox[3]+ym;}
1019                           else
1020                             {xg[1]=ixbox[1];  yg[1]= iybox[1]- iybox[2]+ym;}
1021                           C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1022                           xg[0]=xg[1];  ; xg[1] =ixbox[0];
1023                           yg[0]=yg[1]; yg[1]= ym- iybox[3]+ iybox[5];
1024                           C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1025                           C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1026                         }
1027                     }
1028                 }
1029               
1030               /* and subtics */
1031               if(i != nbtics-1)
1032                 {
1033                   if(ppsubwin->logflags[2] =='l')
1034                     {
1035                       double tmp[2];
1036                       double pas=0;
1037                       double * tmp_log_grads = (double *) NULL;
1038                       
1039                       
1040                       double * grads = ppsubwin->axes.zgrads;
1041                       
1042                       tmp[0] = exp10(grads[i]);
1043                       tmp[1] = exp10(grads[i+1]);
1044                       pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
1045                       
1046                       if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
1047                         sciprint("Error allocating tmp_log_grads\n");
1048                         return -1;
1049                       }
1050                       
1051                       for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
1052                       
1053                       for(j=0;j<nbsubtics;j++)
1054                         {
1055                           vzz1 = tmp_log_grads[j];
1056                           
1057                           if(vzz1<zminval || vzz1>zmaxval) continue;
1058                           
1059                           if(ppsubwin->axes.reverse[2] == TRUE)
1060                             vzz1 = InvAxis(ppsubwin->FRect[4],ppsubwin->FRect[5],vzz1);
1061                           
1062                           ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&fy,&vzz1);
1063                           
1064                           vx[0]=xm;vy[0]=ym;
1065                           vx[1]= (integer) (vx[0]+barlengthx/2.0);
1066                           vy[1]= (integer) (vy[0]+barlengthy/2.0);
1067                           
1068                           if(ppsubwin->axes.axes_visible[2] == TRUE)
1069                             C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1070                         }
1071                       FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
1072                     } /* end NEW */
1073                   else
1074                     {
1075                       double ztmp2 = ppsubwin->axes.zgrads[i];
1076                       double dz = (ppsubwin->axes.zgrads[i+1] - ppsubwin->axes.zgrads[i]) / nbsubtics;
1077                       for(j=0;j<nbsubtics;j++)
1078                         {
1079                           vzz1=ztmp2+dz*j;
1080                           
1081                           if(vzz1<zminval || vzz1>zmaxval) continue;
1082                           
1083                           if(ppsubwin->axes.reverse[2] == TRUE)
1084                             vzz1 = InvAxis(ppsubwin->FRect[4],ppsubwin->FRect[5],vzz1);
1085                           
1086                           ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&fy,&vzz1);
1087                           /*                  trans3d(psubwin,1,&xm,&ym,&fx,&fy,&vzz1); */
1088                           
1089                           
1090                           vx[0]=xm;vy[0]=ym;
1091                           vx[1]= (integer) (vx[0]+barlengthx/2.0);
1092                           vy[1]= (integer) (vy[0]+barlengthy/2.0);
1093                           
1094                           if(ppsubwin->axes.axes_visible[2] == TRUE)
1095                             C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1096                         }
1097                     }
1098                 }
1099               /***************************************************************/
1100               /************************* END OF COMMON PART ******************/
1101               /***************************************************************/
1102               
1103             }
1104         }
1105     }
1106   
1107   if ( sciGetVisibility(ppsubwin->mon_z_label) )
1108     {
1109       /* draw z label */
1110       sciLabel * ppLabel = pLABEL_FEATURE(ppsubwin->mon_z_label) ;
1111             
1112       if ( ppLabel->auto_rotation )
1113       {
1114         /* mult by 10 because */
1115         sciSetFontOrientation(ppsubwin->mon_z_label, 270 * 10 ) ;
1116       }
1117       
1118       if( ppLabel->auto_position )
1119       {
1120         
1121         int segmentStart[2] = { ixbox[2], iybox[2] } ;
1122         int segmentEnd[2]   = { ixbox[3], iybox[3] } ;
1123         
1124         /* add the bar size and ticks label size to the offset */
1125         int offset[2] = { constOffset[0] + maxTicksLabelSize[0] + abs( barlengthx ), 
1126                           constOffset[1] + maxTicksLabelSize[1] + abs( barlengthy )  } ;
1127         computeLabelAutoPos( ppsubwin->mon_z_label, segmentStart, segmentEnd, offset ) ;
1128       }
1129       /* a trick to force the display with 2d scale */
1130       drawTextEntity( ppLabel->text ) ;
1131       
1132     }
1133   
1134
1135   /***********************/ /** bottom right side ***/
1136   /*** le  x-y scaling ***/ /* DISPLAY x or y graduations */
1137   /***********************/
1138
1139   
1140   if (( xind[4]+xind[5] == 3) || ( xind[4]+xind[5] == 11))
1141     {
1142       if (pSUBWIN_FEATURE (psubwin)->project[0]==1) /* x HERE */
1143         {
1144           double fx,fy,fz;
1145           char c_format[5];
1146
1147           integer Ticsdir[2]; 
1148           Ticsdir[0]=ixbox[4]-ixbox[3];
1149           Ticsdir[1]=iybox[4]-iybox[3];
1150           BBoxToval(&fx,&fy,&fz,xind[4],bbox);
1151           x=inint((ixbox[4]+ixbox[5])/2+1.5*rect[2] +iof);
1152           y=inint(((2/3.0)*iybox[4]+(1/3.0)*iybox[5])+1.5*rect[3]+iof);
1153           
1154           if( !ppsubwin->axes.auto_ticks[0] )
1155             {
1156               /* we display the x tics specified by the user*/
1157               nbtics = ppsubwin->axes.u_nxgrads;
1158               nbsubtics = ppsubwin->axes.nbsubtics[0];
1159               
1160               maxTicksLabelSize[0] = 0 ;
1161               maxTicksLabelSize[1] = 0 ;
1162
1163               for(i=0;i<nbtics;i++)
1164                 {
1165                   char *foo = ppsubwin->axes.u_xlabels[i]; 
1166                   double xtmp = ppsubwin->axes.u_xgrads[i];
1167                   
1168                   if(xtmp<xminval || xtmp>xmaxval) 
1169                     {
1170                       /*   sciprint("je rejete la valeur: %lf\n\n",xtmp); */
1171                       continue; /* cas ou TL est ON et on a des graduations qui ne seront pas affichees de tte facon */
1172                       /* donc autant ne pas aller plus loin dans l'algo... */
1173                     }
1174
1175                   /***************************************************************/
1176                   /************************* COMMON PART *************************/
1177                   /***************************************************************/
1178                   
1179                   if(ppsubwin->axes.reverse[0] == TRUE)
1180                     xtmp = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],xtmp);
1181                                   
1182                   ComputeGoodTrans3d(psubwin,1,&xm,&ym,&xtmp,&fy,&fz);
1183                   /*   trans3d(psubwin,1,&xm,&ym,&xtmp,&fy,&fz); */
1184
1185
1186                   vx[0]=xm;vy[0]=ym;
1187
1188                   barlengthx= (integer) (( Ticsdir[0])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
1189                   barlengthy= (integer) (( Ticsdir[1])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
1190
1191                   C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); /* fix bug noticed by R.N. */
1192
1193                   /* get the size of the icks label */
1194                   C2F(dr)("xstringl",foo,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1195                   maxTicksLabelSize[0] = Max( maxTicksLabelSize[0], rect[2] ) ;
1196                   maxTicksLabelSize[1] = Max( maxTicksLabelSize[1], rect[3] ) ;
1197                   
1198                   
1199                   if (IsDownAxes(psubwin)){
1200                     vx[1]=vx[0];
1201                     vy[1]=vy[0]+iof/2;
1202                     posi[0] = inint(xm-rect[2]/2); 
1203                     posi[1]=inint( vy[0] + iof + rect[3]);}
1204                   else{
1205                     vx[1]=vx[0]+barlengthx;
1206                     vy[1]=vy[0]+barlengthy;
1207                     posi[0] = inint( xm+2*barlengthx);
1208                     posi[1]=inint( ym + 2*barlengthy + rect[3]);}
1209                       
1210                   if( ppsubwin->axes.axes_visible[0] )
1211                   {    
1212                     C2F(dr)("xset","pattern",&textcolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1213                     C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1214                     C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&ang, PD0,PD0,PD0,0L,0L);
1215                     C2F(dr)("xset","pattern",&ticscolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);   
1216                     C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1217                   }
1218                   /* grid to put here */
1219                   if ( ppsubwin->grid[0] > -1 && ppsubwin->axes.axes_visible[0] )
1220                     {
1221                       gstyle = pSUBWIN_FEATURE (psubwin)->grid[0];
1222
1223                       if((ppsubwin->logflags[0] =='l') && (i != nbtics-1))
1224                         {
1225                           double tmp[2];
1226                           double pas=0;
1227                           double * tmp_log_grads = (double *) NULL;
1228                           
1229                           
1230                           double * grads = ppsubwin->axes.u_xgrads;
1231
1232                           tmp[0] = exp10(grads[i]);
1233                           tmp[1] = exp10(grads[i+1]);
1234                           pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
1235                           
1236                           if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
1237                             sciprint("Error allocating tmp_log_grads\n");
1238                             return -1;
1239                           }
1240                           
1241                           for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
1242                           
1243                           for(j=0;j<nbsubtics;j++)
1244                             {
1245                               vxx1 = tmp_log_grads[j];
1246                               
1247                               if(vxx1<=xminval || vxx1>=xmaxval) continue;
1248                               
1249                               if(ppsubwin->axes.reverse[0] == TRUE)
1250                                 vxx1 = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],vxx1);
1251                               
1252                               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&vxx1,&fy,&fz);
1253                               
1254                               /*  if ((xm != ixbox[5]) && (xm != ixbox[4])) */
1255                               /*                                {  */
1256                               xg[0]= xm;  yg[0]= ym;  
1257                               if (Ishidden(psubwin)) 
1258                                 { xg[1]= xm; yg[1]= iybox[2] -iybox[3]+ym; }
1259                               else
1260                                 {xg[1]= ixbox[3] - ixbox[4] +xm; yg[1]= iybox[3] - iybox[4] +ym; } 
1261                                   
1262                               C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1263                               C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1264                               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1265                               xg[0]= xg[1]; yg[0]= yg[1];
1266                               xg[1] = ixbox[3] - ixbox[4] +xm; 
1267                               yg[1]=  iybox[2] - iybox[4] +ym;
1268                               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1269                               C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
1270                               /*        } */
1271                             }
1272                           FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
1273                         }
1274                       else
1275                         {
1276                           if(xtmp>xminval && xtmp<xmaxval) 
1277                             {
1278                               xg[0]= xm;  yg[0]= ym;  
1279                               if (Ishidden(psubwin)) 
1280                                 { xg[1]= xm; yg[1]= iybox[2] -iybox[3]+ym; }
1281                               else
1282                                 {xg[1]= ixbox[3] - ixbox[4] +xm; yg[1]= iybox[3] - iybox[4] +ym; } 
1283                               C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1284                               C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1285                               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1286                               xg[0]= xg[1]; yg[0]= yg[1];
1287                               xg[1] = ixbox[3] - ixbox[4] +xm; 
1288                               yg[1]=  iybox[2] - iybox[4] +ym;
1289                               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1290                               C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
1291                             }
1292                         }
1293                     }
1294
1295                   /* and subtics */
1296                   if(i != nbtics-1)
1297                     {
1298                       if(ppsubwin->logflags[0] =='l')
1299                         {
1300                           double tmp[2];
1301                           double pas=0;
1302                           double * tmp_log_grads = (double *) NULL;
1303                           
1304                           
1305                           double * grads = ppsubwin->axes.u_xgrads;
1306
1307                           tmp[0] = exp10(grads[i]);
1308                           tmp[1] = exp10(grads[i+1]);
1309                           pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
1310                           
1311                           if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
1312                             sciprint("Error allocating tmp_log_grads\n");
1313                             return -1;
1314                           }
1315                           
1316                           for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
1317                           
1318                           for(j=0;j<nbsubtics;j++)
1319                             {
1320                               vxx1 = tmp_log_grads[j];
1321                               
1322                               if(vxx1<xminval || vxx1>xmaxval) continue;
1323                               
1324                               if(ppsubwin->axes.reverse[0] == TRUE)
1325                                 vxx1 = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],vxx1);
1326                               
1327                               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&vxx1,&fy,&fz);
1328                               
1329                               if (IsDownAxes(psubwin))
1330                                 {
1331                                   vx[1]=vx[0]=xm;
1332                                   vy[0]=ym;
1333                                   vy[1]=vy[0]+iof/4;
1334                                 }
1335                               else
1336                                 {
1337                                   vx[0]=xm;vy[0]=ym;
1338                                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
1339                                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
1340                                 }
1341                               
1342                               if(ppsubwin->axes.axes_visible[0] == TRUE)
1343                                 C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1344                             }
1345                           
1346                           FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
1347                         } /* end NEW */
1348                       else
1349                         {
1350                           double xtmp2 = ppsubwin->axes.u_xgrads[i];
1351                           double dx = (ppsubwin->axes.u_xgrads[i+1] - ppsubwin->axes.u_xgrads[i]) / nbsubtics;
1352                           
1353                           for (j=1;j<nbsubtics;j++)
1354                             {  
1355                               vxx1=xtmp2+dx*j;
1356                               
1357                               if(vxx1<xminval || vxx1>xmaxval) continue;
1358                               
1359                               if(ppsubwin->axes.reverse[0] == TRUE)
1360                                 vxx1 = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],vxx1);
1361                               
1362                               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&vxx1,&fy,&fz);
1363                               /*                          trans3d(psubwin,1,&xm,&ym,&vxx1,&fy,&fz); */
1364
1365
1366                               if (IsDownAxes(psubwin))
1367                                 {
1368                                   vx[1]=vx[0]=xm;
1369                                   vy[0]=ym;
1370                                   vy[1]=vy[0]+iof/4;
1371                                 }
1372                               else
1373                                 {
1374                                   vx[0]=xm;vy[0]=ym;
1375                                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
1376                                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
1377                                 }
1378                               
1379                               if(ppsubwin->axes.axes_visible[0] == TRUE)   
1380                                 C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1381                             }
1382                         }
1383                     }
1384                   /***************************************************************/
1385                   /************************* END OF COMMON PART ******************/
1386                   /***************************************************************/
1387                   
1388                 }
1389             }
1390           else /* we display the computed tics */
1391             {
1392               AdaptGraduationsOnXBottomRight(iof,x,y,size,Ticsdir,fontid,psubwin,xminval,xmaxval,0.,fy,fz);
1393                       
1394               lastxindex = ppsubwin->axes.nxgrads - 1;
1395               
1396               if(lastxindex == 0)
1397               {
1398                 ChooseFormatForOneGrad(c_format,&(ppsubwin->axes.xgrads[0]));
1399               }
1400               else
1401               {
1402                 ChoixFormatE(c_format,
1403                              ppsubwin->axes.xgrads[0],
1404                              ppsubwin->axes.xgrads[lastxindex],
1405                              ((ppsubwin->axes.xgrads[lastxindex])-(ppsubwin->axes.xgrads[0]))/(lastxindex));
1406               }
1407               
1408               nbtics = ppsubwin->axes.nxgrads;
1409               nbsubtics = ppsubwin->axes.nbsubtics[0];
1410                      
1411               maxTicksLabelSize[0] = 0 ;
1412               maxTicksLabelSize[1] = 0 ;
1413  
1414               for(i=0;i<nbtics;i++)
1415                 {
1416                   char foo[256]; 
1417                   double xtmp = ppsubwin->axes.xgrads[i];
1418                   
1419                   if(xtmp<xminval || xtmp>xmaxval) 
1420                     {
1421                       /*   sciprint("je rejete la valeur: %lf\n\n",xtmp); */
1422                       continue; /* cas ou TL est ON et on a des graduations qui ne seront pas affichees de tte facon */
1423                       /* donc autant ne pas aller plus loin dans l'algo... */
1424                     }
1425                   
1426                   sprintf(foo,c_format,xtmp);
1427
1428                   /***************************************************************/
1429                   /************************* COMMON PART *************************/
1430                   /***************************************************************/
1431                  
1432
1433                   /* F.Leray 03.11.04 Test if log scale to perform a : exp10(x) because trans3d will */
1434                   /* re-do a log10() (that is needed for data computations) */
1435
1436                   if( ppsubwin->axes.reverse[0] )
1437                   {
1438                     xtmp = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],xtmp);
1439                   }
1440                   
1441                   ComputeGoodTrans3d(psubwin,1,&xm,&ym,&xtmp,&fy,&fz);
1442                   
1443                   vx[0]=xm;vy[0]=ym; 
1444                   
1445                   barlengthx= (integer) (( Ticsdir[0])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
1446                   barlengthy= (integer) (( Ticsdir[1])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
1447
1448                   C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); /* fix bug noticed by R.N. */
1449
1450                   /* get the size of ticks label */
1451                   C2F(dr)("xstringl",foo,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1452                   maxTicksLabelSize[0] = Max( maxTicksLabelSize[0], rect[2] ) ;
1453                   maxTicksLabelSize[1] = Max( maxTicksLabelSize[1], rect[3] ) ;
1454
1455                   if (IsDownAxes(psubwin)){
1456                     vx[1]=vx[0];
1457                     vy[1]=vy[0]+iof/2;
1458                     posi[0] = inint(xm-rect[2]/2); 
1459                     posi[1]=inint( vy[0] + iof + rect[3]);}
1460                   else{
1461                     vx[1]=vx[0]+barlengthx;
1462                     vy[1]=vy[0]+barlengthy;
1463                     posi[0] = inint( xm+2*barlengthx);
1464                     posi[1]=inint( ym + 2*barlengthy + rect[3]);}
1465                       
1466                   if( ppsubwin->axes.axes_visible[0] )
1467                   {
1468                     C2F(dr)("xset","pattern",&textcolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1469                     C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1470                     if ( ppsubwin->logflags[0] == 'l' )
1471                     {
1472                       int smallersize = fontid[1]-2;
1473                       int old_rect10[4];
1474                       int posi10[2];
1475                       
1476                       posi10[0] = posi[0] - logrect[2];
1477                       posi10[1] = posi[1] + logrect[3];
1478                       
1479                       C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1480                       C2F(dr)("xstring","10",(&posi10[0]),(&posi10[1]),PI0,&flag,PI0,PI0,&angle,PD0,PD0,PD0,0L,0L);
1481                       
1482                       C2F(dr)("xstringl","10",(&posi10[0]),(&posi10[1]),old_rect10,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1483                         
1484                       posi[0] = old_rect10[0] + old_rect10[2];
1485                       posi[1] = (int) (old_rect10[1] - old_rect10[3]*.1);
1486                         
1487                       C2F(dr)("xset","font",fontid,&smallersize,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1488                       C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&ang, PD0,PD0,PD0,0L,0L);
1489                         
1490                       /* put back the current fontid */
1491                       C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1492                     }
1493                     else
1494                     {
1495                       C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&ang, PD0,PD0,PD0,0L,0L);
1496                     }       
1497                     C2F(dr)("xset","pattern",&ticscolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);   
1498                     C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1499                   }
1500                   /* grid to put here */
1501                   if ( ppsubwin->grid[0] > -1 && ppsubwin->axes.axes_visible[0]  )
1502                   {
1503                     gstyle = pSUBWIN_FEATURE (psubwin)->grid[0];
1504                       
1505                     if((ppsubwin->logflags[0] =='l') && (i != nbtics-1))
1506                     {
1507                       double tmp[2];
1508                       double pas=0;
1509                       double * tmp_log_grads = (double *) NULL;
1510                           
1511                           
1512                       double * grads = ppsubwin->axes.xgrads;
1513
1514                       tmp[0] = exp10(grads[i]);
1515                       tmp[1] = exp10(grads[i+1]);
1516                       pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
1517                           
1518                       if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
1519                         sciprint("Error allocating tmp_log_grads\n");
1520                         return -1;
1521                       }
1522                           
1523                       for(j=0;j<nbsubtics;j++)
1524                       {
1525                         tmp_log_grads[j] = log10( tmp[0] + (j) * pas ) ;
1526                       }
1527                           
1528                       for(j=0;j<nbsubtics;j++)
1529                       {
1530                         vxx1 = tmp_log_grads[j];
1531                               
1532                         if(vxx1<=xminval || vxx1>=xmaxval) continue;
1533                               
1534                         if(ppsubwin->axes.reverse[0] == TRUE)
1535                           vxx1 = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],vxx1);
1536                               
1537                         ComputeGoodTrans3d(psubwin,1,&xm,&ym,&vxx1,&fy,&fz);
1538                               
1539                         /*  if ((xm != ixbox[5]) && (xm != ixbox[4])) */
1540                         /*                              {  */
1541                         xg[0]= xm;  yg[0]= ym;  
1542                         if (Ishidden(psubwin)) 
1543                         { xg[1]= xm; yg[1]= iybox[2] -iybox[3]+ym; }
1544                         else
1545                         {xg[1]= ixbox[3] - ixbox[4] +xm; yg[1]= iybox[3] - iybox[4] +ym; } 
1546                                   
1547                         C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1548                         C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1549                         C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1550                         xg[0]= xg[1]; yg[0]= yg[1];
1551                         xg[1] = ixbox[3] - ixbox[4] +xm; 
1552                         yg[1]=  iybox[2] - iybox[4] +ym;
1553                         C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1554                         C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
1555                         /*      } */
1556                       }
1557                       FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
1558                     }
1559                     else
1560                     {
1561                       if(xtmp>xminval && xtmp<xmaxval) 
1562                       {
1563                         xg[0]= xm;  yg[0]= ym;  
1564                         if (Ishidden(psubwin)) 
1565                         { xg[1]= xm; yg[1]= iybox[2] -iybox[3]+ym; }
1566                         else
1567                         {xg[1]= ixbox[3] - ixbox[4] +xm; yg[1]= iybox[3] - iybox[4] +ym; } 
1568                         C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1569                         C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1570                         C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1571                         xg[0]= xg[1]; yg[0]= yg[1];
1572                         xg[1] = ixbox[3] - ixbox[4] +xm; 
1573                         yg[1]=  iybox[2] - iybox[4] +ym;
1574                         C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1575                         C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
1576                       }
1577                     }   
1578                   }
1579
1580                   /* and subtics */
1581                   if(i != nbtics-1) /* F.Leray NEW 03.11.04 */
1582                     {
1583                       
1584                       if(ppsubwin->logflags[0] =='l')
1585                         {
1586                           double tmp[2];
1587                           double pas=0;
1588                           double * tmp_log_grads = (double *) NULL;
1589                           
1590                           
1591                           double * grads = ppsubwin->axes.xgrads;
1592
1593                           tmp[0] = exp10(grads[i]);
1594                           tmp[1] = exp10(grads[i+1]);
1595                           pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
1596                           
1597                           if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
1598                             sciprint("Error allocating tmp_log_grads\n");
1599                             return -1;
1600                           }
1601                           
1602                           for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
1603                           
1604                           for(j=0;j<nbsubtics;j++)
1605                             {
1606                               vxx1 = tmp_log_grads[j];
1607                               
1608                               if(vxx1<xminval || vxx1>xmaxval) continue;
1609                               
1610                               if(ppsubwin->axes.reverse[0] == TRUE)
1611                                 vxx1 = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],vxx1);
1612                               
1613                               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&vxx1,&fy,&fz);
1614                               
1615                               if (IsDownAxes(psubwin))
1616                                 {
1617                                   vx[1]=vx[0]=xm;
1618                                   vy[0]=ym;
1619                                   vy[1]=vy[0]+iof/4;
1620                                 }
1621                               else
1622                                 {
1623                                   vx[0]=xm;vy[0]=ym;
1624                                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
1625                                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
1626                                 }
1627                               
1628                               if( ppsubwin->axes.axes_visible[0] )
1629                                 C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1630                             }
1631                           
1632                           FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
1633                         } /* end NEW */
1634                       else
1635                         {
1636                           double xtmp2 = ppsubwin->axes.xgrads[i];
1637                           double dx = (ppsubwin->axes.xgrads[i+1] - ppsubwin->axes.xgrads[i]) / nbsubtics;
1638                           
1639                           for (j=1;j<nbsubtics;j++)
1640                             {  
1641                               vxx1=xtmp2+dx*j;
1642                               
1643                               if(vxx1<xminval || vxx1>xmaxval) continue;
1644                               
1645                               if(ppsubwin->axes.reverse[0] == TRUE)
1646                                 vxx1 = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],vxx1);
1647                               
1648                               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&vxx1,&fy,&fz);
1649
1650                               if (IsDownAxes(psubwin))
1651                                 {
1652                                   vx[1]=vx[0]=xm;
1653                                   vy[0]=ym;
1654                                   vy[1]=vy[0]+iof/4;
1655                                 }
1656                               else
1657                                 {
1658                                   vx[0]=xm;vy[0]=ym;
1659                                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
1660                                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
1661                                 }
1662                           
1663                               if(ppsubwin->axes.axes_visible[0] == TRUE)
1664                                 C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1665                             }
1666                         }
1667                     }
1668                 
1669                   /***************************************************************/
1670                   /************************* END OF COMMON PART ******************/
1671                   /***************************************************************/
1672                   
1673                 }
1674             }
1675         }
1676       if ( sciGetVisibility(ppsubwin->mon_x_label) )
1677       {
1678         sciLabel * ppLabel = pLABEL_FEATURE( ppsubwin->mon_x_label ) ;
1679         if( ppLabel->auto_rotation )
1680         {
1681           sciSetFontOrientation(ppsubwin->mon_x_label, 0) ;
1682         }
1683         
1684           
1685         if( ppLabel->auto_position )
1686         {
1687
1688           int segmentStart[2] = { ixbox[4], iybox[4] } ;
1689           int segmentEnd[2]   = { ixbox[5], iybox[5] } ;
1690           
1691           /* add the bar size and ticks label size to the offset */
1692           int offset[2] = { constOffset[0] + maxTicksLabelSize[0] + abs( barlengthx ), 
1693                             constOffset[1] + maxTicksLabelSize[1] + abs( barlengthy )  } ;
1694           computeLabelAutoPos( ppsubwin->mon_x_label, segmentStart, segmentEnd, offset ) ;
1695         }
1696         /* a trick to force the display with 2d scale */
1697         drawTextEntity( ppLabel->text ) ;
1698         
1699       }
1700     }
1701   else
1702     {
1703       
1704       if ( pSUBWIN_FEATURE (psubwin)->project[1]==1) /* y is HERE */
1705         {
1706           double fx,fy,fz; 
1707           char c_format[5];
1708       
1709           integer Ticsdir[2];
1710           Ticsdir[0]=ixbox[4]-ixbox[3];
1711           Ticsdir[1]=iybox[4]-iybox[3];
1712           BBoxToval(&fx,&fy,&fz,xind[4],bbox);
1713           
1714           x=inint((ixbox[4]+ixbox[5])/2+1.5*rect[2] +iof);
1715           y=inint(((2/3.0)*iybox[4]+(1/3.0)*iybox[5])+1.5*rect[3]+iof);
1716
1717           if(ppsubwin->axes.auto_ticks[1] == FALSE)
1718             {
1719               /* we display the y tics specified by the user*/
1720               nbtics = ppsubwin->axes.u_nygrads;
1721               nbsubtics = ppsubwin->axes.nbsubtics[1];
1722
1723               maxTicksLabelSize[0] = 0 ;
1724               maxTicksLabelSize[1] = 0 ;
1725               
1726               for(i=0;i<nbtics;i++)
1727                 {
1728                   char *foo = ppsubwin->axes.u_ylabels[i]; 
1729                   double ytmp = ppsubwin->axes.u_ygrads[i];
1730                   
1731                   if(ytmp<yminval || ytmp>ymaxval) 
1732                     {
1733                       /*   sciprint("je rejete la valeur: %lf\n\n",xtmp); */
1734                       continue; /* cas ou TL est ON et on a des graduations qui ne seront pas affichees de tte facon */
1735                       /* donc autant ne pas aller plus loin dans l'algo... */
1736                     }
1737                   
1738
1739                   /***************************************************************/
1740                   /************************* COMMON PART *************************/
1741                   /***************************************************************/
1742                   
1743                   if(ppsubwin->axes.reverse[1] == TRUE)
1744                     ytmp = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],ytmp);
1745   
1746                   ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&ytmp,&fz);
1747                   /*              trans3d(psubwin,1,&xm,&ym,&fx,&ytmp,&fz); */
1748                   
1749
1750
1751                   vx[0]=xm;vy[0]=ym;
1752
1753                   barlengthx= (integer) (( Ticsdir[0])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
1754                   barlengthy= (integer) (( Ticsdir[1])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
1755                   /*    NumberFormat(foo,((integer) (yy[0] + i*ceil((yy[1]-yy[0])/yy[3]))), */
1756                   /*                         ((integer) yy[2])); */
1757                   C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); /* fix bug noticed by R.N. */
1758
1759                   /* get the size of the ticks */
1760                   C2F(dr)("xstringl",foo,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1761                   maxTicksLabelSize[0] = Max( maxTicksLabelSize[0], rect[2] ) ;
1762                   maxTicksLabelSize[1] = Max( maxTicksLabelSize[1], rect[3] ) ;
1763                   
1764
1765                   if (IsDownAxes(psubwin)){
1766                     vx[1]=vx[0];
1767                     vy[1]=vy[0]+iof/2;
1768                     posi[0] = inint(xm-rect[2]/2); 
1769                     posi[1]=inint( vy[0] + iof + rect[3]);}
1770                   else{ 
1771                     vx[1]=vx[0]+barlengthx;
1772                     vy[1]=vy[0]+barlengthy;
1773 /*                  posi[0] = inint( xm+2*barlengthx - rect[2]/2); */
1774 /*                  posi[0] = inint( xm+2*barlengthx - rect[2]); */
1775                     posi[0] = inint( xm+2*barlengthx);
1776                     posi[1]=inint( ym + 2*barlengthy + rect[3]);}
1777
1778                   if(ppsubwin->axes.axes_visible[1] == TRUE){
1779                     C2F(dr)("xset","pattern",&textcolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1780                     C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1781                     C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&ang, PD0,PD0,PD0,0L,0L);
1782                     C2F(dr)("xset","pattern",&ticscolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
1783                     C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1784                   }
1785                   /* grid to put here */
1786                   if ( ppsubwin->grid[1] > -1 && ppsubwin->axes.axes_visible[1] )
1787                     {
1788                       gstyle = pSUBWIN_FEATURE (psubwin)->grid[1];
1789
1790                       if((ppsubwin->logflags[1] =='l') && (i != nbtics-1))
1791                         {
1792                           double tmp[2];
1793                           double pas=0;
1794                           double * tmp_log_grads = (double *) NULL;
1795                           
1796                           
1797                           double * grads = ppsubwin->axes.u_ygrads;
1798
1799                           tmp[0] = exp10(grads[i]);
1800                           tmp[1] = exp10(grads[i+1]);
1801                           pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
1802                           
1803                           if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
1804                             sciprint("Error allocating tmp_log_grads\n");
1805                             return -1;
1806                           }
1807                           
1808                           for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
1809                           
1810                           for(j=0;j<nbsubtics;j++)
1811                             {
1812                               vyy1 = tmp_log_grads[j];
1813                               
1814                               if(vyy1<=yminval || vyy1>=ymaxval) continue;
1815                               
1816                               if(ppsubwin->axes.reverse[1] == TRUE)
1817                                 vyy1 = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],vyy1);
1818                               
1819                               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&vyy1,&fz);
1820
1821                               /*  if ((xm != ixbox[5]) && (xm != ixbox[4])) */
1822                               /*                                {  */
1823                               xg[0]= xm;  yg[0]= ym;  
1824                               if (Ishidden(psubwin))
1825                                 { xg[1]= xm; yg[1]= iybox[2] -iybox[3]+ym; }
1826                               else
1827                                 {xg[1]= ixbox[3] - ixbox[4] +xm; yg[1]= iybox[3] - iybox[4] +ym; } 
1828                               C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1829                               C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1830                               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1831                               xg[0]= xg[1]; yg[0]= yg[1];
1832                               xg[1] = ixbox[3] - ixbox[4] +xm; 
1833                               yg[1]=  iybox[2] - iybox[4] +ym;
1834                               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1835                               C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
1836                               /*        } */
1837                             }
1838                           FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
1839                         }
1840                       else
1841                         {
1842                           if(ytmp>yminval && ytmp<ymaxval) 
1843                             {
1844                               xg[0]= xm;  yg[0]= ym;  
1845                               if (Ishidden(psubwin))
1846                                 { xg[1]= xm; yg[1]= iybox[2] -iybox[3]+ym; }
1847                               else
1848                                 {xg[1]= ixbox[3] - ixbox[4] +xm; yg[1]= iybox[3] - iybox[4] +ym; } 
1849                               C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1850                               C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1851                               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1852                               xg[0]= xg[1]; yg[0]= yg[1];
1853                               xg[1] = ixbox[3] - ixbox[4] +xm; 
1854                               yg[1]=  iybox[2] - iybox[4] +ym;
1855                               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1856                               C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
1857                             }
1858                         }
1859                     }
1860
1861                   /* and subtics */
1862                   if(i != nbtics-1)
1863                     {
1864                       if(ppsubwin->logflags[1] =='l')
1865                         {
1866                           double tmp[2];
1867                           double pas=0;
1868                           double * tmp_log_grads = (double *) NULL;
1869                           
1870                           
1871                           double * grads = ppsubwin->axes.u_ygrads;
1872                           
1873                           tmp[0] = exp10(grads[i]);
1874                           tmp[1] = exp10(grads[i+1]);
1875                           pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
1876                           
1877                           if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
1878                             sciprint("Error allocating tmp_log_grads\n");
1879                             return -1;
1880                           }
1881                           
1882                           for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
1883                           
1884                           for(j=0;j<nbsubtics;j++)
1885                             {
1886                               vyy1 = tmp_log_grads[j];
1887                               
1888                               if(vyy1<yminval || vyy1>ymaxval) continue;
1889                               
1890                               if(ppsubwin->axes.reverse[1] == TRUE)
1891                                 vyy1 = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],vyy1);
1892                               
1893                               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&vyy1,&fz);
1894                               
1895                               if (IsDownAxes(psubwin))
1896                                 {
1897                                   vx[1]=vx[0]=xm;
1898                                   vy[0]=ym;
1899                                   vy[1]=vy[0]+iof/4;
1900                                 }
1901                               else
1902                                 {
1903                                   vx[0]=xm;vy[0]=ym;
1904                                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
1905                                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
1906                                 }
1907                               
1908                               if(ppsubwin->axes.axes_visible[1] == TRUE)
1909                                 C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1910                             }
1911                           FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
1912                           
1913                         } /* end NEW */
1914                       else
1915                         {
1916                           double ytmp2 = ppsubwin->axes.u_ygrads[i];
1917                           double dy = (ppsubwin->axes.u_ygrads[i+1] - ppsubwin->axes.u_ygrads[i]) / nbsubtics;
1918                           for(j=0;j<nbsubtics;j++)
1919                             {
1920                               vyy1=ytmp2+dy*j;
1921                               
1922                               if(vyy1<yminval || vyy1>ymaxval) continue;
1923                               
1924                               if(ppsubwin->axes.reverse[1] == TRUE)
1925                                 vyy1 = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],vyy1);
1926                               
1927                               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&vyy1,&fz);
1928                                                       
1929                               if (IsDownAxes(psubwin))
1930                                 {
1931                                   vx[1]=vx[0]=xm;
1932                                   vy[0]=ym;
1933                                   vy[1]=vy[0]+iof/4;
1934                                 }
1935                               else
1936                                 {
1937                                   vx[0]=xm;vy[0]=ym;
1938                                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
1939                                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
1940                                 }
1941                               
1942                               if(ppsubwin->axes.axes_visible[1] == TRUE)
1943                                 C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1944                             }
1945                         }
1946                     }
1947                   
1948                   /***************************************************************/
1949                   /************************* END OF COMMON PART ******************/
1950                   /***************************************************************/
1951                 }
1952             }
1953           else /* we display the computed tics */
1954             {
1955               AdaptGraduationsOnYBottomRight(iof,x,y,size,Ticsdir,fontid,psubwin,yminval,ymaxval,fx,0.,fz);
1956
1957               lastyindex = ppsubwin->axes.nygrads - 1;
1958               
1959               if(lastyindex == 0)
1960                 ChooseFormatForOneGrad(c_format,&(ppsubwin->axes.ygrads[0]));
1961               else
1962                 ChoixFormatE(c_format,
1963                              ppsubwin->axes.ygrads[0],
1964                              ppsubwin->axes.ygrads[lastyindex],
1965                              ((ppsubwin->axes.ygrads[lastyindex])-(ppsubwin->axes.ygrads[0]))/(lastyindex));
1966               
1967               nbtics = ppsubwin->axes.nygrads;
1968               nbsubtics = ppsubwin->axes.nbsubtics[1];
1969              
1970               maxTicksLabelSize[0] = 0 ;
1971               maxTicksLabelSize[1] = 0 ;
1972  
1973               for(i=0;i<nbtics;i++)
1974                 {
1975                   char foo[256]; 
1976                   double ytmp2 = ppsubwin->axes.ygrads[i];
1977               
1978                   if(ytmp2<yminval || ytmp2>ymaxval) 
1979                     {
1980                       /*   sciprint("je rejete la valeur: %lf\n\n",xtmp); */
1981                       continue; /* cas ou TL est ON et on a des graduations qui ne seront pas affichees de tte facon */
1982                       /* donc autant ne pas aller plus loin dans l'algo... */
1983                     }
1984               
1985                   sprintf(foo,c_format,ytmp2);
1986
1987                   /***************************************************************/
1988                   /************************* COMMON PART *************************/
1989                   /***************************************************************/
1990
1991                   /* F.Leray 03.11.04 Test if log scale to perform a : exp10(x) because trans3d will */
1992                   /* re-do a log10() (that is needed for data computations) */
1993
1994
1995                   if(ppsubwin->axes.reverse[1] == TRUE)
1996                     ytmp2 = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],ytmp2);
1997                   
1998                   ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&ytmp2,&fz);
1999                   
2000                   
2001                   vx[0]=xm;vy[0]=ym;
2002               
2003                   barlengthx= (integer) (( Ticsdir[0])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
2004                   barlengthy= (integer) (( Ticsdir[1])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
2005                     
2006                   C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); /* fix bug noticed by R.N. */
2007                   
2008                   
2009                   C2F(dr)("xstringl",foo,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2010                   maxTicksLabelSize[0] = Max( maxTicksLabelSize[0], rect[2] ) ;
2011                   maxTicksLabelSize[1] = Max( maxTicksLabelSize[1], rect[3] ) ;
2012
2013                   if (IsDownAxes(psubwin)){
2014                     vx[1]=vx[0];
2015                     vy[1]=vy[0]+iof/2;
2016                     posi[0] = inint(xm-rect[2]/2); 
2017                     posi[1]=inint( vy[0] + iof + rect[3]);}
2018                   else{ 
2019                     vx[1]=vx[0]+barlengthx;
2020                     vy[1]=vy[0]+barlengthy;
2021 /*                  posi[0] = inint( xm+2*barlengthx - rect[2]/2); */
2022 /*                  posi[0] = inint( xm+2*barlengthx - rect[2]); */
2023                     posi[0] = inint( xm+2*barlengthx);
2024                     posi[1]=inint( ym + 2*barlengthy + rect[3]);}
2025                   
2026                   if(ppsubwin->axes.axes_visible[1] == TRUE){
2027                     C2F(dr)("xset","pattern",&textcolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2028                     C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2029                     if ( ppsubwin->logflags[1] == 'l' )
2030                       {
2031                         int smallersize = fontid[1]-2;
2032                         int old_rect10[4];
2033                         /*                  char str[2] = "xv"; */
2034                         int posi10[2];
2035                         
2036                         posi10[0] = posi[0] - logrect[2];
2037                         posi10[1] = posi[1] + logrect[3];
2038                         
2039                         C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2040                         C2F(dr)("xstring","10",(&posi10[0]),(&posi10[1]),PI0,&flag,PI0,PI0,&angle,PD0,PD0,PD0,0L,0L);
2041                         
2042                         C2F(dr)("xstringl","10",(&posi10[0]),(&posi10[1]),old_rect10,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2043                         
2044                         posi[0] = old_rect10[0] + old_rect10[2];
2045                         posi[1] = (int) (old_rect10[1] - old_rect10[3]*.1);
2046                         
2047                         C2F(dr)("xset","font",fontid,&smallersize,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2048                         C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&ang, PD0,PD0,PD0,0L,0L);
2049                         
2050                         /* put back the current fontid */
2051                         C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2052                       }
2053                     else
2054                       C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&ang, PD0,PD0,PD0,0L,0L);
2055                     
2056                     C2F(dr)("xset","pattern",&ticscolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
2057                     C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2058                   }
2059                   
2060                   /* grid to put here */
2061                   
2062                   if ( ppsubwin->grid[1] > -1 && ppsubwin->axes.axes_visible[1] )
2063                     {
2064                       gstyle = pSUBWIN_FEATURE (psubwin)->grid[1];
2065
2066                       if((ppsubwin->logflags[1] =='l') && (i != nbtics-1))
2067                         {
2068                           double tmp[2];
2069                           double pas=0;
2070                           double * tmp_log_grads = (double *) NULL;
2071                           
2072                           
2073                           double * grads = ppsubwin->axes.ygrads;
2074
2075                           tmp[0] = exp10(grads[i]);
2076                           tmp[1] = exp10(grads[i+1]);
2077                           pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
2078                           
2079                           if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
2080                             sciprint("Error allocating tmp_log_grads\n");
2081                             return -1;
2082                           }
2083                           
2084                           for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
2085                           
2086                           for(j=0;j<nbsubtics;j++)
2087                             {
2088                               vyy1 = tmp_log_grads[j];
2089                               
2090                               if(vyy1<=yminval || vyy1>=ymaxval) continue;
2091                               
2092                               if(ppsubwin->axes.reverse[1] == TRUE)
2093                                 vyy1 = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],vyy1);
2094                               
2095                               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&vyy1,&fz);
2096                               
2097                               /*  if ((xm != ixbox[5]) && (xm != ixbox[4])) */
2098                               /*                                {  */
2099                               xg[0]= xm;  yg[0]= ym;  
2100                               if (Ishidden(psubwin))
2101                                 { xg[1]= xm; yg[1]= iybox[2] -iybox[3]+ym; }
2102                               else
2103                                 {xg[1]= ixbox[3] - ixbox[4] +xm; yg[1]= iybox[3] - iybox[4] +ym; } 
2104                               C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2105                               C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2106                               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2107                               xg[0]= xg[1]; yg[0]= yg[1];
2108                               xg[1] = ixbox[3] - ixbox[4] +xm; 
2109                               yg[1]=  iybox[2] - iybox[4] +ym;
2110                               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2111                               C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
2112                               /*        } */
2113                             }
2114                           FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
2115                         }
2116                       else
2117                         {
2118                           if(ytmp2>yminval && ytmp2<ymaxval) 
2119                             {
2120                               xg[0]= xm;  yg[0]= ym;  
2121                               if (Ishidden(psubwin))
2122                                 { xg[1]= xm; yg[1]= iybox[2] -iybox[3]+ym; }
2123                               else
2124                                 {xg[1]= ixbox[3] - ixbox[4] +xm; yg[1]= iybox[3] - iybox[4] +ym; } 
2125                               C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2126                               C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2127                               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2128                               xg[0]= xg[1]; yg[0]= yg[1];
2129                               xg[1] = ixbox[3] - ixbox[4] +xm; 
2130                               yg[1]=  iybox[2] - iybox[4] +ym;
2131                               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2132                               C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
2133                             }
2134                         }
2135                     }
2136
2137                   /* and subtics */
2138                   if(i != nbtics-1)
2139                     {
2140                       if(ppsubwin->logflags[1] =='l')
2141                         {
2142                           double tmp[2];
2143                           double pas=0;
2144                           double * tmp_log_grads = (double *) NULL;
2145                           
2146                           
2147                           double * grads = ppsubwin->axes.ygrads;
2148                           
2149                           tmp[0] = exp10(grads[i]);
2150                           tmp[1] = exp10(grads[i+1]);
2151                           pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
2152                           
2153                           if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
2154                             sciprint("Error allocating tmp_log_grads\n");
2155                             return -1;
2156                           }
2157                           
2158                           for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
2159                           
2160                           for(j=0;j<nbsubtics;j++)
2161                             {
2162                               vyy1 = tmp_log_grads[j];
2163                               
2164                               if(vyy1<yminval || vyy1>ymaxval) continue;
2165                               
2166                               if(ppsubwin->axes.reverse[1] == TRUE)
2167                                 vyy1 = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],vyy1);
2168                               
2169                               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&vyy1,&fz);
2170                               
2171                               if (IsDownAxes(psubwin))
2172                                 {
2173                                   vx[1]=vx[0]=xm;
2174                                   vy[0]=ym;
2175                                   vy[1]=vy[0]+iof/4;
2176                                 }
2177                               else
2178                                 {
2179                                   vx[0]=xm;vy[0]=ym;
2180                                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
2181                                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
2182                                 }
2183                               
2184                               if(ppsubwin->axes.axes_visible[1] == TRUE)
2185                                 C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2186                             }
2187                           FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
2188                           
2189                         } /* end NEW */
2190                       else
2191                         {
2192                           double ytmp3 = ppsubwin->axes.ygrads[i];
2193                           double dy = (ppsubwin->axes.ygrads[i+1] - ppsubwin->axes.ygrads[i]) / nbsubtics;
2194                           for(j=0;j<nbsubtics;j++)
2195                             {
2196                               vyy1=ytmp3+dy*j;
2197                           
2198                               if(vyy1<yminval || vyy1>ymaxval) continue;
2199                               
2200                               if(ppsubwin->axes.reverse[1] == TRUE)
2201                                 vyy1 = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],vyy1);
2202                               
2203                               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&vyy1,&fz);
2204                               /*   trans3d(psubwin,1,&xm,&ym,&fx,&vyy1,&fz); */
2205                           
2206                               if (IsDownAxes(psubwin))
2207                                 {
2208                                   vx[1]=vx[0]=xm;
2209                                   vy[0]=ym;
2210                                   vy[1]=vy[0]+iof/4;
2211                                 }
2212                               else
2213                                 {
2214                                   vx[0]=xm;vy[0]=ym;
2215                                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
2216                                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
2217                                 }
2218
2219                               if(ppsubwin->axes.axes_visible[1] == TRUE)
2220                                 C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2221                             }
2222                         }
2223                     }
2224                   /***************************************************************/
2225                   /************************* END OF COMMON PART ******************/
2226                   /***************************************************************/
2227               
2228                 }
2229             }
2230         }
2231       if ( sciGetVisibility(ppsubwin->mon_y_label) )
2232       {
2233         sciLabel * ppLabel = pLABEL_FEATURE( ppsubwin->mon_y_label ) ;
2234         if( ppLabel->auto_rotation )
2235         {
2236           sciSetFontOrientation( ppsubwin->mon_y_label, 0 ) ;
2237         }
2238           
2239         if( ppLabel->auto_position )
2240         {
2241             
2242           int segmentStart[2] = { ixbox[4], iybox[4] } ;
2243           int segmentEnd[2]   = { ixbox[5], iybox[5] } ;
2244             
2245           /* add the bar size and ticks label size to the offset */
2246           int offset[2] = { constOffset[0] + maxTicksLabelSize[0] + abs( barlengthx ), 
2247                             constOffset[1] + maxTicksLabelSize[1] + abs( barlengthy )  } ;
2248           computeLabelAutoPos( ppsubwin->mon_y_label, segmentStart, segmentEnd, offset ) ;
2249         }
2250         /* a trick to force the display with 2d scale */
2251         drawTextEntity( ppLabel->text ) ;
2252         
2253       }
2254     }
2255   
2256   
2257   
2258   /***********************/ /** bottom left side ***/
2259   /*** le  x-y scaling ***/ /* DISPLAY x or y graduations */
2260   /***********************/
2261   
2262   if (( xind[3]+xind[4] == 3) || ( xind[3]+xind[4] == 11))
2263     {
2264       if (pSUBWIN_FEATURE (psubwin)->project[0]==1) /* x HERE */
2265         {
2266           double fx,fy,fz;
2267           char c_format[5];
2268
2269           
2270           integer Ticsdir[2];
2271           Ticsdir[0]=ixbox[4]-ixbox[5];
2272           Ticsdir[1]=iybox[4]-iybox[5];
2273           BBoxToval(&fx,&fy,&fz,xind[3],bbox);
2274
2275           x=inint((ixbox[3]+ixbox[4])/2.0 -rect[2] -iof);
2276           y=inint((1/3.0)*iybox[3]+(2/3.0)*iybox[4]+ iof+ 1.5*rect[3]); 
2277           
2278           if(ppsubwin->axes.auto_ticks[0] == FALSE)
2279             {
2280               /* we display the x tics specified by the user*/
2281               nbtics = ppsubwin->axes.u_nxgrads;
2282               nbsubtics = ppsubwin->axes.nbsubtics[0];
2283               
2284               maxTicksLabelSize[0] = 0 ;
2285               maxTicksLabelSize[1] = 0 ;
2286
2287               for(i=0;i<nbtics;i++)
2288                 {
2289                   char *foo = ppsubwin->axes.u_xlabels[i]; 
2290                   double xtmp = ppsubwin->axes.u_xgrads[i];
2291                   
2292                   if(xtmp<xminval || xtmp>xmaxval) 
2293                     {
2294                       /*   sciprint("je rejete la valeur: %lf\n\n",xtmp); */
2295                       continue; /* cas ou TL est ON et on a des graduations qui ne seront pas affichees de tte facon */
2296                       /* donc autant ne pas aller plus loin dans l'algo... */
2297                     }
2298                   
2299                   /***************************************************************/
2300                   /************************* COMMON PART *************************/
2301                   /***************************************************************/
2302
2303                   if(ppsubwin->axes.reverse[0] == TRUE)
2304                     xtmp = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],xtmp);
2305                   
2306                   ComputeGoodTrans3d(psubwin,1,&xm,&ym,&xtmp,&fy,&fz);
2307                   /*              trans3d(psubwin,1,&xm,&ym,&xtmp,&fy,&fz); */
2308
2309
2310                   vx[0]=xm;vy[0]=ym;
2311
2312                   barlengthx= (integer) (( Ticsdir[0])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
2313                   barlengthy= (integer) (( Ticsdir[1])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
2314                 
2315                   C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); /* fix bug noticed by R.N. */
2316                   
2317                   C2F(dr)("xstringl",foo,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2318                   maxTicksLabelSize[0] = Max( maxTicksLabelSize[0], rect[2] ) ;
2319                   maxTicksLabelSize[1] = Max( maxTicksLabelSize[1], rect[3] ) ;
2320                   
2321
2322                   if (IsDownAxes(psubwin)){
2323                     vx[1]=vx[0];
2324                     vy[1]=vy[0]+iof/2;
2325                     posi[0] = inint(xm-rect[2]/2); 
2326                     posi[1]=inint( vy[0] + iof + rect[3]);}
2327                   else{
2328                     vx[1]=vx[0]+barlengthx;
2329                     vy[1]=vy[0]+barlengthy;
2330                     posi[0] = inint( xm+2*barlengthx-rect[2]); 
2331                     posi[1]=inint( ym + 2*barlengthy + rect[3]);}
2332
2333                   if(ppsubwin->axes.axes_visible[0] == TRUE){
2334                     C2F(dr)("xset","pattern",&textcolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2335                     C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2336                     C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&ang, PD0,PD0,PD0,0L,0L);
2337                     C2F(dr)("xset","pattern",&ticscolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);   
2338                     C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2339                   }
2340                   /* grid to put here */
2341                   if ( ppsubwin->grid[0] > -1 && ppsubwin->axes.axes_visible[0]  )
2342                     {
2343                       gstyle = pSUBWIN_FEATURE (psubwin)->grid[0];
2344
2345                       if((ppsubwin->logflags[0] =='l') && (i != nbtics-1))
2346                         {
2347                           double tmp[2];
2348                           double pas=0;
2349                           double * tmp_log_grads = (double *) NULL;
2350                           
2351                           
2352                           double * grads = ppsubwin->axes.u_xgrads;
2353                           
2354                           tmp[0] = exp10(grads[i]);
2355                           tmp[1] = exp10(grads[i+1]);
2356                           pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
2357                           
2358                           if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
2359                             sciprint("Error allocating tmp_log_grads\n");
2360                             return -1;
2361                           }
2362                           
2363                           for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
2364                           
2365                           for(j=0;j<nbsubtics;j++)
2366                             {
2367                               vxx1 = tmp_log_grads[j];
2368                               
2369                               if(vxx1<=xminval || vxx1>=xmaxval) continue;
2370
2371                               if(ppsubwin->axes.reverse[0] == TRUE)
2372                                 vxx1 = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],vxx1);
2373                               
2374                               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&vxx1,&fy,&fz);
2375
2376                               /*   if ((xm != ixbox[3]) && (xm != ixbox[4])) */
2377                               /*                                {  */
2378                               xg[0]= xm;  yg[0]= ym;  
2379                               if (Ishidden(psubwin))
2380                                 { xg[1]= xm; yg[1]= iybox[0] -iybox[5]+ym; }
2381                               else
2382                                 {xg[1]= ixbox[1] - ixbox[3] +xm; yg[1]= iybox[5] - iybox[4] +ym; } 
2383                               C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2384                               C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2385                               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2386                               xg[0]= xg[1]; yg[0]= yg[1];
2387                               xg[1] = ixbox[1] - ixbox[3] +xm; yg[1]=  iybox[0] - iybox[4] +ym;
2388                               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2389                               C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
2390                               /*        } */
2391                             }
2392                           FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
2393                         }
2394                       else
2395                         {
2396                           if(xtmp>xminval && xtmp<xmaxval) 
2397                             {
2398                               xg[0]= xm;  yg[0]= ym;  
2399                               if (Ishidden(psubwin))
2400                                 { xg[1]= xm; yg[1]= iybox[0] -iybox[5]+ym; }
2401                               else
2402                                 {xg[1]= ixbox[1] - ixbox[3] +xm; yg[1]= iybox[5] - iybox[4] +ym; } 
2403                               C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2404                               C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2405                               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2406                               xg[0]= xg[1]; yg[0]= yg[1];
2407                               xg[1] = ixbox[1] - ixbox[3] +xm; yg[1]=  iybox[0] - iybox[4] +ym;
2408                               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2409                               C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
2410                             }
2411                         }
2412                     }
2413
2414                   /* and subtics */
2415                   if(i != nbtics-1)
2416                     {
2417                       if(ppsubwin->logflags[0] =='l')
2418                         {
2419                           double tmp[2];
2420                           double pas=0;
2421                           double * tmp_log_grads = (double *) NULL;
2422                           
2423                           
2424                           double * grads = ppsubwin->axes.u_xgrads;
2425                           
2426                           tmp[0] = exp10(grads[i]);
2427                           tmp[1] = exp10(grads[i+1]);
2428                           pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
2429                           
2430                           if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
2431                             sciprint("Error allocating tmp_log_grads\n");
2432                             return -1;
2433                           }
2434                           
2435                           for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
2436                           
2437                           for(j=0;j<nbsubtics;j++)
2438                             {
2439                               vxx1 = tmp_log_grads[j];
2440                               
2441                               if(vxx1<xminval || vxx1>xmaxval) continue;
2442                               
2443                               if(ppsubwin->axes.reverse[0] == TRUE)
2444                                 vxx1 = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],vxx1);
2445                               
2446                               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&vxx1,&fy,&fz);
2447                               
2448                               if (IsDownAxes(psubwin))
2449                                 {
2450                                   vx[1]=vx[0]=xm;
2451                                   vy[0]=ym;
2452                                   vy[1]=vy[0]+iof/4;
2453                                 }
2454                               else
2455                                 {
2456                                   vx[0]=xm;vy[0]=ym;
2457                                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
2458                                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
2459                                 }
2460                               
2461                               if(ppsubwin->axes.axes_visible[0] == TRUE)
2462                                 C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2463                             }
2464
2465                           FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
2466                         } /* end NEW */
2467                       else
2468                         {
2469                           double xtmp2 = ppsubwin->axes.u_xgrads[i];
2470                           double dx = (ppsubwin->axes.u_xgrads[i+1] - ppsubwin->axes.u_xgrads[i]) / nbsubtics;
2471                           
2472                           for (j=1;j<nbsubtics;j++)
2473                             {  
2474                               vxx1=xtmp2+dx*j;
2475                               
2476                               if(vxx1<xminval || vxx1>xmaxval) continue;
2477
2478                               if(ppsubwin->axes.reverse[0] == TRUE)
2479                                 vxx1 = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],vxx1);
2480                               
2481                               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&vxx1,&fy,&fz);
2482                               /*                  trans3d(psubwin,1,&xm,&ym,&vxx1,&fy,&fz); */
2483
2484
2485                               if (IsDownAxes(psubwin))
2486                                 {
2487                                   vx[1]=vx[0]=xm;
2488                                   vy[0]=ym;
2489                                   vy[1]=vy[0]+iof/4;
2490                                 }
2491                               else
2492                                 {
2493                                   vx[0]=xm;vy[0]=ym;
2494                                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
2495                                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
2496                                 }
2497
2498                               if(ppsubwin->axes.axes_visible[0] == TRUE)
2499                                 C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2500                             }
2501                         }
2502                     }
2503                   /***************************************************************/
2504                   /************************* COMMON PART *************************/
2505                   /***************************************************************/
2506                   
2507
2508                 }
2509               
2510             }
2511           else /* we display the computed tics */
2512             {
2513               AdaptGraduationsOnXBottomLeft(iof,x,y,size,Ticsdir,fontid,psubwin,xminval,xmaxval,0.,fy,fz);
2514               
2515               lastxindex = ppsubwin->axes.nxgrads - 1;
2516               
2517               if(lastxindex == 0)
2518                 ChooseFormatForOneGrad(c_format,&(ppsubwin->axes.xgrads[0]));
2519               else
2520                 ChoixFormatE(c_format,
2521                              ppsubwin->axes.xgrads[0],
2522                              ppsubwin->axes.xgrads[lastxindex],
2523                              ((ppsubwin->axes.xgrads[lastxindex])-(ppsubwin->axes.xgrads[0]))/(lastxindex));
2524               
2525               nbtics = ppsubwin->axes.nxgrads;
2526               nbsubtics = ppsubwin->axes.nbsubtics[0];
2527
2528               maxTicksLabelSize[0] = 0 ;
2529               maxTicksLabelSize[1] = 0 ;
2530                    
2531               for(i=0;i<nbtics;i++)
2532                 {
2533                   char foo[256]; 
2534                   double xtmp = ppsubwin->axes.xgrads[i];
2535                   
2536                   if(xtmp<xminval || xtmp>xmaxval) 
2537                     {
2538                       /*   sciprint("je rejete la valeur: %lf\n\n",xtmp); */
2539                       continue; /* cas ou TL est ON et on a des graduations qui ne seront pas affichees de tte facon */
2540                       /* donc autant ne pas aller plus loin dans l'algo... */
2541                     }
2542                   
2543                   sprintf(foo,c_format,xtmp);
2544                   
2545                   /***************************************************************/
2546                   /************************* COMMON PART *************************/
2547                   /***************************************************************/
2548
2549                   if(ppsubwin->axes.reverse[0] == TRUE)
2550                     xtmp = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],xtmp);
2551                   
2552                   ComputeGoodTrans3d(psubwin,1,&xm,&ym,&xtmp,&fy,&fz);
2553
2554                   vx[0]=xm;vy[0]=ym;
2555
2556                   barlengthx= (integer) (( Ticsdir[0])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
2557                   barlengthy= (integer) (( Ticsdir[1])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
2558                      
2559                   C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); /* fix bug noticed by R.N. */
2560                   
2561                   C2F(dr)("xstringl",foo,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2562                   maxTicksLabelSize[0] = Max( maxTicksLabelSize[0], rect[2] ) ;
2563                   maxTicksLabelSize[1] = Max( maxTicksLabelSize[1], rect[3] ) ;
2564
2565                   if (IsDownAxes(psubwin)){
2566                     vx[1]=vx[0];
2567                     vy[1]=vy[0]+iof/2;
2568                     posi[0] = inint(xm-rect[2]/2); 
2569                     posi[1]=inint( vy[0] + iof + rect[3]);}
2570                   else{
2571                     vx[1]=vx[0]+barlengthx;
2572                     vy[1]=vy[0]+barlengthy;
2573                     posi[0] = inint( xm+2*barlengthx-rect[2]); 
2574                     posi[1]=inint( ym + 2*barlengthy + rect[3]);}
2575
2576                   if(ppsubwin->axes.axes_visible[0] == TRUE){
2577                     C2F(dr)("xset","pattern",&textcolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2578                     C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2579                     if ( ppsubwin->logflags[0] == 'l' )
2580                       {
2581                         int smallersize = fontid[1]-2;
2582                         int old_rect10[4];
2583                         int posi10[2];
2584                         
2585                         posi10[0] = posi[0] - logrect[2];
2586                         posi10[1] = posi[1] + logrect[3];
2587                         
2588                         C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2589                         C2F(dr)("xstring","10",(&posi10[0]),(&posi10[1]),PI0,&flag,PI0,PI0,&angle,PD0,PD0,PD0,0L,0L);
2590                         
2591                         C2F(dr)("xstringl","10",(&posi10[0]),(&posi10[1]),old_rect10,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2592                         
2593                         posi[0] = old_rect10[0] + old_rect10[2];
2594                         posi[1] = (int) (old_rect10[1] - old_rect10[3]*.1);
2595                         
2596                         C2F(dr)("xset","font",fontid,&smallersize,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2597                         C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&ang, PD0,PD0,PD0,0L,0L);
2598                         
2599                         /* put back the current fontid */
2600                         C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2601                       }
2602                     else
2603                       C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&ang, PD0,PD0,PD0,0L,0L);
2604
2605                     C2F(dr)("xset","pattern",&ticscolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);   
2606                     C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2607                   }
2608                   /* grid to put here */
2609                   if ( ppsubwin->grid[0] > -1 && ppsubwin->axes.axes_visible[0] )
2610                     {
2611                       gstyle = pSUBWIN_FEATURE (psubwin)->grid[0];
2612                       
2613                       if((ppsubwin->logflags[0] =='l') && (i != nbtics-1))
2614                         {
2615                           double tmp[2];
2616                           double pas=0;
2617                           double * tmp_log_grads = (double *) NULL;
2618                           
2619                           
2620                           double * grads = ppsubwin->axes.xgrads;
2621                           
2622                           tmp[0] = exp10(grads[i]);
2623                           tmp[1] = exp10(grads[i+1]);
2624                           pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
2625                           
2626                           if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
2627                             sciprint("Error allocating tmp_log_grads\n");
2628                             return -1;
2629                           }
2630                           
2631                           for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
2632                           
2633                           for(j=0;j<nbsubtics;j++)
2634                             {
2635                               vxx1 = tmp_log_grads[j];
2636                               
2637                               if(vxx1<=xminval || vxx1>=xmaxval) continue;
2638                               
2639                               if(ppsubwin->axes.reverse[0] == TRUE)
2640                                 vxx1 = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],vxx1);
2641                               
2642                               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&vxx1,&fy,&fz);
2643                               
2644                                                       
2645                               xg[0]= xm;  yg[0]= ym;  
2646                               if (Ishidden(psubwin))
2647                                 { xg[1]= xm; yg[1]= iybox[0] -iybox[5]+ym; }
2648                               else
2649                                 {xg[1]= ixbox[1] - ixbox[3] +xm; yg[1]= iybox[5] - iybox[4] +ym; } 
2650                               C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2651                               C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2652                               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2653                               xg[0]= xg[1]; yg[0]= yg[1];
2654                               xg[1] = ixbox[1] - ixbox[3] +xm; yg[1]=  iybox[0] - iybox[4] +ym;
2655                               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2656                               C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
2657                               
2658                             }
2659                           FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
2660                         }
2661                       else
2662                         {
2663                           if(xtmp>xminval && xtmp<xmaxval) 
2664                             {
2665                               xg[0]= xm;  yg[0]= ym;  
2666                               if (Ishidden(psubwin))
2667                                 { xg[1]= xm; yg[1]= iybox[0] -iybox[5]+ym; }
2668                               else
2669                                 {xg[1]= ixbox[1] - ixbox[3] +xm; yg[1]= iybox[5] - iybox[4] +ym; } 
2670                               C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2671                               C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2672                               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2673                               xg[0]= xg[1]; yg[0]= yg[1];
2674                               xg[1] = ixbox[1] - ixbox[3] +xm; yg[1]=  iybox[0] - iybox[4] +ym;
2675                               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2676                               C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
2677                             }
2678                         }
2679                     }
2680                   
2681                   /* and subtics */
2682                   if(i != nbtics-1)
2683                     {
2684                       if(ppsubwin->logflags[0] =='l')
2685                         {
2686                           double tmp[2];
2687                           double pas=0;
2688                           double * tmp_log_grads = (double *) NULL;
2689                           
2690                           
2691                           double * grads = ppsubwin->axes.xgrads;
2692
2693                           tmp[0] = exp10(grads[i]);
2694                           tmp[1] = exp10(grads[i+1]);
2695                           pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
2696                           
2697                           if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
2698                             sciprint("Error allocating tmp_log_grads\n");
2699                             return -1;
2700                           }
2701                           
2702                           for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
2703                           
2704                           for(j=0;j<nbsubtics;j++)
2705                             {
2706                               vxx1 = tmp_log_grads[j];
2707                               
2708                               if(vxx1<xminval || vxx1>xmaxval) continue;
2709                               
2710                               if(ppsubwin->axes.reverse[0] == TRUE)
2711                                 vxx1 = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],vxx1);
2712                               
2713                               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&vxx1,&fy,&fz);
2714                               
2715                               if (IsDownAxes(psubwin))
2716                                 {
2717                                   vx[1]=vx[0]=xm;
2718                                   vy[0]=ym;
2719                                   vy[1]=vy[0]+iof/4;
2720                                 }
2721                               else
2722                                 {
2723                                   vx[0]=xm;vy[0]=ym;
2724                                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
2725                                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
2726                                 }
2727                               
2728                               if(ppsubwin->axes.axes_visible[0] == TRUE)
2729                                 C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2730                             }
2731                           FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
2732                         } /* end NEW */
2733                       else
2734                         {
2735                           double xtmp2 = ppsubwin->axes.xgrads[i];
2736                           double dx = (ppsubwin->axes.xgrads[i+1] - ppsubwin->axes.xgrads[i]) / nbsubtics;
2737                           
2738                           for (j=1;j<nbsubtics;j++)
2739                             {  
2740                               vxx1=xtmp2+dx*j;
2741                               
2742                               if(vxx1<xminval || vxx1>xmaxval) continue;
2743                               
2744                               if(ppsubwin->axes.reverse[0] == TRUE)
2745                                 vxx1 = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],vxx1);
2746                               
2747                               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&vxx1,&fy,&fz);
2748                               /*                  trans3d(psubwin,1,&xm,&ym,&vxx1,&fy,&fz); */
2749                               
2750                               
2751                               if (IsDownAxes(psubwin))
2752                                 {
2753                                   vx[1]=vx[0]=xm;
2754                                   vy[0]=ym;
2755                                   vy[1]=vy[0]+iof/4;
2756                                 }
2757                               else
2758                                 {
2759                                   vx[0]=xm;vy[0]=ym;
2760                                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
2761                                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
2762                                 }
2763                               
2764                               if(ppsubwin->axes.axes_visible[0] == TRUE)
2765                                 C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2766                             }
2767                         }
2768                     }
2769                   /***************************************************************/
2770                   /************************* COMMON PART *************************/
2771                   /***************************************************************/
2772                   
2773                 }
2774             }
2775         }
2776
2777       if ( sciGetVisibility(ppsubwin->mon_x_label) )
2778       { 
2779           
2780           sciLabel * ppLabel = pLABEL_FEATURE(ppsubwin->mon_x_label) ;
2781           if( ppLabel->auto_rotation )
2782           {
2783             sciSetFontOrientation(ppsubwin->mon_x_label, 0 ) ;
2784           }
2785           
2786
2787            if( ppLabel->auto_position )
2788            {
2789              
2790              int segmentStart[2] = { ixbox[3], iybox[3] } ;
2791              int segmentEnd[2]   = { ixbox[4], iybox[4] } ;
2792             
2793              /* add the bar size and ticks label size to the offset */
2794              int offset[2] = { constOffset[0] + maxTicksLabelSize[0] + abs( barlengthx ), 
2795                                constOffset[1] + maxTicksLabelSize[1] + abs( barlengthy )  } ;
2796              computeLabelAutoPos( ppsubwin->mon_x_label, segmentStart, segmentEnd, offset ) ;
2797            }
2798            /* a trick to force the display with 2d scale */
2799            drawTextEntity( ppLabel->text ) ;
2800            
2801         }
2802     }
2803   else 
2804     {
2805       if  (pSUBWIN_FEATURE (psubwin)->project[1]==1) /* y is HERE */
2806         {
2807           double fx,fy,fz;
2808           char c_format[5];
2809
2810           integer Ticsdir[2];
2811           Ticsdir[0]=ixbox[4]-ixbox[5];
2812           Ticsdir[1]=iybox[4]-iybox[5];
2813           BBoxToval(&fx,&fy,&fz,xind[3],bbox);
2814           
2815           x=inint((ixbox[3]+ixbox[4])/2.0 -rect[2] -iof);
2816           y=inint((1/3.0)*iybox[3]+(2/3.0)*iybox[4]+ iof + 1.5*rect[3]);  
2817           
2818           if(ppsubwin->axes.auto_ticks[1] == FALSE)
2819             {
2820               /* we display the y tics specified by the user*/
2821               nbtics = ppsubwin->axes.u_nygrads;
2822               nbsubtics = ppsubwin->axes.nbsubtics[1];
2823               
2824               maxTicksLabelSize[0] = 0 ;
2825               maxTicksLabelSize[1] = 0 ;
2826
2827               for(i=0;i<nbtics;i++)
2828                 {
2829                   char *foo = ppsubwin->axes.u_ylabels[i]; 
2830                   double ytmp = ppsubwin->axes.u_ygrads[i];
2831                   
2832                   if(ytmp<yminval || ytmp>ymaxval) 
2833                     {
2834                       /*   sciprint("je rejete la valeur: %lf\n\n",xtmp); */
2835                       continue; /* cas ou TL est ON et on a des graduations qui ne seront pas affichees de tte facon */
2836                       /* donc autant ne pas aller plus loin dans l'algo... */
2837                     }
2838                   
2839                   /***************************************************************/
2840                   /************************* COMMON PART *************************/
2841                   /***************************************************************/
2842
2843                   if(ppsubwin->axes.reverse[1] == TRUE)
2844                     ytmp = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],ytmp);
2845                   
2846                   ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&ytmp,&fz);
2847                   /*              trans3d(psubwin,1,&xm,&ym,&fx,&ytmp,&fz); */
2848
2849
2850                   vx[0]=xm;vy[0]=ym; 
2851                   
2852                   barlengthx= (integer) (( Ticsdir[0])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
2853                   barlengthy= (integer) (( Ticsdir[1])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
2854                      
2855                   C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); /* fix bug noticed by R.N. */
2856                   
2857                   C2F(dr)("xstringl",foo,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2858                   maxTicksLabelSize[0] = Max( maxTicksLabelSize[0], rect[2] ) ;
2859                   maxTicksLabelSize[1] = Max( maxTicksLabelSize[1], rect[3] ) ;
2860                   
2861                   if (IsDownAxes(psubwin)){
2862                     vx[1]=vx[0];
2863                     vy[1]=vy[0]+iof/2;
2864                     posi[0] = inint(xm-rect[2]/2); 
2865                     posi[1]=inint( vy[0] + iof + rect[3]);}
2866                   else{
2867                     vx[1]=vx[0]+barlengthx;
2868                     vy[1]=vy[0]+barlengthy;
2869 /*                  posi[0] = inint( xm+2*barlengthx-rect[2]/2);  */
2870                     posi[0] = inint( xm+2*barlengthx-rect[2]); 
2871                     posi[1]=inint( ym + 2*barlengthy + rect[3]);}
2872                       
2873
2874                   if(ppsubwin->axes.axes_visible[1] == TRUE){
2875                     C2F(dr)("xset","pattern",&textcolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2876                     C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2877                     C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&ang, PD0,PD0,PD0,0L,0L);
2878                     C2F(dr)("xset","pattern",&ticscolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);   
2879                     C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2880                   }
2881                   /* grid to put here */
2882                   if ( ppsubwin->grid[1] > -1 && ppsubwin->axes.axes_visible[1] )
2883                     {
2884                       gstyle = pSUBWIN_FEATURE (psubwin)->grid[1];
2885                       
2886                       if((ppsubwin->logflags[1] =='l') && (i != nbtics-1))
2887                         {
2888                           double tmp[2];
2889                           double pas=0;
2890                           double * tmp_log_grads = (double *) NULL;
2891                           
2892                           
2893                           double * grads = ppsubwin->axes.u_ygrads;
2894                           
2895                           tmp[0] = exp10(grads[i]);
2896                           tmp[1] = exp10(grads[i+1]);
2897                           pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
2898                           
2899                           if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
2900                             sciprint("Error allocating tmp_log_grads\n");
2901                             return -1;
2902                           }
2903                           
2904                           for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
2905                           
2906                           for(j=0;j<nbsubtics;j++)
2907                             {
2908                               vyy1 = tmp_log_grads[j];
2909                               
2910                               if(vyy1<=yminval || vyy1>=ymaxval) continue;
2911                               
2912                               if(ppsubwin->axes.reverse[1] == TRUE)
2913                                 vyy1 = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],vyy1);
2914                               
2915                               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&vyy1,&fz);
2916                               
2917                               /*   if ((xm != ixbox[3]) && (xm != ixbox[4])) */
2918                               /*                                { */ 
2919                               xg[0]= xm;  yg[0]= ym;  
2920                               if (Ishidden(psubwin))
2921                                 { xg[1]= xm; yg[1]= iybox[0] -iybox[5]+ym; }
2922                               else
2923                                 {xg[1]= ixbox[1] - ixbox[3] +xm; yg[1]= iybox[5] - iybox[4] +ym; } 
2924                               C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2925                               C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2926                               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2927                               xg[0]= xg[1]; yg[0]= yg[1];
2928                               xg[1] = ixbox[1] - ixbox[3] +xm; yg[1]=  iybox[0] - iybox[4] +ym;
2929                               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2930                               C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
2931                               /*        } */
2932                             }
2933                           FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
2934                         }
2935                       else
2936                         {
2937                           if(ytmp>yminval && ytmp<ymaxval) 
2938                             {
2939                               xg[0]= xm;  yg[0]= ym;  
2940                               if (Ishidden(psubwin))
2941                                 { xg[1]= xm; yg[1]= iybox[0] -iybox[5]+ym; }
2942                               else
2943                                 {xg[1]= ixbox[1] - ixbox[3] +xm; yg[1]= iybox[5] - iybox[4] +ym; } 
2944                               C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2945                               C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2946                               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2947                               xg[0]= xg[1]; yg[0]= yg[1];
2948                               xg[1] = ixbox[1] - ixbox[3] +xm; yg[1]=  iybox[0] - iybox[4] +ym;
2949                               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2950                               C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
2951                             }
2952                         }
2953                     }
2954                     
2955                   /* and subtics */
2956                   if(i != nbtics-1)
2957                     {
2958                       if(ppsubwin->logflags[1] =='l')
2959                         {
2960                           double tmp[2];
2961                           double pas=0;
2962                           double * tmp_log_grads = (double *) NULL;
2963                           
2964                           
2965                           double * grads = ppsubwin->axes.u_ygrads;
2966                           
2967                           tmp[0] = exp10(grads[i]);
2968                           tmp[1] = exp10(grads[i+1]);
2969                           pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
2970                           
2971                           if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
2972                             sciprint("Error allocating tmp_log_grads\n");
2973                             return -1;
2974                           }
2975                           
2976                           for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
2977                           
2978                           for(j=0;j<nbsubtics;j++)
2979                             {
2980                               vyy1 = tmp_log_grads[j];
2981                               
2982                               if(vyy1<yminval || vyy1>ymaxval) continue;
2983                               
2984                               if(ppsubwin->axes.reverse[1] == TRUE)
2985                                 vyy1 = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],vyy1);
2986                               
2987                               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&vyy1,&fz);
2988                               
2989                               if (IsDownAxes(psubwin))
2990                                 {
2991                                   vx[1]=vx[0]=xm;
2992                                   vy[0]=ym;
2993                                   vy[1]=vy[0]+iof/4;
2994                                 }
2995                               else
2996                                 {
2997                                   vx[0]=xm;vy[0]=ym;
2998                                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
2999                                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
3000                                 }
3001                               
3002                               if(ppsubwin->axes.axes_visible[1] == TRUE)
3003                                 C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
3004                             }
3005                           FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
3006                           
3007                         } /* end NEW */
3008                       else
3009                         {
3010                           
3011                           double ytmp2 = ppsubwin->axes.u_ygrads[i];
3012                           double dy = (ppsubwin->axes.u_ygrads[i+1] - ppsubwin->axes.u_ygrads[i]) / nbsubtics;
3013                           for(j=0;j<nbsubtics;j++)
3014                             {
3015                               vyy1=ytmp2+dy*j;
3016                               
3017                               if(vyy1<yminval || vyy1>ymaxval) continue;
3018                               
3019                               if(ppsubwin->axes.reverse[1] == TRUE)
3020                                 vyy1 = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],vyy1);
3021                               
3022                               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&vyy1,&fz);
3023                               /*                  trans3d(psubwin,1,&xm,&ym,&fx,&vyy1,&fz); */
3024                               
3025                               
3026                               if (IsDownAxes(psubwin))
3027                                 {
3028                                   vx[1]=vx[0]=xm;
3029                                   vy[0]=ym;
3030                                   vy[1]=vy[0]+iof/4;
3031                                 }
3032                               else
3033                                 {
3034                                   vx[0]=xm;vy[0]=ym;
3035                                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
3036                                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
3037                                 }
3038                               
3039                               if(ppsubwin->axes.axes_visible[1] == TRUE)
3040                                 C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
3041                             }
3042                         }
3043                     }
3044                   /***************************************************************/
3045                   /************************* COMMON PART *************************/
3046                   /***************************************************************/
3047                   
3048                 }
3049             }
3050           else /* we display the computed tics */
3051             {
3052               AdaptGraduationsOnYBottomLeft(iof,x,y,size,Ticsdir,fontid,psubwin,yminval,ymaxval,fx,0.,fz);
3053               
3054               lastyindex = ppsubwin->axes.nygrads - 1;
3055
3056               if(lastyindex == 0)
3057                 ChooseFormatForOneGrad(c_format,&(ppsubwin->axes.ygrads[0]));
3058               else
3059                 ChoixFormatE(c_format,
3060                              ppsubwin->axes.ygrads[0],
3061                              ppsubwin->axes.ygrads[lastyindex],
3062                              ((ppsubwin->axes.ygrads[lastyindex])-(ppsubwin->axes.ygrads[0]))/(lastyindex));
3063               
3064               nbtics = ppsubwin->axes.nygrads;
3065               nbsubtics = ppsubwin->axes.nbsubtics[1];
3066               
3067               maxTicksLabelSize[0] = 0 ;
3068               maxTicksLabelSize[1] = 0 ;
3069
3070               for(i=0;i<nbtics;i++)
3071                 {
3072                   char foo[256]; 
3073                   double ytmp = ppsubwin->axes.ygrads[i];
3074               
3075                   if(ytmp<yminval || ytmp>ymaxval) 
3076                     {
3077                       /*   sciprint("je rejete la valeur: %lf\n\n",xtmp); */
3078                       continue; /* cas ou TL est ON et on a des graduations qui ne seront pas affichees de tte facon */
3079                       /* donc autant ne pas aller plus loin dans l'algo... */
3080                     }
3081                   
3082                   sprintf(foo,c_format,ytmp);
3083                   
3084                   /***************************************************************/
3085                   /************************* COMMON PART *************************/
3086                   /***************************************************************/
3087
3088                   if(ppsubwin->axes.reverse[1] == TRUE)
3089                     ytmp = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],ytmp);
3090                   
3091                   ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&ytmp,&fz);
3092                   /*              trans3d(psubwin,1,&xm,&ym,&fx,&ytmp,&fz); */
3093
3094
3095                   vx[0]=xm;vy[0]=ym; 
3096                   
3097                   barlengthx= (integer) (( Ticsdir[0])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
3098                   barlengthy= (integer) (( Ticsdir[1])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
3099                   
3100                   C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); /* fix bug noticed by R.N. */
3101                   
3102                   C2F(dr)("xstringl",foo,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3103                   maxTicksLabelSize[0] = Max( maxTicksLabelSize[0], rect[2] ) ;
3104                   maxTicksLabelSize[1] = Max( maxTicksLabelSize[1], rect[3] ) ;
3105                   
3106                   if (IsDownAxes(psubwin)){
3107                     vx[1]=vx[0];
3108                     vy[1]=vy[0]+iof/2;
3109                     posi[0] = inint(xm-rect[2]/2); 
3110                     posi[1]=inint( vy[0] + iof + rect[3]);}
3111                   else{
3112                     vx[1]=vx[0]+barlengthx;
3113                     vy[1]=vy[0]+barlengthy;
3114 /*                  posi[0] = inint( xm+2*barlengthx-rect[2]/2);  */
3115                     posi[0] = inint( xm+2*barlengthx-rect[2]); 
3116                     posi[1]=inint( ym + 2*barlengthy + rect[3]);}
3117                       
3118                   if(ppsubwin->axes.axes_visible[1] == TRUE){
3119                     C2F(dr)("xset","pattern",&textcolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3120                     C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3121                     if ( ppsubwin->logflags[1] == 'l' )
3122                       {
3123                         int smallersize = fontid[1]-2;
3124                         int old_rect10[4];
3125                         /*                  char str[2] = "xv"; */
3126                         int posi10[2];
3127                         
3128                         posi10[0] = posi[0] - logrect[2];
3129                         posi10[1] = posi[1] + logrect[3];
3130                         
3131                         C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3132                         C2F(dr)("xstring","10",(&posi10[0]),(&posi10[1]),PI0,&flag,PI0,PI0,&angle,PD0,PD0,PD0,0L,0L);
3133                         
3134                         C2F(dr)("xstringl","10",(&posi10[0]),(&posi10[1]),old_rect10,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3135                         
3136                         posi[0] = old_rect10[0] + old_rect10[2];
3137                         posi[1] = (int) (old_rect10[1] - old_rect10[3]*.1);
3138                         
3139                         C2F(dr)("xset","font",fontid,&smallersize,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3140                         C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&ang, PD0,PD0,PD0,0L,0L);
3141                         
3142                         /* put back the current fontid */
3143                         C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3144                       }
3145                     else
3146                       C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&ang, PD0,PD0,PD0,0L,0L);
3147                     
3148                     C2F(dr)("xset","pattern",&ticscolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);   
3149                     C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
3150                   }
3151                   /* grid to put here */
3152                   if ( ppsubwin->grid[1] > -1 && ppsubwin->axes.axes_visible[1] )
3153                     {
3154                       gstyle = pSUBWIN_FEATURE (psubwin)->grid[1];
3155
3156                       if((ppsubwin->logflags[1] =='l') && (i != nbtics-1))
3157                         {
3158                           double tmp[2];
3159                           double pas=0;
3160                           double * tmp_log_grads = (double *) NULL;
3161                           
3162                           
3163                           double * grads = ppsubwin->axes.ygrads;
3164                           
3165                           tmp[0] = exp10(grads[i]);
3166                           tmp[1] = exp10(grads[i+1]);
3167                           pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
3168                           
3169                           if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
3170                             sciprint("Error allocating tmp_log_grads\n");
3171                             return -1;
3172                           }
3173                           
3174                           for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
3175                           
3176                           for(j=0;j<nbsubtics;j++)
3177                             {
3178                               vyy1 = tmp_log_grads[j];
3179                               
3180                               if(vyy1<=yminval || vyy1>=ymaxval) continue;
3181                               
3182                               if(ppsubwin->axes.reverse[1] == TRUE)
3183                                 vyy1 = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],vyy1);
3184                               
3185                               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&vyy1,&fz);
3186                               
3187                               /*    if ((xm != ixbox[3]) && (xm != ixbox[4])) */
3188                               /*                                {  */
3189                               xg[0]= xm;  yg[0]= ym;  
3190                               if (Ishidden(psubwin))
3191                                 { xg[1]= xm; yg[1]= iybox[0] -iybox[5]+ym; }
3192                               else
3193                                 {xg[1]= ixbox[1] - ixbox[3] +xm; yg[1]= iybox[5] - iybox[4] +ym; } 
3194                               C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3195                               C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3196                               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
3197                               xg[0]= xg[1]; yg[0]= yg[1];
3198                               xg[1] = ixbox[1] - ixbox[3] +xm; yg[1]=  iybox[0] - iybox[4] +ym;
3199                               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
3200                               C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
3201                               /*        } */
3202                             }
3203                           FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
3204                         }
3205                       else
3206                         {
3207                           if(ytmp>yminval && ytmp<ymaxval) 
3208                             {
3209                               xg[0]= xm;  yg[0]= ym;  
3210                               if (Ishidden(psubwin))
3211                                 { xg[1]= xm; yg[1]= iybox[0] -iybox[5]+ym; }
3212                               else
3213                                 {xg[1]= ixbox[1] - ixbox[3] +xm; yg[1]= iybox[5] - iybox[4] +ym; } 
3214                               C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3215                               C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3216                               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
3217                               xg[0]= xg[1]; yg[0]= yg[1];
3218                               xg[1] = ixbox[1] - ixbox[3] +xm; yg[1]=  iybox[0] - iybox[4] +ym;
3219                               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
3220                               C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
3221                             }
3222                         }
3223                     }
3224                   
3225                   /* and subtics */
3226                   if(i != nbtics-1)
3227                     {
3228                       if(ppsubwin->logflags[1] =='l')
3229                         {
3230                           double tmp[2];
3231                           double pas=0;
3232                           double * tmp_log_grads = (double *) NULL;
3233                           
3234                           
3235                           double * grads = ppsubwin->axes.ygrads;
3236                           
3237                           tmp[0] = exp10(grads[i]);
3238                           tmp[1] = exp10(grads[i+1]);
3239                           pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
3240                           
3241                           if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
3242                             sciprint("Error allocating tmp_log_grads\n");
3243                             return -1;
3244                           }
3245                           
3246                           for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
3247                           
3248                           for(j=0;j<nbsubtics;j++)
3249                             {
3250                               vyy1 = tmp_log_grads[j];
3251                               
3252                               if(vyy1<yminval || vyy1>ymaxval) continue;
3253                               
3254                               if(ppsubwin->axes.reverse[1] == TRUE)
3255                                 vyy1 = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],vyy1);
3256                               
3257                               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&vyy1,&fz);
3258                               
3259                               if (IsDownAxes(psubwin))
3260                                 {
3261                                   vx[1]=vx[0]=xm;
3262                                   vy[0]=ym;
3263                                   vy[1]=vy[0]+iof/4;
3264                                 }
3265                               else
3266                                 {
3267                                   vx[0]=xm;vy[0]=ym;
3268                                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
3269                                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
3270                                 }
3271                               
3272                               if(ppsubwin->axes.axes_visible[1] == TRUE)
3273                                 C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
3274                             }
3275                           FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
3276                           
3277                         } /* end NEW */
3278                       else
3279                         {
3280                           
3281                           double ytmp2 = ppsubwin->axes.ygrads[i];
3282                           double dy = (ppsubwin->axes.ygrads[i+1] - ppsubwin->axes.ygrads[i]) / nbsubtics;
3283                           for(j=0;j<nbsubtics;j++)
3284                             {
3285                               vyy1=ytmp2+dy*j;
3286                               
3287                               if(vyy1<yminval || vyy1>ymaxval) continue;
3288                               
3289                               if(ppsubwin->axes.reverse[1] == TRUE)
3290                                 vyy1 = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],vyy1);
3291                               
3292                               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&vyy1,&fz);
3293                                                       
3294                               if (IsDownAxes(psubwin))
3295                                 {
3296                                   vx[1]=vx[0]=xm;
3297                                   vy[0]=ym;
3298                                   vy[1]=vy[0]+iof/4;
3299                                 }
3300                               else
3301                                 {
3302                                   vx[0]=xm;vy[0]=ym;
3303                                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
3304                                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
3305                                 }
3306                               
3307                               if(ppsubwin->axes.axes_visible[1] == TRUE)
3308                                 C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
3309                             }
3310                         }
3311                     }
3312                   
3313                   /***************************************************************/
3314                   /************************* COMMON PART *************************/
3315                   /***************************************************************/
3316                 }
3317             }
3318         }
3319       
3320       if ( sciGetVisibility(ppsubwin->mon_y_label) )
3321       {  
3322         sciLabel * ppLabel =  pLABEL_FEATURE(ppsubwin->mon_y_label) ;
3323         if( ppLabel->auto_rotation )
3324         {
3325           sciSetFontOrientation(ppsubwin->mon_y_label, 0 ) ;
3326         }
3327                 
3328         if( ppLabel->auto_position )
3329         {
3330              
3331           int segmentStart[2] = { ixbox[3], iybox[3] } ;
3332           int segmentEnd[2]   = { ixbox[4], iybox[4] } ;
3333           
3334           /* add the bar size and ticks label size to the offset */
3335           int offset[2] = { constOffset[0] + maxTicksLabelSize[0] + abs( barlengthx ), 
3336                             constOffset[1] + maxTicksLabelSize[1] + abs( barlengthy )  } ;
3337           computeLabelAutoPos( ppsubwin->mon_y_label, segmentStart, segmentEnd, offset ) ;
3338         }
3339         /* a trick to force the display with 2d scale */
3340         drawTextEntity( ppLabel->text ) ;
3341         
3342       }
3343     }
3344   /* reset font to its current size & to current color*/ 
3345   if ( fontsize != -1 ){
3346     fontid[1] = fontsize_kp;
3347     C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3348   }
3349   if ( textcolor != -1 || ticscolor != -1 ) 
3350     C2F(dr)("xset","pattern",&color_kp,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3351   /***/
3352   /* FREE(loc); */
3353
3354   
3355   return 0;
3356 }
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368 BOOL Ishidden(sciPointObj *pobj)
3369 {
3370   double alpha;
3371   if (sciGetEntityType(pobj) == SCI_SUBWIN){
3372     alpha = pSUBWIN_FEATURE (pobj)->alpha;
3373     if ((alpha <0.0 ) && (alpha > -90.0))
3374       return TRUE;
3375     if ((alpha <360.0 ) && (alpha > 270.0)) /* missing case added to fix bug 839 F.Leray */
3376       return TRUE;
3377     if ((alpha <-180.0 ) && (alpha > -270.0))
3378       return TRUE;
3379     if ((alpha <180.0 ) && (alpha > 90.0))
3380       return TRUE;
3381   }
3382   return FALSE;
3383 }
3384
3385 /* When alpha is close to a singularity (90,-90,270...), use to determine how to draw the x and y graduations */
3386 /* depending on cof */
3387 BOOL IsDownAxes(sciPointObj *pobj)
3388 {
3389   double alpha,cof;
3390   
3391   if (sciGetEntityType(pobj) == SCI_SUBWIN){
3392     alpha = pSUBWIN_FEATURE (pobj)->alpha;   
3393     if (!(pSUBWIN_FEATURE (pobj)->isoview))
3394       cof=10.0;
3395     else
3396       cof = 5.0; /* F.Leray : hard fixed here */
3397     /* Correction Warnings Attention Precision*/
3398     /*   cof= (double) (Min(5.0,ceil(Max( */
3399     /*                                abs((int)ppsubwin->axes.xlim[1]-(int)ppsubwin->axes.xlim[0])/ */
3400     /*                                abs((int)ppsubwin->axes.ylim[1]-(int)ppsubwin->axes.ylim[0]), */
3401     /*                                abs((int)ppsubwin->axes.ylim[1]-(int)ppsubwin->axes.ylim[0])/ */
3402     /*                                abs((int)ppsubwin->axes.xlim[1]-(int)ppsubwin->axes.xlim[0]))))); */
3403     if (cof == 0 ) cof =5;
3404     if ((alpha <=(-90.0+cof) ) && (alpha >= (-90.0-cof))) 
3405       return TRUE;
3406     if ((alpha <=(-270.0+cof) ) && (alpha >= (-270.0-cof)))
3407       return TRUE;
3408     if ((alpha <=(90.0+cof) ) && (alpha >= (90.0-cof)))
3409       return TRUE;
3410     if ((alpha <=(270.0+cof) ) && (alpha >= (270.0-cof)))
3411       return TRUE;
3412   }
3413   return FALSE;
3414 }
3415
3416 /* compute the graduation of the segment [minVal,maxVal] knowing the number of ticks */
3417 void GradFixedlog( double minVal, double maxVal, double * ticks, int nbGrads )
3418 {
3419   int initSize ;
3420   int i ;
3421
3422   /* intialize the array as usual */
3423   GradLog( minVal, maxVal, ticks, &initSize, FALSE ) ;
3424
3425   if ( initSize > nbGrads )
3426   {
3427     /* we create a smaller vector from a bigger one */
3428     int nbRemove = initSize - nbGrads ;
3429     
3430     BOOL * removedTicks ;
3431     if( ( removedTicks = MALLOC( initSize * sizeof(BOOL) ) ) == NULL )
3432     {
3433       return ;
3434     }
3435
3436     for ( i = 0 ; i < initSize ; i++ )
3437     {
3438       removedTicks[i] = FALSE ;
3439     }
3440
3441     /* we now remove the nbremove indexes : round( ( 0.5 + i ) * size / nbRemove ) */
3442     /* i=0..nbReg-1 should do the thing */
3443     for ( i = 0 ; i < nbRemove ; i++ )
3444     {
3445       int remIndex = 1 + (int) round(  i  * ((double) initSize - 2 ) / ( (double) nbRemove ) ) ;
3446       removedTicks[remIndex] = TRUE ;
3447     }
3448
3449     removeBadTicks( ticks, removedTicks, &initSize ) ;
3450
3451     FREE( removedTicks ) ;
3452
3453   }
3454
3455 }
3456
3457
3458 /* compute the automatic graduation of the segment [_min,_max] and store it in _grads */
3459 /* the number of graduation may be fixed if compNgrads is TRUE or automaticaly computed */
3460 /* otherwise. */
3461 int GradLog( double   _min   ,
3462              double   _max   ,
3463              double * _grads ,
3464              int    * n_grads,
3465              int      compNgrads )
3466 {
3467   int i;
3468   int log_min, log_max;
3469   int size;
3470   
3471   if ( compNgrads )
3472   {
3473     GradFixedlog( _min, _max, _grads, *n_grads ) ;
3474     return 0 ;
3475   }
3476
3477   log_max =  (int) ceil(_max);
3478   log_min =  (int) floor(_min);
3479   
3480
3481   size = log_max - log_min +1;
3482   /*  tab=(int *)MALLOC(size*sizeof(int)); */
3483   
3484   /*   for(i=0;i<size;i++) tab[i]=log_min+i; */
3485
3486   *n_grads = 0 ;
3487
3488   if(size<=7)    {
3489       for(i=0;i<size;i++)
3490         {
3491           /*    _grads[i] = exp10(tab[i]); */
3492           _grads[i] = log_min+i;
3493           *n_grads = (*n_grads) + 1;
3494           /*      sciprint("Juste en sortie, _grads[%d] = %lf\n",i, _grads[i]); */
3495         }
3496     }
3497   else
3498     {
3499       int pas = 0, old_pas= 0,j;
3500       int val = size, passed = 0;
3501       
3502       for(j=val-1;j>1;j--)
3503         if(val%j == 0){
3504           old_pas = pas;
3505           pas=j; 
3506           passed = 1;
3507
3508           if((7*pas)<=val){ 
3509             if(old_pas != 0) {pas = old_pas; }
3510             break;
3511           }
3512         }
3513       
3514       if(passed != 1 || (size/pas)>15 ) pas = size;
3515             
3516       if(pas==size)
3517         {
3518           _grads[0] = log_min;
3519           _grads[1] = log_max;
3520           *n_grads =2;
3521         }
3522       else
3523       {
3524         for(i=0;i<=(int )(size/pas);i++)
3525           {
3526             _grads[i] = log_min+(i*pas);
3527             
3528             *n_grads = (*n_grads) + 1;
3529             /*      sciprint("Juste en sortie, _grads[%d] = %lf\n",i, _grads[i]); */
3530           }
3531       }
3532     }
3533   
3534   return 0;
3535 }
3536
3537 /**
3538  * get the exponent used for log axis from given data bounds
3539  * @return 0 if OK, -1 if negative bounds.
3540  */
3541 int sciGetLogExponent( double minBound, double maxBound, double * expMin, double * expMax )
3542 {
3543   if ( minBound > 0 )
3544   {
3545     *expMin = floor( log10( minBound ) ) ;
3546     *expMax = ceil(  log10( maxBound ) ) ;
3547     return 0 ;
3548   }
3549   *expMax = 1.0 ;
3550   *expMin = 0.0 ;
3551   return -1 ;
3552 }
3553
3554 /* get the displayed bounds of an axis */
3555 void sciGetDisplayedBounds( sciPointObj * pSubWin,
3556                             double      * xmin   ,
3557                             double      * xmax   ,
3558                             double      * ymin   ,
3559                             double      * ymax   ,
3560                             double      * zmin   ,
3561                             double      * zmax    )
3562 {
3563   sciSubWindow * ppsubwin =  pSUBWIN_FEATURE ( pSubWin ) ;
3564     /*****************************************************************
3565      * get initial bounds
3566    *****************************************************************/
3567   if( sciGetZooming( pSubWin ) )
3568   {
3569     *xmin = ppsubwin->ZRect[0] ; 
3570     *ymin = ppsubwin->ZRect[1] ; 
3571     *xmax = ppsubwin->ZRect[2] ;
3572     *ymax = ppsubwin->ZRect[3] ;
3573     *zmin = ppsubwin->ZRect[4] ;
3574     *zmax = ppsubwin->ZRect[5] ;
3575   }
3576   else
3577   {
3578     *xmin = ppsubwin->SRect[0] ;
3579     *ymin = ppsubwin->SRect[2] ;
3580     *xmax = ppsubwin->SRect[1] ;
3581     *ymax = ppsubwin->SRect[3] ;
3582     *zmin = ppsubwin->SRect[4] ;
3583     *zmax = ppsubwin->SRect[5] ;
3584   }
3585   
3586   
3587    
3588   /*****************************************************************
3589    * modify  bounds and aaint  if using log scaling X axis
3590    *****************************************************************/
3591   if ( ppsubwin->logflags[0] == 'l' )
3592   {
3593     if ( sciGetLogExponent( *xmin, *xmax, xmin, xmax ) != 0 )
3594     {
3595       sciprint("Warning: Can't use Log on X-axis xmin is negative. \n");
3596     }
3597   }
3598
3599   /*****************************************************************
3600    * modify  bounds and aaint  if using log scaling Y axis
3601    *****************************************************************/
3602   if ( ppsubwin->logflags[1] == 'l' )
3603   {
3604     if ( sciGetLogExponent( *ymin, *ymax, ymin, ymax ) != 0 )
3605     {
3606       sciprint("Warning: Can't use Log on Y-axis ymin is negative. \n");
3607     }
3608   }
3609
3610   /*****************************************************************
3611    * modify  bounds and aaint  if using log scaling Z axis
3612    *****************************************************************/
3613   if ( ppsubwin->logflags[2] == 'l' )
3614   {
3615     if ( sciGetLogExponent( *zmin, *zmax, zmin, zmax ) != 0 )
3616     {
3617       sciprint("Warning: Can't use Log on Z-axis zmin is negative. \n");
3618     }
3619   }
3620
3621 }
3622
3623 /* F.Leray au 13.10.04 completly review for new axes graduations */
3624 /*** F.Leray 02.04.04 */
3625 /* FUNCTION FOR 2D UPDATE ONLY !!!!! <=> beginning of axis_3ddraw (in 2d HERE of course! ) */
3626 /* Copy on update_frame_bounds */
3627 BOOL sci_update_frame_bounds_2d(sciPointObj *pobj)
3628 {
3629   double xmax, xmin, ymin, ymax, zmin, zmax ;
3630   double hx,hy,hx1,hy1;
3631   int i;
3632   
3633   sciSubWindow * ppsubwin =  pSUBWIN_FEATURE (pobj);
3634   double FRect[4],WRect[4],ARect[4]; 
3635   char logscale[2];
3636   
3637   /* Temp variables only used when called from update_specification_bounds */
3638   /* to know if we have to redraw all the figure */
3639   double ExistingFRect[4]; /* the Existing FRect at start to be compared at the end of this routine */
3640   /* in order to determine wheter or not the bounds have changed... */
3641   int nbsubtics[2];
3642   int nbgrads[2];
3643   /* End of Temp variables */
3644   
3645   for(i=0;i<4;i++) ExistingFRect[i] =  ppsubwin->FRect[i]; /* store old initial bounds*/
3646
3647   for(i=0;i<2;i++) nbsubtics[i] = ppsubwin->axes.nbsubtics[i];
3648   nbgrads[0] = ppsubwin->axes.nxgrads;
3649   nbgrads[1] = ppsubwin->axes.nygrads;
3650   
3651   /* nbtics on z put to 0 */
3652   /*   ppsubwin->axes.nzgrads = 0; */
3653   
3654
3655   sciGetDisplayedBounds( pobj, &xmin, &xmax, &ymin, &ymax, &zmin, &zmax ) ;
3656
3657
3658   /* _grad Init. to 0. */
3659   for(i=0;i<20;i++) 
3660     {
3661       ppsubwin->axes.xgrads[i] = 0.;
3662       ppsubwin->axes.ygrads[i] = 0.;
3663     }
3664    
3665  
3666   if ( ppsubwin->logflags[0]=='n') { /* x-axis */
3667     TheTicks(&xmin, &xmax, &(ppsubwin->axes.xgrads[0]), &ppsubwin->axes.nxgrads, FALSE); 
3668     ppsubwin->axes.nbsubtics[0] = ComputeNbSubTics(pobj,ppsubwin->axes.nxgrads,'n',NULL,ppsubwin->axes.nbsubtics[0]); /* Nb of subtics computation and storage */ /* F.Leray 07.10.04 */
3669   }
3670   else{ /* log. case */
3671     GradLog(xmin,xmax,ppsubwin->axes.xgrads,&ppsubwin->axes.nxgrads, FALSE );
3672     ppsubwin->axes.nbsubtics[0] = ComputeNbSubTics(pobj,ppsubwin->axes.nxgrads,'l',ppsubwin->axes.xgrads,0);
3673   }
3674    
3675   if ( ppsubwin->logflags[1]=='n') { /* y-axis */
3676     TheTicks(&ymin, &ymax, &(ppsubwin->axes.ygrads[0]), &ppsubwin->axes.nygrads, FALSE);
3677     ppsubwin->axes.nbsubtics[1] = ComputeNbSubTics(pobj,ppsubwin->axes.nygrads,'n',NULL, ppsubwin->axes.nbsubtics[1]); /* Nb of subtics computation and storage */ /* F.Leray 07.10.04 */
3678   }
3679   else{ /* log. case */
3680     GradLog(ymin,ymax,ppsubwin->axes.ygrads,&ppsubwin->axes.nygrads, FALSE );
3681     ppsubwin->axes.nbsubtics[1] = ComputeNbSubTics(pobj,ppsubwin->axes.nygrads,'l',ppsubwin->axes.ygrads,0);
3682   }
3683    
3684   if(ppsubwin->tight_limits == FALSE )
3685     {
3686       xmin = ppsubwin->axes.xgrads[0];
3687       xmax = ppsubwin->axes.xgrads[ ppsubwin->axes.nxgrads - 1];
3688       ymin = ppsubwin->axes.ygrads[0];
3689       ymax = ppsubwin->axes.ygrads[ ppsubwin->axes.nygrads - 1];
3690     }
3691
3692   /*****************************************************************
3693    * modify  bounds if  isoview requested 
3694    *****************************************************************/
3695   if ( ppsubwin->isoview == TRUE) {      
3696     int verbose=0,wdim[2],narg; 
3697         
3698     C2F(dr)("xget","wdim",&verbose,wdim,&narg, PI0, PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3699     hx=xmax-xmin;
3700     hy=ymax-ymin;
3701     getscale2d(WRect,FRect,logscale,ARect);
3702     
3703     wdim[0]=linint((double)wdim[0] *WRect[2]);
3704     wdim[1]=linint((double)wdim[1] *WRect[3]);
3705     
3706     if ( hx/(double)wdim[0]  <hy/(double) wdim[1] ) {
3707       hx1=wdim[0]*hy/wdim[1];
3708       xmin=xmin-(hx1-hx)/2.0;
3709       xmax=xmax+(hx1-hx)/2.0;
3710     }
3711     else {
3712       hy1=wdim[1]*hx/wdim[0];
3713       ymin=ymin-(hy1-hy)/2.0;
3714       ymax=ymax+(hy1-hy)/2.0;
3715     }
3716     
3717     /* F.Leray 28.09.04 */
3718     /* I need to recompute the correct xgrads and ygrads vector to have a good display */
3719      
3720     if ( ppsubwin->logflags[0]=='n') { /* x-axis */
3721       TheTicks(&xmin, &xmax, &(ppsubwin->axes.xgrads[0]), &ppsubwin->axes.nxgrads, FALSE);
3722       ppsubwin->axes.nbsubtics[0] = ComputeNbSubTics(pobj,ppsubwin->axes.nxgrads,'n',NULL, ppsubwin->axes.nbsubtics[0]); /* Nb of subtics computation and storage */ /* F.Leray 07.10.04 */
3723     }
3724     else{ /* log. case */
3725       GradLog(xmin,xmax,ppsubwin->axes.xgrads,&ppsubwin->axes.nxgrads, FALSE);
3726       ppsubwin->axes.nbsubtics[0] = ComputeNbSubTics(pobj,ppsubwin->axes.nxgrads,'l',ppsubwin->axes.xgrads,0);
3727     }
3728
3729  
3730
3731     if ( ppsubwin->logflags[1]=='n') { /* y-axis */
3732       TheTicks(&ymin, &ymax, &(ppsubwin->axes.ygrads[0]), &ppsubwin->axes.nygrads, FALSE);
3733       ppsubwin->axes.nbsubtics[1] = ComputeNbSubTics(pobj,ppsubwin->axes.nygrads,'n',NULL, ppsubwin->axes.nbsubtics[1]); /* Nb of subtics computation and storage */ /* F.Leray 07.10.04 */
3734     }
3735     else{ /* log. case */
3736       GradLog(ymin,ymax,ppsubwin->axes.ygrads,&ppsubwin->axes.nygrads, FALSE );
3737       ppsubwin->axes.nbsubtics[1] = ComputeNbSubTics(pobj,ppsubwin->axes.nygrads,'l',ppsubwin->axes.ygrads,0);
3738     }
3739    
3740    
3741     /* END ISO if */
3742   }
3743   
3744   /* Changement ci-dessous F.Leray 21.09.04 */
3745   ppsubwin->axes.xlim[0]=xmin;
3746   ppsubwin->axes.xlim[1]=xmax;
3747   ppsubwin->axes.xlim[2]=0;
3748   ppsubwin->axes.ylim[0]=ymin;
3749   ppsubwin->axes.ylim[1]=ymax;
3750   ppsubwin->axes.ylim[2]=0;
3751    
3752    
3753    
3754   /*****************************************************************
3755    * set the actual bounds in subwindow data structure
3756    *****************************************************************/
3757    
3758    
3759   ppsubwin->FRect[0]=xmin;
3760   ppsubwin->FRect[2]=xmax;
3761   ppsubwin->FRect[1]=ymin;
3762   ppsubwin->FRect[3]=ymax;
3763    
3764   ppsubwin->axes.xlim[3] = ppsubwin->axes.nxgrads;
3765   ppsubwin->axes.ylim[3] = ppsubwin->axes.nygrads;
3766    
3767   /*   ppsubwin->axes.reverse[0] = FALSE; /\*TRUE;*\/  /\* TEST en DUR F.Leray ICIIIIIIIIIIIII 12.10.04 *\/ */
3768   /*    ppsubwin->axes.reverse[1] = FALSE; /\*TRUE;*\/  */
3769    
3770    
3771   set_scale("tftftf",NULL,ppsubwin->FRect,NULL,ppsubwin->logflags,NULL); 
3772    
3773    
3774   for(i=0;i<4;i++)
3775     if(ppsubwin->FRect[i] != ExistingFRect[i]){
3776       return TRUE;
3777       break;
3778     } 
3779    
3780   for(i=0;i<2;i++) 
3781     if(nbsubtics[i] != ppsubwin->axes.nbsubtics[i]){
3782       return TRUE;
3783       break;
3784     }
3785    
3786   if(nbgrads[0] != ppsubwin->axes.nxgrads) return TRUE;
3787   if(nbgrads[1] != ppsubwin->axes.nygrads) return TRUE;
3788    
3789   return FALSE;
3790 }
3791
3792 /**update_3dbounds -> renammed sci_update_frame_bounds_3d
3793  * @author Djalel Abdemouche 10/2003
3794  * Should be in Plo2dEch.c file
3795  */
3796 BOOL sci_update_frame_bounds_3d(sciPointObj *pobj)
3797 {
3798   double xmin,xmax,ymin,ymax,zmin,zmax; 
3799   int i;
3800   sciSubWindow * ppsubwin = pSUBWIN_FEATURE (pobj); 
3801
3802   /* Temp variables only used when called from update_specification_bounds */
3803   /* to know if we have to redraw all the figure */
3804   double ExistingFRect[6]; /* the Existing FRect at start to be compared at the end of this routine */
3805   /* in order to determine wheter or not the bounds have changed... */
3806   int nbsubtics[3];
3807   int nbgrads[3];
3808   /* End of Temp variables */
3809
3810   for(i=0;i<6;i++) ExistingFRect[i] =  ppsubwin->FRect[i]; /* store old initial bounds*/
3811   
3812   for(i=0;i<3;i++) nbsubtics[i] = ppsubwin->axes.nbsubtics[i];
3813   nbgrads[0] = ppsubwin->axes.nxgrads;
3814   nbgrads[1] = ppsubwin->axes.nygrads;
3815   nbgrads[2] = ppsubwin->axes.nzgrads;
3816
3817   sciGetDisplayedBounds( pobj, &xmin, &xmax, &ymin, &ymax, &zmin, &zmax ) ;
3818   
3819
3820   /* _grad Init. to 0. */
3821   for(i=0;i<20;i++) 
3822     {
3823       ppsubwin->axes.xgrads[i] = 0.;
3824       ppsubwin->axes.ygrads[i] = 0.;
3825       ppsubwin->axes.zgrads[i] = 0.;
3826     }
3827    
3828   
3829   if ( ppsubwin->logflags[0]=='n') { /* x-axis */
3830     TheTicks(&xmin, &xmax, &(ppsubwin->axes.xgrads[0]), &ppsubwin->axes.nxgrads, FALSE);
3831     ppsubwin->axes.nbsubtics[0] = ComputeNbSubTics(pobj,ppsubwin->axes.nxgrads,'n',NULL,ppsubwin->axes.nbsubtics[0]); /* Nb of subtics computation and storage */
3832   }
3833   else{ /* log. case */
3834     GradLog(xmin,xmax,ppsubwin->axes.xgrads,&ppsubwin->axes.nxgrads, FALSE );
3835     ppsubwin->axes.nbsubtics[0] = ComputeNbSubTics(pobj,ppsubwin->axes.nxgrads,'l',ppsubwin->axes.xgrads,0);
3836   }
3837   
3838   if ( ppsubwin->logflags[1]=='n') { /* y-axis */
3839     TheTicks(&ymin, &ymax, &(ppsubwin->axes.ygrads[0]), &ppsubwin->axes.nygrads, FALSE);
3840     ppsubwin->axes.nbsubtics[1] = ComputeNbSubTics(pobj,ppsubwin->axes.nygrads,'n',NULL, ppsubwin->axes.nbsubtics[1]); /* Nb of subtics computation and storage */
3841   }
3842   else{ /* log. case */
3843     GradLog(ymin,ymax,ppsubwin->axes.ygrads,&ppsubwin->axes.nygrads, FALSE );
3844     ppsubwin->axes.nbsubtics[1] = ComputeNbSubTics(pobj,ppsubwin->axes.nygrads,'l',ppsubwin->axes.ygrads,0);
3845   }
3846   
3847   if ( ppsubwin->logflags[2]=='n') { /* z-axis */
3848     TheTicks(&zmin, &zmax, &(ppsubwin->axes.zgrads[0]), &ppsubwin->axes.nzgrads, FALSE);
3849     ppsubwin->axes.nbsubtics[2] = ComputeNbSubTics(pobj,ppsubwin->axes.nzgrads,'n',NULL, ppsubwin->axes.nbsubtics[2]); /* Nb of subtics computation and storage */
3850   }
3851   else{ /* log. case */
3852     GradLog(zmin,zmax,ppsubwin->axes.zgrads,&ppsubwin->axes.nzgrads, FALSE );
3853     ppsubwin->axes.nbsubtics[2] = ComputeNbSubTics(pobj,ppsubwin->axes.nzgrads,'l',ppsubwin->axes.zgrads,0);
3854   }
3855   
3856   if(ppsubwin->tight_limits == FALSE )
3857     {
3858       xmin = ppsubwin->axes.xgrads[0];
3859       xmax = ppsubwin->axes.xgrads[ ppsubwin->axes.nxgrads - 1];
3860       ymin = ppsubwin->axes.ygrads[0];
3861       ymax = ppsubwin->axes.ygrads[ ppsubwin->axes.nygrads - 1];
3862       zmin = ppsubwin->axes.zgrads[0];
3863       zmax = ppsubwin->axes.zgrads[ ppsubwin->axes.nzgrads - 1];
3864     }
3865
3866   ppsubwin->axes.xlim[0]=xmin;
3867   ppsubwin->axes.xlim[1]=xmax;
3868   ppsubwin->axes.xlim[2]=0;
3869   ppsubwin->axes.ylim[0]=ymin;
3870   ppsubwin->axes.ylim[1]=ymax;
3871   ppsubwin->axes.ylim[2]=0;
3872   ppsubwin->axes.zlim[0]=zmin; /* rajout pour z */
3873   ppsubwin->axes.zlim[1]=zmax;
3874   ppsubwin->axes.zlim[2]=0;
3875      
3876   ppsubwin->FRect[0]=xmin;
3877   ppsubwin->FRect[2]=xmax;
3878   ppsubwin->FRect[1]=ymin;
3879   ppsubwin->FRect[3]=ymax;
3880   ppsubwin->FRect[4]=zmin;
3881   ppsubwin->FRect[5]=zmax;
3882     
3883   ppsubwin->axes.xlim[3] = ppsubwin->axes.nxgrads;
3884   ppsubwin->axes.ylim[3] = ppsubwin->axes.nygrads;
3885   ppsubwin->axes.zlim[3] = ppsubwin->axes.nzgrads;
3886    
3887   set_scale("tftftf",NULL,ppsubwin->FRect,NULL,ppsubwin->logflags,NULL); 
3888      
3889   wininfo("alpha=%.1f,theta=%.1f",ppsubwin->alpha,ppsubwin->theta); 
3890     
3891   for(i=0;i<6;i++)
3892     if(ppsubwin->FRect[i] != ExistingFRect[i]){
3893       return TRUE;
3894       break;
3895     } 
3896     
3897   for(i=0;i<3;i++) 
3898     if(nbsubtics[i] != ppsubwin->axes.nbsubtics[i]){
3899       return TRUE;
3900       break;
3901     }
3902   
3903   if(nbgrads[0] != ppsubwin->axes.nxgrads) return TRUE;
3904   if(nbgrads[1] != ppsubwin->axes.nygrads) return TRUE;
3905   if(nbgrads[2] != ppsubwin->axes.nzgrads) return TRUE;
3906   
3907   return FALSE;  
3908 }
3909
3910
3911
3912
3913
3914
3915
3916 int ComputeNbSubTics(sciPointObj * pobj, int nbtics, char logflag, double * grads, int nbsubtics_input)
3917 {
3918   int ticsval[] =    {2 ,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
3919   int subticsval[] = {10,7,5,5,4,4,3,2,2 ,2 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 };
3920   int i;
3921   sciSubWindow * ppsubwin = pSUBWIN_FEATURE (pobj);
3922
3923
3924   if(logflag =='l'){
3925     if((grads[1]-grads[0])==1) /* intervalle de type ...10^n 10^(n+1)...*/
3926       {
3927         return 9; /* 9 subtics to have a pretty tics/grid in log.*/
3928       }
3929     else
3930       {
3931         return 1; /* no subtics at all (1 but draw on a tics place) */
3932       }
3933   }
3934   else{
3935     if(ppsubwin->flagNax == FALSE) /* if auto subtics mode == ON */
3936       { 
3937         for(i=0;i<19;i++)
3938           if(nbtics == ticsval[i])
3939             {
3940               return subticsval[i];
3941             }
3942       }
3943     else /* if auto subtics mode == OFF already computed in Plo2dn.c, Champ.c routines... */
3944       {  /* or given via a.subtics=[nbsubtics_on_x, nbsubtics_on_y, nbsubtics_on_z] command */
3945         return nbsubtics_input;
3946       }
3947   }
3948   
3949   return -1;
3950 }
3951
3952 /* test on x and y axes only : used in 2D routines only */
3953 BOOL GetIsAxes2D(sciPointObj *psubwin)
3954 {
3955   sciSubWindow * ppsubwin = pSUBWIN_FEATURE (psubwin);
3956   
3957   if((ppsubwin->axes.axes_visible[0] == FALSE)
3958      && (ppsubwin->axes.axes_visible[1] == FALSE))
3959     return FALSE;
3960   else
3961     return TRUE;
3962 }
3963
3964 int ComputeCorrectXindAndInsideUD(double Teta,double Alpha, double *dbox, integer *xind, integer *InsideU, integer *InsideD)
3965 {
3966   double xbox[8], ybox[8], zbox[8];
3967
3968   Teta = 0.1; /* Little offset to compute correct values for xind,  InsideU and InsideD */
3969
3970   /* update Cscale.m from the new viewing angles */
3971   sciUpdateScaleAngles( Teta, Alpha ) ;
3972  
3973   sciGetAxisBox( dbox, xbox, ybox, zbox ) ;
3974  
3975   sciAxesVerticesIndices( InsideU, InsideD, xbox, ybox, xind ) ;
3976
3977   return 0;
3978 }
3979
3980 /* don't waste time on %NaN */
3981 int CheckIfiisNan(int j, int dim, int * tab)
3982 {
3983   int i;
3984
3985   for(i=0;i<dim;i++)
3986   {
3987     if(tab[i] == j)
3988       return -1;
3989   }
3990
3991   return 0;
3992 }
3993
3994
3995
3996 int ComputeGoodTrans3d( sciPointObj * psubwin, int n, int *xm, int *ym, double * fx, double *fy, double *fz)
3997 {
3998   sciSubWindow * ppsubwin = pSUBWIN_FEATURE(psubwin);
3999
4000   
4001   double tmp_fx = *fx;
4002   double tmp_fy = *fy;
4003   double tmp_fz = *fz;
4004   
4005   if(ppsubwin->logflags[0] == 'l')
4006     tmp_fx = exp10(tmp_fx);
4007   
4008   if(ppsubwin->logflags[1] == 'l')
4009     tmp_fy = exp10(tmp_fy);
4010   
4011   if(ppsubwin->logflags[2] == 'l')
4012     tmp_fz = exp10(tmp_fz);
4013   
4014   trans3d(psubwin, n, xm, ym, &tmp_fx, &tmp_fy, &tmp_fz);
4015   
4016   return 0;
4017 }
4018
4019
4020 /**DrawAxesIfRequired
4021  * Draws Axes (only the basic  graphicobject under subwindows) in its SubWindow or figure
4022  * if and only if pFIGURE_FEATURE(pobj)->auto_redraw == TRUE !!
4023  * Only used inside High Level functions calls (sucha as plot2d, plot3d...)
4024  * @param sciPointObj * pobj: the pointer to the entity
4025  * @return  int 0 if OK, -1 if not
4026  */
4027 void DrawAxesIfRequired(sciPointObj * pobj)
4028 {
4029   sciPointObj * pfigure = sciGetParentFigure(pobj);
4030   
4031   if( pFIGURE_FEATURE(pfigure)->auto_redraw && pFIGURE_FEATURE(pfigure)->visible )
4032   {
4033     DrawAxes(pobj);
4034   }
4035   
4036 }
4037
4038 /* Routine used inside Plo2dn.c, Champ.c, Gray.c... */
4039 /* to force the drawing of the axes after a new object is created */
4040 void DrawAxes(sciPointObj * pobj)
4041 {
4042   sciPointObj * psubwin = sciGetParentSubwin(pobj);
4043   /*   sciPointObj * pfigure = sciGetParentFigure(pobj); */
4044   char STRFLAG[4];
4045   integer x[6], v, markidsizenew[2];
4046   double dv;
4047
4048   if (!sciGetVisibility(pobj)) return;
4049   
4050   x[0] = sciGetForeground (psubwin);
4051   x[2] = sciGetLineWidth (psubwin);
4052   x[3] = sciGetLineStyle (psubwin);
4053   markidsizenew[0] = sciGetMarkStyle(psubwin);
4054   markidsizenew[1] = sciGetLineWidth (psubwin);
4055   x[4] = 0;
4056   v = 0;
4057   dv = 0;
4058
4059   
4060   sciSetSelectedSubWin(psubwin); 
4061   
4062   set_scale ("tttftt", pSUBWIN_FEATURE (psubwin)->WRect, pSUBWIN_FEATURE (psubwin)->FRect,
4063              NULL, pSUBWIN_FEATURE (psubwin)->logflags, 
4064              pSUBWIN_FEATURE (psubwin)->ARect); 
4065      
4066   if (!pSUBWIN_FEATURE (psubwin)->is3d)   /* we are in 2D mode...*/
4067     {
4068       /* F.Leray 07.12.04 */
4069       /* TO CORRECT the bug 1115 : Big object (grayplots) could cover axes*/
4070       C2F (dr) ("xset","dashes",x,x,x+4,x+4,x+4,&v,&dv,&dv,&dv,&dv,5L,4096);
4071       C2F (dr) ("xset","foreground",x,x,x+4,x+4,x+4,&v,&dv,&dv,&dv,&dv,5L,4096);
4072       C2F (dr) ("xset","thickness",x+2,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4073       C2F (dr) ("xset","mark",&markidsizenew[0],&markidsizenew[1],PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4074
4075       rebuild_strflag(psubwin,STRFLAG);
4076       axis_draw2 (STRFLAG); /* Axes is rebuilt here to avoid being covered by the new created object */
4077     }
4078 }
4079
4080
4081 /* Used only when switching from a plot3d to a plot2d or 
4082  * when typing: a=gca();
4083  *              a.view='2d' and we were in 3d 
4084  * to have a good update of 3d graphics scale in 2D
4085  * whenever we are in auto_redraw OFF  */
4086 void UpdateSubwinScale(sciPointObj * pobj)
4087 {
4088   sciSubWindow * ppsubwin = pSUBWIN_FEATURE (pobj);
4089   sciPointObj * currentsubwin = NULL;
4090   BOOL vis_save = FALSE;
4091   double xbox[8],ybox[8],zbox[8];
4092   static integer InsideU[4],InsideD[4];
4093         
4094   currentsubwin = (sciPointObj *)sciGetSelectedSubWin (sciGetCurrentFigure ());
4095
4096   sciSetSelectedSubWin(pobj); 
4097   
4098   /*   set_scale ("tttftt", pSUBWIN_FEATURE (pobj)->WRect, pSUBWIN_FEATURE (pobj)->FRect, */
4099   /*         NULL, pSUBWIN_FEATURE (pobj)->logflags,  */
4100   /*         pSUBWIN_FEATURE (pobj)->ARect);  */
4101   
4102   if (ppsubwin->is3d) 
4103     {  /* 3D Coordinates */ /* verifier si c'est encore utile SS */
4104       /*To have directly all the possible ISOVIEW Modes*/
4105       long isoflag = (long)(ppsubwin->axes.flag[1]+1)/2; 
4106       
4107       if(ppsubwin->isoview == TRUE) {
4108         if(isoflag ==2 || isoflag == 3){                }
4109         else {
4110           if((ppsubwin->axes.flag[1] == 0)
4111              || (ppsubwin->axes.flag[1] == 2))
4112             /* The default isoview mode is type=4 3d isometric bounds 
4113                derived from the data, to similarily type=2  */
4114             ppsubwin->axes.flag[1] = 4; 
4115           else if(ppsubwin->axes.flag[1] == 1)
4116             ppsubwin->axes.flag[1] = 3;
4117         }
4118       }
4119       else {
4120         if((ppsubwin->axes.flag[1] == 3) 
4121            || (ppsubwin->axes.flag[1] == 5))
4122           ppsubwin->axes.flag[1] = 1; /* computed from ebox*/
4123         else if((ppsubwin->axes.flag[1] == 4) 
4124                 || (ppsubwin->axes.flag[1] == 6))
4125           /* The default NON-isoview mode is 2 computed from data*/
4126           ppsubwin->axes.flag[1] = 2; 
4127       }
4128       
4129
4130       vis_save = sciGetVisibility(pobj);
4131
4132       sciSetVisibility(pobj,FALSE);
4133       axis_3ddraw(pobj,xbox,ybox,zbox,InsideU,InsideD); /* TEST on sciGetVisibility inside */
4134       /* because axis_3ddraw displays 3d axes BUT ALSO compute + reset the 3d scale BEFORE !! */
4135       sciSetVisibility(pobj,vis_save);
4136     }
4137   else /* we are in 2D mode...*/
4138     {
4139       sci_update_frame_bounds_2d(pobj);
4140     }
4141
4142   sciSetSelectedSubWin(currentsubwin); 
4143   
4144 }
4145
4146 int Gen3DPoints(integer type,integer *polyx, integer *polyy, integer *fill, integer whiteid, double zmin, double zmax, double *x, double *y, double *z, integer i, integer j, integer jj1, integer *p, integer dc, integer fg, sciPointObj * psurface)
4147 {
4148   sciPointObj *pobj;
4149   int facteur = 1;
4150
4151   sciPointObj *psubwin = sciGetSelectedSubWin (sciGetCurrentFigure ());
4152   sciSubWindow * ppsubwin = pSUBWIN_FEATURE(psubwin);
4153   sciSurface * ppsurface = pSURFACE_FEATURE (psurface);
4154   
4155   pobj = sciGetSelectedSubWin (sciGetCurrentFigure ()); 
4156   if (trans3d(pobj ,1, &(polyx[  5*jj1]),&(polyy[  5*jj1]),&(x[i]),&(y[j]),&(z[i+(*p)*j]))==0) return 0; 
4157   if (trans3d(pobj ,1, &(polyx[1+  5*jj1]),&(polyy[1+  5*jj1]),&(x[i]),&(y[j+1]),&(z[i+(*p)*(j+1)]))==0) return 0; 
4158   if (trans3d(pobj ,1, &(polyx[2+  5*jj1]),&(polyy[2+  5*jj1]),&(x[i+1]),&(y[j+1]),&(z[(i+1)+(*p)*(j+1)]))==0) return 0; 
4159   if (trans3d(pobj ,1, &(polyx[3+  5*jj1]),&(polyy[3+  5*jj1]),&(x[i+1]),&(y[j]),&(z[(i+1)+(*p)*j]))==0) return 0;   
4160   if (trans3d(pobj ,1, &(polyx[4+  5*jj1]),&(polyy[4+  5*jj1]),&(x[i]),&(y[j]),&(z[i+(*p)*j]))==0) return 0; 
4161   
4162   
4163   if(ppsubwin->axes.reverse[0] == TRUE) facteur = -facteur;
4164   if(ppsubwin->axes.reverse[1] == TRUE) facteur = -facteur;
4165   if(ppsubwin->axes.reverse[2] == TRUE) facteur = -facteur;
4166   
4167   /* try */
4168   facteur = ppsurface->flag_x * ppsurface->flag_y * facteur;
4169   
4170   /* type == flagcolor and dc == color_mode */
4171   /* fg = hidden color */
4172   
4173   if ((((polyx[1+5*jj1]-polyx[0+5*jj1])*(polyy[2+5*jj1]-polyy[0+5*jj1])-
4174         (polyy[1+5*jj1]-polyy[0+5*jj1])*(polyx[2+5*jj1]-polyx[0+5*jj1]))*facteur <  0) && (fg >=0 )) 
4175     {
4176       
4177       /* ------------------- */
4178       /* Beneath the surface */
4179       /* ------------------- */
4180
4181       if (type != 0) /* flagcolor = 1 case : special treatment compared to flagcolor = 0 */
4182                      /* don't know why... F.Leray */
4183         fill[jj1]= (dc < 0 ) ? -fg : fg ;
4184       else           /* flagcolor = 0 :  No shading at all, fixed facecolor. */
4185         fill[jj1]=  (dc != 0 ) ? fg : dc ;
4186     }
4187   else
4188     {
4189
4190       /* ------------------- */
4191       /* Above the surface */
4192       /* ------------------- */
4193
4194      if (type != 0)
4195         {  /* flagcolor = 1 :  Z-level flat shading. */
4196           fill[jj1]=inint((whiteid-1)*((1/4.0*( z[i+(*p)*j]+ z[i+1+(*p)*j]+
4197                                                 z[i+(*p)*(j+1)]+ z[i+1+(*p)*(j+1)])-zmin)
4198                                        /(zmax-zmin)))+1;
4199           if ( dc < 0 ) fill[jj1]= -fill[jj1];  
4200         }
4201       else
4202         fill[jj1]= dc;     
4203     }
4204   
4205   return(1);
4206   
4207 }
4208
4209
4210
4211 int Merge3dDimension(sciPointObj *pparent)
4212 {
4213   integer N,q; 
4214   sciSons *psonstmp;
4215
4216   /* ========================================================================
4217    * Compute the number of facets, segments,... included in all the subwin 
4218    * children
4219    * Each entities to merge; is decomposed in a set of basic elements 
4220    *  (facet, segment, point,...)
4221    * Each basic element is represented in the Merge structure by the handle of its entity and an 
4222    *   index within this entity
4223    * ========================================================================*/
4224
4225   q=0;
4226   psonstmp = sciGetSons (pparent);
4227   while (psonstmp != (sciSons *) NULL) {   
4228     switch (sciGetEntityType (psonstmp->pointobj)) {  
4229     case SCI_SURFACE:
4230       if (pSURFACE_FEATURE (psonstmp->pointobj)->typeof3d == SCI_PLOT3D) 
4231         N=(pSURFACE_FEATURE (psonstmp->pointobj)->dimzx-1)*(pSURFACE_FEATURE (psonstmp->pointobj)->dimzy-1);
4232       else
4233         N = pSURFACE_FEATURE (psonstmp->pointobj)->dimzy;
4234       break;
4235
4236     case  SCI_POLYLINE:
4237       {
4238         if ( pPOLYLINE_FEATURE(psonstmp->pointobj)->n1 == 0 )
4239         {
4240           N = 0 ;
4241         }
4242         else if (pPOLYLINE_FEATURE (psonstmp->pointobj)->plot != 5)
4243         {/*polyline*/
4244           N = pPOLYLINE_FEATURE (psonstmp->pointobj)->n1-1;
4245           if ((pPOLYLINE_FEATURE (psonstmp->pointobj)->plot != 2) && 
4246             (sciGetIsMark((sciPointObj *)psonstmp->pointobj) == 1))
4247           {
4248             N = N + 1 ;
4249           }
4250         }
4251         else /* patch */
4252         {
4253           N = 1 ;
4254         }
4255       }
4256       break;
4257     case  SCI_SEGS: 
4258       N=pSEGS_FEATURE (psonstmp->pointobj)->Nbr1 / 2 ;
4259       break;
4260     case  SCI_RECTANGLE: 
4261       N = 4;
4262       break;
4263     case SCI_AGREG:
4264       N =  Merge3dDimension(psonstmp->pointobj);
4265       break;
4266     default:
4267       N=0;
4268     }
4269     q+=N;
4270     psonstmp = psonstmp->pnext;
4271   }
4272
4273   return q;
4274 }
4275
4276 int ChildrenCounter(sciPointObj *pparent)
4277 {
4278   int N,q=0;
4279   sciSons * psonstmp = sciGetSons (pparent);
4280   
4281   while (psonstmp != (sciSons *) NULL) {   
4282     switch (sciGetEntityType (psonstmp->pointobj)) {  
4283     case SCI_SURFACE:
4284       N=1;
4285       break;
4286     case  SCI_POLYLINE:
4287       N = 1; 
4288       break;
4289     case  SCI_SEGS: 
4290       N=1;
4291       break;
4292     case  SCI_RECTANGLE: 
4293       N = 1;
4294       break;
4295     case SCI_AGREG:
4296       N = ChildrenCounter(psonstmp->pointobj);
4297       break;
4298     default:
4299       N=0;
4300     }
4301     q+=N;
4302     psonstmp = psonstmp->pnext;
4303   }
4304
4305   return q;
4306 }
4307
4308
4309 void Merge3dBuildTable(sciPointObj *pparent, int *index_in_entity, long *from_entity, int *pos)
4310 {
4311   sciSons *psonstmp;
4312   int i,N;
4313
4314   psonstmp = sciGetSons (pparent);
4315
4316   while (psonstmp != (sciSons *) NULL) {   
4317     switch (sciGetEntityType (psonstmp->pointobj)) {  
4318     case SCI_SURFACE:
4319       if (pSURFACE_FEATURE (psonstmp->pointobj)->typeof3d == SCI_PLOT3D) 
4320         N=(pSURFACE_FEATURE (psonstmp->pointobj)->dimzx-1)*(pSURFACE_FEATURE (psonstmp->pointobj)->dimzy-1);
4321       else
4322         N = pSURFACE_FEATURE (psonstmp->pointobj)->dimzy;
4323       break;
4324     case  SCI_POLYLINE:
4325       if ( pPOLYLINE_FEATURE(psonstmp->pointobj)->n1 == 0 )
4326       {
4327         N = 0 ;
4328       }
4329       else if (pPOLYLINE_FEATURE (psonstmp->pointobj)->plot != 5)
4330       {/*polyline*/
4331         N = pPOLYLINE_FEATURE (psonstmp->pointobj)->n1-1;
4332         if ((pPOLYLINE_FEATURE (psonstmp->pointobj)->plot != 2) && 
4333             (sciGetIsMark((sciPointObj *)psonstmp->pointobj) == 1))
4334         {
4335           N = N + 1 ;
4336         }
4337       }
4338       else /* patch */
4339       {
4340         N = 1 ;
4341       }
4342       break;
4343     case  SCI_SEGS: 
4344       N=pSEGS_FEATURE (psonstmp->pointobj)->Nbr1/2;
4345       break;
4346     case  SCI_RECTANGLE: 
4347       N = 4;
4348       break;
4349     case SCI_AGREG:
4350       Merge3dBuildTable(psonstmp->pointobj, index_in_entity, from_entity, pos);
4351       break;
4352     default:
4353       N = 0;
4354     }
4355     if (sciGetEntityType (psonstmp->pointobj) != SCI_AGREG)
4356       for (i=0 ; i<N; i++) {
4357         index_in_entity[*pos]=i;
4358         from_entity[*pos]=(long) sciGetHandle (psonstmp->pointobj);
4359         *pos=*pos+1;
4360       }
4361     psonstmp = psonstmp->pnext;
4362   }
4363 }
4364
4365
4366 void Merge3d(sciPointObj *psubwin)
4367 {
4368   integer q,k; 
4369   sciPointObj *pmerge; 
4370   int *index_in_entity;
4371   long *from_entity;
4372   
4373   if(sciGetEntityType (psubwin) != SCI_SUBWIN) return; 
4374   if ((pmerge= sciGetMerge(psubwin)) != (sciPointObj *) NULL)
4375     DestroyMerge(pmerge); 
4376   
4377   /* ========================================================================
4378    * Compute the number of facets, segments,... included in all the subwin 
4379    * children
4380    * ========================================================================*/
4381   
4382   
4383   q =  Merge3dDimension(psubwin);
4384   
4385   
4386   /* ========================================================================
4387    * allocate tables for index and handles
4388    * ========================================================================*/
4389   
4390   /* q now contains the total number of elements */
4391   if ((index_in_entity = (int *) MALLOC (q * sizeof (int))) == (int *)NULL) {
4392     sciprint("Merge3d : not enough memory to allocate \n");
4393     return;
4394   }
4395   if ((from_entity   = (long *) MALLOC (q * sizeof (long))) == (long *) NULL) {
4396     sciprint("Merge3d : not enough memory to allocate \n");
4397     FREE(index_in_entity);
4398   }
4399   
4400   /* ========================================================================
4401    * fill the index and handles tables
4402    * ========================================================================*/
4403   k=0;
4404   Merge3dBuildTable(psubwin, index_in_entity, from_entity, &k);
4405   
4406   /* ========================================================================
4407    * create the Merge data structure
4408    * ========================================================================*/
4409   
4410   if ((pmerge=ConstructMerge ((sciPointObj *) psubwin,q,index_in_entity,from_entity)) == (sciPointObj *) NULL) {
4411     FREE(index_in_entity);
4412     FREE(from_entity);
4413     sciprint ("\r\n No merge supported");}
4414   else /* inform the subwindow to display Merge instead of individual children */
4415     pSUBWIN_FEATURE (psubwin)->facetmerge = TRUE;
4416   
4417 }
4418
4419 /*------------------------------------------------------------------------------------------*/
4420 /**
4421  * draw the figure number numFigure.
4422  */
4423 void sciDrawFigure( int numFigure )
4424 {
4425   int curFigure = sciGetNumFigure( sciGetCurrentFigure() ) ;
4426   sciSetUsedWindow( numFigure ) ;
4427   sciDrawObj( sciGetCurrentFigure() ) ;
4428   sciSetUsedWindow( curFigure ) ;
4429 }
4430 /*------------------------------------------------------------------------------------------*/
4431
4432 /*-------------------------------------------------------------------------------------------*/
4433 /* sciRefreshObj                                                                             */
4434 /* draw an object but before select the rigth figure for display                             */
4435 /*-------------------------------------------------------------------------------------------*/
4436 int sciRefreshObj( sciPointObj * pobj )
4437 {
4438   
4439   int parentId = sciGetNum( sciGetParentFigure( pobj ) ) ;
4440   int currentId             ;
4441   int status                ;
4442   int verboseGet        = 0 ;
4443   int iDontKnowWhatItIs     ;
4444   /* get current Id in ScilabXgc */
4445   C2F (dr) ("xget", "window",&verboseGet,&currentId,&iDontKnowWhatItIs,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4446
4447   /* set the parent figure of the object as the current figure */
4448   if ( parentId != currentId )
4449   {
4450     C2F (dr) ("xset", "window",&parentId,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4451   }
4452   
4453   /* draw the object */
4454   status = sciDrawObjIfRequired( pobj ) ;
4455
4456   /* set back the values */
4457   if ( parentId != currentId )
4458   {
4459     C2F (dr) ("xset", "window",&currentId,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4460   }
4461
4462   return status ;
4463   
4464   
4465 }
4466
4467
4468
4469 /**sciDrawObjIfRequired
4470  * Draws Object (only the basic  graphicobject under subwindows) in its SubWindow or figure
4471  * if and only if pFIGURE_FEATURE(pobj)->auto_redraw == TRUE !!
4472  * Only used inside High Level functions calls (sucha as plot2d, plot3d...)
4473  * @param sciPointObj * pobj: the pointer to the entity
4474  * @return  int 0 if OK, -1 if not
4475  */
4476 int
4477 sciDrawObjIfRequired (sciPointObj * pobj)
4478 {
4479   sciPointObj * pfigure = sciGetParentFigure(pobj);
4480
4481   if( pFIGURE_FEATURE(pfigure)->auto_redraw && pFIGURE_FEATURE(pfigure)->visible )
4482   {
4483     sciDrawObj(pobj);
4484   }
4485
4486   return 0;
4487 }
4488
4489 /**sciDrawObj
4490  * Draws Object (only the basic  graphicobject under subwindows) in its SubWindow or figure
4491  * @param sciPointObj * pobj: the pointer to the entity
4492  * @return  int 0 if OK, -1 if not
4493  */
4494 int
4495 sciDrawObj (sciPointObj * pobj)
4496 {
4497   
4498   /*sciPointObj * curSubWin = sciGetSelectedSubWin( sciGetCurrentFigure() ) ;*/
4499   
4500   /* driver test */  
4501   if((GetDriverId() != 0) && ( isGraphicSessionOpened() )){
4502     return -1;
4503   }
4504
4505   switch (sciGetEntityType (pobj))
4506     {
4507     case SCI_FIGURE:
4508       return drawFigureEntity( pobj ) ;
4509       break;
4510     case SCI_SUBWIN:
4511       return drawSubWinEntity( pobj ) ;
4512       break ;
4513     case SCI_AGREG:
4514       return drawCompoundEntity( pobj ) ;
4515       break;
4516     case SCI_LEGEND:
4517       return drawLegendEntity( pobj ) ;
4518       break;   
4519     case SCI_FEC:
4520       return drawFecEntity( pobj ) ;
4521       break;      
4522     case SCI_SEGS:
4523       return drawSegsEntity( pobj ) ;
4524       break;
4525     case SCI_GRAYPLOT:
4526       return drawGrayplotEntity( pobj ) ;
4527       break;
4528     case SCI_POLYLINE:   
4529       return drawPolylineEntity( pobj ) ;
4530       break;
4531     case SCI_ARC:
4532       return drawArcEntity( pobj ) ;
4533       break;
4534     case SCI_RECTANGLE:
4535       return drawRectangleEntity( pobj ) ;
4536       break;
4537     case SCI_TEXT:
4538       return drawTextEntity( pobj ) ;
4539       break;
4540     case SCI_AXES:
4541       return drawAxesEntity(pobj) ;
4542       break;
4543     case SCI_MERGE:
4544       return drawMergeEntity(pobj) ;
4545       break ;
4546     case SCI_SURFACE:
4547       return drawSurfaceEntity(pobj) ;
4548       break;
4549     case SCI_LIGHT:
4550     case SCI_PANNER:
4551     case SCI_SBH:
4552     case SCI_SBV:
4553     case SCI_MENU:
4554     case SCI_MENUCONTEXT:
4555     case SCI_STATUSB:
4556     default:
4557       return -1;
4558       break;
4559     }
4560   /*sciSetSelectedSubWin (curSubWin);*/
4561   return -1;
4562 }
4563
4564
4565
4566
4567 /* F.Leray 25.02.05 */
4568 /* This function is used to determine how the pixel data*/
4569 /* is given to Xt method (like XDrawLines) */
4570 /* 0 : pixel itself */
4571 /* 1 : pixel's interval */
4572 /* Explanation :*/
4573 /* i.e.in X11 (same thing using Win32 driver), with x2=x1+1 and y1=y2, we have : */
4574 /*   XDrawLine(x1,y1,x1,y1)  does nothing (no pixel lit) */
4575 /*   XDrawLine(x1,y1,x2,y2)  ONE pixel lit */
4576 /* BUT the corresponding function with driver Gif (and others?) give us: */
4577 /* for now (and only for marks), I make a trick using a pixel_offset set to 0 or 1 */
4578 /* depending on the driver. */
4579
4580 /* slight modif from Bruno : if fact GetDriverId return also 0 */
4581 /* if gtk is enable so I have added a call to withgtk to get the */
4582 /* the good pixel_offset */
4583
4584
4585
4586 int AdaptGraduationsOnYBottomLeft(int iof, int x, int y, int size, integer *Ticsdir, int *fontid, sciPointObj * psubwin, double yminval, double ymaxval, double fx, double fy, double fz)
4587 {
4588   int i;
4589   int nbtics, nbsubtics;
4590   int lastyindex;
4591   int old_rect[4];
4592   int nb_grads_max = 0;
4593   int vx[2], vy[2];
4594   int xm, ym;
4595   double grads_tmp[20];
4596   char c_format[5];
4597   integer barlengthx = 0,barlengthy = 0;
4598   integer rect[4],posi[2];
4599   integer textcolor = -1;
4600   int logrect[4] ;
4601   int XX = 0 ;
4602   int YY = 0 ;
4603   int pas;
4604   double fact_h = 1.5, fact_w = 1.5;
4605   int compteur = 0;
4606
4607   int possible_pas, possible_compteur;
4608   
4609   sciSubWindow * ppsubwin = pSUBWIN_FEATURE(psubwin);
4610   
4611   for(i=0;i<4;i++) { old_rect[i] = 0 ; } /* Init. old_rect to force first grad. to be displayed */
4612   
4613   lastyindex = ppsubwin->axes.nygrads - 1;
4614   
4615   if(lastyindex == 0)
4616     ChooseFormatForOneGrad(c_format,&(ppsubwin->axes.ygrads[0]));
4617   else
4618     ChoixFormatE(c_format,
4619                  ppsubwin->axes.ygrads[0],
4620                  ppsubwin->axes.ygrads[lastyindex],
4621                  ((ppsubwin->axes.ygrads[lastyindex])-(ppsubwin->axes.ygrads[0]))/(lastyindex));
4622   
4623   nbtics = ppsubwin->axes.nygrads;
4624   nbsubtics = ppsubwin->axes.nbsubtics[1];
4625   
4626   
4627   for(i=0;i<nbtics;i++) grads_tmp[i] = ppsubwin->axes.ygrads[i];
4628
4629   for(i=0;i<nbtics;i++)
4630     {
4631       char foo[256];
4632       double ytmp = ppsubwin->axes.ygrads[i];
4633                   
4634                   
4635       sprintf(foo,c_format,ytmp);
4636
4637       /***************************************************************/
4638       /************************* COMMON PART *************************/
4639       /***************************************************************/
4640       if(ppsubwin->axes.reverse[1] == TRUE)
4641         ytmp = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],ytmp);
4642                   
4643       ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&ytmp,&fz);
4644                   
4645       vx[0]=xm;vy[0]=ym;
4646                   
4647       barlengthx= (integer) (( Ticsdir[0])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
4648       barlengthy= (integer) (( Ticsdir[1])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
4649
4650       C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); /* fix bug noticed by R.N. */
4651       C2F(dr)("xstringl",foo,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4652                       
4653       
4654       if (IsDownAxes(psubwin)){
4655         vx[1]=vx[0];
4656         vy[1]=vy[0]+iof/2;
4657         posi[0] = inint(xm-rect[2]/2);
4658         posi[1]=inint( vy[0] + iof + rect[3]);}
4659       else{
4660         vx[1]=vx[0]+barlengthx;
4661         vy[1]=vy[0]+barlengthy;
4662 /*      posi[0] = inint( xm+2*barlengthx-rect[2]/2);  */
4663         posi[0] = inint( xm+2*barlengthx-rect[2]);
4664         posi[1]=inint( ym + 2*barlengthy + rect[3]);}
4665       
4666       /* compute bounding of "10"  string used for log scale ON and auto_ticks ON */
4667       C2F(dr)("xstringl","10",&XX,&YY,logrect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4668       
4669       
4670       if(CheckDisplay(fact_h, fact_w, ppsubwin->logflags[1],foo,posi,fontid,old_rect) == 0)
4671         continue; /*  graduation too close, DO NOT display the graduation ! */
4672       
4673       
4674       C2F(dr)("xset","pattern",&textcolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4675       C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4676       if ( ppsubwin->logflags[1] == 'l' )
4677         {
4678           int smallersize = fontid[1]-2;
4679           int old_rect10[4];
4680           int posi10[2];
4681
4682           posi10[0] = posi[0] - logrect[2];
4683           posi10[1] = posi[1] + logrect[3];
4684           
4685           C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4686           
4687           C2F(dr)("xstringl","10",(&posi10[0]),(&posi10[1]),old_rect10,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4688           
4689           posi[0] = old_rect10[0] + old_rect10[2];
4690           posi[1] = (int) (old_rect10[1] - old_rect10[3]*.1);
4691           
4692           C2F(dr)("xset","font",fontid,&smallersize,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4693           C2F(dr)("xstringl",foo,(&posi[0]),(&posi[1]),old_rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4694           
4695           /* update old_rect */
4696           old_rect[2] = (int)(fact_w*(old_rect[2] + (double)old_rect10[2]));
4697           old_rect[3] = (int)(fact_h*(old_rect[3] + old_rect10[3] + (int) (old_rect10[3]*.1)));
4698           old_rect[0] = old_rect10[0];
4699           old_rect[1] = old_rect[1];
4700           
4701           nb_grads_max++;
4702           
4703           /* put back the current fontid */
4704           C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4705         }
4706       else{
4707         /* update old_rect */
4708         C2F(dr)("xstringl",foo,(&posi[0]),(&posi[1]),old_rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4709         old_rect[3] = (int)(fact_h* old_rect[3]);
4710         old_rect[2] = (int)(fact_w* old_rect[2]);
4711         nb_grads_max++;
4712       }
4713     }
4714   
4715   if(ppsubwin->logflags[1] != 'l')
4716     if(nb_grads_max == 1) /* only one grad. can be displayed : we choose to display the average value (max+min)/2 */
4717       {
4718         ppsubwin->axes.ygrads[0] = (grads_tmp[0]+grads_tmp[lastyindex])/2.;
4719         ppsubwin->axes.nygrads = 1;
4720         
4721         if ( !ppsubwin->flagNax )
4722         {
4723           /* don't change the number if it aldready has been specified */
4724           ppsubwin->axes.nbsubtics[1] = 1 ;
4725         }
4726         return 0;
4727       }
4728   
4729   
4730   pas = nbtics - 2; /* pas == grads number - 2 */
4731   
4732   possible_pas = -99;
4733   possible_compteur = -99;
4734   
4735   while(pas > 0)
4736     {
4737       int tmp = 0;
4738       compteur = 0;
4739       for(;;)
4740         {
4741           tmp = tmp + pas;
4742           compteur++;
4743           
4744           if((tmp == (nbtics - 1)) && (compteur < nb_grads_max)){
4745             possible_pas = pas;
4746             possible_compteur = ++compteur;
4747             break;
4748           }
4749           
4750           if(tmp > (nbtics - 1))
4751             break;
4752         }
4753       
4754       pas--;
4755     }
4756   
4757   
4758   if(possible_compteur != -99){
4759     compteur = possible_compteur;
4760     pas = possible_pas;
4761     
4762     for(i=0;i<compteur;i++)
4763       ppsubwin->axes.ygrads[i] = grads_tmp[i*pas];
4764     
4765     ppsubwin->axes.nygrads = compteur;
4766     
4767     /* Nb of subtics computation and storage */
4768     /* jb Silvy 01/2006 : default value was Max((int) abs((13-compteur)/2),2) */
4769     ppsubwin->axes.nbsubtics[1] = ComputeNbSubTicsFor3dUse(psubwin,
4770                                                            ppsubwin->axes.nygrads,
4771                                                            ppsubwin->logflags[1],
4772                                                            ppsubwin->axes.ygrads,
4773                                                            ppsubwin->axes.nbsubtics[1]);
4774   }
4775   else{
4776     ppsubwin->axes.ygrads[0] = grads_tmp[0];
4777     ppsubwin->axes.ygrads[1] = grads_tmp[lastyindex];
4778     ppsubwin->axes.nygrads = 2;
4779     /* Nb of subtics computation and storage */
4780     /* jb Silvy 01/2006 : default value was Max((int) abs((13-compteur)/2),2) */
4781     ppsubwin->axes.nbsubtics[1] = ComputeNbSubTicsFor3dUse(psubwin,
4782                                                            ppsubwin->axes.nygrads,
4783                                                            ppsubwin->logflags[1],
4784                                                            ppsubwin->axes.ygrads,
4785                                                            ppsubwin->axes.nbsubtics[1]);
4786     
4787     if(ppsubwin->logflags[1] == 'n'){
4788       if(nb_grads_max > 4) {
4789         /* we could display at least 4 graduations but we did not find a proper interval... */
4790         /* To avoid to display only the min and max (see above), we add 2 newly created grads by interpolating between min and max */
4791         double pas_ = (grads_tmp[lastyindex]-grads_tmp[0])/3;
4792         for(i=0;i<3;i++){
4793           ppsubwin->axes.ygrads[i] = grads_tmp[0] + i*pas_;
4794         }
4795         
4796         ppsubwin->axes.ygrads[3] = grads_tmp[lastyindex]; /* exact max */
4797         ppsubwin->axes.nygrads = 4;
4798         /* Nb of subtics computation and storage */
4799         ppsubwin->axes.nbsubtics[1] = ComputeNbSubTicsFor3dUse(psubwin,
4800                                                                ppsubwin->axes.nygrads,
4801                                                                'n',
4802                                                                ppsubwin->axes.ygrads,
4803                                                                ppsubwin->axes.nbsubtics[1]);
4804       }
4805     }
4806   }
4807   
4808   return 0;
4809 }
4810
4811
4812 int AdaptGraduationsOnXBottomLeft(int iof, int x, int y, int size, integer *Ticsdir, int *fontid, sciPointObj * psubwin, double xminval, double xmaxval, double fx, double fy, double fz)
4813 {
4814   int i;
4815   int nbtics, nbsubtics;
4816   int lastxindex;
4817   int old_rect[4];
4818   int nb_grads_max = 0;
4819   int vx[2], vy[2];
4820   int xm, ym;
4821   double grads_tmp[20];
4822   char c_format[5];
4823   integer barlengthx = 0,barlengthy = 0;
4824   integer rect[4],posi[2]; 
4825   integer textcolor = -1;
4826   int logrect[4],XX,YY;
4827   int pas;
4828   double fact_h = 1.5, fact_w = 1.5;
4829   int compteur = 0;
4830
4831   int possible_pas, possible_compteur;
4832   
4833   sciSubWindow * ppsubwin = pSUBWIN_FEATURE(psubwin);
4834   
4835   for(i=0;i<4;i++) old_rect[i] = 0; /* Init. old_rect to force first grad. to be displayed */
4836   
4837   lastxindex = ppsubwin->axes.nxgrads - 1;
4838   
4839   if(lastxindex == 0)
4840     ChooseFormatForOneGrad(c_format,&(ppsubwin->axes.xgrads[0]));
4841   else
4842     ChoixFormatE(c_format,
4843                  ppsubwin->axes.xgrads[0],
4844                  ppsubwin->axes.xgrads[lastxindex],
4845                  ((ppsubwin->axes.xgrads[lastxindex])-(ppsubwin->axes.xgrads[0]))/(lastxindex));
4846   
4847   nbtics = ppsubwin->axes.nxgrads;
4848   nbsubtics = ppsubwin->axes.nbsubtics[0];
4849   
4850   
4851   for(i=0;i<nbtics;i++) grads_tmp[i] = ppsubwin->axes.xgrads[i];
4852
4853   for(i=0;i<nbtics;i++)
4854     {
4855       char foo[256]; 
4856       double xtmp = ppsubwin->axes.xgrads[i];
4857                   
4858 /*       if(xtmp<xminval || xtmp>xmaxval)  */
4859 /*      { */
4860 /*        /\*   sciprint("je rejete la valeur: %lf\n\n",xtmp); *\/ */
4861 /*        continue; /\* cas ou TL est ON et on a des graduations qui ne seront pas affichees de tte facon *\/ */
4862 /*        /\* donc autant ne pas aller plus loin dans l'algo... *\/ */
4863 /*      } */
4864                   
4865       sprintf(foo,c_format,xtmp);
4866
4867       /***************************************************************/
4868       /************************* COMMON PART *************************/
4869       /***************************************************************/
4870       if(ppsubwin->axes.reverse[0] == TRUE)
4871         xtmp = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],xtmp);
4872                   
4873       ComputeGoodTrans3d(psubwin,1,&xm,&ym,&xtmp,&fy,&fz);
4874                   
4875       vx[0]=xm;vy[0]=ym; 
4876                   
4877       barlengthx= (integer) (( Ticsdir[0])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
4878       barlengthy= (integer) (( Ticsdir[1])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
4879
4880       C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); /* fix bug noticed by R.N. */
4881       C2F(dr)("xstringl",foo,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4882       
4883
4884 /*       if (IsDownAxes(psubwin)){ */
4885 /*      vx[1]=vx[0]; */
4886 /*      vy[1]=vy[0]+iof/2; */
4887 /*      posi[0] = inint(xm-rect[2]/2);  */
4888 /*      posi[1]=inint( vy[0] + iof + rect[3]);} */
4889 /*       else{ */
4890 /*      vx[1]=vx[0]+barlengthx; */
4891 /*      vy[1]=vy[0]+barlengthy; */
4892 /*      posi[0] = inint( xm+2*barlengthx); */
4893 /*      posi[1]=inint( ym + 2*barlengthy + rect[3]);} */
4894                       
4895       if (IsDownAxes(psubwin)){
4896         vx[1]=vx[0];
4897         vy[1]=vy[0]+iof/2;
4898         posi[0] = inint(xm-rect[2]/2); 
4899         posi[1]=inint( vy[0] + iof + rect[3]);}
4900       else{
4901         vx[1]=vx[0]+barlengthx;
4902         vy[1]=vy[0]+barlengthy;
4903         posi[0] = inint( xm+2*barlengthx-rect[2]); 
4904         posi[1]=inint( ym + 2*barlengthy + rect[3]);}
4905       
4906       /* compute bounding of "10"  string used for log scale ON and auto_ticks ON */
4907       C2F(dr)("xstringl","10",&XX,&YY,logrect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);       
4908       
4909       
4910       if(CheckDisplay(fact_h, fact_w, ppsubwin->logflags[0],foo,posi,fontid,old_rect) == 0)
4911         continue; /*  graduation too close, DO NOT display the graduation ! */
4912       
4913       
4914       C2F(dr)("xset","pattern",&textcolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4915       C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4916       if ( ppsubwin->logflags[0] == 'l' )
4917         {
4918           int smallersize = fontid[1]-2;
4919           int old_rect10[4];
4920           int posi10[2];
4921
4922           posi10[0] = posi[0] - logrect[2];
4923           posi10[1] = posi[1] + logrect[3];
4924           
4925           C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4926           
4927           C2F(dr)("xstringl","10",(&posi10[0]),(&posi10[1]),old_rect10,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4928           
4929           posi[0] = old_rect10[0] + old_rect10[2];
4930           posi[1] = (int) (old_rect10[1] - old_rect10[3]*.1);
4931           
4932           C2F(dr)("xset","font",fontid,&smallersize,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4933           C2F(dr)("xstringl",foo,(&posi[0]),(&posi[1]),old_rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4934           
4935           /* update old_rect */
4936           old_rect[2] = (int)(fact_w*(old_rect[2] + old_rect10[2]));
4937           old_rect[3] = (int)(fact_h*(old_rect[3] + old_rect10[3] + (int) (old_rect10[3]*.1)));
4938           old_rect[0] = old_rect10[0];
4939           old_rect[1] = old_rect[1];
4940           
4941           nb_grads_max++;
4942           
4943           /* put back the current fontid */
4944           C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4945         }
4946       else{
4947         /* update old_rect */
4948         C2F(dr)("xstringl",foo,(&posi[0]),(&posi[1]),old_rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4949         old_rect[3] = (int)(fact_h* old_rect[3]);
4950         old_rect[2] = (int)(fact_w* old_rect[2]);
4951         nb_grads_max++;
4952       }
4953     }
4954   
4955   if(ppsubwin->logflags[0] != 'l')
4956     if(nb_grads_max == 1) /* only one grad. can be displayed : we choose to display the average value (max+min)/2 */
4957       {
4958         ppsubwin->axes.xgrads[0] = (grads_tmp[0]+grads_tmp[lastxindex])/2.;
4959         ppsubwin->axes.nxgrads = 1;
4960         if ( !ppsubwin->flagNax )
4961         {
4962           ppsubwin->axes.nbsubtics[0] = 1;
4963         }
4964         return 0;
4965       }
4966   
4967   
4968   pas = nbtics - 2; /* pas == grads number - 2 */
4969   
4970   possible_pas = -99;
4971   possible_compteur = -99;
4972   
4973   while(pas > 0)
4974     {
4975       int tmp = 0;
4976       compteur = 0;
4977       for(;;)
4978         {
4979           tmp = tmp + pas;
4980           compteur++;
4981           
4982           if((tmp == (nbtics - 1)) && (compteur < nb_grads_max)){
4983             possible_pas = pas;
4984             possible_compteur = ++compteur;
4985             break;
4986           }
4987           
4988           if(tmp > (nbtics - 1))
4989             break;
4990         }
4991       
4992       pas--;
4993     }
4994   
4995   
4996   if(possible_compteur != -99){
4997     compteur = possible_compteur;
4998     pas = possible_pas;
4999     
5000     for(i=0;i<compteur;i++)
5001       ppsubwin->axes.xgrads[i] = grads_tmp[i*pas];
5002     
5003     ppsubwin->axes.nxgrads = compteur;
5004     
5005     /* Nb of subtics computation and storage */
5006     /* jb Silvy 01/2006 : default value was Max((int) abs((13-compteur)/2),2) */
5007     ppsubwin->axes.nbsubtics[0] = ComputeNbSubTicsFor3dUse(psubwin,
5008                                                            ppsubwin->axes.nxgrads,
5009                                                            ppsubwin->logflags[0],
5010                                                            ppsubwin->axes.xgrads,
5011                                                            ppsubwin->axes.nbsubtics[0]); 
5012   }
5013   else{
5014     ppsubwin->axes.xgrads[0] = grads_tmp[0];
5015     ppsubwin->axes.xgrads[1] = grads_tmp[lastxindex];
5016     ppsubwin->axes.nxgrads = 2;
5017     /* Nb of subtics computation and storage */
5018     /* jb Silvy 01/2006 : default value was Max((int) abs((13-compteur)/2),2) */
5019     ppsubwin->axes.nbsubtics[0] = ComputeNbSubTicsFor3dUse(psubwin,
5020                                                            ppsubwin->axes.nxgrads,
5021                                                            ppsubwin->logflags[0],
5022                                                            ppsubwin->axes.xgrads,
5023                                                            ppsubwin->axes.nbsubtics[0]); 
5024     
5025     if(ppsubwin->logflags[0] == 'n'){
5026       if(nb_grads_max > 4) {
5027         /* we could display at least 4 graduations but we did not find a proper interval... */
5028         /* To avoid to display only the min and max (see above), we add 2 newly created grads by interpolating between min and max */
5029         double pas_ = (grads_tmp[lastxindex]-grads_tmp[0])/3;
5030         for(i=0;i<3;i++){
5031           ppsubwin->axes.xgrads[i] = grads_tmp[0] + i*pas_;
5032         }
5033         
5034         ppsubwin->axes.xgrads[3] = grads_tmp[lastxindex]; /* exact max */
5035         ppsubwin->axes.nxgrads = 4;
5036         
5037         /* Nb of subtics computation and storage */
5038         /* jb Silvy 01/2006 : default value was Max((int) abs((13-compteur)/2),2) */
5039         ppsubwin->axes.nbsubtics[0] = ComputeNbSubTicsFor3dUse(psubwin,
5040                                                                ppsubwin->axes.nxgrads,
5041                                                                'n',
5042                                                                ppsubwin->axes.xgrads,
5043                                                                ppsubwin->axes.nbsubtics[0]); 
5044       }
5045     }
5046   }
5047   
5048   return 0;
5049 }
5050
5051
5052
5053 int AdaptGraduationsOnYBottomRight(int iof, int x, int y, int size, integer *Ticsdir, int *fontid, sciPointObj * psubwin, double yminval, double ymaxval, double fx, double fy, double fz)
5054 {
5055   int i;
5056   int nbtics, nbsubtics;
5057   int lastyindex;
5058   int old_rect[4];
5059   int nb_grads_max = 0;
5060   int vx[2], vy[2];
5061   int xm, ym;
5062   double grads_tmp[20];
5063   char c_format[5];
5064   integer barlengthx = 0,barlengthy = 0;
5065   integer rect[4],posi[2]; 
5066   integer textcolor = -1;
5067   int logrect[4] ;
5068   int XX = 0 ;
5069   int YY = 0 ;
5070   int pas;
5071   double fact_h = 1.5, fact_w = 1.5;
5072   int compteur = 0;
5073
5074   int possible_pas, possible_compteur;
5075   
5076   sciSubWindow * ppsubwin = pSUBWIN_FEATURE(psubwin);
5077   
5078   for(i=0;i<4;i++) old_rect[i] = 0; /* Init. old_rect to force first grad. to be displayed */
5079   
5080   lastyindex = ppsubwin->axes.nygrads - 1;
5081   
5082   if(lastyindex == 0)
5083     ChooseFormatForOneGrad(c_format,&(ppsubwin->axes.ygrads[0]));
5084   else
5085     ChoixFormatE(c_format,
5086                  ppsubwin->axes.ygrads[0],
5087                  ppsubwin->axes.ygrads[lastyindex],
5088                  ((ppsubwin->axes.ygrads[lastyindex])-(ppsubwin->axes.ygrads[0]))/(lastyindex));
5089   
5090   nbtics = ppsubwin->axes.nygrads;
5091   nbsubtics = ppsubwin->axes.nbsubtics[1];
5092   
5093   
5094   for(i=0;i<nbtics;i++) grads_tmp[i] = ppsubwin->axes.ygrads[i];
5095
5096   for(i=0;i<nbtics;i++)
5097     {
5098       char foo[256]; 
5099       double ytmp = ppsubwin->axes.ygrads[i];
5100                   
5101       sprintf(foo,c_format,ytmp);
5102
5103       /***************************************************************/
5104       /************************* COMMON PART *************************/
5105       /***************************************************************/
5106       if(ppsubwin->axes.reverse[1] == TRUE)
5107         ytmp = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],ytmp);
5108                   
5109       ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&ytmp,&fz);
5110                   
5111       vx[0]=xm;vy[0]=ym; 
5112                   
5113       barlengthx= (integer) (( Ticsdir[0])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
5114       barlengthy= (integer) (( Ticsdir[1])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
5115
5116       C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); /* fix bug noticed by R.N. */
5117       C2F(dr)("xstringl",foo,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5118       
5119
5120       if (IsDownAxes(psubwin)){
5121         vx[1]=vx[0];
5122         vy[1]=vy[0]+iof/2;
5123         posi[0] = inint(xm-rect[2]/2); 
5124         posi[1]=inint( vy[0] + iof + rect[3]);}
5125       else{
5126         vx[1]=vx[0]+barlengthx;
5127         vy[1]=vy[0]+barlengthy;
5128         posi[0] = inint( xm+2*barlengthx);
5129         posi[1]=inint( ym + 2*barlengthy + rect[3]);}
5130                       
5131       
5132       /* compute bounding of "10"  string used for log scale ON and auto_ticks ON */
5133       C2F(dr)("xstringl","10",&XX,&YY,logrect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);       
5134       
5135       
5136       if(CheckDisplay(fact_h, fact_w, ppsubwin->logflags[1],foo,posi,fontid,old_rect) == 0)
5137         continue; /*  graduation too close, DO NOT display the graduation ! */
5138       
5139       
5140       C2F(dr)("xset","pattern",&textcolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5141       C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5142       if ( ppsubwin->logflags[1] == 'l' )
5143         {
5144           int smallersize = fontid[1]-2;
5145           int old_rect10[4];
5146           int posi10[2];
5147
5148           posi10[0] = posi[0] - logrect[2];
5149           posi10[1] = posi[1] + logrect[3];
5150           
5151           C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5152           
5153           C2F(dr)("xstringl","10",(&posi10[0]),(&posi10[1]),old_rect10,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5154           
5155           posi[0] = old_rect10[0] + old_rect10[2];
5156           posi[1] = (int) (old_rect10[1] - old_rect10[3]*.1);
5157           
5158           C2F(dr)("xset","font",fontid,&smallersize,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5159           C2F(dr)("xstringl",foo,(&posi[0]),(&posi[1]),old_rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5160           
5161           /* update old_rect */
5162           old_rect[2] = (int)(fact_w*(old_rect[2] + old_rect10[2]));
5163           old_rect[3] = (int)(fact_h*(old_rect[3] + old_rect10[3] + (int) (old_rect10[3]*.1)));
5164           old_rect[0] = old_rect10[0];
5165           old_rect[1] = old_rect[1];
5166           
5167           nb_grads_max++;
5168           
5169           /* put back the current fontid */
5170           C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5171         }
5172       else{
5173         /* update old_rect */
5174         C2F(dr)("xstringl",foo,(&posi[0]),(&posi[1]),old_rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5175         old_rect[3] = (int)(fact_h* old_rect[3]);
5176         old_rect[2] = (int)(fact_w* old_rect[2]);
5177         nb_grads_max++;
5178       }
5179     }
5180   
5181   if(ppsubwin->logflags[1] != 'l')
5182     if(nb_grads_max == 1) /* only one grad. can be displayed : we choose to display the average value (max+min)/2 */
5183       {
5184         ppsubwin->axes.ygrads[0] = (grads_tmp[0]+grads_tmp[lastyindex])/2.;
5185         ppsubwin->axes.nygrads = 1;
5186         if ( !ppsubwin->flagNax )
5187         {
5188           ppsubwin->axes.nbsubtics[1] = 1;
5189         }
5190         return 0;
5191       }
5192   
5193   
5194   pas = nbtics - 2; /* pas == grads number - 2 */
5195   
5196   possible_pas = -99;
5197   possible_compteur = -99;
5198   
5199   while(pas > 0)
5200     {
5201       int tmp = 0;
5202       compteur = 0;
5203       for(;;)
5204         {
5205           tmp = tmp + pas;
5206           compteur++;
5207           
5208           if((tmp == (nbtics - 1)) && (compteur < nb_grads_max)){
5209             possible_pas = pas;
5210             possible_compteur = ++compteur;
5211             break;
5212           }
5213           
5214           if(tmp > (nbtics - 1))
5215             break;
5216         }
5217       
5218       pas--;
5219     }
5220   
5221   
5222   if(possible_compteur != -99){
5223     compteur = possible_compteur;
5224     pas = possible_pas;
5225     
5226     for(i=0;i<compteur;i++)
5227       ppsubwin->axes.ygrads[i] = grads_tmp[i*pas];
5228     
5229     ppsubwin->axes.nygrads = compteur;
5230     
5231     /* Nb of subtics computation and storage */
5232     /* jb Silvy 01/2006 : default value was Max((int) abs((13-compteur)/2),2) */
5233     ppsubwin->axes.nbsubtics[1] = ComputeNbSubTicsFor3dUse(psubwin,
5234                                                            ppsubwin->axes.nygrads,
5235                                                            ppsubwin->logflags[1],
5236                                                            ppsubwin->axes.ygrads,
5237                                                            ppsubwin->axes.nbsubtics[1]);
5238   }
5239   else{
5240     ppsubwin->axes.ygrads[0] = grads_tmp[0];
5241     ppsubwin->axes.ygrads[1] = grads_tmp[lastyindex];
5242     ppsubwin->axes.nygrads = 2;
5243
5244     /* Nb of subtics computation and storage */
5245     /* jb Silvy 01/2006 : default value was Max((int) abs((13-compteur)/2),2) */
5246     ppsubwin->axes.nbsubtics[1] = ComputeNbSubTicsFor3dUse(psubwin,
5247                                                            ppsubwin->axes.nygrads,
5248                                                            ppsubwin->logflags[1],
5249                                                            ppsubwin->axes.ygrads,
5250                                                            ppsubwin->axes.nbsubtics[1]);
5251     
5252     if(ppsubwin->logflags[1] == 'n'){
5253       if(nb_grads_max > 4) {
5254         /* we could display at least 4 graduations but we did not find a proper interval... */
5255         /* To avoid to display only the min and max (see above), we add 2 newly created grads by interpolating between min and max */
5256         double pas_ = (grads_tmp[lastyindex]-grads_tmp[0])/3;
5257         for(i=0;i<3;i++){
5258           ppsubwin->axes.ygrads[i] = grads_tmp[0] + i*pas_;
5259         }
5260         
5261         ppsubwin->axes.ygrads[3] = grads_tmp[lastyindex]; /* exact max */
5262         ppsubwin->axes.nygrads = 4;
5263         /* Nb of subtics computation and storage */
5264         /* jb Silvy 01/2006 : default value was Max((int) abs((13-compteur)/2),2) */
5265         ppsubwin->axes.nbsubtics[1] = ComputeNbSubTicsFor3dUse(psubwin,
5266                                                                ppsubwin->axes.nygrads,
5267                                                                'n',
5268        &