Revision 708

View differences:

2.1/branches/org.gvsig.view3d_vector_and_extrusion_2.3/org.gvsig.view3d/org.gvsig.view3d/org.gvsig.view3d.lib/org.gvsig.view3d.lib.api/src/main/java/org/gvsig/view3d/lib/api/E3DElevationModes.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright © 2007-2016 gvSIG Association
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.view3d.lib.api;
26

  
27
import org.gvsig.fmap.dal.exception.ReadException;
28
import org.gvsig.fmap.geom.Geometry.TYPES;
29
import org.gvsig.fmap.geom.type.GeometryType;
30
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
31
import org.gvsig.tools.ToolsLocator;
32

  
33
import gov.nasa.worldwind.WorldWind;
34

  
35
/**
36
 * The available elevation modes that can be used for 3d.
37
 * 
38
 * @author Andrea Antonello andrea.antonello@gmail.com
39
 */
40
public enum E3DElevationModes {
41
    ABSOLUTE(ToolsLocator.getI18nManager().getTranslation("Absolute"), WorldWind.ABSOLUTE), //
42
    RELATIVE_TO_GROUND(ToolsLocator.getI18nManager().getTranslation("Relative to ground"),
43
        WorldWind.RELATIVE_TO_GROUND), //
44
    CLAMP_TO_GROUND(ToolsLocator.getI18nManager().getTranslation("Clamp to ground"), WorldWind.CLAMP_TO_GROUND), //
45
    CONSTANT(ToolsLocator.getI18nManager().getTranslation("Constant"), WorldWind.CONSTANT);//
46

  
47
    private String title;
48
    private int value;
49

  
50
    /**
51
     * 
52
     * @param title
53
     *            a title/name to be used in labels.
54
     * @param isRaster
55
     *            if <code>true</code>, the mode has to be available for
56
     *            raster data types.
57
     */
58
    private E3DElevationModes(String title, int value) {
59
        this.title = title;
60
        this.value = value;
61
    }
62

  
63
    public int getValue() {
64
        return value;
65
    }
66

  
67
    public String getTitle() {
68
        return title;
69
    }
70

  
71
    public static String[] getExtrudedModeNames(FLyrVect vectorLayer) throws ReadException {
72
        return new String[] { RELATIVE_TO_GROUND.getTitle(), ABSOLUTE.getTitle() };
73
    }
74

  
75
    public static String[] getNormalModeNames(FLyrVect vectorLayer) throws ReadException {
76
        return new String[] { CLAMP_TO_GROUND.getTitle(), ABSOLUTE.getTitle(), RELATIVE_TO_GROUND.getTitle() };
77
    }
78

  
79
    public static E3DElevationModes getModeFromValue(int value) {
80
        for (E3DElevationModes mode : values()) {
81
            if (mode.getValue() == value) {
82
                return mode;
83
            }
84
        }
85
        throw new RuntimeException("Can't understand mode: " + value);
86
    }
87

  
88
    public static E3DElevationModes getModeFromTitle(String title) {
89
        for (E3DElevationModes mode : values()) {
90
            if (mode.getTitle().equals(title)) {
91
                return mode;
92
            }
93
        }
94
        throw new RuntimeException("Can't understand mode: " + title);
95
    }
96

  
97
}
2.1/branches/org.gvsig.view3d_vector_and_extrusion_2.3/org.gvsig.view3d/org.gvsig.view3d/org.gvsig.view3d.lib/org.gvsig.view3d.lib.api/src/main/java/org/gvsig/view3d/lib/api/View3DManager.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright � 2007-2015 gvSIG Association
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.view3d.lib.api;
26

  
27
import java.util.List;
28

  
29
import org.gvsig.fmap.mapcontext.layers.FLayer;
30
import org.gvsig.view3d.lib.api.loadingmodes.NwwLoaderFactory;
31
import org.gvsig.view3d.lib.api.properties.LayerProperties3D;
32

  
33
/**
34
 * This class is responsible of the management of the application logic.
35
 * It is the library's main entry point, and provides all the
36
 * services to manage logic components.
37
 * 
38
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
39
 * @author Andrea Antonello andrea.antonello@gmail.com
40
 */
