Search in sources :

Example 1 with DataSet

use of org.openstreetmap.josm.data.osm.DataSet in project josm by JOSM.

the class AddNodeAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (!isEnabled())
        return;
    // #17682 - Run the action later in EDT to make sure the KeyEvent triggering it is consumed before the dialog is shown
    SwingUtilities.invokeLater(() -> {
        LatLonDialog dialog = new LatLonDialog(MainApplication.getMainFrame(), tr("Add Node..."), ht("/Action/AddNode"));
        if (textLatLon != null) {
            dialog.setLatLonText(textLatLon);
        }
        if (textEastNorth != null) {
            dialog.setEastNorthText(textEastNorth);
        }
        dialog.showDialog();
        if (dialog.getValue() != 1)
            return;
        LatLon coordinates = dialog.getCoordinates();
        if (coordinates == null)
            return;
        textLatLon = dialog.getLatLonText();
        textEastNorth = dialog.getEastNorthText();
        Node nnew = new Node(coordinates);
        // add the node
        DataSet ds = getLayerManager().getEditDataSet();
        UndoRedoHandler.getInstance().add(new AddCommand(ds, nnew));
        ds.setSelected(nnew);
        MapView mapView = MainApplication.getMap().mapView;
        if (mapView != null && !mapView.getRealBounds().contains(nnew.getCoor())) {
            AutoScaleAction.zoomTo(Collections.<OsmPrimitive>singleton(nnew));
        }
    });
}
Also used : LatLon(org.openstreetmap.josm.data.coor.LatLon) DataSet(org.openstreetmap.josm.data.osm.DataSet) Node(org.openstreetmap.josm.data.osm.Node) MapView(org.openstreetmap.josm.gui.MapView) LatLonDialog(org.openstreetmap.josm.gui.dialogs.LatLonDialog) AddCommand(org.openstreetmap.josm.command.AddCommand)

Example 2 with DataSet

use of org.openstreetmap.josm.data.osm.DataSet in project josm by JOSM.

the class CombineWayAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent event) {
    final DataSet ds = getLayerManager().getEditDataSet();
    if (ds == null)
        return;
    Collection<Way> selectedWays = new LinkedHashSet<>(ds.getSelectedWays());
    selectedWays.removeIf(Way::isEmpty);
    if (selectedWays.size() < 2) {
        new Notification(tr("Please select at least two ways to combine.")).setIcon(JOptionPane.INFORMATION_MESSAGE).setDuration(Notification.TIME_SHORT).show();
        return;
    }
    // see #18083: check if we will combine ways at nodes outside of the download area
    Set<Node> endNodesOutside = new HashSet<>();
    for (Way w : selectedWays) {
        final Node[] endnodes = { w.firstNode(), w.lastNode() };
        for (Node n : endnodes) {
            if (!n.isNew() && n.isOutsideDownloadArea() && !endNodesOutside.add(n)) {
                new Notification(tr("Combine ways refused<br>" + "(A shared node is outside of the download area)")).setIcon(JOptionPane.INFORMATION_MESSAGE).show();
                return;
            }
        }
    }
    // combine and update gui
    Pair<Way, Command> combineResult;
    try {
        combineResult = combineWaysWorker(selectedWays);
    } catch (UserCancelException ex) {
        Logging.trace(ex);
        return;
    }
    if (combineResult == null)
        return;
    final Way selectedWay = combineResult.a;
    UndoRedoHandler.getInstance().add(combineResult.b);
    Test test = new OverlappingWays();
    test.startTest(null);
    test.visit(combineResult.a);
    test.endTest();
    if (test.getErrors().isEmpty()) {
        test = new SelfIntersectingWay();
        test.startTest(null);
        test.visit(combineResult.a);
        test.endTest();
    }
    if (!test.getErrors().isEmpty()) {
        new Notification(test.getErrors().get(0).getMessage()).setIcon(JOptionPane.WARNING_MESSAGE).setDuration(Notification.TIME_SHORT).show();
    }
    if (selectedWay != null) {
        GuiHelper.runInEDT(() -> ds.setSelected(selectedWay));
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) OverlappingWays(org.openstreetmap.josm.data.validation.tests.OverlappingWays) DataSet(org.openstreetmap.josm.data.osm.DataSet) Node(org.openstreetmap.josm.data.osm.Node) UserCancelException(org.openstreetmap.josm.tools.UserCancelException) Way(org.openstreetmap.josm.data.osm.Way) JoinedWay(org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon.JoinedWay) SelfIntersectingWay(org.openstreetmap.josm.data.validation.tests.SelfIntersectingWay) Notification(org.openstreetmap.josm.gui.Notification) SelfIntersectingWay(org.openstreetmap.josm.data.validation.tests.SelfIntersectingWay) DeleteCommand(org.openstreetmap.josm.command.DeleteCommand) Command(org.openstreetmap.josm.command.Command) SequenceCommand(org.openstreetmap.josm.command.SequenceCommand) ChangeNodesCommand(org.openstreetmap.josm.command.ChangeNodesCommand) Test(org.openstreetmap.josm.data.validation.Test) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 3 with DataSet

use of org.openstreetmap.josm.data.osm.DataSet in project josm by JOSM.

the class CopyAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    DataSet set = getLayerManager().getActiveDataSet();
    Collection<OsmPrimitive> selection = set == null ? Collections.<OsmPrimitive>emptySet() : set.getSelected();
    if (selection.isEmpty()) {
        showEmptySelectionWarning();
        return;
    }
    copy(getLayerManager().getActiveDataLayer(), selection);
}
Also used : DataSet(org.openstreetmap.josm.data.osm.DataSet) OsmPrimitive(org.openstreetmap.josm.data.osm.OsmPrimitive)

