Revision 28764

View differences:

branches/v2_0_0_prep/extensions/extEditing/config/config.xml
193 193
				<selectable-tool icon="edition-geometry-stretch" action-command="_stretch" tooltip="stretch" group="vista" position="12"/>
194 194
			</tool-bar>
195 195
		</extension>
196
		<!--extension class-name="com.iver.cit.gvsig.ExtendExtension"
197
			description="Extensi?n encargada de alargar geometr?as en una capa en edici?n."
198
			active="true">
199
			<menu text="geometry/modify/extend" action-command="_extend" icon="edition-modify-geometry-extend"/>
200
			<tool-bar name="modificar" position="31">
201
				<selectable-tool icon="edition-modify-geometry-extend" action-command="_extend" tooltip="extend" group="vista" position="13"/>
202
			</tool-bar>
203
		</extension-->
204 196
		<extension class-name="com.iver.cit.gvsig.ComplexSelectionGeometryExtension"
205 197
			description="Extensi?n encargada de la selecci?n compleja de geometr?as."
206 198
			active="true">
branches/v2_0_0_prep/extensions/extEditing/src/com/iver/cit/gvsig/ExtendExtension.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;
42

  
43
import org.gvsig.fmap.dal.exception.DataException;
44
import org.gvsig.fmap.dal.exception.ReadException;
45
import org.gvsig.fmap.dal.feature.FeatureSelection;
46
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
47
import org.gvsig.fmap.mapcontrol.MapControl;
48

  
49
import com.iver.andami.PluginServices;
50
import com.iver.andami.messages.NotificationManager;
51
import com.iver.andami.plugins.Extension;
52
import com.iver.cit.gvsig.gui.cad.tools.ExtendCADTool;
53
import com.iver.cit.gvsig.layers.VectorialLayerEdited;
54
import com.iver.cit.gvsig.project.documents.view.gui.View;
55

  
56
/**
57
 * Extensi?n que gestiona el alargar una geometr?a.
58
 *
59
 * @author Vicente Caballero Navarro
60
 */
61
public class ExtendExtension extends Extension {
62
	private View view;
63

  
64
	private MapControl mapControl;
65
	private ExtendCADTool extend;
66

  
67
	/**
68
	 * @see com.iver.andami.plugins.IExtension#initialize()
69
	 */
70
	public void initialize() {
71
		extend=new ExtendCADTool();
72
		CADExtension.addCADTool("_extend",extend);
73

  
74
		registerIcons();
75
	}
76

  
77
	private void registerIcons(){
78
		PluginServices.getIconTheme().registerDefault(
79
				"edition-modify-geometry-extend",
80
				this.getClass().getClassLoader().getResource("images/Extend.png")
81
			);
82

  
83
	}
84

  
85
	/**
86
	 * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
87
	 */
88
	public void execute(String s) {
89
		CADExtension.initFocus();
90
		if (s.equals("_extend")) {
91
        	CADExtension.setCADTool(s,true);
92
        }
93
		CADExtension.getEditionManager().setMapControl(mapControl);
94
		CADExtension.getCADToolAdapter().configureMenu();
95
	}
96

  
97
	/**
98
	 * @see com.iver.andami.plugins.IExtension#isEnabled()
99
	 */
100
	public boolean isEnabled() {
101

  
102
		try {
103
			if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) {
104
				view = (View) PluginServices.getMDIManager().getActiveWindow();
105
				mapControl = view.getMapControl();
106
				EditionManager em=CADExtension.getEditionManager();
107
				if (em.getActiveLayerEdited()==null)
108
					return false;
109
				VectorialLayerEdited vle=(VectorialLayerEdited)em.getActiveLayerEdited();
110
				if (((FeatureSelection)vle.getFeatureStore().getSelection()).getSize()<1)
111
					return false;
112
				FLyrVect lv=(FLyrVect)vle.getLayer();
113
//				ArrayList selectedRows=vle.getSelectedRow();
114
//				if (selectedRows.size()<1) {
115
//					return false;
116
//				}
117
				if (extend.isApplicable(lv.getShapeType())){
118
					return true;
119
				}
120
			}
121
		} catch (ReadException e) {
122
			NotificationManager.addError(e.getMessage(),e);
123
		} catch (DataException e) {
124
			NotificationManager.addError(e.getMessage(),e);
125
		}
126
		return false;
127
	}
128

  
129
	/**
130
	 * @see com.iver.andami.plugins.IExtension#isVisible()
131
	 */
