]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Merge "(refs #7218) Sort labels by integer values when generating switch"
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 12 May 2017 11:56:07 +0000 (14:56 +0300)
committerGerrit Code Review <gerrit2@www.simantics.org>
Fri, 12 May 2017 11:56:07 +0000 (14:56 +0300)
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/NamespaceMigrationStep.java
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.graph/META-INF/MANIFEST.MF
bundles/org.simantics.graph/src/org/simantics/graph/refactoring/GraphRefactoringUtils.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 1262f3909d92bf6895f5a13b15e86d86e103c15a..a0d4f9da5e202f87a893aa76556c942b83c81e1b 100644 (file)
@@ -11,8 +11,6 @@
  *******************************************************************************/
 package org.simantics.db.layer0.migration;
 
-import gnu.trove.set.hash.TIntHashSet;
-
 import java.util.ArrayList;
 
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -29,12 +27,19 @@ import org.simantics.graph.refactoring.GraphRefactoringException;
 import org.simantics.graph.refactoring.GraphRefactoringUtils;
 import org.simantics.graph.refactoring.MappingSpecification;
 import org.simantics.graph.refactoring.MappingSpecification.MappingRule;
+import org.simantics.graph.representation.Identity;
+import org.simantics.graph.representation.Internal;
 import org.simantics.graph.representation.TransferableGraph1;
 import org.simantics.graph.store.IdentityStore;
 import org.simantics.layer0.Layer0;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import gnu.trove.set.hash.TIntHashSet;
 
 public class NamespaceMigrationStep implements MigrationStep {
-       
+    private static final Logger LOGGER = LoggerFactory.getLogger(NamespaceMigrationStep.class);
+
     final ArrayList<MappingRule> rules;
     
        public NamespaceMigrationStep(ReadGraph graph, Resource step) throws DatabaseException {
@@ -50,7 +55,7 @@ public class NamespaceMigrationStep implements MigrationStep {
                                if(fromURI != null && toURI != null)
                                        rules.add(new MappingRule(fromURI, toURI));
                                else
-                                       System.err.println("Namespace migration uri formation error: base " + base + " from " + from + " to " + to);
+                                   LOGGER.error("Namespace migration uri formation error: base " + base + " from " + from + " to " + to);
                        }
                }
        }
@@ -63,9 +68,13 @@ public class NamespaceMigrationStep implements MigrationStep {
         try {
             MappingSpecification mappingSpec = new MappingSpecification(rules);
             boolean fixed = GraphRefactoringUtils.fixIncorrectRoot(tg.identities);
-            System.err.println("fixed=" + fixed);
+            LOGGER.info("fixed=" + fixed);
             IdentityStore idStore = TransferableGraphConversion.extractIdentities(tg);
-            idStore.printChildMap();
+            // Mark internal identities new
+            for(Identity id : tg.identities)
+                if(id.definition instanceof Internal)
+                    idStore.markNew(id.resource);
+//            idStore.printChildMap();
 //            System.err.println("ids: " + idStore);
 //            System.err.println("rc: " + tg.resourceCount);
 //            System.err.println("idStore: " + idStore.toArray().length);
@@ -79,7 +88,7 @@ public class NamespaceMigrationStep implements MigrationStep {
             if(fixed)
                 GraphRefactoringUtils.unfixIncorrectRoot(tg.identities);
 
-            System.err.println("rc2: " + tg.resourceCount);
+            LOGGER.info("rc2: " + tg.resourceCount);
 //            System.err.println("idStore2: " + idStore.toArray().length);
 
         } catch (GraphRefactoringException e) {
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 5f4404acc377654f15cb79c95be04028b3fc09a7..d64e63f57228046ce763af88b54e7019462ea286 100644 (file)
@@ -18,3 +18,4 @@ Export-Package: org.simantics.graph,
  org.simantics.graph.utils
 Bundle-ClassPath: .
 Bundle-Vendor: VTT Technical Research Centre of Finland
+Import-Package: org.slf4j
index 9882048b788144c74de9ac5ec56b69f6954ff384..ddc31aa5b15811722b65b785886b871e31c4053b 100644 (file)
@@ -21,13 +21,13 @@ import org.simantics.graph.representation.old.OldTransferableGraph1;
 import org.simantics.graph.representation.old.OldValue1;
 import org.simantics.graph.store.GraphStore;
 import org.simantics.graph.store.IdentityStore;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-import gnu.trove.list.array.TIntArrayList;
-import gnu.trove.map.hash.TIntIntHashMap;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class GraphRefactoringUtils {
-
+    private static final Logger LOGGER = LoggerFactory.getLogger(GraphRefactoringUtils.class);
     /**
      * Moves an external resource. Returns true if did something.
      * @param parentsAffected 
@@ -48,7 +48,7 @@ public class GraphRefactoringUtils {
         // Find parent id
         int toParentId = ids.createPathToId(to.parent);
         if(ids.hasChild(toParentId, to.name)) {
-               System.err.println("refactor statements from " + from + " to " + to);
+            LOGGER.info("refactor statements from " + from + " to " + to);
             //throw new GraphRefactoringException("External reference to " + to + " already exists.");
                int toId = ids.pathToId(to);
             int[] statements = tg.statements;
@@ -68,7 +68,7 @@ public class GraphRefactoringUtils {
             if(!(rule.to instanceof PathChild))
                 throw new GraphRefactoringException("Invalid target URI " + rule.to);
             if(!moveExternal(tg, ids, rule.from, (PathChild)rule.to, parentsAffected))
-                System.err.println("Didn't find " + rule.from);
+                LOGGER.warn("Didn't find " + rule.from);
         }
     }
 
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(),