Revision 1573

View differences:

branches/pilotoDWG/applications/appgvSIG/src/com/iver/cit/gvsig/gui/cad/CadGrid.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.gui.cad;
42

  
43
import java.awt.Graphics;
44
import java.awt.Point;
45

  
46

  
47
/**
48
 * DOCUMENT ME!
49
 *
50
 * @author Vicente Caballero Navarro
51
 */
52
public class CadGrid {
53
	private boolean grid = false;
54
	private int gridSize = 20;
55
	private CadMapControl cadmapcontrol;
56

  
57
	/**
58
	 * Crea un nuevo CadGrid.
59
	 *
60
	 * @param cmc DOCUMENT ME!
61
	 */
62
	public CadGrid() {
63
	}
64
public void setCadMapControl(CadMapControl cmc){
65
	cadmapcontrol=cmc;
66
}
67
	/**
68
	 * Ajusta un punto de la imagen que se pasa como  par?metro al handler m?s
69
	 * cercano si se encuentra lo suficientemente  cerca y devuelve la
70
	 * distancia del punto original al punto ajustado
71
	 *
72
	 * @param point
73
	 *
74
	 * @return Distancia del punto que se pasa como par?metro al punto ajustado
75
	 */
76
	public double adjustToGrid(Point point) {
77
		if (grid) {
78
			Point p = new Point(point);
79
			point.x = (((int) point.getX() + (gridSize / 2)) / gridSize) * gridSize;
80
			point.y = (((int) point.getY() + (gridSize / 2)) / gridSize) * gridSize;
81

  
82
			return p.distance(point);
83
		}
84

  
85
		return Double.MAX_VALUE;
86
	}
87

  
88
	/**
89
	 * Dibuja el grid sobre el graphics que se pasa como par?metro
90
	 *
91
	 * @param g Graphics sobre el que dibujar el grid.
92
	 */
93
	public void drawGrid(Graphics g) {
94
		if (!grid) {
95
			return;
96
		}
97

  
98
		for (int x = 0; x < cadmapcontrol.getWidth(); x += gridSize) {
99
			for (int y = 0; y < cadmapcontrol.getHeight(); y += gridSize) {
100
				g.drawRect(x, y, 1, 1);
101
			}
102
		}
103
	}
104
	public void setUseGrid(boolean b){
105
		grid=b;
106
	}
107
}
0 108

  
branches/pilotoDWG/applications/appgvSIG/src/com/iver/cit/gvsig/gui/cad/CadMapControl.java
373 373
	 */
374 374
	public void startEdition(EditionEvent e) {
375 375
		FLayer lyr = e.getSource();
376
		cadToolAdapter.setEditableFeatureSource((EditableFeatureSourceProxy)e.getEditingAdapter(), ((Selectable)lyr).getSelection());		
376
		cadToolAdapter.setEditableFeatureSource(e.getEditingAdapter(), ((Selectable)lyr).getSelection());		
377 377
	}
378 378

  
379 379
	/**
branches/pilotoDWG/applications/appgvSIG/src/com/iver/cit/gvsig/GeometryExtension.java
40 40
 */
41 41
package com.iver.cit.gvsig;
42 42

  
43
import java.io.IOException;
44

  
43 45
import com.iver.andami.PluginServices;
44 46
import com.iver.andami.plugins.Extension;
45 47

  
46 48
import com.iver.cit.gvsig.fmap.FMap;
49
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
47 50
import com.iver.cit.gvsig.fmap.layers.FLayer;
48 51
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
49 52
import com.iver.cit.gvsig.fmap.layers.layerOperations.EditableVectorialLayer;
......
121 124
		} else if (s.compareTo("POLYGON") == 0) {
122 125
			vista.getMapControl().setCadTool("polygon");
123 126
		} else if (s.compareTo("UNDO") == 0) {
124
			cadmap.getCadToolAdapter().undo();
127
			try {
128
				cadmap.getCadToolAdapter().getEditableFeatureSource().undo();
129
			} catch (DriverIOException e) {
130
				e.printStackTrace();
131
			} catch (IOException e) {
132
				e.printStackTrace();
133
			}
125 134
			vista.getMapControl().getMapControl().drawMap(false);
126 135
		} else if (s.compareTo("REDO") == 0) {
127
			cadmap.getCadToolAdapter().redo();
136
			try {
137
				cadmap.getCadToolAdapter().getEditableFeatureSource().redo();
138
			} catch (DriverIOException e) {
139
				e.printStackTrace();
140
			} catch (IOException e) {
141
				e.printStackTrace();
142
			}
128 143
			vista.getMapControl().getMapControl().drawMap(false);
129 144
		}
