From c2e2c7cd017e8e6c203cc6607319ca80b4c98b3d Mon Sep 17 00:00:00 2001
From: baigner <benedikt.aigner@rwth-aachen.de>
Date: Fri, 6 Apr 2018 10:32:14 +0200
Subject: [PATCH] New data structure try 2: Prepared new function in
 mixin_vistoms.py to send the schema data as an array of xPaths. d3.js data
 structure for tree view can be created within VISTOMS.html itself (this still
 needs to be done)

Former-commit-id: d52b3a0cc9445ef369397dbb702b11c3d35bb19c
---
 kadmos/graph/mixin_vistoms.py                 | 52 +++++++++++++++++++
 kadmos/vispack/VISTOMS/templates/VISTOMS.html |  5 +-
 kadmos/vispack/VISTOMS/vistoms.py             |  4 +-
 3 files changed, 58 insertions(+), 3 deletions(-)

diff --git a/kadmos/graph/mixin_vistoms.py b/kadmos/graph/mixin_vistoms.py
index 2c48c19d3..eb6c98239 100644
--- a/kadmos/graph/mixin_vistoms.py
+++ b/kadmos/graph/mixin_vistoms.py
@@ -422,6 +422,12 @@ class VistomsMixin(object):
         # Write dictionary entry
         graph_data_entry['xdsm'] = xdsm_dict
 
+        # Benedikt: New schema function
+        # Get variable tree based on schema NEW
+        variable_tree_dataschema_new = self._get_variable_tree_dataschema_new(full_graph, reference_file)
+        # Write dictionary entry
+        graph_data_entry['variableSchemes']['schema_new'] = variable_tree_dataschema_new
+
         # Get variable tree based on schema
         variable_tree_dataschema = self._get_variable_tree_dataschema(full_graph, reference_file)
         # Write dictionary entry
@@ -757,6 +763,52 @@ class VistomsMixin(object):
         logger.debug('Successfully created xdsm.')
         return xdsm_dict
 
+    def _get_variable_tree_dataschema_new(self, full_graph, reference_file):
+        """ Function to determine the variable tree based on the data schema.
+
+        :param full_graph: dictionary with graph data
+        :type full_graph: dict
+        :param reference_file: file with reference values
+        :type reference_file: file
+        :return: variable tree definition
+        :rtype: dict
+        """
+        # Settings
+        coordinator_str = self.COORDINATOR_STRING
+
+        logger.debug('Creating schema variable tree...')
+
+        variable_tree_dataschema = []
+        if reference_file:
+            # Parse reference XML
+            reference_xml = etree.parse(reference_file)
+            # Check validity of the CPACS file
+            # noinspection PyUnusedLocal
+            reference_valid = recursively_unique_attribute(reference_xml)
+        for key in full_graph:
+            if key is not 'attributes' and key is not coordinator_str:
+                if self.node[key]['category'] == 'variable':
+                    # Determine element element value and dimension based on reference file
+                    if reference_file:
+                        # Check if the variable node is actually a related node
+                        if 'related_to_schema_node' in self.node[key]:
+                            xpath = self.node[key]['related_to_schema_node']
+                        else:
+                            xpath = key
+                        # Get element details
+                        # noinspection PyUnboundLocalVariable
+                        var_value, var_dim = get_element_details(reference_xml, xpath)
+                    else:
+                        var_value = 'unknown'
+                        var_dim = None
+                        xpath = key
+                    print xpath
+                    var_dict = dict(xpath=xpath, value=var_value, dimension=var_dim, type='variable')
+                    variable_tree_dataschema.append(var_dict)
+        logger.debug('Successfully created schema variable tree.')
+        return variable_tree_dataschema
+
+
     def _get_variable_tree_dataschema(self, full_graph, reference_file):
         """ Function to determine the variable tree based on the data schema.
 
diff --git a/kadmos/vispack/VISTOMS/templates/VISTOMS.html b/kadmos/vispack/VISTOMS/templates/VISTOMS.html
index 296b0fd61..06b06663b 100644
--- a/kadmos/vispack/VISTOMS/templates/VISTOMS.html
+++ b/kadmos/vispack/VISTOMS/templates/VISTOMS.html
@@ -21451,6 +21451,9 @@
 				{			
                     var schema = currentGraph.variableSchemes[aVarCategory];
                     
+                    console.log("schema")
+                    console.log(schema)
+                    
                     var treeData = (JSON.parse(JSON.stringify(schema)));				
                     //aigner: Here, the minimalized tree is created!
                     //Transferred variables: 
@@ -21459,7 +21462,7 @@
                     //3) xPathList --> Array of actually used pipeLine data
                     
                     //aigner:HIER WEITER!!
-                    console.log("treeData")
+                    
                     
                     function appendElement(anElement)
                     {
diff --git a/kadmos/vispack/VISTOMS/vistoms.py b/kadmos/vispack/VISTOMS/vistoms.py
index 8bc9f86ad..8c0e6ba41 100644
--- a/kadmos/vispack/VISTOMS/vistoms.py
+++ b/kadmos/vispack/VISTOMS/vistoms.py
@@ -4,10 +4,10 @@ import json
 import logging
 import os
 import shutil
+import sys
+import tempfile
 import webbrowser
 import zipfile
-import tempfile
-import sys
 from copy import deepcopy
 from os.path import expanduser
 from shutil import copyfile
-- 
GitLab