X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.debug.graphical%2Fsrc%2Forg%2Fsimantics%2Fdebug%2Fgraphical%2FDebuggerCanvas.java;h=107125f46e35e9f6b20349f6d18528b8a0efcd33;hp=00a539990a6c466ae42ac0788a254889cab68508;hb=58a208e96edcddb07af89796859416dc6fc59f14;hpb=b29a69792f689d2ac7beffb725c814aa65fca301;ds=sidebyside diff --git a/bundles/org.simantics.debug.graphical/src/org/simantics/debug/graphical/DebuggerCanvas.java b/bundles/org.simantics.debug.graphical/src/org/simantics/debug/graphical/DebuggerCanvas.java index 00a539990..107125f46 100644 --- a/bundles/org.simantics.debug.graphical/src/org/simantics/debug/graphical/DebuggerCanvas.java +++ b/bundles/org.simantics.debug.graphical/src/org/simantics/debug/graphical/DebuggerCanvas.java @@ -1,9 +1,5 @@ package org.simantics.debug.graphical; -import gnu.trove.list.array.TDoubleArrayList; -import gnu.trove.map.hash.THashMap; -import gnu.trove.map.hash.TObjectIntHashMap; - import java.awt.Color; import java.awt.GradientPaint; import java.awt.Graphics; @@ -53,11 +49,17 @@ import org.simantics.debug.graphical.model.LabelContent; import org.simantics.debug.graphical.model.Node; import org.simantics.debug.graphical.model.NodeData; import org.simantics.layer0.Layer0; +import org.simantics.scl.runtime.SCLContext; +import org.simantics.scl.runtime.function.Function; import org.simantics.ui.dnd.LocalObjectTransfer; import org.simantics.ui.dnd.LocalObjectTransferable; import org.simantics.ui.selection.AnyResource; import org.simantics.ui.selection.WorkbenchSelectionElement; +import gnu.trove.list.array.TDoubleArrayList; +import gnu.trove.map.hash.THashMap; +import gnu.trove.map.hash.TObjectIntHashMap; + public class DebuggerCanvas extends JPanel { private static final long serialVersionUID = -718678297301786379L; @@ -74,10 +76,19 @@ public class DebuggerCanvas extends JPanel { double canvasZoom = 1.0; boolean extensionMode = false; Random random = new Random(); - + public Function statementFilter; + LabelingPreferences labelingPreferences = new LabelingPreferences(); + public void setStatementFilter(Function statementFilter) { + this.statementFilter = statementFilter; + } + + public void removeStatementFilter() { + this.statementFilter = null; + } + @Override public void paint(Graphics _g) { Graphics2D g = (Graphics2D)_g; @@ -284,6 +295,29 @@ public class DebuggerCanvas extends JPanel { nodes.add(a); return a; } + + public void addResource(Resource resource) { + double x, y; + if(nodes.isEmpty()) { + x = 0.0; + y = 0.0; + } + else { + double xMin=Double.POSITIVE_INFINITY, yMin=Double.POSITIVE_INFINITY; + double xMax=Double.NEGATIVE_INFINITY, yMax=Double.NEGATIVE_INFINITY; + for(Node node : nodes) { + xMin = Math.min(node.getMinX(), xMin); + yMin = Math.min(node.getMinY(), yMin); + xMax = Math.max(node.getMaxX(), xMax); + yMax = Math.max(node.getMaxY(), yMax); + } + x = xMin + (xMax - xMin) * random.nextDouble(); + y = yMin + (yMax - yMin) * random.nextDouble(); + } + + addResource(x, y, resource); + repaint(); + } private void scheduleUpdate() { Simantics.getSession().asyncRequest(new ReadRequest() { @@ -462,29 +496,41 @@ public class DebuggerCanvas extends JPanel { Simantics.getSession().syncRequest(new ReadRequest() { @Override public void run(ReadGraph graph) throws DatabaseException { - THashMap oldExtensionNodeMap = DebuggerCanvas.this.extensionNodeMap; - THashMap extensionNodeMap = new THashMap(); - for(Node node : nodes) { - for(Statement stat : node.getData().getStatements()) { - Resource object = stat.getObject(); - Node node2 = extensionNodeMap.get(object); - if(node2 == null) { - node2 = oldExtensionNodeMap.get(object); + SCLContext sclContext = SCLContext.getCurrent(); + Object oldGraph = sclContext.put("graph", graph); + try { + THashMap oldExtensionNodeMap = DebuggerCanvas.this.extensionNodeMap; + THashMap extensionNodeMap = new THashMap(); + for(Node node : nodes) { + for(Statement stat : node.getData().getStatements()) { + Resource object = stat.getObject(); + Node node2 = extensionNodeMap.get(object); if(node2 == null) { - node2 = new Node(new NodeData(object)); - double angle = random.nextDouble() * Math.PI * 2.0; - double dx = Math.cos(angle); - double dy = Math.sin(angle); - double len = 150.0; - node2.setPos(node.getX() + dx*len, node.getY() + dy*len); + if(statementFilter != null && Boolean.FALSE.equals(statementFilter.apply(stat))) + continue; + node2 = oldExtensionNodeMap.get(object); + if(node2 == null) { + node2 = new Node(new NodeData(object)); + double angle = random.nextDouble() * Math.PI * 2.0; + double dx = Math.cos(angle); + double dy = Math.sin(angle); + double len = 150.0; + node2.setPos(node.getX() + dx*len, node.getY() + dy*len); + } + node2.getData().updateData(graph, labelingPreferences); + node2.setContent(new LabelContent(node2.getData().getLabels())); + extensionNodeMap.put(object, node2); + extensionNodes.add(node2); } - node2.getData().updateData(graph, labelingPreferences); - node2.setContent(new LabelContent(node2.getData().getLabels())); - extensionNodeMap.put(object, node2); - extensionNodes.add(node2); + extensionEdges.add(createEdge(graph, stat, node, node2)); } - extensionEdges.add(createEdge(graph, stat, node, node2)); } + } catch (Throwable t) { + if (t instanceof DatabaseException) + throw (DatabaseException) t; + throw new DatabaseException(t); + } finally { + sclContext.put("graph", oldGraph); } DebuggerCanvas.this.extensionNodeMap = extensionNodeMap; layoutExtension();