Skip to content

Commit

Permalink
merge: Add missing representation links to diagrams
Browse files Browse the repository at this point in the history
  • Loading branch information
Wuestengecko committed Oct 25, 2023
2 parents 9c92750 + 56f8b9e commit ee3d152
Show file tree
Hide file tree
Showing 10 changed files with 409 additions and 212 deletions.
4 changes: 3 additions & 1 deletion capellambse/aird/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ def parse_diagram(

def _element_from_xml(ebd: C.ElementBuilder) -> diagram.DiagramElement:
"""Construct a single diagram element from the model XML."""
if ebd.data_element.get("element") is not None:
element = ebd.data_element.get("element")
tag = ebd.melodyloader[element].tag if element else None
if element is not None and tag != "ownedRepresentationDescriptors":
factory = _semantic.from_xml
else:
factory = _visual.from_xml
Expand Down
17 changes: 15 additions & 2 deletions capellambse/aird/_visual.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ def shape_factory(ebd: c.ElementBuilder) -> diagram.Box:
assert ebd.target_diagram.styleclass is not None

uid = ebd.data_element.attrib[c.ATT_XMID]
label = ebd.data_element.get("description", "")
element = ebd.data_element.get("element")
if element is not None:
label = ebd.melodyloader[element].attrib["name"]
description = ebd.data_element.get("description", "")
else:
label = ebd.data_element.get("description", "")
description = None
parent = ebd.data_element.getparent()
while parent.tag == "children":
parent_uid = parent.attrib.get("element") or parent.attrib.get(
Expand Down Expand Up @@ -97,14 +103,21 @@ def shape_factory(ebd: c.ElementBuilder) -> diagram.Box:
int(layout.attrib.get("width", "0")),
int(layout.attrib.get("height", "0")),
)
styleclass = ebd.data_element.attrib["type"]

if element is not None:
styleclass = "RepresentationLink"
else:
styleclass = "Note"

styleoverrides = _styling.apply_visualelement_styles(
ebd.target_diagram.styleclass, f"Box.{styleclass}", ebd.data_element
)

return diagram.Box(
pos,
size,
label=label,
description=description,
uuid=uid,
parent=parent,
styleclass=styleclass,
Expand Down
4 changes: 4 additions & 0 deletions capellambse/diagram/_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def __init__(
size: diagram.Vec2ish,
*,
label: Box | str | None = None,
description: str | None = None,
uuid: str | None = None,
parent: Box | None = None,
collapsed: bool = False,
Expand All @@ -87,6 +88,8 @@ def __init__(
Box' label text and contained children.
label
This box' label text.
description
Optional label text used only by Representation Links.
uuid
UUID of the semantic element this box represents.
parent
Expand Down Expand Up @@ -124,6 +127,7 @@ def __init__(
self.minsize = minsize
self.maxsize = maxsize
self.label: Box | str | None = label
self.description: str | None = description
self.collapsed: bool = collapsed
self.features: cabc.MutableSequence[str] | None = features

Expand Down
2 changes: 2 additions & 0 deletions capellambse/diagram/_json_enc.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def __encode_box(o: diagram.Box) -> object:
}
if o.label is not None and not o.hidelabel:
jsonobj["label"] = _encode_label(o.label)
if o.description is not None:
jsonobj["description"] = o.description
if o.styleoverrides:
jsonobj["style"] = _encode_styleoverrides(o.styleoverrides)
if o.features:
Expand Down
5 changes: 5 additions & 0 deletions capellambse/diagram/capstyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ class in the form::
"stroke": RGB(255, 204, 102),
"text_fill": RGB(0, 0, 0),
},
"Box.RepresentationLink": {
"fill": RGB(255, 255, 203),
"stroke": RGB(255, 204, 102),
"text_fill": RGB(0, 0, 0),
},
"Box.Requirement": { # ReqVP_Requirement
"fill": COLORS["light_purple"],
"stroke": COLORS["dark_purple"],
Expand Down
1 change: 1 addition & 0 deletions capellambse/svg/decorations.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"Class",
"Enumeration",
"Note",
"RepresentationLink",
"OperationalActivity",
"PhysicalComponent",
}
Expand Down
18 changes: 18 additions & 0 deletions capellambse/svg/drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def add_rect(
*,
class_: str = "",
label: LabelDict | None = None,
description: str | None = None,
features: cabc.Sequence[str] = (),
id_: str | None = None,
children: bool = False,
Expand All @@ -143,6 +144,21 @@ def add_rect(
rect: shapes.Rect = self.__drawing.rect(**rectparams)
grp.add(rect)

if description is not None and label is not None:
new_label: LabelDict = copy.deepcopy(label)
new_label["text"] = description
self._draw_box_label(
LabelBuilder(
new_label,
grp,
labelstyle=text_style,
class_=class_,
text_anchor="middle",
y_margin=None,
icon=False,
)
)

if features or class_ in decorations.needs_feature_line:
self._draw_feature_line(rect, grp, rect_style)
if features:
Expand Down Expand Up @@ -589,6 +605,7 @@ def _draw_box(
children_: cabc.Sequence[str] = (),
features_: cabc.Sequence[str] = (),
label_: str | LabelDict | None = None,
description_: str | None = None,
id_: str,
class_: str,
obj_style: style.Styling,
Expand Down Expand Up @@ -621,6 +638,7 @@ def _draw_box(
class_=class_,
id_=id_,
label=label,
description=description_,
features=features_,
children=bool(children_),
)
Expand Down
1 change: 1 addition & 0 deletions capellambse/svg/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"__GLOBAL__": (
"ErrorSymbol",
"RequirementSymbol",
"RepresentationLinkSymbol",
),
"Error": (),
"Class Diagram Blank": ("ClassSymbol",),
Expand Down
47 changes: 47 additions & 0 deletions capellambse/svg/symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,53 @@ def class_symbol(id_: str = "ClassSymbol") -> container.Symbol:
return symb


@decorations.deco_factories
def representation_link_symbol(
id_: str = "RepresentationLinkSymbol",
) -> container.Symbol:
symb = container.Symbol(id=id_, viewBox="0 0 16 16")
grp = symb.add(container.Group(style="stroke-width:0.5;"))
grp.add(
shapes.Rect(
insert=(5.95, 2.96),
size=(4.98, 2.7),
rx=0.5,
style="fill:#d9d297;stroke:#a48a44;",
)
)
grp.add(
shapes.Rect(
insert=(1.66, 10.1),
size=(4.98, 2.7),
rx=0.5,
style="fill:#abc0c9;stroke:#557099;",
)
)
grp.add(
shapes.Rect(
insert=(10.12, 10.1),
size=(4.98, 2.7),
rx=0.5,
style="fill:#acbd57;stroke:#326f46;",
)
)
grp.add(
path.Path(
d="m 8.4526548,7.7355622 -4.3161119,-0.00711 0.00491,"
"2.2573969 m 4.3112023,-2.250294 4.3161128,-0.00711 "
"-0.0049,2.2573968",
style="fill:none;stroke:#557099;",
)
)
grp.add(
path.Path(
d="m 8.5000114,5.7276095 0.00519,2.0502552",
style="fill:none;stroke:#557099;",
)
)
return symb


@decorations.deco_factories
def fine_arrow_mark(
id_: str = "FineArrow", *, style: style_.Styling, **kw
Expand Down
Loading

0 comments on commit ee3d152

Please sign in to comment.