Statistics
| Revision:

gvsig-3d / 2.0 / trunk / org.gvsig.gvsig3d.app / org.gvsig.gvsig3d.app.extension / src / main / java / org / gvsig / gvsig3d / app / extension / View3DManager.java @ 258

History | View | Annotate | Download (7.87 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.WindowLayout;
40
import org.gvsig.app.project.documents.view.DefaultViewDocument;
41
import org.gvsig.app.project.documents.view.gui.ViewProperties;
42
import org.gvsig.fmap.mapcontext.MapContext;
43
import org.gvsig.fmap.mapcontext.ViewPort;
44
import org.gvsig.fmap.mapcontext.layers.FLayers;
45
import org.gvsig.gvsig3d.Gvsig3DException;
46
import org.gvsig.gvsig3d.Gvsig3DLocator;
47
import org.gvsig.gvsig3d.Gvsig3DManager;
48
import org.gvsig.gvsig3d.app.view.ViewProperties3D;
49
import org.gvsig.gvsig3d.map3d.layers.FLayers3D;
50
import org.gvsig.osgvp.exceptions.node.NodeException;
51
import org.gvsig.osgvp.terrain.Extent;
52
import org.gvsig.osgvp.terrain.JavaDataDriver;
53
import org.gvsig.osgvp.terrain.LayerManager;
54
import org.gvsig.osgvp.terrain.Terrain;
55
import org.gvsig.osgvp.terrain.TerrainViewer;
56
import org.gvsig.osgvp.viewer.Camera;
57
import org.gvsig.osgvp.viewer.IViewerContainer;
58
import org.gvsig.osgvp.viewer.ViewerFactory;
59
import org.gvsig.osgvp.viewer.ViewerStateListener;
60
import org.gvsig.tools.ToolsLocator;
61
import org.gvsig.tools.dynobject.DynStruct;
62
import org.gvsig.tools.persistence.PersistenceManager;
63

    
64
/**
65
 * @author gvSIG Team
66
 * @version $Id$
67
 * 
68
 */
69
public class View3DManager extends AbstractDocumentManager {
70

    
71
        private static final String PERSISTENCE_VIEW3D_DOCUMENT_DEFINITION_NAME = "DefaultView3DDocument";
72
        public static String TYPENAME = "project.document.view3d";
73
        private DynStruct persistenceDefinition;
74

    
75
        public View3DManager() {
76
                // Do nothing
77
        }
78

    
79
        public int getPriority() {
80
                return 0;
81
        }
82

    
83
        public ImageIcon getIcon() {
84
                return PluginServices.getIconTheme().get("document-view3d-icon");
85
        }
86

    
87
        public ImageIcon getIconSelected() {
88
                return PluginServices.getIconTheme().get("document-view3d-icon-sel");
89
        }
90

    
91
        public String getTitle() {
92
                return PluginServices.getText(this, "Vista3d");
93
        }
94

    
95
        public String getTypeName() {
96
                return TYPENAME;
97
        }
98

    
99
        public AbstractDocument createDocument() {
100

    
101
                String viewName = "Vista3D";
102
                String aux = PluginServices.getText(this, "untitled");
103
                Gvsig3DManager manager = Gvsig3DLocator.getManager();
104
                // int numViews = ((Integer) AbstractDocument.NUMS.get(_registerName))
105
                // .intValue();
106
                //
107
                // viewName = aux + " - " + numViews++;
108
                //
109
                // ProjectDocument.NUMS.put(_registerName, new Integer(numViews));
110

    
111
                DefaultView3DDocument viewDocument = new DefaultView3DDocument(this);
112

    
113
                ViewPort vp = manager.createDefaultViewPort3DInstance(DefaultProject
114
                                .getPreferences().getDefaultProjection());
115
                FLayers3D layers = manager.createDefaultFLayers3DInstance(vp);
116
                viewDocument.setMapContext(layers.getMapContext());
117
                viewDocument.setMapOverViewContext(new MapContext(null));
118
                viewDocument.getMapOverViewContext().setProjection(
119
                                viewDocument.getMapContext().getProjection());
120
                viewDocument.setName(viewName);
121
                viewDocument.setCreationDate(DateFormat.getInstance()
122
                                .format(new Date()));
123

    
124
                setView3DProperties(viewDocument);
125

    
126
                return viewDocument;
127
        }
128

    
129
        public IWindow getMainWindow(Document doc, WindowLayout layout) {
130

    
131
                DefaultView3DPanel view = new DefaultView3DPanel();
132
                DefaultView3DDocument viewDoc = (DefaultView3DDocument) doc;
133

    
134
                ViewPort vp = new ViewPort();
135

    
136
                IViewerContainer canvas3d = viewDoc.getOrCreateCanvas3D();
137
                view.setCanvas3d(canvas3d);
138
                view.setTerrain(viewDoc.getTerrain());
139
                view.setDataManager(viewDoc.getTerrainDataManager());
140
                view.setLayerManager(viewDoc.getTerrainLayerManager());
141

    
142
                if (layout != null) {
143
                        view.setWindowLayout(layout);
144
                }
145
                view.initialize();
146
                view.setDocument(doc);
147
                ((AbstractDocument) doc).raiseEventCreateWindow(view);
148

    
149
                return view;
150

    
151
        }
152

    
153
        private void setView3DProperties(DefaultView3DDocument prView) {
154

    
155
                ViewProperties3D viewProperties = new ViewProperties3D(prView, true);
156
                PluginServices.getMDIManager().addWindow(viewProperties);
157
        }
158

    
159
        public IWindow getPropertiesWindow(Document doc) {
160
                return new ViewProperties((DefaultViewDocument) doc);
161
        }
162

    
163
        /**
164
         * Registers in the points of extension the Factory with alias.
165
         * 
166
         */
167
        public static void register() {
168
                View3DManager factory = new View3DManager();
169
                ProjectManager.getInstance().registerDocumentFactory(factory);
170

    
171
                PersistenceManager manager = ToolsLocator.getPersistenceManager();
172
                manager.registerFactory(factory);
173

    
174
                ProjectManager.getInstance().registerDocumentAction(TYPENAME,
175
                                new CopyDocumentAction());
176
                ProjectManager.getInstance().registerDocumentAction(TYPENAME,
177
                                new CutDocumentAction());
178
                ProjectManager.getInstance().registerDocumentAction(TYPENAME,
179
                                new PasteDocumentAction());
180

    
181
                PluginServices.getIconTheme().registerDefault(
182
                                "document-view3d-icon",
183
                                View3DManager.class.getClassLoader().getResource(
184
                                                "images/ProjectView3D.png"));
185
                PluginServices.getIconTheme().registerDefault(
186
                                "document-view3d-icon-sel",
187
                                View3DManager.class.getClassLoader().getResource(
188
                                                "images/ProjectView3DSel.png"));
189

    
190
                // if (factory.persistenceDefinition == null) {
191
                // factory.persistenceDefinition = manager.addDefinition(
192
                // ViewDocument.class,
193
                // PERSISTENCE_VIEW3D_DOCUMENT_DEFINITION_NAME,
194
                // "Default view 3D document persistence definition", null, null);
195
                // factory.persistenceDefinition
196
                // .extend(manager
197
                // .getDefinition(AbstractDocument.PERSISTENCE_DEFINITION_NAME));
198
                //
199
                // factory.persistenceDefinition.addDynFieldBoolean("useMapOverview")
200
                // .setMandatory(true);
201
                // factory.persistenceDefinition.addDynFieldObject("mainMapContext")
202
                // .setClassOfValue(MapContext.class).setMandatory(true);
203
                // factory.persistenceDefinition
204
                // .addDynFieldObject("overviewMapContext")
205
                // .setClassOfValue(MapContext.class).setMandatory(false);
206
                //
207
                // }
208

    
209
        }
210

    
211
        @SuppressWarnings("rawtypes")
212
        public DynStruct getDefinition(String className) {
213

    
214
                // if (this.persistenceDefinition.getName().equalsIgnoreCase(className))
215
                // {
216
                // return this.persistenceDefinition;
217
                // }
218
                // if (this.persistenceDefinition.getFullName()
219
                // .equalsIgnoreCase(className)) {
220
                // return this.persistenceDefinition;
221
                // }
222
                // if (this.getDocumentClass().getName().equals(className)) {
223
                // return this.persistenceDefinition;
224
                // }
225
                //
226
                // Class theClass;
227
                // try {
228
                // theClass = (Class) Class.forName(className);
229
                // } catch (ClassNotFoundException e) {
230
                // return null;
231
                // }
232
                // if (this.manages(theClass)) {
233
                // return this.persistenceDefinition;
234
                // }
235

    
236
                return null;
237

    
238
        }
239

    
240
        @SuppressWarnings("rawtypes")
241
        protected Class getDocumentClass() {
242
                return DefaultViewDocument.class;
243
        }
244

    
245
}