Fix bug 2540
[scilab.git] / scilab / modules / graphics / src / c / sciCall.c
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2002-2004 - INRIA - Djalel Abdemouche
4  * Copyright (C) 2004-2006 - INRIA - Fabrice Leray
5  * Copyright (C) 2005 - INRIA - Jean-Baptiste Silvy
6  *
7  * This file must be used under the terms of the CeCILL.
8  * This source file is licensed as described in the file COPYING, which
9  * you should have received as part of this distribution.  The terms
10  * are also available at
11  * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
12  *
13  */
14
15 /*------------------------------------------------------------------------
16  *    Graphic library
17  *    Graphic subroutines interface
18  --------------------------------------------------------------------------*/
19 #include <math.h>
20 #include <stdio.h>
21 #include <string.h>
22
23 #include "SetProperty.h"
24 #include "GetProperty.h"
25 #include "DrawObjects.h"
26 #include "BuildObjects.h"
27 #include "InitObjects.h"
28 #include "BasicAlgos.h"
29 #include "math_graphics.h"
30 #include "PloEch.h"
31 #include "Axes.h"
32 #include "Scierror.h"
33 #include "Fec.h"
34 #include "GrayPlot.h"
35 #include "CurrentObjectsManagement.h"
36 #include "GraphicSynchronizerInterface.h"
37 #include "localization.h"
38 #include "MALLOC.h" /* MALLOC */
39 #include "Scierror.h"
40 #include "sciCall.h"
41 #include "DrawingBridge.h"
42 #include "Plot2d.h"
43
44 /**
45  * Put min and max of vector in dMin and dMax.
46  * If no min and max can't be found (no finite data in dMin or dMax),
47  * then use the default values
48  */
49 static void getDrect(const double vector[], int nbElements,
50                                                                                  double * dMin, double * dMax,
51                                                                                  double defaultMin, double defaultMax);
52 /*------------------------------------------------
53  * Objrect :
54  * On recupere la figure courante, puis on recupere la sous fenetre qui y est selectionnee
55  *   puis on contruit le rectangle, qu on le place comme objet courant
56  * ensuite il reste qu'appeler la fonction du dessin de l'objet
57  *-----------------------------------------------*/
58
59 void Objrect ( double * x         ,
60                double * y         ,
61                double * width     ,
62                double * height    ,
63                int    * foreground,
64                int    * background,
65                BOOL     isfilled  ,
66                BOOL     isline    ,
67                long   * hdl       )
68 {
69   sciPointObj * newObj = NULL ;
70   sciPointObj *psubwin;
71   sciPointObj * pFigure = sciGetCurrentFigure();
72
73   psubwin = sciGetCurrentSubWin();
74   /* check if the auto_clear property is on and then erase everything */
75   checkRedrawing() ;
76   newObj = ConstructRectangle(psubwin ,*x,*y,*height, *width,
77                               foreground, background, isfilled, isline) ;
78
79   if ( newObj == NULL )
80   {
81     endFigureDataWriting(pFigure);
82     /* an error occured */
83     *hdl = -1 ;
84     return ;
85   }
86   sciSetCurrentObj( newObj ) ;
87   *hdl=sciGetHandle( newObj ) ;
88
89 }
90
91
92 /*----------------------------------------------
93  * Objarc :
94  *-----------------------------------------------*/
95
96 void Objarc( double * angle1    ,
97              double * angle2    ,
98              double * x         ,
99              double * y         ,
100              double * width     ,
101              double * height    ,
102              int    * foreground,
103              int    * background,
104              BOOL     isfilled  ,
105              BOOL     isline    ,
106              long   * hdl        )
107 {
108   sciPointObj * psubwin;
109   sciPointObj * pobj;
110
111   psubwin = sciGetCurrentSubWin() ;
112   checkRedrawing() ;
113   pobj = ConstructArc(psubwin,*x,*y,
114                       *height, *width, *angle1, *angle2, foreground, background, isfilled, isline);
115   sciSetCurrentObj(pobj);
116
117   *hdl=sciGetHandle(pobj);
118 }
119
120 /*------------------------------------------------
121  * Objpoly :
122  *-----------------------------------------------*/
123
124 void Objpoly ( double  * x     ,
125                double  * y     ,
126                int   n     ,
127                int   closed,
128                int       mark  ,
129                long    * hdl    )
130 {
131   sciPointObj * pFigure = NULL;
132   sciPointObj * psubwin;
133   sciPointObj * pobj;
134
135   pFigure = sciGetCurrentFigure();
136   psubwin = sciGetCurrentSubWin();
137
138
139   checkRedrawing() ;
140   if (mark <= 0)
141     {
142       int absmark = abs(mark);
143       pobj = ConstructPolyline(psubwin,x,y,PD0,closed,n,1,
144                                NULL,NULL,&absmark,NULL,NULL,FALSE,FALSE,TRUE,FALSE);
145     }
146   else
147     {
148       pobj = ConstructPolyline(psubwin,x,y,PD0,closed,n,1,
149                                &mark,NULL,NULL,NULL,NULL,TRUE,FALSE,FALSE,FALSE);
150     }
151   sciSetCurrentObj(pobj);
152    *hdl=sciGetHandle(pobj);
153 }
154
155
156 /*------------------------------------------------
157  * Objfpoly :
158  *-----------------------------------------------*/
159
160 void Objfpoly ( double  * x    ,
161                 double  * y    ,
162                 int   n    ,
163                 int * style,
164                 long    * hdl  ,
165                 int   shading )
166 {
167   int fillcolor, contourcolor;
168   sciPointObj *psubwin, *pobj;
169   int closed = 1; /* we close the polyline by default */
170   psubwin = sciGetCurrentSubWin();
171
172   checkRedrawing() ;
173
174   if(shading == 2)
175     {
176       /* interpolated shading is "on" */
177       pobj = ConstructPolyline(psubwin,x,y,PD0,closed,n,
178                                1,NULL,style,NULL,NULL,NULL,FALSE,TRUE,FALSE,TRUE);
179     }
180   else
181     {
182       /* flat mode is "on" */
183       if (*style < 0){
184         fillcolor = abs(*style);
185         pobj = ConstructPolyline(psubwin,x,y,PD0,closed,n,
186                                  1,NULL,&fillcolor,NULL,NULL,NULL,FALSE,TRUE,FALSE,FALSE);
187       }
188       else if (*style == 0){
189         contourcolor = sciGetForeground(psubwin);
190         pobj = ConstructPolyline(psubwin,x,y,PD0,closed,n,
191                                  1,&contourcolor,NULL,NULL,NULL,NULL,TRUE,FALSE,FALSE,FALSE);
192       }
193       else{ /* *style > 0*/
194         fillcolor = *style;
195         contourcolor = sciGetForeground(psubwin);
196         pobj = ConstructPolyline(psubwin,x,y,PD0,closed,n,
197                                  1,&contourcolor,&fillcolor,NULL,NULL,NULL,TRUE,TRUE,FALSE,FALSE);
198       }
199
200     }
201     sciSetCurrentObj(pobj);
202     *hdl=sciGetHandle(pobj);
203
204 }
205
206
207 /*-----------------------------------------------------------
208  *   Objsegs :
209  *-----------------------------------------------------------*/
210 void Objsegs ( int * style,
211                int   flag ,
212                int   n1   ,
213                double  * x    ,
214                double  * y    ,
215                double    arsize )
216 {
217   int type=0,n2, colored=0;
218   double *fx,*fy,arfact=1.0;
219   int typeofchamp = -1; /* no champ here, only segs ; this info is useless */
220   sciPointObj *psubwin = sciGetCurrentSubWin();
221
222   checkRedrawing() ;
223
224   n2=n1;
225   fx=x;fy=y;
226   sciSetCurrentObj (ConstructSegs(psubwin,type,
227                                   x,y,n1,n2,fx,fy,flag,style,arsize,colored,arfact,typeofchamp));
228 }
229 /*-----------------------------------------------------------
230  * Objstring:
231  *-----------------------------------------------------------*/
232
233 /* box is an OUTPUT re-used inside matdes.c in scixstring */
234 void Objstring( char            ** fname      ,
235                 int                nbRow      ,
236                 int                nbCol      ,
237                 double             x          ,
238                 double             y          ,
239                 double           * angle      ,
240                 double             box[4]     ,
241                 BOOL               autoSize   ,
242                 double             userSize[2],
243                 long             * hdl        ,
244                 BOOL               centerPos  ,
245                 int              * foreground ,
246                 int              * background ,
247                 BOOL               isboxed    ,
248                 BOOL               isline     ,
249                 BOOL               isfilled   ,
250                 sciTextAlignment   alignment   )
251 {
252   sciPointObj * psubwin = NULL;
253   sciPointObj * pobj = NULL;
254   sciPointObj * pFigure = NULL;
255
256   startGraphicDataWriting();
257   pFigure = sciGetCurrentFigure();
258   psubwin = sciGetCurrentSubWin();
259   endGraphicDataWriting();
260
261   checkRedrawing() ;
262
263   startFigureDataWriting(pFigure);
264   sciSetCurrentObj( ConstructText( psubwin   ,
265                                    fname     ,
266                                    nbRow     ,
267                                    nbCol     ,
268                                    x         ,
269                                    y         ,
270                                    autoSize  ,
271                                    userSize  ,
272                                    centerPos ,
273                                    foreground,
274                                    background,
275                                    isboxed   ,
276                                    isline    ,
277                                    isfilled  ,
278                                    alignment  ) ) ;
279   endFigureDataWriting(pFigure);
280
281   startFigureDataReading(pFigure);
282   pobj=sciGetCurrentObj ();
283   *hdl= sciGetHandle(pobj);
284   sciSetFontOrientation (pobj, *angle);
285
286   sciDrawObj(pobj);
287   endFigureDataReading(pFigure);
288
289 }
290
291
292 /*------------------------------------------------
293  *  plot2d
294  *-----------------------------------------------*/
295
296 void Objplot2d ( int       ptype     ,
297                  char      logflags[],
298                  double    x[]       ,
299                  double    y[]       ,
300                  int * n1        ,
301                  int * n2        ,
302                  int   style[]   ,
303                  char      strflag[] ,
304                  char      legend[]  ,
305                  double    brect[]   ,
306                  int   aaint[]   ,
307                  BOOL      flagNax    )
308 {
309   plot2dn(ptype,logflags,x,y,n1,n2,style,strflag,legend,brect,aaint,flagNax,4L,bsiz);
310 }
311
312 /*------------------------------------------------
313  *  grayplot
314  *-----------------------------------------------*/
315 void Objgrayplot ( double    x[]      ,
316                    double    y[]      ,
317                    double    z[]      ,
318                    int * n1       ,
319                    int * n2       ,
320                    char      strflag[],
321                    double    brect[]  ,
322                    int   aaint[]  ,
323                    BOOL      flagNax   )
324 {
325   C2F(xgray)(x,y,z,n1,n2,strflag, brect, aaint, flagNax, bsiz );
326 }
327
328 /*------------------------------------------------
329  *  Matplot
330  *-----------------------------------------------*/
331 void Objmatplot (double    z[]      ,
332                  int * n1       ,
333                  int * n2       ,
334                  char      strflag[],
335                  double    brect[]  ,
336                  int    aaint[]  ,
337                  BOOL      flagNax   )
338 {
339   C2F(xgray1)(z,n1,n2,strflag, brect, aaint, flagNax, bsiz);
340 }
341
342 /*------------------------------------------------
343  *  Matplot1
344  *-----------------------------------------------*/
345 void Objmatplot1 ( double    z[],
346                    int * n1 ,
347                    int * n2 ,
348                    double    xrect[] )
349 {
350   C2F(xgray2)(z, n1, n2,xrect);
351 }
352
353 /*------------------------------------------------
354  *  plot3d
355  *-----------------------------------------------*/
356 void Objplot3d ( char    * fname ,
357                  int * isfac ,
358                  int * izcol ,
359                  double    x[]   ,
360                  double    y[]   ,
361                  double    z[]   ,
362                  double  * zcol  ,
363                  int * m     ,
364                  int * n     ,
365                  double  * theta ,
366                  double  * alpha ,
367                  char    * legend,
368                  int * iflag ,
369                  double  * ebox  ,
370                  int * m1    , /*Adding F.Leray 12.03.04 and 19.03.04*/
371                  int * n1    ,
372                  int * m2    ,
373                  int * n2    ,
374                  int * m3    ,
375                  int * n3    ,
376                  int * m3n   ,
377                  int * n3n    )
378      /* F.Leray 25.04.05 : warning here legends means "X@Y@Z": it is labels writings!! */
379      /* legends has not the same meaning than inside plot2dn (there, it is really the legends of the plotted curves)*/
380 {
381         sciTypeOf3D typeof3d;
382         int flagcolor;
383         long *hdltab;
384         int i;
385         sciPointObj *psubwin = NULL, *pobj = NULL;
386         sciPointObj * parentFigure = NULL;
387         double drect[6];
388         char * loc = NULL;
389         char * legx = NULL;
390         char * legy = NULL;
391         char * legz = NULL;
392         /*   char * buff = NULL; */
393         int flag_x = 1;
394         int flag_y = 1;
395         int dimvectx = -1;
396         int dimvecty = -1;
397         char linLogFlags[3] = {'n','n','n'};
398
399         sciPointObj  * pNewSurface = NULL ;
400         sciSubWindow * ppsubwin = NULL;
401         BOOL bounds_changed = FALSE; /* cannot be used here because we have to force redrawing since there is no way to avoid merge (=> complete redraaw) */
402
403         /* Initialisation drect A.C pour debuggueur */
404         drect[0] = 0.0;
405         drect[1] = 0.0;
406         drect[2] = 0.0;
407         drect[3] = 0.0;
408         drect[4] = 0.0;
409         drect[5] = 0.0;
410
411         /* =================================================
412         * Force SubWindow properties according to arguments
413         * ================================================= */
414         startGraphicDataWriting();
415         parentFigure = sciGetCurrentFigure();
416         psubwin= sciGetCurrentSubWin();
417         endGraphicDataWriting();
418
419         startFigureDataWriting(parentFigure);
420         checkRedrawing() ;
421
422         /* Force psubwin->is3d to TRUE: we are in 3D mode */
423         pSUBWIN_FEATURE (psubwin)->is3d = TRUE;
424         pSUBWIN_FEATURE (psubwin)->project[2] = 1; /* to force z axis display */
425
426         ppsubwin = pSUBWIN_FEATURE(psubwin);
427
428         if ( legend != NULL )
429         {
430                 /* F.Leray 25.04.05 replace the default labels by the user labels if specified */
431                 loc=(char *) MALLOC( (strlen(legend)+1)*sizeof(char));
432                 if ( loc == NULL) {
433                         Scierror(999, _("%s: No more memory.\n"),"Objplot3d");
434                 }
435
436                 strcpy(loc,legend);
437
438                 /*   legx=strtok_r(loc,"@",&buff); */
439                 legx=strtok(loc,"@");
440
441                 if (legx != NULL)
442                 {
443                         sciSetText( ppsubwin->mon_x_label, &legx , 1, 1 ) ;
444                 }
445
446                 /*   legy=strtok_r((char *)0,"@",&buff); */
447                 legy=strtok((char *)NULL,"@"); /* NULL to begin at the last read character */
448                 if ( legy != NULL )
449                 {
450                         sciSetText( ppsubwin->mon_y_label, &legy , 1, 1 ) ;
451                 }
452
453                 /*   legz=strtok_r((char *)0,"@",&buff); */
454                 legz=strtok((char *)NULL,"@");
455                 if ( legz != NULL )
456                 {
457                         sciSetText( ppsubwin->mon_z_label, &legz , 1, 1 ) ;
458                 }
459         }
460
461         /* Force psubwin->logflags to linear */
462         sciSetLogFlags(psubwin, linLogFlags);
463
464
465         pSUBWIN_FEATURE (psubwin)->axes.flag[0] = iflag[0]; /* mode: treatment of hidden parts */
466         if (iflag[1] != 0){
467                 if (iflag[1]<7)
468                         pSUBWIN_FEATURE (psubwin)->axes.flag[1] = iflag[1]; /* type: scaling (no more useful)  */
469                 else
470                         pSUBWIN_FEATURE (psubwin)->axes.flag[1] = iflag[1]-6; /* type: scaling (no more useful)  */
471         }
472
473         if( pSUBWIN_FEATURE (psubwin)->FirstPlot == FALSE && (iflag[2] == 0 || iflag[2] == 1))
474         {
475                 /* Nothing to do: we leave as before */
476         }
477         else
478         {
479                 pSUBWIN_FEATURE (psubwin)->axes.flag[2] = iflag[2]; /* box: frame around the plot      */
480
481                 if(iflag[2] == 0 || iflag[2] == 1)
482                 {
483
484                         if (pSUBWIN_FEATURE(psubwin)->FirstPlot)
485                         {
486                                 pSUBWIN_FEATURE (psubwin)->axes.axes_visible[0] = FALSE;
487                                 pSUBWIN_FEATURE (psubwin)->axes.axes_visible[1] = FALSE;
488                                 pSUBWIN_FEATURE (psubwin)->axes.axes_visible[2] = FALSE;
489                                 pSUBWIN_FEATURE (psubwin)->axes.rect = BT_OFF ;
490
491                                 sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_x_label,FALSE);
492                                 sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_y_label,FALSE);
493                                 sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_z_label,FALSE);
494                         }
495                         /*else no changes : the axes visible properties are driven by the previous plot */
496                 }
497                 else if(iflag[2] == 2)
498                 {
499                         pSUBWIN_FEATURE (psubwin)->axes.rect = BT_HIDDEN_AXIS ; /* for 2d use only (when switching to 2d mode) */
500
501                         pSUBWIN_FEATURE (psubwin)->axes.axes_visible[0] = FALSE;
502                         pSUBWIN_FEATURE (psubwin)->axes.axes_visible[1] = FALSE;
503                         pSUBWIN_FEATURE (psubwin)->axes.axes_visible[2] = FALSE;
504
505                         sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_x_label,FALSE);
506                         sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_y_label,FALSE);
507                         sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_z_label,FALSE);
508                 }
509                 else if(iflag[2] == 3)
510                 {
511                         pSUBWIN_FEATURE (psubwin)->axes.rect = BT_ON ; /* for 2d use only (when switching to 2d mode) */
512
513                         pSUBWIN_FEATURE (psubwin)->axes.axes_visible[0] = FALSE;
514                         pSUBWIN_FEATURE (psubwin)->axes.axes_visible[1] = FALSE;
515                         pSUBWIN_FEATURE (psubwin)->axes.axes_visible[2] = FALSE;
516
517                         sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_x_label,TRUE);
518                         sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_y_label,TRUE);
519                         sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_z_label,TRUE);
520                 }
521                 else if(iflag[2] == 4)
522                 {
523                         pSUBWIN_FEATURE (psubwin)->axes.rect = BT_ON ;
524
525                         pSUBWIN_FEATURE (psubwin)->axes.axes_visible[0] = TRUE;
526                         pSUBWIN_FEATURE (psubwin)->axes.axes_visible[1] = TRUE;
527                         pSUBWIN_FEATURE (psubwin)->axes.axes_visible[2] = TRUE;
528
529                         sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_x_label,TRUE);
530                         sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_y_label,TRUE);
531                         sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_z_label,TRUE);
532                 }
533         }
534
535         pSUBWIN_FEATURE (psubwin)->alpha  = *alpha;
536         pSUBWIN_FEATURE (psubwin)->theta  = *theta;
537
538         if ((sciGetGraphicMode (psubwin)->autoscaling)) {
539                 /* compute and merge new specified bounds with psubwin->Srect */
540                 switch (iflag[1])  {
541                 case 0:  /* do not change psubwin->Srect */
542                         break;
543                 case 1 : case 3 : case 5 : case 7 : /* Force psubwin->Srect=ebox */
544                         drect[0] = ebox[0]; /*xmin*/
545                         drect[2] = ebox[2]; /*ymin*/
546                         drect[1] = ebox[1]; /*xmax*/
547                         drect[3] = ebox[3]; /*ymax*/
548                         drect[4] = ebox[4]; /*zmin*/
549                         drect[5] = ebox[5]; /*zmax*/
550                         break;
551                 case 2 : case 4 : case 6 : case 8:/* Force psubwin->Srect to the x and y bounds */
552                         getDrect(x, (*m1) * (*n1), &drect[0], &drect[1],
553                                              pSUBWIN_FEATURE(psubwin)->SRect[0], pSUBWIN_FEATURE(psubwin)->SRect[1]);
554
555                         getDrect(y, (*m2) * (*n2), &drect[2], &drect[3],
556                                              pSUBWIN_FEATURE(psubwin)->SRect[2], pSUBWIN_FEATURE(psubwin)->SRect[3]);
557
558                         getDrect(z, (*m3) * (*n3), &drect[4], &drect[5],
559                                              pSUBWIN_FEATURE(psubwin)->SRect[4], pSUBWIN_FEATURE(psubwin)->SRect[5]);
560                         
561                         break;
562                 }
563                 if (!pSUBWIN_FEATURE(psubwin)->FirstPlot ) { /* merge psubwin->Srect and drect */
564                         drect[0] = Min(pSUBWIN_FEATURE(psubwin)->SRect[0],drect[0]); /*xmin*/
565                         drect[1] = Max(pSUBWIN_FEATURE(psubwin)->SRect[1],drect[1]); /*xmax*/
566                         drect[2] = Min(pSUBWIN_FEATURE(psubwin)->SRect[2],drect[2]); /*ymin*/
567                         drect[3] = Max(pSUBWIN_FEATURE(psubwin)->SRect[3],drect[3]); /*ymax*/
568                         drect[4] = Min(pSUBWIN_FEATURE(psubwin)->SRect[4],drect[4]); /*zmin*/
569                         drect[5] = Max(pSUBWIN_FEATURE(psubwin)->SRect[5],drect[5]); /*zmax*/
570                 }
571                 if (iflag[1] != 0)
572                 {
573                         bounds_changed = update_specification_bounds(psubwin, drect,3);
574                 }
575         }
576
577         if(iflag[1] != 0)
578                 pSUBWIN_FEATURE(psubwin)->isoview = (BOOL)( iflag[1] == 3 || iflag[1] == 4 ||
579                 iflag[1] == 5 || iflag[1] == 6);
580
581         /* =================================================
582         * Analyze arguments to find entity type
583         * ================================================= */
584
585         if (*isfac== 1) {
586                 if (*izcol == 0) {
587                         if (strcmp(fname,"plot3d1")==0) {typeof3d = SCI_FAC3D;   flagcolor=1;}
588                         else                               {typeof3d = SCI_FAC3D;   flagcolor=0;}
589                 }
590                 else if (*izcol == 2)                {typeof3d = SCI_FAC3D;   flagcolor=3;}
591                 else                                 {typeof3d = SCI_FAC3D;   flagcolor=2;}
592         }
593         else  if  (*isfac== 0) {
594                 if (strcmp(fname,"plot3d1")==0)   {typeof3d = SCI_PLOT3D;  flagcolor=1;}
595                 else                                 {typeof3d = SCI_PLOT3D;  flagcolor=0;}
596         }
597         else                                   {typeof3d = SCI_PARAM3D1;flagcolor=1;}
598
599
600         /* =================================================
601         * Construct the Entities
602         * ================================================= */
603
604         if ( typeof3d != SCI_PARAM3D1 ) {/*Distinction here between SCI_PARAM3D1 and others*/
605
606
607                 if ( *isfac == 1 )
608                 {
609                         /* x is considered as a matrix */
610                         dimvectx = -1 ;
611                 }
612                 else if ( *m1 == 1 ) /* x is a row vector */
613                 {
614                         dimvectx = *n1;
615                 }
616                 else if ( *n1 == 1 ) /* x is a column vector */
617                 {
618                         dimvectx = *m1;
619                 }
620                 else /* x is a matrix */
621                 {
622                         dimvectx = -1;
623                 }
624
625                 if ( dimvectx > 1 )
626                 {
627                         int monotony = checkMonotony( x, dimvectx ) ;
628                         if ( monotony == 0 )
629                         {
630                                 endFigureDataWriting(parentFigure);
631                                 Scierror(999, _("%s: x vector is not monotonous.\n"),"Objplot3d");
632                                 return;
633                         }
634
635                         flag_x = monotony ;
636                 }
637
638                 if ( *isfac == 1 )
639                 {
640                         /* y is considered as a matrix */
641                         dimvecty = -1 ;
642                 }
643                 else if ( *m2 == 1 ) /* y is a row vector */
644                 {
645                         dimvecty = *n2 ;
646                 }
647                 else if ( *n2 == 1 ) /* y is a column vector */
648                 {
649                         dimvecty = *m2 ;
650                 }
651                 else /* y is a matrix */
652                 {
653                         dimvecty = -1 ;
654                 }
655
656                 if( dimvecty > 1 )
657                 {
658                         /* test the monotony on y*/
659                         int monotony = checkMonotony( y, dimvecty ) ;
660                         if ( monotony == 0 )
661                         {
662                                 endFigureDataWriting(parentFigure);
663                                 Scierror(999, _("%s: x vector is not monotonous.\n"),"Objplot3d");
664                                 return ;
665                         }
666
667                         flag_y = monotony ;
668                 }
669
670                 pNewSurface = ConstructSurface( psubwin, typeof3d,
671                         x, y, z, zcol, *izcol, *m, *n, iflag,ebox,flagcolor,
672                         isfac,m1,n1,m2,n2,m3,n3,m3n,n3n) ;
673
674                 if ( pNewSurface == NULL )
675                 {
676                         endFigureDataWriting(parentFigure);
677                         return ;
678                 }
679
680                 sciSetCurrentObj( pNewSurface ) ;
681
682                 pSURFACE_FEATURE (pNewSurface)->flag_x = flag_x;
683                 pSURFACE_FEATURE (pNewSurface)->flag_y = flag_y;
684
685                 /* Force clipping */
686                 sciSetIsClipping(pNewSurface, 0);  /* clipgrf */
687
688
689         }
690         else
691         {
692                 if ((hdltab = MALLOC (*n * sizeof (long))) == NULL) {
693                         endFigureDataWriting(parentFigure);
694                         Scierror(999,"%s: No more memory.\n",fname);
695                         return;
696                 }
697                 for (i = 0; i < *n; ++i) {
698                         /* F.Leray Pb here: In fact we do not create a Surface but one or several 3D Polylines
699                         Pb comes when wanting to access the fields "surface_color" or "flag" for example
700                         in function sciSet (cf. matdes.c).
701                         Question 1: Are these properties accessible from a SCI_PARAM3D1 ?
702                         Question 2: Is "flag" obsolete and replaced by "color_mode"?*/
703
704                         if ((*n > 0) && (zcol != (double *)NULL)) {
705                                 if ((int) zcol[i] > 0){
706                                         int intzcol = (int) zcol[i];
707                                         sciSetCurrentObj (ConstructPolyline
708                                                 (sciGetCurrentSubWin(),
709                                                 &(x[*m * i]),&(y[*m * i]),&(z[*m * i]),0,*m,1,
710                                                 &intzcol,NULL,NULL,NULL,NULL,TRUE,FALSE,FALSE,FALSE));
711                                 }
712                                 else {
713                                         int intzcol = (int) -zcol[i];
714                                         sciSetCurrentObj (ConstructPolyline
715                                                 (sciGetCurrentSubWin(),
716                                                 &(x[*m * i]),&(y[*m * i]),&(z[*m * i]),0,*m,1,
717                                                 NULL,NULL,&intzcol,NULL,NULL,FALSE,FALSE,TRUE,FALSE));
718                                 }
719                         }
720                         else { /* default case, nothing is given */
721                                 int curcolor = sciGetForeground(sciGetCurrentSubWin()); /* current color equivalent for new graphics mode */
722                                 sciSetCurrentObj (ConstructPolyline
723                                         (sciGetCurrentSubWin(),
724                                         &(x[*m * i]),&(y[*m * i]),&(z[*m * i]),0,*m,1,
725                                         &curcolor,NULL,NULL,NULL,NULL,TRUE,FALSE,FALSE,FALSE));
726                         }
727
728                         pobj = sciGetCurrentObj();
729
730                         hdltab[i]=sciGetHandle(pobj);
731                 }
732
733
734                 /** construct Compound and make it current object**/
735                 if ( *n>1 ) sciSetCurrentObj (ConstructCompound (hdltab, *n));
736                 FREE(hdltab);
737         }
738
739         /* =================================================
740         * Redraw Figure
741         * ================================================= */
742         // subwin has been modified
743         forceRedraw(psubwin);
744         endFigureDataWriting(parentFigure);
745         sciDrawObj(sciGetCurrentFigure ());
746
747         pSUBWIN_FEATURE(psubwin)->FirstPlot=FALSE;
748
749         FREE(loc); loc = NULL;
750
751 }
752 /*-----------------------------------------------------------
753  * Objaxis:
754  *-----------------------------------------------------------*/
755
756 void Objdrawaxis ( char     dir    ,
757                    char     tics   ,
758                    double * x      ,
759                    int    * nx     ,
760                    double * y      ,
761                    int    * ny     ,
762                    char   * val[]  ,
763                    int      subint ,
764                    char   * format ,
765                    int      font   ,
766                    int      textcol,
767                    int      ticscol,
768                    char     flag   ,
769                    int      seg    ,
770                    int      nb_tics_labels )
771 {
772   checkRedrawing() ;
773   sciSetCurrentObj (ConstructAxes
774                     ((sciPointObj *)
775                      sciGetCurrentSubWin(),
776                      dir,tics,x,*nx,y,*ny,val,subint,format,font,textcol,ticscol,flag,seg,nb_tics_labels));
777   sciDrawObjIfRequired(sciGetCurrentObj ());
778
779 }
780
781 /*-----------------------------------------------------------
782  * Objnumb:
783  *-----------------------------------------------------------*/
784
785 void Objnumb( char          * fname    ,
786               unsigned long   fname_len,
787               int         n        ,
788               int         flag     ,
789               double          x        ,
790               double          y        ,
791               double        * angle    ,
792               double        * box       )
793 {
794   /*** faire une macro scilab sur xstring ****/
795
796
797 }
798
799 /*------------------------------------------------
800  * fec
801  *-----------------------------------------------*/
802 void Objfec ( double    x[]        ,
803               double    y[]        ,
804               double    noeud[]    ,
805               double  * fun        ,
806               int * n          ,
807               int * m          ,
808               char      strflag[]  ,
809               char      legend[]   ,
810               double    brect[]    ,
811               int   aaint[]    ,
812               double    Zminmax[]  ,
813               int   Colminmax[],
814               int   ColOut[]   ,
815               BOOL      WithMesh   ,
816               BOOL      flagNax     )
817 {
818   C2F(fec)(x,y,noeud,fun,n,m,strflag,legend,brect,aaint,
819            Zminmax,Colminmax,ColOut,WithMesh,flagNax,4L,bsiz);
820 }
821 /*------------------------------------------------------------------------*/
822 static void getDrect(const double vector[], int nbElements,
823                                                                                  double * dMin, double * dMax,
824                                                                                  double defaultMin, double defaultMax)
825 {
826         if (containsOneFiniteElement(vector, nbElements))
827         {
828                 *dMin = Mini(vector, nbElements);
829                 *dMax = Maxi(vector, nbElements);
830         }
831         else
832         {
833                 *dMin = defaultMin;
834                 *dMax = defaultMax;
835         }
836 }
837 /*------------------------------------------------------------------------*/