Revision 37328 branches/v2_0_0_prep/extensions/extEditing/src/org/gvsig/editing/gui/cad/tools/RectangleCADTool.java

View differences:

RectangleCADTool.java
25 25
import java.awt.geom.Point2D;
26 26

  
27 27
import org.gvsig.andami.PluginServices;
28
import org.gvsig.editing.gui.cad.DefaultCADTool;
29 28
import org.gvsig.editing.gui.cad.exception.CommandException;
30 29
import org.gvsig.editing.gui.cad.tools.smc.RectangleCADToolContext;
31 30
import org.gvsig.editing.gui.cad.tools.smc.RectangleCADToolContext.RectangleCADToolState;
32
import org.gvsig.fmap.geom.Geometry;
33 31
import org.gvsig.fmap.geom.primitive.GeneralPathX;
34 32
import org.gvsig.fmap.geom.primitive.OrientablePrimitive;
35 33
import org.gvsig.fmap.mapcontrol.MapControlDrawer;
36 34

  
37

  
38

  
39 35
/**
40 36
 * DOCUMENT ME!
41
 *
37
 * 
42 38
 * @author Vicente Caballero Navarro
43 39
 */
44
public class RectangleCADTool extends DefaultCADTool {
40
public class RectangleCADTool extends AbstractCurveSurfaceCADTool {
41

  
45 42
    protected RectangleCADToolContext _fsm;
46 43
    protected Point2D firstPoint;
47 44
    protected Point2D lastPoint;
48 45

  
49 46
    /**
50
     * Crea un nuevo LineCADTool.
51
     */
52
    public RectangleCADTool() {
53

  
54
    }
55

  
56
    /**
57 47
     * M?todo de incio, para poner el c?digo de todo lo que se requiera de una
58 48
     * carga previa a la utilizaci?n de la herramienta.
59 49
     */
......
61 51
        _fsm = new RectangleCADToolContext(this);
62 52
    }
63 53

  
64
    /* (non-Javadoc)
65
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
66
     */
67 54
    public void transition(double x, double y, InputEvent event) {
68 55
        _fsm.addPoint(x, y, event);
69 56
    }
70 57

  
71
    /* (non-Javadoc)
72
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
73
     */
74 58
    public void transition(double d) {
75 59
        _fsm.addValue(d);
76 60
    }
77 61

  
78
    /* (non-Javadoc)
79
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
80
     */
81 62
    public void transition(String s) throws CommandException {
82
        if (!super.changeCommand(s)){
63
        if (!super.changeCommand(s)) {
83 64
            _fsm.addOption(s);
84 65
        }
85 66
    }
......
87 68
    /**
88 69
     * Equivale al transition del prototipo pero sin pasarle como par? metro el
89 70
     * editableFeatureSource que ya estar? creado.
90
     *
91
     * @param sel Bitset con las geometr?as que est?n seleccionadas.
92
     * @param x par?metro x del punto que se pase en esta transici?n.
93
     * @param y par?metro y del punto que se pase en esta transici?n.
71
     * 
72
     * @param sel
73
     *            Bitset con las geometr?as que est?n seleccionadas.
74
     * @param x
75
     *            par?metro x del punto que se pase en esta transici?n.
76
     * @param y
77
     *            par?metro y del punto que se pase en esta transici?n.
94 78
     */
95
    public void addPoint(double x, double y,InputEvent event) {
96
        RectangleCADToolState actualState = (RectangleCADToolState) _fsm.getPreviousState();
79
    public void addPoint(double x, double y, InputEvent event) {
80
        RectangleCADToolState actualState =
81
            (RectangleCADToolState) _fsm.getPreviousState();
97 82

  
98 83
        String status = actualState.getName();
99 84

  
100 85
        if (status.equals("Rectangle.FirstPoint")) {
101 86
            firstPoint = new Point2D.Double(x, y);
102
        } else if (status == "Rectangle.SecondPointOrSquare") {
103
            lastPoint = new Point2D.Double(x, y);
87
        } else
88
            if (status == "Rectangle.SecondPointOrSquare") {
89
                lastPoint = new Point2D.Double(x, y);
104 90

  
105
            OrientablePrimitive orientablePrimitive;
106
            int type = getCadToolAdapter().getActiveLayerType();
107
            if ((type == Geometry.TYPES.CURVE) || (type == Geometry.TYPES.MULTICURVE)){
108
                orientablePrimitive = createCurve();              
109
            }else{
110
                orientablePrimitive = createSurface();
111
            }            
112
            
113
            orientablePrimitive.addMoveToVertex(createPoint(firstPoint.getX(), firstPoint.getY()));
114
            orientablePrimitive.addVertex(createPoint(lastPoint.getX(), firstPoint.getY()));
115
            orientablePrimitive.addVertex(createPoint(lastPoint.getX(), lastPoint.getY()));
116
            orientablePrimitive.addVertex(createPoint(firstPoint.getX(), lastPoint.getY()));            
117
            orientablePrimitive.closePrimitive();
118
                     
119
            insertAndSelectGeometry(orientablePrimitive);               
120
          
121
            firstPoint = (Point2D) lastPoint.clone();
122
        } else if (status == "Rectangle.SecondPointSquare") {
123
            lastPoint = new Point2D.Double(x, y);
91
                OrientablePrimitive orientablePrimitive =
92
                    createOrientablePrimitive();
124 93

  
125
            OrientablePrimitive orientablePrimitive;
126
            int type = getCadToolAdapter().getActiveLayerType();
127
            if ((type == Geometry.TYPES.CURVE) || (type == Geometry.TYPES.MULTICURVE)){
128
                orientablePrimitive = createCurve();              
129
            }else{
130
                orientablePrimitive = createSurface();
131
            }
132

  
133
            orientablePrimitive.addMoveToVertex(createPoint(firstPoint.getX(), firstPoint.getY()));
134
            orientablePrimitive.addVertex(createPoint(lastPoint.getX(), firstPoint.getY()));
135

  
136
            if (((lastPoint.getY() <= firstPoint.getY()) &&
137
                (lastPoint.getX() <= firstPoint.getX())) ||
138
                ((lastPoint.getY() > firstPoint.getY()) &&
139
                    (lastPoint.getX() > firstPoint.getX()))) {
94
                orientablePrimitive.addMoveToVertex(createPoint(
95
                    firstPoint.getX(), firstPoint.getY()));
140 96
                orientablePrimitive.addVertex(createPoint(lastPoint.getX(),
141
                    firstPoint.getY() + (lastPoint.getX() - firstPoint.getX())));
142
                orientablePrimitive.addVertex(createPoint(firstPoint.getX(),
143
                    firstPoint.getY() + (lastPoint.getX() - firstPoint.getX())));
144
            } else {
97
                    firstPoint.getY()));
145 98
                orientablePrimitive.addVertex(createPoint(lastPoint.getX(),
146
                    firstPoint.getY() - (lastPoint.getX() - firstPoint.getX())));
99
                    lastPoint.getY()));
147 100
                orientablePrimitive.addVertex(createPoint(firstPoint.getX(),
148
                    firstPoint.getY() - (lastPoint.getX() - firstPoint.getX())));
149
            }
150
            orientablePrimitive.closePrimitive();
101
                    lastPoint.getY()));
102
                orientablePrimitive.closePrimitive();
151 103

  
152
            insertAndSelectGeometry(orientablePrimitive);            	
104
                insertAndSelectGeometry(orientablePrimitive);
153 105

  
154
            firstPoint = (Point2D) lastPoint.clone();
155
        }
106
                firstPoint = (Point2D) lastPoint.clone();
107
            } else
108
                if (status == "Rectangle.SecondPointSquare") {
109
                    lastPoint = new Point2D.Double(x, y);
110

  
111
                    OrientablePrimitive orientablePrimitive =
112
                        createOrientablePrimitive();
113

  
114
                    orientablePrimitive.addMoveToVertex(createPoint(
115
                        firstPoint.getX(), firstPoint.getY()));
116
                    orientablePrimitive.addVertex(createPoint(lastPoint.getX(),
117
                        firstPoint.getY()));
118

  
119
                    if (((lastPoint.getY() <= firstPoint.getY()) && (lastPoint
120
                        .getX() <= firstPoint.getX()))
121
                        || ((lastPoint.getY() > firstPoint.getY()) && (lastPoint
122
                            .getX() > firstPoint.getX()))) {
123
                        orientablePrimitive.addVertex(createPoint(
124
                            lastPoint.getX(),
125
                            firstPoint.getY()
126
                                + (lastPoint.getX() - firstPoint.getX())));
127
                        orientablePrimitive.addVertex(createPoint(
128
                            firstPoint.getX(),
129
                            firstPoint.getY()
130
                                + (lastPoint.getX() - firstPoint.getX())));
131
                    } else {
132
                        orientablePrimitive.addVertex(createPoint(
133
                            lastPoint.getX(),
134
                            firstPoint.getY()
135
                                - (lastPoint.getX() - firstPoint.getX())));
136
                        orientablePrimitive.addVertex(createPoint(
137
                            firstPoint.getX(),
138
                            firstPoint.getY()
139
                                - (lastPoint.getX() - firstPoint.getX())));
140
                    }
141
                    orientablePrimitive.closePrimitive();
142

  
143
                    insertAndSelectGeometry(orientablePrimitive);
144

  
145
                    firstPoint = (Point2D) lastPoint.clone();
146
                }
