Revision 3883

View differences:

trunk/extensions/extCAD/src/com/iver/cit/gvsig/EditingExtension.java
12 12

  
13 13
/**
14 14
 * DOCUMENT ME!
15
 * 
15
 *
16 16
 * @author Vicente Caballero Navarro
17 17
 */
18 18
public class EditingExtension implements Extension {
......
48 48
				}
49 49
			}
50 50
		} else if (s.equals("SHOWGRID")) {
51
			// vista.getMapControl().getCadToolAdapter().setGrid(true);
51
			CADExtension.getCADToolAdapter().setMapControl(vista.getMapControl());
52
			CADExtension.getCADToolAdapter().setGrid(true);
52 53
		} else if (s.equals("HIDEGRID")) {
53
			// vista.getMapControl().getCadToolAdapter().setGrid(false);
54
			CADExtension.getCADToolAdapter().setMapControl(vista.getMapControl());
55
			CADExtension.getCADToolAdapter().setGrid(false);
54 56
		} else if (s.equals("SETADJUSTGRID")) {
55
			// vista.getMapControl().getCadToolAdapter().setAdjustGrid(true);
57
			CADExtension.getCADToolAdapter().setMapControl(vista.getMapControl());
58
			CADExtension.getCADToolAdapter().setAdjustGrid(true);
56 59
		} else if (s.equals("NOTADJUSTGRID")) {
57
			// vista.getMapControl().getCadToolAdapter().setAdjustGrid(false);
60
			CADExtension.getCADToolAdapter().setMapControl(vista.getMapControl());
61
			CADExtension.getCADToolAdapter().setAdjustGrid(false);
58 62
		}
59 63

  
60 64
		PluginServices.getMainFrame().enableControls();
trunk/extensions/extCAD/src/com/iver/cit/gvsig/CADExtension.java
41 41
package com.iver.cit.gvsig;
42 42

  
43 43
import java.awt.event.ActionEvent;
44
import java.awt.event.ActionListener;
44 45
import java.awt.event.KeyEvent;
46
import java.awt.event.MouseEvent;
45 47
import java.util.HashMap;
46 48

  
47 49
import javax.swing.AbstractAction;
48 50
import javax.swing.FocusManager;
49 51
import javax.swing.JComponent;
52
import javax.swing.JMenuItem;
53
import javax.swing.JPopupMenu;
50 54
import javax.swing.KeyStroke;
51 55

  
52 56
import com.iver.andami.PluginServices;
53 57
import com.iver.andami.plugins.Extension;
54 58
import com.iver.cit.gvsig.fmap.MapControl;
55 59
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter;
56
import com.iver.cit.gvsig.fmap.layers.FBitSet;
57 60
import com.iver.cit.gvsig.fmap.layers.FLayer;
58 61
import com.iver.cit.gvsig.fmap.layers.FLayers;
59 62
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
......
63 66
import com.iver.cit.gvsig.gui.cad.CADToolAdapter;
64 67
import com.iver.cit.gvsig.gui.cad.tools.ArcCADTool;
65 68
import com.iver.cit.gvsig.gui.cad.tools.CircleCADTool;
69
import com.iver.cit.gvsig.gui.cad.tools.CopyCADTool;
66 70
import com.iver.cit.gvsig.gui.cad.tools.EllipseCADTool;
67 71
import com.iver.cit.gvsig.gui.cad.tools.LineCADTool;
68 72
import com.iver.cit.gvsig.gui.cad.tools.PointCADTool;
69 73
import com.iver.cit.gvsig.gui.cad.tools.PolygonCADTool;
70 74
import com.iver.cit.gvsig.gui.cad.tools.PolylineCADTool;
71 75
import com.iver.cit.gvsig.gui.cad.tools.RectangleCADTool;
76
import com.iver.cit.gvsig.gui.cad.tools.RotateCADTool;
77
import com.iver.cit.gvsig.gui.cad.tools.ScaleCADTool;
72 78
import com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool;
73 79
import com.iver.utiles.console.ResponseListener;
74 80
/**
......
80 86
public class CADExtension implements Extension {
81 87
   private static CADToolAdapter adapter=new CADToolAdapter();
82 88
   private static HashMap namesCadTools = new HashMap();
83
   private boolean isLoad =false;
84 89
   private MapControl mapControl;
85
   private View view;
90
   private static View view;
86 91
   public static CADToolAdapter getCADToolAdapter(){
87 92
	   return adapter;
88 93
   }
......
90 95
     * @see com.iver.andami.plugins.Extension#inicializar()
91 96
     */
92 97
    public void inicializar() {
93

  
94

  
95

  
96

  
97 98
        SelectionCADTool selection=new SelectionCADTool();
98 99
    	LineCADTool line = new LineCADTool();
99 100
        PointCADTool point = new PointCADTool();
......
103 104
        EllipseCADTool ellipse=new EllipseCADTool();
104 105
        ArcCADTool arc=new ArcCADTool();
105 106
        PolygonCADTool polygon=new PolygonCADTool();
107
        CopyCADTool copy=new CopyCADTool();
108
        RotateCADTool rotate=new RotateCADTool();
109
        ScaleCADTool scale=new ScaleCADTool();
106 110
        addCADTool("selection", selection);
107 111
        addCADTool("line", line);
108 112
        addCADTool("point", point);
......
112 116
        addCADTool("ellipse", ellipse);
113 117
        addCADTool("arc", arc);
114 118
        addCADTool("polygon", polygon);
119
        addCADTool("copy",copy);
120
        addCADTool("rotate",rotate);
121
        addCADTool("scale",scale);
115 122
    }
