From: Tuukka Lehtonen Date: Fri, 12 May 2017 11:56:07 +0000 (+0300) Subject: Merge "(refs #7218) Sort labels by integer values when generating switch" X-Git-Tag: v1.29.0~58 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=e8269f6cba002c702c25d80db5399b5b50b97ab9;hp=5d55c8c863ea9909064ee847f25163bf02e5e8f2 Merge "(refs #7218) Sort labels by integer values when generating switch" --- diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/NamespaceMigrationStep.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/NamespaceMigrationStep.java index 1262f3909..a0d4f9da5 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/NamespaceMigrationStep.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/NamespaceMigrationStep.java @@ -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 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) { 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 3c1109762..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; @@ -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 sgProvider = new AtomicReference(); final ISessionContext sessionContext = Simantics.getSessionContext(); final DataContainer result = new DataContainer(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 sgProvider = new AtomicReference(); + final DataContainer result = new DataContainer(null); + final DataContainer exception = new DataContainer(null); + + try { + + final ISessionContext sessionContext = Simantics.getSessionContext(); + + Pair modelAndRVI = sessionContext.getSession().syncRequest(new UniqueRead>() { + @Override + public Pair perform(ReadGraph graph) throws DatabaseException { + return new Pair( 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(); + + } + } 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.diagram/src/org/simantics/diagram/handler/Paster.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/Paster.java index c8995f4c1..667259907 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/Paster.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/Paster.java @@ -1364,4 +1364,8 @@ public class Paster { protected PasteOperation getOperation() { return op; } + + public WriteGraph getGraph() { + return graph; + } } diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/StyleBase.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/StyleBase.java index 5aed90b48..ee203616d 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/StyleBase.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/StyleBase.java @@ -457,7 +457,11 @@ public abstract class StyleBase 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() { 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.graph/META-INF/MANIFEST.MF b/bundles/org.simantics.graph/META-INF/MANIFEST.MF index 5f4404acc..d64e63f57 100644 --- a/bundles/org.simantics.graph/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.graph/META-INF/MANIFEST.MF @@ -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 diff --git a/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/GraphRefactoringUtils.java b/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/GraphRefactoringUtils.java index 9882048b7..ddc31aa5b 100644 --- a/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/GraphRefactoringUtils.java +++ b/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/GraphRefactoringUtils.java @@ -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); } } 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); diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/connection/RouteGraphNode.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/connection/RouteGraphNode.java index 4650d2e13..084c0d658 100644 --- a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/connection/RouteGraphNode.java +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/connection/RouteGraphNode.java @@ -215,7 +215,7 @@ public class RouteGraphNode extends G2DNode implements ISelectionPainterNode, In if(dynamicColor != null || dynamicStroke != null) { BasicConnectionStyle baseStyle = (BasicConnectionStyle)tryGetStyle(baseRenderer); try { - Constructor c = baseStyle.getClass().getConstructor(Color.class, Color.class, double.class, Stroke.class, Stroke.class, double.class); + Constructor 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(),