-
Notifications
You must be signed in to change notification settings - Fork 28
/
FordiacLayoutData.java
102 lines (86 loc) · 3.67 KB
/
FordiacLayoutData.java
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
100
101
102
/*******************************************************************************
* Copyright (c) 2022 Primetals Technologies Austria GmbH
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Daniel Lindhuber
* - initial API and implementation and/or initial documentation
*******************************************************************************/
package org.eclipse.fordiac.ide.elk;
import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.fordiac.ide.model.CoordinateConverter;
import org.eclipse.fordiac.ide.model.libraryElement.Connection;
import org.eclipse.fordiac.ide.model.libraryElement.ConnectionRoutingData;
import org.eclipse.fordiac.ide.model.libraryElement.FBNetworkElement;
import org.eclipse.fordiac.ide.model.libraryElement.Group;
import org.eclipse.fordiac.ide.model.libraryElement.IInterfaceElement;
import org.eclipse.fordiac.ide.model.libraryElement.LibraryElementFactory;
import org.eclipse.fordiac.ide.model.libraryElement.Position;
public class FordiacLayoutData {
// this helper class should get a record when upgrading to Java 17
public static class ConnectionLayoutData {
public final Connection con;
public final ConnectionRoutingData routingData;
public ConnectionLayoutData(final Connection con, final ConnectionRoutingData routingData) {
this.con = con;
this.routingData = routingData;
}
}
private final Map<FBNetworkElement, Position> positions = new HashMap<>();
private final List<ConnectionLayoutData> connData = new ArrayList<>();
private final Map<IInterfaceElement, Integer> pins = new HashMap<>();
private final Map<Group, Entry<Double, Double>> groups = new HashMap<>();
public Map<FBNetworkElement, Position> getPositions() {
return positions;
}
public List<ConnectionLayoutData> getConnectionPoints() {
return connData;
}
public Map<IInterfaceElement, Integer> getPins() {
return pins;
}
public Map<Group, Entry<Double, Double>> getGroups() {
return groups;
}
public void addPosition(final FBNetworkElement element, final Position position) {
positions.put(element, position);
}
public void addConnectionPoints(final Connection connection, final PointList pointList) {
connData.add(new ConnectionLayoutData(connection, createRoutingData(pointList)));
}
public void addPin(final IInterfaceElement pin, final Integer padding) {
pins.put(pin, padding);
}
public void addGroup(final Group group, final int height, final int width) {
groups.put(group, new SimpleEntry<>(Double.valueOf(CoordinateConverter.INSTANCE.screenToIEC61499(height)),
Double.valueOf(CoordinateConverter.INSTANCE.screenToIEC61499(width))));
}
private static ConnectionRoutingData createRoutingData(final PointList pointList) {
final ConnectionRoutingData routingData = LibraryElementFactory.eINSTANCE.createConnectionRoutingData();
if (pointList.size() > 2) {
// 3 segments
routingData.setDx1(fromScreen(pointList.getPoint(1).x() - pointList.getFirstPoint().x()));
if (pointList.size() > 4) {
// 5 segments
routingData.setDy(fromScreen(pointList.getPoint(2).y() - pointList.getFirstPoint().y()));
routingData.setDx2(
fromScreen(pointList.getLastPoint().x() - pointList.getPoint(pointList.size() - 2).x()));
}
}
return routingData;
}
private static double fromScreen(final int val) {
return CoordinateConverter.INSTANCE.screenToIEC61499(val);
}
}