root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / ArcCADTool.java @ 37138
History | View | Annotate | Download (5.56 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.editing.gui.cad.tools; |
23 |
|
24 |
import java.awt.event.InputEvent; |
25 |
import java.awt.geom.Point2D; |
26 |
|
27 |
import org.gvsig.andami.PluginServices; |
28 |
import org.gvsig.editing.gui.cad.DefaultCADTool; |
29 |
import org.gvsig.editing.gui.cad.exception.CommandException; |
30 |
import org.gvsig.editing.gui.cad.tools.smc.ArcCADToolContext; |
31 |
import org.gvsig.editing.gui.cad.tools.smc.ArcCADToolContext.ArcCADToolState; |
32 |
import org.gvsig.fmap.geom.Geometry; |
33 |
import org.gvsig.fmap.geom.primitive.Point; |
34 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
35 |
|
36 |
/**
|
37 |
*
|
38 |
* @author Vicente Caballero Navarro
|
39 |
*/
|
40 |
public class ArcCADTool extends DefaultCADTool { |
41 |
|
42 |
private ArcCADToolContext _fsm;
|
43 |
private Point p1; |
44 |
private Point p2; |
45 |
private Point p3; |
46 |
|
47 |
/**
|
48 |
* Crea un nuevo LineCADTool.
|
49 |
*/
|
50 |
public ArcCADTool() {
|
51 |
} |
52 |
|
53 |
/**
|
54 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
55 |
* carga previa a la utilizaci?n de la herramienta.
|
56 |
*/
|
57 |
public void init() { |
58 |
_fsm = new ArcCADToolContext(this); |
59 |
} |
60 |
|
61 |
public void transition(double x, double y, InputEvent event) { |
62 |
_fsm.addPoint(x, y, event); |
63 |
} |
64 |
|
65 |
public void transition(double d) { |
66 |
_fsm.addValue(d); |
67 |
} |
68 |
|
69 |
public void transition(String s) throws CommandException { |
70 |
if (!super.changeCommand(s)) { |
71 |
_fsm.addOption(s); |
72 |
} |
73 |
} |
74 |
|
75 |
/**
|
76 |
* Equivale al transition del prototipo pero sin pasarle como par? metro el
|
77 |
* editableFeatureSource que ya estar? creado.
|
78 |
*
|
79 |
* @param sel
|
80 |
* Bitset con las geometr?as que est?n seleccionadas.
|
81 |
* @param x
|
82 |
* par?metro x del punto que se pase en esta transici?n.
|
83 |
* @param y
|
84 |
* par?metro y del punto que se pase en esta transici?n.
|
85 |
*/
|
86 |
public void addPoint(double x, double y, InputEvent event) { |
87 |
ArcCADToolState actualState = (ArcCADToolState) _fsm.getPreviousState(); |
88 |
String status = actualState.getName();
|
89 |
|
90 |
if (status.equals("Arc.FirstPoint")) { |
91 |
p1 = createPoint(x, y); |
92 |
} else
|
93 |
if (status.equals("Arc.SecondPoint")) { |
94 |
p2 = createPoint(x, y); |
95 |
} else
|
96 |
if (status.equals("Arc.ThirdPoint")) { |
97 |
p3 = createPoint(x, y); |
98 |
Geometry ig = createArc(p1, p2, p3); |
99 |
if (ig != null) { |
100 |
insertAndSelectGeometry(ig); |
101 |
} |
102 |
} |
103 |
} |
104 |
|
105 |
/**
|
106 |
* M?todo para dibujar lo necesario para el estado en el que nos
|
107 |
* encontremos.
|
108 |
*
|
109 |
* @param g
|
110 |
* Graphics sobre el que dibujar.
|
111 |
* @param selectedGeometries
|
112 |
* BitSet con las geometr?as seleccionadas.
|
113 |
* @param x
|
114 |
* par?metro x del punto que se pase para dibujar.
|
115 |
* @param y
|
116 |
* par?metro x del punto que se pase para dibujar.
|
117 |
*/
|
118 |
public void drawOperation(MapControlDrawer renderer, double x, double y) { |
119 |
ArcCADToolState actualState = _fsm.getState(); |
120 |
String status = actualState.getName();
|
121 |
|
122 |
if (status.equals("Arc.SecondPoint")) { |
123 |
renderer.drawLine(new Point2D.Double(p1.getX(), p1.getY()), |
124 |
new Point2D.Double(x, y), |
125 |
mapControlManager.getGeometrySelectionSymbol()); |
126 |
} else
|
127 |
if (status.equals("Arc.ThirdPoint")) { |
128 |
Point current = createPoint(x, y);
|
129 |
|
130 |
Geometry ig = createArc(p1, p2, current); |
131 |
renderer.draw(ig, |
132 |
mapControlManager.getGeometrySelectionSymbol()); |
133 |
|
134 |
Point2D p =
|
135 |
getCadToolAdapter().getMapControl().getViewPort() |
136 |
.fromMapPoint(p1.getX(), p1.getY()); |
137 |
renderer.drawRect((int) p.getX(), (int) p.getY(), 1, 1); |
138 |
p = |
139 |
getCadToolAdapter().getMapControl().getViewPort() |
140 |
.fromMapPoint(p2.getX(), p2.getY()); |
141 |
renderer.drawRect((int) p.getX(), (int) p.getY(), 1, 1); |
142 |
} |
143 |
} |
144 |
|
145 |
/**
|
146 |
* Add a diferent option.
|
147 |
*
|
148 |
* @param sel
|
149 |
* DOCUMENT ME!
|
150 |
* @param s
|
151 |
* Diferent option.
|
152 |
*/
|
153 |
public void addOption(String s) { |
154 |
// TODO Auto-generated method stub
|
155 |
} |
156 |
|
157 |
public void addValue(double d) { |
158 |
} |
159 |
|
160 |
public String getName() { |
161 |
return PluginServices.getText(this, "arc_"); |
162 |
} |
163 |
|
164 |
public String toString() { |
165 |
return "_arc"; |
166 |
} |
167 |
|
168 |
public boolean isApplicable(int shapeType) { |
169 |
switch (shapeType) {
|
170 |
case Geometry.TYPES.POINT:
|
171 |
case Geometry.TYPES.SURFACE:
|
172 |
case Geometry.TYPES.MULTIPOINT:
|
173 |
return false; |
174 |
} |
175 |
return true; |
176 |
} |
177 |
|
178 |
} |