From 5bc0259970ad200f17b823a54465b7193d39e8cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bartek=20G=C3=B3rny?= <bartek@gorny.edu.pl>
Date: Wed, 28 Mar 2007 10:32:50 +0000
Subject: [PATCH] simulation tree viewer - shows tree of simulations related to
 context. To be beautified. Contributed by Luke.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13748 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../erp5_toolbox/Base_getSimulationTree.xml   | 205 ++++++++++++++++++
 .../erp5_toolbox/Base_viewSimulationTree.xml  | 177 +++++++++++++++
 bt5/erp5_forge/bt/revision                    |   2 +-
 3 files changed, 383 insertions(+), 1 deletion(-)
 create mode 100644 bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/Base_getSimulationTree.xml
 create mode 100644 bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/Base_viewSimulationTree.xml

diff --git a/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/Base_getSimulationTree.xml b/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/Base_getSimulationTree.xml
new file mode 100644
index 0000000000..76a146d585
--- /dev/null
+++ b/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/Base_getSimulationTree.xml
@@ -0,0 +1,205 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <tuple>
+        <tuple>
+          <string>Products.PythonScripts.PythonScript</string>
+          <string>PythonScript</string>
+        </tuple>
+        <none/>
+      </tuple>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>Python_magic</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>Script_magic</string> </key>
+            <value> <int>3</int> </value>
+        </item>
+        <item>
+            <key> <string>__ac_local_roles__</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>_bind_names</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
+                </klass>
+                <tuple/>
+                <state>
+                  <dictionary>
+                    <item>
+                        <key> <string>_asgns</string> </key>
+                        <value>
+                          <dictionary>
+                            <item>
+                                <key> <string>name_container</string> </key>
+                                <value> <string>container</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>name_context</string> </key>
+                                <value> <string>context</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>name_m_self</string> </key>
+                                <value> <string>script</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>name_subpath</string> </key>
+                                <value> <string>traverse_subpath</string> </value>
+                            </item>
+                          </dictionary>
+                        </value>
+                    </item>
+                  </dictionary>
+                </state>
+              </object>
+            </value>
+        </item>
+        <item>
+            <key> <string>_body</string> </key>
+            <value> <string encoding="cdata"><![CDATA[
+
+# License: GPL\n
+# Author: Lukasz Nowak <lukasz.nowak@ventis.com.pl>\n
+# Copyright 2007 Ventis s. c.\n
+# SYNOPSIS\n
+# This script exctracts simulations (Applied Rule and Simulation Movement) for context.\n
+# If start_path is given it instead extracts tree with root as given start_path.\n
+\n
+\n
+def getByRecurse(obj,rv=[]):\n
+  rv = []\n
+  for o in [q.getObject() for q in obj.searchFolder()]:\n
+    rv.append(getByRecurse(o))\n
+  return rv\n
+\n
+def getFromCatalog(start_path):\n
+  return [x.getObject() for x in context.portal_catalog(\n
+    portal_type=(\'Applied Rule\',\'Simulation Movement\',),\n
+    path=start_path+\'%%\',\n
+    sort_on=((\'path\',\'ascending\',\'string\'),)\n
+  )]\n
+\n
+if start_path is None:\n
+  # we have to detect simulations\n
+  if context.getPortalType() in [\'Simulation Movement\',\'Applied Rule\']:\n
+    # we are run from simulation, its our root\n
+    start_paths = [context.getPath(),]\n
+  else:\n
+    # hm, it might be, that our context have simulations in relate objects?\n
+    start_paths = [x.getPath() for x in context.portal_categories.getRelatedValueList(context,portal_type=[\'Simulation Movement\',\'Applied Rule\'])]\n
+else:\n
+  start_paths = [start_path,]\n
+if start_paths == []:\n
+  # we are in no simulation related object\n
+  print \'No related simulations found\'\n
+  return printed\n
+\n
+print \'%s simulation related path found.\'%(len(start_paths),)\n
+related_simulations = {}\n
+for start_path in start_paths:\n
+\n
+  related_simulations[start_path] = getFromCatalog(start_path)\n
+\n
+return related_simulations\n
+
+
+]]></string> </value>
+        </item>
+        <item>
+            <key> <string>_code</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>_filepath</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>_params</string> </key>
+            <value> <string>start_path=None</string> </value>
+        </item>
+        <item>
+            <key> <string>errors</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+        <item>
+            <key> <string>func_code</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
+                </klass>
+                <tuple/>
+                <state>
+                  <dictionary>
+                    <item>
+                        <key> <string>co_argcount</string> </key>
+                        <value> <int>1</int> </value>
+                    </item>
+                    <item>
+                        <key> <string>co_varnames</string> </key>
+                        <value>
+                          <tuple>
+                            <string>start_path</string>
+                            <string>_print_</string>
+                            <string>_print</string>
+                            <string>getByRecurse</string>
+                            <string>getFromCatalog</string>
+                            <string>None</string>
+                            <string>_getattr_</string>
+                            <string>context</string>
+                            <string>start_paths</string>
+                            <string>append</string>
+                            <string>$append0</string>
+                            <string>_getiter_</string>
+                            <string>x</string>
+                            <string>len</string>
+                            <string>related_simulations</string>
+                            <string>_write_</string>
+                          </tuple>
+                        </value>
+                    </item>
+                  </dictionary>
+                </state>
+              </object>
+            </value>
+        </item>
+        <item>
+            <key> <string>func_defaults</string> </key>
+            <value>
+              <tuple>
+                <none/>
+              </tuple>
+            </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>Base_getSimulationTree</string> </value>
+        </item>
+        <item>
+            <key> <string>warnings</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/Base_viewSimulationTree.xml b/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/Base_viewSimulationTree.xml
new file mode 100644
index 0000000000..95f1d43c9f
--- /dev/null
+++ b/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/Base_viewSimulationTree.xml
@@ -0,0 +1,177 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <tuple>
+        <tuple>
+          <string>Products.PythonScripts.PythonScript</string>
+          <string>PythonScript</string>
+        </tuple>
+        <none/>
+      </tuple>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>Python_magic</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>Script_magic</string> </key>
+            <value> <int>3</int> </value>
+        </item>
+        <item>
+            <key> <string>__ac_local_roles__</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>_bind_names</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
+                </klass>
+                <tuple/>
+                <state>
+                  <dictionary>
+                    <item>
+                        <key> <string>_asgns</string> </key>
+                        <value>
+                          <dictionary>
+                            <item>
+                                <key> <string>name_container</string> </key>
+                                <value> <string>container</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>name_context</string> </key>
+                                <value> <string>context</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>name_m_self</string> </key>
+                                <value> <string>script</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>name_subpath</string> </key>
+                                <value> <string>traverse_subpath</string> </value>
+                            </item>
+                          </dictionary>
+                        </value>
+                    </item>
+                  </dictionary>
+                </state>
+              </object>
+            </value>
+        </item>
+        <item>
+            <key> <string>_body</string> </key>
+            <value> <string encoding="cdata"><![CDATA[
+
+# License: GPL\n
+# Author: Lukasz Nowak <lukasz.nowak@ventis.com.pl>\n
+# Copyright 2007 Ventis s. c.\n
+\n
+simulations_found = context.Base_getSimulationTree(start_path=start_path)\n
+\n
+if len(simulations_found) == 0:\n
+  print \'No simulations related\'\n
+else:\n
+  for simulation_root in simulations_found.iterkeys():\n
+    print simulation_root\n
+    for simulation in simulations_found[simulation_root]:\n
+      print \'\\t\',simulation.getPath(),simulation.getPortalType(),\n
+      if simulation.getPortalType() == \'Simulation Movement\':\n
+        print simulation.getCausalityState(),\n
+      else:\n
+        print \'nostate\',\n
+      print simulation.getCategoriesList()\n
+\n
+return printed\n
+
+
+]]></string> </value>
+        </item>
+        <item>
+            <key> <string>_code</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>_filepath</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>_params</string> </key>
+            <value> <string>start_path=None</string> </value>
+        </item>
+        <item>
+            <key> <string>errors</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+        <item>
+            <key> <string>func_code</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
+                </klass>
+                <tuple/>
+                <state>
+                  <dictionary>
+                    <item>
+                        <key> <string>co_argcount</string> </key>
+                        <value> <int>1</int> </value>
+                    </item>
+                    <item>
+                        <key> <string>co_varnames</string> </key>
+                        <value>
+                          <tuple>
+                            <string>start_path</string>
+                            <string>_print_</string>
+                            <string>_print</string>
+                            <string>_getattr_</string>
+<string>context</string>
+                            <string>simulations_found</string>
+                            <string>len</string>
+                            <string>_getiter_</string>
+                            <string>simulation_root</string>
+                            <string>_getitem_</string>
+                            <string>simulation</string>
+                          </tuple>
+                        </value>
+                    </item>
+                  </dictionary>
+                </state>
+              </object>
+            </value>
+        </item>
+        <item>
+            <key> <string>func_defaults</string> </key>
+            <value>
+              <tuple>
+                <none/>
+              </tuple>
+            </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>Base_viewSimulationTree</string> </value>
+        </item>
+        <item>
+            <key> <string>warnings</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_forge/bt/revision b/bt5/erp5_forge/bt/revision
index 8bc6583717..405e057083 100644
--- a/bt5/erp5_forge/bt/revision
+++ b/bt5/erp5_forge/bt/revision
@@ -1 +1 @@
-120
\ No newline at end of file
+127
\ No newline at end of file
-- 
2.30.9