41
public interface View3DManager {
42

  
43
    /**
44
     * Gets the 3D properties of the layer
45
     * 
46
     * @param layer the layer to get the properties for.
47
     * @param loadingfactory the loading factory. If <code>null</code> and no properties
48
     *            are available from the layer, a default mode for the given 
49
     *            layer type should be used. If properties are available from the 
50
     *            layer and the loading factory is != null but different from the 
51
     *            layer's properties, a new properties object should be
52
     *            created to be compatible with the passed loadingMode. 
53
     * @return the layer properties.
54
     */
55
    public LayerProperties3D getLayerProperties(FLayer layer, NwwLoaderFactory loadingfactory);
56

  
57
    /**
58
     * Gets the 3d loading factory for the layer.
59
     * 
60
     * <p>
61
     * If none has been defined yet, the default is passed.</p>
62
     * 
63
     * @param layer the layer.
64
     * @return the loading mode.
65
     */
66
    public NwwLoaderFactory getLayerLoadingFactory(FLayer layer);
67

  
68
//    /**
69
//     * Create a new NWW layer from a gvSIG layer.
70
//     * 
71
//     * @param layer the gvSIG layer.
72
//     * @return the created NWW layer.
73
//     */
74
//    public Layer createVectorLayer(FLayer layer);
75

  
76
    /**
77
     * Sets 3D properties to the layer
78
     * 
79
     * @param layer the gvSIG layer.
80
     * @param properties the layer properties.
81
     */
82
    public void setLayerProperties(FLayer layer, LayerProperties3D properties);
83

  
84
    /**
85
     * Register a Nww vector layer loader factory.
86
     * 
87
     * @param loaderFactory the factory.
88
     */
89
    public void registerVectorLoaderFactory(NwwLoaderFactory loaderFactory);
90

  
91
    /**
92
     * Get all the registered vector loader factories.
93
     *   
94
     * @return the list of loader factories registered.
95
     */
96
    public List<NwwLoaderFactory> getVectorLoaderFactories();
97

  
98
    /**
99
     * Register a Nww raster layer loader factory.
100
     * 
101
     * @param loaderFactory the factory.
102
     */
103
    public void registerRasterLoaderFactory(NwwLoaderFactory loaderFactory);
104

  
105
    /**
106
     * Get all the registered raster loader factories.
107
     *   
108
     * @return the list of loader factories registered.
109
     */
110
    public List<NwwLoaderFactory> getRasterLoaderFactories();
111
}
2.1/branches/org.gvsig.view3d_vector_and_extrusion_2.3/org.gvsig.view3d/org.gvsig.view3d/org.gvsig.view3d.lib/org.gvsig.view3d.lib.api/src/main/java/org/gvsig/view3d/lib/api/properties/LayerProperties3D.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright © 2007-2016 gvSIG Association
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.view3d.lib.api.properties;
26

  
27
import org.gvsig.fmap.mapcontext.layers.FLayer;
28

  
29
/**
30
 * This class defines the layer 3D properties.
31
 * 
32
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
33
 * @author Andrea Antonello
34
 */
35
public interface LayerProperties3D {
36

  
37
    public static final String FLAYER = "flayer";
38

  
39
    /**
40
     * Gets the layer of these 3D properties.
41
     * 
42
     * @return the {@link FLayer}.
43
     */
44
    public FLayer getLayer();
45

  
46
    /**
47
     * Sets layer of this 3D properties.
48
     * 
49
     * @param layer
50
     */
51
    public void setLayer(FLayer layer);
52

  
53
}
2.1/branches/org.gvsig.view3d_vector_and_extrusion_2.3/org.gvsig.view3d/org.gvsig.view3d/org.gvsig.view3d.lib/org.gvsig.view3d.lib.api/src/main/java/org/gvsig/view3d/lib/api/properties/RasterizedVectorLayerProperties3D.java
1
package org.gvsig.view3d.lib.api.properties;
2

  
3
/**
4
 * This class defines the 3D properties for rasterized vector layers.
5
 * 
6
 * @author Andrea Antonello andrea.antonello@gmail.com
7
 *
8
 */
9
public interface RasterizedVectorLayerProperties3D
10
    extends RasterLayerProperties3D {
11

  
12
}
2.1/branches/org.gvsig.view3d_vector_and_extrusion_2.3/org.gvsig.view3d/org.gvsig.view3d/org.gvsig.view3d.lib/org.gvsig.view3d.lib.api/src/main/java/org/gvsig/view3d/lib/api/properties/RasterLayerProperties3D.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright © 2007-2016 gvSIG Association
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.view3d.lib.api.properties;
26

  
27
/**
28
 * This class defines the layer 3D raster properties.
29
 * 
30
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
31
 * @author Andrea Antonello andrea.antonello@gmail.com
32
 */
33
public interface RasterLayerProperties3D extends LayerProperties3D {
34

  
35
    public static final String TILE_WIDTH = "tileWidth";
36
    public static final String TILE_HEIGHT = "tileHeight";
37
    public static final String MIN_LEVEL = "minLevel";
38
    public static final String MAX_LEVEL = "maxLevel";
39
    public static final String LEVEL_ZERO_RESOLUTION_MULTIPLIER =
40
        "levelZeroResolutionMultiplier";
41

  
42
    /**
43
     * Gets the level zero resolution multiplier. The level zero resolution
44
     * multiplier indicates the relationship between resolution showed at zero
45
     * level.
46
     * 
47
     * @return
48
     */
49
    public double getLevelZeroResolutionMultiplier();
50

  
51
    /**
52
     * Sets level zero resolution multiplier.
53
     * 
54
     * @param multiplier
55
     */
56
    public void setLevelZeroResolutionMultiplier(double multiplier);
57

  
58
    /**
59
     * Gets the maximum level of deatil showed.
60
     * 
61
     * @return
62
     */
63
    public int getMaxLevel();
64

  
65
    /**
66
     * Set maximum level of detail showed.
67
     * 
68
     * @param maxLevel
69
     */
70
    public void setMaxLevel(int maxLevel);
71

  
72
    /**
73
     * Gets the minimum level of detail showed.
74
     * 
75
     * @return
76
     */
77
    public int getMinLevel();
78

  
79
    /**
80
     * Set minimum level of detail showed.
81
     * 
82
     * @param minLevel
83
     */
84
    public void setMinLevel(int minLevel);
85

  
86
    /**
87
     * Gets height of tile.
88
     * 
89
     * @return
90
     */
91
    public int getTileHeight();
92

  
93
    /**
94
     * Sets height of tile
95
     * 
96
     * @param height
97
     */
98
    public void setTileHeight(int height);
99

  
100
    /**
101
     * Gets width of tile.
102
     * 
103
     * @return
104
     */
105
    public int getTileWidth();
106

  
107
    /**
108
     * Sets width of tile
109
     * 
110
     * @param width
111
     */
112
    public void setTileWidth(int width);
113

  
114
}
2.1/branches/org.gvsig.view3d_vector_and_extrusion_2.3/org.gvsig.view3d/org.gvsig.view3d/org.gvsig.view3d.lib/org.gvsig.view3d.lib.api/src/main/java/org/gvsig/view3d/lib/api/properties/VectorLayerProperties3D.java
1
package org.gvsig.view3d.lib.api.properties;
2

  
3
import java.awt.Color;
4

  
5
/**
6
 * This class defines the 3D properties for vector layers.s
7
 * 
8
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
9
 * @author Andrea Antonello andrea.antonello@gmail.com
10
 */
11
public interface VectorLayerProperties3D extends LayerProperties3D {
12

  
13
    public static final String DEFAULT_COLOR = "defaultColor";
14
    public static final String ELEVATION_MODE = "elevationMode";
15
    public static final String CONSTANT_HEIGHT = "constantHeight";
16

  
17
    /**
18
     * The elevation mode to use.
19
     * 
20
     * <p>
21
     * Supported modes are:
22
     * <ul>
23
     * <li>gov.nasa.worldwind.WorldWind.ABSOLUTE: if the layer has 3d
24
     * coordinates,
25
     * the coordinates are used to define the absolute elevation of
26
     * the polygon's base vertexes.</li>
27
     * <li>gov.nasa.worldwind.WorldWind.CLAMP_TO_GROUND</li>
28
     * <li>gov.nasa.worldwind.WorldWind.RELATIVE_TO_GROUND: if the layer has 3d
29
     * coordinates,
30
     * the coordinates are used as if they were heights relative to the ground.
31
     * </li>
32
     * </ul>
33
     * 
34
     * @return the elevation mode.
35
     */
36
    public int getElevationMode();
37

  
38
    /**
39
     * Set the elevationMode to use.
40
     * 
41
     * @param elevationMode
42
     * @see #getElevationMode()
43
     */
44
    public void setElevationMode(int elevationMode);
45

  
46
    /**
47
     * Getter for the default color, which is used if the style
48
     * can't be taken from the layer's legend.
49
     * 
50
     * @return the default color to use.
51
     */
52
    public Color getDefaultColor();
53

  
54
    /**
55
     * Setter for the default color for the style..
56
     * 
57
     * @param defaultColor
58
     *            the default color to use.
59
     */
60
    public void setDefaultColor(Color defaultColor);
61

  
62
    /**
63
     * Getter for the value of constant height to use either for offset or extrusion
64
     * depending of the type of loading mode.
65
     * 
66
     * <p>
67
     * This is set as a Double object, so that it can also be <code>null</code>.
68
     * if it is null, no constant value is used.
69
     * 
70
     * @return the constant height to use or <code>null</code>.
71
     */
72
    public Double getConstantHeight();
73

  
74
    /**
75
     * Setter for the constant height to use  for offset or extrusion
76
     * depending of the type of loading mode.
77
     * 
78
     * @param constantHeight
79
     *            the constant height to use.
80
     */
81
    public void setConstantHeight(Double constantHeight);
82

  
83
}
2.1/branches/org.gvsig.view3d_vector_and_extrusion_2.3/org.gvsig.view3d/org.gvsig.view3d/org.gvsig.view3d.lib/org.gvsig.view3d.lib.api/src/main/java/org/gvsig/view3d/lib/api/properties/ElevationLayerProperties3D.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright © 2007-2016 gvSIG Association
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.view3d.lib.api.properties;
25

  
26
/**
27
 * Interface that defines 3D elevation raster layer properties.
28
 * 
29
 * @author Andrea Antonello    andrea.antonello@gmail.com
30
 *
31
 */
32
public interface ElevationLayerProperties3D extends RasterLayerProperties3D {
33
    public static final String NO_DATA_VALUE = "noDataValue";
34
    public static final String ELEVATION_UNITS = "elevationUnits";
35

  
36
    /**
37
     * Getter for the nodata value.
38
     * 
39
     * @return the value for nodata.
40
     */
41
    public double getNoDataValue();
42

  
43
    /**
44
     * Setter for nodata values.
45
     * 
46
     * @param noDataValue
47
     *            the nodata value to set.
48
     */
49
    public void setNoDataValue(double noDataValue);
50
    
51
    /**
52
     * Getter for the elevation units.
53
     * 
54
     * @return
55
     */
56
    public String getElevationUnits();
57
    
58
    /**
59
     * Setter for the elevation units.
60
     * 
61
     * @param elevationUnits
62
     */
63
    public void setElevationUnits(String elevationUnits);
64
    
65

  
66

  
67

  
68
}
2.1/branches/org.gvsig.view3d_vector_and_extrusion_2.3/org.gvsig.view3d/org.gvsig.view3d/org.gvsig.view3d.lib/org.gvsig.view3d.lib.api/src/main/java/org/gvsig/view3d/lib/api/properties/ExtrudedVectorLayerProperties3D.java
1
package org.gvsig.view3d.lib.api.properties;
2

  
3
/**
4
 * This class defines the 3D properties for extruded vector layers.
5
 * 
6
 * @author Andrea Antonello andrea.antonello@gmail.com
7
 */
