gvsig-3d / 2.0 / trunk / org.gvsig.gvsig3d.app / org.gvsig.gvsig3d.app.extension / src / main / java / org / gvsig / gvsig3d / app / import3D / ControlImport3D.java @ 348
History | View | Annotate | Download (24.4 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
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 |
|
20 |
package org.gvsig.gvsig3d.app.import3D; |
21 |
|
22 |
import java.awt.BorderLayout; |
23 |
import java.awt.Component; |
24 |
import java.awt.GridLayout; |
25 |
import java.awt.Point; |
26 |
import java.awt.event.ActionEvent; |
27 |
import java.awt.event.ActionListener; |
28 |
import java.awt.event.KeyEvent; |
29 |
import java.awt.event.MouseEvent; |
30 |
import java.awt.event.MouseListener; |
31 |
import java.awt.geom.Point2D; |
32 |
import java.io.File; |
33 |
import java.io.FileInputStream; |
34 |
import java.io.FileNotFoundException; |
35 |
import java.util.Hashtable; |
36 |
import java.util.Iterator; |
37 |
import java.util.Vector; |
38 |
|
39 |
import javax.swing.JButton; |
40 |
import javax.swing.JFileChooser; |
41 |
import javax.swing.JLabel; |
42 |
import javax.swing.JOptionPane; |
43 |
import javax.swing.JPanel; |
44 |
import javax.swing.JTextField; |
45 |
import javax.swing.border.TitledBorder; |
46 |
import javax.swing.filechooser.FileFilter; |
47 |
|
48 |
import org.gvsig.andami.PluginServices; |
49 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
50 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
51 |
import org.gvsig.app.project.documents.view.ViewDocument; |
52 |
import org.gvsig.fmap.dal.exception.DataException; |
53 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
54 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
55 |
import org.gvsig.fmap.dal.feature.FeatureType; |
56 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore; |
57 |
import org.gvsig.fmap.dal.feature.spi.DefaultFeatureProvider; |
58 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
59 |
import org.gvsig.fmap.dal.feature.spi.memory.AbstractMemoryStoreProvider; |
60 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
61 |
import org.gvsig.fmap.geom.GeometryLocator; |
62 |
import org.gvsig.fmap.geom.GeometryManager; |
63 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
64 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
65 |
import org.gvsig.fmap.geom.primitive.Envelope; |
66 |
import org.gvsig.fmap.mapcontext.MapContext; |
67 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
68 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
69 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
70 |
import org.gvsig.gui.beans.datainput.DataInputField; |
71 |
import org.gvsig.gvsig3d.app.extension.DefaultView3DPanel; |
72 |
import org.gvsig.gvsig3d.map3d.Layer3DProps; |
73 |
import org.gvsig.gvsig3d.map3d.MapContext3D; |
74 |
import org.gvsig.osgvp.core.osg.Node; |
75 |
import org.gvsig.osgvp.core.osg.PositionAttitudeTransform; |
76 |
import org.gvsig.osgvp.core.osg.Vec3; |
77 |
import org.gvsig.osgvp.core.osgdb.osgDB; |
78 |
import org.gvsig.osgvp.exceptions.node.LoadNodeException; |
79 |
import org.gvsig.osgvp.exceptions.node.NodeException; |
80 |
import org.gvsig.osgvp.manipulator.EditionManager; |
81 |
import org.gvsig.osgvp.viewer.Intersections; |
82 |
|
83 |
/**
|
84 |
* @author ?ngel Fraile Gri??n e-mail: angel.fraile@iver.es
|
85 |
* @since 1.1
|
86 |
*
|
87 |
*/
|
88 |
public class ControlImport3D extends JPanel implements IWindow, ActionListener, |
89 |
MouseListener {
|
90 |
|
91 |
private static final long serialVersionUID = 8557746972654979029L; |
92 |
|
93 |
private int tipoObjectImport; |
94 |
private DefaultView3DPanel _view3D;
|
95 |
private File _fileOSG = null; |
96 |
private FileInputStream _fileInput = null; |
97 |
private Vec3 _position = new Vec3(0, 0, 0); |
98 |
private Hashtable iveExtensionsSupported = null; |
99 |
private Hashtable osgExtensionsSupported = null; |
100 |
private String lastPath = null; |
101 |
private JPanel panelPosition; |
102 |
private JPanel panelAux; |
103 |
private JPanel panelPath; |
104 |
private JPanel panelButtons; |
105 |
private JPanel panelObjectPosition; |
106 |
private TitledBorder borderPanelPosition; |
107 |
private TitledBorder borderPanelPath; |
108 |
private JLabel labelInfo; |
109 |
private JLabel labelLatitud; |
110 |
private JLabel labelLongitud; |
111 |
private JLabel labelAltura; |
112 |
private JLabel labelX; |
113 |
private JLabel labelY; |
114 |
private JLabel labelEscaladoX; |
115 |
private JLabel labelEscaladoY; |
116 |
private JLabel labelEscaladoZ; |
117 |
private JLabel labelRotacionX; |
118 |
private JLabel labelRotacionY; |
119 |
private JLabel labelRotacionZ; |
120 |
private JTextField textFile; |
121 |
private DataInputField textLatitud;
|
122 |
private DataInputField textLongitud;
|
123 |
private DataInputField textAltura;
|
124 |
private DataInputField textX;
|
125 |
private DataInputField textY;
|
126 |
private DataInputField textEscaladoX;
|
127 |
private DataInputField textEscaladoY;
|
128 |
private DataInputField textEscaladoZ;
|
129 |
private DataInputField textRotacionX;
|
130 |
private DataInputField textRotacionY;
|
131 |
private DataInputField textRotacionZ;
|
132 |
private JButton buttonImport; |
133 |
private JButton buttonAccept; |
134 |
private JButton buttonCancel; |
135 |
|
136 |
private int ID_FIELD_ID = 0; |
137 |
private int ID_FIELD_GEOMETRY = 1; |
138 |
|
139 |
/**
|
140 |
* Building the panel options
|
141 |
*
|
142 |
* @param tipoObjeto
|
143 |
* @param vista3D
|
144 |
* : actual 3D view selected
|
145 |
*/
|
146 |
public ControlImport3D(int tipoObjeto, DefaultView3DPanel view3D) { |
147 |
|
148 |
tipoObjectImport = tipoObjeto; |
149 |
_view3D = view3D; |
150 |
|
151 |
initialize(); |
152 |
|
153 |
_view3D.getCanvas3d().addMouseListener(this);
|
154 |
|
155 |
} |
156 |
|
157 |
public void initialize() { |
158 |
this.setLayout(new BorderLayout(5, 5)); |
159 |
this.add(getPanelAux(), BorderLayout.NORTH); |
160 |
// fake panel to grow up with the windows
|
161 |
// beacause the window is always resizable with docking skin
|
162 |
this.add(new JPanel(), BorderLayout.CENTER); |
163 |
} |
164 |
|
165 |
public JPanel getPanelAux() { |
166 |
if (panelAux == null) { |
167 |
panelAux = new JPanel(new BorderLayout()); |
168 |
panelAux.add(getPanelPosition(), BorderLayout.NORTH);
|
169 |
panelAux.add(getPanelFile(), BorderLayout.CENTER);
|
170 |
panelAux.add(getPanelButtons(), BorderLayout.SOUTH);
|
171 |
} |
172 |
|
173 |
return panelAux;
|
174 |
} |
175 |
|
176 |
public JPanel getPanelPosition() { |
177 |
if (panelPosition == null) { |
178 |
|
179 |
panelPosition = new JPanel(); |
180 |
panelPosition.setLayout(new BorderLayout(5, 5)); |
181 |
|
182 |
borderPanelPosition = new TitledBorder(PluginServices.getText(this, |
183 |
"Opciones_de_objeto"));
|
184 |
panelPosition.setBorder(this.borderPanelPosition);
|
185 |
|
186 |
labelInfo = new JLabel(PluginServices.getText(this, |
187 |
"input_object_info"), JLabel.LEFT); |
188 |
|
189 |
panelObjectPosition = new JPanel(); |
190 |
panelObjectPosition.setLayout(new GridLayout(5, 6, 5, 5)); |
191 |
|
192 |
textLatitud = new DataInputField();
|
193 |
labelLatitud = new JLabel(PluginServices.getText(this, "Latitude"), |
194 |
JLabel.RIGHT);
|
195 |
|
196 |
textLongitud = new DataInputField();
|
197 |
labelLongitud = new JLabel( |
198 |
PluginServices.getText(this, "Longitude"), JLabel.RIGHT); |
199 |
|
200 |
textAltura = new DataInputField();
|
201 |
labelAltura = new JLabel(PluginServices.getText(this, "Hight"), |
202 |
JLabel.RIGHT);
|
203 |
|
204 |
textX = new DataInputField();
|
205 |
labelX = new JLabel(PluginServices.getText(this, "Coordinate_X"), |
206 |
JLabel.RIGHT);
|
207 |
|
208 |
textY = new DataInputField();
|
209 |
labelY = new JLabel(PluginServices.getText(this, "Coordinate_Y"), |
210 |
JLabel.RIGHT);
|
211 |
|
212 |
textEscaladoX = new DataInputField();
|
213 |
textEscaladoX.setValue("1");
|
214 |
labelEscaladoX = new JLabel(PluginServices.getText(this, |
215 |
"EscaladoX"), JLabel.RIGHT); |
216 |
|
217 |
textEscaladoY = new DataInputField();
|
218 |
textEscaladoY.setValue("1");
|
219 |
labelEscaladoY = new JLabel(PluginServices.getText(this, |
220 |
"EscaladoY"), JLabel.RIGHT); |
221 |
|
222 |
textEscaladoZ = new DataInputField();
|
223 |
textEscaladoZ.setValue("1");
|
224 |
labelEscaladoZ = new JLabel(PluginServices.getText(this, |
225 |
"EscaladoZ"), JLabel.RIGHT); |
226 |
|
227 |
textRotacionX = new DataInputField();
|
228 |
labelRotacionX = new JLabel(PluginServices.getText(this, |
229 |
"Rotation_degreesX"), JLabel.RIGHT); |
230 |
|
231 |
textRotacionY = new DataInputField();
|
232 |
labelRotacionY = new JLabel(PluginServices.getText(this, |
233 |
"Rotation_degreesY"), JLabel.RIGHT); |
234 |
|
235 |
textRotacionZ = new DataInputField();
|
236 |
labelRotacionZ = new JLabel(PluginServices.getText(this, |
237 |
"Rotation_degreesZ"), JLabel.RIGHT); |
238 |
|
239 |
panelObjectPosition.add(this.labelLatitud);
|
240 |
panelObjectPosition.add(this.textLatitud);
|
241 |
panelObjectPosition.add(this.labelX);
|
242 |
panelObjectPosition.add(this.textX);
|
243 |
panelObjectPosition.add(new JPanel()); |
244 |
panelObjectPosition.add(new JPanel()); |
245 |
|
246 |
panelObjectPosition.add(this.labelLongitud);
|
247 |
panelObjectPosition.add(this.textLongitud);
|
248 |
panelObjectPosition.add(this.labelY);
|
249 |
panelObjectPosition.add(this.textY);
|
250 |
panelObjectPosition.add(new JPanel()); |
251 |
panelObjectPosition.add(new JPanel()); |
252 |
|
253 |
panelObjectPosition.add(this.labelAltura);
|
254 |
panelObjectPosition.add(this.textAltura);
|
255 |
panelObjectPosition.add(new JPanel()); |
256 |
panelObjectPosition.add(new JPanel()); |
257 |
panelObjectPosition.add(new JPanel()); |
258 |
panelObjectPosition.add(new JPanel()); |
259 |
|
260 |
panelObjectPosition.add(this.labelEscaladoX);
|
261 |
panelObjectPosition.add(this.textEscaladoX);
|
262 |
panelObjectPosition.add(this.labelEscaladoY);
|
263 |
panelObjectPosition.add(this.textEscaladoY);
|
264 |
panelObjectPosition.add(this.labelEscaladoZ);
|
265 |
panelObjectPosition.add(this.textEscaladoZ);
|
266 |
|
267 |
panelObjectPosition.add(this.labelRotacionX);
|
268 |
panelObjectPosition.add(this.textRotacionX);
|
269 |
panelObjectPosition.add(this.labelRotacionY);
|
270 |
panelObjectPosition.add(this.textRotacionY);
|
271 |
panelObjectPosition.add(this.labelRotacionZ);
|
272 |
panelObjectPosition.add(this.textRotacionZ);
|
273 |
|
274 |
panelPosition.add(labelInfo, BorderLayout.NORTH);
|
275 |
panelPosition.add(panelObjectPosition, BorderLayout.SOUTH);
|
276 |
} |
277 |
return panelPosition;
|
278 |
} |
279 |
|
280 |
public JPanel getPanelFile() { |
281 |
if (panelPath == null) { |
282 |
panelPath = new JPanel(); |
283 |
panelPath.setLayout(new BorderLayout(5, 5)); |
284 |
|
285 |
borderPanelPath = new TitledBorder(PluginServices.getText(this, |
286 |
"File"));
|
287 |
panelPath.setBorder(borderPanelPath); |
288 |
|
289 |
textFile = new JTextField(); |
290 |
textFile.setBounds(new java.awt.Rectangle(5, 10, 350, 23)); |
291 |
textFile.addKeyListener(new java.awt.event.KeyAdapter() {
|
292 |
public void keyReleased(KeyEvent arg0) { |
293 |
if (!textFile.getText().equals("")) |
294 |
buttonAccept.setEnabled(true);
|
295 |
else
|
296 |
buttonAccept.setEnabled(false);
|
297 |
} |
298 |
|
299 |
}); |
300 |
|
301 |
buttonImport = new JButton(); |
302 |
buttonImport.setText("...");
|
303 |
buttonImport.setBounds(new java.awt.Rectangle(355, 10, 32, 22)); |
304 |
buttonImport.addActionListener(this);
|
305 |
|
306 |
panelPath.add(textFile, BorderLayout.CENTER);
|
307 |
panelPath.add(buttonImport, BorderLayout.EAST);
|
308 |
|
309 |
} |
310 |
|
311 |
return panelPath;
|
312 |
} |
313 |
|
314 |
public JPanel getPanelButtons() { |
315 |
if (panelButtons == null) { |
316 |
JPanel panelButtonsAux = new JPanel(); |
317 |
panelButtonsAux.setLayout(new GridLayout(1, 2, 5, 5)); |
318 |
|
319 |
panelButtons = new JPanel(); |
320 |
panelButtons.setLayout(new BorderLayout()); |
321 |
|
322 |
buttonAccept = new JButton(PluginServices.getText(this, "Accept")); |
323 |
buttonAccept.addActionListener(this);
|
324 |
buttonAccept.setEnabled(false);
|
325 |
|
326 |
buttonCancel = new JButton(PluginServices.getText(this, "Cancel")); |
327 |
buttonCancel.addActionListener(this);
|
328 |
|
329 |
panelButtonsAux.add(buttonAccept); |
330 |
panelButtonsAux.add(buttonCancel); |
331 |
panelButtons.add(panelButtonsAux, BorderLayout.EAST);
|
332 |
} |
333 |
|
334 |
return panelButtons;
|
335 |
} |
336 |
|
337 |
/**
|
338 |
* Window properties
|
339 |
*
|
340 |
* @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
|
341 |
*/
|
342 |
|
343 |
public WindowInfo getWindowInfo() {
|
344 |
WindowInfo m_viewinfo = new WindowInfo(WindowInfo.TOOL_PROFILE);
|
345 |
String cad = null; |
346 |
|
347 |
if (tipoObjectImport == 0) |
348 |
cad = "Importar_Objeto_3D";
|
349 |
else if (tipoObjectImport == 1) |
350 |
cad = "Importar_Objeto_3D_Vectorial";
|
351 |
|
352 |
m_viewinfo.setTitle(PluginServices.getText(this, cad));
|
353 |
m_viewinfo.setHeight(280);
|
354 |
m_viewinfo.setWidth(500);
|
355 |
return m_viewinfo;
|
356 |
} |
357 |
|
358 |
/**
|
359 |
* Buttons events listener
|
360 |
*/
|
361 |
public void actionPerformed(ActionEvent event) { |
362 |
if (event.getSource() == this.buttonImport) { |
363 |
actionPerformedImport(); |
364 |
|
365 |
} |
366 |
if (event.getSource() == this.buttonAccept) { |
367 |
actionPerformedAccept(); |
368 |
|
369 |
} |
370 |
if (event.getSource() == this.buttonCancel) { |
371 |
PluginServices.getMDIManager().closeWindow(this);
|
372 |
} |
373 |
} |
374 |
|
375 |
/**
|
376 |
* Accept button listener
|
377 |
*/
|
378 |
private void actionPerformedAccept() { |
379 |
|
380 |
if (_fileOSG == null) {// of the user write the file |
381 |
if (getJTextFieldFichero().equals("")) { |
382 |
JOptionPane.showMessageDialog(null, |
383 |
PluginServices.getText(this, "root_in"), |
384 |
PluginServices.getText(this, "no_file"), |
385 |
JOptionPane.WARNING_MESSAGE);
|
386 |
return;
|
387 |
} else {
|
388 |
_fileOSG = new File(getJTextFieldFichero()); |
389 |
if (!_fileOSG.exists()) {
|
390 |
JOptionPane.showMessageDialog(null, |
391 |
PluginServices.getText(this, "no_root"), |
392 |
PluginServices.getText(this, "no_file2"), |
393 |
JOptionPane.WARNING_MESSAGE);
|
394 |
_fileOSG = null;
|
395 |
this.setTextFieldFichero();
|
396 |
return;
|
397 |
} |
398 |
} |
399 |
|
400 |
} else {
|
401 |
try {
|
402 |
if (!_fileOSG.exists()) {
|
403 |
JOptionPane.showMessageDialog(null, |
404 |
PluginServices.getText(this, "root_in"), |
405 |
PluginServices.getText(this, "no_file"), |
406 |
JOptionPane.WARNING_MESSAGE);
|
407 |
return;
|
408 |
} |
409 |
_fileInput = new FileInputStream(_fileOSG); |
410 |
|
411 |
} catch (FileNotFoundException e) { |
412 |
e.printStackTrace(); |
413 |
} |
414 |
} |
415 |
|
416 |
// OSGDriver _osgDriver = new OSGDriver();
|
417 |
// OSGParser parser = new OSGParser("OSG", "OSG File Formats Parser");
|
418 |
// parser.parse(_osgDriver, null, _fileOSG.toURI());
|
419 |
// MultiGeometry root = _osgDriver.getRootFeature();
|
420 |
|
421 |
ViewDocument model = _view3D.getModel(); |
422 |
MapContext mapContext = model.getMapContext(); |
423 |
FLayers layers = mapContext.getLayers(); |
424 |
FLayer[] actives = layers.getActives();
|
425 |
Layer3DProps props3D = ((MapContext3D) actives[0].getMapContext())
|
426 |
.getLayer3DProps(actives[0]);
|
427 |
if (actives.length == 1 && props3D.getType() == Layer3DProps.layer3DOSG) { |
428 |
|
429 |
Vec3 scale = new Vec3(Double.parseDouble(textEscaladoX.getValue()), |
430 |
Double.parseDouble(textEscaladoY.getValue()),
|
431 |
Double.parseDouble(textEscaladoZ.getValue()));
|
432 |
Vec3 rotation = new Vec3(Double.parseDouble(textRotacionX |
433 |
.getValue()), Double.parseDouble(textRotacionY.getValue()),
|
434 |
Double.parseDouble(textRotacionZ.getValue()));
|
435 |
// osgCache.AddGeometryToLayer(root,_position,rotation,scale);
|
436 |
|
437 |
try {
|
438 |
// If you want to use Optimizer take care because texure could
|
439 |
// disappear.
|
440 |
// Optimizer opt = new Optimizer();
|
441 |
|
442 |
MapContext3D m3d = ((MapContext3D) actives[0].getMapContext());
|
443 |
|
444 |
Node n = osgDB.readNodeFile(_fileOSG.toString()); |
445 |
// opt.optimize(n);
|
446 |
// osgCache.AddNodeToLayer(n, _position, rotation, scale);
|
447 |
EditionManager em = m3d.getEditionManager(actives[0]);
|
448 |
|
449 |
Vector<Vec3> origTrans = n.getBoundingBox();
|
450 |
|
451 |
PositionAttitudeTransform posAttTrasn = null;
|
452 |
posAttTrasn = new PositionAttitudeTransform();
|
453 |
posAttTrasn.setPosition(_position); |
454 |
posAttTrasn.setScale(scale); |
455 |
posAttTrasn.setNodeName("PAT");
|
456 |
posAttTrasn.addChild(n); |
457 |
|
458 |
em.setScene(posAttTrasn); |
459 |
|
460 |
// A?adir un punto a la capa con el valor de la posicion del
|
461 |
// objeto
|
462 |
|
463 |
addPointToStore((FLyrVect) actives[0], posAttTrasn);
|
464 |
|
465 |
} catch (LoadNodeException e) {
|
466 |
// TODO Auto-generated catch block
|
467 |
e.printStackTrace(); |
468 |
} catch (FileNotFoundException e) { |
469 |
// TODO Auto-generated catch block
|
470 |
e.printStackTrace(); |
471 |
} catch (NodeException e) {
|
472 |
// TODO Auto-generated catch block
|
473 |
e.printStackTrace(); |
474 |
} |
475 |
|
476 |
} else {
|
477 |
JOptionPane.showMessageDialog(null, |
478 |
PluginServices.getText(this, "editable_layer_select_info"), |
479 |
PluginServices.getText(this, "editable_layer_select"), |
480 |
JOptionPane.WARNING_MESSAGE);
|
481 |
return;
|
482 |
} |
483 |
|
484 |
_view3D.getCanvas3d().removeMouseListener(this);
|
485 |
PluginServices.getMDIManager().closeWindow(this);
|
486 |
} |
487 |
|
488 |
private void addPointToStore(FLyrVect layer, Node node) { |
489 |
|
490 |
try {
|
491 |
Envelope envelope; |
492 |
Vector<Vec3> bound = node.getBoundingBox();
|
493 |
GeometryManager geometryManager = GeometryLocator |
494 |
.getGeometryManager(); |
495 |
org.gvsig.fmap.geom.primitive.Point min = geometryManager |
496 |
.createPoint(bound.get(0).x(), bound.get(0).y(), |
497 |
SUBTYPES.GEOM3D); |
498 |
min.setCoordinateAt(2, bound.get(0).z()); |
499 |
org.gvsig.fmap.geom.primitive.Point max = geometryManager |
500 |
.createPoint(bound.get(1).x(), bound.get(1).y(), |
501 |
SUBTYPES.GEOM3D); |
502 |
max.setCoordinateAt(2, bound.get(1).z()); |
503 |
envelope = geometryManager.createEnvelope(SUBTYPES.GEOM3D); |
504 |
envelope.setLowerCorner(min); |
505 |
envelope.setUpperCorner(max); |
506 |
double centerx = envelope.getCenter(0); |
507 |
double centery = envelope.getCenter(1); |
508 |
double centerz = envelope.getCenter(2); |
509 |
org.gvsig.fmap.geom.primitive.Point geom = geometryManager |
510 |
.createPoint(centerx, centery, SUBTYPES.GEOM3D); |
511 |
geom.setCoordinateAt(2, centerz);
|
512 |
|
513 |
FeatureStore fStore = (FeatureStore) layer.getDataStore(); |
514 |
|
515 |
fStore.getEnvelope().add(envelope); |
516 |
fStore.edit(FeatureStore.MODE_FULLEDIT); |
517 |
FeatureType featureType = ((EditableFeatureType) fStore |
518 |
.getFeatureTypes().get(0)).getNotEditableCopy();
|
519 |
// EditableFeature feature =
|
520 |
// fStore.createNewFeature(fStore.getDefaultFeatureType(),true);
|
521 |
|
522 |
FeatureProvider fProvider = new DefaultFeatureProvider(featureType);
|
523 |
|
524 |
fProvider.set(0, fStore.getFeatureCount());
|
525 |
fProvider.set(1, geom);
|
526 |
fProvider.setDefaultGeometry(geom); |
527 |
|
528 |
((AbstractMemoryStoreProvider) ((DefaultFeatureStore) fStore) |
529 |
.getProvider()).addFeatureProvider(fProvider); |
530 |
|
531 |
fStore.finishEditing(); |
532 |
|
533 |
} catch (DataException e) {
|
534 |
// TODO Auto-generated catch block
|
535 |
e.printStackTrace(); |
536 |
} catch (CreateGeometryException e) {
|
537 |
// TODO Auto-generated catch block
|
538 |
e.printStackTrace(); |
539 |
} catch (CreateEnvelopeException e) {
|
540 |
// TODO Auto-generated catch block
|
541 |
e.printStackTrace(); |
542 |
} |
543 |
|
544 |
} |
545 |
|
546 |
/**
|
547 |
* Import file button listener
|
548 |
*/
|
549 |
private void actionPerformedImport() { |
550 |
JFileChooser jfc = new JFileChooser(lastPath); |
551 |
jfc.removeChoosableFileFilter(jfc.getAcceptAllFileFilter()); |
552 |
iveExtensionsSupported = new Hashtable(); |
553 |
osgExtensionsSupported = new Hashtable(); |
554 |
osgExtensionsSupported.put("osg", new MyFileFilter("osg", |
555 |
PluginServices.getText(this, "Ficheros *.osg"), "osg")); |
556 |
iveExtensionsSupported.put("ive", new MyFileFilter("ive", |
557 |
PluginServices.getText(this, "Ficheros *.ive"), "ive")); |
558 |
iveExtensionsSupported.put("obj", new MyFileFilter("obj", |
559 |
PluginServices.getText(this, "Ficheros *.obj"), "obj")); |
560 |
iveExtensionsSupported.put("dae", new MyFileFilter("dae", |
561 |
PluginServices.getText(this, "Ficheros *.dae"), "dae")); |
562 |
iveExtensionsSupported.put("3ds", new MyFileFilter("3ds", |
563 |
PluginServices.getText(this, "Ficheros *.3ds"), "3ds")); |
564 |
iveExtensionsSupported.put("3dc", new MyFileFilter("3dc", |
565 |
PluginServices.getText(this, "Ficheros *.3dc"), "3dc")); |
566 |
iveExtensionsSupported.put( |
567 |
"*",
|
568 |
new MyFileFilter("*", PluginServices.getText(this, |
569 |
"Ficheros *.*"), "*.*")); |
570 |
|
571 |
Iterator iter = osgExtensionsSupported.values().iterator();
|
572 |
|
573 |
while (iter.hasNext()) {
|
574 |
jfc.addChoosableFileFilter((FileFilter) iter.next());
|
575 |
} |
576 |
|
577 |
iter = iveExtensionsSupported.values().iterator(); |
578 |
while (iter.hasNext()) {
|
579 |
jfc.addChoosableFileFilter((FileFilter) iter.next());
|
580 |
} |
581 |
|
582 |
if (jfc.showOpenDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
583 |
|
584 |
_fileOSG = jfc.getSelectedFile(); |
585 |
if (_fileOSG.exists()) {// file don't exists in the directory. |
586 |
|
587 |
MyFileFilter filter = (MyFileFilter) jfc.getFileFilter(); |
588 |
_fileOSG = filter.normalizeExtension(_fileOSG); |
589 |
textFile.setText(_fileOSG.getAbsolutePath()); |
590 |
} else {
|
591 |
JOptionPane.showMessageDialog(null, |
592 |
PluginServices.getText(this, "no_root"), |
593 |
PluginServices.getText(this, "no_file2"), |
594 |
JOptionPane.WARNING_MESSAGE);
|
595 |
return;
|
596 |
} |
597 |
buttonAccept.setEnabled(true);
|
598 |
}// If aprove option.
|
599 |
else {
|
600 |
buttonAccept.setEnabled(false);
|
601 |
} |
602 |
} |
603 |
|
604 |
/**
|
605 |
* Getters and Setters of all TextFields values
|
606 |
*/
|
607 |
public String getJTextFieldFichero() { |
608 |
// return textFile.getText();
|
609 |
return null; |
610 |
} |
611 |
|
612 |
public void setTextFieldFichero() { |
613 |
// textFile.setText(null);
|
614 |
} |
615 |
|
616 |
/*
|
617 |
* All MouseListener methods
|
618 |
*/
|
619 |
public void mouseClicked(MouseEvent e) { |
620 |
// TODO Auto-generated method stub
|
621 |
} |
622 |
|
623 |
public void mouseEntered(MouseEvent e) { |
624 |
// TODO Auto-generated method stub
|
625 |
|
626 |
} |
627 |
|
628 |
public void mouseExited(MouseEvent e) { |
629 |
// TODO Auto-generated method stub
|
630 |
|
631 |
} |
632 |
|
633 |
public void mousePressed(MouseEvent e) { |
634 |
// TODO Auto-generated method stub
|
635 |
} |
636 |
|
637 |
public void mouseReleased(MouseEvent e) { |
638 |
|
639 |
Point pScreen = e.getPoint();
|
640 |
|
641 |
if (e.getButton() == MouseEvent.BUTTON1) { |
642 |
Vec3 intersection = null;
|
643 |
|
644 |
textX.setValue(Double.toString(pScreen.getX()));
|
645 |
textY.setValue(Double.toString(pScreen.getY()));
|
646 |
|
647 |
ViewDocument model = _view3D.getModel(); |
648 |
|
649 |
MapContext3D mcontext = (MapContext3D) model.getMapContext(); |
650 |
mcontext.getCanvas3d(); |
651 |
|
652 |
Intersections hits = mcontext.getCanvas3d().getOSGViewer() |
653 |
.rayPick((int) pScreen.getX(), (int) pScreen.getY()); |
654 |
Point2D pWorld = new Point2D.Double(); |
655 |
if (hits.containsIntersections()) {
|
656 |
Vec3 hit = hits.getFirstIntersection().getIntersectionPoint(); |
657 |
// convert to geo coordinates
|
658 |
_position = hit; |
659 |
if (mcontext.getProjection().getAbrev()
|
660 |
.compareToIgnoreCase("EPSG:4326") == 0) { |
661 |
Vec3 geoPt = mcontext.getTerrain() |
662 |
.convertXYZToLatLongHeight(hit); |
663 |
// Swap the coordinates X and Y, because they are invert.
|
664 |
intersection = new Vec3(geoPt.y(), geoPt.x(), geoPt.z());
|
665 |
} else {
|
666 |
intersection = hit; |
667 |
} |
668 |
} else {
|
669 |
if (mcontext.getProjection().getAbrev()
|
670 |
.compareToIgnoreCase("EPSG:4326") == 0) { |
671 |
pWorld.setLocation(360, 120); |
672 |
intersection = new Vec3(360, 120, 0); |
673 |
} else {
|
674 |
intersection = new Vec3(1e100, 1e100, 0); |
675 |
// pWorld.setLocation(1e100, 1e100);
|
676 |
} |
677 |
} |
678 |
|
679 |
textLatitud.setValue(Double.toString(intersection.x()));
|
680 |
textLongitud.setValue(Double.toString(intersection.y()));
|
681 |
|
682 |
textAltura.setValue(Double.toString(intersection.z()));
|
683 |
|
684 |
}// if e.getButton()
|
685 |
}// if hits
|
686 |
|
687 |
public Object getWindowProfile() { |
688 |
return WindowInfo.PROPERTIES_PROFILE;
|
689 |
} |
690 |
|
691 |
} |
692 |
|
693 |
/**
|
694 |
*
|
695 |
* @version 14/08/2007
|
696 |
* @author Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
697 |
*
|
698 |
*/
|
699 |
class MyFileFilter extends FileFilter { |
700 |
|
701 |
private String[] extensiones = new String[1]; |
702 |
private String description; |
703 |
private boolean dirs = true; |
704 |
private String info = null; |
705 |
|
706 |
public MyFileFilter(String[] ext, String desc) { |
707 |
extensiones = ext; |
708 |
description = desc; |
709 |
} |
710 |
|
711 |
public MyFileFilter(String[] ext, String desc, String info) { |
712 |
extensiones = ext; |
713 |
description = desc; |
714 |
this.info = info;
|
715 |
} |
716 |
|
717 |
public MyFileFilter(String ext, String desc) { |
718 |
extensiones[0] = ext;
|
719 |
description = desc; |
720 |
} |
721 |
|
722 |
public MyFileFilter(String ext, String desc, String info) { |
723 |
extensiones[0] = ext;
|
724 |
description = desc; |
725 |
this.info = info;
|
726 |
} |
727 |
|
728 |
public MyFileFilter(String ext, String desc, boolean dirs) { |
729 |
extensiones[0] = ext;
|
730 |
description = desc; |
731 |
this.dirs = dirs;
|
732 |
} |
733 |
|
734 |
public MyFileFilter(String ext, String desc, boolean dirs, String info) { |
735 |
extensiones[0] = ext;
|
736 |
description = desc; |
737 |
this.dirs = dirs;
|
738 |
this.info = info;
|
739 |
} |
740 |
|
741 |
public boolean accept(File f) { |
742 |
if (f.isDirectory()) {
|
743 |
if (dirs) {
|
744 |
return true; |
745 |
} else {
|
746 |
return false; |
747 |
} |
748 |
} |
749 |
for (int i = 0; i < extensiones.length; i++) { |
750 |
if (extensiones[i].equals("")) { |
751 |
continue;
|
752 |
} |
753 |
if (getExtensionOfAFile(f).equalsIgnoreCase(extensiones[i])) {
|
754 |
return true; |
755 |
} |
756 |
} |
757 |
|
758 |
return false; |
759 |
} |
760 |
|
761 |
/**
|
762 |
* @see javax.swing.filechooser.FileFilter#getDescription()
|
763 |
*/
|
764 |
public String getDescription() { |
765 |
return description;
|
766 |
} |
767 |
|
768 |
public String[] getExtensions() { |
769 |
return extensiones;
|
770 |
} |
771 |
|
772 |
public boolean isDirectory() { |
773 |
return dirs;
|
774 |
} |
775 |
|
776 |
private String getExtensionOfAFile(File file) { |
777 |
String name;
|
778 |
int dotPos;
|
779 |
name = file.getName(); |
780 |
dotPos = name.lastIndexOf(".");
|
781 |
if (dotPos < 1) { |
782 |
return ""; |
783 |
} |
784 |
return name.substring(dotPos + 1); |
785 |
} |
786 |
|
787 |
public File normalizeExtension(File file) { |
788 |
String ext = getExtensionOfAFile(file);
|
789 |
if (ext.equals("") || !(this.accept(file))) { |
790 |
return new File(file.getAbsolutePath() + "." + extensiones[0]); |
791 |
} |
792 |
return file;
|
793 |
} |
794 |
|
795 |
public String getInfo() { |
796 |
return this.info; |
797 |
} |
798 |
|
799 |
public void setInfo(String info) { |
800 |
this.info = info;
|
801 |
} |
802 |
|
803 |
} |