r3614 - in branches/4.1/src/main: java/fr/ifremer/isisfish/entities java/fr/ifremer/isisfish/simulator java/fr/ifremer/isisfish/ui/input/variable xmi
Author: echatellier Date: 2012-02-20 13:12:45 +0100 (Mon, 20 Feb 2012) New Revision: 3614 Url: http://forge.codelutin.com/repositories/revision/isis-fish/3614 Log: Replace "type" string by enumeration. Add equation and matrix output Added: branches/4.1/src/main/java/fr/ifremer/isisfish/entities/VariableType.java Modified: branches/4.1/src/main/java/fr/ifremer/isisfish/entities/VariableImpl.java branches/4.1/src/main/java/fr/ifremer/isisfish/simulator/SimulationContext.java branches/4.1/src/main/java/fr/ifremer/isisfish/simulator/SimulationVariable.java branches/4.1/src/main/java/fr/ifremer/isisfish/ui/input/variable/EntityVariableHandler.java branches/4.1/src/main/java/fr/ifremer/isisfish/ui/input/variable/VariableTypeComboModel.java branches/4.1/src/main/xmi/isis-fish.properties branches/4.1/src/main/xmi/isis-fish.zargo Modified: branches/4.1/src/main/java/fr/ifremer/isisfish/entities/VariableImpl.java =================================================================== --- branches/4.1/src/main/java/fr/ifremer/isisfish/entities/VariableImpl.java 2012-02-17 16:37:27 UTC (rev 3613) +++ branches/4.1/src/main/java/fr/ifremer/isisfish/entities/VariableImpl.java 2012-02-20 12:12:45 UTC (rev 3614) @@ -41,9 +41,13 @@ private static final long serialVersionUID = 3978428224373810278L; /* - private static Log log = LogFactory.getLog(VariableImpl.class); + private static Log log = LogFactory.getLog(VariableImpl.class); */ - @Override + public VariableImpl() { + setType(VariableType.DOUBLE); + } + + /*@Override public void setDoubleValue(double doubleValue) { super.setDoubleValue(doubleValue); super.setMatrixValue(null); Added: branches/4.1/src/main/java/fr/ifremer/isisfish/entities/VariableType.java =================================================================== --- branches/4.1/src/main/java/fr/ifremer/isisfish/entities/VariableType.java (rev 0) +++ branches/4.1/src/main/java/fr/ifremer/isisfish/entities/VariableType.java 2012-02-20 12:12:45 UTC (rev 3614) @@ -0,0 +1,41 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Ifremer, Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package fr.ifremer.isisfish.entities; + +/** + * Variable type. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public enum VariableType { + DOUBLE, + EQUATION, + MATRIX +} Property changes on: branches/4.1/src/main/java/fr/ifremer/isisfish/entities/VariableType.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: branches/4.1/src/main/java/fr/ifremer/isisfish/simulator/SimulationContext.java =================================================================== --- branches/4.1/src/main/java/fr/ifremer/isisfish/simulator/SimulationContext.java 2012-02-17 16:37:27 UTC (rev 3613) +++ branches/4.1/src/main/java/fr/ifremer/isisfish/simulator/SimulationContext.java 2012-02-20 12:12:45 UTC (rev 3614) @@ -81,6 +81,7 @@ protected Set<SimulationListener> simulationListeners = new LinkedHashSet<SimulationListener>(); protected ClassLoader classLoader = null; protected File scriptDirectory; + protected TimeStep timeStep; /** TopiaContext must be used by rule action to modify data */ protected TopiaContext db = null; @@ -320,6 +321,26 @@ } /** + * Set simulation current time step. + * + * @param timeStep current time step + * @since 4.1.0.0 + */ + public void setTimeStep(TimeStep timeStep) { + this.timeStep = timeStep; + } + + /** + * Get simulation current time step. + * + * @return current time step + * @since 4.1.0.0 + */ + public TimeStep getTimeStep() { + return timeStep; + } + + /** * Script directory to use. * * Used to chnage isis-database-3 directory in running simulation context. @@ -392,6 +413,7 @@ * * @param entity entity * @return map object for this class + * @since 4.1.0.0 */ public SimulationVariable get(TopiaEntity entity) { SimulationVariable v = variablesCache.get(entity); @@ -405,16 +427,16 @@ /** * Save all cached context values. * - * @param step + * @since 4.1.0.0 */ - public void saveContextValues(TimeStep step) { + public void saveContextValues() { File exportFile = new File(getScriptDirectory(), "variables.txt"); Writer out = null; try { out = new FileWriter(exportFile, true); - out.write("=========== Step : " + step.toString() + " ===========\n"); + out.write("=========== Step : " + timeStep.toString() + " ===========\n"); for (Map.Entry<TopiaEntity, SimulationVariable> entry : variablesCache.entrySet()) { TopiaEntity entity = entry.getKey(); SimulationVariable simVariable = entry.getValue(); @@ -432,13 +454,17 @@ out.write(name + " "); out.write(variable.getName()); out.write(" = "); - - if ("double".equals(variable.getType())) { + + switch (variable.getType()) { + case DOUBLE: out.write(String.valueOf(variable.getDoubleValue())); - } else if ("matrix".equals(variable.getType())) { - out.write("todo matrix"); - } else if ("equation".equals(variable.getType())) { - out.write("todo equation"); + break; + case MATRIX: + out.write(variable.getMatrixValue().toString()); + break; + case EQUATION: + out.write(String.valueOf(simVariable.eval(variable))); + break; } out.write("\n"); } Modified: branches/4.1/src/main/java/fr/ifremer/isisfish/simulator/SimulationVariable.java =================================================================== --- branches/4.1/src/main/java/fr/ifremer/isisfish/simulator/SimulationVariable.java 2012-02-17 16:37:27 UTC (rev 3613) +++ branches/4.1/src/main/java/fr/ifremer/isisfish/simulator/SimulationVariable.java 2012-02-20 12:12:45 UTC (rev 3614) @@ -46,6 +46,7 @@ * * @author chatellier * @version $Revision$ + * @since 4.1.0.0 * * Last update : $Date$ * By : $Author$ @@ -148,15 +149,25 @@ */ public double eval(String name) throws TopiaException { Variable v = getVariableEntity(name); + return eval(v); + } + + /** + * Eval current variable equation. + * + * @param v variable + * @return equation result + */ + protected double eval(Variable v) { Equation eq = v.getEquationValue(); Map<String, Object> args = new HashMap<String, Object>(); args.put("context", simulationContext); args.put("entity", topiaEntity); - args.put("step", new TimeStep()); // FIXME echatellier how to get real timestep value ? + args.put("step", simulationContext.getTimeStep()); Object val = EvaluatorHelper.evaluate("fr.ifremer.isisfish.equation", - topiaEntity.getTopiaId() + "#" + name, VariableEquation.class, + topiaEntity.getTopiaId() + "#" + v.getName(), VariableEquation.class, eq.getContent(), args); double result = 0.0; Modified: branches/4.1/src/main/java/fr/ifremer/isisfish/ui/input/variable/EntityVariableHandler.java =================================================================== --- branches/4.1/src/main/java/fr/ifremer/isisfish/ui/input/variable/EntityVariableHandler.java 2012-02-17 16:37:27 UTC (rev 3613) +++ branches/4.1/src/main/java/fr/ifremer/isisfish/ui/input/variable/EntityVariableHandler.java 2012-02-20 12:12:45 UTC (rev 3614) @@ -42,6 +42,7 @@ import fr.ifremer.isisfish.IsisFishRuntimeException; import fr.ifremer.isisfish.entities.Variable; import fr.ifremer.isisfish.entities.VariableDAO; +import fr.ifremer.isisfish.entities.VariableType; import fr.ifremer.isisfish.ui.input.model.TopiaEntityListModel; /** @@ -97,8 +98,7 @@ Variable variable = dao.create( Variable.PROPERTY_ENTITY_ID, view.getBean().getTopiaId(), - Variable.PROPERTY_NAME, _("isisfish.variables.defaultname"), - Variable.PROPERTY_TYPE, "double"); + Variable.PROPERTY_NAME, _("isisfish.variables.defaultname")); TopiaEntityListModel model = (TopiaEntityListModel)view.getVariablesList().getModel(); List<Variable> variables = (List<Variable>)model.getElements(); @@ -174,14 +174,18 @@ */ public void showSelectedType(EntityVariableUI view) { CardLayout cardLayout = view.getVariableTypeLayout(); - String type = (String)view.getVariableTypeCombo().getSelectedItem(); + VariableType type = (VariableType)view.getVariableTypeCombo().getSelectedItem(); view.getVariable().setType(type); - if ("double".equals(type)) { + switch (type) { + case DOUBLE: cardLayout.show(view.getVariableTypePanel(), "doubletype"); - } else if ("matrix".equals(type)) { - cardLayout.show(view.getVariableTypePanel(), "matrixtype"); - } else if ("equation".equals(type)) { + break; + case EQUATION: cardLayout.show(view.getVariableTypePanel(), "equationtype"); + break; + case MATRIX: + cardLayout.show(view.getVariableTypePanel(), "matrixtype"); + break; } } @@ -195,10 +199,10 @@ Variable variable = (Variable)variableList.getSelectedValue(); variable.setName(view.getVariableNameField().getText().trim()); - String type = (String)view.getVariableTypeCombo().getSelectedItem(); - //variable.setType((String)view.getVariableTypeCombo().getSelectedItem()); + VariableType type = (VariableType)view.getVariableTypeCombo().getSelectedItem(); - if ("double".equals(type)) { + switch (type) { + case DOUBLE: try { double v = Double.parseDouble(view.getVariableDoubleValue().getText().trim()); variable.setDoubleValue(v); @@ -207,16 +211,11 @@ log.warn("Can't parse double value as double", ex); } } - } else if ("matrix".equals(type)) { + break; + case MATRIX: variable.setMatrixValue(view.getMatrixPanel().getMatrix()); - } /*else if ("equation".equals(type)) { - Equation eq = variable.getEquationValue(); - if (eq == null) { - eq = new EquationImpl(); - } - eq.setContent(view.getVariableDoubleValue().getText()); - variable.setEquationValue(eq); - }*/ + break; + } // equation already set by ui component try { // save in db Modified: branches/4.1/src/main/java/fr/ifremer/isisfish/ui/input/variable/VariableTypeComboModel.java =================================================================== --- branches/4.1/src/main/java/fr/ifremer/isisfish/ui/input/variable/VariableTypeComboModel.java 2012-02-17 16:37:27 UTC (rev 3613) +++ branches/4.1/src/main/java/fr/ifremer/isisfish/ui/input/variable/VariableTypeComboModel.java 2012-02-20 12:12:45 UTC (rev 3614) @@ -30,6 +30,8 @@ import javax.swing.DefaultComboBoxModel; +import fr.ifremer.isisfish.entities.VariableType; + /** * Modele pour la liste des type possible de variable. * @@ -45,16 +47,13 @@ private static final long serialVersionUID = 6171850179969290032L; /** Values list */ - protected List<String> variableTypes; + protected VariableType[] variableTypes; /** * Empty constructor. */ public VariableTypeComboModel() { - variableTypes = new ArrayList<String>(); - variableTypes.add("double"); - variableTypes.add("equation"); - variableTypes.add("matrix"); + variableTypes = VariableType.values(); } /* @@ -62,7 +61,7 @@ */ @Override public Object getElementAt(int index) { - return variableTypes.get(index); + return variableTypes[index]; } /* @@ -73,7 +72,7 @@ int size = 0; if (variableTypes != null) { - size = variableTypes.size(); + size = variableTypes.length; } return size; } Modified: branches/4.1/src/main/xmi/isis-fish.properties =================================================================== --- branches/4.1/src/main/xmi/isis-fish.properties 2012-02-17 16:37:27 UTC (rev 3613) +++ branches/4.1/src/main/xmi/isis-fish.properties 2012-02-20 12:12:45 UTC (rev 3614) @@ -31,6 +31,7 @@ model.tagvalue.java.lang.String=text model.tagvalue.hibernateProxyInterface=none model.tagvalue.constantPrefix=PROPERTY_ +model.tagvalue.useEnumerationName=true fr.ifremer.isisfish.entities.ActiveRule.class.tagvalue.contextable=true fr.ifremer.isisfish.entities.Cell.class.tagvalue.contextable=true fr.ifremer.isisfish.entities.EffortDescription.class.tagvalue.contextable=true Modified: branches/4.1/src/main/xmi/isis-fish.zargo =================================================================== (Binary files differ)
participants (1)
-
echatellier@users.forge.codelutin.com