Ignore:
Timestamp:
2015-06-06T18:54:58+02:00 (9 years ago)
Author:
akks
Message:

[josm_fastdraw] Fix settings saving, allow edit existing ways (Q)

Location:
applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/FDSettings.java

    r29457 r31224  
    3535    // option for simplifiction: 0="Autosimplify and wait",
    3636    //1="Simplify and wait", 2="Save as is"
     37
     38    public boolean allowEditExistingWays;
    3739
    3840    public boolean drawClosed;
     
    7375        drawClosed =  Main.pref.getBoolean("fastdraw.drawclosed", false);
    7476        simplifyMode = Main.pref.getInteger("fastdraw.simplifymode", 0);
     77        allowEditExistingWays = Main.pref.getBoolean("fastdraw.alloweditexisting", false);
     78
    7579        autoTags = Main.pref.get("fastdraw.autotags");
    7680    }
     
    9195         Main.pref.putInteger("fastdraw.simplifymode", simplifyMode);
    9296         Main.pref.put("fastdraw.autotags", autoTags);
     97         Main.pref.put("fastdraw.alloweditexisting", allowEditExistingWays);
    9398         try {Main.pref.save();} catch (IOException e) {
    9499             System.err.println(tr("Can not save preferences"));
  • applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/FastDrawConfigDialog.java

    r30710 r31224  
    4141    private final JCheckBox fixedClickCb = new JCheckBox(tr("Add fixed points on click"));
    4242    private final JCheckBox fixedSpaceCb = new JCheckBox(tr("Add fixed points on spacebar"));
     43    private final JCheckBox allowEditExistingWaysCb = new JCheckBox(tr("Allow edit existing ways"));
    4344    private final JCheckBox drawClosedCb = new JCheckBox(tr("Draw closed polygons only"));
    4445    private final HistoryComboBox addTags = new HistoryComboBox();
     
    8788        all.add(drawClosedCb,GBC.eop().insets(20,0,0,0));
    8889       
     90        all.add(allowEditExistingWaysCb,GBC.eop().insets(20,0,0,0));
     91       
    8992        addTags.setText(settings.autoTags);
    9093        text1.setValue(settings.epsilonMult);
     
    9598        fixedSpaceCb.setSelected(settings.fixedSpacebar);
    9699        drawClosedCb.setSelected(settings.drawClosed);
     100        allowEditExistingWaysCb.setSelected(settings.allowEditExistingWays);
    97101        combo1.setSelectedIndex(settings.simplifyMode);
    98102       
     
    110114    public ExtendedDialog showDialog() {
    111115        ExtendedDialog result = super.showDialog();
    112         if (getValue() == 0) {
     116        if (getValue() == 1) {
    113117            try {
    114118                settings.epsilonMult=NumberFormat.getInstance().parse(text1.getText()).doubleValue();
     
    118122                settings.fixedClick=fixedClickCb.isSelected();
    119123                settings.fixedSpacebar=fixedSpaceCb.isSelected();
     124                settings.allowEditExistingWays=allowEditExistingWaysCb.isSelected();
    120125                settings.drawClosed=drawClosedCb.isSelected();
    121126                settings.simplifyMode=combo1.getSelectedIndex();
  • applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/FastDrawingMode.java

    r30710 r31224  
    1515import java.util.ArrayList;
    1616import java.util.Collection;
     17import java.util.Collections;
    1718import java.util.HashSet;
    1819import java.util.Iterator;
     
    2728import org.openstreetmap.josm.actions.mapmode.MapMode;
    2829import org.openstreetmap.josm.command.AddCommand;
     30import org.openstreetmap.josm.command.ChangeCommand;
    2931import org.openstreetmap.josm.command.Command;
    3032import org.openstreetmap.josm.command.DeleteCommand;
     
    7375    private int nearestPointIndex;
    7476    private int dragNode=-1;
    75     private SequenceCommand delCmd;
    7677    private List<Node> oldNodes;
    7778   
    7879    private boolean lineWasSaved;
    7980    private boolean deltaChanged;
     81    private Way oldWay;
    8082   
    8183    FastDrawingMode(MapFrame mapFrame) {
     
    511513// <editor-fold defaultstate="collapsed" desc="Different action helper methods">
    512514    public void newDrawing() {
    513         if (delCmd!=null) delCmd.undoCommand();
    514         delCmd=null; oldNodes=null;
     515        oldWay=null; oldNodes=null;
    515516        eps=settings.startingEps;
    516517        line.clear();
     
    526527        Collection<Command> cmds = new LinkedList<>();
    527528        int i = 0;
    528         Way w = new Way();
     529       
     530        Way w;
     531        if (oldWay==null) {
     532            w = new Way();
     533        } else {
     534            w = new Way(oldWay);
     535            w.setNodes(new ArrayList<Node>()); // nodes will be created frosm scratch
     536        }
     537       
    529538        LatLon first=pts.get(0);
    530539        Node firstNode=null;
     
    570579            }
    571580        }
    572         if (delCmd!=null) {
     581        if (oldWay!=null) {
    573582            List<Node> nodes = w.getNodes();
     583            cmds.add(new ChangeCommand(oldWay, w));
    574584            for (Node nd: oldNodes) {
    575585                // node from old way but not in new way
     
    577587                    List<OsmPrimitive> refs = nd.getReferrers();
    578588                    // does someone need this node? if no-delete it.
    579                     if (refs.isEmpty() && !nd.isDeleted() && nd.isUsable()) cmds.add(new DeleteCommand(nd));                                       
     589                    if (refs.size()==1 && !nd.isDeleted() && nd.isUsable() && !nd.isTagged()) cmds.add(new DeleteCommand(nd));
    580590                }
    581591            }
    582             delCmd = null; // that is all with this command
    583             cmds.add(new AddCommand(w));
     592            oldWay = null; // that is all with this command
    584593        } else cmds.add(new AddCommand(w));
    585594        Command c = new SequenceCommand(tr("Draw the way by mouse"), cmds);
     
    638647
    639648    private void loadFromWay(Way w) {
    640         Collection<Command> cmds = new LinkedList<>();
    641649       
    642650        Object[] nodes = w.getNodes().toArray();
     
    645653        for (int i=0;i<n;i++) {
    646654            Node nd=(Node) nodes[i];
    647             line.addLast(nd.getCoor());
     655            List<OsmPrimitive> refs = nd.getReferrers();
     656            if (refs.size()>1 || nd.isTagged()) {
     657                line.addFixed(nd.getCoor());
     658            } else {
     659                line.addLast(nd.getCoor());
     660            }
    648661        }
    649662        if (w.isClosed()) line.closeLine();
    650663        oldNodes = w.getNodes();
    651         List <OsmPrimitive> wl = new ArrayList<>(); wl.add(w);
    652        
    653         Command c = DeleteCommand.delete(getEditLayer(), wl, false);
    654         if (c != null) cmds.add(c);
    655         delCmd = new SequenceCommand(tr("Convert way to FastDraw line"), cmds);
    656         Main.main.undoRedo.add(delCmd);
     664        oldWay = w;
    657665    }
    658666
     
    690698            Way w = selectedWays.iterator().next();
    691699           
    692             if (w.isNew()) loadFromWay(w);
     700            if (w.isNew() || settings.allowEditExistingWays) loadFromWay(w);
    693701        }
    694702    }
Note: See TracChangeset for help on using the changeset viewer.