* Bug 16095 fixed: matrix_handles.prop = [] restored
[scilab.git] / scilab / modules / graphics / macros / %h_set.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) INRIA
3 // Copyright (C) 2012 - 2016 - Scilab Enterprises
4 // Copyright (C) 2018 - Samuel GOUGEON
5 //
6 // This file is hereby licensed under the terms of the GNU GPL v2.0,
7 // pursuant to article 5.3.4 of the CeCILL v.2.1.
8 // This file was originally licensed under the terms of the CeCILL v2.1,
9 // and continues to be available under such terms.
10 // For more information, see the COPYING file which you should have received
11 // along with this program.
12
13 function hdl = %h_set(varargin)
14     s = size(varargin);
15     if s == 2
16         str = varargin(1)
17         val = varargin(2)
18         hdl=[]
19         set(str, val)
20
21     elseif s > 2
22         hdl = varargin(1)
23         Hsize = size(hdl);
24         nh = prod(Hsize);
25         for i = 2:2:s   // Loop on ("property",value) pairs
26             prop = varargin(i);
27             rhs = varargin(i+1);
28             if nh==1
29                 // scalar handle => direct assignment
30                 hdl(prop) = rhs;
31             else
32                 // array of handles
33                 RHSsize = size(rhs);
34                 for j = 1:nh  // Loop on handles
35                     h = hdl(j)  // works around http://bugzilla.scilab.org/15802
36                     lhs = h(prop);     // Current handle's content
37                     LHSsize = size(lhs);
38                     if and(RHSsize==LHSsize) | lhs==[] | rhs==[]
39                         // => repeated assignment
40                         h(prop) = rhs;
41                     elseif size(lhs,"*")==1 & and(RHSsize==Hsize)
42                         // => element-wise assignments
43                         h(prop) = rhs(j);
44                     elseif LHSsize(2)==1 & LHSsize(1)==RHSsize(1) & RHSsize(2)==nh
45                         // column-wise assignments
46                         h(prop) = rhs(:,j);
47                     elseif LHSsize(1)==1 & LHSsize(2)==RHSsize(2) & RHSsize(1)==nh
48                         // row-wise assignments
49                         h(prop) = rhs(j,:);
50                     elseif prod(LHSsize)==prod(RHSsize)
51                         // Repeated assignment after RHS reformating
52                         h(prop) = matrix(rhs,LHSsize);
53                     elseif RHSsize(1)==nh & RHSsize(2)==prod(LHSsize)
54                         // example: axes.data_bounds is a 2x2 matrix,
55                         //          but a 1x4 assigment is possible
56                         h(prop) = rhs(j,:);
57                     else
58                         msg = _("%s: Unsupported assignment for property ''%s''.\n")
59                         error(msprintf(msg, "%h_set", prop))
60                     end
61                     hdl(j) = h;
62                 end
63             end
64         end
65     end
66 endfunction