From: jsimomaa Date: Fri, 5 May 2017 04:31:32 +0000 (+0300) Subject: Combination of Simantics-platform related changes and fixes for district X-Git-Tag: v1.31.0~264^2~27 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F47%2F747%2F5;p=simantics%2Fplatform.git Combination of Simantics-platform related changes and fixes for district Some platform changes for district Change-Id: Ib7aa44432f3e468ca11542debf33191b8403c742 Some more fixes to platform for district Change-Id: Ifd718c20d5a98806e93c365b45ce3bdd003b4118 --- diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/NodeRequest.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/NodeRequest.java index a6f2e0a77..198b4b341 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/NodeRequest.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/NodeRequest.java @@ -11,6 +11,8 @@ *******************************************************************************/ package org.simantics.diagram.adapter; +import java.util.List; + import org.simantics.db.AsyncReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.primitiverequest.Adapter; @@ -20,6 +22,7 @@ import org.simantics.db.procedure.Listener; import org.simantics.diagram.synchronization.ErrorHandler; import org.simantics.g2d.canvas.ICanvasContext; import org.simantics.g2d.diagram.IDiagram; +import org.simantics.g2d.diagram.handler.SubstituteElementClass; import org.simantics.g2d.element.ElementClass; import org.simantics.g2d.element.IElement; import org.slf4j.Logger; @@ -110,8 +113,12 @@ public class NodeRequest extends BaseRequest2 { } @Override - public void execute(AsyncReadGraph graph, final ElementClass clazz) { - + public void execute(AsyncReadGraph graph, ElementClass mutableClazz) { + List substitutes = diagram.getDiagramClass().getItemsByClass(SubstituteElementClass.class); + for (SubstituteElementClass subs : substitutes) { + mutableClazz = subs.substitute(diagram, mutableClazz); + } + final ElementClass clazz = mutableClazz; graph.asyncRequest(new SpawnRequest(canvas, clazz, data), new TransientCacheAsyncListener() { @Override diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayerManager.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayerManager.java index 41947ef99..e92ce1b41 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayerManager.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayerManager.java @@ -433,8 +433,10 @@ public class GraphLayerManager { graph.forHasStatement(element, gl.getVisible(), element, new AsyncProcedureAdapter() { @Override public void execute(AsyncReadGraph graph, Boolean result) { - synchronized (visible) { - visible.add(l); + if (result) { + synchronized (visible) { + visible.add(l); + } } if (DEBUG_LAYERS) System.out.println(" Visible on layer '" + gl.getName() + "'"); @@ -452,8 +454,10 @@ public class GraphLayerManager { graph.forHasStatement(element, gl.getFocusable(), element, new AsyncProcedureAdapter() { @Override public void execute(AsyncReadGraph graph, Boolean result) { - synchronized (focusable) { - focusable.add(l); + if (result) { + synchronized (focusable) { + focusable.add(l); + } } if (DEBUG_LAYERS) System.out.println(" Focusable on layer '" + gl.getName() + "'"); 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 d69ef69c6..eb9e33607 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 @@ -1012,8 +1012,9 @@ public class ElementPainter extends AbstractDiagramParticipant implements Compos Shape shape = ElementUtils.getElementShapeOrBounds(e); Rectangle2D bounds = shape.getBounds2D(); //System.out.println("selection bounds: "+bounds); - final double margin = 1; - bounds.setFrame(bounds.getMinX() - margin, bounds.getMinY() - margin, bounds.getWidth() + 2*margin, bounds.getHeight() + 2*margin); + final double marginX = 1 / selectionTransform.getScaleX(); + final double marginY = 1 / selectionTransform.getScaleY(); + bounds.setFrame(bounds.getMinX() - marginX, bounds.getMinY() - marginY, bounds.getWidth() + 2*marginX, bounds.getHeight() + 2*marginY); List ss = e.getElementClass().getItemsByClass(SelectionSpecification.class); if (!ss.isEmpty()) { diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/image/impl/AWTImage.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/image/impl/AWTImage.java index e547a663e..0fbe895be 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/image/impl/AWTImage.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/image/impl/AWTImage.java @@ -34,13 +34,19 @@ public class AWTImage extends AbstractImage implements Image { BufferedImage bi; Rectangle2D rect; + float alpha; - public AWTImage(BufferedImage bi) { + public AWTImage(BufferedImage bi, float alpha) { assert(bi!=null); this.bi = bi; + this.alpha = alpha; rect = new Rectangle2D.Double(bi.getMinX(),bi.getMinY(),bi.getWidth(), bi.getHeight()); } + public AWTImage(BufferedImage bi) { + this(bi, 1.0f); + } + @Override public Rectangle2D getBounds() { return rect; @@ -55,6 +61,8 @@ public class AWTImage extends AbstractImage implements Image { public Node init(G2DParentNode parent) { ImageNode node = parent.getOrCreateNode("image", ImageNode.class); node.setImage(bi); + node.setAlpha(alpha); + node.setZIndex(-100); return node; } diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/RulerPainter.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/RulerPainter.java index e4f90791e..bffe0c9df 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/RulerPainter.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/RulerPainter.java @@ -102,17 +102,21 @@ public class RulerPainter extends AbstractCanvasParticipant { @SGInit public void initSG(G2DParentNode parent) { - node = parent.addNode("ruler", RulerNode.class); + node = parent.addNode("ruler", getNodeClass()); node.setZIndex(PAINT_PRIORITY); updateNode(); } + protected Class getNodeClass() { + return RulerNode.class; + } + @SGCleanup public void cleanupSG() { node.remove(); } - void updateNode() { + protected void updateNode() { node.setEnabled(isPaintingEnabled()); node.setGridSize(getGridSize()); } diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/e4/ImportSVGPNG.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/e4/ImportSVGPNG.java index 931bfdf3d..b864c4bcf 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/e4/ImportSVGPNG.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/e4/ImportSVGPNG.java @@ -36,7 +36,12 @@ import org.simantics.db.common.request.IndexRoot; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.db.request.Read; +import org.simantics.diagram.synchronization.IModifiableSynchronizationContext; +import org.simantics.diagram.synchronization.SynchronizationHints; +import org.simantics.diagram.synchronization.graph.GraphSynchronizationHints; +import org.simantics.diagram.synchronization.graph.layer.GraphLayerManager; import org.simantics.g2d.canvas.ICanvasContext; +import org.simantics.g2d.diagram.IDiagram; import org.simantics.g2d.participant.MouseUtil; import org.simantics.g2d.participant.MouseUtil.MouseInfo; import org.simantics.modeling.ModelingResources; @@ -112,10 +117,12 @@ public class ImportSVGPNG { IResourceEditorInput input = (IResourceEditorInput)viewer.getEditorInput(); Resource composite = input.getResource(); - addSVG(mpos.getX(), mpos.getY(), composite); + IDiagram idiagram = viewer.getAdapter(IDiagram.class); + + addSVG(mpos.getX(), mpos.getY(), composite, idiagram); } - public static void addSVG(final double mposX, final double mposY, final Resource composite) { + public static void addSVG(final double mposX, final double mposY, final Resource composite, IDiagram idiagram) { Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); @@ -135,9 +142,20 @@ public class ImportSVGPNG { @Override public void perform(WriteGraph g) throws DatabaseException { - Commands.get(g, "Simantics/Diagram/createSVGElement") + Object svg = Commands.get(g, "Simantics/Diagram/createSVGElementR") .execute(g, g.syncRequest(new IndexRoot(composite)), composite, suffix(filename), data, mposX, mposY); + + if (svg != null && svg instanceof Resource) { + Resource resource = (Resource) svg; + // 7. Put the element on all the currently active layers if possible. + IModifiableSynchronizationContext context = idiagram.getHint(SynchronizationHints.CONTEXT); + GraphLayerManager glm = context.get(GraphSynchronizationHints.GRAPH_LAYER_MANAGER); + if (glm != null) { + glm.removeFromAllLayers(g, resource); + glm.putElementOnVisibleLayers(idiagram, g, resource); + } + } } }); diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramViewer.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramViewer.java index b5381917d..1762dea7f 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramViewer.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramViewer.java @@ -727,9 +727,7 @@ public class DiagramViewer addKeyBindingParticipants(ctx); // Grid & Ruler & Background - ctx.add(new GridPainter()); - ctx.add(new RulerPainter()); - ctx.add(new BackgroundPainter()); + addGridRulerBackgroundParticipants(ctx); h.setHint(Hints.KEY_DISPLAY_PAGE, diagramPreferences.get(DiagramPreferences.P_DISPLAY_PAGE_SIZE)); h.setHint(Hints.KEY_DISPLAY_MARGINS, diagramPreferences.get(DiagramPreferences.P_DISPLAY_MARGINS)); @@ -776,6 +774,12 @@ public class DiagramViewer ctx.setLocked(false); } + protected void addGridRulerBackgroundParticipants(CanvasContext ctx) { + ctx.add(new GridPainter()); + ctx.add(new RulerPainter()); + ctx.add(new BackgroundPainter()); + } + protected void loadPageSettings(ICanvasContext ctx) { DiagramDesc diagramDesc = null; diff --git a/bundles/org.simantics.modeling/scl/Simantics/Diagram.scl b/bundles/org.simantics.modeling/scl/Simantics/Diagram.scl index bf5c589e8..554a25eda 100644 --- a/bundles/org.simantics.modeling/scl/Simantics/Diagram.scl +++ b/bundles/org.simantics.modeling/scl/Simantics/Diagram.scl @@ -805,8 +805,10 @@ setTransform element transform = claimRelatedValueWithType element DIA.HasTransf importJava "org.simantics.modeling.svg.CreateSVGElement" where createSVGElement :: Resource -> String -> ByteArray -> Double -> Double -> () + createSVGElementR :: Resource -> String -> ByteArray -> Double -> Double -> Resource importSVGElement :: Resource -> File -> Double -> Double -> () + importSVGElementR :: Resource -> File -> Double -> Double -> Resource importJava "org.simantics.diagram.synchronization.graph.RemoveElement" where removeElement :: Resource -> Resource -> () diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/svg/CreateSVGElement.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/svg/CreateSVGElement.java index 994d417c9..1f302a64d 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/svg/CreateSVGElement.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/svg/CreateSVGElement.java @@ -19,6 +19,10 @@ import org.simantics.utils.FileUtils; public class CreateSVGElement { public static void createSVGElement(WriteGraph g, Resource diagram, String suffix, byte[] data, double mposX, double mposY) throws DatabaseException { + createSVGElement(g, diagram, suffix, data, mposX, mposY); + } + + public static Resource createSVGElementR(WriteGraph g, Resource diagram, String suffix, byte[] data, double mposX, double mposY) throws DatabaseException { Layer0 L0 = Layer0.getInstance(g); DiagramResource DIA = DiagramResource.getInstance(g); @@ -50,19 +54,22 @@ public class CreateSVGElement { throw new DatabaseException("Unknown image format " + suffix); OrderedSetUtils.addFirst(g, diagram, element); g.claim(diagram, L0.ConsistsOf, element); - + return element; } - + public static void importSVGElement(WriteGraph graph, Resource diagram, File file, double posX, double posY) throws DatabaseException, IOException { - + importSVGElementR(graph, diagram, file, posX, posY); + } + + public static Resource importSVGElementR(WriteGraph graph, Resource diagram, File file, double posX, double posY) throws DatabaseException, IOException { final byte[] data = FileUtils.readFile(file); - createSVGElement(graph, diagram, suffix(file.getName()), data, posX, posY); + return createSVGElementR(graph, diagram, suffix(file.getName()), data, posX, posY); } - + private static String suffix(String fileName) { int len = fileName.length(); if(len < 3) return null; else return fileName.substring(len-3,len).toLowerCase(); } - + } diff --git a/bundles/org.simantics.platform.ui.ontology/graph/PlatformUIViews.pgraph b/bundles/org.simantics.platform.ui.ontology/graph/PlatformUIViews.pgraph index a265df8b1..eeab91d81 100644 --- a/bundles/org.simantics.platform.ui.ontology/graph/PlatformUIViews.pgraph +++ b/bundles/org.simantics.platform.ui.ontology/graph/PlatformUIViews.pgraph @@ -101,7 +101,7 @@ VIEWS.SharedLibraryContribution : SWT.TypedVariableTabContribution //VIEWS.SharedLibraryContribution2 : SWT.TypedVariableTabContribution // SEL.AbstractVariableTabContribution.HasPriority 1 -// SEL.AbstractTypedVariableTabContribution.HasType L0.SharedOntology +// SEL.AbstractTypedTabContribution.HasType L0.SharedOntology // SWT.TypedVariableTabContribution.HasView SharedLibraries // L0.HasLabel "Shared Libraries" diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/ImageNode.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/ImageNode.java index df35e968e..43cf64eb0 100644 --- a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/ImageNode.java +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/ImageNode.java @@ -11,6 +11,8 @@ *******************************************************************************/ package org.simantics.scenegraph.g2d.nodes; +import java.awt.AlphaComposite; +import java.awt.Composite; import java.awt.Graphics2D; import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; @@ -28,6 +30,7 @@ public class ImageNode extends G2DNode { protected Boolean visible = Boolean.TRUE; protected BufferedImage img = null; + protected float alpha = 1.0f; @SyncField("visible") public void setVisible(Boolean visible) { @@ -50,6 +53,10 @@ public class ImageNode extends G2DNode { img = src; } + public void setAlpha(float alpha) { + this.alpha = Math.max(0.0f, Math.min(alpha, 1.0f)); + } + @Override public void render(Graphics2D g) { if (!visible || img == null) return; @@ -65,8 +72,17 @@ public class ImageNode extends G2DNode { // Rectangle2D b = parent.getBoundsInLocal(); // g.drawImage(img, (int)b.getMinX(), (int)b.getMinY(), (int)b.getWidth()+(int)b.getMinX(), (int)b.getHeight()+(int)b.getMinY(), 0, 0, img.getWidth(), img.getHeight(), null); // } + + Composite old = null; + if (alpha < 1.0f) { + old = g.getComposite(); + g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); + } + g.drawImage(img, 0, 0, null); + if (old != null) + g.setComposite(old); if (ot != null) g.setTransform(ot); } diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/RulerNode.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/RulerNode.java index f7e0d1e5c..27c1c1fd2 100644 --- a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/RulerNode.java +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/RulerNode.java @@ -57,7 +57,7 @@ public class RulerNode extends G2DNode { public void render(Graphics2D g) { if (!enabled) return; - + AffineTransform tr = g.getTransform(); double scaleX = Math.abs(tr.getScaleX()); double scaleY = Math.abs(tr.getScaleY()); @@ -109,7 +109,9 @@ public class RulerNode extends G2DNode { // Vertical ruler for(double x = offsetX%stepX-stepX; x < bounds.getMaxX(); x+=stepX) { if(x > 20) { - String str = formatValue((x-offsetX)/scaleX); + double val = (x-offsetX)/scaleX / getTransform().getScaleX(); + double modifiedValue = modifyHorizontalValue(val); + String str = formatValue(modifiedValue); FontMetrics fm = g.getFontMetrics(); Rectangle2D r = fm.getStringBounds(str, g); if((x-r.getWidth()/2) > previousText) { @@ -140,10 +142,9 @@ public class RulerNode extends G2DNode { previousText = -100; for(double y = offsetY%stepY-stepY; y < bounds.getMaxY(); y+=stepY) { if(y > 20) { - double val = (y-offsetY)/scaleY; - if (MAP_Y_SCALING) - val = Math.toDegrees(Math.atan(Math.sinh(Math.toRadians(val)))); - String str = formatValue(val); + double val = (y-offsetY)/scaleY / getTransform().getScaleY(); + double modifiedValue = modifyVerticalValue(val); + String str = formatValue(modifiedValue); FontMetrics fm = g.getFontMetrics(); Rectangle2D r = fm.getStringBounds(str, g); if(y-1+r.getHeight()/2 > previousText) { @@ -175,6 +176,26 @@ public class RulerNode extends G2DNode { g.setTransform(tr); } + /** + * A method for subclasses to alter the actual X-value of the ruler + * + * @param value + * @return possibly modified X-value + */ + protected double modifyHorizontalValue(double value) { + return value; + } + + /** + * A method for subclasses to alter the actual Y-value of the ruler + * + * @param value + * @return possibly modified Y-value + */ + protected double modifyVerticalValue(double value) { + return value; + } + private static final transient int MAX_DIGITS = 5; private static final transient double EPSILON = 0.01; private static final transient double TRIM_THRESHOLD_MAX_VALUE = Math.pow(10, 4); diff --git a/bundles/org.simantics.ui/src/org/simantics/ui/workbench/e4/E4WorkbenchUtils.java b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/e4/E4WorkbenchUtils.java index 3c1888a01..6d7daeb3c 100644 --- a/bundles/org.simantics.ui/src/org/simantics/ui/workbench/e4/E4WorkbenchUtils.java +++ b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/e4/E4WorkbenchUtils.java @@ -5,6 +5,7 @@ import java.util.Map; import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.ui.model.application.MApplication; +import org.eclipse.e4.ui.model.application.commands.MCommand; import org.eclipse.e4.ui.model.application.ui.MUIElement; import org.eclipse.e4.ui.model.application.ui.advanced.MArea; import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder; @@ -14,9 +15,12 @@ import org.eclipse.e4.ui.model.application.ui.basic.MPartStack; import org.eclipse.e4.ui.workbench.modeling.EModelService; import org.eclipse.e4.ui.workbench.modeling.EPartService; import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState; +import org.eclipse.ui.IEditorPart; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor; import org.simantics.db.Resource; import org.simantics.utils.datastructures.ArrayMap; +import org.simantics.utils.ui.workbench.WorkbenchUtils; /** * @author Tuukka Lehtonen @@ -166,5 +170,32 @@ public class E4WorkbenchUtils { part = partService.createPart(partId); return part; } + + public static MCommand getMCommandById(String id) { + IEclipseContext context = PlatformUI.getWorkbench().getService(IEclipseContext.class); + MApplication application = context.get(MApplication.class); + for (MCommand command : application.getCommands()) { + if (id.equals(command.getElementId())) { + return command; + } + } + return null; + } + @SuppressWarnings("restriction") + public static IEditorPart getActiveIEditorPart(MPart mActiveEditorPart) { + // TODO: Fix this when we get rid of CompatibilityEditors + IEditorPart activeEditor = null; + if (mActiveEditorPart != null) { + Object editor = mActiveEditorPart.getObject(); + if (editor instanceof CompatibilityEditor) { + CompatibilityEditor compEditor = (CompatibilityEditor) editor; + activeEditor = compEditor.getEditor(); + } else { + // TODO: This is not good practice with E4 but an OK fallback for now + activeEditor = WorkbenchUtils.getActiveEditor(); + } + } + return activeEditor; + } }