-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignal.py
More file actions
72 lines (56 loc) · 2.34 KB
/
Copy pathSignal.py
File metadata and controls
72 lines (56 loc) · 2.34 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""Signal class definition file."""
from parapy.core import Base, Input, Part, derived
from parapy.geom import Point, Polyline
from model.Node import Node
class Signal(Base):
"""Represent the Signal class.
This class is the template for each signal object.
"""
signal_dict: dict = Input()
weight: float = Input(0.)
source: str = Input(derived)
destination: str = Input(derived)
source_coordinate: Point = Input(derived)
destination_coordinate: Point = Input(derived)
system_code: int = Input(derived)
mass_per_meter: float = Input(derived)
color: str = Input("red")
@source.getter
def source(self) -> str:
"""Return the source name from the dict."""
return self.signal_dict["source"]
@source_coordinate.getter
def source_coordinate(self) -> Point:
"""Return the source coordinate from the dict."""
return self.signal_dict["source_coordinate"]
@destination.getter
def destination(self) -> str:
"""Return the destination name from the dict."""
return self.signal_dict["destination"]
@destination_coordinate.getter
def destination_coordinate(self) -> Point:
"""Return the destination coordinate from the dict."""
return self.signal_dict["destination_coordinate"]
@system_code.getter
def system_code(self) -> int:
"""Return the system code from the dict."""
return self.signal_dict["system_code"]
@mass_per_meter.getter
def mass_per_meter(self) -> float:
"""Return the mass per unit length from the dict. If not available, return a default value."""
if "mass_per_length" in self.signal_dict:
return self.signal_dict["mass_per_meter"]
else:
return 0.25 # 0.25 kg per meter as default value
@Input
def path(self) -> list[Node]:
"""Initialize the path as a straight line from the source to the destination."""
return [
Node(number=-1, coordinate=self.source_coordinate),
Node(number=-1, coordinate=self.destination_coordinate),
]
@Part
def path_line(self) -> Polyline:
"""Create edges to display in GUI."""
return Polyline(points=[node.coordinate for node in self.path],
line_thickness=2)