Пример #1
0
 def write_macro_for_listof(self, sbml_class):
     if sbml_class['hasListOf']:
         if 'lo_elementName' in sbml_class \
                 and sbml_class['lo_elementName'] != '':
             lo_name = strFunctions.upper_first(
                 sbml_class['lo_elementName'])
         else:
             lo_name = strFunctions.cap_list_of_name(sbml_class['name'])
         self.write_line('\\newcommand{0}\\{1}{2}{0}\\defRef{0}{1}{2}'
                         '{0}{3}{2}{2}'.format(
                             self.start_b, lo_name, self.end_b,
                             strFunctions.make_class(lo_name)))
         # hack for render
         if sbml_class['name'] == 'GradientBase':
             self.write_line('\\newcommand{0}\\{4}{2}{0}\\defRef{0}{1}{2}'
                             '{0}{3}{2}{2}'.format(
                                 self.start_b, lo_name, self.end_b,
                                 strFunctions.make_class(lo_name),
                                 'ListOfGradientBases'))
         elif sbml_class['name'] == 'RenderPoint':
             self.write_line('\\newcommand{0}\\{4}{2}{0}\\defRef{0}{1}{2}'
                             '{0}{3}{2}{2}'.format(
                                 self.start_b, lo_name, self.end_b,
                                 strFunctions.make_class(lo_name),
                                 'ListOfRenderPoints'))
Пример #2
0
 def write_macro_for_listof(self, sbml_class):
     if sbml_class['hasListOf']:
         if 'lo_elementName' in sbml_class \
                 and sbml_class['lo_elementName'] != '':
             lo_name = strFunctions.upper_first(
                 sbml_class['lo_elementName'])
         else:
             lo_name = strFunctions.cap_list_of_name(sbml_class['name'])
         self.write_line('\\newcommand{0}\\{1}{2}{0}\\defRef{0}{1}{2}'
                         '{0}{3}{2}{2}'
                         .format(self.start_b, lo_name, self.end_b,
                                 strFunctions.make_class(lo_name)))
         # hack for render
         if sbml_class['name'] == 'GradientBase':
             self.write_line('\\newcommand{0}\\{4}{2}{0}\\defRef{0}{1}{2}'
                             '{0}{3}{2}{2}'
                             .format(self.start_b, lo_name, self.end_b,
                                     strFunctions.make_class(lo_name),
                                     'ListOfGradientBases'))
         elif sbml_class['name'] == 'RenderPoint':
             self.write_line('\\newcommand{0}\\{4}{2}{0}\\defRef{0}{1}{2}'
                             '{0}{3}{2}{2}'
                             .format(self.start_b, lo_name, self.end_b,
                                     strFunctions.make_class(lo_name),
                                     'ListOfRenderPoints'))
Пример #3
0
    def write_body_for_lo_class(self, sbml_class, nested=False):
        lo_name = 'default'
        if sbml_class['hasListOf']:
            if 'lo_elementName' in sbml_class \
                    and sbml_class['lo_elementName'] != '':
                lo_name = strFunctions.upper_first(
                    sbml_class['lo_elementName'])
            else:
                lo_name = strFunctions.cap_list_of_name(sbml_class['name'])

        # do not write if already written
        if lo_name in self.classes_written:
            return
        self.classes_written.append(lo_name)

        if 'texname' in sbml_class:
            classname = sbml_class['texname']
        else:
            classname = sbml_class['name']

        self.write_comment_line('---------------------------------------------'
                                '------------')
        self.write_line('\subsection{0}The \class{0}{1}{2} class{2}'
                        .format(self.start_b, lo_name, self.end_b))
        self.write_line('\label{0}{1}-class{2}'
                        .format(self.start_b, lo_name.lower(), self.end_b))
        self.skip_line()
        self.write_to_do('explain {0}'.format(lo_name))

        if 'min_lo_children' not in sbml_class:
            number = 'one'
        elif sbml_class['min_lo_children'] == 1:
            number = 'one'
        else:
            number = strFunctions.replace_digits(str(
                sbml_class['min_lo_children'])).lower()

        self.write_line('The \\{0} object derives from the \\class{1}SBase{2}'
                        ' and inherits the core attributes and subobjects '
                        'from that class.  It contains '
                        '{4} or more objects of type \\{3}.'
                        .format(lo_name, self.start_b, self.end_b, classname,
                                number))
        self.skip_line()

        written = False
        for i in range(0, len(sbml_class['lo_attribs'])):
            if not written:
                self.write_line('In addition the  \\{0} object has the '
                                'following attributes.'
                                .format(lo_name))
                self.skip_line()
                written = True
            att = sbml_class['lo_attribs'][i]
            self.write_attibute_paragraph(att, lo_name)

        if not nested:
            self.write_body_for_class(self.get_class(sbml_class['name']))
