Search in sources :

Example 1 with LineClass

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

the class LSLibraryItem method createLibraryItem.

public LibraryItem createLibraryItem(LibraryBuilder libraryBuilder) throws LSException {
    LibraryItemType type = LibraryItemType.valueOf(getType());
    ObjectWithId object = null;
    switch(type) {
        case ENGINE_CLASS:
            object = ((LSEngineClass) getObject()).createEngineClass(id -> {
                ObjectWithId foundObject = libraryBuilder.getObjectById(id);
                return foundObject instanceof LineClass ? (LineClass) foundObject : null;
            });
            break;
        case LINE_CLASS:
            object = ((LSLineClass) getObject()).createLineClass();
            break;
        case NODE:
            object = ((LSNode) getObject()).createNode(libraryBuilder.getPartFactory(), libraryBuilder::getObjectById);
            break;
        case OUTPUT_TEMPLATE:
            object = ((LSOutputTemplate) getObject()).createOutputTemplate(libraryBuilder.getPartFactory(), libraryBuilder::getObjectById);
            break;
        case TRAIN_TYPE:
            object = ((LSTrainType) getObject()).createTrainType(libraryBuilder.getPartFactory(), libraryBuilder::getObjectById, id -> {
                ObjectWithId foundObject = libraryBuilder.getObjectById(id);
                return foundObject instanceof TrainTypeCategory ? (TrainTypeCategory) foundObject : null;
            });
            break;
        case TRAIN_TYPE_CATEGORY:
            object = ((LSTrainTypeCategory) getObject()).createTrainTypeCategory();
            break;
    }
    LibraryItem item = libraryBuilder.addObject(object);
    item.getAttributes().add(this.getAttributes().createAttributes(libraryBuilder::getObjectById));
    return item;
}
Also used : XmlAttribute(javax.xml.bind.annotation.XmlAttribute) LibraryItem(net.parostroj.timetable.model.library.LibraryItem) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) Node(net.parostroj.timetable.model.Node) ObjectWithId(net.parostroj.timetable.model.ObjectWithId) OutputTemplate(net.parostroj.timetable.model.OutputTemplate) XmlType(javax.xml.bind.annotation.XmlType) TrainTypeCategory(net.parostroj.timetable.model.TrainTypeCategory) XmlElements(javax.xml.bind.annotation.XmlElements) LibraryBuilder(net.parostroj.timetable.model.library.LibraryBuilder) LSException(net.parostroj.timetable.model.ls.LSException) EngineClass(net.parostroj.timetable.model.EngineClass) TrainType(net.parostroj.timetable.model.TrainType) LibraryItemType(net.parostroj.timetable.model.library.LibraryItemType) LineClass(net.parostroj.timetable.model.LineClass) XmlElement(javax.xml.bind.annotation.XmlElement) ObjectWithId(net.parostroj.timetable.model.ObjectWithId) LineClass(net.parostroj.timetable.model.LineClass) LibraryItem(net.parostroj.timetable.model.library.LibraryItem) LibraryItemType(net.parostroj.timetable.model.library.LibraryItemType) TrainTypeCategory(net.parostroj.timetable.model.TrainTypeCategory)

Example 2 with LineClass

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

the class LibraryBuilder method importEngineClass.

public LibraryItem importEngineClass(EngineClass engineClass) {
    EngineClass engineClassCopy = copyFactory.copy(engineClass, engineClass.getId());
    for (WeightTableRow row : engineClassCopy.getWeightTable()) {
        for (LineClass origLineClass : ImmutableList.copyOf(row.getWeights().keySet())) {
            Integer weight = row.getWeight(origLineClass);
            row.removeWeightInfo(origLineClass);
            ObjectWithId currentLineClass = this.getObjectById(origLineClass.getId());
            if (currentLineClass == null) {
                if (config.isAddMissing()) {
                    LibraryItem lineClassItem = this.importLineClass(origLineClass);
                    currentLineClass = lineClassItem.getObject();
                } else {
                    throw new IllegalArgumentException("Line class missing from library: " + origLineClass);
                }
            } else if (!(currentLineClass instanceof LineClass)) {
                throw new IllegalArgumentException("Wrong type of line class: " + origLineClass);
            }
            row.setWeightInfo((LineClass) currentLineClass, weight);
        }
    }
    return addImpl(engineClassCopy, LibraryItemType.ENGINE_CLASS);
}
Also used : WeightTableRow(net.parostroj.timetable.model.WeightTableRow) ObjectWithId(net.parostroj.timetable.model.ObjectWithId) LineClass(net.parostroj.timetable.model.LineClass) EngineClass(net.parostroj.timetable.model.EngineClass)

