Exemple #1
0
def transform_Items(di, parent):
    href = parent.child_with_tag("Definition").attributes["href"]
    ref = templates[href].attributes["uuid"]
    return [
        xml_dict.xml_node("Template", {"ref": ref}),
        xml_dict.xml_node("TemplateRules", {"operator": "and"})
    ]
Exemple #2
0
 def xml(self):
     return xml_dict.xml_node(
         tag='packagedElement',
         attributes={
             XMI.type: 'uml:Enumeration',
             XMI.id: self.id,
             'name': self.name,
         },
         children=[
             xml_dict.xml_node(tag='ownedLiteral',
                               attributes={
                                   XMI.type: 'uml:EnumerationLiteral',
                                   XMI.id: new_id(),
                                   'name': v,
                               }) for v in self.values
         ])
Exemple #3
0
def create_mvd(roots):
    return [xml_dict.xml_node(
        "mvdXML",
        {
            "uuid": transform_uuid(ifcopenshell.guid.new()),
            "name": "",
            "status": "sample",
        },
        children=[xml_dict.xml_node(
            "Templates",
            children=[templates[t] for t in used_template_ids.keys()]
        ),xml_dict.xml_node(
            "Views",
            children=roots
        )]
    )]
Exemple #4
0
 def xml(self):
     return xml_dict.xml_node(tag='packagedElement',
                              attributes={
                                  XMI.type: 'uml:Class',
                                  XMI.id: self.id,
                                  'name': self.name,
                                  'visibility': 'public'
                              })
Exemple #5
0
 def xml(self):
     return xml_dict.xml_node(tag='packagedElement',
                              attributes={
                                  XMI.type: 'uml:Realization',
                                  XMI.id: self.id,
                                  "supplier": self.supplier,
                                  "client": self.client
                              })
Exemple #6
0
def transform_DocConceptRoot(di, parent):
    return xml_dict.xml_node(
        "ConceptRoot",
        {
            'uuid': transform_uuid(di.attributes["UniqueId"]),
            'name': di.child_with_tag("ApplicableEntity").attributes["href"],
            'applicableRootEntity': di.child_with_tag("ApplicableEntity").attributes["href"]
        }
    )
Exemple #7
0
def transform_DocTemplateDefinition(di, parent):
    if di.attributes.get("href"):
        if di.attributes["href"] not in templates:
            raise DependencyError(di.attributes["href"])
        ref = templates[di.attributes["href"]].attributes["uuid"]
        return xml_dict.xml_node(
            "Template",
            {'ref': ref}
        )
    elif di.attributes.get("Type") and di.attributes.get("id"):
        return xml_dict.xml_node(
            "ConceptTemplate",
            {
                'id': di.attributes["id"],
                'uuid': transform_uuid(di.attributes["UniqueId"]),
                'name': di.attributes["Name"],
                'applicableEntity': di.attributes["Type"]
            }
        )
Exemple #8
0
def transform_Documentation(di, parent):
    if parent.tag == "DocTemplateUsage":
        try:
            text = di.text.strip()
        except:
            text = None
        
        if text:
            return xml_dict.xml_node(
                "Definitions",
                children=[xml_dict.xml_node(
                    "Definition",
                    children=[xml_dict.xml_node(
                        "Body",
                        # is already being escaped
                        # text=f"<![CDATA[{text}]]>"
                        text=text                        
                    )]
                )]
            )
Exemple #9
0
def transform_Rules(di, parent):
    if parent.tag == "DocTemplateDefinition":
        tag = "Rules"
    elif parent.tag == "DocModelRuleAttribute":
        tag = "EntityRules"
    else:
        if 'DocModelRuleConstraint' in [c.tag for c in di.children]:
            tag = "Constraints"
            assert len(di.children) == 1
        else:
            tag = "AttributeRules"        
    return xml_dict.xml_node(tag)
Exemple #10
0
    def inner(type_id_connector_id, owner):
        # @todo flatstarmap?
        type_id, connector_id = type_id_connector_id
        li = [
            xml_dict.xml_node(tag='memberEnd',
                              attributes={
                                  XMI.idref: connector_id,
                              })
        ]
        if owner is None:
            li.append(
                xml_dict.xml_node(tag='ownedEnd',
                                  attributes={
                                      XMI.type: 'uml:Property',
                                      XMI.id: connector_id,
                                      "association": assoc_id
                                  },
                                  children=[
                                      xml_dict.xml_node(tag='type',
                                                        attributes={
                                                            XMI.idref: type_id,
                                                        })
                                  ]))
        else:
            owner.children.append(
                xml_dict.xml_node(tag='ownedAttribute',
                                  attributes={
                                      XMI.type: 'uml:Property',
                                      XMI.id: connector_id,
                                      "association": assoc_id
                                  },
                                  children=[
                                      xml_dict.xml_node(tag='type',
                                                        attributes={
                                                            XMI.idref: type_id,
                                                        })
                                  ]))

        return li
Exemple #11
0
def transform_DocTemplateUsage(di, parent):
    children = []
    if di.child_with_tag("Definition").child_with_tag("Items") is None:
        # for non-parametrized usages we need to take care of the definition
        ref = templates[di.child_with_tag("Definition").attributes["href"]].attributes["uuid"]
        children.append(
            xml_dict.xml_node("Template", {"ref": ref})
        )
         
    href = di.child_with_tag("Definition").attributes["href"]
    if href not in used_template_ids:
        used_template_ids[href] = 1
    return xml_dict.xml_node(
        "Concept",
        {
            'uuid': transform_uuid(di.attributes["UniqueId"]),
            'name': templates[href].attributes["name"],
            'status': "sample",
            'override': "false"
        },
        children=children
    )
Exemple #12
0
    def xml(self):

        c_ids = [
            cid or new_id()
            for _, cid in zip_l(self.connector_types, self.connector_ids or [])
        ]
        owners = self.owners or ([None] * len(c_ids))

        return xml_dict.xml_node(tag='packagedElement',
                                 attributes={
                                     XMI.type: self.type,
                                     XMI.id: self.id,
                                     'visibility': 'public'
                                 },
                                 children=list(
                                     flatmap(create_connector(self.id),
                                             zip(self.connector_types, c_ids),
                                             owners)))
Exemple #13
0
def transform_DocTemplateItem(di, parent):
    if "RuleParameters" in di.attributes:       
        params = [p for p in di.attributes.get("RuleParameters", "").split(";") if p and do_try(lambda: parse_mvd_expr(p), lambda: print(f"Failed to parse {p}")) is not failure]
        params = ";".join(params)
        if params:
            params += ";"
            
        try:
            description = [("Description", di.child_with_tag("Documentation").text)]
        except:
            description = []
            
        return xml_dict.xml_node(
            "TemplateRule",
            dict([
                *description,
                ("Parameters", params)
            ])
        )
Exemple #14
0
def transform_DocModelRuleConstraint(di, parent):
    v = di.child_with_tag("Expression").child_with_tag("Value").attributes["Literal"].replace("'", "")
    return xml_dict.xml_node(
        "Constraint", {"Expression": f"[Value]='{v}'"}
    )
Exemple #15
0
 def inner(di, parent):
     return xml_dict.xml_node(
         target,
         {attribute_mapping.get(k, k): v for k, v in di.attributes.items()}
     )