import org.simantics.db.common.request.WriteRequest;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.request.Read;
+import org.simantics.diagram.synchronization.IModifiableSynchronizationContext;
+import org.simantics.diagram.synchronization.SynchronizationHints;
+import org.simantics.diagram.synchronization.graph.GraphSynchronizationHints;
+import org.simantics.diagram.synchronization.graph.layer.GraphLayerManager;
import org.simantics.g2d.canvas.ICanvasContext;
+import org.simantics.g2d.diagram.IDiagram;
import org.simantics.g2d.participant.MouseUtil;
import org.simantics.g2d.participant.MouseUtil.MouseInfo;
import org.simantics.modeling.ModelingResources;
IResourceEditorInput input = (IResourceEditorInput)viewer.getEditorInput();
Resource composite = input.getResource();
- addSVG(mpos.getX(), mpos.getY(), composite);
+ IDiagram idiagram = viewer.getAdapter(IDiagram.class);
+
+ addSVG(mpos.getX(), mpos.getY(), composite, idiagram);
}
- public static void addSVG(final double mposX, final double mposY, final Resource composite) {
+ public static void addSVG(final double mposX, final double mposY, final Resource composite, IDiagram idiagram) {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
@Override
public void perform(WriteGraph g) throws DatabaseException {
- Commands.get(g, "Simantics/Diagram/createSVGElement")
+ Object svg = Commands.get(g, "Simantics/Diagram/createSVGElementR")
.execute(g, g.syncRequest(new IndexRoot(composite)),
composite, suffix(filename), data, mposX, mposY);
+
+ if (svg != null && svg instanceof Resource) {
+ Resource resource = (Resource) svg;
+ // 7. Put the element on all the currently active layers if possible.
+ IModifiableSynchronizationContext context = idiagram.getHint(SynchronizationHints.CONTEXT);
+ GraphLayerManager glm = context.get(GraphSynchronizationHints.GRAPH_LAYER_MANAGER);
+ if (glm != null) {
+ glm.removeFromAllLayers(g, resource);
+ glm.putElementOnVisibleLayers(idiagram, g, resource);
+ }
+ }
}
});
importJava "org.simantics.modeling.svg.CreateSVGElement" where
createSVGElement :: Resource -> String -> ByteArray -> Double -> Double -> <WriteGraph> ()
+ createSVGElementR :: Resource -> String -> ByteArray -> Double -> Double -> <WriteGraph> Resource
importSVGElement :: Resource -> File -> Double -> Double -> <WriteGraph> ()
+ importSVGElementR :: Resource -> File -> Double -> Double -> <WriteGraph> Resource
importJava "org.simantics.diagram.synchronization.graph.RemoveElement" where
removeElement :: Resource -> Resource -> <WriteGraph> ()
public class CreateSVGElement {
public static void createSVGElement(WriteGraph g, Resource diagram, String suffix, byte[] data, double mposX, double mposY) throws DatabaseException {
+ createSVGElement(g, diagram, suffix, data, mposX, mposY);
+ }
+
+ public static Resource createSVGElementR(WriteGraph g, Resource diagram, String suffix, byte[] data, double mposX, double mposY) throws DatabaseException {
Layer0 L0 = Layer0.getInstance(g);
DiagramResource DIA = DiagramResource.getInstance(g);
throw new DatabaseException("Unknown image format " + suffix);
OrderedSetUtils.addFirst(g, diagram, element);
g.claim(diagram, L0.ConsistsOf, element);
-
+ return element;
}
public static void importSVGElement(WriteGraph graph, Resource diagram, File file, double posX, double posY) throws DatabaseException, IOException {
+ importSVGElementR(graph, diagram, file, posX, posY);
+ }
+
+ public static Resource importSVGElementR(WriteGraph graph, Resource diagram, File file, double posX, double posY) throws DatabaseException, IOException {
final byte[] data = FileUtils.readFile(file);
- createSVGElement(graph, diagram, suffix(file.getName()), data, posX, posY);
+ return createSVGElementR(graph, diagram, suffix(file.getName()), data, posX, posY);
}
private static String suffix(String fileName) {