Zum Inhalt

UICube

A class representing a Rubik's cube in the RoboDK graphical user interface.

detach_face(self, face)

Detach the given face from the gripper and attaches it to the mount. That means the chosen segments are set to children of the grip coordinate frame.

Parameters:

Name Type Description Default
face FacePosition

The face to detach

required
Source code in core/ui/ui_cube.py
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
def detach_face(self, face: FacePosition):
    """
    Detach the given face from the gripper and attaches it to the mount.
    That means the chosen segments are set to children of the grip coordinate frame.
    Args:
        face: The face to detach
    """
    self.link.Render(False)
    selected_segments = list(filter(lambda segment: segment is not None and segment.located_in(face), self.segments))
    for segment in selected_segments:
        ui_segment = UIUtilities.get_or_add_cube_segment(segment.id, self.ui_cube_frame)
        ui_segment.setParentStatic(self.link.Item('grip'))
    self.link.Render(True)

perform_rotations(self, rotations, before_step=None, after_step=None)

Perform the given rotations on the cube.

Parameters:

Name Type Description Default
rotations List[core.spatial.Rotation.Rotation]

the rotations to perform

required
before_step Optional[Callable]

an action to perform before each rotation step

None
after_step Optional[Callable]

an action to perform after each rotation step

None
Source code in core/ui/ui_cube.py
80
81
82
83
84
85
86
87
88
89
def perform_rotations(self, rotations: List[spatial.Rotation], before_step: Optional[Callable] = None, after_step: Optional[Callable] = None):
    """Perform the given rotations on the cube.

    Args:
        rotations: the rotations to perform
        before_step: an action to perform before each rotation step
        after_step: an action to perform after each rotation step
    """
    super(UICube, self).perform_rotations(rotations, before_step=before_step, after_step=after_step)
    self.update_ui()

rotate(self, rotation=None, face=None, n=1)

Perform the given rotation on the cube.

If the rotation is given, face and n are ignored.

Parameters:

Name Type Description Default
rotation Optional[core.spatial.Rotation.Rotation]

the rotations to perform

None
face Optional[core.cube.FacePosition.FacePosition]

the face to rotate

None
n int

the number of 90° turns to execute

1
Source code in core/ui/ui_cube.py
67
68
69
70
71
72
73
74
75
76
77
78
def rotate(self, rotation: Optional[spatial.Rotation] = None, face: Optional[FacePosition] = None, n: int = 1):
    """Perform the given rotation on the cube.

    If the `rotation` is given, `face` and `n` are ignored.

    Args:
        rotation: the rotations to perform
        face: the face to rotate
        n: the number of 90° turns to execute
    """
    super(UICube, self).rotate(rotation=rotation, face=face, n=n)
    self.update_ui()

update_ui(self)

Updates the ui of the cube, i.e. take the internal representation (Cube3D) and display it in RoboDK.

Source code in core/ui/ui_cube.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
def update_ui(self):
    """
    Updates the ui of the cube, i.e. take the internal representation (`Cube3D`) and display it in RoboDK.
    """
    self.link.Render(False)

    for segment in self.segments:
        ui_segment = UIUtilities.get_or_add_cube_segment(segment.id, self.ui_cube_frame)
        UIUtilities.set_pose(item=ui_segment, cs=segment.coordinate_system, scaling=UIUtilities.CUBE_SEGMENT_EDGE_LENGTH)
        ui_segment.setColor([0.3, 0.3, 0.3])

        to_delete = set(FacePosition) - segment.colors

        for tile_to_delete in to_delete:
            tile_name = '{}_{}'.format(segment.id, str(tile_to_delete))

            item = self.link.Item(tile_name)
            if item.Valid():
                item.Delete()

        for face in segment.colors:
            tile_name = '{}_{}'.format(segment.id, str(face))

            if face is None or not isinstance(face.to_color(), TileColor):
                continue

            ui_color_tile = UIUtilities.get_or_add_color_tile(tile_name, ui_segment)
            translation = face.to_vector()

            rotation = [0, 0, 0]
            if face == FacePosition.FRONT or face == FacePosition.BACK:
                rotation[2] = 90
            elif face == FacePosition.TOP or face == FacePosition.BOTTOM:
                rotation[0] = 90

            UIUtilities.set_pose(
                ui_color_tile,
                x=translation[0], y=translation[1], z=translation[2],
                rx=rotation[0], ry=rotation[1], rz=rotation[2],
                scaling=UIUtilities.CUBE_SEGMENT_EDGE_LENGTH/2.0-0.5
            )

            ui_color_tile.setColor(list(face.to_color().as_channels(bgr=False, float=True)))

    self.link.Render(True)