Statistics
| Revision:

gvsig-3d / 2.1 / trunk / org.gvsig.gvsig3d / org.gvsig.gvsig3d.app / org.gvsig.gvsig3d.app.commons / src / main / java / org / gvsig / gvsig3d / app / import3D / SaveLayerOSG.java @ 385

History | View | Annotate | Download (6.2 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
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
40
 *
41
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
42
 *
43
 * This program is free software; you can redistribute it and/or
44
 * modify it under the terms of the GNU General Public License
45
 * as published by the Free Software Foundation; either version 2
46
 * of the License, or (at your option) any later version.
47
 *
48
 * This program is distributed in the hope that it will be useful,
49
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
50
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
51
 * GNU General Public License for more details.
52
 *
53
 * You should have received a copy of the GNU General Public License
54
 * along with this program; if not, write to the Free Software
55
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
56
 */
57

    
58
package org.gvsig.gvsig3d.app.import3D;
59

    
60
import java.util.Hashtable;
61

    
62
import javax.swing.JOptionPane;
63

    
64
import org.gvsig.andami.PluginServices;
65
import org.gvsig.andami.plugins.Extension;
66
import org.gvsig.andami.ui.mdiManager.IWindow;
67
import org.gvsig.app.project.documents.view.ViewDocument;
68
import org.gvsig.fmap.mapcontext.MapContext;
69
import org.gvsig.fmap.mapcontext.layers.FLayer;
70
import org.gvsig.fmap.mapcontext.layers.FLayers;
71
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
72
import org.gvsig.gvsig3d.app.extension.DefaultView3DPanel;
73
import org.gvsig.gvsig3d.map3d.Layer3DProps;
74
import org.gvsig.gvsig3d.map3d.MapContext3D;
75
import org.gvsig.osgvp.core.osg.Group;
76
import org.gvsig.osgvp.core.osg.Node;
77
import org.gvsig.osgvp.core.osgdb.osgDB;
78
import org.gvsig.osgvp.exceptions.node.NodeException;
79
import org.gvsig.osgvp.exceptions.node.SaveNodeException;
80
import org.gvsig.osgvp.manipulator.EditionManager;
81

    
82
/**
83
 * @author Jesus Zarzoso- jzarzoso@ai2.upv.es
84
 * @version $Id$
85
 * 
86
 */
87
public class SaveLayerOSG extends Extension {
88

    
89
        private Hashtable _iveExtensionsSupported = null;
90
        private Hashtable _osgExtensionsSupported = null;
91
        private String _lastPath = null;
92

    
93
        /**
94
         * Creating save panel options
95
         */
96
        public void execute(String actionCommand) {
97
                if (actionCommand.equals("SALVARCAPA")) {
98
                        IWindow activeWindow = PluginServices.getMDIManager()
99
                                        .getActiveWindow();
100

    
101
                        DefaultView3DPanel vista = (DefaultView3DPanel) PluginServices
102
                                        .getMDIManager().getActiveWindow();
103
                        ViewDocument model = vista.getModel();
104
                        MapContext mapContext = model.getMapContext();
105
                        FLayers layers = mapContext.getLayers();
106
                        FLayer[] actives = layers.getActives();
107
                        Node n = null;
108

    
109
                        try {
110
                                if (actives.length == 1
111
                                                && ((MapContext3D) actives[0].getMapContext())
112
                                                                .getLayer3DProps(actives[0]).getType() == Layer3DProps.layer3DOSG) {
113

    
114
                                        EditionManager manager = ((MapContext3D) actives[0]
115
                                                        .getMapContext()).getEditionManager(actives[0]);
116
                                        
117
                                        manager.removeAllNodes();
118
                                        n = manager.getScene();
119
                                        n.setNodeName("gvSIG3D");
120
                                        
121
                                        // Group node = osgCache.getLayerNode();
122
                                        String path = ((FLyrVect) actives[0])
123
                                        .getDataStore().getFullName();
124

    
125
                                        osgDB.writeNodeFile(n, path);
126

    
127
                                        JOptionPane.showMessageDialog(null,
128
                                                        PluginServices.getText(this, "saved_layer_ok"));
129

    
130
                                        // ((GvsigDriverOSG
131
                                        // )((FLyrVect)actives[0]).getSource().getDriver()).open(f);
132
                                        // /actives[0].getXMLEntity().putProperty("file",f.getAbsolutePath());
133

    
134
                                        // setProperty("file", f.getAbsolutePath());
135
                                }
136
                        } catch (SaveNodeException e) {
137
                                JOptionPane.showMessageDialog(null,
138
                                                PluginServices.getText(this, "saved_layer_error"));
139
                                e.printStackTrace();
140
                        } catch (NodeException e) {
141
                                JOptionPane.showMessageDialog(null,
142
                                                PluginServices.getText(this, "saved_layer_error"));
143
                                e.printStackTrace();
144
                                // screen snapshop.
145
                        }// if activeWindow.
146
                }// If aprove option.
147
        }
148

    
149
        // }
150
        // }
151

    
152
        public void initialize() {
153
                PluginServices.getIconTheme().registerDefault(
154
                                "save_layer_OSG",
155
                                this.getClass().getClassLoader()
156
                                                .getResource("images/plugin_edit.png"));
157
        }
158

    
159
        /**
160
         * Enable options. Enabled when a layer is selected and this type layer is
161
         * layer3DOSG
162
         */
163
        public boolean isEnabled() {
164

    
165
                DefaultView3DPanel vista = (DefaultView3DPanel) PluginServices
166
                                .getMDIManager().getActiveWindow();
167
                ViewDocument model = vista.getModel();
168
                MapContext mapContext = model.getMapContext();
169
                FLayers layers = mapContext.getLayers();
170
                FLayer[] actives = layers.getActives();
171
                if (actives.length == 1
172
                                && ((MapContext3D) actives[0].getMapContext())
173
                                                .getLayer3DProps(actives[0]) != null
174
                                && ((MapContext3D) actives[0].getMapContext()).getLayer3DProps(
175
                                                actives[0]).getType() == Layer3DProps.layer3DOSG) {
176

    
177
                        return true;
178
                } else
179
                        return false;
180
        }
181

    
182
        public boolean isVisible() {
183
                IWindow f = PluginServices.getMDIManager().getActiveWindow();
184

    
185
                if (f == null) {
186
                        return false;
187
                }
188
                // Only isVisible = true, where the view has a view3D.
189
                if (f instanceof DefaultView3DPanel) {
190
                        return true;
191
                }
192
                return false;
193
        }
194

    
195
}