Search in sources :

Example 21 with TimeInterval

use of net.parostroj.timetable.model.TimeInterval in project grafikon by jub77.

the class BaseConnectionStrategy method getFreightToNodesImpl.

private void getFreightToNodesImpl(Node start, TimeInterval fromInterval, List<TrainConnection> path, List<FreightConnectionPath> result, Set<FNConnection> used, FreightConnectionFilter filter, FilterContext context) {
    FilterResult filterResult;
    Iterator<TimeInterval> intervals = fromInterval.getTrain().iterator();
    Iterators.find(intervals, interval -> interval == fromInterval);
    intervals = Iterators.filter(intervals, interval -> interval.isNodeOwner() && (interval.isFreightTo() || interval.isFreightConnection()));
    while (intervals.hasNext()) {
        TimeInterval i = intervals.next();
        if (i.isFreight()) {
            FreightConnectionPath newDst = FreightFactory.createFreightNodeConnection(start, i.getOwnerAsNode(), i.isRegionCenterTransfer(), createNewPath(path, fromInterval, i));
            filterResult = filter.accepted(context, newDst, 0);
            if (filterResult == FilterResult.STOP_EXCLUDE) {
                break;
            }
            if (filterResult != FilterResult.IGNORE) {
                result.add(newDst);
            }
            if (filterResult == FilterResult.STOP_INCLUDE) {
                break;
            }
        }
        for (FNConnection conn : freightNet.getTrainsFrom(i)) {
            if (!used.contains(conn)) {
                used.add(conn);
                List<TrainConnection> newPath = createNewPath(path, fromInterval, conn.getFrom());
                this.getFreightToNodesImpl(start, conn.getTo(), newPath, result, used, conn.getFreightDstFilter(filter, false), context);
            }
        }
    }
}
Also used : Iterator(java.util.Iterator) FilterResult(net.parostroj.timetable.model.FreightConnectionFilter.FilterResult) Collection(java.util.Collection) Set(java.util.Set) Node(net.parostroj.timetable.model.Node) Iterators(com.google.common.collect.Iterators) FNConnection(net.parostroj.timetable.model.FNConnection) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) FilterContext(net.parostroj.timetable.model.FreightConnectionFilter.FilterContext) TimeInterval(net.parostroj.timetable.model.TimeInterval) FreightNet(net.parostroj.timetable.model.FreightNet) Map(java.util.Map) FreightConnectionFilter(net.parostroj.timetable.model.FreightConnectionFilter) LinkedList(java.util.LinkedList) Collections(java.util.Collections) TrainDiagram(net.parostroj.timetable.model.TrainDiagram) Train(net.parostroj.timetable.model.Train) TimeInterval(net.parostroj.timetable.model.TimeInterval) FilterResult(net.parostroj.timetable.model.FreightConnectionFilter.FilterResult) FNConnection(net.parostroj.timetable.model.FNConnection)

Example 22 with TimeInterval

use of net.parostroj.timetable.model.TimeInterval in project grafikon by jub77.

the class TrainTableModel method setValueAt.

