Revision 5207

View differences:

trunk/extensions/extCAD/sm/ComplexSelectionCADTool.sm
1
// -*- tab-width: 4; -*-
2

  
3
%{
4
//
5
// Vicente Caballero Navarro
6
%}
7

  
8
%start Selection::FirstPoint
9
%class ComplexSelectionCADTool
10
%package com.iver.cit.gvsig.gui.cad.tools.smc
11
%import com.iver.cit.gvsig.gui.cad.tools.ComplexSelectionCADTool
12
%import com.iver.cit.gvsig.fmap.layers.FBitSet
13
%import java.awt.event.InputEvent
14
%import com.iver.andami.PluginServices
15

  
16

  
17
%map Selection
18
%%
19
// A task begins life in suspended animation.
20

  
21
FirstPoint
22

  
23
  Entry {
24
    setQuestion(
25
    PluginServices.getText(this,"insert_point_selection_or_types"));
26
    setDescription(new String[]{"out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
27
    }
28
  Exit{
29
    }
30

  
31
  {
32
    addOption(s:String)
33
      FirstPoint{
34
        setQuestion(PluginServices.getText(this,"insert_point_selection_or_types"));
35
        setDescription(new String[]{"out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
36
        addOption(s);
37
        }
38
    addPoint( pointX:double,pointY:double,event:InputEvent)
39
      [ctxt.getType().equals(PluginServices.getText(this,"out_rectangle"))]
40
      SecondPointOutRectangle{
41
        setQuestion(PluginServices.getText(this,"insert_second_point_selection"));
42
        setDescription(new String[]{"out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
43
        addPoint( pointX,pointY,event);
44
        }
45
    addPoint( pointX:double,pointY:double,event:InputEvent)
46
      [ctxt.getType().equals(PluginServices.getText(this,"inside_circle")) || ctxt.getType().equals(PluginServices.getText(this,"cross_circle")) || ctxt.getType().equals(PluginServices.getText(this,"out_circle"))]
47
      SecondPointCircle{
48
        setQuestion(PluginServices.getText(this,"insert_second_point_selection"));
49
        setDescription(new String[]{"out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
50
        addPoint( pointX,pointY,event);
51
        }
52
    addPoint( pointX:double,pointY:double,event:InputEvent)
53
      [ctxt.getType().equals(PluginServices.getText(this,"inside_polygon")) || ctxt.getType().equals(PluginServices.getText(this,"cross_polygon")) || ctxt.getType().equals(PluginServices.getText(this,"out_polygon"))]
54
      NextPointPolygon{
55
        setQuestion(PluginServices.getText(this,"insert_next_point_selection_or_end_polygon"));
56
        setDescription(new String[]{"end_polygon","out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
57
        addPoint( pointX,pointY,event);
58
        }
59

  
60
    addPoint( pointX:double,pointY:double,event:InputEvent)
61
      [ctxt.getType().equals(PluginServices.getText(this,"simple")) && ctxt.selectFeatures(pointX,pointY, event) && ctxt.getNextState().equals("Selection.SecondPoint")]
62
      SecondPoint{
63
        setQuestion(PluginServices.getText(this,"insert_second_point_selection"));
64
        setDescription(new String[]{"out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
65
        addPoint( pointX,pointY,event);
66
        }
67
//    addPoint( pointX:double,pointY:double,event:InputEvent)
68
//      [ctxt.getType().equals(PluginServices.getText(this,"simple")) && ctxt.getNextState().equals("Selection.WithSelectedFeatures")]
69
//      WithSelectedFeatures {
70
//        setQuestion(PluginServices.getText(this,"select_handlers"));
71
//        setDescription(new String[]{"simple","out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
72
//        addPoint( pointX,pointY,event);
73
//        end();
74
//        }
75
}
76

  
77
SecondPoint{
78
  // Si hemos conseguido seleccionar algo
79
  addPoint( pointX:double,pointY:double,event:InputEvent)
80
      [ctxt.selectWithSecondPoint(pointX,pointY, event) > 0]
81
      WithSelectedFeatures {
82
        setQuestion(PluginServices.getText(this,"select_handlers"));
83
        setDescription(new String[]{"out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
84
        addPoint( pointX,pointY,event);
85
        end();
86
        }
87
  // Si no lo hemos conseguido
88
  addPoint( pointX:double,pointY:double,event:InputEvent)
89
      FirstPoint {
90
        setQuestion(PluginServices.getText(this,"insert_point_selection_or_types"));
91
        setDescription(new String[]{"out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
92
        addPoint(pointX,pointY,event);
93
        }
94
  addOption(s:String)
95
      FirstPoint{
96
        setQuestion(PluginServices.getText(this,"insert_point_selection_or_types"));
97
        setDescription(new String[]{"end_polygon","out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
98
        setType(s);
99
        }
100

  
101
}
102
WithSelectedFeatures{
103

  
104
  // Si hemos pinchado encima de un handler
105
  addPoint( pointX:double,pointY:double,event:InputEvent)
106
  [ctxt.selectHandlers(pointX, pointY, event)>0]
107
      WithHandlers {
108
        setQuestion(PluginServices.getText(this,"insert_destination_point"));
109
        setDescription(new String[]{"out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
110
        addPoint( pointX,pointY,event);
111
        // refresh();
112
        }
113

  
114
  // Si no hemos cogido un handler, probamos a seleccionar
115
  // otra entidad
116
  addPoint( pointX:double,pointY:double,event:InputEvent)
117
    [ctxt.selectFeatures(pointX,pointY, event) && ctxt.getNextState().equals("Selection.WithSelectedFeatures")]
118
      WithSelectedFeatures {
119
        setQuestion(PluginServices.getText(this,"select_handlers"));
120
        setDescription(new String[]{"out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
121
        addPoint( pointX,pointY,event);
122
        }
123

  
124

  
125
  // Cualquier otro caso (hemos pinchado en algo vacio), volvemos al estado inicial
126
  addPoint( pointX:double,pointY:double,event:InputEvent)
127
      FirstPoint {
128
        setQuestion(PluginServices.getText(this,"insert_point_selection_or_types"));
129
        setDescription(new String[]{"out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
130
        addPoint( pointX,pointY,event);
131
        // refresh();
132
        }
133
	 addOption(s:String)
134
      FirstPoint{
135
        setQuestion(PluginServices.getText(this,"insert_point_selection_or_types"));
136
        setDescription(new String[]{"end_polygon","out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
137
        setType(s);
138
        }
139
}
140

  
141
WithHandlers{
142
  addPoint( pointX:double,pointY:double,event:InputEvent)
143
      WithSelectedFeatures {
144
        setQuestion(PluginServices.getText(this,"select_handlers"));
145
        setDescription(new String[]{"out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
146
        addPoint( pointX,pointY,event);
147
        refresh();
148
        }
149
}
150

  
151
SecondPointOutRectangle{
152
  // Si hemos conseguido seleccionar algo
153
  addPoint( pointX:double,pointY:double,event:InputEvent)
154
      [ctxt.selectWithSecondPointOutRectangle(pointX,pointY, event) > 0]
155
      WithSelectedFeatures {
156
        setQuestion(PluginServices.getText(this,"select_handlers"));
157
        setDescription(new String[]{"out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
158
        addPoint( pointX,pointY,event);
159
        end();
160
        }
161
  // Si no lo hemos conseguido
162
  addPoint( pointX:double,pointY:double,event:InputEvent)
163
      FirstPoint {
164
        setQuestion(PluginServices.getText(this,"insert_point_selection_or_types"));
165
        setDescription(new String[]{"out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
166
        addPoint(pointX,pointY,event);
167
        }
168
  addOption(s:String)
169
      FirstPoint{
170
        setQuestion(PluginServices.getText(this,"insert_point_selection_or_types"));
171
        setDescription(new String[]{"end_polygon","out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
172
        setType(s);
173
        }
174

  
175
}
176
SecondPointCircle{
177
  // Si hemos conseguido seleccionar algo
178
  addPoint( pointX:double,pointY:double,event:InputEvent)
179
      [ctxt.selectWithCircle(pointX,pointY, event) > 0]
180
      WithSelectedFeatures {
181
        setQuestion(PluginServices.getText(this,"select_handlers"));
182
        setDescription(new String[]{"out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
183
        addPoint( pointX,pointY,event);
184
        end();
185
        }
186
  // Si no lo hemos conseguido
187
  addPoint( pointX:double,pointY:double,event:InputEvent)
188
      FirstPoint {
189
        setQuestion(PluginServices.getText(this,"insert_point_selection_or_types"));
190
        setDescription(new String[]{"out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
191
        addPoint(pointX,pointY,event);
192
        }
193
  addOption(s:String)
194
      FirstPoint{
195
        setQuestion(PluginServices.getText(this,"insert_point_selection_or_types"));
196
        setDescription(new String[]{"out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
197
        setType(s);
198
        }
199
}
200

  
201
NextPointPolygon{
202
  addPoint( pointX:double,pointY:double,event:InputEvent)
203
      NextPointPolygon {
204
        setQuestion(PluginServices.getText(this,"insert_next_point_selection_or_end_polygon"));
205
        setDescription(new String[]{"end_polygon","out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
206
        addPoint(pointX,pointY,event);
207
        }
208
  addOption(s:String)
209
      FirstPoint{
210
        setQuestion(PluginServices.getText(this,"insert_point_selection_or_types"));
211
        setDescription(new String[]{"end_polygon","out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
212
        addOption(s);
213
        }
214
}
215

  
216
Default
217
{
218
  addOption(s:String)
219
    [s.equals(PluginServices.getText(this,"cancel"))]
220
    FirstPoint{
221
      end();
222
      }
223
}
224
%%
0 225

  
trunk/extensions/extCAD/sm/SelectionCADTool.sm
22 22

  
23 23
  Entry {
24 24
    setQuestion(
25
    PluginServices.getText(this,"insert_point_selection_or_types"));
26
    setDescription(new String[]{"simple","out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
25
    PluginServices.getText(this,"insert_point_selection"));
26
    setDescription(new String[]{"cancel"});
27 27
    }
28 28
  Exit{
29 29
    }
......
31 31
  {
32 32
    addOption(s:String)
33 33
      FirstPoint{
34
        setQuestion(PluginServices.getText(this,"insert_point_selection_or_types"));
35
        setDescription(new String[]{"simple","out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
34
        setQuestion(PluginServices.getText(this,"insert_point_selection"));
35
        setDescription(new String[]{"cancel"});
36 36
        addOption(s);
37 37
        }
38
    addPoint( pointX:double,pointY:double,event:InputEvent)
39
      [ctxt.getType().equals(PluginServices.getText(this,"out_rectangle"))]
40
      SecondPointOutRectangle{
41
        setQuestion(PluginServices.getText(this,"insert_second_point_selection"));
42
        setDescription(new String[]{"simple","out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
43
        addPoint( pointX,pointY,event);
44
        }
45
    addPoint( pointX:double,pointY:double,event:InputEvent)
46
      [ctxt.getType().equals(PluginServices.getText(this,"inside_circle")) || ctxt.getType().equals(PluginServices.getText(this,"cross_circle")) || ctxt.getType().equals(PluginServices.getText(this,"out_circle"))]
47
      SecondPointCircle{
48
        setQuestion(PluginServices.getText(this,"insert_second_point_selection"));
49
        setDescription(new String[]{"simple","out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
50
        addPoint( pointX,pointY,event);
51
        }
52
    addPoint( pointX:double,pointY:double,event:InputEvent)
53
      [ctxt.getType().equals(PluginServices.getText(this,"inside_polygon")) || ctxt.getType().equals(PluginServices.getText(this,"cross_polygon")) || ctxt.getType().equals(PluginServices.getText(this,"out_polygon"))]
54
      NextPointPolygon{
55
        setQuestion(PluginServices.getText(this,"insert_next_point_selection_or_end_polygon"));
56
        setDescription(new String[]{"end_polygon","simple","out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
57
        addPoint( pointX,pointY,event);
58
        }
59 38

  
60 39
    addPoint( pointX:double,pointY:double,event:InputEvent)
61 40
      [ctxt.getType().equals(PluginServices.getText(this,"simple")) && ctxt.selectFeatures(pointX,pointY, event) && ctxt.getNextState().equals("Selection.SecondPoint")]
62 41
      SecondPoint{
63
        setQuestion(PluginServices.getText(this,"insert_second_point_selection"));
64
        setDescription(new String[]{"simple","out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
42
        setQuestion(PluginServices.getText(this,"insert_second_point"));
43
        setDescription(new String[]{"cancel"});
65 44
        addPoint( pointX,pointY,event);
66 45
        }
67 46
    addPoint( pointX:double,pointY:double,event:InputEvent)
68 47
      [ctxt.getType().equals(PluginServices.getText(this,"simple")) && ctxt.getNextState().equals("Selection.WithSelectedFeatures")]
69 48
      WithSelectedFeatures {
70 49
        setQuestion(PluginServices.getText(this,"select_handlers"));
71
        setDescription(new String[]{"simple","out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
50
        setDescription(new String[]{"cancel"});
72 51
        addPoint( pointX,pointY,event);
73 52
        end();
74 53
        }
......
80 59
      [ctxt.selectWithSecondPoint(pointX,pointY, event) > 0]
81 60
      WithSelectedFeatures {
82 61
        setQuestion(PluginServices.getText(this,"select_handlers"));
83
        setDescription(new String[]{"simple","out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
62
        setDescription(new String[]{"cancel"});
84 63
        addPoint( pointX,pointY,event);
85 64
        end();
86 65
        }
87 66
  // Si no lo hemos conseguido
88 67
  addPoint( pointX:double,pointY:double,event:InputEvent)
89 68
      FirstPoint {
90
        setQuestion(PluginServices.getText(this,"insert_point_selection_or_types"));
91
        setDescription(new String[]{"simple","out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
69
        setQuestion(PluginServices.getText(this,"insert_point_selection"));
70
        setDescription(new String[]{"cancel"});
92 71
        addPoint(pointX,pointY,event);
93 72
        }
94 73
  addOption(s:String)
95 74
      FirstPoint{
96
        setQuestion(PluginServices.getText(this,"insert_point_selection_or_types"));
97
        setDescription(new String[]{"end_polygon","simple","out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
75
        setQuestion(PluginServices.getText(this,"insert_point_selection"));
76
        setDescription(new String[]{"cancel"});
98 77
        setType(s);
99 78
        }
100 79

  
......
106 85
  [ctxt.selectHandlers(pointX, pointY, event)>0]
107 86
      WithHandlers {
108 87
        setQuestion(PluginServices.getText(this,"insert_destination_point"));
109
        setDescription(new String[]{"simple","out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
88
        setDescription(new String[]{"cancel"});
110 89
        addPoint( pointX,pointY,event);
111 90
        // refresh();
112 91
        }
......
117 96
    [ctxt.selectFeatures(pointX,pointY, event) && ctxt.getNextState().equals("Selection.WithSelectedFeatures")]
118 97
      WithSelectedFeatures {
119 98
        setQuestion(PluginServices.getText(this,"select_handlers"));
120
        setDescription(new String[]{"simple","out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
99
        setDescription(new String[]{"cancel"});
121 100
        addPoint( pointX,pointY,event);
122 101
        }
123 102

  
......
125 104
  // Cualquier otro caso (hemos pinchado en algo vacio), volvemos al estado inicial
126 105
  addPoint( pointX:double,pointY:double,event:InputEvent)
127 106
      FirstPoint {
128
        setQuestion(PluginServices.getText(this,"insert_point_selection_or_types"));
129
        setDescription(new String[]{"simple","out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
107
        setQuestion(PluginServices.getText(this,"insert_point_selection"));
108
        setDescription(new String[]{"cancel"});
130 109
        addPoint( pointX,pointY,event);
131 110
        // refresh();
132 111
        }
133 112
	 addOption(s:String)
134 113
      FirstPoint{
135
        setQuestion(PluginServices.getText(this,"insert_point_selection_or_types"));
136
        setDescription(new String[]{"end_polygon","simple","out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
114
        setQuestion(PluginServices.getText(this,"insert_point_selection"));
115
        setDescription(new String[]{"cancel"});
137 116
        setType(s);
138 117
        }
139 118
}
......
142 121
  addPoint( pointX:double,pointY:double,event:InputEvent)
143 122
      WithSelectedFeatures {
144 123
        setQuestion(PluginServices.getText(this,"select_handlers"));
145
        setDescription(new String[]{"simple","out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
124
        setDescription(new String[]{"cancel"});
146 125
        addPoint( pointX,pointY,event);
147 126
        refresh();
148 127
        }
149 128
}
150 129

  
151
SecondPointOutRectangle{
152
  // Si hemos conseguido seleccionar algo
153
  addPoint( pointX:double,pointY:double,event:InputEvent)
154
      [ctxt.selectWithSecondPointOutRectangle(pointX,pointY, event) > 0]
155
      WithSelectedFeatures {
156
        setQuestion(PluginServices.getText(this,"select_handlers"));
157
        setDescription(new String[]{"simple","out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
158
        addPoint( pointX,pointY,event);
159
        end();
160
        }
161
  // Si no lo hemos conseguido
162
  addPoint( pointX:double,pointY:double,event:InputEvent)
163
      FirstPoint {
164
        setQuestion(PluginServices.getText(this,"insert_point_selection_or_types"));
165
        setDescription(new String[]{"simple","out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
166
        addPoint(pointX,pointY,event);
167
        }
168
  addOption(s:String)
169
      FirstPoint{
170
        setQuestion(PluginServices.getText(this,"insert_point_selection_or_types"));
171
        setDescription(new String[]{"end_polygon","simple","out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
172
        setType(s);
173
        }
174

  
175
}
176
SecondPointCircle{
177
  // Si hemos conseguido seleccionar algo
178
  addPoint( pointX:double,pointY:double,event:InputEvent)
179
      [ctxt.selectWithCircle(pointX,pointY, event) > 0]
180
      WithSelectedFeatures {
181
        setQuestion(PluginServices.getText(this,"select_handlers"));
182
        setDescription(new String[]{"simple","out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
183
        addPoint( pointX,pointY,event);
184
        end();
185
        }
186
  // Si no lo hemos conseguido
187
  addPoint( pointX:double,pointY:double,event:InputEvent)
188
      FirstPoint {
189
        setQuestion(PluginServices.getText(this,"insert_point_selection_or_types"));
190
        setDescription(new String[]{"simple","out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
191
        addPoint(pointX,pointY,event);
192
        }
193
  addOption(s:String)
194
      FirstPoint{
195
        setQuestion(PluginServices.getText(this,"insert_point_selection_or_types"));
196
        setDescription(new String[]{"simple","out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
197
        setType(s);
198
        }
199
}
200

  
201
NextPointPolygon{
202
  addPoint( pointX:double,pointY:double,event:InputEvent)
203
      NextPointPolygon {
204
        setQuestion(PluginServices.getText(this,"insert_next_selection_or_end_polygon"));
205
        setDescription(new String[]{"end_polygon","simple","out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
206
        addPoint(pointX,pointY,event);
207
        }
208
  addOption(s:String)
209
      FirstPoint{
210
        setQuestion(PluginServices.getText(this,"insert_point_selection_or_types"));
211
        setDescription(new String[]{"end_polygon","simple","out_rectangle","inside_polygon","cross_polygon","out_polygon","inside_circle","cross_circle","out_circle","select_all","cancel"});
212
        addOption(s);
213
        }
214
}
215

  
216 130
Default
217 131
{
218 132
  addOption(s:String)
trunk/extensions/extCAD/config/config.xml
82 82
			description="Extensi?n encargada de gestionar los eventos realizados sobre las geometr?as."
83 83
			active="true">
84 84
			<!--menu text="geometry/insert/spline" action-command="_spline" icon="images/Spline.png"/-->
85
			<menu text="geometry/insert/copy" action-command="_copy" icon="images/Copy.png"/>
85
			<menu text="geometry/modify/copy" action-command="_copy" icon="images/Copy.png"/>
86 86

  
87
			<!--menu text="geometry/insert/equidistance" action-command="_equidistance" icon="images/Equidistance.png"/-->
88
			<!--menu text="geometry/insert/matriz" action-command="_matriz" icon="images/Matriz.png"/-->
89
			<!--menu text="geometry/insert/symmetry" action-command="_symmetry" icon="images/Symmetry.png"/-->
90
			<menu text="geometry/insert/rotate" action-command="_rotate" icon="images/Rotation.png"/>
91
			<!--menu text="geometry/insert/stretch" action-command="_stretch" icon="images/Stretching.png"/-->
92
			<menu text="geometry/insert/scale" action-command="_scale" icon="images/Scale.png"/>
93
			<!--menu text="geometry/insert/extend" action-command="_extend" icon="images/Extend.png"/-->
94
			<!--menu text="geometry/insert/trim" action-command="_trim" icon="images/Trim.png"/-->
95
			<!--menu text="geometry/insert/unite_separate" action-command="_unit" icon="images/Unit.png"/-->
96
			<!--menu text="geometry/insert/exploit" action-command="_exploit" icon="images/Exploit.png"/-->
97
			<!--menu text="geometry/insert/chaflan" action-command="_chaflan" icon="images/Chaflan.png"/-->
98
			<!--menu text="geometry/insert/join" action-command="_join" icon="images/Join.png"/-->
87
			<!--menu text="geometry/modify/equidistance" action-command="_equidistance" icon="images/Equidistance.png"/-->
88
			<!--menu text="geometry/modify/matriz" action-command="_matriz" icon="images/Matriz.png"/-->
89
			<!--menu text="geometry/modify/symmetry" action-command="_symmetry" icon="images/Symmetry.png"/-->
90
			<menu text="geometry/modify/rotate" action-command="_rotate" icon="images/Rotation.png"/>
91
			<!--menu text="geometry/modify/stretch" action-command="_stretch" icon="images/Stretching.png"/-->
92
			<menu text="geometry/modify/scale" action-command="_scale" icon="images/Scale.png"/>
93
			<!--menu text="geometry/modify/extend" action-command="_extend" icon="images/Extend.png"/-->
94
			<!--menu text="geometry/modify/trim" action-command="_trim" icon="images/Trim.png"/-->
95
			<!--menu text="geometry/modify/unite_separate" action-command="_unit" icon="images/Unit.png"/-->
96
			<!--menu text="geometry/modify/exploit" action-command="_exploit" icon="images/Exploit.png"/-->
97
			<!--menu text="geometry/modify/chaflan" action-command="_chaflan" icon="images/Chaflan.png"/-->
98
			<!--menu text="geometry/modify/join" action-command="_join" icon="images/Join.png"/-->
99 99

  
100 100
			<tool-bar name="insert">
101 101
				<!--selectable-tool icon="images/Spline.png" action-command="_spline" tooltip="spline" group="vista"/-->
102 102
			</tool-bar>
103 103
			<tool-bar name="modificar">
104
				<selectable-tool name="selection" icon="images/Select.png" action-command="_select" tooltip="selection" group="vista"/>
105 104
				<selectable-tool icon="images/Copy.png" action-command="_copy" tooltip="copy" group="vista"/>
106 105
				<!--selectable-tool icon="images/Equidistance.png" action-command="_equidistance" tooltip="equidistance" group="vista"/-->
107 106
				<!--selectable-tool icon="images/Matriz.png" action-command="_matriz" tooltip="matriz" group="vista"/-->
......
173 172
				<selectable-tool icon="images/EditVertex.png" action-command="_editvertex" tooltip="edit_vertex" group="vista"/>
174 173
			</tool-bar>
175 174
		</extension>
175
		<extension class-name="com.iver.cit.gvsig.ComplexSelectionGeometryExtension"
176
			description="Extensi?n encargada de la selecci?n compleja de geometr?as."
177
			active="true">
178
			<menu text="geometry/seleccion_compleja" action-command="_complex_selection" icon="images/ComplexSelCAD.png"/>
179
			<tool-bar name="modificar">
180
				<selectable-tool icon="images/ComplexSelCAD.png" action-command="_complex_selection" tooltip="complex_selection" group="vista"/>
181
			</tool-bar>
182
		</extension>
176 183
		<extension class-name="com.iver.cit.gvsig.SelectionGeometryExtension"
177 184
			description="Extensi?n encargada de seleccionar las geometr?as."
178 185
			active="true">
......
181 188
				<selectable-tool icon="images/SelCAD.png" action-command="_selection" tooltip="selection" group="vista"/>
182 189
			</tool-bar>
183 190
		</extension>
191

  
184 192
	</extensions>
185 193
</plugin-config>
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/ComplexSelectionCADTool.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.Color;
44
import java.awt.Graphics;
45
import java.awt.Graphics2D;
46
import java.awt.Image;
47
import java.awt.event.InputEvent;
48
import java.awt.event.MouseEvent;
49
import java.awt.geom.Point2D;
50
import java.io.IOException;
51
import java.util.ArrayList;
52

  
53
import com.iver.andami.PluginServices;
54
import com.iver.cit.gvsig.CADExtension;
55
import com.iver.cit.gvsig.fmap.MapControl;
56
import com.iver.cit.gvsig.fmap.ViewPort;
57
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
58
import com.iver.cit.gvsig.fmap.core.Handler;
59
import com.iver.cit.gvsig.fmap.core.IFeature;
60
import com.iver.cit.gvsig.fmap.core.IGeometry;
61
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
62
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
63
import com.iver.cit.gvsig.fmap.edition.IRowEdited;
64
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter;
65
import com.iver.cit.gvsig.gui.cad.CADTool;
66
import com.iver.cit.gvsig.gui.cad.exception.CommadException;
67
import com.iver.cit.gvsig.gui.cad.tools.smc.ComplexSelectionCADToolContext;
68
import com.iver.cit.gvsig.gui.cad.tools.smc.ComplexSelectionCADToolContext.ComplexSelectionCADToolState;
69
import com.iver.cit.gvsig.layers.VectorialLayerEdited;
70

  
71
/**
72
 * DOCUMENT ME!
73
 *
74
 * @author Vicente Caballero Navarro
75
 */
76
public class ComplexSelectionCADTool extends SelectionCADTool {
77
	//public final static int tolerance = 4;
78

  
79
	private ComplexSelectionCADToolContext _fsm;
80

  
81
	//private Point2D firstPoint;
82

  
83
	//private Point2D lastPoint;
84

  
85

  
86

  
87
	//private String nextState;
88
// Registros de los que se ha sleccionado alg?n handler.
89
	//private ArrayList rowselectedHandlers=new ArrayList();
90
	//private String type=PluginServices.getText(this,"inside_circle");
91
	//private ArrayList pointsPolygon=new ArrayList();
92
	/**
93
	 * Crea un nuevo ComplexSelectionCADTool.
94
	 */
95
	public ComplexSelectionCADTool() {
96
		type=PluginServices.getText(this,"inside_circle");
97
	}
98

  
99
	/**
100
	 * M?todo de incio, para poner el c?digo de todo lo que se requiera de una
101
	 * carga previa a la utilizaci?n de la herramienta.
102
	 */
103
	public void init() {
104
		_fsm = new ComplexSelectionCADToolContext(this);
105
		setNextTool("complex_selection");
106

  
107
		setType(PluginServices.getText(this,"inside_circle"));
108
	}
109

  
110
	/**
111
	 * Equivale al transition del prototipo pero sin pasarle como par? metro el
112
	 * editableFeatureSource que ya estar? creado.
113
	 *
114
	 * @param selection
115
	 *            Bitset con las geometr?as que est?n seleccionadas.
116
	 * @param x
117
	 *            par?metro x del punto que se pase en esta transici?n.
118
	 * @param y
119
	 *            par?metro y del punto que se pase en esta transici?n.
120
	 */
121
	public void addPoint(double x, double y, InputEvent event) {
122
		if (((MouseEvent)event).getClickCount()==2){
123
			pointDoubleClick((MapControl)event.getComponent());
124
			return;
125
		}
126
		ComplexSelectionCADToolState actualState = (ComplexSelectionCADToolState) _fsm
127
				.getPreviousState();
128
		String status = actualState.getName();
129
		System.out.println("PREVIOUSSTATE =" + status); // + "ESTADO ACTUAL: " +
130
														// _fsm.getState());
131
		VectorialLayerEdited vle = getVLE();
132
		VectorialEditableAdapter vea=vle.getVEA();
133
		ArrayList selectedHandler = vle.getSelectedHandler();
134
		ArrayList selectedRow = vle.getSelectedRow();
135
		System.out.println("STATUS ACTUAL = " + _fsm.getTransition());
136
		if (status.equals("Selection.FirstPoint")) {
137
			firstPoint=new Point2D.Double(x,y);
138
			pointsPolygon.add(firstPoint);
139
		} else if (status.equals("Selection.SecondPoint")) {
140
		} else if (status.equals("Selection.WithFeatures")) {
141
		} else if (status.equals("Selection.WithHandlers")) {
142
			vea.startComplexRow();
143
			for (int i = 0; i < selectedRow.size(); i++) {
144
				IRowEdited row = (IRowEdited) selectedRow.get(i);
145
				// Movemos los handlers que hemos seleccionado
146
				// previamente dentro del m?todo select()
147
				for (int k = 0; k < selectedHandler.size(); k++) {
148
					Handler h = (Handler) selectedHandler.get(k);
149
					h.set(x, y);
150
				}
151

  
152
				modifyFeature(row.getIndex(), (IFeature) row.getLinkedRow().cloneRow());
153
			}
154
			try {
155
				vea.endComplexRow();
156
			} catch (IOException e) {
157
				e.printStackTrace();
158
			} catch (DriverIOException e) {
159
				e.printStackTrace();
160
			}
161
		}else if (status.equals("Selection.NextPointPolygon")) {
162
			pointsPolygon.add(new Point2D.Double(x,y));
163
		}
164
	}
165

  
166
	/**
167
	 * Receives second point
168
	 * @param x
169
	 * @param y
170
	 * @return numFeatures selected
171
	 */
172
	public int selectWithSecondPointOutRectangle(double x, double y, InputEvent event) {
173
		Point2D lastPoint=new Point2D.Double(x,y);
174
		GeneralPathX gpx=new GeneralPathX();
175
		gpx.moveTo(firstPoint.getX(),firstPoint.getY());
176
		gpx.lineTo(lastPoint.getX(),firstPoint.getY());
177
		gpx.lineTo(lastPoint.getX(),lastPoint.getY());
178
		gpx.lineTo(firstPoint.getX(),lastPoint.getY());
179
		gpx.closePath();
180
		IGeometry rectangle=ShapeFactory.createPolygon2D(gpx);
181
		return selectWithPolygon(rectangle);
182
	}
183
	/**
184
	 * Receives second point
185
	 * @param x
186
	 * @param y
187
	 * @return numFeatures selected
188
	 */
189
	public int selectWithCircle(double x, double y, InputEvent event) {
190
		IGeometry circle=ShapeFactory.createCircle(firstPoint,new Point2D.Double(x,y));
191
		return selectWithPolygon(circle);
192
	}
193
	public int selectWithPolygon(IGeometry polygon) {
194
		VectorialLayerEdited vle = getVLE();
195
		PluginServices.getMDIManager().setWaitCursor();
196

  
197
		if (getType().equals(PluginServices.getText(this,"inside_circle")) || getType().equals(PluginServices.getText(this,"inside_polygon"))) {
198
			vle.selectInsidePolygon(polygon);
199
		} else if (getType().equals(PluginServices.getText(this,"cross_circle")) || getType().equals(PluginServices.getText(this,"cross_polygon"))) {
200
			vle.selectCrossPolygon(polygon);
201
		} else if (getType().equals(PluginServices.getText(this,"out_circle")) || getType().equals(PluginServices.getText(this,"out_polygon")) || getType().equals(PluginServices.getText(this,"out_rectangle"))) {
202
			vle.selectOutPolygon(polygon);
203
		}
204
		ArrayList selectedRow = vle.getSelectedRow();
205
		PluginServices.getMDIManager().restoreCursor();
206
		if (selectedRow.size() > 0) {
207
			nextState = "Selection.WithSelectedFeatures";
208
			end();
209
		} else
210
			nextState = "Selection.FirstPoint";
211
		return selectedRow.size();
212
	}
213

  
214
	/**
215
	 * M?todo para dibujar la lo necesario para el estado en el que nos
216
	 * encontremos.
217
	 *
218
	 * @param g
219
	 *            Graphics sobre el que dibujar.
220
	 * @param selectedGeometries
221
	 *            BitSet con las geometr?as seleccionadas.
222
	 * @param x
223
	 *            par?metro x del punto que se pase para dibujar.
224
	 * @param y
225
	 *            par?metro x del punto que se pase para dibujar.
226
	 */
227
	public void drawOperation(Graphics g, double x, double y) {
228
		ComplexSelectionCADToolState actualState = _fsm.getState();
229
		String status = actualState.getName();
230
		VectorialLayerEdited vle = getVLE();
231
		ArrayList selectedHandler = vle.getSelectedHandler();
232
		ViewPort vp=vle.getLayer().getFMap().getViewPort();
233
		if (status.equals("Selection.SecondPoint") || status.equals("Selection.SecondPointOutRectangle")) {
234
			// Dibuja el rect?ngulo de selecci?n
235
			GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
236
					4);
237
			elShape.moveTo(firstPoint.getX(), firstPoint.getY());
238
			elShape.lineTo(x, firstPoint.getY());
239
			elShape.lineTo(x, y);
240
			elShape.lineTo(firstPoint.getX(), y);
241
			elShape.lineTo(firstPoint.getX(), firstPoint.getY());
242
			ShapeFactory.createPolyline2D(elShape).draw((Graphics2D) g,
243
					vp,
244
					CADTool.selectSymbol);
245
			Image img = vle.getSelectionImage();
246
	        g.drawImage(img, 0, 0, null);
247
	        return;
248
		}if (status.equals("Selection.SecondPointCircle")) {
249
			// Dibuja el c?rculo de selecci?n
250
			ShapeFactory.createCircle(firstPoint,new Point2D.Double(x,y)).draw((Graphics2D) g,
251
					vp,
252
					CADTool.selectSymbol);
253
			Image img = vle.getSelectionImage();
254
	        g.drawImage(img, 0, 0, null);
255
	        return;
256
		}else if (status.equals("Selection.NextPointPolygon")) {
257
			// Dibuja el pol?gono de selecci?n
258
			IGeometry polygon=getGeometryPolygon(new Point2D.Double(x,y));
259
			polygon.draw((Graphics2D) g,
260
					vp,
261
					CADTool.selectSymbol);
262
			Image img = vle.getSelectionImage();
263
	        g.drawImage(img, 0, 0, null);
264
	        return;
265
		}else if (status.equals("Selection.WithHandlers")) {
266
			// Movemos los handlers que hemos seleccionado
267
			// previamente dentro del m?todo select()
268
			for (int k = 0; k < selectedHandler.size(); k++) {
269
				Handler h = (Handler) selectedHandler.get(k);
270
				h.set(x, y);
271
			}
272
			// Y una vez movidos los v?rtices (handles)
273
			// redibujamos la nueva geometr?a.
274
			for (int i = 0; i < rowselectedHandlers.size(); i++) {
275
				IRowEdited rowEd = (IRowEdited) rowselectedHandlers.get(i);
276
				IGeometry geom = ((IFeature) rowEd.getLinkedRow())
277
						.getGeometry().cloneGeometry();
278
				g.setColor(Color.gray);
279
				geom.draw((Graphics2D) g, vp, CADTool.modifySymbol);
280
			}
281
			return;
282
		}else{
283
			try{
284
			Image imgSel = vle.getSelectionImage();
285
	        if (imgSel!=null)
286
			g.drawImage(imgSel, 0, 0, null);
287
	        Image imgHand = vle.getHandlersImage();
288
	        if (imgHand!=null)
289
			g.drawImage(imgHand, 0, 0, null);
290
			}catch (Exception e) {
291
			}
292
		}
293
	}
294

  
295
	/**
296
	 * Add a diferent option.
297
	 *
298
	 * @param sel
299
	 *            DOCUMENT ME!
300
	 * @param s
301
	 *            Diferent option.
302
	 */
303
	public void addOption(String s) {
304
		ComplexSelectionCADToolState actualState = (ComplexSelectionCADToolState) _fsm
305
				.getPreviousState();
306
		String status = actualState.getName();
307
		System.out.println("PREVIOUSSTATE =" + status); // + "ESTADO ACTUAL: " +
308
		// _fsm.getState());
309
		System.out.println("STATUS ACTUAL = " + _fsm.getTransition());
310
		if (s.equals(PluginServices.getText(this,"cancel"))){
311
			init();
312
			return;
313
		}else if (s.equals(PluginServices.getText(this,"select_all"))){
314
			selectAll();
315
			init();
316
			return;
317
		}
318
		if (status.equals("Selection.FirstPoint")) {
319
			setType(s);
320
			return;
321
		}else if (status.equals("Selection.NextPointPolygon")){
322
			if (s.equals(PluginServices.getText(this,"end_polygon")) || s.equals("E") || s.equals("e")) {
323
			IGeometry polygon=getGeometryPolygon(null);
324
			selectWithPolygon(polygon);
325
			pointsPolygon.clear();
326
			setType(PluginServices.getText(this,"inside_circle"));
327
			return;
328
			}
329
		}
330
		init();
331
	}
332
	private int selectAll() {
333
		VectorialLayerEdited vle = getVLE();
334
		PluginServices.getMDIManager().setWaitCursor();
335
		vle.selectAll();
336
		ArrayList selectedRow = vle.getSelectedRow();
337
		PluginServices.getMDIManager().restoreCursor();
338
		if (selectedRow.size() > 0) {
339
			nextState = "Selection.WithSelectedFeatures";
340
		} else
341
			nextState = "Selection.FirstPoint";
342
		end();
343
		return selectedRow.size();
344
	}
345

  
346
	private IGeometry getGeometryPolygon(Point2D p) {
347
		Point2D[] points = (Point2D[]) pointsPolygon.toArray(new Point2D[0]);
348
		GeneralPathX gpx = new GeneralPathX();
349
		for (int i = 0; i < points.length; i++) {
350
			if (i == 0) {
351
				gpx.moveTo(points[i].getX(), points[i].getY());
352
			} else {
353
				gpx.lineTo(points[i].getX(), points[i].getY());
354
			}
355
		}
356
		if (p!=null){
357
			gpx.lineTo(p.getX(),p.getY());
358
			gpx.closePath();
359
			IGeometry polyline = ShapeFactory.createPolyline2D(gpx);
360
			return polyline;
361
		}
362
		gpx.closePath();
363
		IGeometry polygon = ShapeFactory.createPolygon2D(gpx);
364
		return polygon;
365
	}
366

  
367
	/*
368
	 * (non-Javadoc)
369
	 *
370
	 * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
371
	 */
372
	public void addValue(double d) {
373
	}
374

  
375
	public void end() {
376
		if (!getNextTool().equals("complex_selection"))
377
			CADExtension.setCADTool(getNextTool(),false);
378
	}
379

  
380
	public String getName() {
381
		return PluginServices.getText(this,"complex_selection_");
382
	}
383

  
384
	public boolean selectFeatures(double x, double y, InputEvent event) {
385
		ComplexSelectionCADToolState actualState = (ComplexSelectionCADToolState) _fsm
386
				.getState();
387

  
388
		String status = actualState.getName();
389
		VectorialLayerEdited vle = getVLE();
390

  
391

  
392
		if ((status.equals("Selection.FirstPoint"))
393
				|| (status.equals("Selection.WithSelectedFeatures"))) {
394
			PluginServices.getMDIManager().setWaitCursor();
395
			firstPoint = new Point2D.Double(x, y);
396
			vle.selectWithPoint(x,y);
397
			PluginServices.getMDIManager().restoreCursor();
398
		}
399
		ArrayList selectedRow = vle.getSelectedRow();
400
		if (selectedRow.size() > 0) {
401
			nextState = "Selection.WithSelectedFeatures";
402
			return true;
403
		} else {
404
			{
405
				nextState = "Selection.SecondPoint";
406
				return true;
407
			}
408
		}
409
	}
410

  
411
	public int selectHandlers(double x, double y, InputEvent event) {
412
		Point2D auxPoint = new Point2D.Double(x, y);
413

  
414
		VectorialLayerEdited vle = getVLE();
415
		ArrayList selectedHandler = vle.getSelectedHandler();
416
		ArrayList selectedRow = vle.getSelectedRow();
417
		System.out.println("DENTRO DE selectHandlers. selectedRow.size= "
418
				+ selectedRow.size());
419
		selectedHandler.clear();
420

  
421
		// Se comprueba si se pincha en una gemometr?a
422
		PluginServices.getMDIManager().setWaitCursor();
423

  
424
		double tam = getCadToolAdapter().getMapControl().getViewPort()
425
				.toMapDistance(tolerance);
426

  
427
		Handler[] handlers = null;
428
		rowselectedHandlers.clear();
429
		for (int i = 0; i < selectedRow.size(); i++) {
430
			IRowEdited rowEd = (IRowEdited) selectedRow.get(i);
431

  
432
			IFeature fea = (IFeature) rowEd.getLinkedRow();
433
			handlers = fea.getGeometry().getHandlers(IGeometry.SELECTHANDLER);
434
			// y miramos los handlers de cada entidad seleccionada
435
			double min = tam;
436
			// int hSel = -1;
437

  
438
			for (int j = 0; j < handlers.length; j++) {
439
				Point2D handlerPoint = handlers[j].getPoint();
440
				double distance = auxPoint.distance(handlerPoint);
441
				if (distance <= min) {
442
					min = distance;
443
					// hSel = j;
444
					selectedHandler.add(handlers[j]);
445
					rowselectedHandlers.add(rowEd);
446
				}
447
			}
448
		}
449
		PluginServices.getMDIManager().restoreCursor();
450

  
451
		int numHandlesSelected = selectedHandler.size();
452

  
453
		/*
454
		 * if (numHandlesSelected == 0) selectFeatures(x,y);
455
		 */
456

  
457
		return numHandlesSelected;
458
	}
459

  
460
	public String getType() {
461
		return type;
462
	}
463

  
464
	public void setType(String type) {
465
		if (type.equals("OR") || type.equals("or")){
466
			this.type=PluginServices.getText(this,"out_rectangle");
467
		}else if (type.equals("IP") || type.equals("ip")){
468
			this.type=PluginServices.getText(this,"inside_polygon");
469
		}else if (type.equals("CP") || type.equals("cp")){
470
			this.type=PluginServices.getText(this,"cross_polygon");
471
		}else if (type.equals("OP") || type.equals("op")){
472
			this.type=PluginServices.getText(this,"out_polygon");
473
		}else if (type.equals("IC") || type.equals("ic")){
474
			this.type=PluginServices.getText(this,"inside_circle");
475
		}else if (type.equals("CC") || type.equals("cc")){
476
			this.type=PluginServices.getText(this,"cross_circle");
477
		}else if (type.equals("OC") || type.equals("oc")){
478
			this.type=PluginServices.getText(this,"cross_circle");
479
		}else if (type.equals(PluginServices.getText(this,"select_all"))){
480
			selectAll();
481
			init();
482
		}else{
483
			this.type = type;
484
		}
485
		pointsPolygon.clear();
486
	}
487
	/*
488
	 * (non-Javadoc)
489
	 *
490
	 * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet,
491
	 *      double, double)
492
	 */
493
	public void transition(double x, double y, InputEvent event) {
494
		System.out.println("TRANSICION DESDE ESTADO " + _fsm.getState()
495
				+ " x= " + x + " y=" + y);
496
		try{
497
		_fsm.addPoint(x, y, event);
498
		}catch (Exception e) {
499
			init();
500
		}
501
		System.out.println("ESTADO ACTUAL: " + getStatus());
502

  
503
		// ESTO LO QUITO POR AHORA, PERO PUEDE QUE LO NECESITEMOS VOLVER A PONER.
504
		// Lo he quitado porque cuando seleccionas algo con CAD, molesta que
505
		// te hagan un redibujado.
506
		/* FLyrVect lv=(FLyrVect)((VectorialLayerEdited)CADExtension.getEditionManager().getActiveLayerEdited()).getLayer();
507
		lv.getSource().getRecordset().getSelectionSupport().fireSelectionEvents(); */
508
	}
509
	public String getStatus() {
510
		try {
511
			ComplexSelectionCADToolState actualState = (ComplexSelectionCADToolState) _fsm
512
					.getPreviousState();
513
			String status = actualState.getName();
514

  
515
			return status;
516
		} catch (NullPointerException e) {
517
			return "Selection.FirstPoint";
518
		}
519
	}
520
	/*
521
	 * (non-Javadoc)
522
	 *
523
	 * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet,
524
	 *      java.lang.String)
525
	 */
526
	public void transition(String s) throws CommadException {
527
		if (!super.changeCommand(s)){
528

  
529
			_fsm.addOption(s);
530

  
531
    	}
532
	}
533
	/*
534
	 * (non-Javadoc)
535
	 *
536
	 * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet,
537
	 *      double)
538
	 */
539
	public void transition(double d) {
540
		// _fsm.addValue(sel,d);
541
	}
542

  
543
	public String toString() {
544
		return "_complex_selection";
545
	}
546
	public String getNextState() {
547
		return nextState;
548
	}
549

  
550
}
0 551

  
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/SelectionCADTool.java
91 91

  
92 92
	private SelectionCADToolContext _fsm;
93 93

  
94
	private Point2D firstPoint;
94
	protected Point2D firstPoint;
95 95

  
96 96
	//private Point2D lastPoint;
97 97

  
98 98

  
99 99

  
100
	private String nextState;
100
	protected String nextState;
101 101
// Registros de los que se ha sleccionado alg?n handler.
102
	private ArrayList rowselectedHandlers=new ArrayList();
103
	private String type=PluginServices.getText(this,"simple");
104
	private ArrayList pointsPolygon=new ArrayList();
102
	protected ArrayList rowselectedHandlers=new ArrayList();
103
	protected String type=PluginServices.getText(this,"simple");
104
	protected ArrayList pointsPolygon=new ArrayList();
105 105
	/**
106 106
	 * Crea un nuevo SelectionCADTool.
107 107
	 */
......
114 114
	public void init() {
115 115
		_fsm = new SelectionCADToolContext(this);
116 116
		setNextTool("selection");
117

  
118 117
		setType(PluginServices.getText(this,"simple"));
119 118
	}
120 119

  
......
257 256
			} catch (DriverIOException e) {
258 257
				e.printStackTrace();
259 258
			}
260
		}else if (status.equals("Selection.NextPointPolygon")) {
261
			pointsPolygon.add(new Point2D.Double(x,y));
262 259
		}
263 260
	}
264 261

  
......
280 277
			nextState = "Selection.FirstPoint";
281 278
		return selectedRow.size();
282 279
	}
283
	/**
284
	 * Receives second point
285
	 * @param x
286
	 * @param y
287
	 * @return numFeatures selected
288
	 */
289
	public int selectWithSecondPointOutRectangle(double x, double y, InputEvent event) {
290
		Point2D lastPoint=new Point2D.Double(x,y);
291
		GeneralPathX gpx=new GeneralPathX();
292
		gpx.moveTo(firstPoint.getX(),firstPoint.getY());
293
		gpx.lineTo(lastPoint.getX(),firstPoint.getY());
294
		gpx.lineTo(lastPoint.getX(),lastPoint.getY());
295
		gpx.lineTo(firstPoint.getX(),lastPoint.getY());
296
		gpx.closePath();
297
		IGeometry rectangle=ShapeFactory.createPolygon2D(gpx);
298
		return selectWithPolygon(rectangle);
299
//		VectorialLayerEdited vle = getVLE();
300
//		PluginServices.getMDIManager().setWaitCursor();
301
//		vle.selectWithSecondPointOutRectangle(firstPoint,x,y);
302
//		ArrayList selectedRow = vle.getSelectedRow();
303
//		PluginServices.getMDIManager().restoreCursor();
304
//		if (selectedRow.size() > 0) {
305
//			nextState = "Selection.WithSelectedFeatures";
306
//		} else
307
//			nextState = "Selection.FirstPoint";
308
//		return selectedRow.size();
309
	}
310
	/**
311
	 * Receives second point
312
	 * @param x
313
	 * @param y
314
	 * @return numFeatures selected
315
	 */
316
	public int selectWithCircle(double x, double y, InputEvent event) {
317
		IGeometry circle=ShapeFactory.createCircle(firstPoint,new Point2D.Double(x,y));
318
		return selectWithPolygon(circle);
319
	}
320
	public int selectWithPolygon(IGeometry polygon) {
321
		VectorialLayerEdited vle = getVLE();
322
		PluginServices.getMDIManager().setWaitCursor();
323 280

  
324
		if (getType().equals(PluginServices.getText(this,"inside_circle")) || getType().equals(PluginServices.getText(this,"inside_polygon"))) {
325
			vle.selectInsidePolygon(polygon);
326
		} else if (getType().equals(PluginServices.getText(this,"cross_circle")) || getType().equals(PluginServices.getText(this,"cross_polygon"))) {
327
			vle.selectCrossPolygon(polygon);
328
		} else if (getType().equals(PluginServices.getText(this,"out_circle")) || getType().equals(PluginServices.getText(this,"out_polygon")) || getType().equals(PluginServices.getText(this,"out_rectangle"))) {
329
			vle.selectOutPolygon(polygon);
330
		}
331
		ArrayList selectedRow = vle.getSelectedRow();
332
		PluginServices.getMDIManager().restoreCursor();
333
		if (selectedRow.size() > 0) {
334
			nextState = "Selection.WithSelectedFeatures";
335
			end();
336
		} else
337
			nextState = "Selection.FirstPoint";
338
		return selectedRow.size();
339
	}
340

  
341 281
	/**
342 282
	 * M?todo para dibujar la lo necesario para el estado en el que nos
343 283
	 * encontremos.
......
357 297
		VectorialLayerEdited vle = getVLE();
358 298
		ArrayList selectedHandler = vle.getSelectedHandler();
359 299
		ViewPort vp=vle.getLayer().getFMap().getViewPort();
360
		if (status.equals("Selection.SecondPoint") || status.equals("Selection.SecondPointOutRectangle")) {
300
		if (status.equals("Selection.SecondPoint")) {
361 301
			// Dibuja el rect?ngulo de selecci?n
362 302
			GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
363 303
					4);
......
372 312
			Image img = vle.getSelectionImage();
373 313
	        g.drawImage(img, 0, 0, null);
374 314
	        return;
375
		}if (status.equals("Selection.SecondPointCircle")) {
376
			// Dibuja el c?rculo de selecci?n
377
			ShapeFactory.createCircle(firstPoint,new Point2D.Double(x,y)).draw((Graphics2D) g,
378
					vp,
379
					CADTool.selectSymbol);
380
			Image img = vle.getSelectionImage();
381
	        g.drawImage(img, 0, 0, null);
382
	        return;
383
		}else if (status.equals("Selection.NextPointPolygon")) {
384
			// Dibuja el pol?gono de selecci?n
385
			IGeometry polygon=getGeometryPolygon(new Point2D.Double(x,y));
386
			polygon.draw((Graphics2D) g,
387
					vp,
388
					CADTool.selectSymbol);
389
			Image img = vle.getSelectionImage();
390
	        g.drawImage(img, 0, 0, null);
391
	        return;
392 315
		}else if (status.equals("Selection.WithHandlers")) {
393 316
			// Movemos los handlers que hemos seleccionado
394 317
			// previamente dentro del m?todo select()
......
437 360
		if (s.equals(PluginServices.getText(this,"cancel"))){
438 361
			init();
439 362
			return;
440
		}else if (s.equals(PluginServices.getText(this,"select_all"))){
441
			selectAll();
442
			init();
443
			return;
444 363
		}
445 364
		if (status.equals("Selection.FirstPoint")) {
446 365
			setType(s);
447 366
			return;
448
		}else if (status.equals("Selection.NextPointPolygon")){
449
			if (s.equals(PluginServices.getText(this,"end_polygon")) || s.equals("E") || s.equals("e")) {
450
			IGeometry polygon=getGeometryPolygon(null);
451
			selectWithPolygon(polygon);
452
			pointsPolygon.clear();
453
			setType(PluginServices.getText(this,"simple"));
454
			return;
455
			}
456 367
		}
457 368
		init();
458 369
	}
459
	private int selectAll() {
460
		VectorialLayerEdited vle = getVLE();
461
		PluginServices.getMDIManager().setWaitCursor();
462
		vle.selectAll();
463
		ArrayList selectedRow = vle.getSelectedRow();
464
		PluginServices.getMDIManager().restoreCursor();
465
		if (selectedRow.size() > 0) {
466
			nextState = "Selection.WithSelectedFeatures";
467
		} else
468
			nextState = "Selection.FirstPoint";
469
		end();
470
		return selectedRow.size();
471
	}
472 370

  
473
	private IGeometry getGeometryPolygon(Point2D p) {
474
		Point2D[] points = (Point2D[]) pointsPolygon.toArray(new Point2D[0]);
475
		GeneralPathX gpx = new GeneralPathX();
476
		for (int i = 0; i < points.length; i++) {
477
			if (i == 0) {
478
				gpx.moveTo(points[i].getX(), points[i].getY());
479
			} else {
480
				gpx.lineTo(points[i].getX(), points[i].getY());
481
			}
482
		}
483
		if (p!=null){
484
			gpx.lineTo(p.getX(),p.getY());
485
			gpx.closePath();
486
			IGeometry polyline = ShapeFactory.createPolyline2D(gpx);
487
			return polyline;
488
		}
489
		gpx.closePath();
490
		IGeometry polygon = ShapeFactory.createPolygon2D(gpx);
491
		return polygon;
492
	}
493 371

  
372

  
373

  
494 374
	/*
495 375
	 * (non-Javadoc)
496 376
	 *
......
605 485
	public void setType(String type) {
606 486
		if (type.equals("S") || type.equals("s")){
607 487
			this.type=PluginServices.getText(this,"simple");
608
		}else if (type.equals("OR") || type.equals("or")){
609
			this.type=PluginServices.getText(this,"out_rectangle");
610
		}else if (type.equals("IP") || type.equals("ip")){
611
			this.type=PluginServices.getText(this,"inside_polygon");
612
		}else if (type.equals("CP") || type.equals("cp")){
613
			this.type=PluginServices.getText(this,"cross_polygon");
614
		}else if (type.equals("OP") || type.equals("op")){
615
			this.type=PluginServices.getText(this,"out_polygon");
616
		}else if (type.equals("IC") || type.equals("ic")){
617
			this.type=PluginServices.getText(this,"inside_circle");
618
		}else if (type.equals("CC") || type.equals("cc")){
619
			this.type=PluginServices.getText(this,"cross_circle");
620
		}else if (type.equals("OC") || type.equals("oc")){
621
			this.type=PluginServices.getText(this,"cross_circle");
622
		}else if (type.equals(PluginServices.getText(this,"select_all"))){
623
			selectAll();
624
			init();
625 488
		}else{
626 489
			this.type = type;
627 490
		}
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/smc/SelectionCADToolContext.java
126 126
        /* package */ static Selection_Default.Selection_SecondPoint SecondPoint;
127 127
        /* package */ static Selection_Default.Selection_WithSelectedFeatures WithSelectedFeatures;
128 128
        /* package */ static Selection_Default.Selection_WithHandlers WithHandlers;
129
        /* package */ static Selection_Default.Selection_SecondPointOutRectangle SecondPointOutRectangle;
130
        /* package */ static Selection_Default.Selection_SecondPointCircle SecondPointCircle;
131
        /* package */ static Selection_Default.Selection_NextPointPolygon NextPointPolygon;
132 129
        private static Selection_Default Default;
133 130

  
134 131
        static
......
137 134
            SecondPoint = new Selection_Default.Selection_SecondPoint("Selection.SecondPoint", 1);
138 135
            WithSelectedFeatures = new Selection_Default.Selection_WithSelectedFeatures("Selection.WithSelectedFeatures", 2);
139 136
            WithHandlers = new Selection_Default.Selection_WithHandlers("Selection.WithHandlers", 3);
140
            SecondPointOutRectangle = new Selection_Default.Selection_SecondPointOutRectangle("Selection.SecondPointOutRectangle", 4);
141
            SecondPointCircle = new Selection_Default.Selection_SecondPointCircle("Selection.SecondPointCircle", 5);
142
            NextPointPolygon = new Selection_Default.Selection_NextPointPolygon("Selection.NextPointPolygon", 6);
143 137
            Default = new Selection_Default("Selection.Default", -1);
144 138
        }
145 139

  
......
217 211
            {
218 212
                SelectionCADTool ctxt = context.getOwner();
219 213

  
220
                ctxt.setQuestion(PluginServices.getText(this,"insert_point_selection_or_types"));
221
                ctxt.setDescription(new String[]{"simple", "out_rectangle", "inside_polygon", "cross_polygon", "out_polygon", "inside_circle", "cross_circle", "out_circle", "select_all", "cancel"});
214
                ctxt.setQuestion(PluginServices.getText(this,"insert_point_selection"));
215
                ctxt.setDescription(new String[]{"cancel"});
222 216
                return;
223 217
            }
224 218

  
......
231 225
                context.clearState();
232 226
                try
233 227
                {
234
                    ctxt.setQuestion(PluginServices.getText(this,"insert_point_selection_or_types"));
235
                    ctxt.setDescription(new String[]{"simple", "out_rectangle", "inside_polygon", "cross_polygon", "out_polygon", "inside_circle", "cross_circle", "out_circle", "select_all", "cancel"});
228
                    ctxt.setQuestion(PluginServices.getText(this,"insert_point_selection"));
229
                    ctxt.setDescription(new String[]{"cancel"});
236 230
                    ctxt.addOption(s);
237 231
                }
238 232
                finally
......
246 240
            {
247 241
                SelectionCADTool ctxt = context.getOwner();
248 242

  
249
                if (ctxt.getType().equals(PluginServices.getText(this,"out_rectangle")))
243
                if (ctxt.getType().equals(PluginServices.getText(this,"simple")) && ctxt.selectFeatures(pointX,pointY, event) && ctxt.getNextState().equals("Selection.SecondPoint"))
250 244
                {
251 245

  
252 246
                    (context.getState()).Exit(context);
253 247
                    context.clearState();
254 248
                    try
255 249
                    {
256
                        ctxt.setQuestion(PluginServices.getText(this,"insert_second_point_selection"));
257
                        ctxt.setDescription(new String[]{"simple", "out_rectangle", "inside_polygon", "cross_polygon", "out_polygon", "inside_circle", "cross_circle", "out_circle", "select_all", "cancel"});
250
                        ctxt.setQuestion(PluginServices.getText(this,"insert_second_point"));
251
                        ctxt.setDescription(new String[]{"cancel"});
258 252
                        ctxt.addPoint(pointX, pointY, event);
259 253
                    }
260 254
                    finally
261 255
                    {
262
                        context.setState(Selection.SecondPointOutRectangle);
263
                        (context.getState()).Entry(context);
264
                    }
265
                }
266
                else if (ctxt.getType().equals(PluginServices.getText(this,"inside_circle")) || ctxt.getType().equals(PluginServices.getText(this,"cross_circle")) || ctxt.getType().equals(PluginServices.getText(this,"out_circle")))
267
                {
268

  
269
                    (context.getState()).Exit(context);
270
                    context.clearState();
271
                    try
272
                    {
273
                        ctxt.setQuestion(PluginServices.getText(this,"insert_second_point_selection"));
274
                        ctxt.setDescription(new String[]{"simple", "out_rectangle", "inside_polygon", "cross_polygon", "out_polygon", "inside_circle", "cross_circle", "out_circle", "select_all", "cancel"});
275
                        ctxt.addPoint(pointX, pointY, event);
276
                    }
277
                    finally
278
                    {
279
                        context.setState(Selection.SecondPointCircle);
280
                        (context.getState()).Entry(context);
281
                    }
282
                }
283
                else if (ctxt.getType().equals(PluginServices.getText(this,"inside_polygon")) || ctxt.getType().equals(PluginServices.getText(this,"cross_polygon")) || ctxt.getType().equals(PluginServices.getText(this,"out_polygon")))
284
                {
285

  
286
                    (context.getState()).Exit(context);
287
                    context.clearState();
288
                    try
289
                    {
290
                        ctxt.setQuestion(PluginServices.getText(this,"insert_next_point_selection_or_end_polygon"));
291
                        ctxt.setDescription(new String[]{"end_polygon", "simple", "out_rectangle", "inside_polygon", "cross_polygon", "out_polygon", "inside_circle", "cross_circle", "out_circle", "select_all", "cancel"});
292
                        ctxt.addPoint(pointX, pointY, event);
293
                    }
294
                    finally
295
                    {
296
                        context.setState(Selection.NextPointPolygon);
297
                        (context.getState()).Entry(context);
298
                    }
299
                }
300
                else if (ctxt.getType().equals(PluginServices.getText(this,"simple")) && ctxt.selectFeatures(pointX,pointY, event) && ctxt.getNextState().equals("Selection.SecondPoint"))
301
                {
302

  
303
                    (context.getState()).Exit(context);
304
                    context.clearState();
305
                    try
306
                    {
307
                        ctxt.setQuestion(PluginServices.getText(this,"insert_second_point_selection"));
308
                        ctxt.setDescription(new String[]{"simple", "out_rectangle", "inside_polygon", "cross_polygon", "out_polygon", "inside_circle", "cross_circle", "out_circle", "select_all", "cancel"});
309
                        ctxt.addPoint(pointX, pointY, event);
310
                    }
311
                    finally
312
                    {
313 256
                        context.setState(Selection.SecondPoint);
314 257
                        (context.getState()).Entry(context);
315 258
                    }
......
322 265
                    try
323 266
                    {
324 267
                        ctxt.setQuestion(PluginServices.getText(this,"select_handlers"));
325
                        ctxt.setDescription(new String[]{"simple", "out_rectangle", "inside_polygon", "cross_polygon", "out_polygon", "inside_circle", "cross_circle", "out_circle", "select_all", "cancel"});
268
                        ctxt.setDescription(new String[]{"cancel"});
326 269
                        ctxt.addPoint(pointX, pointY, event);
327 270
                        ctxt.end();
328 271
                    }
......
365 308
                context.clearState();
366 309
                try
367 310
                {
368
                    ctxt.setQuestion(PluginServices.getText(this,"insert_point_selection_or_types"));
369
                    ctxt.setDescription(new String[]{"end_polygon", "simple", "out_rectangle", "inside_polygon", "cross_polygon", "out_polygon", "inside_circle", "cross_circle", "out_circle", "select_all", "cancel"});
311
                    ctxt.setQuestion(PluginServices.getText(this,"insert_point_selection"));
312
                    ctxt.setDescription(new String[]{"cancel"});
370 313
                    ctxt.setType(s);
371 314
                }
372 315
                finally
......
389 332
                    try
390 333
                    {
391 334
                        ctxt.setQuestion(PluginServices.getText(this,"select_handlers"));
392
                        ctxt.setDescription(new String[]{"simple", "out_rectangle", "inside_polygon", "cross_polygon", "out_polygon", "inside_circle", "cross_circle", "out_circle", "select_all", "cancel"});
335
                        ctxt.setDescription(new String[]{"cancel"});
393 336
                        ctxt.addPoint(pointX, pointY, event);
394 337
                        ctxt.end();
395 338
                    }
......
406 349
                    context.clearState();
407 350
                    try
408 351
                    {
409
                        ctxt.setQuestion(PluginServices.getText(this,"insert_point_selection_or_types"));
410
                        ctxt.setDescription(new String[]{"simple", "out_rectangle", "inside_polygon", "cross_polygon", "out_polygon", "inside_circle", "cross_circle", "out_circle", "select_all", "cancel"});
352
                        ctxt.setQuestion(PluginServices.getText(this,"insert_point_selection"));
353
                        ctxt.setDescription(new String[]{"cancel"});
411 354
                        ctxt.addPoint(pointX, pointY, event);
412 355
                    }
413 356
                    finally
......
446 389
                context.clearState();
447 390
                try
448 391
                {
449
                    ctxt.setQuestion(PluginServices.getText(this,"insert_point_selection_or_types"));
450
                    ctxt.setDescription(new String[]{"end_polygon", "simple", "out_rectangle", "inside_polygon", "cross_polygon", "out_polygon", "inside_circle", "cross_circle", "out_circle", "select_all", "cancel"});
392
                    ctxt.setQuestion(PluginServices.getText(this,"insert_point_selection"));
393
                    ctxt.setDescription(new String[]{"cancel"});
451 394
                    ctxt.setType(s);
452 395
                }
453 396
                finally
......
470 413
                    try
471 414
                    {
472 415
                        ctxt.setQuestion(PluginServices.getText(this,"insert_destination_point"));
473
                        ctxt.setDescription(new String[]{"simple", "out_rectangle", "inside_polygon", "cross_polygon", "out_polygon", "inside_circle", "cross_circle", "out_circle", "select_all", "cancel"});
416
                        ctxt.setDescription(new String[]{"cancel"});
474 417
                        ctxt.addPoint(pointX, pointY, event);
475 418
                    }
476 419
                    finally
......
487 430
                    try
488 431
                    {
489 432
                        ctxt.setQuestion(PluginServices.getText(this,"select_handlers"));
490
                        ctxt.setDescription(new String[]{"simple", "out_rectangle", "inside_polygon", "cross_polygon", "out_polygon", "inside_circle", "cross_circle", "out_circle", "select_all", "cancel"});
433
                        ctxt.setDescription(new String[]{"cancel"});
491 434
                        ctxt.addPoint(pointX, pointY, event);
492 435
                    }
493 436
                    finally
......
502 445
                    context.clearState();
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff