Fix datatipSetDisplay. 55/13455/4
Vincent COUVERT [Fri, 17 Jan 2014 16:39:35 +0000 (17:39 +0100)]
To test: test_run graphics bug_10298

Change-Id: Idbe75be32873a9c2b23343e9fff0f99670e67f84

scilab/modules/api_scilab/src/cpp/api_common.cpp
scilab/modules/graphic_objects/src/java/org/scilab/modules/graphic_objects/datatip/Datatip.java
scilab/modules/graphics/help/en_US/datatips/datatipSetDisplay.xml
scilab/modules/graphics/macros/datatips/datatipSetDisplay.sci [deleted file]
scilab/modules/graphics/tests/nonreg_tests/bug_10298.dia.ref
scilab/modules/graphics/tests/nonreg_tests/bug_10298.tst
scilab/modules/gui/sci_gateway/cpp/sci_datatip_set_display.cpp
scilab/modules/helptools/data/configuration/scilab_macros.txt
scilab/modules/helptools/data/configuration/scilab_primitives.txt

index 763f2f7..6af658a 100644 (file)
@@ -288,7 +288,7 @@ SciErr getVarNameFromPosition(void *_pvCtx, int _iVar, char *_pstName)
     int iNameLen = 0;
     int iJob1 = 1;
 
-    CvNameL(&vstk_.idstk[(_iVar - 1) * 6], _pstName, &iJob1, &iNameLen);
+    CvNameL(&vstk_.idstk[(Top - Rhs + _iVar - 1) * 6], _pstName, &iJob1, &iNameLen);
     if (iNameLen == 0)
     {
         addErrorMessage(&sciErr, API_ERROR_INVALID_NAME, _("%s: Unable to get name of argument #%d"), "getVarNameFromPosition", _iVar);
index 9637cfa..bda59d6 100755 (executable)
@@ -31,6 +31,7 @@ import org.scilab.modules.graphic_objects.graphicController.GraphicController;
 import org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties;
 import org.scilab.modules.graphic_objects.graphicObject.Visitor;
 import org.scilab.modules.graphic_objects.textObject.Text;
+import org.scilab.modules.localization.Messages;
 
 public class Datatip extends Text {
 
@@ -327,14 +328,15 @@ public class Datatip extends Text {
             }
         }
 
+        String errMsg =  Messages.gettext("\"Wrong value for ''%s'' property: A valid function name expected.\n\"");
         String updateCommand = "try;" +
-                               "d = getcallbackobject(" + getIdentifier() + ");" +
-                               "d.text = " + fnc + "(d.data);" +
-                               "clear(\"d\");" +
+                               "    d = getcallbackobject(" + getIdentifier() + ");" +
+                               "    d.text = " + fnc + "(d);" +
+                               "    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,\"" + fnc + "\"));" +
+                               "    d.display_function = \"\";" +
+                               "    clear(\"d\");" +
+                               "    error(msprintf(" + errMsg + ", \"display_function\"));" +
                                "end;";
         InterpreterManagement.requestScilabExec(updateCommand);
     }
index 8c0b249..aa53054 100644 (file)
         <title>Calling Sequence</title>
         <synopsis>
             datatipSetDisplay(tip_handle,"fun")
-            datatipSetDisplay(tip_handle)
+            datatipSetDisplay(tip_handle, fun)
         </synopsis>
     </refsynopsisdiv>
     <refsection>
         <title>Arguments</title>
         <variablelist>
             <varlistentry>
-                <term>tip_handle</term>
+                <term>datatip_handle or datatip_parent_handle</term>
                 <listitem>
                     <para>
-                        A handle on a datatip.
+                        A handle on a datatip or its parent.
                     </para>
                 </listitem>
             </varlistentry>
                 <term>"fun"</term>
                 <listitem>
                     <para>
-                        A character string that contains a function name. 
-                        This function calling sequence must be
-                        <literal>str=fun(pt)</literal> where
-                        <literal>pt</literal> is the vector of datatip coordinates.
+                        A variable that contains a function (type==11 or type==13) or the name of this function. This function calling sequence must be <literal>str=fun(h)</literal> where <literal>h</literal> is the handle of the datatip.
                     </para>
                     <para>
                         This function must return a string or a vector of strings
@@ -65,8 +62,9 @@
     d21=datatipCreate(e(2),600);
     d1=datatipCreate(e(1),700);
 