132
	public boolean isVisible() {
133
		if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE)
134
			return true;
135
		return false;
136
	}
137
}
branches/v2_0_0_prep/extensions/extEditing/src/com/iver/cit/gvsig/gui/cad/tools/ExtendCADTool.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.event.InputEvent;
45
import java.awt.geom.PathIterator;
46
import java.awt.geom.Point2D;
47
import java.util.ArrayList;
48

  
49
import org.gvsig.fmap.dal.exception.DataException;
50
import org.gvsig.fmap.dal.exception.ReadException;
51
import org.gvsig.fmap.dal.feature.DisposableIterator;
52
import org.gvsig.fmap.dal.feature.EditableFeature;
53
import org.gvsig.fmap.dal.feature.Feature;
54
import org.gvsig.fmap.dal.feature.FeatureSelection;
55
import org.gvsig.fmap.dal.feature.FeatureSet;
56
import org.gvsig.fmap.dal.feature.FeatureStore;
57
import org.gvsig.fmap.geom.Geometry;
58
import org.gvsig.fmap.geom.primitive.GeneralPathX;
59
import org.gvsig.fmap.geom.util.Converter;
60
import org.gvsig.fmap.geom.util.UtilFunctions;
61

  
62
import com.iver.andami.PluginServices;
63
import com.iver.andami.messages.NotificationManager;
64
import com.iver.cit.gvsig.CADExtension;
65
import com.iver.cit.gvsig.gui.cad.DefaultCADTool;
66
import com.iver.cit.gvsig.gui.cad.exception.CommandException;
67
import com.iver.cit.gvsig.gui.cad.tools.smc.ExtendCADToolContext;
68
import com.iver.cit.gvsig.gui.cad.tools.smc.ExtendCADToolContext.ExtendCADToolState;
69
import com.iver.cit.gvsig.layers.VectorialLayerEdited;
70

  
71
/**
72
 * DOCUMENT ME!
73
 *
74
 * @author Vicente Caballero Navarro
75
 */
