Previously the profile style implementation would reset the edge info
direction to match the simplified edge data whenever the style result
was recalculated from the database.
Now the style just tells the static info node the
DistrictNetworkEdgeNode it is supposed to visualize and the info node
will calculate the info pos/orientation based on that during render.
This is an interim fix because the style implementation will be removed
once this visualization is moved into the district visualization toolbox
from the diagram profile implementation. At that point the visualization
also needs to be optimized to only show the information for the edges
inside the current viewbox.
gitlab #47
Change-Id: I8b8ea78378df5749cf59405d7f9fae8d9848698e
(cherry picked from commit
7f3b0d5297006df708f9169e473448ec6f85e211)
private static final Font FONT = new Font(Font.SANS_SERIF, Font.PLAIN, DPIUtil.upscale(10));
private static final Font FONT = new Font(Font.SANS_SERIF, Font.PLAIN, DPIUtil.upscale(10));
- private static final Point2D UNIT_X = new Point2D.Double(1.0, 0.0);
-
public static final String NODE_KEY = "DISTRICT_NETWORK_STATIC_INFO";
String info = null;
Point2D origin = new Point2D.Double();
public static final String NODE_KEY = "DISTRICT_NETWORK_STATIC_INFO";
String info = null;
Point2D origin = new Point2D.Double();
- Point2D direction = UNIT_X;
+ Point2D direction = new Point2D.Double();
private DistrictNetworkEdgeNode edgeNode = null;
private DistrictNetworkEdgeNode edgeNode = null;
}
public void setLocation(Point2D origin, Point2D direction) {
}
public void setLocation(Point2D origin, Point2D direction) {
- this.origin = origin;
- this.direction = direction;
+ this.origin.setLocation(origin);
+ this.direction.setLocation(direction);
}
public void setInfo(String info) {
}
public void setInfo(String info) {
public void setEdgeNode(DistrictNetworkEdgeNode n) {
this.edgeNode = n;
public void setEdgeNode(DistrictNetworkEdgeNode n) {
this.edgeNode = n;
+ // Ensure that origin/location are recalculated
+ prevZoomLevel = -1;
package org.simantics.district.network.ui.styles;
import java.awt.geom.Point2D;
package org.simantics.district.network.ui.styles;
import java.awt.geom.Point2D;
+import java.util.Objects;
import java.util.Set;
import org.simantics.Simantics;
import java.util.Set;
import org.simantics.Simantics;
private static final String PIPELINE_INFO = "pipelineInfo";
public static final String STATIC_INFO_DEFERRED = "staticInfo";
private static final String PIPELINE_INFO = "pipelineInfo";
public static final String STATIC_INFO_DEFERRED = "staticInfo";
public static class StyleResult {
public static class StyleResult {
- public StyleResult(Point2D p1, Point2D p2, String info) {
+ public StyleResult(Resource r, Point2D p1, String info) {
+ this.r = r;
-
- public Point2D p1;
- public Point2D p2;
- public String info;
+
+ public final Resource r;
+ public final Point2D p1;
+ public final String info;
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + r.hashCode();
+ result = prime * result + ((info == null) ? 0 : info.hashCode());
+ result = prime * result + ((p1 == null) ? 0 : p1.hashCode());
+ return result;
+ }
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ StyleResult other = (StyleResult) obj;
+ return r.equals(other.r) && Objects.equals(info, other.info) && Objects.equals(p1, other.p1);
+ }
public DistrictNetworkStaticInfoStyle(Resource style) {
super(style);
}
public DistrictNetworkStaticInfoStyle(Resource style) {
super(style);
}
+
+ private static final Point2D EDGE = new Point2D.Double();
+
@Override
public StyleResult calculateStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource mapElement)
throws DatabaseException {
DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
@Override
public StyleResult calculateStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource mapElement)
throws DatabaseException {
DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
-
- boolean isEdge = graph.isInstanceOf(mapElement, DN.Edge);
- boolean isVertex = graph.isInstanceOf(mapElement, DN.Vertex);
+ Set<Resource> types = graph.getTypes(mapElement);
+ boolean isEdge = types.contains(DN.Edge);
+ boolean isVertex = types.contains(DN.Vertex);
if (!isEdge && !isVertex)
return null;
if (!isEdge && !isVertex)
return null;
if (isEdge) {
Resource diagram = graph.getSingleObject(mapElement, Layer0.getInstance(graph).PartOf);
Set<Resource> edgesToUse = graph.syncRequest(new MidBranchEdgeSetRequest(diagram), TransientCacheListener.instance());
if (!edgesToUse.contains(mapElement))
return null;
}
if (isEdge) {
Resource diagram = graph.getSingleObject(mapElement, Layer0.getInstance(graph).PartOf);
Set<Resource> edgesToUse = graph.syncRequest(new MidBranchEdgeSetRequest(diagram), TransientCacheListener.instance());
if (!edgesToUse.contains(mapElement))
return null;
}
-
- DiagramResource DIA = DiagramResource.getInstance(graph);
- StructuralResource2 STR = StructuralResource2.getInstance(graph);
-
Resource module = DistrictNetworkUtil.getMappedComponentCached(graph, mapElement);
if (module == null)
return null;
Resource module = DistrictNetworkUtil.getMappedComponentCached(graph, mapElement);
if (module == null)
return null;
+ StructuralResource2 STR = StructuralResource2.getInstance(graph);
Resource moduleType = graph.getPossibleType(module, STR.Component);
if (moduleType == null)
return null;
Resource moduleType = graph.getPossibleType(module, STR.Component);
if (moduleType == null)
return null;
Function1<Variable, String> function = getUCPipelineInfoFunctionCached(graph, moduleType);
if (function == null)
return null;
Function1<Variable, String> function = getUCPipelineInfoFunctionCached(graph, moduleType);
if (function == null)
return null;
String result;
try {
Variable variable = Variables.getVariable(graph, module);
String result;
try {
Variable variable = Variables.getVariable(graph, module);
} catch (PendingVariableException | MissingVariableValueException e) {
result = null;
} catch (MissingVariableException e) {
} catch (PendingVariableException | MissingVariableValueException e) {
result = null;
} 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 = "<" + message + ">";
+ // the requested variable is missing from the UC
+ String message = e.getMessage();
+ LOGGER.warn("Missing variable for calculating style with function {} {}", function, message);
+ result = "<" + message + ">";
+ DiagramResource DIA = DiagramResource.getInstance(graph);
double[] coords = graph.getRelatedValue(mapElement, DIA.HasLocation);
Point2D p = DistrictNetworkNodeUtils.calculatePoint2D(new Point2D.Double(coords[0], coords[1]), null);
double[] coords = graph.getRelatedValue(mapElement, DIA.HasLocation);
Point2D p = DistrictNetworkNodeUtils.calculatePoint2D(new Point2D.Double(coords[0], coords[1]), null);
- return new StyleResult(p, p, result);
- }
- else if (isEdge) {
- 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);
- Point2D p1 = DistrictNetworkNodeUtils.calculatePoint2D(new Point2D.Double(coords1[0], coords1[1]), null);
- Point2D p2 = DistrictNetworkNodeUtils.calculatePoint2D(new Point2D.Double(coords2[0], coords2[1]), null);
-
- return new StyleResult(p1, p2, result);
+ return new StyleResult(mapElement, p, result);
+ } else if (isEdge) {
+ return new StyleResult(mapElement, EDGE, result);
@Override
public void applyStyleForNode(EvaluationContext evaluationContext, INode parent, StyleResult result) {
if (result == null) {
cleanupStyleForNode(evaluationContext, parent);
return;
}
@Override
public void applyStyleForNode(EvaluationContext evaluationContext, INode parent, StyleResult result) {
if (result == null) {
cleanupStyleForNode(evaluationContext, parent);
return;
}
ParentNode<?> root = (ParentNode<?>) NodeUtil.getNearestParentOfType(parent, RTreeNode.class);
if (root != null) {
DeferredRenderingNode deferred = ProfileVariables.claimChild(root, "", STATIC_INFO_DEFERRED, DeferredRenderingNode.class, evaluationContext);
deferred.setZIndex(Integer.MAX_VALUE-1);
}
ParentNode<?> root = (ParentNode<?>) NodeUtil.getNearestParentOfType(parent, RTreeNode.class);
if (root != null) {
DeferredRenderingNode deferred = ProfileVariables.claimChild(root, "", STATIC_INFO_DEFERRED, DeferredRenderingNode.class, evaluationContext);
deferred.setZIndex(Integer.MAX_VALUE-1);
}
DistrictNetworkStaticInfoNode node = ProfileVariables.claimChild(parent, "*", DistrictNetworkStaticInfoNode.NODE_KEY, DistrictNetworkStaticInfoNode.class, evaluationContext);
if (node == null)
return;
Point2D p1 = result.p1;
DistrictNetworkStaticInfoNode node = ProfileVariables.claimChild(parent, "*", DistrictNetworkStaticInfoNode.NODE_KEY, DistrictNetworkStaticInfoNode.class, evaluationContext);
if (node == null)
return;
Point2D p1 = result.p1;
- Point2D p2 = result.p2;
-
- if (p1.equals(p2)) {
node.setLocation(p1, new Point2D.Double(1.0, 0.0));
node.setLocation(p1, new Point2D.Double(1.0, 0.0));
- }
- else {
- double sign = Math.signum(p1.getX() - p2.getX());
- Point2D.Double origin = new Point2D.Double(0.5 * (p1.getX() + p2.getX()), 0.5 * (p1.getY() + p2.getY()));
- Point2D direction = new Point2D.Double(0.5 * sign * (p1.getX() - p2.getX()), 0.5 * sign * (p1.getY() - p2.getY()));
-
- node.setLocation(origin, direction);
-
+ } else {
+ // StaticInfoNode takes care of positioning the text during render
+ // based on the found DistrictNetworkEdgeNode's information.
for (IG2DNode n : ((ConnectionNode)parent).getNodes()) {
if (n instanceof DistrictNetworkEdgeNode) {
node.setEdgeNode((DistrictNetworkEdgeNode) n);
}
}
}
for (IG2DNode n : ((ConnectionNode)parent).getNodes()) {
if (n instanceof DistrictNetworkEdgeNode) {
node.setEdgeNode((DistrictNetworkEdgeNode) n);
}
}
}
node.setInfo(result.info);
}
node.setInfo(result.info);
}
private static Function1<Variable, String> getUCPipelineInfoFunctionCached(ReadGraph graph, Resource componentType)
throws DatabaseException {
return graph.syncRequest(new UCPipelineInfoRequest(componentType), TransientCacheListener.instance());
}
private static Function1<Variable, String> getUCPipelineInfoFunctionCached(ReadGraph graph, Resource componentType)
throws DatabaseException {
return graph.syncRequest(new UCPipelineInfoRequest(componentType), TransientCacheListener.instance());
}
private static final class UCPipelineInfoRequest extends ResourceRead<Function1<Variable, String>> {
public UCPipelineInfoRequest(Resource resource) {
super(resource);
private static final class UCPipelineInfoRequest extends ResourceRead<Function1<Variable, String>> {
public UCPipelineInfoRequest(Resource resource) {
super(resource);
Resource actionsModule = Layer0Utils.getPossibleChild(graph, resource, ACTIONS_MODULE);
if (actionsModule == null || !graph.isInstanceOf(actionsModule, Layer0.getInstance(graph).SCLModule))
return null;
Resource actionsModule = Layer0Utils.getPossibleChild(graph, resource, ACTIONS_MODULE);
if (actionsModule == null || !graph.isInstanceOf(actionsModule, Layer0.getInstance(graph).SCLModule))
return null;
String uri = graph.getURI(actionsModule);
SCLContext sclContext = SCLContext.getCurrent();
Object oldGraph = sclContext.get("graph");
String uri = graph.getURI(actionsModule);
SCLContext sclContext = SCLContext.getCurrent();
Object oldGraph = sclContext.get("graph");
@Override
protected void cleanupStyleForNode(EvaluationContext evaluationContext, INode node) {
ProfileVariables.denyChild(node, "*", DistrictNetworkStaticInfoNode.NODE_KEY);
}
@Override
protected void cleanupStyleForNode(EvaluationContext evaluationContext, INode node) {
ProfileVariables.denyChild(node, "*", DistrictNetworkStaticInfoNode.NODE_KEY);
}