root / branches / pilotoDWG / applications / appgvSIG / src / com / iver / cit / gvsig / gui / cad / tools / CircleCadTool.java @ 1695
History | View | Annotate | Download (6.53 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 com.iver.cit.gvsig.fmap.core.ShapeFactory; |
44 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
45 |
import com.iver.cit.gvsig.fmap.edition.EditableFeatureSource; |
46 |
import com.iver.cit.gvsig.fmap.edition.cad.Status; |
47 |
import com.iver.cit.gvsig.fmap.edition.cad.TrigonometricalFunctions; |
48 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
49 |
import com.iver.cit.gvsig.gui.cad.CadTool; |
50 |
import com.iver.cit.gvsig.gui.cad.automaton.Circulo; |
51 |
|
52 |
import com.iver.fsac.Automaton; |
53 |
|
54 |
import java.awt.Graphics; |
55 |
import java.awt.Graphics2D; |
56 |
import java.awt.geom.Point2D; |
57 |
|
58 |
import java.io.IOException; |
59 |
|
60 |
|
61 |
/**
|
62 |
* Herramienta para crear una circunferencia a partir de tres puntos o del
|
63 |
* centro y el radio.
|
64 |
*
|
65 |
* @author Vicente Caballero Navarro
|
66 |
*/
|
67 |
public class CircleCadTool extends AbstractCadTool { |
68 |
private static Status[] STATUS = { |
69 |
new Status("Precise punto central o [3P]"), |
70 |
new Status("Precise radio"), |
71 |
new Status("Precise primer punto del c?rculo"), |
72 |
new Status("Precise segundo punto del c?rculo"), |
73 |
new Status("Precise tercer punto del c?rculo"), |
74 |
}; |
75 |
private Circulo circleStatus = new Circulo(); |
76 |
private Point2D center; |
77 |
private Point2D p1; |
78 |
private Point2D p2; |
79 |
private Point2D p3; |
80 |
|
81 |
/**
|
82 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#transition(java.lang.String,
|
83 |
* com.iver.cit.gvsig.fmap.edition.EditableFeatureSource,
|
84 |
* com.iver.cit.gvsig.fmap.layers.FBitSet, double[])
|
85 |
*/
|
86 |
public int transition(String text, EditableFeatureSource editingSource, |
87 |
FBitSet selectedGeometries, double[] values) { |
88 |
int ret = circleStatus.transition(text);
|
89 |
|
90 |
int status = circleStatus.getStatus();
|
91 |
|
92 |
if (status == 0) { |
93 |
} else if (status == 1) { |
94 |
center = new Point2D.Double(values[0], values[1]); |
95 |
} else if (status == 2) { |
96 |
} else if (status == 3) { |
97 |
p1 = new Point2D.Double(values[0], values[1]); |
98 |
} else if (status == 4) { |
99 |
p2 = new Point2D.Double(values[0], values[1]); |
100 |
} else if (status == 5) { |
101 |
p3 = new Point2D.Double(values[0], values[1]); |
102 |
center = TrigonometricalFunctions.getCircleCenter(p1, p2, p3); |
103 |
|
104 |
double radio = center.distance(p1);
|
105 |
|
106 |
try {
|
107 |
editingSource.addGeometry(ShapeFactory.createCircle(center, |
108 |
radio)); |
109 |
} catch (DriverIOException e) {
|
110 |
e.printStackTrace(); |
111 |
} catch (IOException e) { |
112 |
e.printStackTrace(); |
113 |
} |
114 |
|
115 |
ret = ret | circleStatus.transition("cancel");
|
116 |
} else if (status == 6) { |
117 |
try {
|
118 |
editingSource.addGeometry(ShapeFactory.createCircle(center, |
119 |
values[0]));
|
120 |
} catch (DriverIOException e) {
|
121 |
e.printStackTrace(); |
122 |
} catch (IOException e) { |
123 |
e.printStackTrace(); |
124 |
} |
125 |
|
126 |
ret = ret | circleStatus.transition("cancel");
|
127 |
} else if (status == 7) { |
128 |
try {
|
129 |
editingSource.addGeometry(ShapeFactory.createCircle(center, |
130 |
new Point2D.Double(values[0], values[1]))); |
131 |
} catch (DriverIOException e) {
|
132 |
e.printStackTrace(); |
133 |
} catch (IOException e) { |
134 |
e.printStackTrace(); |
135 |
} |
136 |
|
137 |
ret = ret | circleStatus.transition("cancel");
|
138 |
} |
139 |
|
140 |
return ret;
|
141 |
} |
142 |
|
143 |
/**
|
144 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#drawOperation(java.awt.Graphics,
|
145 |
* com.iver.cit.gvsig.fmap.edition.EditableFeatureSource,
|
146 |
* com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
147 |
*/
|
148 |
public void drawOperation(Graphics g, EditableFeatureSource efs, |
149 |
FBitSet selectedGeometries, double x, double y) { |
150 |
int status = circleStatus.getStatus();
|
151 |
|
152 |
if (status == 1) { |
153 |
Point2D currentPoint = new Point2D.Double(x, y); |
154 |
double dist = currentPoint.distance(center);
|
155 |
ShapeFactory.createCircle(center, dist).draw((Graphics2D) g,
|
156 |
getCadToolAdapter().getMapControl().getViewPort(), |
157 |
CadTool.modifySymbol); |
158 |
} else if (status == 2) { |
159 |
} else if (status == 3) { |
160 |
drawLine((Graphics2D) g, p1, new Point2D.Double(x, y)); |
161 |
} else if (status == 4) { |
162 |
Point2D currentPoint = new Point2D.Double(x, y); |
163 |
|
164 |
if (p1.getX() == p2.getX()) {
|
165 |
p2 = new Point2D.Double(p2.getX() + 0.0000001, p2.getY()); |
166 |
} else if (p1.getY() == p2.getY()) { |
167 |
p2 = new Point2D.Double(p2.getX(), p2.getY() + 0.0000001); |
168 |
} /*if (currentPoint.getX()==p1.getX()){
|
169 |
currentPoint=new Point2D.Double(currentPoint.getX()+0.0000001,currentPoint.getY());
|
170 |
}else if (currentPoint.getY()==p1.getY()){
|
171 |
currentPoint=new Point2D.Double(currentPoint.getX(),currentPoint.getY()+0.0000001);
|
172 |
}if (currentPoint.getX()==p2.getX()){
|
173 |
currentPoint=new Point2D.Double(currentPoint.getX()+0.0000001,currentPoint.getY());
|
174 |
}else if (currentPoint.getY()==p2.getY()){
|
175 |
currentPoint=new Point2D.Double(currentPoint.getX(),currentPoint.getY()+0.0000001);
|
176 |
}*/
|
177 |
Point2D currentCenter = TrigonometricalFunctions.getCircleCenter(p1,
|
178 |
p2, currentPoint); |
179 |
double radio = currentCenter.distance(p1);
|
180 |
ShapeFactory.createCircle(currentCenter, radio).draw((Graphics2D) g,
|
181 |
getCadToolAdapter().getMapControl().getViewPort(), |
182 |
CadTool.modifySymbol); |
183 |
} |
184 |
} |
185 |
|
186 |
/**
|
187 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#getQuestion()
|
188 |
*/
|
189 |
public String getQuestion() { |
190 |
return STATUS[circleStatus.getStatus()].getQuestion();
|
191 |
} |
192 |
|
193 |
/**
|
194 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#initializeStatus()
|
195 |
*/
|
196 |
public void initializeStatus() { |
197 |
circleStatus.initialize(); |
198 |
} |
199 |
|
200 |
/**
|
201 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#getAutomaton()
|
202 |
*/
|
203 |
public Automaton getAutomaton() {
|
204 |
return circleStatus;
|
205 |
} |
206 |
|
207 |
/**
|
208 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#getName()
|
209 |
*/
|
210 |
public String getName() { |
211 |
return "C?RCULO"; |
212 |
} |
213 |
} |