summaryrefslogtreecommitdiffstats
path: root/scilab
diff options
context:
space:
mode:
authorStéphane MOTTELET <stephane.mottelet@utc.fr>2019-05-15 18:13:19 +0200
committerClement DAVID <clement.david@esi-group.com>2020-12-22 12:20:10 +0100
commit04d8da5edae7eba142333d4b7b2834afbddf3d15 (patch)
tree4c503df6aaa5084da2a7e3da182142c14dc62450 /scilab
parent5c22e8c3c2edbc13bd2035340205c299816e546a (diff)
downloadscilab-04d8da5edae7eba142333d4b7b2834afbddf3d15.zip
scilab-04d8da5edae7eba142333d4b7b2834afbddf3d15.tar.gz
* Bug 7117 fixed: now findobj() can search within given object
http://bugzilla.scilab.org/show_bug.cgi?id=7117 help page: http://bugzilla.scilab.org/attachment.cgi?id=5153 Change-Id: I1c8c1e4b95b6b36686bdf1de7de5920ec3f2b0c6
Diffstat (limited to 'scilab')
-rw-r--r--scilab/CHANGES.md1
-rw-r--r--scilab/modules/gui/help/en_US/findobj.xml71
-rw-r--r--scilab/modules/gui/help/ja_JP/findobj.xml87
-rw-r--r--scilab/modules/gui/macros/findobj.sci203
4 files changed, 196 insertions, 166 deletions
diff --git a/scilab/CHANGES.md b/scilab/CHANGES.md
index c62a8d8..e94a97e 100644
--- a/scilab/CHANGES.md
+++ b/scilab/CHANGES.md
@@ -275,6 +275,7 @@ Bug Fixes
275 275
276### Bugs fixed in 6.1.1: 276### Bugs fixed in 6.1.1:
277* [#3188](https://bugzilla.scilab.org/3188): `part()` was slower than in Scilab 4.1.2. 277* [#3188](https://bugzilla.scilab.org/3188): `part()` was slower than in Scilab 4.1.2.
278* [#7117](https://bugzilla.scilab.org/7117): `findobj()` could not search within given object.
278* [#8059](https://bugzilla.scilab.org/8059): A local `.wgetrc` config file could make troubles in `atomsDownload`. 279* [#8059](https://bugzilla.scilab.org/8059): A local `.wgetrc` config file could make troubles in `atomsDownload`.
279* [#8378](https://bugzilla.scilab.org/8378): Datatip `ContextMenu => Delete last datatip` was useless. 280* [#8378](https://bugzilla.scilab.org/8378): Datatip `ContextMenu => Delete last datatip` was useless.
280* [#9909](https://bugzilla.scilab.org/9909): In the help browser, add a way to open the online version of the current page. 281* [#9909](https://bugzilla.scilab.org/9909): In the help browser, add a way to open the online version of the current page.
diff --git a/scilab/modules/gui/help/en_US/findobj.xml b/scilab/modules/gui/help/en_US/findobj.xml
index 6c730df..be954ec 100644
--- a/scilab/modules/gui/help/en_US/findobj.xml
+++ b/scilab/modules/gui/help/en_US/findobj.xml
@@ -7,7 +7,13 @@
7 <refsynopsisdiv> 7 <refsynopsisdiv>
8 <title>Syntax</title> 8 <title>Syntax</title>
9 <synopsis> 9 <synopsis>
10 h = findobj(propertyName, propertyValue) 10 h = findobj()
11 h = findobj(propertyName, propertyValue)
12 h = findobj(propertyName, propertyValue, operator, propertyName, propertyValue, ...)
13 h = findobj("-property", propertyName, ...)
14 h = findobj(searchHandles, ...)
15 h = findobj(..., '-depth', d, ...)
16 h = findobj(..., '-flat', ...)
11 </synopsis> 17 </synopsis>
12 </refsynopsisdiv> 18 </refsynopsisdiv>
13 <refsection> 19 <refsection>
@@ -22,13 +28,31 @@
22 <varlistentry> 28 <varlistentry>
23 <term>propertyValue</term> 29 <term>propertyValue</term>
24 <listitem> 30 <listitem>
25 <para>string character specify the value the tested property should be equal to (case sensitive).</para> 31 <para>character string specify the value the tested property should be equal to (case sensitive).</para>
32 </listitem>
33 </varlistentry>
34 <varlistentry>
35 <term>operator</term>
36 <listitem>
37 <para>character string belonging to the set {"-and", "-or", "-not"}.</para>
38 </listitem>
39 </varlistentry>
40 <varlistentry>
41 <term>searchHandles</term>
42 <listitem>
43 <para>Vector of graphic handles where the search is restricted to.</para>
44 </listitem>
45 </varlistentry>
46 <varlistentry>
47 <term>d</term>
48 <listitem>
49 <para>positive integer, the depth of the search.</para>
26 </listitem> 50 </listitem>
27 </varlistentry> 51 </varlistentry>
28 <varlistentry> 52 <varlistentry>
29 <term>h</term> 53 <term>h</term>
30 <listitem> 54 <listitem>
31 <para>handle of the found object.</para> 55 <para>handles of the found objects.</para>
32 </listitem> 56 </listitem>
33 </varlistentry> 57 </varlistentry>
34 </variablelist> 58 </variablelist>
@@ -36,17 +60,28 @@
36 <refsection> 60 <refsection>
37 <title>Description</title> 61 <title>Description</title>
38 <para> 62 <para>
39 This routine is currently used to find objects knowing their 'tag' 63 Without arguments <literal>findobj</literal> returns handles of all graphic objects and their descendants. If such an object does not exist, the
40 property. It returns handle of the first found object which property
41 <emphasis role="italic">propertyName</emphasis> is equal to <emphasis role="italic">propertyValue</emphasis>. If such an object does not exist, the
42 function returns an empty matrix. 64 function returns an empty matrix.
43 </para> 65 </para>
66 <para>
67 <literal>findobj(propertyName, propertyValue, ...)</literal> returns the handles of objects having the property <literal>propertyName</literal> set to <literal>propertyValue</literal>.
68 If successive property/vaue pairs are given the handles of objects verifing all conditions are returned, i.e. there is an implicit <literal>"-and"</literal> operator between pairs.
69 Another operator can be explicitely given with <literal>findobj(propertyName, propertyValue, operator, propertyName, propertyValue, ...)</literal>.
70 </para>
71 <para>The priority of evaluations in a composite condition using operators can be controlled by using a cell argument, e.g. <literal>findobj({propertyName, propertyValue, ...}, operator, ...)</literal>
72 </para>
73 <para>
74 <literal>findobj("-property", propertyName, ...)</literal> returns the handles of objects having the property <literal>propertyName</literal>. Other conditions can be added.
75 </para>
76 <para>
77 By default the search is done within all figures and <literal>findobj(searchHandles, ...)</literal> restricts the search to the given handles. The depth of the search is by default infinite and can be restricted by <literal>findobj(searchHandles, '-depth', d, ...)</literal>. A value of 0 restricts the search to objects given in <literal>searchHandles</literal> and does not search within descendants, this is equivalent to the <literal>"flat"</literal> optional string.
78 </para>
44 </refsection> 79 </refsection>
45 <refsection> 80 <refsection>
46 <title>Examples</title> 81 <title>Examples</title>
47 <programlisting role="example"><![CDATA[ 82 <programlisting role="example"><![CDATA[
48// Create a figure 83// Create a figure
49h=figure(); 84h=scf();
50// Put a text in the figure 85// Put a text in the figure
51uicontrol(h, "style","text", ... 86uicontrol(h, "style","text", ...
52 "string","This is a figure", ... 87 "string","This is a figure", ...
@@ -56,8 +91,26 @@ uicontrol(h, "style","text", ...
56// Find the object which "tag" value is "Alabel" 91// Find the object which "tag" value is "Alabel"
57lab=findobj("tag","Alabel"); 92lab=findobj("tag","Alabel");
58disp("The text of the label is """+lab.string+""""); 93disp("The text of the label is """+lab.string+"""");
59// Close the figure 94 ]]></programlisting>
60close(); 95 <programlisting role="example"><![CDATA[
96// Create a figure
97h=scf();
98// plot something
99plot()
100xlabel abscissae
101ylabel ordinate
102title "a plot"
103legend "c1" "c2" "c3"
104
105// Find the objects having a "font_size" property
106h1 = findobj("-property","font_size")
107// Change the font size of all text objects
108h1.font_size = 3
109
110// Find the objects having a "thickness" property
111h2 = findobj("-property","thickness")
112// Change the thickness of such objects
113h2.thickness = 2
61 ]]></programlisting> 114 ]]></programlisting>
62 </refsection> 115 </refsection>
63 <refsection role="see also"> 116 <refsection role="see also">
diff --git a/scilab/modules/gui/help/ja_JP/findobj.xml b/scilab/modules/gui/help/ja_JP/findobj.xml
deleted file mode 100644
index d990830..0000000
--- a/scilab/modules/gui/help/ja_JP/findobj.xml
+++ /dev/null
@@ -1,87 +0,0 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="ja" xml:id="findobj">
3 <refnamediv>
4 <refname>findobj</refname>
5 <refpurpose>指定したプロパティを有するオブジェクトを探す</refpurpose>
6 </refnamediv>
7 <refsynopsisdiv>
8 <title>呼び出し手順</title>
9 <synopsis>
10 h = findobj(propertyName, propertyValue)
11 </synopsis>
12 </refsynopsisdiv>
13 <refsection>
14 <title>引数</title>
15 <variablelist>
16 <varlistentry>
17 <term>propertyName</term>
18 <listitem>
19 <para>文字列,探すプロパティ名 (大文字小文字を区別しない).</para>
20 </listitem>
21 </varlistentry>
22 <varlistentry>
23 <term>propertyValue</term>
24 <listitem>
25 <para>
26 探すプロパティが一致する値を指定する文字列
27 (大文字小文字を区別する).
28 </para>
29 </listitem>
30 </varlistentry>
31 <varlistentry>
32 <term>h</term>
33 <listitem>
34 <para>見つかったオブジェクトのハンドル.</para>
35 </listitem>
36 </varlistentry>
37 </variablelist>
38 </refsection>
39 <refsection>
40 <title>説明</title>
41 <para>
42 このルーチンは,現在,
43 'tag'プロパティが既知のオブジェクトを探す際に使用されています.
44 このルーチンは,
45 <emphasis role="italic">propertyName</emphasis>が
46 <emphasis role="italic">propertyValue</emphasis>に等しい
47 最初に見つかったオブジェクトのハンドルを返します.
48 そのようなオブジェクトが存在しない場合,
49 この関数は空の行列を返します.
50 </para>
51 </refsection>
52 <refsection>
53 <title>例</title>
54 <programlisting role="example"><![CDATA[
55// 図を作成
56h=figure();
57// 図にテキストを表示
58uicontrol(h, "style","text", ...
59 "string","This is a figure", ...
60 "position",[50 70 100 100], ...
61 "fontsize",15, ...
62 "tag","Alabel");
63// "tag" の値が"Alabel"であるオブジェクトを探す
64lab=findobj("tag","Alabel");
65disp("The text of the label is """+lab.string+"""");
66// 図を閉じる
67close();
68 ]]></programlisting>
69 </refsection>
70 <refsection role="see also">
71 <title>参照</title>
72 <simplelist type="inline">
73 <member>
74 <link linkend="uicontrol">uicontrol</link>
75 </member>
76 <member>
77 <link linkend="uimenu">uimenu</link>
78 </member>
79 <member>
80 <link linkend="set">set</link>
81 </member>
82 <member>
83 <link linkend="get">get</link>
84 </member>
85 </simplelist>
86 </refsection>
87</refentry>
diff --git a/scilab/modules/gui/macros/findobj.sci b/scilab/modules/gui/macros/findobj.sci
index 66b6043..0f45b42 100644
--- a/scilab/modules/gui/macros/findobj.sci
+++ b/scilab/modules/gui/macros/findobj.sci
@@ -1,8 +1,8 @@
1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2// Copyright (C) 2008 - INRIA - Vincent COUVERT 2// Copyright (C) 2008 - INRIA - Vincent COUVERT
3// Copyright (C) 2008 - DIGITEO - Vincent COUVERT 3// Copyright (C) 2008 - DIGITEO - Vincent COUVERT
4//
5// Copyright (C) 2012 - 2016 - Scilab Enterprises 4// Copyright (C) 2012 - 2016 - Scilab Enterprises
5// Copyright (C) 2020 - Stéphane MOTTELET
6// 6//
7// This file is hereby licensed under the terms of the GNU GPL v2.0, 7// This file is hereby licensed under the terms of the GNU GPL v2.0,
8// pursuant to article 5.3.4 of the CeCILL v.2.1. 8// pursuant to article 5.3.4 of the CeCILL v.2.1.
@@ -11,93 +11,156 @@
11// For more information, see the COPYING file which you should have received 11// For more information, see the COPYING file which you should have received
12// along with this program. 12// along with this program.
13 13
14function h = findobj(propertyName, propertyValue) 14function h = findobj(varargin)
15 15
16 rhs = argn(2); 16 rhs = argn(2);
17 if rhs<> [1 2] then
18 msg = gettext("%s: Wrong number of input arguments: %d or %d expected.\n");
19 error(msprintf(msg, "findobj", 1, 2));
20 return;
21 end
22
23 if rhs == 1 then
24 h = get(propertyName);
25 return
26 end
27 if strcmp(propertyName, "tag", "i") == 0 then
28 h = get(propertyValue);
29 return
30 end
31
32 // Return value
33 h = []
34
35 // Get all opened figures
36 figureIds = winsid();
37 if isempty(figureIds) then
38 return
39 end
40 17
41 currentFig = gcf(); 18 searchHandles= [];
42 19 iPos = 1;
43 propertyName = convstr(propertyName,"l"); 20 if rhs >= 1
44 21 if typeof(varargin(1)) == "handle"
45 // Special fast case: finding a figure 22 if and(is_handle_valid(varargin(1)))
46 if propertyName=="figure_id" then 23 searchHandles = varargin(1);
47 if type(propertyValue)==1 & or(figureIds==propertyValue) 24 else
48 h = scf(propertyValue); 25 msg = gettext("%s: Input argument #%d must be a valid handle.\n");
49 scf(currentFig); 26 error(msprintf(msg, "findobj", 1));
27 end
28 iPos = 2;
29 elseif typeof(varargin(1) <> "string")
30 msg = gettext("%s: Wrong type for argument #%d: A string expected.\n");
31 error(msprintf(msg, "findobj", 1));
50 end 32 end
51 return
52 end 33 end
53 34
54 // Otherwise: 35 if isempty(searchHandles)
55 // Iterate over all figures 36 // Get all opened figures
56 for figureindex = 1:size(figureIds,2) 37 figureIds = winsid();
57 // Does the figure match the propertyName/propertyValue set ? 38 if isempty(figureIds) then
58 f=scf(figureIds(figureindex)); 39 return
59
60 %ierr = execstr("%bool = isequal(get(f, propertyName), propertyValue);", "errcatch");
61 if %ierr==0 & %bool then
62 h = f;
63 break
64 end 40 end
65 41 // Iterate over all figures
66 answ = findMatchingChild(f.children, propertyName, propertyValue); 42 for figureindex = 1:size(figureIds,2)
67 if ~isempty(answ) then 43 searchHandles(figureindex) = scf(figureIds(figureindex));
68 h = answ;
69 break
70 end 44 end
71 end 45 end
72 46
73 scf(currentFig); 47 try
48 [testString,depth] = parse(varargin(iPos:$));
49 catch
50 error(lasterror())
51 end
52
53 h = findMatchingChild(searchHandles, testString, depth);
74 54
75endfunction 55endfunction
76//-----------------------------------------------------------------------------
77function hFound = findMatchingChild(children, propertyName, propertyValue)
78 // Copyright DIGITEO 2008
79 // Vincent COUVERT
80 56
57function hFound = findMatchingChild(handles, testString, depth)
81 hFound = [] 58 hFound = []
82 59 for index = 1:size(handles,1)
83 for childIndex = 1:size(children,1) 60 h = handles(index);
84 61 [bResult, ierr] = evstr(testString);
85 %ierr = execstr("%bool = isequal(get(children(childIndex), propertyName), propertyValue);", "errcatch"); 62 if ierr==0 & bResult then
86 if %ierr==0 & %bool then 63 hFound = [hFound; handles(index)];
87 hFound = children(childIndex); 64 end
88 return 65 if depth > 0
66 [children,ierr] = evstr("get(handles(index), ""children"");"); // Does the child have a children property
67 if get(handles(index),"type") == "Axes" // Title and Label entities of Axes are children
68 children = [children
69 get(handles(index),"Title")
70 get(handles(index),"x_label")
71 get(handles(index),"y_label")
72 get(handles(index),"z_label")];
73 end
74 if ~isempty(children) // Yes the child can have children
75 answ = findMatchingChild(children, testString, depth-1);
76 if ~isempty(answ) then
77 hFound = [hFound; answ];
78 end
79 end
89 end 80 end
81 end
82endfunction
90 83
91 %ierr = execstr("get(children(childIndex), ""children"");", "errcatch"); // Does the child have a children property
92 84
93 if %ierr==0 then // Yes the child can have children 85function [out,depth] = parse(varargin)
94 answ = findMatchingChild(children(childIndex).children, propertyName, propertyValue); 86 operators = ["&&","||","~" ]
95 if ~isempty(answ) then 87 depth = %inf;
96 hFound = answ; 88 out = "";
97 return 89 currentOp = "";
90 i = 1;
91 while i <= length(varargin)
92 op = operators(varargin(i) == ["-and","-or","-not"]);
93 if ~isempty(op)
94 // token is an operator
95 if ~isempty(currentOp) && op <> "~"
96 msg = gettext("%s: Argument #%d cannot be a binary operator.");
97 error(msprintf(msg, "findobj", i));
98 end
99 currentOp = currentOp + op;
100 if op <> "~" && isempty(out)
101 msg = gettext("%s: Argument #%d cannot be a binary operator.");
102 error(msprintf(msg, "findobj", i));
103 end
104 if i == length(varargin)
105 msg = gettext("%s: Wrong number of input argument(s): At least %d expected.");
106 error(msprintf(msg, "findobj", i+1));
107 end
108 i = i+1;
109 continue
110 end
111 if ~isempty(out) && (isempty(currentOp) || currentOp == "~")
112 // by default all successive conditions are connected with &&
113 currentOp = "&&"+currentOp;
114 end
115 if typeof(varargin(i)) == "ce"
116 // recursively parse content of cell
117 cellArg = varargin(i);
118 out = out + msprintf("%s(%s)",currentOp,parse(cellArg{:}(:)));
119 currentOp = "";
120 i = i+1;
121 elseif varargin(i) == "-depth"
122 // set depth
123 if i < length(varargin)
124 n = varargin(i+1);
125 if type(n) == 1 && isscalar(n) && n >= 0 && floor(n) == n
126 depth = varargin(i+1);
127 i = i+2;
128 else
129 msg = gettext("%s: Wrong type for input argument #%d: A positive integer value expected.\n");
130 error(msprintf(msg, "findobj", i+1));
131 end
132 else
133 msg = gettext("%s: Wrong number of input argument(s): At least %d expected.");
134 error(msprintf(msg, "findobj", i+1));
135 end
136 elseif varargin(i) == "-flat"
137 // set depth at 0
138 depth = 0;
139 i = i+1;
140 elseif varargin(i) == "-property"
141 // search handles having a given property
142 if i < length(varargin)
143 if type(varargin(i+1)) == 10
144 out = out+msprintf("%s~execstr(""h.%s"",""errcatch"")",currentOp,varargin(i+1))
145 currentOp = "";
146 i = i+2;
147 else
148 msg = gettext("%s: Wrong type for argument #%d: A string expected.\n");
149 error(msprintf(msg, "findobj", i+1));
150 end
151 else
152 msg = gettext("%s: Wrong number of input argument(s): At least %d expected.");
153 error(msprintf(msg, "findobj", i+1));
154 end
155 else // property, value sequence, likely
156 if i < length(varargin)
157 out = out+msprintf("%s(h.%s==%s)",currentOp,varargin(i),sci2exp(varargin(i+1)));
158 currentOp = "";
159 i = i+2;
160 else
161 msg = gettext("%s: Wrong number of input argument(s): At least %d expected.");
162 error(msprintf(msg, "findobj", i+1));
98 end 163 end
99 end 164 end
100 end 165 end
101
102endfunction 166endfunction
103//-----------------------------------------------------------------------------