Commit fd2924ab authored by Daniel Lehmberg's avatar Daniel Lehmberg

[WIP] implement setAttributes of all inheriting classes of ScenarioElement

parent 939c6119
Pipeline #59468 passed with stage
in 51 seconds
......@@ -143,7 +143,7 @@ public class ScenarioElementView extends JPanel implements ISelectScenarioElemen
} else {
try {
Attributes attributes = StateJsonConverter.deserializeScenarioElementType(json, element.getType());
ReflectionAttributeModifier.setAttributes(element, attributes);
element.setAttributes(attributes); // Replaces previous ReflectionAttributeModifier.setAttributes (see #91)
ScenarioPanel.removeJsonParsingErrorMsg();
ProjectView.getMainWindow().refreshScenarioNames();
jsonValidIndicator.setValid();
......
......@@ -3,6 +3,7 @@ package org.vadere.gui.topographycreator.control;
import java.lang.reflect.Field;
import org.vadere.gui.topographycreator.model.AgentWrapper;
import org.vadere.simulator.projects.Scenario;
import org.vadere.state.attributes.Attributes;
import org.vadere.state.scenario.ScenarioElement;
import org.vadere.util.geometry.shapes.VPoint;
......
......@@ -71,6 +71,11 @@ public final class AgentWrapper extends ScenarioElement {
return agent.getAttributes();
}
@Override
public void setAttributes(Attributes attributes){
this.agent.setAttributes(attributes);
}
@Override
public AgentWrapper clone() {
return new AgentWrapper((Agent) agent.clone());
......
......@@ -252,7 +252,12 @@ public class ScenarioBuilder {
AttributesBuilder<Attributes> attBuilder = new AttributesBuilder<>(element.getAttributes());
attBuilder.setField(fieldName, value);
E clone = (E) element.clone();
reflectionAttributeModifier.setAttributes(clone, attBuilder.build());
//NOTE see issue #91:
//This class is not tested - revert change by uncommenting reflextion and comment in
//clone.setAttributes
//reflectionAttributeModifier.setAttributes(clone, attBuilder.build());
clone.setAttributes(attBuilder.build());
return clone;
}
......
......@@ -7,6 +7,7 @@ import java.util.Random;
import org.apache.commons.math3.random.JDKRandomGenerator;
import org.apache.commons.math3.random.RandomGenerator;
import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.util.geometry.Vector2D;
import org.vadere.util.geometry.shapes.VCircle;
......@@ -31,7 +32,7 @@ public abstract class Agent extends DynamicElement {
private double freeFlowSpeed;
private final AttributesAgent attributes;
private AttributesAgent attributes;
public Agent(AttributesAgent attributesAgent) {
position = new VPoint(0, 0);
......@@ -184,6 +185,11 @@ public abstract class Agent extends DynamicElement {
// Setters...
@Override
public void setAttributes(Attributes attributes){
this.attributes = (AttributesAgent) attributes;
}
/**
* Set the index pointing to the next target in the target list.
*
......
......@@ -2,6 +2,7 @@ package org.vadere.state.scenario;
import java.util.Random;
import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.scenario.AttributesCar;
import org.vadere.state.types.ScenarioElementType;
import org.vadere.util.geometry.Vector2D;
......@@ -11,7 +12,7 @@ import org.vadere.util.geometry.shapes.VRectangle;
public class Car extends Agent implements Comparable<Car> {
private final AttributesCar attributesCar;
private AttributesCar attributesCar;
public Car(AttributesCar attributesCar, Random random) {
super(attributesCar, random);
......@@ -63,6 +64,10 @@ public class Car extends Agent implements Comparable<Car> {
return this.attributesCar;
}
public void setAttributes(Attributes attributes) {
this.attributesCar = (AttributesCar) attributes;
}
@Override
public int getId() {
return attributesCar.getId();
......
package org.vadere.state.scenario;
import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.attributes.scenario.AttributesObstacle;
import org.vadere.state.types.ScenarioElementType;
import org.vadere.util.geometry.shapes.VShape;
public class Obstacle extends ScenarioElement {
private final AttributesObstacle attributes;
private AttributesObstacle attributes;
public Obstacle(AttributesObstacle attributes) {
if (attributes == null)
......@@ -71,6 +72,12 @@ public class Obstacle extends ScenarioElement {
return attributes;
}
@Override
public void setAttributes(Attributes attributes){
this.attributes = (AttributesObstacle) attributes;
}
@Override
public Obstacle clone() {
return new Obstacle((AttributesObstacle) attributes.clone());
......
package org.vadere.state.scenario;
import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.scenario.AttributesSource;
import org.vadere.state.types.ScenarioElementType;
import org.vadere.util.geometry.shapes.VShape;
public class Source extends ScenarioElement {
private final AttributesSource attributes;
private AttributesSource attributes;
public Source(AttributesSource attributes) {
this.attributes = attributes;
......@@ -32,6 +33,13 @@ public class Source extends ScenarioElement {
return attributes;
}
@Override
public void setAttributes(Attributes attributes){
this.attributes = (AttributesSource) attributes;
}
public double getStartTime() {
return attributes.getStartTime();
}
......
......@@ -6,13 +6,14 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.scenario.AttributesTarget;
import org.vadere.state.types.ScenarioElementType;
import org.vadere.util.geometry.shapes.VShape;
public class Target extends ScenarioElement implements Comparable<Target> {
private final AttributesTarget attributes;
private AttributesTarget attributes;
private final Map<Integer, Double> enteringTimes;
/**
......@@ -113,6 +114,13 @@ public class Target extends ScenarioElement implements Comparable<Target> {
return attributes;
}
@Override
public void setAttributes(Attributes attributes){
this.attributes = (AttributesTarget) attributes;
}
/** Is this target actually a pedestrian? @see scenario.TargetPedestrian */
public boolean isTargetPedestrian() {
return false;
......
package org.vadere.state.scenario;
import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.scenario.AttributesTeleporter;
import org.vadere.state.types.ScenarioElementType;
import org.vadere.util.geometry.Vector2D;
......@@ -8,7 +9,7 @@ import org.vadere.util.geometry.shapes.VShape;
public class Teleporter extends ScenarioElement {
private final AttributesTeleporter attributes;
private AttributesTeleporter attributes;
public Teleporter(AttributesTeleporter attributes) {
this.attributes = attributes;
......@@ -37,6 +38,11 @@ public class Teleporter extends ScenarioElement {
return attributes;
}
@Override
public void setAttributes(Attributes attributes) {
this.attributes = (AttributesTeleporter) attributes;
}
@Override
public ScenarioElementType getType() {
return ScenarioElementType.TELEPORTER;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment