gvsig-3d / 2.0 / trunk / org.gvsig.gvsig3d.app / org.gvsig.gvsig3d.app.extension / src / main / java / org / gvsig / gvsig3d / app / extension / View3DManager.java @ 318
History | View | Annotate | Download (9.52 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 |
*/
|
22 |
package org.gvsig.gvsig3d.app.extension; |
23 |
|
24 |
import java.text.DateFormat; |
25 |
import java.util.Date; |
26 |
|
27 |
import javax.swing.ImageIcon; |
28 |
|
29 |
import org.gvsig.andami.PluginServices; |
30 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
31 |
import org.gvsig.app.project.DefaultProject; |
32 |
import org.gvsig.app.project.ProjectManager; |
33 |
import org.gvsig.app.project.documents.AbstractDocument; |
34 |
import org.gvsig.app.project.documents.AbstractDocumentManager; |
35 |
import org.gvsig.app.project.documents.Document; |
36 |
import org.gvsig.app.project.documents.actions.CopyDocumentAction; |
37 |
import org.gvsig.app.project.documents.actions.CutDocumentAction; |
38 |
import org.gvsig.app.project.documents.actions.PasteDocumentAction; |
39 |
import org.gvsig.app.project.documents.gui.IDocumentWindow; |
40 |
import org.gvsig.app.project.documents.gui.WindowLayout; |
41 |
import org.gvsig.app.project.documents.view.ViewDocument; |
42 |
import org.gvsig.fmap.mapcontext.MapContext; |
43 |
import org.gvsig.fmap.mapcontext.ViewPort; |
44 |
import org.gvsig.gvsig3d.Gvsig3DLocator; |
45 |
import org.gvsig.gvsig3d.Gvsig3DManager; |
46 |
import org.gvsig.gvsig3d.app.view.ViewProperties3D; |
47 |
import org.gvsig.gvsig3d.impl.map3d.MapContext3DImpl; |
48 |
import org.gvsig.gvsig3d.map3d.layers.FLayers3D; |
49 |
import org.gvsig.osgvp.viewer.IViewerContainer; |
50 |
import org.gvsig.osgvp.viewer.ViewerFactory; |
51 |
import org.gvsig.tools.ToolsLocator; |
52 |
import org.gvsig.tools.dynobject.DynStruct; |
53 |
import org.gvsig.tools.persistence.PersistenceManager; |
54 |
import org.gvsig.tools.persistence.PersistentState; |
55 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
56 |
|
57 |
/**
|
58 |
* @author AI2
|
59 |
* @version $Id$
|
60 |
*
|
61 |
*/
|
62 |
public class View3DManager extends AbstractDocumentManager { |
63 |
|
64 |
private static final String PERSISTENCE_VIEW3D_DOCUMENT_DEFINITION_NAME = "DefaultView3DDocument"; |
65 |
public static String TYPENAME = "project.document.view3d"; |
66 |
private DynStruct persistenceDefinition;
|
67 |
private Gvsig3DManager _manager;
|
68 |
|
69 |
public View3DManager() {
|
70 |
// Do nothing
|
71 |
} |
72 |
|
73 |
public int getPriority() { |
74 |
return 10; |
75 |
} |
76 |
|
77 |
public ImageIcon getIcon() { |
78 |
return PluginServices.getIconTheme().get("document-view3d-icon"); |
79 |
} |
80 |
|
81 |
public ImageIcon getIconSelected() { |
82 |
return PluginServices.getIconTheme().get("document-view3d-icon-sel"); |
83 |
} |
84 |
|
85 |
public String getTitle() { |
86 |
return PluginServices.getText(this, "show_3Dview"); |
87 |
} |
88 |
|
89 |
public String getTypeName() { |
90 |
return TYPENAME;
|
91 |
} |
92 |
|
93 |
public AbstractDocument createDocument() { |
94 |
|
95 |
String viewName = "View3D"; |
96 |
String aux = PluginServices.getText(this, "untitled"); |
97 |
int numViews = ProjectManager.getInstance().getCurrentProject()
|
98 |
.getDocuments(TYPENAME).size(); |
99 |
viewName = aux + " - " + numViews++;
|
100 |
|
101 |
// Buscamos si alguna vista ya ten?a este nombre:
|
102 |
while (ProjectManager.getInstance().getCurrentProject()
|
103 |
.getDocument(viewName, TYPENAME) != null) {
|
104 |
viewName = aux + " - " + numViews++;
|
105 |
} |
106 |
|
107 |
_manager = Gvsig3DLocator.getManager(); |
108 |
|
109 |
DefaultView3DDocument viewDocument = new DefaultView3DDocument(this); |
110 |
|
111 |
ViewPort vp = _manager.createDefaultViewPort3DInstance(DefaultProject |
112 |
.getPreferences().getDefaultProjection()); |
113 |
FLayers3D layers = _manager.createDefaultFLayers3DInstance(vp); |
114 |
viewDocument.setMapContext(layers.getMapContext()); |
115 |
viewDocument.setMapOverViewContext(new MapContext(new ViewPort(layers |
116 |
.getMapContext().getProjection()))); |
117 |
viewDocument.setName(viewName); |
118 |
viewDocument.setCreationDate(DateFormat.getInstance()
|
119 |
.format(new Date())); |
120 |
|
121 |
setView3DProperties(viewDocument); |
122 |
|
123 |
return viewDocument;
|
124 |
} |
125 |
|
126 |
public IWindow getMainWindow(Document doc, WindowLayout layout) { |
127 |
|
128 |
DefaultView3DDocument viewDoc = (DefaultView3DDocument) doc; |
129 |
|
130 |
IDocumentWindow docview; |
131 |
|
132 |
docview = (IDocumentWindow) PluginServices.getMDIManager() |
133 |
.getSingletonWindow(getMainWindowClass(), doc); |
134 |
if (docview != null) { |
135 |
// The view window document is already created, return it.
|
136 |
return docview;
|
137 |
} |
138 |
|
139 |
DefaultView3DPanel view = new DefaultView3DPanel();
|
140 |
|
141 |
ViewPort vp = new ViewPort();
|
142 |
|
143 |
IViewerContainer canvas3d = viewDoc.getOrCreateCanvas3D(); |
144 |
view.setCanvas3d(canvas3d); |
145 |
ViewerFactory.getInstance().addViewerToAnimator(canvas3d); |
146 |
ViewerFactory.getInstance().startAnimator(); |
147 |
view.setTerrain(viewDoc.getTerrain()); |
148 |
view.setDataManager(viewDoc.getTerrainDataManager()); |
149 |
view.setLayerManager(viewDoc.getTerrainLayerManager()); |
150 |
|
151 |
view.setNavMode(_manager.createDefaultNavigationModeInstance(viewDoc |
152 |
.getTerrainViewer().getTerrainCameraManipulator())); |
153 |
|
154 |
if (layout != null) { |
155 |
view.setWindowLayout(layout); |
156 |
} |
157 |
view.initialize(); |
158 |
view.setDocument(doc); |
159 |
((AbstractDocument) doc).raiseEventCreateWindow(view);
|
160 |
|
161 |
return view;
|
162 |
|
163 |
} |
164 |
|
165 |
private void setView3DProperties(DefaultView3DDocument prView) { |
166 |
|
167 |
ViewProperties3D viewProperties = new ViewProperties3D(prView, true); |
168 |
PluginServices.getMDIManager().addWindow(viewProperties); |
169 |
} |
170 |
|
171 |
public IWindow getPropertiesWindow(Document doc) { |
172 |
return new ViewProperties3D((DefaultView3DDocument) doc, true); |
173 |
} |
174 |
|
175 |
/**
|
176 |
* Registers in the points of extension the Factory with alias.
|
177 |
*
|
178 |
*/
|
179 |
public static void register() { |
180 |
View3DManager factory = new View3DManager();
|
181 |
ProjectManager.getInstance().registerDocumentFactory(factory); |
182 |
|
183 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
184 |
manager.registerFactory(factory); |
185 |
|
186 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME, |
187 |
new CopyDocumentAction());
|
188 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME, |
189 |
new CutDocumentAction());
|
190 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME, |
191 |
new PasteDocumentAction());
|
192 |
|
193 |
PluginServices.getIconTheme().registerDefault( |
194 |
"document-view3d-icon",
|
195 |
View3DManager.class.getClassLoader().getResource( |
196 |
"images/ProjectView3D.png"));
|
197 |
PluginServices.getIconTheme().registerDefault( |
198 |
"document-view3d-icon-sel",
|
199 |
View3DManager.class.getClassLoader().getResource( |
200 |
"images/ProjectView3DSel.png"));
|
201 |
|
202 |
if (factory.persistenceDefinition == null) { |
203 |
factory.persistenceDefinition = manager.addDefinition( |
204 |
ViewDocument.class, |
205 |
PERSISTENCE_VIEW3D_DOCUMENT_DEFINITION_NAME, |
206 |
"Default view 3D document persistence definition", null, |
207 |
null);
|
208 |
factory.persistenceDefinition |
209 |
.extend(manager |
210 |
.getDefinition(AbstractDocument.PERSISTENCE_DEFINITION_NAME));
|
211 |
|
212 |
factory.persistenceDefinition.addDynFieldBoolean("useMapOverview")
|
213 |
.setMandatory(true);
|
214 |
factory.persistenceDefinition.addDynFieldObject("mainMapContext")
|
215 |
.setClassOfValue(MapContext3DImpl.class).setMandatory(true);
|
216 |
factory.persistenceDefinition |
217 |
.addDynFieldObject("overviewMapContext")
|
218 |
.setClassOfValue(MapContext.class).setMandatory(false);
|
219 |
|
220 |
} |
221 |
|
222 |
} |
223 |
|
224 |
@SuppressWarnings("rawtypes") |
225 |
public DynStruct getDefinition(String className) { |
226 |
|
227 |
if (this.persistenceDefinition.getName().equalsIgnoreCase(className)) { |
228 |
return this.persistenceDefinition; |
229 |
} |
230 |
if (this.persistenceDefinition.getFullName() |
231 |
.equalsIgnoreCase(className)) { |
232 |
return this.persistenceDefinition; |
233 |
} |
234 |
if (this.getDocumentClass().getName().equals(className)) { |
235 |
return this.persistenceDefinition; |
236 |
} |
237 |
|
238 |
Class theClass;
|
239 |
try {
|
240 |
theClass = (Class) Class.forName(className); |
241 |
} catch (ClassNotFoundException e) { |
242 |
return null; |
243 |
} |
244 |
if (this.manages(theClass)) { |
245 |
return this.persistenceDefinition; |
246 |
} |
247 |
|
248 |
return null; |
249 |
|
250 |
} |
251 |
|
252 |
@SuppressWarnings("rawtypes") |
253 |
protected Class getDocumentClass() { |
254 |
return DefaultView3DDocument.class;
|
255 |
} |
256 |
|
257 |
public Class getMainWindowClass() { |
258 |
|
259 |
return DefaultView3DPanel.class;
|
260 |
} |
261 |
|
262 |
public boolean manages(Object object) { |
263 |
return object instanceof ViewDocument; |
264 |
} |
265 |
|
266 |
public AbstractDocument createDocumentFromState(PersistentState state) { |
267 |
|
268 |
String viewName = "View3D"; |
269 |
String aux = PluginServices.getText(this, "untitled"); |
270 |
int numViews = ProjectManager.getInstance().getCurrentProject()
|
271 |
.getDocuments(TYPENAME).size(); |
272 |
viewName = aux + " - " + numViews++;
|
273 |
|
274 |
// Buscamos si alguna vista ya ten?a este nombre:
|
275 |
while (ProjectManager.getInstance().getCurrentProject()
|
276 |
.getDocument(viewName, TYPENAME) != null) {
|
277 |
viewName = aux + " - " + numViews++;
|
278 |
} |
279 |
|
280 |
_manager = Gvsig3DLocator.getManager(); |
281 |
|
282 |
DefaultView3DDocument viewDocument = new DefaultView3DDocument(this); |
283 |
|
284 |
ViewPort vp = _manager.createDefaultViewPort3DInstance(DefaultProject |
285 |
.getPreferences().getDefaultProjection()); |
286 |
FLayers3D layers = _manager.createDefaultFLayers3DInstance(vp); |
287 |
viewDocument.setMapContext(layers.getMapContext()); |
288 |
viewDocument.setMapOverViewContext(new MapContext(new ViewPort(layers |
289 |
.getMapContext().getProjection()))); |
290 |
viewDocument.setName(viewName); |
291 |
viewDocument.setCreationDate(DateFormat.getInstance()
|
292 |
.format(new Date())); |
293 |
|
294 |
return viewDocument;
|
295 |
} |
296 |
|
297 |
public Object createFromState(PersistentState state) |
298 |
throws PersistenceException {
|
299 |
|
300 |
Document doc = this.createDocumentFromState(state); |
301 |
return doc;
|
302 |
} |
303 |
|
304 |
} |