@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    int time = 0;
    editBlock = true;
    TimeInterval interval = train.getTimeIntervalList().get(rowIndex);
    TrainTableColumn column = TrainTableColumn.getColumn(columnIndex);
    switch(column) {
        case START:
            time = converter.convertTextToInt((String) aValue);
            if (time != -1) {
                int oldTime = TimeUtil.normalizeTime(interval.getStart());
                int newTime = TimeUtil.normalizeTime(time);
                int newStartTime = TimeUtil.normalizeTime(train.getStartTime() + (newTime - oldTime));
                train.move(newStartTime);
                this.fireTableRowsUpdated(0, lastRow);
            }
            break;
        case END:
            // departure
            time = converter.convertTextToInt((String) aValue);
            if (time != -1) {
                if (rowIndex == 0) {
                    train.move(time);
                    this.fireTableDataChanged();
                } else {
                    int start = TimeUtil.normalizeTime(interval.getStart());
                    time = TimeUtil.normalizeTime(time);
                    if (time < start) {
                        time += TimeInterval.DAY;
                    }
                    int newStop = time - start;
                    if (newStop >= 0) {
                        train.changeStopTime(interval, newStop);
                        this.fireTableRowsUpdated(rowIndex - 1, lastRow);
                    }
                }
            }
            break;
        case STOP:
            // stop time
            try {
                time = converter.convertMinutesTextToInt((String) aValue);
            } catch (ParseException e) {
                // wrong conversion doesn't change anything
                time = -1;
            }
            if (time >= 0) {
                boolean originalIsFreight = interval.isFreight();
                train.changeStopTime(interval, time);
                int firstRow = rowIndex - 1;
                if (interval.isFreight() != originalIsFreight) {
                    firstRow = 0;
                }
                this.fireTableRowsUpdated(firstRow, lastRow);
            }
            break;
        case SPEED_LIMIT:
            // velocity limit
            Integer velocity = (Integer) aValue;
            if (velocity == null || velocity > 0) {
                train.changeSpeedAndAddedTime(interval, velocity, interval.getAddedTime());
                this.fireTableRowsUpdated(rowIndex - 2 >= 0 ? rowIndex - 2 : 0, lastRow);
            }
            break;
        case ADDED_TIME:
            // added time
            if (aValue != null) {
                int addedTime;
                try {
                    addedTime = ObjectsUtil.isEmpty((String) aValue) ? 0 : converter.convertMinutesTextToInt((String) aValue);
                } catch (ParseException e) {
                    // wrong conversion doesn't change anything
                    addedTime = -1;
                }
                if (addedTime >= 0) {
                    train.changeSpeedAndAddedTime(interval, interval.getSpeedLimit(), addedTime);
                }
            } else {
                train.changeSpeedAndAddedTime(interval, interval.getSpeedLimit(), 0);
            }
            this.fireTableRowsUpdated(rowIndex, lastRow);
            break;
        case PLATFORM:
            // platform
            Track track = (Track) aValue;
            if (interval.isNodeOwner()) {
                NodeTrack newTrack = (NodeTrack) track;
                if (newTrack != null) {
                    train.changeNodeTrack(interval, newTrack);
                    this.fireTableRowsUpdated(rowIndex, rowIndex);
                }
            } else if (interval.isLineOwner()) {
                LineTrack newTrack = (LineTrack) track;
                if (newTrack != null) {
                    train.changeLineTrack(interval, newTrack);
                    this.fireTableRowsUpdated(rowIndex, rowIndex);
                }
            }
            break;
        case COMMENT:
            // comment
            String commentStr = ObjectsUtil.checkAndTrim((String) aValue);
            LocalizedString lComment = null;
            if (commentStr != null) {
                lComment = LocalizedString.newBuilder(interval.getComment()).setDefaultString(commentStr).build();
            }
            interval.getAttributes().setRemove(TimeInterval.ATTR_COMMENT, lComment);
            break;
        case OCCUPIED_ENTRY:
            // entry of the occupied track
            interval.getAttributes().setBool(TimeInterval.ATTR_OCCUPIED, (Boolean) aValue);
            break;
        case SHUNT:
            // entry shunting on the far side
            interval.getAttributes().setBool(TimeInterval.ATTR_SHUNT, (Boolean) aValue);
            break;
        case COMMENT_SHOWN:
            // entry shunting on the far side
            interval.getAttributes().setBool(TimeInterval.ATTR_COMMENT_SHOWN, (Boolean) aValue);
            break;
        case SET_SPEED:
            // train speed
            Integer trainSpeed = (Integer) aValue;
            if (trainSpeed != null && trainSpeed <= 0) {
                trainSpeed = null;
            }
            interval.getAttributes().setRemove(TimeInterval.ATTR_SET_SPEED, trainSpeed);
            break;
        case IGNORE_LENGTH:
            // ignore length of the station in computation
            interval.getAttributes().setBool(TimeInterval.ATTR_IGNORE_LENGTH, (Boolean) aValue);
            this.fireTableRowsUpdated(rowIndex, rowIndex);
            break;
        case MANAGED_FREIGHT:
            interval.getAttributes().setBool(TimeInterval.ATTR_NOT_MANAGED_FREIGHT, !((Boolean) aValue));
            this.fireTableRowsUpdated(0, lastRow);
            break;
        case REGION_CENTER_TRANSFER:
            interval.setAttributeAsBool(TimeInterval.ATTR_NO_REGION_CENTER_TRANSFER, !((Boolean) aValue));
            this.fireTableRowsUpdated(0, lastRow);
            break;
        default:
            break;
    }
    editBlock = false;
}
Also used : NodeTrack(net.parostroj.timetable.model.NodeTrack) TimeInterval(net.parostroj.timetable.model.TimeInterval) LocalizedString(net.parostroj.timetable.model.LocalizedString) ParseException(java.text.ParseException) LocalizedString(net.parostroj.timetable.model.LocalizedString) LineTrack(net.parostroj.timetable.model.LineTrack) NodeTrack(net.parostroj.timetable.model.NodeTrack) Track(net.parostroj.timetable.model.Track) LineTrack(net.parostroj.timetable.model.LineTrack)