-    function str=mydisplay(pt)
-       str=msprintf('sinc(%-0.2g)=%-0.2g', 20*pt(1),pt(2))
+    function str=mydisplay(h)
+        pt = h.data;
+        str=msprintf('sinc(%-0.2g)=%-0.2g', 20*pt(1),pt(2))
     endfunction
     datatipSetDisplay(d21,"mydisplay")
     ]]></programlisting>
             e=gce();e=e.children;
             d21=datatipCreate(e(2),600);
             d1=datatipCreate(e(1),700);
-
-            function str=mydisplay(pt)
+            
+            function str=mydisplay(h)
+            pt = h.data;
             str=msprintf('sinc(%-0.2g)=%-0.2g', 20*pt(1),pt(2))
             endfunction
+            datatipSetDisplay(d21,mydisplay)
             datatipSetDisplay(d21,"mydisplay")
         </scilab:image>
         The display function can also be used to place tip text in different locations:
         <programlisting role="example"><![CDATA[
-    function str=infodisplay(pt)
-       xinfo(msprintf('x=%0.2g,\t 1-x^2=%0.2g', pt(1),pt(2)))
-       str=''
+    function str=infodisplay(h)
+        pt = h.data;
+        xinfo(msprintf('x=%0.2g,\t 1-x^2=%0.2g', pt(1),pt(2)))
+        str=''
     endfunction
     datatipSetDisplay(d1,"infodisplay") //tip text displayed in the info bar
     ]]></programlisting>
diff --git a/scilab/modules/graphics/macros/datatips/datatipSetDisplay.sci b/scilab/modules/graphics/macros/datatips/datatipSetDisplay.sci
deleted file mode 100644 (file)
index 1ae8824..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 2010 - INRIA - Serge Steer <serge.steer@inria.fr>
-//
-// 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.1-en.txt
-
-function datatipSetDisplay(curve_handle,fun)
-    //Changes the datatips visualisation function for a given curve
-    if argn(2)<1 then
-        error(msprintf(_("%s: Wrong number of input argument(s): At least %d expected.\n"),...
-        "datatipSetDisplay",1))
-    end
-    if type(curve_handle)<>9|size(curve_handle,"*")<>1|curve_handle.type<>"Polyline" then
-        error(msprintf(_("%s: Wrong type for input argument #%d: A ''%s'' handle expected.\n"),"datatipSetDisplay",1,"Polyline"))
-    end
-    ds=datatipGetStruct(curve_handle)
-    if  typeof(ds)<>"datatips" then;
-        if ~datatipInitStruct(curve_handle) then return,end
-        ds=datatipGetStruct(curve_handle)
-    end
-    if argn(2)==1 then
-        // function definition is queried
-        txt=fun2string(ds.formatfunction,"fun")
-        while %t then
-            txt=x_dialog("Function Editor",txt)
-            if txt==[] then ok=%f,break,end
-            ierr=execstr(txt,"errcatch")
-            if ierr==0 then ok=%t,break,end
-            messagebox(lasterror(),"","error")
-        end
-        if ~ok then return,end
-    end
-    if ~datatipCheckFunction(fun) then return,end
-    ds.formatfunction=fun
-    datatipSetStruct(curve_handle,ds)
-    for k=1:size(ds.tips.children,"*")
-        tip_handle=ds.tips.children(k)
-        point_handle=tip_handle.children(1);
-        string_handle=tip_handle.children(2);
-        tip_index=point_handle.user_data(2)
-        string_handle.text=fun(curve_handle,point_handle.data,tip_index)
-        datatipSetTipStyle(tip_handle,ds.style)
-    end
-
-endfunction
-function ok=datatipCheckFunction(fun)
-    ok=%f
-    [out,in,c]=string(fun)
-    if size(in,"*")<>3 then
-        messagebox(_("The selected function must have 3 input parameters (curve,pt,index)"))
-        return
-    end
-    if size(out,"*")<>1 then
-        messagebox(_("The selected function must have 1 output parameter (str)"))
-        return
-    end
-    ok=%t
-endfunction
index 0032c3d..c6e465a 100644 (file)
@@ -19,7 +19,11 @@ e=gce();e=e.children;
 d21=datatipCreate(e(2),600);
 d22=datatipCreate(e(2),200);
 d1=datatipCreate(e(1),700);
-function str=mydisplay(curve, pt, index)
-   str=msprintf('sinc(%-0.2g)=%-0.2g', 20*pt(1),pt(2))
+function str=mydisplay(datatip_handle)
+    pt = datatip_handle.data;
+    str=msprintf('sinc(%-0.2g)=%-0.2g', 20*pt(1),pt(2))
 endfunction
