svn-gvsig-desktop / branches / pilotoDWG / applications / appgvSIG / src / com / iver / cit / gvsig / gui / cad / tools / CircleCadTool.java @ 1548
History | View | Annotate | Download (6.2 KB)
1 | 1487 | fernando | /* 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.ShapeFactory; |
||
49 | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
||
50 | import com.iver.cit.gvsig.fmap.edition.EditableFeatureSource; |
||
51 | import com.iver.cit.gvsig.fmap.edition.cad.Status; |
||
52 | 1548 | vcaballero | import com.iver.cit.gvsig.fmap.edition.cad.TrigonometricalFunctions; |
53 | 1487 | fernando | 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.Circulo; |
||
56 | 1489 | fernando | import com.iver.fsac.Automaton; |
57 | 1487 | fernando | |
58 | |||
59 | /**
|
||
60 | * DOCUMENT ME!
|
||
61 | *
|
||
62 | * @author Vicente Caballero Navarro
|
||
63 | */
|
||
64 | public class CircleCadTool extends AbstractCadTool { |
||
65 | private static Status[] STATUS = { |
||
66 | 1548 | vcaballero | new Status("Precise punto central o [3P]"), |
67 | new Status("Precise radio"), |
||
68 | new Status("Precise primer punto del c?rculo"), |
||
69 | new Status("Precise segundo punto del c?rculo"), |
||
70 | new Status("Precise tercer punto del c?rculo"), |
||
71 | 1487 | fernando | }; |
72 | private Circulo circleStatus = new Circulo(); |
||
73 | private Point2D center; |
||
74 | 1548 | vcaballero | private Point2D p1; |
75 | private Point2D p2; |
||
76 | private Point2D p3; |
||
77 | 1487 | fernando | |
78 | /**
|
||
79 | * @see com.iver.cit.gvsig.gui.cad.CadTool#transition(java.lang.String,
|
||
80 | * com.iver.cit.gvsig.fmap.edition.EditableFeatureSource,
|
||
81 | * com.iver.cit.gvsig.fmap.layers.FBitSet, double[])
|
||
82 | */
|
||
83 | public int transition(String text, EditableFeatureSource editingSource, |
||
84 | FBitSet selectedGeometries, double[] values) { |
||
85 | int ret = circleStatus.transition(text);
|
||
86 | |||
87 | int status = circleStatus.getStatus();
|
||
88 | |||
89 | if (status == 0) { |
||
90 | } else if (status == 1) { |
||
91 | center = new Point2D.Double(values[0], values[1]); |
||
92 | 1548 | vcaballero | }else if (status == 2) { |
93 | |||
94 | }else if (status == 3) { |
||
95 | p1=new Point2D.Double(values[0], values[1]); |
||
96 | }else if (status == 4) { |
||
97 | p2=new Point2D.Double(values[0], values[1]); |
||
98 | }else if (status == 5) { |
||
99 | p3=new Point2D.Double(values[0], values[1]); |
||
100 | center=TrigonometricalFunctions.getCircleCenter(p1,p2,p3); |
||
101 | double radio=center.distance(p1);
|
||
102 | 1487 | fernando | try {
|
103 | 1548 | vcaballero | editingSource.addGeometry(ShapeFactory.createCircle(center,radio)); |
104 | } catch (DriverIOException e) {
|
||
105 | e.printStackTrace(); |
||
106 | } catch (IOException e) { |
||
107 | e.printStackTrace(); |
||
108 | } |
||
109 | ret = ret | circleStatus.transition("cancel");
|
||
110 | } else if (status == 6) { |
||
111 | try {
|
||
112 | 1487 | fernando | editingSource.addGeometry(ShapeFactory.createCircle(center, values[0]));
|
113 | } catch (DriverIOException e) {
|
||
114 | e.printStackTrace(); |
||
115 | } catch (IOException e) { |
||
116 | e.printStackTrace(); |
||
117 | } |
||
118 | ret = ret | circleStatus.transition("cancel");
|
||
119 | 1548 | vcaballero | } else if (status == 7) { |
120 | 1487 | fernando | try {
|
121 | editingSource.addGeometry(ShapeFactory.createCircle(center, new Point2D.Double(values[0], values[1]))); |
||
122 | } catch (DriverIOException e) {
|
||
123 | e.printStackTrace(); |
||
124 | } catch (IOException e) { |
||
125 | e.printStackTrace(); |
||
126 | } |
||
127 | ret = ret | circleStatus.transition("cancel");
|
||
128 | } |
||
129 | |||
130 | return ret;
|
||
131 | } |
||
132 | |||
133 | /**
|
||
134 | * @see com.iver.cit.gvsig.gui.cad.CadTool#drawOperation(java.awt.Graphics,
|
||
135 | * com.iver.cit.gvsig.fmap.edition.EditableFeatureSource,
|
||
136 | * com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
||
137 | */
|
||
138 | public void drawOperation(Graphics g, EditableFeatureSource efs, |
||
139 | FBitSet selectedGeometries, double x, double y) { |
||
140 | int status = circleStatus.getStatus();
|
||
141 | |||
142 | if (status == 1){ |
||
143 | Point2D currentPoint = new Point2D.Double(x, y); |
||
144 | double dist = currentPoint.distance(center);
|
||
145 | 1535 | vcaballero | ShapeFactory.createCircle(center, dist).draw((Graphics2D) g, getCadToolAdapter().getMapControl().getViewPort(), CadTool.modifySymbol);
|
146 | 1548 | vcaballero | }else if (status == 2){ |
147 | }else if (status == 3){ |
||
148 | drawLine((Graphics2D)g,p1,new Point2D.Double(x,y)); |
||
149 | }else if (status == 4){ |
||
150 | Point2D currentPoint=new Point2D.Double(x,y); |
||
151 | if (p1.getX()==p2.getX()){
|
||
152 | p2=new Point2D.Double(p2.getX()+0.0000001,p2.getY()); |
||
153 | }else if (p1.getY()==p2.getY()){ |
||
154 | p2=new Point2D.Double(p2.getX(),p2.getY()+0.0000001); |
||
155 | }/*if (currentPoint.getX()==p1.getX()){
|
||
156 | currentPoint=new Point2D.Double(currentPoint.getX()+0.0000001,currentPoint.getY());
|
||
157 | }else if (currentPoint.getY()==p1.getY()){
|
||
158 | currentPoint=new Point2D.Double(currentPoint.getX(),currentPoint.getY()+0.0000001);
|
||
159 | }if (currentPoint.getX()==p2.getX()){
|
||
160 | currentPoint=new Point2D.Double(currentPoint.getX()+0.0000001,currentPoint.getY());
|
||
161 | }else if (currentPoint.getY()==p2.getY()){
|
||
162 | currentPoint=new Point2D.Double(currentPoint.getX(),currentPoint.getY()+0.0000001);
|
||
163 | }*/
|
||
164 | Point2D currentCenter=TrigonometricalFunctions.getCircleCenter(p1,p2,currentPoint);
|
||
165 | double radio=currentCenter.distance(p1);
|
||
166 | ShapeFactory.createCircle(currentCenter, radio).draw((Graphics2D) g, getCadToolAdapter().getMapControl().getViewPort(), CadTool.modifySymbol);
|
||
167 | 1487 | fernando | } |
168 | } |
||
169 | |||
170 | /**
|
||
171 | * @see com.iver.cit.gvsig.gui.cad.CadTool#getQuestion()
|
||
172 | */
|
||
173 | public String getQuestion() { |
||
174 | return STATUS[circleStatus.getStatus()].getQuestion();
|
||
175 | } |
||
176 | |||
177 | /**
|
||
178 | * @see com.iver.cit.gvsig.gui.cad.CadTool#initializeStatus()
|
||
179 | */
|
||
180 | public void initializeStatus() { |
||
181 | circleStatus.initialize(); |
||
182 | } |
||
183 | 1489 | fernando | |
184 | /**
|
||
185 | * @see com.iver.cit.gvsig.gui.cad.CadTool#getAutomaton()
|
||
186 | */
|
||
187 | public Automaton getAutomaton() {
|
||
188 | return circleStatus;
|
||
189 | } |
||
190 | 1487 | fernando | } |