Revision 30335 branches/v2_0_0_prep/extensions/extEditing/src/org/gvsig/editing/gui/cad/tools/ArcCADTool.java
ArcCADTool.java | ||
---|---|---|
40 | 40 |
*/ |
41 | 41 |
package org.gvsig.editing.gui.cad.tools; |
42 | 42 |
|
43 |
import java.awt.Graphics; |
|
44 |
import java.awt.Graphics2D; |
|
45 | 43 |
import java.awt.Image; |
46 | 44 |
import java.awt.event.InputEvent; |
47 | 45 |
import java.awt.geom.Point2D; |
... | ... | |
53 | 51 |
import org.gvsig.editing.gui.cad.tools.smc.ArcCADToolContext.ArcCADToolState; |
54 | 52 |
import org.gvsig.editing.layers.VectorialLayerEdited; |
55 | 53 |
import org.gvsig.fmap.geom.Geometry; |
56 |
import org.gvsig.fmap.geom.operation.Draw; |
|
57 |
import org.gvsig.fmap.geom.operation.DrawOperationContext; |
|
58 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
59 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
60 | 54 |
import org.gvsig.fmap.geom.primitive.Point; |
55 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
|
61 | 56 |
|
62 | 57 |
|
63 | 58 |
|
... | ... | |
67 | 62 |
* @author Vicente Caballero Navarro |
68 | 63 |
*/ |
69 | 64 |
public class ArcCADTool extends DefaultCADTool { |
70 |
private ArcCADToolContext _fsm;
|
|
71 |
private Point p1;
|
|
72 |
private Point p2;
|
|
73 |
private Point p3;
|
|
65 |
private ArcCADToolContext _fsm;
|
|
66 |
private Point p1;
|
|
67 |
private Point p2;
|
|
68 |
private Point p3;
|
|
74 | 69 |
|
75 |
/**
|
|
76 |
* Crea un nuevo LineCADTool.
|
|
77 |
*/
|
|
78 |
public ArcCADTool() {
|
|
79 |
}
|
|
70 |
/**
|
|
71 |
* Crea un nuevo LineCADTool.
|
|
72 |
*/
|
|
73 |
public ArcCADTool() {
|
|
74 |
}
|
|
80 | 75 |
|
81 |
/**
|
|
82 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
|
83 |
* carga previa a la utilizaci?n de la herramienta.
|
|
84 |
*/
|
|
85 |
public void init() {
|
|
86 |
_fsm = new ArcCADToolContext(this);
|
|
87 |
}
|
|
76 |
/**
|
|
77 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
|
78 |
* carga previa a la utilizaci?n de la herramienta.
|
|
79 |
*/
|
|
80 |
public void init() {
|
|
81 |
_fsm = new ArcCADToolContext(this);
|
|
82 |
}
|
|
88 | 83 |
|
89 |
/* (non-Javadoc)
|
|
90 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
|
91 |
*/
|
|
92 |
public void transition(double x, double y, InputEvent event) {
|
|
93 |
_fsm.addPoint(x, y,event);
|
|
94 |
}
|
|
84 |
/* (non-Javadoc)
|
|
85 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
|
86 |
*/
|
|
87 |
public void transition(double x, double y, InputEvent event) {
|
|
88 |
_fsm.addPoint(x, y,event);
|
|
89 |
}
|
|
95 | 90 |
|
96 |
/* (non-Javadoc)
|
|
97 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
|
|
98 |
*/
|
|
99 |
public void transition(double d){
|
|
100 |
_fsm.addValue(d);
|
|
101 |
}
|
|
91 |
/* (non-Javadoc)
|
|
92 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
|
|
93 |
*/
|
|
94 |
public void transition(double d){
|
|
95 |
_fsm.addValue(d);
|
|
96 |
}
|
|
102 | 97 |
|
103 |
/* (non-Javadoc)
|
|
104 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
|
|
105 |
*/
|
|
106 |
public void transition(String s) throws CommandException {
|
|
107 |
if (!super.changeCommand(s)){
|
|
108 |
_fsm.addOption(s);
|
|
109 |
}
|
|
110 |
}
|
|
98 |
/* (non-Javadoc)
|
|
99 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
|
|
100 |
*/
|
|
101 |
public void transition(String s) throws CommandException {
|
|
102 |
if (!super.changeCommand(s)){
|
|
103 |
_fsm.addOption(s);
|
|
104 |
}
|
|
105 |
}
|
|
111 | 106 |
|
112 |
/**
|
|
113 |
* Equivale al transition del prototipo pero sin pasarle como par? metro el
|
|
114 |
* editableFeatureSource que ya estar? creado.
|
|
115 |
*
|
|
116 |
* @param sel Bitset con las geometr?as que est?n seleccionadas.
|
|
117 |
* @param x par?metro x del punto que se pase en esta transici?n.
|
|
118 |
* @param y par?metro y del punto que se pase en esta transici?n.
|
|
119 |
*/
|
|
120 |
public void addPoint(double x, double y,InputEvent event) {
|
|
121 |
ArcCADToolState actualState = (ArcCADToolState) _fsm.getPreviousState();
|
|
122 |
String status = actualState.getName();
|
|
107 |
/**
|
|
108 |
* Equivale al transition del prototipo pero sin pasarle como par? metro el
|
|
109 |
* editableFeatureSource que ya estar? creado.
|
|
110 |
*
|
|
111 |
* @param sel Bitset con las geometr?as que est?n seleccionadas.
|
|
112 |
* @param x par?metro x del punto que se pase en esta transici?n.
|
|
113 |
* @param y par?metro y del punto que se pase en esta transici?n.
|
|
114 |
*/
|
|
115 |
public void addPoint(double x, double y,InputEvent event) {
|
|
116 |
ArcCADToolState actualState = (ArcCADToolState) _fsm.getPreviousState();
|
|
117 |
String status = actualState.getName();
|
|
123 | 118 |
|
124 |
if (status.equals("Arc.FirstPoint")) {
|
|
125 |
p1 = createPoint(x, y);
|
|
126 |
} else if (status.equals("Arc.SecondPoint")) {
|
|
127 |
p2 = createPoint(x, y);
|
|
128 |
} else if (status.equals("Arc.ThirdPoint")) {
|
|
129 |
p3 = createPoint(x, y);
|
|
130 |
Geometry ig = createArc(p1, p2, p3);
|
|
131 |
if (ig != null) {
|
|
132 |
insertAndSelectGeometry(ig);
|
|
133 |
}
|
|
134 |
}
|
|
135 |
}
|
|
119 |
if (status.equals("Arc.FirstPoint")) {
|
|
120 |
p1 = createPoint(x, y);
|
|
121 |
} else if (status.equals("Arc.SecondPoint")) {
|
|
122 |
p2 = createPoint(x, y);
|
|
123 |
} else if (status.equals("Arc.ThirdPoint")) {
|
|
124 |
p3 = createPoint(x, y);
|
|
125 |
Geometry ig = createArc(p1, p2, p3);
|
|
126 |
if (ig != null) {
|
|
127 |
insertAndSelectGeometry(ig);
|
|
128 |
}
|
|
129 |
}
|
|
130 |
}
|
|
136 | 131 |
|
137 |
/**
|
|
138 |
* M?todo para dibujar lo necesario para el estado en el que nos
|
|
139 |
* encontremos.
|
|
140 |
*
|
|
141 |
* @param g Graphics sobre el que dibujar.
|
|
142 |
* @param selectedGeometries BitSet con las geometr?as seleccionadas.
|
|
143 |
* @param x par?metro x del punto que se pase para dibujar.
|
|
144 |
* @param y par?metro x del punto que se pase para dibujar.
|
|
145 |
*/
|
|
146 |
public void drawOperation(Graphics g, double x,
|
|
147 |
double y) {
|
|
148 |
ArcCADToolState actualState = _fsm.getState();
|
|
149 |
String status = actualState.getName();
|
|
132 |
/**
|
|
133 |
* M?todo para dibujar lo necesario para el estado en el que nos
|
|
134 |
* encontremos.
|
|
135 |
*
|
|
136 |
* @param g Graphics sobre el que dibujar.
|
|
137 |
* @param selectedGeometries BitSet con las geometr?as seleccionadas.
|
|
138 |
* @param x par?metro x del punto que se pase para dibujar.
|
|
139 |
* @param y par?metro x del punto que se pase para dibujar.
|
|
140 |
*/
|
|
141 |
public void drawOperation(MapControlDrawer renderer, double x,
|
|
142 |
double y) {
|
|
143 |
ArcCADToolState actualState = _fsm.getState();
|
|
144 |
String status = actualState.getName();
|
|
150 | 145 |
|
151 |
if (status.equals("Arc.SecondPoint")) {
|
|
152 |
drawLine((Graphics2D) g, new Point2D.Double(p1.getX(), p1.getY()), new Point2D.Double(x, y),geometrySelectSymbol);
|
|
153 |
} else if (status.equals("Arc.ThirdPoint")) {
|
|
154 |
Point current = createPoint(x, y);
|
|
155 |
try{
|
|
156 |
Geometry ig = createArc(p1, p2, current);
|
|
146 |
if (status.equals("Arc.SecondPoint")) {
|
|
147 |
renderer.drawLine(new Point2D.Double(p1.getX(), p1.getY()),
|
|
148 |
new Point2D.Double(x, y),
|
|
149 |
mapControlManager.getGeometrySelectionSymbol());
|
|
150 |
} else if (status.equals("Arc.ThirdPoint")) {
|
|
151 |
Point current = createPoint(x, y);
|
|
157 | 152 |
|
158 |
if (ig != null) { |
|
159 |
DrawOperationContext doc=new DrawOperationContext(); |
|
160 |
doc.setGraphics((Graphics2D)g); |
|
161 |
doc.setViewPort(getCadToolAdapter().getMapControl().getViewPort()); |
|
162 |
doc.setSymbol(DefaultCADTool.geometrySelectSymbol); |
|
163 |
try { |
|
164 |
ig.invokeOperation(Draw.CODE,doc); |
|
165 |
} catch (GeometryOperationNotSupportedException e) { |
|
166 |
e.printStackTrace(); |
|
167 |
} catch (GeometryOperationException e) { |
|
168 |
e.printStackTrace(); |
|
169 |
} |
|
170 |
} |
|
171 |
}catch (IllegalArgumentException e) { |
|
172 |
// TODO: handle exception |
|
153 |
Geometry ig = createArc(p1, p2, current); |
|
154 |
renderer.draw(ig, mapControlManager.getGeometrySelectionSymbol()); |
|
155 |
|
|
156 |
Point2D p = getCadToolAdapter().getMapControl().getViewPort() |
|
157 |
.fromMapPoint(p1.getX(), p1.getY()); |
|
158 |
renderer.drawRect((int) p.getX(), (int) p.getY(), 1, 1); |
|
159 |
p = getCadToolAdapter().getMapControl().getViewPort().fromMapPoint(p2.getX(), |
|
160 |
p2.getY()); |
|
161 |
renderer.drawRect((int) p.getX(), (int) p.getY(), 1, 1); |
|
162 |
}else{ |
|
163 |
VectorialLayerEdited vle=getVLE(); |
|
164 |
if (!vle.getLayer().isVisible()) |
|
165 |
return; |
|
166 |
try{ |
|
167 |
Image imgSel = vle.getSelectionImage(); |
|
168 |
renderer.drawImage(imgSel, 0, 0); |
|
169 |
|
|
170 |
Image imgHand = vle.getHandlersImage(); |
|
171 |
renderer.drawImage(imgHand, 0, 0); |
|
172 |
}catch (Exception e) { |
|
173 | 173 |
} |
174 |
Point2D p = getCadToolAdapter().getMapControl().getViewPort() |
|
175 |
.fromMapPoint(p1.getX(), p1.getY()); |
|
176 |
g.drawRect((int) p.getX(), (int) p.getY(), 1, 1); |
|
177 |
p = getCadToolAdapter().getMapControl().getViewPort().fromMapPoint(p2.getX(), |
|
178 |
p2.getY()); |
|
179 |
g.drawRect((int) p.getX(), (int) p.getY(), 1, 1); |
|
180 |
}else{ |
|
181 |
VectorialLayerEdited vle=getVLE(); |
|
182 |
if (!vle.getLayer().isVisible()) |
|
183 |
return; |
|
184 |
try{ |
|
185 |
Image imgSel = vle.getSelectionImage(); |
|
186 |
if (imgSel!=null) |
|
187 |
g.drawImage(imgSel, 0, 0, null); |
|
188 |
Image imgHand = vle.getHandlersImage(); |
|
189 |
if (imgHand!=null) |
|
190 |
g.drawImage(imgHand, 0, 0, null); |
|
191 |
}catch (Exception e) { |
|
192 |
} |
|
193 |
} |
|
174 |
} |
|
194 | 175 |
|
195 |
}
|
|
176 |
}
|
|
196 | 177 |
|
197 |
/**
|
|
198 |
* Add a diferent option.
|
|
199 |
*
|
|
200 |
* @param sel DOCUMENT ME!
|
|
201 |
* @param s Diferent option.
|
|
202 |
*/
|
|
203 |
public void addOption(String s) {
|
|
204 |
// TODO Auto-generated method stub
|
|
205 |
}
|
|
178 |
/**
|
|
179 |
* Add a diferent option.
|
|
180 |
*
|
|
181 |
* @param sel DOCUMENT ME!
|
|
182 |
* @param s Diferent option.
|
|
183 |
*/
|
|
184 |
public void addOption(String s) {
|
|
185 |
// TODO Auto-generated method stub
|
|
186 |
}
|
|
206 | 187 |
|
207 |
/* (non-Javadoc)
|
|
208 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
|
209 |
*/
|
|
210 |
public void addValue(double d) {
|
|
211 |
}
|
|
188 |
/* (non-Javadoc)
|
|
189 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
|
190 |
*/
|
|
191 |
public void addValue(double d) {
|
|
192 |
}
|
|
212 | 193 |
|
213 | 194 |
public String getName() { |
214 | 195 |
return PluginServices.getText(this,"arc_"); |
Also available in: Unified diff