Revision 3847

View differences:

trunk/extensions/extCAD/src/com/iver/cit/gvsig/CADExtension.java
46 46

  
47 47
import javax.swing.AbstractAction;
48 48
import javax.swing.FocusManager;
49
import javax.swing.JComponent;
49 50
import javax.swing.KeyStroke;
50 51

  
51 52
import com.iver.andami.PluginServices;
......
89 90
     * @see com.iver.andami.plugins.Extension#inicializar()
90 91
     */
91 92
    public void inicializar() {
93

  
94

  
95

  
96

  
92 97
        SelectionCADTool selection=new SelectionCADTool();
93 98
    	LineCADTool line = new LineCADTool();
94 99
        PointCADTool point = new PointCADTool();
......
131 136
     			}
132 137
     		});
133 138
        	registerKeyStrokes();
139
        	view.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "elimina");
140
            view.getActionMap().put("elimina", new MyAction("eliminar"));
141
            view.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "escape");
142
            view.getActionMap().put("escape", new MyAction("escape"));
143

  
134 144
        FLayers layers=mapControl.getMapContext().getLayers();
135 145
		for (int i=0;i<layers.getLayersCount();i++){
136 146
			if (layers.getLayer(i).isEditing() && layers.getLayer(i) instanceof FLyrVect){
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/CADToolAdapter.java
21 21
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior;
22 22
import com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener;
23 23
import com.iver.cit.gvsig.gui.View;
24
import com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool;
24 25

  
25 26
/**
26 27
 * DOCUMENT ME!
......
68 69
	 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
69 70
	 */
70 71
	public void mouseClicked(MouseEvent e) throws BehaviorException {
72

  
71 73
	}
72 74

  
73 75
	/**
......
648 650
		if (actionCommand.equals("eliminar")) {
649 651
			delete();
650 652
		} else if (actionCommand.equals("escape")) {
651
			if (getMapControl().getCurrentMapTool() instanceof CADToolAdapter){
653
			if (getMapControl().getTool().equals("cadtooladapter")){
654
				CADTool ct = (CADTool) cadToolStack.peek();
655
				ct.end();
652 656
				cadToolStack.clear();
653
				/***pushCadTool(new SelectionCadTool());***/
657
				pushCadTool(new SelectionCADTool());
654 658
				getVectorialAdapter().getSelection().clear();
655 659
				getMapControl().drawMap(false);
656 660
				/***PluginServices.getMainFrame().setSelectedTool("selection");***/
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/DefaultCADTool.java
139 139
            e.printStackTrace();
140 140
        }
141 141

  
142
        draw(geometry);
142
        draw(geometry.cloneGeometry());
143 143
    }
