コード例 #1
0
ファイル: SplitWayAction.java プロジェクト: ourty196270/josm
 @Override
 protected void buttonAction(int buttonIndex, ActionEvent evt) {
   super.buttonAction(buttonIndex, evt);
   if (getValue() == 1) {
     final Way wayToKeep = list.getSelectedValue();
     final SplitWayResult result =
         doSplitWay(getEditLayer(), selectedWay, wayToKeep, newWays, selection);
     Main.main.undoRedo.add(result.getCommand());
     getCurrentDataSet().setSelected(result.getNewSelection());
   }
 }
コード例 #2
0
ファイル: SplitWayAction.java プロジェクト: ourty196270/josm
  /**
   * Called when the action is executed.
   *
   * <p>This method performs an expensive check whether the selection clearly defines one of the
   * split actions outlined above, and if yes, calls the splitWay method.
   */
  @Override
  public void actionPerformed(ActionEvent e) {

    Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected();

    List<Node> selectedNodes = OsmPrimitive.getFilteredList(selection, Node.class);
    List<Way> selectedWays = OsmPrimitive.getFilteredList(selection, Way.class);
    List<Relation> selectedRelations = OsmPrimitive.getFilteredList(selection, Relation.class);
    List<Way> applicableWays = getApplicableWays(selectedWays, selectedNodes);

    if (applicableWays == null) {
      new Notification(
              tr("The current selection cannot be used for splitting - no node is selected."))
          .setIcon(JOptionPane.WARNING_MESSAGE)
          .show();
      return;
    } else if (applicableWays.isEmpty()) {
      new Notification(tr("The selected nodes do not share the same way."))
          .setIcon(JOptionPane.WARNING_MESSAGE)
          .show();
      return;
    }

    // If several ways have been found, remove ways that doesn't have selected
    // node in the middle
    if (applicableWays.size() > 1) {
      for (Iterator<Way> it = applicableWays.iterator(); it.hasNext(); ) {
        Way w = it.next();
        for (Node n : selectedNodes) {
          if (!w.isInnerNode(n)) {
            it.remove();
            break;
          }
        }
      }
    }

    if (applicableWays.isEmpty()) {
      new Notification(
              trn(
                  "The selected node is not in the middle of any way.",
                  "The selected nodes are not in the middle of any way.",
                  selectedNodes.size()))
          .setIcon(JOptionPane.WARNING_MESSAGE)
          .show();
      return;
    } else if (applicableWays.size() > 1) {
      new Notification(
              trn(
                  "There is more than one way using the node you selected. Please select the way also.",
                  "There is more than one way using the nodes you selected. Please select the way also.",
                  selectedNodes.size()))
          .setIcon(JOptionPane.WARNING_MESSAGE)
          .show();
      return;
    }

    // Finally, applicableWays contains only one perfect way
    final Way selectedWay = applicableWays.get(0);
    final List<List<Node>> wayChunks = buildSplitChunks(selectedWay, selectedNodes);
    if (wayChunks != null) {
      final List<OsmPrimitive> sel =
          new ArrayList<>(selectedWays.size() + selectedRelations.size());
      sel.addAll(selectedWays);
      sel.addAll(selectedRelations);

      final List<Way> newWays = createNewWaysFromChunks(selectedWay, wayChunks);
      final Way wayToKeep = determineWayToKeep(newWays);

      if (ExpertToggleAction.isExpert() && !selectedWay.isNew()) {
        final ExtendedDialog dialog =
            new SegmentToKeepSelectionDialog(selectedWay, newWays, wayToKeep, sel);
        dialog.setModal(false);
        dialog.showDialog();
      } else {
        final SplitWayResult result =
            doSplitWay(getEditLayer(), selectedWay, wayToKeep, newWays, sel);
        Main.main.undoRedo.add(result.getCommand());
        getCurrentDataSet().setSelected(result.getNewSelection());
      }
    }
  }