116 123

  
117 124
    /**
......
120 127
    public void execute(String s) {
121 128
        view = (View) PluginServices.getMDIManager().getActiveView();
122 129
        mapControl = (MapControl) view.getMapControl();
123
        if (!isLoad){
124
        	mapControl.addMapTool("cadtooladapter", new Behavior[]{adapter});
125
        	isLoad=true;
126
        }
130
        if (!mapControl.getNamesMapTools().containsKey("cadtooladapter"))
131
        	mapControl.addMapTool("cadtooladapter",adapter);
132
        	view.getMapControl().setTool("cadtooladapter");
127 133
        	view.addConsoleListener("cad", new ResponseListener() {
128 134
     			public void acceptResponse(String response) {
129 135
     				adapter.textEntered(response);
......
146 152
			if (layers.getLayer(i).isEditing() && layers.getLayer(i) instanceof FLyrVect){
147 153
				adapter.setVectorialAdapter((VectorialEditableAdapter)((FLyrVect)layers.getLayer(i)).getSource());
148 154
				adapter.setMapControl(mapControl);
155

  
149 156
			}
150 157
		}
151 158

  
152 159
        view.getMapControl().setTool("cadtooladapter");
160

  
153 161
        if (s.compareTo("SPLINE") == 0) {
154 162
        	setCADTool("spline");
155 163
        } else if (s.compareTo("COPY") == 0) {
......
161 169
        } else if (s.compareTo("SYMMETRY") == 0) {
162 170
        	setCADTool("symmetry");
163 171
        } else if (s.compareTo("ROTATION") == 0) {
164
        	setCADTool("rotation");
172
        	setCADTool("rotate");
165 173
        } else if (s.compareTo("STRETCHING") == 0) {
166 174
        	setCADTool("stretching");
167 175
        } else if (s.compareTo("SCALE") == 0) {
......
178 186
        	setCADTool("chaflan");
179 187
        } else if (s.compareTo("JOIN") == 0) {
180 188
        	setCADTool("join");
181
        } else if (s.compareTo("SELECT") == 0) {
189
        } else if (s.compareTo("SELCAD") == 0) {
182 190
        	setCADTool("selection");
183 191
        } else if (s.compareTo("POINT") == 0) {
184 192
        	setCADTool("point");
......
197 205
        } else if (s.compareTo("POLYGON") == 0) {
198 206
        	setCADTool("polygon");
199 207
        }
200

  
208
        adapter.configureMenu();
201 209
        //ViewControls.CANCELED=false;
202 210
    }
203 211
    public void addCADTool(String name, CADTool c){
......
206 214
    public static void setCADTool(String text){
207 215
		CADTool ct = (CADTool) namesCadTools.get(text);
208 216
		if (ct == null) throw new RuntimeException("No such cad tool");
217
		adapter.setCadTool(ct);
209 218
		ct.init();
210
		adapter.setCadTool(ct);
219
		//PluginServices.getMainFrame().setSelectedTool("SELECT");
220
		//PluginServices.getMainFrame().enableControls();
211 221
	}
212 222
    /**
213 223
     * @see com.iver.andami.plugins.Extension#isEnabled()
......
309 319
		mapControl.getInputMap(MapControl.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),keyChar);
310 320
		mapControl.getActionMap().put(keyChar, new KeyAction(""));
311 321
	}
322

  
323
	private static JPopupMenu popup = new JPopupMenu();
324
	public static  void clearMenu(){
325
		popup.removeAll();
326
	}
327

  
328
	public static void addMenuEntry(String text){
329
		JMenuItem menu = new JMenuItem(text);
330
		menu.setActionCommand(text);
331
		menu.setEnabled(true);
332
		menu.setVisible(true);
333
		menu.addActionListener(new ActionListener() {
334
			public void actionPerformed(ActionEvent e) {
335
				adapter.transition(e.getActionCommand());
336
			}
337
		});
338

  
339
		popup.add(menu);
340
	}
341
	public static void showPopup(MouseEvent e) {
342
		    popup.show(e.getComponent(),
343
                       e.getX(), e.getY());
344
    }
345
	public static View getView() {
346
		return view;
347
	}
312 348
}
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/DefaultCADTool.java
40 40
 */
41 41
package com.iver.cit.gvsig.gui.cad;
42 42

  
43
import java.awt.Graphics;
44
import java.awt.Graphics2D;
45
import java.awt.geom.AffineTransform;
46
import java.awt.geom.Point2D;
47
import java.awt.image.BufferedImage;
48
import java.io.IOException;
49

  
43 50
import com.hardcode.gdbms.engine.values.Value;
44

  
51
import com.iver.andami.PluginServices;
52
import com.iver.cit.gvsig.CADExtension;
45 53
import com.iver.cit.gvsig.fmap.ViewPort;
46 54
import com.iver.cit.gvsig.fmap.core.DefaultFeature;
47 55
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
48 56
import com.iver.cit.gvsig.fmap.core.Handler;
49
import com.iver.cit.gvsig.fmap.core.IFeature;
50 57
import com.iver.cit.gvsig.fmap.core.IGeometry;
51 58
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
52 59
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities;
53 60
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
54
import com.iver.cit.gvsig.fmap.edition.IRowEdited;
55 61
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter;
56 62
import com.iver.cit.gvsig.fmap.layers.FBitSet;
57 63

  
58
import java.awt.Graphics;
59
import java.awt.Graphics2D;
60
import java.awt.geom.AffineTransform;
61
import java.awt.geom.Point2D;
62
import java.awt.image.BufferedImage;
63 64

  
64
import java.io.IOException;
65

  
66

  
67 65
/**
68 66
 * DOCUMENT ME!
69 67
 *
......
71 69
 */