156 147
    }
157 148

  
158 149
    /**
159 150
     * M?todo para dibujar la lo necesario para el estado en el que nos
160 151
     * encontremos.
161
     *
162
     * @param g Graphics sobre el que dibujar.
163
     * @param selectedGeometries BitSet con las geometr?as seleccionadas.
164
     * @param x par?metro x del punto que se pase para dibujar.
165
     * @param y par?metro x del punto que se pase para dibujar.
152
     * 
153
     * @param g
154
     *            Graphics sobre el que dibujar.
155
     * @param selectedGeometries
156
     *            BitSet con las geometr?as seleccionadas.
157
     * @param x
158
     *            par?metro x del punto que se pase para dibujar.
159
     * @param y
160
     *            par?metro x del punto que se pase para dibujar.
166 161
     */
167
    public void drawOperation(MapControlDrawer renderer, double x,
168
        double y) {
162
    public void drawOperation(MapControlDrawer renderer, double x, double y) {
169 163
        RectangleCADToolState actualState = _fsm.getState();
170 164
        String status = actualState.getName();
171 165

  
172 166
        if (status == "Rectangle.SecondPointOrSquare") {
173
            GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
174
                4);
167
            GeneralPathX elShape =
168
                new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, 4);
175 169
            elShape.moveTo(firstPoint.getX(), firstPoint.getY());
176 170
            elShape.lineTo(x, firstPoint.getY());
177 171
            elShape.lineTo(x, y);
178 172
            elShape.lineTo(firstPoint.getX(), y);
179 173
            elShape.lineTo(firstPoint.getX(), firstPoint.getY());
180 174

  
181
            renderer.draw(createCurve(elShape), mapControlManager.getGeometrySelectionSymbol());
182
        } else if (status == "Rectangle.SecondPointSquare") {
183
            GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
184
                4);
185
            elShape.moveTo(firstPoint.getX(), firstPoint.getY());
186
            elShape.lineTo(x, firstPoint.getY());
175
            renderer.draw(createCurve(elShape),
176
                mapControlManager.getGeometrySelectionSymbol());
177
        } else
178
            if (status == "Rectangle.SecondPointSquare") {
179
                GeneralPathX elShape =
180
                    new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, 4);
