Revision: 6601
          http://sourceforge.net/p/jump-pilot/code/6601
Author:   michaudm
Date:     2020-10-24 18:31:05 +0000 (Sat, 24 Oct 2020)
Log Message:
-----------
fix #382 : deleting warping vectors was not possible with incremental mode

Modified Paths:
--------------
    core/trunk/ChangeLog
    
core/trunk/src/com/vividsolutions/jump/workbench/ui/warp/AbstractDeleteVectorTool.java
    
core/trunk/src/com/vividsolutions/jump/workbench/ui/warp/DeleteIncrementalWarpingVectorTool.java
    core/trunk/src/com/vividsolutions/jump/workbench/ui/warp/WarpingPanel.java

Modified: core/trunk/ChangeLog
===================================================================
--- core/trunk/ChangeLog        2020-10-24 10:01:09 UTC (rev 6600)
+++ core/trunk/ChangeLog        2020-10-24 18:31:05 UTC (rev 6601)
@@ -4,6 +4,9 @@
 # 3. be concise but convey the change in a way that ordinary users understand
 #<-------------------------------- 80 chars ---------------------------------->
 
+2020-10-24 mmichaud
+  * fix #382 : deleting warping vectors was not possible with incremental mode
+
 2020-10-06 ede
   * added gdal support for debian/ubuntu, installing package libgdal-java
     suffices now to have gdal image loaders up and running, tested on Ubuntu 20

Modified: 
core/trunk/src/com/vividsolutions/jump/workbench/ui/warp/AbstractDeleteVectorTool.java
===================================================================
--- 
core/trunk/src/com/vividsolutions/jump/workbench/ui/warp/AbstractDeleteVectorTool.java
      2020-10-24 10:01:09 UTC (rev 6600)
+++ 
core/trunk/src/com/vividsolutions/jump/workbench/ui/warp/AbstractDeleteVectorTool.java
      2020-10-24 18:31:05 UTC (rev 6601)
@@ -42,6 +42,7 @@
 import com.vividsolutions.jump.feature.Feature;
 import com.vividsolutions.jump.geom.EnvelopeUtil;
 import com.vividsolutions.jump.workbench.model.AbstractVectorLayerFinder;
+import com.vividsolutions.jump.workbench.model.Layer;
 import com.vividsolutions.jump.workbench.model.LayerManagerProxy;
 import com.vividsolutions.jump.workbench.model.UndoableCommand;
 import com.vividsolutions.jump.workbench.ui.cursortool.Animations;
@@ -55,7 +56,7 @@
         setViewClickBuffer(6);
     }
        
-    private void showAnimation(Collection vectorFeatures) {
+    void showAnimation(Collection vectorFeatures) {
         try {
             Animations.drawExpandingRings(
                 getPanel().getViewport().toViewPoints(centres(vectorFeatures)),
@@ -66,9 +67,9 @@
         } catch (NoninvertibleTransformException e) {
             //Eat it. [Jon Aquino]
         }
-    }        
+    }
 
-    private Collection centres(Collection vectorFeatures) {
+    Collection centres(Collection vectorFeatures) {
         ArrayList centers = new ArrayList();
         for (Iterator i = vectorFeatures.iterator(); i.hasNext();) {
             Feature vectorFeature = (Feature) i.next();
@@ -83,27 +84,35 @@
     }
     
     protected abstract AbstractVectorLayerFinder 
createVectorLayerFinder(LayerManagerProxy layerManagerProxy);
-                
+
     protected void gestureFinished() throws Exception {
         reportNothingToUndoYet();
         AbstractVectorLayerFinder finder = createVectorLayerFinder(getPanel());
-        if (finder.getLayer() == null) {
+        Layer layer = finder.getLayer();
+        if (layer == null) {
             return;
         }
+        boolean oldVisible = layer.isVisible();
+        layer.setVisible(true); // next instruction search only in visible 
layers
         if (!layerToSpecifiedFeaturesMap().containsKey(finder.getLayer())) {
             return;
         }
+        layer.setVisible(oldVisible);
         execute(createCommand());        
     }
     
     protected UndoableCommand createCommand() throws 
NoninvertibleTransformException {
         final AbstractVectorLayerFinder finder = 
createVectorLayerFinder(getPanel());
+        Layer layer = finder.getLayer();
+        boolean oldVisible = layer.isVisible();
+        layer.setVisible(true); // next instruction search only in visible 
layers
         final Collection vectorFeaturesToDelete =
-            (Collection) layerToSpecifiedFeaturesMap().get(finder.getLayer());
+                (Collection) layerToSpecifiedFeaturesMap().get(layer);
+        layer.setVisible(oldVisible);
         Assert.isTrue(vectorFeaturesToDelete != null);
         Assert.isTrue(!vectorFeaturesToDelete.isEmpty());
         return new UndoableCommand(getName()) {
-            public void execute() {                
+            public void execute() {
                 
finder.getLayer().getFeatureCollectionWrapper().removeAll(vectorFeaturesToDelete);
                 showAnimation(vectorFeaturesToDelete);
             }

Modified: 
core/trunk/src/com/vividsolutions/jump/workbench/ui/warp/DeleteIncrementalWarpingVectorTool.java
===================================================================
--- 
core/trunk/src/com/vividsolutions/jump/workbench/ui/warp/DeleteIncrementalWarpingVectorTool.java
    2020-10-24 10:01:09 UTC (rev 6600)
+++ 
core/trunk/src/com/vividsolutions/jump/workbench/ui/warp/DeleteIncrementalWarpingVectorTool.java
    2020-10-24 18:31:05 UTC (rev 6601)
@@ -34,10 +34,13 @@
 
 import java.awt.Cursor;
 import java.awt.geom.NoninvertibleTransformException;
+import java.util.Collection;
 
 import javax.swing.Icon;
 
+import com.vividsolutions.jts.util.Assert;
 import com.vividsolutions.jump.workbench.model.AbstractVectorLayerFinder;
+import com.vividsolutions.jump.workbench.model.Layer;
 import com.vividsolutions.jump.workbench.model.LayerManagerProxy;
 import com.vividsolutions.jump.workbench.model.UndoableCommand;
 import com.vividsolutions.jump.workbench.ui.images.IconLoader;
@@ -51,11 +54,15 @@
     private WarpingPanel warpingPanel;
 
     protected AbstractVectorLayerFinder 
createVectorLayerFinder(LayerManagerProxy layerManagerProxy) {
+        return new WarpingVectorLayerFinder(layerManagerProxy);
+    }
+
+    protected AbstractVectorLayerFinder 
createIncrementalVectorLayerFinder(LayerManagerProxy layerManagerProxy) {
         return new IncrementalWarpingVectorLayerFinder(layerManagerProxy);
     }
 
     protected UndoableCommand createCommand() throws 
NoninvertibleTransformException {
-        return 
warpingPanel.addWarping(warpingPanel.addWarpingVectorGeneration(super.createCommand()));
+        return 
warpingPanel.addWarping(warpingPanel.addWarpingVectorGeneration(createBaseCommand()));
     }
 
     public Icon getIcon() {
@@ -66,4 +73,39 @@
         return 
createCursor(IconLoader.icon("DeleteVectorCursor.gif").getImage());
     }
 
+    /**
+     * The command returned uses super.createCommand to delete the feature in 
VectorLayer
+     * and add the deletion of the feature from IncrementalVectorLayer
+     * @return
+     * @throws NoninvertibleTransformException
+     */
+    protected UndoableCommand createBaseCommand() throws 
NoninvertibleTransformException {
+        final UndoableCommand superCommand = super.createCommand();
+        final AbstractVectorLayerFinder incrementalVectorLayerFinder =
+                createIncrementalVectorLayerFinder(getPanel());
+        Assert.isTrue(incrementalVectorLayerFinder != null);
+        Layer layer = incrementalVectorLayerFinder.getLayer();
+        Assert.isTrue(layer != null);
+        boolean oldVisible = layer.isVisible();
+        layer.setVisible(true); // next instruction search only in visible 
layers
+        final Collection incrementalVectorFeaturesToDelete =
+                (Collection) layerToSpecifiedFeaturesMap().get(layer);
+        layer.setVisible(oldVisible);
+        Assert.isTrue(incrementalVectorFeaturesToDelete != null);
+        Assert.isTrue(!incrementalVectorFeaturesToDelete.isEmpty());
+        return new UndoableCommand(getName()) {
+            public void execute() {
+                superCommand.execute();
+                
incrementalVectorLayerFinder.getLayer().getFeatureCollectionWrapper()
+                        .removeAll(incrementalVectorFeaturesToDelete);
+                showAnimation(incrementalVectorFeaturesToDelete);
+            }
+            public void unexecute() {
+                superCommand.unexecute();
+                incrementalVectorLayerFinder.getLayer()
+                        
.getFeatureCollectionWrapper().addAll(incrementalVectorFeaturesToDelete);
+            }
+        };
+    }
+
 }

Modified: 
core/trunk/src/com/vividsolutions/jump/workbench/ui/warp/WarpingPanel.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/workbench/ui/warp/WarpingPanel.java  
2020-10-24 10:01:09 UTC (rev 6600)
+++ core/trunk/src/com/vividsolutions/jump/workbench/ui/warp/WarpingPanel.java  
2020-10-24 18:31:05 UTC (rev 6601)
@@ -150,7 +150,7 @@
         });
     }
 
-    /*
+    /**
      * Method used by Draw/Delete incremental warping vector toos
      */
     public UndoableCommand addWarping(final UndoableCommand wrappeeCommand) {
@@ -158,8 +158,7 @@
             // Cache warping because user may change #isWarpingIncrementally.
             // [Jon Aquino]
             // Must cache warping lazily because #warpConditionsMet requires
-            // that
-            // drawCommand execute first. [Jon Aquino]
+            // that drawCommand execute first. [Jon Aquino]
             private Boolean warping = null;
             // Must create warpCommand lazily because it requires that
             // #warping return true. [Jon Aquino]
@@ -167,13 +166,12 @@
 
             private boolean warping() {
                 if (warping == null) {
-                    warping = new Boolean(isWarpingIncrementally()
-                            && warpConditionsMet());
-                    if (warping.booleanValue()) {
+                    warping = isWarpingIncrementally() && warpConditionsMet();
+                    if (warping) {
                         warpCommand = executeCommand();
                     }
                 }
-                return warping.booleanValue();
+                return warping;
             }
 
             @Override
@@ -288,8 +286,7 @@
                                 @Override
                                 public void unexecute() {
                                     // Triangulation layer undo is handled by
-                                    // ShowTriangulationPlugIn#addUndo. [Jon
-                                    // Aquino]
+                                    // ShowTriangulationPlugIn#addUndo. [Jon 
Aquino]
                                     try {
                                         if (willShowSourceLayer) {
                                             sourceLayer.setVisible(false);
@@ -371,6 +368,13 @@
                         MODIFIED_OUTSIDE_WARP_KEY) ? new ArrayList()
                 : (Collection) currentOutputLayer().getBlackboard().get(
                         RECONSTRUCTION_VECTORS_KEY);
+        // Fix #382 : if we are deleting a vector incrementally, we don't
+        // want to use reconstructionVectors cached from the Blackboard but
+        // an upadated collection where the deleted vector has been removed
+        if (isWarpingIncrementally() && warpingVectorLayerFinder().getLayer() 
!= null) {
+            reconstructionVectors = warpingVectorLayerFinder().getLayer()
+                    .getFeatureCollectionWrapper().getFeatures();
+        }
         final Collection newWarpingVectors = toWarpingVectors(
                 incrementalWarpingVectorLayerFinder().getLayer()
                         .getFeatureCollectionWrapper().getFeatures(),
@@ -738,6 +742,7 @@
                                             .getUndoableEditReceiver()
                                             .reportIrreversibleChange();
                                 }
+                                System.out.println("main : end");
                             }
 
                             @Override



_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to