144 144
    /**
145 145
     * DOCUMENT ME!
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/SelectionCADTool.java
72 72
    private SelectionCADToolContext _fsm;
73 73
    private Point2D firstPoint;
74 74
    private Point2D lastPoint;
75
    private Point2D point;
76 75
    private ArrayList selectedHandler = new ArrayList();
77 76
    private ArrayList selectedRow = new ArrayList();
78 77
    private ArrayList selectedRowIndex = new ArrayList();
......
122 121
        //_fsm.addOption(sel,s);
123 122
    }
124 123

  
124

  
125
    public boolean isSelected(double x, double y){
126
    	firstPoint=new Point2D.Double(x,y);
127
    	FBitSet selection=getVectorialAdapter().getSelection();
128
    	if (selection.cardinality() > 0) {
129
            //Se comprueba si se pincha un handler. El m?s cercano (o los m?s cercanos si hay empate)
130
            selectedRow.clear();
131
            selectedRowIndex.clear();
132
            selectedHandler.clear();
133

  
134
            double min = Double.MAX_VALUE;
135

  
136
            for (int i = selection.nextSetBit(0); i >= 0;
137
                    i = selection.nextSetBit(i + 1)) {
138
                Handler[] handlers=null;
139
				try {
140
					handlers = getVectorialAdapter().getShape(i)
141
					                         .getHandlers(IGeometry.SELECTHANDLER);
142
				} catch (DriverIOException e) {
143
					// TODO Auto-generated catch block
144
					e.printStackTrace();
145
				}
146

  
147
                DefaultFeature fea = null;
148

  
149
                for (int j = 0; j < handlers.length; j++) {
150
                    Point2D handlerPoint = handlers[j].getPoint();
151
                    double distance = firstPoint.distance(handlerPoint);
152
                    if ((distance <= min) &&
153
                            (distance < getCadToolAdapter()
154
                                                .getMapControl()
155
                                                .getViewPort()
156
                                                .toMapDistance(tolerance))) {
157
                        if (distance < min) {
158
                            selectedRow.clear();
159
                            selectedRowIndex.clear();
160
                            selectedHandler.clear();
161
                        }
162

  
163
                        min = distance;
164

  
165
                        if (fea == null) {
166
                            IGeometry clonedGeometry=null;
167
							try {
168
								clonedGeometry = getVectorialAdapter()
169
								                               .getShape(i)
170
								                               .cloneGeometry();
171
							} catch (DriverIOException e) {
172
								// TODO Auto-generated catch block
173
								e.printStackTrace();
174
							}
175
                            try {
176
								fea = (DefaultFeature) getVectorialAdapter()
177
								                           .getFeature(i);
178
							} catch (DriverException e) {
179
								// TODO Auto-generated catch block
180
								e.printStackTrace();
181
							}
182
                            selectedRow.add(new DefaultFeature(clonedGeometry,fea.getAttributes()));
183
                            selectedHandler.add(clonedGeometry
184
                                                   .getHandlers(IGeometry.SELECTHANDLER)[j]);
185
                            selectedRowIndex.add(new Integer(i));
186
                        }
187

  
188

  
189
                    }
190
                }
191
            }
192

  
193
        }
194

  
195
        if ((selectedRow.size() == 0) ||
196
                (selection.cardinality() == 0)) {
197
            // Se comprueba si se pincha en una gemometr?a
198
            PluginServices.getMDIManager().setWaitCursor();
199

  
200
            double tam = getCadToolAdapter().getMapControl()
201
                             .getViewPort().toMapDistance(tolerance);
202
            Rectangle2D rect = new Rectangle2D.Double(firstPoint.getX() -
203
                    tam, firstPoint.getY() - tam, tam * 2, tam * 2);
204
            int[] indexes = getVectorialAdapter().getRowsIndexes(rect);
205

  
206
            selection.clear();
207

  
208
            for (int i = 0; i < indexes.length; i++) {
209
                try {
210
					if (getVectorialAdapter().getShape(indexes[i])
211
					            .intersects(rect)) {
212
					    // .intersects(rect,FLATNESS)) {
213
					    selection.set(indexes[i], true);
214
					}
215
				} catch (DriverIOException e) {
216
					// TODO Auto-generated catch block
217
					e.printStackTrace();
218
				}
219
            }
220

  
221
            PluginServices.getMDIManager().restoreCursor();
222
        }
223
        return selection.cardinality()>0;
224
    }
225

  
125 226
    /**
126 227
     * Equivale al transition del prototipo pero sin pasarle como par? metro el
127 228
     * editableFeatureSource que ya estar? creado.
......
136 237
        FBitSet selection=getVectorialAdapter().getSelection();
137 238
        try {
138 239
            if (status.equals("ExecuteMap.Initial")) {
139
                firstPoint = new Point2D.Double(x, y);
240
                //firstPoint = new Point2D.Double(x, y);
140 241
            } else if (status.equals("ExecuteMap.First")) {
141 242
                //PluginServices.getMDIManager().setWaitCursor();
142 243
                lastPoint = new Point2D.Double(x, y);
......
186 287
                PluginServices.getMDIManager().restoreCursor();
187 288
                //cardinality = selection.cardinality();
188 289
            } else if (status.equals("ExecuteMap.Second")) {
189
                point = new Point2D.Double(x, y);
190

  
191
                if (selection.cardinality() > 0) {
192
                    //Se comprueba si se pincha un handler. El m?s cercano (o los m?s cercanos si hay empate)
193
                    selectedRow.clear();
194
                    selectedRowIndex.clear();
195
                    selectedHandler.clear();
196

  
197
                    double min = Double.MAX_VALUE;
198

  
199
                    for (int i = selection.nextSetBit(0); i >= 0;
200
                            i = selection.nextSetBit(i + 1)) {
201
                        Handler[] handlers = getVectorialAdapter().getShape(i)
202
                                                 .getHandlers(IGeometry.SELECTHANDLER);
203

  
204
                        DefaultFeature fea = null;
205

  
206
                        for (int j = 0; j < handlers.length; j++) {
207
                            Point2D handlerPoint = handlers[j].getPoint();
208
                            double distance = point.distance(handlerPoint);
209
                            if ((distance <= min) &&
210
                                    (distance < getCadToolAdapter()
211
                                                        .getMapControl()
212
                                                        .getViewPort()
213
                                                        .toMapDistance(tolerance))) {
214
                                if (distance < min) {
215
                                    selectedRow.clear();
216
                                    selectedRowIndex.clear();
217
                                    selectedHandler.clear();
218
                                }
219

  
220
                                min = distance;
221

  
222
                                if (fea == null) {
223
                                    IGeometry clonedGeometry = getVectorialAdapter()
224
                                                                   .getShape(i)
225
                                                                   .cloneGeometry();
226
                                    fea = (DefaultFeature) getVectorialAdapter()
227
                                                               .getFeature(i);
228
                                    selectedRow.add(new DefaultFeature(clonedGeometry,fea.getAttributes()));
229
                                    selectedHandler.add(clonedGeometry
230
                                                           .getHandlers(IGeometry.SELECTHANDLER)[j]);
231
                                    selectedRowIndex.add(new Integer(i));
232
                                }
233

  
234

  
235
                            }
236
                        }
237
                    }
238
                }
239

  
240
          /*      if ((selectedRow.size() == 0) ||
241
                        (selection.cardinality() == 0)) {
242
                    // Se comprueba si se pincha en una gemometr?a
243
                    PluginServices.getMDIManager().setWaitCursor();
244

  
245
                    double tam = getCadToolAdapter().getMapControl()
246
                                     .getViewPort().toMapDistance(tolerance);
247
                    Rectangle2D rect = new Rectangle2D.Double(firstPoint.getX() -
248
                            tam, firstPoint.getY() - tam, tam * 2, tam * 2);
249
                    int[] indexes = getVectorialAdapter().getRowsIndexes(rect);
250

  
251
                    selection.clear();
252

  
253
                    for (int i = 0; i < indexes.length; i++) {
254
                        if (getVectorialAdapter().getShape(indexes[i])
255
                                    .intersects(rect)) {
256
                            // .intersects(rect,FLATNESS)) {
257
                            selection.set(indexes[i], true);
258
                        }
259
                    }
260

  
261
                    PluginServices.getMDIManager().restoreCursor();
262
                    cardinality = selection.cardinality();
263
                }
264
*/            } else if (status.equals("ExecuteMap.Third")) {
265
                for (int i = 0; i < selectedRow.size(); i++) {
290
            	for (int i = 0; i < selectedRow.size(); i++) {
266 291
                    Handler h = (Handler) selectedHandler.get(i);
267 292
                    DefaultFeature row = (DefaultFeature) selectedRow.get(i);
268 293
                    int index = ((Integer) selectedRowIndex.get(i)).intValue();
......
271 296
                    //getVectorialAdapter().modifyRow(index, row);
272 297
                    modifyFeature(index,row);
273 298
                }
274

  
275
                //  			ret = ret | selectionStatus.transition("done");
276 299
            }
277 300
       // } catch (IOException e) {
278 301
            // TODO Auto-generated catch block
......
280 303
        } catch (DriverIOException e) {
281 304
            // TODO Auto-generated catch block
282 305
            e.printStackTrace();
283
        } catch (DriverException e) {
284
            // TODO Auto-generated catch block
285
            e.printStackTrace();
286 306
        }
287 307
    }
288 308

  
......
318 338
            ShapeFactory.createPolyline2D(elShape).draw((Graphics2D) g,
319 339
                getCadToolAdapter().getMapControl().getViewPort(),
320 340
                CADTool.selectSymbol);
321
        } else if (status.equals("ExecuteMap.Third")) {
341
        } else if (status.equals("ExecuteMap.Second")) {
322 342
            for (int i = 0; i < selectedRow.size(); i++) {
323 343
                Handler h = (Handler) selectedHandler.get(i);
324 344
                IGeometry geom = ((IGeometry) ((DefaultFeature)selectedRow.get(i)).getGeometry()).cloneGeometry();
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/smc/RectangleCADToolContext.java
172 172
                RectangleCADTool ctxt = context.getOwner();
173 173

  
174 174
                ctxt.init();
175
                ctxt.setQuestion("Insertar primer punto de esquina");
175
                ctxt.setQuestion("RECTANGULO" + "\n" +
176
		"Insertar primer punto de esquina");
176 177
                return;
177 178
            }
178 179

  
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/smc/ArcCADToolContext.java
157 157
                ArcCADTool ctxt = context.getOwner();
158 158

  
159 159
                ctxt.init();
160
                ctxt.setQuestion("Insertar primer punto");
160
                ctxt.setQuestion("ARCO" + "\n"+
161
		"Insertar primer punto");
161 162
                return;
162 163
            }
163 164

  
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/smc/SelectionCADToolContext.java
111 111
        /* package */ static ExecuteMap_Default.ExecuteMap_First First;
112 112
        /* package */ static ExecuteMap_Default.ExecuteMap_Second Second;
113 113
        /* package */ static ExecuteMap_Default.ExecuteMap_Third Third;
114
        /* package */ static ExecuteMap_Default.ExecuteMap_Fourth Fourth;
115 114
        private static ExecuteMap_Default Default;
116 115

  
117 116
        static
......
120 119
            First = new ExecuteMap_Default.ExecuteMap_First("ExecuteMap.First", 1);
121 120
            Second = new ExecuteMap_Default.ExecuteMap_Second("ExecuteMap.Second", 2);
122 121
            Third = new ExecuteMap_Default.ExecuteMap_Third("ExecuteMap.Third", 3);
123
            Fourth = new ExecuteMap_Default.ExecuteMap_Fourth("ExecuteMap.Fourth", 4);
124 122
            Default = new ExecuteMap_Default("ExecuteMap.Default", -1);
125 123
        }
126 124

  
......
160 158
                SelectionCADTool ctxt = context.getOwner();
161 159

  
162 160
                ctxt.init();
163
                ctxt.setQuestion("Precise punto del rect?ngulo de selecci?n");
161
                ctxt.setQuestion("SELECCION" + "\n" +
162
		"Precise punto del rect?ngulo de selecci?n");
164 163
                return;
165 164
            }
166 165

  
......
168 167
            {
169 168
                SelectionCADTool ctxt = context.getOwner();
170 169

  
171

  
172
                (context.getState()).Exit(context);
173
                context.clearState();
174
                try
170
                if (!ctxt.isSelected(pointX,pointY))
175 171
                {
176
                    ctxt.setQuestion("Precise segundo punto del rect?ngulo de seleccion");
177
                    ctxt.addPoint(pointX, pointY);
172

  
173
                    (context.getState()).Exit(context);
174
                    context.clearState();
175
                    try
176
                    {
177
                        ctxt.setQuestion("Precise segundo punto del rect?ngulo de seleccion");
178
                        ctxt.addPoint(pointX, pointY);
179
                    }
180
                    finally
181
                    {
182
                        context.setState(ExecuteMap.First);
183
                        (context.getState()).Entry(context);
184
                    }
178 185
                }
179
                finally
186
                else if (ctxt.isSelected(pointX,pointY))
180 187
                {
181
                    context.setState(ExecuteMap.First);
182
                    (context.getState()).Entry(context);
188

  
189
                    (context.getState()).Exit(context);
190
                    context.clearState();
191
                    try
192
                    {
193
                        ctxt.setQuestion("Precise punto destino");
194
                        ctxt.addPoint(pointX, pointY);
195
                    }
196
                    finally
197
                    {
198
                        context.setState(ExecuteMap.Second);
199
                        (context.getState()).Entry(context);
200
                    }
201
                }                else
202
                {
203
                    super.addPoint(context, pointX, pointY);
183 204
                }
205

  
184 206
                return;
185 207
            }
186 208

  
......
215 237
                }
216 238
                finally
