use of net.parostroj.timetable.model.Net in project grafikon by jub77.
the class RegionValidator method validate.
@Override
public boolean validate(Event event) {
if (event.getSource() instanceof Net && event.getType() == Type.REMOVED && event.getObject() instanceof Region) {
this.cancelSuperRegion((Region) event.getObject());
this.removeRegionFromNet((Region) event.getObject());
return true;
}
if (event.getType() == Type.OBJECT_ATTRIBUTE && event.getObject() instanceof Region) {
checkObjectAttributeOfRegion(event);
}
// in case region is used - cannot be used as super-region
if (event.getSource() instanceof Node && event.getType() == Type.ATTRIBUTE && event.getAttributeChange().checkName(Node.ATTR_REGIONS)) {
for (Region region : ((Node) event.getSource()).getRegions()) {
if (region.hasSubRegions())
this.cancelSuperRegion(region);
}
checkCommonSuperRegion((Node) event.getSource());
}
return false;
}
use of net.parostroj.timetable.model.Net in project grafikon by jub77.
the class LSLine method createLine.
public Line createLine(TrainDiagram diagram) throws LSException {
Net net = diagram.getNet();
Node fromNode = net.getNodeById(getFrom());
Node toNode = net.getNodeById(getTo());
if (speed != null && speed <= 0) {
speed = null;
}
Line line = diagram.getPartFactory().createLine(id, length, fromNode, toNode, speed);
line.getAttributes().add(attributes.createAttributes(diagram::getObjectById));
// tracks
if (this.tracks != null)
for (LSLineTrack lsLineTrack : this.tracks) {
LineTrack lineTrack = lsLineTrack.createLineTrack(diagram::getObjectById);
NodeTrack fromStraight = fromNode.getTrackById(lsLineTrack.getFromStraightTrack());
NodeTrack toStraight = toNode.getTrackById(lsLineTrack.getToStraightTrack());
lineTrack.setFromStraightTrack(fromStraight);
lineTrack.setToStraightTrack(toStraight);
line.addTrack(lineTrack);
}
return line;
}
use of net.parostroj.timetable.model.Net in project grafikon by jub77.
the class TrainDiagramBuilder method setNet.
public void setNet(LSNet lsNet) throws LSException {
Net net = lsNet.createNet(this.diagram);
this.diagram.setNet(net);
// add regions
if (lsNet.getRegions() != null) {
Collection<DelayedAttributes<Region>> regions = new ArrayList<>();
for (LSRegion lsRegion : lsNet.getRegions()) {
DelayedAttributes<Region> daRegion = lsRegion.createRegion(diagram);
net.getRegions().add(daRegion.getObject());
regions.add(daRegion);
}
for (DelayedAttributes<Region> daRegion : regions) {
daRegion.addAttributes();
}
}
// add line classes
if (lsNet.getLineClasses() != null) {
for (LSLineClass lsLineClass : lsNet.getLineClasses()) {
net.getLineClasses().add(lsLineClass.createLineClass());
}
}
// create nodes ...
if (lsNet.getNodes() != null) {
for (LSNode lsNode : lsNet.getNodes()) {
Node node = lsNode.createNode(diagram.getPartFactory(), diagram::getObjectById);
net.addNode(node);
}
}
// create lines ...
if (lsNet.getLines() != null) {
for (LSLine lsLine : lsNet.getLines()) {
Line line = lsLine.createLine(diagram);
Node from = net.getNodeById(lsLine.getFrom());
Node to = net.getNodeById(lsLine.getTo());
net.addLine(from, to, line);
}
}
}
Aggregations