]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Some platform changes for district
authorjsimomaa <jani.simomaa@gmail.com>
Fri, 5 May 2017 04:31:32 +0000 (07:31 +0300)
committerjsimomaa <jani.simomaa@gmail.com>
Tue, 27 Jun 2017 07:53:18 +0000 (10:53 +0300)
Change-Id: Ib7aa44432f3e468ca11542debf33191b8403c742

12 files changed:
bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/NodeRequest.java
bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayerManager.java
bundles/org.simantics.g2d/src/org/simantics/g2d/image/impl/AWTImage.java
bundles/org.simantics.g2d/src/org/simantics/g2d/participant/RulerPainter.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/e4/ImportSVGPNG.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramViewer.java
bundles/org.simantics.modeling/scl/Simantics/Diagram.scl
bundles/org.simantics.modeling/src/org/simantics/modeling/svg/CreateSVGElement.java
bundles/org.simantics.platform.ui.ontology/graph/PlatformUIViews.pgraph
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/ImageNode.java
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/RulerNode.java
bundles/org.simantics.ui/src/org/simantics/ui/workbench/e4/E4WorkbenchUtils.java

index a6f2e0a77f4f354c146f98d52e38072a0f1cb7fd..198b4b341114616aa75137b7a719f8162ccaf40d 100644 (file)
@@ -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<Resource, IElement> {
                             }
 
                             @Override
-                            public void execute(AsyncReadGraph graph, final ElementClass clazz) {
-
+                            public void execute(AsyncReadGraph graph, ElementClass mutableClazz) {
+                                List<SubstituteElementClass> 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<IElement>() {
 
                                     @Override
index 41947ef993c49bc937b39eedddb0a0cbf3d25460..e92ce1b41da779df96b1d08359241a7b959fa6b1 100644 (file)
@@ -433,8 +433,10 @@ public class GraphLayerManager {
                 graph.forHasStatement(element, gl.getVisible(), element, new AsyncProcedureAdapter<Boolean>() {
                     @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<Boolean>() {
                     @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() + "'");
index e547a663e8e8844024f110485ee85ba81d7ee302..b6c6f891851fbe24673d85a3af3f8decf62077c0 100644 (file)
@@ -34,12 +34,18 @@ 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() {
@@ -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;
     }
 
index e4f90791e2123b8fa1c01bf1566ae82de90ac0f7..74a5f358674009cc44b2ae52ef731c6e579a9997 100644 (file)
@@ -102,11 +102,15 @@ 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<? extends RulerNode> getNodeClass() {
+        return RulerNode.class;
+    }
+
     @SGCleanup
     public void cleanupSG() {
         node.remove();
index 931bfdf3d60d073c0b63c271dbda2c163f060c41..e3cbb5a7cba7e4b9bb8693b38b758986617e5755 100644 (file)
@@ -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);
+                        }
+                    }
                 }
 
             });
index b5381917d4b8acd3dd2e03f571b8a334d273e6de..1762dea7f6108d34b0a265731387adc9325cb002 100644 (file)
@@ -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;
 
index bf5c589e85f8f2a248d55a71c5244bc1332b2fae..554a25edad081a50f4388688d19820b359440942 100644 (file)
@@ -805,8 +805,10 @@ setTransform element transform = claimRelatedValueWithType element DIA.HasTransf
     
 importJava "org.simantics.modeling.svg.CreateSVGElement" where
     createSVGElement :: Resource -> String -> ByteArray -> Double -> Double -> <WriteGraph> ()
+    createSVGElementR :: Resource -> String -> ByteArray -> Double -> Double -> <WriteGraph> Resource
     
     importSVGElement :: Resource -> File -> Double -> Double -> <WriteGraph> ()
+    importSVGElementR :: Resource -> File -> Double -> Double -> <WriteGraph> Resource
     
 importJava "org.simantics.diagram.synchronization.graph.RemoveElement" where
     removeElement :: Resource -> Resource -> <WriteGraph> ()
index 994d417c99b815ba4c3deae54511777a84e8fc05..c0d2081480c51cd7941a1d1d15f0c6e43132fe80 100644 (file)
@@ -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,13 +54,17 @@ 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) {
index a265df8b136b86e9711d84843e5b8417d3e9cba3..eeab91d816030948d4c98212a87b9dcca30915eb 100644 (file)
@@ -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"
 
index df35e968ef41501bd537425e97a513759719d747..36112a15ed265b8344d2d5c14f0eb9e896d4675c 100644 (file)
@@ -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) {
@@ -49,6 +52,10 @@ public class ImageNode extends G2DNode {
     public void setImage(BufferedImage src) {
         img = src;
     }
+    
+    public void setAlpha(float alpha) {
+        this.alpha = alpha;
+    }
 
     @Override
     public void render(Graphics2D g) {
@@ -65,8 +72,15 @@ 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 = g.getComposite();
+        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f));
+        
         g.drawImage(img, 0, 0, null);
 
+        if (old != null)
+            g.setComposite(old);
         if (ot != null)
             g.setTransform(ot);
     }
index f7e0d1e5c6b5cb05d280b9a5ae514758723b2370..daec9e55e2a80c1143426228c098572ad206f89f 100644 (file)
@@ -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;
+                double modifiedValue = modifyHorizontalValue(val);
+                String str = formatValue(modifiedValue);
                 FontMetrics fm = g.getFontMetrics();
                 Rectangle2D r = fm.getStringBounds(str, g);
                 if((x-r.getWidth()/2) > previousText) {
@@ -141,9 +143,8 @@ public class RulerNode extends G2DNode {
         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 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);
index 3c1888a0112c2c2f382e82c05915372ce51d440d..6d7daeb3c6ff191f8e04e444240bf99776f699d3 100644 (file)
@@ -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;
+    }
 }