svn-gvsig-desktop / branches / pilotoDWG / applications / appgvSIG / src / com / iver / cit / gvsig / gui / cad / tools / EllipseCadTool.java @ 1763
History | View | Annotate | Download (5.43 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.layers.FBitSet; |
48 |
import com.iver.cit.gvsig.gui.cad.CadTool; |
49 |
import com.iver.cit.gvsig.gui.cad.automaton.Elipse; |
50 |
|
51 |
import com.iver.fsac.Automaton; |
52 |
|
53 |
import java.awt.Graphics; |
54 |
import java.awt.Graphics2D; |
55 |
import java.awt.geom.Point2D; |
56 |
|
57 |
import java.io.IOException; |
58 |
|
59 |
|
60 |
/**
|
61 |
* Herramienta para la creaci?n de una elipse a partir de dos puntos y la
|
62 |
* distancia del eje mayor.
|
63 |
*
|
64 |
* @author Vicente Caballero Navarro
|
65 |
*/
|
66 |
public class EllipseCadTool extends AbstractCadTool { |
67 |
private static Status[] STATUS = { |
68 |
new Status("Precise punto inicial de eje de elipse(x,y):"), |
69 |
new Status("Precise punto final de eje(x,y):"), |
70 |
new Status("Precise distancia otro eje(d):") |
71 |
}; |
72 |
private Elipse ellipseStatus = new Elipse(); |
73 |
private Point2D startAxis; |
74 |
private Point2D endAxis; |
75 |
private double distance; |
76 |
|
77 |
/**
|
78 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#transition(java.lang.String,
|
79 |
* com.iver.cit.gvsig.fmap.edition.EditableFeatureSource,
|
80 |
* com.iver.cit.gvsig.fmap.layers.FBitSet, double[])
|
81 |
*/
|
82 |
public int transition(String text, EditableFeatureSource editingSource, |
83 |
FBitSet selectedGeometries, double[] values) { |
84 |
int ret = ellipseStatus.transition(text);
|
85 |
|
86 |
int status = ellipseStatus.getStatus();
|
87 |
|
88 |
if (status == 0) { |
89 |
} else if (status == 1) { |
90 |
startAxis = new Point2D.Double(values[0], values[1]); |
91 |
} else if (status == 2) { |
92 |
endAxis = new Point2D.Double(values[0], values[1]); |
93 |
} else if (status == 3) { |
94 |
Point2D middle = new Point2D.Double((startAxis.getX() + |
95 |
endAxis.getX()) / 2, (startAxis.getY() + endAxis.getY()) / 2); |
96 |
|
97 |
Point2D third = new Point2D.Double(values[0], values[1]); |
98 |
|
99 |
distance = middle.distance(third); |
100 |
|
101 |
try {
|
102 |
editingSource.addGeometry(ShapeFactory.createEllipse( |
103 |
startAxis, endAxis, distance)); |
104 |
} catch (DriverIOException e) {
|
105 |
e.printStackTrace(); |
106 |
} catch (IOException e) { |
107 |
e.printStackTrace(); |
108 |
} |
109 |
|
110 |
ret = ret | ellipseStatus.transition("cancel");
|
111 |
} else if (status == 4) { |
112 |
distance = values[0];
|
113 |
|
114 |
try {
|
115 |
editingSource.addGeometry(ShapeFactory.createEllipse( |
116 |
startAxis, endAxis, distance)); |
117 |
} catch (DriverIOException e) {
|
118 |
e.printStackTrace(); |
119 |
} catch (IOException e) { |
120 |
e.printStackTrace(); |
121 |
} |
122 |
|
123 |
ret = ret | ellipseStatus.transition("cancel");
|
124 |
} |
125 |
|
126 |
System.err.println(startAxis);
|
127 |
System.err.println(endAxis);
|
128 |
System.err.println(distance);
|
129 |
|
130 |
return ret;
|
131 |
} |
132 |
|
133 |
/**
|
134 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#drawOperation(java.awt.Graphics,
|
135 |
* com.iver.cit.gvsig.fmap.edition.EditableFeatureSource,
|
136 |
* com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
137 |
*/
|
138 |
public void drawOperation(Graphics g, EditableFeatureSource efs, |
139 |
FBitSet selectedGeometries, double x, double y) { |
140 |
int status = ellipseStatus.getStatus();
|
141 |
|
142 |
if (status == 0) { |
143 |
} else if (status == 1) { |
144 |
drawLine((Graphics2D) g, startAxis, new Point2D.Double(x, y)); |
145 |
} else if (status == 2) { |
146 |
Point2D middle = new Point2D.Double((startAxis.getX() + |
147 |
endAxis.getX()) / 2, (startAxis.getY() + endAxis.getY()) / 2); |
148 |
|
149 |
Point2D third = new Point2D.Double(x, y); |
150 |
|
151 |
distance = middle.distance(third); |
152 |
|
153 |
ShapeFactory.createEllipse(startAxis, endAxis, distance).draw((Graphics2D) g,
|
154 |
getCadToolAdapter().getMapControl().getViewPort(), |
155 |
CadTool.modifySymbol); |
156 |
|
157 |
Point2D mediop = new Point2D.Double((startAxis.getX() + |
158 |
endAxis.getX()) / 2, (startAxis.getY() + endAxis.getY()) / 2); |
159 |
drawLine((Graphics2D) g, mediop, third);
|
160 |
} |
161 |
} |
162 |
|
163 |
/**
|
164 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#getQuestion()
|
165 |
*/
|
166 |
public String getQuestion() { |
167 |
return STATUS[ellipseStatus.getStatus()].getQuestion();
|
168 |
} |
169 |
|
170 |
/**
|
171 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#initializeStatus()
|
172 |
*/
|
173 |
public void initializeStatus() { |
174 |
startAxis = null;
|
175 |
endAxis = null;
|
176 |
distance = 0;
|
177 |
ellipseStatus.initialize(); |
178 |
} |
179 |
|
180 |
/**
|
181 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#getAutomaton()
|
182 |
*/
|
183 |
public Automaton getAutomaton() {
|
184 |
return ellipseStatus;
|
185 |
} |
186 |
|
187 |
/**
|
188 |
* @see com.iver.cit.gvsig.gui.cad.CadTool#getName()
|
189 |
*/
|
190 |
public String getName() { |
191 |
return "ELIPSE"; |
192 |
} |
193 |
} |