Пример #4
0
    def write_body_for_lo_class(self, sbml_class, nested=False):
        lo_name = 'default'
        if sbml_class['hasListOf']:
            if 'lo_elementName' in sbml_class \
                    and sbml_class['lo_elementName'] != '':
                lo_name = strFunctions.upper_first(
                    sbml_class['lo_elementName'])
            else:
                lo_name = strFunctions.cap_list_of_name(sbml_class['name'])

        # do not write if already written
        if lo_name in self.classes_written:
            return
        self.classes_written.append(lo_name)

        if 'texname' in sbml_class:
            classname = sbml_class['texname']
        else:
            classname = sbml_class['name']

        self.write_comment_line('---------------------------------------------'
                                '------------')
        self.write_line('\subsection{0}The \class{0}{1}{2} class{2}'
                        .format(self.start_b, lo_name, self.end_b))
        self.write_line('\label{0}{1}-class{2}'
                        .format(self.start_b, lo_name.lower(), self.end_b))
        self.skip_line()
        self.write_to_do('explain {0}'.format(lo_name))

        if 'min_lo_children' not in sbml_class:
            number = 'one'
        elif sbml_class['min_lo_children'] == 1:
            number = 'one'
        else:
            number = strFunctions.replace_digits(str(
                sbml_class['min_lo_children'])).lower()

        self.write_line('The \\{0} object derives from the \\class{1}SBase{2}'
                        ' and inherits the core attributes and subobjects '
                        'from that class.  It contains '
                        '{4} or more objects of type \\{3}.'
                        .format(lo_name, self.start_b, self.end_b, classname,
                                number))
        self.skip_line()

        written = False
        for i in range(0, len(sbml_class['lo_attribs'])):
            if not written:
                self.write_line('In addition the  \\{0} object has the '
                                'following attributes.'
                                .format(lo_name))
                self.skip_line()
                written = True
            att = sbml_class['lo_attribs'][i]
            self.write_attibute_paragraph(att, lo_name)

        if not nested:
            self.write_body_for_class(self.get_class(sbml_class['name']))
Пример #5
0
 def get_class(self, name):
     for i in range(0, len(self.sbml_classes)):
         this_class = self.sbml_classes[i]
         if this_class['name'] == name:
             return this_class
         elif this_class['hasListOf'] is True:
             if strFunctions.cap_list_of_name(this_class['name']) == name:
                 return this_class
     return None
Пример #6
0
 def get_class(self, name):
     for i in range(0, len(self.sbml_classes)):
         this_class = self.sbml_classes[i]
         if this_class['name'] == name:
             return this_class
         elif this_class['hasListOf'] is True:
             if strFunctions.cap_list_of_name(this_class['name']) == name:
                 return this_class
     return None
Пример #7
0
    def write_child_element(self, attrib, name):
        if attrib['type'] == 'element':
            if self.derives_from_other_ns(attrib['element']):
                child_name = '\\class{' + attrib['element'] + '}'
            else:
                child_name = '\\' + attrib['element']
        elif attrib['type'] == 'lo_element':
            child_name = '\\' + strFunctions.cap_list_of_name(attrib['name'])
        elif attrib['type'] == 'inline_lo_element':
            child_name = '\\' + strFunctions.cap_list_of_name(attrib['name'])
        else:
            return

        # hack for render
        if child_name == '\\RelAbsVector':
            return

        self.write_line('{0} \{1} contains {2} {3} element.'.format(
            strFunctions.get_indefinite(name).capitalize(), name,
            'at most one' if attrib['reqd'] is True else 'exactly one',
            child_name))
