fixed bug when deleting tiles

This commit is contained in:
Stephan Richter
2020-12-04 15:20:31 +01:00
parent 6ce8fa1693
commit 35c0666ab2
40 changed files with 50 additions and 107 deletions

View File

@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.srsoftware</groupId>
<artifactId>web4rail</artifactId>
<version>1.2.18</version>
<version>1.2.19</version>
<name>Web4Rail</name>
<packaging>jar</packaging>
<description>Java Model Railway Control</description>

View File

@@ -164,11 +164,6 @@ public class Application extends BaseClass{
return Files.probeContentType(file.toPath());
}
@Override
protected void removeChild(BaseClass child) {
throw new RuntimeException(this.getClass().getSimpleName()+".removeChild should never be called!");
}
/**
* sends a response generated from the application to a given client
* @param client

View File

@@ -387,12 +387,12 @@ public abstract class BaseClass implements Constants{
}
public BaseClass remove() {
LOG.debug("Called remove on {} ({})",id(),this);
LOG.debug("BaseClass.Remove {} ({})",id(),this);
if (isSet(parent)) parent.removeChild(this);
return registry.remove(id());
}
protected abstract void removeChild(BaseClass child);
protected void removeChild(BaseClass child) {}
protected static String t(String txt, Object...fills) {
return Translation.get(Application.class, txt, fills);

View File

@@ -109,9 +109,4 @@ public class PathFinder extends BaseClass{
return selectetRoute;
}
@Override
protected void removeChild(BaseClass child) {
// this class has no child elements
}
}

View File

@@ -639,6 +639,7 @@ public class Plan extends BaseClass{
@Override
protected void removeChild(BaseClass child) {
if (child instanceof Tile) drop((Tile) child);
super.removeChild(child);
}
/**

View File

@@ -28,11 +28,6 @@ public class Range extends BaseClass{
if (max - min == 0) return max - min;
return min + random.nextInt(max - min);
}
@Override
protected void removeChild(BaseClass child) {
// this class has no child elements
}
@Override
public String toString() {

View File

@@ -753,15 +753,20 @@ public class Route extends BaseClass implements Comparable<Route>{
@Override
public BaseClass remove() {
super.remove();
LOG.debug("Removing route ({}) {}",id(),this);
if (isSet(train)) train.removeChild(this);
path.forEach(tile -> tile.removeChild(this));
for (Tile tile : path) {
if (tile.id().equals(Tile.id(4, 6))) {
System.err.println(tile);
}
tile.removeChild(this);
}
conditions.remove();
for (String key : new Vector<String>(triggeredActions.keySet())){
ActionList actionList = triggeredActions.remove(key);
if (isSet(actionList)) actionList.remove();
};
return this;
return super.remove();
}
@Override
@@ -772,10 +777,13 @@ public class Route extends BaseClass implements Comparable<Route>{
path.remove(child);
signals.remove(child);
if (child == train) train = null;
for (ActionList list : triggeredActions.values()) list.removeChild(child);
for (ActionList list : triggeredActions.values()) {
list.removeChild(child);
}
turnouts.remove(child);
if (child == startBlock) startBlock = null;
triggeredContacts.remove(child);
super.removeChild(child);
}
public boolean reset() {

View File

@@ -199,6 +199,7 @@ public class ActionList extends Action implements Iterable<Action>{
@Override
public BaseClass remove() {
LOG.debug("Removing Action List ({}) {}",id(),this);
super.remove();
while (!actions.isEmpty()) actions.lastElement().remove();
return this;
@@ -207,5 +208,6 @@ public class ActionList extends Action implements Iterable<Action>{
@Override
public void removeChild(BaseClass child) {
actions.remove(child);
super.removeChild(child);
}
}

View File

@@ -14,9 +14,4 @@ public class BrakeCancel extends Action {
context.route().brakeCancel();
return true;
}
@Override
protected void removeChild(BaseClass child) {
// this class has no child elements
}
}

View File

@@ -15,9 +15,4 @@ public class BrakeStart extends Action {
LOG.debug("Started brake process...");
return true;
}
@Override
protected void removeChild(BaseClass child) {
// this class has no child elements
}
}

View File

@@ -14,9 +14,4 @@ public class BrakeStop extends Action {
context.route().brakeStop();
return true;
}
@Override
protected void removeChild(BaseClass child) {
// this class has no child elements
}
}

View File

@@ -71,7 +71,7 @@ public class ConditionalAction extends ActionList {
@Override
public void removeChild(BaseClass child) {
conditions.remove(child);
actions.remove(child);
super.removeChild(child);
}
@Override

View File

@@ -49,6 +49,7 @@ public class DetermineTrainInBlock extends Action {
@Override
protected void removeChild(BaseClass child) {
if (child == block) block = null;
super.removeChild(child);
}
public String toString() {

View File

@@ -15,9 +15,4 @@ public class FinishRoute extends Action {
if (isSet(route)) route.finish();
return true;
}
@Override
protected void removeChild(BaseClass child) {
// this class has no child elements
}
}

View File

@@ -29,9 +29,4 @@ public class PreserveRoute extends Action {
train.reserveNext();
return true;
}
@Override
protected void removeChild(BaseClass child) {
// this class has no child elements
}
}

View File

@@ -54,11 +54,6 @@ public class SendCommand extends Action{
return super.properties(preForm, formInputs, postForm);
}
@Override
protected void removeChild(BaseClass child) {
// this class has no child elements
}
@Override
public String toString() {
return t("Send command \"{}\" to control unit",command);

View File

@@ -57,7 +57,8 @@ public class SetContextTrain extends Action {
@Override
protected void removeChild(BaseClass child) {
if (child == train) train = null;
if (child == train) train = null;
super.removeChild(child);
}
public String toString() {

View File

@@ -54,6 +54,7 @@ public class SetDisplayText extends TextAction{
@Override
protected void removeChild(BaseClass child) {
if (child == display) display = null;
super.removeChild(child);
}
@Override

View File

@@ -68,11 +68,6 @@ public class SetPower extends Action{
return super.properties(preForm, formInputs, postForm);
}
@Override
protected void removeChild(BaseClass child) {
// this class has no child elements
}
@Override
public String toString() {
switch (pc) {

View File

@@ -64,6 +64,7 @@ public class SetRelay extends Action {
@Override
protected void removeChild(BaseClass child) {
if (child == relay) relay = null;
super.removeChild(child);
}
public String toString() {

View File

@@ -70,6 +70,7 @@ public class SetSignal extends Action {
@Override
protected void removeChild(BaseClass child) {
if (child == signal) signal = null;
super.removeChild(child);
}
public SetSignal set(Signal sig) {

View File

@@ -45,11 +45,6 @@ public class SetSpeed extends Action{
formInputs.add(t("Set speed to"),new Input(MAX_SPEED, speed).numeric());
return super.properties(preForm, formInputs, postForm);
}
@Override
protected void removeChild(BaseClass child) {
// this class has no child elements
}
@Override
public String toString() {

View File

@@ -21,11 +21,6 @@ public class ShowText extends TextAction{
return new Label(t("Text to display on clients:")+NBSP);
}
@Override
protected void removeChild(BaseClass child) {
// this class has no child elements
}
@Override
public String toString() {
return t("Display \"{}\" on clients.",text);

View File

@@ -14,9 +14,4 @@ public class StopAllTrains extends Action {
Train.list().forEach(train -> train.stopNow());
return true;
}
@Override
protected void removeChild(BaseClass child) {
// this class has no child elements
}
}

View File

@@ -14,9 +14,4 @@ public class StopAuto extends Action {
context.train().quitAutopilot();
return true;
}
@Override
protected void removeChild(BaseClass child) {
// this class has no child elements
}
}

View File

@@ -48,6 +48,7 @@ public class TriggerContact extends Action {
@Override
protected void removeChild(BaseClass child) {
if (child == contact) contact = null;
super.removeChild(child);
}
public String toString() {

View File

@@ -16,9 +16,4 @@ public class TurnTrain extends Action{
}
return false;
}
@Override
protected void removeChild(BaseClass child) {
// this class has no child elements
}
}

View File

@@ -45,6 +45,7 @@ public class BlockFree extends Condition {
@Override
protected void removeChild(BaseClass child) {
if (child == block) block = null;
super.removeChild(child);
}
@Override

View File

@@ -122,6 +122,7 @@ public class ConditionList extends Condition implements Iterable<Condition>{
@Override
public BaseClass remove() {
LOG.debug("Removing Condition List ({}) {}",id(),this);
super.remove();
while (!conditions.isEmpty()) conditions.lastElement().remove();
return this;
@@ -134,6 +135,7 @@ public class ConditionList extends Condition implements Iterable<Condition>{
@Override
public void removeChild(BaseClass child) {
conditions.remove(child);
super.removeChild(child);
}

View File

@@ -8,11 +8,6 @@ public class PushPullTrain extends Condition {
public boolean fulfilledBy(Context context) {
return context.train().pushPull != inverted;
}
@Override
protected void removeChild(BaseClass child) {
// this class has no child elements
}
@Override
public String toString() {

View File

@@ -38,11 +38,6 @@ public class TrainHasTag extends Condition {
return super.properties(preForm, formInputs, postForm);
}
@Override
protected void removeChild(BaseClass child) {
// this class has no child elements
}
@Override
public String toString() {
if (tag == null) return "["+t("Click to setup tag")+"]";

View File

@@ -39,11 +39,6 @@ public class TrainLength extends Condition {
return super.properties(preForm, formInputs, postForm);
}
@Override
protected void removeChild(BaseClass child) {
// this class has no child elements
}
@Override
public String toString() {
return t(inverted ? "train is longer than {}" : "train is shorter than {}",maxLength) ;

View File

@@ -40,6 +40,7 @@ public class TrainSelect extends Condition {
@Override
protected void removeChild(BaseClass child) {
if (child == train) train = null;
super.removeChild(child);
}
@Override

View File

@@ -208,6 +208,7 @@ public class Car extends BaseClass implements Comparable<Car>{
@Override
protected void removeChild(BaseClass child) {
if (child == train) train = null;
super.removeChild(child);
}

View File

@@ -570,6 +570,7 @@ public class Train extends BaseClass implements Comparable<Train> {
cars.remove(child);
locos.remove(child);
trace.remove(child);
super.removeChild(child);
}
public void reserveNext() {

View File

@@ -104,7 +104,7 @@ public abstract class Bridge extends Tile {
@Override
public void removeChild(BaseClass child) {
if (child == counterpart) counterpart = null;
plan.place(this);
super.removeChild(child);
}
@Override

View File

@@ -190,6 +190,7 @@ public class Contact extends Tile{
@Override
public void removeChild(BaseClass child) {
if (child == actions) actions = null;
super.removeChild(child);
}
public static Select selector(Contact preselect) {

View File

@@ -33,10 +33,11 @@ public class Shadow extends Tile{
@Override
public void removeChild(BaseClass child) {
super.removeChild(child);
if (child == overlay) {
overlay = null;
remove();
}
}
}
@Override

View File

@@ -77,9 +77,9 @@ public abstract class StretchableTile extends Tile {
@Override
public BaseClass remove() {
super.remove();
LOG.debug("Removing stretchable Tile ({}) {}",id(),this);
removeShadows();
return this;
return super.remove();
}
private void removeShadows() {

View File

@@ -376,16 +376,24 @@ public abstract class Tile extends BaseClass implements Comparable<Tile>{
@Override
public BaseClass remove() {
super.remove();
while (!routes.isEmpty()) routes.first().remove();
return this;
while (!routes.isEmpty()) {
routes.first().remove();
}
return super.remove();
}
@Override
public void removeChild(BaseClass child) {
routes.remove(child);
String childAsString = child.toString();
if (childAsString.length()>20) childAsString = childAsString.substring(0, 20)+"";
LOG.debug("Removing {} from {}",childAsString,this);
if (child instanceof Route) {
routes.remove(child);
}
if (child == train) train = null;
if (child == route) route = null;
super.removeChild(child);
plan.place(this);
}