Fix bug 4108
Jean-Baptiste Silvy [Fri, 27 Feb 2009 13:09:41 +0000 (14:09 +0100)]
12 files changed:
scilab/CHANGES_5.1.X
scilab/modules/cacsd/demos/tracking/track.dem.sce
scilab/modules/graphics/includes/Axes.h
scilab/modules/graphics/includes/GetProperty.h
scilab/modules/graphics/includes/ObjectStructure.h
scilab/modules/graphics/includes/SetProperty.h
scilab/modules/graphics/sci_gateway/c/sci_Legend.c
scilab/modules/graphics/src/c/Axes.c
scilab/modules/graphics/src/c/BuildObjects.c
scilab/modules/graphics/src/c/GetProperty.c
scilab/modules/graphics/src/c/SetProperty.c
scilab/modules/graphics/src/c/getHandleProperty/set_legend_location_property.c

index 60ad412..ce412d1 100644 (file)
@@ -515,6 +515,8 @@ Bug fixes:
 
 * bug 4106 fixed - bar and barh override drawlater/drawnow mode.
 
+* bug 4108 fixed - Argument location of function caption has no effect.
+
 * bug 4173 fixed - Graphic export : Style the text fonts is not respected when exporting to SVG.
 
 * Side effect in the setenvc function.
index 6e0c98d..3be64e1 100644 (file)
@@ -33,7 +33,7 @@ totrack=flts(uu(instants),dscr(Model,dt));    //Signal
 
 my_handle             = scf(100001);
 clf(my_handle,"reset");
-plot2d(instants',totrack');
+plot2d(instants',totrack',axesflag=1);
 
 halt();
 
@@ -63,5 +63,7 @@ Bigsyst=dscr(syslin('c',BigA,BigB,BigC,BigD,BigX0),dt);
 
 z=flts(uu(instants),Bigsyst);
 plot2d([instants',instants'],..
-       [totrack(1,:)',z(1,:)'],[1 2],leg='Signal to track@Computed signal');
+       [totrack(1,:)',z(1,:)'], axesflag=1);
+curves = gce();
+captions(curves.children,['Signal to track','Computed signal'],"upper_caption");
 xtitle('tracking');
index 4b614b6..217d77e 100644 (file)
@@ -49,5 +49,10 @@ BOOL checkRedrawing( void ) ;
  */
 sciPointObj * getClickedSubwin(sciPointObj * pFigure, int xCoord, int yCoord);
 
+/**
+ * Convert property name into a sciLegendPlace
+ */
+sciLegendPlace propertyNameToLegendPlace(const char * string);
+
 /*-----------------------------------------------------------------------------*/
 #endif /*__SCI_AXES_H_*/
index 9aca6e5..7bd52c6 100644 (file)
@@ -269,6 +269,8 @@ void sciGetZBounds(sciPointObj * pObj, double bounds[2]); /* GET */
 
 BOOL sciGetGridFront(sciPointObj * pObj); /* GET */
 
+sciLegendPlace sciGetLegendLocation(sciPointObj * pObj); /* GET */
+
 void printSetGetErrorMessage(const char * propertyName);
 
 #endif /* __SCI_GET_PROPERTY__ */
index ed0a237..30e8e04 100644 (file)
@@ -400,13 +400,12 @@ sciText;
 
 
 