Пример #8
0
    def write_child_element(self, attrib, name):
        if attrib['type'] == 'element':
            if self.derives_from_other_ns(attrib['element']):
                child_name = '\\class{' + attrib['element'] + '}'
            else:
                child_name = '\\' + attrib['element']
        elif attrib['type'] == 'lo_element':
            child_name = '\\' + strFunctions.cap_list_of_name(attrib['name'])
        elif attrib['type'] == 'inline_lo_element':
            child_name = '\\' + strFunctions.cap_list_of_name(attrib['name'])
        else:
            return

        # hack for render
        if child_name == '\\RelAbsVector':
            return

        self.write_line('{0} \{1} contains {2} {3} element.'
                        .format(strFunctions.get_indefinite(name).
                                capitalize(), name,
                                'at most one' if attrib['reqd'] is True
                                else 'exactly one', child_name))
Пример #9
0
 def get_lo_element(self, attrib):
     lo_name = strFunctions.lower_first(strFunctions.cap_list_of_name(attrib['name']))
     attrib_node = self.doc.createElement('element')
     attrib_node.setAttribute('name', '{0}'.format(lo_name))
     ref = self.doc.createElement('ref')
     ref.setAttribute('name', '{0}.datatype'.format(lo_name))
     attrib_node.appendChild(ref)
     if attrib['reqd']:
         return attrib_node
     else:
         optional = self.doc.createElement('optional')
         optional.appendChild(attrib_node)
         return optional
Пример #10
0
 def get_lo_element(self, attrib):
     lo_name = strFunctions.lower_first(
         strFunctions.cap_list_of_name(attrib['name']))
     attrib_node = self.doc.createElement('element')
     attrib_node.setAttribute('name', '{0}'.format(lo_name))
     ref = self.doc.createElement('ref')
     ref.setAttribute('name', '{0}.datatype'.format(lo_name))
     attrib_node.appendChild(ref)
     if attrib['reqd']:
         return attrib_node
     else:
         optional = self.doc.createElement('optional')
         optional.appendChild(attrib_node)
         return optional
Пример #11
0
 def write_lo_class_definition(self, new_class):
     lo_name = strFunctions.lower_first(strFunctions.cap_list_of_name(new_class['name']))
     comment = self.doc.createComment('definition of {0}'.format(lo_name))
     self.doc.documentElement.appendChild(comment)
     element = self.doc.createElement('define')
     element.setAttribute('name', '{0}.datatype'.format(lo_name))
     element.setAttribute('combine', 'interleave')
     interleave = self.doc.createElement('interleave')
     base = self.get_base_class(new_class['baseClass'], False)
     interleave.appendChild(base)
     child_elements = self.get_lo_children(strFunctions.lower_first(new_class['name']))
     for attrib in new_class['lo_attribs']:
         attribute = self.get_attribute(attrib)
         interleave.appendChild(attribute)
     interleave.appendChild(child_elements)
     element.appendChild(interleave)
     return element
Пример #12
0
 def write_lo_class_definition(self, new_class):
     lo_name = strFunctions.lower_first(
         strFunctions.cap_list_of_name(new_class['name']))
     comment = self.doc.createComment('definition of {0}'.format(lo_name))
     self.doc.documentElement.appendChild(comment)
     element = self.doc.createElement('define')
     element.setAttribute('name', '{0}.datatype'.format(lo_name))
     element.setAttribute('combine', 'interleave')
     interleave = self.doc.createElement('interleave')
     base = self.get_base_class(new_class['baseClass'], False)
     interleave.appendChild(base)
     child_elements = self.get_lo_children(
         strFunctions.lower_first(new_class['name']))
     for attrib in new_class['lo_attribs']:
         attribute = self.get_attribute(attrib)
         interleave.appendChild(attribute)
     interleave.appendChild(child_elements)
     element.appendChild(interleave)
     return element
