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