Skip to content

Fix issue 77 block properties removed when rerouting #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/jcs/persistence/H2PersistenceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ public synchronized void remove(RouteBean route) {
database.sql("delete from route_elements where route_id =?", route.getId()).execute();
}

int rows = this.database.delete(route).getRowsAffected();
int rows = database.delete(route).getRowsAffected();
Logger.trace(rows + " rows deleted");
changeSupport.firePropertyChange("data.route.deleted", route, null);
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/jcs/ui/JCSFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,6 @@ private void showLocomotives() {
locomotiveDialog.setLocationRelativeTo(null);
}
locomotiveDialog.setVisible(true);

//Should add a listener here?
}

private void showAccessories() {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/jcs/ui/layout/LayoutCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,8 @@ private void mousePressedAction(MouseEvent evt) {
if (MouseEvent.BUTTON1 == evt.getButton() && selectedTile == null) {
//Only add a new tile when there is no tile on the selected snapPoint
Logger.trace("Adding a new tile: " + tileType + " @ (" + snapPoint.x + ", " + snapPoint.y + ")");
selectedTile = addTile(snapPoint, tileType, orientation, direction, true, !readonly);
selectedTile = addTile(snapPoint, tileType, orientation, direction, true, showCenter);
if (selectedTile != null) {
//selectedTiles.addAll(selectedTile.getAllPoints());
selectedTile.setSelected(true);
repaint(selectedTile.getTileBounds());
}
Expand Down
12 changes: 0 additions & 12 deletions src/main/java/jcs/ui/layout/LayoutPanel.form
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,11 @@
<Properties>
<Property name="text" type="java.lang.String" value="Vertical"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="verticalMIActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="horizontalMI">
<Properties>
<Property name="text" type="java.lang.String" value="Horizontal"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="horizontalMIActionPerformed"/>
</Events>
</MenuItem>
</SubComponents>
</Container>
Expand All @@ -36,17 +30,11 @@
<Properties>
<Property name="text" type="java.lang.String" value="Right"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="rightMIActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="leftMI">
<Properties>
<Property name="text" type="java.lang.String" value="Left"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="leftMIActionPerformed"/>
</Events>
</MenuItem>
</SubComponents>
</Container>
Expand Down
58 changes: 0 additions & 58 deletions src/main/java/jcs/ui/layout/LayoutPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,35 +240,15 @@ private void initComponents() {
canvas = new LayoutCanvas(this.readonly);

verticalMI.setText("Vertical");
verticalMI.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
verticalMIActionPerformed(evt);
}
});
straightPopupMenu.add(verticalMI);

horizontalMI.setText("Horizontal");
horizontalMI.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
horizontalMIActionPerformed(evt);
}
});
straightPopupMenu.add(horizontalMI);

rightMI.setText("Right");
rightMI.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
rightMIActionPerformed(evt);
}
});
curvedPopupMenu.add(rightMI);

leftMI.setText("Left");
leftMI.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
leftMIActionPerformed(evt);
}
});
curvedPopupMenu.add(leftMI);

xyMI.setText("x: y:");
Expand Down Expand Up @@ -741,44 +721,6 @@ public void actionPerformed(ActionEvent evt) {
canvasScrollPane.getAccessibleContext().setAccessibleDescription("");
}// </editor-fold>//GEN-END:initComponents

private void horizontalMIActionPerformed(ActionEvent evt) {//GEN-FIRST:event_horizontalMIActionPerformed
// Logger.trace(this.orientation + ", " + evt.getModifiers() + ", " + evt.paramString());
//
// if (this.mouseLocation != null && evt.getModifiers() == ActionEvent.MOUSE_EVENT_MASK) {
// addTile(this.mouseLocation);
// this.mouseLocation = null;
// }
}//GEN-LAST:event_horizontalMIActionPerformed

private void verticalMIActionPerformed(ActionEvent evt) {//GEN-FIRST:event_verticalMIActionPerformed
// Logger.trace(this.orientation + ", " + evt.getModifiers() + ", " + evt.paramString());
//
// if (this.mouseLocation != null && evt.getModifiers() == ActionEvent.MOUSE_EVENT_MASK) {
// addTile(this.mouseLocation);
// this.mouseLocation = null;
// }
}//GEN-LAST:event_verticalMIActionPerformed

private void rightMIActionPerformed(ActionEvent evt) {//GEN-FIRST:event_rightMIActionPerformed
// Logger.trace(this.orientation + ", " + evt.getModifiers() + ", " + evt.paramString());
//
// if (this.mouseLocation != null && evt.getModifiers() == ActionEvent.MOUSE_EVENT_MASK) {
// addTile(this.mouseLocation);
// this.mouseLocation = null;
// }
}//GEN-LAST:event_rightMIActionPerformed

