Added tip_disp_function on Datatip object handler and 80/12280/2
Gustavo LIBOTTE [Tue, 13 Aug 2013 22:05:36 +0000 (19:05 -0300)]
Implementation of datatipSetDisplay(datatip_handler, ["disp_function_name"])

Test case:

x=linspace(-1,1,1000);

clf()

plot(x,sinc(20*x),x,1-x^2);

e=gce();e=e.children;

d21=datatipCreate(e(2),600);

d22=datatipCreate(e(2),200);

d1=datatipCreate(e(1),700);

function str=mydisplay(pt)

   str=msprintf('sinc(%-0.2g)=%-0.2g', pt(1),pt(2))

   xinfo(msprintf('x=%0.2g,\t 1-x^2=%0.2g', pt(1),pt(2)))

endfunction

datatipSetDisplay(d21,"mydisplay")

//Standard label

datatipSetDisplay(d21)

//Defining from the object field

d22.tip_disp_function = "mydisplay"

//Standard label from the object field

d22.tip_disp_function = ""

Change-Id: If8325b47be34aa3335dbc834e48f192aa289de1c

16 files changed:
scilab/modules/graphic_objects/src/java/org/scilab/modules/graphic_objects/datatip/Datatip.java
scilab/modules/graphics/macros/%h_p.sci
scilab/modules/graphics/src/c/getHandleProperty/GetHashTable.c
scilab/modules/graphics/src/c/getHandleProperty/SetHashTable.c
scilab/modules/graphics/src/c/getHandleProperty/getHandleProperty.h
scilab/modules/graphics/src/c/getHandleProperty/get_datatip_property.c
scilab/modules/graphics/src/c/getHandleProperty/setHandleProperty.h
scilab/modules/graphics/src/c/getHandleProperty/set_datatip_property.c
scilab/modules/gui/Makefile.am
scilab/modules/gui/Makefile.in
scilab/modules/gui/includes/gw_gui.h
scilab/modules/gui/sci_gateway/c/gw_gui.c
scilab/modules/gui/sci_gateway/cpp/sci_datatip_set_display.cpp [new file with mode: 0644]
scilab/modules/gui/sci_gateway/gui_gateway.xml
scilab/modules/gui/src/c/gui.vcxproj
scilab/modules/gui/src/c/gui.vcxproj.filters

index bf04adc..9d1238e 100755 (executable)
@@ -20,6 +20,7 @@ import org.scilab.modules.graphic_objects.graphicObject.Visitor;
 
 import java.text.DecimalFormat;
 
