gvsig-3d / 2.0 / trunk / org.gvsig.gvsig3d.app / org.gvsig.gvsig3d.app.extension / src / main / java / org / gvsig / gvsig3d / app / extension / Manipulator3DExtension.java @ 365
History | View | Annotate | Download (4.11 KB)
1 | 346 | jzarzoso | package org.gvsig.gvsig3d.app.extension; |
---|---|---|---|
2 | |||
3 | import org.gvsig.fmap.dal.DataStore; |
||
4 | import org.gvsig.fmap.mapcontext.MapContext; |
||
5 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
6 | import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer; |
||
7 | import org.gvsig.gvsig3d.app.extension.DefaultView3DPanel; |
||
8 | import org.gvsig.gvsig3d.map3d.Layer3DProps; |
||
9 | import org.gvsig.gvsig3d.map3d.MapContext3D; |
||
10 | import org.gvsig.osgvp.manipulator.EditionManager; |
||
11 | import org.gvsig.osgvp.manipulator.Manipulator.DraggerType; |
||
12 | import org.gvsig.andami.PluginServices; |
||
13 | import org.gvsig.andami.plugins.Extension; |
||
14 | import org.gvsig.andami.ui.mdiManager.IWindow; |
||
15 | import org.gvsig.app.project.documents.view.ViewDocument; |
||
16 | |||
17 | 365 | jzarzoso | /**
|
18 | * @author AI2
|
||
19 | * @version $Id$
|
||
20 | *
|
||
21 | */
|
||
22 | 346 | jzarzoso | public class Manipulator3DExtension extends Extension { |
23 | |||
24 | private EditionManager em;
|
||
25 | |||
26 | public void execute(String actionCommand) { |
||
27 | |||
28 | // Getting View
|
||
29 | IWindow view = PluginServices.getMDIManager().getActiveWindow(); |
||
30 | if (!(view instanceof DefaultView3DPanel)) |
||
31 | return;
|
||
32 | // Casting to View3D
|
||
33 | DefaultView3DPanel vista3D = (DefaultView3DPanel) view; |
||
34 | |||
35 | ViewDocument model = vista3D.getModel(); |
||
36 | MapContext3D mapa = (MapContext3D) model.getMapContext(); |
||
37 | FLayer[] activeLayers = mapa.getLayers().getActives();
|
||
38 | if (activeLayers.length > 0) { |
||
39 | FLayer layer = activeLayers[0];
|
||
40 | |||
41 | Layer3DProps props3D = ((MapContext3D) layer.getMapContext()) |
||
42 | .getLayer3DProps(layer); |
||
43 | |||
44 | em = ((MapContext3D) layer.getMapContext()) |
||
45 | .getEditionManager(layer); |
||
46 | |||
47 | if (actionCommand.equals("ROTATION_MANIPULATOR")) { |
||
48 | em.changeDragger(DraggerType.TRACKBALL_DRAGGER); |
||
49 | em.setEnabledHandlers(true);
|
||
50 | } else if (actionCommand.equals("TABBOX_MANIPULATOR")) { |
||
51 | em.changeDragger(DraggerType.TABBOX_DRAGGER); |
||
52 | em.setEnabledHandlers(true);
|
||
53 | } else if (actionCommand.equals("GROUP_MANIPULATOR")) { |
||
54 | |||
55 | if (props3D.isEditing())
|
||
56 | em.group(); |
||
57 | |||
58 | } else if (actionCommand.equals("UNGROUP_MANIPULATOR")) { |
||
59 | |||
60 | if (props3D.isEditing())
|
||
61 | em.ungroup(); |
||
62 | |||
63 | } else if (actionCommand.equals("DELETE_MANIPULATOR")) { |
||
64 | |||
65 | if (props3D.isEditing())
|
||
66 | em.deleteSelectedNodes(); |
||
67 | |||
68 | } |
||
69 | |||
70 | } |
||
71 | |||
72 | } |
||
73 | |||
74 | public void initialize() { |
||
75 | // TODO Auto-generated method stub
|
||
76 | |||
77 | // Registering icons.
|
||
78 | PluginServices.getIconTheme().registerDefault( |
||
79 | "rotation_manipulator",
|
||
80 | this.getClass().getClassLoader()
|
||
81 | .getResource("images/rotation_manipulator.png"));
|
||
82 | |||
83 | PluginServices.getIconTheme().registerDefault( |
||
84 | "tabbox_manipulator",
|
||
85 | this.getClass().getClassLoader()
|
||
86 | .getResource("images/tabbox_manipulator.gif"));
|
||
87 | |||
88 | PluginServices.getIconTheme().registerDefault( |
||
89 | "group_manip",
|
||
90 | this.getClass().getClassLoader()
|
||
91 | .getResource("images/group.png"));
|
||
92 | |||
93 | PluginServices.getIconTheme().registerDefault( |
||
94 | "ungroup_manip",
|
||
95 | this.getClass().getClassLoader()
|
||
96 | .getResource("images/ungroup.png"));
|
||
97 | PluginServices.getIconTheme().registerDefault( |
||
98 | "delete_manip",
|
||
99 | this.getClass().getClassLoader()
|
||
100 | .getResource("images/delete.gif"));
|
||
101 | |||
102 | } |
||
103 | |||
104 | public FLayer osgLayerActive() {
|
||
105 | |||
106 | FLayer activeLayer = null;
|
||
107 | // Getting view3
|
||
108 | IWindow view = PluginServices.getMDIManager().getActiveWindow(); |
||
109 | if ((view instanceof DefaultView3DPanel)) { |
||
110 | // Casting to View3D
|
||
111 | DefaultView3DPanel vista3D = (DefaultView3DPanel) view; |
||
112 | |||
113 | ViewDocument model = vista3D.getModel(); |
||
114 | MapContext mapa = model.getMapContext(); |
||
115 | FLayer[] activeLayers = mapa.getLayers().getActives();
|
||
116 | if (activeLayers.length == 1) { |
||
117 | FLayer layer = activeLayers[0];
|
||
118 | DataStore ds = ((SingleLayer) layer).getDataStore(); |
||
119 | |||
120 | |||
121 | if (ds.getProviderName() == "OSG") { |
||
122 | |||
123 | activeLayer = layer; |
||
124 | } |
||
125 | |||
126 | } |
||
127 | } |
||
128 | |||
129 | return activeLayer;
|
||
130 | |||
131 | } |
||
132 | |||
133 | public boolean isEnabled() { |
||
134 | |||
135 | FLayer layer = osgLayerActive(); |
||
136 | Layer3DProps props3D = ((MapContext3D) layer.getMapContext()) |
||
137 | .getLayer3DProps(layer); |
||
138 | if (props3D.isEditing()) {
|
||
139 | return true; |
||
140 | |||
141 | } else
|
||
142 | return false; |
||
143 | } |
||
144 | |||
145 | public boolean isVisible() { |
||
146 | |||
147 | FLayer layer = osgLayerActive(); |
||
148 | |||
149 | if (layer != null) { |
||
150 | |||
151 | return true; |
||
152 | } else
|
||
153 | return false; |
||
154 | |||
155 | } |
||
156 | |||
157 | } |