From: Antti Villberg Date: Mon, 12 Nov 2018 07:19:58 +0000 (+0200) Subject: Add customisation possibilities for SelectionNode X-Git-Tag: v1.43.0~136^2~284^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F47%2F2447%2F1;p=simantics%2Fplatform.git Add customisation possibilities for SelectionNode gitlab #191 Change-Id: I400ef4099128845792498377e058103e8fbff065 --- diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/ElementPainter.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/ElementPainter.java index 6e9ff85b1..71b87c714 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/ElementPainter.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/ElementPainter.java @@ -137,7 +137,7 @@ public class ElementPainter extends AbstractDiagramParticipant implements Compos * ElementPainter. */ public static interface ISelectionProvider { - public void init(final IElement e, final G2DParentNode parentNode, final String nodeId, + public void init(int selectionId, final IElement e, final G2DParentNode parentNode, final String nodeId, final AffineTransform transform, final Rectangle2D bounds, final Color color); } @@ -953,7 +953,7 @@ public class ElementPainter extends AbstractDiagramParticipant implements Compos continue; if (NodeUtil.needSelectionPaint(elementNode)) - paintSelectionFrame(elementNode, selectionNode, el, color); + paintSelectionFrame(selectionId, elementNode, selectionNode, el, color); nodesUpdated = true; } @@ -999,7 +999,7 @@ public class ElementPainter extends AbstractDiagramParticipant implements Compos createSelectionReference(selectionsNode, elementNode); if (NodeUtil.needSelectionPaint(elementNode)) - paintSelectionFrame(en, selectionNode, e, color); + paintSelectionFrame(selectionId, en, selectionNode, e, color); } else { if (elementNode != null) { @@ -1027,7 +1027,7 @@ public class ElementPainter extends AbstractDiagramParticipant implements Compos return result; } - public void paintSelectionFrame(G2DParentNode elementNode, G2DParentNode selectionNode, final IElement e, Color color) { + public void paintSelectionFrame(int selectionId, G2DParentNode elementNode, G2DParentNode selectionNode, final IElement e, Color color) { // The element node already has the correct transform. AffineTransform selectionTransform = ElementUtils.getTransform(e);// no it doesnt ... new AffineTransform(); Shape shape = ElementUtils.getElementShapeOrBounds(e); @@ -1104,10 +1104,10 @@ public class ElementPainter extends AbstractDiagramParticipant implements Compos ISelectionProvider provider = this.getContext().getDefaultHintContext().getHint(KEY_SELECTION_PROVIDER); if (provider != null) { - provider.init(e, selectionNode, getNodeId("shape", e), selectionTransform, bounds, color); + provider.init(selectionId, e, selectionNode, getNodeId("shape", e), selectionTransform, bounds, color); } else { SelectionNode s = selectionNode.getOrCreateNode(getNodeId("shape", e), SelectionNode.class); - s.init(selectionTransform, bounds, color); + s.init(selectionId, selectionTransform, bounds, color); Double paddingFactor = diagram.getHint(DiagramHints.SELECTION_PADDING_SCALE_FACTOR); if (paddingFactor != null) s.setPaddingFactor(paddingFactor); diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/gallery/GalleryViewer.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/gallery/GalleryViewer.java index ce5687e84..5bbe9f26e 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/gallery/GalleryViewer.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/gallery/GalleryViewer.java @@ -673,7 +673,7 @@ public class GalleryViewer extends ContentViewer { static class GalleryItemPainter extends ElementPainter { @Override - public void paintSelectionFrame(G2DParentNode elementNode, G2DParentNode selectionNode, IElement e, Color color) { + public void paintSelectionFrame(int selectionId, G2DParentNode elementNode, G2DParentNode selectionNode, IElement e, Color color) { final Shape outline = ElementUtils.getElementBoundsOnDiagram(e); Rectangle2D bounds = outline.getBounds2D(); GeometryUtils.expandRectangle(bounds, 2, 2, 2, 2); diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/SCLScenegraph.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/SCLScenegraph.java index 55ed12656..630e41abe 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/SCLScenegraph.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/SCLScenegraph.java @@ -821,7 +821,7 @@ public class SCLScenegraph { parentBuilder.append(SELECTION_SECTION, "\n"); parentBuilder.append(MAIN_SECTION, "\n"); - } else if (node instanceof SelectionNode) { + } else if (isSelection0(node)) { SelectionNode n = (SelectionNode)node; SingleElementNode parentSEN = (SingleElementNode)NodeUtil.getNearestParentOfType(node, SingleElementNode.class); @@ -849,6 +849,14 @@ public class SCLScenegraph { parentBuilder2.append(SELECTION_MASK_SECTION,"\n"); } + } else if (node instanceof SelectionNode) { + + Element doc = renderSVGNode(svgGenerator, (IG2DNode)node); + String svg = printSVGDocument(doc); + parentBuilder.append(MAIN_SECTION, ""); + parentBuilder.append(MAIN_SECTION, svg); + parentBuilder.append(MAIN_SECTION, "\n"); + } else if (node instanceof SVGNode) { SVGNode svg = (SVGNode)node; parentBuilder.append(MAIN_SECTION, svg.getSVGText()); @@ -882,6 +890,17 @@ public class SCLScenegraph { } + private boolean isSelection0(IG2DNode node) { + + if(node instanceof SelectionNode) { + SelectionNode sn = (SelectionNode)node; + return sn.getSelectionId() == 0; + } else { + return false; + } + + } + private RenderSVGContext getParentBuilder(IG2DNode node) { INode parentSEN = NodeUtil.getNearestParentOfType(node, SingleElementNode.class); diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/SelectionNode.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/SelectionNode.java index bd09c4574..98aaebb25 100644 --- a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/SelectionNode.java +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/SelectionNode.java @@ -11,8 +11,10 @@ *******************************************************************************/ package org.simantics.scenegraph.g2d.nodes; +import java.awt.AlphaComposite; import java.awt.BasicStroke; import java.awt.Color; +import java.awt.Composite; import java.awt.Graphics2D; import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; @@ -35,9 +37,14 @@ public class SelectionNode extends G2DNode implements Decoration { protected transient Rectangle2D rect; protected transient BasicStroke scaledStroke; protected transient double previousScaleRecip = Double.NaN; - private boolean ignore = false; - private double paddingFactor = 5.0; + protected boolean ignore = false; + protected double paddingFactor = 5.0; + protected int selectionId; + public int getSelectionId() { + return selectionId; + } + public void setIgnore(boolean value) { ignore = value; } @@ -47,12 +54,17 @@ public class SelectionNode extends G2DNode implements Decoration { } @SyncField({"transform", "bounds", "color"}) - public void init(AffineTransform transform, Rectangle2D bounds, Color color) { + public void init(int selectionId, AffineTransform transform, Rectangle2D bounds, Color color) { + this.selectionId = selectionId; this.transform = transform; this.bounds = bounds; this.color = color; } + public void init(AffineTransform transform, Rectangle2D bounds, Color color) { + init(0, transform, bounds, color); + } + @Override public void render(Graphics2D g) { if (bounds == null) return;