working on route allocation
@@ -40,7 +40,7 @@ svg rect{
|
||||
}
|
||||
|
||||
svg.locked polygon,
|
||||
svg.locked rect{
|
||||
svg.locked rect:not(.sig_a):not(.sig_b){
|
||||
fill:lime;
|
||||
}
|
||||
|
||||
@@ -160,4 +160,11 @@ h2{
|
||||
top: 10px;
|
||||
right: 10px;
|
||||
display: none;
|
||||
}
|
||||
|
||||
svg.left rect,
|
||||
svg.right rect,
|
||||
svg.straight .left,
|
||||
svg.straight .right{
|
||||
fill: white !important;
|
||||
}
|
||||
@@ -24,7 +24,7 @@ function addTile(x,y){
|
||||
}
|
||||
|
||||
function bodyClick(ev){
|
||||
console.log('bodyClick:',ev);
|
||||
//console.log('bodyClick:',ev);
|
||||
var x = Math.floor(ev.clientX/SQUARE);
|
||||
var y = Math.floor(ev.clientY/SQUARE);
|
||||
|
||||
@@ -42,7 +42,7 @@ function bodyClick(ev){
|
||||
|
||||
function clickTile(x,y){
|
||||
console.log("clickTile:",x,y);
|
||||
if ($('#tile-'+x+'-'+y).length > 0) request({action:'openProps',x:x,y:y});
|
||||
if ($('#tile-'+x+'-'+y).length > 0) request({action:'click',x:x,y:y});
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -129,8 +129,10 @@ function request(data){
|
||||
data : data,
|
||||
success: function(resp){
|
||||
closeWindows();
|
||||
if (resp.startsWith('<')){
|
||||
$('body').append($(resp));
|
||||
if (resp.startsWith('<svg')){
|
||||
$('#plan').append($(resp));
|
||||
} else if (resp.startsWith('<')) {
|
||||
$(BODY).append($(resp));
|
||||
} else {
|
||||
addMessage(resp);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<svg width="100" height="100" viewbox="0 0 100 100">
|
||||
<rect x="0" y="35" width="100" height="30" />
|
||||
<polygon points="100,65 65,100 35,100 100,35" />
|
||||
<polygon class="left" points="100,65 65,100 35,100 100,35" />
|
||||
<polygon points="100,65 65,65 100,35" />
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 156 B After Width: | Height: | Size: 211 B |
@@ -1,4 +1,5 @@
|
||||
<svg width="100" height="100" viewbox="0 0 100 100">
|
||||
<rect x="35" y="0" width="30" height="100" />
|
||||
<polygon points="65,0 100,35 100,65 35,0" />
|
||||
<polygon class="left" points="65,0 100,35 100,65 35,0" />
|
||||
<polygon points="35,0 65,0 65,35" />
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 152 B After Width: | Height: | Size: 203 B |
@@ -1,4 +1,5 @@
|
||||
<svg width="100" height="100" viewbox="0 0 100 100">
|
||||
<rect x="35" y="0" width="30" height="100" />
|
||||
<polygon points="0,35 65,100 35,100 0,65" />
|
||||
<polygon class="left" points="0,35 65,100 35,100 0,65" />
|
||||
<polygon points="35,100 65,100 35,65" />
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 152 B After Width: | Height: | Size: 207 B |
@@ -1,4 +1,5 @@
|
||||
<svg width="100" height="100" viewbox="0 0 100 100">
|
||||
<rect x="0" y="35" width="100" height="30" />
|
||||
<polygon points="0,35 35,0 65,0 0,65" />
|
||||
<polygon class="left" points="0,35 35,0 65,0 0,65" />
|
||||
<polygon points="0,35 35,35 0,65" />
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 148 B After Width: | Height: | Size: 199 B |
@@ -1,4 +1,5 @@
|
||||
<svg width="100" height="100" viewbox="0 0 100 100">
|
||||
<rect x="0" y="35" width="100" height="30" />
|
||||
<polygon points="100,65 35,0 65,0 100,35" />
|
||||
<polygon class="right" points="100,65 35,0 65,0 100,35" />
|
||||
<polygon points="100,35 100,65 65,35" />
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 152 B After Width: | Height: | Size: 208 B |
@@ -1,4 +1,5 @@
|
||||
<svg width="100" height="100" viewbox="0 0 100 100">
|
||||
<rect x="35" y="0" width="30" height="100" />
|
||||
<polygon points="65,0 0,65 0,35 35,0" />
|
||||
<polygon class="right" points="65,0 0,65 0,35 35,0" />
|
||||
<polygon points="35,0 65,0 35,35" />
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 148 B After Width: | Height: | Size: 200 B |
@@ -1,4 +1,5 @@
|
||||
<svg width="100" height="100" viewbox="0 0 100 100">
|
||||
<rect x="35" y="0" width="30" height="100" />
|
||||
<polygon points="35,100 100,35 100,65 65,100" />
|
||||
<polygon class="right" points="35,100 100,35 100,65 65,100" />
|
||||
<polygon points="35,100 65,100 65,65" />
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 156 B After Width: | Height: | Size: 212 B |
@@ -1,4 +1,5 @@
|
||||
<svg width="100" height="100" viewbox="0 0 100 100">
|
||||
<rect x="0" y="35" width="100" height="30" />
|
||||
<polygon points="0,35 65,100 35,100 0,65" />
|
||||
<polygon class="right" points="0,35 65,100 35,100 0,65" />
|
||||
<polygon points="0,35 0,65 35,65" />
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 152 B After Width: | Height: | Size: 204 B |
@@ -86,7 +86,7 @@ public class Plan {
|
||||
private static final String ACTION_ADD = "add";
|
||||
private static final String ACTION_ANALYZE = "analyze";
|
||||
private static final String ACTION_MOVE = "move";
|
||||
private static final String ACTION_PROPS = "openProps";
|
||||
private static final String ACTION_CLICK = "click";
|
||||
private static final String ACTION_SAVE = "save";
|
||||
private static final String ACTION_UPDATE = "update";
|
||||
private static final String TILE = "tile";
|
||||
@@ -160,6 +160,11 @@ public class Plan {
|
||||
public Collection<Block> blocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
private Object click(Tile tile) throws IOException {
|
||||
if (tile == null) return null;
|
||||
return tile.click();
|
||||
}
|
||||
|
||||
private Collection<Route> follow(Route route, Connector connector) {
|
||||
Tile tile = get(connector.x,connector.y,false);
|
||||
@@ -340,7 +345,7 @@ public class Plan {
|
||||
}
|
||||
|
||||
private boolean moveTile(int x, int y,int xstep,int ystep) throws IOException {
|
||||
LOG.error("moveTile({}+ {},{}+ {}) not implemented",x,xstep,y,ystep);
|
||||
LOG.error("moveTile({}+ {},{}+ {})",x,xstep,y,ystep);
|
||||
Stack<Tile> stack = new Stack<Tile>();
|
||||
Tile tile = get(x,y,false);
|
||||
while (tile != null) {
|
||||
@@ -368,12 +373,12 @@ public class Plan {
|
||||
switch (action) {
|
||||
case ACTION_ADD:
|
||||
return addTile(params.get(TILE),params.get(X),params.get(Y),null);
|
||||
case ACTION_CLICK:
|
||||
return click(get(params.get(X),params.get(Y),true));
|
||||
case ACTION_ANALYZE:
|
||||
return analyze();
|
||||
case ACTION_MOVE:
|
||||
return moveTile(params.get(DIRECTION),params.get(X),params.get(Y));
|
||||
case ACTION_PROPS:
|
||||
return propMenu(get(params.get(X),params.get(Y),true));
|
||||
case ACTION_ROUTE:
|
||||
return routeProperties(params.get(ID));
|
||||
case ACTION_SAVE:
|
||||
@@ -408,11 +413,6 @@ public class Plan {
|
||||
if (route == null) return t("Could not find route \"{}\"",routeId);
|
||||
return route.properties();
|
||||
}
|
||||
|
||||
private Tag propMenu(Tile tile) {
|
||||
if (tile == null) return null;
|
||||
return tile.propMenu();
|
||||
}
|
||||
|
||||
private void registerRoute(Route route) {
|
||||
for (Tile tile: route.path()) tile.add(route);
|
||||
@@ -482,7 +482,7 @@ public class Plan {
|
||||
return (train == null) ? null : train.props();
|
||||
}
|
||||
|
||||
private String start(Train train) {
|
||||
private String start(Train train) throws IOException {
|
||||
if (train == null) return null;
|
||||
return train.start();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.srsoftware.web4rail;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -111,7 +112,10 @@ public class Route {
|
||||
return props.toString();
|
||||
}
|
||||
|
||||
public Route lock(Train train) {
|
||||
public Route lock(Train train) throws IOException {
|
||||
for (Entry<Turnout, State> entry : turnouts.entrySet()) {
|
||||
entry.getKey().state(entry.getValue());
|
||||
}
|
||||
for (Tile tile : path) tile.lock(train);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.srsoftware.web4rail.moving;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.Vector;
|
||||
@@ -55,7 +56,7 @@ public class Train {
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
public String start() {
|
||||
public String start() throws IOException {
|
||||
if (block == null) return t("{] not in a block",this);
|
||||
HashSet<Route> routes = block.routes();
|
||||
Vector<Route> availableRoutes = new Vector<Route>();
|
||||
|
||||
@@ -19,10 +19,10 @@ import de.srsoftware.web4rail.Application;
|
||||
import de.srsoftware.web4rail.Connector;
|
||||
import de.srsoftware.web4rail.Plan;
|
||||
import de.srsoftware.web4rail.Plan.Direction;
|
||||
import de.srsoftware.web4rail.tags.Form;
|
||||
import de.srsoftware.web4rail.Route;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.moving.Train;
|
||||
import de.srsoftware.web4rail.tags.Form;
|
||||
|
||||
public abstract class Tile {
|
||||
|
||||
@@ -30,7 +30,7 @@ public abstract class Tile {
|
||||
protected HashSet<String> classes = new HashSet<>();
|
||||
protected HashSet<Shadow> shadows = new HashSet<>();
|
||||
private HashSet<Route> routes = new HashSet<>();
|
||||
private Plan plan;
|
||||
protected Plan plan;
|
||||
private Train lockedBy;
|
||||
|
||||
protected static Logger LOG = LoggerFactory.getLogger(Tile.class);
|
||||
@@ -48,6 +48,10 @@ public abstract class Tile {
|
||||
shadows.add(shadow);
|
||||
}
|
||||
|
||||
public Object click() throws IOException {
|
||||
return propMenu();
|
||||
}
|
||||
|
||||
public JSONObject config() {
|
||||
return new JSONObject();
|
||||
}
|
||||
@@ -69,6 +73,7 @@ public abstract class Tile {
|
||||
|
||||
public void lock(Train train) {
|
||||
lockedBy = train;
|
||||
classes.add("locked");
|
||||
plan.stream("addclass tile-"+x+"-"+y+" locked");
|
||||
}
|
||||
|
||||
@@ -190,6 +195,7 @@ public abstract class Tile {
|
||||
|
||||
public void unlock() {
|
||||
lockedBy = null;
|
||||
classes.remove("locked");
|
||||
plan.stream("dropclass tile-"+x+"-"+y+" locked");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,35 @@
|
||||
package de.srsoftware.web4rail.tiles;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
|
||||
public abstract class Turnout extends Tile {
|
||||
public static final String STATE = "state";
|
||||
public enum State{
|
||||
LEFT,STRAIGHT,RIGHT,UNDEF;
|
||||
}
|
||||
private boolean straight = true;
|
||||
protected State state = State.STRAIGHT;
|
||||
|
||||
public boolean toggle() {
|
||||
straight = !straight;
|
||||
return straight;
|
||||
public State state() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void state(State newState) throws IOException {
|
||||
state = newState;
|
||||
LOG.debug("Setting {} to {}",this,state);
|
||||
plan.stream("place "+tag(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag tag(Map<String, Object> replacements) throws IOException {
|
||||
Tag tag = super.tag(replacements);
|
||||
tag.clazz(tag.get("class")+(" "+state).toLowerCase());
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void toggle() {
|
||||
state = State.STRAIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
11
src/main/java/de/srsoftware/web4rail/tiles/TurnoutL.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package de.srsoftware.web4rail.tiles;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class TurnoutL extends Turnout {
|
||||
@Override
|
||||
public Object click() throws IOException {
|
||||
state = (state == State.STRAIGHT) ? State.LEFT : State.STRAIGHT;
|
||||
return tag(null);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import java.util.Map;
|
||||
import de.srsoftware.web4rail.Connector;
|
||||
import de.srsoftware.web4rail.Plan.Direction;
|
||||
|
||||
public class TurnoutLE extends Turnout{
|
||||
public class TurnoutLE extends TurnoutL{
|
||||
|
||||
@Override
|
||||
public Map<Connector, State> connections(Direction from) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.Map;
|
||||
import de.srsoftware.web4rail.Connector;
|
||||
import de.srsoftware.web4rail.Plan.Direction;
|
||||
|
||||
public class TurnoutLN extends Turnout{
|
||||
public class TurnoutLN extends TurnoutL{
|
||||
|
||||
@Override
|
||||
public Map<Connector, State> connections(Direction from) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.Map;
|
||||
import de.srsoftware.web4rail.Connector;
|
||||
import de.srsoftware.web4rail.Plan.Direction;
|
||||
|
||||
public class TurnoutLS extends Turnout{
|
||||
public class TurnoutLS extends TurnoutL{
|
||||
|
||||
@Override
|
||||
public Map<Connector, State> connections(Direction from) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.Map;
|
||||
import de.srsoftware.web4rail.Connector;
|
||||
import de.srsoftware.web4rail.Plan.Direction;
|
||||
|
||||
public class TurnoutLW extends Turnout{
|
||||
public class TurnoutLW extends TurnoutL{
|
||||
|
||||
@Override
|
||||
public Map<Connector, State> connections(Direction from) {
|
||||
|
||||
11
src/main/java/de/srsoftware/web4rail/tiles/TurnoutR.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package de.srsoftware.web4rail.tiles;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class TurnoutR extends Turnout {
|
||||
@Override
|
||||
public Object click() throws IOException {
|
||||
state = (state == State.STRAIGHT) ? State.RIGHT : State.STRAIGHT;
|
||||
return tag(null);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import java.util.Map;
|
||||
import de.srsoftware.web4rail.Connector;
|
||||
import de.srsoftware.web4rail.Plan.Direction;
|
||||
|
||||
public class TurnoutRE extends Turnout{
|
||||
public class TurnoutRE extends TurnoutR{
|
||||
|
||||
@Override
|
||||
public Map<Connector, State> connections(Direction from) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.Map;
|
||||
import de.srsoftware.web4rail.Connector;
|
||||
import de.srsoftware.web4rail.Plan.Direction;
|
||||
|
||||
public class TurnoutRN extends Turnout{
|
||||
public class TurnoutRN extends TurnoutR{
|
||||
|
||||
@Override
|
||||
public Map<Connector, State> connections(Direction from) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.Map;
|
||||
import de.srsoftware.web4rail.Connector;
|
||||
import de.srsoftware.web4rail.Plan.Direction;
|
||||
|
||||
public class TurnoutRS extends Turnout{
|
||||
public class TurnoutRS extends TurnoutR{
|
||||
|
||||
@Override
|
||||
public Map<Connector, State> connections(Direction from) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.Map;
|
||||
import de.srsoftware.web4rail.Connector;
|
||||
import de.srsoftware.web4rail.Plan.Direction;
|
||||
|
||||
public class TurnoutRW extends Turnout{
|
||||
public class TurnoutRW extends TurnoutR{
|
||||
|
||||
@Override
|
||||
public Map<Connector, State> connections(Direction from) {
|
||||
|
||||