*******************************************************************************/
package org.simantics.db.layer0.migration;
-import gnu.trove.set.hash.TIntHashSet;
-
import java.util.ArrayList;
import org.eclipse.core.runtime.IProgressMonitor;
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 {
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);
}
}
}
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);
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) {
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 {}
/**
org.simantics.graph.utils
Bundle-ClassPath: .
Bundle-Vendor: VTT Technical Research Centre of Finland
+Import-Package: org.slf4j
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
// 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;
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);
}
}
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(),