76
public class ExtendCADTool extends DefaultCADTool {
77
	private ExtendCADToolContext _fsm;
78

  
79
	/**
80
	 * Crea un nuevo ExtendCADTool.
81
	 */
82
	public ExtendCADTool() {
83
	}
84

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

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

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

  
113
	/*
114
	 * (non-Javadoc)
115
	 *
116
	 * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet,
117
	 *      java.lang.String)
118
	 */
119
	public void transition(String s) throws CommandException {
120
		if (!super.changeCommand(s)) {
121
			_fsm.addOption(s);
122
		}
123
	}
124

  
125
	/**
126
	 * DOCUMENT ME!
127
	 */
128
	public void selection() {
129
		FeatureSet selection = null;
130
		try {
131
			selection = (FeatureSet) getVLE().getFeatureStore().getSelection();
132

  
133
			if (selection.getSize() == 0
134
					&& !CADExtension
135
							.getCADTool()
136
							.getClass()
137
							.getName()
138
							.equals(
139
									"com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) {
140
				CADExtension.setCADTool("_selection", false);
141
				((SelectionCADTool) CADExtension.getCADTool())
142
						.setNextTool("_extend");
143
			}
144
		} catch (ReadException e) {
145
			// TODO Auto-generated catch block
146
			e.printStackTrace();
147
		} catch (DataException e) {
148
			// TODO Auto-generated catch block
149
			e.printStackTrace();
150
		}
151
	}
152

  
153
	/**
154
	 * Equivale al transition del prototipo pero sin pasarle como par?metro el
155
	 * editableFeatureSource que ya estar? creado.
156
	 *
157
	 * @param x
158
	 *            par?metro x del punto que se pase en esta transici?n.
159
	 * @param y
160
	 *            par?metro y del punto que se pase en esta transici?n.
161
	 */
162
	public void addPoint(double x, double y, InputEvent event) {
163
		ExtendCADToolState actualState = (ExtendCADToolState) _fsm
164
				.getPreviousState();
165
		String status = actualState.getName();
166

  
167
		if (status.equals("Extend.SelectGeometryToExtend")) {
168

  
169
			VectorialLayerEdited vle = getVLE();
170
			FeatureStore featureStore = null;
171
			DisposableIterator iterator = null;
172
			try {
173
				featureStore = vle.getFeatureStore();
174

  
175
				featureStore.beginEditingGroup(getName());
176

  
177
				iterator = ((FeatureSelection) featureStore.getSelection())
178
						.iterator();
179

  
180
				// ArrayList selectedRow=getSelectedRows();
181
				ArrayList selectedRowAux = new ArrayList();
182
				// for (int i=0;i<selectedRow.size();i++) {
183
				// selectedRowAux.addAll(selectedRow);
184
				// }
185
				// selection();
186
				vle.selectWithPoint(x, y, false);
187
				// ArrayList newSelectedRow=new ArrayList();
188
				while (iterator.hasNext()) {
189
					Feature feature = (Feature) iterator.next();
190

  
191
					// }
192
					// for (int i=0;i<selectedRowAux.size();i++) {
193
					// IRowEdited edRow1 = (IRowEdited) selectedRowAux.get(i);
194
					// DefaultFeature fea1 = (DefaultFeature)
195
					// edRow1.getLinkedRow().cloneRow();
196
					Geometry geometry1 = (feature
197
							.getDefaultGeometry()).cloneGeometry();
198

  
199
					// IRowEdited edRow2 = (IRowEdited) newSelectedRow.get(i);
200
					// DefaultFeature fea2 = (DefaultFeature)
201
					// edRow2.getLinkedRow().cloneRow();
202
					Geometry geometry2 = (feature
203
							.getDefaultGeometry()).cloneGeometry();
204
					// for (int j=0;j<newSelectedRow.size();j++) {
205
					// if (geometry1 instanceof FPolygon2D) {
206
					EditableFeature eFeature = feature.getEditable();
207
					eFeature.setGeometry(featureStore.getDefaultFeatureType()
208
							.getDefaultGeometryAttributeName(),
209
							intersectsGeometry(geometry2, geometry1));
210
					// fea2.setGeometry(intersectsGeometry(geometry2,geometry1));
211
					// }
212
					// }
213
					featureStore.update(eFeature);
214
					// vea.modifyRow(edRow2.getIndex(),fea2,getName(),EditionEvent.GRAPHIC);
215
					clearSelection();
216
					// newSelectedRow.add(new
217
					// DefaultRowEdited(fea2,IRowEdited.STATUS_MODIFIED,edRow2.getIndex()));
218
				}
219

  
220
				featureStore.endEditingGroup();
221
				// vle.setSelectionCache(VectorialLayerEdited.NOTSAVEPREVIOUS,
222
				// newSelectedRow);
223
			} catch (DataException e) {
224
				NotificationManager.addError(e.getMessage(), e);
225
			} finally {
226
				if (iterator != null) {
227
					iterator.dispose();
228
				}
229
			}
230
		}
231
	}
232

  
233
	private Geometry intersectsGeometry(Geometry geometry1, Geometry geometry2) {
234
		Point2D p3 = null;
235
		Point2D p4 = null;
236
		Point2D p1 = null;
237
		Point2D p2 = null;
238
		GeneralPathX gpx = new GeneralPathX();
239
		PathIterator theIterator = geometry1.getInternalShape()
240
				.getPathIterator(null, Converter.FLATNESS);
241
		boolean first = true;
242
		double[] theData = new double[6];
243
		int theType;
244
		while (!theIterator.isDone()) {
245
			theType = theIterator.currentSegment(theData);
246
			switch (theType) {
247

  
248
			case PathIterator.SEG_MOVETO:
249
				p1 = new Point2D.Double(theData[0], theData[1]);
250
				gpx.moveTo(p1.getX(), p1.getY());
251
				break;
252

  
253
			case PathIterator.SEG_LINETO:
254
				p2 = new Point2D.Double(theData[0], theData[1]);
255
				ArrayList lines = getLines(geometry2);
256
				boolean isLineTo = true;
257
				for (int i = 0; i < lines.size(); i++) {
258
					Point2D[] ps1 = (Point2D[]) lines.get(i);
259
					Point2D p = UtilFunctions.getIntersection(ps1[0], ps1[1],
260
							p1, p2);
261
					// GeneralPathX gpxAux=new GeneralPathX();
262
					// gpxAux.moveTo(p.getX(),p.getY());
263
					// gpxAux.lineTo(ps1[0].getX(),ps1[0].getY());
264
					// Geometry
265
					// gjts1=FConverter.java2d_to_jts((FShape)ShapeFactory.createPolyline2D(gpxAux).getInternalShape());
266
					// Geometry
267
					// gjts2=FConverter.java2d_to_jts((FShape)geometry2.getInternalShape());
268
					// GeometryCollection
269
					// result=(GeometryCollection)gjts1.intersection(gjts2);
270
					// Point point=(Point)result.getGeometryN(1);
271
					// p=new Point2D.Double(point.getX(),point.getY());
272
					if (p != null && first) {
273
						gpx.lineTo(p.getX(), p.getY());
274
						first = false;
275
						isLineTo = false;
276
						break;
277
					} else {
278
						// gpx.lineTo(p2.getX(),p2.getY());
279
					}
280
				}
281
				if (!first && isLineTo) {
282
					gpx.lineTo(p2.getX(), p2.getY());
283
				}
284

  
285
				break;
286

  
287
			} // end switch
288

  
289
			theIterator.next();
290
		} // end while loop
291
		return createCurve(gpx);
292
	}
293

  
294
	private ArrayList getLines(Geometry geometry1) {
295
		Point2D p1 = null;
296
		Point2D p2 = null;
297
		ArrayList lines = new ArrayList();
298
		PathIterator theIterator = geometry1.getInternalShape()
299
				.getPathIterator(null, Converter.FLATNESS);
300
		double[] theData = new double[6];
301
		int theType;
302
		while (!theIterator.isDone()) {
303
			theType = theIterator.currentSegment(theData);
304
			switch (theType) {
305
			case PathIterator.SEG_MOVETO:
306
				p1 = new Point2D.Double(theData[0], theData[1]);
307
				break;
308

  
309
			case PathIterator.SEG_LINETO:
310
				p2 = new Point2D.Double(theData[0], theData[1]);
311
				lines.add(new Point2D[] { p1, p2 });
312
				break;
313

  
314
			} // end switch
315

  
316
			theIterator.next();
317
		} // end while loop
318
		return lines;
319
	}
320

  
321
	/**
322
	 * M?todo para dibujar la lo necesario para el estado en el que nos
323
	 * encontremos.
324
	 *
325
	 * @param g
326
	 *            Graphics sobre el que dibujar.
327
	 * @param x
328
	 *            par?metro x del punto que se pase para dibujar.
329
	 * @param y
330
	 *            par?metro x del punto que se pase para dibujar.
331
	 */
332
	public void drawOperation(Graphics g, double x, double y) {
333
	}
334

  
335
	/**
336
	 * Add a diferent option.
337
	 *
338
	 * @param s
339
	 *            Diferent option.
340
	 */
341
	public void addOption(String s) {
342
	}
343

  
344
	/*
345
	 * (non-Javadoc)
346
	 *
347
	 * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
348
	 */
349
	public void addValue(double d) {
350
	}
351

  
352
	public String getName() {
353
		return PluginServices.getText(this, "extend_");
354
	}
355

  
356
	public String toString() {
357
		return "_extend";
358
	}
359

  
360
	public boolean isApplicable(int shapeType) {
361
		switch (shapeType) {
362
		case Geometry.TYPES.CURVE:
363
		case Geometry.TYPES.GEOMETRY:
364
			return true;
365
		}
366
		return false;
367
	}
368

  
369
}
branches/v2_0_0_prep/extensions/extEditing/src/com/iver/cit/gvsig/gui/cad/tools/smc/ExtendCADToolContext.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.ExtendCADTool;
9
import java.awt.event.InputEvent;
10
import com.iver.andami.PluginServices;
11

  
12
public final class ExtendCADToolContext
13
    extends statemap.FSMContext
14
{
15
//---------------------------------------------------------------
16
// Member methods.
17
//
18

  
19
    public ExtendCADToolContext(ExtendCADTool owner)
20
    {
21
        super();
22

  
23
        _owner = owner;
24
        setState(Extend.SelectGeometryToExtend);
25
        Extend.SelectGeometryToExtend.Entry(this);
26
    }
27

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

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

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

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

  
61
        return ((ExtendCADToolState) _state);
62
    }
63

  
64
    protected ExtendCADTool getOwner()
65
    {
66
        return (_owner);
67
    }
68

  
69
//---------------------------------------------------------------
70
// Member data.
71
//
72

  
73
    transient private ExtendCADTool _owner;
74

  
75
//---------------------------------------------------------------
76
// Inner classes.
77
//
78

  
79
    public static abstract class ExtendCADToolState
80
        extends statemap.State
81
    {
82
    //-----------------------------------------------------------
83
    // Member methods.
84
    //
85

  
86
        protected ExtendCADToolState(String name, int id)
87
        {
88
            super (name, id);
89
        }
90

  
91
        protected void Entry(ExtendCADToolContext context) {}
92
        protected void Exit(ExtendCADToolContext context) {}
93

  
94
        protected void addOption(ExtendCADToolContext context, String s)
95
        {
96
            Default(context);
97
        }
98

  
99
        protected void addPoint(ExtendCADToolContext context, double pointX, double pointY, InputEvent event)
100
        {
101
            Default(context);
102
        }
103

  
104
        protected void addValue(ExtendCADToolContext context, double d)
105
        {
106
            Default(context);
107
        }
108

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

  
119
    //-----------------------------------------------------------
120
    // Member data.
121
    //
122
    }
123

  
124
    /* package */ static abstract class Extend
125
    {
126
    //-----------------------------------------------------------
127
    // Member methods.
128
    //
129

  
130
    //-----------------------------------------------------------
131
    // Member data.
132
    //
133

  
134
        //-------------------------------------------------------
135
        // Statics.
136
        //
137
        /* package */ static Extend_Default.Extend_SelectGeometryToExtend SelectGeometryToExtend;
138
        private static Extend_Default Default;
139

  
140
        static
141
        {
142
            SelectGeometryToExtend = new Extend_Default.Extend_SelectGeometryToExtend("Extend.SelectGeometryToExtend", 0);
143
            Default = new Extend_Default("Extend.Default", -1);
144
        }
145

  
146
    }
147

  
148
    protected static class Extend_Default
149
        extends ExtendCADToolState
150
    {
151
    //-----------------------------------------------------------
152
    // Member methods.
153
    //
154

  
155
        protected Extend_Default(String name, int id)
156
        {
157
            super (name, id);
158
        }
159

  
160
        protected void addOption(ExtendCADToolContext context, String s)
161
        {
162
            ExtendCADTool ctxt = context.getOwner();
163

  
164
            if (s.equals(PluginServices.getText(this,"cancel")))
165
            {
166
                boolean loopbackFlag =
167
                    context.getState().getName().equals(
168
                        Extend.SelectGeometryToExtend.getName());
169

  
170
                if (loopbackFlag == false)
171
                {
172
                    (context.getState()).Exit(context);
173
                }
174

  
175
                context.clearState();
176
                try
177
                {
178
                    ctxt.end();
179
                }
180
                finally
181
                {
182
                    context.setState(Extend.SelectGeometryToExtend);
183

  
184
                    if (loopbackFlag == false)
185
                    {
186
                        (context.getState()).Entry(context);
187
                    }
188

  
189
                }
190
            }
191
            else
192
            {
193
                boolean loopbackFlag =
194
                    context.getState().getName().equals(
195
                        Extend.SelectGeometryToExtend.getName());
196

  
197
                if (loopbackFlag == false)
198
                {
199
                    (context.getState()).Exit(context);
200
                }
201

  
202
                context.clearState();
203
                try
204
                {
205
                    ctxt.throwOptionException(PluginServices.getText(this,"incorrect_option"), s);
206
                }
207
                finally
208
                {
209
                    context.setState(Extend.SelectGeometryToExtend);
210

  
211
                    if (loopbackFlag == false)
212
                    {
213
                        (context.getState()).Entry(context);
214
                    }
215

  
216
                }
217
            }
218

  
219
            return;
220
        }
221

  
222
        protected void addValue(ExtendCADToolContext context, double d)
223
        {
224
            ExtendCADTool ctxt = context.getOwner();
225

  
226
            boolean loopbackFlag =
227
                context.getState().getName().equals(
228
                    Extend.SelectGeometryToExtend.getName());
229

  
230
            if (loopbackFlag == false)
231
            {
232
                (context.getState()).Exit(context);
233
            }
234

  
235
            context.clearState();
236
            try
237
            {
238
                ctxt.throwValueException(PluginServices.getText(this,"incorrect_value"), d);
239
            }
240
            finally
241
            {
242
                context.setState(Extend.SelectGeometryToExtend);
243

  
244
                if (loopbackFlag == false)
245
                {
246
                    (context.getState()).Entry(context);
247
                }
248

  
249
            }
250
            return;
251
        }
252

  
253
        protected void addPoint(ExtendCADToolContext context, double pointX, double pointY, InputEvent event)
254
        {
255
            ExtendCADTool ctxt = context.getOwner();
256

  
257
            boolean loopbackFlag =
258
                context.getState().getName().equals(
259
                    Extend.SelectGeometryToExtend.getName());
260

  
261
            if (loopbackFlag == false)
262
            {
263
                (context.getState()).Exit(context);
264
            }
265

  
266
            context.clearState();
267
            try
268
            {
269
                ctxt.throwPointException(PluginServices.getText(this,"incorrect_point"), pointX, pointY);
270
            }
271
            finally
272
            {
273
                context.setState(Extend.SelectGeometryToExtend);
274

  
275
                if (loopbackFlag == false)
276
                {
277
                    (context.getState()).Entry(context);
278
                }
279

  
280
            }
281
            return;
282
        }
283

  
284
    //-----------------------------------------------------------
285
    // Inner classse.
286
    //
287

  
288

  
289
        private static final class Extend_SelectGeometryToExtend
290
            extends Extend_Default
291
        {
292
        //-------------------------------------------------------
293
        // Member methods.
294
        //
295

  
296
            private Extend_SelectGeometryToExtend(String name, int id)
297
            {
298
                super (name, id);
299
            }
300

  
301
            protected void Entry(ExtendCADToolContext context)
302
            {
303
                ExtendCADTool ctxt = context.getOwner();
304

  
305
                ctxt.selection();
306
                ctxt.setQuestion(PluginServices.getText(this,"select_geometry_to_extend"));
307
                ctxt.setDescription(new String[]{"cancel"});
308
                return;
309
            }
310

  
311
            protected void addPoint(ExtendCADToolContext context, double pointX, double pointY, InputEvent event)
312
            {
313
                ExtendCADTool ctxt = context.getOwner();
314

  
315
                ExtendCADToolState endState = context.getState();
316

  
317
                context.clearState();
318
                try
319
                {
320
                    ctxt.setQuestion(PluginServices.getText(this,"select_geometry_to_extend"));
321
                    ctxt.setDescription(new String[]{"cancel"});
322
                    ctxt.addPoint(pointX, pointY, event);
323
                }
324
                finally
325
                {
326
                    context.setState(endState);
327
                }
328
                return;
329
            }
330

  
331
        //-------------------------------------------------------
332
        // Member data.
333
        //
334
        }
335

  
336
    //-----------------------------------------------------------
337
    // Member data.
338
    //
339
    }
340
}
branches/v2_0_0_prep/extensions/extEditing/sm/ExtendCADTool.sm
1
// -*- tab-width: 4; -*-
2

  
3
%{
4
//
5
// Vicente Caballero Navarro
6
%}
7

  
8
%start Extend::SelectGeometryToExtend
9
%class ExtendCADTool
10
%package com.iver.cit.gvsig.gui.cad.tools.smc
11
%import com.iver.cit.gvsig.gui.cad.tools.ExtendCADTool
12
%import java.awt.event.InputEvent
13
%import com.iver.andami.PluginServices
14

  
15
%map Extend
16
%%
17
// A task begins life in suspended animation.
18

  
19
SelectGeometryToExtend
20
	Entry {
21
		selection();
22
		setQuestion(
23
		PluginServices.getText(this,"select_geometry_to_extend"));
24
		setDescription(new String[]{"cancel"});
25

  
26
		}
27
	Exit{
28
		}
29

  
30
	{
31
		addPoint( pointX:double,pointY:double,event:InputEvent)
32
			SelectGeometryToExtend {
33
				setQuestion(PluginServices.getText(this,"select_geometry_to_extend"));
34
				setDescription(new String[]{"cancel"});
35
				addPoint( pointX,pointY,event);
36
				}
37
	}
38

  
39
Default
40
{
41
	addOption(s:String)
42
		[s.equals(PluginServices.getText(this,"cancel"))]
43
		SelectGeometryToExtend{
44
			end();
45
			}
46
	addOption(s:String)
47
		SelectGeometryToExtend{
48
			throwOptionException(PluginServices.getText(this,"incorrect_option"),s);
49
			}
50
	addValue(d:double)
51
		SelectGeometryToExtend{
52
			throwValueException(PluginServices.getText(this,"incorrect_value"),d);
53
			}
54
	addPoint(pointX:double,pointY:double,event:InputEvent)
55
		SelectGeometryToExtend{
56
			throwPointException(PluginServices.getText(this,"incorrect_point"),pointX,pointY);
57
			}
58
}
59
%%

Also available in: Unified diff