Statistics
| Revision:

gvsig-3d / 2.0 / trunk / org.gvsig.gvsig3d / org.gvsig.gvsig3d.lib / org.gvsig.gvsig3d.lib.impl / src / main / java / org / gvsig / gvsig3d / impl / symbology3d / fill / impl / SimpleFill3DSymbol.java @ 323

History | View | Annotate | Download (5.77 KB)

1
package org.gvsig.gvsig3d.impl.symbology3d.fill.impl;
2

    
3
import java.awt.Color;
4
import java.awt.Graphics2D;
5
import java.awt.Rectangle;
6
import java.awt.geom.AffineTransform;
7

    
8
import org.gvsig.compat.print.PrintAttributes;
9
import org.gvsig.fmap.dal.feature.Feature;
10
import org.gvsig.fmap.geom.Geometry;
11
import org.gvsig.fmap.geom.GeometryLocator;
12
import org.gvsig.fmap.geom.GeometryManager;
13
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
14
import org.gvsig.fmap.geom.exception.CreateGeometryException;
15
import org.gvsig.fmap.geom.primitive.GeneralPathX;
16
import org.gvsig.fmap.geom.primitive.GeneralPathXIterator;
17
import org.gvsig.fmap.geom.primitive.Surface;
18
import org.gvsig.fmap.mapcontext.MapContextLocator;
19
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
20
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException;
21
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager;
22
import org.gvsig.gvsig3d.impl.symbology3d.marker.impl.SimpleMarker3DSymbol;
23
import org.gvsig.gvsig3d.symbology3d.fill.ISimpleFill3DSymbol;
24
import org.gvsig.gvsig3d.symbology3d.marker.ISimpleMarker3DSymbol;
25
import org.gvsig.osgvp.exceptions.node.NodeException;
26
import org.gvsig.osgvp.geometry.GeoMultiPolygon3D;
27
import org.gvsig.osgvp.geometry.GeoPointArray3D;
28
import org.gvsig.osgvp.geometry.GeoPolygon3D;
29
import org.gvsig.osgvp.geometry.GeoPolygonList3D;
30
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.AbstractFillSymbol;
31
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.SimpleFillSymbol;
32
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.AbstractMarkerSymbol;
33
import org.gvsig.tools.task.Cancellable;
34
import org.gvsig.tools.util.Callable;
35
import org.slf4j.Logger;
36
import org.slf4j.LoggerFactory;
37

    
38

    
39
/**
40
 * 
41
 * @author jtorres
42
 *
43
 */
44

    
45
public class SimpleFill3DSymbol extends AbstractFillSymbol implements ISimpleFill3DSymbol{
46

    
47
        public static final String SIMPLE_FILL3D_SYMBOL_PERSISTENCE_DEFINITION_NAME = "SimpleFill3DSymbol";
48
        private static final GeometryManager geomManager = GeometryLocator.getGeometryManager();
49
        private static final Logger LOG = LoggerFactory.getLogger(SimpleFill3DSymbol.class);
50
        public GeoPolygonList3D _geometry;
51
        public GeoMultiPolygon3D _mpolygon;
52
        protected float _height= 100;
53
        
54
        
55
        public SimpleFill3DSymbol() 
56
        {
57
                super();
58
                try {
59
                        _geometry = new GeoPolygonList3D();
60
                } catch (NodeException e) {
61
                        // TODO Auto-generated catch block
62
                        e.printStackTrace();
63
                }
64
        }
65

    
66
        public ISymbol getSymbolForSelection() {
67
                // TODO Auto-generated method stub
68
                return null;
69
        }
70

    
71

    
72

    
73
        public void draw(Graphics2D g, AffineTransform affineTransform,
74
                        Geometry geom, Feature f, Cancellable cancel) {
75

    
76
                Color c = getFillColor();
77
                //geom.getClass().getName()
78
                
79

    
80
                //WAITING for gvSIG ARCHITECTS to do something with polygons with holes in shp files
81
                //in the meanwhile nothing is gonna happen with this kind of polygons
82
                if (geom.getGeometryType().isTypeOf(Geometry.TYPES.SURFACE))
83
                {
84
                        Surface s = (Surface)geom.cloneGeometry();
85
                        _geometry.addMultiPolygon(getGeoMultiPolygon(s));
86
                }
87
                
88
                
89
                //                if (c!=null && hasFill()) {
90
                //                        g.setColor(c);
91
                //                        
92
                //                        
93
                //                        
94
                //                        g.fill(geom.getShape(affineTransform));
95
                //                }
96
                //      Border color                
97
                //                if (getOutline() != null && hasOutline()) {
98
                //                        getOutline().draw(g, affineTransform, geom, f, cancel);
99
                //                }
100

    
101
        }
102
        
103
        
104
        public GeoMultiPolygon3D getGeoMultiPolygon(Surface surface)
105
        {
106
                GeoMultiPolygon3D gmpoly = null;
107
                GeoPolygon3D poly = null;
108
                try {
109
                        gmpoly=        new GeoMultiPolygon3D();
110
                        poly = new GeoPolygon3D();
111
                } catch (NodeException e) {
112
                        // TODO Auto-generated catch block
113
                        e.printStackTrace();
114
                }
115
                int numVerts = surface.getNumVertices();
116
                if (surface.getGeometryType().isSubTypeOf(Geometry.SUBTYPES.GEOM3D))
117
                        for(int i=0;i<numVerts;i++)                
118
                                poly.addPoint(surface.getCoordinateAt(i, 0),surface.getCoordinateAt(i, 1),surface.getCoordinateAt(i, 2));
119
                else
120
                        for(int i=0;i<numVerts;i++)
121
                                poly.addPoint(surface.getCoordinateAt(i, 0),surface.getCoordinateAt(i, 1),1.0);
122
                gmpoly.addPolygon(poly);
123
                
124
                return gmpoly;
125
        }
126
        public GeoPolygonList3D getGeometry(){
127
                return _geometry;
128
        }
129
        public int getSymbolType() {
130
                // TODO Auto-generated method stub
131
                return 0;
132
        }
133

    
134
        public void drawInsideRectangle(Graphics2D g,
135
                        AffineTransform scaleInstance, Rectangle r,
136
                        PrintAttributes properties) throws SymbolDrawingException {
137

    
138
                Rectangle rect = new Rectangle(r.x, r.y, r.width, r.height);
139
                rect.setFrame(((int) rect.getMinX())+1, ((int) rect.getMinY())+1, ((int) rect.getWidth())-2, ((int) rect.getHeight())-2);
140
                Geometry geom;
141
                try {
142
                        geom = geomManager.createSurface(new GeneralPathX(rect.getPathIterator(null)), SUBTYPES.GEOM2D);
143
                } catch (CreateGeometryException e) {
144
                        LOG.error("Creating a surface", e);
145
                        throw new SymbolDrawingException(getSymbolType());
146
                }
147

    
148
                Color c = getFillColor();
149
                if (c != null && hasFill()) {
150
                        g.setColor(c);
151
                        g.fillRect(rect.x, rect.y, rect.width, rect.height);
152
                }
153
                // Border Polygons
154
                //                
155
                //                if (getOutline() != null && hasOutline()) {
156
                //                        if (properties==null)
157
                //                                getOutline().draw(g, scaleInstance, geom, null, null);
158
                //                        else
159
                //                                print(g, new AffineTransform(), geom, properties);
160
                //                }
161

    
162
        }
163
        public static class RegisterSymbol implements Callable {
164

    
165
                public Object call() throws Exception {
166
                        int[] shapeTypes;
167
                        SymbolManager manager = MapContextLocator.getSymbolManager();
168

    
169
                        shapeTypes =
170
                                new int[] { Geometry.TYPES.SURFACE, Geometry.TYPES.MULTISURFACE};
171
                        manager.registerSymbol(ISimpleFill3DSymbol.SYMBOL_NAME,
172
                                        shapeTypes,
173
                                        SimpleFill3DSymbol.class,"project.document.view3d");
174

    
175
                        return Boolean.TRUE;
176
                }
177

    
178
        }
179
        public void print(Graphics2D g, AffineTransform at, Geometry shape,
180
                        PrintAttributes properties) {
181
                // TODO Auto-generated method stub
182

    
183
        }
184

    
185
        public void setFixedHeight(float height) {
186
                _height=height;
187
                
188
        }
189

    
190

    
191
}