Revision 4434

View differences:

trunk/extensions/extCAD/config/config.xml
16 16
			<menu text="Vista/new_theme/new_dxf" action-command="DXF"/>
17 17
			<menu text="Vista/new_theme/new_postgis" action-command="POSTGIS"/>			
18 18
		</extension>
19
		
19

  
20 20
		<extension class-name="com.iver.cit.gvsig.StopEditing"
21 21
			description="Extensi?n encargada de terminar la edici?n sobre la capa activa y guardarla sobre s? misma."
22 22
			active="true">
......
83 83
			<menu text="geometria/insertar/arc" action-command="ARC" icon="images/Arc.png"/>
84 84
			<!--menu text="geometria/insertar/curva" action-command="SPLINE" icon="images/Spline.png"/-->
85 85
			<menu text="geometria/insertar/copia" action-command="COPY" icon="images/Copy.png"/>
86
			<menu text="geometria/insertar/desplazar" action-command="MOVE" icon="images/Move.png"/>
86 87
			<!--menu text="geometria/insertar/equidistante" action-command="EQUIDISTANCE" icon="images/Equidistance.png"/-->
87 88
			<!--menu text="geometria/insertar/Matriz" action-command="MATRIZ" icon="images/Matriz.png"/-->
88 89
			<!--menu text="geometria/insertar/simetria" action-command="SYMMETRY" icon="images/Symmetry.png"/-->
......
111 112
			<tool-bar name="modificar">
112 113
				<selectable-tool name="selection" icon="images/Select.png" action-command="SELECT" tooltip="seleccionar_por_rectangulo" group="vista"/>
113 114
				<selectable-tool icon="images/Copy.png" action-command="COPY" tooltip="copia" group="vista"/>
115
				<selectable-tool icon="images/Move.png" action-command="MOVE" tooltip="desplazar" group="vista"/>
114 116
				<!--selectable-tool icon="images/Equidistance.png" action-command="EQUIDISTANCE" tooltip="equidistante" group="vista"/-->
115 117
				<!--selectable-tool icon="images/Matriz.png" action-command="MATRIZ" tooltip="matriz" group="vista"/-->
116 118
				<!--selectable-tool icon="images/Symmetry.png" action-command="SYMMETRY" tooltip="simetria" group="vista"/-->
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/smc/MoveCADToolContext.java
1

  
2
//
3
// Vicente Caballero Navarro
4

  
5

  
6
package com.iver.cit.gvsig.gui.cad.tools.smc;
7

  
8
import com.iver.cit.gvsig.gui.cad.tools.MoveCADTool;
9
import java.awt.event.InputEvent;
10

  
11
public final class MoveCADToolContext
12
    extends statemap.FSMContext
13
{
14
//---------------------------------------------------------------
15
// Member methods.
16
//
17

  
18
    public MoveCADToolContext(MoveCADTool owner)
19
    {
20
        super();
21

  
22
        _owner = owner;
23
        setState(Move.FirstPointToMove);
24
        Move.FirstPointToMove.Entry(this);
25
    }
26

  
27
    public void addOption(String s)
28
    {
29
        _transition = "addOption";
30
        getState().addOption(this, s);
31
        _transition = "";
32
        return;
33
    }
34

  
35
    public void addPoint(double pointX, double pointY, InputEvent event)
36
    {
37
        _transition = "addPoint";
38
        getState().addPoint(this, pointX, pointY, event);
39
        _transition = "";
40
        return;
41
    }
42

  
43
    public MoveCADToolState getState()
44
        throws statemap.StateUndefinedException
45
    {
46
        if (_state == null)
47
        {
48
            throw(
49
                new statemap.StateUndefinedException());
50
        }
51

  
52
        return ((MoveCADToolState) _state);
53
    }
54

  
55
    protected MoveCADTool getOwner()
56
    {
57
        return (_owner);
58
    }
59

  
60
//---------------------------------------------------------------
61
// Member data.
62
//
63

  
64
    transient private MoveCADTool _owner;
65

  
66
//---------------------------------------------------------------
67
// Inner classes.
68
//
69

  
70
    public static abstract class MoveCADToolState
71
        extends statemap.State
72
    {
73
    //-----------------------------------------------------------
74
    // Member methods.
75
    //
76

  
77
        protected MoveCADToolState(String name, int id)
78
        {
79
            super (name, id);
80
        }
81

  
82
        protected void Entry(MoveCADToolContext context) {}
83
        protected void Exit(MoveCADToolContext context) {}
84

  
85
        protected void addOption(MoveCADToolContext context, String s)
86
        {
87
            Default(context);
88
        }
89

  
90
        protected void addPoint(MoveCADToolContext context, double pointX, double pointY, InputEvent event)
91
        {
92
            Default(context);
93
        }
94

  
95
        protected void Default(MoveCADToolContext context)
96
        {
97
            throw (
98
                new statemap.TransitionUndefinedException(
99
                    "State: " +
100
                    context.getState().getName() +
101
                    ", Transition: " +
102
                    context.getTransition()));
103
        }
104

  
105
    //-----------------------------------------------------------
106
    // Member data.
107
    //
108
    }
109

  
110
    /* package */ static abstract class Move
111
    {
112
    //-----------------------------------------------------------
113
    // Member methods.
114
    //
115

  
116
    //-----------------------------------------------------------
117
    // Member data.
118
    //
119

  
120
        //-------------------------------------------------------
121
        // Statics.
122
        //
123
        /* package */ static Move_Default.Move_FirstPointToMove FirstPointToMove;
124
        /* package */ static Move_Default.Move_SecondPointToMove SecondPointToMove;
125
        private static Move_Default Default;
126

  
127
        static
128
        {
129
            FirstPointToMove = new Move_Default.Move_FirstPointToMove("Move.FirstPointToMove", 0);
130
            SecondPointToMove = new Move_Default.Move_SecondPointToMove("Move.SecondPointToMove", 1);
131
            Default = new Move_Default("Move.Default", -1);
132
        }
133

  
134
    }
135

  
136
    protected static class Move_Default
137
        extends MoveCADToolState
138
    {
139
    //-----------------------------------------------------------
140
    // Member methods.
141
    //
142

  
143
        protected Move_Default(String name, int id)
144
        {
145
            super (name, id);
146
        }
147

  
148
        protected void addOption(MoveCADToolContext context, String s)
149
        {
150
            MoveCADTool ctxt = context.getOwner();
151

  
152
            if (s.equals("Cancelar"))
153
            {
154
                boolean loopbackFlag =
155
                    context.getState().getName().equals(
156
                        Move.FirstPointToMove.getName());
157

  
158
                if (loopbackFlag == false)
159
                {
160
                    (context.getState()).Exit(context);
161
                }
162

  
163
                context.clearState();
164
                try
165
                {
166
                    ctxt.end();
167
                }
168
                finally
169
                {
170
                    context.setState(Move.FirstPointToMove);
171

  
172
                    if (loopbackFlag == false)
173
                    {
174
                        (context.getState()).Entry(context);
175
                    }
176

  
177
                }
178
            }
179
            else
180
            {
181
                super.addOption(context, s);
182
            }
183

  
184
            return;
185
        }
186

  
187
    //-----------------------------------------------------------
188
    // Inner classse.
189
    //
190

  
191

  
192
        private static final class Move_FirstPointToMove
193
            extends Move_Default
194
        {
195
        //-------------------------------------------------------
196
        // Member methods.
197
        //
198

  
199
            private Move_FirstPointToMove(String name, int id)
200
            {
201
                super (name, id);
202
            }
203

  
204
            protected void Entry(MoveCADToolContext context)
205
            {
206
                MoveCADTool ctxt = context.getOwner();
207

  
208
                ctxt.selection();
209
                ctxt.setQuestion("DESPLAZAR" + "\n" +
210
		"Precisar punto de desplazamiento");
211
                ctxt.setDescription(new String[]{"Cancelar"});
212
                return;
213
            }
214

  
215
            protected void addPoint(MoveCADToolContext context, double pointX, double pointY, InputEvent event)
216
            {
217
                MoveCADTool ctxt = context.getOwner();
218

  
219

  
220
                (context.getState()).Exit(context);
221
                context.clearState();
222
                try
223
                {
224
                    ctxt.setQuestion("Precisar segundo punto del desplazamiento");
225
                    ctxt.setDescription(new String[]{"Cancelar"});
226
                    ctxt.addPoint(pointX, pointY, event);
227
                }
228
                finally
229
                {
230
                    context.setState(Move.SecondPointToMove);
231
                    (context.getState()).Entry(context);
232
                }
233
                return;
234
            }
235

  
236
        //-------------------------------------------------------
237
        // Member data.
238
        //
239
        }
240

  
241
        private static final class Move_SecondPointToMove
242
            extends Move_Default
243
        {
244
        //-------------------------------------------------------
245
        // Member methods.
246
        //
247

  
248
            private Move_SecondPointToMove(String name, int id)
249
            {
250
                super (name, id);
251
            }
252

  
253
            protected void addPoint(MoveCADToolContext context, double pointX, double pointY, InputEvent event)
254
            {
255
                MoveCADTool ctxt = context.getOwner();
256

  
257

  
258
                (context.getState()).Exit(context);
259
                context.clearState();
260
                try
261
                {
262
                    ctxt.setDescription(new String[]{"Cancelar"});
263
                    ctxt.addPoint(pointX, pointY, event);
264
                    ctxt.end();
265
                    ctxt.refresh();
266
                }
267
                finally
268
                {
269
                    context.setState(Move.FirstPointToMove);
270
                    (context.getState()).Entry(context);
271
                }
272
                return;
273
            }
274

  
275
        //-------------------------------------------------------
276
        // Member data.
277
        //
278
        }
279

  
280
    //-----------------------------------------------------------
281
    // Member data.
282
    //
283
    }
284
}
0 285

  
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/MoveCADTool.java
1
/* 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
import java.awt.Graphics;
44
import java.awt.Graphics2D;
45
import java.awt.event.InputEvent;
46
import java.awt.geom.Point2D;
47
import java.io.IOException;
48

  
49
import com.iver.andami.PluginServices;
50
import com.iver.cit.gvsig.CADExtension;
51
import com.iver.cit.gvsig.fmap.core.DefaultFeature;
52
import com.iver.cit.gvsig.fmap.core.IGeometry;
53
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
54
import com.iver.cit.gvsig.fmap.edition.UtilFunctions;
55
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter;
56
import com.iver.cit.gvsig.fmap.layers.FBitSet;
57
import com.iver.cit.gvsig.gui.cad.CADTool;
58
import com.iver.cit.gvsig.gui.cad.DefaultCADTool;
59
import com.iver.cit.gvsig.gui.cad.tools.smc.MoveCADToolContext;
60
import com.iver.cit.gvsig.gui.cad.tools.smc.MoveCADToolContext.MoveCADToolState;
61

  
62

  
63
/**
64
 * DOCUMENT ME!
65
 *
66
 * @author Vicente Caballero Navarro
67
 */
