Commit 0ac1d206 authored by Benedikt Zoennchen's avatar Benedikt Zoennchen

issue #148 completed, and fix the incorrect drawing of the VADERE logo.

parent 0122c59c
......@@ -290,6 +290,7 @@ TopographyCreator.btnRedo.tooltip=Redo
TopographyCreator.btnCutTopography.tooltip=Cut Scenario
TopographyCreator.btnInsertPedestrian.tooltip=Pedestrian
TopographyCreator.btnTopographyBound.tooltip=Topography Bound
TopographyCreator.btnTranslation.tooltip=Translate topography
TopographyCreator.btnInsertObstacle.tooltip=Obstacle
TopographyCreator.btnInsertTarget.tooltip=Target
TopographyCreator.btnInsertSource.tooltip=Source
......
......@@ -285,6 +285,7 @@ TopographyCreator.btnInsertPedestrian.tooltip=Fu\u00dfg\u00e4nger
TopographyCreator.btnInsertObstacle.tooltip=Hindernis
TopographyCreator.btnInsertTarget.tooltip=Ziel
TopographyCreator.btnTopographyBound.tooltip=Topographie Grenze
TopographyCreator.btnTranslation.tooltip=Topographie verschieben
TopographyCreator.btnInsertSource.tooltip=Quelle
TopographyCreator.btnInsertStairs.tooltip=Treppen
TopographyCreator.btnErase.tooltip=Radierer
......
......@@ -29,14 +29,25 @@ public class JViewportChangeListener implements ChangeListener {
@Override
public void stateChanged(final ChangeEvent e) {
Rectangle2D.Double topographyBound = defaultModel.getTopographyBound();
Rectangle2D.Double viewp = defaultModel.getViewportBound();
JViewport viewPort = (JViewport) e.getSource();
if (topographyBound != null) {
Rectangle rect = viewPort.getViewRect();
double x = Math.max(topographyBound.getMinX(), topographyBound.getMinX() + rect.getX() / defaultModel.getScaleFactor());
double barHeight;
if(verticalScrollBar.getHeight() > 0) {
barHeight = verticalScrollBar.getHeight();
}
else {
barHeight = rect.getHeight();
}
double y = Math.max(topographyBound.getMinY(), topographyBound.getMinY() + topographyBound.getHeight()
- ((rect.getY() + verticalScrollBar.getHeight()) / defaultModel.getScaleFactor()));
- ((rect.getY() + barHeight) / defaultModel.getScaleFactor()));
double w = rect.getWidth() / defaultModel.getScaleFactor();
double h = rect.getHeight() / defaultModel.getScaleFactor();
defaultModel.setViewportBound(new Rectangle2D.Double(x, y, w, h));
defaultModel.notifyObservers();
}
......
......@@ -35,6 +35,8 @@ public class ViewportChangeListener implements IViewportChangeListener {
boolean scaleChanges = defaultModel.setScale(scale);
if (scaleChanges || !viewport.equals(defaultModel.getViewportBound())) {
double dx = viewportBound.getMinX() - topographyBound.getMinX();
double dy = viewportBound.getMinY() - topographyBound.getMinY();
if (scaleChanges) {
defaultModel.notifyScaleListeners();
}
......@@ -44,11 +46,16 @@ public class ViewportChangeListener implements IViewportChangeListener {
viewport.getView().setPreferredSize(new Dimension(
(int) (topographyBound.getWidth() * scale),
(int) (topographyBound.getHeight() * scale)));
viewport.setViewSize(new Dimension((int) (topographyBound.getWidth() * scale),
viewport.setViewSize(new Dimension(
(int) (topographyBound.getWidth() * scale),
(int) (topographyBound.getHeight() * scale)));
viewport.setViewPosition(new Point((int) ((viewportBound.getX()) * scale),
(int) ((topographyBound.getHeight() - (viewportBound.getY() + viewportBound.getHeight()))
viewport.setViewPosition(new Point(
(int) (dx * scale),
(int) ((topographyBound.getHeight() - (dy + viewportBound.getHeight()))
* scale)));
defaultModel.notifyObservers();
}
}
......
......@@ -203,15 +203,25 @@ public abstract class DefaultRenderer {
*/
double dy = defaultModel.getTopographyBound().getHeight() - defaultModel.getViewportBound().getHeight();
// undo the viewport translation
graphics.translate(defaultModel.getViewportBound().getX(),
-Math.max((dy - defaultModel.getViewportBound().getY()), 0));
-Math.max((dy - defaultModel.getViewportBound().getY()), -defaultModel.getViewportBound().getY()));
graphics.scale(1.0 / scale, 1.0 / scale);
graphics.translate(0, +defaultModel.getTopographyBound().getHeight() * defaultModel.getScaleFactor());
graphics.scale(1.0, -1.0);
graphics.translate(0, 2.0);
graphics.scale(0.25, 0.25);
graphics.drawImage(logo, 0, 0, null);
// undo all scaling and translation
graphics.scale(1.0/0.25, 1.0/0.25);
graphics.translate(0, 1.0/2.0);
graphics.scale(1.0, -1.0);
graphics.translate(0, -defaultModel.getTopographyBound().getHeight() * defaultModel.getScaleFactor());
graphics.translate(-defaultModel.getViewportBound().getX(),
Math.max((dy - defaultModel.getViewportBound().getY()), -defaultModel.getViewportBound().getY()));
}
protected boolean hasLogo() {
......
......@@ -2,6 +2,7 @@ package org.vadere.gui.topographycreator.control;
import org.vadere.gui.topographycreator.model.IDrawPanelModel;
import org.vadere.gui.topographycreator.model.TopographyCreatorModel;
import org.vadere.gui.topographycreator.view.ActionResizeTopographyBoundDialog;
import org.vadere.util.geometry.shapes.VRectangle;
import java.awt.event.ActionEvent;
......@@ -9,6 +10,9 @@ import java.awt.event.ActionEvent;
import javax.swing.*;
import javax.swing.undo.UndoableEditSupport;
/**
* @author Benedikt Zoennchen
*/
public class ActionResizeTopographyBound extends TopographyAction {
private TopographyAction action;
......
package org.vadere.gui.topographycreator.control;
import org.jetbrains.annotations.NotNull;
import org.vadere.gui.topographycreator.model.IDrawPanelModel;
import org.vadere.gui.topographycreator.model.TopographyCreatorModel;
import org.vadere.gui.topographycreator.view.ActionResizeTopographyBoundDialog;
import org.vadere.gui.topographycreator.view.ActionTranslateTopographyDialog;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle;
import java.awt.event.ActionEvent;
import java.awt.geom.Rectangle2D;
import javax.swing.*;
import javax.swing.undo.UndoableEditSupport;
/**
* @author Benedikt Zoennchen
*/
public class ActionTranslateTopography extends TopographyAction {
private TopographyAction action;
private final UndoableEditSupport undoableEditSupport;
public ActionTranslateTopography(String name,
ImageIcon icon,
@NotNull IDrawPanelModel<?> panelModel,
@NotNull TopographyAction action,
@NotNull final UndoableEditSupport undoSupport) {
super(name, icon, panelModel);
this.action = action;
this.undoableEditSupport = undoSupport;
}
@Override
public void actionPerformed(ActionEvent e) {
action.actionPerformed(e);
TopographyCreatorModel model = (TopographyCreatorModel) getScenarioPanelModel();
Rectangle2D.Double topographyBound = model.getTopographyBound();
ActionTranslateTopographyDialog dialog = new ActionTranslateTopographyDialog(topographyBound.getMinX(), topographyBound.getMinY());
if (dialog.getValue()){
double xOld = topographyBound.getMinX();
double yOld = topographyBound.getMinY();
double x = dialog.getX();
double y = dialog.getY();
TopographyCreatorModel topographyCreatorModel = (TopographyCreatorModel) getScenarioPanelModel();
topographyCreatorModel.translateTopography(x, y);
VRectangle viewportBound = new VRectangle(model.getViewportBound()).translate(new VPoint(x - xOld, y - yOld));
topographyCreatorModel.setViewportBound(viewportBound);
undoableEditSupport.postEdit(new EditTranslateTopography(topographyCreatorModel, xOld, yOld, x, y));
}
getScenarioPanelModel().notifyObservers();
}
}
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.attributes.AttributesEmbedShape;
import org.vadere.state.scenario.ScenarioElement;
import org.vadere.util.geometry.shapes.VPoint;
......@@ -24,7 +20,7 @@ public class AttributeModifier {
* @param element the attributes
* @param shape the shape
*/
static void setShapeToAttributes(final ScenarioElement element, final VShape shape) {
public static void setShapeToAttributes(final ScenarioElement element, final VShape shape) {
try {
if (element instanceof AgentWrapper) {
double x = shape.getBounds2D().getCenterX();
......
package org.vadere.gui.topographycreator.control;
import org.jetbrains.annotations.NotNull;
import org.vadere.gui.topographycreator.model.TopographyCreatorModel;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle;
import javax.swing.undo.AbstractUndoableEdit;
import javax.swing.undo.CannotRedoException;
import javax.swing.undo.CannotUndoException;
/**
* @author Benedikt Zoennchen
*/
public class EditTranslateTopography extends AbstractUndoableEdit {
private static final long serialVersionUID = 5176192525116057658L;
private final TopographyCreatorModel panelModel;
private final double xOld;
private final double yOld;
private final double xNew;
private final double yNew;
public EditTranslateTopography(@NotNull final TopographyCreatorModel panelModel,
final double xOld,
final double yOld,
final double xNew,
final double yNew) {
this.panelModel = panelModel;
this.xOld = xOld;
this.yOld = yOld;
this.xNew = xNew;
this.yNew = yNew;
}
@Override
public void undo() throws CannotUndoException {
panelModel.translateTopography(xOld, yOld);
VRectangle viewportBound = new VRectangle(panelModel.getViewportBound()).translate(new VPoint(xOld - xNew, yOld - yNew));
panelModel.setViewportBound(viewportBound);
}
@Override
public void redo() throws CannotRedoException {
panelModel.translateTopography(xNew, yNew);
VRectangle viewportBound = new VRectangle(panelModel.getViewportBound()).translate(new VPoint(xNew - xOld, yNew - yOld));
panelModel.setViewportBound(viewportBound);
}
@Override
public boolean canUndo() {
return true;
}
@Override
public boolean canRedo() {
return true;
}
@Override
public String getPresentationName() {
return "translate topography";
}
}
......@@ -5,6 +5,7 @@ import java.lang.reflect.Field;
import java.util.Iterator;
import java.util.LinkedList;
import org.vadere.gui.topographycreator.control.AttributeModifier;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.attributes.scenario.AttributesCar;
import org.vadere.state.attributes.scenario.AttributesTopography;
......@@ -17,6 +18,7 @@ import org.vadere.state.scenario.Target;
import org.vadere.state.scenario.Teleporter;
import org.vadere.state.scenario.Topography;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VShape;
/**
* A TopographyBuilder builds a Topography-Object step by step. After the Topography-Object is build
......@@ -136,6 +138,13 @@ public class TopographyBuilder implements Iterable<ScenarioElement> {
return topography;
}
public void translateElements(final double x, final double y) {
for(ScenarioElement element : topographyElements) {
VShape shape = element.getShape().translate(new VPoint(x, y));
AttributeModifier.setShapeToAttributes(element, shape);
}
}
public ScenarioElement selectElement(final VPoint position) {
for (ScenarioElement element : topographyElements)
if (element.getShape().intersects(new Rectangle2D.Double(position.x - 0.1, position.y - 0.1, 0.2, 0.2)))
......
......@@ -319,6 +319,15 @@ public class TopographyCreatorModel extends DefaultModel implements IDrawPanelMo
return element;
}
public void translateTopography(final double x, final double y) {
double oldX = getTopographyBound().x;
double oldY = getTopographyBound().y;
topographyBuilder.translateElements(x - oldX, y - oldY);
setTopographyBound(new VRectangle(x, y, getTopographyBound().getWidth(), getTopographyBound().getHeight()));
setChanged();
}
@Override
public VShape translate(final Point vector) {
VPoint worldVector = new VPoint(vector.x / getScaleFactor(), -vector.y / getScaleFactor());
......
package org.vadere.gui.topographycreator.control;
package org.vadere.gui.topographycreator.view;
import org.vadere.gui.projectview.view.ProjectView;
import org.vadere.util.geometry.shapes.VRectangle;
import java.awt.*;
import java.awt.geom.Rectangle2D;
......
package org.vadere.gui.topographycreator.view;
import org.vadere.gui.projectview.view.ProjectView;
import java.awt.*;
import java.awt.geom.Rectangle2D;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
public class ActionTranslateTopographyDialog {
private JTextField textField;
private double x;
private double y;
private final double xOld;
private final double yOld;
private boolean valid;
public ActionTranslateTopographyDialog(final double x, double y){
this.textField = new JTextField(30);
this.textField.setText(String.format("%f, %f", x, y));
this.textField.getDocument().addDocumentListener(new DialogListener());
this.valid = false;
this.x = x;
this.y = y;
this.xOld = x;
this.yOld = y;
}
public double getX() {
return valid ? x : xOld;
}
public double getY() {
return valid ? y : yOld;
}
public boolean getValue(){
return JOptionPane.showConfirmDialog(
ProjectView.getMainWindow(),
textField,
"x, y",
JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION;
}
private class DialogListener implements DocumentListener{
private JTextField textField;
private String text;
DialogListener(){
textField = ActionTranslateTopographyDialog.this.textField;
}
@Override
public void insertUpdate(DocumentEvent e) {
handle(e);
}
@Override
public void removeUpdate(DocumentEvent e) {
handle(e);
}
@Override
public void changedUpdate(DocumentEvent e) {
handle(e);
}
private void handle(DocumentEvent e){
text = textField.getText().replaceAll("\\s+", "");
String[] tmp = text.split(",");
double x;
double y;
try {
x = Double.valueOf(tmp[0]);
y = Double.valueOf(tmp[1]);
ActionTranslateTopographyDialog.this.x = x;
ActionTranslateTopographyDialog.this.y = y;
ActionTranslateTopographyDialog.this.valid = true;
textField.setForeground(Color.BLACK);
}catch (Exception ex){
ActionTranslateTopographyDialog.this.valid = false;
textField.setForeground(Color.RED);
}
}
}
}
......@@ -31,6 +31,7 @@ import org.vadere.gui.topographycreator.control.ActionSwitchCategory;
import org.vadere.gui.topographycreator.control.ActionSwitchSelectionMode;
import org.vadere.gui.topographycreator.control.ActionTopographyCheckerMenu;
import org.vadere.gui.topographycreator.control.ActionTopographyMakroMenu;
import org.vadere.gui.topographycreator.control.ActionTranslateTopography;
import org.vadere.gui.topographycreator.control.ActionUndo;
import org.vadere.gui.topographycreator.control.ActionZoomIn;
import org.vadere.gui.topographycreator.control.ActionZoomOut;
......@@ -302,9 +303,9 @@ public class TopographyWindow extends JPanel {
new ImageIcon(Resources.class.getResource("/icons/topography_icon.png")),
panelModel, selectShape, undoSupport);
/*TopographyAction translateTopographyBound =new ActionResizeTopographyBound("SetTopograpyBound",
new ImageIcon(Resources.class.getResource("/icons/topography_icon.png")),
panelModel, selectShape, undoSupport);*/
TopographyAction translateTopography =new ActionTranslateTopography("SetTopograpyBound",
new ImageIcon(Resources.class.getResource("/icons/translation_icon.png")),
panelModel, selectShape, undoSupport);
/* Makros */
ActionTopographyMakroMenu actionTopographyMakroMenu =
......@@ -345,6 +346,7 @@ public class TopographyWindow extends JPanel {
// "TopographyCreator.btnMinimizeTopography.tooltip");
addActionToToolbar(toolbar, maximizeAction, "TopographyCreator.btnMaximizeTopography.tooltip");
addActionToToolbar(toolbar, resizeTopographyBound, "TopographyCreator.btnTopographyBound.tooltip");
addActionToToolbar(toolbar, translateTopography, "TopographyCreator.btnTranslation.tooltip");
toolbar.addSeparator(new Dimension(5, 50));
addActionToToolbar(toolbar, selectCutAction, "TopographyCreator.btnCutTopography.tooltip");
addActionToToolbar(toolbar, resetScenarioAction, "TopographyCreator.btnNewTopography.tooltip");
......
......@@ -99,7 +99,7 @@ public class VRectangle extends Rectangle2D.Double implements VShape {
}
@Override
public VShape translate(final VPoint vector) {
public VRectangle translate(final VPoint vector) {
return new VRectangle(getX() + vector.x, getY() + vector.y, getWidth(), getHeight());
}
......
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