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

History | View | Annotate | Download (7.6 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.ProjectManager;
32
import org.gvsig.app.project.documents.AbstractDocument;
33
import org.gvsig.app.project.documents.AbstractDocumentManager;
34
import org.gvsig.app.project.documents.Document;
35
import org.gvsig.app.project.documents.actions.CopyDocumentAction;
36
import org.gvsig.app.project.documents.actions.CutDocumentAction;
37
import org.gvsig.app.project.documents.actions.PasteDocumentAction;
38
import org.gvsig.app.project.documents.gui.WindowLayout;
39
import org.gvsig.app.project.documents.view.DefaultViewDocument;
40
import org.gvsig.app.project.documents.view.gui.ViewProperties;
41
import org.gvsig.fmap.mapcontext.MapContext;
42
import org.gvsig.fmap.mapcontext.ViewPort;
43
import org.gvsig.fmap.mapcontext.layers.FLayers;
44
import org.gvsig.gvsig3d.Gvsig3DException;
45
import org.gvsig.gvsig3d.Gvsig3DLocator;
46
import org.gvsig.gvsig3d.Gvsig3DManager;
47
import org.gvsig.gvsig3d.map3d.layers.FLayers3D;
48
import org.gvsig.osgvp.exceptions.node.NodeException;
49
import org.gvsig.osgvp.terrain.Extent;
50
import org.gvsig.osgvp.terrain.JavaDataDriver;
51
import org.gvsig.osgvp.terrain.LayerManager;
52
import org.gvsig.osgvp.terrain.Terrain;
53
import org.gvsig.osgvp.terrain.TerrainViewer;
54
import org.gvsig.osgvp.viewer.Camera;
55
import org.gvsig.osgvp.viewer.IViewerContainer;
56
import org.gvsig.osgvp.viewer.ViewerFactory;
57
import org.gvsig.osgvp.viewer.ViewerStateListener;
58
import org.gvsig.tools.ToolsLocator;
59
import org.gvsig.tools.dynobject.DynStruct;
60
import org.gvsig.tools.persistence.PersistenceManager;
61

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

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

    
73

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

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

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

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

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

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

    
98
        public AbstractDocument createDocument() {
99

    
100
                String viewName = "Vista3D";
101
                String aux = PluginServices.getText(this, "untitled");
102
                Gvsig3DManager manager = Gvsig3DLocator.getManager();
103
//                int numViews = ((Integer) AbstractDocument.NUMS.get(_registerName))
104
//                                .intValue();
105
//
106
//                viewName = aux + " - " + numViews++;
107
//
108
//                ProjectDocument.NUMS.put(_registerName, new Integer(numViews));
109
                
110
                DefaultView3DDocument viewDocument = new DefaultView3DDocument(this);
111
                
112
                try {
113
                        ViewPort vp = manager.createDefaultViewPort3DInstance();
114
                        FLayers3D layers = manager.createDefaultFLayers3DInstance(vp);
115
                        viewDocument.setMapContext(layers.getMapContext());
116
                        viewDocument.setMapOverViewContext(new MapContext(null));
117
                        viewDocument.getMapOverViewContext().setProjection(
118
                                        viewDocument.getMapContext().getProjection());
119
                        viewDocument.setName(viewName);
120
                        viewDocument.setCreationDate(DateFormat.getInstance().format(new Date()));
121
                        
122
                } catch (Gvsig3DException e) {
123
                        // TODO Auto-generated catch block
124
                        e.printStackTrace();
125
                }
126
                
127
                return viewDocument;
128
        }
129

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

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

    
135
                ViewPort vp = new ViewPort();
136
                
137

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

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

    
151
                return view;
152
        }
153

    
154
        public IWindow getPropertiesWindow(Document doc) {
155
                return new ViewProperties((DefaultViewDocument) doc);
156
        }
157

    
158
        /**
159
         * Registers in the points of extension the Factory with alias.
160
         * 
161
         */
162
        public static void register() {
163
                View3DManager factory = new View3DManager();
164
                ProjectManager.getInstance().registerDocumentFactory(factory);
165

    
166
                PersistenceManager manager = ToolsLocator.getPersistenceManager();
167
                manager.registerFactory(factory);
168

    
169
                ProjectManager.getInstance().registerDocumentAction(TYPENAME,
170
                                new CopyDocumentAction());
171
                ProjectManager.getInstance().registerDocumentAction(TYPENAME,
172
                                new CutDocumentAction());
173
                ProjectManager.getInstance().registerDocumentAction(TYPENAME,
174
                                new PasteDocumentAction());
175

    
176
                PluginServices.getIconTheme().registerDefault(
177
                                "document-view3d-icon",
178
                                View3DManager.class.getClassLoader().getResource(
179
                                                "images/ProjectView3D.png"));
180
                PluginServices.getIconTheme().registerDefault(
181
                                "document-view3d-icon-sel",
182
                                View3DManager.class.getClassLoader().getResource(
183
                                                "images/ProjectView3DSel.png"));
184

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

    
204
        }
205

    
206
        @SuppressWarnings("rawtypes")
207
        public DynStruct getDefinition(String className) {
208

    
209
//                if (this.persistenceDefinition.getName().equalsIgnoreCase(className)) {
210
//                        return this.persistenceDefinition;
211
//                }
212
//                if (this.persistenceDefinition.getFullName()
213
//                                .equalsIgnoreCase(className)) {
214
//                        return this.persistenceDefinition;
215
//                }
216
//                if (this.getDocumentClass().getName().equals(className)) {
217
//                        return this.persistenceDefinition;
218
//                }
219
//
220
//                Class theClass;
221
//                try {
222
//                        theClass = (Class) Class.forName(className);
223
//                } catch (ClassNotFoundException e) {
224
//                        return null;
225
//                }
226
//                if (this.manages(theClass)) {
227
//                        return this.persistenceDefinition;
228
//                }
229

    
230
                return null;
231

    
232
        }
233

    
234
        @SuppressWarnings("rawtypes")
235
        protected Class getDocumentClass() {
236
                return DefaultViewDocument.class;
237
        }
238

    
239

    
240
}