Пример #13
0
 def write_core_subobject_rule(self, lo_child=None):
     if lo_child is None:
         text = '{0} {1} object may have the optional SBML Level~3 ' \
                'Core subobjects for notes and annotations. No other ' \
                'elements from the SBML Level~3 Core namespaces are ' \
                'permitted on {2} {1}.'\
             .format(self.indef_u, self.formatted_name, self.indef)
         ref = 'SBML Level~3 Version~1 Core, Section~3.2.'
         sev = 'ERROR'
         tc = '{0}{1}AllowedCoreElements'.format(self.up_package, self.name)
         lo = False
     else:
         if 'type' in lo_child:
             loname = strFunctions.get_element_name(lo_child)
             element = lo_child['element']
             lo_name = strFunctions.plural(element)
         else:
             # we are in a plugin so have different fields
             loname = strFunctions.cap_list_of_name(lo_child['name'])
             element = lo_child['name']
             lo_name = strFunctions.plural(element)
         text = 'Apart from the general notes and annotations subobjects ' \
                'permitted on all SBML objects, a \{0} container object ' \
                'may only contain \{1} objects.'\
             .format(loname, element)
         add_extended = True
         if self.package == 'render':
             add_extended = False
         ref = '{0}, {1}.'\
             .format(self.pkg_ref, strFunctions.wrap_section(self.name, True, add_extended))
         sev = 'ERROR'
         tc = '{0}{1}LO{2}AllowedCoreElements'.format(self.up_package, self.name,
                                                  lo_name)
         lo = True
     lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib)
     short = 'Core elements allowed on <{0}>.'.format(self.lower_name)
     lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package)
     return dict({'number': self.number, 'text': text,
                  'reference': ref, 'severity': sev, 'typecode': tc,
                  'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref,
                  'plugin': True, 'object': self.name, 'lo': lo,
                  'reqd': self.reqd_elem, 'opt': self.opt_elem})
Пример #14
0
 def write_core_subobject_rule(self, lo_child=None):
     if lo_child is None:
         text = '{0} {1} object may have the optional SBML Level~3 ' \
                'Core subobjects for notes and annotations. No other ' \
                'elements from the SBML Level 3 Core namespaces are ' \
                'permitted on {2} {1}.'\
             .format(self.indef_u, self.formatted_name, self.indef)
         ref = 'SBML Level~3 Version~1 Core, Section~3.2.'
         sev = 'ERROR'
         tc = '{0}{1}AllowedCoreElements'.format(self.up_package, self.name)
         lo = False
     else:
         if 'type' in lo_child:
             loname = strFunctions.get_element_name(lo_child)
             element = lo_child['element']
             lo_name = strFunctions.plural(element)
         else:
             # we are in a plugin so have different fields
             loname = strFunctions.cap_list_of_name(lo_child['name'])
             element = lo_child['name']
             lo_name = strFunctions.plural(element)
         text = 'Apart from the general notes and annotations subobjects ' \
                'permitted on all SBML objects, a \{0} container object ' \
                'may only contain \{1} objects.'\
             .format(loname, element)
         ref = '{0}, {1}.'\
             .format(self.pkg_ref, strFunctions.wrap_section(self.name))
         sev = 'ERROR'
         tc = '{0}{1}LO{2}AllowedCoreElements'.format(self.up_package, self.name,
                                                  lo_name)
         lo = True
     lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib)
     short = 'Core elements allowed on <{0}>.'.format(self.lower_name)
     lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package)
     return dict({'number': self.number, 'text': text,
                  'reference': ref, 'severity': sev, 'typecode': tc,
                  'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref,
                  'plugin': True, 'object': self.name, 'lo': lo,
                  'reqd': self.reqd_elem, 'opt': self.opt_elem})