Example 4 with DataSet

use of org.openstreetmap.josm.data.osm.DataSet in project josm by JOSM.

the class ConflictResolveCommand method undoCommand.

@Override
public void undoCommand() {
    super.undoCommand();
    DataSet ds = getAffectedDataSet();
    if (!OsmDataManager.getInstance().containsDataSet(ds)) {
        Logging.warn(tr("Cannot undo command ''{0}'' because layer ''{1}'' is not present any more", this.toString(), ds.getName()));
        return;
    }
    OsmDataManager.getInstance().setActiveDataSet(ds);
    reconstituteConflicts();
}
Also used : DataSet(org.openstreetmap.josm.data.osm.DataSet)

Example 5 with DataSet

use of org.openstreetmap.josm.data.osm.DataSet in project josm by JOSM.

the class UndoRedoHandler method undo.

/**
 * Undoes multiple commands.
 * @param num The number of commands to undo
 */
public synchronized void undo(int num) {
    if (commands.isEmpty())
        return;
    GuiHelper.runInEDTAndWait(() -> {
        DataSet ds = OsmDataManager.getInstance().getEditDataSet();
        if (ds != null) {
            ds.beginUpdate();
        }
        try {
            for (int i = 1; i <= num; ++i) {
                final Command c = commands.removeLast();
                try {
                    c.undoCommand();
                } catch (Exception e) {
                    // NOPMD
                    // fix #20098: restore command stack as we will not fire an event
                    commands.add(c);
                    throw e;
                }
                redoCommands.addFirst(c);
                fireEvent(new CommandUndoneEvent(this, c));
                if (commands.isEmpty()) {
                    break;
                }
            }
        } finally {
            if (ds != null) {
                ds.endUpdate();
            }
        }
        fireCommandsChanged();
    });
}
Also used : DataSet(org.openstreetmap.josm.data.osm.DataSet) Command(org.openstreetmap.josm.command.Command)

Aggregations

DataSet (org.openstreetmap.josm.data.osm.DataSet)989 Test (org.junit.jupiter.api.Test)638 Node (org.openstreetmap.josm.data.osm.Node)436 Way (org.openstreetmap.josm.data.osm.Way)321 OsmDataLayer (org.openstreetmap.josm.gui.layer.OsmDataLayer)290 OsmPrimitive (org.openstreetmap.josm.data.osm.OsmPrimitive)213 LatLon (org.openstreetmap.josm.data.coor.LatLon)190 Relation (org.openstreetmap.josm.data.osm.Relation)166 ArrayList (java.util.ArrayList)124 InputStream (java.io.InputStream)84 Command (org.openstreetmap.josm.command.Command)80 Bounds (org.openstreetmap.josm.data.Bounds)80 List (java.util.List)78 SequenceCommand (org.openstreetmap.josm.command.SequenceCommand)75 RelationMember (org.openstreetmap.josm.data.osm.RelationMember)75 Collection (java.util.Collection)70 EastNorth (org.openstreetmap.josm.data.coor.EastNorth)70 Collectors (java.util.stream.Collectors)66 Collections (java.util.Collections)61 HashSet (java.util.HashSet)60