Statistics
| Revision:

gvsig-3d / 1.10 / trunk / libraries / lib3DMap / src / org / gvsig / gvsig3d / listener / EditorListener.java @ 71

History | View | Annotate | Download (5.65 KB)

1
package org.gvsig.gvsig3d.listener;
2

    
3
/* gvSIG. Geographic Information System of the Valencian Government
4
 *  osgVP. OSG Virtual Planets.
5
 *
6
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
7
 * of the Valencian Government (CIT)
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22
 * MA  02110-1301, USA.
23
 *
24
 */
25
/*
26
 * AUTHORS (In addition to CIT):
27
 * 2008 Instituto de Automática e Informática Industrial, UPV.
28
 */
29

    
30
import java.awt.event.KeyEvent;
31
import java.awt.event.KeyListener;
32
import java.awt.event.MouseEvent;
33
import java.awt.event.MouseListener;
34
import java.util.logging.Level;
35

    
36
import org.apache.log4j.Logger;
37
import org.gvsig.gvsig3d.navigation.NavigationMode;
38
import org.gvsig.osgvp.core.osg.Group;
39
import org.gvsig.osgvp.core.osg.Node;
40
import org.gvsig.osgvp.exceptions.node.NodeException;
41
import org.gvsig.osgvp.manipulator.AddSelectionCommand;
42
import org.gvsig.osgvp.manipulator.EditionManager;
43
import org.gvsig.osgvp.manipulator.Manipulator;
44
import org.gvsig.osgvp.manipulator.ManipulatorHandler;
45
import org.gvsig.osgvp.manipulator.RemoveAllSelectionCommand;
46
import org.gvsig.osgvp.terrain.TerrainViewer;
47
import org.gvsig.osgvp.util.ActionCommand;
48
import org.gvsig.osgvp.util.Util;
49
import org.gvsig.osgvp.viewer.Camera;
50
import org.gvsig.osgvp.viewer.IViewerContainer;
51
import org.gvsig.osgvp.viewer.Intersection;
52
import org.gvsig.osgvp.viewer.Intersections;
53

    
54
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps;
55
import com.iver.cit.gvsig.fmap.layers.FLayer;
56

    
57
public class EditorListener implements MouseListener, KeyListener {
58

    
59
        private EditionManager _manager;
60
        private ManipulatorHandler _handler;
61
        private IViewerContainer _viewer;
62
        private FLayer _layer;
63
        IViewerContainer _canvas3d;
64
        private TerrainViewer _terrainViewer;
65
        private boolean _restoredNavigation = false;
66

    
67
        public EditorListener(EditionManager manager, ManipulatorHandler handler,
68
                        FLayer layer, IViewerContainer canvas3d, TerrainViewer terrainViewer) {
69

    
70
                _manager = manager;
71
                _handler = handler;
72
                _layer = layer;
73
                _canvas3d = canvas3d;
74
                _viewer = canvas3d;
75
                // _viewer.addMouseListener(this);
76
                // _viewer.addKeyListener(this);
77
                _terrainViewer = terrainViewer;
78
                
79

    
80
        }
81

    
82
        public void mouseDoubleClick(MouseEvent e) {
83

    
84
        }
85

    
86
        public void mouseDown(MouseEvent e) {
87

    
88
        }
89

    
90
        public void mouseUp(MouseEvent e) {
91

    
92
        }
93

    
94
        public void keyPressed(KeyEvent e) {
95

    
96
                if (e.getKeyCode() == KeyEvent.VK_CONTROL) {
97
                        _handler.setActive(false);
98
                        if (!_restoredNavigation) {
99
                                NavigationMode.restoreAllNavigationModes(_terrainViewer
100
                                                .getTerrainCameraManipulator());
101
                                _restoredNavigation = true;
102
                        }
103
                        
104

    
105
                } else if (e.getKeyCode() == KeyEvent.VK_G) {
106

    
107
                        _manager.group();
108

    
109
                } else if (e.getKeyCode() == KeyEvent.VK_U) {
110

    
111
                        _manager.ungroup();
112

    
113
                }
114

    
115
        }
116

    
117
        public void keyReleased(KeyEvent e) {
118

    
119
                if (e.getKeyCode() == KeyEvent.VK_CONTROL) {
120

    
121
                        _handler.setActive(true);
122
                        NavigationMode.removeAllNavigationModes(_terrainViewer
123
                                        .getTerrainCameraManipulator());
124
                        _restoredNavigation = false;
125
                        
126

    
127
                } else if (e.getKeyCode() == KeyEvent.VK_DELETE) {
128

    
129
                        if (Layer3DProps.getLayer3DProps(this._layer).isEditing()) {
130
                                _manager.deleteSelectedNodes();
131
                        }
132

    
133
                }
134

    
135
        }
136

    
137
        public void mouseClicked(MouseEvent e) {
138

    
139
                ActionCommand command;
140

    
141
                try {
142
                        if (e.getButton() == MouseEvent.BUTTON1) {
143
                                Intersections polytopeHits;
144
                        //        polytopeHits = _viewer.getOSGViewer().polytopePick(this._manager.getScene(),  e.getX(), e.getY(),20, Manipulator.NEG_MANIPULATOR_NODEMASK);
145
                                
146
                                        polytopeHits = _viewer.getOSGViewer().rayPick(
147
                                                this._manager.getScene(), e.getX(), e.getY(),
148
                                                Manipulator.NEG_MANIPULATOR_NODEMASK);
149
                        
150
                                if (polytopeHits.containsIntersections()) {
151
                                        System.out.println("entro a ver que paisa");
152
                                        Intersection hit = polytopeHits.getFirstIntersection();
153
                                        
154
                                        Node nodeHit = (Node) hit.getNodePath().get(1);
155
                                        System.out.println("Node name: " + nodeHit.getNodeName());
156
                                        /*
157
                                         * Group parent; parent = new
158
                                         * Group(nodeHit.getParent(0).getCPtr()); int k; k =
159
                                         * parent.getChildIndex(nodeHit); command = new
160
                                         * AddSelectionCommand(k, _manager); command.execute();
161
                                         * 
162
                                         * System.out.println("SELECTED A TRUE!");
163
                                         */
164
                                        int k;
165
                                        try {
166
                                                k = nodeHit.getParent(0).getChildIndex(nodeHit);
167

    
168
                                                AddSelectionCommand addCommand = new AddSelectionCommand(
169
                                                                k, _manager);
170
                                                addCommand.execute();
171

    
172
                                        } catch (NodeException e1) {
173
                                                // TODO Auto-generated catch block
174
                                                e1.printStackTrace();
175
                                        }
176

    
177
                                }
178

    
179
                                else {
180

    
181
                                        command = new RemoveAllSelectionCommand(_manager);
182
                                        command.execute();
183

    
184
                                }
185
                        }
186
                } catch (NodeException e2) {
187
                        // TODO Auto-generated catch block
188
                        e2.printStackTrace();
189
                }
190

    
191
        }
192

    
193
        public void mouseEntered(MouseEvent e) {
194
                // TODO Auto-generated method stub
195

    
196
        }
197

    
198
        public void mouseExited(MouseEvent e) {
199
                // TODO Auto-generated method stub
200

    
201
        }
202

    
203
        public void mousePressed(MouseEvent e) {
204
                // TODO Auto-generated method stub
205

    
206
        }
207

    
208
        public void mouseReleased(MouseEvent e) {
209
                // TODO Auto-generated method stub
210

    
211
        }
212

    
213
        public void keyTyped(KeyEvent e) {
214
                // TODO Auto-generated method stub
215

    
216
        }
217

    
218
}