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):
"""
self.model = model
self.name = '$$'
self.note = ""
self.xloc = x_coord
self.yloc = y_coord
self.father = None
......
# -*- coding: utf-8 -*-
## Filename : chart_xml.py
## Author(s) : Geoffroy Andrieux
## Created : 04/2010
......@@ -41,6 +42,8 @@
"""
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 xml.sax import make_parser
......@@ -51,9 +54,7 @@ from lxml import objectify
class XmlVisitor:
"""
Visitor used to generate xml cadbiom code
"""
"""Visitor used to generate xml cadbiom code when the model is exported."""
def __init__(self, model):
self.model_name = model.name
......@@ -78,7 +79,7 @@ class XmlVisitor:
Detect double declarations
"""
try:
dec = self.symb[name]
self.symb[name]
except:
self.symb[name] = "ok"
return
......@@ -192,33 +193,35 @@ class XmlVisitor:
namespace="http://cadbiom",
nsmap={None : "http://cadbiom"})
xmodel = header.model(name=self.model_name)
# nodes
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':
subel = etree.SubElement(xmodel, properties[0])
element = etree.Element(properties[0])
if len(properties) > 1:
attrname = properties[1]
attr = properties[2]
attributes = subel.attrib
attributes = element.attrib
# Set attributes and values (name, event, coords...)
for i in range(0, len(attrname)):
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
for gtr in tnode.transitions:
for trans in gtr:
properties = trans.accept(self)
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)
create_xml_element(trans)
# constraints
if len(tnode.model.constraints) > 0:
......@@ -247,8 +250,9 @@ class XmlVisitor:
return [tag, attrname, attr]
def return_xml(self):
"""
get xml string
"""Return the model as xml string.
.. note:: Used when the model is saved in a .bcx file.
"""
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