From: Tuukka Lehtonen Date: Thu, 11 May 2017 11:19:32 +0000 (+0300) Subject: Added mechanism to diagram IFlagType to prevent graph modifications X-Git-Tag: v1.29.0~60 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=c0464cc6dd167281b1c104b61dd81da23e7a8698;p=simantics%2Fplatform.git Added mechanism to diagram IFlagType to prevent graph modifications 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 (cherry picked from commit c92959f34dd3cf5f365d8798839a919840b5487a) --- diff --git a/bundles/org.simantics.diagram.svg/src/org/simantics/diagram/svg/export/DiagramToSVG.java b/bundles/org.simantics.diagram.svg/src/org/simantics/diagram/svg/export/DiagramToSVG.java index 555be8be7..9964592f9 100644 --- a/bundles/org.simantics.diagram.svg/src/org/simantics/diagram/svg/export/DiagramToSVG.java +++ b/bundles/org.simantics.diagram.svg/src/org/simantics/diagram/svg/export/DiagramToSVG.java @@ -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 sgProvider = new AtomicReference(); final ISessionContext sessionContext = Simantics.getSessionContext(); final DataContainer result = new DataContainer(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 sgProvider = new AtomicReference(); final DataContainer result = new DataContainer(null); final DataContainer exception = new DataContainer(null); diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/FlagClassFactory.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/FlagClassFactory.java index 30efa54f0..56c2ceef4 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/FlagClassFactory.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/FlagClassFactory.java @@ -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) { diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/flag/IFlagType.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/flag/IFlagType.java index 8176d1e79..0c5974a8f 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/flag/IFlagType.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/flag/IFlagType.java @@ -17,6 +17,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; @@ -46,7 +47,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); + } } diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/canvas/Hints.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/canvas/Hints.java index cf5f70610..3fd43f0f0 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/canvas/Hints.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/canvas/Hints.java @@ -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 true 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 {} /** diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/pdf/PDFPainter.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/pdf/PDFPainter.java index 1adcf25c2..bec1e5408 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/pdf/PDFPainter.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/pdf/PDFPainter.java @@ -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);