Xcos GUI: implement SuperBlock masks 40/17540/2
Clément DAVID [Fri, 4 Dec 2015 08:36:39 +0000 (09:36 +0100)]
Change-Id: I3c488624aadc2ca4c4767d6abfe4a8938c080082

scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/SuperBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/SuperblockMaskCreateAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/SuperblockMaskCustomizeAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/SuperblockMaskRemoveAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/io/ContextUpdate.java

index 1eac49c..51ddf1d 100644 (file)
@@ -80,7 +80,7 @@ public final class SuperBlock extends BasicBlock {
 
         setValue(label);
         if (masked) {
-            mask();
+            mask(new JavaController());
         }
     }
 
@@ -118,9 +118,7 @@ public final class SuperBlock extends BasicBlock {
     /**
      * Mask the SuperBlock
      */
-    public void mask() {
-        JavaController controller = new JavaController();
-
+    public void mask(final JavaController controller) {
         controller.setObjectProperty(getUID(), Kind.BLOCK, ObjectProperties.INTERFACE_FUNCTION, MASKED_INTERFUNCTION_NAME);
         controller.setObjectProperty(getUID(), Kind.BLOCK, ObjectProperties.SIM_FUNCTION_NAME, MASKED_SIMULATION_NAME);
 
@@ -132,9 +130,7 @@ public final class SuperBlock extends BasicBlock {
     /**
      * Unmask the SuperBlock
      */
-    public void unmask() {
-        JavaController controller = new JavaController();
-
+    public void unmask(final JavaController controller) {
         controller.setObjectProperty(getUID(), Kind.BLOCK, ObjectProperties.INTERFACE_FUNCTION, INTERFUNCTION_NAME);
         controller.setObjectProperty(getUID(), Kind.BLOCK, ObjectProperties.SIM_FUNCTION_NAME, SIMULATION_NAME);
     }
index 9b6a585..9262485 100644 (file)
 package org.scilab.modules.xcos.block.actions;
 
 import java.awt.event.ActionEvent;
+import java.util.Arrays;
 
 import org.scilab.modules.graph.ScilabComponent;
 import org.scilab.modules.graph.ScilabGraph;
 import org.scilab.modules.graph.actions.base.DefaultAction;
+import org.scilab.modules.graph.actions.base.GraphActionManager;
 import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.types.ScilabDouble;
+import org.scilab.modules.types.ScilabList;
+import org.scilab.modules.types.ScilabString;
+import org.scilab.modules.types.ScilabTList;
+import org.scilab.modules.types.ScilabType;
+import org.scilab.modules.xcos.JavaController;
+import org.scilab.modules.xcos.Kind;
+import org.scilab.modules.xcos.ObjectProperties;
+import org.scilab.modules.xcos.VectorOfDouble;
 import org.scilab.modules.xcos.block.SuperBlock;
 import org.scilab.modules.xcos.graph.XcosDiagram;
+import org.scilab.modules.xcos.io.ScilabTypeCoder;
 import org.scilab.modules.xcos.utils.XcosMessages;
 
 /**
@@ -73,33 +85,38 @@ public final class SuperblockMaskCreateAction extends DefaultAction {
 
         SuperBlock block = (SuperBlock) graph.getSelectionCell();
 
-        block.mask();
+        JavaController controller = new JavaController();
+        block.mask(controller);
 
         /*
          * Create a valid DSUPER exprs field if not already present.
          */
-        // FIXME take a look at the DSUPER management
-        //        if (!(block.getExprs() instanceof ScilabList)) {
-        //
-        //            /* Set default values */
-        //            ScilabList exprs = new ScilabList(
-        //                Arrays.asList(
-        //                    new ScilabDouble(),
-        //                    new ScilabList(
-        //                        Arrays.asList(
-        //                            new ScilabDouble(),
-        //                            new ScilabString(
-        //                                XcosMessages.MASK_DEFAULTWINDOWNAME),
-        //                            new ScilabList(Arrays
-        //                                           .asList(new ScilabDouble()))))));
-        //
-        //            block.setExprs(exprs);
-        //
-        //            /*
-        //             * Open the customization UI on a new mask creation
-        //             */
-        //            GraphActionManager.getInstance(graph,
-        //                                           SuperblockMaskCustomizeAction.class).actionPerformed(e);
-        //        }
+
+        VectorOfDouble vec = new VectorOfDouble();
+        controller.getObjectProperty(block.getUID(), block.getKind(), ObjectProperties.EXPRS, vec);
+
+        ScilabType var = new ScilabTypeCoder().vec2var(vec);
+        if (!(var instanceof ScilabList)) {
+
+            /* Set default values */
+            ScilabList exprsVar = new ScilabList(
+                Arrays.asList(
+                    new ScilabDouble(),
+                    new ScilabList(
+                        Arrays.asList(
+                            new ScilabDouble(),
+                            new ScilabString(
+                                XcosMessages.MASK_DEFAULTWINDOWNAME),
+                            new ScilabList(Arrays
+                                           .asList(new ScilabDouble()))))));
+
+            vec = new ScilabTypeCoder().var2vec(exprsVar);
+            controller.setObjectProperty(block.getUID(), block.getKind(), ObjectProperties.EXPRS, vec);
+
+            /*
+             * Open the customization UI on a new mask creation
+             */
+            GraphActionManager.getInstance(graph, SuperblockMaskCustomizeAction.class).actionPerformed(e);
+        }
     }
 }
index 529b09b..c59f5f3 100644 (file)
@@ -45,8 +45,12 @@ import org.scilab.modules.types.ScilabDouble;
 import org.scilab.modules.types.ScilabList;
 import org.scilab.modules.types.ScilabString;
 import org.scilab.modules.types.ScilabType;
+import org.scilab.modules.xcos.JavaController;
+import org.scilab.modules.xcos.ObjectProperties;
+import org.scilab.modules.xcos.VectorOfDouble;
 import org.scilab.modules.xcos.block.SuperBlock;
 import org.scilab.modules.xcos.graph.XcosDiagram;
+import org.scilab.modules.xcos.io.ScilabTypeCoder;
 import org.scilab.modules.xcos.utils.XcosMessages;
 
 /**
@@ -414,7 +418,7 @@ public final class SuperblockMaskCustomizeAction extends DefaultAction {
                      * reconstruct pol fields. The default types of the values.
                      *
                      * This field indicate the dimension of each entry (-1.0 is
-                     * automatic). FIXME: type the data there instead of using
+                     * automatic). TODO: type the data there instead of using
                      * the generic "pol".
                      */
                     polFields.add(new ScilabString("pol"));
@@ -434,8 +438,10 @@ public final class SuperblockMaskCustomizeAction extends DefaultAction {
                     exprs = new ScilabList(Arrays.asList(new ScilabString(values),
                                                          new ScilabList(Arrays.asList(new ScilabString(varNames), new ScilabString(varDesc), polFields))));
                 }
-                // FIXME: this exprs will be var2vec encoded on the model ; handle that from Java
-                //                getBlock().setExprs(exprs);
+
+                JavaController controller = new JavaController();
+                VectorOfDouble vec = new ScilabTypeCoder().var2vec(exprs);
+                controller.setObjectProperty(block.getUID(), block.getKind(), ObjectProperties.EXPRS, vec);
 
                 /*
                  * Trace the exprs update.
@@ -453,9 +459,10 @@ public final class SuperblockMaskCustomizeAction extends DefaultAction {
                 ScilabString varNames;
                 ScilabString varDesc;
 
-                //                FIXME: this exprs will be var2vec encoded on the model ; handle that from Java
-                //                ScilabType rawExprs = getBlock().getExprs();
-                ScilabType rawExprs = new ScilabDouble();
+                JavaController controller = new JavaController();
+                VectorOfDouble vec = new VectorOfDouble();
+                controller.getObjectProperty(block.getUID(), block.getKind(), ObjectProperties.EXPRS, vec);
+                ScilabType rawExprs = new ScilabTypeCoder().vec2var(vec);
 
                 // Xcos from Scilab 5.2.0 version
                 // so set default values
index bf2c5ae..2459a61 100644 (file)
@@ -19,6 +19,7 @@ import org.scilab.modules.graph.ScilabComponent;
 import org.scilab.modules.graph.ScilabGraph;
 import org.scilab.modules.graph.actions.base.DefaultAction;
 import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.xcos.JavaController;
 import org.scilab.modules.xcos.block.SuperBlock;
 import org.scilab.modules.xcos.graph.XcosDiagram;
 import org.scilab.modules.xcos.utils.XcosMessages;
@@ -74,6 +75,6 @@ public final class SuperblockMaskRemoveAction extends DefaultAction {
         }
 
         SuperBlock block = (SuperBlock) graph.getSelectionCell();
-        block.unmask();
+        block.unmask(new JavaController());
     }
 }
index 94a5c35..38f3745 100644 (file)
@@ -296,7 +296,7 @@ public abstract class ContextUpdate extends BasicBlock {
                     try {
                         JavaController controller = new JavaController();
 
-                        // FIXME: dunno if I should disable the view there :
+                        // TODO: dunno if I should disable the view there :
                         // CHECK
                         JavaController.unregister_view(disabledView);