contact within block now working
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>de.srsoftware</groupId>
|
<groupId>de.srsoftware</groupId>
|
||||||
<artifactId>web4rail</artifactId>
|
<artifactId>web4rail</artifactId>
|
||||||
<version>1.2.46</version>
|
<version>1.2.47</version>
|
||||||
<name>Web4Rail</name>
|
<name>Web4Rail</name>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<description>Java Model Railway Control</description>
|
<description>Java Model Railway Control</description>
|
||||||
|
|||||||
@@ -230,6 +230,9 @@ svg.straight .right{
|
|||||||
.active circle{
|
.active circle{
|
||||||
fill: #f57900;
|
fill: #f57900;
|
||||||
}
|
}
|
||||||
|
.Block.active{
|
||||||
|
background: #f57900;
|
||||||
|
}
|
||||||
|
|
||||||
polygon.oneway{
|
polygon.oneway{
|
||||||
fill: lime;
|
fill: lime;
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import de.srsoftware.web4rail.tags.Input;
|
|||||||
import de.srsoftware.web4rail.tags.Label;
|
import de.srsoftware.web4rail.tags.Label;
|
||||||
import de.srsoftware.web4rail.tags.Table;
|
import de.srsoftware.web4rail.tags.Table;
|
||||||
import de.srsoftware.web4rail.tiles.Block;
|
import de.srsoftware.web4rail.tiles.Block;
|
||||||
|
import de.srsoftware.web4rail.tiles.BlockContact;
|
||||||
import de.srsoftware.web4rail.tiles.BlockH;
|
import de.srsoftware.web4rail.tiles.BlockH;
|
||||||
import de.srsoftware.web4rail.tiles.BlockV;
|
import de.srsoftware.web4rail.tiles.BlockV;
|
||||||
import de.srsoftware.web4rail.tiles.Bridge;
|
import de.srsoftware.web4rail.tiles.Bridge;
|
||||||
@@ -301,7 +302,7 @@ public class Plan extends BaseClass{
|
|||||||
Vector<Route> results = new Vector<>();
|
Vector<Route> results = new Vector<>();
|
||||||
if (tile == null) return results;
|
if (tile == null) return results;
|
||||||
Tile addedTile = route.add(tile,connector.from.inverse());
|
Tile addedTile = route.add(tile,connector.from.inverse());
|
||||||
if (addedTile instanceof Block) {
|
if (addedTile instanceof Block) { // Route wird mit einem Block abgeschlossen
|
||||||
Map<Connector, State> cons = addedTile.connections(connector.from);
|
Map<Connector, State> cons = addedTile.connections(connector.from);
|
||||||
LOG.debug("Found {}, coming from {}.",addedTile,connector.from);
|
LOG.debug("Found {}, coming from {}.",addedTile,connector.from);
|
||||||
for (Connector con : cons.keySet()) { // falls direkt nach dem Block noch ein Kontakt kommt: diesen mit zu Route hinzufügen
|
for (Connector con : cons.keySet()) { // falls direkt nach dem Block noch ein Kontakt kommt: diesen mit zu Route hinzufügen
|
||||||
@@ -711,7 +712,6 @@ public class Plan extends BaseClass{
|
|||||||
learningContact = null;
|
learningContact = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSet(contact)) contact.activate(active);
|
if (isSet(contact)) contact.activate(active);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -194,6 +194,7 @@ public class Route extends BaseClass {
|
|||||||
if (tile instanceof Block) {
|
if (tile instanceof Block) {
|
||||||
endBlock = (Block) tile;
|
endBlock = (Block) tile;
|
||||||
endDirection = direrction;
|
endDirection = direrction;
|
||||||
|
contacts.addAll(endBlock.contacts());
|
||||||
}
|
}
|
||||||
path.add(tile);
|
path.add(tile);
|
||||||
if (tile instanceof Contact) contacts.add((Contact) tile);
|
if (tile instanceof Contact) contacts.add((Contact) tile);
|
||||||
@@ -296,11 +297,11 @@ public class Route extends BaseClass {
|
|||||||
|
|
||||||
public Route begin(Block block,Direction to) {
|
public Route begin(Block block,Direction to) {
|
||||||
// add those fields to clone, too!
|
// add those fields to clone, too!
|
||||||
contacts = new Vector<Contact>();
|
startBlock = block;
|
||||||
|
contacts = new Vector<Contact>(startBlock.contacts());
|
||||||
signals = new Vector<Signal>();
|
signals = new Vector<Signal>();
|
||||||
path = new Vector<Tile>();
|
path = new Vector<Tile>();
|
||||||
turnouts = new HashMap<>();
|
turnouts = new HashMap<>();
|
||||||
startBlock = block;
|
|
||||||
startDirection = to;
|
startDirection = to;
|
||||||
path.add(block);
|
path.add(block);
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -159,6 +159,10 @@ public abstract class Block extends StretchableTile{
|
|||||||
return fieldset;
|
return fieldset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Collection<? extends Contact> contacts() {
|
||||||
|
return internalContacts;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract Direction directionA();
|
public abstract Direction directionA();
|
||||||
public abstract Direction directionB();
|
public abstract Direction directionB();
|
||||||
|
|
||||||
@@ -194,6 +198,10 @@ public abstract class Block extends StretchableTile{
|
|||||||
}
|
}
|
||||||
return getWaitTime(NO_TAG).get(dir);
|
return getWaitTime(NO_TAG).get(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int indexOf(BlockContact contact) {
|
||||||
|
return 1+internalContacts.indexOf(contact);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject json() {
|
public JSONObject json() {
|
||||||
@@ -203,6 +211,15 @@ public abstract class Block extends StretchableTile{
|
|||||||
JSONArray jWaitTimes = new JSONArray();
|
JSONArray jWaitTimes = new JSONArray();
|
||||||
for (WaitTime wt : waitTimes) jWaitTimes.put(wt.json());
|
for (WaitTime wt : waitTimes) jWaitTimes.put(wt.json());
|
||||||
json.put(WAIT_TIMES, jWaitTimes);
|
json.put(WAIT_TIMES, jWaitTimes);
|
||||||
|
JSONObject jContacts = null;
|
||||||
|
for (BlockContact contact : internalContacts) {
|
||||||
|
int addr = contact.addr();
|
||||||
|
if (addr != 0) {
|
||||||
|
if (isNull(jContacts)) jContacts = new JSONObject();
|
||||||
|
jContacts.put(contact.id().toString(), contact.addr());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isSet(jContacts)) json.put(CONTACT, jContacts);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,6 +247,10 @@ public abstract class Block extends StretchableTile{
|
|||||||
if (object instanceof JSONObject) waitTimes.add(new WaitTime(null).load((JSONObject) object));
|
if (object instanceof JSONObject) waitTimes.add(new WaitTime(null).load((JSONObject) object));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (json.has(CONTACT)) {
|
||||||
|
JSONObject jContact = json.getJSONObject(CONTACT);
|
||||||
|
for (String key : jContact.keySet()) new BlockContact(this).addr(jContact.getInt(key));
|
||||||
|
}
|
||||||
return super.load(json);
|
return super.load(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,6 +281,16 @@ public abstract class Block extends StretchableTile{
|
|||||||
return contact;
|
return contact;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeChild(BaseClass child) {
|
||||||
|
super.removeChild(child);
|
||||||
|
internalContacts.remove(child);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeContact(BlockContact blockContact) {
|
||||||
|
internalContacts.remove(blockContact);
|
||||||
|
}
|
||||||
|
|
||||||
public static Select selector(Block preselected,Collection<Block> exclude) {
|
public static Select selector(Block preselected,Collection<Block> exclude) {
|
||||||
if (isNull(exclude)) exclude = new Vector<Block>();
|
if (isNull(exclude)) exclude = new Vector<Block>();
|
||||||
Select select = new Select(Block.class.getSimpleName());
|
Select select = new Select(Block.class.getSimpleName());
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
package de.srsoftware.web4rail.tiles;
|
package de.srsoftware.web4rail.tiles;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import de.srsoftware.tools.Tag;
|
||||||
|
import de.srsoftware.web4rail.Route;
|
||||||
import de.srsoftware.web4rail.Window;
|
import de.srsoftware.web4rail.Window;
|
||||||
|
|
||||||
public class BlockContact extends Contact {
|
public class BlockContact extends Contact {
|
||||||
@@ -11,14 +16,16 @@ public class BlockContact extends Contact {
|
|||||||
@Override
|
@Override
|
||||||
public Contact addr(int address) {
|
public Contact addr(int address) {
|
||||||
super.addr(address);
|
super.addr(address);
|
||||||
Block block = (Block) parent();
|
Block block = (Block) parent();
|
||||||
return block.register(this);
|
block.removeContact(this);
|
||||||
|
if (address != 0) block.register(this);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Id id() {
|
public Id id() {
|
||||||
if (id == null) id = new Id();
|
Block block = ((Block)parent());
|
||||||
return id;
|
return new Id(block.name+":"+block.indexOf(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -26,8 +33,18 @@ public class BlockContact extends Contact {
|
|||||||
return parent().properties();
|
return parent().properties();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Route route() {
|
||||||
|
return ((Block)parent()).route();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Tag tag(Map<String, Object> replacements) throws IOException {
|
||||||
|
return ((Block)parent()).tag(replacements);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getClass().getSimpleName()+"("+addr+")";
|
return id().toString()+" ("+addr+")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import org.json.JSONObject;
|
|||||||
|
|
||||||
import de.srsoftware.tools.Tag;
|
import de.srsoftware.tools.Tag;
|
||||||
import de.srsoftware.web4rail.BaseClass;
|
import de.srsoftware.web4rail.BaseClass;
|
||||||
|
import de.srsoftware.web4rail.Route;
|
||||||
import de.srsoftware.web4rail.Window;
|
import de.srsoftware.web4rail.Window;
|
||||||
import de.srsoftware.web4rail.actions.Action;
|
import de.srsoftware.web4rail.actions.Action;
|
||||||
import de.srsoftware.web4rail.actions.ActionList;
|
import de.srsoftware.web4rail.actions.ActionList;
|
||||||
@@ -74,6 +75,7 @@ public class Contact extends Tile{
|
|||||||
state = true;
|
state = true;
|
||||||
if (isSet(timer)) timer.abort();
|
if (isSet(timer)) timer.abort();
|
||||||
Context context = null;
|
Context context = null;
|
||||||
|
Route route = route();
|
||||||
if (isSet(route)) {
|
if (isSet(route)) {
|
||||||
context = route.context();
|
context = route.context();
|
||||||
actions.fire(context);
|
actions.fire(context);
|
||||||
@@ -95,7 +97,7 @@ public class Contact extends Tile{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Contact addr(int address) {
|
public Contact addr(int address) {
|
||||||
contactsByAddr.remove(addr); // alte ID aus der Map löschen
|
Contact oldContact = contactsByAddr.remove(addr); // alte ID aus der Map löschen
|
||||||
addr = address;
|
addr = address;
|
||||||
if (addr != 0) contactsByAddr.put(addr, this); // neue ID setzen
|
if (addr != 0) contactsByAddr.put(addr, this); // neue ID setzen
|
||||||
return this;
|
return this;
|
||||||
@@ -204,7 +206,7 @@ public class Contact extends Tile{
|
|||||||
|
|
||||||
public void stream() {
|
public void stream() {
|
||||||
try {
|
try {
|
||||||
Tag tag = super.tag(null);
|
Tag tag = tag(null);
|
||||||
if (state) tag.clazz(tag.get("class")+" active");
|
if (state) tag.clazz(tag.get("class")+" active");
|
||||||
plan.stream("place "+tag);
|
plan.stream("place "+tag);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user