Esempio n. 1
0
 def sort_attribute_names(classes):
     if classes is not None:
         for i in range(0, len(classes)):
             attribs = classes[i]['attribs']
             for j in range(0, len(attribs)):
                 name = attribs[j]['name']
                 texname = strFunctions.texify(name)
                 attribs[j]['texname'] = texname
         for i in range(0, len(classes)):
             if 'lo_attribs' in classes[i]:
                 lo_attribs = classes[i]['lo_attribs']
                 for j in range(0, len(lo_attribs)):
                     name = lo_attribs[j]['name']
                     texname = strFunctions.texify(name)
                     lo_attribs[j]['texname'] = texname
Esempio n. 2
0
    def __init__(self, name, extension, object_desc):
        BaseFile.BaseFile.__init__(self, name, extension)

        # change the comment delimiter and line length
        self.comment = '%'
        self.line_length = 72

        self.package = object_desc['name']
        self.fullname = object_desc['fullname']
        self.sbml_classes = object_desc['sbmlElements']
        self.offset = object_desc['offset']
        self.plugins = object_desc['plugins']
        self.enums = object_desc['enums']
        self.level = object_desc['sbml_level']
        self.version = object_desc['sbml_version']
        self.pkg_version = object_desc['pkg_version']

        self.prim_class = []

        self.start_b = '{'
        self.end_b = '}'

        # expand the information for the classes
        self.fulltexname = strFunctions.texify(self.fullname)
        self.upper_package = strFunctions.upper_first(self.package)
        self.sort_class_names(self.sbml_classes)
        self.sort_attribute_names(self.sbml_classes)
        self.sort_enum_names(self.enums)

        self.full_pkg_command = '\\{}Package'.format(self.fulltexname)
        self.brief_pkg_command = '\\{}'.format(self.upper_package)
Esempio n. 3
0
 def sort_class_names(self, classes):
     if classes is not None:
         for i in range(0, len(classes)):
             name = classes[i]['name']
             texname = strFunctions.texify(name)
             classes[i]['texname'] = texname
             # hack for render
             if name == 'Ellipse' or name == 'Rectangle':
                 texname = 'Render' + name
                 classes[i]['texname'] = texname
             if name == 'RelAbsVector':
                 self.prim_class.append(classes[i])
    def write_attribute_type_rule(self, attribute):
        att_type = attribute['type']
        name = strFunctions.wrap_token(attribute['texname'], self.package)
        if att_type == 'SId':
            return
        elif att_type == 'SIdRef':
            ref_name = strFunctions.upper_first(attribute['name'])
            # hack for render
            if ref_name == 'StartHead' or ref_name == 'EndHead':
                ref_name = 'LineEnding'
            text = 'The value of the attribute {} of {} {} object must be ' \
                   'the identifier of an existing \{} object defined in the ' \
                   'enclosing \Model object.'\
                .format(name, self.indef, self.formatted_name, ref_name)
        elif att_type == 'string':
            text = 'The attribute {} on {} {} must have a value of data ' \
                   'type {}.'\
                .format(name, self.indef, self.formatted_name,
                        strFunctions.wrap_token('string'))
        elif att_type == 'int' or att_type == 'uint':
            text = 'The attribute {} on {} {} must have a value of data ' \
                   'type {}.'\
                .format(name, self.indef, self.formatted_name,
                        strFunctions.wrap_token('integer'))
        elif att_type == 'double':
            text = 'The attribute {} on {} {} must have a value of data ' \
                   'type {}.'\
                .format(name, self.indef, self.formatted_name,
                        strFunctions.wrap_token('double'))
        elif att_type == 'boolean' or att_type == 'bool':
            text = 'The attribute {} on {} {} must have a value of data ' \
                   'type {}.'\
                .format(name, self.indef, self.formatted_name,
                        strFunctions.wrap_token('boolean'))
        elif att_type == 'enum':
            enum_name = strFunctions.texify(attribute['element'])
            enums = attribute['parent']['root']['enums']
            enum_values = self.parse_enum_values(attribute['element'], enums)
            text = 'The value of the attribute {0} of {1} {2} object must ' \
                   'conform to the syntax of SBML data type {3} and ' \
                   'may only take on the allowed values of {3} defined ' \
                   'in SBML; that is the value must be one of the ' \
                   'following {4}.'.format(name, self.indef,
                                           self.formatted_name,
                                           strFunctions.wrap_enum(enum_name),
                                           enum_values)
        elif att_type == 'array':
            text = 'The value of the attribute {} of {} {} object must ' \
                   'be an array of values of type {}.'\
                .format(name, self.indef, self.formatted_name,
                        strFunctions.wrap_token(attribute['element']))
        elif att_type == 'element' and attribute['element'] == 'RelAbsVector':
            text = 'The value of the attribute {0} of {1} {2} object must ' \
                   'conform to the syntax of SBML data type \\RelAbsVector ' \
                   'i.e. a string encoding optionally an absolute number ' \
                   'followed by an optional relative number followed ' \
                   'by a \\% sign. Adding spaces between the ' \
                   'coordinates is encouraged, but not required.'\
                .format(name, self.indef, self.formatted_name)
        else:
            text = 'FIX ME: Encountered an unknown attribute type {} in ' \
                   'ValidationRulesForClass:write_attribute_type_rule'\
                .format(att_type)

        ref = '{}, {}.'\
            .format(self.pkg_ref, strFunctions.wrap_section(self.name))
        sev = 'ERROR'
        return dict({'number': self.number, 'text': text,
                     'reference': ref, 'severity': sev})
Esempio n. 5
0
 def sort_enum_names(enums):
     if enums is not None:
         for i in range(0, len(enums)):
             name = enums[i]['name']
             texname = strFunctions.texify(name)
             enums[i]['texname'] = texname