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 @ 350

History | View | Annotate | Download (5.98 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.core.osg.Node;
26
import org.gvsig.osgvp.exceptions.node.NodeException;
27
import org.gvsig.osgvp.geometry.GeoMultiPolygon3D;
28
import org.gvsig.osgvp.geometry.GeoPointArray3D;
29
import org.gvsig.osgvp.geometry.GeoPolygon3D;
30
import org.gvsig.osgvp.geometry.GeoPolygonList3D;
31
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.AbstractFillSymbol;
32
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.SimpleFillSymbol;
33
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.AbstractMarkerSymbol;
34
import org.gvsig.tools.task.Cancellable;
35
import org.gvsig.tools.util.Callable;
36
import org.slf4j.Logger;
37
import org.slf4j.LoggerFactory;
38

    
39

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

    
46
public class SimpleFill3DSymbol extends AbstractFillSymbol implements ISimpleFill3DSymbol{
47

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

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

    
72

    
73

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

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

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

    
102
        }
103
        
104
        
105
        public GeoMultiPolygon3D getGeoMultiPolygon(Surface surface)
106
        {
107
                GeoMultiPolygon3D gmpoly = null;
108
                GeoPolygon3D poly = null;
109
                try {
110
                        gmpoly=        new GeoMultiPolygon3D();
111
                        poly = new GeoPolygon3D();
112
                } catch (NodeException e) {
113
                        // TODO Auto-generated catch block
114
                        e.printStackTrace();
115
                }
116
                int numVerts = surface.getNumVertices();
117
                if (surface.getGeometryType().isSubTypeOf(Geometry.SUBTYPES.GEOM3D))
118
                        for(int i=0;i<numVerts;i++)                
119
                                poly.addPoint(surface.getCoordinateAt(i, 0),surface.getCoordinateAt(i, 1),surface.getCoordinateAt(i, 2));
120
                else
121
                        for(int i=0;i<numVerts;i++)
122
                                poly.addPoint(surface.getCoordinateAt(i, 0),surface.getCoordinateAt(i, 1),1.0);
123
                gmpoly.addPolygon(poly);
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
        public void setCoordinateSystemType(int cst) {
191
                // TODO Auto-generated method stub
192
                
193
        }
194

    
195
        public Node getRenderNode() {
196
                // TODO Auto-generated method stub
197
                return null;
198
        }
199

    
200

    
201
}