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

View differences:

SelectionCADTool.java
48 48
import java.util.ArrayList;
49 49

  
50 50
import com.iver.andami.PluginServices;
51
import com.iver.cit.gvsig.CADExtension;
51 52
import com.iver.cit.gvsig.fmap.DriverException;
52 53
import com.iver.cit.gvsig.fmap.core.DefaultFeature;
53 54
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
......
75 76
    private ArrayList selectedHandler = new ArrayList();
76 77
    private ArrayList selectedRow = new ArrayList();
77 78
    private ArrayList selectedRowIndex = new ArrayList();
78
    //private int cardinality;
79
    private String tool="selection";
79 80

  
80 81
    //double FLATNESS=getCadToolAdapter().getMapControl().getViewPort().toMapDistance(2);
81 82

  
......
83 84
     * Crea un nuevo LineCADTool.
84 85
     */
85 86
    public SelectionCADTool() {
86
        _fsm = new SelectionCADToolContext(this);
87

  
87 88
    }
88 89

  
89 90
    /**
......
91 92
     * carga previa a la utilizaci?n de la herramienta.
92 93
     */
93 94
    public void init() {
95
    	_fsm = new SelectionCADToolContext(this);
96
    	setNextTool("selection");
94 97
    }
95 98

  
96 99
    /* (non-Javadoc)
97
     * @see com.iver.cit.gvsig.gui.cad.CADTool#end()
98
     */
99
    public void end() {
100
        _fsm = new SelectionCADToolContext(this);
101
    }
102

  
103
    /* (non-Javadoc)
104 100
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
105 101
     */
106 102
    public void transition(double x, double y) {
107
        _fsm.addPoint(x, y);
103
    	((SelectionCADToolContext)_fsm).addPoint(x, y);
108 104
    }
109 105

  
110 106
    /* (non-Javadoc)
......
118 114
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
119 115
     */
120 116
    public void transition(String s) {
121
        //_fsm.addOption(sel,s);
117
        _fsm.addOption(s);
122 118
    }
