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;
}
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);
}
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;
}
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;
}
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;
}
}
Aggregations