]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Merge "(refs #7215) Preserve identity types in NamespaceMigrationStep"
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Fri, 12 May 2017 10:24:49 +0000 (13:24 +0300)
committerGerrit Code Review <gerrit2@www.simantics.org>
Fri, 12 May 2017 10:24:49 +0000 (13:24 +0300)
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.diagram/src/org/simantics/diagram/handler/Paster.java
bundles/org.simantics.diagram/src/org/simantics/diagram/profile/StyleBase.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
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/connection/RouteGraphNode.java

index 3c110976294a86bf1aa2414ea50eda567881365b..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;
@@ -29,6 +30,7 @@ import org.simantics.structural2.StructuralVariables;
 import org.simantics.utils.DataContainer;
 import org.simantics.utils.datastructures.Pair;
 import org.simantics.utils.page.MarginUtils.Margins;
+import org.simantics.utils.threads.IThreadWorkQueue;
 import org.simantics.utils.threads.ThreadUtils;
 import org.simantics.utils.threads.WorkerThread;
 
@@ -127,13 +129,11 @@ public class DiagramToSVG {
                if (diagram == null)
                        throw new DatabaseException("Input " + input + " cannot be resolved as diagram");
                
-               
-       
-               
                final WorkerThread thread = new WorkerThread("Diagram Image Painter");
                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);
@@ -203,8 +203,6 @@ public class DiagramToSVG {
         return model;
     }
 
-
-
     private static String resolveRVI(ReadGraph graph, Resource diagram) throws DatabaseException {
        ModelingResources mod = ModelingResources.getInstance(graph);
         Resource composite = graph.getSingleObject(diagram, mod.DiagramToComposite);
@@ -213,4 +211,74 @@ public class DiagramToSVG {
         return StructuralVariables.getRVI(graph, variablePath);
     }
 
+       public static String renderWithLoader(final Resource input, final ImagePrinter.ImageExportPlan exportPlan,
+                       Margins margins, SVGGraphics2D svgExporter,
+                       IThreadWorkQueue loaderThread,
+                       IThreadWorkQueue painterThread) throws Exception {
+
+               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);
+
+               try {
+                       
+                       final ISessionContext sessionContext = Simantics.getSessionContext();
+
+                       Pair<Resource, String> modelAndRVI = sessionContext.getSession().syncRequest(new UniqueRead<Pair<Resource, String>>() {
+                               @Override
+                               public Pair<Resource, String> perform(ReadGraph graph) throws DatabaseException {
+                                       return new Pair<Resource, String>( resolveModel(graph, exportPlan.diagram ), resolveRVI(graph, exportPlan.diagram) );
+                               }
+                       });
+
+                       ICanvasSceneGraphProvider provider = DiagramNodeUtil.loadSceneGraphProvider(ctx, modelAndRVI.first, exportPlan.diagram, modelAndRVI.second);
+                       sgProvider.set( provider );
+
+                       final Semaphore done = new Semaphore(0);
+
+                       ThreadUtils.asyncExec(loaderThread, new Runnable() {
+                               @Override
+                               public void run() {
+                                       try {
+                                               SVGBuilder chassis = margins != null ?
+                                                               new SVGBuilder(exportPlan.dpi,exportPlan.size,margins) :
+                                                                       new SVGBuilder(exportPlan.dpi,exportPlan.size,exportPlan.margin);
+                                                               result.set(chassis.paint(ctx, svgExporter));
+                                       } catch (DatabaseException e) {
+                                               exception.set(e);
+                                               done.release();
+                                       } catch (Throwable e) {
+                                               exception.set(new DatabaseException(e));
+                                               done.release();
+                                       } finally {
+                                               done.release();
+                                       }
+                               }
+                       });
+
+                       done.acquire();
+
+               } catch (DatabaseException e) {
+                       exception.set(e);
+               } catch (Throwable e) {
+                       exception.set(new DatabaseException(e));
+               } finally {
+
+                       if (sgProvider.get() != null)
+                               sgProvider.get().dispose();
+                       ctx.dispose();
+
+               }
+
+               if(exception.get() != null) 
+                       throw exception.get();
+
+               return result.get();
+               
+       }
+       
 }
index 30efa54f0301b3724f2fe0f95e88e5df56c6e202..56c2ceef42ae172e53f5aae6624e568bd9f23d13 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 8176d1e7931081fdc66665ff1cb1065b2d4731c0..0c5974a8f54f968030f4ebbc695cc032f6c7363e 100644 (file)
@@ -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);
+    }
 
 }
index c8995f4c1f4777be79311bc0d502616af534f147..6672599073b1b18e717bd1f79c36f6e3ac0bdb78 100644 (file)
@@ -1364,4 +1364,8 @@ public class Paster {
     protected PasteOperation getOperation() {
        return op;
     }
+    
+    public WriteGraph getGraph() {
+               return graph;
+       }
 }
index 5aed90b48931b2a15bb911b0986860d96e01481f..ee203616da950f31d0fa1f1abbfae793de988f2d 100644 (file)
@@ -457,7 +457,11 @@ public abstract class StyleBase<Result> implements Style {
      * @param items the diagram data items that need to be cleaned up
      */
     protected final void cleanupItems(final EvaluationContext evaluationContext, final IDiagram diagram, final Object[] items) {
-        AWTThread.getThreadAccess().asyncExec(new Runnable() {
+
+        ICanvasContext context = evaluationContext.getConstant(ProfileKeys.CANVAS);
+
+       context.getThreadAccess().asyncExec(new Runnable() {
+               
             @Override
             public void run() {
                 
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);
index 4650d2e13587c46cc85e3a2cccc3ba8470c0bda5..084c0d6582874a7f7cb64439a58e2495e4da12f8 100644 (file)
@@ -215,7 +215,7 @@ public class RouteGraphNode extends G2DNode implements ISelectionPainterNode, In
         if(dynamicColor != null || dynamicStroke != null) {
             BasicConnectionStyle baseStyle = (BasicConnectionStyle)tryGetStyle(baseRenderer);
             try {
-               Constructor<? extends BasicConnectionStyle> c = baseStyle.getClass().getConstructor(Color.class, Color.class, double.class, Stroke.class, Stroke.class, double.class);
+               Constructor<? extends BasicConnectionStyle> c = baseStyle.getClass().getConstructor(Color.class, Color.class, double.class, Stroke.class, Stroke.class, double.class, double.class);
                renderer = new StyledRouteGraphRenderer(c.newInstance(
                         dynamicColor != null ? dynamicColor : baseStyle.getLineColor(),
                                 baseStyle.getBranchPointColor(), baseStyle.getBranchPointRadius(),