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;
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;
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);
return model;
}
-
-
private static String resolveRVI(ReadGraph graph, Resource diagram) throws DatabaseException {
ModelingResources mod = ModelingResources.getInstance(graph);
Resource composite = graph.getSingleObject(diagram, mod.DiagramToComposite);
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();
+
+ }
+
}
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) {
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;
* @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);
+ }
}
protected PasteOperation getOperation() {
return op;
}
+
+ public WriteGraph getGraph() {
+ return graph;
+ }
}
* @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() {
* 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 {}
/**
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);
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(),
package org.simantics.scl.compiler.internal.codegen.ssa.exits;
import java.util.ArrayList;
+import java.util.Arrays;
import org.objectweb.asm.Label;
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.compiler.types.Types;
+import gnu.trove.map.hash.TIntObjectHashMap;
+
public class Switch extends SSAExit implements ValRefBinder {
ValRef scrutinee;
int defaultId;
for(defaultId=0;defaultId<branches.length-1&&branches[defaultId].constructor!=null;++defaultId);
int[] values = new int[defaultId];
- Label[] labels = new Label[defaultId];
Cont[] continuations = new Cont[defaultId+1];
+ TIntObjectHashMap<Label> labelMap = new TIntObjectHashMap<Label>(defaultId);
for(int i=0;i<defaultId;++i) {
- values[i] = ((IntegerConstant)branches[i].constructor).getValue();
+ int value = ((IntegerConstant)branches[i].constructor).getValue();
+ values[i] = value;
Cont cont = branches[i].cont.getBinding();
- labels[i] = mb.getLabel(cont);
+ labelMap.put(value, mb.getLabel(cont));
continuations[i] = cont;
}
+ Arrays.sort(values);
+ Label[] labels = new Label[defaultId];
+ for(int i=0;i<defaultId;++i)
+ labels[i] = labelMap.get(values[i]);
Label defaultLabel;
{
Cont cont = branches[defaultId].cont.getBinding();
@Test public void Matching2() { test(); }
@Test public void Matching4() { test(); }
@Test public void Matching5() { test(); }
+ @Test public void Matching6() { test(); }
@Test public void MatchingWithMissingParameter() { test(); }
@Test public void MatchingWithoutTypeAnnotations() { test(); }
@Test public void MaximumBy() { test(); }
--- /dev/null
+import "Prelude"
+
+main = do
+ match 1+1 :: Integer with
+ 2 -> 2
+ 0 -> 0
+ 1 -> 1
+--
+2
\ No newline at end of file