Currently job artifacts in CI/CD pipelines on LRZ GitLab never expire. Starting from Wed 26.1.2022 the default expiration time will be 30 days (GitLab default). Currently existing artifacts in already completed jobs will not be affected by the change. The latest artifacts for all jobs in the latest successful pipelines will be kept. More information: https://gitlab.lrz.de/help/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration

Commit f6601b40 authored by Jakob Schöttl's avatar Jakob Schöttl
Browse files

Merge branch 'dojo1' into develop

parents 614098e2 1114b0f6
package org.vadere.gui.components.utils;
import org.vadere.state.attributes.scenario.AttributesDynamicElement;
import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;
/**
* This Exclusion strategy exclude the {@link AttributesDynamicElement#id} from serialization. This
* is useful if you want
* to protect the id from changes via text.
*
*/
public class GsonAttributeDynamicElementExclusionStrategy implements ExclusionStrategy {
@Override
public boolean shouldSkipField(final FieldAttributes f) {
return (f.getDeclaringClass() == AttributesDynamicElement.class) && f.getName().equals("id");
}
@Override
public boolean shouldSkipClass(final Class<?> clazz) {
return false;
}
}
package org.vadere.gui.components.view;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
import java.awt.*;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.IOException;
import java.io.InputStream;
import javax.swing.*;
import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.BadLocationException;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
......@@ -25,10 +26,13 @@ import org.vadere.gui.projectview.view.ProjectView;
import org.vadere.gui.projectview.view.ScenarioJPanel;
import org.vadere.gui.topographycreator.model.AgentWrapper;
import org.vadere.gui.topographycreator.model.TopographyCreatorModel;
import org.vadere.simulator.projects.io.JsonConverter;
import org.vadere.state.attributes.Attributes;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.ScenarioElement;
import org.vadere.state.util.StateJsonConverter;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
/**
* The ScenarioElementView display's a ScenarioElement in JSON-Format.
......@@ -131,14 +135,14 @@ public class ScenarioElementView extends JPanel implements ISelectScenarioElemen
// JsonSerializerVShape shapeSerializer = new JsonSerializerVShape();
Pedestrian ped = null;
try {
ped = JsonConverter.deserializePedestrian(json);
ped = StateJsonConverter.deserializePedestrian(json);
} catch (IOException e) {
e.printStackTrace();
}
((AgentWrapper) element).setAgentInitialStore(ped);
} else {
try {
Attributes attributes = JsonConverter.deserializeScenarioElementType(json, element.getType());
Attributes attributes = StateJsonConverter.deserializeScenarioElementType(json, element.getType());
ReflectionAttributeModifier.setAttributes(element, attributes);
ScenarioJPanel.removeJsonParsingErrorMsg();
ProjectView.getMainWindow().refreshScenarioNames();
......@@ -174,18 +178,14 @@ public class ScenarioElementView extends JPanel implements ISelectScenarioElemen
jsonValidIndicator.hide();
}
} else {
try {
if (scenarioElement instanceof AgentWrapper) {
this.txtrTextfiletextarea.setText(
JsonConverter.serializeObject(((AgentWrapper) scenarioElement).getAgentInitialStore()));
} else if (scenarioElement instanceof Pedestrian) {
this.txtrTextfiletextarea.setText(JsonConverter.serializeObject(scenarioElement));
} else {
this.txtrTextfiletextarea.setText(JsonConverter
.serializeObject(ReflectionAttributeModifier.getAttributes(scenarioElement)));
}
} catch (JsonProcessingException e) {
// ?
if (scenarioElement instanceof AgentWrapper) {
this.txtrTextfiletextarea.setText(
StateJsonConverter.serializeObject(((AgentWrapper) scenarioElement).getAgentInitialStore()));
} else if (scenarioElement instanceof Pedestrian) {
this.txtrTextfiletextarea.setText(StateJsonConverter.serializeObject(scenarioElement));
} else {
this.txtrTextfiletextarea.setText(StateJsonConverter
.serializeObject(ReflectionAttributeModifier.getAttributes(scenarioElement)));
}
}
}
......
......@@ -21,7 +21,6 @@ import org.apache.log4j.Logger;
import org.vadere.gui.components.model.SimulationModel;
import org.vadere.gui.postvisualization.utils.PotentialFieldContainer;
import org.vadere.simulator.projects.ScenarioRunManager;
import org.vadere.simulator.projects.io.JsonConverter;
import org.vadere.state.scenario.Agent;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.ScenarioElement;
......@@ -29,6 +28,7 @@ import org.vadere.state.scenario.Topography;
import org.vadere.state.scenario.TopographyIterator;
import org.vadere.state.simulation.Step;
import org.vadere.state.simulation.Trajectory;
import org.vadere.state.util.StateJsonConverter;
import org.vadere.util.io.IOUtils;
import org.vadere.util.io.parser.JsonLogicParser;
import org.vadere.util.io.parser.VPredicate;
......@@ -221,7 +221,7 @@ public class PostvisualizationModel extends SimulationModel<PostvisualizationCon
}
public Optional<Color> getColor(final Agent agent) {
JsonNode jsonObj = JsonConverter.toJsonNode(agent);
JsonNode jsonObj = StateJsonConverter.toJsonNode(agent);
Optional<Map.Entry<Integer, VPredicate<JsonNode>>> firstEntry = colorEvalFunctions.entrySet().stream().filter(
entry -> {
try {
......
package org.vadere.gui.projectview.utils;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@Deprecated
public abstract class JsonFieldValidator {
private static Map<Class, Set<String>> fieldNamesMap = new HashMap<>();
public static void validateFields(Class cls, String jsonString) throws JsonParseException {
JsonObject jsonObj = new JsonParser().parse(jsonString).getAsJsonObject();
Set<String> classFieldNames = getFieldNames(cls);
for (Map.Entry<String, JsonElement> entry : jsonObj.entrySet())
if (!classFieldNames.contains(entry.getKey()))
throw new JsonParseException("The field \"" + entry.getKey() + "\" is unknown");
}
public static Set<String> getFieldNames(Class cls) {
if (fieldNamesMap.containsKey(cls))
return fieldNamesMap.get(cls);
Set<String> fieldNames = new HashSet<>();
for (Field field : cls.getDeclaredFields())
fieldNames.add(field.getName());
fieldNamesMap.put(cls, fieldNames);
return fieldNames;
}
public static void clear() {
fieldNamesMap.clear();
}
}
......@@ -11,8 +11,8 @@ import org.vadere.gui.topographycreator.view.TopographyWindow;
import org.vadere.simulator.projects.ProjectFinishedListener;
import org.vadere.simulator.projects.ScenarioRunManager;
import org.vadere.simulator.projects.VadereProject;
import org.vadere.simulator.projects.io.JsonConverter;
import org.vadere.state.scenario.Topography;
import org.vadere.state.util.StateJsonConverter;
import org.vadere.util.io.IOUtils;
import java.awt.*;
......@@ -119,7 +119,7 @@ public class ScenarioJPanel extends JPanel implements IProjectChangeListener, Pr
Messages.getString("Tab.Model.confirmLoadTemplate.title"),
JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
try {
attributesModelView.setText(JsonConverter.serializeModelPreset(modelDefinition));
attributesModelView.setText(StateJsonConverter.serializeModelPreset(modelDefinition));
} catch (Exception e1) {
e1.printStackTrace();
}
......@@ -136,7 +136,7 @@ public class ScenarioJPanel extends JPanel implements IProjectChangeListener, Pr
@Override
public void actionPerformed(ActionEvent e) {
try {
attributesModelView.setText(JsonConverter.addAttributesModel(attributesClassName,
attributesModelView.setText(StateJsonConverter.addAttributesModel(attributesClassName,
attributesModelView.getText()));
} catch (IOException e1) {
e1.printStackTrace();
......
package org.vadere.gui.projectview.view;
import com.fasterxml.jackson.core.JsonProcessingException;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.InputStream;
import java.util.prefs.Preferences;
import javax.swing.AbstractButton;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
......@@ -14,20 +32,10 @@ import org.vadere.simulator.projects.dataprocessing.DataProcessingJsonManager;
import org.vadere.simulator.projects.io.JsonConverter;
import org.vadere.state.attributes.ModelDefinition;
import org.vadere.state.scenario.Topography;
import org.vadere.state.util.StateJsonConverter;
import org.vadere.util.io.IOUtils;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.InputStream;
import java.util.prefs.Preferences;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import com.fasterxml.jackson.core.JsonProcessingException;
/**
* Shows text like the JSON formatted attributes.
......@@ -174,13 +182,13 @@ public class TextView extends JPanel {
currentScenario.setAttributesModel(modelDefinition.getAttributesList());
break;
case SIMULATION:
currentScenario.setAttributesSimulation(JsonConverter.deserializeAttributesSimulation(json));
currentScenario.setAttributesSimulation(StateJsonConverter.deserializeAttributesSimulation(json));
break;
case OUTPUTPROCESSOR:
currentScenario.setDataProcessingJsonManager(DataProcessingJsonManager.deserialize(json));
break;
case TOPOGRAPHY:
currentScenario.setTopography(JsonConverter.deserializeTopography(json));
currentScenario.setTopography(StateJsonConverter.deserializeTopography(json));
break;
}
currentScenario.updateCurrentStateSerialized();
......@@ -212,12 +220,12 @@ public class TextView extends JPanel {
switch (attributeType) {
case MODEL:
this.txtrTextfiletextarea.setText(JsonConverter.serializeMainModelAttributesModelBundle(
this.txtrTextfiletextarea.setText(StateJsonConverter.serializeMainModelAttributesModelBundle(
scenario.getSortedAttributesMode(), scenario.getScenarioStore().mainModel));
break;
case SIMULATION:
this.txtrTextfiletextarea
.setText(JsonConverter.serializeAttributesSimulation(scenario.getAttributesSimulation()));
.setText(StateJsonConverter.serializeAttributesSimulation(scenario.getAttributesSimulation()));
break;
case OUTPUTPROCESSOR:
this.txtrTextfiletextarea.setText(scenario.getDataProcessingJsonManager().serialize());
......@@ -226,7 +234,7 @@ public class TextView extends JPanel {
case TOPOGRAPHY:
Topography topography = scenario.getTopography().clone();
topography.removeBoundary();
this.txtrTextfiletextarea.setText(JsonConverter.serializeTopography(topography));
this.txtrTextfiletextarea.setText(StateJsonConverter.serializeTopography(topography));
break;
}
this.txtrTextfiletextarea.setCaretPosition(0);
......
......@@ -10,9 +10,7 @@ import javax.swing.undo.UndoableEditSupport;
import org.vadere.gui.topographycreator.model.AgentWrapper;
import org.vadere.gui.topographycreator.model.IDrawPanelModel;
import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.AttributesBuilder;
import org.vadere.state.scenario.ScenarioElement;
import org.vadere.state.scenario.ScenarioElementBuilder;
import org.vadere.util.geometry.shapes.VCircle;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VShape;
......@@ -35,45 +33,42 @@ public class ActionInsertCopiedElement extends TopographyAction {
@Override
public void actionPerformed(ActionEvent e) {
IDrawPanelModel model = getScenarioPanelModel();
ScenarioElement element = model.getCopiedElement();
ScenarioElement elementToCopy = model.getCopiedElement();
if (element != null) {
// 1. reposition the copy
VPoint elementPos;
if (elementToCopy == null) {
Toolkit.getDefaultToolkit().beep();
return;
}
Rectangle2D rect = element.getShape().getBounds2D();
// 1. reposition the copy
ScenarioElement newElement = elementToCopy.clone();
VPoint elementPos = getElementPosition(elementToCopy);
if (element.getShape() instanceof VCircle) {
elementPos = new VPoint(rect.getCenterX(), rect.getCenterY());
} else {
elementPos = new VPoint(rect.getX(), rect.getY());
}
VPoint diff = model.getMousePosition().subtract(elementPos);
VShape newShape = model.translate(diff);
VPoint diff = model.getMousePosition().subtract(elementPos);
VShape newShape = model.translate(diff);
ScenarioElement newElement = null;
if (elementToCopy instanceof AgentWrapper) {
VPoint position = new VPoint(newShape.getBounds2D().getCenterX(), newShape.getBounds2D().getCenterY());
((AgentWrapper) newElement).getAgentInitialStore().setPosition(position);
} else {
newElement.setShape(newShape);
}
if (element instanceof AgentWrapper) {
VPoint position = new VPoint(newShape.getBounds2D().getCenterX(), newShape.getBounds2D().getCenterY());
newElement = element.clone();
((AgentWrapper) newElement).getAgentInitialStore().setPosition(position);
} else {
// change attributes with reflection!
ScenarioElementBuilder<ScenarioElement> elBuilder = new ScenarioElementBuilder<>(element);
AttributesBuilder<Attributes> attBuilder = new AttributesBuilder<Attributes>(element.getAttributes());
attBuilder.setField("shape", newShape);
elBuilder.setAttributes(attBuilder.build());
newElement = elBuilder.build();
}
// 2. add the copy
UndoableEdit edit = new EditDrawShape(model, newElement.getType());
undoSupport.postEdit(edit);
model.addShape(newElement);
// getScenarioPanelModel().setSelectedElement(element);
model.notifyObservers();
}
// 2. add the copy
UndoableEdit edit = new EditDrawShape(model, newElement.getType());
undoSupport.postEdit(edit);
model.addShape(newElement);
// getScenarioPanelModel().setSelectedElement(element);
model.notifyObservers();
private VPoint getElementPosition(ScenarioElement elementToCopy) {
final Rectangle2D rect = elementToCopy.getShape().getBounds2D();
if (elementToCopy.getShape() instanceof VCircle) {
return new VPoint(rect.getCenterX(), rect.getCenterY());
} else {
Toolkit.getDefaultToolkit().beep();
return new VPoint(rect.getX(), rect.getY());
}
}
}
......@@ -4,8 +4,8 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import org.vadere.simulator.projects.io.JsonConverter;
import org.vadere.state.scenario.Topography;
import org.vadere.state.util.StateJsonConverter;
import com.fasterxml.jackson.core.JsonProcessingException;
......@@ -25,7 +25,7 @@ public class TopographyJsonWriter {
}
public static void writeTopography(Topography topography, PrintStream stream) throws JsonProcessingException {
stream.print(JsonConverter.serializeTopography(topography));
stream.print(StateJsonConverter.serializeTopography(topography));
stream.flush();
}
}
package org.vadere.gui.vadere;
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.LinkedList;
import java.util.stream.Collectors;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import org.junit.BeforeClass;
import org.junit.Test;
import org.vadere.simulator.models.osm.OptimalStepsModel;
import org.vadere.simulator.projects.ProjectWriter;
import org.vadere.simulator.projects.ScenarioRunManager;
import org.vadere.simulator.projects.ScenarioStore;
import org.vadere.simulator.projects.VadereProject;
import org.vadere.simulator.projects.ProjectWriter;
import org.vadere.simulator.projects.io.IOVadere;
import org.vadere.simulator.projects.io.JsonConverter;
import org.vadere.state.attributes.Attributes;
......@@ -18,16 +29,6 @@ import org.vadere.state.attributes.models.AttributesPotentialOSM;
import org.vadere.state.scenario.Topography;
import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.LinkedList;
import java.util.stream.Collectors;
import static org.junit.Assert.assertEquals;
public class TestProjectWriterAndReader {
private static VadereProject testProject;
......
......@@ -28,11 +28,12 @@ public class TestVadereTestProject {
@Test
public void testToJSON() throws IOException {
// TODO implement json test
/*
* String json = IOUtils.toPrettyPrintJson(IOVadere.toJson(testProject));
* // System.out.println(json);
*
* Map<String, Object> store = new Gson().fromJson(json, Map.class);
* Map<String, Object> store = fromJson(json, Map.class);
*
* assertEquals(testProject.getName(), store.get("name"));
*
......@@ -48,6 +49,7 @@ public class TestVadereTestProject {
@Test
public void testFromJSON() throws IOException {
// TODO implement json test
/*
* String json = IOUtils.toPrettyPrintJson(IOVadere.toJson(testProject));
* VadereProject testInstanceNew = IOVadere.projectFromJson(json);
......
package org.vadere.simulator.entrypoints;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.vadere.simulator.projects.ScenarioRunManager;
import org.vadere.simulator.projects.ScenarioStore;
import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.AttributesBuilder;
import org.vadere.state.attributes.AttributesSimulation;
import org.vadere.state.scenario.ScenarioElement;
import org.vadere.state.scenario.ScenarioElementBuilder;
import org.vadere.state.scenario.Teleporter;
import org.vadere.state.scenario.Topography;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
/**
* {@link VadereBuilder} provide methods to manipulate the attributes/parameters of a scenario.
* It's an interface for generate multiple Vadere-Scenario based on the same infrastructure but
* with different attributes/parameters. The class does not provide methods to change the
* infrastructure of the {@link Topography}. To use this effectively the user need a
* good knowledge about the parameters of the given scenario!
*
*
*/
public class VadereBuilder {
private static Logger logger = LogManager.getLogger(VadereBuilder.class);
private ScenarioRunManager scenario;
private ScenarioStore store;
public VadereBuilder(final ScenarioRunManager base) {
scenario = base.clone();
store = scenario.getScenarioStore();
}
public ScenarioRunManager build() {
store.topography = scenario.getTopography();
return scenario;
}
/**
* Changes the name of the output-files that will be generated during and after the simulation.
* To prevent yourself from overriding files it's necessary to set a new output name for every
* generated scenario!
*
* @param name the name of the output file
*/
public void setName(final String name) {
scenario.setName(name);
}
// change attributes
public <T> void setSimulationField(final String fieldName, final T value) {
AttributesBuilder<AttributesSimulation> simAttsBuilder = new AttributesBuilder<>(store.attributesSimulation);
simAttsBuilder.setField(fieldName, value);
store.attributesSimulation = simAttsBuilder.build();
}
public <T> void setPedestrianField(final String fieldName, final T value) {
/*
* AttributesBuilder<AttributesPedestrian> simAttsBuilder = new
* AttributesBuilder<>(store.attributesPedestrian);
* simAttsBuilder.setField(fieldName, value);
* store.attributesPedestrian = simAttsBuilder.build();
*/
}
public <T> void setModel(final List<Attributes> model) {
store.attributesList = model;
}
// change topography
/**
* Assign the {@link value} to the field identified by {@link fieldName} of the first source,
* identified by {@link sourceId}.
* If no source was found, nothing will happen.
*
* @param fieldName name of the field (e.g. spawnNumber)
* @param sourceId id of the source
* @param value value that will be assigned
*/
public <T> void setSourceField(final String fieldName, final int sourceId, final T value) {
setField(scenario.getTopography().getSources(), sourceId, fieldName, value);
}
/**
* Assign the {@link value} to the field identified by {@link fieldName} of the first target,
* identified by {@link sourceId}.
* If no source was found, nothing will happen.
*
* @param fieldName name of the field (e.g. spawnNumber)
* @param targetId id of the target
* @param value value that will be assigned
*/
public <T> void setTargetField(final String fieldName, final int targetId, final T value) {
setField(scenario.getTopography().getTargets(), targetId, fieldName, value);
}
/**
* Assign the {@link value} to the field identified by {@link fieldName}.
*
* @param fieldName field identifier
* @param value the assigned value
*/
public <T> void setTeleporterField(final String fieldName, final T value) {
Teleporter teleporter = scenario.getTopography().getTeleporter();
teleporter = setField(fieldName, teleporter, value);
scenario.getTopography().setTeleporter(teleporter);
}
/**