Revision 3748
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/v02/FGraphicUtilities.java | ||
---|---|---|
137 | 137 |
GeneralPathX line = new GeneralPathX(); |
138 | 138 |
line.moveTo(rect.x, rect.y + (rect.height / 2)); |
139 | 139 |
|
140 |
// line.lineTo(rect.x + rect.width/3, rect.y + rect.height);
|
|
141 |
// line.lineTo(rect.x + 2*rect.width/3, rect.y);
|
|
140 |
// line.lineTo(rect.x + rect.width/3, rect.y + rect.height); |
|
141 |
// line.lineTo(rect.x + 2*rect.width/3, rect.y); |
|
142 | 142 |
// line.lineTo(rect.x + rect.width, rect.y + rect.height/2); |
143 | 143 |
line.curveTo(rect.x + (rect.width / 3), |
144 | 144 |
rect.y + (2 * rect.height), |
... | ... | |
251 | 251 |
|
252 | 252 |
case FShape.LINE: |
253 | 253 |
case FShape.LINE + FShape.Z: |
254 |
case FShape.CIRCLE: |
|
255 |
case FShape.CIRCLE + FShape.Z: |
|
254 | 256 |
// Shape theShp = mT.createTransformedShape(shp.m_Polyline); |
255 | 257 |
// g2.setColor(theSymbol.m_Color); |
256 | 258 |
if (theSymbol.getStroke() != null) { |
... | ... | |
266 | 268 |
if (theSymbol.getFill() != null) |
267 | 269 |
g2.setPaint(theSymbol.getFill()); |
268 | 270 |
|
269 |
if (theSymbol.getColor() != null)
|
|
271 |
if (theSymbol.getColor() != null) |
|
270 | 272 |
if (theSymbol.getStyle() != FConstant.SYMBOL_STYLE_DGNSPECIAL) { |
271 | 273 |
g2.fill(shp); |
272 |
}
|
|
274 |
} |
|
273 | 275 |
|
274 | 276 |
if (theSymbol.isOutlined()) { |
275 | 277 |
g2.setColor(theSymbol.getOutlineColor()); |
... | ... | |
282 | 284 |
} |
283 | 285 |
|
284 | 286 |
break; |
287 |
|
|
285 | 288 |
} |
286 | 289 |
} |
287 | 290 |
|
... | ... | |
361 | 364 |
|
362 | 365 |
case FShape.LINE: |
363 | 366 |
|
364 |
//
|
|
367 |
// |
|
365 | 368 |
if (theLabel.getOrig() == null) // Calculamos el punto y la orientaci?n solo la primera vez |
366 | 369 |
{ |
367 | 370 |
PathLength pathLen = new PathLength(shp); |
... | ... | |
388 | 391 |
|
389 | 392 |
// pAux = theLabel.getOrig(); |
390 | 393 |
// GlyphVector theGlyphs = theSymbol.m_Font.createGlyphVector(g2.getFontRenderContext(), theLabel); |
391 |
// Shape txtShp = TextPathLayout.layoutGlyphVector(theGlyphs, shp.m_Polyline,TextPathLayout.ALIGN_MIDDLE);
|
|
394 |
// Shape txtShp = TextPathLayout.layoutGlyphVector(theGlyphs, shp.m_Polyline,TextPathLayout.ALIGN_MIDDLE); |
|
392 | 395 |
// g2.draw(txtShp); |
393 | 396 |
// System.out.println("Pintando etiqueta " + theLabel ); |
394 | 397 |
break; |
... | ... | |
401 | 404 |
|
402 | 405 |
// System.out.println("Area de " + m_labelValues[numReg] + " = " |
403 | 406 |
// + geo.getArea()); |
404 |
// System.out.println(geo.toText());
|
|
407 |
// System.out.println(geo.toText()); |
|
405 | 408 |
Point pJTS = geo.getInteriorPoint(); |
406 | 409 |
FShape pLabel = FConverter.jts_to_java2d(pJTS); |
407 | 410 |
theLabel.setRotation(0); |
... | ... | |
596 | 599 |
/* lf.lfHeight = -radioSimbolo_en_pixels; |
597 | 600 |
angulo = pSimbolo->m_Rotation; // En radianes, de -pi a pi |
598 | 601 |
angulo = -180.0 * angulo / PI; |
599 |
|
|
602 |
|
|
600 | 603 |
lf.lfEscapement = (long) angulo*10; |
601 | 604 |
lf.lfOrientation = (long) angulo*10; |
602 |
|
|
605 |
|
|
603 | 606 |
fuente.CreateFontIndirect(&lf); |
604 | 607 |
pOldFont = pDC->SelectObject(&fuente); |
605 |
|
|
608 |
|
|
606 | 609 |
pDC->TextOut(pAPI.x, pAPI.y+radioSimbolo_en_pixels/2,elChar,1); |
607 |
|
|
610 |
|
|
608 | 611 |
pDC->SelectObject(pOldFont); |
609 | 612 |
fuente.DeleteObject(); |
610 |
|
|
613 |
|
|
611 | 614 |
break; */ |
612 | 615 |
case FConstant.SYMBOL_STYLE_MARKER_IMAGEN: // Icono |
613 | 616 |
{ |
... | ... | |
634 | 637 |
g2.drawImage(theSymbol.getIcon(), rectAux.x, rectAux.y, |
635 | 638 |
rectAux.width, rectAux.height, null); |
636 | 639 |
} else { |
637 |
String strImg = "Image"; // Utilities.getMessage(FGraphicUtilities.class,"imagen");
|
|
640 |
String strImg = "Image"; // Utilities.getMessage(FGraphicUtilities.class,"imagen"); |
|
638 | 641 |
FontMetrics metrics = g2.getFontMetrics(); |
639 | 642 |
int width = metrics.stringWidth(strImg); |
640 | 643 |
int height = metrics.getMaxAscent(); |
... | ... | |
665 | 668 |
break; |
666 | 669 |
} // del switch estilo |
667 | 670 |
} |
668 |
|
|
671 |
|
|
669 | 672 |
} |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/ShapeFactory.java | ||
---|---|---|
40 | 40 |
*/ |
41 | 41 |
package com.iver.cit.gvsig.fmap.core; |
42 | 42 |
|
43 |
import java.awt.geom.Arc2D; |
|
44 |
import java.awt.geom.Point2D; |
|
45 |
|
|
43 | 46 |
import com.iver.cit.gvsig.fmap.core.gt2.FLiteShape; |
47 |
import com.iver.cit.gvsig.fmap.edition.UtilFunctions; |
|
44 | 48 |
|
45 | 49 |
|
46 | 50 |
/** |
... | ... | |
63 | 67 |
return new FGeometry(p); |
64 | 68 |
} |
65 | 69 |
|
66 |
|
|
70 |
|
|
67 | 71 |
/** |
68 | 72 |
* Crea una geometr?a que contiene como shape un Multipunto 2D. |
69 | 73 |
* |
... | ... | |
158 | 162 |
public static FGeometry createGeometry(FShape shp) { |
159 | 163 |
return new FGeometry(shp); |
160 | 164 |
} |
161 |
|
|
165 |
|
|
162 | 166 |
public static IGeometry createGeometry(FLiteShape gt2geometry) { |
163 | 167 |
return new Gt2Geometry(gt2geometry); |
164 | 168 |
} |
169 |
public static IGeometry createCircle(Point2D center, Point2D r){ |
|
170 |
double radio = center.distance(r); |
|
171 |
return createCircle(center, radio); |
|
172 |
} |
|
165 | 173 |
|
166 |
|
|
174 |
public static IGeometry createCircle(Point2D center, double radio){ |
|
175 |
Arc2D.Double arc = new Arc2D.Double(center.getX()-radio, center.getY() - radio, |
|
176 |
2 * radio, 2 * radio, 0, 360, Arc2D.OPEN); |
|
177 |
|
|
178 |
return new FGeometry(new FCircle2D(new GeneralPathX(arc),center,radio)); |
|
179 |
} |
|
180 |
public static IGeometry createCircle(Point2D p1, Point2D p2, Point2D p3){ |
|
181 |
Point2D center = UtilFunctions.getCenter(p1, p2, p3); |
|
182 |
if (center!=null) |
|
183 |
return createCircle(center,p1); |
|
184 |
return null; |
|
185 |
} |
|
186 |
|
|
167 | 187 |
} |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/FCircle2D.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.fmap.core; |
|
42 |
|
|
43 |
import java.awt.geom.AffineTransform; |
|
44 |
import java.awt.geom.Arc2D; |
|
45 |
import java.awt.geom.Point2D; |
|
46 |
import java.awt.geom.Rectangle2D; |
|
47 |
|
|
48 |
import java.util.ArrayList; |
|
49 |
|
|
50 |
import com.iver.cit.gvsig.fmap.edition.UtilFunctions; |
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
/** |
|
55 |
* DOCUMENT ME! |
|
56 |
* |
|
57 |
* @author Vicente Caballero Navarro |
|
58 |
*/ |
|
59 |
public class FCircle2D extends FPolyline2D { |
|
60 |
private Point2D center; |
|
61 |
private double radio; |
|
62 |
|
|
63 |
|
|
64 |
/** |
|
65 |
* DOCUMENT ME! |
|
66 |
* |
|
67 |
* @param gpx |
|
68 |
*/ |
|
69 |
public FCircle2D(GeneralPathX gpx,Point2D c,double r) { |
|
70 |
super(gpx); |
|
71 |
center=c; |
|
72 |
radio=r; |
|
73 |
} |
|
74 |
public Point2D getCenter(){ |
|
75 |
return center; |
|
76 |
} |
|
77 |
public double getRadio(){ |
|
78 |
return radio; |
|
79 |
} |
|
80 |
/* (non-Javadoc) |
|
81 |
* @see com.iver.cit.gvsig.fmap.core.FShape#cloneFShape() |
|
82 |
*/ |
|
83 |
public FShape cloneFShape() { |
|
84 |
return new FCircle2D((GeneralPathX) gp.clone(),center,radio); |
|
85 |
} |
|
86 |
/** |
|
87 |
* @see com.iver.cit.gvsig.fmap.core.FShape#getShapeType() |
|
88 |
*/ |
|
89 |
public int getShapeType() { |
|
90 |
return FShape.CIRCLE; |
|
91 |
} |
|
92 |
/** |
|
93 |
* DOCUMENT ME! |
|
94 |
* |
|
95 |
* @param at DOCUMENT ME! |
|
96 |
*/ |
|
97 |
public void transform(AffineTransform at) { |
|
98 |
Point2D pdist=UtilFunctions.getPerpendicularPoint(new Point2D.Double(center.getX()+10,center.getY()),new Point2D.Double(center.getX()-10,center.getY()),center,radio); |
|
99 |
Point2D aux=new Point2D.Double(); |
|
100 |
at.transform(center,aux); |
|
101 |
center=aux; |
|
102 |
Point2D aux3=new Point2D.Double(); |
|
103 |
at.transform(pdist,aux3); |
|
104 |
radio=center.distance(aux3); |
|
105 |
gp.transform(at); |
|
106 |
} |
|
107 |
/** |
|
108 |
* DOCUMENT ME! |
|
109 |
* |
|
110 |
* @return DOCUMENT ME! |
|
111 |
*/ |
|
112 |
/*public Handler[] getStretchingHandlers() { |
|
113 |
ArrayList handlers = new ArrayList(); |
|
114 |
Rectangle2D rect = this.getBounds2D(); |
|
115 |
handlers.add(new CenterHandler(0, rect.getCenterX(), rect.getCenterY())); |
|
116 |
//handlers.add(new RadioHandler(1, rect.getX(), rect.getCenterY())); |
|
117 |
//handlers.add(new RadioHandler(2, rect.getMaxX(), rect.getCenterY())); |
|
118 |
//handlers.add(new RadioHandler(3, rect.getCenterX(), rect.getY())); |
|
119 |
//handlers.add(new RadioHandler(3, rect.getCenterX(), rect.getMaxY())); |
|
120 |
|
|
121 |
return (Handler[]) handlers.toArray(new Handler[0]); |
|
122 |
} |
|
123 |
public Handler[] getSelectHandlers() { |
|
124 |
ArrayList handlers = new ArrayList(); |
|
125 |
handlers.add(new CenterSelHandler(0,center.getX(), center.getY())); |
|
126 |
handlers.add(new RadioSelHandler(1, center.getX()-radio, center.getY())); |
|
127 |
handlers.add(new RadioSelHandler(2, center.getX()+radio, center.getY())); |
|
128 |
handlers.add(new RadioSelHandler(3, center.getX(), center.getY()-radio)); |
|
129 |
handlers.add(new RadioSelHandler(3, center.getX(), center.getY()+radio)); |
|
130 |
|
|
131 |
return (Handler[]) handlers.toArray(new Handler[0]); |
|
132 |
}*/ |
|
133 |
/** |
|
134 |
* DOCUMENT ME! |
|
135 |
* |
|
136 |
* @author Vicente Caballero Navarro |
|
137 |
*/ |
|
138 |
//class CenterHandler extends AbstractHandler { |
|
139 |
/** |
|
140 |
* Crea un nuevo PointHandler. |
|
141 |
* |
|
142 |
* @param i DOCUMENT ME! |
|
143 |
* @param x DOCUMENT ME! |
|
144 |
* @param y DOCUMENT ME! |
|
145 |
*/ |
|
146 |
/* public CenterHandler(int i, double x, double y) { |
|
147 |
point = new Point2D.Double(x, y); |
|
148 |
index = i; |
|
149 |
} |
|
150 |
*/ |
|
151 |
/** |
|
152 |
* DOCUMENT ME! |
|
153 |
* |
|
154 |
* @param x DOCUMENT ME! |
|
155 |
* @param y DOCUMENT ME! |
|
156 |
* |
|
157 |
* @return DOCUMENT ME! |
|
158 |
*/ |
|
159 |
/*public void move(double x, double y) { |
|
160 |
center=new Point2D.Double(center.getX()+x,center.getY()+y); |
|
161 |
for (int i=0;i<gp.numCoords/2;i++){ |
|
162 |
gp.pointCoords[i*2]+=x; |
|
163 |
gp.pointCoords[i*2+1]+=y; |
|
164 |
} |
|
165 |
} |
|
166 |
*/ |
|
167 |
/** |
|
168 |
* @see com.iver.cit.gvsig.fmap.core.Handler#set(double, double) |
|
169 |
*/ |
|
170 |
/* public void set(double x, double y) { |
|
171 |
} |
|
172 |
|
|
173 |
}*/ |
|
174 |
/** |
|
175 |
* DOCUMENT ME! |
|
176 |
* |
|
177 |
* @author Vicente Caballero Navarro |
|
178 |
*/ |
|
179 |
//class CenterSelHandler extends AbstractHandler { |
|
180 |
/** |
|
181 |
* Crea un nuevo PointHandler. |
|
182 |
* |
|
183 |
* @param i DOCUMENT ME! |
|
184 |
* @param x DOCUMENT ME! |
|
185 |
* @param y DOCUMENT ME! |
|
186 |
*/ |
|
187 |
/*public CenterSelHandler(int i, double x, double y) { |
|
188 |
point = new Point2D.Double(x, y); |
|
189 |
index = i; |
|
190 |
} |
|
191 |
*/ |
|
192 |
/** |
|
193 |
* DOCUMENT ME! |
|
194 |
* |
|
195 |
* @param x DOCUMENT ME! |
|
196 |
* @param y DOCUMENT ME! |
|
197 |
* |
|
198 |
* @return DOCUMENT ME! |
|
199 |
*/ |
|
200 |
/* public void move(double x, double y) { |
|
201 |
for (int i=0;i<gp.numCoords/2;i++){ |
|
202 |
gp.pointCoords[i*2]+=x; |
|
203 |
gp.pointCoords[i*2+1]+=y; |
|
204 |
} |
|
205 |
} |
|
206 |
*/ |
|
207 |
/** |
|
208 |
* @see com.iver.cit.gvsig.fmap.core.Handler#set(double, double) |
|
209 |
*/ |
|
210 |
/* public void set(double x, double y) { |
|
211 |
center=new Point2D.Double(x,y); |
|
212 |
Arc2D.Double arc = new Arc2D.Double(center.getX()-radio, center.getY() - radio, |
|
213 |
2 * radio, 2 * radio, 0, 360, Arc2D.OPEN); |
|
214 |
gp=new GeneralPathX(arc); |
|
215 |
|
|
216 |
} |
|
217 |
} |
|
218 |
*/ |
|
219 |
/** |
|
220 |
* DOCUMENT ME! |
|
221 |
* |
|
222 |
* @author Vicente Caballero Navarro |
|
223 |
*/ |
|
224 |
/* class RadioSelHandler extends AbstractHandler { |
|
225 |
*/ |
|
226 |
/** |
|
227 |
* Crea un nuevo PointHandler. |
|
228 |
* |
|
229 |
* @param i DOCUMENT ME! |
|
230 |
* @param x DOCUMENT ME! |
|
231 |
* @param y DOCUMENT ME! |
|
232 |
*/ |
|
233 |
/* public RadioSelHandler(int i, double x, double y) { |
|
234 |
point = new Point2D.Double(x, y); |
|
235 |
index = i; |
|
236 |
} |
|
237 |
*/ |
|
238 |
/** |
|
239 |
* DOCUMENT ME! |
|
240 |
* |
|
241 |
* @param x DOCUMENT ME! |
|
242 |
* @param y DOCUMENT ME! |
|
243 |
* |
|
244 |
* @return DOCUMENT ME! |
|
245 |
*/ |
|
246 |
/* public void move(double x, double y) { |
|
247 |
|
|
248 |
} |
|
249 |
*/ |
|
250 |
/** |
|
251 |
* @see com.iver.cit.gvsig.fmap.core.Handler#set(double, double) |
|
252 |
*/ |
|
253 |
/* public void set(double x, double y) { |
|
254 |
radio = center.distance(x,y); |
|
255 |
Arc2D.Double arc = new Arc2D.Double(center.getX()-radio, center.getY() - radio, |
|
256 |
2 * radio, 2 * radio, 0, 360, Arc2D.OPEN); |
|
257 |
gp=new GeneralPathX(arc); |
|
258 |
} |
|
259 |
}*/ |
|
260 |
|
|
261 |
} |
|
0 | 262 |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/FShape.java | ||
---|---|---|
57 | 57 |
public final static int TEXT = 8; |
58 | 58 |
public final static int MULTI = 16; |
59 | 59 |
public final static int MULTIPOINT = 32; |
60 |
public final static int Z=64; |
|
60 |
public final static int CIRCLE = 64; |
|
61 |
public final static int Z=128; |
|
61 | 62 |
/** |
62 | 63 |
* Obtiene el tipo de shape que contiene. Puede ser una de las constantes |
63 | 64 |
* POINT, LINE o POLYGON |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/UtilFunctions.java | ||
---|---|---|
2 | 2 |
* Created on 10-feb-2005 |
3 | 3 |
* |
4 | 4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
7 |
*
|
|
7 |
* |
|
8 | 8 |
* This program is free software; you can redistribute it and/or |
9 | 9 |
* modify it under the terms of the GNU General Public License |
10 | 10 |
* as published by the Free Software Foundation; either version 2 |
11 | 11 |
* of the License, or (at your option) any later version. |
12 |
*
|
|
12 |
* |
|
13 | 13 |
* This program is distributed in the hope that it will be useful, |
14 | 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | 16 |
* GNU General Public License for more details. |
17 |
*
|
|
17 |
* |
|
18 | 18 |
* You should have received a copy of the GNU General Public License |
19 | 19 |
* along with this program; if not, write to the Free Software |
20 | 20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 |
*
|
|
21 |
* |
|
22 | 22 |
* For more information, contact: |
23 | 23 |
* |
24 | 24 |
* Generalitat Valenciana |
... | ... | |
30 | 30 |
* +34 963862235 |
31 | 31 |
* gvsig@gva.es |
32 | 32 |
* www.gvsig.gva.es |
33 |
*
|
|
33 |
* |
|
34 | 34 |
* or |
35 |
*
|
|
35 |
* |
|
36 | 36 |
* IVER T.I. S.A |
37 | 37 |
* Salamanca 50 |
38 | 38 |
* 46005 Valencia |
39 | 39 |
* Spain |
40 |
*
|
|
40 |
* |
|
41 | 41 |
* +34 963163400 |
42 | 42 |
* dac@iver.es |
43 | 43 |
*/ |
... | ... | |
61 | 61 |
static public Arc2D createCircle(Point2D p1, Point2D p2, Point2D p3) //, Graphics g) |
62 | 62 |
{ |
63 | 63 |
double xC, yC, w, h; |
64 |
|
|
64 |
|
|
65 | 65 |
// Calculamos 2 secantes, tiramos perpendiculares por sus puntos |
66 | 66 |
// medios y obtenemos el centro. Luego calculamos el radio. |
67 | 67 |
// Puntos medios de los segmentos. |
68 | 68 |
double xm1, ym1, xm2, ym2; |
69 | 69 |
xm1 = (p1.getX() + p2.getX())/ 2.0; |
70 | 70 |
ym1 = (p1.getY() + p2.getY())/ 2.0; |
71 |
xm2 = (p2.getX() + p3.getX())/ 2.0;
|
|
71 |
xm2 = (p2.getX() + p3.getX())/ 2.0; |
|
72 | 72 |
ym2 = (p2.getY() + p3.getY())/ 2.0; |
73 |
|
|
73 |
|
|
74 | 74 |
/* g.setColor(Color.GRAY); |
75 | 75 |
g.draw3DRect((int)xm1, (int) ym1, 1, 1, true); |
76 | 76 |
g.draw3DRect((int)xm2, (int) ym2, 1, 1, true); */ |
77 |
// Pendientes de las perpendiculares y constantes
|
|
77 |
// Pendientes de las perpendiculares y constantes |
|
78 | 78 |
double mP1=0, mP2=0, A1, A2; |
79 | 79 |
boolean bPerp1 = false, bPerp2 = false; |
80 | 80 |
if (p2.getY() - p1.getY() == 0) |
... | ... | |
95 | 95 |
else |
96 | 96 |
{ |
97 | 97 |
mP2 = (p3.getX() - p2.getX()) /(p2.getY() - p3.getY()); |
98 |
A2 = ym2 - xm2 * mP2;
|
|
98 |
A2 = ym2 - xm2 * mP2; |
|
99 | 99 |
} |
100 | 100 |
if (mP2 == mP1) |
101 | 101 |
{ |
... | ... | |
106 | 106 |
xC = (A2 - A1)/(mP1-mP2); |
107 | 107 |
if (!bPerp1) |
108 | 108 |
yC = xC * mP1 + A1; |
109 |
else
|
|
109 |
else |
|
110 | 110 |
yC = xC * mP2 + A2; |
111 | 111 |
} |
112 | 112 |
double Radio = p1.distance(xC, yC); |
... | ... | |
128 | 128 |
g.drawString("3", (int) p3.getX(), (int) p3.getY()); |
129 | 129 |
g.drawString("C", (int) xC, (int) yC); |
130 | 130 |
g.draw3DRect((int)xC, (int) yC, 2, 2, true); */ |
131 |
|
|
131 |
|
|
132 | 132 |
return resul; |
133 | 133 |
} |
134 |
/** |
|
135 |
* Obtiene un par de puntos que definen la recta perpendicular a p1-p2 que |
|
136 |
* pasa por el punto perp |
|
137 |
* |
|
138 |
* @param p1 punto de la recta p1-p2 |
|
139 |
* @param p2 punto de la recta p1-p2 |
|
140 |
* @param perp Punto por el que pasa la recta perpendicular, debe ser |
|
141 |
* distinto a p2 |
|
142 |
* |
|
143 |
* @return Array con dos puntos que definen la recta resultante |
|
144 |
*/ |
|
145 |
public static Point2D[] getPerpendicular(Point2D p1, Point2D p2, |
|
146 |
Point2D perp) { |
|
147 |
if ((p2.getY() - p1.getY()) == 0) { |
|
148 |
return new Point2D[] { |
|
149 |
new Point2D.Double(perp.getX(), 0), |
|
150 |
new Point2D.Double(perp.getX(), 1) |
|
151 |
}; |
|
152 |
} |
|
134 | 153 |
|
154 |
//Pendiente de la recta perpendicular |
|
155 |
double m = (p1.getX() - p2.getX()) / (p2.getY() - p1.getY()); |
|
156 |
|
|
157 |
//b de la funcion de la recta perpendicular |
|
158 |
double b = perp.getY() - (m * perp.getX()); |
|
159 |
|
|
160 |
//Obtenemos un par de puntos |
|
161 |
Point2D[] res = new Point2D[2]; |
|
162 |
|
|
163 |
res[0] = new Point2D.Double(0, (m * 0) + b); |
|
164 |
res[1] = new Point2D.Double(1000, (m * 1000) + b); |
|
165 |
|
|
166 |
return res; |
|
167 |
} |
|
168 |
/** |
|
169 |
* Obtiene el punto que se encuentra a una distancia 'dist' de la recta |
|
170 |
* p1-p2 y se encuentra en la recta perpendicular que pasa por perpPoint |
|
171 |
* |
|
172 |
* @param p1 Punto de la recta p1-p2 |
|
173 |
* @param p2 Punto de la recta p1-p2 |
|
174 |
* @param perpPoint Punto de la recta perpendicular |
|
175 |
* @param dist Distancia del punto que se quiere obtener a la recta p1-p2 |
|
176 |
* |
|
177 |
* @return DOCUMENT ME! |
|
178 |
*/ |
|
179 |
public static Point2D getPerpendicularPoint(Point2D p1, Point2D p2, |
|
180 |
Point2D perpPoint, double dist) { |
|
181 |
Point2D[] p = getPerpendicular(p1, p2, perpPoint); |
|
182 |
Point2D unit = getUnitVector(p[0], p[1]); |
|
183 |
|
|
184 |
return new Point2D.Double(perpPoint.getX() + (unit.getX() * dist), |
|
185 |
perpPoint.getY() + (unit.getY() * dist)); |
|
186 |
} |
|
187 |
|
|
188 |
/** |
|
189 |
* Devuelve un vector unitario en forma de punto a partir de dos puntos. |
|
190 |
* |
|
191 |
* @param p1 punto origen. |
|
192 |
* @param p2 punto destino. |
|
193 |
* |
|
194 |
* @return vector unitario. |
|
195 |
*/ |
|
196 |
public static Point2D getUnitVector(Point2D p1, Point2D p2) { |
|
197 |
Point2D paux = new Point2D.Double(p2.getX() - p1.getX(), |
|
198 |
p2.getY() - p1.getY()); |
|
199 |
double v = Math.sqrt(Math.pow((double) paux.getX(), (double) 2) + |
|
200 |
Math.pow((double) paux.getY(), (double) 2)); |
|
201 |
paux = new Point2D.Double(paux.getX() / v, paux.getY() / v); |
|
202 |
|
|
203 |
return paux; |
|
204 |
} |
|
205 |
/** |
|
206 |
* Obtiene el centro del c?rculo que pasa por los tres puntos que se pasan |
|
207 |
* como par?metro |
|
208 |
* |
|
209 |
* @param p1 primer punto del c?rculo cuyo centro se quiere obtener |
|
210 |
* @param p2 segundo punto del c?rculo cuyo centro se quiere obtener |
|
211 |
* @param p3 tercer punto del c?rculo cuyo centro se quiere obtener |
|
212 |
* |
|
213 |
* @return Devuelve null si los puntos est?n alineados o no son 3 puntos |
|
214 |
* distintos |
|
215 |
*/ |
|
216 |
public static Point2D getCenter(Point2D p1, Point2D p2, Point2D p3) { |
|
217 |
if (p1.equals(p2) || p2.equals(p3) || p1.equals(p3)) { |
|
218 |
return null; |
|
219 |
} |
|
220 |
|
|
221 |
Point2D[] perp1 = getPerpendicular(p1, p2, |
|
222 |
new Point2D.Double((p1.getX() + p2.getX()) / 2, |
|
223 |
(p1.getY() + p2.getY()) / 2)); |
|
224 |
Point2D[] perp2 = getPerpendicular(p2, p3, |
|
225 |
new Point2D.Double((p2.getX() + p3.getX()) / 2, |
|
226 |
(p2.getY() + p3.getY()) / 2)); |
|
227 |
|
|
228 |
return getIntersection(perp1[0], perp1[1], perp2[0], perp2[1]); |
|
229 |
} |
|
230 |
/** |
|
231 |
* Devuelve el punto de la intersecci?n entre las lineas p1-p2 y p3-p4. |
|
232 |
* |
|
233 |
* @param p1 punto de la recta p1-p2 |
|
234 |
* @param p2 punto de la recta p1-p2 |
|
235 |
* @param p3 punto de la recta p3-p4 |
|
236 |
* @param p4 punto de la recta p3-p4 |
|
237 |
* |
|
238 |
* @return DOCUMENT ME! |
|
239 |
* |
|
240 |
* @throws RuntimeException DOCUMENT ME! |
|
241 |
*/ |
|
242 |
public static Point2D getIntersection(Point2D p1, Point2D p2, Point2D p3, |
|
243 |
Point2D p4) { |
|
244 |
double m1 = Double.POSITIVE_INFINITY; |
|
245 |
|
|
246 |
if ((p2.getX() - p1.getX()) != 0) { |
|
247 |
m1 = (p2.getY() - p1.getY()) / (p2.getX() - p1.getX()); |
|
248 |
} |
|
249 |
|
|
250 |
double m2 = Double.POSITIVE_INFINITY; |
|
251 |
|
|
252 |
if ((p4.getX() - p3.getX()) != 0) { |
|
253 |
m2 = (p4.getY() - p3.getY()) / (p4.getX() - p3.getX()); |
|
254 |
} |
|
255 |
|
|
256 |
if ((m1 == Double.POSITIVE_INFINITY) && |
|
257 |
(m2 == Double.POSITIVE_INFINITY)) { |
|
258 |
return null; |
|
259 |
} |
|
260 |
|
|
261 |
double b1 = p2.getY() - (m1 * p2.getX()); |
|
262 |
|
|
263 |
double b2 = p4.getY() - (m2 * p4.getX()); |
|
264 |
|
|
265 |
if ((m1 != Double.POSITIVE_INFINITY) && |
|
266 |
(m2 != Double.POSITIVE_INFINITY)) { |
|
267 |
if (m1 == m2) { |
|
268 |
return null; |
|
269 |
} |
|
270 |
|
|
271 |
double x = (b2 - b1) / (m1 - m2); |
|
272 |
|
|
273 |
return new Point2D.Double(x, (m1 * x) + b1); |
|
274 |
} else if (m1 == Double.POSITIVE_INFINITY) { |
|
275 |
double x = p1.getX(); |
|
276 |
|
|
277 |
return new Point2D.Double(x, (m2 * x) + b2); |
|
278 |
} else if (m2 == Double.POSITIVE_INFINITY) { |
|
279 |
double x = p3.getX(); |
|
280 |
|
|
281 |
return new Point2D.Double(x, (m1 * x) + b1); |
|
282 |
} |
|
283 |
|
|
284 |
//no llega nunca |
|
285 |
throw new RuntimeException("BUG!"); |
|
286 |
} |
|
287 |
|
|
135 | 288 |
} |
trunk/extensions/extCAD/src/com/iver/cit/gvsig/CADExtension.java | ||
---|---|---|
59 | 59 |
import com.iver.cit.gvsig.gui.View; |
60 | 60 |
import com.iver.cit.gvsig.gui.cad.CADTool; |
61 | 61 |
import com.iver.cit.gvsig.gui.cad.CADToolAdapter; |
62 |
import com.iver.cit.gvsig.gui.cad.tools.CircleCADTool; |
|
62 | 63 |
import com.iver.cit.gvsig.gui.cad.tools.LineCADTool; |
63 | 64 |
import com.iver.cit.gvsig.gui.cad.tools.PointCADTool; |
64 | 65 |
import com.iver.utiles.console.ResponseListener; |
... | ... | |
70 | 71 |
*/ |
71 | 72 |
public class CADExtension implements Extension { |
72 | 73 |
private static CADToolAdapter adapter=new CADToolAdapter(); |
73 |
private HashMap namesCadTools = new HashMap(); |
|
74 |
private static HashMap namesCadTools = new HashMap();
|
|
74 | 75 |
private boolean isLoad =false; |
75 | 76 |
private MapControl mapControl; |
76 | 77 |
private View view; |
... | ... | |
83 | 84 |
public void inicializar() { |
84 | 85 |
LineCADTool line = new LineCADTool(); |
85 | 86 |
PointCADTool point = new PointCADTool(); |
87 |
CircleCADTool circle=new CircleCADTool(); |
|
86 | 88 |
addCADTool("line", line); |
87 | 89 |
addCADTool("point", point); |
90 |
addCADTool("circle",circle); |
|
88 | 91 |
} |
89 | 92 |
|
90 | 93 |
/** |
... | ... | |
157 | 160 |
} else if (s.compareTo("SELECT") == 0) { |
158 | 161 |
///vista.getMapControl().setCadTool("selection"); |
159 | 162 |
} else if (s.compareTo("POINT") == 0) { |
160 |
///vista.getMapControl().setCadTool("point"); |
|
161 | 163 |
setCADTool("point"); |
162 | 164 |
} else if (s.compareTo("LINE") == 0) { |
163 | 165 |
setCADTool("line"); |
164 |
///vista.getMapControl().setCadTool("line"); |
|
165 | 166 |
} else if (s.compareTo("POLYLINE") == 0) { |
166 | 167 |
///vista.getMapControl().setCadTool("polyline"); |
167 | 168 |
} else if (s.compareTo("CIRCLE") == 0) { |
168 |
///vista.getMapControl().setCadTool("circle");
|
|
169 |
setCADTool("circle");
|
|
169 | 170 |
} else if (s.compareTo("ARC") == 0) { |
170 | 171 |
///vista.getMapControl().setCadTool("arc"); |
171 | 172 |
} else if (s.compareTo("ELLIPSE") == 0) { |
... | ... | |
181 | 182 |
public void addCADTool(String name, CADTool c){ |
182 | 183 |
namesCadTools.put(name, c); |
183 | 184 |
} |
184 |
public void setCADTool(String text){ |
|
185 |
public static void setCADTool(String text){
|
|
185 | 186 |
CADTool ct = (CADTool) namesCadTools.get(text); |
186 | 187 |
if (ct == null) throw new RuntimeException("No such cad tool"); |
187 | 188 |
ct.init(); |
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/CADTool.java | ||
---|---|---|
69 | 69 |
public void setVectorialAdapter(VectorialEditableAdapter vea); |
70 | 70 |
public void addpoint(FBitSet sel,double x,double y); |
71 | 71 |
public void addvalue(FBitSet sel,double d); |
72 |
public void addoption(String s); |
|
72 |
public void addoption(FBitSet sel,String s);
|
|
73 | 73 |
public void setQuestion(String s); |
74 | 74 |
//public void updateState(String s); |
75 | 75 |
|
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/PointCADTool.java | ||
---|---|---|
13 | 13 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
14 | 14 |
import com.iver.cit.gvsig.gui.cad.CADTool; |
15 | 15 |
import com.iver.cit.gvsig.gui.cad.tools.smc.PointCADToolContext; |
16 |
import com.iver.cit.gvsig.gui.cad.tools.smc.LineCADToolContext.LineCADToolState; |
|
17 | 16 |
import com.iver.cit.gvsig.gui.cad.tools.smc.PointCADToolContext.PointCADToolState; |
18 | 17 |
|
19 | 18 |
|
... | ... | |
163 | 162 |
* |
164 | 163 |
* @param s Diferent option. |
165 | 164 |
*/ |
166 |
public void addoption(String s) { |
|
165 |
public void addoption(FBitSet sel,String s) {
|
|
167 | 166 |
// TODO Auto-generated method stub |
168 | 167 |
} |
169 | 168 |
public void refresh(){ |
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/smc/CircleCADToolContext.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.CircleCADTool; |
|
9 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
|
10 |
|
|
11 |
public final class CircleCADToolContext |
|
12 |
extends statemap.FSMContext |
|
13 |
{ |
|
14 |
//--------------------------------------------------------------- |
|
15 |
// Member methods. |
|
16 |
// |
|
17 |
|
|
18 |
public CircleCADToolContext(CircleCADTool owner) |
|
19 |
{ |
|
20 |
super(); |
|
21 |
|
|
22 |
_owner = owner; |
|
23 |
setState(ExecuteMap.Initial); |
|
24 |
ExecuteMap.Initial.Entry(this); |
|
25 |
} |
|
26 |
|
|
27 |
public void addoption(FBitSet sel, String s) |
|
28 |
{ |
|
29 |
_transition = "addoption"; |
|
30 |
getState().addoption(this, sel, s); |
|
31 |
_transition = ""; |
|
32 |
return; |
|
33 |
} |
|
34 |
|
|
35 |
public void addpoint(FBitSet sel, double pointX, double pointY) |
|
36 |
{ |
|
37 |
_transition = "addpoint"; |
|
38 |
getState().addpoint(this, sel, pointX, pointY); |
|
39 |
_transition = ""; |
|
40 |
return; |
|
41 |
} |
|
42 |
|
|
43 |
public void addvalue(FBitSet sel, double d) |
|
44 |
{ |
|
45 |
_transition = "addvalue"; |
|
46 |
getState().addvalue(this, sel, d); |
|
47 |
_transition = ""; |
|
48 |
return; |
|
49 |
} |
|
50 |
|
|
51 |
public CircleCADToolState getState() |
|
52 |
throws statemap.StateUndefinedException |
|
53 |
{ |
|
54 |
if (_state == null) |
|
55 |
{ |
|
56 |
throw( |
|
57 |
new statemap.StateUndefinedException()); |
|
58 |
} |
|
59 |
|
|
60 |
return ((CircleCADToolState) _state); |
|
61 |
} |
|
62 |
|
|
63 |
protected CircleCADTool getOwner() |
|
64 |
{ |
|
65 |
return (_owner); |
|
66 |
} |
|
67 |
|
|
68 |
//--------------------------------------------------------------- |
|
69 |
// Member data. |
|
70 |
// |
|
71 |
|
|
72 |
transient private CircleCADTool _owner; |
|
73 |
|
|
74 |
//--------------------------------------------------------------- |
|
75 |
// Inner classes. |
|
76 |
// |
|
77 |
|
|
78 |
public static abstract class CircleCADToolState |
|
79 |
extends statemap.State |
|
80 |
{ |
|
81 |
//----------------------------------------------------------- |
|
82 |
// Member methods. |
|
83 |
// |
|
84 |
|
|
85 |
protected CircleCADToolState(String name, int id) |
|
86 |
{ |
|
87 |
super (name, id); |
|
88 |
} |
|
89 |
|
|
90 |
protected void Entry(CircleCADToolContext context) {} |
|
91 |
protected void Exit(CircleCADToolContext context) {} |
|
92 |
|
|
93 |
protected void addoption(CircleCADToolContext context, FBitSet sel, String s) |
|
94 |
{ |
|
95 |
Default(context); |
|
96 |
} |
|
97 |
|
|
98 |
protected void addpoint(CircleCADToolContext context, FBitSet sel, double pointX, double pointY) |
|
99 |
{ |
|
100 |
Default(context); |
|
101 |
} |
|
102 |
|
|
103 |
protected void addvalue(CircleCADToolContext context, FBitSet sel, double d) |
|
104 |
{ |
|
105 |
Default(context); |
|
106 |
} |
|
107 |
|
|
108 |
protected void Default(CircleCADToolContext context) |
|
109 |
{ |
|
110 |
throw ( |
|
111 |
new statemap.TransitionUndefinedException( |
|
112 |
"State: " + |
|
113 |
context.getState().getName() + |
|
114 |
", Transition: " + |
|
115 |
context.getTransition())); |
|
116 |
} |
|
117 |
|
|
118 |
//----------------------------------------------------------- |
|
119 |
// Member data. |
|
120 |
// |
|
121 |
} |
|
122 |
|
|
123 |
/* package */ static abstract class ExecuteMap |
|
124 |
{ |
|
125 |
//----------------------------------------------------------- |
|
126 |
// Member methods. |
|
127 |
// |
|
128 |
|
|
129 |
//----------------------------------------------------------- |
|
130 |
// Member data. |
|
131 |
// |
|
132 |
|
|
133 |
//------------------------------------------------------- |
|
134 |
// Statics. |
|
135 |
// |
|
136 |
/* package */ static ExecuteMap_Default.ExecuteMap_Initial Initial; |
|
137 |
/* package */ static ExecuteMap_Default.ExecuteMap_First First; |
|
138 |
/* package */ static ExecuteMap_Default.ExecuteMap_Second Second; |
|
139 |
/* package */ static ExecuteMap_Default.ExecuteMap_Third Third; |
|
140 |
/* package */ static ExecuteMap_Default.ExecuteMap_Fourth Fourth; |
|
141 |
/* package */ static ExecuteMap_Default.ExecuteMap_Fiveth Fiveth; |
|
142 |
/* package */ static ExecuteMap_Default.ExecuteMap_Sixth Sixth; |
|
143 |
/* package */ static ExecuteMap_Default.ExecuteMap_Seventh Seventh; |
|
144 |
private static ExecuteMap_Default Default; |
|
145 |
|
|
146 |
static |
|
147 |
{ |
|
148 |
Initial = new ExecuteMap_Default.ExecuteMap_Initial("ExecuteMap.Initial", 0); |
|
149 |
First = new ExecuteMap_Default.ExecuteMap_First("ExecuteMap.First", 1); |
|
150 |
Second = new ExecuteMap_Default.ExecuteMap_Second("ExecuteMap.Second", 2); |
|
151 |
Third = new ExecuteMap_Default.ExecuteMap_Third("ExecuteMap.Third", 3); |
|
152 |
Fourth = new ExecuteMap_Default.ExecuteMap_Fourth("ExecuteMap.Fourth", 4); |
|
153 |
Fiveth = new ExecuteMap_Default.ExecuteMap_Fiveth("ExecuteMap.Fiveth", 5); |
|
154 |
Sixth = new ExecuteMap_Default.ExecuteMap_Sixth("ExecuteMap.Sixth", 6); |
|
155 |
Seventh = new ExecuteMap_Default.ExecuteMap_Seventh("ExecuteMap.Seventh", 7); |
|
156 |
Default = new ExecuteMap_Default("ExecuteMap.Default", -1); |
|
157 |
} |
|
158 |
|
|
159 |
} |
|
160 |
|
|
161 |
protected static class ExecuteMap_Default |
|
162 |
extends CircleCADToolState |
|
163 |
{ |
|
164 |
//----------------------------------------------------------- |
|
165 |
// Member methods. |
|
166 |
// |
|
167 |
|
|
168 |
protected ExecuteMap_Default(String name, int id) |
|
169 |
{ |
|
170 |
super (name, id); |
|
171 |
} |
|
172 |
|
|
173 |
//----------------------------------------------------------- |
|
174 |
// Inner classse. |
|
175 |
// |
|
176 |
|
|
177 |
|
|
178 |
private static final class ExecuteMap_Initial |
|
179 |
extends ExecuteMap_Default |
|
180 |
{ |
|
181 |
//------------------------------------------------------- |
|
182 |
// Member methods. |
|
183 |
// |
|
184 |
|
|
185 |
private ExecuteMap_Initial(String name, int id) |
|
186 |
{ |
|
187 |
super (name, id); |
|
188 |
} |
|
189 |
|
|
190 |
protected void Entry(CircleCADToolContext context) |
|
191 |
{ |
|
192 |
CircleCADTool ctxt = context.getOwner(); |
|
193 |
|
|
194 |
ctxt.init(); |
|
195 |
ctxt.setQuestion("Insertar punto central o [3P]:"); |
|
196 |
return; |
|
197 |
} |
|
198 |
|
|
199 |
protected void addoption(CircleCADToolContext context, FBitSet sel, String s) |
|
200 |
{ |
|
201 |
CircleCADTool ctxt = context.getOwner(); |
|
202 |
|
|
203 |
|
|
204 |
(context.getState()).Exit(context); |
|
205 |
context.clearState(); |
|
206 |
try |
|
207 |
{ |
|
208 |
ctxt.setQuestion("Insertar primer punto"); |
|
209 |
ctxt.addoption(sel, s); |
|
210 |
} |
|
211 |
finally |
|
212 |
{ |
|
213 |
context.setState(ExecuteMap.Seventh); |
|
214 |
(context.getState()).Entry(context); |
|
215 |
} |
|
216 |
return; |
|
217 |
} |
|
218 |
|
|
219 |
protected void addpoint(CircleCADToolContext context, FBitSet sel, double pointX, double pointY) |
|
220 |
{ |
|
221 |
CircleCADTool ctxt = context.getOwner(); |
|
222 |
|
|
223 |
|
|
224 |
(context.getState()).Exit(context); |
|
225 |
context.clearState(); |
|
226 |
try |
|
227 |
{ |
|
228 |
ctxt.setQuestion("Insertar radio o segundo punto"); |
|
229 |
ctxt.addpoint(sel, pointX, pointY); |
|
230 |
} |
|
231 |
finally |
|
232 |
{ |
|
233 |
context.setState(ExecuteMap.First); |
|
234 |
(context.getState()).Entry(context); |
|
235 |
} |
|
236 |
return; |
|
237 |
} |
|
238 |
|
|
239 |
//------------------------------------------------------- |
|
240 |
// Member data. |
|
241 |
// |
|
242 |
} |
|
243 |
|
|
244 |
private static final class ExecuteMap_First |
|
245 |
extends ExecuteMap_Default |
|
246 |
{ |
|
247 |
//------------------------------------------------------- |
|
248 |
// Member methods. |
|
249 |
// |
|
250 |
|
|
251 |
private ExecuteMap_First(String name, int id) |
|
252 |
{ |
|
253 |
super (name, id); |
|
254 |
} |
|
255 |
|
|
256 |
protected void addpoint(CircleCADToolContext context, FBitSet sel, double pointX, double pointY) |
|
257 |
{ |
|
258 |
CircleCADTool ctxt = context.getOwner(); |
|
259 |
|
|
260 |
|
|
261 |
(context.getState()).Exit(context); |
|
262 |
context.clearState(); |
|
263 |
try |
|
264 |
{ |
|
265 |
ctxt.addpoint(sel, pointX, pointY); |
|
266 |
ctxt.refresh(); |
|
267 |
ctxt.end(); |
|
268 |
} |
|
269 |
finally |
|
270 |
{ |
|
271 |
context.setState(ExecuteMap.Sixth); |
|
272 |
(context.getState()).Entry(context); |
|
273 |
} |
|
274 |
return; |
|
275 |
} |
|
276 |
|
|
277 |
protected void addvalue(CircleCADToolContext context, FBitSet sel, double d) |
|
278 |
{ |
|
279 |
CircleCADTool ctxt = context.getOwner(); |
|
280 |
|
|
281 |
|
|
282 |
(context.getState()).Exit(context); |
|
283 |
context.clearState(); |
|
284 |
try |
|
285 |
{ |
|
286 |
ctxt.addvalue(sel, d); |
|
287 |
ctxt.refresh(); |
|
288 |
ctxt.end(); |
|
289 |
} |
|
290 |
finally |
|
291 |
{ |
|
292 |
context.setState(ExecuteMap.Fiveth); |
|
293 |
(context.getState()).Entry(context); |
|
294 |
} |
|
295 |
return; |
|
296 |
} |
|
297 |
|
|
298 |
//------------------------------------------------------- |
|
299 |
// Member data. |
|
300 |
// |
|
301 |
} |
|
302 |
|
|
303 |
private static final class ExecuteMap_Second |
|
304 |
extends ExecuteMap_Default |
|
305 |
{ |
|
306 |
//------------------------------------------------------- |
|
307 |
// Member methods. |
|
308 |
// |
|
309 |
|
|
310 |
private ExecuteMap_Second(String name, int id) |
|
311 |
{ |
|
312 |
super (name, id); |
|
313 |
} |
|
314 |
|
|
315 |
protected void addpoint(CircleCADToolContext context, FBitSet sel, double pointX, double pointY) |
|
316 |
{ |
|
317 |
CircleCADTool ctxt = context.getOwner(); |
|
318 |
|
|
319 |
|
|
320 |
(context.getState()).Exit(context); |
|
321 |
context.clearState(); |
|
322 |
try |
|
323 |
{ |
|
324 |
ctxt.setQuestion("Insertar tercer punto"); |
|
325 |
ctxt.addpoint(sel, pointX, pointY); |
|
326 |
} |
|
327 |
finally |
|
328 |
{ |
|
329 |
context.setState(ExecuteMap.Third); |
|
330 |
(context.getState()).Entry(context); |
|
331 |
} |
|
332 |
return; |
|
333 |
} |
|
334 |
|
|
335 |
//------------------------------------------------------- |
|
336 |
// Member data. |
|
337 |
// |
|
338 |
} |
|
339 |
|
|
340 |
private static final class ExecuteMap_Third |
|
341 |
extends ExecuteMap_Default |
|
342 |
{ |
|
343 |
//------------------------------------------------------- |
|
344 |
// Member methods. |
|
345 |
// |
|
346 |
|
|
347 |
private ExecuteMap_Third(String name, int id) |
|
348 |
{ |
|
349 |
super (name, id); |
|
350 |
} |
|
351 |
|
|
352 |
protected void addpoint(CircleCADToolContext context, FBitSet sel, double pointX, double pointY) |
|
353 |
{ |
|
354 |
CircleCADTool ctxt = context.getOwner(); |
|
355 |
|
|
356 |
|
|
357 |
(context.getState()).Exit(context); |
|
358 |
context.clearState(); |
|
359 |
try |
|
360 |
{ |
|
361 |
ctxt.addpoint(sel, pointX, pointY); |
|
362 |
ctxt.refresh(); |
|
363 |
ctxt.end(); |
|
364 |
} |
|
365 |
finally |
|
366 |
{ |
|
367 |
context.setState(ExecuteMap.Fourth); |
|
368 |
(context.getState()).Entry(context); |
|
369 |
} |
|
370 |
return; |
|
371 |
} |
|
372 |
|
|
373 |
//------------------------------------------------------- |
|
374 |
// Member data. |
|
375 |
// |
|
376 |
} |
|
377 |
|
|
378 |
private static final class ExecuteMap_Fourth |
|
379 |
extends ExecuteMap_Default |
|
380 |
{ |
|
381 |
//------------------------------------------------------- |
|
382 |
// Member methods. |
|
383 |
// |
|
384 |
|
|
385 |
private ExecuteMap_Fourth(String name, int id) |
|
386 |
{ |
|
387 |
super (name, id); |
|
388 |
} |
|
389 |
|
|
390 |
//------------------------------------------------------- |
|
391 |
// Member data. |
|
392 |
// |
|
393 |
} |
|
394 |
|
|
395 |
private static final class ExecuteMap_Fiveth |
|
396 |
extends ExecuteMap_Default |
|
397 |
{ |
|
398 |
//------------------------------------------------------- |
|
399 |
// Member methods. |
|
400 |
// |
|
401 |
|
|
402 |
private ExecuteMap_Fiveth(String name, int id) |
|
403 |
{ |
|
404 |
super (name, id); |
|
405 |
} |
|
406 |
|
|
407 |
//------------------------------------------------------- |
|
408 |
// Member data. |
|
409 |
// |
|
410 |
} |
|
411 |
|
|
412 |
private static final class ExecuteMap_Sixth |
|
413 |
extends ExecuteMap_Default |
|
414 |
{ |
|
415 |
//------------------------------------------------------- |
|
416 |
// Member methods. |
|
417 |
// |
|
418 |
|
|
419 |
private ExecuteMap_Sixth(String name, int id) |
|
420 |
{ |
|
421 |
super (name, id); |
|
422 |
} |
|
423 |
|
|
424 |
//------------------------------------------------------- |
|
425 |
// Member data. |
|
426 |
// |
|
427 |
} |
|
428 |
|
|
429 |
private static final class ExecuteMap_Seventh |
|
430 |
extends ExecuteMap_Default |
|
431 |
{ |
|
432 |
//------------------------------------------------------- |
|
433 |
// Member methods. |
|
434 |
// |
|
435 |
|
|
436 |
private ExecuteMap_Seventh(String name, int id) |
|
437 |
{ |
|
438 |
super (name, id); |
|
439 |
} |
|
440 |
|
|
441 |
protected void addpoint(CircleCADToolContext context, FBitSet sel, double pointX, double pointY) |
|
442 |
{ |
|
443 |
CircleCADTool ctxt = context.getOwner(); |
|
444 |
|
|
445 |
|
|
446 |
(context.getState()).Exit(context); |
|
447 |
context.clearState(); |
|
448 |
try |
|
449 |
{ |
|
450 |
ctxt.setQuestion("Insertar segundo punto"); |
|
451 |
ctxt.addpoint(sel, pointX, pointY); |
|
452 |
} |
|
453 |
finally |
|
454 |
{ |
|
455 |
context.setState(ExecuteMap.Second); |
|
456 |
(context.getState()).Entry(context); |
|
457 |
} |
|
458 |
return; |
|
459 |
} |
|
460 |
|
|
461 |
//------------------------------------------------------- |
|
462 |
// Member data. |
|
463 |
// |
|
464 |
} |
|
465 |
|
|
466 |
//----------------------------------------------------------- |
|
467 |
// Member data. |
|
468 |
// |
|
469 |
} |
|
470 |
} |
|
0 | 471 |
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/CircleCADTool.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.gui.cad.tools; |
|
2 |
|
|
3 |
import java.awt.Graphics; |
|
4 |
import java.awt.Graphics2D; |
|
5 |
import java.awt.geom.Point2D; |
|
6 |
import java.io.IOException; |
|
7 |
|
|
8 |
import statemap.State; |
|
9 |
import statemap.TransitionUndefinedException; |
|
10 |
|
|
11 |
import com.iver.cit.gvsig.CADExtension; |
|
12 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
|
13 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
14 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
|
15 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
|
16 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
|
17 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
|
18 |
import com.iver.cit.gvsig.gui.cad.CADTool; |
|
19 |
import com.iver.cit.gvsig.gui.cad.tools.smc.CircleCADToolContext; |
|
20 |
import com.iver.cit.gvsig.gui.cad.tools.smc.CircleCADToolContext.CircleCADToolState; |
|
21 |
|
|
22 |
|
|
23 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
24 |
* |
|
25 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
26 |
* |
|
27 |
* This program is free software; you can redistribute it and/or |
|
28 |
* modify it under the terms of the GNU General Public License |
|
29 |
* as published by the Free Software Foundation; either version 2 |
|
30 |
* of the License, or (at your option) any later version. |
|
31 |
* |
|
32 |
* This program is distributed in the hope that it will be useful, |
|
33 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
34 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
35 |
* GNU General Public License for more details. |
|
36 |
* |
|
37 |
* You should have received a copy of the GNU General Public License |
|
38 |
* along with this program; if not, write to the Free Software |
|
39 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
40 |
* |
|
41 |
* For more information, contact: |
|
42 |
* |
|
43 |
* Generalitat Valenciana |
|
44 |
* Conselleria d'Infraestructures i Transport |
|
45 |
* Av. Blasco Ib??ez, 50 |
|
46 |
* 46010 VALENCIA |
|
47 |
* SPAIN |
|
48 |
* |
|
49 |
* +34 963862235 |
|
50 |
* gvsig@gva.es |
|
51 |
* www.gvsig.gva.es |
|
52 |
* |
|
53 |
* or |
|
54 |
* |
|
55 |
* IVER T.I. S.A |
|
56 |
* Salamanca 50 |
|
57 |
* 46005 Valencia |
|
58 |
* Spain |
|
59 |
* |
|
60 |
* +34 963163400 |
|
61 |
* dac@iver.es |
|
62 |
*/ |
|
63 |
public class CircleCADTool extends DefaultCADTool { |
|
64 |
private CircleCADToolContext _fsm; |
|
65 |
private VectorialEditableAdapter vea; |
|
66 |
private String question; |
|
67 |
private Point2D center; |
|
68 |
private Point2D firstPoint; |
|
69 |
private Point2D secondPoint; |
|
70 |
private Point2D thirdPoint; |
|
71 |
|
|
72 |
/** |
|
73 |
* Crea un nuevo LineCADTool. |
|
74 |
*/ |
|
75 |
public CircleCADTool() { |
|
76 |
_fsm = new CircleCADToolContext(this); |
|
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 |
} |
|
85 |
|
|
86 |
/* (non-Javadoc) |
|
87 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#end() |
|
88 |
*/ |
|
89 |
public void end() { |
|
90 |
_fsm = new CircleCADToolContext(this); |
|
91 |
firstPoint=null; |
|
92 |
} |
|
93 |
|
|
94 |
/* (non-Javadoc) |
|
95 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double) |
|
96 |
*/ |
|
97 |
public void transition(FBitSet sel, double x, double y) throws TransitionUndefinedException { |
|
98 |
_fsm.addpoint(sel, x, y); |
|
99 |
} |
|
100 |
/* (non-Javadoc) |
|
101 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double) |
|
102 |
*/ |
|
103 |
public void transition(FBitSet sel, double d) throws TransitionUndefinedException { |
|
104 |
_fsm.addvalue(sel,d); |
|
105 |
} |
|
106 |
|
|
107 |
/* (non-Javadoc) |
|
108 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String) |
|
109 |
*/ |
|
110 |
public void transition(FBitSet sel, String s) throws TransitionUndefinedException{ |
|
111 |
_fsm.addoption(sel,s); |
|
112 |
} |
|
113 |
/** |
|
114 |
* Equivale al transition del prototipo pero sin pasarle como par? metro el |
|
115 |
* editableFeatureSource que ya estar? creado. |
|
116 |
* |
|
117 |
* @param sel Bitset con las geometr?as que est?n seleccionadas. |
|
118 |
* @param x par?metro x del punto que se pase en esta transici?n. |
|
119 |
* @param y par?metro y del punto que se pase en esta transici?n. |
|
120 |
*/ |
|
121 |
public void addpoint(FBitSet sel, double x, double y) { |
|
122 |
CircleCADToolState actualState = (CircleCADToolState) _fsm.getPreviousState(); |
|
123 |
String status = actualState.getName(); |
|
124 |
if (status.equals("ExecuteMap.Initial")) { |
|
125 |
center = new Point2D.Double(x, y); |
|
126 |
} else if (status == "ExecuteMap.First") { |
|
127 |
try { |
|
128 |
DefaultFeature df = new DefaultFeature(ShapeFactory.createCircle(center, |
|
129 |
new Point2D.Double(x,y)), null); |
|
130 |
vea.addRow(df); |
|
131 |
} catch (DriverIOException e) { |
|
132 |
e.printStackTrace(); |
|
133 |
} catch (IOException e) { |
|
134 |
e.printStackTrace(); |
|
135 |
} |
|
136 |
} else if (status == "ExecuteMap.Seventh") { |
|
137 |
firstPoint= new Point2D.Double(x, y); |
|
138 |
} else if (status == "ExecuteMap.Second") { |
|
139 |
secondPoint= new Point2D.Double(x, y); |
|
140 |
} else if (status == "ExecuteMap.Third") { |
|
141 |
thirdPoint= new Point2D.Double(x, y); |
|
142 |
try { |
|
143 |
DefaultFeature df = new DefaultFeature(ShapeFactory.createCircle(firstPoint,secondPoint,thirdPoint), null); |
|
144 |
vea.addRow(df); |
|
145 |
} catch (DriverIOException e) { |
|
146 |
e.printStackTrace(); |
|
147 |
} catch (IOException e) { |
|
148 |
e.printStackTrace(); |
|
149 |
} |
|
150 |
} else if (status == "ExecuteMap.Sixth") { |
|
151 |
try { |
|
152 |
DefaultFeature df = new DefaultFeature(ShapeFactory.createCircle(center,new Point2D.Double(x, y)), null); |
|
153 |
vea.addRow(df); |
|
154 |
} catch (DriverIOException e) { |
|
155 |
e.printStackTrace(); |
|
156 |
} catch (IOException e) { |
|
157 |
e.printStackTrace(); |
|
158 |
} |
|
159 |
} |
|
160 |
} |
|
161 |
|
|
162 |
/** |
|
163 |
* Devuelve la cadena que corresponde al estado en el que nos encontramos. |
|
164 |
* |
|
165 |
* @return Cadena para mostrar por consola. |
|
166 |
*/ |
|
167 |
public String getQuestion() { |
|
168 |
System.out.println("Question : " + question); |
|
169 |
|
|
170 |
return question; |
|
171 |
} |
|
172 |
|
|
173 |
/** |
|
174 |
* Devuelve el nombre de la clase en la que nos encontramos. |
|
175 |
* |
|
176 |
* @return Nombre de la clase en la que nos encontramos. |
|
177 |
*/ |
|
178 |
public String getName() { |
|
179 |
return this.getClass().getName(); |
|
180 |
} |
|
181 |
|
|
182 |
/** |
|
183 |
* M?todo para dibujar la lo necesario para el estado en el que nos |
|
184 |
* encontremos. |
|
185 |
* |
|
186 |
* @param g Graphics sobre el que dibujar. |
|
187 |
* @param selectedGeometries BitSet con las geometr?as seleccionadas. |
|
188 |
* @param x par?metro x del punto que se pase para dibujar. |
|
189 |
* @param y par?metro x del punto que se pase para dibujar. |
|
190 |
*/ |
|
191 |
public void drawOperation(Graphics g, FBitSet selectedGeometries, double x, |
|
192 |
double y) { |
|
193 |
CircleCADToolState actualState = _fsm.getState(); |
|
194 |
String status = actualState.getName(); |
|
195 |
|
|
196 |
if ((status == "ExecuteMap.Initial")) { // || (status == "5")) { |
|
197 |
|
|
198 |
if (firstPoint != null) { |
|
199 |
drawLine((Graphics2D) g, firstPoint, new Point2D.Double(x, y)); |
|
200 |
} |
|
201 |
} |
|
202 |
if (status == "ExecuteMap.First") { |
|
203 |
Point2D currentPoint = new Point2D.Double(x, y); |
|
204 |
ShapeFactory.createCircle(center,currentPoint).draw((Graphics2D) g, |
|
205 |
getCadToolAdapter().getMapControl().getViewPort(), |
|
206 |
CADTool.modifySymbol); |
|
207 |
} else if (status == "ExecuteMap.Second") { |
|
208 |
drawLine((Graphics2D) g, firstPoint, new Point2D.Double(x, y)); |
|
209 |
} else if (status == "ExecuteMap.Third") { |
|
210 |
Point2D currentPoint = new Point2D.Double(x, y); |
|
211 |
//System.out.println("p2 = "+p2); |
|
212 |
//System.out.println("currentPoint = "+currentPoint); |
|
213 |
IGeometry geom=ShapeFactory.createCircle(firstPoint,secondPoint,currentPoint); |
|
214 |
if (geom!=null){ |
Also available in: Unified diff