Statistics
| Revision:

root / trunk / libraries / libExpressions / src / main / java / org / gvsig / baseclasses / GraphicOperator.java @ 23299

History | View | Annotate | Download (3.14 KB)

1
package org.gvsig.baseclasses;
2

    
3
import java.awt.geom.PathIterator;
4
import java.util.ArrayList;
5

    
6
import com.iver.cit.gvsig.fmap.core.IGeometry;
7
import com.iver.cit.gvsig.fmap.core.v02.FConverter;
8
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
9
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
10
/**
11
 * @author Vicente Caballero Navarro
12
 */
13
public abstract class GraphicOperator extends AbstractOperator{
14
        private FLyrVect lv=null;
15
        public void setLayer(FLyrVect lv) {
16
                this.lv=lv;
17
        }
18
        public FLyrVect getLayer() {
19
                return lv;
20
        }
21
        public abstract double process(Index index) throws DriverIOException;
22
        protected ArrayList getXY(IGeometry geometry) {
23
        ArrayList xs = new ArrayList();
24
        ArrayList ys = new ArrayList();
25
        ArrayList parts=new ArrayList();
26
        double[] theData = new double[6];
27

    
28
        //double[] aux = new double[6];
29
        PathIterator theIterator;
30
        int theType;
31
        int numParts = 0;
32
        boolean close=false;
33
        // boolean bFirst = true;
34
        // int xInt, yInt, antX = -1, antY = -1;
35
        theIterator = geometry.getPathIterator(null,FConverter.FLATNESS); //, flatness);
36

    
37
        // int numSegmentsAdded = 0;
38
        while (!theIterator.isDone()) {
39
            theType = theIterator.currentSegment(theData);
40

    
41
            switch (theType) {
42
            case PathIterator.SEG_MOVETO:
43
                if (numParts==0){
44
                        xs.add(new Double(theData[0]));
45
                        ys.add(new Double(theData[1]));
46
                }else{
47
                         Double[] x = (Double[]) xs.toArray(new Double[0]);
48
                     Double[] y = (Double[]) ys.toArray(new Double[0]);
49
                     parts.add(new Double[][] { x, y });
50
                     xs.clear();
51
                     ys.clear();
52
                     xs.add(new Double(theData[0]));
53
                          ys.add(new Double(theData[1]));
54
                }
55
                numParts++;
56

    
57
                break;
58

    
59
            case PathIterator.SEG_LINETO:
60
                xs.add(new Double(theData[0]));
61
                ys.add(new Double(theData[1]));
62

    
63

    
64
                break;
65

    
66

    
67
            case PathIterator.SEG_CLOSE:
68
                xs.add(new Double(theData[0]));
69
                ys.add(new Double(theData[1]));
70
                Double[] x = (Double[]) xs.toArray(new Double[0]);
71
                Double[] y = (Double[]) ys.toArray(new Double[0]);
72
                parts.add(new Double[][] { x, y });
73
                xs.clear();
74
                ys.clear();
75
                close=true;
76
                break;
77
            } //end switch
78

    
79
            theIterator.next();
80
        } //end while loop
81

    
82
//        Double[] x = (Double[]) xs.toArray(new Double[0]);
83
//        Double[] y = (Double[]) ys.toArray(new Double[0]);
84
        if (!close){
85
                xs.add(new Double(theData[0]));
86
            ys.add(new Double(theData[1]));
87
            Double[] x = (Double[]) xs.toArray(new Double[0]);
88
            Double[] y = (Double[]) ys.toArray(new Double[0]);
89
            parts.add(new Double[][] { x, y });
90
            xs.clear();
91
            ys.clear();
92
        }
93
        return parts;
94

    
95
    }
96

    
97
}