Handles name, color and layer metadata for subshapes. :param s: The subshape to add metadata to. :param name: The name to assign to the subshape. :param color: The color to assign to the subshape. :param layer: The layer to assign to the subshape. :r
(
self,
s: Shape,
name: Optional[str] = None,
color: Optional[Color] = None,
layer: Optional[str] = None,
)
| 751 | return display(self)._repr_javascript_() |
| 752 | |
| 753 | def addSubshape( |
| 754 | self, |
| 755 | s: Shape, |
| 756 | name: Optional[str] = None, |
| 757 | color: Optional[Color] = None, |
| 758 | layer: Optional[str] = None, |
| 759 | ) -> "Assembly": |
| 760 | """ |
| 761 | Handles name, color and layer metadata for subshapes. |
| 762 | |
| 763 | :param s: The subshape to add metadata to. |
| 764 | :param name: The name to assign to the subshape. |
| 765 | :param color: The color to assign to the subshape. |
| 766 | :param layer: The layer to assign to the subshape. |
| 767 | :return: The modified assembly. |
| 768 | """ |
| 769 | |
| 770 | # check if the subshape belongs to the stored object |
| 771 | if any(isSubshape(s, obj) for obj in self.shapes): |
| 772 | assy = self |
| 773 | else: |
| 774 | warn( |
| 775 | "Current node does not contain any Shapes, searching in subnodes. In the future this will result in an error." |
| 776 | ) |
| 777 | |
| 778 | found = False |
| 779 | for ch in self.children: |
| 780 | if any(isSubshape(s, obj) for obj in ch.shapes): |
| 781 | assy = ch |
| 782 | found = True |
| 783 | break |
| 784 | |
| 785 | if not found: |
| 786 | raise ValueError( |
| 787 | f"{s} is not a subshape of the current node or its children" |
| 788 | ) |
| 789 | |
| 790 | # Handle any metadata we were passed |
| 791 | if name: |
| 792 | assy._subshape_names[s] = name |
| 793 | if color: |
| 794 | assy._subshape_colors[s] = color |
| 795 | if layer: |
| 796 | assy._subshape_layers[s] = layer |
| 797 | |
| 798 | return self |
| 799 | |
| 800 | def __getitem__(self, name: str) -> Union["Assembly", Shape]: |
| 801 | """ |