/*******************************************************************************\r
- * Copyright (c) 2010, 2012 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012, 2014 Association for Decentralized Information Management in\r
* Industry THTH ry.\r
* All rights reserved. This program and the accompanying materials\r
* are made available under the terms of the Eclipse Public License v1.0\r
/**\r
* Builds a graph of the dependencies of a selected variable\r
* \r
- * \r
* @author Teemu Lempinen\r
+ * @author Tuomas Miettinen\r
*\r
*/\r
public class DependencyGraphRequest implements Read<Graph> {\r
\r
- Resource root;\r
- HashMap<Resource, Node> nodes;\r
- boolean isInverted;\r
- int levels;\r
+ protected Resource root;\r
+ protected HashMap<Resource, Node> nodes;\r
+ protected boolean isInverted;\r
+ protected int levels;\r
\r
/**\r
* Builds a graph of the dependencies of a selected variable\r
* @param root Root resource\r
* @throws DatabaseException\r
*/\r
- private void setRoot(ReadGraph g, IGraph graph, Resource root) throws DatabaseException {\r
+ protected void setRoot(ReadGraph g, IGraph graph, Resource root) throws DatabaseException {\r
Node n;\r
n = new Node(graph, getName(g, root));\r
setShape(g, root, n);\r
* @param n Node\r
* @throws DatabaseException\r
*/\r
- private void setShape(ReadGraph g, Resource r, Node n) throws DatabaseException {\r
+ protected void setShape(ReadGraph g, Resource r, Node n) throws DatabaseException {\r
SysdynResource sr = SysdynResource.getInstance(g);\r
if(g.isInstanceOf(r, sr.Stock))\r
n.setShape("rectangle");\r
n.setShape("ellipse");\r
}\r
\r
- private String getName(ReadGraph g, Resource r) throws DatabaseException {\r
+ protected String getName(ReadGraph g, Resource r) throws DatabaseException {\r
return (String)g.getRelatedValue(r, Layer0.getInstance(g).HasName);\r
}\r
\r
/*******************************************************************************\r
- * Copyright (c) 2007, 2012 Association for Decentralized Information Management in\r
+ * Copyright (c) 2007, 2012, 2014 Association for Decentralized Information Management in\r
* Industry THTH ry.\r
* All rights reserved. This program and the accompanying materials\r
* are made available under the terms of the Eclipse Public License v1.0\r
* View for displaying different types of structural visualizations\r
* \r
* @author Teemu Lempinen\r
+ * @author Tuomas Miettinen\r
*\r
*/\r
public class StructureView extends ViewPart {\r
private ISelectionListener selectionListener;\r
private Dependencies dependencies;\r
private ModuleStructure moduleStructure;\r
- \r
+ private Loops loops;\r
\r
@Override\r
public void createPartControl(Composite parent) {\r
// Hierarchical model structure\r
moduleStructure = new ModuleStructure(tabFolder, SWT.NONE);\r
\r
+ // Loops\r
+ loops = new Loops(tabFolder, SWT.NONE);\r
\r
selectionListener = new ISelectionListener() {\r
\r
public void widgetDefaultSelected(SelectionEvent e) {\r
}\r
});\r
+ \r
+ // Listener for refreshing module structure visualization on first loading\r
+ tabFolder.addSelectionListener(new SelectionListener() {\r
+ \r
+ private boolean openedOnce = false;\r
+ \r
+ @Override\r
+ public void widgetSelected(SelectionEvent e) {\r
+ if(!openedOnce && e.item.equals(loops)) {\r
+ openedOnce = true;\r
+ loops.drawSelection(currentSeletion);\r
+ }\r
+ }\r
+ \r
+ @Override\r
+ public void widgetDefaultSelected(SelectionEvent e) {\r
+ }\r
+ });\r
}\r
\r
/**\r
private void drawSelection(ISelection selection) {\r
dependencies.drawSelection(selection);\r
moduleStructure.drawSelection(selection);\r
+ loops.drawSelection(selection);\r
}\r
\r
\r
-package org.simantics.sysdyn.ui.utils;\r
+package org.simantics.sysdyn.utils;\r
\r
import java.util.ArrayList;\r
import java.util.Collection;\r
}\r
}\r
\r
- public static List<Resource> getLoops(final Resource r) {\r
- List<Resource> loops = Collections.emptyList();\r
+ /**\r
+ * Get all the loops within the diagram where the resource belongs to.\r
+ * @param r Resource that is studied\r
+ * @return List of loops; each loop is a list of resources in the same order in which\r
+ * they appear in the loop. The first item in the list can be any of the items in the\r
+ * loop. \r
+ */\r
+ public static List<List<Resource>> getLoops(final Resource r) {\r
+ List<List<Resource>> loops = Collections.emptyList();\r
try {\r
- loops = SimanticsUI.getSession().syncRequest(new Read<List<Resource>>() {\r
+ loops = SimanticsUI.getSession().syncRequest(new Read<List<List<Resource>>>() {\r
\r
@Override\r
- public List<Resource> perform(ReadGraph graph)\r
+ public List<List<Resource>> perform(ReadGraph graph)\r
throws DatabaseException {\r
return getLoops(graph, r);\r
}\r
return loops;\r
}\r
\r
- @SuppressWarnings("rawtypes")\r
- public static List<Resource> getLoops(ReadGraph g, Resource r) throws DatabaseException, ServiceException {\r
+ @SuppressWarnings({ "rawtypes", "unchecked", "unused" })\r
+ public static List<List<Resource>> getLoops(ReadGraph g, Resource r) throws DatabaseException, ServiceException {\r
Layer0 l0 = Layer0.getInstance(g);\r
SysdynResource sr = SysdynResource.getInstance(g);\r
- List<Resource> loops = Collections.emptyList();\r
+ List<List<Resource>> loops = Collections.emptyList();\r
Resource configuration = g.getPossibleObject(r, l0.PartOf);\r
if (configuration == null)\r
return loops;\r
\r
- loops = new ArrayList<Resource>();\r
+ loops = new ArrayList<List<Resource>>();\r
\r
Collection<Resource> variables = g.getObjects(configuration, l0.ConsistsOf);\r
ArrayList<Resource> shadows = new ArrayList<Resource>();\r
}\r
}\r
\r
- HashMap<Resource, ElementaryLoopItem> elementaryLoopItems = new HashMap<Resource, ElementaryLoopItem>();\r
- \r
int variableCount = variables.size();\r
Resource nodes[] = new Resource[variableCount];\r
- boolean adjMatrix[][] = new boolean[variableCount][variableCount];\r
\r
// Add independent variables to map and array\r
int k = 0;\r
+ HashMap<Resource, ElementaryLoopItem> elementaryLoopItems = new HashMap<Resource, ElementaryLoopItem>();\r
for (Resource variable : variables) {\r
ArrayList<Resource> dependingVariables = new ArrayList<Resource>();\r
Collection<Resource> dependencies = g.getObjects(variable, sr.Variable_isTailOf);\r
}\r
\r
// Fill the adjacent matrix\r
+ boolean adjMatrix[][] = new boolean[variableCount][variableCount];\r
for (int j = 0; j < nodes.length; ++j) {\r
ArrayList<Resource> dependingVariables = elementaryLoopItems.get(nodes[j]).dependencies;\r
for (Resource v : dependingVariables) {\r
}\r
}\r
\r
- // Debug print the result\r
+ // Get ALL nodes in the diagram.\r
ElementaryCyclesSearch ecs = new ElementaryCyclesSearch(adjMatrix, nodes);\r
List cycles = ecs.getElementaryCycles();\r
- for (int i = 0; i < cycles.size(); i++) {\r
- List cycle = (List) cycles.get(i);\r
- for (int j = 0; j < cycle.size(); j++) {\r
- Resource node = (Resource) cycle.get(j);\r
- if (j < cycle.size() - 1) {\r
- System.out.print(g.getPossibleRelatedValue(node, l0.HasName, Bindings.STRING) + " -> ");\r
- } else {\r
- System.out.print(g.getPossibleRelatedValue(node, l0.HasName, Bindings.STRING));\r
+ \r
+ // Collect all those loops in which the original resource exists.\r
+ for (Object o : cycles) {\r
+ if (o instanceof List) {\r
+ List loop = (List)o;\r
+ if (loop.contains(r))\r
+ loops.add(loop);\r
+ }\r
+ }\r
+ \r
+ // Debug print the result\r
+ if (false) {\r
+ for (int i = 0; i < cycles.size(); i++) {\r
+ List cycle = (List) cycles.get(i);\r
+ for (int j = 0; j < cycle.size(); j++) {\r
+ Resource node = (Resource) cycle.get(j);\r
+ if (j < cycle.size() - 1) {\r
+ System.out.print(g.getPossibleRelatedValue(node, l0.HasName, Bindings.STRING) + " -> ");\r
+ } else {\r
+ System.out.print(g.getPossibleRelatedValue(node, l0.HasName, Bindings.STRING));\r
+ }\r
}\r
+ System.out.print("\n");\r
}\r
- System.out.print("\n");\r
}\r
\r
return loops;\r
}\r
- \r
}\r