68
public class MoveCADTool extends DefaultCADTool {
69
    private MoveCADToolContext _fsm;
70
    private Point2D firstPoint;
71
    private Point2D lastPoint;
72

  
73
    /**
74
     * Crea un nuevo PolylineCADTool.
75
     */
76
    public MoveCADTool() {
77
    }
78

  
79
    /**
80
     * M?todo de incio, para poner el c?digo de todo lo que se requiera de una
81
     * carga previa a la utilizaci?n de la herramienta.
82
     */
83
    public void init() {
84
        _fsm = new MoveCADToolContext(this);
85
    }
86

  
87
    /* (non-Javadoc)
88
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
89
     */
90
    public void transition(double x, double y, InputEvent event) {
91
        _fsm.addPoint(x, y, event);
92
    }
93

  
94
    /* (non-Javadoc)
95
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
96
     */
97
    public void transition(double d) {
98
        //_fsm.addValue(sel,d);
99
    }
100

  
101
    /* (non-Javadoc)
102
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
103
     */
104
    public void transition(String s) {
105
        _fsm.addOption(s);
106
    }
107

  
108
    /**
109
     * DOCUMENT ME!
110
     */
111
    public void selection() {
112
        FBitSet selection = CADExtension.getCADToolAdapter()
113
                                        .getVectorialAdapter().getSelection();
114

  
115
        if (selection.cardinality() == 0) {
116
            CADExtension.setCADTool("selection");
117
            ((SelectionCADTool) CADExtension.getCADToolAdapter().getCadTool()).setNextTool(
118
                "move");
119
        }
120
    }
121

  
122
    /**
123
     * Equivale al transition del prototipo pero sin pasarle como par?metro el
124
     * editableFeatureSource que ya estar? creado.
125
     *
126
     * @param x par?metro x del punto que se pase en esta transici?n.
127
     * @param y par?metro y del punto que se pase en esta transici?n.
128
     */
129
    public void addPoint(double x, double y,InputEvent event) {
130
        MoveCADToolState actualState = (MoveCADToolState) _fsm.getPreviousState();
131
        String status = actualState.getName();
132
        VectorialEditableAdapter vea = getCadToolAdapter().getVectorialAdapter();
133
        FBitSet selection = vea.getSelection();
134

  
135
        if (status.equals("Move.FirstPointToMove")) {
136
            firstPoint = new Point2D.Double(x, y);
137
        } else if (status.equals("Move.SecondPointToMove")) {
138
            PluginServices.getMDIManager().setWaitCursor();
139
            lastPoint = new Point2D.Double(x, y);
140
            vea.startComplexRow();
141

  
142
            try {
143
                for (int i = selection.nextSetBit(0); i >= 0;
144
                        i = selection.nextSetBit(i + 1)) {
145
                    DefaultFeature fea = (DefaultFeature) vea.getRow(i)
146
                                                             .getLinkedRow()
147
                                                             .cloneRow();
148
                    // Movemos la geometr?a
149
                    UtilFunctions.moveGeom(fea.getGeometry(), lastPoint.getX() -
150
                            firstPoint.getX(), lastPoint.getY() - firstPoint.getY());
151

  
152
                    vea.modifyRow(i,fea,getName());
153
                }
154

  
155
                vea.endComplexRow();
156
            } catch (DriverIOException e) {
157
                // TODO Auto-generated catch block
158
                e.printStackTrace();
159
            } catch (IOException e) {
160
                // TODO Auto-generated catch block
161
                e.printStackTrace();
162
            }
163

  
164
            selection.clear();
165
            PluginServices.getMDIManager().restoreCursor();
166

  
167
            //ret = ret | copyStatus.transition("cancel");
168
        }
169
    }
170

  
171
    /**
172
     * M?todo para dibujar la lo necesario para el estado en el que nos
173
     * encontremos.
174
     *
175
     * @param g Graphics sobre el que dibujar.
176
     * @param x par?metro x del punto que se pase para dibujar.
177
     * @param y par?metro x del punto que se pase para dibujar.
178
     */
179
    public void drawOperation(Graphics g, double x, double y) {
180
        MoveCADToolState actualState = ((MoveCADToolContext) _fsm).getState();
181
        String status = actualState.getName();
182
        VectorialEditableAdapter vea = getCadToolAdapter().getVectorialAdapter();
183
        FBitSet selection = vea.getSelection();
184

  
185
        try {
186
            drawHandlers(g, selection,
187
                getCadToolAdapter().getMapControl().getViewPort()
188
                    .getAffineTransform());
189
        } catch (DriverIOException e) {
190
            // TODO Auto-generated catch block
191
            e.printStackTrace();
192
        }
193

  
194
        if (status.equals("Move.SecondPointToMove")) {
195
            ///int dx = getCadToolAdapter().getMapControl().getViewPort().fromMapDistance(x - firstPoint.getX());
196
            ///int dy = -getCadToolAdapter().getMapControl().getViewPort().fromMapDistance(y - firstPoint.getY());
197
            ///Image img = getCadToolAdapter().getVectorialAdapter().getImage();
198
            ///g.drawImage(img, dx, dy, null);
199
            try {
200
                for (int i = selection.nextSetBit(0); i >= 0;
201
                        i = selection.nextSetBit(i + 1)) {
202
                    IGeometry geometry = vea.getShape(i).cloneGeometry();
203
                    // Movemos la geometr?a
204
                    UtilFunctions.moveGeom(geometry, x - firstPoint.getX(), y - firstPoint.getY());
205
                    // geometry.move(x - firstPoint.getX(), y - firstPoint.getY());
206
                    geometry.draw((Graphics2D) g,
207
                        getCadToolAdapter().getMapControl().getViewPort(),
208
                        CADTool.drawingSymbol);
209
                }
210
            } catch (DriverIOException e) {
211
                e.printStackTrace();
212
            }
213
        }
214
    }
215

  
216
    /**
217
     * Add a diferent option.
218
     *
219
     * @param s Diferent option.
220
     */
221
    public void addOption(String s) {
222
    }
223

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

  
230
	public String getName() {
231
		return "DESPLAZAR";
232
	}
233
}
0 234

  
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/PolylineCADTool.java
433 433
    }
434 434

  
435 435
    public void cancel(){
436
    	endGeometry();
436 437
    	list.clear();
437 438
    	antantPoint=antCenter=antInter=antPoint=firstPoint=null;
438 439
    }

Also available in: Unified diff