]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Loops under structure view in Sysdyn, initial implementation (refs #3012).
authormiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 20 Jan 2014 05:35:12 +0000 (05:35 +0000)
committermiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 20 Jan 2014 05:35:12 +0000 (05:35 +0000)
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

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/structure/DependencyGraphRequest.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/structure/StructureView.java
org.simantics.sysdyn/META-INF/MANIFEST.MF
org.simantics.sysdyn/src/org/simantics/sysdyn/utils/ConfigurationUtils.java [moved from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ConfigurationUtils.java with 68% similarity]

index ca898582fe41f6c7880b84b92d28ebf076e0d004..290755917e33ff8f076632665735fcdcd9942506 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\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
@@ -32,16 +32,16 @@ import org.simantics.sysdyn.SysdynResource;
 /**\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
@@ -90,7 +90,7 @@ public class DependencyGraphRequest implements Read<Graph> {
         * @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
@@ -173,7 +173,7 @@ public class DependencyGraphRequest implements Read<Graph> {
         * @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
@@ -185,7 +185,7 @@ public class DependencyGraphRequest implements Read<Graph> {
                        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
index ab3983b4936af7bc9bea72794d9d12f626a6544b..7d7f53dd296f870147a01e5ad96082b1d48374b4 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\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
@@ -27,6 +27,7 @@ import org.eclipse.ui.part.ViewPart;
  * 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
@@ -35,7 +36,7 @@ public class StructureView extends ViewPart {
     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
@@ -52,6 +53,8 @@ public class StructureView extends ViewPart {
         // 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
@@ -80,6 +83,24 @@ public class StructureView extends ViewPart {
             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
@@ -90,6 +111,7 @@ public class StructureView extends ViewPart {
     private void drawSelection(ISelection selection) {\r
         dependencies.drawSelection(selection);\r
         moduleStructure.drawSelection(selection);\r
+        loops.drawSelection(selection);\r
     }\r
     \r
 \r
index 5eaad95f1d1e5ed8d1b379c878a498d3ef817904..6780adff09272c280e242f271697bb111c95c8a3 100644 (file)
@@ -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
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 28db93d252f97ef2b81229458637f3cb18537fef..ef821e853edcf49b965780c30c2a6ffae695dece 100644 (file)
@@ -1,4 +1,4 @@
-package org.simantics.sysdyn.ui.utils;\r
+package org.simantics.sysdyn.utils;\r
 \r
 import java.util.ArrayList;\r
 import java.util.Collection;\r
@@ -35,13 +35,20 @@ public class ConfigurationUtils {
                }\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
@@ -52,16 +59,16 @@ public class ConfigurationUtils {
                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
@@ -81,14 +88,12 @@ public class ConfigurationUtils {
                        }\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
@@ -117,6 +122,7 @@ public class ConfigurationUtils {
                }\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
@@ -124,23 +130,35 @@ public class ConfigurationUtils {
                        }\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