8
public interface ExtrudedVectorLayerProperties3D
9
    extends VectorLayerProperties3D {
10

  
11
    public static final String EXTRUSION_HEIGHT_FIELD = "extrusionHeightField";
12
    public static final String VERTICAL_EXAGGERATION = "verticalExaggeration";
13

  
14
    /**
15
     * Gets the field name that defines the extrusion height values.
16
     * 
17
     * @return the name of the extrusion height field.
18
     */
19
    public String getExtrusionHeightField();
20

  
21
    /**
22
     * Sets the field name that defines the extrusion height values.
23
     * 
24
     * @param field
25
     *            the name of the extrusion height field.
26
     */
27
    public void setExtrusionHeightField(String field);
28

  
29
    /**
30
     * Getter for the vertical exaggeration, which defaults to 1.0.
31
     * 
32
     * <p>
33
     * This value is used to multiply the value contained in the
34
     * extrusion height field. That way it is for example possible to
35
     * define in the attributes table as extruded height the number
36
     * of floors of the building and use a vertical exaggeration of
37
     * 3.0 meters to get the desired result.
38
     * 
39
     * @return the vertical exageration.
40
     */
41
    public double getVerticalExaggeration();
42

  
43
    /**
44
     * Setter for the vertical exaggeration.
45
     * 
46
     * @param verticalExaggeration
47
     *            the value to set.
48
     */
49
    public void setVerticalExaggeration(double verticalExaggeration);
50

  
51
}
2.1/branches/org.gvsig.view3d_vector_and_extrusion_2.3/org.gvsig.view3d/org.gvsig.view3d/org.gvsig.view3d.lib/org.gvsig.view3d.lib.api/src/main/java/org/gvsig/view3d/lib/api/properties/E3DLayerLoadingModes.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright © 2007-2016 gvSIG Association
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.view3d.lib.api.properties;
26

  
27
import org.gvsig.tools.ToolsLocator;
28

  
29
/**
30
 * The available types of layer loading in 3d.
31
 * 
32
 * @author Andrea Antonello andrea.antonello@gmail.com
33
 */
34
public enum E3DLayerLoadingModes {
35
    RASTER_IMAGE(ToolsLocator.getI18nManager().getTranslation("Raster image"), true), //
36
    ELEVATION(ToolsLocator.getI18nManager().getTranslation("Elevation"), true), //
37
    RASTERIZED_VECTOR(ToolsLocator.getI18nManager().getTranslation("Rasterized vector"), false), //
38
    VECTOR(ToolsLocator.getI18nManager().getTranslation("Vector"), false), //
39
    EXTRUDED_VECTOR(ToolsLocator.getI18nManager().getTranslation("Extruded vector"), false);
40

  
41
    /**
42
     * Name of gvSIG Layer property
43
     */
44
    public static final String GVSIG_LAYER = "org.gvsig.fmap.mapcontext.layers.FLayer";
45

  
46
    private boolean isRaster;
47
    private String title;
48

  
49
    /**
50
     * 
51
     * @param title
52
     *            a title/name to be used in labels.
53
     * @param isRaster
54
     *            if <code>true</code>, the mode has to be available for
55
     *            raster data types.
56
     */
57
    private E3DLayerLoadingModes(String title, boolean isRaster) {
58
        this.title = title;
59
        this.isRaster = isRaster;
60
    }
61

  
62
    public boolean isRaster() {
63
        return isRaster;
64
    }
65

  
66
    public String getTitle() {
67
        return title;
68
    }
69

  
70
    public static String[] getRasterLoadingModeNames() {
71
        return new String[] { RASTER_IMAGE.getTitle(), ELEVATION.getTitle() };
72
    }
73

  
74
    public static String[] getVectorLoadingModeNames() {
75
        return new String[] { RASTERIZED_VECTOR.getTitle(), VECTOR.getTitle(), EXTRUDED_VECTOR.getTitle() };
76
    }
77

  
78
    public static E3DLayerLoadingModes getModeFromTitle(String loadingMode) {
79
        for (E3DLayerLoadingModes mode : values()) {
80
            if (mode.getTitle().equals(loadingMode)) {
81
                return mode;
82
            }
83
        }
84
        throw new RuntimeException("Can't understand mode: " + loadingMode);
85
    }
86

  
87
}
2.1/branches/org.gvsig.view3d_vector_and_extrusion_2.3/org.gvsig.view3d/org.gvsig.view3d/org.gvsig.view3d.lib/org.gvsig.view3d.lib.api/src/main/java/org/gvsig/view3d/lib/api/layers/NwwVectorLayer.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright © 2007-2016 gvSIG Association
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.view3d.lib.api.layers;
26

  
27
import java.awt.Color;
28

  
29
import org.cresques.cts.IProjection;
30
import org.gvsig.fmap.crs.CRSFactory;
31

  
32
import gov.nasa.worldwind.layers.RenderableLayer;
33

  
34
/**
35
 * Abstract class for nww vector layers that are {@link RenderableLayer}s. 
36
 * 
37
 * @author Andrea Antonello    andrea.antonello@gmail.com
38
 */
39
public abstract class NwwVectorLayer extends RenderableLayer {
40

  
41
    private IProjection nwwPrj;
42

  
43
    public abstract void updateLegend( );
44

  
45
    /**
46
     * Get the projection for NWW.
47
     * 
48
     * @return the NWW prj.
49
     */
50
    public IProjection getNwwPrj() {
51
        if (nwwPrj == null)
52
            nwwPrj = CRSFactory.getCRS("EPSG:4326");
53
        return nwwPrj;
54
    }
55

  
56
    /**
57
     * Slightly darken the supplied color.
58
     * 
59
     * @param color the color to make darker.
60
     * @return the darker color.
61
     */
62
    protected Color darkenColor( Color color ) {
63
        float factor = 0.8f;
64
        int r = color.getRed();
65
        int g = color.getGreen();
66
        int b = color.getBlue();
67

  
68
        Color sideFillColor = new Color(Math.max((int) (r * factor), 0), Math.max((int) (g * factor), 0),
69
                Math.max((int) (b * factor), 0));
70
        return sideFillColor;
71
    }
72
}
2.1/branches/org.gvsig.view3d_vector_and_extrusion_2.3/org.gvsig.view3d/org.gvsig.view3d/org.gvsig.view3d.lib/org.gvsig.view3d.lib.api/src/main/java/org/gvsig/view3d/lib/api/layers/LayerLegendListener.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright © 2007-2016 gvSIG Association
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.view3d.lib.api.layers;
26

  
27
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
28
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendChangedEvent;
29
import org.gvsig.fmap.mapcontext.rendering.legend.events.listeners.LegendListener;
30

  
31
/**
32
 * Listener for changes in the style of a vector layer.
33
 * 
34
 * @author Andrea Antonello (www.hydrologis.com)
35
 */