Example 23 with TimeInterval

use of net.parostroj.timetable.model.TimeInterval in project grafikon by jub77.

the class LoadFilter4d19 method checkDiagram.

@Override
public void checkDiagram(TrainDiagram diagram, ModelVersion version) {
    if (version.compareTo(new ModelVersion(4, 19, 0)) <= 0) {
        // not passing cargo in center (move to time interval from train)
        for (Train train : diagram.getTrains()) {
            if (train.getAttributeAsBool("no.transitive.region.start")) {
                for (TimeInterval interval : train.getNodeIntervals()) {
                    if (interval.isFirst())
                        continue;
                    if (interval.getOwnerAsNode().isCenterOfRegions()) {
                        interval.setAttributeAsBool(TimeInterval.ATTR_NO_REGION_CENTER_TRANSFER, true);
                    }
                }
            }
        }
    }
    if (version.compareTo(new ModelVersion(4, 19, 2)) <= 0) {
        // convert some texts to localized strings
        this.convertToLocalizedStrings(diagram);
        // filter out output templates with default.template
        removeDefaultTemplatesExceptDrawAndXml(diagram);
    }
}
Also used : TimeInterval(net.parostroj.timetable.model.TimeInterval) ModelVersion(net.parostroj.timetable.model.ls.ModelVersion) Train(net.parostroj.timetable.model.Train)

Example 24 with TimeInterval

use of net.parostroj.timetable.model.TimeInterval in project grafikon by jub77.

the class TrainTimetablesExtractor method extractRows.

private void extractRows(Train train, TrainTimetable timetable) {
    timetable.setRows(new LinkedList<TrainTimetableRow>());
    Iterator<TimeInterval> i = train.getTimeIntervalList().iterator();
    TimeInterval lastLineI = null;
    while (i.hasNext()) {
        TimeInterval nodeI = i.next();
        TimeInterval lineI = i.hasNext() ? i.next() : null;
        if (nodeI.getOwnerAsNode().getType() == NodeType.SIGNAL) {
            lastLineI = lineI;
            continue;
        }
        TrainTimetableRow row = new TrainTimetableRow();
        row.setRef(nodeI);
        if (nodeI.getOwnerAsNode().getAttributes().getBool(Node.ATTR_CONTROL_STATION)) {
            row.setControlStation(true);
        }
        if (Node.IP_NEW_SIGNALS.equals(nodeI.getOwnerAsNode().getAttribute(Node.ATTR_INTERLOCKING_PLANT, String.class))) {
            row.setLightSignals(true);
        }
        row.setStation(nodeI.getOwnerAsNode().getName());
        row.setStationAbbr(nodeI.getOwnerAsNode().getAbbr());
        row.setStationType(nodeI.getOwnerAsNode().getType().getKey());
        if (!nodeI.isFirst())
            row.setArrival(diagram.getTimeConverter().convertIntToXml(nodeI.getStart()));
        if (!nodeI.isLast())
            row.setDeparture(diagram.getTimeConverter().convertIntToXml(nodeI.getEnd()));
        if (lineI != null) {
            row.setSpeed(lineI.getSpeed());
            row.setLineTracks(lineI.getOwnerAsLine().getTracks().size());
            row.setSetSpeed(lineI.getAttribute(TimeInterval.ATTR_SET_SPEED, Integer.class));
        }
        // comment
        if (nodeI.getAttributes().getBool(TimeInterval.ATTR_COMMENT_SHOWN)) {
            row.setComment(nodeI.getComment());
        }
        // check line end
        if ((nodeI.isLast() || nodeI.isInnerStop()) && nodeI.getTrack().getAttributes().getBool(Track.ATTR_LINE_END)) {
            row.setLineEnd(Boolean.TRUE);
        }
        // check occupied track
        if (nodeI.getAttributes().getBool(TimeInterval.ATTR_OCCUPIED)) {
            row.setOccupied(Boolean.TRUE);
        }
        // check shunt
        if (nodeI.getAttributes().getBool(TimeInterval.ATTR_SHUNT)) {
            row.setShunt(Boolean.TRUE);
        }
        if (nodeI.getOwnerAsNode().getTracks().size() > 1)
            row.setTrack(nodeI.getTrack().getNumber());
        boolean onControlled = checkOnControlled(nodeI.getOwnerAsNode());
        if (onControlled)
            row.setOnControlled(true);
        if (lastLineI != null && lastLineI.getToStraightTrack() != null)
            row.setStraight(lastLineI.getToStraightTrack() == nodeI.getTrack());
        if (nodeI.getOwnerAsNode().getAttributes().getBool(Node.ATTR_TRAPEZOID_SIGN)) {
            Pair<Boolean, List<TranslatedString>> concurrentTrains = this.getConcurrentTrains(nodeI);
            if (concurrentTrains != null) {
                row.setConcurrentTrains(concurrentTrains.second);
                row.setFirstConcurrent(concurrentTrains.first);
            }
        }
        LineClass lineClass = lineI != null ? lineI.getLineClass() : null;
        if (lineClass != null)
            row.setLineClass(lineClass.getName());
        // route position
        Double routePosition = null;
        Double routePositionOut = null;
        if (lineI != null)
            routePositionOut = this.getRoutePosition(lineI.getOwnerAsLine(), nodeI.getOwnerAsNode());
        if (lastLineI != null)
            routePosition = this.getRoutePosition(lastLineI.getOwnerAsLine(), nodeI.getOwnerAsNode());
        if (routePosition == null)
            routePosition = routePositionOut;
        if (routePosition != null && routePositionOut != null && routePosition.doubleValue() == routePositionOut.doubleValue())
            routePositionOut = null;
        row.setRoutePosition(routePosition);
        row.setRoutePositionOut(routePositionOut);
        // freight
        if (nodeI.isFirst() && nodeI.isFreight()) {
            List<? extends FreightConnection> freightDests = strategy.getFreightToNodes(nodeI);
            if (!freightDests.isEmpty()) {
                ArrayList<FreightDestinationInfo> fl = new ArrayList<>(freightDests.size());
                for (FreightConnection dst : freightDests) {
                    fl.add(FreightDestinationInfo.convert(locale, dst));
                }
                row.setFreightDest(fl);
            }
        }
        timetable.getRows().add(row);
        lastLineI = lineI;
    }
}
Also used : TimeInterval(net.parostroj.timetable.model.TimeInterval) ArrayList(java.util.ArrayList) TranslatedString(net.parostroj.timetable.model.TranslatedString) FreightConnection(net.parostroj.timetable.model.freight.FreightConnection) LineClass(net.parostroj.timetable.model.LineClass) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List)

