VALIDATIONS.Units.moduleInterfaceExtension : L0.Function\r
\r
\r
-\r
SYSDYN.Variable\r
@VALIDATIONS.constraint\r
VALIDATIONS.ExpressionConstraint\r
VALIDATIONS.Dependencies.missingDependencyValidator \r
VALIDATIONS.Functions.baseRealizationFunction \r
\r
+VALIDATIONS.Units.UnitIssueSource\r
+ >-- VALIDATIONS.Units.UnitIssueSource.allowEquivalents >-- L0.Boolean <R L0.HasProperty : L0.FunctionalRelation\r
+\r
SYSDYN.Component\r
@VALIDATIONS.listeningConstraint\r
VALIDATIONS.UnitConstraint\r
VALIDATIONS.Units.UnitIssueSource\r
@L0.assert L0.HasName "UnitIssueSource"\r
+ @L0.assert VALIDATIONS.Units.UnitIssueSource.allowEquivalents L0.True\r
L0.Asserts _ : L0.Assertion\r
L0.HasPredicate ISSUE.Sources.DependencyTracker.HasExtension\r
L0.HasObject VALIDATIONS.Units.moduleInterfaceExtension\r
public final Resource Validations_UnitWarning;\r
public final Resource Validations_Units;\r
public final Resource Validations_Units_UnitIssueSource;\r
+ public final Resource Validations_Units_UnitIssueSource_allowEquivalents;\r
+ public final Resource Validations_Units_UnitIssueSource_allowEquivalents_Inverse;\r
public final Resource Validations_Units_moduleInputUnitWarningDescription;\r
public final Resource Validations_Units_moduleInterfaceExtension;\r
public final Resource Validations_Units_moduleOutputUnitWarningDescription;\r
public static final String Validations_UnitWarning = "http://www.simantics.org/Sysdyn-1.1/Validations/UnitWarning";\r
public static final String Validations_Units = "http://www.simantics.org/Sysdyn-1.1/Validations/Units";\r
public static final String Validations_Units_UnitIssueSource = "http://www.simantics.org/Sysdyn-1.1/Validations/Units/UnitIssueSource";\r
+ public static final String Validations_Units_UnitIssueSource_allowEquivalents = "http://www.simantics.org/Sysdyn-1.1/Validations/Units/UnitIssueSource/allowEquivalents";\r
+ public static final String Validations_Units_UnitIssueSource_allowEquivalents_Inverse = "http://www.simantics.org/Sysdyn-1.1/Validations/Units/UnitIssueSource/allowEquivalents/Inverse";\r
public static final String Validations_Units_moduleInputUnitWarningDescription = "http://www.simantics.org/Sysdyn-1.1/Validations/Units/moduleInputUnitWarningDescription";\r
public static final String Validations_Units_moduleInterfaceExtension = "http://www.simantics.org/Sysdyn-1.1/Validations/Units/moduleInterfaceExtension";\r
public static final String Validations_Units_moduleOutputUnitWarningDescription = "http://www.simantics.org/Sysdyn-1.1/Validations/Units/moduleOutputUnitWarningDescription";\r
Validations_UnitWarning = getResourceOrNull(graph, URIs.Validations_UnitWarning);\r
Validations_Units = getResourceOrNull(graph, URIs.Validations_Units);\r
Validations_Units_UnitIssueSource = getResourceOrNull(graph, URIs.Validations_Units_UnitIssueSource);\r
+ Validations_Units_UnitIssueSource_allowEquivalents = getResourceOrNull(graph, URIs.Validations_Units_UnitIssueSource_allowEquivalents);\r
+ Validations_Units_UnitIssueSource_allowEquivalents_Inverse = getResourceOrNull(graph, URIs.Validations_Units_UnitIssueSource_allowEquivalents_Inverse);\r
Validations_Units_moduleInputUnitWarningDescription = getResourceOrNull(graph, URIs.Validations_Units_moduleInputUnitWarningDescription);\r
Validations_Units_moduleInterfaceExtension = getResourceOrNull(graph, URIs.Validations_Units_moduleInterfaceExtension);\r
Validations_Units_moduleOutputUnitWarningDescription = getResourceOrNull(graph, URIs.Validations_Units_moduleOutputUnitWarningDescription);\r
/*******************************************************************************\r
- * Copyright (c) 2010, 2012 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012, 2014 Association for Decentralized Information Management in\r
* Industry THTH ry.\r
* All rights reserved. This program and the accompanying materials\r
* are made available under the terms of the Eclipse Public License v1.0\r
import org.simantics.layer0.Layer0;\r
import org.simantics.operation.Layer0X;\r
import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.properties.widgets.EquivalentUnitsWidget;\r
import org.simantics.sysdyn.ui.properties.widgets.factories.ComboStringPropertyModifier;\r
import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory;\r
import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier;\r
* Tab displaying configuration properties. Displayed for model and configuration.\r
* \r
* @author Teemu Lempinen\r
+ * @author Tuomas Miettinen\r
*\r
*/\r
public class ConfigurationTab extends AdjustableTab {\r
\r
- ScrolledComposite sc;\r
- Composite composite;\r
- Label nameLabel, startTimeLabel, stopTimeLabel, stepLengthLabel, \r
+ private ScrolledComposite sc;\r
+ private Composite composite;\r
+ private Label nameLabel, startTimeLabel, stopTimeLabel, stepLengthLabel, \r
outputIntervalLabel, methodLabel, toleranceLabel, variableFilterLabel;\r
- TrackedText name, startTime, stopTime, stepLength, outputInterval, tolerance, variableFilter;\r
- TrackedCombo method, timeUnit;\r
- Button validateUnits;\r
+ private TrackedText name, startTime, stopTime, stepLength, outputInterval, tolerance, variableFilter;\r
+ private TrackedCombo method, timeUnit;\r
+ private Button validateUnits;\r
+ private EquivalentUnitsWidget equivalentUnitsWidget;\r
/**\r
* Modifier for modifying model labels\r
* @author Teemu Lempinen\r
if(result == null)\r
result = false;\r
graph.claimLiteral(unitIssueSource, ISSUE.IssueSource_active, Boolean.FALSE.equals(result));\r
+ \r
+ // Enable or disable the Unit Equivalents button based if\r
+ // unit validation is enabled or not.\r
+ final boolean enabled = !result;\r
+ if (!equivalentUnitsWidget.getWidget().isDisposed())\r
+ equivalentUnitsWidget.getWidget().getDisplay().asyncExec(new Runnable() {\r
+ \r
+ @Override\r
+ public void run() {\r
+ if(!equivalentUnitsWidget.getWidget().isDisposed())\r
+ equivalentUnitsWidget.getWidget().setEnabled(enabled);\r
+ }\r
+ });\r
+\r
}\r
\r
});\r
+ equivalentUnitsWidget = new EquivalentUnitsWidget(composite, support, 0);\r
\r
timeUnit = new TrackedCombo(composite, support, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);\r
timeUnit.setItemFactory(new ReadFactoryImpl<Resource, Map<String,Object>>() {\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2014 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.properties.widgets;\r
+\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.jface.viewers.IStructuredSelection;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.widgets.Button;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl;\r
+import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.PossibleObjectWithType;\r
+import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.management.ISessionContext;\r
+import org.simantics.issues.ontology.IssueResource;\r
+import org.simantics.operation.Layer0X;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.utils.ui.ISelectionUtils;\r
+\r
+/**\r
+ * Widget for equivalent units selection.\r
+ * @author Tuomas Miettinen\r
+ *\r
+ */\r
+public class EquivalentUnitsWidget implements Widget{\r
+\r
+ Resource model = null; \r
+ org.simantics.browsing.ui.swt.widgets.Button unitEquivalents;\r
+ \r
+ public EquivalentUnitsWidget(Composite parent, WidgetSupport support, int style) {\r
+ support.register(this);\r
+ unitEquivalents = new org.simantics.browsing.ui.swt.widgets.Button(parent, support, style |= SWT.CHECK);\r
+ unitEquivalents.setText("Unit equivalents");\r
+ unitEquivalents.getWidget().setToolTipText("Supported equivalent units:\n" +\r
+ "$, $s, dollar, dollars, usd\n"+\r
+ "\u20ac, \u20acs, eur, euro, euros, e, ecu\n"+\r
+ "£, £s, pound, pounds, gbp\n"+\r
+ "Unit, Units\n"+\r
+ "Person, People, Persons\n"+\r
+ "second, seconds, sec, s\n"+\r
+ "minute, minutes, min\n"+\r
+ "hour, hours, h, hr\n"+\r
+ "day, days, d\n"+\r
+ "month, months, mon, mth, mo, mos\n"+\r
+ "year, years, a, y, yr");\r
+ \r
+ }\r
+\r
+ @Override\r
+ public void setInput(ISessionContext context, Object input) {\r
+ if(input instanceof ISelection) {\r
+ ISelection selection = (ISelection)input;\r
+ if(selection instanceof IStructuredSelection) {\r
+ Resource resource = ISelectionUtils.filterSingleSelection(selection, Resource.class);\r
+ if(resource != null) {\r
+ model = resource;\r
+ }\r
+ }\r
+ }\r
+ \r
+ if(model == null) return;\r
+ \r
+ try {\r
+ context.getSession().syncRequest(new ReadRequest() {\r
+ \r
+ @Override\r
+ public void run(ReadGraph graph) throws DatabaseException {\r
+ // Determine if unit validation is enabled.\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ final Resource unitIssueSource = graph.syncRequest(\r
+ new PossibleObjectWithType(model, \r
+ Layer0X.getInstance(graph).Activates, \r
+ sr.Validations_Units_UnitIssueSource));\r
+ IssueResource ISSUE = IssueResource.getInstance(graph);\r
+ final Boolean issueSource_active = graph.getPossibleRelatedValue(unitIssueSource, ISSUE.IssueSource_active, Bindings.BOOLEAN);\r
+ \r
+ Boolean result = false;\r
+ if(unitIssueSource != null) {\r
+ result = graph.getPossibleRelatedValue(unitIssueSource, sr.Validations_Units_UnitIssueSource_allowEquivalents, Bindings.BOOLEAN);\r
+ }\r
+\r
+ final boolean enable = result;\r
+ final Button button = getWidget();\r
+ button.getDisplay().asyncExec(new Runnable() {\r
+ \r
+ @Override\r
+ public void run() {\r
+ if(button.isDisposed()) return;\r
+ \r
+ // Is unit validation is enabled, enable the button.\r
+ getWidget().setEnabled(unitIssueSource!=null && issueSource_active);\r
+ if(Boolean.TRUE.equals(enable))\r
+ button.setSelection(true);\r
+ else\r
+ button.setSelection(false);\r
+ }\r
+ }); \r
+ }\r
+ });\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ \r
+ unitEquivalents.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
+\r
+ @Override\r
+ public void apply(WriteGraph graph, Resource model) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Resource unitIssueSource = graph.syncRequest(\r
+ new PossibleObjectWithType(model, \r
+ Layer0X.getInstance(graph).Activates, \r
+ sr.Validations_Units_UnitIssueSource));\r
+ if(unitIssueSource == null)\r
+ return;\r
+ \r
+ Boolean result = graph.getPossibleRelatedValue(unitIssueSource, sr.Validations_Units_UnitIssueSource_allowEquivalents, Bindings.BOOLEAN);\r
+ if(result == null)\r
+ result = false;\r
+ graph.claimLiteral(unitIssueSource, sr.Validations_Units_UnitIssueSource_allowEquivalents, Boolean.FALSE.equals(result));\r
+ }\r
+ });\r
+ }\r
+ \r
+ public Button getWidget() {\r
+ return unitEquivalents.getWidget();\r
+ }\r
+\r
+}\r
/*******************************************************************************\r
- * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * Copyright (c) 2013-2014 Association for Decentralized Information Management in\r
* Industry THTH ry.\r
* All rights reserved. This program and the accompanying materials\r
* are made available under the terms of the Eclipse Public License v1.0\r
*\r
* Contributors:\r
* Semantum Oy - initial API and implementation\r
+ * VTT Technical Research Centre of Finland\r
*******************************************************************************/\r
package org.simantics.sysdyn.ui.validation;\r
\r
import org.simantics.sysdyn.representation.IndependentVariable;\r
import org.simantics.sysdyn.representation.expressions.IExpression;\r
import org.simantics.sysdyn.representation.utils.UnitUtils;\r
+import org.simantics.sysdyn.utils.ModelUtils;\r
\r
public class UnitFunction {\r
\r
if(configuration == null)\r
return Collections.emptyList();\r
\r
+ SysdynModel model = ModelUtils.getModel(graph, module);\r
String result = null;\r
ArrayList<Issue> issues = new ArrayList<Issue>();\r
for(Resource outputRelation : graph.getObjects(module, SR.Variable_isTailOf)) {\r
continue;\r
String left = graph.getPossibleRelatedValue(output, SR.Variable_unit);\r
String right = graph.getPossibleRelatedValue(reference, SR.Variable_unit);\r
- result = UnitUtils.matchUnits(left, right);\r
+ result = UnitUtils.matchUnits(left, right, UnitUtils.allowEquivalents(graph, model));\r
if(result != null)\r
issues.add(new ModuleStandardIssue(SR.Validations_ModuleOutputUnitWarning, module, output, reference));\r
}\r
continue;\r
String left = graph.getPossibleRelatedValue(variable, SR.Variable_unit);\r
String right = graph.getPossibleRelatedValue(reference, SR.Variable_unit);\r
- result = UnitUtils.matchUnits(left, right);\r
+ result = UnitUtils.matchUnits(left, right, UnitUtils.allowEquivalents(graph, model));\r
if(result != null)\r
issues.add(new ModuleStandardIssue(SR.Validations_ModuleInputUnitWarning, module, variable, reference));\r
}\r
if(right == null || right.isEmpty())\r
return "No unit defined for " + NameUtils.getSafeName(graph, rightResource);\r
\r
- String result = UnitUtils.matchUnits(left, right);\r
+ SysdynModel model = ModelUtils.getModel(graph, leftResource);\r
+ String result = UnitUtils.matchUnits(left, right, UnitUtils.allowEquivalents(graph, model));\r
\r
if(result != null)\r
result = prefix + result + suffix;\r
/*******************************************************************************\r
- * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * Copyright (c) 2013-2014 Association for Decentralized Information Management in\r
* Industry THTH ry.\r
* All rights reserved. This program and the accompanying materials\r
* are made available under the terms of the Eclipse Public License v1.0\r
*\r
* Contributors:\r
* Semantum Oy - initial API and implementation\r
+ * VTT Technical Research Centre of Finland\r
*******************************************************************************/\r
package org.simantics.sysdyn;\r
\r
public static void main(String[] args) {\r
\r
HashMap<String, String> units = new HashMap<String, String>();\r
- \r
- doScenario(scenario1(units), units);\r
- doScenario(scenario2(units), units);\r
- doScenario(scenario3(units), units);\r
- doScenario(scenario4(units), units);\r
- doScenario(scenario5(units), units);\r
- doScenario(scenario6(units), units);\r
- doScenario(scenario7(units), units);\r
- doScenario(scenario8(units), units);\r
- doScenario(scenario9(units), units);\r
- doScenario(scenario10(units), units);\r
- doScenario(scenario11(units), units);\r
- doScenario(scenario12(units), units);\r
- doScenario(scenario13(units), units);\r
+ boolean allowEquivalents = true;\r
+ \r
+ doScenario(scenario1(units), units, allowEquivalents);\r
+ doScenario(scenario2(units), units, allowEquivalents);\r
+ doScenario(scenario3(units), units, allowEquivalents);\r
+ doScenario(scenario4(units), units, allowEquivalents);\r
+ doScenario(scenario5(units), units, allowEquivalents);\r
+ doScenario(scenario6(units), units, allowEquivalents);\r
+ doScenario(scenario7(units), units, allowEquivalents);\r
+ doScenario(scenario8(units), units, allowEquivalents);\r
+ doScenario(scenario9(units), units, allowEquivalents);\r
+ doScenario(scenario10(units), units, allowEquivalents);\r
+ doScenario(scenario11(units), units, allowEquivalents);\r
+ doScenario(scenario12(units), units, allowEquivalents);\r
+ doScenario(scenario13(units), units, allowEquivalents);\r
\r
}\r
\r
- private static void doScenario(String expression, HashMap<String, String> units) {\r
+ private static void doScenario(String expression, HashMap<String, String> units, boolean allowEquivalents) {\r
System.out.println("-----------------------------------");\r
System.out.println("Expression: " + expression);\r
System.out.println("Units: ");\r
UnitCheckingNode node = (UnitCheckingNode) parser.expr();\r
\r
try {\r
- UnitResult u = node.getUnits(units);\r
+ UnitResult u = node.getUnits(units, allowEquivalents);\r
System.out.println("Result: " + u.getCleanFullUnit());\r
} catch (UnitCheckingException e) {\r
e.printStackTrace();\r
/*******************************************************************************\r
- * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * Copyright (c) 2013-2014 Association for Decentralized Information Management in\r
* Industry THTH ry.\r
* All rights reserved. This program and the accompanying materials\r
* are made available under the terms of the Eclipse Public License v1.0\r
*\r
* Contributors:\r
* Semantum Oy - initial API and implementation\r
+ * VTT Technical Research Centre of Finland\r
*******************************************************************************/\r
package org.simantics.sysdyn.representation.utils;\r
\r
import java.util.HashSet;\r
import java.util.Set;\r
\r
+import org.simantics.databoard.Bindings;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.PossibleObjectWithType;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;\r
import org.simantics.db.exception.ServiceException;\r
import org.simantics.db.layer0.request.PossibleModel;\r
+import org.simantics.operation.Layer0X;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.manager.SysdynModel;\r
import org.simantics.sysdyn.representation.Configuration;\r
HashMap<String, String> units = UnitUtils.findUnits(graph, model, configuration, components);\r
\r
try {\r
- node.getUnits(units);\r
+ node.getUnits(units, allowEquivalents(graph, model));\r
} catch (UnitCheckingException e) {\r
return e.getMessage();\r
- }\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
\r
} catch (ParseException e) {\r
e.printStackTrace();\r
return null;\r
}\r
\r
+ /**\r
+ * Determine if the Unit Equivalents checkbox is selected \r
+ * @param graph\r
+ * @param model SysdynModel of which configuration is queried\r
+ * @return true iff equivalent units are allowed\r
+ * @throws DatabaseException\r
+ */\r
+ public static boolean allowEquivalents(ReadGraph graph, SysdynModel model) throws DatabaseException {\r
+ Resource modelResource = graph.syncRequest(new PossibleModel(model.getConfigurationResource()));\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Resource unitIssueSource = graph.syncRequest(\r
+ new PossibleObjectWithType(modelResource, \r
+ Layer0X.getInstance(graph).Activates, \r
+ sr.Validations_Units_UnitIssueSource));\r
+ if(unitIssueSource == null)\r
+ return false;\r
+ \r
+ Boolean result = graph.getPossibleRelatedValue(unitIssueSource, sr.Validations_Units_UnitIssueSource_allowEquivalents, Bindings.BOOLEAN);\r
+ if(result == null)\r
+ result = false;\r
+ \r
+ return result;\r
+ }\r
+ \r
public static String matchUnits(ReadGraph graph, SysdynModel model, Configuration configuration, String unit, String expression) {\r
if(unit == null)\r
return "Unit not defined";\r
leftReader.close();\r
\r
try {\r
- UnitResult rightUnits = right.getUnits(units);\r
- UnitResult leftUnits = left.getUnits(null);\r
+ boolean allowEquivalents = allowEquivalents(graph, model);\r
+ UnitResult rightUnits = right.getUnits(units, allowEquivalents);\r
+ UnitResult leftUnits = left.getUnits(null, allowEquivalents);\r
\r
if(!rightUnits.equals(leftUnits))\r
return leftUnits.getCleanFullUnit() + " != " + rightUnits.getCleanFullUnit();\r
} catch (UnitCheckingException e) {\r
return e.getMessage();\r
- }\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
\r
} catch (ParseException e) {\r
e.printStackTrace();\r
}\r
\r
\r
- public static String matchUnits(String left, String right) throws DatabaseException {\r
+ public static String matchUnits(String left, String right, boolean allowEquivalents) throws DatabaseException {\r
if(left == null || right == null || left.isEmpty() || right.isEmpty())\r
return "No unit defined";\r
\r
rightReader.close();\r
\r
try {\r
- UnitResult leftUnits = leftNode.getUnits(null);\r
- UnitResult rightUnits = rightNode.getUnits(null);\r
+ UnitResult leftUnits = leftNode.getUnits(null, allowEquivalents);\r
+ UnitResult rightUnits = rightNode.getUnits(null, allowEquivalents);\r
\r
if(!rightUnits.equals(leftUnits))\r
return leftUnits.getCleanFullUnit() + " != " + rightUnits.getCleanFullUnit();\r
/*******************************************************************************\r
- * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * Copyright (c) 2013-2014 Association for Decentralized Information Management in\r
* Industry THTH ry.\r
* All rights reserved. This program and the accompanying materials\r
* are made available under the terms of the Eclipse Public License v1.0\r
*\r
* Contributors:\r
* Semantum Oy - initial API and implementation\r
+ * VTT Technical Research Centre of Finland\r
*******************************************************************************/\r
package org.simantics.sysdyn.unitParser;\r
\r
super(id);\r
}\r
\r
- public UnitResult getUnits(HashMap<String, String> units) throws UnitCheckingException{\r
- UnitResult result = new UnitResult();\r
+ public UnitResult getUnits(HashMap<String, String> units, boolean allowEquivalents) throws UnitCheckingException{\r
+ UnitResult result = new UnitResult(allowEquivalents);\r
\r
if(jjtGetNumChildren() == 0){\r
String node = printNode();\r
result.append(node);\r
} else {\r
for(int i = 0; i < jjtGetNumChildren(); i++) {\r
- result.appendResult(((UnitCheckingNode)jjtGetChild(i)).getUnits(units));\r
+ result.appendResult(((UnitCheckingNode)jjtGetChild(i)).getUnits(units, allowEquivalents));\r
}\r
}\r
return result; \r
| "*" | "/" | ".*" | "./"\r
| "^" | ".^"\r
| "=" | ":=" \r
-| <IDENT: ["a"-"z","A"-"Z","_","\u20ac"] (["a"-"z","A"-"Z","_","\u20ac","0"-"9"])* >\r
+| <IDENT: ["a"-"z","A"-"Z","_","\u20ac","$","£","%","\u0391"-"\u03c9","µ"] (["a"-"z","A"-"Z","_","\u20ac","$","£","%","\u0391"-"\u03c9","µ","0"-"9"])* >\r
| <STRING: "\"" (~["\"", "\\", "\n"] | "\\" ~["\n"])* "\"">\r
{ matchedToken.image = matchedToken.image.substring(1,matchedToken.image.length()-1); }\r
| <UNSIGNED_INTEGER: (["0"-"9"])+ >\r
/*******************************************************************************\r
- * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * Copyright (c) 2013-2014 Association for Decentralized Information Management in\r
* Industry THTH ry.\r
* All rights reserved. This program and the accompanying materials\r
* are made available under the terms of the Eclipse Public License v1.0\r
*\r
* Contributors:\r
* Semantum Oy - initial API and implementation\r
+ * VTT Technical Research Centre of Finland\r
*******************************************************************************/\r
package org.simantics.sysdyn.unitParser.nodes;\r
\r
/**\r
* See UnitCheckingNodeFactory for mapping\r
* @author Teemu Lempinen\r
+ * @author Tuomas Miettinen\r
*\r
*/\r
public class AddOp extends UnitCheckingNode {\r
}\r
\r
@Override\r
- public UnitResult getUnits(HashMap<String, String> units) throws UnitCheckingException {\r
- UnitResult result = super.getUnits(units);\r
+ public UnitResult getUnits(HashMap<String, String> units, boolean allowEquivalents) throws UnitCheckingException {\r
+ UnitResult result = super.getUnits(units, allowEquivalents);\r
result.setUnitType(UnitType.OPERATOR);\r
return result;\r
}\r
/*******************************************************************************\r
- * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * Copyright (c) 2013-2014 Association for Decentralized Information Management in\r
* Industry THTH ry.\r
* All rights reserved. This program and the accompanying materials\r
* are made available under the terms of the Eclipse Public License v1.0\r
*\r
* Contributors:\r
* Semantum Oy - initial API and implementation\r
+ * VTT Technical Research Centre of Finland\r
*******************************************************************************/\r
package org.simantics.sysdyn.unitParser.nodes;\r
\r
/**\r
* See UnitCheckingNodeFactory for mapping\r
* @author Teemu Lempinen\r
+ * @author Tuomas Miettinen\r
*\r
*/\r
public class Arithmetic extends UnitCheckingNode {\r
\r
\r
@Override\r
- public UnitResult getUnits(HashMap<String, String> units) throws UnitCheckingException {\r
- UnitResult result = new UnitResult();\r
+ public UnitResult getUnits(HashMap<String, String> units, boolean allowEquivalents) throws UnitCheckingException {\r
+ UnitResult result = new UnitResult(allowEquivalents);\r
\r
UnitCheckingNode base = null;\r
UnitCheckingNode operator = null;\r
\r
for(int i = 0; i < jjtGetNumChildren(); i++) {\r
candidateNode = ((UnitCheckingNode)jjtGetChild(i));\r
- UnitResult candidateUnits = candidateNode.getUnits(units);\r
+ UnitResult candidateUnits = candidateNode.getUnits(units, allowEquivalents);\r
if(candidateUnits.getUnitType() == UnitType.OPERATOR) {\r
continue;\r
} else if(base == null || result.getUnitType() == UnitType.SCALAR || result.getUnitType() == UnitType.ANY) {\r
base = ((UnitCheckingNode)jjtGetChild(i));\r
- result.appendResult(base.getUnits(units));\r
+ result.appendResult(base.getUnits(units, allowEquivalents));\r
continue;\r
} else if(candidateUnits.getUnitType() == UnitType.SCALAR) {\r
continue;\r
/*******************************************************************************\r
- * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * Copyright (c) 2013-2014 Association for Decentralized Information Management in\r
* Industry THTH ry.\r
* All rights reserved. This program and the accompanying materials\r
* are made available under the terms of the Eclipse Public License v1.0\r
*\r
* Contributors:\r
* Semantum Oy - initial API and implementation\r
+ * VTT Technical Research Centre of Finland\r
*******************************************************************************/\r
package org.simantics.sysdyn.unitParser.nodes;\r
\r
/**\r
* See UnitCheckingNodeFactory for mapping\r
* @author Teemu Lempinen\r
+ * @author Tuomas Miettinen\r
*\r
*/\r
public class ArrayDefinition extends UnitCheckingNode {\r
\r
\r
@Override\r
- public UnitResult getUnits(HashMap<String, String> units) throws UnitCheckingException {\r
- UnitResult result = new UnitResult();\r
+ public UnitResult getUnits(HashMap<String, String> units, boolean allowEquivalents) throws UnitCheckingException {\r
+ UnitResult result = new UnitResult(allowEquivalents);\r
result.setUnitType(UnitType.SCALAR);\r
\r
UnitCheckingNode base = null;\r
FunctionArguments functionArguments = (FunctionArguments) jjtGetChild(0);\r
\r
for(UnitCheckingNode candidateNode : gatherExpressions(functionArguments, new ArrayList<UnitCheckingNode>())) {\r
- UnitResult candidateUnits = candidateNode.getUnits(units);\r
+ UnitResult candidateUnits = candidateNode.getUnits(units, allowEquivalents);\r
if(candidateUnits.getUnitType() == UnitType.SCALAR) {\r
continue;\r
} else if(base == null) {\r
base = candidateNode;\r
UnitType oldUnitType = result.getUnitType();\r
- result.appendResult(base.getUnits(units));\r
+ result.appendResult(base.getUnits(units, allowEquivalents));\r
\r
/*\r
* Make sure unit type persist\r
/*******************************************************************************\r
- * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * Copyright (c) 2013-2014 Association for Decentralized Information Management in\r
* Industry THTH ry.\r
* All rights reserved. This program and the accompanying materials\r
* are made available under the terms of the Eclipse Public License v1.0\r
*\r
* Contributors:\r
* Semantum Oy - initial API and implementation\r
+ * VTT Technical Research Centre of Finland\r
*******************************************************************************/\r
package org.simantics.sysdyn.unitParser.nodes;\r
\r
/**\r
* See UnitCheckingNodeFactory for mapping\r
* @author Teemu Lempinen\r
+ * @author Tuomas Miettinen\r
*\r
*/\r
public class ComponentReferenceFull extends UnitCheckingNode {\r
super(id);\r
}\r
\r
- protected UnitResult parseUnits(String units) {\r
+ protected UnitResult parseUnits(String units, boolean allowEquivalents) {\r
StringReader sr = new StringReader(units);\r
UnitParser parser = new UnitParser(sr);\r
try {\r
UnitCheckingNode node = (UnitCheckingNode) parser.expr();\r
- return node.getUnits(null);\r
+ return node.getUnits(null, allowEquivalents);\r
} catch (ParseException e) {\r
e.printStackTrace();\r
} catch (UnitCheckingException e) {\r
}\r
\r
@Override\r
- public UnitResult getUnits(HashMap<String, String> units) throws UnitCheckingException {\r
+ public UnitResult getUnits(HashMap<String, String> units, boolean allowEquivalents) throws UnitCheckingException {\r
String node = printNode();\r
\r
if("dmnl".equals(node)) {\r
- UnitResult result = new UnitResult();\r
+ UnitResult result = new UnitResult(allowEquivalents);\r
result.setUnitType(UnitType.DMNL);\r
return result;\r
}\r
if(!units.containsKey(node) || units.get(node) == null)\r
throw new UnitCheckingException("No units defined for " + node);\r
else {\r
- return parseUnits(units.get(node));\r
+ return parseUnits(units.get(node), allowEquivalents);\r
}\r
} else {\r
- UnitResult result = new UnitResult();\r
+ UnitResult result = new UnitResult(allowEquivalents);\r
result.addDivident(node);\r
result.append(node);\r
return result; \r
/*******************************************************************************\r
- * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * Copyright (c) 2013-2014 Association for Decentralized Information Management in\r
* Industry THTH ry.\r
* All rights reserved. This program and the accompanying materials\r
* are made available under the terms of the Eclipse Public License v1.0\r
*\r
* Contributors:\r
* Semantum Oy - initial API and implementation\r
+ * VTT Technical Research Centre of Finland\r
*******************************************************************************/\r
package org.simantics.sysdyn.unitParser.nodes;\r
\r
/**\r
* See UnitCheckingNodeFactory for mapping\r
* @author Teemu Lempinen\r
+ * @author Tuomas Miettinen\r
*\r
*/\r
public class Divide extends UnitCheckingNode {\r
}\r
\r
@Override\r
- public UnitResult getUnits(HashMap<String, String> units) throws UnitCheckingException {\r
- UnitResult result = super.getUnits(units);\r
+ public UnitResult getUnits(HashMap<String, String> units, boolean allowEquivalents) throws UnitCheckingException {\r
+ UnitResult result = super.getUnits(units, allowEquivalents);\r
result.setUnitType(UnitType.OPERATOR);\r
return result;\r
}\r
*\r
* Contributors:\r
* Semantum Oy - initial API and implementation\r
+ * VTT Technical Research Centre of Finland\r
*******************************************************************************/\r
package org.simantics.sysdyn.unitParser.nodes;\r
\r
}\r
\r
@Override\r
- public UnitResult getUnits(HashMap<String, String> units) throws UnitCheckingException {\r
- UnitResult result = new UnitResult();\r
+ public UnitResult getUnits(HashMap<String, String> units, boolean allowEquivalents) throws UnitCheckingException {\r
+ UnitResult result = new UnitResult(allowEquivalents);\r
\r
UnitCheckingNode current = null;\r
UnitCheckingNode operator = null;\r
\r
for(int i = 0; i < jjtGetNumChildren(); i++) {\r
current = ((UnitCheckingNode)jjtGetChild(i));\r
- UnitResult currentUnits = current.getUnits(units);\r
+ UnitResult currentUnits = current.getUnits(units, allowEquivalents);\r
\r
if(currentUnits.getUnitType() == UnitType.ANY) {\r
- result = new UnitResult();\r
+ result = new UnitResult(allowEquivalents);\r
result.setUnitType(UnitType.ANY);\r
return result;\r
} else if(currentUnits.getUnitType() == UnitType.OPERATOR) {\r
UnitType unitType = currentUnits.getUnitType();\r
if(unitType == UnitType.SCALAR) {\r
int exponent;\r
- UnitResult baseUnits = base.getUnits(units);\r
+ UnitResult baseUnits = base.getUnits(units, allowEquivalents);\r
try {\r
exponent = Integer.valueOf(currentUnits.getFullUnit());\r
} catch (NumberFormatException e) {\r
/*******************************************************************************\r
- * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * Copyright (c) 2013-2014 Association for Decentralized Information Management in\r
* Industry THTH ry.\r
* All rights reserved. This program and the accompanying materials\r
* are made available under the terms of the Eclipse Public License v1.0\r
*\r
* Contributors:\r
* Semantum Oy - initial API and implementation\r
+ * VTT Technical Research Centre of Finland\r
*******************************************************************************/\r
package org.simantics.sysdyn.unitParser.nodes;\r
\r
/**\r
* See UnitCheckingNodeFactory for mapping\r
* @author Teemu Lempinen\r
+ * @author Tuomas Miettinen\r
*\r
*/\r
public class ForIndex extends UnitCheckingNode {\r
}\r
\r
@Override\r
- public UnitResult getUnits(HashMap<String, String> units) throws UnitCheckingException {\r
- return new UnitResult();\r
+ public UnitResult getUnits(HashMap<String, String> units, boolean allowEquivalents) throws UnitCheckingException {\r
+ return new UnitResult(allowEquivalents);\r
}\r
\r
}\r
/*******************************************************************************\r
- * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * Copyright (c) 2013-2014 Association for Decentralized Information Management in\r
* Industry THTH ry.\r
* All rights reserved. This program and the accompanying materials\r
* are made available under the terms of the Eclipse Public License v1.0\r
*\r
* Contributors:\r
* Semantum Oy - initial API and implementation\r
+ * VTT Technical Research Centre of Finland\r
*******************************************************************************/\r
package org.simantics.sysdyn.unitParser.nodes;\r
\r
/**\r
* See UnitCheckingNodeFactory for mapping\r
* @author Teemu Lempinen\r
+ * @author Tuomas Miettinen\r
*\r
*/\r
public class FunctionCall extends UnitCheckingNode {\r
}\r
\r
@Override\r
- public UnitResult getUnits(HashMap<String, String> units) throws UnitCheckingException {\r
- UnitResult result = new UnitResult();\r
+ public UnitResult getUnits(HashMap<String, String> units, boolean allowEquivalents) throws UnitCheckingException {\r
+ UnitResult result = new UnitResult(allowEquivalents);\r
result.setUnitType(UnitType.ANY);\r
return result;\r
}\r
/*******************************************************************************\r
- * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * Copyright (c) 2013-2014 Association for Decentralized Information Management in\r
* Industry THTH ry.\r
* All rights reserved. This program and the accompanying materials\r
* are made available under the terms of the Eclipse Public License v1.0\r
*\r
* Contributors:\r
* Semantum Oy - initial API and implementation\r
+ * VTT Technical Research Centre of Finland\r
*******************************************************************************/\r
package org.simantics.sysdyn.unitParser.nodes;\r
\r
/**\r
* See UnitCheckingNodeFactory for mapping\r
* @author Teemu Lempinen\r
+ * @author Tuomas Miettinen\r
*\r
*/\r
public class IfThenElse extends UnitCheckingNode {\r
\r
\r
@Override\r
- public UnitResult getUnits(HashMap<String, String> units) throws UnitCheckingException {\r
+ public UnitResult getUnits(HashMap<String, String> units, boolean allowEquivalents) throws UnitCheckingException {\r
UnitResult base = null;\r
UnitCheckingNode baseNode = null;\r
UnitCheckingNode candidateNode = null;\r
\r
for(int i = 0; i < jjtGetNumChildren(); i++) {\r
candidateNode = ((UnitCheckingNode)jjtGetChild(i));\r
- UnitResult candidateUnits = candidateNode.getUnits(units);\r
+ UnitResult candidateUnits = candidateNode.getUnits(units, allowEquivalents);\r
\r
if(!(candidateNode instanceof Condition)) {\r
\r
/*******************************************************************************\r
- * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * Copyright (c) 2013-2014 Association for Decentralized Information Management in\r
* Industry THTH ry.\r
* All rights reserved. This program and the accompanying materials\r
* are made available under the terms of the Eclipse Public License v1.0\r
*\r
* Contributors:\r
* Semantum Oy - initial API and implementation\r
+ * VTT Technical Research Centre of Finland\r
*******************************************************************************/\r
package org.simantics.sysdyn.unitParser.nodes;\r
\r
/**\r
* See UnitCheckingNodeFactory for mapping\r
* @author Teemu Lempinen\r
+ * @author Tuomas Miettinen\r
*\r
*/\r
public class Multiplication extends UnitCheckingNode {\r
}\r
\r
@Override\r
- public UnitResult getUnits(HashMap<String, String> units) throws UnitCheckingException {\r
- UnitResult result = super.getUnits(units);\r
+ public UnitResult getUnits(HashMap<String, String> units, boolean allowEquivalents) throws UnitCheckingException {\r
+ UnitResult result = super.getUnits(units, allowEquivalents);\r
result.setUnitType(UnitType.OPERATOR);\r
return result;\r
}\r
}\r
\r
@Override\r
- public UnitResult getUnits(HashMap<String, String> units) throws UnitCheckingException {\r
- UnitResult result = super.getUnits(units);\r
+ public UnitResult getUnits(HashMap<String, String> units, boolean allowEquivalents) throws UnitCheckingException {\r
+ UnitResult result = super.getUnits(units, allowEquivalents);\r
result.setUnitType(UnitType.OPERATOR);\r
return result;\r
}\r
/*******************************************************************************\r
- * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * Copyright (c) 2013-2014 Association for Decentralized Information Management in\r
* Industry THTH ry.\r
* All rights reserved. This program and the accompanying materials\r
* are made available under the terms of the Eclipse Public License v1.0\r
*\r
* Contributors:\r
* Semantum Oy - initial API and implementation\r
+ * VTT Technical Research Centre of Finland\r
*******************************************************************************/\r
package org.simantics.sysdyn.unitParser.nodes;\r
\r
/**\r
* See UnitCheckingNodeFactory for mapping\r
* @author Teemu Lempinen\r
+ * @author Tuomas Miettinen\r
*\r
*/\r
public class RelOp extends UnitCheckingNode {\r
}\r
\r
@Override\r
- public UnitResult getUnits(HashMap<String, String> units) throws UnitCheckingException {\r
- UnitResult result = super.getUnits(units);\r
+ public UnitResult getUnits(HashMap<String, String> units, boolean allowEquivalents) throws UnitCheckingException {\r
+ UnitResult result = super.getUnits(units, allowEquivalents);\r
result.setUnitType(UnitType.OPERATOR);\r
return result;\r
}\r
/*******************************************************************************\r
- * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * Copyright (c) 2013-2014 Association for Decentralized Information Management in\r
* Industry THTH ry.\r
* All rights reserved. This program and the accompanying materials\r
* are made available under the terms of the Eclipse Public License v1.0\r
*\r
* Contributors:\r
* Semantum Oy - initial API and implementation\r
+ * VTT Technical Research Centre of Finland\r
*******************************************************************************/\r
package org.simantics.sysdyn.unitParser.nodes;\r
\r
/**\r
* See UnitCheckingNodeFactory for mapping\r
* @author Teemu Lempinen\r
+ * @author Tuomas Miettinen\r
*\r
*/\r
public class Relation extends UnitCheckingNode {\r
}\r
\r
@Override\r
- public UnitResult getUnits(HashMap<String, String> units) throws UnitCheckingException {\r
- UnitResult result = new UnitResult();\r
+ public UnitResult getUnits(HashMap<String, String> units, boolean allowEquivalents) throws UnitCheckingException {\r
+ UnitResult result = new UnitResult(allowEquivalents);\r
\r
UnitCheckingNode base = null;\r
UnitCheckingNode operator = null;\r
base = ((UnitCheckingNode)jjtGetChild(1));\r
\r
if(base instanceof Arithmetic) {\r
- result.appendResult(base.getUnits(units));\r
+ result.appendResult(base.getUnits(units, allowEquivalents));\r
\r
for(int i = 2; i < jjtGetNumChildren(); i = i + 2) {\r
candidateNode = ((UnitCheckingNode)jjtGetChild(i));\r
\r
if(!(candidateNode instanceof Value)) {\r
operator = ((UnitCheckingNode)jjtGetChild(i-1));\r
- UnitResult candidateUnits = candidateNode.getUnits(units);\r
+ UnitResult candidateUnits = candidateNode.getUnits(units, allowEquivalents);\r
if(!result.equals(candidateUnits)) {\r
result.equals(candidateUnits);\r
throw new UnitCheckingException("Not equals exception: " +\r
/*******************************************************************************\r
- * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * Copyright (c) 2013-2014 Association for Decentralized Information Management in\r
* Industry THTH ry.\r
* All rights reserved. This program and the accompanying materials\r
* are made available under the terms of the Eclipse Public License v1.0\r
*\r
* Contributors:\r
* Semantum Oy - initial API and implementation\r
+ * VTT Technical Research Centre of Finland\r
*******************************************************************************/\r
package org.simantics.sysdyn.unitParser.nodes;\r
\r
/**\r
* See UnitCheckingNodeFactory for mapping\r
* @author Teemu Lempinen\r
+ * @author Tuomas Miettinen\r
*\r
*/\r
public class Term extends UnitCheckingNode {\r
}\r
\r
@Override\r
- public UnitResult getUnits(HashMap<String, String> units) throws UnitCheckingException {\r
- UnitResult result = new UnitResult();\r
+ public UnitResult getUnits(HashMap<String, String> units, boolean allowEquivalents) throws UnitCheckingException {\r
+ UnitResult result = new UnitResult(allowEquivalents);\r
\r
UnitCheckingNode current = null;\r
UnitCheckingNode operator = null;\r
\r
for(int i = 0; i < jjtGetNumChildren(); i++) {\r
current = ((UnitCheckingNode)jjtGetChild(i));\r
- UnitResult currentUnits = current.getUnits(units);\r
+ UnitResult currentUnits = current.getUnits(units, allowEquivalents);\r
\r
if(currentUnits.getUnitType() == UnitType.ANY) {\r
- result = new UnitResult();\r
+ result = new UnitResult(allowEquivalents);\r
result.setUnitType(UnitType.ANY);\r
return result;\r
} else if(currentUnits.getUnitType() == UnitType.OPERATOR) {\r
* clean representation of the unit. ( e.g. m * s / m -> s )\r
* \r
* @author Teemu Lempinen\r
+ * @author Tuomas Miettinen\r
*\r
*/\r
public class UnitResult {\r
private StringBuilder fullUnit = new StringBuilder();\r
private UnitType unitType;\r
\r
- public UnitResult() {\r
+ // Equivalent forms of units:\r
+ private final Equivalent[] EQUIVALENTS = {\r
+ new Equivalent("$","$s","dollar","dollars","usd"),\r
+ new Equivalent("\u20ac","\u20acs","eur","euro","euros","e","ecu"),\r
+ new Equivalent("£","£s","pound","pounds","gbp"),\r
+ new Equivalent("Unit","Units"),\r
+ new Equivalent("Person","People","Persons"),\r
+ new Equivalent("second","seconds","sec","s"),\r
+ new Equivalent("minute","minutes","min"),\r
+ new Equivalent("hour","hours","h","hr"),\r
+ new Equivalent("day","days","d"),\r
+ new Equivalent("month","months","mon","mth","mo","mos"),\r
+ new Equivalent("year","years","a","y","yr")\r
+ };\r
+ private boolean allowEquivalents;\r
+ \r
+ private class Equivalent {\r
+ public ArrayList<String> forms;\r
+ \r
+ Equivalent(String ... forms) {\r
+ this.forms = new ArrayList<String>();\r
+ for (String f : forms)\r
+ this.forms.add(f);\r
+ }\r
+ \r
+ public boolean contains(String form) {\r
+ for (String f : forms)\r
+ if (f.equalsIgnoreCase(form))\r
+ return true;\r
+ return false;\r
+ }\r
+ \r
+ public String getDefault() {\r
+ if (forms.size() > 0)\r
+ return forms.get(0);\r
+ else return null;\r
+ }\r
+ }\r
+ \r
+ public UnitResult(boolean allowEquivalents) {\r
+ this.allowEquivalents = allowEquivalents;\r
setUnitType(UnitType.NORMAL);\r
}\r
\r
if(copyDividers1.size() != copyDividers2.size())\r
return false;\r
\r
+ if (allowEquivalents) {\r
+ // Replace and sort all once again.\r
+ for(int i = 0; i < copyDividents1.size(); i++) {\r
+ copyDividents1.set(i, getDefaultForm(copyDividents1.get(i)));\r
+ copyDividents2.set(i, getDefaultForm(copyDividents2.get(i)));\r
+ Collections.sort(copyDividents1);\r
+ Collections.sort(copyDividents2);\r
+ }\r
+ for(int i = 0; i < copyDividers1.size(); i++) {\r
+ copyDividers1.set(i, getDefaultForm(copyDividers1.get(i)));\r
+ copyDividers2.set(i, getDefaultForm(copyDividers2.get(i)));\r
+ Collections.sort(copyDividers1);\r
+ Collections.sort(copyDividers2);\r
+ }\r
+ }\r
+ \r
for(int i = 0; i < copyDividents1.size(); i++) {\r
String a = copyDividents1.get(i);\r
String b = copyDividents2.get(i);\r
return false;\r
}\r
}\r
- \r
for(int i = 0; i < copyDividers1.size(); i++) {\r
String a = copyDividers1.get(i);\r
String b = copyDividers2.get(i);\r
return true;\r
}\r
\r
- public void reduceUnitLists(ArrayList<String> originalDividents, ArrayList<String> copyDividents, ArrayList<String> copyDividers) {\r
+ /**\r
+ * Get the default form of a unit (e.g. dollars -> $).\r
+ * @param unit\r
+ * @return default form of unit\r
+ */\r
+ private String getDefaultForm(String unit) {\r
+ for (Equivalent e : EQUIVALENTS)\r
+ if (e.contains(unit))\r
+ return e.getDefault();\r
+ return unit;\r
+ }\r
+\r
+ public void reduceUnitLists(ArrayList<String> originalDividents, ArrayList<String> copyDividents, ArrayList<String> copyDividers) {\r
for(String s : originalDividents) {\r
if(copyDividers.contains(s)) {\r
copyDividers.remove(s);\r
/*******************************************************************************\r
- * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * Copyright (c) 2013-2014 Association for Decentralized Information Management in\r
* Industry THTH ry.\r
* All rights reserved. This program and the accompanying materials\r
* are made available under the terms of the Eclipse Public License v1.0\r
*\r
* Contributors:\r
* Semantum Oy - initial API and implementation\r
+ * VTT Technical Research Centre of Finland\r
*******************************************************************************/\r
package org.simantics.sysdyn.unitParser.nodes;\r
\r
/**\r
* See UnitCheckingNodeFactory for mapping\r
* @author Teemu Lempinen\r
+ * @author Tuomas Miettinen\r
*\r
*/\r
public class Value extends UnitCheckingNode {\r
}\r
\r
@Override\r
- public UnitResult getUnits(HashMap<String, String> units) throws UnitCheckingException {\r
- UnitResult result = super.getUnits(units);\r
+ public UnitResult getUnits(HashMap<String, String> units, boolean allowEquivalents) throws UnitCheckingException {\r
+ UnitResult result = super.getUnits(units, allowEquivalents);\r
result.setUnitType(UnitType.SCALAR);\r
return result;\r
}\r