36
public abstract class LayerLegendListener implements LegendListener {
37

  
38
    protected FLyrVect mVectorLayer;
39

  
40
    public LayerLegendListener(FLyrVect vectorLayer) {
41
        mVectorLayer = vectorLayer;
42
    }
43

  
44
    public abstract void legendChanged(LegendChangedEvent e);
45

  
46
}
2.1/branches/org.gvsig.view3d_vector_and_extrusion_2.3/org.gvsig.view3d/org.gvsig.view3d/org.gvsig.view3d.lib/org.gvsig.view3d.lib.api/src/main/java/org/gvsig/view3d/lib/api/View3DLocator.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright � 2007-2015 gvSIG Association
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.view3d.lib.api;
26

  
27
import org.gvsig.tools.locator.BaseLocator;
28
import org.gvsig.tools.locator.LocatorException;
29

  
30

  
31
/**
32
 * This locator is the entry point for the View 3D library, providing
33
 * access to View3D services through the {@link View3DManager} .
34
 *
35
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
36
 * @version $Id$
37
 */
38
public class View3DLocator extends BaseLocator {
39

  
40
    private static final String LOCATOR_NAME = "View3DLocator";
41

  
42
    public static final String MANAGER_NAME = "View3D.Manager";
43

  
44
    private static final String MANAGER_DESCRIPTION = "View 3D Manager";
45

  
46
    private static final View3DLocator instance = new View3DLocator();
47

  
48
    /**
49
     * Return the singleton instance.
50
     * 
51
     * @return the singleton instance
52
     */
53
    public static View3DLocator getInstance() {
54
        return instance;
55
    }
56

  
57
    public String getLocatorName() {
58
        return LOCATOR_NAME;
59
    }
60

  
61
    /**
62
     * Return a reference to View3DManager.
63
     * 
64
     * @return a reference to View3DManager
65
     * @throws LocatorException
66
     *             if there is no access to the class or the class
67
     *             cannot be instantiated
68
     * @see Locator#get(String)View3DManager
69
     */
70
    public static View3DManager getManager() throws LocatorException {
71
        return (View3DManager) getInstance().get(MANAGER_NAME);
72
    }
73

  
74
    /**
75
     * Registers the Class implementing the View3DLocator interface.
76
     * 
77
     * @param clazz
78
     *            implementing the View3DManager interface
79
     */
80
    public static void registerManager(Class<?> clazz) {
81
        getInstance().register(MANAGER_NAME, MANAGER_DESCRIPTION, clazz);
82
    }
83

  
84
    public static void registerDefaultManager(Class<?> clazz) {
85
        getInstance().registerDefault(MANAGER_NAME, MANAGER_DESCRIPTION, clazz);
86
    }
87
}
2.1/branches/org.gvsig.view3d_vector_and_extrusion_2.3/org.gvsig.view3d/org.gvsig.view3d/org.gvsig.view3d.lib/org.gvsig.view3d.lib.api/src/main/java/org/gvsig/view3d/lib/api/loadingmodes/NwwLoaderFactory.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright © 2007-2016 gvSIG Association
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.view3d.lib.api.loadingmodes;
26

  
27
import org.gvsig.view3d.lib.api.properties.LayerProperties3D;
28

  
29
import gov.nasa.worldwind.layers.Layer;
30

  
31
/**
32
 * A factory interface for loading modes.
33
 * 
34
 * @author Andrea Antonello    andrea.antonello@gmail.com
35
 */
36
public interface NwwLoaderFactory {
37

  
38
    /**
39
     * Creates the layer properties for this loading type.
40
     * 
41
     * @return the layer properties.
42
     */
43
    LayerProperties3D createProperties();
44

  
45
    /**
46
     * Creates a NWW layers loader for this loading type. 
47
     * 
48
     * @return the loader.
49
     */
50
    Layer loadLayer(LayerProperties3D properties);
51

  
52
    /**
53
     * Getter for the name of this loading mode.
54
     * 
55
     * @return the name of this loading mode.
56
     */
57
    String getName();
58
}
2.1/branches/org.gvsig.view3d_vector_and_extrusion_2.3/org.gvsig.view3d/org.gvsig.view3d/org.gvsig.view3d.lib/org.gvsig.view3d.lib.api/src/main/java/org/gvsig/view3d/lib/api/loadingmodes/NwwVectorLoaderFactory.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright © 2007-2016 gvSIG Association
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.view3d.lib.api.loadingmodes;
26

  
27
/**
28
 * A factory interface for loading modes.
29
 * 
30
 * @author Andrea Antonello    andrea.antonello@gmail.com
31
 */