+import org.scilab.modules.action_binding.InterpreterManagement;
 
 public class Datatip extends Text {
 
@@ -79,7 +80,7 @@ public class Datatip extends Text {
         tipBoxMode = true;
         tipLabelMode = true;
         interpMode = true;
-        displayFnc = null;
+        displayFnc = "";
         setVisible(true);
         setBox(true);
         setLineMode(true);
@@ -278,6 +279,30 @@ public class Datatip extends Text {
         setTextStrings(textArray);
     }
 
+    /**
+     * Update the text from the datatip for datatipSetDisplay
+     */
+    void updateTextDispFunction(String displayFnc) {
+
+        if (displayFnc.length() != 0) {
+            String updateCommand = "try;" +
+                                   "d = getcallbackobject(\"" + getIdentifier() + "\");" +
+                                   "d.text = " + displayFnc + "(d.tip_data);" +
+                                   "clear(\"d\");" +
+                                   "catch;" +
+                                   "d.tip_disp_function = \"\";" +
+                                   "clear(\"d\");" +
+                                   "error(msprintf(_( \"%s: Wrong name of input argument #%d: Function ''%s'' not defined.\n\"),\"datatipSetDisplay\",2,\"" + displayFnc + "\"));" +
+                                   "end;";
+
+
+            InterpreterManagement.requestScilabExec(updateCommand);
+        } else {
+            updateText();
+        }
+
+    }
+
     public Boolean getTipBoxMode() {
         return tipBoxMode;
     }
@@ -309,6 +334,7 @@ public class Datatip extends Text {
 
     public void setDisplayFunction(String fnc) {
         displayFnc = fnc;
+        updateTextDispFunction(displayFnc);
     }
 
     @Override
index f396973..ea18261 100755 (executable)
@@ -558,6 +558,7 @@ function %h_p(h)
             "tip_3component = "+sci2exp(h.tip_3component)
             "tip_auto_orientation = "+sci2exp(h.tip_auto_orientation)
             "tip_interp_mode = "+sci2exp(h.tip_interp_mode)
+            "tip_disp_function = "+sci2exp(h.tip_disp_function)
             "font_foreground = "+string(h.font_foreground)
             "foreground = "+string(h.foreground)
             "background = "+string(h.background)
index 9ede55a..0874bc2 100755 (executable)
@@ -46,7 +46,7 @@ typedef struct
  * don't forget to modify it each time the propertyTable
  * is modified.
  */
-#define NB_PROPERTIES 169
+#define NB_PROPERTIES 170
 
 /**
  * list of all property names and associated functions in scilab
@@ -222,7 +222,8 @@ static getHashTableCouple propertyTable[NB_PROPERTIES] =
     {"tip_auto_orientation", get_tip_auto_orientation_property},
     {"tip_interp_mode", get_tip_interp_mode_property},
     {"tip_box_mode", get_tip_box_mode_property},
-    {"tip_label_mode", get_tip_label_mode_property}
+    {"tip_label_mode", get_tip_label_mode_property},
+    {"tip_disp_function", get_tip_disp_function_property}
 };
 
 /*--------------------------------------------------------------------------*/
index 4195b08..bc5f26a 100755 (executable)
@@ -52,7 +52,7 @@ typedef struct
 * don't forget to modify it each time the propertyTable
 * is modified.
 */
-#define NB_PROPERTIES 164
+#define NB_PROPERTIES 165
 
 /**
 * list of all property names and associated functions in scilab
@@ -223,7 +223,8 @@ static setHashTableCouple propertyTable[NB_PROPERTIES] =
     {"tip_auto_orientation", set_tip_auto_orientation_property},
     {"tip_interp_mode", set_tip_interp_mode_property},
     {"tip_box_mode", set_tip_box_mode_property},
-    {"tip_label_mode", set_tip_label_mode_property}
+    {"tip_label_mode", set_tip_label_mode_property},
+    {"tip_disp_function", set_tip_disp_function_property}
 };
 
 /*--------------------------------------------------------------------------*/
index c96ce80..a621f9c 100755 (executable)
@@ -187,5 +187,6 @@ int get_tip_auto_orientation_property(void* _pvCtx, char* pobjUID);
 int get_tip_interp_mode_property(void* _pvCtx, char* pobjUID);
 int get_tip_box_mode_property(void* _pvCtx, char* pobjUID);
 int get_tip_label_mode_property(void* _pvCtx, char* pobjUID);
+int get_tip_disp_function_property(void* _pvCtx, char* pobjUID);
 
 #endif /* _GET_HANDLE_PROPERTY_H_ */
index 58d55ec..ad060f8 100755 (executable)
@@ -187,4 +187,22 @@ int get_tip_label_mode_property(void* _pvCtx, char* pobjUID)
     {
         return sciReturnString(_pvCtx, "off");
     }
+}
+
+
+/**
+ * Get the datatip display function.
+ */
+int get_tip_disp_function_property(void* _pvCtx, char* pobjUID)
+{
+    char *tip_disp_function = NULL;
+    getGraphicObjectProperty(pobjUID, __GO_DATATIP_DISPLAY_FNC__, jni_string, (void **)&tip_disp_function);
+
+    if (tip_disp_function == NULL)
+    {
+        Scierror(999, _("'%s' property does not exist for this handle.\n"), "tip_disp_function");
+        return -1;
+    }
+
+    return sciReturnString(_pvCtx, tip_disp_function);
 }
\ No newline at end of file
index f8f9bfd..01113ba 100755 (executable)
@@ -188,5 +188,6 @@ int set_tip_auto_orientation_property(void* _pvCtx, char* pobj, void* _pvData, i
 int set_tip_interp_mode_property(void* _pvCtx, char* pobj, void* _pvData, int valueType, int nbRow, int nbCol);
 int set_tip_box_mode_property(void* _pvCtx, char* pobj, void* _pvData, int valueType, int nbRow, int nbCol);
 int set_tip_label_mode_property(void* _pvCtx, char* pobj, void* _pvData, int valueType, int nbRow, int nbCol);
+int set_tip_disp_function_property(void* _pvCtx, char* pobj, void* _pvData, int valueType, int nbRow, int nbCol);
 
 #endif /* _SET_HANDLE_PROPERTY_H_ */
index 4a8a7b1..9940f41 100755 (executable)
@@ -209,4 +209,27 @@ int set_tip_label_mode_property(void* _pvCtx, char* pobj, void* _pvData, int val
         Scierror(999, _("'%s' property does not exist for this handle.\n"), "tip_label_mode");
         return SET_PROPERTY_ERROR;
     }
+}
+
+
+int set_tip_disp_function_property(void* _pvCtx, char* pobj, void* _pvData, int valueType, int nbRow, int nbCol)
+{
+    BOOL status = FALSE;
+    if (valueType != sci_strings)
+    {
+        Scierror(999, _("Wrong type for '%s' property: String expected.\n"), "tip_disp_function");
+        return SET_PROPERTY_ERROR;
+    }
+
+    status = setGraphicObjectProperty(pobj, __GO_DATATIP_DISPLAY_FNC__, _pvData, jni_string, 1);
+
+    if (status == TRUE)
+    {
+        return SET_PROPERTY_SUCCEED;
+    }
+    else
+    {
+        Scierror(999, _("'%s' property does not exist for this handle.\n"), "tip_disp_function");
+        return SET_PROPERTY_ERROR;
+    }
 }
\ No newline at end of file
index d6ce4b2..c5056a1 100755 (executable)
@@ -212,7 +212,8 @@ sci_gateway/cpp/sci_plotbrowser.cpp \
 sci_gateway/cpp/sci_datatip_manager_mode.cpp \
 sci_gateway/cpp/sci_datatip_toggle.cpp \
 sci_gateway/cpp/sci_datatipmove.cpp \
-sci_gateway/cpp/sci_datatip_set_style.cpp
+sci_gateway/cpp/sci_datatip_set_style.cpp \
+sci_gateway/cpp/sci_datatip_set_display.cpp
 
 libscigui_la_CPPFLAGS = \
                        -I$(srcdir)/includes/ \
index 6edb059..fe86274 100644 (file)
@@ -274,7 +274,8 @@ am__objects_5 = libscigui_la-sci_printsetupbox.lo \
        libscigui_la-sci_datatip_manager_mode.lo \
        libscigui_la-sci_datatip_toggle.lo \
        libscigui_la-sci_datatipmove.lo \
-       libscigui_la-sci_datatip_set_style.lo
+       libscigui_la-sci_datatip_set_style.lo \
+       libscigui_la-sci_datatip_set_display.lo
 am_libscigui_la_OBJECTS = $(am__objects_4) $(am__objects_5)
 libscigui_la_OBJECTS = $(am_libscigui_la_OBJECTS)
 @GUI_TRUE@am_libscigui_la_rpath = -rpath $(pkglibdir)
@@ -763,7 +764,8 @@ sci_gateway/cpp/sci_plotbrowser.cpp \
 sci_gateway/cpp/sci_datatip_manager_mode.cpp \
 sci_gateway/cpp/sci_datatip_toggle.cpp \
 sci_gateway/cpp/sci_datatipmove.cpp \
-sci_gateway/cpp/sci_datatip_set_style.cpp
+sci_gateway/cpp/sci_datatip_set_style.cpp \
+sci_gateway/cpp/sci_datatip_set_display.cpp
 
 libscigui_la_CPPFLAGS = \
                        -I$(srcdir)/includes/ \
@@ -1207,6 +1209,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscigui_la-sci_ClipBoard.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscigui_la-sci_about.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscigui_la-sci_datatip_manager_mode.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscigui_la-sci_datatip_set_display.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscigui_la-sci_datatip_set_style.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscigui_la-sci_datatip_toggle.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscigui_la-sci_datatipcreate.Plo@am__quote@
@@ -2252,6 +2255,13 @@ libscigui_la-sci_datatip_set_style.lo: sci_gateway/cpp/sci_datatip_set_style.cpp
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscigui_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscigui_la-sci_datatip_set_style.lo `test -f 'sci_gateway/cpp/sci_datatip_set_style.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_datatip_set_style.cpp
 
+libscigui_la-sci_datatip_set_display.lo: sci_gateway/cpp/sci_datatip_set_display.cpp
+@am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscigui_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libscigui_la-sci_datatip_set_display.lo -MD -MP -MF $(DEPDIR)/libscigui_la-sci_datatip_set_display.Tpo -c -o libscigui_la-sci_datatip_set_display.lo `test -f 'sci_gateway/cpp/sci_datatip_set_display.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_datatip_set_display.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscigui_la-sci_datatip_set_display.Tpo $(DEPDIR)/libscigui_la-sci_datatip_set_display.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_datatip_set_display.cpp' object='libscigui_la-sci_datatip_set_display.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscigui_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscigui_la-sci_datatip_set_display.lo `test -f 'sci_gateway/cpp/sci_datatip_set_display.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_datatip_set_display.cpp
+
 mostlyclean-libtool:
        -rm -f *.lo
 
index 8c19dd9..bf6bbae 100755 (executable)
@@ -63,6 +63,7 @@ GUI_IMPEXP int sci_datatip_manager_mode(char *fname, unsigned long fname_len);
 GUI_IMPEXP int sci_datatip_toggle(char *fname, unsigned long fname_len);
 GUI_IMPEXP int sci_datatipmove(char *fname, unsigned long fname_len);
 GUI_IMPEXP int sci_datatip_set_style(char *fname, unsigned long fname_len);
+GUI_IMPEXP int sci_datatip_set_display(char *fname, unsigned long fname_len);
 /*--------------------------------------------------------------------------*/
 #endif /*  __GW_GUI__ */
 /*--------------------------------------------------------------------------*/
index afb2bea..09a4684 100755 (executable)
@@ -70,7 +70,8 @@ static gw_generic_table Tab[] =
     {sci_datatip_manager_mode, "datatipManagerMode"},
     {sci_datatip_toggle, "datatipToggle"},
     {sci_datatipmove, "datatipMove"},
-    {sci_datatip_set_style, "datatipSetStyle"}
+    {sci_datatip_set_style, "datatipSetStyle"},
+    {sci_datatip_set_display, "datatipSetDisplay"}
 };
 /*--------------------------------------------------------------------------*/
 int gw_gui(void)
diff --git a/scilab/modules/gui/sci_gateway/cpp/sci_datatip_set_display.cpp b/scilab/modules/gui/sci_gateway/cpp/sci_datatip_set_display.cpp
new file mode 100644 (file)
index 0000000..9fe3c94
--- /dev/null
@@ -0,0 +1,134 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2013 - Gustavo Barbosa Libotte <gustavolibotte@gmail.com>
+*
+* This file must be used under the terms of the CeCILL.
+* This source file is licensed as described in the file COPYING, which
+* you should have received as part of this distribution.  The terms
+* are also available at
+* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+*
+*/
+
+extern "C"
+{
+#include "api_scilab.h"
+#include "getScilabJavaVM.h"
+#include "localization.h"
+#include "Scierror.h"
+#include "gw_gui.h"
+#include "HandleManagement.h"
+#include "CurrentFigure.h"
+#include "getGraphicObjectProperty.h"
+#include "setGraphicObjectProperty.h"
+#include "graphicObjectProperties.h"
+}
+
+int sci_datatip_set_display(char *fname, unsigned long fname_len)
+{
+
+    SciErr sciErr;
+    CheckInputArgument(pvApiCtx, 1, 2);
+    CheckOutputArgument(pvApiCtx, 1, 1);
+
+    int stkAdr = 0;
+    int nbRow = 0, nbCol = 0;
+    char* datatipUID = NULL;
+    int iType = 0;
+    int *piType = &iType;
+    int* piAddr = NULL;
+    int iRet = 0;
+    char* pstData = NULL;
+
+    GetRhsVar(1, GRAPHICAL_HANDLE_DATATYPE, &nbRow, &nbCol, &stkAdr);
+    datatipUID = (char *)getObjectFromHandle((unsigned long) * (hstk(stkAdr)));
+
+    if (checkInputArgumentType(pvApiCtx, 1, sci_handles))
+    {
+
+        getGraphicObjectProperty(datatipUID, __GO_TYPE__, jni_int, (void**) &piType);
+        if (iType == __GO_DATATIP__)
+        {
+
+            if (nbInputArgument(pvApiCtx) == 1)
+            {
+
+                setGraphicObjectProperty(datatipUID, __GO_DATATIP_DISPLAY_FNC__, "", jni_string, 1);
+                LhsVar(1) = 0;
+                PutLhsVar();
+                return FALSE;
+
+            }
+            else if (nbInputArgument(pvApiCtx) == 2)
+            {
+
+                sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
+                if (sciErr.iErr)
+                {
+                    printError(&sciErr, 0);
+                    return 0;
+                }
+
+                if (isStringType(pvApiCtx, piAddr))
+                {
+                    if (isScalar(pvApiCtx, piAddr))
+                    {
+
+                        iRet = getAllocatedSingleString(pvApiCtx, piAddr, &pstData);
+                        if (iRet)
+                        {
+                            freeAllocatedSingleString(pstData);
+                            return iRet;
+                        }
+
+                        setGraphicObjectProperty(datatipUID, __GO_DATATIP_DISPLAY_FNC__, pstData, jni_string, 1);
+
+                        freeAllocatedSingleString(pstData);
+                        LhsVar(1) = 0;
+                        PutLhsVar();
+                        return FALSE;
+                    }
+                    else
+                    {
+
+                        Scierror(999, _("%s: Wrong size for input argument #%d: single dimension string expected.\n"), fname, 2);
+                        return FALSE;
+
+                    }
+                }
+                else
+                {
+
+                    Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 2);
+                    return FALSE;
+
+                }
+
+            }
+            else
+            {
+
+                Scierror(999, _("%s: Wrong number of input arguments: %d or %d expected.\n"), fname, 1, 2);
+                return FALSE;
+
+            }
+
+        }
+        else
+        {
+
+            Scierror(999, _("%s: Wrong type for input argument #%d: Datatip handler expected.\n"), fname, 1);
+            return FALSE;
+
+        }
+
+    }
+    else
+    {
+
+        Scierror(999, _("%s: Wrong type for input argument #%d: Datatip handler expected.\n"), fname, 1);
+        return FALSE;
+
+    }
+
+}
\ No newline at end of file
index f387422..b5523db 100644 (file)
@@ -77,4 +77,5 @@
     <PRIMITIVE gatewayId="25" primitiveId="44" primitiveName="datatipToggle" />
     <PRIMITIVE gatewayId="25" primitiveId="45" primitiveName="datatipMove" />
     <PRIMITIVE gatewayId="25" primitiveId="46" primitiveName="datatipSetStyle" />
+    <PRIMITIVE gatewayId="25" primitiveId="47" primitiveName="datatipSetDisplay" />
 </GATEWAY>
index e85f40e..74b7ef7 100755 (executable)
   </ItemDefinitionGroup>
   <ItemGroup>
     <ClCompile Include="..\..\sci_gateway\cpp\sci_datatipmove.cpp" />
+    <ClCompile Include="..\..\sci_gateway\cpp\sci_datatip_set_display.cpp" />
     <ClCompile Include="..\..\sci_gateway\cpp\sci_datatip_set_style.cpp" />
     <ClCompile Include="..\..\sci_gateway\cpp\sci_datatip_toggle.cpp" />
     <ClCompile Include="..\..\sci_gateway\cpp\sci_datatip_manager_mode.cpp" />
index fa26bc0..b706d7a 100755 (executable)
     <ClCompile Include="..\..\sci_gateway\cpp\sci_datatip_set_style.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\sci_gateway\cpp\sci_datatip_set_display.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
     <ClCompile Include="..\jni\StartPlotBrowser.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>