Xcos: add exprs informations to user defined blocks
[scilab.git] / scilab / modules / xcos / src / java / org / scilab / modules / xcos / block / BasicBlock.java
index 6008a9f..c8c0c6d 100644 (file)
@@ -660,30 +660,73 @@ public class BasicBlock extends ScilabGraphUniqueObject implements Serializable
     /**
      * @return the expression as a object array
      */
-    public String[] getExprsFormat() {
+    public Object[] getExprsFormat() {
        // evaluate emptiness
                if (getExprs() == null || getExprs().isEmpty()
                                || getExprs().getHeight() == 0 || getExprs().getWidth() == 0) {
                        return new String[0];
                }
        
-               // only ScilabString is handled
-               if (!(getExprs() instanceof ScilabString)) {
-                       return new String[0];
+               List<String[]> stack = getString(null, getExprs());
+               
+               int len = 0;
+               for (Object[] strings : stack) {
+                       len += strings.length;
                }
-               String[][] scilabData = ((ScilabString) getExprs()).getData();
                
-       // normal case
-               final String[] array = new String[getExprs().getHeight() * getExprs().getWidth()];
-               final int width = scilabData[0].length;
-               for (int i = 0; i < scilabData.length; ++i) {
-                       System.arraycopy(scilabData[i], 0, array, i * width, width);
+               final Object[] array = new Object[len];
+               int start = 0;
+               for (Object[] strings : stack) {
+                       System.arraycopy(strings, 0, array, start, strings.length);
+                       start += strings.length;
                }
                
                return array;
     }
     
     /**
+     * Append the data recursively to the stack
+     * @param stack the current stack
+     * @param data the data to append
+     * @return the stack
+     */
+    private List<String[]> getString(List<String[]> stack, ScilabType data)  {
+       if (stack == null) {
+               stack = new LinkedList<String[]>();
+       }
+               
+       if (data instanceof List) {
+               /*
+                * Container case (ScilabList, ScilabMList, ScilabTList) 
+                */
+               
+               @SuppressWarnings("unchecked")
+                       final List<ScilabType> list = (List<ScilabType>) data;
+               
+               for (final ScilabType scilabType : list) {
+                               getString(stack, scilabType);
+                       }
+       } else if (data instanceof ScilabString) {
+               /*
+                * native case (only ScilabString supported)
+                */
+               
+               final String[][] scilabData = ((ScilabString) data).getData();
+               final int height = data.getHeight();
+               final int width = data.getWidth();
+               
+               final String[] array = new String[height * width];
+               for (int i = 0; i < height; ++i) {
+                       System.arraycopy(scilabData[i], 0, array, i * width, width);
+               }
+               
+               stack.add(array);
+       }
+       
+       return stack;
+    }
+    
+    /**
      * @return zero crossing value
      */
     public ScilabType getNbZerosCrossing() {