32
public interface NwwVectorLoaderFactory extends NwwLoaderFactory {
33

  
34
}
2.1/branches/org.gvsig.view3d_vector_and_extrusion_2.3/org.gvsig.view3d/org.gvsig.view3d/org.gvsig.view3d.lib/org.gvsig.view3d.lib.api/src/main/java/org/gvsig/view3d/lib/api/View3DLibrary.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright © 2007-2016 gvSIG Association
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.view3d.lib.api;
25

  
26
import org.gvsig.fmap.dal.DALLibrary;
27
import org.gvsig.tools.library.AbstractLibrary;
28
import org.gvsig.tools.library.LibraryException;
29
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
30

  
31

  
32
/**
33
 * Library for API initialization and configuration.
34
 * 
35
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
36
 */
37
public class View3DLibrary extends AbstractLibrary {
38
    
39
    @Override
40
    public void doRegistration() {
41
        registerAsAPI(View3DLibrary.class);
42
        require(DALLibrary.class);
43
    }
44

  
45
    @Override
46
    protected void doInitialize() throws LibraryException {
47
    }
48

  
49
    @Override
50
    protected void doPostInitialize() throws LibraryException {
51
        View3DManager manager = View3DLocator.getManager();
52
        if (manager == null) {
53
            throw new ReferenceNotRegisteredException(
54
                View3DLocator.MANAGER_NAME, View3DLocator.getInstance());
55
        }
56

  
57
    }
58

  
59
}
2.1/branches/org.gvsig.view3d_vector_and_extrusion_2.3/org.gvsig.view3d/org.gvsig.view3d/org.gvsig.view3d.lib/org.gvsig.view3d.lib.api/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.view3d.lib.api.View3DLibrary
2.1/branches/org.gvsig.view3d_vector_and_extrusion_2.3/org.gvsig.view3d/org.gvsig.view3d/org.gvsig.view3d.lib/org.gvsig.view3d.lib.api/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3
	<modelVersion>4.0.0</modelVersion>
4
	<parent>
5
		<groupId>org.gvsig</groupId>
6
		<artifactId>org.gvsig.view3d.lib</artifactId>
7
		<version>1.0.15-SNAPSHOT</version>
8
	</parent>
9
	<artifactId>org.gvsig.view3d.lib.api</artifactId>
10
	<name>org.gvsig.view3d.lib.api</name>
11
	<dependencies>
12
		<dependency>
13
			<groupId>org.gvsig</groupId>
14
			<artifactId>org.gvsig.tools.lib</artifactId>
15
		</dependency>
16
		<dependency>
17
			<groupId>org.gvsig</groupId>
18
			<artifactId>org.gvsig.fmap.mapcontext.api</artifactId>
19
		</dependency>
20
		<dependency>
21
			<groupId>gov.nasa</groupId>
22
			<artifactId>worldwind</artifactId>
23
		</dependency>
24
		<dependency>
25
			<groupId>gov.nasa</groupId>
26
			<artifactId>worldwindx</artifactId>
27
			<version>2.0.0</version>
28
		</dependency>
29
	</dependencies>
30
</project>
2.1/branches/org.gvsig.view3d_vector_and_extrusion_2.3/org.gvsig.view3d/org.gvsig.view3d/org.gvsig.view3d.lib/org.gvsig.view3d.lib.impl/src/main/java/org/gvsig/view3d/lib/impl/DefaultView3DLibrary.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright � 2007-2015 gvSIG Association
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.view3d.lib.impl;
26

  
27
import org.gvsig.fmap.dal.DALLibrary;
28
import org.gvsig.tools.ToolsLocator;
29
import org.gvsig.tools.library.AbstractLibrary;
30
import org.gvsig.tools.library.LibraryException;
31
import org.gvsig.tools.persistence.PersistenceManager;
32
import org.gvsig.view3d.lib.api.View3DLibrary;
33
import org.gvsig.view3d.lib.api.View3DLocator;
34
import org.gvsig.view3d.lib.api.View3DManager;
35
import org.gvsig.view3d.lib.impl.layers.loaders.ExtrudedVectorLayerLoaderFactory;
36
import org.gvsig.view3d.lib.impl.layers.loaders.VectorLayerLoaderFactory;
37
import org.gvsig.view3d.lib.impl.layers.persistence.ElevationLayerProperties3DPersistenceFactory;
38
import org.gvsig.view3d.lib.impl.layers.persistence.ExtrudedVectorLayerProperties3DPersistenceFactory;
39
import org.gvsig.view3d.lib.impl.layers.persistence.LayerProperties3DPersistenceFactory;
40
import org.gvsig.view3d.lib.impl.layers.persistence.RasterLayerProperties3DPersistenceFactory;
41
import org.gvsig.view3d.lib.impl.layers.persistence.RasterizedVectorLayerProperties3DPersistenceFactory;
42
import org.gvsig.view3d.lib.impl.layers.persistence.VectorLayerProperties3DPersistenceFactory;
43

  
44
/**
45
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
46
 * @author Andrea Antonello andrea.antonello@gmail.com
47
 *
48
 */
