add display_tree function in gui module
antoine ELIAS [Fri, 3 Apr 2009 08:08:24 +0000 (10:08 +0200)]
scilab/modules/core/includes/stack3.h
scilab/modules/core/src/c/stack3.c
scilab/modules/gui/includes/gw_gui.h
scilab/modules/gui/sci_gateway/c/gw_gui.c
scilab/modules/gui/sci_gateway/cpp/sci_displaytree.cpp [new file with mode: 0644]
scilab/modules/gui/sci_gateway/gui_gateway.xml
scilab/modules/gui/src/c/LibScilab_Import.def
scilab/modules/gui/src/c/gui.vcproj
scilab/modules/gui/src/cpp/displaytree.cpp [new file with mode: 0644]
scilab/modules/gui/src/cpp/displaytree.hxx [new file with mode: 0644]

index 5156ebb..afc88bd 100644 (file)
@@ -315,7 +315,9 @@ int iAllocMatrixOfStringToAddress(int _iAddr, int _iRows, int _iCols, int *_piLe
 
 /*Get List Information*/
 //Get Item Count and type of each item
-int iGetListItemType(int _iVar, int *_piItemNumber, int *_pElemType);
+int iGetListItemType(int _iVar, int* _piParentList, int *_piItemNumber, int *_pElemType);
+//Get SubList reference
+int* iGetListItemList(int _iVar, int* _piParentList, int iItemPos);
 //Get Sparse Item
 int iGetListItemSparse(int _iVar, int _iItemNumber, int *_piRows, int *_piCols, int* _piTotalElem, int* _piElemByRow, double **_pdblReal, double **_pdblImg);
 //Get Poly Item
@@ -327,6 +329,9 @@ int iIsComplexItemElem(int _iVar, int _iItemNumber);
 //Get Item String
 int iGetListItemString(int _iVar, int _iItemNumber, int *_piRows, int *_piCols, int *_piLen, char* _pszData);
 
+//Get SubItem String
+int iGetListSubItemString(int _iVar, int* _piParentList, int _iItemNumber, int *_piRows, int *_piCols, int *_piLen, char* _pszData);
+
 /*Create List*/
 //Reserved VarNum for List
 int* iAllocList(int _iVar, int _iItemNumber);
@@ -381,6 +386,8 @@ int IsKindOfList(int* _piNode);
 void vCloseNode(int _iVar, int *_piCurrentNode, int _iItemPos, int *_piEnd);
 
 
+//Internal fonctions to retrieve varaibles information from pointer ( real memory address )
+int iGetStringFromPointer(int* _piAddr, int *_piRows, int *_piCols, int *_piLen, int** _piString);
 
 
 //Internal fonctions to retrieve varaibles information from Address ( old "il" )
index 47700b4..1956412 100644 (file)
@@ -780,7 +780,7 @@ int iArraySum(int *_piArray, int _iStart, int _iEnd)
        /*Iterative function*/
        int iIndex = 0;
        int iVal = 0;
-       for(iIndex = 0 ; iIndex < _iEnd ; iIndex++)
+       for(iIndex = _iStart >= 0 ? _iStart : 0; iIndex < _iEnd ; iIndex++)
        {
                iVal += _piArray[iIndex];
        }
@@ -1535,33 +1535,50 @@ int iAllocBooleanSparseMatrix(int _iNewVal, int _iRows, int _iCols, int _iTotalE
        return 0;
 }
 
-int iGetListItemType(int _iVar, int *_piItemNumber, int *_pElemType)
+int iGetListItemType(int _iVar, int* _piParentList, int *_piItemNumber, int *_pElemType)
 {
-       int iAddrBase           = iadr(*Lstk(Top - Rhs + _iVar));
-       int iValType            = *istk(iAddrBase);
-       int iAddrOffset         = iAddrBase + 2;
-       int iAddrItem           = 0;
-
+       int *piBase                     = NULL;
+       int *piOffset           = NULL;
+       int *piItem                     = NULL;
        int iIndex                      = 0;
-       if(iValType < 0)
+
+       if(_piParentList == NULL)
        {
-               iAddrBase               = iadr(*istk(iAddrBase + 1));
-               iAddrOffset             = iAddrBase + 2;
-               iValType                = *istk(iAddrBase);
+               int iAddrBase   =       iadr(*Lstk(Top - Rhs + _iVar));
+               int iValType    = *istk(iAddrBase);
+
+               if(iValType < 0)
+               {
+                       iAddrBase               =       iadr(*istk(iAddrBase + 1));
+                       iValType                = *istk(iAddrBase);
+               }
+
+               piBase                          = istk(iAddrBase);
+               piOffset                        = piBase + 2;
+       }
+       else
+       {
+               if(IsKindOfList(_piParentList))
+               {
+                       piBase                  = _piParentList;
+                       piOffset                = _piParentList + 2;
+               }
+               else
+               {
+                       return 0;
+               }
        }
 
-       *_piItemNumber          = *istk(iAddrBase + 1);
+       *_piItemNumber          = piBase[1];
 
        if(_pElemType == NULL)
                return 0;
 
-
        //Warning : variable starts at a even ( pair ) address, so if the size is odd, we add 1 to have a even address.
-       iAddrItem                       = iAddrOffset + *_piItemNumber + 1 + !(*_piItemNumber % 2);
+       piItem          = piOffset + (1 + *_piItemNumber + !(*_piItemNumber % 2));
        for(iIndex = 0 ; iIndex < *_piItemNumber ; iIndex++)
        {
-               _pElemType[iIndex] = *istk(iAddrItem);
-               iAddrItem       += (*istk(iAddrOffset + iIndex + 1) - *istk(iAddrOffset + iIndex)) * 2;
+               _pElemType[iIndex] = piItem[(piOffset[iIndex] - 1) * 2]; //-/+ 1
        }
        return 0;
 }
@@ -1584,7 +1601,7 @@ int* iGetAddressFromItemPos(int *_piParent, int _iItemPos)
                iAddrItem       += (*istk(iAddrOffset + _iItemNumber) - *istk(iAddrOffset + _iItemNumber - 1)) * 2;
 */
 //     iAddrItem       += (piOffset[_iItemPos - 1] - 1) * (sizeof(double) / sizeof(int));
-       piAddrItem      += (piOffset[_iItemPos - 1] - 1) * (sizeof(double) / sizeof(int));
+       piAddrItem      += (piOffset[_iItemPos] - 1) * (sizeof(double) / sizeof(int));
 
        return piAddrItem;
 }
