@Override
public Color calculateThrottledStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem) throws DatabaseException {
DiagramSettings ds = graph.syncRequest(new DiagramSettingsRequest(runtimeDiagram), TransientCacheAsyncListener.instance());
- if (ds.elementColoringFunction.isPresent()) {
- if (DEBUG)
- System.out.print("elementColoringFunction: " + ds.elementColoringFunction + "(" + groupItem + "): ");
- Double t = Simantics.applySCLRead(graph, ds.elementColoringFunction.get(), groupItem);
- if (DEBUG)
- System.out.print(t);
- if (t != null) {
- Color result = ds.coloringGradient.get(t);
- //System.out.println("color(" + t + "): " + result);
- return result;
+ // Prevent PendingVariableExceptions from coming through
+ boolean wasSynchronous = graph.setSynchronous(true);
+ try {
+ if (ds.elementColoringFunction.isPresent()) {
+ if (DEBUG)
+ System.out.print("elementColoringFunction: " + ds.elementColoringFunction + "(" + groupItem + "): ");
+ Double t = Simantics.applySCLRead(graph, ds.elementColoringFunction.get(), groupItem);
+ if (DEBUG)
+ System.out.print(t);
+ if (t != null) {
+ Color result = ds.coloringGradient.get(t);
+ //System.out.println("color(" + t + "): " + result);
+ return result;
+ }
}
}
+ finally {
+ graph.setSynchronous(wasSynchronous);
+ }
return null;
}
@Override
public Double calculateThrottledStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem) throws DatabaseException {
DiagramSettings ds = graph.syncRequest(new DiagramSettingsRequest(runtimeDiagram), TransientCacheAsyncListener.instance());
- Double thickness = ONE;
- if (ds.edgeThicknessProperty.isPresent()) {
- thickness = Simantics.applySCLRead(graph, ds.edgeThicknessProperty.get(), groupItem);
-// System.out.println("read thickness: " + thickness + " : " + ds.edgeThicknessProperty);
- if (thickness == null) {
- thickness = ONE;
- } else {
- thickness = thickness * ds.edgeThicknessGain + ds.edgeThicknessBias;
+ // Prevent PendingVariableExceptions from coming through
+ boolean wasSynchronous = graph.setSynchronous(true);
+ try {
+ Double thickness = ONE;
+ if (ds.edgeThicknessProperty.isPresent()) {
+ thickness = Simantics.applySCLRead(graph, ds.edgeThicknessProperty.get(), groupItem);
+ // System.out.println("read thickness: " + thickness + " : " + ds.edgeThicknessProperty);
+ if (thickness == null) {
+ thickness = ONE;
+ } else {
+ thickness = thickness * ds.edgeThicknessGain + ds.edgeThicknessBias;
+ }
}
+
+ return thickness;
+ }
+ finally {
+ graph.setSynchronous(wasSynchronous);
}
- return thickness;
}
@Override
@Override
public final Optional<Result> calculateStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry,
Resource groupItem) throws DatabaseException {
- long currentTimestamp = System.currentTimeMillis();
- if (lastCalculateTimestamp > (currentTimestamp - interval.get())) {
- LOGGER.debug("Throttling result calculation for {} {} {} {}", runtimeDiagram, entry, groupItem, interval.get());
- return Optional.empty();
- }
- lastCalculateTimestamp = currentTimestamp;
+// Needs fixing - this will result registration of listeners for nothing in the cache
+// long currentTimestamp = System.currentTimeMillis();
+// if (lastCalculateTimestamp > (currentTimestamp - interval.get())) {
+// LOGGER.debug("Throttling result calculation for {} {} {} {}", runtimeDiagram, entry, groupItem, interval.get());
+// return Optional.empty();
+// }
+// lastCalculateTimestamp = currentTimestamp;
// let's calculate
return Optional.ofNullable(calculateThrottledStyle(graph, runtimeDiagram, entry, groupItem));
}
public Double calculateThrottledStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem) throws DatabaseException {
DiagramSettings ds = graph.syncRequest(new DiagramSettingsRequest(runtimeDiagram), TransientCacheAsyncListener.instance());
Double scaling = ONE;
- if (ds.vertexScaleProperty.isPresent()) {
- scaling = Simantics.applySCLRead(graph, ds.vertexScaleProperty.get(), groupItem);
- if (scaling == null) {
- scaling = ONE;
- } else {
-// System.out.println("read vertex scaling: " + scaling + " : " + ds.vertexScaleProperty);
- scaling = scaling * ds.vertexScaleGain + ds.vertexScaleBias;
-// System.out.println("RESULT: " + scaling);
+ // Prevent PendingVariableExceptions from coming through
+ boolean wasSynchronous = graph.setSynchronous(true);
+ try {
+ if (ds.vertexScaleProperty.isPresent()) {
+ scaling = Simantics.applySCLRead(graph, ds.vertexScaleProperty.get(), groupItem);
+ if (scaling == null) {
+ scaling = ONE;
+ } else {
+ // System.out.println("read vertex scaling: " + scaling + " : " + ds.vertexScaleProperty);
+ scaling = scaling * ds.vertexScaleGain + ds.vertexScaleBias;
+ // System.out.println("RESULT: " + scaling);
+ }
}
+ return scaling;
+ }
+ finally {
+ graph.setSynchronous(wasSynchronous);
}
- return scaling;
}
@Override
import org.simantics.db.common.procedure.adapter.TransientCacheListener;
import org.simantics.db.common.request.ResourceRead;
import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.layer0.exception.PendingVariableException;
import org.simantics.district.network.ontology.DistrictNetworkResource;
import org.simantics.layer0.Layer0;
import org.simantics.scenegraph.INode;
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public String calculateThrottledStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem) throws DatabaseException {
-
- Function symbolFunction = getSymbolFunction(graph, entry);
- if (symbolFunction == null)
- return null;
-
+ // Prevent PendingVariableExceptions from coming through
+ boolean wasSynchronous = graph.setSynchronous(true);
try {
- return (String) Simantics.applySCLRead(graph, symbolFunction, groupItem);
- } catch (PendingVariableException e) {
- throw e;
- } catch (Exception e) {
- LOGGER.error("Getting dynamic symbol for " + groupItem + " (" + graph.getPossibleRelatedValue(groupItem, Layer0.getInstance(graph).HasName) + ") failed", e);
- return null;
+ Function symbolFunction = getSymbolFunction(graph, entry);
+ if (symbolFunction == null)
+ return null;
+
+ try {
+ return (String) Simantics.applySCLRead(graph, symbolFunction, groupItem);
+ } catch (Exception e) {
+ LOGGER.error("Getting dynamic symbol for " + groupItem + " (" + graph.getPossibleRelatedValue(groupItem, Layer0.getInstance(graph).HasName) + ") failed", e);
+ return null;
+ }
+ }
+ finally {
+ graph.setSynchronous(wasSynchronous);
}
}