1 /*******************************************************************************
\r
2 * Copyright (c) 2010, 2012 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.sysdyn.representation.expressions;
\r
14 import org.simantics.db.ReadGraph;
\r
15 import org.simantics.objmap.annotations.GraphType;
\r
16 import org.simantics.objmap.annotations.RelatedValue;
\r
17 import org.simantics.sysdyn.SysdynResource;
\r
18 import org.simantics.sysdyn.manager.SysdynModel;
\r
19 import org.simantics.sysdyn.representation.utils.FormatUtils;
\r
20 import org.simantics.sysdyn.representation.utils.IndexUtils;
\r
21 import org.simantics.sysdyn.representation.utils.SheetFormatUtils;
\r
22 import org.simantics.sysdyn.representation.utils.UnitUtils;
\r
25 * Representation of a withlookup expression
\r
27 * @author Teemu Lempinen
\r
30 @GraphType(SysdynResource.URIs.WithLookupExpression)
\r
31 public class WithLookupExpression extends Expression {
\r
33 @RelatedValue(SysdynResource.URIs.WithLookupExpression_lookup)
\r
34 private String lookupTable;
\r
35 @RelatedValue(SysdynResource.URIs.WithLookupExpression_expression)
\r
36 private String equation;
\r
39 public String getEquation() {
\r
40 String equation = FormatUtils.formatExpressionForModelica(parent, this.equation);
\r
41 String range = IndexUtils.rangeToIndexes(parent, this.getArrayRange());
\r
44 " " + parent.getName() + (range.equals("[:]") ? "" : range) + " = interpolate(" + equation + ", " + SheetFormatUtils.reformatSheetReferences(parent, lookupTable) + ");\n";
\r
48 public String getExpression() {
\r
49 return "interpolate(" + equation + ", " + lookupTable + ")";
\r
53 public String validateUnits(ReadGraph graph, SysdynModel model) {
\r
54 if(parent.getUnit() == null)
\r
55 return "Unit not defined for " + parent.getName();
\r
57 String result = UnitUtils.expressionUnitsValid(graph, model, parent.getParentConfiguration(), equation);
\r
58 if(result == null) {
\r
59 result = UnitUtils.matchUnits(graph, model, parent.getParentConfiguration(), parent.getUnit(), lookupTable);
\r