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
package org.gvsig.gvsig3dgui.manipulator;
2

    
3
import java.io.File;
4

    
5
import javax.swing.Icon;
6
import javax.swing.ImageIcon;
7

    
8
import org.gvsig.gvsig3d.cacheservices.OSGCacheService;
9
import org.gvsig.gvsig3d.map3d.MapContext3D;
10
import org.gvsig.gvsig3d.navigation.NavigationMode;
11
import org.gvsig.gvsig3dgui.view.View3D;
12
import org.gvsig.osgvp.core.osg.Vec4;
13
import org.gvsig.osgvp.exceptions.node.NodeException;
14
import org.gvsig.osgvp.features.Text;
15
import org.gvsig.osgvp.manipulator.EditionManager;
16
import org.gvsig.osgvp.manipulator.ManipulatorHandler;
17
import org.gvsig.osgvp.manipulator.Manipulator.DraggerType;
18
import org.gvsig.osgvp.terrain.TerrainViewer;
19
import org.gvsig.osgvp.viewer.IViewerContainer;
20
import org.gvsig.osgvp.viewer.OSGViewer;
21

    
22
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps;
23
import com.iver.ai2.gvsig3d.resources.ResourcesFactory;
24
import com.iver.andami.PluginServices;
25
import com.iver.andami.plugins.Extension;
26
import com.iver.andami.ui.mdiFrame.JToolBarButton;
27
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
        private IViewerContainer _canvas3d = null;
34
        private EditionManager em;
35
        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

    
42
        public void execute(String actionCommand) {
43

    
44
                // Getting View
45
                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
                _canvas3d = vista3D.getCanvas3d();
53

    
54
                IProjectView model = vista3D.getModel();
55
                MapContext3D mapa = (MapContext3D) model.getMapContext();
56
                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

    
66
                        if (actionCommand.equals("ROTATION_MANIPULATOR")) {
67
                                em.changeDragger(DraggerType.TRACKBALL_DRAGGER);
68
                        } else if (actionCommand.equals("TABBOX_MANIPULATOR")) {
69
                                em.changeDragger(DraggerType.TABBOX_DRAGGER);
70
                        }else if (actionCommand.equals("GROUP_MANIPULATOR")) {
71

    
72
                                if (osgCacheService.getManipulatorsActive())
73
                                        em.group();
74

    
75
                        } else if (actionCommand.equals("UNGROUP_MANIPULATOR")) {
76

    
77
                                if (osgCacheService.getManipulatorsActive())
78
                                        em.ungroup();
79

    
80
                        }
81

    
82
                }
83

    
84
        }
85

    
86
        public void initialize() {
87
                // TODO Auto-generated method stub
88

    
89
                // Registering icons.
90
                PluginServices.getIconTheme().registerDefault(
91
                                "rotation_manipulator",
92
                                this.getClass().getClassLoader().getResource(
93
                                                "images/rotation_manipulator.png"));
94

    
95
                PluginServices.getIconTheme().registerDefault(
96
                                "tabbox_manipulator",
97
                                this.getClass().getClassLoader().getResource(
98
                                                "images/tabbox_manipulator.gif"));
99

    
100
                PluginServices.getIconTheme().registerDefault(
101
                                "enable_manipulator",
102
                                this.getClass().getClassLoader()
103
                                                .getResource("images/pick2.png"));
104

    
105
                PluginServices.getIconTheme().registerDefault(
106
                                "group_manip",
107
                                this.getClass().getClassLoader()
108
                                                .getResource("images/group.png"));
109

    
110
                PluginServices.getIconTheme().registerDefault(
111
                                "ungroup_manip",
112
                                this.getClass().getClassLoader().getResource(
113
                                                "images/ungroup.png"));
114

    
115
                initEditTextHud();
116

    
117
        }
118

    
119
        public FLayer osgLayerActive() {
120

    
121
                FLayer activeLayer = null;
122
                // Getting view3
123
                com.iver.andami.ui.mdiManager.IWindow view = PluginServices
124
                                .getMDIManager().getActiveWindow();
125
                if ((view instanceof View3D)) {
126
                        // Casting to View3D
127
                        View3D vista3D = (View3D) view;
128

    
129
                        IProjectView model = vista3D.getModel();
130
                        MapContext mapa = model.getMapContext();
131
                        FLayer[] activeLayers = mapa.getLayers().getActives();
132
                        if (activeLayers.length == 1) {
133
                                FLayer layer = activeLayers[0];
134

    
135
                                Layer3DProps props3D = Layer3DProps.getLayer3DProps(layer);
136
                                if (props3D != null
137
                                                && props3D.getType() == Layer3DProps.layer3DOSG) {
138

    
139
                                        activeLayer = layer;
140
                                }
141

    
142
                        }
143
                }
144

    
145
                return activeLayer;
146

    
147
        }
148

    
149
        public boolean isEnabled() {
150

    
151
                FLayer layer = osgLayerActive();
152
                Layer3DProps props3D = Layer3DProps.getLayer3DProps(layer);
153
                if (props3D.isEditing()) {
154
                        return true;
155

    
156
                } else
157
                        return false;
158
        }
159

    
160
        public boolean isVisible() {
161

    
162
                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
        }
173

    
174
        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
                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
                b1.setEnabled(false);
191
                b2.setEnabled(false);
192

    
193
        }
194

    
195
        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
}