49
public class DefaultView3DLibrary extends AbstractLibrary {
50

  
51
    @Override
52
    public void doRegistration() {
53
        registerAsImplementationOf(View3DLibrary.class);
54
        require(DALLibrary.class);
55
    }
56

  
57
    @Override
58
    protected void doInitialize() throws LibraryException {
59
        View3DLocator.registerManager(DefaultView3DManger.class);
60

  
61
        // Register persistence
62
        registerPersistence();
63

  
64
        // register default loading modes
65
        View3DManager manager = View3DLocator.getManager();
66
        manager.registerVectorLoaderFactory(new VectorLayerLoaderFactory());
67
        manager.registerVectorLoaderFactory(new ExtrudedVectorLayerLoaderFactory());
68
    }
69

  
70
    private void registerPersistence() {
71
        PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager();
72
        persistenceManager.registerFactory(new LayerProperties3DPersistenceFactory());
73

  
74
        persistenceManager.registerFactory(new VectorLayerProperties3DPersistenceFactory());
75
        persistenceManager.registerFactory(new ExtrudedVectorLayerProperties3DPersistenceFactory());
76

  
77
        persistenceManager.registerFactory(new RasterLayerProperties3DPersistenceFactory());
78
        persistenceManager.registerFactory(new ElevationLayerProperties3DPersistenceFactory());
79
        persistenceManager.registerFactory(new RasterizedVectorLayerProperties3DPersistenceFactory());
80
    }
81

  
82
    @Override
83
    protected void doPostInitialize() throws LibraryException {
84
    }
85

  
86
}
2.1/branches/org.gvsig.view3d_vector_and_extrusion_2.3/org.gvsig.view3d/org.gvsig.view3d/org.gvsig.view3d.lib/org.gvsig.view3d.lib.impl/src/main/java/org/gvsig/view3d/lib/impl/layers/vector/DefaultLineLayer.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright © 2007-2016 gvSIG Association
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.view3d.lib.impl.layers.vector;
26

  
27
import java.awt.Color;
28
import java.util.ArrayList;
29
import java.util.List;
30

  
31
import org.cresques.cts.ICoordTrans;
32
import org.cresques.cts.IProjection;
33
import org.slf4j.Logger;
34
import org.slf4j.LoggerFactory;
35

  
36
import org.gvsig.fmap.dal.DataStore;
37
import org.gvsig.fmap.dal.exception.DataException;
38
import org.gvsig.fmap.dal.feature.Feature;
39
import org.gvsig.fmap.dal.feature.FeatureSet;
40
import org.gvsig.fmap.dal.feature.FeatureStore;
41
import org.gvsig.fmap.geom.Geometry;
42
import org.gvsig.fmap.geom.aggregate.MultiCurve;
43
import org.gvsig.fmap.geom.primitive.Curve;
44
import org.gvsig.fmap.geom.primitive.Point;
45
import org.gvsig.fmap.mapcontext.layers.FLayer;
46
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
47
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
48
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
49
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
50
import org.gvsig.tools.dispose.DisposableIterator;
51
import org.gvsig.tools.dispose.DisposeUtils;
52
import org.gvsig.view3d.lib.api.E3DElevationModes;
53
import org.gvsig.view3d.lib.api.View3DLocator;
54
import org.gvsig.view3d.lib.api.View3DManager;
55
import org.gvsig.view3d.lib.api.layers.NwwVectorLayer;
56
import org.gvsig.view3d.lib.api.properties.E3DLayerLoadingModes;
57
import org.gvsig.view3d.lib.api.properties.ExtrudedVectorLayerProperties3D;
58
import org.gvsig.view3d.lib.api.properties.LayerProperties3D;
59
import org.gvsig.view3d.lib.api.properties.VectorLayerProperties3D;
60

  
61
import gov.nasa.worldwind.avlist.AVKey;
62
import gov.nasa.worldwind.avlist.AVList;
63
import gov.nasa.worldwind.geom.Position;
64
import gov.nasa.worldwind.render.BasicShapeAttributes;
65
import gov.nasa.worldwind.render.Material;
66
import gov.nasa.worldwind.render.Path;
67
import gov.nasa.worldwind.render.Renderable;
68
import gov.nasa.worldwind.util.WWUtil;
69

  
70
/**
71
 * A default vector lines layer created from a gvisg layer.
72
 * 
73
 * <p>Extruded Lines, i.e. NWW Path with setExtrude, behave much like the  
74
 * Extruded Polygons. See the javadoc in {@link DefaultPolygonLayer}.
75
 * 
76
 * @author Andrea Antonello andrea.antonello@gmail.com
77
 */
