import org.simantics.maps.MapScalingTransform;
import org.simantics.scenegraph.INode;
import org.simantics.scenegraph.ISelectionPainterNode;
+import org.simantics.scenegraph.INode.PropertySetter;
import org.simantics.scenegraph.g2d.G2DNode;
import org.simantics.scenegraph.g2d.G2DParentNode;
import org.simantics.scenegraph.g2d.nodes.SVGNode;
private transient Rectangle2D symbolRect;
private transient AffineTransform symbolTransform;
+ private boolean hidden = false;
+
private Double arrowLength;
private static double startX;
g2d.transform(getTransform());
}
- Object aaHint = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
- g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
-
- Color oldColor = g2d.getColor();
- BasicStroke oldStroke = (BasicStroke) g2d.getStroke();
-
- BasicStroke bs = null;
+ double scale = 1.0;
if (scaleStroke) {
AffineTransform tr = g2d.getTransform();
scale = DistrictNetworkNodeUtils.getScale(tr);
- bs = GeometryUtils.scaleStroke(STROKE, getStrokeWidth(scale));
- } else {
- bs = STROKE;
- }
- int zoomLevel = MapScalingTransform.zoomLevel(ot);
- path = calculatePath(edge, path, zoomLevel > 15);
-
- if (isSelected()) {
- g2d.setColor(SELECTION_COLOR);
- g2d.setStroke(GeometryUtils.scaleAndOffsetStrokeWidth(bs, 1.f, (float)(2 * STROKE.getLineWidth() / scale)));
- g2d.draw(path);
}
-
- g2d.setColor(dynamicColor != null ? dynamicColor : color);
- g2d.setStroke(bs);
- g2d.draw(path);
-
- // Draw arrow
- if (arrowLength != null) {
- g2d.setColor(Color.BLACK);
- g2d.setStroke(new BasicStroke(bs.getLineWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
-
- double l = arrowLength;
- double w = 2 * (double) bs.getLineWidth() * Math.signum(l);
- if (Math.abs(w) > Math.abs(l)) w = l;
- double offset = 2 * (double) bs.getLineWidth();
-
- double centerX = (startX + endX) / 2, centerY = (startY + endY) / 2;
- double deltaX = endX - startX, deltaY = endY - startY;
- double length = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
- deltaX /= length;
- deltaY /= length;
-
- double x0 = centerX - l/2 * deltaX + offset * deltaY;
- double y0 = centerY - l/2 * deltaY - offset * deltaX;
- double x1 = centerX + (l/2 - w) * deltaX + offset * deltaY;
- double y1 = centerY + (l/2 - w) * deltaY - offset * deltaX;
+
+ if (!hidden) {
+ Object aaHint = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
+ g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+
+ Color oldColor = g2d.getColor();
+ BasicStroke oldStroke = (BasicStroke) g2d.getStroke();
+
+ BasicStroke bs = null;
+ if (scaleStroke) {
+ bs = GeometryUtils.scaleStroke(STROKE, getStrokeWidth(scale));
+ } else {
+ bs = STROKE;
+ }
- g2d.draw(new Line2D.Double(x0, y0, x1, y1));
+ int zoomLevel = MapScalingTransform.zoomLevel(ot);
+ path = calculatePath(edge, path, zoomLevel > 15);
+
+ if (isSelected()) {
+ g2d.setColor(SELECTION_COLOR);
+ g2d.setStroke(GeometryUtils.scaleAndOffsetStrokeWidth(bs, 1.f, (float)(2 * STROKE.getLineWidth() / scale)));
+ g2d.draw(path);
+ }
+
+ g2d.setColor(dynamicColor != null ? dynamicColor : color);
+ g2d.setStroke(bs);
+ g2d.draw(path);
+
+ // Draw arrow
+ if (arrowLength != null) {
+ g2d.setColor(Color.BLACK);
+ float lw = STROKE.getLineWidth() / (float)scale;
+ g2d.setStroke(new BasicStroke(lw, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
+
+ double l = arrowLength;
+ double w = 2 * (double) lw * Math.signum(l);
+ if (Math.abs(w) > Math.abs(l)) w = l;
+ double offset = 2 * (double) lw;
+
+ double centerX = (startX + endX) / 2, centerY = (startY + endY) / 2;
+ double deltaX = endX - startX, deltaY = endY - startY;
+ double length = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
+ deltaX /= length;
+ deltaY /= length;
+
+ double x0 = centerX - l/2 * deltaX + offset * deltaY;
+ double y0 = centerY - l/2 * deltaY - offset * deltaX;
+ double x1 = centerX + (l/2 - w) * deltaX + offset * deltaY;
+ double y1 = centerY + (l/2 - w) * deltaY - offset * deltaX;
+
+ g2d.draw(new Line2D.Double(x0, y0, x1, y1));
+
+ Path2D path = new Path2D.Double();
+ path.moveTo(x1 + w * deltaX, y1 + w * deltaY);
+ path.lineTo(x1 + w * deltaY, y1 - w * deltaX);
+ path.lineTo(x1 - w * deltaY, y1 + w * deltaX);
+ path.closePath();
+ g2d.fill(path);
+ }
- Path2D path = new Path2D.Double();
- path.moveTo(x1 + w * deltaX, y1 + w * deltaY);
- path.lineTo(x1 + w * deltaY, y1 - w * deltaX);
- path.lineTo(x1 - w * deltaY, y1 + w * deltaX);
- path.closePath();
- g2d.fill(path);
- }
-
- // Reset
- g2d.setStroke(oldStroke);
- g2d.setColor(oldColor);
-
- // Render SVG symbol
- double viewScaleRecip = 10;
- if (scaleStroke) {
- double scale = GeometryUtils.getScale(g2d.getTransform());
- scale = Math.max(10000, Math.min(scale, 50000));
- viewScaleRecip /= scale;
+ // Reset
+ g2d.setStroke(oldStroke);
+ g2d.setColor(oldColor);
+ g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, aaHint);
}
-
- Point2D p = getCenterPoint();
- symbolRect = DistrictNetworkNodeUtils.calculateDrawnGeometry(p, NORMAL, symbolRect, viewScaleRecip);
- symbolTransform = DistrictNetworkNodeUtils.getTransformToRectangle(symbolRect, symbolTransform);
-
+
for (INode nn : getNodes()) {
G2DNode g2dNode = (G2DNode)nn;
- if (g2dNode instanceof SVGNode)
+ if (g2dNode instanceof SVGNode) {
+ // Render SVG symbol
+ double viewScaleRecip = 10;
+ if (scaleStroke) {
+ viewScaleRecip /= scale;
+ }
+
+ Point2D p = getCenterPoint();
+ symbolRect = DistrictNetworkNodeUtils.calculateDrawnGeometry(p, NORMAL, symbolRect, viewScaleRecip);
+ symbolTransform = DistrictNetworkNodeUtils.getTransformToRectangle(symbolRect, symbolTransform);
+
g2dNode.setTransform(symbolTransform);
+ }
g2dNode.render(g2d);
}
- g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, aaHint);
-
if (ot != null)
g2d.setTransform(ot);
}
((SVGNode)nn).setData(value);
}
+
+ @PropertySetter(value = "hidden")
+ public void setHidden(Boolean value) {
+ this.hidden = value;
+ }
}
private double nodeSize = 1.0;
+ private boolean hidden = false;
+
@Override
public void init() {
setZIndex(2);
@Override
public void render(Graphics2D g2d) {
- if (nodeSize <= 0.0)
- return;
-
AffineTransform ot = null;
AffineTransform t = getTransform();
if (t != null && !t.isIdentity()) {
g2d.transform(t);
}
- Object oaaHint = null;
- Object aaHint = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
- if (aaHint != RenderingHints.VALUE_ANTIALIAS_OFF) {
- oaaHint = aaHint;
- g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
- }
-
- Color oldColor = g2d.getColor();
- Color newColor = dynamicColor != null ? dynamicColor : color;
- boolean changeColor = !oldColor.equals(newColor);
-
+ // Translate lat and lon to X and Y
+ Point2D p = point = DistrictNetworkNodeUtils.calculatePoint2D(vertex.getPoint(), point);
+
double viewScaleRecip = 1;
if (scaleStroke) {
viewScaleRecip *= DistrictNetworkNodeUtils.calculateScaleRecip(g2d.getTransform());
}
- double scaleRecip = viewScaleRecip * nodeSize;
-
- // Translate lat and lon to X and Y
- Point2D p = point = DistrictNetworkNodeUtils.calculatePoint2D(vertex.getPoint(), point);
- Rectangle2D toDraw = rect = DistrictNetworkNodeUtils.calculateDrawnGeometry(p, hover ? HOVERED : NORMAL, rect, scaleRecip);
-
- if (NodeUtil.isSelected(this, 1)) {
- changeColor = true;
- g2d.setColor(SELECTION_COLOR);
- BasicStroke ss = GeometryUtils.scaleStroke(STROKE, (float)viewScaleRecip);
- g2d.setStroke(ss);
- g2d.draw(toDraw);
- }
-
- // render
- if (changeColor)
- g2d.setColor(newColor);
- g2d.fill(toDraw);
- // Reset settings
- if (changeColor)
- g2d.setColor(oldColor);
- if (oaaHint != null)
- g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, aaHint);
+ if (!hidden && nodeSize > 0.0) {
+ Object oaaHint = null;
+ Object aaHint = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
+ if (aaHint != RenderingHints.VALUE_ANTIALIAS_OFF) {
+ oaaHint = aaHint;
+ g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
+ }
+
+ Color oldColor = g2d.getColor();
+ Color newColor = dynamicColor != null ? dynamicColor : color;
+ boolean changeColor = !oldColor.equals(newColor);
+
+ double scaleRecip = viewScaleRecip * nodeSize;
+
+ Rectangle2D toDraw = rect = DistrictNetworkNodeUtils.calculateDrawnGeometry(p, hover ? HOVERED : NORMAL, rect, scaleRecip);
+
+ if (NodeUtil.isSelected(this, 1)) {
+ changeColor = true;
+ g2d.setColor(SELECTION_COLOR);
+ BasicStroke ss = GeometryUtils.scaleStroke(STROKE, (float)viewScaleRecip);
+ g2d.setStroke(ss);
+ g2d.draw(toDraw);
+ }
+
+ // render
+ if (changeColor)
+ g2d.setColor(newColor);
+ g2d.fill(toDraw);
+
+ // Reset settings
+ if (changeColor)
+ g2d.setColor(oldColor);
+ if (oaaHint != null)
+ g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, aaHint);
+ }
// Render SVG symbol
for (INode nn : getNodes()) {
G2DNode g2dNode = (G2DNode)nn;
if (nn instanceof SVGNode) {
+ Rectangle2D toDraw = rect = DistrictNetworkNodeUtils.calculateDrawnGeometry(p, hover ? HOVERED : NORMAL, rect, viewScaleRecip);
symbolTransform = DistrictNetworkNodeUtils.getTransformToRectangle(toDraw, symbolTransform);
g2dNode.setTransform(symbolTransform);
}
this.dynamicColor = color;
}
+ @PropertySetter(value = "hidden")
+ public void setHidden(Boolean value) {
+ this.hidden = value;
+ }
}
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
import org.simantics.db.exception.DatabaseException;
-import org.simantics.diagram.profile.ProfileKeys;
import org.simantics.diagram.profile.StyleBase;
-import org.simantics.g2d.diagram.IDiagram;
-import org.simantics.g2d.diagram.handler.DataElementMap;
-import org.simantics.g2d.element.ElementUtils;
-import org.simantics.g2d.element.IElement;
import org.simantics.scenegraph.INode;
import org.simantics.scenegraph.g2d.nodes.SingleElementNode;
-import org.simantics.scenegraph.profile.DataNodeMap;
import org.simantics.scenegraph.profile.EvaluationContext;
+import org.simantics.scenegraph.profile.common.ProfileVariables;
/**
* @author Tuukka Lehtonen
}
@Override
- public void applyStyleForItem(EvaluationContext evaluationContext, DataNodeMap map, Object item, Boolean value) {
- INode node = map.getNode(item);
- if (node == null) {
- evaluationContext.update();
- return;
- }
-
- IDiagram diagram = evaluationContext.getConstant(ProfileKeys.DIAGRAM);
- DataElementMap emap = diagram.getDiagramClass().getSingleItem(DataElementMap.class);
- IElement element = emap.getElement(diagram, item);
- if (element == null)
- return;
-
- hideElements(evaluationContext, diagram, element, node);
+ public void applyStyleForNode(EvaluationContext evaluationContext, INode node, Boolean result) {
+ SingleElementNode n = (SingleElementNode) node;
+ for (INode nn : n.getNodes())
+ ProfileVariables.claimNodeProperty(nn, "hidden", true, evaluationContext);
}
-
+
@Override
- protected void cleanupStyleForItem(EvaluationContext evaluationContext, DataNodeMap map, Object item) {
- IDiagram diagram = evaluationContext.getConstant(ProfileKeys.DIAGRAM);
- DataElementMap emap = diagram.getDiagramClass().getSingleItem(DataElementMap.class);
-
- INode node = map.getNode(item);
- if (node == null)
- return;
- IElement element = emap.getElement(diagram, item);
- if (element == null)
- return;
-
- showElements(diagram, element, node);
- }
-
- protected void hideElements(EvaluationContext evaluationContext, IDiagram diagram, IElement element, INode node) {
- setVisibility(element, node, false);
- }
-
- protected void showElements(IDiagram diagram, IElement element, INode node) {
- setVisibility(element, node, true);
- }
-
- protected void setVisibility(IElement element, INode node, boolean visible) {
- if (element != null)
- ElementUtils.setHidden(element, !visible);
- if (node instanceof SingleElementNode) {
- ((SingleElementNode) node).setHidden(!visible);
- }
+ protected void cleanupStyleForNode(EvaluationContext evaluationContext, INode node) {
+ SingleElementNode n = (SingleElementNode) node;
+ for (INode nn : n.getNodes())
+ ProfileVariables.claimNodeProperty(nn, "hidden", false, evaluationContext);
}
@Override