]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Added mechanism to diagram IFlagType to prevent graph modifications 06/506/2
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 11 May 2017 11:19:32 +0000 (14:19 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 11 May 2017 11:20:33 +0000 (14:20 +0300)
When diagram flags are loaded, some implementations trigger graph
modifications because the flag type may know the flag to have wrong
direction information based on analysis of the model. Printing diagrams
to PDF or SVG should not modify the database in any way, just trust what
is in there.

refs #7208

Change-Id: Id2d438c0523ed708a0d11219a8efd6954ac5000e

bundles/org.simantics.diagram.svg/src/org/simantics/diagram/svg/export/DiagramToSVG.java
bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/FlagClassFactory.java
bundles/org.simantics.diagram/src/org/simantics/diagram/flag/IFlagType.java
bundles/org.simantics.g2d/src/org/simantics/g2d/canvas/Hints.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/pdf/PDFPainter.java

index 555be8be7d1cf68224a7e38c0e4bc78043567f55..9964592f95c6136eed0b38a426fc840db49e4ca3 100644 (file)
@@ -20,6 +20,7 @@ import org.simantics.db.request.Read;
 import org.simantics.diagram.elements.DiagramNodeUtil;
 import org.simantics.diagram.export.ImagePrinter;
 import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.g2d.canvas.Hints;
 import org.simantics.g2d.canvas.impl.CanvasContext;
 import org.simantics.g2d.scenegraph.ICanvasSceneGraphProvider;
 import org.simantics.layer0.Layer0;
@@ -132,6 +133,7 @@ public class DiagramToSVG {
                thread.start();
                
         final CanvasContext ctx = new CanvasContext(thread);
+        ctx.getDefaultHintContext().setHint(Hints.KEY_DISABLE_GRAPH_MODIFICATIONS, Boolean.TRUE);
         final AtomicReference<ICanvasSceneGraphProvider> sgProvider = new AtomicReference<ICanvasSceneGraphProvider>();
                final ISessionContext sessionContext = Simantics.getSessionContext();
                final DataContainer<String> result = new DataContainer<String>(null);
@@ -217,6 +219,7 @@ public class DiagramToSVG {
                if(!painterThread.currentThreadAccess()) throw new IllegalStateException("The callable should be called from the contextThread");
 
                final CanvasContext ctx = new CanvasContext(loaderThread);
+               ctx.getDefaultHintContext().setHint(Hints.KEY_DISABLE_GRAPH_MODIFICATIONS, Boolean.TRUE);
                final AtomicReference<ICanvasSceneGraphProvider> sgProvider = new AtomicReference<ICanvasSceneGraphProvider>();
                final DataContainer<String> result = new DataContainer<String>(null);
                final DataContainer<Exception> exception = new DataContainer<Exception>(null);
index d0a44984d5bd63a2ad27be6e94c3afa6f95484cb..47af66cc674538c5e9856c31f88d6ad4c1575611 100644 (file)
@@ -184,7 +184,7 @@ public class FlagClassFactory extends SyncElementFactory {
             if (ftr != null) {
                 IFlagType ft = ftr.read(g, flag, modelingRules);
 
-                FlagInfo info = ft.getInfo(g);
+                FlagInfo info = ft.getInfo(g, canvas);
 
                 Shape shape = info.getShape();
                 if (shape != null) {
index 8ee0ff93dcc6712a5ebde1f5b9baa1fa5208d93d..cfa4eebcd86b67a4ce08ea8275201a55fc6f0565 100644 (file)
@@ -16,6 +16,7 @@ import java.awt.geom.Rectangle2D;
 
 import org.simantics.db.ReadGraph;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.g2d.canvas.ICanvasContext;
 import org.simantics.g2d.elementclass.FlagClass;
 import org.simantics.g2d.utils.Alignment;
 
@@ -44,7 +45,23 @@ public interface IFlagType {
      * @param graph database read access
      * @return all info gathered up about the flag
      * @throws DatabaseException
+     * @Deprecated implement {@link #getInfo(ReadGraph, ICanvasContext)} instead
      */
-    FlagInfo getInfo(ReadGraph graph) throws DatabaseException;
+    default FlagInfo getInfo(ReadGraph graph) throws DatabaseException {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Reads and calculates information about this flags graphical
+     * representation.
+     * 
+     * @param graph database read access
+     * @param context the canvas context with which the info is loaded 
+     * @return all info gathered up about the flag
+     * @throws DatabaseException
+     */
+    default FlagInfo getInfo(ReadGraph graph, ICanvasContext context) throws DatabaseException {
+        return getInfo(graph);
+    }
 
 }
index cf5f70610210ff7646828f9273dc33b6964ae4b2..3fd43f0f08dd17121ac5bc43e3aeb2c4d22af20e 100644 (file)
@@ -92,8 +92,14 @@ public class Hints {
      * Set to true when the canvas is rendering to a printer
      */
     public static final Key KEY_PRINT = new KeyOf(Boolean.class, "PRINTING");
-   
-    
+
+    /**
+     * Set this hint to <code>true</code> to prevent any modifications from
+     * being made to the diagram model by the diagram loading logic. Using this
+     * may be necessary for printing.
+     */
+    public static final Key KEY_DISABLE_GRAPH_MODIFICATIONS = new KeyOf(Boolean.class, "DISABLE_GRAPH_MODIFICATIONS");
+
     private interface Dirty {}
 
     /**
index 1adcf25c23d33a2b2f7ede11eaf9210697097fb6..bec1e5408ae414c82c568b102cff6743cefec5ac 100644 (file)
@@ -64,6 +64,7 @@ public class PDFPainter {
         ICanvasSceneGraphProvider[] sgProvider = { null };
 
         CanvasContext ctx = new CanvasContext(thread);
+        ctx.getDefaultHintContext().setHint(Hints.KEY_DISABLE_GRAPH_MODIFICATIONS, Boolean.TRUE);
 
         try {
             final Semaphore done = new Semaphore(0);