From 3ec10beaefc3da6cd0bfab715d8c743f9d40f47c Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Mon, 30 Mar 2020 13:05:41 +0300 Subject: [PATCH] Added `possibleInvertibleExpressionReferencedTransformedProperty` This allows retrieval of the gain/bias applied to direct property references in derived properties of user components. Also switched DatasourceAdapter to use SLF4J logging instead of java.util logging, which should not be used anywhere. gitlab #505 Change-Id: I753b89fa1738e378e3e1ad5eac2a44e4dba9692f --- .../InvertBasicExpressionVisitor.java | 38 ++++++++++++------- .../simulation/data/DatasourceAdapter.java | 19 +++++----- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/InvertBasicExpressionVisitor.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/InvertBasicExpressionVisitor.java index 5bcce3ee4..4ac6adbff 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/InvertBasicExpressionVisitor.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/InvertBasicExpressionVisitor.java @@ -208,26 +208,36 @@ public class InvertBasicExpressionVisitor extends DepthFirstAdapter { } - public static Variable possibleInvertibleExpressionReferencedProperty(ReadGraph graph, Variable base, String expression) throws DatabaseException { + @SuppressWarnings("unchecked") + private static Triple possibleInvertibleExpression(ReadGraph graph, Variable base, String expression) throws DatabaseException { if (base == null || expression == null || expression.isEmpty()) return null; InvertBasicExpressionVisitor visitor = new InvertBasicExpressionVisitor(); //System.out.println("invert : " + expression + " -> " + replaced(expression) + " for " + base.getURI(graph)); Expressions.evaluate(replaced(expression), visitor); - Object pair = visitor.getResult(); - if(pair == null) - return null; - if(pair instanceof Triple) { - @SuppressWarnings("unchecked") - Triple data = (Triple)pair; - String key = data.third.replace(MAGIC,"."); - String path = getVariablePath(graph, base, key); - if (path == null) - return null; - Variable targetVariable = base.browsePossible(graph, path); - return targetVariable; - } + Object result = visitor.getResult(); + if (result instanceof Triple) + return (Triple) result; return null; } + public static Variable possibleInvertibleExpressionReferencedProperty(ReadGraph graph, Variable base, String expression) throws DatabaseException { + Triple data = possibleInvertibleExpression(graph, base, expression); + if (data == null) + return null; + String path = getVariablePath(graph, base, data.third.replace(MAGIC, ".")); + return path != null ? base.browsePossible(graph, path) : null; + } + + public static Triple possibleInvertibleExpressionReferencedTransformedProperty(ReadGraph graph, Variable base, String expression) throws DatabaseException { + Triple data = possibleInvertibleExpression(graph, base, expression); + if (data == null) + return null; + String path = getVariablePath(graph, base, data.third.replace(MAGIC, ".")); + if (path == null) + return null; + Variable targetVariable = base.browsePossible(graph, path); + return targetVariable != null ? Triple.make(data.first, data.second, targetVariable) : null; + } + } diff --git a/bundles/org.simantics.simulation/src/org/simantics/simulation/data/DatasourceAdapter.java b/bundles/org.simantics.simulation/src/org/simantics/simulation/data/DatasourceAdapter.java index 1ee543f4c..34fbb587d 100644 --- a/bundles/org.simantics.simulation/src/org/simantics/simulation/data/DatasourceAdapter.java +++ b/bundles/org.simantics.simulation/src/org/simantics/simulation/data/DatasourceAdapter.java @@ -19,8 +19,6 @@ import java.util.Set; import java.util.concurrent.Executor; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; -import java.util.logging.Level; -import java.util.logging.Logger; import org.simantics.databoard.Bindings; import org.simantics.databoard.accessor.error.AccessorException; @@ -32,6 +30,8 @@ import org.simantics.history.HistoryException; import org.simantics.history.util.subscription.SubscriptionItem; import org.simantics.simulation.data.Datasource.DatasourceListener; import org.simantics.utils.datastructures.Triple; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * This adapter reads data from Datasource and writes to an open Subscription. @@ -41,7 +41,7 @@ import org.simantics.utils.datastructures.Triple; */ public class DatasourceAdapter implements DatasourceListener { - protected Logger logger = Logger.getLogger( DatasourceAdapter.class.toString() ); + protected Logger logger = LoggerFactory.getLogger( DatasourceAdapter.class ); protected Collector session; protected boolean loaded = false; protected List handles = new ArrayList(); @@ -139,7 +139,7 @@ public class DatasourceAdapter implements DatasourceListener { result.add(Triple.make(key, binding, value)); } catch (AccessorException e) { if (failedIds.add(key)) - logger.log(Level.SEVERE, e.toString(), e); + logger.error(e.toString(), e); continue; } } @@ -172,20 +172,20 @@ public class DatasourceAdapter implements DatasourceListener { value = handle.getValue(source); } catch (AccessorException e) { if (failedIds.add(key)) - logger.log(Level.SEVERE, e.toString(), e); + logger.error(e.toString(), e); continue; } Binding binding = handle.binding(); try { session.setValue( key, binding, value ); } catch (HistoryException e) { - logger.log(Level.SEVERE, e.toString(), e); + logger.error(e.toString(), e); } } else { Binding binding = bindings.get(i); if (binding != null) { session.setValue( key, binding, value ); - } + } } } @@ -193,11 +193,11 @@ public class DatasourceAdapter implements DatasourceListener { try { session.endStep(); } catch (HistoryException e) { - logger.log(Level.SEVERE, e.toString(), e); + logger.error(e.toString(), e); } } } catch (HistoryException e) { - logger.log(Level.SEVERE, e.toString(), e); + logger.error(e.toString(), e); } finally { stepLock.unlock(); } @@ -207,6 +207,5 @@ public class DatasourceAdapter implements DatasourceListener { public Executor getExecutor() { return null; } - } -- 2.43.2