Example 3 with LineClass

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

the class LineClassImport method importObjectImpl.

@Override
protected ObjectWithId importObjectImpl(ObjectWithId o) {
    // check class
    if (!(o instanceof LineClass))
        return null;
    LineClass importedLineClass = (LineClass) o;
    // check existence
    LineClass checkedLineClass = this.getLineClass(importedLineClass);
    if (checkedLineClass != null) {
        String message = "line class already exists";
        this.addError(importedLineClass, message);
        log.debug("{}: {}", message, checkedLineClass);
        return null;
    }
    // create new line class
    LineClass lineClass = new LineClass(this.getId(importedLineClass), importedLineClass.getName());
    // add to diagram
    this.getDiagram().getNet().getLineClasses().add(lineClass);
    this.addImportedObject(lineClass);
    log.trace("Successfully imported line class: {}", lineClass);
    return lineClass;
}
Also used : LineClass(net.parostroj.timetable.model.LineClass)

Example 4 with LineClass

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

the class EngineClassImport method importObjectImpl.

@Override
protected ObjectWithId importObjectImpl(ObjectWithId o) {
    // check class
    if (!(o instanceof EngineClass))
        return null;
    EngineClass importedEngineClass = (EngineClass) o;
    // check existence
    EngineClass checkedEngineClass = this.getEngineClass(importedEngineClass);
    if (checkedEngineClass != null) {
        if (overwrite) {
            this.getDiagram().getEngineClasses().remove(checkedEngineClass);
        } else {
            String message = "engine class already exists";
            this.addError(importedEngineClass, message);
            log.debug("{}: {}", message, checkedEngineClass);
            return null;
        }
    }
    // create new engine class
    EngineClass engineClass = new EngineClass(this.getId(importedEngineClass), importedEngineClass.getName());
    // process weight rows
    for (WeightTableRow impRow : importedEngineClass.getWeightTable()) {
        WeightTableRow row = engineClass.createWeightTableRow(impRow.getSpeed());
        for (Map.Entry<LineClass, Integer> impEntry : impRow.getWeights().entrySet()) {
            LineClass lineClass = this.getLineClass(impEntry.getKey());
            if (lineClass == null) {
                String message = "line class missing: " + impEntry.getKey().getName();
                this.addError(importedEngineClass, message);
                log.debug(message);
                return null;
            }
            row.setWeightInfo(lineClass, impEntry.getValue());
        }
        engineClass.addWeightTableRow(row);
    }
    // add to diagram
    this.getDiagram().getEngineClasses().add(engineClass);
    this.addImportedObject(engineClass);
    log.trace("Successfully imported engine class: {}", engineClass);
    return engineClass;
}
Also used : WeightTableRow(net.parostroj.timetable.model.WeightTableRow) LineClass(net.parostroj.timetable.model.LineClass) EngineClass(net.parostroj.timetable.model.EngineClass) Map(java.util.Map)

Example 5 with LineClass

use of net.parostroj.timetable.model.LineClass 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)

Aggregations

LineClass (net.parostroj.timetable.model.LineClass)5 EngineClass (net.parostroj.timetable.model.EngineClass)3 ObjectWithId (net.parostroj.timetable.model.ObjectWithId)2 WeightTableRow (net.parostroj.timetable.model.WeightTableRow)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 XmlAttribute (javax.xml.bind.annotation.XmlAttribute)1 XmlElement (javax.xml.bind.annotation.XmlElement)1 XmlElements (javax.xml.bind.annotation.XmlElements)1 XmlRootElement (javax.xml.bind.annotation.XmlRootElement)1 XmlType (javax.xml.bind.annotation.XmlType)1 Node (net.parostroj.timetable.model.Node)1 OutputTemplate (net.parostroj.timetable.model.OutputTemplate)1 TimeInterval (net.parostroj.timetable.model.TimeInterval)1 TrainType (net.parostroj.timetable.model.TrainType)1 TrainTypeCategory (net.parostroj.timetable.model.TrainTypeCategory)1 TranslatedString (net.parostroj.timetable.model.TranslatedString)1 FreightConnection (net.parostroj.timetable.model.freight.FreightConnection)1