Revision 28763
trunk/extensions/extCAD/config/config.xml | ||
---|---|---|
192 | 192 |
<selectable-tool icon="edition-geometry-stretch" action-command="_stretch" tooltip="stretch" position="12"/> |
193 | 193 |
</tool-bar> |
194 | 194 |
</extension> |
195 |
<!--extension class-name="com.iver.cit.gvsig.ExtendExtension" |
|
196 |
description="Extensi?n encargada de alargar geometr?as en una capa en edici?n." |
|
197 |
active="true"> |
|
198 |
<menu text="geometry/modify/extend" action-command="_extend" icon="edition-modify-geometry-extend"/> |
|
199 |
<tool-bar name="modificar" position="31"> |
|
200 |
<selectable-tool icon="edition-modify-geometry-extend" action-command="_extend" tooltip="extend" position="13"/> |
|
201 |
</tool-bar> |
|
202 |
</extension--> |
|
203 | 195 |
<extension class-name="com.iver.cit.gvsig.ComplexSelectionGeometryExtension" |
204 | 196 |
description="Extensi?n encargada de la selecci?n compleja de geometr?as." |
205 | 197 |
active="true"> |
trunk/extensions/extCAD/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 java.util.ArrayList; |
|
44 |
|
|
45 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
46 |
import com.iver.andami.PluginServices; |
|
47 |
import com.iver.andami.messages.NotificationManager; |
|
48 |
import com.iver.andami.plugins.Extension; |
|
49 |
import com.iver.cit.gvsig.fmap.MapControl; |
|
50 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
|
51 |
import com.iver.cit.gvsig.gui.cad.tools.ExtendCADTool; |
|
52 |
import com.iver.cit.gvsig.layers.VectorialLayerEdited; |
|
53 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
|
54 |
|
|
55 |
/** |
|
56 |
* Extensi?n que gestiona el alargar una geometr?a. |
|
57 |
* |
|
58 |
* @author Vicente Caballero Navarro |
|
59 |
*/ |
|
60 |
public class ExtendExtension extends Extension { |
|
61 |
private View view; |
|
62 |
|
|
63 |
private MapControl mapControl; |
|
64 |
private ExtendCADTool extend; |
|
65 |
|
|
66 |
/** |
|
67 |
* @see com.iver.andami.plugins.IExtension#initialize() |
|
68 |
*/ |
|
69 |
public void initialize() { |
|
70 |
extend=new ExtendCADTool(); |
|
71 |
CADExtension.addCADTool("_extend",extend); |
|
72 |
|
|
73 |
registerIcons(); |
|
74 |
} |
|
75 |
|
|
76 |
private void registerIcons(){ |
|
77 |
PluginServices.getIconTheme().registerDefault( |
|
78 |
"edition-modify-geometry-extend", |
|
79 |
this.getClass().getClassLoader().getResource("images/Extend.png") |
|
80 |
); |
|
81 |
|
|
82 |
} |
|
83 |
|
|
84 |
/** |
|
85 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String) |
|
86 |
*/ |
|
87 |
public void execute(String s) { |
|
88 |
CADExtension.initFocus(); |
|
89 |
if (s.equals("_extend")) { |
|
90 |
CADExtension.setCADTool(s,true); |
|
91 |
} |
|
92 |
CADExtension.getEditionManager().setMapControl(mapControl); |
|
93 |
CADExtension.getCADToolAdapter().configureMenu(); |
|
94 |
} |
|
95 |
|
|
96 |
/** |
|
97 |
* @see com.iver.andami.plugins.IExtension#isEnabled() |
|
98 |
*/ |
|
99 |
public boolean isEnabled() { |
|
100 |
|
|
101 |
try { |
|
102 |
if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) { |
|
103 |
view = (View) PluginServices.getMDIManager().getActiveWindow(); |
|
104 |
mapControl = view.getMapControl(); |
|
105 |
EditionManager em=CADExtension.getEditionManager(); |
|
106 |
if (em.getActiveLayerEdited()==null) |
|
107 |
return false; |
|
108 |
VectorialLayerEdited vle=(VectorialLayerEdited)em.getActiveLayerEdited(); |
|
109 |
FLyrVect lv=(FLyrVect)vle.getLayer(); |
|
110 |
ArrayList selectedRows=vle.getSelectedRow(); |
|
111 |
if (selectedRows.size()<1) { |
|
112 |
return false; |
|
113 |
} |
|
114 |
if (extend.isApplicable(lv.getShapeType())){ |
|
115 |
return true; |
|
116 |
} |
|
117 |
} |
|
118 |
} catch (ReadDriverException e) { |
|
119 |
NotificationManager.addError(e.getMessage(),e); |
|
120 |
} |
|
121 |
return false; |
|
122 |
} |
|
123 |
|
|
124 |
/** |
|
125 |
* @see com.iver.andami.plugins.IExtension#isVisible() |
|
126 |
*/ |
|
127 |
public boolean isVisible() { |
|
128 |
if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) |
|
129 |
return true; |
|
130 |
return false; |
|
131 |
} |
|
132 |
} |
trunk/extensions/extCAD/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 com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
50 |
import com.iver.andami.PluginServices; |
|
51 |
import com.iver.andami.messages.NotificationManager; |
|
52 |
import com.iver.cit.gvsig.CADExtension; |
|
53 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileWriteException; |
|
54 |
import com.iver.cit.gvsig.exceptions.validate.ValidateRowException; |
|
55 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
|
56 |
import com.iver.cit.gvsig.fmap.core.FShape; |
|
57 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
|
58 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
59 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
|
60 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
|
61 |
import com.iver.cit.gvsig.fmap.edition.DefaultRowEdited; |
|
62 |
import com.iver.cit.gvsig.fmap.edition.EditionEvent; |
|
63 |
import com.iver.cit.gvsig.fmap.edition.IRowEdited; |
|
64 |
import com.iver.cit.gvsig.fmap.edition.UtilFunctions; |
|
65 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
|
66 |
import com.iver.cit.gvsig.gui.cad.DefaultCADTool; |
|
67 |
import com.iver.cit.gvsig.gui.cad.exception.CommandException; |
|
68 |
import com.iver.cit.gvsig.gui.cad.tools.smc.ExtendCADToolContext; |
|
69 |
import com.iver.cit.gvsig.gui.cad.tools.smc.ExtendCADToolContext.ExtendCADToolState; |
|
70 |
import com.iver.cit.gvsig.layers.VectorialLayerEdited; |
|
71 |
|
|
72 |
|
|
73 |
/** |
|
74 |
* DOCUMENT ME! |
|
75 |
* |
|
76 |
* @author Vicente Caballero Navarro |
|
77 |
*/ |
|
78 |
public class ExtendCADTool extends DefaultCADTool { |
|
79 |
private ExtendCADToolContext _fsm; |
|
80 |
|
|
81 |
/** |
|
82 |
* Crea un nuevo ExtendCADTool. |
|
83 |
*/ |
|
84 |
public ExtendCADTool() { |
|
85 |
} |
|
86 |
|
|
87 |
/** |
|
88 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una |
|
89 |
* carga previa a la utilizaci?n de la herramienta. |
|
90 |
*/ |
|
91 |
public void init() { |
|
92 |
_fsm = new ExtendCADToolContext(this); |
|
93 |
} |
|
94 |
|
|
95 |
/* (non-Javadoc) |
|
96 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double) |
|
97 |
*/ |
|
98 |
public void transition(double x, double y, InputEvent event) { |
|
99 |
_fsm.addPoint(x, y, event); |
|
100 |
} |
|
101 |
|
|
102 |
/* (non-Javadoc) |
|
103 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double) |
|
104 |
*/ |
|
105 |
public void transition(double d) { |
|
106 |
_fsm.addValue(d); |
|
107 |
} |
|
108 |
|
|
109 |
/* (non-Javadoc) |
|
110 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String) |
|
111 |
*/ |
|
112 |
public void transition(String s) throws CommandException { |
|
113 |
if (!super.changeCommand(s)){ |
|
114 |
_fsm.addOption(s); |
|
115 |
} |
|
116 |
} |
|
117 |
|
|
118 |
/** |
|
119 |
* DOCUMENT ME! |
|
120 |
*/ |
|
121 |
public void selection() { |
|
122 |
ArrayList rowSelected=getSelectedRows(); |
|
123 |
if (rowSelected.size() == 0 && !CADExtension.getCADTool().getClass().getName().equals("com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) { |
|
124 |
CADExtension.setCADTool("_selection",false); |
|
125 |
((SelectionCADTool) CADExtension.getCADTool()).setNextTool( |
|
126 |
"_extend"); |
|
127 |
} |
|
128 |
} |
|
129 |
|
|
130 |
/** |
|
131 |
* Equivale al transition del prototipo pero sin pasarle como par?metro el |
|
132 |
* editableFeatureSource que ya estar? creado. |
|
133 |
* |
|
134 |
* @param x par?metro x del punto que se pase en esta transici?n. |
|
135 |
* @param y par?metro y del punto que se pase en esta transici?n. |
|
136 |
*/ |
|
137 |
public void addPoint(double x, double y,InputEvent event) { |
|
138 |
ExtendCADToolState actualState = (ExtendCADToolState) _fsm.getPreviousState(); |
|
139 |
String status = actualState.getName(); |
|
140 |
|
|
141 |
|
|
142 |
if (status.equals("Extend.SelectGeometryToExtend")) { |
|
143 |
|
|
144 |
VectorialLayerEdited vle=getVLE(); |
|
145 |
VectorialEditableAdapter vea=vle.getVEA(); |
|
146 |
vea.startComplexRow(); |
|
147 |
ArrayList selectedRow=getSelectedRows(); |
|
148 |
ArrayList selectedRowAux=new ArrayList(); |
|
149 |
//for (int i=0;i<selectedRow.size();i++) { |
|
150 |
selectedRowAux.addAll(selectedRow); |
|
151 |
//} |
|
152 |
//selection(); |
|
153 |
vle.selectWithPoint(x,y,false); |
|
154 |
ArrayList newSelectedRow=getSelectedRows(); |
|
155 |
try { |
|
156 |
for (int i=0;i<selectedRowAux.size();i++) { |
|
157 |
IRowEdited edRow1 = (IRowEdited) selectedRowAux.get(i); |
|
158 |
DefaultFeature fea1 = (DefaultFeature) edRow1.getLinkedRow().cloneRow(); |
|
159 |
IGeometry geometry1 = null; |
|
160 |
geometry1 = fea1.getGeometry(); |
|
161 |
|
|
162 |
IRowEdited edRow2 = (IRowEdited) newSelectedRow.get(i); |
|
163 |
DefaultFeature fea2 = (DefaultFeature) edRow2.getLinkedRow().cloneRow(); |
|
164 |
IGeometry geometry2 = null; |
|
165 |
geometry2 = fea2.getGeometry(); |
|
166 |
//for (int j=0;j<newSelectedRow.size();j++) { |
|
167 |
//if (geometry1 instanceof FPolygon2D) { |
|
168 |
fea2.setGeometry(intersectsGeometry(geometry2,geometry1)); |
|
169 |
//} |
|
170 |
//} |
|
171 |
|
|
172 |
vea.modifyRow(edRow2.getIndex(),fea2,getName(),EditionEvent.GRAPHIC); |
|
173 |
clearSelection(); |
|
174 |
newSelectedRow.add(new DefaultRowEdited(fea2,IRowEdited.STATUS_MODIFIED,edRow2.getIndex())); |
|
175 |
} |
|
176 |
|
|
177 |
vea.endComplexRow(getName()); |
|
178 |
vle.setSelectionCache(VectorialLayerEdited.NOTSAVEPREVIOUS, newSelectedRow); |
|
179 |
} catch (ValidateRowException e) { |
|
180 |
NotificationManager.addError(e.getMessage(),e); |
|
181 |
} catch (ExpansionFileWriteException e) { |
|
182 |
NotificationManager.addError(e.getMessage(),e); |
|
183 |
} catch (ReadDriverException e) { |
|
184 |
NotificationManager.addError(e.getMessage(),e); |
|
185 |
} |
|
186 |
} |
|
187 |
} |
|
188 |
|
|
189 |
private IGeometry intersectsGeometry(IGeometry geometry1, IGeometry geometry2) { |
|
190 |
Point2D p3=null; |
|
191 |
Point2D p4=null; |
|
192 |
Point2D p1=null; |
|
193 |
Point2D p2=null; |
|
194 |
GeneralPathX gpx=new GeneralPathX(); |
|
195 |
PathIterator theIterator=geometry1.getInternalShape().getPathIterator(null,FConverter.FLATNESS); |
|
196 |
boolean first=true; |
|
197 |
double[] theData = new double[6]; |
|
198 |
int theType; |
|
199 |
while (!theIterator.isDone()) { |
|
200 |
theType = theIterator.currentSegment(theData); |
|
201 |
switch (theType) { |
|
202 |
|
|
203 |
case PathIterator.SEG_MOVETO: |
|
204 |
p1=new Point2D.Double(theData[0], theData[1]); |
|
205 |
gpx.moveTo(p1.getX(),p1.getY()); |
|
206 |
break; |
|
207 |
|
|
208 |
case PathIterator.SEG_LINETO: |
|
209 |
p2=new Point2D.Double(theData[0], theData[1]); |
|
210 |
ArrayList lines=getLines(geometry2); |
|
211 |
boolean isLineTo=true; |
|
212 |
for (int i=0;i<lines.size();i++) { |
|
213 |
Point2D[] ps1=(Point2D[])lines.get(i); |
|
214 |
Point2D p=UtilFunctions.getIntersection(ps1[0],ps1[1],p1,p2); |
|
215 |
// GeneralPathX gpxAux=new GeneralPathX(); |
|
216 |
// gpxAux.moveTo(p.getX(),p.getY()); |
|
217 |
// gpxAux.lineTo(ps1[0].getX(),ps1[0].getY()); |
|
218 |
// Geometry gjts1=FConverter.java2d_to_jts((FShape)ShapeFactory.createPolyline2D(gpxAux).getInternalShape()); |
|
219 |
// Geometry gjts2=FConverter.java2d_to_jts((FShape)geometry2.getInternalShape()); |
|
220 |
// GeometryCollection result=(GeometryCollection)gjts1.intersection(gjts2); |
|
221 |
// Point point=(Point)result.getGeometryN(1); |
|
222 |
// p=new Point2D.Double(point.getX(),point.getY()); |
|
223 |
if (p!=null && first) { |
|
224 |
gpx.lineTo(p.getX(),p.getY()); |
|
225 |
first=false; |
|
226 |
isLineTo=false; |
|
227 |
break; |
|
228 |
}else { |
|
229 |
//gpx.lineTo(p2.getX(),p2.getY()); |
|
230 |
} |
|
231 |
} |
|
232 |
if (!first && isLineTo) |
|
233 |
gpx.lineTo(p2.getX(),p2.getY()); |
|
234 |
|
|
235 |
break; |
|
236 |
|
|
237 |
} //end switch |
|
238 |
|
|
239 |
theIterator.next(); |
|
240 |
} //end while loop |
|
241 |
return ShapeFactory.createPolyline2D(gpx); |
|
242 |
} |
|
243 |
|
|
244 |
|
|
245 |
private ArrayList getLines(IGeometry geometry1) { |
|
246 |
Point2D p1=null; |
|
247 |
Point2D p2=null; |
|
248 |
ArrayList lines=new ArrayList(); |
|
249 |
PathIterator theIterator=geometry1.getInternalShape().getPathIterator(null,FConverter.FLATNESS); |
|
250 |
double[] theData = new double[6]; |
|
251 |
int theType; |
|
252 |
while (!theIterator.isDone()) { |
|
253 |
theType = theIterator.currentSegment(theData); |
|
254 |
switch (theType) { |
|
255 |
case PathIterator.SEG_MOVETO: |
|
256 |
p1=new Point2D.Double(theData[0], theData[1]); |
|
257 |
break; |
|
258 |
|
|
259 |
case PathIterator.SEG_LINETO: |
|
260 |
p2=new Point2D.Double(theData[0], theData[1]); |
|
261 |
lines.add(new Point2D[] {p1,p2}); |
|
262 |
break; |
|
263 |
|
|
264 |
} //end switch |
|
265 |
|
|
266 |
theIterator.next(); |
|
267 |
} //end while loop |
|
268 |
return lines; |
|
269 |
} |
|
270 |
/** |
|
271 |
* M?todo para dibujar la lo necesario para el estado en el que nos |
|
272 |
* encontremos. |
|
273 |
* |
|
274 |
* @param g Graphics sobre el que dibujar. |
|
275 |
* @param x par?metro x del punto que se pase para dibujar. |
|
276 |
* @param y par?metro x del punto que se pase para dibujar. |
|
277 |
*/ |
|
278 |
public void drawOperation(Graphics g, double x, double y) { |
|
279 |
} |
|
280 |
|
|
281 |
/** |
|
282 |
* Add a diferent option. |
|
283 |
* |
|
284 |
* @param s |
|
285 |
* Diferent option. |
|
286 |
*/ |
|
287 |
public void addOption(String s) { |
|
288 |
} |
|
289 |
|
|
290 |
/* (non-Javadoc) |
|
291 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double) |
|
292 |
*/ |
|
293 |
public void addValue(double d) { |
|
294 |
} |
|
295 |
|
|
296 |
public String getName() { |
|
297 |
return PluginServices.getText(this,"extend_"); |
|
298 |
} |
|
299 |
|
|
300 |
public String toString() { |
|
301 |
return "_extend"; |
|
302 |
} |
|
303 |
public boolean isApplicable(int shapeType) { |
|
304 |
switch (shapeType) { |
|
305 |
case FShape.LINE: |
|
306 |
case FShape.MULTI: |
|
307 |
return true; |
|
308 |
} |
|
309 |
return false; |
|
310 |
} |
|
311 |
|
|
312 |
} |
trunk/extensions/extCAD/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 |
} |
trunk/extensions/extCAD/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