<commit_before>package com.net2plan.gui.utils.topologyPane.mapControl.osm.state;

import com.net2plan.gui.utils.INetworkCallback;
import com.net2plan.gui.utils.topologyPane.TopologyPanel;
import com.net2plan.gui.utils.topologyPane.mapControl.osm.OSMMapController;
import com.net2plan.interfaces.networkDesign.NetPlan;
import com.net2plan.interfaces.networkDesign.Node;
import com.net2plan.internal.plugins.ITopologyCanvas;
import org.jxmapviewer.viewer.GeoPosition;

import java.awt.geom.Point2D;

/**
 * @author <NAME>
 * @date 01-Dec-16
 */
public class OSMRunningState extends OSMState
{
    @Override
    public void panTo(Point2D initialPoint, Point2D currentPoint)
    {
        final double dxPanelPixelCoord = (currentPoint.getX() - initialPoint.getX());
        final double dyPanelPixelCoord = (currentPoint.getY() - initialPoint.getY());

        OSMMapController.moveMap(-dxPanelPixelCoord, -dyPanelPixelCoord);
    }

    @Override
    public void zoomIn()
    {
        OSMMapController.zoomIn();
    }

    @Override
    public void zoomOut()
    {
        OSMMapController.zoomOut();
    }

    @Override
    public void zoomAll()
    {
        OSMMapController.restoreMap();
    }

    @Override
    public void addNode(TopologyPanel topologyPanel, NetPlan netPlan, String name, Point2D pos)
    {
        // Changing the original state zoom seems to break the point to geoposition conversion. For the time being, it is necessary to add the new nodes at the original state.
        OSMMapController.restoreMap();

        final GeoPosition geoPosition = OSMMapController.convertPointToGeo(new Point2D.Double(pos.getX(), -pos.getY()));
        final Node node = netPlan.addNode(geoPosition.getLongitude(), geoPosition.getLatitude(), name, null);

        topologyPanel.getCanvas().addNode(node);
        topologyPanel.getCanvas().refresh();

        OSMMapController.restoreMap();
    }

    @Override
    public void moveNode(INetworkCallback callback, ITopologyCanvas canvas, Node node, Point2D pos)
    {
//        final Point2D jungPoint = canvas.convertViewCoordinatesToRealCoordinates(pos);
//        final GeoPosition geoPosition = OSMMapController.convertPointToGeo(new Point2D.Double(pos.getX(), -pos.getY()));
//
//        callback.moveNode(node.getId(), new Point2D.Double(geoPosition.getLongitude(), geoPosition.getLatitude()));
//        canvas.moveNodeToXYPosition(node, new Point2D.Double(jungPoint.getX(), -jungPoint.getY()));
    }
}<commit_msg>Added node translation, zooming the map breaks it apart<commit_after>package com.net2plan.gui.utils.topologyPane.mapControl.osm.state;

import com.net2plan.gui.utils.INetworkCallback;
import com.net2plan.gui.utils.topologyPane.TopologyPanel;
import com.net2plan.gui.utils.topologyPane.mapControl.osm.OSMMapController;
import com.net2plan.interfaces.networkDesign.NetPlan;
import com.net2plan.interfaces.networkDesign.Node;
import com.net2plan.internal.plugins.ITopologyCanvas;
import org.jxmapviewer.viewer.GeoPosition;

import java.awt.geom.Point2D;

/**
 * @author <NAME>
 * @date 01-Dec-16
 */
public class OSMRunningState extends OSMState
{
    @Override
    public void panTo(Point2D initialPoint, Point2D currentPoint)
    {
        final double dxPanelPixelCoord = (currentPoint.getX() - initialPoint.getX());
        final double dyPanelPixelCoord = (currentPoint.getY() - initialPoint.getY());

        OSMMapController.moveMap(-dxPanelPixelCoord, -dyPanelPixelCoord);
    }

    @Override
    public void zoomIn()
    {
        OSMMapController.zoomIn();
    }

    @Override
    public void zoomOut()
    {
        OSMMapController.zoomOut();
    }

    @Override
    public void zoomAll()
    {
        OSMMapController.restoreMap();
    }

    @Override
    public void addNode(TopologyPanel topologyPanel, NetPlan netPlan, String name, Point2D pos)
    {
        // Changing the original state zoom seems to break the point to geoposition conversion. For the time being, it is necessary to add the new nodes at the original state.
        OSMMapController.restoreMap();

        final GeoPosition geoPosition = OSMMapController.convertPointToGeo(new Point2D.Double(pos.getX(), -pos.getY()));
        final Node node = netPlan.addNode(geoPosition.getLongitude(), geoPosition.getLatitude(), name, null);

        topologyPanel.getCanvas().addNode(node);
        topologyPanel.getCanvas().refresh();

        OSMMapController.restoreMap();
    }

    @Override
    public void moveNode(INetworkCallback callback, ITopologyCanvas canvas, Node node, Point2D pos)
    {
        final Point2D jungPoint = canvas.convertViewCoordinatesToRealCoordinates(pos);
        final GeoPosition geoPosition = OSMMapController.convertPointToGeo(new Point2D.Double(jungPoint.getX(), -jungPoint.getY()));

        callback.moveNode(node.getId(), new Point2D.Double(geoPosition.getLongitude(), geoPosition.getLatitude()));
        canvas.moveNodeToXYPosition(node, new Point2D.Double(jungPoint.getX(), -jungPoint.getY()));
    }
}
{'fraction_non_alphanumeric': 0.1054, 'fraction_numerical': 0.0084, 'mean_word_length': 3.794822627037392, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6207449', 'n_tokens_mistral': 1540, 'n_tokens_neox': 1497, 'n_words': 302}