130 145
	}
branches/pilotoDWG/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/EditableFeatureSource.java
185 185
	void undoAddGeometry(int index) throws DriverIOException, IOException;
186 186
	void undoModifyGeometry(int index,int previndex);
187 187
	void undoRemoveGeometry(int index);
188
	SelectionSupport getSelectionSuport();
189 188
}
branches/pilotoDWG/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/DefaultEditableFeatureSource.java
2 2

  
3 3
import com.iver.cit.gvsig.fmap.core.IGeometry;
4 4
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
5
import com.iver.cit.gvsig.fmap.layers.FBitSet;
5 6
import com.iver.cit.gvsig.fmap.layers.SelectionSupport;
6 7

  
7 8
import com.vividsolutions.jts.geom.Envelope;
......
31 32
	private Quadtree index;
32 33
	private Image selectionImage;
33 34
	private CommandRecord cr;
34
	private SelectionSupport selectionSupport = new SelectionSupport();
35
	private FBitSet fbitset;
35 36
	/**
36 37
	 * Crea un nuevo AbstractEditableFeatureSource.
37 38
	 *
......
39 40
	 * @param ofa DOCUMENT ME!
40 41
	 */
41 42
	public DefaultEditableFeatureSource(ExpansionFile ef,
42
		OriginalFeatureAdapter ofa) {
43
		OriginalFeatureAdapter ofa,FBitSet bitset) {
43 44
		expansionFile = ef;
44 45
		this.ofa = ofa;
45 46
		this.cr= new MemoryCommandRecord();
47
		fbitset=bitset;
46 48
	}
47 49

  
48 50
	/**
......
454 456
	 * @see com.iver.cit.gvsig.fmap.edition.EditableFeatureSource#undo()
455 457
	 */
456 458
	public void undo() throws DriverIOException, IOException{
457
		selectionSupport.clearSelection();
459
		fbitset.clear();
458 460
		if (moreUndoCommands())
459 461
		cr.popCommand();
460 462
	}
......
462 464
	 * @see com.iver.cit.gvsig.fmap.edition.EditableFeatureSource#redo()
463 465
	 */
464 466
	public void redo(){
465
		selectionSupport.clearSelection();
467
		fbitset.clear();
466 468
		if (moreRedoCommands())
467 469
		cr.pushCommand();
468 470
	}
......
481 483
	public boolean moreRedoCommands() {
482 484
		return cr.moreRedoCommands();
483 485
	}
484

  
485
	/**
486
	 * @see com.iver.cit.gvsig.fmap.edition.EditableFeatureSource#getSelectionSuport()
487
	 */
488
	public SelectionSupport getSelectionSuport() {
489
		return selectionSupport;
490
	}
486
	
491 487
}
branches/pilotoDWG/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/FLyrVect.java
155 155
	public EditableFeatureSource startEdition() throws EditionException {
156 156
		FileEditableFeatureSource fefs = new FileEditableFeatureSource((VectorialFileAdapter) source);
157 157
		MemoryExpansionFile mef = new MemoryExpansionFile();
158
		efs = new EditableFeatureSourceProxy(new DefaultEditableFeatureSource(mef,
159
				fefs));
158
		efs = new DefaultEditableFeatureSource(mef,
159
				fefs,selectionSupport.getSelection());
160 160
		
161 161
		efs.startEdition();
162 162
	
......
174 174
	 * @param listener SelectionListener.
175 175
	 */
176 176
	public void addSelectionListener(SelectionListener listener) {
177
		if (efs!=null)
177 178
		selectionSupport.addSelectionListener(listener);
178 179
	}
179 180

  

Also available in: Unified diff