Statistics
| Revision:

root / branches / pilotoDWG / applications / appgvSIG / src / com / iver / cit / gvsig / gui / cad / tools / ArcCadTool.java @ 1634

History | View | Annotate | Download (4.56 KB)

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.geom.Point2D;
46
import java.io.IOException;
47

    
48
import com.iver.cit.gvsig.fmap.core.IGeometry;
49
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
50
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
51
import com.iver.cit.gvsig.fmap.edition.EditableFeatureSource;
52
import com.iver.cit.gvsig.fmap.edition.cad.Status;
53
import com.iver.cit.gvsig.fmap.layers.FBitSet;
54
import com.iver.cit.gvsig.gui.cad.CadTool;
55
import com.iver.cit.gvsig.gui.cad.automaton.Arco;
56
import com.iver.fsac.Automaton;
57

    
58

    
59
/**
60
 * Herramienta para crear un arco a partir de tres puntos.
61
 *
62
 * @author Vicente Caballero Navarro
63
 */
64
public class ArcCadTool extends AbstractCadTool {
65
        private static Status[] STATUS = {
66
                        new Status("Precise punto inicial"),
67
                        new Status("Precise segundo punto"),
68
                        new Status("Precise punto final")
69
                };
70
        private Arco arcStatus = new Arco();
71
        
72
        private Point2D p1;
73
        private Point2D p2;
74
        private Point2D p3;
75

    
76
        /**
77
         * @see com.iver.cit.gvsig.gui.cad.CadTool#transition(java.lang.String,
78
         *                 com.iver.cit.gvsig.fmap.edition.EditableFeatureSource,
79
         *                 com.iver.cit.gvsig.fmap.layers.FBitSet, double[])
80
         */
81
        public int transition(String text, EditableFeatureSource editingSource,
82
                FBitSet selectedGeometries, double[] values) {
83
                int ret = arcStatus.transition(text);
84

    
85
                int status = arcStatus.getStatus();
86

    
87
                if (status == 0) {
88
                } else if (status == 1) {
89
                        p1 = new Point2D.Double(values[0], values[1]);
90
                } else if (status == 2) {
91
                        p2 = new Point2D.Double(values[0], values[1]);
92
                } else if (status == 3) {
93
                        p3 = new Point2D.Double(values[0], values[1]);
94
                        try {
95
                                IGeometry ig = ShapeFactory.createArc(p1, p2, p3);
96
                                if (ig != null)
97
                                editingSource.addGeometry(ig);
98
                        } catch (DriverIOException e) {
99
                                e.printStackTrace();
100
                        } catch (IOException e) {
101
                                e.printStackTrace();
102
                        }
103
                        ret = ret | arcStatus.transition("cancel");
104
                }
105

    
106
                return ret;
107
        }
108

    
109
        /**
110
         * @see com.iver.cit.gvsig.gui.cad.CadTool#drawOperation(java.awt.Graphics,
111
         *                 com.iver.cit.gvsig.fmap.edition.EditableFeatureSource,
112
         *                 com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
113
         */
114
        public void drawOperation(Graphics g, EditableFeatureSource efs,
115
                FBitSet selectedGeometries, double x, double y) {
116
                int status = arcStatus.getStatus();
117
                if (status==1){
118
                        drawLine((Graphics2D)g,p1,new Point2D.Double(x, y));
119
                }else if (status == 2){
120
                        Point2D current = new Point2D.Double(x, y);
121
                        
122
                        IGeometry ig = ShapeFactory.createArc(p1, p2, current);
123
                        if (ig != null)
124
                        ig.draw((Graphics2D)g, getCadToolAdapter().getMapControl().getViewPort(), CadTool.modifySymbol);
125
                        
126
                        Point2D p = getCadToolAdapter().getMapControl().getViewPort().fromMapPoint(p1.getX(), p1.getY());
127
                        g.drawRect((int) p.getX(), (int) p.getY(), 1, 1);
128
                        p = getCadToolAdapter().getMapControl().getViewPort().fromMapPoint(p2.getX(), p2.getY());
129
                        g.drawRect((int) p.getX(), (int) p.getY(), 1, 1);
130
                }
131
        }
132

    
133
        /**
134
         * @see com.iver.cit.gvsig.gui.cad.CadTool#getQuestion()
135
         */
136
        public String getQuestion() {
137
                return STATUS[arcStatus.getStatus()].getQuestion();
138
        }
139

    
140
        /**
141
         * @see com.iver.cit.gvsig.gui.cad.CadTool#initializeStatus()
142
         */
143
        public void initializeStatus() {
144
                arcStatus.initialize();
145
                p1 = null;
146
                p2 = null;
147
                p3 = null;
148
        }
149

    
150
        /**
151
         * @see com.iver.cit.gvsig.gui.cad.CadTool#getAutomaton()
152
         */
153
        public Automaton getAutomaton() {
154
                return arcStatus;
155
        }
156
}