svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.editing.app / org.gvsig.editing.app.mainplugin / src / main / java / org / gvsig / editing / gui / cad / tools / ArcCADTool.java @ 40557
History | View | Annotate | Download (5.92 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.editing.gui.cad.tools; |
25 |
|
26 |
import java.awt.event.InputEvent; |
27 |
import java.awt.geom.Point2D; |
28 |
|
29 |
import javax.swing.JOptionPane; |
30 |
|
31 |
import org.gvsig.andami.PluginServices; |
32 |
import org.gvsig.app.ApplicationLocator; |
33 |
import org.gvsig.editing.gui.cad.exception.CommandException; |
34 |
import org.gvsig.editing.gui.cad.tools.smc.ArcCADToolContext; |
35 |
import org.gvsig.editing.gui.cad.tools.smc.ArcCADToolContext.ArcCADToolState; |
36 |
import org.gvsig.fmap.geom.Geometry; |
37 |
import org.gvsig.fmap.geom.primitive.Point; |
38 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
39 |
import org.gvsig.i18n.Messages; |
40 |
|
41 |
/**
|
42 |
*
|
43 |
* @author Vicente Caballero Navarro
|
44 |
*/
|
45 |
public class ArcCADTool extends AbstractCurveCADTool { |
46 |
|
47 |
private ArcCADToolContext _fsm;
|
48 |
private Point p1; |
49 |
private Point p2; |
50 |
private Point p3; |
51 |
|
52 |
/**
|
53 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
54 |
* carga previa a la utilizaci?n de la herramienta.
|
55 |
*/
|
56 |
public void init() { |
57 |
_fsm = new ArcCADToolContext(this); |
58 |
} |
59 |
|
60 |
public void transition(double x, double y, InputEvent event) { |
61 |
_fsm.addPoint(x, y, event); |
62 |
} |
63 |
|
64 |
public void transition(double d) { |
65 |
_fsm.addValue(d); |
66 |
} |
67 |
|
68 |
public void transition(String s) throws CommandException { |
69 |
if (!super.changeCommand(s)) { |
70 |
_fsm.addOption(s); |
71 |
} |
72 |
} |
73 |
|
74 |
/**
|
75 |
* Equivale al transition del prototipo pero sin pasarle como par? metro el
|
76 |
* editableFeatureSource que ya estar? creado.
|
77 |
*
|
78 |
* @param sel
|
79 |
* Bitset con las geometr?as que est?n seleccionadas.
|
80 |
* @param x
|
81 |
* par?metro x del punto que se pase en esta transici?n.
|
82 |
* @param y
|
83 |
* par?metro y del punto que se pase en esta transici?n.
|
84 |
*/
|
85 |
public void addPoint(double x, double y, InputEvent event) { |
86 |
ArcCADToolState actualState = (ArcCADToolState) _fsm.getPreviousState(); |
87 |
String status = actualState.getName();
|
88 |
|
89 |
if (status.equals("Arc.FirstPoint")) { |
90 |
p1 = createPoint(x, y); |
91 |
} else
|
92 |
if (status.equals("Arc.SecondPoint")) { |
93 |
p2 = createPoint(x, y); |
94 |
} else
|
95 |
if (status.equals("Arc.ThirdPoint")) { |
96 |
p3 = createPoint(x, y); |
97 |
Geometry ig = createArc(p1, p2, p3); |
98 |
if (ig != null) { |
99 |
insertAndSelectGeometry(ig); |
100 |
} else {
|
101 |
ApplicationLocator.getManager().message( |
102 |
Messages.getText("_Unable_to_create_arc"),
|
103 |
JOptionPane.ERROR_MESSAGE);
|
104 |
} |
105 |
} |
106 |
} |
107 |
|
108 |
/**
|
109 |
* M?todo para dibujar lo necesario para el estado en el que nos
|
110 |
* encontremos.
|
111 |
*
|
112 |
* @param g
|
113 |
* Graphics sobre el que dibujar.
|
114 |
* @param selectedGeometries
|
115 |
* BitSet con las geometr?as seleccionadas.
|
116 |
* @param x
|
117 |
* par?metro x del punto que se pase para dibujar.
|
118 |
* @param y
|
119 |
* par?metro x del punto que se pase para dibujar.
|
120 |
*/
|
121 |
public void drawOperation(MapControlDrawer renderer, double x, double y) { |
122 |
ArcCADToolState actualState = _fsm.getState(); |
123 |
String status = actualState.getName();
|
124 |
|
125 |
if (status.equals("Arc.SecondPoint")) { |
126 |
renderer.drawLine(new Point2D.Double(p1.getX(), p1.getY()), |
127 |
new Point2D.Double(x, y), |
128 |
mapControlManager.getGeometrySelectionSymbol()); |
129 |
} else
|
130 |
if (status.equals("Arc.ThirdPoint")) { |
131 |
Point current = createPoint(x, y);
|
132 |
|
133 |
Geometry ig = createArc(p1, p2, current); |
134 |
|
135 |
if (ig != null) { |
136 |
/*
|
137 |
* sometims it's not possible to create arc
|
138 |
* (example: aligned points)
|
139 |
*/
|
140 |
renderer.draw(ig, |
141 |
mapControlManager.getGeometrySelectionSymbol()); |
142 |
|
143 |
Point2D p =
|
144 |
getCadToolAdapter().getMapControl().getViewPort() |
145 |
.fromMapPoint(p1.getX(), p1.getY()); |
146 |
renderer.drawRect((int) p.getX(), (int) p.getY(), 1, 1); |
147 |
p = |
148 |
getCadToolAdapter().getMapControl().getViewPort() |
149 |
.fromMapPoint(p2.getX(), p2.getY()); |
150 |
renderer.drawRect((int) p.getX(), (int) p.getY(), 1, 1); |
151 |
} |
152 |
} |
153 |
} |
154 |
|
155 |
/**
|
156 |
* Add a diferent option.
|
157 |
*
|
158 |
* @param sel
|
159 |
* DOCUMENT ME!
|
160 |
* @param s
|
161 |
* Diferent option.
|
162 |
*/
|
163 |
public void addOption(String s) { |
164 |
// Nothing to do
|
165 |
} |
166 |
|
167 |
public void addValue(double d) { |
168 |
// Nothing to do
|
169 |
} |
170 |
|
171 |
public String getName() { |
172 |
return PluginServices.getText(this, "arc_"); |
173 |
} |
174 |
|
175 |
public String toString() { |
176 |
return "_arc"; |
177 |
} |
178 |
|
179 |
@Override
|
180 |
protected int getSupportedPrimitiveGeometryType() { |
181 |
return ARC;
|
182 |
} |
183 |
|
184 |
} |