123 119

  
124 120

  
125 121
    public boolean isSelected(double x, double y){
126 122
    	firstPoint=new Point2D.Double(x,y);
127
    	FBitSet selection=getVectorialAdapter().getSelection();
123
    	FBitSet selection=getCadToolAdapter().getVectorialAdapter().getSelection();
128 124
    	if (selection.cardinality() > 0) {
129 125
            //Se comprueba si se pincha un handler. El m?s cercano (o los m?s cercanos si hay empate)
130 126
            selectedRow.clear();
......
137 133
                    i = selection.nextSetBit(i + 1)) {
138 134
                Handler[] handlers=null;
139 135
				try {
140
					handlers = getVectorialAdapter().getShape(i)
136
					handlers = getCadToolAdapter().getVectorialAdapter().getShape(i)
141 137
					                         .getHandlers(IGeometry.SELECTHANDLER);
142 138
				} catch (DriverIOException e) {
143 139
					// TODO Auto-generated catch block
......
165 161
                        if (fea == null) {
166 162
                            IGeometry clonedGeometry=null;
167 163
							try {
168
								clonedGeometry = getVectorialAdapter()
164
								clonedGeometry = getCadToolAdapter().getVectorialAdapter()
169 165
								                               .getShape(i)
170 166
								                               .cloneGeometry();
171 167
							} catch (DriverIOException e) {
......
173 169
								e.printStackTrace();
174 170
							}
175 171
                            try {
176
								fea = (DefaultFeature) getVectorialAdapter()
172
								fea = (DefaultFeature) getCadToolAdapter().getVectorialAdapter()
177 173
								                           .getFeature(i);
178 174
							} catch (DriverException e) {
179 175
								// TODO Auto-generated catch block
......
201 197
                             .getViewPort().toMapDistance(tolerance);
202 198
            Rectangle2D rect = new Rectangle2D.Double(firstPoint.getX() -
203 199
                    tam, firstPoint.getY() - tam, tam * 2, tam * 2);
204
            int[] indexes = getVectorialAdapter().getRowsIndexes(rect);
200
            int[] indexes = getCadToolAdapter().getVectorialAdapter().getRowsIndexes(rect);
205 201

  
206 202
            selection.clear();
207 203

  
208 204
            for (int i = 0; i < indexes.length; i++) {
209 205
                try {
210
					if (getVectorialAdapter().getShape(indexes[i])
206
					if (getCadToolAdapter().getVectorialAdapter().getShape(indexes[i])
211 207
					            .intersects(rect)) {
212 208
					    // .intersects(rect,FLATNESS)) {
213 209
					    selection.set(indexes[i], true);
......
234 230
    public void addPoint(double x, double y) {
235 231
        SelectionCADToolState actualState = (SelectionCADToolState) _fsm.getPreviousState();
236 232
        String status = actualState.getName();
237
        FBitSet selection=getVectorialAdapter().getSelection();
233
        FBitSet selection=getCadToolAdapter().getVectorialAdapter().getSelection();
238 234
        try {
239 235
            if (status.equals("ExecuteMap.Initial")) {
240 236
                //firstPoint = new Point2D.Double(x, y);
......
266 262

  
267 263
                Rectangle2D rect = new Rectangle2D.Double(x1, y1, w1, h1);
268 264

  
269
                int[] indexes = getVectorialAdapter().getRowsIndexes(new Rectangle2D.Double(
265
                int[] indexes = getCadToolAdapter().getVectorialAdapter().getRowsIndexes(new Rectangle2D.Double(
270 266
                            x1, y1, w1, h1));
271 267

  
272 268
                for (int i = 0; i < indexes.length; i++) {
273 269
                    if (firstPoint.getX() < lastPoint.getX()) {
274
                        if (rect.contains(getVectorialAdapter()
270
                        if (rect.contains(getCadToolAdapter().getVectorialAdapter()
275 271
                                                  .getShape(indexes[i])
276 272
                                                  .getBounds2D())) {
277 273
                            selection.set(indexes[i], true);
278 274
                        }
279 275
                    } else {
280
                        if (getVectorialAdapter().getShape(indexes[i])
276
                        if (getCadToolAdapter().getVectorialAdapter().getShape(indexes[i])
281 277
                                    .intersects(rect)) { //, 0.1)){
282 278
                            selection.set(indexes[i], true);
283 279
                        }
......
317 313
     */
318 314
    public void drawOperation(Graphics g, double x,
319 315
        double y) {
320
        SelectionCADToolState actualState = _fsm.getState();
316
    	SelectionCADToolState actualState = ((SelectionCADToolContext)_fsm).getState();
321 317
        String status = actualState.getName();
322
        FBitSet selection=getVectorialAdapter().getSelection();
318
        FBitSet selection=getCadToolAdapter().getVectorialAdapter().getSelection();
323 319
        try {
324 320
			drawHandlers(g, selection, getCadToolAdapter().getMapControl().getViewPort().getAffineTransform());
325 321
		} catch (DriverIOException e) {
......
379 375
        return this.selectedRow.size();
380 376
    }
381 377

  
378
    public String getStatus(){
379
    	try{
380
    	SelectionCADToolState actualState = (SelectionCADToolState) _fsm.getPreviousState();
381
         String status = actualState.getName();
382
         return status;
383
    	}catch (NullPointerException e) {
384
			return "ExecuteMap.Initial";
385
		}
386
    }
382 387

  
388

  
389
    public String getTool() {
390
		return tool;
391
	}
392

  
393
	public void setNextTool(String tool) {
394
		this.tool = tool;
395
	}
396
	public void end() {
397
    	CADExtension.setCADTool(getTool());
398
    }
399

  
383 400
}

Also available in: Unified diff