72 70
public abstract class DefaultCADTool implements CADTool {
73 71
    private CADToolAdapter cadToolAdapter;
74
    private VectorialEditableAdapter vea;
75 72
    private String question;
73
    private String[] currentdescriptions;
76 74

  
77 75
    /**
78 76
     * DOCUMENT ME!
......
130 128
        DefaultFeature df = new DefaultFeature(geometry, null);
131 129

  
132 130
        try {
133
            vea.addRow(df);
131
            getCadToolAdapter().getVectorialAdapter().addRow(df);
134 132
        } catch (DriverIOException e) {
135 133
            // TODO Auto-generated catch block
136 134
            e.printStackTrace();
......
148 146
     */
149 147
    public void modifyFeature(int index,DefaultFeature row) {
150 148
    	try {
151
			vea.modifyRow(index, row);
149
			getCadToolAdapter().getVectorialAdapter().modifyRow(index, row);
152 150
		} catch (IOException e1) {
153 151
			// TODO Auto-generated catch block
154 152
			e1.printStackTrace();
......
168 166
    }
169 167

  
170 168
    /**
171
     * DOCUMENT ME!
172
     *
173
     * @param vea DOCUMENT ME!
174
     */
175
    public void setVectorialAdapter(VectorialEditableAdapter vea) {
176
        this.vea = vea;
177
    }
178

  
179

  
180
    /**
181 169
     * Devuelve la cadena que corresponde al estado en el que nos encontramos.
182 170
     *
183 171
     * @return Cadena para mostrar por consola.
......
202 190
        getCadToolAdapter().getMapControl().drawMap(false);
203 191
    }
204 192

  
205
	public VectorialEditableAdapter getVectorialAdapter() {
206
		return vea;
207
	}
208 193
	public void drawHandlers(Graphics g,FBitSet sel,AffineTransform at) throws DriverIOException{
209 194
		 for (int i = sel.nextSetBit(0); i >= 0;
210 195
         i = sel.nextSetBit(i + 1)) {
211
			IGeometry ig = getVectorialAdapter().getShape(i).cloneGeometry();
196
			IGeometry ig = getCadToolAdapter().getVectorialAdapter().getShape(i).cloneGeometry();
212 197
			if (ig == null) continue;
213 198
				Handler[] handlers=ig.getHandlers(IGeometry.SELECTHANDLER);
214 199
				FGraphicUtilities.DrawHandlers((Graphics2D)g,at,handlers);
215 200
		}
216 201
	}
202

  
203
	public void setDescription(String[] currentdescriptions) {
204
		this.currentdescriptions = currentdescriptions;
205
	}
206
	public String[] getDescriptions(){
207
		return currentdescriptions;
208
	}
209
	/* (non-Javadoc)
210
     * @see com.iver.cit.gvsig.gui.cad.CADTool#end()
211
     */
212
    public void end() {
213
    	CADExtension.setCADTool("selection");
214
    	PluginServices.getMainFrame().setSelectedTool("SELCAD");
215
    }
216

  
217 217
}
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/CADGrid.java
56 56
 */
57 57
public class CADGrid {
58 58
	private boolean grid = false;
59
	private int gridSize = 0;
59
	private double gridSize = 0;
60 60
	private ViewPort viewport;
61 61
	private boolean adjustGrid;
62 62

  
......
69 69
		viewport = vp;
70 70

  
71 71
		if (gridSize == 0) {
72
			gridSize = (int) viewport.toMapDistance(20);
72
			gridSize = viewport.toMapDistance(25);
73
			//if (gridSize<1)gridSize=1;
73 74
		}
74 75
	}
75 76

  
......
117 118
		Rectangle2D extent = viewport.getAdjustedExtent();
118 119
		Point2D auxp = new Point2D.Double(0, 0);
119 120

  
120
		for (int i = (int) extent.getMinX(); i < (extent.getMaxX() + gridSize);
121
		for (double i = extent.getMinX(); i < (extent.getMaxX() + gridSize);
121 122
				i += gridSize) {
122
			for (int j = (int) extent.getMinY();
123
			for (double j = extent.getMinY();
123 124
					j < (extent.getMaxY() + gridSize); j += gridSize) {
124 125
				Point2D po = new Point2D.Double(i, j);
125 126
				Point2D point = viewport.fromMapPoint(po);
......
127 128
					((auxp.getX()) % gridSize);
128 129
				double y = ((po.getY() + gridSize) % gridSize) -
129 130
					((auxp.getY()) % gridSize);
130
				x = (int) (point.getX() - viewport.fromMapDistance(x));
131
				y = (int) (point.getY() + viewport.fromMapDistance(y));
131
				x = (point.getX() - viewport.fromMapDistance(x));
132
				y = (point.getY() + viewport.fromMapDistance(y));
132 133

  
133 134
				if (viewport.fromMapDistance(gridSize) > 3) {
134 135
					g.drawRect((int) x, (int) y, 1, 1);
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/LineCADTool.java
67 67
     * Crea un nuevo LineCADTool.
68 68
     */
69 69
    public LineCADTool() {
70
        _fsm = new LineCADToolContext(this);
70

  
71 71
    }
72 72

  
73 73
    /**
......
75 75
     * carga previa a la utilizaci?n de la herramienta.
76 76
     */
77 77
    public void init() {
78
    	 _fsm = new LineCADToolContext(this);
78 79
    }
79 80

  
80 81
    /* (non-Javadoc)
81
     * @see com.iver.cit.gvsig.gui.cad.CADTool#end()
82
     */
83
    public void end() {
84
    }
85

  
86
    /* (non-Javadoc)
87 82
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
88 83
     */
89 84
    public void transition(double x, double y) {
......
101 96
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
102 97
     */
103 98
    public void transition(String s) {
104
        //_fsm.addOption(sel,s);
99
        _fsm.addOption(s);
105 100
    }
106 101

  
107 102
    /**
......
202 197
            firstPoint = (Point2D) lastPoint.clone();
203 198
        }
204 199
    }
200

  
205 201
}
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/PolygonCADTool.java
70 70
     * Crea un nuevo PolygonCADTool.
71 71
     */
72 72
    public PolygonCADTool() {
73
        _fsm = new PolygonCADToolContext(this);
73

  
74 74
    }
75 75

  
76 76
    /**
......
78 78
     * carga previa a la utilizaci?n de la herramienta.
79 79
     */
80 80
    public void init() {
81
    	_fsm = new PolygonCADToolContext(this);
81 82
    }
82 83

  
83 84
    /* (non-Javadoc)
84
     * @see com.iver.cit.gvsig.gui.cad.CADTool#end()
85
     */
86
    public void end() {
87
        _fsm = new PolygonCADToolContext(this);
88
    }
89

  
90
    /* (non-Javadoc)
91 85
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
92 86
     */
93 87
    public void transition(double x, double y) {
......
98 92
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
99 93
     */
100 94
    public void transition(double d) {
101
        //_fsm.addValue(sel,d);
95
        _fsm.addValue(d);
102 96
    }
103 97

  
104 98
    /* (non-Javadoc)
......
127 121
        } else if (status.equals("ExecuteMap.Second") ||
128 122
                status.equals("ExecuteMap.Third")) {
129 123
            Point2D point = new Point2D.Double(x, y);
130

  
131 124
            //Pol?gono a partir de la circunferencia.
132 125
            if (isI) {
133 126
                addGeometry(getIPolygon(point, point.distance(center)));
......
184 177
        String status = actualState.getName();
185 178

  
186 179
        if (status.equals("ExecuteMap.Second")) {
187
            if (s.equals("C") || s.equals("c")) {
180
            if (s.equals("C") || s.equals("c") || s.equals("Circunscrito")) {
188 181
                isI = false;
189
            } else if (s.equals("I") || s.equals("i")) {
182
            } else if (s.equals("I") || s.equals("i") || s.equals("Inscrito")) {
190 183
                isI = true;
191 184
            }
192 185
        }
......
291 284

  
292 285
        return new FGeometryCollection(geoms);
293 286
    }
287

  
294 288
}
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/ScaleCADTool.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.tools;
42

  
43
import java.awt.Graphics;
44
import java.awt.Graphics2D;
45
import java.awt.Image;
46
import java.awt.geom.AffineTransform;
47
import java.awt.geom.Point2D;
48
import java.awt.geom.Point2D.Double;
49
import java.io.IOException;
50

  
51
import com.iver.andami.PluginServices;
52
import com.iver.cit.gvsig.CADExtension;
53
import com.iver.cit.gvsig.fmap.core.DefaultFeature;
54
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
55
import com.iver.cit.gvsig.fmap.core.IFeature;
56
import com.iver.cit.gvsig.fmap.core.IGeometry;
57
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
58
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
59
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter;
60
import com.iver.cit.gvsig.fmap.layers.FBitSet;
61
import com.iver.cit.gvsig.gui.cad.CADTool;
62
import com.iver.cit.gvsig.gui.cad.DefaultCADTool;
63
import com.iver.cit.gvsig.gui.cad.tools.smc.ScaleCADToolContext;
64
import com.iver.cit.gvsig.gui.cad.tools.smc.ScaleCADToolContext.ScaleCADToolState;
65

  
66

  
67
/**
68
 * DOCUMENT ME!
69
 *
70
 * @author Vicente Caballero Navarro
71
 */
72
public class ScaleCADTool extends DefaultCADTool {
73
    private ScaleCADToolContext _fsm;
74
    private Point2D firstPoint;
75
    private Point2D lastPoint;
76
	private Point2D scalePoint;
77
	private Double orr;
78
	private Double frr;
79
	private Double ore;
80
	private Double fre;
81

  
82
    /**
83
     * Crea un nuevo PolylineCADTool.
84
     */
85
    public ScaleCADTool() {
86
    }
87

  
88
    /**
89
     * M?todo de incio, para poner el c?digo de todo lo que se requiera de una
90
     * carga previa a la utilizaci?n de la herramienta.
91
     */
92
    public void init() {
93
        _fsm = new ScaleCADToolContext(this);
94
    }
95

  
96
    /* (non-Javadoc)
97
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
98
     */
99
    public void transition(double x, double y) {
100
        _fsm.addPoint(x, y);
101
    }
102

  
103
    /* (non-Javadoc)
104
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
105
     */
106
    public void transition(double d) {
107
        _fsm.addValue(d);
108
    }
109

  
110
    /* (non-Javadoc)
111
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
112
     */
113
    public void transition(String s) {
114
        _fsm.addOption(s);
115
    }
116

  
117
    /**
118
     * DOCUMENT ME!
119
     */
120
    public void selection() {
121
        FBitSet selection = CADExtension.getCADToolAdapter()
122
                                        .getVectorialAdapter().getSelection();
123

  
124
        if (selection.cardinality() == 0) {
125
            CADExtension.setCADTool("selection");
126
            ((SelectionCADTool) CADExtension.getCADToolAdapter().getCadTool()).setNextTool(
127
                "scale");
128
        }
129
    }
130

  
131
    /**
132
     * Equivale al transition del prototipo pero sin pasarle como par?metro el
133
     * editableFeatureSource que ya estar? creado.
134
     *
135
     * @param x par?metro x del punto que se pase en esta transici?n.
136
     * @param y par?metro y del punto que se pase en esta transici?n.
137
     */
138
    public void addPoint(double x, double y) {
139
        ScaleCADToolState actualState = (ScaleCADToolState) _fsm.getPreviousState();
140
        String status = actualState.getName();
141
        VectorialEditableAdapter vea = getCadToolAdapter().getVectorialAdapter();
142
        FBitSet selection = vea.getSelection();
143

  
144

  
145
        if (status.equals("ExecuteMap.Initial")) {
146
				firstPoint = new Point2D.Double(x, y);
147
			    scalePoint = firstPoint;
148
		} else if (status.equals("ExecuteMap.First")) {
149
			PluginServices.getMDIManager().setWaitCursor();
150
			lastPoint = new Point2D.Double(x, y);
151

  
152
			double w;
153
			double h;
154
			w = lastPoint.getX() - firstPoint.getX();
155
			h = lastPoint.getY() - firstPoint.getY();
156

  
157
			try {
158
				double size=getCadToolAdapter().getMapControl().getViewPort().toMapDistance(getCadToolAdapter().getMapControl().getWidth());
159
				scale(firstPoint.distance(lastPoint)/(size/40));
160
			} catch (DriverIOException e) {
161
				e.printStackTrace();
162
			} catch (IOException e1) {
163
				e1.printStackTrace();
164
			}
165

  
166
			PluginServices.getMDIManager().restoreCursor();
167
		} else if (status.equals("ExecuteMap.Second")) {
168
			orr = new Point2D.Double(x, y);
169
		} else if (status.equals("ExecuteMap.Third")) {
170
			frr = new Point2D.Double(x, y);
171
		} else if (status.equals("ExecuteMap.Fourth")) {
172
			ore = new Point2D.Double(x, y);
173
			firstPoint = ore;
174
		} else if (status.equals("ExecuteMap.Fiveth")) {
175
			fre = new Point2D.Double(x, y);
176

  
177
			double distrr = orr.distance(frr);
178
			double distre = ore.distance(fre);
179
			double escalado = distre / distrr;
180

  
181
			try {
182
				scale(escalado);
183
			} catch (DriverIOException e) {
184
				e.printStackTrace();
185
			} catch (IOException e) {
186
				e.printStackTrace();
187
			}
188

  
189
		}
190

  
191

  
192

  
193

  
194
        if (status.equals("ExecuteMap.Initial")) {
195
        	firstPoint = new Point2D.Double(x, y);
196
    		} else if (status.equals("ExecuteMap.First")) {
197
    			PluginServices.getMDIManager().setWaitCursor();
198
    			lastPoint = new Point2D.Double(x,y);
199

  
200
    			double w;
201
    			double h;
202
    			w = lastPoint.getX() - firstPoint.getX();
203
    			h = lastPoint.getY() - firstPoint.getY();
204

  
205
    			try {
206
    				getCadToolAdapter().getVectorialAdapter().startComplexRow();
207

  
208
    				for (int i = selection.nextSetBit(0); i >= 0;
209
    						i = selection.nextSetBit(i + 1)) {
210
    					DefaultFeature fea = (DefaultFeature)getCadToolAdapter().getVectorialAdapter().getRow(i).cloneRow();
211
    					fea.getGeometry().rotate(-Math.atan2(w, h) + (Math.PI / 2),
212
    						firstPoint.getX(), firstPoint.getY());
213
    					getCadToolAdapter().getVectorialAdapter().modifyRow(i, fea);
214
    				}
215

  
216
    				getCadToolAdapter().getVectorialAdapter().endComplexRow();
217
    			} catch (DriverIOException e) {
218
    				e.printStackTrace();
219
    			} catch (IOException e1) {
220
    				e1.printStackTrace();
221
    			}
222

  
223
    			PluginServices.getMDIManager().restoreCursor();
224
    		}
225
    }
226

  
227
    /**
228
     * M?todo para dibujar la lo necesario para el estado en el que nos
229
     * encontremos.
230
     *
231
     * @param g Graphics sobre el que dibujar.
232
     * @param x par?metro x del punto que se pase para dibujar.
233
     * @param y par?metro x del punto que se pase para dibujar.
234
     */
235
    public void drawOperation(Graphics g, double x, double y) {
236
        ScaleCADToolState actualState = ((ScaleCADToolContext) _fsm).getState();
237
        String status = actualState.getName();
238
        VectorialEditableAdapter vea = getCadToolAdapter().getVectorialAdapter();
239
        FBitSet selection = vea.getSelection();
240
        Point2D currentPoint = new Point2D.Double(x, y);
241

  
242

  
243
        if (status.equals("ExecuteMap.First")) {
244
        	try {
245
				for (int i = 0; i < vea.getRowCount(); i++) {
246
					if (selection.get(i)) {
247
						IGeometry geometry = vea.getShape(i);
248
						double size=getCadToolAdapter().getMapControl().getViewPort().toMapDistance(getCadToolAdapter().getMapControl().getWidth());
249
						geometry.scale(firstPoint,
250
							firstPoint.distance(currentPoint)/(size/40),
251
							firstPoint.distance(currentPoint)/(size/40));
252
						geometry.draw((Graphics2D) g,
253
							getCadToolAdapter().getMapControl().getViewPort(),
254
							CADTool.modifySymbol);
255
						drawLine((Graphics2D) g, firstPoint, currentPoint);
256
						PluginServices.getMainFrame().getStatusBar().setMessage("5","Factor = "+firstPoint.distance(currentPoint)/(size/40));
257
					}
258
				}
259
			} catch (DriverIOException e) {
260
				e.printStackTrace();
261
			} catch (IOException e) {
262
				e.printStackTrace();
263
			}
264
		} else if (status.equals("ExecuteMap.Fiveth")) {
265
			try {
266
				for (int i = 0; i < vea.getRowCount(); i++) {
267
					if (selection.get(i)) {
268
						IGeometry geometry = vea.getShape(i);
269

  
270

  
271
						double distrr = orr.distance(frr);
272
						double distre = ore.distance(currentPoint);
273
						double escalado = distre / distrr;
274

  
275
						geometry.scale(scalePoint, escalado, escalado);
276
						geometry.draw((Graphics2D) g,
277
							getCadToolAdapter().getMapControl().getViewPort(),
278
							CADTool.modifySymbol);
279
						drawLine((Graphics2D) g, firstPoint,
280
							new Point2D.Double(x, y));
281
					}
282
				}
283
			} catch (DriverIOException e) {
284
				e.printStackTrace();
285
			} catch (IOException e1) {
286
				e1.printStackTrace();
287
			}
288
		}
289
    }
290

  
291
    /**
292
     * Add a diferent option.
293
     *
294
     * @param s Diferent option.
295
     */
296
    public void addOption(String s) {
297
    	ScaleCADToolState actualState = (ScaleCADToolState) _fsm.getPreviousState();
298
        String status = actualState.getName();
299
       if (status.equals("ExecuteMap.First")) {
300
			try {
301
				scale(2);
302
			} catch (DriverIOException e) {
303
				// TODO Auto-generated catch block
304
				e.printStackTrace();
305
			} catch (IOException e) {
306
				// TODO Auto-generated catch block
307
				e.printStackTrace();
308
			}
309
		}
310
    }
311

  
312
    /* (non-Javadoc)
313
     * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
314
     */
315
    public void addValue(double d) {
316
    	ScaleCADToolState actualState = (ScaleCADToolState) _fsm.getPreviousState();
317
        String status = actualState.getName();
318
        if (status.equals("ExecuteMap.First")) {
319
    			try {
320
    				scale(d);
321
    			} catch (DriverIOException e) {
322
    				e.printStackTrace();
323
    			} catch (IOException e1) {
324
    				e1.printStackTrace();
325
    			}
326

  
327
    	}
328
    }
329
    private void scale(double scaleFactor) throws DriverIOException, IOException {
330
    		VectorialEditableAdapter vea=getCadToolAdapter().getVectorialAdapter();
331
    		vea.startComplexRow();
332
    		FBitSet selection=vea.getSelection();
333
    		for (int i = 0; i < vea.getRowCount(); i++) {
334
    			if (selection.get(i)) {
335
    				DefaultFeature df=vea.getRow(i).cloneRow();
336
    				df.getGeometry().scale(scalePoint, scaleFactor, scaleFactor);
337
    				vea.modifyRow(i, df);
338
    			}
339
    		}
340
    		vea.endComplexRow();
341
    	}
342
}
0 343

  
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/PointCADTool.java
60 60
     * Crea un nuevo PointCADTool.
61 61
     */
62 62
    public PointCADTool() {
63
        _fsm = new PointCADToolContext(this);
63

  
64 64
    }
65 65

  
66 66
    /**
......
68 68
     * carga previa a la utilizaci?n de la herramienta.
69 69
     */
70 70
    public void init() {
71
    	_fsm = new PointCADToolContext(this);
71 72
    }
72 73

  
73 74
    /**
......
92 93
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
93 94
     */
94 95
    public void transition(String s) {
95
        // TODO Auto-generated method stub
96
        _fsm.addOption(s);
96 97
    }
97 98

  
98 99
    /**
......
137 138
    }
138 139

  
139 140
    /* (non-Javadoc)
140
     * @see com.iver.cit.gvsig.gui.cad.CADTool#end()
141
     */
142
    public void end() {
143
        // TODO Auto-generated method stub
144
    }
145

  
146
    /* (non-Javadoc)
147 141
     * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
148 142
     */
149 143
    public void addValue(double d) {
150 144
        // TODO Auto-generated method stub
151 145
    }
146

  
152 147
}
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/CopyCADTool.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.tools;
42

  
43
import com.iver.andami.PluginServices;
44

  
45
import com.iver.cit.gvsig.CADExtension;
46
import com.iver.cit.gvsig.fmap.core.DefaultFeature;
47
import com.iver.cit.gvsig.fmap.core.IGeometry;
48
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
49
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter;
50
import com.iver.cit.gvsig.fmap.layers.FBitSet;
51
import com.iver.cit.gvsig.gui.cad.CADTool;
52
import com.iver.cit.gvsig.gui.cad.DefaultCADTool;
53
import com.iver.cit.gvsig.gui.cad.tools.smc.CopyCADToolContext;
54
import com.iver.cit.gvsig.gui.cad.tools.smc.CopyCADToolContext.CopyCADToolState;
55

  
56
import java.awt.Graphics;
57
import java.awt.Graphics2D;
58
import java.awt.geom.Point2D;
59

  
60
import java.io.IOException;
61

  
62

  
63
/**
64
 * DOCUMENT ME!
65
 *
66
 * @author Vicente Caballero Navarro
67
 */
68
public class CopyCADTool extends DefaultCADTool {
69
    private CopyCADToolContext _fsm;
70
    private Point2D firstPoint;
71
    private Point2D lastPoint;
72

  
73
    /**
74
     * Crea un nuevo PolylineCADTool.
75
     */
76
    public CopyCADTool() {
77
    }
78

  
79
    /**
80
     * M?todo de incio, para poner el c?digo de todo lo que se requiera de una
81
     * carga previa a la utilizaci?n de la herramienta.
82
     */
83
    public void init() {
84
        _fsm = new CopyCADToolContext(this);
85
    }
86

  
87
    /* (non-Javadoc)
88
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
89
     */
90
    public void transition(double x, double y) {
91
        _fsm.addPoint(x, y);
92
    }
93

  
94
    /* (non-Javadoc)
95
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
96
     */
97
    public void transition(double d) {
98
        //_fsm.addValue(sel,d);
99
    }
100

  
101
    /* (non-Javadoc)
102
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
103
     */
104
    public void transition(String s) {
105
        _fsm.addOption(s);
106
    }
107

  
108
    /**
109
     * DOCUMENT ME!
110
     */
111
    public void selection() {
112
        FBitSet selection = CADExtension.getCADToolAdapter()
113
                                        .getVectorialAdapter().getSelection();
114

  
115
        if (selection.cardinality() == 0) {
116
            CADExtension.setCADTool("selection");
117
            ((SelectionCADTool) CADExtension.getCADToolAdapter().getCadTool()).setNextTool(
118
                "copy");
119
        }
120
    }
121

  
122
    /**
123
     * Equivale al transition del prototipo pero sin pasarle como par?metro el
124
     * editableFeatureSource que ya estar? creado.
125
     *
126
     * @param x par?metro x del punto que se pase en esta transici?n.
127
     * @param y par?metro y del punto que se pase en esta transici?n.
128
     */
129
    public void addPoint(double x, double y) {
130
        CopyCADToolState actualState = (CopyCADToolState) _fsm.getPreviousState();
131
        String status = actualState.getName();
132
        VectorialEditableAdapter vea = getCadToolAdapter().getVectorialAdapter();
133
        FBitSet selection = vea.getSelection();
134

  
135
        if (status.equals("ExecuteMap.Initial")) {
136
            firstPoint = new Point2D.Double(x, y);
137
        } else if (status.equals("ExecuteMap.First")) {
138
            PluginServices.getMDIManager().setWaitCursor();
139
            lastPoint = new Point2D.Double(x, y);
140
            vea.startComplexRow();
141

  
142
            try {
143
                for (int i = selection.nextSetBit(0); i >= 0;
144
                        i = selection.nextSetBit(i + 1)) {
145
                    DefaultFeature fea = (DefaultFeature) vea.getRow(i)
146
                                                             .getLinkedRow()
147
                                                             .cloneRow();
148
                    fea.getGeometry().move(lastPoint.getX() -
149
                        firstPoint.getX(), lastPoint.getY() -
150
                        firstPoint.getY());
151

  
152
                    vea.addRow(fea);
153
                }
154

  
155
                vea.endComplexRow();
156
            } catch (DriverIOException e) {
157
                // TODO Auto-generated catch block
158
                e.printStackTrace();
159
            } catch (IOException e) {
160
                // TODO Auto-generated catch block
161
                e.printStackTrace();
162
            }
163

  
164
            selection.clear();
165
            PluginServices.getMDIManager().restoreCursor();
166

  
167
            //ret = ret | copyStatus.transition("cancel");
168
        }
169
    }
170

  
171
    /**
172
     * M?todo para dibujar la lo necesario para el estado en el que nos
173
     * encontremos.
174
     *
175
     * @param g Graphics sobre el que dibujar.
176
     * @param x par?metro x del punto que se pase para dibujar.
177
     * @param y par?metro x del punto que se pase para dibujar.
178
     */
179
    public void drawOperation(Graphics g, double x, double y) {
180
        CopyCADToolState actualState = ((CopyCADToolContext) _fsm).getState();
181
        String status = actualState.getName();
182
        VectorialEditableAdapter vea = getCadToolAdapter().getVectorialAdapter();
183
        FBitSet selection = vea.getSelection();
184

  
185
        try {
186
            drawHandlers(g, selection,
187
                getCadToolAdapter().getMapControl().getViewPort()
188
                    .getAffineTransform());
189
        } catch (DriverIOException e) {
190
            // TODO Auto-generated catch block
191
            e.printStackTrace();
192
        }
193

  
194
        if (status.equals("ExecuteMap.First")) {
195
            ///int dx = getCadToolAdapter().getMapControl().getViewPort().fromMapDistance(x - firstPoint.getX());
196
            ///int dy = -getCadToolAdapter().getMapControl().getViewPort().fromMapDistance(y - firstPoint.getY());
197
            ///Image img = getCadToolAdapter().getVectorialAdapter().getImage();
198
            ///g.drawImage(img, dx, dy, null);
199
            try {
200
                for (int i = selection.nextSetBit(0); i >= 0;
201
                        i = selection.nextSetBit(i + 1)) {
202
                    IGeometry geometry = vea.getShape(i).cloneGeometry();
203
                    geometry.move(x - firstPoint.getX(), y - firstPoint.getY());
204
                    geometry.draw((Graphics2D) g,
205
                        getCadToolAdapter().getMapControl().getViewPort(),
206
                        CADTool.drawingSymbol);
207
                }
208
            } catch (DriverIOException e) {
209
                e.printStackTrace();
210
            }
211
        }
212
    }
213

  
214
    /**
215
     * Add a diferent option.
216
     *
217
     * @param s Diferent option.
218
     */
219
    public void addOption(String s) {
220
    }
221

  
222
    /* (non-Javadoc)
223
     * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
224
     */
225
    public void addValue(double d) {
226
    }
227
}
0 228

  
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/PolylineCADTool.java
75 75
     * Crea un nuevo PolylineCADTool.
76 76
     */
77 77
    public PolylineCADTool() {
78
        _fsm = new PolylineCADToolContext(this);
78

  
79 79
    }
80 80

  
81 81
    /**
......
83 83
     * carga previa a la utilizaci?n de la herramienta.
84 84
     */
85 85
    public void init() {
86
    	_fsm = new PolylineCADToolContext(this);
86 87
    }
87 88

  
88
    /* (non-Javadoc)
89
     * @see com.iver.cit.gvsig.gui.cad.CADTool#end()
90
     */
91
    public void end() {
89
    public void endGeometry() {
92 90
    	IGeometry[] geoms = (IGeometry[]) list.toArray(new IGeometry[0]);
93 91
        FGeometryCollection fgc = new FGeometryCollection(geoms);
94 92
        addGeometry(fgc);
95 93
        _fsm = new PolylineCADToolContext(this);
96
        firstPoint = null;
94
        list.clear();
95
        antantPoint=antCenter=antInter=antPoint=firstPoint=null;
97 96
    }
97
    public void closeGeometry(){
98
    	GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
99
				2);
100
		elShape.moveTo(antPoint.getX(), antPoint.getY());
101
		elShape.lineTo(firstPoint.getX(), firstPoint.getY());
98 102

  
103
		list.add(ShapeFactory.createPolyline2D(elShape));
104
		list.add(ShapeFactory.createPolyline2D(elShape));
105

  
106
    }
99 107
    /* (non-Javadoc)
100 108
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
101 109
     */
102 110
    public void transition(double x, double y) {
103
        _fsm.addPoint(x, y);
111
        ((PolylineCADToolContext)_fsm).addPoint(x, y);
104 112
    }
105 113

  
106 114
    /* (non-Javadoc)
......
114 122
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
115 123
     */
116 124
    public void transition(String s) {
117
        _fsm.addOption(s);
125
        ((PolylineCADToolContext)_fsm).addOption(s);
118 126
    }
119 127

  
120 128
    /**
......
126 134
     * @param y par?metro y del punto que se pase en esta transici?n.
127 135
     */
128 136
    public void addPoint(double x, double y) {
129
        PolylineCADToolState actualState = (PolylineCADToolState) _fsm.getPreviousState();
137
    	PolylineCADToolState actualState = (PolylineCADToolState) _fsm.getPreviousState();
130 138
        String status = actualState.getName();
131 139

  
132 140
        if (status.equals("ExecuteMap.Initial")) {
......
269 277
     */
270 278
    public void drawOperation(Graphics g, double x,
271 279
        double y) {
272
        PolylineCADToolState actualState = _fsm.getState();
280
        PolylineCADToolState actualState = ((PolylineCADToolContext)_fsm).getState();
273 281
        String status = actualState.getName();
274 282

  
275 283
        if (status.equals("ExecuteMap.First")) {
......
421 429
     */
422 430
    public void addValue(double d) {
423 431
    }
432

  
433
    public void cancel(){
434
    	list.clear();
435
    	antantPoint=antCenter=antInter=antPoint=firstPoint=null;
436
    }
424 437
}
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/smc/EllipseCADToolContext.java
23 23
        ExecuteMap.Initial.Entry(this);
24 24
    }
25 25

  
26
    public void addOption(String s)
27
    {
28
        _transition = "addOption";
29
        getState().addOption(this, s);
30
        _transition = "";
31
        return;
32
    }
33

  
26 34
    public void addPoint(double pointX, double pointY)
27 35
    {
28 36
        _transition = "addPoint";
......
81 89
        protected void Entry(EllipseCADToolContext context) {}
82 90
        protected void Exit(EllipseCADToolContext context) {}
83 91

  
92
        protected void addOption(EllipseCADToolContext context, String s)
93
        {
94
            Default(context);
95
        }
96

  
84 97
        protected void addPoint(EllipseCADToolContext context, double pointX, double pointY)
85 98
        {
86 99
            Default(context);
......
150 163
            super (name, id);
151 164
        }
152 165

  
166
        protected void addOption(EllipseCADToolContext context, String s)
167
        {
168
            EllipseCADTool ctxt = context.getOwner();
169

  
170
            if (s.equals("Cancelar"))
171
            {
172
                boolean loopbackFlag =
173
                    context.getState().getName().equals(
174
                        ExecuteMap.Initial.getName());
175

  
176
                if (loopbackFlag == false)
177
                {
178
                    (context.getState()).Exit(context);
179
                }
180

  
181
                context.clearState();
182
                try
183
                {
184
                    ctxt.end();
185
                }
186
                finally
187
                {
188
                    context.setState(ExecuteMap.Initial);
189

  
190
                    if (loopbackFlag == false)
191
                    {
192
                        (context.getState()).Entry(context);
193
                    }
194

  
195
                }
196
            }
197
            else
198
            {
199
                super.addOption(context, s);
200
            }
201

  
202
            return;
203
        }
204

  
153 205
    //-----------------------------------------------------------
154 206
    // Inner classse.
155 207
    //
......
171 223
            {
172 224
                EllipseCADTool ctxt = context.getOwner();
173 225

  
174
                ctxt.init();
175 226
                ctxt.setQuestion("ELIPSE" + "\n" +
176 227
		"Insertar punto inicial de eje de elipse");
228
                ctxt.setDescription(new String[]{"Cancelar"});
177 229
                return;
178 230
            }
179 231

  
......
187 239
                try
188 240
                {
189 241
                    ctxt.setQuestion("Insertar punto final de eje de elipse");
242
                    ctxt.setDescription(new String[]{"Cancelar"});
190 243
                    ctxt.addPoint(pointX, pointY);
191 244
                }
192 245
                finally
......
224 277
                try
225 278
                {
226 279
                    ctxt.setQuestion("Insertar distancia al otro eje");
280
                    ctxt.setDescription(new String[]{"Cancelar"});
227 281
                    ctxt.addPoint(pointX, pointY);
228 282
                }
229 283
                finally
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/smc/RotateCADToolContext.java
1

  
2
//
3
// Vicente Caballero Navarro
4

  
5

  
6
package com.iver.cit.gvsig.gui.cad.tools.smc;
7

  
8
import com.iver.cit.gvsig.gui.cad.tools.RotateCADTool;
9

  
10
public final class RotateCADToolContext
11
    extends statemap.FSMContext
12
{
13
//---------------------------------------------------------------
14
// Member methods.
15
//
16

  
17
    public RotateCADToolContext(RotateCADTool owner)
18
    {
19
        super();
20

  
21
        _owner = owner;
22
        setState(ExecuteMap.Initial);
23
        ExecuteMap.Initial.Entry(this);
24
    }
25

  
26
    public void addOption(String s)
27
    {
28
        _transition = "addOption";
29
        getState().addOption(this, s);
30
        _transition = "";
31
        return;
32
    }
33

  
34
    public void addPoint(double pointX, double pointY)
35
    {
36
        _transition = "addPoint";
37
        getState().addPoint(this, pointX, pointY);
38
        _transition = "";
39
        return;
40
    }
41

  
42
    public void addValue(double d)
43
    {
44
        _transition = "addValue";
45
        getState().addValue(this, d);
46
        _transition = "";
47
        return;
48
    }
49

  
50
    public RotateCADToolState getState()
51
        throws statemap.StateUndefinedException
52
    {
53
        if (_state == null)
54
        {
55
            throw(
56
                new statemap.StateUndefinedException());
57
        }
58

  
59
        return ((RotateCADToolState) _state);
60
    }
61

  
62
    protected RotateCADTool getOwner()
63
    {
64
        return (_owner);
65
    }
66

  
67
//---------------------------------------------------------------
68
// Member data.
69
//
70

  
71
    transient private RotateCADTool _owner;
72

  
73
//---------------------------------------------------------------
74
// Inner classes.
75
//
76

  
77
    public static abstract class RotateCADToolState
78
        extends statemap.State
79
    {
80
    //-----------------------------------------------------------
81
    // Member methods.
82
    //
83

  
84
        protected RotateCADToolState(String name, int id)
85
        {
86
            super (name, id);
87
        }
88

  
89
        protected void Entry(RotateCADToolContext context) {}
90
        protected void Exit(RotateCADToolContext context) {}
91

  
92
        protected void addOption(RotateCADToolContext context, String s)
93
        {
94
            Default(context);
95
        }
96

  
97
        protected void addPoint(RotateCADToolContext context, double pointX, double pointY)
98
        {
99
            Default(context);
100
        }
101

  
102
        protected void addValue(RotateCADToolContext context, double d)
103
        {
104
            Default(context);
105
        }
106

  
107
        protected void Default(RotateCADToolContext context)
108
        {
109
            throw (
110
                new statemap.TransitionUndefinedException(
111
                    "State: " +
112
                    context.getState().getName() +
113
                    ", Transition: " +
114
                    context.getTransition()));
115
        }
116

  
117
    //-----------------------------------------------------------
118
    // Member data.
119
    //
120
    }
121

  
122
    /* package */ static abstract class ExecuteMap
123
    {
124
    //-----------------------------------------------------------
125
    // Member methods.
126
    //
127

  
128
    //-----------------------------------------------------------
129
    // Member data.
130
    //
131

  
132
        //-------------------------------------------------------
133
        // Statics.
134
        //
135
        /* package */ static ExecuteMap_Default.ExecuteMap_Initial Initial;
136
        /* package */ static ExecuteMap_Default.ExecuteMap_First First;
137
        /* package */ static ExecuteMap_Default.ExecuteMap_Second Second;
138
        private static ExecuteMap_Default Default;
139

  
140
        static
141
        {
142
            Initial = new ExecuteMap_Default.ExecuteMap_Initial("ExecuteMap.Initial", 0);
143
            First = new ExecuteMap_Default.ExecuteMap_First("ExecuteMap.First", 1);
144
            Second = new ExecuteMap_Default.ExecuteMap_Second("ExecuteMap.Second", 2);
145
            Default = new ExecuteMap_Default("ExecuteMap.Default", -1);
146
        }
147

  
148
    }
149

  
150
    protected static class ExecuteMap_Default
151
        extends RotateCADToolState
152
    {
153
    //-----------------------------------------------------------
154
    // Member methods.
155
    //
156

  
157
        protected ExecuteMap_Default(String name, int id)
158
        {
159
            super (name, id);
160
        }
161

  
162
        protected void addOption(RotateCADToolContext context, String s)
163
        {
164
            RotateCADTool ctxt = context.getOwner();
165

  
166
            if (s.equals("Cancelar"))
167
            {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff