From e792ac2c6faa5d2b42b5c67141c89131ce9e6cd0 Mon Sep 17 00:00:00 2001 From: miettinen Date: Mon, 20 Jan 2014 05:35:12 +0000 Subject: [PATCH] Loops under structure view in Sysdyn, initial implementation (refs #3012). Moved ConfigurationUtils from sysdyn.ui to sysdyn package. git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@28669 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../ui/structure/DependencyGraphRequest.java | 18 +++--- .../sysdyn/ui/structure/StructureView.java | 26 +++++++- org.simantics.sysdyn/META-INF/MANIFEST.MF | 3 +- .../sysdyn}/utils/ConfigurationUtils.java | 64 ++++++++++++------- 4 files changed, 76 insertions(+), 35 deletions(-) rename {org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui => org.simantics.sysdyn/src/org/simantics/sysdyn}/utils/ConfigurationUtils.java (68%) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/structure/DependencyGraphRequest.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/structure/DependencyGraphRequest.java index ca898582..29075591 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/structure/DependencyGraphRequest.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/structure/DependencyGraphRequest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2012 Association for Decentralized Information Management in + * Copyright (c) 2010, 2012, 2014 Association for Decentralized Information Management in * Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -32,16 +32,16 @@ import org.simantics.sysdyn.SysdynResource; /** * Builds a graph of the dependencies of a selected variable * - * * @author Teemu Lempinen + * @author Tuomas Miettinen * */ public class DependencyGraphRequest implements Read { - Resource root; - HashMap nodes; - boolean isInverted; - int levels; + protected Resource root; + protected HashMap nodes; + protected boolean isInverted; + protected int levels; /** * Builds a graph of the dependencies of a selected variable @@ -90,7 +90,7 @@ public class DependencyGraphRequest implements Read { * @param root Root resource * @throws DatabaseException */ - private void setRoot(ReadGraph g, IGraph graph, Resource root) throws DatabaseException { + protected void setRoot(ReadGraph g, IGraph graph, Resource root) throws DatabaseException { Node n; n = new Node(graph, getName(g, root)); setShape(g, root, n); @@ -173,7 +173,7 @@ public class DependencyGraphRequest implements Read { * @param n Node * @throws DatabaseException */ - private void setShape(ReadGraph g, Resource r, Node n) throws DatabaseException { + protected void setShape(ReadGraph g, Resource r, Node n) throws DatabaseException { SysdynResource sr = SysdynResource.getInstance(g); if(g.isInstanceOf(r, sr.Stock)) n.setShape("rectangle"); @@ -185,7 +185,7 @@ public class DependencyGraphRequest implements Read { n.setShape("ellipse"); } - private String getName(ReadGraph g, Resource r) throws DatabaseException { + protected String getName(ReadGraph g, Resource r) throws DatabaseException { return (String)g.getRelatedValue(r, Layer0.getInstance(g).HasName); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/structure/StructureView.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/structure/StructureView.java index ab3983b4..7d7f53dd 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/structure/StructureView.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/structure/StructureView.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2012 Association for Decentralized Information Management in + * Copyright (c) 2007, 2012, 2014 Association for Decentralized Information Management in * Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -27,6 +27,7 @@ import org.eclipse.ui.part.ViewPart; * View for displaying different types of structural visualizations * * @author Teemu Lempinen + * @author Tuomas Miettinen * */ public class StructureView extends ViewPart { @@ -35,7 +36,7 @@ public class StructureView extends ViewPart { private ISelectionListener selectionListener; private Dependencies dependencies; private ModuleStructure moduleStructure; - + private Loops loops; @Override public void createPartControl(Composite parent) { @@ -52,6 +53,8 @@ public class StructureView extends ViewPart { // Hierarchical model structure moduleStructure = new ModuleStructure(tabFolder, SWT.NONE); + // Loops + loops = new Loops(tabFolder, SWT.NONE); selectionListener = new ISelectionListener() { @@ -80,6 +83,24 @@ public class StructureView extends ViewPart { public void widgetDefaultSelected(SelectionEvent e) { } }); + + // Listener for refreshing module structure visualization on first loading + tabFolder.addSelectionListener(new SelectionListener() { + + private boolean openedOnce = false; + + @Override + public void widgetSelected(SelectionEvent e) { + if(!openedOnce && e.item.equals(loops)) { + openedOnce = true; + loops.drawSelection(currentSeletion); + } + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }); } /** @@ -90,6 +111,7 @@ public class StructureView extends ViewPart { private void drawSelection(ISelection selection) { dependencies.drawSelection(selection); moduleStructure.drawSelection(selection); + loops.drawSelection(selection); } diff --git a/org.simantics.sysdyn/META-INF/MANIFEST.MF b/org.simantics.sysdyn/META-INF/MANIFEST.MF index 5eaad95f..6780adff 100644 --- a/org.simantics.sysdyn/META-INF/MANIFEST.MF +++ b/org.simantics.sysdyn/META-INF/MANIFEST.MF @@ -55,5 +55,6 @@ Export-Package: org.simantics.sysdyn, org.simantics.sysdyn.utils.imports Bundle-Activator: org.simantics.sysdyn.Activator Bundle-ActivationPolicy: lazy -Import-Package: org.eclipse.ui +Import-Package: org.eclipse.ui, + org.simantics.ui Bundle-Vendor: VTT Technical Reserarch Centre of Finland diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ConfigurationUtils.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/ConfigurationUtils.java similarity index 68% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ConfigurationUtils.java rename to org.simantics.sysdyn/src/org/simantics/sysdyn/utils/ConfigurationUtils.java index 28db93d2..ef821e85 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ConfigurationUtils.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/ConfigurationUtils.java @@ -1,4 +1,4 @@ -package org.simantics.sysdyn.ui.utils; +package org.simantics.sysdyn.utils; import java.util.ArrayList; import java.util.Collection; @@ -35,13 +35,20 @@ public class ConfigurationUtils { } } - public static List getLoops(final Resource r) { - List loops = Collections.emptyList(); + /** + * Get all the loops within the diagram where the resource belongs to. + * @param r Resource that is studied + * @return List of loops; each loop is a list of resources in the same order in which + * they appear in the loop. The first item in the list can be any of the items in the + * loop. + */ + public static List> getLoops(final Resource r) { + List> loops = Collections.emptyList(); try { - loops = SimanticsUI.getSession().syncRequest(new Read>() { + loops = SimanticsUI.getSession().syncRequest(new Read>>() { @Override - public List perform(ReadGraph graph) + public List> perform(ReadGraph graph) throws DatabaseException { return getLoops(graph, r); } @@ -52,16 +59,16 @@ public class ConfigurationUtils { return loops; } - @SuppressWarnings("rawtypes") - public static List getLoops(ReadGraph g, Resource r) throws DatabaseException, ServiceException { + @SuppressWarnings({ "rawtypes", "unchecked", "unused" }) + public static List> getLoops(ReadGraph g, Resource r) throws DatabaseException, ServiceException { Layer0 l0 = Layer0.getInstance(g); SysdynResource sr = SysdynResource.getInstance(g); - List loops = Collections.emptyList(); + List> loops = Collections.emptyList(); Resource configuration = g.getPossibleObject(r, l0.PartOf); if (configuration == null) return loops; - loops = new ArrayList(); + loops = new ArrayList>(); Collection variables = g.getObjects(configuration, l0.ConsistsOf); ArrayList shadows = new ArrayList(); @@ -81,14 +88,12 @@ public class ConfigurationUtils { } } - HashMap elementaryLoopItems = new HashMap(); - int variableCount = variables.size(); Resource nodes[] = new Resource[variableCount]; - boolean adjMatrix[][] = new boolean[variableCount][variableCount]; // Add independent variables to map and array int k = 0; + HashMap elementaryLoopItems = new HashMap(); for (Resource variable : variables) { ArrayList dependingVariables = new ArrayList(); Collection dependencies = g.getObjects(variable, sr.Variable_isTailOf); @@ -117,6 +122,7 @@ public class ConfigurationUtils { } // Fill the adjacent matrix + boolean adjMatrix[][] = new boolean[variableCount][variableCount]; for (int j = 0; j < nodes.length; ++j) { ArrayList dependingVariables = elementaryLoopItems.get(nodes[j]).dependencies; for (Resource v : dependingVariables) { @@ -124,23 +130,35 @@ public class ConfigurationUtils { } } - // Debug print the result + // Get ALL nodes in the diagram. ElementaryCyclesSearch ecs = new ElementaryCyclesSearch(adjMatrix, nodes); List cycles = ecs.getElementaryCycles(); - for (int i = 0; i < cycles.size(); i++) { - List cycle = (List) cycles.get(i); - for (int j = 0; j < cycle.size(); j++) { - Resource node = (Resource) cycle.get(j); - if (j < cycle.size() - 1) { - System.out.print(g.getPossibleRelatedValue(node, l0.HasName, Bindings.STRING) + " -> "); - } else { - System.out.print(g.getPossibleRelatedValue(node, l0.HasName, Bindings.STRING)); + + // Collect all those loops in which the original resource exists. + for (Object o : cycles) { + if (o instanceof List) { + List loop = (List)o; + if (loop.contains(r)) + loops.add(loop); + } + } + + // Debug print the result + if (false) { + for (int i = 0; i < cycles.size(); i++) { + List cycle = (List) cycles.get(i); + for (int j = 0; j < cycle.size(); j++) { + Resource node = (Resource) cycle.get(j); + if (j < cycle.size() - 1) { + System.out.print(g.getPossibleRelatedValue(node, l0.HasName, Bindings.STRING) + " -> "); + } else { + System.out.print(g.getPossibleRelatedValue(node, l0.HasName, Bindings.STRING)); + } } + System.out.print("\n"); } - System.out.print("\n"); } return loops; } - } -- 2.47.1