diff options
Diffstat (limited to 'modules/gui/macros/tree')
24 files changed, 994 insertions, 0 deletions
diff --git a/modules/gui/macros/tree/lib b/modules/gui/macros/tree/lib Binary files differnew file mode 100755 index 000000000..76bf7098e --- /dev/null +++ b/modules/gui/macros/tree/lib diff --git a/modules/gui/macros/tree/names b/modules/gui/macros/tree/names new file mode 100755 index 000000000..8f43993be --- /dev/null +++ b/modules/gui/macros/tree/names @@ -0,0 +1,11 @@ +uiConcatTree +uiCreateNode +uiCreateTree +uiDeleteNode +uiDumpTree +uiEqualsTree +uiFindNode +uiGetChildrenNode +uiGetNodePosition +uiGetParentNode +uiInsertNode diff --git a/modules/gui/macros/tree/uiConcatTree.bin b/modules/gui/macros/tree/uiConcatTree.bin Binary files differnew file mode 100755 index 000000000..99bdc2240 --- /dev/null +++ b/modules/gui/macros/tree/uiConcatTree.bin diff --git a/modules/gui/macros/tree/uiConcatTree.sci b/modules/gui/macros/tree/uiConcatTree.sci new file mode 100755 index 000000000..405a7c117 --- /dev/null +++ b/modules/gui/macros/tree/uiConcatTree.sci @@ -0,0 +1,41 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2009 - DIGITEO - Sylvestre Koumar +// +// 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 myNewTree = uiConcatTree(tree1, tree2) + + [lhs,rhs]=argn(0); + + + //Input arguments checking + if rhs <> 2 then + error(msprintf(gettext("%s: Wrong number of input arguments: %d expected.\n"), "uiConcatTree",2)); + return; + end + + // Check 1st and 2nd inputs : tree1 & tree2 + if rhs == 2 then + if (typeof(tree1) == "uitree") then + myTree1 = tree1; + else + error(msprintf(gettext("%s: Wrong type for input argument #%d: uitree expected.\n"), "uiConcatTree",1)); + return; + end + + if (typeof(tree2) == "uitree") then + myTree2 = tree2; + else + error(msprintf(gettext("%s: Wrong type for input argument #%d: uitree expected.\n"), "uiConcatTree",2)); + return; + end + end + + tree1($+1) = tree2; + myNewTree = tree1; + +endfunction diff --git a/modules/gui/macros/tree/uiCreateNode.bin b/modules/gui/macros/tree/uiCreateNode.bin Binary files differnew file mode 100755 index 000000000..71260a539 --- /dev/null +++ b/modules/gui/macros/tree/uiCreateNode.bin diff --git a/modules/gui/macros/tree/uiCreateNode.sci b/modules/gui/macros/tree/uiCreateNode.sci new file mode 100755 index 000000000..eb5f4a903 --- /dev/null +++ b/modules/gui/macros/tree/uiCreateNode.sci @@ -0,0 +1,57 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2009 - DIGITEO - Sylvestre Koumar +// +// 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 myNode = uiCreateNode(label, icon, callback) + + [lhs,rhs]=argn(0); + + //Input arguments checking + if rhs <= 0 | rhs > 3 then + error(msprintf(gettext("%s: Wrong number of input arguments: %d to %d expected.\n"), "uiCreateNode",1,3)); + return; + end + + // Check 1st input : label + if rhs >= 1 then + if (type(label) == 10) then + myLabel = label; + myIcon = ""; + myCallback = ""; + else + error(msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"), "uiCreateNode",1)); + return; + end + // Check 2nd input : icon + if rhs >= 2 then + if (type(icon) == 10) then + myIcon = icon; + myCallback = ""; + else + error(msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"), "uiCreateNode",2)); + return; + end + // Check 3rd input : callback + if rhs == 3 then + if (type(callback) == 10) then + myCallback = callback; + else + error(msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"), "uiCreateNode",3)); + return; + end + end + + end + + end + + // Creation of the node + node = struct("label",myLabel,"icon",myIcon,"callback",myCallback) + myNode = tlist("uitree", node) + +endfunction diff --git a/modules/gui/macros/tree/uiCreateTree.bin b/modules/gui/macros/tree/uiCreateTree.bin Binary files differnew file mode 100755 index 000000000..2d35baf6e --- /dev/null +++ b/modules/gui/macros/tree/uiCreateTree.bin diff --git a/modules/gui/macros/tree/uiCreateTree.sci b/modules/gui/macros/tree/uiCreateTree.sci new file mode 100755 index 000000000..90cc4dbc5 --- /dev/null +++ b/modules/gui/macros/tree/uiCreateTree.sci @@ -0,0 +1,39 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2009 - DIGITEO - Sylvestre Koumar +// +// 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 myTree = uiCreateTree(parentNode, varargin) + + [lhs,rhs]=argn(0); + + //Input arguments checking + if rhs == 0 then + error(msprintf(gettext("%s: Wrong number of input argument(s): At least %d expected.\n"), "uiCreateTree",1)); + return; + end + + if rhs >=1 then + // Check if parentNode is a Tree + if (typeof(parentNode) == "uitree") then + myTree = tlist("uitree", parentNode(2)); + // Add subTrees into myTree + for subTreesIndex = 1:size(varargin) + if (typeof(varargin(subTreesIndex)) == "uitree") then + myTree(subTreesIndex + 2) = varargin(subTreesIndex) + else + error(msprintf(gettext("%s: Wrong type for element %d of input argument #%d: uitree expected.\n"), "uiCreateTree", subTreesIndex, 2)); + return; + end + end + else + error(msprintf(gettext("%s: Wrong type for input argument #%d: uitree expected.\n"), "uiCreateTree",1)); + return; + end + end + +endfunction diff --git a/modules/gui/macros/tree/uiDeleteNode.bin b/modules/gui/macros/tree/uiDeleteNode.bin Binary files differnew file mode 100755 index 000000000..296b11584 --- /dev/null +++ b/modules/gui/macros/tree/uiDeleteNode.bin diff --git a/modules/gui/macros/tree/uiDeleteNode.sci b/modules/gui/macros/tree/uiDeleteNode.sci new file mode 100755 index 000000000..61f66cb5b --- /dev/null +++ b/modules/gui/macros/tree/uiDeleteNode.sci @@ -0,0 +1,126 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2009 - DIGITEO - Sylvestre Koumar +// +// 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 myNewTree = uiDeleteNode(tree, position) + + [lhs,rhs]=argn(0); + + //Input arguments checking + if rhs <> 2 then + error(msprintf(gettext("%s: Wrong number of input arguments: %d expected.\n"), "uiDeleteNode",2)); + return; + end + + // Check 1st and 2nd inputs : tree & (position or node) + if rhs == 2 then + if (typeof(tree) == "uitree") then + myTree = tree; + isPosition = %F; + isNode = %F; + else + error(msprintf(gettext("%s: Wrong type for input argument #%d: uitree expected.\n"), "uiDeleteNode",1)); + return; + end + + if (type(position) == 10) then + myPosition = position; + isPosition = %T; + + elseif (typeof(position) == "uitree") then + myNode = position; + isNode = %T; + else + error(msprintf(gettext("%s: Wrong type for input argument #%d: String or uitree expected.\n"), "uiDeleteNode",2)); + return; + end + end + + // Check if the given position exist + function existPos = existPosition(myTree, myPosition, existPos, curPos) + + if (myPosition == curPos) then + existPos = %T; + end + + for index = 3:size(myTree) + if curPos ~= "root" then + existPos = existPosition(myTree(index), myPosition, existPos, curPos+"."+string(index-2)) + else + existPos = existPosition(myTree(index), myPosition, existPos, string(index-2)) + end + end + endfunction + + // Find the node at the given position and delete it + function r = findAndDelete(myTree, atPosition, curpos) + + r = uiCreateTree(myTree); + for index = 3:size(myTree) + + if curpos ~= "root" then + localpos = curpos+"."+string(index-2); + else + localpos = string(index-2); + end + + // We don't do the concatenation for the given position + // What means making a deletion + if localpos <> atPosition then + r = uiConcatTree(r,findAndDelete(myTree(index), atPosition, localpos)); + end + end + endfunction + + // Deletion with a position + if isPosition then + + // Check if the given position is valid(exists in the tree) + existPos = %F; + existPos = existPosition(myTree, myPosition, existPos, "root"); + + if existPos then + myNewTree = findAndDelete(myTree, myPosition, "root"); + else + error(msprintf(gettext("%s: Invalid position ''%s''.\n"), "uiDeleteNode",myPosition)); + end + end + + // Deletion with a node + if isNode then + + // Check if the given node is valid(exists in the tree OR too many matching nodes) + r = uiFindNode(myTree, myNode); + + if (size(r) == 1) then + + nodePosList = uiGetNodePosition(myTree, myNode); + + if size(nodePosList) == 1 then + nodePos = nodePosList(1); + + myNewTree = findAndDelete(myTree, nodePos, "root"); + + elseif size(nodePosList) > 1 then + error(msprintf(gettext("%s: #%d matching nodes.\n"), "uiDeleteNode",size(nodePosList))); + return; + else + error(msprintf(gettext("%s: Invalid node.\n"), "uiDeleteNode")); + return; + end + + elseif (size(r) > 1) then + error(msprintf(gettext("%s: #%d matching nodes.\n"), "uiDeleteNode",size(r))); + return; + elseif (size(r) == 0) then + error(msprintf(gettext("%s: No matching node.\n"), "uiDeleteNode")); + return; + end + end + +endfunction diff --git a/modules/gui/macros/tree/uiDumpTree.bin b/modules/gui/macros/tree/uiDumpTree.bin Binary files differnew file mode 100755 index 000000000..59cf7753f --- /dev/null +++ b/modules/gui/macros/tree/uiDumpTree.bin diff --git a/modules/gui/macros/tree/uiDumpTree.sci b/modules/gui/macros/tree/uiDumpTree.sci new file mode 100755 index 000000000..b319ba688 --- /dev/null +++ b/modules/gui/macros/tree/uiDumpTree.sci @@ -0,0 +1,69 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2009 - DIGITEO - Sylvestre Koumar +// +// 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 uiDumpTree(tree, b) + + [lhs,rhs]=argn(0); + + //Input arguments checking + if rhs <= 0 | rhs > 2 then + error(msprintf(gettext("%s: Wrong number of input arguments: %d to %d expected.\n"), "uiDumpTree",1,2)); + return; + end + + // Check 1st input : tree + if rhs >= 1 then + if (typeof(tree) == "uitree") then + myTree = tree; + myB = %F; + else + error(msprintf(gettext("%s: Wrong type for input argument #%d: uitree expected.\n"), "uiDumpTree",1)); + return; + end + // Check 2nd input : b + if rhs == 2 then + if (type(b) == 4) then + myB = b; + else + error(msprintf(gettext("%s: Wrong type for input argument #%d: Boolean expected.\n"), "uiDumpTree",2)); + return; + end + end + end + + // Printing the tree + function prettyPrint(myTree, myB, indentation) + + mprintf(indentation); + mprintf("|_./ "); + mprintf(myTree(2).label + "\n"); + + indentation = indentation + "| "; + + if myB then + mprintf(indentation); + mprintf("`- " + myTree(2).icon + "\n"); + mprintf(indentation); + mprintf("`- " + myTree(2).callback + "\n"); + end + + for childIndex = 3:size(myTree) + prettyPrint(myTree(childIndex), myB, indentation); + end + + endfunction + + prettyPrint(myTree, myB, ""); + +endfunction + + + + + diff --git a/modules/gui/macros/tree/uiEqualsTree.bin b/modules/gui/macros/tree/uiEqualsTree.bin Binary files differnew file mode 100755 index 000000000..e93ed8afa --- /dev/null +++ b/modules/gui/macros/tree/uiEqualsTree.bin diff --git a/modules/gui/macros/tree/uiEqualsTree.sci b/modules/gui/macros/tree/uiEqualsTree.sci new file mode 100755 index 000000000..1e3b5aa69 --- /dev/null +++ b/modules/gui/macros/tree/uiEqualsTree.sci @@ -0,0 +1,60 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2009 - DIGITEO - Sylvestre Koumar +// +// 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 b = uiEqualsTree(tree1, tree2) + + [lhs,rhs]=argn(0); + + //Input arguments checking + if rhs <> 2 then + error(msprintf(gettext("%s: Wrong number of input arguments: %d expected.\n"), "uiEqualsTree",2)); + return; + end + + // Check 1st and 2nd inputs : tree1 & tree2 + if rhs == 2 then + if (typeof(tree1) == "uitree") then + myTree1 = tree1; + else + error(msprintf(gettext("%s: Wrong type for input argument #%d: uitree expected.\n"), "uiEqualsTree",1)); + return; + end + + if (typeof(tree2) == "uitree") then + myTree2 = tree2; + else + error(msprintf(gettext("%s: Wrong type for input argument #%d: uitree expected.\n"), "uiEqualsTree",2)); + return; + end + end + + // Check if features of each nodes are matching + if myTree1(1) == myTree2(1) then + if myTree1(2).label == myTree2(2).label then + if myTree1(2).icon == myTree2(2).icon then + if myTree1(2).callback == myTree2(2).callback then + b = %T + else + b = %F + return; + end + else + b = %F + return; + end + else + b = %F + return; + end + else + b = %F + return; + end + +endfunction diff --git a/modules/gui/macros/tree/uiFindNode.bin b/modules/gui/macros/tree/uiFindNode.bin Binary files differnew file mode 100755 index 000000000..7f4ee47af --- /dev/null +++ b/modules/gui/macros/tree/uiFindNode.bin diff --git a/modules/gui/macros/tree/uiFindNode.sci b/modules/gui/macros/tree/uiFindNode.sci new file mode 100755 index 000000000..abb88aa7a --- /dev/null +++ b/modules/gui/macros/tree/uiFindNode.sci @@ -0,0 +1,148 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2009 - DIGITEO - Sylvestre Koumar +// +// 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 nodeList = uiFindNode(tree, node, value) + + [lhs,rhs]=argn(0); + + //Input arguments checking + if rhs < 2 | rhs > 3 then + error(msprintf(gettext("%s: Wrong number of input arguments: %d or %d expected.\n"), "uiFindNode",2,3)); + return; + end + + // Check 1st and 2nd inputs : tree & (node or property) + if rhs >= 2 then + if (typeof(tree) == "uitree") then + myTree = tree; + isNode = %F; + isPosition = %F; + isProperty = %F; + else + error(msprintf(gettext("%s: Wrong type for input argument #%d: uitree expected.\n"), "uiFindNode",1)); + return; + end + + if (typeof(node) == "uitree") then + myNode = node; + isNode = %T; + + elseif (type(node) == 10) then + if rhs == 2 + myPosition = node; + isPosition = %T; + end + else + error(msprintf(gettext("%s: Wrong type for input argument #%d: String or uitree expected.\n"), "uiFindNode",2)); + return; + end + + // Check 3rd input : property's value + if rhs == 3 then + if (type(node) == 10 & type(value) == 10) then + if (node == "label" | node == "icon" | node == "callback") then + myProperty = node; + myValue = value; + isProperty = %T; + else + error(msprintf(gettext("%s: Wrong type for input argument #%d: must be ''label'', ''icon'' or ''callback''.\n"), "uiFindNode",2)); + return; + end + else + error(msprintf(gettext("%s: Wrong type for input argument #%d or #%d: String expected.\n"), "uiFindNode",2,3)); + return; + end + end + end + + // Find matching node(s) + function r = internalFindNode(myTree, myNode, r) + + if uiEqualsTree(myTree, myNode) then + r($+1) = myTree; + end + + for index = 3:size(myTree) + r = internalFindNode(myTree(index), myNode, r) + end + + endfunction + + // Finding node with a given position + function r = findPos(myTree, myPosition, r, curpos) + + if myPosition == curpos then + r($+1) = myTree; + end + + for index = 3:size(myTree) + if curpos ~= "root" then + r = findPos(myTree(index), myPosition, r, curpos+"."+string(index-2)) + else + r = findPos(myTree(index), myPosition, r, string(index-2)) + end + end + + endfunction + + // Finding node(s) with a given property + function r = findProperty(myTree, myProperty, myValue, r) + + if myTree(2)(myProperty) == myValue then + r($+1) = myTree; + end + + for index = 3:size(myTree) + r = findProperty(myTree(index), myProperty, myValue, r) + end + + endfunction + + // List containing result + r = list(); + + // Find with a node + if isNode then + // List of matching nodes + nodeList = internalFindNode(myTree, myNode, r); + if (size(nodeList) > 1) then + warning(msprintf(gettext("%s: #%d matching nodes.\n"), "uiFindNode",size(nodeList))); + return; + elseif (size(nodeList) == 0) then + warning(msprintf(gettext("%s: No results found.\n"), "uiFindNode")); + return; + end + end + + // Find with a position + if isPosition then + // List of matching nodes + nodeList = findPos(myTree, myPosition, r, "root"); + if size(nodeList) == 0 then + error(msprintf(gettext("%s: Invalid position ''%s''.\n"), "uiFindNode",myPosition)); + return; + end + end + + // Find with a property + if isProperty then + // List of matching nodes + nodeList = findProperty(myTree, myProperty, myValue, r) + if size(nodeList) == 0 then + warning(msprintf(gettext("%s: No results found for property ''%s'' and value ''%s''.\n"), "uiFindNode",myProperty, myValue)); + return; + else + if (size(nodeList) > 1) then + warning(msprintf(gettext("%s: #%d matching nodes.\n"), "uiFindNode",size(nodeList))); + return; + end + end + end + +endfunction diff --git a/modules/gui/macros/tree/uiGetChildrenNode.bin b/modules/gui/macros/tree/uiGetChildrenNode.bin Binary files differnew file mode 100755 index 000000000..e2a46da73 --- /dev/null +++ b/modules/gui/macros/tree/uiGetChildrenNode.bin diff --git a/modules/gui/macros/tree/uiGetChildrenNode.sci b/modules/gui/macros/tree/uiGetChildrenNode.sci new file mode 100755 index 000000000..a0dbd02fc --- /dev/null +++ b/modules/gui/macros/tree/uiGetChildrenNode.sci @@ -0,0 +1,81 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2009 - DIGITEO - Sylvestre Koumar +// +// 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 childrenNode = uiGetChildrenNode(tree, node) + + [lhs,rhs]=argn(0); + + //Input arguments checking + if rhs <> 2 then + error(msprintf(gettext("%s: Wrong number of input arguments: %d expected.\n"), "uiGetChildrenNode",2)); + return; + end + + // Check 1st and 2nd inputs : tree & (node or position) + if rhs == 2 then + if (typeof(tree) == "uitree") then + myTree = tree; + isNode = %F; + isPosition = %F; + else + error(msprintf(gettext("%s: Wrong type for input argument #%d: uitree expected.\n"), "uiGetChildrenNode",1)); + return; + end + + if (typeof(node) == "uitree") then + myNode = node; + isNode = %T; + + elseif (type(node) == 10) then + myPosition = node; + isPosition = %T; + + else + error(msprintf(gettext("%s: Wrong type for input argument #%d: String or uitree expected.\n"), "uiGetChildrenNode",2)); + return; + end + end + + // Find children nodes + function childrenNode = findChildren(myTree, childrenNode) + + childrenNode($+1) = myTree; + + for index = 3:size(myTree) + childrenNode = findChildren(myTree(index), childrenNode) + end + + endfunction + + if isNode then + // First find if the node exists and if we have multiple matching nodes + result = uiFindNode(myTree, myNode) + end + + if isPosition then + // First find if the position exists and if we have multiple matching nodes + result = uiFindNode(myTree, myPosition) + end + + if (size(result) == 1) then + parentNode = result(1); + + result2 = list(); + // List containing children nodes + result2 = findChildren(parentNode, result2); + + childrenNode = list(); + for index = 2:size(result2) + childrenNode($+1) = result2(index); + end + else + childrenNode = list(); + end + +endfunction diff --git a/modules/gui/macros/tree/uiGetNodePosition.bin b/modules/gui/macros/tree/uiGetNodePosition.bin Binary files differnew file mode 100755 index 000000000..3cc942f73 --- /dev/null +++ b/modules/gui/macros/tree/uiGetNodePosition.bin diff --git a/modules/gui/macros/tree/uiGetNodePosition.sci b/modules/gui/macros/tree/uiGetNodePosition.sci new file mode 100755 index 000000000..feec4c87c --- /dev/null +++ b/modules/gui/macros/tree/uiGetNodePosition.sci @@ -0,0 +1,58 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2009 - DIGITEO - Sylvestre Koumar +// +// 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 position = uiGetNodePosition(tree, node) + + [lhs,rhs]=argn(0); + + //Input arguments checking + if rhs <> 2 then + error(msprintf(gettext("%s: Wrong number of input arguments: %d expected.\n"), "uiGetNodePosition",2)); + return; + end + + // Check 1st and 2nd inputs : tree & node + if rhs == 2 then + if (typeof(tree) == "uitree") then + myTree = tree; + else + error(msprintf(gettext("%s: Wrong type for input argument #%d: uitree expected.\n"), "uiGetNodePosition",1)); + return; + end + + if (typeof(node) == "uitree") then + myNode = node; + else + error(msprintf(gettext("%s: Wrong type for input argument #%d: uitree expected.\n"), "uiGetNodePosition",2)); + return; + end + end + + // Find node(s) position(s) + function r = findPos(myTree, myNode, r, curpos) + + if uiEqualsTree(myTree, myNode) then + r($+1) = curpos; + end + + for index = 3:size(myTree) + if curpos ~= "root" then + r = findPos(myTree(index), myNode, r, curpos+"."+string(index-2)) + else + r = findPos(myTree(index), myNode, r, string(index-2)) + end + end + + endfunction + + // List of matching nodes + r = list(); + position = findPos(myTree, myNode, r, "root"); + +endfunction diff --git a/modules/gui/macros/tree/uiGetParentNode.bin b/modules/gui/macros/tree/uiGetParentNode.bin Binary files differnew file mode 100755 index 000000000..9b355097f --- /dev/null +++ b/modules/gui/macros/tree/uiGetParentNode.bin diff --git a/modules/gui/macros/tree/uiGetParentNode.sci b/modules/gui/macros/tree/uiGetParentNode.sci new file mode 100755 index 000000000..51bdb5c43 --- /dev/null +++ b/modules/gui/macros/tree/uiGetParentNode.sci @@ -0,0 +1,91 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2009 - DIGITEO - Sylvestre Koumar +// +// 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 parentNode = uiGetParentNode(tree, node) + + [lhs,rhs]=argn(0); + + //Input arguments checking + if rhs <> 2 then + error(msprintf(gettext("%s: Wrong number of input arguments: %d expected.\n"), "uiGetParentNode",2)); + return; + end + + // Check 1st and 2nd inputs : tree & (node or position) + if rhs == 2 then + if (typeof(tree) == "uitree") then + myTree = tree; + isNode = %F; + isPosition = %F; + else + error(msprintf(gettext("%s: Wrong type for input argument #%d: uitree expected.\n"), "uiGetParentNode",1)); + return; + end + + if (typeof(node) == "uitree") then + myNode = node; + isNode = %T; + + elseif (type(node) == 10) then + myPosition = node; + isPosition = %T; + + else + error(msprintf(gettext("%s: Wrong type for input argument #%d: String or uitree expected.\n"), "uiGetParentNode",2)); + return; + end + end + + + // Find parent node + function [parentNode, found]= findParent(myTree, sonNode) + + found = %f; + parentNode = list(); + // if the son tree exist + if uiEqualsTree(myTree, sonNode) then + found = %t; + end + + if ~found then + for index = 3:size(myTree) + [parentNode, found] = findParent(myTree(index), sonNode) + if parentNode ~= list() then + break; + end + if found then + found = %f; + parentNode = uiCreateTree(myTree); + break; + end + end + end + + endfunction + + if isNode then + // First find if the node exist and if we have multiple matching nodes + result = uiFindNode(myTree, myNode) + end + + if isPosition then + // First find if the position exist and if we have multiple matching nodes + result = uiFindNode(myTree, myPosition) + end + + if (size(result) == 1) then + sonNode = result(1); + + [parentNode, found] = findParent(myTree, sonNode) + else + error(msprintf(gettext("%s: #%d matching nodes.\n"), "uiGetParentNode", size(result))); + return; + end + +endfunction diff --git a/modules/gui/macros/tree/uiInsertNode.bin b/modules/gui/macros/tree/uiInsertNode.bin Binary files differnew file mode 100755 index 000000000..129e5ea2b --- /dev/null +++ b/modules/gui/macros/tree/uiInsertNode.bin diff --git a/modules/gui/macros/tree/uiInsertNode.sci b/modules/gui/macros/tree/uiInsertNode.sci new file mode 100755 index 000000000..c248ab589 --- /dev/null +++ b/modules/gui/macros/tree/uiInsertNode.sci @@ -0,0 +1,213 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2009 - DIGITEO - Sylvestre Koumar +// +// 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 myNewTree = uiInsertNode(tree, position, node) + + [lhs,rhs]=argn(0); + + //Input arguments checking + if rhs <> 3 then + error(msprintf(gettext("%s: Wrong number of input arguments: %d expected.\n"), "uiInsertNode",3)); + return; + end + + // Check 1st, 2nd and 3rd inputs : tree, (position or parent node) & node + if rhs == 3 then + if (typeof(tree) == "uitree") then + myTree = tree; + isPosition = %F; + isParentNode = %F; + else + error(msprintf(gettext("%s: Wrong type for input argument #%d: uitree expected.\n"), "uiInsertNode",1)); + return; + end + + if (type(position) == 10) then + myPosition = position; + isPosition = %T; + + elseif (typeof(position) == "uitree") then + myParentNode = position; + isParentNode = %T; + else + error(msprintf(gettext("%s: Wrong type for input argument #%d: String or uitree expected.\n"), "uiInsertNode",2)); + return; + end + + if (typeof(node) == "uitree") then + myNode = node; + else + error(msprintf(gettext("%s: Wrong type for input argument #%d: uitree expected.\n"), "uiInsertNode",3)); + return; + end + end + + // Return the previous position of a node + function prevPos = previousPosition(myTree, myPosition) + + // Tokenise the position + TOKENS = []; + token = strtok(myPosition,"."); + TOKENS = [TOKENS,token]; + while( token <> "" ) + token = strtok("."); + TOKENS = [TOKENS,token]; + end + + nbElement = size(TOKENS,"*")-1; // because the tokens have the last element as " " + + // Previous position of "1" returns "root" + if myPosition == "1" then + prevPos = "root"; + end + + // if we have an integer position (ex: 1, 2, 3 ...) + if nbElement == 1 & myPosition <> "1" then + pos = eval(TOKENS(1)); + prevPos = string(pos-1); + end + + // if we have a complexe position (ex: 1.1, 2.4, 3.8 ...) + if nbElement > 1 then + + first = eval(TOKENS(nbElement-1)); + second = eval(TOKENS(nbElement)); + + if (second == 1) then + prevPos = TOKENS(1); + for index = 2:nbElement-1 + prevPos = prevPos + "." + TOKENS(index); + end + elseif (second > 1) then + + prevPos = TOKENS(1); + for index = 2:nbElement-1 + prevPos = prevPos + "." + TOKENS(index); + end + + pos = eval(TOKENS(nbElement)); + prevPos = prevPos + "." + string(pos-1); + end + end + + // Previous position of "0" or "root" returns an error + if myPosition == "0" | myPosition == "root" then + error(msprintf(gettext("%s: Invalid position ''%s''.\n"), "uiInsertNode",myPosition)); + return; + end + + endfunction + + // Check if the position exist + function existPos = existPosition(myTree, myPosition, existPos, curPos) + + if (myPosition == curPos) then + existPos = %T; + end + + for index = 3:size(myTree) + if curPos ~= "root" then + existPos = existPosition(myTree(index), myPosition, existPos, curPos+"."+string(index-2)); + else + existPos = existPosition(myTree(index), myPosition, existPos, string(index-2)); + end + end + + endfunction + + // Find a node and do the insertion with existing position + function r = findAndInsert(myTree, atPosition, curpos, node) + + r = uiCreateTree(myTree); + for index = 3:size(myTree) + + if curpos ~= "root" then + localpos = curpos+"."+string(index-2); + else + localpos = string(index-2); + end + + if localpos == atPosition then + r = uiConcatTree(r, node); + end + r = uiConcatTree(r,findAndInsert(myTree(index), atPosition, localpos, node)); + end + + endfunction + + // Insertion in a node which the position don't exists + function r = findAndConcat(myTree, atPosition, curpos, node) + + r = uiCreateTree(myTree); + for index = 3:size(myTree) + + if curpos ~= "root" then + localpos = curpos+"."+string(index-2); + else + localpos = string(index-2); + end + + r = uiConcatTree(r,findAndConcat(myTree(index), atPosition, localpos, node)); + if localpos == atPosition + r = uiConcatTree(r, node); + end + end + + endfunction + + // Insertion with a position + if isPosition then + + prevPos = ""; + prevPos = previousPosition(myTree, myPosition); + + existPos = %F; + existPrevPos = %F; + existPos = existPosition(myTree, myPosition, existPos, "root"); + existPrevPos = existPosition(myTree, prevPos, existPrevPos, "root"); + + + if (existPos & existPrevPos) then + + myNewTree = findAndInsert(myTree, myPosition, "root", myNode); + + elseif (existPos == %F & existPrevPos == %T) then + + parentNode = uiGetParentNode(myTree, prevPos); + parentNode($+1) = myNode; + + myNewTree = findAndConcat(myTree, prevPos, "root", myNode); + + else + error(msprintf(gettext("%s: Invalid position ''%s''.\n"), "uiInsertNode",myPosition)); + return; + end + + end + + // Insertion with a parent node + if isParentNode then + + nodePosList = uiGetNodePosition(myTree, myParentNode); + + if size(nodePosList) == 1 then + parentNodePos = nodePosList(1); + + myNewTree = findAndConcat(myTree, parentNodePos, "root", myNode); + + elseif size(nodePosList) > 1 then + error(msprintf(gettext("%s: #%d matching parent nodes.\n"), "uiInsertNode",size(nodePosList))); + return; + else + error(msprintf(gettext("%s: Invalid parent node.\n"), "uiInsertNode")); + return; + end + end + +endfunction |