implemented route display on block properties
This commit is contained in:
@@ -100,7 +100,10 @@ public class Plan {
|
|||||||
for (Block block : blocks) {
|
for (Block block : blocks) {
|
||||||
for (Connector con : block.startPoints()) routes.addAll(follow(new Route().start(block),con));
|
for (Connector con : block.startPoints()) routes.addAll(follow(new Route().start(block),con));
|
||||||
}
|
}
|
||||||
for (Route r : routes) LOG.debug("found route: {}",r);
|
for (Route route : routes) {
|
||||||
|
route.start().add(route);
|
||||||
|
LOG.debug("found route: {}",route);
|
||||||
|
}
|
||||||
return t("Found {} routes.",routes.size());
|
return t("Found {} routes.",routes.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ public class Route {
|
|||||||
|
|
||||||
private Vector<Tile> path;
|
private Vector<Tile> path;
|
||||||
private Vector<Signal> signals;
|
private Vector<Signal> signals;
|
||||||
|
private String id;
|
||||||
|
private String name;
|
||||||
|
|
||||||
public Tile add(Tile tile) {
|
public Tile add(Tile tile) {
|
||||||
path.add(tile);
|
path.add(tile);
|
||||||
@@ -22,12 +24,35 @@ public class Route {
|
|||||||
clone.path = new Vector<>(path);
|
clone.path = new Vector<>(path);
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String id() {
|
||||||
|
if (id == null) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (int i=0; i<path.size();i++) {
|
||||||
|
Tile tile = path.get(i);
|
||||||
|
if (i==0) {
|
||||||
|
sb.append(((Block)tile).name);
|
||||||
|
} else if (i==path.size()-1){
|
||||||
|
sb.append("-"+((Block)tile).name);
|
||||||
|
} else {
|
||||||
|
sb.append("-"+tile.x+":"+tile.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
id = sb.toString();
|
||||||
|
}
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
public List<Route> multiply(int size) {
|
public List<Route> multiply(int size) {
|
||||||
Vector<Route> routes = new Vector<Route>();
|
Vector<Route> routes = new Vector<Route>();
|
||||||
for (int i=0; i<size; i++) routes.add(i==0 ? this : this.clone());
|
for (int i=0; i<size; i++) routes.add(i==0 ? this : this.clone());
|
||||||
return routes;
|
return routes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String name() {
|
||||||
|
if (name == null) name = id();
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
public Route start(Block block) {
|
public Route start(Block block) {
|
||||||
path = new Vector<Tile>();
|
path = new Vector<Tile>();
|
||||||
@@ -37,6 +62,10 @@ public class Route {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getClass().getSimpleName()+"("+path+")";
|
return getClass().getSimpleName()+"("+id()+")";
|
||||||
|
}
|
||||||
|
|
||||||
|
public Block start() {
|
||||||
|
return (Block) path.get(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,80 @@
|
|||||||
package de.srsoftware.web4rail.tiles;
|
package de.srsoftware.web4rail.tiles;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import de.srsoftware.tools.Tag;
|
||||||
import de.srsoftware.web4rail.Connector;
|
import de.srsoftware.web4rail.Connector;
|
||||||
import de.srsoftware.web4rail.Route;
|
import de.srsoftware.web4rail.Route;
|
||||||
|
|
||||||
public abstract class Block extends StretchableTile{
|
public abstract class Block extends StretchableTile{
|
||||||
public abstract Set<Route> routes();
|
private static final String NAME = "name";
|
||||||
|
public String name = "Block";
|
||||||
|
private HashSet<Route> routes = new HashSet<Route>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject config() {
|
||||||
|
JSONObject config = super.config();
|
||||||
|
config.put(NAME, name);
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void configure(JSONObject config) {
|
||||||
|
super.configure(config);
|
||||||
|
if (config.has(NAME)) name = config.getString(NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Route> routes(){
|
||||||
|
return routes;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract List<Connector> startPoints();
|
public abstract List<Connector> startPoints();
|
||||||
|
|
||||||
|
public void add(Route route) {
|
||||||
|
routes.add(route);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Tag propForm() {
|
||||||
|
Tag form = super.propForm();
|
||||||
|
|
||||||
|
Tag label = new Tag("label").content(t("name:"));
|
||||||
|
new Tag("input").attr("type", "text").attr(NAME,"name").attr("value", name).addTo(label);
|
||||||
|
label.addTo(form);
|
||||||
|
|
||||||
|
new Tag("h4").content(t("Routes from here:")).addTo(form);
|
||||||
|
Tag routeList = new Tag("ul");
|
||||||
|
for (Route route : routes) {
|
||||||
|
new Tag("li").content(route.id()).addTo(routeList);
|
||||||
|
}
|
||||||
|
routeList.addTo(form);
|
||||||
|
|
||||||
|
return form;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Tag tag(Map<String, Object> replacements) throws IOException {
|
||||||
|
if (replacements == null) replacements = new HashMap<String, Object>();
|
||||||
|
replacements.put("%text%",name);
|
||||||
|
return super.tag(replacements);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getClass().getSimpleName()+"("+name+") @ ("+x+","+y+")";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Tile update(HashMap<String, String> params) {
|
||||||
|
super.update(params);
|
||||||
|
if (params.containsKey(NAME)) name=params.get(NAME);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,78 +1,20 @@
|
|||||||
package de.srsoftware.web4rail.tiles;
|
package de.srsoftware.web4rail.tiles;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import de.srsoftware.tools.Tag;
|
|
||||||
import de.srsoftware.web4rail.Connector;
|
import de.srsoftware.web4rail.Connector;
|
||||||
import de.srsoftware.web4rail.Plan.Direction;
|
import de.srsoftware.web4rail.Plan.Direction;
|
||||||
import de.srsoftware.web4rail.Route;
|
|
||||||
|
|
||||||
public class BlockH extends Block{
|
public class BlockH extends Block{
|
||||||
private static final String NAME = "name";
|
|
||||||
Contact north,center,south;
|
Contact north,center,south;
|
||||||
private String name = "Block";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JSONObject config() {
|
|
||||||
JSONObject config = super.config();
|
|
||||||
config.put(NAME, name);
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void configure(JSONObject config) {
|
|
||||||
super.configure(config);
|
|
||||||
if (config.has(NAME)) name = config.getString(NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int len() {
|
public int len() {
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Tag propForm() {
|
|
||||||
Tag form = super.propForm();
|
|
||||||
|
|
||||||
Tag label = new Tag("label").content(t("name:"));
|
|
||||||
new Tag("input").attr("type", "text").attr(NAME,"name").attr("value", name).addTo(label);
|
|
||||||
label.addTo(form);
|
|
||||||
|
|
||||||
return form;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<Route> routes() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Connector> startPoints() {
|
public List<Connector> startPoints() {
|
||||||
return List.of(new Connector(x-1, y, Direction.EAST),new Connector(x+len(), y, Direction.WEST));
|
return List.of(new Connector(x-1, y, Direction.EAST),new Connector(x+len(), y, Direction.WEST));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Tag tag(Map<String, Object> replacements) throws IOException {
|
|
||||||
if (replacements == null) replacements = new HashMap<String, Object>();
|
|
||||||
replacements.put("%text%",name);
|
|
||||||
return super.tag(replacements);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return getClass().getSimpleName()+"("+name+") @ ("+x+","+y+")";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Tile update(HashMap<String, String> params) {
|
|
||||||
super.update(params);
|
|
||||||
if (params.containsKey(NAME)) name=params.get(NAME);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,79 +1,20 @@
|
|||||||
package de.srsoftware.web4rail.tiles;
|
package de.srsoftware.web4rail.tiles;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import de.srsoftware.tools.Tag;
|
|
||||||
import de.srsoftware.web4rail.Connector;
|
import de.srsoftware.web4rail.Connector;
|
||||||
import de.srsoftware.web4rail.Plan.Direction;
|
import de.srsoftware.web4rail.Plan.Direction;
|
||||||
import de.srsoftware.web4rail.Route;
|
|
||||||
|
|
||||||
public class BlockV extends Block{
|
public class BlockV extends Block{
|
||||||
private static final String NAME = "name";
|
|
||||||
Contact west,center,east;
|
Contact west,center,east;
|
||||||
private String name = "Block";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JSONObject config() {
|
|
||||||
JSONObject config = super.config();
|
|
||||||
config.put(NAME, name);
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void configure(JSONObject config) {
|
|
||||||
super.configure(config);
|
|
||||||
if (config.has(NAME)) name = config.getString(NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int height() {
|
public int height() {
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Tag propForm() {
|
|
||||||
Tag form = super.propForm();
|
|
||||||
|
|
||||||
Tag label = new Tag("label").content(t("name:"));
|
|
||||||
new Tag("input").attr("type", "text").attr(NAME,"name").attr("value", name).addTo(label);
|
|
||||||
label.addTo(form);
|
|
||||||
|
|
||||||
return form;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<Route> routes() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Connector> startPoints() {
|
public List<Connector> startPoints() {
|
||||||
return List.of(new Connector(x,y-1,Direction.SOUTH),new Connector(x,y+height(),Direction.NORTH));
|
return List.of(new Connector(x,y-1,Direction.SOUTH),new Connector(x,y+height(),Direction.NORTH));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Tag tag(Map<String, Object> replacements) throws IOException {
|
|
||||||
if (replacements == null) replacements = new HashMap<String, Object>();
|
|
||||||
replacements.put("%text%",name);
|
|
||||||
return super.tag(replacements);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return getClass().getSimpleName()+"("+name+") @ ("+x+","+y+")";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Tile update(HashMap<String, String> params) {
|
|
||||||
super.update(params);
|
|
||||||
if (params.containsKey(NAME)) name=params.get(NAME);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import de.srsoftware.web4rail.Plan.Direction;
|
|||||||
|
|
||||||
public abstract class Tile {
|
public abstract class Tile {
|
||||||
|
|
||||||
protected int x = -1,y = -1;
|
public int x = -1,y = -1;
|
||||||
protected HashSet<String> classes = new HashSet<String>();
|
protected HashSet<String> classes = new HashSet<String>();
|
||||||
protected HashSet<Shadow> shadows = new HashSet<Shadow>();
|
protected HashSet<Shadow> shadows = new HashSet<Shadow>();
|
||||||
protected static Logger LOG = LoggerFactory.getLogger(Tile.class);
|
protected static Logger LOG = LoggerFactory.getLogger(Tile.class);
|
||||||
@@ -33,6 +33,10 @@ public abstract class Tile {
|
|||||||
classes.add("tile");
|
classes.add("tile");
|
||||||
classes.add(getClass().getSimpleName());
|
classes.add(getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addShadow(Shadow shadow) {
|
||||||
|
shadows.add(shadow);
|
||||||
|
}
|
||||||
|
|
||||||
public JSONObject config() {
|
public JSONObject config() {
|
||||||
return new JSONObject();
|
return new JSONObject();
|
||||||
@@ -149,9 +153,5 @@ public abstract class Tile {
|
|||||||
public Tile update(HashMap<String, String> params) {
|
public Tile update(HashMap<String, String> params) {
|
||||||
LOG.debug("{}.update({})",getClass().getSimpleName(),params);
|
LOG.debug("{}.update({})",getClass().getSimpleName(),params);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addShadow(Shadow shadow) {
|
|
||||||
shadows.add(shadow);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user