def render_inheritance_relations(self, context, class_list): if not context.render_inheritance: return for cl in class_list: if is_cenum(cl): continue for sub_class in cl.subclasses: if sub_class in class_list: context.add_line( self.get_node_id(context, cl) + " <|--- " + self.get_node_id(context, sub_class))
def render_classes(self, context, class_list): for cl in class_list: if not is_cclassifier(cl) and not is_cenum(cl): raise CException( f"'{cl!s}' handed to class renderer is not a classifier or enum'" ) self.render_classifier_specification(context, cl) self.render_inheritance_relations(context, class_list) for cl in class_list: self.render_associations(context, cl, class_list) if is_cstereotype(cl): self.render_extended_relations(context, cl, class_list)
def render_associations(self, context, cl, class_list): if not context.render_associations: return if is_cenum(cl): return for association in cl.associations: if context.included_associations is not None: if association not in context.included_associations: continue if association in context.excluded_associations: continue if not association.source == cl: # only render associations outgoing from this class continue if association not in context.visited_associations: context.visited_associations.add(association) if association.target in class_list: self.render_association(context, association, class_list)
def render_attributes(self, context, cl): if not context.render_attributes: return "" if is_cenum(cl): if len(cl.values) == 0: return "" value_string = "{\n" for value in cl.values: value_string += value + "\n" value_string += "}\n" return value_string # this is a classifier if len(cl.attributes) == 0: return "" attribute_string = "{\n" for attribute in cl.attributes: attribute_string += self.render_attribute(attribute) attribute_string += "}\n" return attribute_string
def render_attribute(attribute): type_ = attribute.type t = None if is_cenum(type_) or is_cclassifier(type_): t = type_.name if t is None: t = " " elif type_ == str: t = "String" elif type_ == int: t = "Integer" elif type_ == float: t = "Float" elif type_ == bool: t = "Boolean" elif type_ == list: t = "List" if t is None: raise CException(f"unknown type of attribute: '{attribute!s}") return attribute.name + ": " + t + "\n"