181
                elShape.moveTo(firstPoint.getX(), firstPoint.getY());
182
                elShape.lineTo(x, firstPoint.getY());
187 183

  
188
            if (((y <= firstPoint.getY()) && (x <= firstPoint.getX())) ||
189
                ((y > firstPoint.getY()) && (x > firstPoint.getX()))) {
190
                elShape.lineTo(x, firstPoint.getY() + (x - firstPoint.getX()));
191
                elShape.lineTo(firstPoint.getX(),
192
                    firstPoint.getY() + (x - firstPoint.getX()));
193
                elShape.lineTo(firstPoint.getX(), firstPoint.getY());
194
            } else {
195
                elShape.lineTo(x, firstPoint.getY() - (x - firstPoint.getX()));
196
                elShape.lineTo(firstPoint.getX(),
197
                    firstPoint.getY() - (x - firstPoint.getX()));
198
                elShape.lineTo(firstPoint.getX(), firstPoint.getY());
184
                if (((y <= firstPoint.getY()) && (x <= firstPoint.getX()))
185
                    || ((y > firstPoint.getY()) && (x > firstPoint.getX()))) {
186
                    elShape.lineTo(x,
187
                        firstPoint.getY() + (x - firstPoint.getX()));
188
                    elShape.lineTo(firstPoint.getX(), firstPoint.getY()
189
                        + (x - firstPoint.getX()));
190
                    elShape.lineTo(firstPoint.getX(), firstPoint.getY());
191
                } else {
192
                    elShape.lineTo(x,
193
                        firstPoint.getY() - (x - firstPoint.getX()));
194
                    elShape.lineTo(firstPoint.getX(), firstPoint.getY()
195
                        - (x - firstPoint.getX()));
196
                    elShape.lineTo(firstPoint.getX(), firstPoint.getY());
197
                }
198
                renderer.draw(createCurve(elShape),
199
                    mapControlManager.getGeometrySelectionSymbol());
199 200
            }
200
            renderer.draw(createCurve(elShape), mapControlManager.getGeometrySelectionSymbol());
201
        }
202 201
    }
203 202

  
204 203
    /**
205 204
     * Add a diferent option.
206
     *
207
     * @param sel DOCUMENT ME!
208
     * @param s Diferent option.
205
     * 
206
     * @param sel
207
     *            DOCUMENT ME!
208
     * @param s
209
     *            Diferent option.
209 210
     */
210 211
    public void addOption(String s) {
211
        RectangleCADToolState actualState = (RectangleCADToolState) _fsm.getPreviousState();
212
        RectangleCADToolState actualState =
213
            (RectangleCADToolState) _fsm.getPreviousState();
212 214
        String status = actualState.getName();
213 215

  
214 216
        if (status == "Rectangle.SecondPointOrSquare") {
215
            if (s.equalsIgnoreCase(PluginServices.getText(this,"RectangleCADTool.square"))) {
216
                //Opci?n correcta
217
            if (s.equalsIgnoreCase(PluginServices.getText(this,
218
                "RectangleCADTool.square"))) {
219
                // Opci?n correcta
217 220
            }
218 221
        }
219 222
    }
220 223

  
221
    /* (non-Javadoc)
222
     * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
223
     */
224 224
    public void addValue(double d) {
225 225
    }
226 226

  
227 227
    public String getName() {
228
        return PluginServices.getText(this,"rectangle_");
228
        return PluginServices.getText(this, "rectangle_");
229 229
    }
230 230

  
231 231
    public String toString() {
232 232
        return "_rectangle";
233 233
    }
234
    public boolean isApplicable(int shapeType) {
235
        switch (shapeType) {
236
        case Geometry.TYPES.POINT:
237
        case Geometry.TYPES.MULTIPOINT:
238
            return false;
239
        }
240
        return true;
241
    }
234

  
242 235
}

Also available in: Unified diff