gvsig-3d / 2.1 / trunk / org.gvsig.gvsig3d / org.gvsig.gvsig3d.lib / org.gvsig.gvsig3d.lib.impl / src / main / java / org / gvsig / gvsig3d / impl / layers / FLayers3DImpl.java @ 385
History | View | Annotate | Download (4.96 KB)
1 |
/* gvSIG 3D extension for gvSIG
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2012 Prodevelop.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Prodevelop, S.L.
|
22 |
* Pza. Don Juan de Villarrasa, 14 - 5
|
23 |
* 46001 Valencia
|
24 |
* Spain
|
25 |
*
|
26 |
* +34 963 510 612
|
27 |
* +34 963 510 968
|
28 |
* prode@prodevelop.es
|
29 |
* http://www.prodevelop.es
|
30 |
*/
|
31 |
/*
|
32 |
* AUTHORS:
|
33 |
* 2012 AI2 - Instituto Universitario de Automatica e Informatica Industrial.
|
34 |
* Universitat Politecnica de Valencia (UPV)
|
35 |
* http://www.ai2.upv.es
|
36 |
*/
|
37 |
|
38 |
|
39 |
package org.gvsig.gvsig3d.impl.layers; |
40 |
|
41 |
import org.gvsig.fmap.mapcontext.MapContext; |
42 |
import org.gvsig.fmap.mapcontext.ViewPort; |
43 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
44 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
45 |
import org.gvsig.fmap.mapcontext.layers.FLyrDefault; |
46 |
import org.gvsig.fmap.mapcontext.layers.LayerCollectionEvent; |
47 |
import org.gvsig.fmap.mapcontext.layers.LayerPositionEvent; |
48 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
49 |
import org.gvsig.gvsig3d.Gvsig3DException; |
50 |
import org.gvsig.gvsig3d.Gvsig3DLocator; |
51 |
import org.gvsig.gvsig3d.Gvsig3DManager; |
52 |
import org.gvsig.gvsig3d.impl.map3d.Layer3DPropsImpl; |
53 |
import org.gvsig.gvsig3d.map3d.Layer3DProps; |
54 |
import org.gvsig.gvsig3d.map3d.MapContext3D; |
55 |
import org.gvsig.gvsig3d.map3d.layers.FLayers3D; |
56 |
import org.gvsig.tools.ToolsLocator; |
57 |
import org.gvsig.tools.dynobject.DynStruct; |
58 |
import org.gvsig.tools.persistence.PersistenceManager; |
59 |
import org.gvsig.tools.persistence.Persistent; |
60 |
import org.gvsig.tools.persistence.PersistentState; |
61 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
62 |
import org.gvsig.tools.util.Callable; |
63 |
|
64 |
/**
|
65 |
* @author Jesus Zarzoso- jzarzoso@ai2.upv.es
|
66 |
* @version $Id$
|
67 |
*
|
68 |
*/
|
69 |
public class FLayers3DImpl extends FLayers3D { |
70 |
|
71 |
public static final String PARAMETERS_DEFINITION_NAME = "FLayers3DImpl"; |
72 |
|
73 |
public FLayers3DImpl() {
|
74 |
|
75 |
super();
|
76 |
|
77 |
} |
78 |
|
79 |
/**
|
80 |
* Constructor that can be used to create a MapContext containing the
|
81 |
* FLayers3D
|
82 |
*
|
83 |
* @param fmap
|
84 |
* MapContext (can be null)
|
85 |
* @param parent
|
86 |
* FLayers (can be null)
|
87 |
*/
|
88 |
public FLayers3DImpl(MapContext fmap, FLayers parent, ViewPort vp) {
|
89 |
|
90 |
super();
|
91 |
this.setMapContext(fmap);
|
92 |
this.setParentLayer(parent);
|
93 |
|
94 |
Gvsig3DManager manager = Gvsig3DLocator.getManager(); |
95 |
// add 3D properties, mainly to keep track of hooked state
|
96 |
Layer3DProps props3D; |
97 |
try {
|
98 |
props3D = manager.createDefaultLayer3DPropsInstance(this);
|
99 |
props3D.setLayer(this);
|
100 |
setProperty("3DLayerExtension", props3D);
|
101 |
|
102 |
if (fmap == null) { |
103 |
MapContext newMap = manager.createDefaultMapContext3DInstance( |
104 |
this, vp);
|
105 |
this.fmap = newMap;
|
106 |
props3D.setHooked(true);
|
107 |
} else {
|
108 |
fmap.setViewPort(vp); |
109 |
} |
110 |
} catch (Gvsig3DException e) {
|
111 |
// TODO Auto-generated catch block
|
112 |
e.printStackTrace(); |
113 |
} |
114 |
|
115 |
} |
116 |
|
117 |
// overrides for layer collection events
|
118 |
|
119 |
@Override
|
120 |
public void addLayer(FLayer layer) { |
121 |
super.addLayer(layer);
|
122 |
} |
123 |
|
124 |
protected void callLayerAdded(LayerCollectionEvent event) { |
125 |
if (isHooked()) {
|
126 |
FLayer layer = event.getAffectedLayer(); |
127 |
((MapContext3D) fmap).layerAdded(this, layer);
|
128 |
} |
129 |
super.callLayerAdded(event);
|
130 |
} |
131 |
|
132 |
protected void callLayerRemoved(LayerCollectionEvent event) { |
133 |
if (isHooked()) {
|
134 |
FLayer layer = event.getAffectedLayer(); |
135 |
((MapContext3D) fmap).layerRemoved(this, layer);
|
136 |
} |
137 |
super.callLayerRemoved(event);
|
138 |
} |
139 |
|
140 |
protected void callLayerMoved(LayerPositionEvent event) { |
141 |
super.callLayerMoved(event);
|
142 |
if (isHooked())
|
143 |
((MapContext3D) fmap).layerMoved(this, event.getAffectedLayer(),
|
144 |
event.getOldPos(), event.getNewPos()); |
145 |
} |
146 |
|
147 |
public boolean isHooked() { |
148 |
// Layer3DProps props3D = Layer3DProps.getLayer3DProps(this);
|
149 |
// if (((MapContext3D)fmap).getLayers()==this) // this is the root
|
150 |
// FLayers3D
|
151 |
// props3D.setHooked(true);
|
152 |
//
|
153 |
// return props3D.getHooked();
|
154 |
return true; |
155 |
} |
156 |
|
157 |
public static class RegisterPersistence implements Callable { |
158 |
|
159 |
public Object call() throws Exception { |
160 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
161 |
if (manager.getDefinition(FLayers.class) == null) { |
162 |
FLayers.registerPersistent(); |
163 |
} |
164 |
DynStruct definition = manager.addDefinition(FLayers3DImpl.class, |
165 |
"FLayers3DImpl", "FLayers3DImpl Persistence definition", |
166 |
null, null); |
167 |
definition.extend(PersistenceManager.PERSISTENCE_NAMESPACE, |
168 |
"FLayers");
|
169 |
|
170 |
return Boolean.TRUE; |
171 |
} |
172 |
} |
173 |
|
174 |
} |