78
public class DefaultLineLayer extends NwwVectorLayer {
79

  
80
    private static final Logger LOG = LoggerFactory.getLogger(DefaultLineLayer.class);
81

  
82
    private FLyrVect vectorLayer;
83

  
84
    private BasicShapeAttributes normalShapeAttributes;
85

  
86
    private LayerProperties3D mLayerProperties;
87

  
88
    private String heightFieldName;
89
    private double verticalExageration = 1.0;
90
    private double constantHeight = 1.0;
91
    private boolean hasConstantHeight = false;
92
    private boolean applyExtrusion = false;
93

  
94
    private Material outlineMaterial = Material.BLACK;
95
    private double outlineOpacity = 1.0;
96
    private double outlineWidth = 3.0;
97

  
98
    private E3DElevationModes elevationMode = E3DElevationModes.RELATIVE_TO_GROUND;
99

  
100
    private Color defaultColor = Color.RED;
101

  
102
    private ICoordTrans data2NwwCT;
103

  
104
    public DefaultLineLayer( AVList params ) {
105
        params = params != null ? params : (AVList) this.getValue(AVKey.CONSTRUCTION_PARAMETERS);
106
        if (params == null) {
107
            LOG.error("Can not load data, no parameters supplied");
108
            throw new IllegalArgumentException();
109
        }
110

  
111
        if (this.getValue(AVKey.CONSTRUCTION_PARAMETERS) == null) {
112
            this.setValue(AVKey.CONSTRUCTION_PARAMETERS, params.copy());
113
            params = (AVList) this.getValue(AVKey.CONSTRUCTION_PARAMETERS);
114
        }
115

  
116
        String datasetName = params.getStringValue(AVKey.DATASET_NAME);
117
        if (WWUtil.isEmpty(datasetName)) {
118
            LOG.error("Can not load vector data, missing required parameter: {}", AVKey.DATASET_NAME);
119
            throw new IllegalArgumentException();
120
        }
121

  
122
        FLayer layer = (FLayer) params.getValue(E3DLayerLoadingModes.GVSIG_LAYER);
123
        if (layer instanceof FLyrVect) {
124
            vectorLayer = (FLyrVect) layer;
125
            IProjection sourcePrj = vectorLayer.getProjection();
126
            if (!sourcePrj.equals(getNwwPrj())) {
127
                data2NwwCT = sourcePrj.getCT(getNwwPrj());
128
            }
129
        } else {
130
            LOG.error("Can not load vector data, missing layer or invalid layer type.");
131
            throw new IllegalArgumentException();
132
        }
133

  
134
        View3DManager manager = View3DLocator.getManager();
135
        mLayerProperties = manager.getLayerProperties(layer, null);
136

  
137
        if (mLayerProperties instanceof VectorLayerProperties3D) {
138
            VectorLayerProperties3D properties = (VectorLayerProperties3D) mLayerProperties;
139
            defaultColor = properties.getDefaultColor();
140

  
141
            elevationMode = E3DElevationModes.getModeFromValue(properties.getElevationMode());
142

  
143
            Double constantExtrusionHeight = properties.getConstantHeight();
144
            if (constantExtrusionHeight != null) {
145
                // apply constant height
146
                hasConstantHeight = true;
147
                constantHeight = constantExtrusionHeight;
148
            }
149
        }
150
        if (mLayerProperties instanceof ExtrudedVectorLayerProperties3D) {
151
            ExtrudedVectorLayerProperties3D properties = (ExtrudedVectorLayerProperties3D) mLayerProperties;
152
            heightFieldName = properties.getExtrusionHeightField();
153
            applyExtrusion = true;
154
            if (heightFieldName != null) {
155
                verticalExageration = properties.getVerticalExaggeration();
156
            }
157
        }
158

  
159
        updateLegend();
160

  
161
        try {
162
            Thread t = new WorkerThread();
163
            t.start();
164
        } catch (Exception e) {
165
            LOG.error("Error loading the data...", e);
166
        }
167
    }
168

  
169
    public class WorkerThread extends Thread {
170

  
171
        public void run() {
172
            addLinesTorender();
173
        }
174
    }
175

  
176
    private void addLinesTorender() {
177
        try {
178
            ArrayList<Renderable> renderablesList = new ArrayList<>();
179
            FeatureStore linesStore = vectorLayer.getFeatureStore();
180
            FeatureSet linesSet = null;
181
            DisposableIterator linesIterator = null;
182
            try {
183
                linesSet = linesStore.getFeatureSet();
184
                linesIterator = linesSet.fastIterator();
185
                while( linesIterator.hasNext() ) {
186
                    Feature lineFeature;
187
                    synchronized (linesStore) {
188
                        lineFeature = (Feature) linesIterator.next();
189
                    }
190
                    makeShape(renderablesList, lineFeature);
191
                }
192
            } finally {
193
                DisposeUtils.dispose(linesIterator);
194
                DisposeUtils.dispose(linesSet);
195
            }
196
            setRenderables(renderablesList);
197
        } catch (DataException e) {
198
            LOG.error("Can not load vector data, missing layer or invalid layer type.");
199
            e.printStackTrace();
200
        }
201
    }
202

  
203
    private void makeShape( ArrayList<Renderable> renderablesList, Feature lineFeature ) {
204
        Geometry geometry = lineFeature.getDefaultGeometry().cloneGeometry();
205
        geometry.reProject(data2NwwCT);
206
        if (geometry instanceof Curve) {
207
            Curve curve = (Curve) geometry;
208
            addLine(renderablesList, lineFeature, curve);
209
        } else if (geometry instanceof MultiCurve) {
210
            MultiCurve multiCurve = (MultiCurve) geometry;
211
            int linesCount = multiCurve.getPrimitivesNumber();
212
            for( int i = 0; i < linesCount; i++ ) {
213
                Curve curve = multiCurve.getCurveAt(i);
214
                addLine(renderablesList, lineFeature, curve);
215
            }
216
        }
217
    }
218

  
219
    private void addLine( ArrayList<Renderable> renderablesList, Feature lineFeature, Curve curve ) {
220
        int numVertices = curve.getNumVertices();
221
        if (numVertices < 2)
222
            return;
223

  
224
        boolean hasZ = curve.getDimension() > 2;
225

  
226
        double h = 0.0;
227
        switch( elevationMode ) {
228
        case CLAMP_TO_GROUND:
229
            hasZ = false;
230
            break;
231
        case RELATIVE_TO_GROUND:
232
            /*
233
             * we ignore the 3rd coordinate in that case and continue.
234
             * The altitude mode will the handle the passed values
235
             * properly as absolute or relative. 
236
             */
237
            hasZ = false;
238
        case ABSOLUTE:
239
        default:
240
            if (hasConstantHeight) {
241
                h = constantHeight;
242
            }
243
            if (heightFieldName != null) {
244
                double tmpH = lineFeature.getDouble(heightFieldName);
245
                h += tmpH;
246
            }
247
            break;
248
        }
249
        h *= verticalExageration;
250

  
251
        List<Position> verticesList = new ArrayList<>(numVertices);
252
        for( int i = 0; i < numVertices; i++ ) {
253
            Point vertex = curve.getVertex(i);
254
            if (hasZ) {
255
                double z = vertex.getCoordinateAt(2);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff