implemented removal of old routes when new routes are searched
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.15</version>
|
<version>1.2.16</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>
|
||||||
|
|||||||
@@ -387,6 +387,7 @@ public abstract class BaseClass implements Constants{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BaseClass remove() {
|
public BaseClass remove() {
|
||||||
|
LOG.debug("Called remove on {} ({})",id(),this);
|
||||||
if (isSet(parent)) parent.removeChild(this);
|
if (isSet(parent)) parent.removeChild(this);
|
||||||
return registry.remove(id());
|
return registry.remove(id());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -249,18 +249,23 @@ public class Plan extends BaseClass{
|
|||||||
* @return a string giving information how many routes have been found
|
* @return a string giving information how many routes have been found
|
||||||
*/
|
*/
|
||||||
private String analyze() {
|
private String analyze() {
|
||||||
Vector<Route> routes = new Vector<Route>();
|
List<Route> oldRoutes = BaseClass.listElements(Route.class);
|
||||||
|
Vector<Route> newRoutes = new Vector<Route>();
|
||||||
for (Block block : BaseClass.listElements(Block.class)) {
|
for (Block block : BaseClass.listElements(Block.class)) {
|
||||||
if (block.name.equals("Huhu")) {
|
if (block.name.equals("Huhu")) {
|
||||||
System.err.println("Here we go!");
|
System.err.println("Here we go!");
|
||||||
}
|
}
|
||||||
for (Connector con : block.startPoints()) {
|
for (Connector con : block.startPoints()) {
|
||||||
routes.addAll(follow(new Route().begin(block,con.from.inverse()),con));
|
newRoutes.addAll(follow(new Route().begin(block,con.from.inverse()),con));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Tile tile : BaseClass.listElements(Tile.class)) tile.routes().clear();
|
for (Tile tile : BaseClass.listElements(Tile.class)) tile.routes().clear();
|
||||||
for (Route route : routes) registerRoute(route.complete());
|
for (Route route : newRoutes) registerRoute(route.complete());
|
||||||
return t("Found {} routes.",routes.size());
|
for (Route oldRoute : oldRoutes) {
|
||||||
|
oldRoute.id = new Id("test"); // new routes may have the same ids and shall not be deleted in the next step!
|
||||||
|
oldRoute.remove();
|
||||||
|
}
|
||||||
|
return t("Found {} routes.",newRoutes.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -286,8 +286,12 @@ public class Route extends BaseClass implements Comparable<Route>{
|
|||||||
public void addPropertiesFrom(Route existingRoute) {
|
public void addPropertiesFrom(Route existingRoute) {
|
||||||
LOG.debug("addPropertiesFrom({})",existingRoute);
|
LOG.debug("addPropertiesFrom({})",existingRoute);
|
||||||
disabled = existingRoute.disabled;
|
disabled = existingRoute.disabled;
|
||||||
|
|
||||||
conditions.addAll(existingRoute.conditions);
|
for (Condition condition : existingRoute.conditions) { // bestehende Bedingungen der neuen zuweisen
|
||||||
|
condition.parent(this);
|
||||||
|
conditions.add(condition);
|
||||||
|
}
|
||||||
|
conditions.forEach(condition -> existingRoute.conditions.removeChild(condition));
|
||||||
|
|
||||||
for (Entry<String, ActionList> entry : triggeredActions.entrySet()) {
|
for (Entry<String, ActionList> entry : triggeredActions.entrySet()) {
|
||||||
String trigger = entry.getKey();
|
String trigger = entry.getKey();
|
||||||
@@ -469,7 +473,7 @@ public class Route extends BaseClass implements Comparable<Route>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Id id() {
|
public Id id() {
|
||||||
if (id == null) id = new Id(""+(generateName().hashCode()));
|
if (isNull(id)) id = new Id(""+(generateName().hashCode()));
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -748,7 +752,7 @@ public class Route extends BaseClass implements Comparable<Route>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BaseClass remove() {
|
public BaseClass remove() {
|
||||||
super.remove();
|
super.remove();
|
||||||
if (isSet(train)) train.removeChild(this);
|
if (isSet(train)) train.removeChild(this);
|
||||||
path.forEach(tile -> tile.removeChild(this));
|
path.forEach(tile -> tile.removeChild(this));
|
||||||
|
|||||||
@@ -74,11 +74,12 @@ public class ActionList extends Action implements Iterable<Action>{
|
|||||||
}
|
}
|
||||||
if (exists) {
|
if (exists) {
|
||||||
LOG.debug("action not added.");
|
LOG.debug("action not added.");
|
||||||
} else {
|
} else { // bestehemde Aktion der neuen Liste zuweisen
|
||||||
this.add(otherAction);
|
this.add(otherAction);
|
||||||
LOG.debug("action added.");
|
LOG.debug("action added.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
actions.forEach(action -> other.removeChild(action)); // zugewiesene Aktionen von alter Liste löschen
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean drop(Action action) {
|
public boolean drop(Action action) {
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ public class ConditionList extends Condition implements Iterable<Condition>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void removeChild(BaseClass child) {
|
public void removeChild(BaseClass child) {
|
||||||
conditions.remove(child);
|
conditions.remove(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -389,7 +389,7 @@ public abstract class Tile extends BaseClass implements Comparable<Tile>{
|
|||||||
@Override
|
@Override
|
||||||
public void removeChild(BaseClass child) {
|
public void removeChild(BaseClass child) {
|
||||||
routes.remove(child);
|
routes.remove(child);
|
||||||
shadows.remove(child);
|
if (child instanceof Shadow) shadows.remove(child);
|
||||||
if (child == train) train = null;
|
if (child == train) train = null;
|
||||||
if (child == route) route = null;
|
if (child == route) route = null;
|
||||||
plan.place(this);
|
plan.place(this);
|
||||||
|
|||||||
Reference in New Issue
Block a user