Example 25 with TimeInterval

use of net.parostroj.timetable.model.TimeInterval in project grafikon by jub77.

the class StationTimetablesExtractor method getStationTimetables.

public List<StationTimetable> getStationTimetables() {
    List<StationTimetable> result = new LinkedList<>();
    for (Node node : nodes) {
        StationTimetable timetable = new StationTimetable(node.getName());
        timetable.setType(node.getType());
        // regions + company
        Set<Region> regions = node.getRegions();
        if (!regions.isEmpty()) {
            timetable.setRegions(regions.stream().map(RegionInfo::convert).collect(Collectors.toList()));
        }
        Company company = node.getAttribute(Node.ATTR_COMPANY, Company.class);
        if (company != null) {
            timetable.setCompany(CompanyInfo.convert(company));
        }
        // process rows ...
        for (TimeInterval interval : this.collectIntervals(node)) {
            if (techTime || !interval.isTechnological()) {
                timetable.getRows().add(this.createRow(interval));
            }
        }
        result.add(timetable);
    }
    return result;
}
Also used : Company(net.parostroj.timetable.model.Company) TimeInterval(net.parostroj.timetable.model.TimeInterval) Node(net.parostroj.timetable.model.Node) Region(net.parostroj.timetable.model.Region) LinkedList(java.util.LinkedList)

Aggregations

TimeInterval (net.parostroj.timetable.model.TimeInterval)26 Train (net.parostroj.timetable.model.Train)9 ArrayList (java.util.ArrayList)6 Node (net.parostroj.timetable.model.Node)6 List (java.util.List)5 LinkedList (java.util.LinkedList)4 TrainDiagram (net.parostroj.timetable.model.TrainDiagram)4 Component (java.awt.Component)3 Collection (java.util.Collection)3 Wrapper (net.parostroj.timetable.gui.wrappers.Wrapper)3 FNConnection (net.parostroj.timetable.model.FNConnection)3 LocalizedString (net.parostroj.timetable.model.LocalizedString)3 TranslatedString (net.parostroj.timetable.model.TranslatedString)3 Pair (net.parostroj.timetable.utils.Pair)3 BorderLayout (java.awt.BorderLayout)2 FlowLayout (java.awt.FlowLayout)2 Rectangle (java.awt.Rectangle)2 Shape (java.awt.Shape)2 ItemEvent (java.awt.event.ItemEvent)2 Collator (java.text.Collator)2