SYSDYN.HasEquation <R L0.HasProperty
L0.HasRange L0.String
+
+SYSDYN.HasEquationOrEmpty <R SYSDYN.HasEquation
+ L0.HasRange L0.String
SYSDYN.HasInitialEquation <R SYSDYN.HasEquation
L0.HasRange L0.String
>-- SYSDYN.DelayExpression.expression --> L0.String <R SYSDYN.HasEquation
>-- SYSDYN.DelayExpression.order --> L0.Integer <R SYSDYN.HasEquation
>-- SYSDYN.DelayExpression.delayTime --> L0.String <R SYSDYN.HasEquation
- >-- SYSDYN.DelayExpression.initialValue --> L0.String <R SYSDYN.HasEquation
+ >-- SYSDYN.DelayExpression.initialValue --> L0.String <R SYSDYN.HasEquationOrEmpty
SYSDYN.StockExpression <T SYSDYN.Expression
@L0.singleProperty SYSDYN.HasInitialEquation
public final Resource HasEnumerationIndexes;\r
public final Resource HasEnumerationIndexes_Inverse;\r
public final Resource HasEquation;\r
+ public final Resource HasEquationOrEmpty;\r
+ public final Resource HasEquationOrEmpty_Inverse;\r
public final Resource HasEquation_Inverse;\r
public final Resource HasExpressions;\r
public final Resource HasExpressions_Inverse;\r
public static final String HasEnumerationIndexes = "http://www.simantics.org/Sysdyn-1.1/HasEnumerationIndexes";\r
public static final String HasEnumerationIndexes_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasEnumerationIndexes/Inverse";\r
public static final String HasEquation = "http://www.simantics.org/Sysdyn-1.1/HasEquation";\r
+ public static final String HasEquationOrEmpty = "http://www.simantics.org/Sysdyn-1.1/HasEquationOrEmpty";\r
+ public static final String HasEquationOrEmpty_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasEquationOrEmpty/Inverse";\r
public static final String HasEquation_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasEquation/Inverse";\r
public static final String HasExpressions = "http://www.simantics.org/Sysdyn-1.1/HasExpressions";\r
public static final String HasExpressions_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasExpressions/Inverse";\r
HasEnumerationIndexes = getResourceOrNull(graph, URIs.HasEnumerationIndexes);\r
HasEnumerationIndexes_Inverse = getResourceOrNull(graph, URIs.HasEnumerationIndexes_Inverse);\r
HasEquation = getResourceOrNull(graph, URIs.HasEquation);\r
+ HasEquationOrEmpty = getResourceOrNull(graph, URIs.HasEquationOrEmpty);\r
+ HasEquationOrEmpty_Inverse = getResourceOrNull(graph, URIs.HasEquationOrEmpty_Inverse);\r
HasEquation_Inverse = getResourceOrNull(graph, URIs.HasEquation_Inverse);\r
HasExpressions = getResourceOrNull(graph, URIs.HasExpressions);\r
HasExpressions_Inverse = getResourceOrNull(graph, URIs.HasExpressions_Inverse);\r
import org.simantics.ui.utils.AdaptionUtils;\r
import org.simantics.utils.datastructures.Pair;\r
\r
+/**\r
+ * Tab for displaying equation information of a variable\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
public class EquationTab extends LabelPropertyTabContributor implements Widget {\r
\r
- TrackedCombo expressionTypeCombo, unitCombo, arrayEquationCombo;\r
- ShortcutTabWidget shortcutTabWidget;\r
- ExpressionWidget expressionWidget;\r
- org.eclipse.ui.IPartListener2 focusLostListener; \r
- IWorkbenchSite site;\r
- WidgetSupport support;\r
- Button deleteExpression, newExpression;\r
-\r
- WidgetSupportImpl expressionSupport = new WidgetSupportImpl();\r
+ private TrackedCombo expressionTypeCombo, unitCombo, arrayEquationCombo;\r
+ private ShortcutTabWidget shortcutTabWidget;\r
+ private ExpressionWidget expressionWidget;\r
+ private org.eclipse.ui.IPartListener2 focusLostListener; \r
+ private IWorkbenchSite site;\r
+ private Button deleteExpression, newExpression;\r
+ private WidgetSupportImpl expressionSupport = new WidgetSupportImpl();\r
\r
@Override\r
public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {\r
this.site = site;\r
- this.support = support;\r
support.register(this);\r
\r
+ // Composite for the whole tab\r
Composite composite = new Composite(body, SWT.NONE);\r
GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);\r
GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(composite);\r
\r
- Composite nameAndEquations = new Composite(composite, SWT.NONE);\r
- GridDataFactory.fillDefaults().grab(true, false).applyTo(nameAndEquations);\r
- GridLayoutFactory.fillDefaults().numColumns(2).applyTo(nameAndEquations);\r
-\r
- Composite nameComposite = new Composite(nameAndEquations, SWT.NONE);\r
+ // Composite holding name controls and controls for adding and removing expressions\r
+ Composite nameComposite = new Composite(composite, SWT.NONE);\r
GridLayoutFactory.fillDefaults().numColumns(3).applyTo(nameComposite);\r
GridDataFactory.fillDefaults().grab(true, false).applyTo(nameComposite);\r
\r
newExpression = new Button(nameComposite, support, SWT.NONE);\r
newExpression.setText("New");\r
GridDataFactory.fillDefaults().applyTo(newExpression.getWidget());\r
- /*\r
- TrackedText nameText = new TrackedText(nameAndEquations, support, SWT.BORDER);\r
- nameText.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasName));\r
- nameText.addModifyListener(new VariableNamePropertyModifier(context, Layer0.URIs.HasName));\r
- nameText.setInputValidator(new VariableNameValidator(support));\r
- GridDataFactory.fillDefaults().grab(true, false).span(2,1).applyTo(nameText.getWidget());\r
- */\r
\r
+ // Shortcut widget. Tabular widget containing tabs for functions and connected variables\r
shortcutTabWidget = new ShortcutTabWidget(composite, support, SWT.NONE);\r
GridDataFactory.fillDefaults().span(1, 3).grab(false, true).applyTo(shortcutTabWidget.getWidget());\r
\r
-\r
+ // Type and unit selection composite\r
Composite TypeAndUnit = new Composite(composite, SWT.NONE);\r
GridDataFactory.fillDefaults().grab(true, false).applyTo(TypeAndUnit);\r
GridLayoutFactory.fillDefaults().numColumns(5).applyTo(TypeAndUnit);\r
IsOutputWidget isOutput = new IsOutputWidget(TypeAndUnit, support, SWT.NULL);\r
GridDataFactory.fillDefaults().grab(true, false).align(SWT.END, SWT.FILL).applyTo(isOutput.getWidget());\r
\r
-\r
+ // The actual expression\r
Composite expressionComposite = new Composite(composite, SWT.NONE);\r
GridDataFactory.fillDefaults().grab(true, true).applyTo(expressionComposite);\r
expressionWidget = new ExpressionWidget(expressionComposite, expressionSupport, SWT.NONE);\r
} catch (DatabaseException e) {\r
e.printStackTrace();\r
}\r
- // No expressions -> creating a new ordered set expressions and the active expression\r
+ // The variable has no expressions -> creating a new ordered set expressions and the active expression\r
if(expression == null && variable != null) {\r
try {\r
expression = SimanticsUI.getSession().syncRequest(new WriteResultRequest<Resource>() {\r
}\r
}\r
\r
-\r
+ // Now the variable should have an expression\r
SimanticsUI.getSession().asyncRequest(new Read<Pair<Boolean, Boolean>>() {\r
\r
+ /**\r
+ * Find out if user can add a new expression or delete the current expression\r
+ */\r
@Override\r
public Pair<Boolean, Boolean> perform(ReadGraph graph) throws DatabaseException {\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
\r
boolean canAdd = true;\r
boolean canDelete = false;\r
+ // If there are multiple expressions, one can be removed\r
if(expressionList.size() > 1)\r
canDelete = true;\r
String defaultRange = ArrayExpressionCombo.getDefaultRange(graph, variable);\r
\r
+ /* If the variable is an array variable, a range has been set to all expressions and none of\r
+ * the ranges is the default range, an expression can be added\r
+ */ \r
for(Resource expression : expressionList) {\r
String range = graph.getPossibleRelatedValue(expression, sr.HasArrayRange);\r
if(range == null || range.equals("") || range.equals(defaultRange)) {\r
return newExpression.getWidget().isDisposed() || deleteExpression.getWidget().isDisposed();\r
}\r
});\r
-\r
+ \r
+ // Set input to widgets using expressionSupport\r
StructuredSelection ss = new StructuredSelection(expression);\r
expressionSupport.fireInput(context, ss);\r
}\r
\r
+ /**\r
+ * Adds listeners to widgets in this tab\r
+ * \r
+ * @param context ISessionContext\r
+ */\r
private void addListeners(ISessionContext context) {\r
\r
+ // Validate expression fields when a dependency has been added or removed\r
shortcutTabWidget.addDependencyListener(new Runnable() {\r
\r
@Override\r
}\r
});\r
\r
+ // Deletes a selected expression\r
deleteExpression.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
\r
@Override\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
Layer0 l0 = Layer0.getInstance(graph);\r
\r
+ // Currently active expressin should be located in (Model sr.HasActiveExpression expression)\r
Resource activeExpression = graph.getPossibleObject(input, sr.HasActiveExpression);\r
if(activeExpression == null)\r
return;\r
if(OrderedSetUtils.toList(graph, expressionList).size() <= 1)\r
return;\r
\r
+ // Get the previous expression in expression list to be activated\r
Resource prev = OrderedSetUtils.prev(graph, expressionList, activeExpression);\r
OrderedSetUtils.remove(graph, expressionList, activeExpression);\r
graph.deny(input, l0.ConsistsOf, activeExpression);\r
\r
if(prev.equals(expressionList)) {\r
+ // If the removed expression was last on the list, prev returns the list.\r
+ // Get a proper list element to be activated\r
Iterator<Resource> iterator = OrderedSetUtils.iterator(graph, expressionList);\r
prev = iterator.next();\r
}\r
\r
+ // Set prev as active in virtual graph\r
final Resource newActive = prev;\r
VirtualGraphSupport support = graph.getService(VirtualGraphSupport.class);\r
final Session session = graph.getSession();\r
}\r
});\r
\r
+ // Creates a new expression\r
newExpression.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
\r
@Override\r
if(expressions == null) {\r
return;\r
}\r
+ // Get the currently active expression\r
Resource activeExpression = graph.getPossibleObject(input, sr.HasActiveExpression);\r
Resource newExpression = graph.newResource();\r
if(activeExpression != null) {\r
+ // Create a new expression based on the old expression\r
graph.claim(newExpression, l0.InstanceOf, graph.getSingleObject(activeExpression, l0.InstanceOf));\r
if(graph.isInstanceOf(newExpression, sr.StockExpression)) {\r
graph.claimLiteral(newExpression, sr.HasInitialEquation, "");\r
}\r
} else {\r
+ // If there was no active expression, create a normal expression\r
graph.claim(newExpression, l0.InstanceOf, sr.NormalExpression);\r
}\r
OrderedSetUtils.add(graph, expressions, newExpression);\r
}\r
});\r
\r
+ // Item factory for expression type combo\r
expressionTypeCombo.setItemFactory(new ReadFactoryImpl<Resource, Map<String,Object>>() {\r
\r
@Override\r
Map<String, Object> map = new HashMap<String, Object>();\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
\r
+ // Select expression types based on the type of the variable\r
final ExpressionType[] expressionTypes;\r
if(graph.isInstanceOf(input, sr.Auxiliary))\r
expressionTypes = ExpressionTypes.auxiliaryExpressions;\r
}\r
});\r
\r
+ // Initial selection to the combo from active expression\r
expressionTypeCombo.setSelectionFactory(new ReadFactoryImpl<Resource, String>() {\r
\r
@Override\r
}\r
});\r
\r
+ // Modify listener for selecting expression type\r
expressionTypeCombo.addModifyListener(new TextModifyListener() {\r
\r
@Override\r
});\r
\r
\r
+ // Add all units used in the model to the unit combo\r
unitCombo.setItemFactory(new ReadFactoryImpl<Resource, Map<String,Object>>() {\r
\r
@Override\r
return map;\r
}\r
});\r
+ \r
+ // Set initial selection of unit combo\r
unitCombo.setSelectionFactory(new ReadFactoryImpl<Resource, String>() {\r
\r
@Override\r
}\r
});\r
\r
+ // Modify unit\r
unitCombo.addModifyListener(new ComboModifyListenerImpl<Resource>() {\r
\r
@Override\r
});\r
\r
\r
+ /*\r
+ * Double-clicking something in shortcut tab widget\r
+ * writes the clicked element into expression widget,\r
+ * sets focus on expression widget and validates its fields\r
+ */\r
shortcutTabWidget.addMouseListener(new MouseListener(){\r
\r
@Override\r
@Override\r
public void run() {\r
if(expressionWidget!= null) {\r
+ expressionWidget.getExpression().focus();\r
expressionWidget.getExpression().replaceSelection(var);\r
- expressionWidget.getExpression().focus();\r
expressionWidget.validateFieldsTimed();\r
}\r
}\r
}\r
\r
});\r
+ \r
+ /*\r
+ * Shortcut tab widget should not maintain any selections for visual reasons\r
+ */\r
shortcutTabWidget.addFocusListener(new FocusListener() {\r
\r
@Override\r
\r
});\r
\r
+ /* Modifying an expression sets a timed validation. The timer is\r
+ * reset after each modification \r
+ */ \r
expressionWidget.addModifyListener(new ModifyListener() {\r
\r
@Override\r
}\r
});\r
\r
+ // Pressing return without shift key triggers saving the expression\r
expressionWidget.addVerifyKeyListener(new VerifyKeyListener() {\r
\r
@Override\r
}\r
});\r
\r
+ // Triggers save when equation tab loses focus\r
if(focusLostListener == null) {\r
focusLostListener = new org.eclipse.ui.IPartListener2()\r
{\r
super.dispose();\r
}\r
\r
+ /**\r
+ * Get the currently active expression of the first expression in expression list if\r
+ * no expression has been set to active\r
+ * \r
+ * @param graph ReadGraph\r
+ * @param variable Variable\r
+ * @return active expression or the first expression in variables expression list\r
+ * @throws DatabaseException\r
+ */\r
private Resource getActiveExpression(ReadGraph graph, Resource variable) throws DatabaseException {\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
Resource expression = graph.getPossibleObject(variable, sr.HasActiveExpression);\r
\r
@Override\r
public void focus() {\r
- equation.setFocus();\r
+ lastSelectedText.setFocus();\r
}\r
\r
@Override\r
public List<ExpressionField> getExpressionFields() {\r
- return Arrays.asList(equation, delayTime);\r
+ return Arrays.asList(equation, delayTime, initialValue);\r
}\r
\r
@Override\r
import org.eclipse.jface.text.source.SourceViewer;\r
import org.eclipse.swt.SWT;\r
import org.eclipse.swt.custom.StyledText;\r
+import org.eclipse.swt.events.FocusEvent;\r
+import org.eclipse.swt.events.FocusListener;\r
import org.eclipse.swt.events.KeyEvent;\r
import org.eclipse.swt.events.KeyListener;\r
import org.eclipse.swt.graphics.Color;\r
import org.eclipse.swt.graphics.Point;\r
import org.simantics.sysdyn.expressionParser.Token;\r
\r
+/**\r
+ * Field for displaying a part of an expression. Expression field uses SourceViewer\r
+ * to display annotations and other visual elements just like any other\r
+ * source viewer in eclipse.\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
public class ExpressionField extends Composite {\r
\r
protected SourceViewer _sourceViewer;\r
\r
IAnnotationAccess annotationAccess = new DefaultMarkerAnnotationAccess();\r
\r
+ /**\r
+ * Create a new expression field\r
+ * @param parent\r
+ * @param style\r
+ */\r
public ExpressionField(Composite parent, int style) {\r
super(parent, style);\r
\r
null,\r
true,\r
styles);\r
+ \r
+ // Configuration for color management\r
_sourceViewer.configure(new ExpressionFieldConfiguration(cManager));\r
-\r
AnnotationPainter painter = new AnnotationPainter(_sourceViewer, annotationAccess);\r
_sourceViewer.addPainter(painter);\r
\r
+ // Annotation types\r
painter.addAnnotationType(MISSING_LINK);\r
painter.setAnnotationTypeColor(MISSING_LINK, new Color(this.getDisplay(), 255,215,0));\r
painter.addAnnotationType(NO_SUCH_VARIABLE);\r
_sourceViewer.setDocument(_document, _annotationModel);\r
\r
GridDataFactory.fillDefaults().grab(true, true).applyTo(_sourceViewer.getControl());\r
-// _sourceViewer.getControl().setLayoutData(new GridData(SWT.FILL,\r
-// SWT.FILL,\r
-// true,\r
-// true)); \r
\r
+ // Parenthesis matching\r
PaintManager paintManager = new PaintManager(_sourceViewer);\r
MatchingCharacterPainter matchingCharacterPainter = new MatchingCharacterPainter(_sourceViewer,\r
new DefaultCharacterPairMatcher( new char[] {'(', ')', '{', '}', '[', ']'} ));\r
paintManager.addPainter(matchingCharacterPainter);\r
\r
\r
+ // Listener for canceling editing. ESC -> revert back to original text\r
_sourceViewer.getTextWidget().addKeyListener(new KeyListener() {\r
\r
@Override\r
}\r
});\r
\r
+ /* Focus listener saving and restoring selections\r
+ * When focus is lost, current selection is saved, but the selection is removed.\r
+ * When focus is gained back, the selection is restored\r
+ */\r
+ _sourceViewer.getTextWidget().addFocusListener(new FocusListener() {\r
+ \r
+ Point selection = null;\r
+ @Override\r
+ public void focusLost(FocusEvent e) {\r
+ selection = ((StyledText)e.widget).getSelection();\r
+ ((StyledText)e.widget).setSelection(0);\r
+ }\r
+ \r
+ @Override\r
+ public void focusGained(FocusEvent e) {\r
+ if(selection != null)\r
+ ((StyledText)e.widget).setSelection(selection);\r
+ }\r
+ });\r
}\r
\r
+ /**\r
+ * Returns the {@link SourceViewer} of this ExpressionField\r
+ * @return Returns the {@link SourceViewer} of this ExpressionField\r
+ */\r
public SourceViewer getSourceViewer() {\r
return this._sourceViewer;\r
}\r
\r
+ /**\r
+ * Sets missing link annotations to given positions\r
+ * @param positions Positions for missing link annotations\r
+ */\r
public void setMissingLinkAnnotations(List<Position> positions){\r
for(Position p : positions) {\r
Annotation annotation = new Annotation(false);\r
}\r
}\r
\r
+ /**\r
+ * Sets no such variable annotations to given positions\r
+ * @param positions Positions for no such variable annotations\r
+ */\r
public void setNoSuchVariableAnnotations(List<Position> positions){\r
for(Position p : positions) {\r
Annotation annotation = new Annotation(false);\r
}\r
}\r
\r
+ /**\r
+ * Sets syntax error for the given token\r
+ * @param token Token with syntax error\r
+ * @param message Message to be displayed in tool tips\r
+ */\r
public void setSyntaxError(Token token, String message){\r
setSyntaxError(token.image, message, token.beginLine, token.beginColumn, token.endLine, token.endColumn);\r
}\r
\r
+ /**\r
+ * Sets syntax error for the given token\r
+ * @param token Token with syntax error\r
+ * @param message Message to be displayed in tool tips\r
+ */\r
public void setSyntaxError(org.simantics.sysdyn.tableParser.Token token, String message){\r
setSyntaxError(token.image, message, token.beginLine, token.beginColumn, token.endLine, token.endColumn);\r
}\r
\r
+ /**\r
+ * Sets syntax error to given location\r
+ * @param image Token image\r
+ * @param message Message to be displayed in tool tips\r
+ * @param beginLine Begin line\r
+ * @param beginColumn Begin column\r
+ * @param endLine End line\r
+ * @param endColumn End column\r
+ */\r
public void setSyntaxError(String image, String message, int beginLine, int beginColumn, int endLine, int endColumn) {\r
int start = 0;\r
int offset = this._document.getLength();\r
setSyntaxError(start, offset, SYNTAX_ERROR, message == null ? "Syntax Error" : message);\r
}\r
\r
+ /**\r
+ * Sets syntax error to given start and offset\r
+ * @param start Start location\r
+ * @param offset Offset\r
+ * @param type Error type (SYNTAX_ERROR, MISSING_LINK, NO_SUCH_VARIABLE)\r
+ * @param text Message to be displayedin tool tips\r
+ */\r
public void setSyntaxError(int start, int offset, String type, String text) {\r
Annotation annotation = new Annotation(false);\r
annotation.setType(type);\r
_annotationModel.addAnnotation(annotation, p); \r
}\r
\r
+ /**\r
+ * Resets all annotations\r
+ */\r
public void resetAnnotations() {\r
_annotationModel.removeAllAnnotations();\r
}\r
+ \r
+ /**\r
+ * Sets an expression to this expression field\r
+ * @param expression\r
+ */\r
public void setExpression(String expression) {\r
_document.set(expression);\r
this.oldExpression = expression;\r
}\r
\r
+ /**\r
+ * Returns the expression of this expression field\r
+ * @return\r
+ */\r
public String getExpression() {\r
return this._document.get();\r
}\r
\r
+ /**\r
+ * Returns the current selection\r
+ * @return current selection\r
+ */\r
public Point getSelection() {\r
return _sourceViewer.getSelectedRange();\r
}\r
\r
+ /**\r
+ * Set selection for this expression field. The length of the selection is 0\r
+ * @param selection Selection location\r
+ */\r
public void setSelection(int selection) {\r
this._sourceViewer.setSelectedRange(selection, 0);\r
}\r
return _document;\r
}\r
\r
+ /**\r
+ * Focus to this expression field\r
+ */\r
public void focus() {\r
this._sourceViewer.getTextWidget().forceFocus();\r
}\r
TableItem[] connectedVariables = variableTable.getItems();\r
for(TableItem ti : connectedVariables) {\r
if(!variables.contains(ti.getText())) {\r
- ti.setForeground(new Color(ti.getDisplay(), 255, 0, 0));\r
+ ti.setForeground(new Color(ti.getDisplay(), 255,125,0));\r
} else {\r
ti.setForeground(new Color(ti.getDisplay(), 0, 0, 0));\r
variables.remove(ti.getText());\r
\r
} \r
\r
-\r
- \r
- \r
- \r
- \r
for(ExpressionField ef : ranges.keySet()) {\r
HashMap<Token, String> tokens = errors.get(ef);\r
if(tokens == null || tokens.isEmpty()) continue;\r
Set<String> dependencies = ValidationUtils.getDependencies(graph, component);\r
Set<String> references = null;\r
\r
+ ArrayList<Issue> result = new ArrayList<Issue>();\r
+\r
+ \r
// Find all references in equations of component\r
try {\r
references = ValidationUtils.getReferences(graph, component);\r
- } catch (SyntaxErrorException e) {\r
- } catch (UnsupportedCharactersException e) {\r
- } catch (UndefinedExpressionException e) {\r
- }\r
-\r
- ArrayList<Issue> result = new ArrayList<Issue>();\r
+ } catch (Exception e) {\r
+ return result;\r
+ } \r
\r
// Check that all arrow dependencies are used in equations\r
if (dependencies != null) {\r
import org.simantics.databoard.Bindings;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
+import org.simantics.db.Statement;\r
import org.simantics.db.common.request.ObjectsWithType;\r
import org.simantics.db.common.utils.OrderedSetUtils;\r
import org.simantics.db.exception.DatabaseException;\r
*\r
*/\r
public class ValidationUtils {\r
- \r
+\r
/**\r
* Find all variables that are referred to in the expressions of variable r\r
* @param graph ReadGraph\r
ExpressionParser parser = new ExpressionParser(new StringReader(""));\r
\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
- Layer0 l0 = Layer0.getInstance(graph);\r
List<Resource> expressionList = getExpressions(graph, r);\r
if(expressionList == null || expressionList.isEmpty())\r
throw new UndefinedExpressionException();\r
for(Resource expression : expressionList) {\r
- Collection<Resource> equations = graph.syncRequest(new ObjectsWithType(expression, sr.HasEquation, l0.String));\r
- if(equations.isEmpty())\r
+ Collection<Statement> statements = graph.getStatements(expression, sr.HasEquation);\r
+ if(statements.isEmpty())\r
throw new UndefinedExpressionException();\r
- \r
- for(Resource s : equations) {\r
- String value = graph.getValue(s, Bindings.STRING);\r
- if(value.length() == 0)\r
- throw new UndefinedExpressionException();\r
+\r
+ for(Statement statement : statements) {\r
+ Object v = graph.getValue(statement.getObject());\r
+ String value = v.toString();\r
+ \r
+ if(value.length() == 0) {\r
+ // Empty might be allowed\r
+ if(graph.isSubrelationOf(statement.getPredicate(), sr.HasEquationOrEmpty))\r
+ return references;\r
+ else\r
+ throw new UndefinedExpressionException();\r
+ }\r
\r
parser.ReInit(new StringReader(value));\r
try {\r
}\r
return references;\r
}\r
- \r
+\r
/**\r
* Get all expressions of a variable r\r
* @param graph ReadGraph\r
return null;\r
}\r
\r
- \r
+\r
/**\r
* Returns the names of the related variables (dependencies)\r
* \r
}\r
return variables;\r
}\r
- \r
+\r
/**\r
* Is reference reachable from variable\r
* \r
else \r
return false;\r
}\r
- \r
+\r
/**\r
* Find a resource starting from variable and using reference path\r
* \r
}\r
return null;\r
}\r
- \r
+\r
}\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
SimulationResource simu = SimulationResource.getInstance(graph);\r
Resource modelResource = graph.getPossibleObject(model.getConfigurationResource(), simu.IsConfigurationOf);\r
+ if(modelResource == null)\r
+ return parents;\r
\r
parents.add(modelResource);\r
\r
sb.append("\tReal" + range + " initialValue = " + (range.length() > 0 ? "fill(-137543," + range.substring(1, range.length() - 1) + ")" : -137543) + ";\n");\r
else\r
// Initial value\r
- sb.append("\tReal" + range + " initialValue = " + initialValue + ";\n");\r
+ sb.append("\tReal" + range + " initialValue = " + FormatUtils.formatExpressionForModelica(variable, this.initialValue) + ";\n");\r
\r
// First valve\r
sb.append("\tReal" + range + " delay0;\n");\r
sb.append("initial equation\n");\r
\r
// "Generic" structure selection. If the "random" number is not used in initial value, use delay0 as initial value\r
- sb.append("\tLV" + n +" = DL * " + \r
- (range.length() > 0 ? "(if max(initialValue) < -137543 or max(initialValue) > -137543 then initialValue else delay0)" :\r
- "(if initialValue < -137543 or initialValue > -137543 then initialValue else delay0)") + ";\n");\r
- \r
// Each stock gets the same initial value\r
- for(int i = 1; i < n; i++)\r
- sb.append("\tLV" + i + " = LV" + n + ";\n");\r
+ for(int i = 1; i <= n; i++)\r
+ sb.append("\tLV" + i +" = DL * " + \r
+ (range.length() > 0 ? "(if max(initialValue) < -137543 or max(initialValue) > -137543 then initialValue else delay0)" :\r
+ "(if initialValue < -137543 or initialValue > -137543 then initialValue else delay0)") + ";\n");\r
\r
sb.append("equation\n");\r
sb.append("\tDL = delayTime/" + n + ";\n");\r
@Override\r
public String getEquation(IndependentVariable variable) {\r
String equation = FormatUtils.formatExpressionForModelica(variable, this.equation);\r
+ String delayTime = FormatUtils.formatExpressionForModelica(variable, this.delayTime);\r
\r
// Set delay properties\r
StringBuilder sb = new StringBuilder();\r