217 239
                {
218
                    context.setState(ExecuteMap.Second);
240
                    context.setState(ExecuteMap.Initial);
219 241
                    (context.getState()).Entry(context);
220 242
                }
221 243
                return;
......
247 269
                context.clearState();
248 270
                try
249 271
                {
250
                    ctxt.setQuestion("Precise punto de estiramiento");
272
                    ctxt.setQuestion("Precise punto destino");
251 273
                    ctxt.addPoint(pointX, pointY);
274
                    ctxt.end();
275
                    ctxt.refresh();
252 276
                }
253 277
                finally
254 278
                {
......
275 299
                super (name, id);
276 300
            }
277 301

  
278
            protected void addPoint(SelectionCADToolContext context, double pointX, double pointY)
279
            {
280
                SelectionCADTool ctxt = context.getOwner();
281

  
282

  
283
                (context.getState()).Exit(context);
284
                context.clearState();
285
                try
286
                {
287
                    ctxt.setQuestion("Precise punto de estiramiento");
288
                    ctxt.addPoint(pointX, pointY);
289
                    ctxt.end();
290
                    ctxt.refresh();
291
                }
292
                finally
293
                {
294
                    context.setState(ExecuteMap.Fourth);
295
                    (context.getState()).Entry(context);
296
                }
297
                return;
298
            }
299

  
300 302
        //-------------------------------------------------------
301 303
        // Member data.
302 304
        //
303 305
        }
304 306

  
305
        private static final class ExecuteMap_Fourth
306
            extends ExecuteMap_Default
307
        {
308
        //-------------------------------------------------------
309
        // Member methods.
310
        //
311

  
312
            private ExecuteMap_Fourth(String name, int id)
313
            {
314
                super (name, id);
315
            }
316

  
317
        //-------------------------------------------------------
318
        // Member data.
319
        //
320
        }
321

  
322 307
    //-----------------------------------------------------------
323 308
    // Member data.
324 309
    //
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/smc/LineCADToolContext.java
168 168
                LineCADTool ctxt = context.getOwner();
169 169

  
170 170
                ctxt.init();
171
                ctxt.setQuestion("Insertar primer punto");
171
                ctxt.setQuestion("LINEA" + "\n" +
172
		"Insertar primer punto");
172 173
                return;
173 174
            }
174 175

  
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/smc/PolygonCADToolContext.java
185 185
                PolygonCADTool ctxt = context.getOwner();
186 186

  
187 187
                ctxt.init();
188
                ctxt.setQuestion("Insertar numero de lados<5>");
188
                ctxt.setQuestion("POLIGONO" + "\n" +
189
		"Insertar numero de lados<5>");
189 190
                return;
190 191
            }
191 192

  
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/smc/PointCADToolContext.java
153 153
                PointCADTool ctxt = context.getOwner();
154 154

  
155 155
                ctxt.init();
156
                ctxt.setQuestion("Defina el punto");
156
                ctxt.setQuestion("PUNTO" + "\n" +
157
		"Defina el punto");
157 158
                return;
158 159
            }
159 160

  
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/smc/PolylineCADToolContext.java
172 172
                PolylineCADTool ctxt = context.getOwner();
173 173

  
174 174
                ctxt.init();
175
                ctxt.setQuestion("Insertar primer punto");
175
                ctxt.setQuestion("POLILINEA" + "\n" +
176
		"Insertar primer punto");
176 177
                return;
177 178
            }
178 179

  
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/smc/EllipseCADToolContext.java
172 172
                EllipseCADTool ctxt = context.getOwner();
173 173

  
174 174
                ctxt.init();
175
                ctxt.setQuestion("Insertar punto inicial de eje de elipse");
175
                ctxt.setQuestion("ELIPSE" + "\n" +
176
		"Insertar punto inicial de eje de elipse");
176 177
                return;
177 178
            }
178 179

  
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/smc/CircleCADToolContext.java
191 191
                CircleCADTool ctxt = context.getOwner();
192 192

  
193 193
                ctxt.init();
194
                ctxt.setQuestion("Insertar punto central o [3P]:");
194
                ctxt.setQuestion("CIRCULO" + "\n" +
195
		"Insertar punto central o [3P]:");
195 196
                return;
196 197
            }
197 198

  

Also available in: Unified diff