X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.network.ui%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fui%2Fstyles%2FDistrictNetworkHoverInfoStyle.java;fp=org.simantics.district.network.ui%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fui%2Fstyles%2FDistrictNetworkHoverInfoStyle.java;h=a5fa89d42b952415f25fb527d2e36c962b32d5ce;hb=7c1f539de88c6ca79b2ac6dc891be3f45282abe2;hp=77be9c90cc392a37df569b5c917b31e6ad61b76f;hpb=2de54d0f65ace8c56d27a5a1191e4420b96e22c2;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/DistrictNetworkHoverInfoStyle.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/DistrictNetworkHoverInfoStyle.java index 77be9c90..a5fa89d4 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/DistrictNetworkHoverInfoStyle.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/DistrictNetworkHoverInfoStyle.java @@ -50,7 +50,7 @@ public class DistrictNetworkHoverInfoStyle extends StyleBase labels; @@ -81,86 +81,97 @@ public class DistrictNetworkHoverInfoStyle extends StyleBase> function = getUCTextGridFunctionCached(graph, moduleType); - if (function == null) - return null; - - List result; - try { - Variable variable = Variables.getVariable(graph, module); - Variable moduleVariable = Variables.possibleActiveVariable(graph, variable); - if (moduleVariable == null) - moduleVariable = variable; - - result = Simantics.applySCLRead(graph, function, moduleVariable); - } catch (PendingVariableException | MissingVariableValueException e) { - result = Collections.singletonList(new Tuple3("", "", "")); - } catch (MissingVariableException e) { + + @Override + public StyleResult calculateStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource mapElement, + Variable configuration) throws DatabaseException { + //return doCalculateStyleResult(graph, runtimeDiagram, mapElement); + return new StyleResult(calculatePoint(graph, mapElement), Collections.emptyList()); + } + + public static StyleResult doCalculateStyleResult(ReadGraph graph, Resource runtimeDiagram, Resource mapElement) throws DatabaseException { + DiagramResource DIA = DiagramResource.getInstance(graph); + StructuralResource2 STR = StructuralResource2.getInstance(graph); + + String variableURI = graph.getPossibleRelatedValue(runtimeDiagram, DIA.RuntimeDiagram_HasVariable, + Bindings.STRING); + Variable activeVariable = org.simantics.db.layer0.variable.Variables.getPossibleVariable(graph, variableURI); + if (activeVariable == null) + return null; + + Resource module = DistrictNetworkUtil.getMappedComponentCached(graph, mapElement); + if (module == null) + return null; + + Resource moduleType = graph.getPossibleType(module, STR.Component); + if (moduleType == null) + return null; + + Function1> function = getUCTextGridFunctionCached(graph, moduleType); + if (function == null) + return null; + + List result; + try { + Variable variable = Variables.getVariable(graph, module); + Variable moduleVariable = Variables.possibleActiveVariable(graph, variable); + if (moduleVariable == null) + moduleVariable = variable; + + result = Simantics.applySCLRead(graph, function, moduleVariable); + } catch (PendingVariableException | MissingVariableValueException e) { + result = Collections.singletonList(new Tuple3("", "", "")); + } catch (MissingVariableException e) { // the requested variable is missing from the UC String message = e.getMessage(); LOGGER.warn("Missing variable for calculating style with function {} {}", function, message); - result = Collections.singletonList(new Tuple3("<" + message +">", "", "")); + result = Collections.singletonList(new Tuple3("<" + message + ">", "", "")); } - - Point2D point; - DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); - if (graph.isInstanceOf(mapElement, DN.Vertex)) { - double[] coords = graph.getRelatedValue(mapElement, DIA.HasLocation); - point = DistrictNetworkNodeUtils.calculatePoint2D(new Point2D.Double(coords[0], coords[1]), null); - } - else if (graph.isInstanceOf(mapElement, DN.Edge)) { - Resource v1 = graph.getSingleObject(mapElement, DN.HasStartVertex); - double[] coords1 = graph.getRelatedValue(v1, DIA.HasLocation); - Resource v2 = graph.getSingleObject(mapElement, DN.HasEndVertex); - double[] coords2 = graph.getRelatedValue(v2, DIA.HasLocation); - point = DistrictNetworkNodeUtils.calculatePoint2D(new Point2D.Double((coords1[0] + coords2[0]) / 2, (coords1[1] + coords2[1]) / 2), null); - } - else { - return null; - } - - return new StyleResult(point, result); - } - + + Point2D point = calculatePoint(graph, mapElement); + + return new StyleResult(point, result); + } + + public static Point2D calculatePoint(ReadGraph graph, Resource mapElement) throws DatabaseException { + Point2D point; + DiagramResource DIA = DiagramResource.getInstance(graph); + DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); + if (graph.isInstanceOf(mapElement, DN.Vertex)) { + double[] coords = graph.getRelatedValue(mapElement, DIA.HasLocation); + point = DistrictNetworkNodeUtils.calculatePoint2D(new Point2D.Double(coords[0], coords[1]), null); + } else if (graph.isInstanceOf(mapElement, DN.Edge)) { + Resource v1 = graph.getSingleObject(mapElement, DN.HasStartVertex); + double[] coords1 = graph.getRelatedValue(v1, DIA.HasLocation); + Resource v2 = graph.getSingleObject(mapElement, DN.HasEndVertex); + double[] coords2 = graph.getRelatedValue(v2, DIA.HasLocation); + point = DistrictNetworkNodeUtils.calculatePoint2D( + new Point2D.Double((coords1[0] + coords2[0]) / 2, (coords1[1] + coords2[1]) / 2), null); + } else { + return null; + } + return point; + } + @Override public void applyStyleForNode(EvaluationContext observer, INode parent, StyleResult results) { - if (results == null) { - cleanupStyleForNode(observer, parent); - return; - } - - DistrictNetworkHoverInfoNode node = ProfileVariables.claimChild(parent, "*", DistrictNetworkHoverInfoNode.NODE_KEY, DistrictNetworkHoverInfoNode.class, observer); - if (node == null) - return; - - ParentNode root = (ParentNode) NodeUtil.getNearestParentOfType(parent, RTreeNode.class); - if (root != null) { - DeferredRenderingNode deferred = ProfileVariables.claimChild(root, "", HOVER_INFO_DEFERRED, DeferredRenderingNode.class, observer); - deferred.setZIndex(Integer.MAX_VALUE); - } - - node.setLabels(results.getLabels()); - node.setOrigin(results.getOrigin()); +// if (results == null) { +// cleanupStyleForNode(observer, parent); +// return; +// } +// +// DistrictNetworkHoverInfoNode node = ProfileVariables.claimChild(parent, "*", DistrictNetworkHoverInfoNode.NODE_KEY, DistrictNetworkHoverInfoNode.class, observer); +// if (node == null) +// return; +// +// ParentNode root = (ParentNode) NodeUtil.getNearestParentOfType(parent, RTreeNode.class); +// if (root != null) { +// DeferredRenderingNode deferred = ProfileVariables.claimChild(root, "", HOVER_INFO_DEFERRED, DeferredRenderingNode.class, observer); +// deferred.setZIndex(Integer.MAX_VALUE); +// } +// +// node.setLabels(results.getLabels()); +// node.setOrigin(results.getOrigin()); } @Override