Commit 3d022039 authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

Ability to export bcx files with notes in all nodes

parent b84b6b06
...@@ -359,6 +359,7 @@ class CNode(object): ...@@ -359,6 +359,7 @@ class CNode(object):
""" """
self.model = model self.model = model
self.name = '$$' self.name = '$$'
self.note = ""
self.xloc = x_coord self.xloc = x_coord
self.yloc = y_coord self.yloc = y_coord
self.father = None self.father = None
......
# -*- coding: utf-8 -*-
## Filename : chart_xml.py ## Filename : chart_xml.py
## Author(s) : Geoffroy Andrieux ## Author(s) : Geoffroy Andrieux
## Created : 04/2010 ## Created : 04/2010
...@@ -41,6 +42,8 @@ ...@@ -41,6 +42,8 @@
""" """
Load and generate Cadbiom xml files Load and generate Cadbiom xml files
""" """
from __future__ import unicode_literals
from __future__ import print_function
from cadbiom.models.guard_transitions.chart_model import ChartModel from cadbiom.models.guard_transitions.chart_model import ChartModel
from xml.sax import make_parser from xml.sax import make_parser
...@@ -51,9 +54,7 @@ from lxml import objectify ...@@ -51,9 +54,7 @@ from lxml import objectify
class XmlVisitor: class XmlVisitor:
""" """Visitor used to generate xml cadbiom code when the model is exported."""
Visitor used to generate xml cadbiom code
"""
def __init__(self, model): def __init__(self, model):
self.model_name = model.name self.model_name = model.name
...@@ -78,7 +79,7 @@ class XmlVisitor: ...@@ -78,7 +79,7 @@ class XmlVisitor:
Detect double declarations Detect double declarations
""" """
try: try:
dec = self.symb[name] self.symb[name]
except: except:
self.symb[name] = "ok" self.symb[name] = "ok"
return return
...@@ -192,33 +193,35 @@ class XmlVisitor: ...@@ -192,33 +193,35 @@ class XmlVisitor:
namespace="http://cadbiom", namespace="http://cadbiom",
nsmap={None : "http://cadbiom"}) nsmap={None : "http://cadbiom"})
xmodel = header.model(name=self.model_name) xmodel = header.model(name=self.model_name)
# nodes
self.current_element = xmodel self.current_element = xmodel
for snode in tnode.sub_nodes:
properties = snode.accept(self) def create_xml_element(entity):
"""Create XML element and add it to root object"""
# get node or transition properties
properties = entity.accept(self)
if properties[0] != 'CMacroNode': if properties[0] != 'CMacroNode':
subel = etree.SubElement(xmodel, properties[0]) element = etree.Element(properties[0])
if len(properties) > 1: if len(properties) > 1:
attrname = properties[1] attrname = properties[1]
attr = properties[2] attr = properties[2]
attributes = subel.attrib attributes = element.attrib
# Set attributes and values (name, event, coords...)
for i in range(0, len(attrname)): for i in range(0, len(attrname)):
attributes[attrname[i]] = str(attr[i]) attributes[attrname[i]] = str(attr[i])
# Add notes/text of element
if entity.note:
element.text = entity.note
# Attach element to the model
xmodel.append(element)
# nodes
for snode in tnode.sub_nodes:
create_xml_element(snode)
# transitions # transitions
for gtr in tnode.transitions: for gtr in tnode.transitions:
for trans in gtr: for trans in gtr:
properties = trans.accept(self) create_xml_element(trans)
sub_tr = etree.Element(properties[0])
if len(properties) > 1:
attrname = properties[1]
attr = properties[2]
attributes = sub_tr.attrib
for i in range(0, len(attrname)):
attributes[attrname[i]] = str(attr[i])
if trans.note:
sub_tr.text = trans.note
xmodel.append(sub_tr)
# constraints # constraints
if len(tnode.model.constraints) > 0: if len(tnode.model.constraints) > 0:
...@@ -247,8 +250,9 @@ class XmlVisitor: ...@@ -247,8 +250,9 @@ class XmlVisitor:
return [tag, attrname, attr] return [tag, attrname, attr]
def return_xml(self): def return_xml(self):
""" """Return the model as xml string.
get xml string
.. note:: Used when the model is saved in a .bcx file.
""" """
return self.xml return self.xml
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment