bug 5530, IN_f, OUT_f and similars blocks accept expression as parameter
antoine ELIAS [Wed, 2 Dec 2009 17:42:28 +0000 (18:42 +0100)]
16 files changed:
scilab/modules/xcos/macros/xcosBlockEval.sci [new file with mode: 0644]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/XcosDiagram.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/XcosUIDObject.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/BasicBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/ConstBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/ContextUpdate.java [new file with mode: 0644]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/EventInBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/EventOutBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/ExplicitInBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/ExplicitOutBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/GainBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/ImplicitInBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/ImplicitOutBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/SuperBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/BlockReader.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/utils/XcosEvent.java

diff --git a/scilab/modules/xcos/macros/xcosBlockEval.sci b/scilab/modules/xcos/macros/xcosBlockEval.sci
new file mode 100644 (file)
index 0000000..624ee6d
--- /dev/null
@@ -0,0 +1,46 @@
+//
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2009-2009 - DIGITEO - 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
+//
+//
+
+//hdf5FileToLoad : input block file
+//hdf5FileToSave : output block file
+//interfaceAlias : block interface function name ( ex "IN_f" )
+//hdf5ContextFile : input context file
+
+function xcosBlockEval(hdf5FileToLoad, hdf5FileToSave, interfaceAlias, hdf5ContextFile)
+
+       //replace scicos_getvalue by    setvalue ( call by interfaceAlias )
+  %mprt = funcprot()
+  funcprot(0)
+  scicos_getvalue = setvalue;
+  function message(txt)
+    messagebox(['In block ' + o.gui + ': ';
+               txt;
+              'current parameter value kept'],'error','modal');
+    [str,n,line,func]=lasterror();
+    printf('do_eval: error %d - %s in %s at line %d\n', n, str, func, line); 
+  endfunction
+  %scicos_prob = %f
+  funcprot(%mprt)
+
+       import_from_hdf5(hdf5ContextFile);
+       %scicos_context = struct();
+       [%scicos_context, ierr] = script2var(context, %scicos_context)
+
+       import_from_hdf5(hdf5FileToLoad);
+
+
+  //create a structure with the new context
+  [new_scs_m, y, typ] = interfaceAlias('set', scs_m, []);
+
+       export_to_hdf5(hdf5FileToSave, "new_scs_m");
+       xcosNotify(hdf5FileToSave);
+endfunction
index 42ad71d..f8033d8 100644 (file)
@@ -29,6 +29,7 @@ import java.util.List;
 import javax.swing.JFileChooser;
 import javax.swing.JOptionPane;
 import javax.swing.SwingUtilities;
+
 import org.scilab.modules.graph.ScilabGraph;
 import org.scilab.modules.graph.actions.PasteAction;
 import org.scilab.modules.graph.actions.RedoAction;
@@ -60,6 +61,7 @@ import org.scilab.modules.xcos.actions.XcosDocumentationAction;
 import org.scilab.modules.xcos.actions.XcosShortCut;
 import org.scilab.modules.xcos.block.AfficheBlock;
 import org.scilab.modules.xcos.block.BasicBlock;
+import org.scilab.modules.xcos.block.ContextUpdate;
 import org.scilab.modules.xcos.block.SplitBlock;
 import org.scilab.modules.xcos.block.SuperBlock;
 import org.scilab.modules.xcos.block.SuperBlockDiagram;
@@ -97,7 +99,6 @@ import com.mxgraph.util.mxPoint;
 import com.mxgraph.util.mxRectangle;
 import com.mxgraph.util.mxUndoableEdit;
 import com.mxgraph.util.mxUtils;
-import com.mxgraph.util.mxEventSource.mxIEventListener;
 import com.mxgraph.util.mxUndoableEdit.mxUndoableChange;
 import com.mxgraph.view.mxMultiplicity;
 
@@ -1298,12 +1299,27 @@ public class XcosDiagram extends ScilabGraph {
     
     public void setContext(String[] context) {
        this.context = context;
+       updateCellsContext();
     }
 
     public String[] getContext() {
        return context;
     }
 
+    public void updateCellsContext() {
+       for (int i = 0; i < getModel().getChildCount(getDefaultParent()); ++i) {
+           Object obj = getModel().getChildAt(getDefaultParent(), i);
+           if ( obj instanceof ContextUpdate) {
+               ((ContextUpdate)obj).onContextChange(buildEntireContext());
+           } else if (obj instanceof SuperBlock) {
+               SuperBlock superBlock = (SuperBlock)obj;
+               if(superBlock.getChild() != null) {
+                   superBlock.getChild().updateCellsContext();
+               }
+           }
+       }
+    }
+
     public String getVersion() {
        return version;
     }
index cc024c6..5b7e551 100644 (file)
@@ -15,10 +15,12 @@ package org.scilab.modules.xcos;
 import java.rmi.server.UID;
 
 import com.mxgraph.model.mxCell;
+import com.mxgraph.util.mxEventObject;
+import com.mxgraph.util.mxEventSource.mxIEventListener;
 
-public class XcosUIDObject extends mxCell {
+public class XcosUIDObject extends mxCell{
 
-    private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = -2915277403393545917L;
 
     public XcosUIDObject() {
        super();
index a142065..56955f5 100644 (file)
@@ -15,10 +15,13 @@ package org.scilab.modules.xcos.block;
 
 import java.awt.MouseInfo;
 import java.io.File;
+import java.io.IOException;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import ncsa.hdf.hdf5lib.exceptions.HDF5Exception;
+
 import org.scilab.modules.action_binding.InterpreterManagement;
 import org.scilab.modules.graph.ScilabGraph;
 import org.scilab.modules.graph.actions.CopyAction;
@@ -526,27 +529,23 @@ public class BasicBlock extends XcosUIDObject {
        final File tempInput;
        final File tempContext;
        try {
-           tempOutput = File.createTempFile("xcos",".h5");
            tempInput = File.createTempFile("xcos",".h5");
-           tempContext = File.createTempFile("xcos",".h5");
-           tempOutput.deleteOnExit();
            tempInput.deleteOnExit();
-           tempContext.deleteOnExit();
-           // Write scs_m
-           int file_id = H5Write.createFile(tempOutput.getAbsolutePath());
-           H5Write.writeInDataSet(file_id, "scs_m", BasicBlockInfo.getAsScilabObj(this));
-           H5Write.closeFile(file_id);
 
+           // Write scs_m
+           tempOutput = exportBlockStruct();
            // Write context
-           int context_file_id = H5Write.createFile(tempContext.getAbsolutePath());
-           H5Write.writeInDataSet(context_file_id, "context", new ScilabString(context));
-           H5Write.closeFile(context_file_id);
-
-           InterpreterManagement.putCommandInScilabQueue("xcosBlockInterface(\""+tempOutput.getAbsolutePath()+"\""+
-                   ", \""+tempInput.getAbsolutePath()+"\""+
-                   ", "+getInterfaceFunctionName()+
-                   ", \"set\""+
-                   ", \""+tempContext.getAbsolutePath()+"\");");
+           tempContext = exportContext(context);
+
+           String cmd;
+           
+           cmd = "xcosBlockInterface(\""+tempOutput.getAbsolutePath()+"\"";
+           cmd += ", \""+tempInput.getAbsolutePath()+"\"";
+           cmd += ", "+getInterfaceFunctionName();
+           cmd += ", \"set\"";
+           cmd += ", \""+tempContext.getAbsolutePath()+"\");";
+           
+           InterpreterManagement.putCommandInScilabQueue(cmd);
            final BasicBlock currentBlock = this;
            Thread launchMe = new Thread() {
                public void run() {
@@ -561,11 +560,48 @@ public class BasicBlock extends XcosUIDObject {
            launchMe.start();
            setLocked(true);
 
-       } catch (Exception e) {
+       } catch (IOException e) {
            e.printStackTrace();
        }
     }
 
+    protected File exportBlockStruct() {
+
+       // Write scs_m
+       File tempOutput;
+       try {
+           tempOutput = File.createTempFile("xcos",".h5");
+           tempOutput.deleteOnExit();
+           int file_id = H5Write.createFile(tempOutput.getAbsolutePath());
+           H5Write.writeInDataSet(file_id, "scs_m", BasicBlockInfo.getAsScilabObj(this));
+           H5Write.closeFile(file_id);
+           return tempOutput;
+       } catch (IOException e) {
+           e.printStackTrace();
+       } catch (HDF5Exception e) {
+           e.printStackTrace();
+       }
+       return null;
+    }
+    
+    protected File exportContext(String[] context) {
+
+       // Write context
+       try {
+           File tempContext = File.createTempFile("xcos",".h5");
+           tempContext.deleteOnExit();
+           int context_file_id = H5Write.createFile(tempContext.getAbsolutePath());
+           H5Write.writeInDataSet(context_file_id, "context", new ScilabString(context));
+           H5Write.closeFile(context_file_id);
+           return tempContext;
+       } catch (IOException e) {
+           e.printStackTrace();
+       } catch (HDF5Exception e) {
+           e.printStackTrace();
+       }
+       return null;
+    }
+    
     public String getToolTipText() {
        StringBuffer result = new StringBuffer();
        result.append("<html>");
@@ -723,11 +759,13 @@ public class BasicBlock extends XcosUIDObject {
     public boolean getMirror(){
        if(getParentDiagram() != null) {
            mxCellState state = getParentDiagram().getView().getState(this);
-           String  currentMirror = mxUtils.getString(state.getStyle(), XcosConstants.STYLE_MIRROR, "false");
-           if(currentMirror.compareTo("true") == 0) {
-               return true;
-           } else {
-               return false;
+           if(state != null) {
+               String  currentMirror = mxUtils.getString(state.getStyle(), XcosConstants.STYLE_MIRROR, "false");
+               if(currentMirror.compareTo("true") == 0) {
+                   return true;
+               } else {
+                   return false;
+               }
            }
        }
        return false;
@@ -745,11 +783,13 @@ public class BasicBlock extends XcosUIDObject {
     public boolean getFlip(){
        if(getParentDiagram() != null) {
            mxCellState state = getParentDiagram().getView().getState(this);
-           String  currentFlip = mxUtils.getString(state.getStyle(), XcosConstants.STYLE_FLIP, "false");
-           if(currentFlip.compareTo("true") == 0) {
-               return true;
-           } else {
-               return false;
+           if(state != null) {
+               String  currentFlip = mxUtils.getString(state.getStyle(), XcosConstants.STYLE_FLIP, "false");
+               if(currentFlip.compareTo("true") == 0) {
+                   return true;
+               } else {
+                   return false;
+               }
            }
        }
        return false;
@@ -798,8 +838,10 @@ public class BasicBlock extends XcosUIDObject {
     public int getAngle() {
        if(getParentDiagram() != null) {
            mxCellState state = getParentDiagram().getView().getState(this);
-           String  currentAngle = mxUtils.getString(state.getStyle(), XcosConstants.STYLE_ROTATION, "0");
-           return Integer.parseInt(currentAngle);
+           if(state != null) {
+               String  currentAngle = mxUtils.getString(state.getStyle(), XcosConstants.STYLE_ROTATION, "0");
+               return Integer.parseInt(currentAngle);
+           }
        }
        return 0;
     }
index 2600756..42cfd6a 100644 (file)
@@ -17,6 +17,8 @@ import org.scilab.modules.hdf5.scilabTypes.ScilabType;
 
 public class ConstBlock extends BasicBlock {
 
+    private static final long serialVersionUID = 4234301593972228584L;
+
     public ConstBlock() {
        super();
        setVertex(false);
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/ContextUpdate.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/ContextUpdate.java
new file mode 100644 (file)
index 0000000..21c25ce
--- /dev/null
@@ -0,0 +1,59 @@
+package org.scilab.modules.xcos.block;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.scilab.modules.action_binding.InterpreterManagement;
+import org.scilab.modules.xcos.io.BlockReader;
+import org.scilab.modules.xcos.utils.Signal;
+
+public abstract class ContextUpdate extends BasicBlock{
+
+    private static final long serialVersionUID = 6076826729067963560L;
+    private static Object _mutex_ = new Object();
+    
+    public ContextUpdate() {
+       super();
+    }
+
+    public ContextUpdate(String label) {
+       super(label);
+    }
+
+    public void onContextChange(String[] context) {
+       //prevent to open twice
+       if(isLocked()) {
+           return;
+       }
+       
+       final File tempOutput;
+       final File tempInput;
+       final File tempContext;
+       try {
+           tempInput = File.createTempFile("xcos",".h5");
+           tempInput.deleteOnExit();
+
+           // Write scs_m
+           tempOutput = exportBlockStruct();
+           // Write context
+           tempContext = exportContext(context);
+
+           String cmd;
+           
+           cmd = "xcosBlockEval(\""+tempOutput.getAbsolutePath()+"\"";
+           cmd += ", \""+tempInput.getAbsolutePath()+"\"";
+           cmd += ", "+getInterfaceFunctionName();
+           cmd += ", \""+tempContext.getAbsolutePath()+"\");";
+
+           synchronized (_mutex_) {
+               InterpreterManagement.putCommandInScilabQueue(cmd);
+               Signal.wait(tempInput.getAbsolutePath());
+               BasicBlock modifiedBlock = BlockReader.readBlockFromFile(tempInput.getAbsolutePath());
+               updateBlockSettings(modifiedBlock);
+           }
+           
+       } catch (IOException e) {
+           e.printStackTrace();
+       }
+    }
+}
index 6ac8419..8e57575 100644 (file)
@@ -14,44 +14,49 @@ package org.scilab.modules.xcos.block;
 
 import org.scilab.modules.hdf5.scilabTypes.ScilabDouble;
 import org.scilab.modules.hdf5.scilabTypes.ScilabList;
-import org.scilab.modules.hdf5.scilabTypes.ScilabString;
 import org.scilab.modules.hdf5.scilabTypes.ScilabType;
 import org.scilab.modules.xcos.utils.XcosEvent;
 
 import com.mxgraph.util.mxEventObject;
 
-public class EventInBlock extends BasicBlock {
+public class EventInBlock extends ContextUpdate {
 
-       public EventInBlock() {
-               super();
-               setVertex(false);
-               setVisible(false);
-       }
+    private static final long serialVersionUID = 2799781225262685322L;
 
-       public EventInBlock(String label) {
-               super(label);
-               setInterfaceFunctionName("CLKINV_f");
-               setSimulationFunctionName("input");
-               setNbZerosCrossing(new ScilabDouble(0));
-               setNmode(new ScilabDouble(0));
-               setODState(new ScilabList());
-               setValue("1");
-       }
+    public EventInBlock() {
+       super();
+       setVertex(false);
+       setVisible(false);
+    }
 
-       public void setExprs(ScilabType exprs) {
-               super.setExprs(exprs);
-               setValue(((ScilabString) getExprs()).getData()[0][0]);
-       }
+    public EventInBlock(String label) {
+       super(label);
+       setInterfaceFunctionName("CLKINV_f");
+       setSimulationFunctionName("input");
+       setNbZerosCrossing(new ScilabDouble(0));
+       setNmode(new ScilabDouble(0));
+       setODState(new ScilabList());
+       setValue(1);
+    }
 
-       public void updateBlockSettings(BasicBlock modifiedBlock) {
+    public void setExprs(ScilabType exprs) {
+       super.setExprs(exprs);
+       //setValue(((ScilabString) getExprs()).getData()[0][0]);
+    }
 
-               String oldValue = (String)getValue();
-               super.updateBlockSettings(modifiedBlock);
-               String newValue = (String)getValue();
-               
-               if(oldValue.compareTo(newValue) != 0){
-                       getParentDiagram().fireEvent(XcosEvent.IN_EVENT_VALUE_UPDATED, new mxEventObject(new Object[]{oldValue,newValue}));
-               }
-               
+    public void updateBlockSettings(BasicBlock modifiedBlock) {
+
+       double oldValue = ((ScilabDouble)getIntegerParameters()).getRealPart()[0][0];
+       super.updateBlockSettings(modifiedBlock);
+       double newValue = ((ScilabDouble)getIntegerParameters()).getRealPart()[0][0];
+
+       if(oldValue != newValue){
+           getParentDiagram().fireEvent(XcosEvent.IN_EVENT_VALUE_UPDATED, new mxEventObject(new Object[]{oldValue,newValue}));
        }
+    }
+
+    public void setIntegerParameters(ScilabType integerParameters) {
+       super.setIntegerParameters(integerParameters);
+       setValue((int)((ScilabDouble)getIntegerParameters()).getRealPart()[0][0]);
+    }
 }
index c36dfa6..3c8f6e3 100644 (file)
@@ -14,44 +14,49 @@ package org.scilab.modules.xcos.block;
 
 import org.scilab.modules.hdf5.scilabTypes.ScilabDouble;
 import org.scilab.modules.hdf5.scilabTypes.ScilabList;
-import org.scilab.modules.hdf5.scilabTypes.ScilabString;
 import org.scilab.modules.hdf5.scilabTypes.ScilabType;
 import org.scilab.modules.xcos.utils.XcosEvent;
 
 import com.mxgraph.util.mxEventObject;
 
-public class EventOutBlock extends BasicBlock {
+public class EventOutBlock extends ContextUpdate {
 
-       public EventOutBlock() {
-               super();
-               setVertex(false);
-               setVisible(false);
-       }
+    private static final long serialVersionUID = 6585655980747217421L;
 
-       public EventOutBlock(String label) {
-               super(label);
-               setInterfaceFunctionName("CLKOUTV_f");
-               setSimulationFunctionName("output");
-               setNbZerosCrossing(new ScilabDouble(0));
-               setNmode(new ScilabDouble(0));
-               setODState(new ScilabList());
-               setValue("1");
-       }
+    public EventOutBlock() {
+       super();
+       setVertex(false);
+       setVisible(false);
+    }
 
-       public void setExprs(ScilabType exprs) {
-               super.setExprs(exprs);
-               setValue(((ScilabString) getExprs()).getData()[0][0]);
-       }
+    public EventOutBlock(String label) {
+       super(label);
+       setInterfaceFunctionName("CLKOUTV_f");
+       setSimulationFunctionName("output");
+       setNbZerosCrossing(new ScilabDouble(0));
+       setNmode(new ScilabDouble(0));
+       setODState(new ScilabList());
+       setValue(1);
+    }
 
-       public void updateBlockSettings(BasicBlock modifiedBlock) {
+    public void setExprs(ScilabType exprs) {
+       super.setExprs(exprs);
+       //setValue(((ScilabString) getExprs()).getData()[0][0]);
+    }
 
-               String oldValue = (String)getValue();
-               super.updateBlockSettings(modifiedBlock);
-               String newValue = (String)getValue();
-               
-               if(oldValue.compareTo(newValue) != 0){
-                       getParentDiagram().fireEvent(XcosEvent.OUT_EVENT_VALUE_UPDATED, new mxEventObject(new Object[]{oldValue,newValue}));
-               }
-               
+    public void updateBlockSettings(BasicBlock modifiedBlock) {
+
+       double oldValue = ((ScilabDouble)getIntegerParameters()).getRealPart()[0][0];
+       super.updateBlockSettings(modifiedBlock);
+       double newValue = ((ScilabDouble)getIntegerParameters()).getRealPart()[0][0];
+
+       if(oldValue != newValue){
+           getParentDiagram().fireEvent(XcosEvent.OUT_EVENT_VALUE_UPDATED, new mxEventObject(new Object[]{oldValue,newValue}));
        }
+    }
+
+    public void setIntegerParameters(ScilabType integerParameters) {
+       super.setIntegerParameters(integerParameters);
+       setValue((int)((ScilabDouble)getIntegerParameters()).getRealPart()[0][0]);
+    }
 }
index d166d40..1af4917 100644 (file)
@@ -14,44 +14,52 @@ package org.scilab.modules.xcos.block;
 
 import org.scilab.modules.hdf5.scilabTypes.ScilabDouble;
 import org.scilab.modules.hdf5.scilabTypes.ScilabList;
-import org.scilab.modules.hdf5.scilabTypes.ScilabString;
 import org.scilab.modules.hdf5.scilabTypes.ScilabType;
 import org.scilab.modules.xcos.utils.XcosEvent;
 
 import com.mxgraph.util.mxEventObject;
 
-public class ExplicitInBlock extends BasicBlock {
+public class ExplicitInBlock extends ContextUpdate {
 
-       public ExplicitInBlock() {
-               super();
-               setVertex(false);
-               setVisible(false);
-       }
+    private static final long serialVersionUID = -5872963017904352162L;
 
-       public ExplicitInBlock(String label) {
-               super(label);
-               setInterfaceFunctionName("IN_f");
-               setSimulationFunctionName("input");
-               setNbZerosCrossing(new ScilabDouble(0));
-               setNmode(new ScilabDouble(0));
-               setODState(new ScilabList());
-               setValue("1");
-       }
+    public ExplicitInBlock() {
+       super();
+       setVertex(false);
+       setVisible(false);
+    }
 
-       public void setExprs(ScilabType exprs) {
-               super.setExprs(exprs);
-               setValue(((ScilabString) getExprs()).getData()[0][0]);
-       }
+    public ExplicitInBlock(String label) {
+       super(label);
+       setInterfaceFunctionName("IN_f");
+       setSimulationFunctionName("input");
+       setNbZerosCrossing(new ScilabDouble(0));
+       setNmode(new ScilabDouble(0));
+       setODState(new ScilabList());
+       setValue(1);
+    }
+
+    public void setExprs(ScilabType exprs) {
+       super.setExprs(exprs);
+    }
 
-       public void updateBlockSettings(BasicBlock modifiedBlock) {
+    public void updateBlockSettings(BasicBlock modifiedBlock) {
 
-               String oldValue = (String)getValue();
-               super.updateBlockSettings(modifiedBlock);
-               String newValue = (String)getValue();
-               
-               if(oldValue.compareTo(newValue) != 0){
-                       getParentDiagram().fireEvent(XcosEvent.IN_EXPLICIT_VALUE_UPDATED, new mxEventObject(new Object[]{oldValue,newValue}));
-               }
-               
+       double oldValue = ((ScilabDouble)getIntegerParameters()).getRealPart()[0][0];
+       super.updateBlockSettings(modifiedBlock);
+       double newValue = ((ScilabDouble)getIntegerParameters()).getRealPart()[0][0];
+
+       if(oldValue != newValue){
+           getParentDiagram().fireEvent(XcosEvent.IN_EXPLICIT_VALUE_UPDATED, new mxEventObject(new Object[]{oldValue,newValue}));
+       }
+    }
+
+    public void setIntegerParameters(ScilabType integerParameters) {
+       super.setIntegerParameters(integerParameters);
+       setValue((int)((ScilabDouble)getIntegerParameters()).getRealPart()[0][0]);
+       if(getParentDiagram() != null) {
+           getParentDiagram().refresh();
        }
+    }
+
 }
index e9761e2..c5373cc 100644 (file)
@@ -14,44 +14,49 @@ package org.scilab.modules.xcos.block;
 
 import org.scilab.modules.hdf5.scilabTypes.ScilabDouble;
 import org.scilab.modules.hdf5.scilabTypes.ScilabList;
-import org.scilab.modules.hdf5.scilabTypes.ScilabString;
 import org.scilab.modules.hdf5.scilabTypes.ScilabType;
 import org.scilab.modules.xcos.utils.XcosEvent;
 
 import com.mxgraph.util.mxEventObject;
 
-public class ExplicitOutBlock extends BasicBlock {
+public class ExplicitOutBlock extends ContextUpdate {
 
-       public ExplicitOutBlock() {
-               super();
-               setVertex(false);
-               setVisible(false);
-       }
+    private static final long serialVersionUID = -3423053321045811400L;
 
-       public ExplicitOutBlock(String label) {
-               super(label);
-               setInterfaceFunctionName("OUT_f");
-               setSimulationFunctionName("output");
-               setNbZerosCrossing(new ScilabDouble(0));
-               setNmode(new ScilabDouble(0));
-               setODState(new ScilabList());
-               setValue("1");
-       }
+    public ExplicitOutBlock() {
+       super();
+       setVertex(false);
+       setVisible(false);
+    }
 
-       public void setExprs(ScilabType exprs) {
-               super.setExprs(exprs);
-               setValue(((ScilabString) getExprs()).getData()[0][0]);
-       }
+    public ExplicitOutBlock(String label) {
+       super(label);
+       setInterfaceFunctionName("OUT_f");
+       setSimulationFunctionName("output");
+       setNbZerosCrossing(new ScilabDouble(0));
+       setNmode(new ScilabDouble(0));
+       setODState(new ScilabList());
+       setValue(1);
+    }
 
-       public void updateBlockSettings(BasicBlock modifiedBlock) {
+    public void setExprs(ScilabType exprs) {
+       super.setExprs(exprs);
+       //setValue(((ScilabString) getExprs()).getData()[0][0]);
+    }
 
-               String oldValue = (String)getValue();
-               super.updateBlockSettings(modifiedBlock);
-               String newValue = (String)getValue();
-               
-               if(oldValue.compareTo(newValue) != 0){
-                       getParentDiagram().fireEvent(XcosEvent.OUT_EXPLICIT_VALUE_UPDATED, new mxEventObject(new Object[]{oldValue,newValue}));
-               }
-               
+    public void updateBlockSettings(BasicBlock modifiedBlock) {
+
+       double oldValue = ((ScilabDouble)getIntegerParameters()).getRealPart()[0][0];
+       super.updateBlockSettings(modifiedBlock);
+       double newValue = ((ScilabDouble)getIntegerParameters()).getRealPart()[0][0];
+
+       if(oldValue != newValue){
+           getParentDiagram().fireEvent(XcosEvent.OUT_EXPLICIT_VALUE_UPDATED, new mxEventObject(new Object[]{oldValue,newValue}));
        }
+    }
+
+    public void setIntegerParameters(ScilabType integerParameters) {
+       super.setIntegerParameters(integerParameters);
+       setValue((int)((ScilabDouble)getIntegerParameters()).getRealPart()[0][0]);
+    }
 }
index 44bac4c..9338dbb 100644 (file)
@@ -17,6 +17,8 @@ import org.scilab.modules.hdf5.scilabTypes.ScilabType;
 
 public class GainBlock extends BasicBlock {
 
+     private static final long serialVersionUID = 7762548847345910801L;
+
     public GainBlock() {
        super();
        setVertex(false);
index 02b594a..1054e99 100644 (file)
@@ -14,13 +14,14 @@ package org.scilab.modules.xcos.block;
 
 import org.scilab.modules.hdf5.scilabTypes.ScilabDouble;
 import org.scilab.modules.hdf5.scilabTypes.ScilabList;
-import org.scilab.modules.hdf5.scilabTypes.ScilabString;
 import org.scilab.modules.hdf5.scilabTypes.ScilabType;
 import org.scilab.modules.xcos.utils.XcosEvent;
 
 import com.mxgraph.util.mxEventObject;
 
-public class ImplicitInBlock extends BasicBlock {
+public class ImplicitInBlock extends ContextUpdate {
+
+    private static final long serialVersionUID = 4280002965735451155L;
 
        public ImplicitInBlock() {
                super();
@@ -35,23 +36,27 @@ public class ImplicitInBlock extends BasicBlock {
                setNbZerosCrossing(new ScilabDouble(0));
                setNmode(new ScilabDouble(0));
                setODState(new ScilabList());
-               setValue("1");
-       }
+               setValue(1);
+           }
 
-       public void setExprs(ScilabType exprs) {
+           public void setExprs(ScilabType exprs) {
                super.setExprs(exprs);
-               setValue(((ScilabString) getExprs()).getData()[0][0]);
-       }
+               //setValue(((ScilabString) getExprs()).getData()[0][0]);
+           }
 
-       public void updateBlockSettings(BasicBlock modifiedBlock) {
+           public void updateBlockSettings(BasicBlock modifiedBlock) {
 
-               String oldValue = (String)getValue();
-               super.updateBlockSettings(modifiedBlock);
-               String newValue = (String)getValue();
-               
-               if(oldValue.compareTo(newValue) != 0){
-                       getParentDiagram().fireEvent(XcosEvent.IN_IMPLICIT_VALUE_UPDATED, new mxEventObject(new Object[]{oldValue,newValue}));
+               double oldValue = ((ScilabDouble)getIntegerParameters()).getRealPart()[0][0];
+               super.updateBlockSettings(modifiedBlock);
+               double newValue = ((ScilabDouble)getIntegerParameters()).getRealPart()[0][0];
+
+               if(oldValue != newValue){
+                   getParentDiagram().fireEvent(XcosEvent.IN_IMPLICIT_VALUE_UPDATED, new mxEventObject(new Object[]{oldValue,newValue}));
                }
-               
-       }
+           }
+
+           public void setIntegerParameters(ScilabType integerParameters) {
+               super.setIntegerParameters(integerParameters);
+               setValue((int)((ScilabDouble)getIntegerParameters()).getRealPart()[0][0]);
+           }
 }
index 4ec574e..20e28cc 100644 (file)
@@ -14,44 +14,49 @@ package org.scilab.modules.xcos.block;
 
 import org.scilab.modules.hdf5.scilabTypes.ScilabDouble;
 import org.scilab.modules.hdf5.scilabTypes.ScilabList;
-import org.scilab.modules.hdf5.scilabTypes.ScilabString;
 import org.scilab.modules.hdf5.scilabTypes.ScilabType;
 import org.scilab.modules.xcos.utils.XcosEvent;
 
 import com.mxgraph.util.mxEventObject;
 
-public class ImplicitOutBlock extends BasicBlock {
+public class ImplicitOutBlock extends ContextUpdate {
 
-       public ImplicitOutBlock() {
-               super();
-               setVertex(false);
-               setVisible(false);
-       }
+     private static final long serialVersionUID = 3573293528173540817L;
 
-       public ImplicitOutBlock(String label) {
-               super(label);
-               setInterfaceFunctionName("OUTIMPL_f");
-               setSimulationFunctionName("outimpl");
-               setNbZerosCrossing(new ScilabDouble(0));
-               setNmode(new ScilabDouble(0));
-               setODState(new ScilabList());
-               setValue("1");
-       }
+    public ImplicitOutBlock() {
+       super();
+       setVertex(false);
+       setVisible(false);
+    }
 
-       public void setExprs(ScilabType exprs) {
-               super.setExprs(exprs);
-               setValue(((ScilabString) getExprs()).getData()[0][0]);
-       }
+    public ImplicitOutBlock(String label) {
+       super(label);
+       setInterfaceFunctionName("OUTIMPL_f");
+       setSimulationFunctionName("outimpl");
+       setNbZerosCrossing(new ScilabDouble(0));
+       setNmode(new ScilabDouble(0));
+       setODState(new ScilabList());
+       setValue(1);
+    }
 
-       public void updateBlockSettings(BasicBlock modifiedBlock) {
+    public void setExprs(ScilabType exprs) {
+       super.setExprs(exprs);
+       //setValue(((ScilabString) getExprs()).getData()[0][0]);
+    }
 
-               String oldValue = (String)getValue();
-               super.updateBlockSettings(modifiedBlock);
-               String newValue = (String)getValue();
-               
-               if(oldValue.compareTo(newValue) != 0){
-                       getParentDiagram().fireEvent(XcosEvent.OUT_IMPLICIT_VALUE_UPDATED, new mxEventObject(new Object[]{oldValue,newValue}));
-               }
-               
+    public void updateBlockSettings(BasicBlock modifiedBlock) {
+
+       double oldValue = ((ScilabDouble)getIntegerParameters()).getRealPart()[0][0];
+       super.updateBlockSettings(modifiedBlock);
+       double newValue = ((ScilabDouble)getIntegerParameters()).getRealPart()[0][0];
+
+       if(oldValue != newValue){
+           getParentDiagram().fireEvent(XcosEvent.OUT_IMPLICIT_VALUE_UPDATED, new mxEventObject(new Object[]{oldValue,newValue}));
        }
+    }
+
+    public void setIntegerParameters(ScilabType integerParameters) {
+       super.setIntegerParameters(integerParameters);
+       setValue((int)((ScilabDouble)getIntegerParameters()).getRealPart()[0][0]);
+    }
 }
index 2ae65e4..fece60a 100644 (file)
@@ -85,6 +85,9 @@ public class SuperBlock extends BasicBlock {
        } else {
            getChild().setVisible(true);
        }
+       
+       
+       getChild().updateCellsContext();
     }
 
     public void closeBlockSettings() {
@@ -263,27 +266,6 @@ public class SuperBlock extends BasicBlock {
        return list; 
     }
 
-    protected int getBlocksWithValueCount(List<mxCell> blocks, String checkValue){
-       int count = 0;
-       for(int i = 0 ; i < blocks.size() ; i++){
-           if(((String)((BasicBlock)blocks.get(i)).getValue()).compareTo(checkValue) == 0){
-               count++;
-           }
-       }
-       return count;
-    }
-
-    protected List<mxCell> getBlocksWithValue(List<mxCell> blocks, String checkValue){
-       List<mxCell> list = new ArrayList<mxCell>();
-
-       for(int i = 0 ; i < blocks.size() ; i++){
-           if(((String)((BasicBlock)blocks.get(i)).getValue()).compareTo(checkValue) == 0){
-               list.add((BasicBlock)blocks.get(i));
-           }
-       }
-       return list;
-    }
-
     protected int getBlocksConsecutiveUniqueValueCount(List<mxCell> blocks){
        if(blocks == null){
                return 0;
@@ -299,7 +281,7 @@ public class SuperBlock extends BasicBlock {
        
        //populate
        for(int i = 0 ; i < array.length; i++){
-               int index = Integer.parseInt((String)((BasicBlock)blocks.get(i)).getValue());
+               int index = (Integer)((BasicBlock)blocks.get(i)).getValue();
                if(index <= array.length){
                        array[index - 1] = 1;   
                }
@@ -344,7 +326,7 @@ public class SuperBlock extends BasicBlock {
 
 
                for(int i = 0 ; i < blocks.size() ; i++){
-                       int index = Integer.parseInt((String)((BasicBlock)blocks.get(i)).getValue());
+                       int index = (Integer)((BasicBlock)blocks.get(i)).getValue();
                        if(index > countUnique || isDone[index - 1] == true){
                                child.getAsComponent().setCellWarning(blocks.get(i), "Wrong port number");
                        }else{
index 265f435..cf1bdee 100644 (file)
@@ -675,13 +675,11 @@ public class BlockReader {
        ArrayList<String> context = new ArrayList<String>();
        if (params.get(5).getHeight() >= params.get(5).getWidth()) {
            for (int i = 0; i < params.get(5).getHeight(); i++) {
-               context.add(((ScilabString) params.get(5)).getData()[i][0]
-                       + ";");
+               context.add(((ScilabString) params.get(5)).getData()[i][0]);
            }
        } else {
            for (int i = 0; i < params.get(5).getWidth(); i++) {
-               context.add(((ScilabString) params.get(5)).getData()[0][i]
-                       + ";");
+               context.add(((ScilabString) params.get(5)).getData()[0][i]);
            }
 
        }
index 16dba67..2cc4951 100644 (file)
@@ -15,9 +15,9 @@ package org.scilab.modules.xcos.utils;
 import com.mxgraph.util.mxEvent;
 
 public class XcosEvent extends mxEvent {
-    public static final String ADD_PORTS                                       = "addPorts";
+    public static final String ADD_PORTS                       = "addPorts";
 
-    public static final String SUPER_BLOCK_UPDATED                     = "superBlockUpdated";
+    public static final String SUPER_BLOCK_UPDATED             = "superBlockUpdated";
     
     public static final String IN_EXPLICIT_VALUE_UPDATED       = "InExplicitValueUpdated";
     public static final String OUT_EXPLICIT_VALUE_UPDATED      = "OutExplicitValueUpdated";
@@ -31,4 +31,5 @@ public class XcosEvent extends mxEvent {
     public static final String FORCE_CELL_RESHAPE              = "ForceCellReshape";
 
     public static final String FORCE_CELL_VALUE_UPDATE                 = "ForceCellValueUpdate";
+    
 }