-assert_checktrue(execstr("datatipSetDisplay(e(2),mydisplay)","errcatch")==0);
+assert_checktrue(execstr("datatipSetDisplay(e(2),mydisplay)","errcatch")==0); // Function
+assert_checktrue(execstr("datatipSetDisplay(e(2),""mydisplay"")","errcatch")==0); // Function name
+assert_checkequal(d21.text, "sinc(4)=-0.19");
+assert_checkequal(d22.text, "sinc(-12)=-0.042");
index a860b6d..471b1be 100644 (file)
@@ -23,8 +23,12 @@ d21=datatipCreate(e(2),600);
 d22=datatipCreate(e(2),200);
 d1=datatipCreate(e(1),700);
 
-function str=mydisplay(curve, pt, index)
-   str=msprintf('sinc(%-0.2g)=%-0.2g', 20*pt(1),pt(2))
+function str=mydisplay(datatip_handle)
+    pt = datatip_handle.data;
+    str=msprintf('sinc(%-0.2g)=%-0.2g', 20*pt(1),pt(2))
 endfunction
-assert_checktrue(execstr("datatipSetDisplay(e(2),mydisplay)","errcatch")==0);
 
+assert_checktrue(execstr("datatipSetDisplay(e(2),mydisplay)","errcatch")==0); // Function
+assert_checktrue(execstr("datatipSetDisplay(e(2),""mydisplay"")","errcatch")==0); // Function name
+assert_checkequal(d21.text, "sinc(4)=-0.19");
+assert_checkequal(d22.text, "sinc(-12)=-0.042");
index 5fd7c5d..0ba6702 100644 (file)
@@ -15,6 +15,7 @@ extern "C"
 #include "api_scilab.h"
 #include "getScilabJavaVM.h"
 #include "localization.h"
+#include "MALLOC.h"
 #include "Scierror.h"
 #include "gw_gui.h"
 #include "HandleManagement.h"
@@ -98,16 +99,34 @@ int sci_datatip_set_display(char *fname, unsigned long fname_len)
                     }
                     else
                     {
-                        Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 2);
+                        Scierror(999, _("%s: Wrong size for input argument #%d: A string or a macro name expected.\n"), fname, 2);
                         return 1;
                     }
                 }
                 else
                 {
-                    Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 2);
-                    return 1;
+                    sciErr = getVarType(pvApiCtx, piAddr, &iType);
+                    if (iType == sci_c_function || iType == sci_u_function)
+                    {
+                        char *pstFunctionName = (char*) MALLOC(sizeof(char) * (200));
+                        sciErr = getVarNameFromPosition(pvApiCtx, 2, pstFunctionName);
+                        if (sciErr.iErr)
+                        {
+                            Scierror(999, _("%s: Wrong type for input argument #%d: A string or a macro name expected.\n"), fname, 2);
+                            return 1;
+                        }
+                        setGraphicObjectProperty(iDatatipUID, __GO_DATATIP_DISPLAY_FNC__, pstFunctionName, jni_string, 1);
+                        FREE(pstFunctionName);
+                        AssignOutputVariable(pvApiCtx, 1) = 0;
+                        ReturnArguments(pvApiCtx);
+                        return 0;
+                    }
+                    else
+                    {
+                        Scierror(999, _("%s: Wrong type for input argument #%d: A string or a macro name expected.\n"), fname, 2);
+                        return 1;
+                    }
                 }
-
             }
             else
             {
@@ -118,13 +137,13 @@ int sci_datatip_set_display(char *fname, unsigned long fname_len)
         }
         else
         {
-            Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' handle expected.\n"), fname, 1, "Datatip");
+            Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' or '%s' handle expected.\n"), fname, 1, "Polyline", "Datatip");
             return 1;
         }
     }
     else
     {
-        Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' handle expected.\n"), fname, 1, "Datatip");
+        Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' or '%s' handle expected.\n"), fname, 1, "Polyline", "Datatip");
         return 1;
     }
 }
index 44a2bc4..75f63fe 100644 (file)
@@ -1053,7 +1053,6 @@ datatipRedraw
 datatipRemove
 datatipRemoveAll
 datatipRemoveNearest
-datatipSetDisplay
 datatipSetGUI
 datatipSetInterp
 datatipSetOrientation
index ff24e21..bf1b64b 100644 (file)
@@ -1,4 +1,4 @@
-!!_invoke_
+!_invoke_
 %H5Object_e
 %H5Object_fieldnames
 %H5Object_p
@@ -397,6 +397,7 @@ daskr
 dasrt
 dassl
 data2sig
+datatipsSetDisplay
 dawson
 dct
 debug