-/**@name sciLegendPlace
- * Enumeration used to specify the title place 
+/**
+ * Enumeration used to specify the title place relative to parent subwindow
  */
 typedef enum
   {
     /** */
-    /** */
     SCI_LEGEND_IN_UPPER_LEFT = 1,
     /** */
     SCI_LEGEND_IN_UPPER_RIGHT = 2,
@@ -416,6 +415,8 @@ typedef enum
     SCI_LEGEND_IN_LOWER_RIGHT = 4,
     /** */
     SCI_LEGEND_BY_COORDINATES = 5,
+               /** */
+               SCI_LEGEND_POSITION_UNSPECIFIED = 0,
     /** */
     SCI_LEGEND_OUT_UPPER_LEFT = -1,
     /** */
index 3c2256e..76c1e8d 100644 (file)
@@ -267,8 +267,11 @@ int sciSetOutsideColors(sciPointObj * pObj, int colors[2]); /* SET */
 int sciInitZBounds(sciPointObj * pObj, double bounds[2]);
 int sciSetZBounds(sciPointObj * pObj, double bounds[2]); /* SET */
 
-BOOL sciInitGridFront(sciPointObj * pObj, BOOL gridFront);
-BOOL sciSetGridFront(sciPointObj * pObj, BOOL gridFront); /* SET */
+int sciInitGridFront(sciPointObj * pObj, BOOL gridFront);
+int sciSetGridFront(sciPointObj * pObj, BOOL gridFront); /* SET */
+
+int sciInitLegendLocation(sciPointObj * pObj, sciLegendPlace location);
+int sciSetLegendLocation(sciPointObj * pObj, sciLegendPlace location); /* SET */
 
 BOOL sciCheckColorIndex(sciPointObj * pObj, int colorIndex);
 
index 412ec63..c19ceab 100644 (file)
@@ -28,7 +28,8 @@
 #include "freeArrayOfString.h"
 #include "GraphicSynchronizerInterface.h"
 #include "DrawObjects.h"
-extern sciLegendPlace string2LegendPlace(char * string);
+
+#define DEF_LEGEND_LOCATION "in_upper_right"
 
 /*--------------------------------------------------------------------------*/
 int sci_Legend( char * fname, unsigned long fname_len )
@@ -40,10 +41,10 @@ int sci_Legend( char * fname, unsigned long fname_len )
   long long *tabofhandles;
   sciPointObj * psubwin = NULL;
   sciPointObj * pFigure = NULL;
-  char def_location[]="in_upper_right";
   sciLegendPlace location;
   sciEntityType type;
   char **Str = NULL;
+       sciPointObj * legend;
 
   CheckRhs(2,3);
   CheckLhs(0,1);
@@ -67,14 +68,14 @@ int sci_Legend( char * fname, unsigned long fname_len )
   GetRhsVar(2,MATRIX_OF_STRING_DATATYPE,&m2,&n2,&Str);
   if (Rhs==3) {
     GetRhsVar(3,STRING_DATATYPE,&m2,&n2,&l2);
-    location = string2LegendPlace(cstk(l2));
-    if ((int)location==0) {
+    location = propertyNameToLegendPlace(cstk(l2));
+    if (location == SCI_LEGEND_POSITION_UNSPECIFIED) {
       Scierror(999,_("%s: Wrong value for input argument #%d: Incorrect value.\n"),fname,3);
       return 0;
     }
   }
   else {
-    location = string2LegendPlace( def_location);
+    location = propertyNameToLegendPlace(DEF_LEGEND_LOCATION);
   }
 
   tabofhandles = (long long *)MALLOC(n*sizeof(long long));
@@ -93,8 +94,6 @@ int sci_Legend( char * fname, unsigned long fname_len )
   for (i = 0; i < n;i++)
   {
     handelsvalue = (unsigned long) (hstk(l1))[n-1-i];
-       /* Serge Please check this : */
-       /* if (psubwin!=sciGetParentSubwin(handelsvalue)) { */
 
     if (psubwin!=sciGetParentSubwin( sciGetPointerFromHandle(handelsvalue) )) {
       Scierror(999,_("%s: Objects must have the same axes.\n"),fname);
@@ -118,13 +117,21 @@ int sci_Legend( char * fname, unsigned long fname_len )
     tabofhandles[i]=handelsvalue;
     
   }
-  sciSetCurrentObj ((sciPointObj *)ConstructLegend (psubwin, Str, tabofhandles, n));
-  startFigureDataReading(pFigure);
-  sciDrawObjIfRequired(sciGetCurrentObj ());
+
+       /* Create the legend */
+       legend = ConstructLegend (psubwin, Str, tabofhandles, n);
+       sciSetLegendLocation(legend, location);
+
+       /* Draw it */
+  sciSetCurrentObj(legend);
+       startFigureDataReading(pFigure);
+  sciDrawObjIfRequired(legend);
   endFigureDataReading(pFigure);
 
   freeArrayOfString(Str,n);
   FREE(tabofhandles);
+
+       /* Return the handle of the newly create dlegend */
   numrow = 1;
   numcol = 1;
   CreateVar(Rhs+1,GRAPHICAL_HANDLE_DATATYPE,&numrow,&numcol,&outindex);
@@ -133,53 +140,3 @@ int sci_Legend( char * fname, unsigned long fname_len )
   return 0;
 }
 /*--------------------------------------------------------------------------*/
-sciLegendPlace string2LegendPlace(char * string)
-{
-  if ( strcmp(string, "in_upper_right" )==0 )
-    {
-      return SCI_LEGEND_IN_UPPER_RIGHT;
-    }
-  else if ( strcmp(string, "in_upper_left" )==0 )
-    {
-      return SCI_LEGEND_IN_UPPER_LEFT;
-    }
-  else if ( strcmp(string, "in_lower_right" )==0 )
-    {
-      return SCI_LEGEND_IN_LOWER_RIGHT;
-    }
-  else if ( strcmp(string, "in_lower_left" )==0 )
-    {
-      return SCI_LEGEND_IN_LOWER_LEFT;
-    }
-  else if ( strcmp(string, "out_upper_right" )==0 )
-    {
-      return SCI_LEGEND_OUT_UPPER_RIGHT;
-    }
-  else if ( strcmp(string, "out_upper_left" )==0 )
-    {
-      return SCI_LEGEND_OUT_UPPER_LEFT;
-    }
-  else if ( strcmp(string, "out_lower_right" )==0 )
-    {
-      return SCI_LEGEND_OUT_LOWER_RIGHT;
-    }
-  else if ( strcmp(string, "out_lower_left" )==0 )
-    {
-      return SCI_LEGEND_OUT_LOWER_LEFT;
-    }
-  else if ( strcmp(string, "upper_caption" )==0 )
-    {
-      return SCI_LEGEND_UPPER_CAPTION;
-    }
-  else if ( strcmp(string, "lower_caption" )==0 )
-    {
-      return SCI_LEGEND_LOWER_CAPTION;
-    }
-  else if ( strcmp(string, "by_coordinates" )==0 )
-    {
-      return SCI_LEGEND_BY_COORDINATES;
-    }
-  else {
-    return (sciLegendPlace) 0;
-  }
-}
index 55dd6d9..815efe7 100644 (file)
@@ -19,9 +19,7 @@
  * Axis drawing for 2d plots
  *--------------------------------------------------------------------------*/
 
-#include <math.h>
 #include <string.h>
-#include <stdio.h>
 #include "math_graphics.h"
 #include "Axes.h"
 #include "DestroyObjects.h"
@@ -44,8 +42,6 @@
 static int getSqDistanceToCenter(sciPointObj * pSubwin, int xCoord, int yCoord);
 static BOOL isSubwinUnderPixel(sciPointObj * pSubwin, int xCoord, int yCoord);
 
-//static int nbCheckRedraw = 0;
-
 /*--------------------------------------------------------------------------------*/
 /* clear a subwindow from all of its children */
 void clearSubWin( sciPointObj * pSubWin )
@@ -247,3 +243,54 @@ sciPointObj * getClickedSubwin(sciPointObj * pFigure, int xCoord, int yCoord)
 
 }
 /*--------------------------------------------------------------------------------*/
+sciLegendPlace propertyNameToLegendPlace(const char * string)
+{
+       if ( strcmp(string, "in_upper_right" ) == 0 )
+       {
+               return SCI_LEGEND_IN_UPPER_RIGHT;
+       }
+       else if ( strcmp(string, "in_upper_left" ) == 0 )
+       {
+               return SCI_LEGEND_IN_UPPER_LEFT;
+       }
+       else if ( strcmp(string, "in_lower_right" ) == 0 )
+       {
+               return SCI_LEGEND_IN_LOWER_RIGHT;
+       }
+       else if ( strcmp(string, "in_lower_left" ) == 0 )
+       {
+               return SCI_LEGEND_IN_LOWER_LEFT;
+       }
+       else if ( strcmp(string, "out_upper_right" ) == 0 )
+       {
+               return SCI_LEGEND_OUT_UPPER_RIGHT;
+       }
+       else if ( strcmp(string, "out_upper_left" ) == 0 )
+       {
+               return SCI_LEGEND_OUT_UPPER_LEFT;
+       }
+       else if ( strcmp(string, "out_lower_right" ) == 0 )
+       {
+               return SCI_LEGEND_OUT_LOWER_RIGHT;
+       }
+       else if ( strcmp(string, "out_lower_left" ) == 0 )
+       {
+               return SCI_LEGEND_OUT_LOWER_LEFT;
+       }
+       else if ( strcmp(string, "upper_caption" ) == 0 )
+       {
+               return SCI_LEGEND_UPPER_CAPTION;
+       }
+       else if ( strcmp(string, "lower_caption" ) == 0 )
+       {
+               return SCI_LEGEND_LOWER_CAPTION;
+       }
+       else if ( strcmp(string, "by_coordinates" ) == 0 )
+       {
+               return SCI_LEGEND_BY_COORDINATES;
+       }
+       else {
+               return (sciLegendPlace) 0;
+       }
+}
+/*--------------------------------------------------------------------------------*/
index 9afe5e8..96f42fc 100644 (file)
@@ -834,7 +834,7 @@ ConstructLegend (sciPointObj * pparentsubwin, char **text, long long tabofhandle
                ppLegend->pos.y = 0;
                ppLegend->width = 0;
                ppLegend->height = 0;
-               ppLegend->place = SCI_LEGEND_LOWER_CAPTION;
+               ppLegend->place = SCI_LEGEND_LOWER_CAPTION; /* Default position */
                ppLegend->isselected = TRUE;
                ppLegend->issurround = FALSE;
 
index 05a70a3..1cf6635 100644 (file)
@@ -3861,6 +3861,21 @@ BOOL sciGetGridFront(sciPointObj * pObj)
 }
 /*----------------------------------------------------------------------------------*/
 /**
+ * Get the position of a legend object relative to its parent subwin
+ */
+sciLegendPlace sciGetLegendLocation(sciPointObj * pObj)
+{
+  switch (sciGetEntityType(pObj))
+  {
+       case SCI_LEGEND:
+               return pLEGEND_FEATURE(pObj)->place;
+  default:
+    printSetGetErrorMessage("legend_location");
+               return SCI_LEGEND_POSITION_UNSPECIFIED;
+  }
+}
+/*----------------------------------------------------------------------------------*/
+/**
  * Print the message "This object has no xxx property." in Scilab.
  */
 void printSetGetErrorMessage(const char * propertyName)
index 99f1c88..cc5dad4 100644 (file)
@@ -3854,7 +3854,7 @@ int sciSetZBounds(sciPointObj * pObj, double bounds[2])
        return sciInitZBounds(pObj, bounds);
 }
 /*----------------------------------------------------------------------------------*/
-BOOL sciInitGridFront(sciPointObj * pObj, BOOL gridFront)
+int sciInitGridFront(sciPointObj * pObj, BOOL gridFront)
 {
   switch (sciGetEntityType(pObj))
   {
@@ -3870,7 +3870,7 @@ BOOL sciInitGridFront(sciPointObj * pObj, BOOL gridFront)
 /**
  * Modify whether the grid is drawn in background or foreground.
  */
-BOOL sciSetGridFront(sciPointObj * pObj, BOOL gridFront)
+int sciSetGridFront(sciPointObj * pObj, BOOL gridFront)
 {
        if (sciGetGridFront(pObj) == gridFront)
        {
@@ -3880,6 +3880,32 @@ BOOL sciSetGridFront(sciPointObj * pObj, BOOL gridFront)
        return sciInitGridFront(pObj, gridFront);
 }
 /*----------------------------------------------------------------------------------*/
+int sciInitLegendLocation(sciPointObj * pObj, sciLegendPlace location)
+{
+       switch (sciGetEntityType(pObj))
+  {
+       case SCI_LEGEND:
+               pLEGEND_FEATURE(pObj)->place = location;
+               return 0;
+       default:
+    printSetGetErrorMessage("legend_location");
+               return -1;
+  }
+}
+/*----------------------------------------------------------------------------------*/
+/**
+ * Modify the legend position relatively to the subwindow
+ */
+int sciSetLegendLocation(sciPointObj * pObj, sciLegendPlace location)
+{
+       if (sciGetLegendLocation(pObj) == location)
+       {
+               /* nothing to do */
+               return 1;
+       }
+       return sciInitLegendLocation(pObj, location);
+}
+/*----------------------------------------------------------------------------------*/
 /**
  * Check that a color index is within the colormap range or not
  * @param pObj object conatining the color
index 7fcff44..c52c540 100644 (file)
 #include "GetProperty.h"
 #include "Scierror.h"
 #include "localization.h"
+#include "Axes.h"
 
 /*------------------------------------------------------------------------*/
 int set_legend_location_property( sciPointObj * pobj, size_t stackPointer, int valueType, int nbRow, int nbCol )
 {
-  
+       sciLegendPlace position;
   if ( !isParameterStringMatrix( valueType ) )
   {
     Scierror(999, _("Incompatible type for property %s.\n"),"legend_location") ;
@@ -42,57 +43,18 @@ int set_legend_location_property( sciPointObj * pobj, size_t stackPointer, int v
     return SET_PROPERTY_ERROR ;
   }
 
-  if ( isStringParamEqual( stackPointer, "in_upper_right" ) )
-  {
-    pLEGEND_FEATURE(pobj)->place = SCI_LEGEND_IN_UPPER_RIGHT;
-  }
-  else if ( isStringParamEqual( stackPointer, "in_upper_left" ) )
-  {
-    pLEGEND_FEATURE(pobj)->place = SCI_LEGEND_IN_UPPER_LEFT;
-  }
- else if ( isStringParamEqual( stackPointer, "in_lower_right" ) )
-  {
-    pLEGEND_FEATURE(pobj)->place = SCI_LEGEND_IN_LOWER_RIGHT;
-  }
-  else if ( isStringParamEqual( stackPointer, "in_lower_left" ) )
-  {
-    pLEGEND_FEATURE(pobj)->place = SCI_LEGEND_IN_LOWER_LEFT;
-  }
-
-  else if ( isStringParamEqual( stackPointer, "out_upper_right" ) )
-  {
-    pLEGEND_FEATURE(pobj)->place = SCI_LEGEND_OUT_UPPER_RIGHT;
-  }
-  else if ( isStringParamEqual( stackPointer, "out_upper_left" ) )
-  {
-    pLEGEND_FEATURE(pobj)->place = SCI_LEGEND_OUT_UPPER_LEFT;
-  }
- else if ( isStringParamEqual( stackPointer, "out_lower_right" ) )
-  {
-    pLEGEND_FEATURE(pobj)->place = SCI_LEGEND_OUT_LOWER_RIGHT;
-  }
-  else if ( isStringParamEqual( stackPointer, "out_lower_left" ) )
-  {
-    pLEGEND_FEATURE(pobj)->place = SCI_LEGEND_OUT_LOWER_LEFT;
-  }
-  else if ( isStringParamEqual( stackPointer, "upper_caption" ) )
-  {
-    pLEGEND_FEATURE(pobj)->place = SCI_LEGEND_UPPER_CAPTION;
-  }
-  else if ( isStringParamEqual( stackPointer, "lower_caption" ) )
-  {
-    pLEGEND_FEATURE(pobj)->place = SCI_LEGEND_LOWER_CAPTION;
-  }
-  else if ( isStringParamEqual( stackPointer, "by_coordinates" ) )
-  {
-    pLEGEND_FEATURE(pobj)->place = SCI_LEGEND_BY_COORDINATES;
-  }
+       position = propertyNameToLegendPlace(getStringFromStack(stackPointer));
 
-  else  
-  {
-    Scierror(999, _("%s: Wrong type for input argument #%d: '%s', '%s' or '%s' expected.\n"), "set_legend_location_property",2,"top","bottom","origin") ;
+       if (position == SCI_LEGEND_POSITION_UNSPECIFIED)
+       {
+               Scierror(999, _("Wrong value for property '%s': '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' or '%s' expected.\n"),
+                                                "legend_location",
+                                                "in_upper_right","in_upper_left","in_lower_right","in_lower_left",
+                                                "out_upper_right","out_upper_left","out_lower_right","out_lower_left",
+                                                "upper_caption","lower_caption","by_coordinates") ;
     return SET_PROPERTY_ERROR ;
-  }
-  return SET_PROPERTY_SUCCEED ;
+       }
+
+       return sciSetLegendLocation(pobj, position);
 }
 /*------------------------------------------------------------------------*/