Statistics
| Revision:

root / branches / gvSIG_19_ext3D_osgVP_2_2_0 / extensions / ext3Dgui / src / org / gvsig / gvsig3dgui / manipulator / Manipulator3DExtension.java @ 32536

History | View | Annotate | Download (6.21 KB)

1 23305 jcampos
package org.gvsig.gvsig3dgui.manipulator;
2
3 32375 jzarzoso
import java.io.File;
4 23305 jcampos
5 32375 jzarzoso
import javax.swing.Icon;
6
import javax.swing.ImageIcon;
7
8 23305 jcampos
import org.gvsig.gvsig3d.cacheservices.OSGCacheService;
9 32536 jzarzoso
import org.gvsig.gvsig3d.map3d.MapContext3D;
10 23305 jcampos
import org.gvsig.gvsig3d.navigation.NavigationMode;
11
import org.gvsig.gvsig3dgui.view.View3D;
12 32536 jzarzoso
import org.gvsig.osgvp.core.osg.Vec4;
13
import org.gvsig.osgvp.exceptions.node.NodeException;
14
import org.gvsig.osgvp.features.Text;
15 23305 jcampos
import org.gvsig.osgvp.manipulator.EditionManager;
16 32375 jzarzoso
import org.gvsig.osgvp.manipulator.ManipulatorHandler;
17 23305 jcampos
import org.gvsig.osgvp.manipulator.Manipulator.DraggerType;
18 32536 jzarzoso
import org.gvsig.osgvp.terrain.TerrainViewer;
19
import org.gvsig.osgvp.viewer.IViewerContainer;
20
import org.gvsig.osgvp.viewer.OSGViewer;
21 23305 jcampos
22
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps;
23 32536 jzarzoso
import com.iver.ai2.gvsig3d.resources.ResourcesFactory;
24 23305 jcampos
import com.iver.andami.PluginServices;
25
import com.iver.andami.plugins.Extension;
26 32375 jzarzoso
import com.iver.andami.ui.mdiFrame.JToolBarButton;
27 23305 jcampos
import com.iver.cit.gvsig.fmap.MapContext;
28
import com.iver.cit.gvsig.fmap.layers.FLayer;
29
import com.iver.cit.gvsig.project.documents.view.IProjectView;
30
31
public class Manipulator3DExtension extends Extension {
32
33 32536 jzarzoso
        private IViewerContainer _canvas3d = null;
34 23305 jcampos
        private EditionManager em;
35 32536 jzarzoso
        private boolean _manipActive = false;
36
        private Icon iconActivar = null;
37
        private Icon iconDesactivar = null;
38
        private Text _editionHud;
39
        private TerrainViewer _terrainViewer;
40
        private FLayer _layerActive = null;
41 23305 jcampos
42
        public void execute(String actionCommand) {
43
44 32536 jzarzoso
                // Getting View
45 23305 jcampos
                com.iver.andami.ui.mdiManager.IWindow view = PluginServices
46
                                .getMDIManager().getActiveWindow();
47
                if (!(view instanceof View3D))
48
                        return;
49
                // Casting to View3D
50
                View3D vista3D = (View3D) view;
51
52 32536 jzarzoso
                _canvas3d = vista3D.getCanvas3d();
53 23305 jcampos
54
                IProjectView model = vista3D.getModel();
55 32536 jzarzoso
                MapContext3D mapa = (MapContext3D) model.getMapContext();
56 23305 jcampos
                FLayer[] activeLayers = mapa.getLayers().getActives();
57
                if (activeLayers.length > 0) {
58
                        FLayer layer = activeLayers[0];
59
60
                        Layer3DProps props3D = Layer3DProps.getLayer3DProps(layer);
61
                        OSGCacheService osgCacheService = (OSGCacheService) props3D
62
                                        .getCacheService();
63
64
                        em = osgCacheService.getEditionManager();
65 32375 jzarzoso
66 23305 jcampos
                        if (actionCommand.equals("ROTATION_MANIPULATOR")) {
67 32404 jzarzoso
                                em.changeDragger(DraggerType.TRACKBALL_DRAGGER);
68
                        } else if (actionCommand.equals("TABBOX_MANIPULATOR")) {
69 23305 jcampos
                                em.changeDragger(DraggerType.TABBOX_DRAGGER);
70 32536 jzarzoso
                        }else if (actionCommand.equals("GROUP_MANIPULATOR")) {
71 32375 jzarzoso
72 32536 jzarzoso
                                if (osgCacheService.getManipulatorsActive())
73
                                        em.group();
74 32375 jzarzoso
75 32536 jzarzoso
                        } else if (actionCommand.equals("UNGROUP_MANIPULATOR")) {
76 32375 jzarzoso
77 32536 jzarzoso
                                if (osgCacheService.getManipulatorsActive())
78
                                        em.ungroup();
79 32375 jzarzoso
80 32536 jzarzoso
                        }
81 32375 jzarzoso
82 23305 jcampos
                }
83
84
        }
85
86
        public void initialize() {
87
                // TODO Auto-generated method stub
88 32375 jzarzoso
89
                // Registering icons.
90 24059 jcampos
                PluginServices.getIconTheme().registerDefault(
91 32404 jzarzoso
                                "rotation_manipulator",
92 24059 jcampos
                                this.getClass().getClassLoader().getResource(
93 32375 jzarzoso
                                                "images/rotation_manipulator.png"));
94
95 25805 jcampos
                PluginServices.getIconTheme().registerDefault(
96 32404 jzarzoso
                                "tabbox_manipulator",
97 25805 jcampos
                                this.getClass().getClassLoader().getResource(
98 32375 jzarzoso
                                                "images/tabbox_manipulator.gif"));
99 23305 jcampos
100 32375 jzarzoso
                PluginServices.getIconTheme().registerDefault(
101
                                "enable_manipulator",
102
                                this.getClass().getClassLoader()
103
                                                .getResource("images/pick2.png"));
104 32536 jzarzoso
105 32404 jzarzoso
                PluginServices.getIconTheme().registerDefault(
106
                                "group_manip",
107
                                this.getClass().getClassLoader()
108
                                                .getResource("images/group.png"));
109 32536 jzarzoso
110 32404 jzarzoso
                PluginServices.getIconTheme().registerDefault(
111
                                "ungroup_manip",
112 32536 jzarzoso
                                this.getClass().getClassLoader().getResource(
113
                                                "images/ungroup.png"));
114 32375 jzarzoso
115 32536 jzarzoso
                initEditTextHud();
116
117 23305 jcampos
        }
118
119 32536 jzarzoso
        public FLayer osgLayerActive() {
120 32375 jzarzoso
121 32536 jzarzoso
                FLayer activeLayer = null;
122 24059 jcampos
                // Getting view3
123
                com.iver.andami.ui.mdiManager.IWindow view = PluginServices
124 32375 jzarzoso
                                .getMDIManager().getActiveWindow();
125
                if ((view instanceof View3D)) {
126 24059 jcampos
                        // Casting to View3D
127
                        View3D vista3D = (View3D) view;
128 32375 jzarzoso
129 24059 jcampos
                        IProjectView model = vista3D.getModel();
130
                        MapContext mapa = model.getMapContext();
131
                        FLayer[] activeLayers = mapa.getLayers().getActives();
132 32536 jzarzoso
                        if (activeLayers.length == 1) {
133 24059 jcampos
                                FLayer layer = activeLayers[0];
134 32536 jzarzoso
135 24059 jcampos
                                Layer3DProps props3D = Layer3DProps.getLayer3DProps(layer);
136 32375 jzarzoso
                                if (props3D != null
137
                                                && props3D.getType() == Layer3DProps.layer3DOSG) {
138 32536 jzarzoso
139
                                        activeLayer = layer;
140 24059 jcampos
                                }
141 32536 jzarzoso
142 24059 jcampos
                        }
143
                }
144 32375 jzarzoso
145 32536 jzarzoso
                return activeLayer;
146 32375 jzarzoso
147 23305 jcampos
        }
148
149 32375 jzarzoso
        public boolean isEnabled() {
150
151 32536 jzarzoso
                FLayer layer = osgLayerActive();
152
                Layer3DProps props3D = Layer3DProps.getLayer3DProps(layer);
153
                if (props3D.isEditing()) {
154
                        return true;
155
156
                } else
157
                        return false;
158 32375 jzarzoso
        }
159
160 23305 jcampos
        public boolean isVisible() {
161 32375 jzarzoso
162 32536 jzarzoso
                FLayer layer = osgLayerActive();
163
164
                if (layer != null) {
165
166
                        Layer3DProps props3D = Layer3DProps.getLayer3DProps(layer);
167
168
                        return true;
169
                } else
170
                        return false;
171
172 23305 jcampos
        }
173
174 32375 jzarzoso
        public void postInitialize() {
175
176
                File file = new File(this.getClass().getClassLoader().getResource(
177
                                "images").getFile());
178
                String path1 = file.getPath() + "/pick2.png";
179
                String path2 = file.getPath() + "/nopick2.png";
180
181 32536 jzarzoso
                iconActivar = new ImageIcon(path1);
182
                iconDesactivar = new ImageIcon(path2);
183
184
                JToolBarButton b1 = (JToolBarButton) PluginServices.getMainFrame()
185
                                .getComponentByName("GROUP_MANIP");
186
187
                JToolBarButton b2 = (JToolBarButton) PluginServices.getMainFrame()
188
                                .getComponentByName("UNGROUP_MANIP");
189
190 32404 jzarzoso
                b1.setEnabled(false);
191
                b2.setEnabled(false);
192 32375 jzarzoso
193
        }
194
195 32536 jzarzoso
        private void initEditTextHud() {
196
197
                // Seting up text
198
                try {
199
                        _editionHud = new Text();
200
                } catch (NodeException e) {
201
                        // TODO Auto-generated catch block
202
                        e.printStackTrace();
203
                }
204
                _editionHud.setCharacterSize(14);
205
                _editionHud.setColor(new Vec4(1.0f, 1.0f, 0.0f, 1.0f));
206
                _editionHud.setBackdropColor(1.0f, 1.0f, 0.0f, 1.0f);
207
208
                if (ResourcesFactory.exitsResouce("arial.ttf"))
209
                        _editionHud.setFont(ResourcesFactory.getResourcePath("arial.ttf"));
210
                else {
211
                        // TODO: This freeze the execution.. disable when working.
212
                        _editionHud.setFont("arial.ttf");
213
                }
214
215
                _editionHud.setPosition(10, 10, 0);
216
                _editionHud.setBackdropType(Text.BackdropType.OUTLINE);
217
                _editionHud.setAlignment(Text.AlignmentType.LEFT_CENTER);
218
                _editionHud
219
                                .setText(PluginServices.getText(this, "Hold_Control_Camera"));
220
221
        }
222
223
224
225 23305 jcampos
}