7c8c1b517dcb03f147331d75cb6d73b68b25b2f5
[scilab.git] / scilab / modules / xcos / src / java / org / scilab / modules / xcos / block / ImplicitInBlock.java
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2009 - DIGITEO - Antoine ELIAS
4  *
5  * This file must be used under the terms of the CeCILL.
6  * This source file is licensed as described in the file COPYING, which
7  * you should have received as part of this distribution.  The terms
8  * are also available at
9  * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10  *
11  */
12
13 package org.scilab.modules.xcos.block;
14
15 import org.scilab.modules.hdf5.scilabTypes.ScilabDouble;
16 import org.scilab.modules.hdf5.scilabTypes.ScilabType;
17
18 import org.scilab.modules.xcos.utils.XcosEvent;
19
20 import com.mxgraph.util.mxEventObject;
21
22 public final class ImplicitInBlock extends ContextUpdate {
23
24     private static final long serialVersionUID = 4280002965735451155L;
25
26         public ImplicitInBlock() {
27                 super();
28         }
29
30         protected ImplicitInBlock(String label) {
31                 this();
32                 setDefaultValues();
33                 setValue(label);
34         }
35
36         /**
37          * Initialize the block with the default values
38          */
39         @Override
40         protected void setDefaultValues() {
41                 super.setDefaultValues();
42                 setInterfaceFunctionName("INIMPL_f");
43                 setSimulationFunctionName("inimpl");
44         }
45
46             public void setExprs(ScilabType exprs) {
47                 super.setExprs(exprs);
48                 //setValue(((ScilabString) getExprs()).getData()[0][0]);
49             }
50
51             public void updateBlockSettings(BasicBlock modifiedBlock) {
52
53                 double oldValue = ((ScilabDouble)getIntegerParameters()).getRealPart()[0][0];
54                 super.updateBlockSettings(modifiedBlock);
55                 double newValue = ((ScilabDouble)getIntegerParameters()).getRealPart()[0][0];
56
57                 if(oldValue != newValue){
58                     getParentDiagram().fireEvent(XcosEvent.IN_IMPLICIT_VALUE_UPDATED, new mxEventObject(new Object[]{oldValue,newValue}));
59                 }
60             }
61
62             public void setIntegerParameters(ScilabType integerParameters) {
63                 super.setIntegerParameters(integerParameters);
64                 setValue((int)((ScilabDouble)getIntegerParameters()).getRealPart()[0][0]);
65             }
66 }