Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.eclipse.set.model.planpro.Bahnuebergang.BUE_Kante
import org.eclipse.set.model.planpro.Balisentechnik_ETCS.DP_Typ_GETCS_AttributeGroup
import org.eclipse.set.model.planpro.Balisentechnik_ETCS.Datenpunkt
import org.eclipse.set.model.planpro.Balisentechnik_ETCS.ZUB_Streckeneigenschaft
import org.eclipse.set.model.planpro.BasisTypen.ENUMAusrichtung
import org.eclipse.set.model.planpro.BasisTypen.ENUMWirkrichtung
import org.eclipse.set.model.planpro.Basisobjekte.Basis_Objekt
import org.eclipse.set.model.planpro.Basisobjekte.Punkt_Objekt
Expand Down Expand Up @@ -351,7 +352,7 @@ class SszaTransformator extends AbstractPlanPro2TableModelTransformator {
fill(
cols.getColumn(rel_Lage_b_zu_a),
datenpunkt,
[datenpunktAllg?.datenpunktLaenge?.wert?.toString]
[relLagebzua]
)

fillFootnotes(datenpunkt)
Expand Down Expand Up @@ -557,4 +558,24 @@ class SszaTransformator extends AbstractPlanPro2TableModelTransformator {
return pointCoordinate.coordinate.
getStreckeKmThroughProjection(strecke).toTableDecimal
}

private def String getRelLagebzua(Datenpunkt dp) {
val lange = dp?.datenpunktAllg?.datenpunktLaenge?.wert.toTableDecimal
if (lange === null) {
return ""
}

val direction = dp?.datenpunktAllg?.ausrichtung?.wert
if (direction === null) {
return lange
}

val topKante = dp.singlePoint.topKante
val isTopKanteRouteSameDirection = dp.punktObjektStrecke.exists [
topKante.isInRouteDirection(IDStrecke.value)
]
return isTopKanteRouteSameDirection ===
(direction === ENUMAusrichtung.ENUM_AUSRICHTUNG_IN) ? lange : "-" +
lange
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class PunktObjektExtensions extends BasisObjektExtensions {
cache.set(poGuid, #[])
return #[]
}

val getStreckeFunc = [ Punkt_Objekt_Strecke_AttributeGroup pos |
pos.IDStrecke?.value?.bezeichnung?.bezeichnungStrecke?.wert ?: ""
]
Expand All @@ -213,13 +213,13 @@ class PunktObjektExtensions extends BasisObjektExtensions {
cache.set(poGuid, result)
return result
}

if (!isFindGeometryComplete) {
return po.punktObjektStrecke.map [ pos |
getStreckeFunc.apply(pos) -> #[]
].toList
}

val routeThroughBereichObjekt = po.singlePoint.
streckenThroughBereichObjekt

Expand All @@ -243,10 +243,18 @@ class PunktObjektExtensions extends BasisObjektExtensions {
return cachedValue.flatMap[value].toList
}

if (po.punktObjektStrecke.size == 1 &&
routeThroughBereichObjekt.contains(
po.punktObjektStrecke.first.IDStrecke.value)) {
return #[po.punktObjektStrecke.first.streckeKm.wert]
}

val kmMassgebend = po.punktObjektStrecke.filter [
kmMassgebend?.wert === true
]
if (!kmMassgebend.nullOrEmpty) {
if (!kmMassgebend.nullOrEmpty &&
routeThroughBereichObjekt.contains(
po.punktObjektStrecke.first.IDStrecke.value)) {
return kmMassgebend.map[streckeKm.wert].toList
}

Expand All @@ -257,7 +265,7 @@ class PunktObjektExtensions extends BasisObjektExtensions {
val result = routeThroughBereichObjekt.map [ route |
try {
return route ->
po.singlePoint.getStreckeKmThroughProjection(route).
po.singlePoints.first.getStreckeKmThroughProjection(route).
toTableDecimal(3)
} catch (Exception e) {
logger.error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
*/
package org.eclipse.set.ppmodel.extensions

import java.util.Comparator
import java.util.regex.Pattern
import org.eclipse.set.basis.extensions.MatcherExtensions
import org.eclipse.set.model.planpro.Basisobjekte.Punkt_Objekt_Strecke_AttributeGroup
import org.eclipse.set.model.planpro.Geodaten.Strecke

Expand All @@ -18,6 +21,10 @@ import org.eclipse.set.model.planpro.Geodaten.Strecke
*/
class PunktObjektStreckeExtensions extends BasisObjektExtensions {

public static final Pattern KILOMETRIERUNG_PATTERN = Pattern.compile(
"(?<numberN>-?([1-9]\\d{0,2}|0)),((?<numberD1>\\d{3})|(?<numberD2>\\d)(?<numberN2>[\\+\\-][1-9]\\d{0,4}))"); // $NON-NLS-1$
static final String EXTRA_LENGTH_GROUP_NAME = "numberN2"; // $NON-NLS-1$

/**
* @param p this Punkt Objekt
*
Expand All @@ -26,4 +33,29 @@ class PunktObjektStreckeExtensions extends BasisObjektExtensions {
def static Strecke getStrecke(Punkt_Objekt_Strecke_AttributeGroup p) {
return p.IDStrecke?.value
}

def static Comparator<String> compareKm() {
return [first, second|
if (!KILOMETRIERUNG_PATTERN.matcher(first).matches || !KILOMETRIERUNG_PATTERN.matcher(second).matches) {
return 0
}
val firstKm = first.analyseKmValue
val secondKm = second.analyseKmValue
val mainValueComapare = firstKm.key.compareTo(secondKm.key)
if (mainValueComapare !== 0) {
return mainValueComapare
}
return firstKm.value.compareTo(secondKm.value)
]
}

def static Pair<Double, Double> analyseKmValue(String km) {
val matcher = KILOMETRIERUNG_PATTERN.matcher(km)
val extraLength = MatcherExtensions.getGroup(matcher, EXTRA_LENGTH_GROUP_NAME)
if (extraLength.present) {
val mainKm = km.replace(extraLength.get, "")
return Double.valueOf(mainKm.replace(",", ".")) -> Double.valueOf(extraLength.get)
}
return Double.valueOf(km.replace(",", ".")) -> Double.valueOf(0)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import org.eclipse.set.model.planpro.Basisobjekte.Ur_Objekt
import org.eclipse.set.model.planpro.Geodaten.ENUMTOPAnschluss
import org.eclipse.set.model.planpro.Geodaten.GEO_Kante
import org.eclipse.set.model.planpro.Geodaten.GEO_Knoten
import org.eclipse.set.model.planpro.Geodaten.Strecke
import org.eclipse.set.model.planpro.Geodaten.TOP_Kante
import org.eclipse.set.model.planpro.Geodaten.TOP_Knoten
import org.eclipse.set.model.planpro.Weichen_und_Gleissperren.W_Kr_Gsp_Element
Expand All @@ -47,9 +48,13 @@ import static extension org.eclipse.set.ppmodel.extensions.GeoKanteExtensions.*
import static extension org.eclipse.set.ppmodel.extensions.GeoKnotenExtensions.*
import static extension org.eclipse.set.ppmodel.extensions.PunktObjektExtensions.*
import static extension org.eclipse.set.ppmodel.extensions.PunktObjektTopKanteExtensions.*
import static extension org.eclipse.set.ppmodel.extensions.PunktObjektStreckeExtensions.*
import static extension org.eclipse.set.ppmodel.extensions.TopKnotenExtensions.*
import static extension org.eclipse.set.ppmodel.extensions.utils.CollectionExtensions.*
import static extension org.eclipse.set.ppmodel.extensions.utils.SetExtensions.*
import static extension org.eclipse.set.ppmodel.extensions.utils.IterableExtensions.*
import org.eclipse.set.ppmodel.extensions.utils.DirectedTopKante
import com.google.common.collect.Comparators

/**
* Diese Klasse erweitert {@link TOP_Kante}.
Expand Down Expand Up @@ -849,4 +854,49 @@ class TopKanteExtensions extends BasisObjektExtensions {
}
return result
}

def static boolean isInRouteDirection(TOP_Kante topKante, Strecke strecke) {
val directTopKante = new DirectedTopKante(topKante, true)
val punktObjektsWithDistance = directTopKante.iterator.filter [
IDTOPKante.value === topKante
].filter[eContainer instanceof Punkt_Objekt].map [
(eContainer as Punkt_Objekt) -> abstand.wert
].toList

// Sorting the Punkt_Objekt by Top_Kante distance to start of TOP_Kante
if (!Comparators.isInOrder(punktObjektsWithDistance, [ a, b |
a.value.compareTo(b.value)
])) {
punktObjektsWithDistance.sortWith([a, b|a.value.compareTo(b.value)])
}

val streckenKmStoredByTopKanteDirection = punktObjektsWithDistance.map [ pair |
pair.key.getStreckeKm(List.of(strecke)).firstOrNull
].filterNull.toList

// The route kilometer of a Punkt_Objekt can be inconsistent and
// may not follow the monotonic route kilometer sequence.
// Consequently, both counter variables track increasing and
// decreasing kilometers along the route. If the number of increasing steps
// exceeds the number of decreasing steps,
// the TOP_Kante is oriented in the same direction as the route.
var upwardCount = 0
var downwardCount = 0
for (var i = 0, var j = streckenKmStoredByTopKanteDirection.size -
1; i < streckenKmStoredByTopKanteDirection.size / 2 &&
j > streckenKmStoredByTopKanteDirection.size / 2; i++, j--) {
val first = streckenKmStoredByTopKanteDirection.get(i)
val second = streckenKmStoredByTopKanteDirection.get(j)
val compareValue = compareKm.compare(
first,
second
)
if (compareValue > 0) {
downwardCount++
} else {
upwardCount++
}
}
return upwardCount > downwardCount
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.eclipse.set.basis.Pair;
import org.eclipse.set.model.planpro.BasisTypen.util.BasisTypenValidator;
import org.eclipse.set.model.planpro.Basisobjekte.Punkt_Objekt;
import org.eclipse.set.ppmodel.extensions.PunktObjektStreckeExtensions;
import org.eclipse.set.utils.table.sorting.CompareRouteAndKmCriterion;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -134,8 +135,7 @@ private void thenExpectEqualsSortedList() {
@SuppressWarnings("boxing")
private void thenThePatternMustMatch() {
assertEquals(1, kilometrierungPatternInSchema.size());
final Pattern kilometrierungPattern = CompareRouteAndKmCriterion
.getKilometrierungPattern();
final Pattern kilometrierungPattern = PunktObjektStreckeExtensions.KILOMETRIERUNG_PATTERN;
final Pattern schemaPattern = Pattern
.compile(kilometrierungPatternInSchema.getFirst());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@
import java.util.Set;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.eclipse.nebula.widgets.nattable.sort.SortDirectionEnum;
import org.eclipse.set.basis.constants.Events;
import org.eclipse.set.basis.extensions.MatcherExtensions;
import org.eclipse.set.model.planpro.Basisobjekte.Punkt_Objekt;
import org.eclipse.set.model.planpro.Basisobjekte.Ur_Objekt;
import org.eclipse.set.model.tablemodel.TableRow;
import org.eclipse.set.model.tablemodel.extensions.TableRowExtensions;
import org.eclipse.set.ppmodel.extensions.PunktObjektExtensions;
import org.eclipse.set.ppmodel.extensions.PunktObjektStreckeExtensions;
import org.eclipse.xtext.xbase.lib.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -46,9 +45,6 @@ public class CompareRouteAndKmCriterion
private final SortDirectionEnum direction;
private final Function<Ur_Objekt, Punkt_Objekt> getPunktObjectFunc;
private final NumericCellComparator numericComparator;
private static final String KILOMETRIERUNG_PATTERN = "(?<numberN>-?([1-9]\\d{0,2}|0)),((?<numberD1>\\d{3})|(?<numberD2>\\d)(?<numberN2>[\\+\\-][1-9]\\d{0,4}))"; //$NON-NLS-1$
private static final String EXTRA_LENGTH_GROUP_NAME = "numberN2"; //$NON-NLS-1$
private final Pattern kmPattern;
private boolean isWaitingOnService = false;

/**
Expand All @@ -72,7 +68,6 @@ public CompareRouteAndKmCriterion(
this.getPunktObjectFunc = getPunktObjectFunc;
this.direction = direction;
this.numericComparator = new NumericCellComparator(direction);
this.kmPattern = getKilometrierungPattern();
}

@Override
Expand Down Expand Up @@ -166,8 +161,10 @@ public int compareKm(final Set<String> firstKms,
}

final int compare = direction == SortDirectionEnum.ASC
? compareKm(firstKm, secondKm)
: compareKm(secondKm, firstKm);
? PunktObjektStreckeExtensions.compareKm()
.compare(firstKm, secondKm)
: PunktObjektStreckeExtensions.compareKm()
.compare(secondKm, firstKm);
if (compare != 0) {
return compare;
}
Expand All @@ -176,47 +173,16 @@ public int compareKm(final Set<String> firstKms,
return 0;
}

private int compareKm(final String first, final String second) {
final Pair<Double, Double> firstKm = analyseKmValue(first);
final Pair<Double, Double> secondKm = analyseKmValue(second);
final int mainValueCompare = firstKm.getKey()
.compareTo(secondKm.getKey());
if (mainValueCompare != 0) {
return mainValueCompare;
}
return firstKm.getValue().compareTo(secondKm.getValue());
}

@SuppressWarnings("nls")
private Pair<Double, Double> analyseKmValue(final String km) {
final Matcher matcher = kmPattern.matcher(km);
final Optional<String> extraLength = MatcherExtensions.getGroup(matcher,
EXTRA_LENGTH_GROUP_NAME);
if (extraLength.isPresent()) {
final String mainKm = km.replace(extraLength.get(), "");
return new Pair<>(Double.valueOf(mainKm.replace(",", ".")),
Double.valueOf(extraLength.get()));
}
return new Pair<>(Double.valueOf(km.replace(",", ".")),
Double.valueOf(0));
}

private boolean kmPatternCheck(final String km) {
final Matcher matcher = kmPattern.matcher(km);
final Matcher matcher = PunktObjektStreckeExtensions.KILOMETRIERUNG_PATTERN
.matcher(km);
if (!matcher.matches()) {
logger.error("Wrong Kilometer format: {}", km); //$NON-NLS-1$
return true;
}
return false;
}

/**
* @return the kilometer pattern
*/
public static Pattern getKilometrierungPattern() {
return Pattern.compile(KILOMETRIERUNG_PATTERN);
}

private <T> Optional<Integer> compareCollection(final Collection<T> first,
final Collection<T> second) {
if (first.isEmpty() == second.isEmpty() && first.isEmpty()) {
Expand Down
Loading