private void leftMIActionPerformed(ActionEvent evt) {//GEN-FIRST:event_leftMIActionPerformed
// Logger.trace(this.orientation + ", " + evt.getModifiers() + ", " + evt.paramString());
//
// if (this.mouseLocation != null && evt.getModifiers() == ActionEvent.MOUSE_EVENT_MASK) {
// addTile(this.mouseLocation);
//
// //do someting with the rotation/direction...
// this.mouseLocation = null;
// }
}//GEN-LAST:event_leftMIActionPerformed

private void rotateMIActionPerformed(ActionEvent evt) {//GEN-FIRST:event_rotateMIActionPerformed
// rotateSelectedTile();
}//GEN-LAST:event_rotateMIActionPerformed
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/jcs/ui/layout/RoutesDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
*/
public class RoutesDialog extends javax.swing.JDialog {

private static final long serialVersionUID = -7597770366968399204L;

private final boolean readonly;
private final List<RouteBean> routes;
private RouteBean selectedRoute;
Expand Down Expand Up @@ -247,7 +249,8 @@ private void routeListValueChanged(javax.swing.event.ListSelectionEvent evt) {//

private void routeBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_routeBtnActionPerformed
if (layoutCanvas != null) {
this.executor.execute(() -> routeLayout());
//executor.execute(() -> routeLayout());
routeLayout();
} else {
Logger.warn("Can not perform routing as the LayoutPanel is null " + evt.paramString());
}
Expand Down
37 changes: 18 additions & 19 deletions src/main/java/jcs/ui/layout/pathfinding/astar/AStar.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
*/
public class AStar {

//private final TileCache tileCache;

private final Graph graph;
private final Map<String, RouteBean> routes;

Expand Down Expand Up @@ -150,19 +148,24 @@ private RouteBean createRouteBeanFromNodePath(List<Node> path) {
}

public void persistRoutes() {
for (RouteBean route : this.routes.values()) {
for (RouteBean route : routes.values()) {
PersistenceFactory.getService().persist(route);
}

//Now also create the blocks
List<Node> blockNodes = this.graph.getBlockNodes();
List<Node> blockNodes = graph.getBlockNodes();

for (Node block : blockNodes) {
BlockBean bb = new BlockBean(block.getTile().getTileBean());
//Use a default
bb.setMinWaitTime(10);
bb.setAlwaysStop(true);

BlockBean bb = block.getTile().getBlockBean();
if (bb == null) {
bb = new BlockBean(block.getTile().getTileBean());
bb.setAlwaysStop(true);
bb.setMinWaitTime(10);
} else {
Logger.trace("Using existing BlockBean: " + bb);
if (bb.getMinWaitTime() == null) {
bb.setMinWaitTime(10);
}
}
PersistenceFactory.getService().persist(bb);
}
}
Expand All @@ -176,8 +179,8 @@ public Map<String, RouteBean> getRoutes() {
}

public List<Node> findPath(String fromNodeId, String fromSuffix, String toNodeId, String toSuffix) {
Node from = this.graph.getNode(fromNodeId);
Node to = this.graph.getNode(toNodeId);
Node from = graph.getNode(fromNodeId);
Node to = graph.getNode(toNodeId);
return findPath(from, fromSuffix, to, toSuffix);
}

Expand Down Expand Up @@ -231,26 +234,22 @@ public List<RouteBean> routeAll() {
}

public void buildGraph(List<Tile> tiles) {
//this.tileCache.reload(tiles);
this.graph.clear();

graph.clear();
//Every Tile becomes a node
for (Tile tile : tiles) {
Node n = new Node(tile);
this.graph.addNode(n);
graph.addNode(n);
}

Logger.trace("Graph has " + this.graph.size() + " nodes...");
Logger.trace("Graph has " + graph.size() + " nodes...");

//Create the links or connection between the Nodes
for (Node node : graph.getNodes()) {
Collection<Point> neighborPoints = node.getTile().getNeighborPoints().values();
Logger.trace("Node: " + node.getId() + " has " + neighborPoints.size() + " neighbors " + (node.isBlock() ? "[Block]" : "") + (node.isJunction() ? "[Junction]" : ""));

for (Point p : neighborPoints) {
//if (tileCache.contains(p)) {
if (TileCache.contains(p)) {
//Node neighbor = graph.getNode(tileCache.getTileId(p));
Node neighbor = graph.getNode(TileCache.findTile(p).getId());

if (node.getTile().isAdjacent(neighbor.getTile())) {
Expand Down
Loading