gvsig-3d / 2.1 / trunk / org.gvsig.gvsig3d / org.gvsig.gvsig3d.app / org.gvsig.gvsig3d.app.commons / src / main / java / org / gvsig / gvsig3d / app / extension / Manipulator3DExtension.java @ 385
History | View | Annotate | Download (5.31 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.app.extension; |
40 |
|
41 |
import org.gvsig.fmap.dal.DataStore; |
42 |
import org.gvsig.fmap.mapcontext.MapContext; |
43 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
44 |
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer; |
45 |
import org.gvsig.gvsig3d.app.extension.DefaultView3DPanel; |
46 |
import org.gvsig.gvsig3d.map3d.Layer3DProps; |
47 |
import org.gvsig.gvsig3d.map3d.MapContext3D; |
48 |
import org.gvsig.osgvp.manipulator.EditionManager; |
49 |
import org.gvsig.osgvp.manipulator.Manipulator.DraggerType; |
50 |
import org.gvsig.andami.PluginServices; |
51 |
import org.gvsig.andami.plugins.Extension; |
52 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
53 |
import org.gvsig.app.project.documents.view.ViewDocument; |
54 |
|
55 |
/**
|
56 |
* @author Jesus Zarzoso- jzarzoso@ai2.upv.es
|
57 |
* @version $Id$
|
58 |
*
|
59 |
*/
|
60 |
public class Manipulator3DExtension extends Extension { |
61 |
|
62 |
private EditionManager em;
|
63 |
|
64 |
public void execute(String actionCommand) { |
65 |
|
66 |
// Getting View
|
67 |
IWindow view = PluginServices.getMDIManager().getActiveWindow(); |
68 |
if (!(view instanceof DefaultView3DPanel)) |
69 |
return;
|
70 |
// Casting to View3D
|
71 |
DefaultView3DPanel vista3D = (DefaultView3DPanel) view; |
72 |
|
73 |
ViewDocument model = vista3D.getModel(); |
74 |
MapContext3D mapa = (MapContext3D) model.getMapContext(); |
75 |
FLayer[] activeLayers = mapa.getLayers().getActives();
|
76 |
if (activeLayers.length > 0) { |
77 |
FLayer layer = activeLayers[0];
|
78 |
|
79 |
Layer3DProps props3D = ((MapContext3D) layer.getMapContext()) |
80 |
.getLayer3DProps(layer); |
81 |
|
82 |
em = ((MapContext3D) layer.getMapContext()) |
83 |
.getEditionManager(layer); |
84 |
|
85 |
if (actionCommand.equals("ROTATION_MANIPULATOR")) { |
86 |
em.changeDragger(DraggerType.TRACKBALL_DRAGGER); |
87 |
em.setEnabledHandlers(true);
|
88 |
} else if (actionCommand.equals("TABBOX_MANIPULATOR")) { |
89 |
em.changeDragger(DraggerType.TABBOX_DRAGGER); |
90 |
em.setEnabledHandlers(true);
|
91 |
} else if (actionCommand.equals("GROUP_MANIPULATOR")) { |
92 |
|
93 |
if (props3D.isEditing())
|
94 |
em.group(); |
95 |
|
96 |
} else if (actionCommand.equals("UNGROUP_MANIPULATOR")) { |
97 |
|
98 |
if (props3D.isEditing())
|
99 |
em.ungroup(); |
100 |
|
101 |
} else if (actionCommand.equals("DELETE_MANIPULATOR")) { |
102 |
|
103 |
if (props3D.isEditing())
|
104 |
em.deleteSelectedNodes(); |
105 |
|
106 |
} |
107 |
|
108 |
} |
109 |
|
110 |
} |
111 |
|
112 |
public void initialize() { |
113 |
// TODO Auto-generated method stub
|
114 |
|
115 |
// Registering icons.
|
116 |
PluginServices.getIconTheme().registerDefault( |
117 |
"rotation_manipulator",
|
118 |
this.getClass().getClassLoader()
|
119 |
.getResource("images/rotation_manipulator.png"));
|
120 |
|
121 |
PluginServices.getIconTheme().registerDefault( |
122 |
"tabbox_manipulator",
|
123 |
this.getClass().getClassLoader()
|
124 |
.getResource("images/tabbox_manipulator.gif"));
|
125 |
|
126 |
PluginServices.getIconTheme().registerDefault( |
127 |
"group_manip",
|
128 |
this.getClass().getClassLoader()
|
129 |
.getResource("images/group.png"));
|
130 |
|
131 |
PluginServices.getIconTheme().registerDefault( |
132 |
"ungroup_manip",
|
133 |
this.getClass().getClassLoader()
|
134 |
.getResource("images/ungroup.png"));
|
135 |
PluginServices.getIconTheme().registerDefault( |
136 |
"delete_manip",
|
137 |
this.getClass().getClassLoader()
|
138 |
.getResource("images/delete.gif"));
|
139 |
|
140 |
} |
141 |
|
142 |
public FLayer osgLayerActive() {
|
143 |
|
144 |
FLayer activeLayer = null;
|
145 |
// Getting view3
|
146 |
IWindow view = PluginServices.getMDIManager().getActiveWindow(); |
147 |
if ((view instanceof DefaultView3DPanel)) { |
148 |
// Casting to View3D
|
149 |
DefaultView3DPanel vista3D = (DefaultView3DPanel) view; |
150 |
|
151 |
ViewDocument model = vista3D.getModel(); |
152 |
MapContext mapa = model.getMapContext(); |
153 |
FLayer[] activeLayers = mapa.getLayers().getActives();
|
154 |
if (activeLayers.length == 1) { |
155 |
FLayer layer = activeLayers[0];
|
156 |
DataStore ds = ((SingleLayer) layer).getDataStore(); |
157 |
|
158 |
|
159 |
if (ds.getProviderName() == "OSG") { |
160 |
|
161 |
activeLayer = layer; |
162 |
} |
163 |
|
164 |
} |
165 |
} |
166 |
|
167 |
return activeLayer;
|
168 |
|
169 |
} |
170 |
|
171 |
public boolean isEnabled() { |
172 |
|
173 |
FLayer layer = osgLayerActive(); |
174 |
Layer3DProps props3D = ((MapContext3D) layer.getMapContext()) |
175 |
.getLayer3DProps(layer); |
176 |
if (props3D.isEditing()) {
|
177 |
return true; |
178 |
|
179 |
} else
|
180 |
return false; |
181 |
} |
182 |
|
183 |
public boolean isVisible() { |
184 |
|
185 |
FLayer layer = osgLayerActive(); |
186 |
|
187 |
if (layer != null) { |
188 |
|
189 |
return true; |
190 |
} else
|
191 |
return false; |
192 |
|
193 |
} |
194 |
|
195 |
} |