@@ -1613,6 +1630,50 @@ int iGetAddressFromItemNumber(int _iVar, int _iItemNumber)
        return iAddrItem;
 }
 
+int* iGetListItemPointerFromItemNumber(int _iVar, int* _piParentList, int _iItemNumber)
+{
+       int *pItemAddr = _piParentList;
+       int iItemCount  = 0;
+       int *piOffset           = NULL;
+       int *piItem                     = NULL;
+
+       if(pItemAddr == NULL)
+       {//parent is the current list
+               int iAddrBase   =       iadr(*Lstk(Top - Rhs + _iVar));
+               int iValType    = *istk(iAddrBase);
+
+               if(iValType < 0)
+               {
+                       iAddrBase               =       iadr(*istk(iAddrBase + 1));
+                       iValType                = *istk(iAddrBase);
+               }
+
+               pItemAddr       = istk(iAddrBase);
+       }
+
+       if(!IsKindOfList(pItemAddr))
+       {
+               return 0;
+       }
+
+       iItemCount      = pItemAddr[1];
+       piOffset                = pItemAddr + 2;
+
+       if(_iItemNumber > iItemCount)
+               return 0;
+
+       piItem                  = piOffset + iItemCount + 1 + !(iItemCount % 2);
+/*
+       for(iIndex = 0 ; iIndex < _iItemNumber ; iIndex++)
+               iAddrItem       += (*istk(iAddrOffset + _iItemNumber) - *istk(iAddrOffset + _iItemNumber - 1)) * 2;
+*/
+       //_pElemType[iIndex] = piItem[(piOffset[iIndex] - 1) * 2]
+       //iAddrItem     += (piOffset[_iItemNumber - 1] - 1) * (sizeof(double) / sizeof(int));
+       piItem += (piOffset[_iItemNumber] - 1) * 2;
+
+       return piItem;
+}
+
 int iGetListItemDouble(int _iVar, int _iItemNumber, int *_piRows, int *_piCols, double **_pdblReal, double **_pdblImg)
 {
        int iAddrItem           = 0;
@@ -1667,6 +1728,72 @@ int iGetListItemString(int _iVar, int _iItemNumber, int *_piRows, int *_piCols,
        return 0;
 }
 
+//Get SubList reference
+int* iGetListItemList(int _iVar, int* _piParentList, int _iItemPos)
+{
+       int iIndex                      = 0;
+       int *piChild            = NULL;
+
+       int *piItemPos          = 0;
+
+       if(_piParentList == NULL)
+       {//parent is the current list
+               int iAddrBase   =       iadr(*Lstk(Top - Rhs + _iVar));
+               int iValType    = *istk(iAddrBase);
+
+               if(iValType < 0)
+               {
+                       iAddrBase               =       iadr(*istk(iAddrBase + 1));
+                       iValType                = *istk(iAddrBase);
+               }
+
+               _piParentList   = istk(iAddrBase);
+       }
+
+       if(!IsKindOfList(_piParentList))
+       {
+               return 0;
+       }
+
+       if(_iItemPos == 0)
+       {
+               piChild = _piParentList;
+       }
+       else
+       {
+               piChild = iGetAddressFromItemPos(_piParentList, _iItemPos);
+       }
+
+       if(!IsKindOfList(piChild))
+               return NULL;
+       return piChild;
+}
+
+//Get SubItem String
+int iGetListSubItemString(int _iVar, int* _piParentList, int _iItemNumber, int *_piRows, int *_piCols, int *_piLen, char* _pszData)
+{
+       int *piString = NULL;
+       int* piItemAdd = iGetListItemPointerFromItemNumber(_iVar, _piParentList, _iItemNumber);
+
+       if(piItemAdd == NULL)
+       {
+               return 1;
+       }
+
+       iGetStringFromPointer(piItemAdd, _piRows, _piCols, _piLen, &piString);
+
+       if(_piLen == NULL || _pszData == NULL)
+       {
+               return 0;
+       }
+
+       code2str(&_pszData, piString, iArraySum(_piLen, 0, *_piRows * *_piCols));
+       {
+               return 0;
+       }
+}
+
+
 //Internal fonctions to retrieve varaibles information from Address ( old "il" )
 int iGetDoubleFromAddress(int _iAddr, int *_piRows, int *_piCols, int *_piReal, int *_piImg)
 {
@@ -1799,6 +1926,29 @@ int iGetStringFromAddress(int _iAddr, int *_piRows, int *_piCols, int *_piLen, i
        *_piString                      = cadr(iAddrData);
        return 0;
 }
+
+int iGetStringFromPointer(int* _piAddr, int *_piRows, int *_piCols, int *_piLen, int** _piString)
+{
+       int iIndex                      = 0;
+       int *piOffset           = NULL;
+
+       *_piRows                                = _piAddr[1];
+       *_piCols                                = _piAddr[2];
+
+
+       if(_piLen == NULL)
+               return 0;
+
+       piOffset                        = _piAddr + 4;
+
+       /*Get all offest*/
+       for(iIndex = 0 ; iIndex < *_piRows * *_piCols; iIndex++)
+               _piLen[iIndex] = piOffset[iIndex + 1] - piOffset[iIndex];
+
+       *_piString                      = _piAddr + (5 + (*_piRows) * (*_piCols));
+       return 0;
+}
+
 void vGetPointerFromDoubleComplex(doublecomplex *_poComplex, int _iSize, double *_pdblReal, double *_pdblImg)
 {
        int iIndex = 0;
index 5ef63c1..fec2561 100644 (file)
@@ -51,6 +51,7 @@ int sci_printsetupbox(char *fname,unsigned long l);
 int sci_toprint(char *fname,unsigned long l);
 int sci_uigetfile( char * fname, unsigned long fname_len ) ;
 int sci_usecanvas(char *fname,unsigned long l);
+int sci_displaytree(char *fname,unsigned long l);
 /*--------------------------------------------------------------------------*/
 #endif /*  __GW_GUI__ */
 /*--------------------------------------------------------------------------*/
index 92a5e34..bd4c558 100644 (file)
@@ -56,7 +56,8 @@ static gw_generic_table Tab[]=
        {sci_printsetupbox,"printsetupbox"},
        {sci_toprint,"toprint"},
        {sci_uigetfile,"uigetfile"},
-       {sci_usecanvas,"usecanvas"}
+       {sci_usecanvas,"usecanvas"},
+       {sci_displaytree,"displaytree"}
 };
 /*--------------------------------------------------------------------------*/
 int gw_gui(void)
diff --git a/scilab/modules/gui/sci_gateway/cpp/sci_displaytree.cpp b/scilab/modules/gui/sci_gateway/cpp/sci_displaytree.cpp
new file mode 100644 (file)
index 0000000..92e295c
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2008 - INRIA - Antoine ELIAS
+ * 
+ * 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
+ *
+ */
+/*--------------------------------------------------------------------------*/ 
+
+
+#include <vector>
+#include <sstream>
+
+extern "C" 
+{
+       #include "stack-c.h"
+       #include "gw_gui.h"
+       #include "stdlib.h"
+       #include "sciprint.h"
+       #include "MALLOC.h"
+}
+
+#include "displaytree.hxx"
+
+using namespace std;
+/*--------------------------------------------------------------------------*/
+int sci_displaytree(char *fname,unsigned long fname_len)
+{
+       int iItemCount = 0;
+
+       CheckRhs(1,1);
+       CheckLhs(1,1);
+
+       vector<string> StructList;
+       int *piCurrentItem = NULL;
+       string szCurLevel = "";
+
+       iGetListItemType(1, piCurrentItem, &iItemCount, NULL);
+       int *piItemType = (int*)MALLOC(iItemCount * sizeof(int));
+       iGetListItemType(1, piCurrentItem, &iItemCount, piItemType);
+
+       if(iItemCount < 2)
+       {
+               sciprint("Invalid size");
+               return 1;
+       }
+
+       if(piItemType[0] != sci_strings && piItemType[1] != sci_mlist) //type
+       {
+               sciprint("Invalid tree");
+               FREE(piItemType);
+               return 1;
+       }
+
+       FREE(piItemType);
+       /*check tree structure*/
+       if(bIsTreeStructure(1, piCurrentItem, 1) == false)
+       {
+               sciprint("Invalid structure");
+               return 1;
+       }
+       //Add node level
+       if(szCurLevel != "")
+       {
+               szCurLevel + ".";
+       }
+       szCurLevel += "1";
+       StructList.push_back(szCurLevel);
+
+       //get label name
+       char *szLabel = NULL;
+       int iRet        = iGetNodeLabel(1, piCurrentItem, szLabel);
+       if(iRet == -1)
+       {
+               return false;
+       }
+
+       szLabel         = (char*)MALLOC((iRet + 1) * sizeof(char));
+       iRet                    = iGetNodeLabel(1, piCurrentItem, szLabel);
+       StructList.push_back(szLabel);
+       FREE(szLabel);
+
+       //get Icon name
+       char *szIcon = NULL;
+       iRet                                    = iGetNodeIcon(1, piCurrentItem, szIcon);
+       if(iRet == -1)
+       {
+               return false;
+       }
+
+       szIcon          = (char*)MALLOC((iRet + 1) * sizeof(char));
+       iRet                    = iGetNodeIcon(1, piCurrentItem, szIcon);
+       StructList.push_back(szIcon);
+       FREE(szIcon);
+
+       //get callback name
+       char *szCallBack        = NULL;
+       iRet                                                    = iGetNodeCallBack(1, piCurrentItem, szCallBack);
+       if(iRet == -1)
+       {
+               return false;
+       }
+
+       szCallBack              = (char*)MALLOC((iRet + 1) * sizeof(char));
+       iRet                    = iGetNodeCallBack(1, piCurrentItem, szCallBack);
+       StructList.push_back(szCallBack);
+       FREE(szCallBack);
+
+       if(iRet == -1)
+       {
+               return false;
+       }
+
+       bool nRet = bParseListItem(1, piCurrentItem, &StructList, szCurLevel);
+
+       //Java
+       return 0;
+}
index 5cb875e..9411a2d 100644 (file)
@@ -64,4 +64,5 @@
 <PRIMITIVE gatewayId="25" primitiveId="31" primitiveName="toprint" />
 <PRIMITIVE gatewayId="25" primitiveId="32" primitiveName="uigetfile" />
 <PRIMITIVE gatewayId="25" primitiveId="33" primitiveName="usecanvas" />
+<PRIMITIVE gatewayId="25" primitiveId="34" primitiveName="displaytree" />
 </GATEWAY>
index 2dc7a44..199e596 100644 (file)
@@ -29,3 +29,7 @@ sciReturnRowVectorFromInt
 sciReturnDouble
 sciReturnString
 sciReturnRowVector
+iGetListItemType
+iGetListItemList
+iGetListSubItemString
+iArraySum
\ No newline at end of file
index 6b0079e..bbf4411 100644 (file)
@@ -44,7 +44,7 @@
                        <Tool
                                Name="VCCLCompilerTool"
                                Optimization="0"
-                               AdditionalIncludeDirectories=".;../jni;../../../../java/jdk/include;../../../../java/jdk/include/win32;../../includes;../../../../libs/MALLOC/includes;../../../../libs/hashtable;../../../core/includes;../../../fileio/includes;../../../graphics/includes;../../../graphic_export/includes;../../../graphics/src/c/getHandleProperty;../../../renderer/src/cpp;../../../renderer/src/jni;../../../localization/includes;../../../jvm/includes;../../../output_stream/includes;../../../dynamic_link/includes;../../../../libs/intl;../../../../libs/doublylinkedlist/includes;../../../string/includes;../../../windows_tools/includes;../../../renderer/includes"
+                               AdditionalIncludeDirectories=".;../jni;../../../../java/jdk/include;../../../../java/jdk/include/win32;../../includes;../../../../libs/MALLOC/includes;../../../../libs/hashtable;../../../core/includes;../../../fileio/includes;../../../graphics/includes;../../../graphic_export/includes;../../../graphics/src/c/getHandleProperty;../../../renderer/src/cpp;../../../renderer/src/jni;../../../localization/includes;../../../jvm/includes;../../../output_stream/includes;../../../dynamic_link/includes;../../../../libs/intl;../../../../libs/doublylinkedlist/includes;../../../string/includes;../../../windows_tools/includes;../../../renderer/includes;../cpp"
                                PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;FORDLL;_DEBUG;_WINDOWS;_USRDLL;GUI_EXPORTS"
                                MinimalRebuild="true"
                                BasicRuntimeChecks="0"
                        <Tool
                                Name="VCCLCompilerTool"
                                Optimization="0"
-                               AdditionalIncludeDirectories=".;../jni;../../../../java/jdk/include;../../../../java/jdk/include/win32;../../includes;../../../../libs/MALLOC/includes;../../../../libs/hashtable;../../../core/includes;../../../fileio/includes;../../../graphics/includes;../../../graphic_export/includes;../../../graphics/src/c/getHandleProperty;../../../renderer/src/cpp;../../../renderer/src/jni;../../../localization/includes;../../../jvm/includes;../../../output_stream/includes;../../../dynamic_link/includes;../../../../libs/intl;../../../../libs/doublylinkedlist/includes;../../../string/includes;../../../windows_tools/includes;../../../renderer/includes"
+                               AdditionalIncludeDirectories=".;../jni;../../../../java/jdk/include;../../../../java/jdk/include/win32;../../includes;../../../../libs/MALLOC/includes;../../../../libs/hashtable;../../../core/includes;../../../fileio/includes;../../../graphics/includes;../../../graphic_export/includes;../../../graphics/src/c/getHandleProperty;../../../renderer/src/cpp;../../../renderer/src/jni;../../../localization/includes;../../../jvm/includes;../../../output_stream/includes;../../../dynamic_link/includes;../../../../libs/intl;../../../../libs/doublylinkedlist/includes;../../../string/includes;../../../windows_tools/includes;../../../renderer/includes;../cpp"
                                PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;FORDLL;_DEBUG;_WINDOWS;_USRDLL;GUI_EXPORTS"
                                MinimalRebuild="true"
                                BasicRuntimeChecks="0"
                                InlineFunctionExpansion="1"
                                FavorSizeOrSpeed="1"
                                WholeProgramOptimization="false"
-                               AdditionalIncludeDirectories=".;../jni;../../../../java/jdk/include;../../../../java/jdk/include/win32;../../includes;../../../../libs/MALLOC/includes;../../../../libs/hashtable;../../../core/includes;../../../fileio/includes;../../../graphics/includes;../../../graphic_export/includes;../../../graphics/src/c/getHandleProperty;../../../renderer/src/cpp;../../../renderer/src/jni;../../../localization/includes;../../../jvm/includes;../../../output_stream/includes;../../../dynamic_link/includes;../../../../libs/intl;../../../../libs/doublylinkedlist/includes;../../../string/includes;../../../windows_tools/includes;../../../renderer/includes"
+                               AdditionalIncludeDirectories=".;../jni;../../../../java/jdk/include;../../../../java/jdk/include/win32;../../includes;../../../../libs/MALLOC/includes;../../../../libs/hashtable;../../../core/includes;../../../fileio/includes;../../../graphics/includes;../../../graphic_export/includes;../../../graphics/src/c/getHandleProperty;../../../renderer/src/cpp;../../../renderer/src/jni;../../../localization/includes;../../../jvm/includes;../../../output_stream/includes;../../../dynamic_link/includes;../../../../libs/intl;../../../../libs/doublylinkedlist/includes;../../../string/includes;../../../windows_tools/includes;../../../renderer/includes;../cpp"
                                PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;FORDLL;NDEBUG;_WINDOWS;_USRDLL;GUI_EXPORTS"
                                StringPooling="true"
                                RuntimeLibrary="2"
                                InlineFunctionExpansion="1"
                                FavorSizeOrSpeed="1"
                                WholeProgramOptimization="false"
-                               AdditionalIncludeDirectories=".;../jni;../../../../java/jdk/include;../../../../java/jdk/include/win32;../../includes;../../../../libs/MALLOC/includes;../../../../libs/hashtable;../../../core/includes;../../../fileio/includes;../../../graphics/includes;../../../graphic_export/includes;../../../graphics/src/c/getHandleProperty;../../../renderer/src/cpp;../../../renderer/src/jni;../../../localization/includes;../../../jvm/includes;../../../output_stream/includes;../../../dynamic_link/includes;../../../../libs/intl;../../../../libs/doublylinkedlist/includes;../../../string/includes;../../../windows_tools/includes;../../../renderer/includes"
+                               AdditionalIncludeDirectories=".;../jni;../../../../java/jdk/include;../../../../java/jdk/include/win32;../../includes;../../../../libs/MALLOC/includes;../../../../libs/hashtable;../../../core/includes;../../../fileio/includes;../../../graphics/includes;../../../graphic_export/includes;../../../graphics/src/c/getHandleProperty;../../../renderer/src/cpp;../../../renderer/src/jni;../../../localization/includes;../../../jvm/includes;../../../output_stream/includes;../../../dynamic_link/includes;../../../../libs/intl;../../../../libs/doublylinkedlist/includes;../../../string/includes;../../../windows_tools/includes;../../../renderer/includes;../cpp"
                                PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;FORDLL;NDEBUG;_WINDOWS;_USRDLL;GUI_EXPORTS"
                                StringPooling="true"
                                RuntimeLibrary="2"
                                >
                        </File>
                        <File
+                               RelativePath="..\cpp\displaytree.cpp"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\DllmainGUI.c"
                                >
                        </File>
                                >
                        </File>
                        <File
+                               RelativePath="..\..\sci_gateway\cpp\sci_displaytree.cpp"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\..\sci_gateway\c\sci_exportUI.c"
                                >
                        </File>
                                >
                        </File>
                        <File
+                               RelativePath="..\cpp\displaytree.hxx"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\..\includes\EditBox.h"
                                >
                        </File>
diff --git a/scilab/modules/gui/src/cpp/displaytree.cpp b/scilab/modules/gui/src/cpp/displaytree.cpp
new file mode 100644 (file)
index 0000000..6a99153
--- /dev/null
@@ -0,0 +1,333 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2008 - INRIA - Antoine ELIAS
+ * 
+ * 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 "stack-c.h"
+       #include "stdlib.h"
+       #include "sciprint.h"
+       #include "MALLOC.h"
+}
+
+#include "displaytree.hxx"
+
+using namespace std;
+
+bool bParseListItem(int _iVar, int *_piCurrentItem, vector<string> *_pvStructList, string _szLevel)
+{
+       int iItemCount = 0;
+       iGetListItemType(_iVar, _piCurrentItem, &iItemCount, NULL);
+       int *piItemType = (int*)MALLOC(iItemCount * sizeof(int));
+       iGetListItemType(_iVar, _piCurrentItem, &iItemCount, piItemType);
+
+       //parse item
+       for(int i = 2 ; i < iItemCount ; i++) //tlist
+       {
+               if(piItemType[i] != sci_tlist)//potential tree
+               {//go up, it is finish for this node
+                       return 0;
+               }
+
+               /*retrieve next item*/
+               int *piChildItem = iGetListItemList(_iVar, _piCurrentItem, i);
+               if(piChildItem == NULL || piChildItem[0] != sci_tlist)
+               {
+                       sciprint("can get node item");
+               }
+
+               int iItemCount = 0;
+
+               string szCurLvl = _szLevel;
+               iGetListItemType(_iVar, piChildItem, &iItemCount, NULL);
+               int *piItemTypeChild = (int*)MALLOC(iItemCount * sizeof(int));
+               iGetListItemType(_iVar, piChildItem, &iItemCount, piItemTypeChild);
+
+               if(iItemCount < 2)
+               {
+                       sciprint("Invalid size");
+                       return 1;
+               }
+
+               if(piItemTypeChild[0] != sci_strings && piItemTypeChild[1] != sci_mlist) //type
+               {
+                       sciprint("Invalid tree");
+                       return 1;
+               }
+
+               /*check tree structure*/
+               if(bIsTreeStructure(_iVar, piChildItem, 1) == false)
+               {
+                       sciprint("Invalid structure");
+                       return 1;
+               }
+               //Add node level
+               szCurLvl += ".";
+               std::ostringstream out;
+               out << i-1;
+               szCurLvl += out.str();;
+
+               _pvStructList->push_back(szCurLvl);
+
+               //get label name
+               char *szLabel = NULL;
+               int iRet        = iGetNodeLabel(_iVar, piChildItem, szLabel);
+               if(iRet == -1)
+               {
+                       return false;
+               }
+
+               szLabel         = (char*)MALLOC((iRet + 1) * sizeof(char));
+               iRet                    = iGetNodeLabel(_iVar, piChildItem, szLabel);
+               if(iRet == -1)
+               {
+                       return false;
+               }
+               _pvStructList->push_back(szLabel);
+
+               //get Icon name
+               char *szIcon = NULL;
+               iRet                                    = iGetNodeIcon(_iVar, piChildItem, szIcon);
+               if(iRet == -1)
+               {
+                       return false;
+               }
+
+               szIcon          = (char*)MALLOC((iRet + 1) * sizeof(char));
+               iRet                    = iGetNodeIcon(_iVar, piChildItem, szIcon);
+               if(iRet == -1)
+               {
+                       return false;
+               }
+               _pvStructList->push_back(szIcon);
+
+               //get callback name
+               char *szCallBack        = NULL;
+               iRet                                                    = iGetNodeCallBack(_iVar, piChildItem, szCallBack);
+               if(iRet == -1)
+               {
+                       return false;
+               }
+
+               szCallBack              = (char*)MALLOC((iRet + 1) * sizeof(char));
+               iRet                    = iGetNodeCallBack(_iVar, piChildItem, szCallBack);
+               if(iRet == -1)
+               {
+                       return false;
+               }
+               _pvStructList->push_back(szCallBack);
+
+               bool nRet = bParseListItem(_iVar, piChildItem, _pvStructList, szCurLvl);
+       }
+       return true;
+}
+
+bool bIsTreeStructure(int _iVar, int* _piCurrentItem, int _iItemNumber)
+{
+       bool bRet                       = false;
+       int iRows                       = 0;
+       int iCols                       = 0;
+       int iLen                        = 0;
+       int *piLen              = NULL;
+       char *pszType   = NULL;
+       int iRet = iGetListSubItemString(_iVar, _piCurrentItem, 0, &iRows, &iCols, piLen, pszType);
+       if(iRet != 0)
+       {
+               return 1;
+       }
+       piLen = (int*)MALLOC(sizeof(int) * iRows * iCols);
+
+       iRet = iGetListSubItemString(_iVar, _piCurrentItem, 0, &iRows, &iCols, piLen, pszType);
+       if(iRet != 0)
+       {
+               return 1;
+       }
+
+       iLen = iArraySum(piLen, 0, iRows * iCols) + 1; // +1 for null terminated
+       pszType = (char*)MALLOC(iLen * sizeof(char));
+       iRet = iGetListSubItemString(_iVar, _piCurrentItem, 0, &iRows, &iCols, piLen, pszType);
+       if(iRet != 0)
+       {
+               return 1;
+       }
+       pszType[iLen - 1] = 0;
+
+       if(strcmp(TREE_REF_NAME, pszType) == 0)
+       {
+               bRet = true;
+       }
+
+       FREE(piLen);
+       FREE(pszType);
+       return bRet;
+}
+
+/*
+returns values :
+0  -> OK
+-1 -> failed
+>0 -> size needed for _pzValue ( _pszValue must be NULL to returns needed length )
+*/
+int iGetNodeInfo(int _iVar, int* _piParentItem, char* _pszInfo, char* _pszValue)
+{
+       int iRet = 0;
+       int *pStruct = iGetListItemList(_iVar, _piParentItem, 1);
+       if(pStruct == NULL)
+       {
+               return 1;
+       }
+
+       int iItemCount = 0;
+       iGetListItemType(_iVar, pStruct, &iItemCount, NULL);
+       int *piItemType = (int*)MALLOC(iItemCount * sizeof(int));
+       iGetListItemType(_iVar, pStruct, &iItemCount, piItemType);
+
+       if(     iItemCount < 2 || 
+                       piItemType[2] != sci_strings || 
+                       piItemType[3] != sci_strings || 
+                       piItemType[4] != sci_strings)
+       {//bad structure
+               return 1;
+       }
+
+       /*retrieve field value*/
+       iRet = iGetFieldValue(_iVar, pStruct, _pszInfo, _pszValue);
+       if(iRet != 0)
+       {
+               return iRet;
+       }
+       return 0;
+}
+
+/*
+returns values :
+0  -> OK
+-1 -> failed
+>0 -> size needed for _pzValue ( _pszValue must be NULL to returns needed length )
+*/
+int iGetNodeLabel(int _iVar, int* _piCurrentItem, char* _pszValue)
+{
+       return iGetNodeInfo(_iVar, _piCurrentItem, TREE_REF_LABEL, _pszValue);
+}
+
+/*
+returns values :
+0  -> OK
+-1 -> failed
+>0 -> size needed for _pzValue ( _pszValue must be NULL to returns needed length )
+*/
+int iGetNodeIcon(int _iVar, int* _piCurrentItem, char* _pszValue)
+{
+       return iGetNodeInfo(_iVar, _piCurrentItem, TREE_REF_ICON, _pszValue);
+}
+
+/*
+returns values :
+0  -> OK
+-1 -> failed
+>0 -> size needed for _pzValue ( _pszValue must be NULL to returns needed length )
+*/
+int iGetNodeCallBack(int _iVar, int* _piCurrentItem, char* _pszValue)
+{
+       return iGetNodeInfo(_iVar, _piCurrentItem, TREE_REF_CALL, _pszValue);
+}
+
+int iGetFieldIndex(int _iVar, int* _piCurrentItem, char* _pszFieldName)
+{
+       int  iIndex             = -1;
+       int iRows                       = 0;
+       int iCols                       = 0;
+       int iLen                        = 0;
+       int *piLen              = NULL;
+       char *pszField  = NULL;
+       int iRet = iGetListSubItemString(_iVar, _piCurrentItem, 0, &iRows, &iCols, piLen, pszField);
+       if(iRet != 0)
+       {
+               return 1;
+       }
+       piLen = (int*)MALLOC(sizeof(int) * iRows * iCols);
+
+       iRet = iGetListSubItemString(_iVar, _piCurrentItem, 0, &iRows, &iCols, piLen, pszField);
+       if(iRet != 0)
+       {
+               return 1;
+       }
+
+       iLen = iArraySum(piLen, 0, iRows * iCols) + 1; // +1 for null terminated
+       pszField = (char*)MALLOC(iLen * sizeof(char));
+       iRet = iGetListSubItemString(_iVar, _piCurrentItem, 0, &iRows, &iCols, piLen, pszField);
+       if(iRet != 0)
+       {
+               return 1;
+       }
+       pszField[iLen - 1] = 0;
+
+       for(int i = 0 ; i < iRows * iCols ; i++)
+       {
+               char *szSubString = (char*)MALLOC(iLen * sizeof(char));
+               strncpy(szSubString, pszField + iArraySum(piLen, 0, i), piLen[i]);
+               if(strcmp(_pszFieldName, szSubString) == 0)
+               {
+                       FREE(szSubString);
+                       iIndex = i;
+                       break;
+               }
+               FREE(szSubString);
+       }
+
+       FREE(piLen);
+       FREE(pszField);
+       return iIndex;
+}
+
+int iGetFieldValue(int _iVar, int* _piCurrentItem, char* _pszFieldName, char * _pszValue)
+{
+       int iIndex = iGetFieldIndex(_iVar, _piCurrentItem, _pszFieldName);
+       if(iIndex == -1)
+       {
+               return -1;
+       }
+
+       int iRows                       = 0;
+       int iCols                       = 0;
+       int iLen                        = 0;
+       int *piLen              = NULL;
+       int iRet = iGetListSubItemString(_iVar, _piCurrentItem, iIndex, &iRows, &iCols, piLen, _pszValue);
+       if(iRet != 0)
+       {
+               return -1;
+       }
+
+       piLen = (int*)MALLOC(sizeof(int) * iRows * iCols);
+       iRet = iGetListSubItemString(_iVar, _piCurrentItem, iIndex, &iRows, &iCols, piLen, _pszValue);
+       if(iRet != 0)
+       {
+               return -1;
+       }
+
+       iLen = iArraySum(piLen, 0, iRows * iCols);
+       if(_pszValue == NULL)
+       {
+               return iLen;
+       }
+
+       iRet = iGetListSubItemString(_iVar, _piCurrentItem, iIndex, &iRows, &iCols, piLen, _pszValue);
+       if(iRet != 0)
+       {
+               return -1;
+       }
+       _pszValue[iLen] = 0;
+
+
+       FREE(piLen);
+       return 0;
+}
diff --git a/scilab/modules/gui/src/cpp/displaytree.hxx b/scilab/modules/gui/src/cpp/displaytree.hxx
new file mode 100644 (file)
index 0000000..11ed717
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2008 - INRIA - Antoine ELIAS
+ * 
+ * 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
+ *
+ */
+/*--------------------------------------------------------------------------*/ 
+
+#ifndef __DISPLAY_TREE__
+#define __DISPLAY_TREE__
+
+#include <vector>
+#include <sstream>
+
+#define TREE_REF_NAME                  "Tree"
+#define TREE_REF_LABEL         "label"
+#define TREE_REF_ICON                  "icon"
+#define TREE_REF_CALL                  "callback"
+
+bool bIsTreeStructure(int _iVar, int* _piCurrentItem, int _iItemNumber);
+bool bParseListItem(int _iVar, int *_piCurrentItem, std::vector<std::string> *_pvStructList, std::string _szLevel);
+int iGetFieldValue(int _iVar, int* _piCurrentItem, char* _pszFieldName, char * _pszValue);
+int iGetFieldIndex(int _iVar, int* _piCurrentItem, char* _pszFieldName);
+int iGetNodeCallBack(int _iVar, int* _piCurrentItem, char* _pzValue);
+int iGetNodeIcon(int _iVar, int* _piCurrentItem, char* _pzValue);
+int iGetNodeLabel(int _iVar, int* _piCurrentItem, char* _pzValue);
+
+#endif /* __DISPLAY_TREE__ */
\ No newline at end of file