svn-gvsig-desktop / tags / v1_0_2_RELEASE / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / EllipseCADTool.java @ 11432
History | View | Annotate | Download (6.49 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.event.InputEvent; |
46 |
import java.awt.geom.Point2D; |
47 |
|
48 |
import com.iver.andami.PluginServices; |
49 |
import com.iver.cit.gvsig.fmap.core.FShape; |
50 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
51 |
import com.iver.cit.gvsig.gui.cad.DefaultCADTool; |
52 |
import com.iver.cit.gvsig.gui.cad.exception.CommandException; |
53 |
import com.iver.cit.gvsig.gui.cad.tools.smc.EllipseCADToolContext; |
54 |
import com.iver.cit.gvsig.gui.cad.tools.smc.EllipseCADToolContext.EllipseCADToolState; |
55 |
|
56 |
|
57 |
/**
|
58 |
* DOCUMENT ME!
|
59 |
*
|
60 |
* @author Vicente Caballero Navarro
|
61 |
*/
|
62 |
public class EllipseCADTool extends DefaultCADTool { |
63 |
private EllipseCADToolContext _fsm;
|
64 |
private Point2D startAxis; |
65 |
private Point2D endAxis; |
66 |
|
67 |
/**
|
68 |
* Crea un nuevo LineCADTool.
|
69 |
*/
|
70 |
public EllipseCADTool() {
|
71 |
|
72 |
} |
73 |
|
74 |
/**
|
75 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
76 |
* carga previa a la utilizaci?n de la herramienta.
|
77 |
*/
|
78 |
public void init() { |
79 |
_fsm = new EllipseCADToolContext(this); |
80 |
} |
81 |
|
82 |
/* (non-Javadoc)
|
83 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
84 |
*/
|
85 |
public void transition(double x, double y, InputEvent event) { |
86 |
_fsm.addPoint(x, y, event); |
87 |
} |
88 |
|
89 |
/* (non-Javadoc)
|
90 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
|
91 |
*/
|
92 |
public void transition(double d) { |
93 |
_fsm.addValue(d); |
94 |
} |
95 |
|
96 |
/* (non-Javadoc)
|
97 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
|
98 |
*/
|
99 |
public void transition(String s) throws CommandException { |
100 |
if (!super.changeCommand(s)){ |
101 |
_fsm.addOption(s); |
102 |
} |
103 |
} |
104 |
|
105 |
/**
|
106 |
* Equivale al transition del prototipo pero sin pasarle como par? metro el
|
107 |
* editableFeatureSource que ya estar? creado.
|
108 |
*
|
109 |
* @param sel Bitset con las geometr?as que est?n seleccionadas.
|
110 |
* @param x par?metro x del punto que se pase en esta transici?n.
|
111 |
* @param y par?metro y del punto que se pase en esta transici?n.
|
112 |
*/
|
113 |
public void addPoint(double x, double y,InputEvent event) { |
114 |
EllipseCADToolState actualState = (EllipseCADToolState) _fsm.getPreviousState(); |
115 |
String status = actualState.getName();
|
116 |
|
117 |
if (status.equals("Ellipse.FirstPointAxis")) { |
118 |
startAxis = new Point2D.Double(x, y); |
119 |
} else if (status.equals("Ellipse.SecondPointAxis")) { |
120 |
endAxis = new Point2D.Double(x, y); |
121 |
} else if (status.equals("Ellipse.DistanceOtherAxis")) { |
122 |
Point2D middle = new Point2D.Double((startAxis.getX() + |
123 |
endAxis.getX()) / 2, (startAxis.getY() + endAxis.getY()) / 2); |
124 |
Point2D third = new Point2D.Double(x, y); |
125 |
double distance = middle.distance(third);
|
126 |
addGeometry(ShapeFactory.createEllipse(startAxis, endAxis, distance)); |
127 |
} |
128 |
} |
129 |
|
130 |
/**
|
131 |
* M?todo para dibujar la lo necesario para el estado en el que nos
|
132 |
* encontremos.
|
133 |
*
|
134 |
* @param g Graphics sobre el que dibujar.
|
135 |
* @param selectedGeometries BitSet con las geometr?as seleccionadas.
|
136 |
* @param x par?metro x del punto que se pase para dibujar.
|
137 |
* @param y par?metro x del punto que se pase para dibujar.
|
138 |
*/
|
139 |
public void drawOperation(Graphics g,double x, |
140 |
double y) {
|
141 |
EllipseCADToolState actualState = _fsm.getState(); |
142 |
String status = actualState.getName();
|
143 |
|
144 |
if (status.equals("Ellipse.SecondPointAxis")) { |
145 |
drawLine((Graphics2D) g, startAxis, new Point2D.Double(x, y)); |
146 |
} else if (status.equals("Ellipse.DistanceOtherAxis")) { |
147 |
Point2D middle = new Point2D.Double((startAxis.getX() + |
148 |
endAxis.getX()) / 2, (startAxis.getY() + endAxis.getY()) / 2); |
149 |
|
150 |
Point2D third = new Point2D.Double(x, y); |
151 |
|
152 |
double distance = middle.distance(third);
|
153 |
|
154 |
ShapeFactory.createEllipse(startAxis, endAxis, distance).draw((Graphics2D) g,
|
155 |
getCadToolAdapter().getMapControl().getViewPort(), |
156 |
DefaultCADTool.modifySymbol); |
157 |
|
158 |
Point2D mediop = new Point2D.Double((startAxis.getX() + |
159 |
endAxis.getX()) / 2, (startAxis.getY() + endAxis.getY()) / 2); |
160 |
drawLine((Graphics2D) g, mediop, third);
|
161 |
} |
162 |
} |
163 |
|
164 |
/**
|
165 |
* Add a diferent option.
|
166 |
*
|
167 |
* @param sel DOCUMENT ME!
|
168 |
* @param s Diferent option.
|
169 |
*/
|
170 |
public void addOption(String s) { |
171 |
// TODO Auto-generated method stub
|
172 |
} |
173 |
|
174 |
/* (non-Javadoc)
|
175 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
176 |
*/
|
177 |
public void addValue(double d) { |
178 |
EllipseCADToolState actualState = (EllipseCADToolState) _fsm.getPreviousState(); |
179 |
String status = actualState.getName();
|
180 |
|
181 |
if (status.equals("Ellipse.DistanceOtherAxis")) { |
182 |
double distance = d;
|
183 |
addGeometry(ShapeFactory.createEllipse(startAxis, endAxis, distance)); |
184 |
} |
185 |
} |
186 |
|
187 |
public String getName() { |
188 |
return PluginServices.getText(this,"ellipse_"); |
189 |
} |
190 |
|
191 |
public String toString() { |
192 |
return "_ellipse"; |
193 |
} |
194 |
public boolean isApplicable(int shapeType) { |
195 |
switch (shapeType) {
|
196 |
case FShape.POINT:
|
197 |
case FShape.MULTIPOINT:
|
198 |
return false; |
199 |
} |
200 |
return true; |
201 |
} |
202 |
} |