Xcos: add exprs informations to user defined blocks 72/2872/2
Clément DAVID [Fri, 7 Jan 2011 13:54:57 +0000 (14:54 +0100)]
Change-Id: Iea1d86e5d270397ca84818c717df3250fd3eee58

scilab/modules/xcos/etc/Xcos-style.xml
scilab/modules/xcos/images/palettes/CBLOCK.png
scilab/modules/xcos/images/palettes/DEBUG_SCICOS.png
scilab/modules/xcos/images/palettes/EXPRESSION.png
scilab/modules/xcos/images/palettes/c_block.png
scilab/modules/xcos/images/palettes/fortran_block.png
scilab/modules/xcos/images/palettes/generic_block3.png
scilab/modules/xcos/images/palettes/scifunc_block_m.png
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/BasicBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/XcosDiagram.java

index f94f4b9..612b9ad 100644 (file)
   <!-- USER-DEFINED FUNCTIONS -->
   <add as="PDE" extend="blockWithLabel"/>
   <add as="fortran_block" extend="blockWithLabel">
-    <add as="displayedLabel" value="Fortran"/>
+    <add as="displayedLabel" value="Fortran block:&lt;BR&gt;%4$s"/>
   </add>
   <add as="DEBUG_SCICOS" extend="blockWithLabel">
-    <add as="displayedLabel" value="Debug"/>
+    <add as="displayedLabel" value="Debug:&lt;BR&gt;%2$s"/>
   </add>
   <add as="EXPRESSION" extend="blockWithLabel">
-    <add as="displayedLabel" value="Mathematical&lt;BR&gt;         expression"/>
+    <add as="displayedLabel" value="Expression:&lt;BR&gt;%2$s"/>
   </add>
   <add as="scifunc_block_m" extend="blockWithLabel">
-    <add as="displayedLabel" value="Scifunc"/>
+    <add as="displayedLabel" value="Function:&lt;BR&gt;%10$s"/>
   </add>
   <add as="scifunc_block" extend="scifunc_block_m"/>
   <add as="CBLOCK" extend="blockWithLabel">
-    <add as="displayedLabel" value="C block 2"/>
+    <add as="displayedLabel" value="C block 2:&lt;BR&gt;%1$s"/>
   </add>
   <add as="generic_block3" extend="blockWithLabel">
-    <add as="displayedLabel" value="GENERIC"/>
+    <add as="displayedLabel" value="native block:&lt;BR&gt;%1$s"/>
   </add>
   <add as="c_block" extend="blockWithLabel">
-    <add as="displayedLabel" value="C block"/>
+    <add as="displayedLabel" value="C block:&lt;BR&gt;%4$s"/>
   </add>
   <add as="SUPER_f" extend="Icon">
     <add as="image" value="$SCILAB/modules/xcos/images/blocks/SUPER.svg"/>
index fd1c184..269bd43 100644 (file)
Binary files a/scilab/modules/xcos/images/palettes/CBLOCK.png and b/scilab/modules/xcos/images/palettes/CBLOCK.png differ
index 69debff..07e8e5e 100644 (file)
Binary files a/scilab/modules/xcos/images/palettes/DEBUG_SCICOS.png and b/scilab/modules/xcos/images/palettes/DEBUG_SCICOS.png differ
index d0a20ef..b892c1c 100644 (file)
Binary files a/scilab/modules/xcos/images/palettes/EXPRESSION.png and b/scilab/modules/xcos/images/palettes/EXPRESSION.png differ
index b21898f..dee6c9f 100644 (file)
Binary files a/scilab/modules/xcos/images/palettes/c_block.png and b/scilab/modules/xcos/images/palettes/c_block.png differ
index 829dbaf..4e0d840 100644 (file)
Binary files a/scilab/modules/xcos/images/palettes/fortran_block.png and b/scilab/modules/xcos/images/palettes/fortran_block.png differ
index 57b0531..0e71731 100644 (file)
Binary files a/scilab/modules/xcos/images/palettes/generic_block3.png and b/scilab/modules/xcos/images/palettes/generic_block3.png differ
index a177a29..cda78d6 100644 (file)
Binary files a/scilab/modules/xcos/images/palettes/scifunc_block_m.png and b/scilab/modules/xcos/images/palettes/scifunc_block_m.png differ
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() {
index 16938b8..d5c911e 100644 (file)
@@ -27,6 +27,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
+import java.util.IllegalFormatException;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
@@ -1213,8 +1214,11 @@ public class XcosDiagram extends ScilabGraph {
                        
                        final String customLabel = (String) style.get("displayedLabel");
                        if (customLabel != null && cell instanceof BasicBlock) {
-                               return String.format(customLabel,
-                                               (Object[]) ((BasicBlock) cell).getExprsFormat());
+                               try {
+                                       return String.format(customLabel, ((BasicBlock) cell).getExprsFormat());
+                               } catch (IllegalFormatException e) {
+                                       LOG.error(e);
+                               }
                        } else {
                                final String label = super.convertValueToString(cell);
                                if (label.isEmpty() && cell instanceof BasicBlock) {