use of trackmodel.model.Block in project on-track by michaelplazek.
the class TrackModelController method makeBlockArray.
private void makeBlockArray() {
blocks = new Block[15];
for (int i = 1; i <= 15; i++) {
Block b = new Block();
b.setLine("Blue");
b.setSection("A");
b.setNumber(i);
b.setSize(i * (float) 2.5);
b.setGrade((float) .2);
b.setSpeedLimit(55);
b.setElevation((float) .2);
b.setCumElevation((float) .35);
if (i % 2 == 0) {
b.setHeated(true);
}
if (i == 2) {
b.setOccupied(true);
}
if (i == 3) {
b.setInfrastructure("STATION;PIONEER");
} else if (i == 4) {
b.setInfrastructure("RAILWAY");
} else if (i == 9) {
b.setInfrastructure("UNDERGROUND");
} else {
b.setInfrastructure("");
}
blocks[i - 1] = b;
}
}
use of trackmodel.model.Block in project on-track by michaelplazek.
the class TrainModel method updateCurrentBlock.
/**
* Updates current block to next block.
*/
private void updateCurrentBlock() {
Block next = activeTrack.getBlock(currentBlock.getNextBlock1());
currentBlock = next;
}
use of trackmodel.model.Block in project on-track by michaelplazek.
the class TrainModel method updatePreviousBlock.
/**
* Updates previous block.
*/
private void updatePreviousBlock() {
Block previous = activeTrack.getBlock(currentBlock.getPreviousBlock());
previousBlock = previous;
}
use of trackmodel.model.Block in project on-track by michaelplazek.
the class TrackModelController method importTrackData.
private void importTrackData(File f) {
try {
BufferedReader br = new BufferedReader(new FileReader(f));
String line = br.readLine();
int i = 0;
String filename = f.getName();
int fileNamePeriodPosition = filename.indexOf('.');
String lineName = filename.substring(0, fileNamePeriodPosition);
lineName = lineName.toUpperCase();
Track newTrack = new Track(lineName);
listOfTracks.put(lineName, newTrack);
ArrayList<String> sections = new ArrayList<String>();
ArrayList<Integer> blocks = new ArrayList<Integer>();
while (line != null) {
if (i == 0) {
// System.out.println("Header Line");
// System.out.println(line);
String[] splitLine = line.split(",");
line = br.readLine();
i++;
} else {
String[] splitLine = line.split(",");
if (!sections.contains(splitLine[1])) {
sections.add(splitLine[1]);
}
if (!blocks.contains(Integer.parseInt(splitLine[2]))) {
blocks.add(Integer.parseInt(splitLine[2]));
}
Block b;
if (splitLine[6].contains("SWITCH")) {
// Create a switch for the Track
final String lineId = splitLine[0];
final String section = splitLine[1];
final int number = Integer.parseInt(splitLine[2]);
final float len = Float.parseFloat(splitLine[3]);
final float grade = Float.parseFloat(splitLine[4]);
final int speedLimit = Integer.parseInt(splitLine[5]);
final String infra = splitLine[6];
final float elevation = Float.parseFloat(splitLine[7]);
final float cumEle = Float.parseFloat(splitLine[8]);
boolean biDirectional;
if (splitLine[9].equals("")) {
biDirectional = false;
} else {
biDirectional = true;
}
final int previous = Integer.parseInt(splitLine[10]);
final int next1 = Integer.parseInt(splitLine[11]);
final int next2 = Integer.parseInt(splitLine[12]);
boolean rightStation = false;
if (splitLine.length > 13) {
if (splitLine[13].equals("")) {
rightStation = false;
} else {
rightStation = true;
}
}
boolean leftStation = false;
if (splitLine.length > 14) {
if (splitLine[14].equals("")) {
leftStation = false;
} else {
leftStation = true;
}
}
b = new Switch(lineId, section, number, len, grade, speedLimit, infra, elevation, cumEle, biDirectional, previous, next1, next2, leftStation, rightStation);
if (splitLine[6].contains("YARD") && splitLine[6].contains("FROM")) {
newTrack.setStartBlock(number);
}
newTrack.addBlock(b);
} else {
// Create a Block for the Track
// System.out.println(splitLine.length);
final String lineId = splitLine[0];
final String section = splitLine[1];
final int number = Integer.parseInt(splitLine[2]);
final float len = Float.parseFloat(splitLine[3]);
final float grade = Float.parseFloat(splitLine[4]);
final int speedLimit = Integer.parseInt(splitLine[5]);
final String infra = splitLine[6];
final float elevation = Float.parseFloat(splitLine[7]);
final float cumEle = Float.parseFloat(splitLine[8]);
boolean biDirectional;
if (splitLine[9].equals("")) {
biDirectional = false;
} else {
biDirectional = true;
}
final int previous = Integer.parseInt(splitLine[10]);
final int next1 = Integer.parseInt(splitLine[11]);
boolean rightStation = false;
if (splitLine.length > 13) {
if (splitLine[13].equals("")) {
rightStation = false;
} else {
rightStation = true;
}
}
boolean leftStation = false;
if (splitLine.length > 14) {
if (splitLine[14].equals("")) {
leftStation = false;
} else {
leftStation = true;
}
}
b = new Block(lineId, section, number, len, grade, speedLimit, infra, elevation, cumEle, biDirectional, previous, next1, leftStation, rightStation);
newTrack.addBlock(b);
}
// System.out.println();
line = br.readLine();
}
}
trackSections.put(lineName, sections);
trackBlockNum.put(lineName, blocks);
System.out.println(newTrack.getNumberOfBlocks());
} catch (FileNotFoundException ex) {
System.out.println("Unable to find the file.");
} catch (IOException ex) {
System.out.println("Error reading file");
}
}
use of trackmodel.model.Block in project on-track by michaelplazek.
the class CentralTrafficControlController method connectOthers.
private void connectOthers() {
TableView.TableViewSelectionModel<ScheduleRow> defaultModel = addScheduleTable.getSelectionModel();
// connect the toggle buttons for mode of operation
mode.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
public void changed(ObservableValue<? extends Toggle> ov, Toggle oldToggle, Toggle newToggle) {
if (mode.getSelectedToggle() != null) {
RadioButton btn = (RadioButton) newToggle.getToggleGroup().getSelectedToggle();
changeMode(btn.getText(), defaultModel);
}
}
});
trainQueueTable.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
if (trainQueueTable.getSelectionModel().getSelectedItem() != null) {
TrainTracker selected = trainQueueTable.getSelectionModel().getSelectedItem();
selectedScheduleTable.setItems(selected.getSchedule().getStops());
}
});
trackSelect.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
if (!newValue.equals("Select track")) {
ctc.setLine(newValue);
ctc.makeStationList();
ctc.makeBlockList();
stopColumn.setCellFactory(ComboBoxTableCell.forTableColumn(new DefaultStringConverter(), ctc.getStationList()));
scheduleBlocks.setDisable(false);
setAuthorityBlocks.setDisable(false);
scheduleBlocks.setItems(ctc.getBlockList());
setAuthorityBlocks.setItems(ctc.getBlockList());
// only show trains that are on the selected line
ctc.getTrainQueueTable().clear();
ctc.getDispatchTable().clear();
selectedScheduleTable.setItems(FXCollections.observableArrayList());
TrainTracker item;
ObservableList<TrainTracker> list = ctc.getTrainList();
for (int i = 0; i < list.size(); i++) {
item = list.get(i);
if (item.getLine().equals(newValue)) {
// first, set the queue table
if (!item.isDispatched()) {
ctc.getTrainQueueTable().add(item);
} else {
// then get the dispatch table
ctc.getDispatchTable().add(item);
}
}
}
// then set the user interface
trainQueueTable.setItems(ctc.getTrainQueueTable());
dispatchTable.setItems(ctc.getDispatchTable());
if (ctc.getBlockList().size() > 0) {
scheduleBlocks.setValue(ctc.getBlockList().get(0));
setAuthorityBlocks.setValue(ctc.getBlockList().get(0));
}
} else {
trackSelect.setValue(oldValue);
}
});
maintenanceActions.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
if (newValue.equals("Select action")) {
maintenanceActions.setValue(oldValue);
} else {
String action = maintenanceActions.getSelectionModel().getSelectedItem();
String line = maintenanceTracks.getSelectionModel().getSelectedItem();
int blockId = extractBlock();
Block block = Track.getListOfTracks().get(line).getBlock(blockId);
if (action.equals("Toggle switch") && !block.isSwitch()) {
submitMaintenance.setDisable(true);
} else {
submitMaintenance.setDisable(false);
}
}
});
maintenanceBlocks.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
String action = maintenanceActions.getSelectionModel().getSelectedItem();
String line = maintenanceTracks.getSelectionModel().getSelectedItem();
int blockId = extractBlock();
Block block = Track.getListOfTracks().get(line).getBlock(blockId);
if (action.equals("Toggle switch") && !block.isSwitch()) {
submitMaintenance.setDisable(true);
} else {
submitMaintenance.setDisable(false);
}
});
maintenanceTracks.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
if (!newValue.equals("Select track")) {
trackMaintenance.setLine(newValue);
trackMaintenance.makeBlockList();
maintenanceBlocks.setItems(trackMaintenance.getBlockList());
if (ctc.getBlockList().size() > 0) {
maintenanceBlocks.setValue(trackMaintenance.getBlockList().get(0));
}
} else {
maintenanceTracks.setValue(oldValue);
}
updateMaintenance();
});
trainStatus.setFill(Paint.valueOf("Grey"));
}
Aggregations