-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathconnection.model.ts
More file actions
99 lines (78 loc) · 1.68 KB
/
connection.model.ts
File metadata and controls
99 lines (78 loc) · 1.68 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import {ConnectionDto, WarningDto} from "../data-structures/technical.data.structures";
import {Vec2D} from "../utils/vec2D";
export class Connection {
private static currentId = 0;
private id: number;
private port1Id: number;
private port2Id: number;
private path: Vec2D[];
private warning: WarningDto | null = null;
private isSelected = false;
constructor(
{id, port1Id, port2Id}: ConnectionDto = {
id: Connection.incrementId(),
port1Id: 0,
port2Id: 0,
},
) {
this.id = id;
this.port1Id = port1Id;
this.port2Id = port2Id;
this.isSelected = false;
if (Connection.currentId < this.id) {
Connection.currentId = this.id;
}
}
private static incrementId(): number {
return ++Connection.currentId;
}
getId(): number {
return this.id;
}
setPort1Id(port1Id: number) {
this.port1Id = port1Id;
}
setPort2Id(port2Id: number) {
this.port2Id = port2Id;
}
getPortId1(): number {
return this.port1Id;
}
getPortId2(): number {
return this.port2Id;
}
setPath(path: Vec2D[]) {
this.path = path;
}
getPath(): Vec2D[] {
return this.path;
}
setWarning(warningTitle: string, warningDescription = "") {
this.warning = {
title: warningTitle,
description: warningDescription,
};
}
resetWarning() {
this.warning = null;
}
hasWarning() {
return this.warning !== null;
}
select() {
this.isSelected = true;
}
unselect() {
this.isSelected = false;
}
selected(): boolean {
return this.isSelected;
}
getDto(): ConnectionDto {
return {
id: this.id,
port1Id: this.port1Id,
port2Id: this.port2Id,
};
}
}