diff --git a/java/bundles/org.eclipse.set.feature.table.pt1/src/org/eclipse/set/feature/table/pt1/ssks/AbstractSignalTableTransform.java b/java/bundles/org.eclipse.set.feature.table.pt1/src/org/eclipse/set/feature/table/pt1/ssks/AbstractSignalTableTransform.java index 73889f77a2..cb6575debe 100644 --- a/java/bundles/org.eclipse.set.feature.table.pt1/src/org/eclipse/set/feature/table/pt1/ssks/AbstractSignalTableTransform.java +++ b/java/bundles/org.eclipse.set.feature.table.pt1/src/org/eclipse/set/feature/table/pt1/ssks/AbstractSignalTableTransform.java @@ -339,7 +339,7 @@ protected void fillAbstandMastMitte(final TableRow row, final Signal signal, if (distances.stream() .anyMatch(v -> v - .getDistanceToNeighborTrack() > 0)) { + .getDistanceToNeighborTrack() != null)) { addTopologicalCell(row, column); } return distances.stream() diff --git a/java/bundles/org.eclipse.set.feature.table.pt1/src/org/eclipse/set/feature/table/pt1/ssks/SignalSideDistance.java b/java/bundles/org.eclipse.set.feature.table.pt1/src/org/eclipse/set/feature/table/pt1/ssks/SignalSideDistance.java index 6fe3b9520f..6f38190409 100644 --- a/java/bundles/org.eclipse.set.feature.table.pt1/src/org/eclipse/set/feature/table/pt1/ssks/SignalSideDistance.java +++ b/java/bundles/org.eclipse.set.feature.table.pt1/src/org/eclipse/set/feature/table/pt1/ssks/SignalSideDistance.java @@ -19,11 +19,12 @@ import java.util.Iterator; import java.util.List; import java.util.Objects; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; -import org.eclipse.set.basis.Pair; import org.eclipse.set.basis.geometry.GeoPosition; +import org.eclipse.set.model.planpro.BasisTypen.ENUMLinksRechts; import org.eclipse.set.model.planpro.BasisTypen.ENUMWirkrichtung; import org.eclipse.set.model.planpro.Basisobjekte.Punkt_Objekt_TOP_Kante_AttributeGroup; import org.eclipse.set.model.planpro.Signale.ENUMBefestigungArt; @@ -34,6 +35,7 @@ import org.eclipse.set.ppmodel.extensions.PunktObjektTopKanteExtensions; import org.eclipse.set.ppmodel.extensions.SignalRahmenExtensions; import org.eclipse.set.ppmodel.extensions.geometry.GEOKanteGeometryExtensions; +import org.eclipse.set.utils.math.DoubleExtensions; import org.locationtech.jts.geom.Coordinate; import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.geom.GeometryFactory; @@ -51,51 +53,71 @@ public class SignalSideDistance { * Helper class for determine side distance */ public static class SideDistance { - long distanceToMainTrack; + Optional distanceToMainTrack; + Optional distanceToNeighborTrack; + Optional position; /** * @return the distance from signal to main track */ - public double getDistanceToMainTrack() { - return distanceToMainTrack; + public Double getDistanceToMainTrack() { + if (distanceToMainTrack.isPresent()) { + return Double.valueOf( + Math.abs(distanceToMainTrack.get().doubleValue())); + } + return null; } /** * @return the distance from signal to neighbor track */ - public double getDistanceToNeighborTrack() { - return distanceToNeighborTrack; + public Double getDistanceToNeighborTrack() { + if (distanceToNeighborTrack.isEmpty()) { + return null; + } + return Double.valueOf(distanceToNeighborTrack.get().doubleValue()); } - long distanceToNeighborTrack; - /** * @param distanceToMainTrack * the distance from signal to main track * @param distanceToNeighborTrack * the distance from main track to neighbor track + * @param position + * the position of signal */ - public SideDistance(final long distanceToMainTrack, - final long distanceToNeighborTrack) { + public SideDistance(final Optional distanceToMainTrack, + final Optional distanceToNeighborTrack, + final Optional position) { this.distanceToMainTrack = distanceToMainTrack; this.distanceToNeighborTrack = distanceToNeighborTrack; + this.position = position; } + @SuppressWarnings({ "nls", "boxing" }) @Override public String toString() { - if (distanceToNeighborTrack > 0) { - return String.format("%s (%s)", //$NON-NLS-1$ - String.valueOf(distanceToMainTrack), - String.valueOf(distanceToNeighborTrack)); + if (distanceToMainTrack.isEmpty() && position.isEmpty()) { + return ""; + } + final StringBuilder builder = new StringBuilder(); + builder.append(distanceToMainTrack.isPresent() + ? DoubleExtensions.toTableDecimal( + Math.abs(distanceToMainTrack.get().doubleValue())) + : "x"); + if (distanceToNeighborTrack.isPresent() + && distanceToNeighborTrack.get().doubleValue() > 0) { + builder.append(" ("); + builder.append(DoubleExtensions.toTableDecimal( + distanceToNeighborTrack.get().doubleValue())); + builder.append(")"); } - return String.valueOf(distanceToMainTrack); + return builder.toString(); } } final Signal signal; - private final Set sideDistancesRight = new HashSet<>(); - - private final Set sideDistancesLeft = new HashSet<>(); + private final Set sideDistances = new HashSet<>(); private final List relevantMastType; /** @@ -120,14 +142,20 @@ public SignalSideDistance(final Signal signal, * @return distances of the signal to tracks on right side */ public Set getSideDistancesRight() { - return sideDistancesRight; + return sideDistances.stream() + .filter(e -> e.position.isPresent() && e.position + .get() == ENUMLinksRechts.ENUM_LINKS_RECHTS_RECHTS) + .collect(Collectors.toSet()); } /** * @return distances of the signal to tracks on left side */ public Set getSideDistancesLeft() { - return sideDistancesLeft; + return sideDistances.stream() + .filter(e -> e.position.isPresent() && e.position + .get() == ENUMLinksRechts.ENUM_LINKS_RECHTS_LINKS) + .collect(Collectors.toSet()); } /** @@ -141,7 +169,6 @@ public Set getSideDistancesLeft() { * the {@link RuntimeException} * */ - @SuppressWarnings("boxing") private void getSideDistance() throws IllegalArgumentException, NullPointerException, RuntimeException { final Set signalBefestigung = getSignalBefestigung(); @@ -158,13 +185,13 @@ private void getSideDistance() throws IllegalArgumentException, .getWert(); final double signalRotation = PunktObjektExtensions .rotation(signal); - final Pair result = getSideDistance(potk, direction, - signalRotation); + final SideDistance result = determinSideDistanceValue(potk, + direction, signalRotation); if (result == null) { return; } - setSideDistances(result.getFirst(), direction, result.getSecond()); + dertermineSignalPosition(result, direction); }); } @@ -181,39 +208,43 @@ private void getSideDistance() throws IllegalArgumentException, * @return */ @SuppressWarnings("boxing") - public static Pair getSideDistance( + public static SideDistance determinSideDistanceValue( final Punkt_Objekt_TOP_Kante_AttributeGroup potk, final ENUMWirkrichtung direction, final double rotation) { - final Long sideDistance = getNullableObject(potk, p -> Math - .round(p.getSeitlicherAbstand().getWert().doubleValue() * 1000)) - .orElse(null); - if (sideDistance == null) { - return null; + final Optional sideDistance = getNullableObject(potk, + p -> Math.round(p.getSeitlicherAbstand().getWert().doubleValue() + * 1000)); + final Optional position = getNullableObject(potk, + p -> p.getSeitlicheLage().getWert()); + if (sideDistance.isEmpty() && position.isEmpty()) { + return new SideDistance(Optional.empty(), Optional.empty(), + Optional.empty()); } - final long distanceFromPoint = MAX_DISTANCE_TO_NEIGHBOR - - Math.abs(sideDistance); + - Math.abs(sideDistance.orElse((long) 0)); final int perpendicularRotation = getPerpendicularRotation(sideDistance, - direction); + direction, position); if (distanceFromPoint <= 0) { - return new Pair<>(sideDistance, (long) 0); + return new SideDistance(sideDistance, Optional.empty(), position); } double opposideDistance = 0.0; - final GeoPosition position = PunktObjektTopKanteExtensions + final GeoPosition geoPosition = PunktObjektTopKanteExtensions .getCoordinate(potk); try { - opposideDistance = getOpposideDistance(potk, position, + opposideDistance = getOpposideDistance(potk, geoPosition, rotation + perpendicularRotation, distanceFromPoint / 1000.0f); } catch (final Exception e) { throw new RuntimeException(e); } final long distanceBetweenTrack = opposideDistance > 0 - ? Math.abs(sideDistance) + Math.round(opposideDistance * 1000) + ? Math.abs(sideDistance.orElse((long) 0)) + + Math.round(opposideDistance * 1000) : 0; - return new Pair<>(sideDistance, distanceBetweenTrack); + return new SideDistance(sideDistance, Optional.of(distanceBetweenTrack), + position); } private Set getSignalBefestigung() { @@ -235,14 +266,36 @@ private Set getSignalBefestigung() { }).filter(Objects::nonNull).collect(Collectors.toSet()); } - private static int getPerpendicularRotation(final long sideDistance, - final ENUMWirkrichtung direction) throws IllegalArgumentException { - final boolean isPositiveSideDistance = sideDistance >= 0; + private static int getPerpendicularRotation( + final Optional sideDistance, final ENUMWirkrichtung direction, + final Optional position) + throws IllegalArgumentException { + final Optional isPositiveSideDistance = sideDistance + .isPresent() + ? Optional.of(Boolean + .valueOf(sideDistance.get().doubleValue() >= 0)) + : Optional.empty(); + if (isPositiveSideDistance.isEmpty() && position.isEmpty()) { + throw new IllegalArgumentException( + "The Punkt_Objekt haven't either side distcane or side position"); //$NON-NLS-1$ + } switch (direction) { case ENUM_WIRKRICHTUNG_IN: - return isPositiveSideDistance ? 90 : -90; + if (isPositiveSideDistance.isPresent() + && isPositiveSideDistance.get().booleanValue() + || position.isPresent() && position + .get() == ENUMLinksRechts.ENUM_LINKS_RECHTS_RECHTS) { + return 90; + } + return -90; case ENUM_WIRKRICHTUNG_GEGEN: - return isPositiveSideDistance ? -90 : 90; + if (isPositiveSideDistance.isPresent() + && isPositiveSideDistance.get().booleanValue() + || position.isPresent() && position + .get() == ENUMLinksRechts.ENUM_LINKS_RECHTS_LINKS) { + return -90; + } + return 90; default: { throw new IllegalArgumentException( "The Punkt_Objekt have Illegal Wirkrichtung: " //$NON-NLS-1$ @@ -311,36 +364,42 @@ private static double getOpposideDistance( .orElse(Double.valueOf(0)); } - private void setSideDistances(final long sideDistance, - final ENUMWirkrichtung direction, final long distanceBetweenTracks) - throws IllegalArgumentException { - final boolean isPositiveSideDistance = sideDistance >= 0; - final long positiveSideDistance = Math.abs(sideDistance); - switch (direction) { + private void dertermineSignalPosition(final SideDistance sideDistance, + final ENUMWirkrichtung direction) throws IllegalArgumentException { + final Optional isPositiveSideDistance = sideDistance.distanceToMainTrack + .isPresent() + ? Optional.of(Boolean + .valueOf(sideDistance.distanceToMainTrack.get() + .doubleValue() >= 0)) + : Optional.empty(); + final ENUMLinksRechts signalPosition = switch (direction) { case ENUM_WIRKRICHTUNG_IN: { - if (isPositiveSideDistance) { - sideDistancesLeft.add(new SideDistance(positiveSideDistance, - distanceBetweenTracks)); - } else { - sideDistancesRight.add(new SideDistance( - positiveSideDistance, distanceBetweenTracks)); + if (isPositiveSideDistance.isPresent() + && isPositiveSideDistance.get().booleanValue() + || sideDistance.position.isPresent() + && sideDistance.position + .get() == ENUMLinksRechts.ENUM_LINKS_RECHTS_RECHTS) { + yield ENUMLinksRechts.ENUM_LINKS_RECHTS_LINKS; } - break; + yield ENUMLinksRechts.ENUM_LINKS_RECHTS_RECHTS; } case ENUM_WIRKRICHTUNG_GEGEN: { - if (!isPositiveSideDistance) { - sideDistancesLeft.add(new SideDistance(positiveSideDistance, - distanceBetweenTracks)); - } else { - sideDistancesRight.add(new SideDistance( - positiveSideDistance, distanceBetweenTracks)); + if (isPositiveSideDistance.isPresent() + && isPositiveSideDistance.get().booleanValue() + || sideDistance.position.isPresent() + && sideDistance.position + .get() == ENUMLinksRechts.ENUM_LINKS_RECHTS_LINKS) { + yield ENUMLinksRechts.ENUM_LINKS_RECHTS_RECHTS; } - break; + yield ENUMLinksRechts.ENUM_LINKS_RECHTS_LINKS; } default: throw new IllegalArgumentException( "The Signal_Befestigung have Illegal Wirkrichtung: " //$NON-NLS-1$ + direction); - } + }; + sideDistances.add(new SideDistance(sideDistance.distanceToMainTrack, + sideDistance.distanceToNeighborTrack, + Optional.of(signalPosition))); } } diff --git a/java/bundles/org.eclipse.set.feature.table.pt1/src/org/eclipse/set/feature/table/pt1/sskz/SskzTransformator.java b/java/bundles/org.eclipse.set.feature.table.pt1/src/org/eclipse/set/feature/table/pt1/sskz/SskzTransformator.java index a8d84fa4e7..52955d5e15 100644 --- a/java/bundles/org.eclipse.set.feature.table.pt1/src/org/eclipse/set/feature/table/pt1/sskz/SskzTransformator.java +++ b/java/bundles/org.eclipse.set.feature.table.pt1/src/org/eclipse/set/feature/table/pt1/sskz/SskzTransformator.java @@ -24,18 +24,17 @@ import java.util.LinkedList; import java.util.List; import java.util.Objects; -import java.util.Optional; import java.util.Set; import java.util.function.Function; import java.util.function.Predicate; import java.util.stream.Stream; -import org.eclipse.set.basis.Pair; import org.eclipse.set.basis.graph.TopPoint; import org.eclipse.set.core.services.enumtranslation.EnumTranslationService; import org.eclipse.set.core.services.graph.BankService; import org.eclipse.set.feature.table.pt1.AbstractPlanPro2TableModelTransformator; import org.eclipse.set.feature.table.pt1.ssks.SignalSideDistance; +import org.eclipse.set.feature.table.pt1.ssks.SignalSideDistance.SideDistance; import org.eclipse.set.model.planpro.Ansteuerung_Element.Aussenelementansteuerung; import org.eclipse.set.model.planpro.Ansteuerung_Element.ENUMAussenelementansteuerungArt; import org.eclipse.set.model.planpro.Ansteuerung_Element.Stellelement; @@ -253,19 +252,13 @@ private void fillTrackMitteDistance(final TableRow row, fillIterableMultiCellWhenAllowed(row, getColumn(cols, Abstand_FEAx_Gleismitte), control, () -> isFindGeometryComplete(schnittStelle), ele -> { - final Pair sideDistance = getSideDistance(potk); - if (sideDistance != null) { - final String trackDistance = sideDistance.getSecond() - .longValue() > 0 ? String.format("(%d)", //$NON-NLS-1$ - sideDistance.getSecond()) : ""; //$NON-NLS-1$ - if (!trackDistance.isEmpty()) { + final SideDistance sideDistance = getSideDistance(potk); + if (sideDistance.getDistanceToMainTrack() != null) { + if (sideDistance.getDistanceToNeighborTrack() != null) { addTopologicalCell(row, getColumn(cols, SskzColumns.Abstand_FEAx_Gleismitte)); } - return String.format("%s%s", //$NON-NLS-1$ - Math.abs(sideDistance.getFirst()), - trackDistance.isEmpty() ? "" //$NON-NLS-1$ - : " " + trackDistance); //$NON-NLS-1$ + return sideDistance.toString(); } return ""; //$NON-NLS-1$ }); @@ -433,7 +426,7 @@ private List getRelevantFieldElements( .toList(); } - private static Pair getSideDistance( + private static SideDistance getSideDistance( final Punkt_Objekt_TOP_Kante_AttributeGroup potk) { final double rotation = PunktObjektTopKanteExtensions .getCoordinate(potk) @@ -443,14 +436,16 @@ private static Pair getSideDistance( // Find neighbor track in two side if (direction == null || direction == ENUMWirkrichtung.ENUM_WIRKRICHTUNG_BEIDE) { - return Optional - .ofNullable(SignalSideDistance.getSideDistance(potk, - ENUMWirkrichtung.ENUM_WIRKRICHTUNG_IN, rotation)) - .orElse(SignalSideDistance.getSideDistance(potk, - ENUMWirkrichtung.ENUM_WIRKRICHTUNG_GEGEN, - rotation)); + final SideDistance sideDistanceInDirection = SignalSideDistance + .determinSideDistanceValue(potk, + ENUMWirkrichtung.ENUM_WIRKRICHTUNG_IN, rotation); + if (sideDistanceInDirection.getDistanceToNeighborTrack() != null) { + return sideDistanceInDirection; + } + return SignalSideDistance.determinSideDistanceValue(potk, + ENUMWirkrichtung.ENUM_WIRKRICHTUNG_GEGEN, rotation); } - return SignalSideDistance.getSideDistance(potk, + return SignalSideDistance.determinSideDistanceValue(potk, potk.getWirkrichtung().getWert(), rotation); } diff --git a/java/bundles/org.eclipse.set.feature/rootdir/data/export/excel/ssks_vorlage.xlsx b/java/bundles/org.eclipse.set.feature/rootdir/data/export/excel/ssks_vorlage.xlsx index 2e3894e3fa..e7a75e0988 100644 Binary files a/java/bundles/org.eclipse.set.feature/rootdir/data/export/excel/ssks_vorlage.xlsx and b/java/bundles/org.eclipse.set.feature/rootdir/data/export/excel/ssks_vorlage.xlsx differ diff --git a/java/bundles/org.eclipse.set.feature/rootdir/data/export/excel/sskx_vorlage.xlsx b/java/bundles/org.eclipse.set.feature/rootdir/data/export/excel/sskx_vorlage.xlsx index c32aacb4e9..79448da374 100644 Binary files a/java/bundles/org.eclipse.set.feature/rootdir/data/export/excel/sskx_vorlage.xlsx and b/java/bundles/org.eclipse.set.feature/rootdir/data/export/excel/sskx_vorlage.xlsx differ