svn-gvsig-desktop / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / EllipseCADTool.java @ 3832
History | View | Annotate | Download (6.47 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.gui.cad.tools; |
42 |
|
43 |
import java.awt.Graphics; |
44 |
import java.awt.Graphics2D; |
45 |
import java.awt.geom.Point2D; |
46 |
|
47 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
48 |
import com.iver.cit.gvsig.gui.cad.CADTool; |
49 |
import com.iver.cit.gvsig.gui.cad.DefaultCADTool; |
50 |
import com.iver.cit.gvsig.gui.cad.tools.smc.EllipseCADToolContext; |
51 |
import com.iver.cit.gvsig.gui.cad.tools.smc.EllipseCADToolContext.EllipseCADToolState; |
52 |
|
53 |
|
54 |
/**
|
55 |
* DOCUMENT ME!
|
56 |
*
|
57 |
* @author Vicente Caballero Navarro
|
58 |
*/
|
59 |
public class EllipseCADTool extends DefaultCADTool { |
60 |
private EllipseCADToolContext _fsm;
|
61 |
private Point2D startAxis; |
62 |
private Point2D endAxis; |
63 |
|
64 |
/**
|
65 |
* Crea un nuevo LineCADTool.
|
66 |
*/
|
67 |
public EllipseCADTool() {
|
68 |
_fsm = new EllipseCADToolContext(this); |
69 |
} |
70 |
|
71 |
/**
|
72 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
73 |
* carga previa a la utilizaci?n de la herramienta.
|
74 |
*/
|
75 |
public void init() { |
76 |
} |
77 |
|
78 |
/* (non-Javadoc)
|
79 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#end()
|
80 |
*/
|
81 |
public void end() { |
82 |
_fsm = new EllipseCADToolContext(this); |
83 |
} |
84 |
|
85 |
/* (non-Javadoc)
|
86 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
87 |
*/
|
88 |
public void transition(double x, double y) { |
89 |
_fsm.addPoint(x, y); |
90 |
} |
91 |
|
92 |
/* (non-Javadoc)
|
93 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
|
94 |
*/
|
95 |
public void transition(double d) { |
96 |
_fsm.addValue(d); |
97 |
} |
98 |
|
99 |
/* (non-Javadoc)
|
100 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
|
101 |
*/
|
102 |
public void transition(String s) { |
103 |
//_fsm.addOption(sel,s);
|
104 |
} |
105 |
|
106 |
/**
|
107 |
* Equivale al transition del prototipo pero sin pasarle como par? metro el
|
108 |
* editableFeatureSource que ya estar? creado.
|
109 |
*
|
110 |
* @param sel Bitset con las geometr?as que est?n seleccionadas.
|
111 |
* @param x par?metro x del punto que se pase en esta transici?n.
|
112 |
* @param y par?metro y del punto que se pase en esta transici?n.
|
113 |
*/
|
114 |
public void addPoint(double x, double y) { |
115 |
EllipseCADToolState actualState = (EllipseCADToolState) _fsm.getPreviousState(); |
116 |
String status = actualState.getName();
|
117 |
|
118 |
if (status.equals("ExecuteMap.Initial")) { |
119 |
startAxis = new Point2D.Double(x, y); |
120 |
} else if (status.equals("ExecuteMap.First")) { |
121 |
endAxis = new Point2D.Double(x, y); |
122 |
} else if (status.equals("ExecuteMap.Second")) { |
123 |
Point2D middle = new Point2D.Double((startAxis.getX() + |
124 |
endAxis.getX()) / 2, (startAxis.getY() + endAxis.getY()) / 2); |
125 |
Point2D third = new Point2D.Double(x, y); |
126 |
double distance = middle.distance(third);
|
127 |
addGeometry(ShapeFactory.createEllipse(startAxis, endAxis, distance)); |
128 |
} else if (status.equals("ExecuteMap.Third")) { |
129 |
Point2D middle = new Point2D.Double((startAxis.getX() + |
130 |
endAxis.getX()) / 2, (startAxis.getY() + endAxis.getY()) / 2); |
131 |
Point2D third = new Point2D.Double(x, y); |
132 |
double distance = middle.distance(third);
|
133 |
addGeometry(ShapeFactory.createEllipse(startAxis, endAxis, distance)); |
134 |
} |
135 |
} |
136 |
|
137 |
/**
|
138 |
* M?todo para dibujar la lo necesario para el estado en el que nos
|
139 |
* encontremos.
|
140 |
*
|
141 |
* @param g Graphics sobre el que dibujar.
|
142 |
* @param selectedGeometries BitSet con las geometr?as seleccionadas.
|
143 |
* @param x par?metro x del punto que se pase para dibujar.
|
144 |
* @param y par?metro x del punto que se pase para dibujar.
|
145 |
*/
|
146 |
public void drawOperation(Graphics g,double x, |
147 |
double y) {
|
148 |
EllipseCADToolState actualState = _fsm.getState(); |
149 |
String status = actualState.getName();
|
150 |
|
151 |
if (status.equals("ExecuteMap.First")) { |
152 |
drawLine((Graphics2D) g, startAxis, new Point2D.Double(x, y)); |
153 |
} else if (status.equals("ExecuteMap.Second")) { |
154 |
Point2D middle = new Point2D.Double((startAxis.getX() + |
155 |
endAxis.getX()) / 2, (startAxis.getY() + endAxis.getY()) / 2); |
156 |
|
157 |
Point2D third = new Point2D.Double(x, y); |
158 |
|
159 |
double distance = middle.distance(third);
|
160 |
|
161 |
ShapeFactory.createEllipse(startAxis, endAxis, distance).draw((Graphics2D) g,
|
162 |
getCadToolAdapter().getMapControl().getViewPort(), |
163 |
CADTool.modifySymbol); |
164 |
|
165 |
Point2D mediop = new Point2D.Double((startAxis.getX() + |
166 |
endAxis.getX()) / 2, (startAxis.getY() + endAxis.getY()) / 2); |
167 |
drawLine((Graphics2D) g, mediop, third);
|
168 |
} |
169 |
} |
170 |
|
171 |
/**
|
172 |
* Add a diferent option.
|
173 |
*
|
174 |
* @param sel DOCUMENT ME!
|
175 |
* @param s Diferent option.
|
176 |
*/
|
177 |
public void addOption(String s) { |
178 |
// TODO Auto-generated method stub
|
179 |
} |
180 |
|
181 |
/* (non-Javadoc)
|
182 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
183 |
*/
|
184 |
public void addValue(double d) { |
185 |
EllipseCADToolState actualState = (EllipseCADToolState) _fsm.getPreviousState(); |
186 |
String status = actualState.getName();
|
187 |
|
188 |
if (status.equals("ExecuteMap.Fourth")) { |
189 |
double distance = d;
|
190 |
addGeometry(ShapeFactory.createEllipse(startAxis, endAxis, distance)); |
191 |
} |
192 |
} |
193 |
} |