/*******************************************************************************\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
\r
import java.awt.Color;\r
import java.awt.Font;\r
+import java.io.StringReader;\r
import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Set;\r
import java.util.concurrent.ConcurrentSkipListMap;\r
import java.util.concurrent.atomic.AtomicInteger;\r
\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.Statement;\r
+import org.simantics.db.common.utils.ListUtils;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.procedure.AsyncMultiProcedure;\r
import org.simantics.db.procedure.AsyncProcedure;\r
import org.simantics.g2d.element.IElement;\r
import org.simantics.g2d.element.handler.impl.StaticObjectAdapter;\r
import org.simantics.layer0.Layer0;\r
+import org.simantics.modeling.ModelingResources;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.expressionParser.ExpressionParser;\r
import org.simantics.sysdyn.ui.editor.routing.DependencyRouter;\r
import org.simantics.sysdyn.ui.preferences.SysdynDiagramPreferences;\r
import org.simantics.sysdyn.ui.preferences.SysdynDiagramPropertyExternalRead;\r
* consists of connection edge segments and branch points as its children.\r
* \r
* @author Tuukka Lehtonen\r
+ * @author Tuomas Miettinen\r
*/\r
public class DependencyConnectionFactory extends ElementFactoryAdapter {\r
\r
if(result != null && !result.isAsserted(elementResource)) {\r
element.setHint(ElementHints.KEY_TEXT_COLOR, G2DUtils.getColor(graph, result.getObject()));\r
} else {\r
- String color = graph.syncRequest(new SysdynDiagramPropertyExternalRead(new Pair<Resource, String>(elementResource, SysdynDiagramPreferences.ARROW_COLOR)));\r
- if(color != null) {\r
+ String color;\r
+ if (isForStockInitialOnly(graph, elementResource)) {\r
+ color = graph.syncRequest(new SysdynDiagramPropertyExternalRead(new Pair<Resource, String>(elementResource, SysdynDiagramPreferences.ARROW_STOCK_INITIAL_COLOR)));\r
+ } else {\r
+ color = graph.syncRequest(new SysdynDiagramPropertyExternalRead(new Pair<Resource, String>(elementResource, SysdynDiagramPreferences.ARROW_COLOR)));\r
+ }\r
+ if(color != null) {\r
RGB rgb = StringConverter.asRGB(color, null);\r
if(rgb != null) {\r
Color c = new Color(rgb.red, rgb.green, rgb.blue);\r
\r
}\r
\r
+ protected static boolean isForStockInitialOnly(ReadGraph graph,\r
+ Resource elementResource) throws DatabaseException {\r
+ SysdynResource SR = SysdynResource.getInstance(graph);\r
+ ModelingResources MO = ModelingResources.getInstance(graph);\r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ Resource connection = graph.getPossibleObject(elementResource, MO.DiagramConnectionToConnection);\r
+ Resource tail = graph.getPossibleObject(connection, SR.Variable_HasTail);\r
+ if (tail == null)\r
+ return false;\r
+ \r
+ if (graph.isInstanceOf(tail, SR.Shadow))\r
+ tail = graph.getPossibleObject(tail, SR.Shadow_original);\r
+ \r
+ Resource head = graph.getPossibleObject(connection, SR.Variable_HasHead);\r
+ if (head == null || !graph.isInstanceOf(head, SR.Stock) || tail == null)\r
+ return false;\r
+ \r
+ Resource expressionListResource = graph.getPossibleObject(head, SR.Variable_expressionList);\r
+ List<Resource> expressionList = ListUtils.toPossibleList(graph, expressionListResource);\r
+ \r
+ // Keep track on whether at least one initial equation contains the variable\r
+ boolean initialContainsVariable = false;\r
+ // Go through all expressions\r
+ for (Resource expression : expressionList) {\r
+ if (!graph.isInstanceOf(expression, SR.StockExpression))\r
+ return false;\r
+ \r
+ String tailStr = graph.getPossibleRelatedValue(tail, L0.HasName, Bindings.STRING);\r
+ String integral = graph.getPossibleRelatedValue(expression, SR.StockExpression_integralEquation, Bindings.STRING);\r
+ if (equationContainsVariable(graph, integral, tailStr))\r
+ // At least one integral equation contains the variable\r
+ return false;\r
+ String initial = graph.getPossibleRelatedValue(expression, SR.StockExpression_initialEquation, Bindings.STRING);\r
+ if (!initialContainsVariable && equationContainsVariable(graph, initial, tailStr))\r
+ // At least one initial equation contains the variable\r
+ initialContainsVariable = true;\r
+ }\r
+ \r
+ // No integral equation contains the variable.\r
+ return initialContainsVariable;\r
+ }\r
+\r
+ private static boolean equationContainsVariable(ReadGraph graph,\r
+ String equation, String variable) {\r
+ ExpressionParser parser = new ExpressionParser(new StringReader(equation));\r
+ try {\r
+ parser.expr();\r
+ } catch (Throwable t) {\r
+ return false;\r
+ }\r
+ \r
+ // Collect references\r
+ Set<String> references = parser.getReferences().keySet();\r
+ \r
+ // See if the equation contains variable\r
+ return references.contains(variable);\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\r
+ * VTT Technical Research Centre of Finland\r
*******************************************************************************/\r
\r
package org.simantics.sysdyn.ui.preferences;\r
/**\r
* \r
* @author Teemu Lempinen\r
+ * @author Tuomas Miettinen\r
*\r
*/\r
public class SysdynDiagramPreferencePage extends FieldEditorPreferencePage implements\r
GridDataFactory.fillDefaults().applyTo(label);\r
\r
addColorFieldEditor(SysdynDiagramPreferences.ARROW_COLOR, "&Dependency", SysdynDiagramPreferences.ARROW_USE_DEFAULT_COLOR);\r
+ addColorFieldEditor(SysdynDiagramPreferences.ARROW_STOCK_INITIAL_COLOR, "&Dependency to Stock Initial", SysdynDiagramPreferences.ARROW_STOCK_INITIAL_USE_DEFAULT_COLOR);\r
addColorFieldEditor(SysdynDiagramPreferences.FLOW_COLOR, "&Flow", SysdynDiagramPreferences.FLOW_USE_DEFAULT_COLOR);\r
addColorFieldEditor(SysdynDiagramPreferences.AUXILIARY_COLOR, "&Auxiliary", SysdynDiagramPreferences.AUXILIARY_USE_DEFAULT_COLOR);\r
addColorFieldEditor(SysdynDiagramPreferences.STOCK_COLOR, "&Stock", SysdynDiagramPreferences.STOCK_USE_DEFAULT_COLOR);\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\r
+ * VTT Technical Research Centre of Finland\r
*******************************************************************************/\r
package org.simantics.sysdyn.ui.preferences;\r
\r
/**\r
* \r
* @author Teemu Lempinen\r
+ * @author Tuomas Miettinen\r
*\r
*/\r
public class SysdynDiagramPreferences {\r
public static String DEFAULT_FONT = "Default font";\r
\r
public static String ARROW_COLOR = "Arrow color";\r
+ public static String ARROW_STOCK_INITIAL_COLOR = "Arrow stock initial color";\r
public static String FLOW_COLOR = "Flow color";\r
public static String AUXILIARY_COLOR = "Auxiliary color";\r
public static String CLOUD_COLOR = "Cloud color";\r
static {\r
colorPreferenceNames = new HashMap<String, String>();\r
colorPreferenceNames.put(SysdynResource.URIs.DependencyConnection, ARROW_COLOR);\r
+ colorPreferenceNames.put(SysdynResource.URIs.DependencyConnection + "_stockInitial", ARROW_STOCK_INITIAL_COLOR);\r
colorPreferenceNames.put(SysdynResource.URIs.FlowConnection, FLOW_COLOR);\r
colorPreferenceNames.put(SysdynResource.URIs.AuxiliarySymbol, AUXILIARY_COLOR);\r
colorPreferenceNames.put(SysdynResource.URIs.CloudSymbol, CLOUD_COLOR);\r
}\r
\r
public static String ARROW_USE_DEFAULT_COLOR = "Arrow use default color";\r
+ public static String ARROW_STOCK_INITIAL_USE_DEFAULT_COLOR = "Arrow stock initial use default color";\r
public static String FLOW_USE_DEFAULT_COLOR = "Flow use default color";\r
public static String AUXILIARY_USE_DEFAULT_COLOR = "Auxiliary use default color";\r
public static String CLOUD_USE_DEFAULT_COLOR = "Cloud use default color";\r
static {\r
colorDefaults = new HashMap<String, String>();\r
colorDefaults.put(ARROW_COLOR, ARROW_USE_DEFAULT_COLOR);\r
+ colorDefaults.put(ARROW_STOCK_INITIAL_COLOR, ARROW_STOCK_INITIAL_USE_DEFAULT_COLOR);\r
colorDefaults.put(FLOW_COLOR, FLOW_USE_DEFAULT_COLOR);\r
colorDefaults.put(AUXILIARY_COLOR, AUXILIARY_USE_DEFAULT_COLOR);\r
colorDefaults.put(CLOUD_COLOR, CLOUD_USE_DEFAULT_COLOR);\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\r
+ * VTT Technical Research Centre of Finland\r
*******************************************************************************/\r
package org.simantics.sysdyn.ui.preferences;\r
\r
/**\r
* \r
* @author Teemu Lempinen\r
+ * @author Tuomas Miettinen\r
*\r
*/\r
public class SysdynDiagramPreferencesInitializer extends AbstractPreferenceInitializer { \r
public void initializeDefaultPreferences() {\r
RGB black = new RGB(0, 0, 0);\r
RGB arrow = new RGB(0,128,192);\r
+ RGB arrowToStockInitial = new RGB(128,128,128);\r
\r
IPreferenceStore store = Activator.getDefault().getPreferenceStore();\r
\r
PreferenceConverter.setDefault(store, SysdynDiagramPreferences.DEFAULT_COLOR, black);\r
+ PreferenceConverter.setDefault(store, SysdynDiagramPreferences.ARROW_STOCK_INITIAL_COLOR, arrowToStockInitial);\r
PreferenceConverter.setDefault(store, SysdynDiagramPreferences.ARROW_COLOR, arrow);\r
PreferenceConverter.setDefault(store, SysdynDiagramPreferences.FLOW_COLOR, black);\r
PreferenceConverter.setDefault(store, SysdynDiagramPreferences.AUXILIARY_COLOR, black);\r
\r
\r
store.setDefault(SysdynDiagramPreferences.ARROW_USE_DEFAULT_COLOR, false);\r
+ store.setDefault(SysdynDiagramPreferences.ARROW_STOCK_INITIAL_USE_DEFAULT_COLOR, false);\r
store.setDefault(SysdynDiagramPreferences.FLOW_USE_DEFAULT_COLOR, true);\r
store.setDefault(SysdynDiagramPreferences.AUXILIARY_USE_DEFAULT_COLOR, true);\r
store.setDefault(SysdynDiagramPreferences.STOCK_USE_DEFAULT_COLOR, true);\r