File: generate_ROTATED.py

package info (click to toggle)
python-mcstasscript 0.0.46%2Bgit20250402111921.bfa5a26-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,440 kB
  • sloc: python: 13,421; makefile: 14
file content (47 lines) | stat: -rw-r--r-- 1,537 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
from mcstasscript.instrument_diagram.connections import ConnectionList
from mcstasscript.instrument_diagram.arrow import Arrow


def generate_ROTATED_arrows(components, component_box_dict, box_names, color=None):
    """
    Generate Arrow objects related to the ROTATED relationship of components
    """
    connections = ConnectionList()
    lane_numbers = {}
    for component in components:
        if not component.ROTATED_specified:
            continue

        origin = component_box_dict[component.name]
        if component.ROTATED_reference is None:
            target = component_box_dict["ABSOLUTE"]
        elif component.ROTATED_reference == "PREVIOUS":
            origin_index = box_names.index(component.name)
            target_index = origin_index - 1
            target = component_box_dict[box_names[target_index]]
        else:
            target = component_box_dict[component.ROTATED_reference]

        connections.add(origin, target)

    connections.distribute_lane_numbers(box_names=box_names)

    arrows = []
    for connection in connections.get_connections():
        origin = connection.origin
        target = connection.target
        lane = connection.lane_number

        arrow = Arrow(origin, target, lane=lane, kind="ROTATED")

        arrow.set_sub_lane(1)
        arrow.set_box_offset_origin(0.16)
        arrow.set_box_offset_target(-0.05)
        if color is None:
            arrow.color = "red"
        else:
            arrow.color = color

        arrows.append(arrow)

    return arrows