root / trunk / extensions / ext3Dgui / src / org / gvsig / gvsig3dgui / import3D / ControlImport3D.java @ 22628
History | View | Annotate | Download (16.1 KB)
1 |
package org.gvsig.gvsig3dgui.import3D; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Component; |
5 |
import java.awt.GridLayout; |
6 |
import java.awt.Point; |
7 |
import java.awt.event.ActionEvent; |
8 |
import java.awt.event.ActionListener; |
9 |
import java.awt.event.MouseEvent; |
10 |
import java.awt.event.MouseListener; |
11 |
import java.awt.geom.Point2D; |
12 |
import java.io.File; |
13 |
import java.io.FileInputStream; |
14 |
import java.io.FileNotFoundException; |
15 |
import java.util.Hashtable; |
16 |
import java.util.Iterator; |
17 |
|
18 |
import javax.swing.JButton; |
19 |
import javax.swing.JFileChooser; |
20 |
import javax.swing.JLabel; |
21 |
import javax.swing.JOptionPane; |
22 |
import javax.swing.JPanel; |
23 |
import javax.swing.JTextField; |
24 |
import javax.swing.border.TitledBorder; |
25 |
import javax.swing.filechooser.FileFilter; |
26 |
|
27 |
import org.gvsig.driver.OSGDriver; |
28 |
import org.gvsig.geometries3D.MultiGeometry; |
29 |
import org.gvsig.gpe.osg.OSGParser; |
30 |
import org.gvsig.gui.beans.datainput.DataInputField; |
31 |
import org.gvsig.gvsig3d.cacheservices.OSGCacheService; |
32 |
import org.gvsig.gvsig3d.map3d.MapContext3D; |
33 |
import org.gvsig.gvsig3dgui.view.View3D; |
34 |
import org.gvsig.osgvp.Group; |
35 |
import org.gvsig.osgvp.Vec3; |
36 |
import org.gvsig.osgvp.viewer.Intersections; |
37 |
|
38 |
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps; |
39 |
import com.iver.andami.PluginServices; |
40 |
import com.iver.andami.ui.mdiManager.IWindow; |
41 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
42 |
import com.iver.cit.gvsig.fmap.MapContext; |
43 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
44 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
45 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
46 |
|
47 |
/**
|
48 |
* DOCUMENT ME!
|
49 |
*
|
50 |
* @author
|
51 |
*/
|
52 |
|
53 |
public class ControlImport3D extends JPanel implements IWindow, ActionListener, |
54 |
MouseListener {
|
55 |
|
56 |
private static final long serialVersionUID = 8557746972654979029L; |
57 |
private JPanel panelOpcionesObjeto; |
58 |
private TitledBorder borderOpcionesObjeto; |
59 |
private JLabel labelLatitud; |
60 |
private DataInputField textLatitud;
|
61 |
private JLabel labelLongitud; |
62 |
private DataInputField textLongitud;
|
63 |
private JLabel labelEscalado; |
64 |
private DataInputField textEscalado;
|
65 |
private JLabel labelRotacion; |
66 |
private DataInputField textRotacion;
|
67 |
private JPanel panelImportar; |
68 |
private TitledBorder borderImportar; |
69 |
private JButton buttonImportar; |
70 |
private int tipoObjectImport; |
71 |
private JTextField textFile; |
72 |
private TitledBorder border; |
73 |
private JPanel panelPath; |
74 |
private Hashtable iveExtensionsSupported = null; |
75 |
private Hashtable osgExtensionsSupported = null; |
76 |
private String lastPath = null; |
77 |
private JLabel labelAltura; |
78 |
private DataInputField textAltura;
|
79 |
private JPanel panelButtons; |
80 |
private JButton buttonAccept; |
81 |
private JButton buttonCancel; |
82 |
private JPanel panelAux; |
83 |
private JLabel labelX; |
84 |
private DataInputField textX;
|
85 |
private JLabel labelY; |
86 |
private DataInputField textY;
|
87 |
|
88 |
private View3D vista;
|
89 |
private File fileOSG = null; |
90 |
private FileInputStream fileInput = null; |
91 |
private Vec3 position = new Vec3(0,0,0); |
92 |
|
93 |
public ControlImport3D(int tipoObjeto, View3D vista3D) { |
94 |
|
95 |
tipoObjectImport = tipoObjeto; |
96 |
vista = vista3D; |
97 |
|
98 |
this.panelOpcionesObjeto = new JPanel(); |
99 |
this.borderOpcionesObjeto = new TitledBorder(PluginServices.getText( |
100 |
this, "Opciones de objeto")); |
101 |
this.panelOpcionesObjeto.setBorder(this.borderOpcionesObjeto); |
102 |
this.panelOpcionesObjeto.setLayout(new GridLayout(5, 4, 5, 5)); |
103 |
|
104 |
this.textLatitud = new DataInputField(); |
105 |
this.labelLatitud = new JLabel( |
106 |
PluginServices.getText(this, "Latitude"), JLabel.RIGHT); |
107 |
|
108 |
this.textLongitud = new DataInputField(); |
109 |
this.labelLongitud = new JLabel(PluginServices.getText(this, |
110 |
"Longitude"), JLabel.RIGHT); |
111 |
|
112 |
this.textEscalado = new DataInputField(); |
113 |
this.labelEscalado = new JLabel(PluginServices |
114 |
.getText(this, "Escalado"), JLabel.RIGHT); |
115 |
|
116 |
this.textRotacion = new DataInputField(); |
117 |
this.labelRotacion = new JLabel(PluginServices.getText(this, |
118 |
"Rotation_degrees"), JLabel.RIGHT); |
119 |
|
120 |
this.textAltura = new DataInputField(); |
121 |
this.labelAltura = new JLabel(PluginServices.getText(this, "Hight"), |
122 |
JLabel.RIGHT);
|
123 |
|
124 |
this.textX = new DataInputField(); |
125 |
this.labelX = new JLabel(PluginServices.getText(this, "Coordenada X:"), |
126 |
JLabel.RIGHT);
|
127 |
|
128 |
this.textY = new DataInputField(); |
129 |
this.labelY = new JLabel(PluginServices.getText(this, "Coordenada Y:"), |
130 |
JLabel.RIGHT);
|
131 |
|
132 |
this.panelOpcionesObjeto.add(this.labelLatitud); |
133 |
this.panelOpcionesObjeto.add(this.textLatitud); |
134 |
this.panelOpcionesObjeto.add(this.labelX); |
135 |
this.panelOpcionesObjeto.add(this.textX); |
136 |
|
137 |
this.panelOpcionesObjeto.add(this.labelLongitud); |
138 |
this.panelOpcionesObjeto.add(this.textLongitud); |
139 |
this.panelOpcionesObjeto.add(this.labelY); |
140 |
this.panelOpcionesObjeto.add(this.textY); |
141 |
|
142 |
this.panelOpcionesObjeto.add(this.labelAltura); |
143 |
this.panelOpcionesObjeto.add(this.textAltura); |
144 |
this.panelOpcionesObjeto.add(new JPanel()); |
145 |
this.panelOpcionesObjeto.add(new JPanel()); |
146 |
|
147 |
this.panelOpcionesObjeto.add(this.labelEscalado); |
148 |
this.panelOpcionesObjeto.add(this.textEscalado); |
149 |
this.panelOpcionesObjeto.add(new JPanel()); |
150 |
this.panelOpcionesObjeto.add(new JPanel()); |
151 |
|
152 |
this.panelOpcionesObjeto.add(this.labelRotacion); |
153 |
this.panelOpcionesObjeto.add(this.textRotacion); |
154 |
this.panelOpcionesObjeto.add(new JPanel()); |
155 |
this.panelOpcionesObjeto.add(new JPanel()); |
156 |
|
157 |
this.panelImportar = new JPanel(); |
158 |
this.borderImportar = new TitledBorder(PluginServices.getText(this, |
159 |
"File"));
|
160 |
this.panelImportar.setBorder(this.borderImportar); |
161 |
this.panelImportar.setLayout(new GridLayout(1, 1, 5, 5)); |
162 |
this.buttonImportar = new JButton(PluginServices.getText(this, |
163 |
"Examine"));
|
164 |
this.panelImportar.add(this.buttonImportar); |
165 |
this.buttonImportar.addActionListener(this); |
166 |
|
167 |
this.panelAux = new JPanel(); |
168 |
this.panelAux.setLayout(new BorderLayout(5, 5)); |
169 |
this.panelAux.add(this.panelOpcionesObjeto, BorderLayout.CENTER); |
170 |
this.panelAux.add(this.panelImportar, BorderLayout.SOUTH); |
171 |
|
172 |
this.panelPath = new JPanel(); |
173 |
this.border = new TitledBorder(PluginServices.getText(this, |
174 |
"Ruta_manual"));
|
175 |
this.panelPath.setBorder(this.border); |
176 |
this.panelPath.setLayout(new GridLayout(1, 1, 5, 5)); |
177 |
this.textFile = new JTextField(); |
178 |
this.panelPath.add(this.textFile); |
179 |
|
180 |
this.panelButtons = new JPanel(); |
181 |
this.panelButtons.setLayout(new GridLayout(1, 3, 5, 5)); |
182 |
this.buttonAccept = new JButton(PluginServices.getText(this, "Accept")); |
183 |
this.buttonAccept.addActionListener(this); |
184 |
this.buttonCancel = new JButton(PluginServices.getText(this, "Cancel")); |
185 |
this.buttonCancel.addActionListener(this); |
186 |
this.panelButtons.add(new JPanel()); |
187 |
this.panelButtons.add(this.buttonAccept); |
188 |
this.panelButtons.add(this.buttonCancel); |
189 |
|
190 |
this.setLayout(new BorderLayout(5, 5)); |
191 |
this.add(this.panelAux, BorderLayout.NORTH); |
192 |
this.add(this.panelPath, BorderLayout.CENTER); |
193 |
this.add(this.panelButtons, BorderLayout.SOUTH); |
194 |
|
195 |
vista.getCanvas3d().addMouseListener(this);
|
196 |
|
197 |
} |
198 |
|
199 |
/*
|
200 |
* Window properties
|
201 |
*
|
202 |
* @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
|
203 |
*/
|
204 |
|
205 |
public WindowInfo getWindowInfo() {
|
206 |
WindowInfo m_viewinfo = new WindowInfo();
|
207 |
String cad = null; |
208 |
// java.awt.Dimension minSize = new java.awt.Dimension();
|
209 |
// minSize.setSize(290, 400);
|
210 |
|
211 |
if (tipoObjectImport == 0) |
212 |
cad = "Importar_Objeto_3D";
|
213 |
else if (tipoObjectImport == 1) |
214 |
cad = "Importar_Objeto_3D_GIS_vectorial";
|
215 |
|
216 |
m_viewinfo.setTitle(PluginServices.getText(this, cad));
|
217 |
m_viewinfo.setHeight(290);
|
218 |
m_viewinfo.setWidth(410);
|
219 |
// m_viewinfo.setMinimumSize(minSize);
|
220 |
return m_viewinfo;
|
221 |
} |
222 |
|
223 |
/*
|
224 |
* Buttons events listener
|
225 |
*/
|
226 |
|
227 |
public void actionPerformed(ActionEvent event) { |
228 |
if (event.getSource() == this.buttonImportar) { |
229 |
actionPerformedImport(); |
230 |
|
231 |
} |
232 |
if (event.getSource() == this.buttonAccept) { |
233 |
actionPerformedAccept(); |
234 |
PluginServices.getMDIManager().closeWindow(this);
|
235 |
|
236 |
} |
237 |
if (event.getSource() == this.buttonCancel) { |
238 |
PluginServices.getMDIManager().closeWindow(this);
|
239 |
} |
240 |
} |
241 |
|
242 |
/*
|
243 |
* Accept button listener
|
244 |
*/
|
245 |
|
246 |
private void actionPerformedAccept() { |
247 |
|
248 |
String lat = getJTextFieldLatitud();
|
249 |
String lon = getJTextFieldLongitud();
|
250 |
String rot = getJTextFieldRotacion();
|
251 |
String higth = getJTextFieldAltura();
|
252 |
String scal = getJTextFieldEscalado();
|
253 |
|
254 |
if (fileOSG == null) {// of the user write the file |
255 |
// String fichManual = getJTextFieldFichero();
|
256 |
fileOSG = new File(getJTextFieldFichero()); |
257 |
try {
|
258 |
fileInput = new FileInputStream(fileOSG); |
259 |
} catch (FileNotFoundException e) { |
260 |
e.printStackTrace(); |
261 |
} |
262 |
|
263 |
} else {
|
264 |
try {
|
265 |
fileInput = new FileInputStream(fileOSG); |
266 |
} catch (FileNotFoundException e) { |
267 |
e.printStackTrace(); |
268 |
} |
269 |
} |
270 |
|
271 |
OSGDriver _osgDriver = new OSGDriver();
|
272 |
OSGParser parser = new OSGParser("OSG", "OSG File Formats Parser"); |
273 |
parser.parse(_osgDriver, null, fileOSG.toURI());
|
274 |
MultiGeometry root = _osgDriver.getRootFeature(); |
275 |
Group rootGroup = new Group(); |
276 |
|
277 |
IProjectView model = vista.getModel(); |
278 |
MapContext mapContext = model.getMapContext(); |
279 |
FLayers layers = mapContext.getLayers(); |
280 |
FLayer[] actives = layers.getActives();
|
281 |
//Layer3DProps props3D = Layer3DProps.getLayer3DProps(actives[0]);
|
282 |
if (actives.length == 1 |
283 |
&& Layer3DProps.getLayer3DProps(actives[0]).getType() == Layer3DProps.layer3DOSG) {
|
284 |
OSGCacheService osgCache = (OSGCacheService) Layer3DProps.getLayer3DProps(actives[0]).getCacheService();
|
285 |
// Vec3 rotation = new Vec3(0, y, z);
|
286 |
// Vec3 scale = new Vec3(x, y, z);
|
287 |
osgCache.AddGeometryToLayer(root, position, null,null); |
288 |
//System.out.println("kjdfkjsdlkd");
|
289 |
} |
290 |
else
|
291 |
JOptionPane.showMessageDialog(null, "Selecciona una capa editable OSG.", |
292 |
"Capa no selecionada o capa no v?lida", JOptionPane.WARNING_MESSAGE); |
293 |
|
294 |
} |
295 |
|
296 |
/*
|
297 |
* Import file button listener
|
298 |
*/
|
299 |
|
300 |
private void actionPerformedImport() { |
301 |
JFileChooser jfc = new JFileChooser(lastPath); |
302 |
jfc.removeChoosableFileFilter(jfc.getAcceptAllFileFilter()); |
303 |
iveExtensionsSupported = new Hashtable(); |
304 |
osgExtensionsSupported = new Hashtable(); |
305 |
iveExtensionsSupported.put("ive", new MyFileFilter("ive", |
306 |
PluginServices.getText(this, "Ficheros *.ive"), "ive")); |
307 |
osgExtensionsSupported.put("osg", new MyFileFilter("osg", |
308 |
PluginServices.getText(this, "Ficheros *.osg"), "osg")); |
309 |
|
310 |
Iterator iter = osgExtensionsSupported.values().iterator();
|
311 |
while (iter.hasNext()) {
|
312 |
jfc.addChoosableFileFilter((FileFilter) iter.next());
|
313 |
} |
314 |
|
315 |
iter = iveExtensionsSupported.values().iterator(); |
316 |
while (iter.hasNext()) {
|
317 |
jfc.addChoosableFileFilter((FileFilter) iter.next());
|
318 |
} |
319 |
|
320 |
if (jfc.showOpenDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
321 |
|
322 |
com.iver.andami.ui.mdiManager.IWindow activeWindow = PluginServices |
323 |
.getMDIManager().getActiveWindow(); |
324 |
fileOSG = jfc.getSelectedFile(); |
325 |
if (fileOSG.exists()) {// file don't exists in the directory. |
326 |
|
327 |
MyFileFilter filter = (MyFileFilter) jfc.getFileFilter(); |
328 |
fileOSG = filter.normalizeExtension(fileOSG); |
329 |
textFile.setText(fileOSG.getAbsolutePath()); |
330 |
} else {
|
331 |
JOptionPane.showMessageDialog(null, "El fichero no existe.", |
332 |
"Fichero no encontrado", JOptionPane.WARNING_MESSAGE); |
333 |
return;
|
334 |
} |
335 |
}// If aprove option.
|
336 |
} |
337 |
|
338 |
/*
|
339 |
* Getters of all TextFields values
|
340 |
*/
|
341 |
|
342 |
public String getJTextFieldLatitud() { |
343 |
return textLatitud.getValue();
|
344 |
} |
345 |
|
346 |
public String getJTextFieldLongitud() { |
347 |
return textLongitud.getValue();
|
348 |
} |
349 |
|
350 |
public String getJTextFieldEscalado() { |
351 |
return textEscalado.getValue();
|
352 |
} |
353 |
|
354 |
public String getJTextFieldRotacion() { |
355 |
return textRotacion.getValue();
|
356 |
} |
357 |
|
358 |
public String getJTextFieldAltura() { |
359 |
return textAltura.getValue();
|
360 |
} |
361 |
|
362 |
public String getJTextFieldFichero() { |
363 |
return textFile.getText();
|
364 |
} |
365 |
|
366 |
/*
|
367 |
* All MouseListener methods
|
368 |
*
|
369 |
*/
|
370 |
public void mouseClicked(MouseEvent e) { |
371 |
// TODO Auto-generated method stub
|
372 |
} |
373 |
|
374 |
public void mouseEntered(MouseEvent e) { |
375 |
// TODO Auto-generated method stub
|
376 |
|
377 |
} |
378 |
|
379 |
public void mouseExited(MouseEvent e) { |
380 |
// TODO Auto-generated method stub
|
381 |
|
382 |
} |
383 |
|
384 |
public void mousePressed(MouseEvent e) { |
385 |
// TODO Auto-generated method stub
|
386 |
} |
387 |
|
388 |
public void mouseReleased(MouseEvent e) { |
389 |
|
390 |
Point pScreen = e.getPoint();
|
391 |
|
392 |
if (e.getButton() == MouseEvent.BUTTON1) { |
393 |
Vec3 intersection = null;
|
394 |
|
395 |
// System.err.println("Coordenadas de pantalla " + pScreen.getX() +
|
396 |
// ","+
|
397 |
// pScreen.getY());
|
398 |
|
399 |
textX.setValue(Double.toString(pScreen.getX()));
|
400 |
textY.setValue(Double.toString(pScreen.getY()));
|
401 |
|
402 |
IProjectView model = vista.getModel(); |
403 |
|
404 |
MapContext3D mcontext = (MapContext3D) model.getMapContext(); |
405 |
mcontext.getCanvas3d(); |
406 |
|
407 |
Intersections hits = mcontext.getCanvas3d().getOSGViewer().rayPick( |
408 |
(int) pScreen.getX(), (int) pScreen.getY()); |
409 |
Point2D pWorld = new Point2D.Double(); |
410 |
if (hits.containsIntersections()) {
|
411 |
Vec3 hit = hits.getFirstIntersection().getIntersectionPoint(); |
412 |
// convert to geo coordinates
|
413 |
position = hit; |
414 |
// System.err.println("Interseccion de osg " + hit.x() + ","+
|
415 |
// hit.y());
|
416 |
if (mcontext.getProjection().getAbrev().compareToIgnoreCase(
|
417 |
"EPSG:4326") == 0) { |
418 |
Vec3 geoPt = mcontext.getPlanet() |
419 |
.convertXYZToLatLongHeight(hit); |
420 |
// Swap the coordinates X and Y, because they are invert.
|
421 |
intersection = new Vec3(geoPt.y(), geoPt.x(), geoPt.z());
|
422 |
} else {
|
423 |
intersection = hit; |
424 |
} |
425 |
} else {
|
426 |
if (mcontext.getProjection().getAbrev().compareToIgnoreCase(
|
427 |
"EPSG:4326") == 0) { |
428 |
pWorld.setLocation(360, 120); |
429 |
intersection = new Vec3(360, 120, 0); |
430 |
} else {
|
431 |
intersection = new Vec3(1e100, 1e100, 0); |
432 |
// pWorld.setLocation(1e100, 1e100);
|
433 |
} |
434 |
} |
435 |
|
436 |
textLatitud.setValue(Double.toString(intersection.x()));
|
437 |
textLongitud.setValue(Double.toString(intersection.y()));
|
438 |
textAltura.setValue(Double.toString(intersection.z()));
|
439 |
|
440 |
}// if e.getButton()
|
441 |
}// if hits
|
442 |
} |
443 |
|
444 |
/**
|
445 |
*
|
446 |
* @version 14/08/2007
|
447 |
* @author Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
448 |
*
|
449 |
*/
|
450 |
class MyFileFilter extends FileFilter { |
451 |
|
452 |
private String[] extensiones = new String[1]; |
453 |
private String description; |
454 |
private boolean dirs = true; |
455 |
private String info = null; |
456 |
|
457 |
public MyFileFilter(String[] ext, String desc) { |
458 |
extensiones = ext; |
459 |
description = desc; |
460 |
} |
461 |
|
462 |
public MyFileFilter(String[] ext, String desc, String info) { |
463 |
extensiones = ext; |
464 |
description = desc; |
465 |
this.info = info;
|
466 |
} |
467 |
|
468 |
public MyFileFilter(String ext, String desc) { |
469 |
extensiones[0] = ext;
|
470 |
description = desc; |
471 |
} |
472 |
|
473 |
public MyFileFilter(String ext, String desc, String info) { |
474 |
extensiones[0] = ext;
|
475 |
description = desc; |
476 |
this.info = info;
|
477 |
} |
478 |
|
479 |
public MyFileFilter(String ext, String desc, boolean dirs) { |
480 |
extensiones[0] = ext;
|
481 |
description = desc; |
482 |
this.dirs = dirs;
|
483 |
} |
484 |
|
485 |
public MyFileFilter(String ext, String desc, boolean dirs, String info) { |
486 |
extensiones[0] = ext;
|
487 |
description = desc; |
488 |
this.dirs = dirs;
|
489 |
this.info = info;
|
490 |
} |
491 |
|
492 |
public boolean accept(File f) { |
493 |
if (f.isDirectory()) {
|
494 |
if (dirs) {
|
495 |
return true; |
496 |
} else {
|
497 |
return false; |
498 |
} |
499 |
} |
500 |
for (int i = 0; i < extensiones.length; i++) { |
501 |
if (extensiones[i].equals("")) { |
502 |
continue;
|
503 |
} |
504 |
if (getExtensionOfAFile(f).equalsIgnoreCase(extensiones[i])) {
|
505 |
return true; |
506 |
} |
507 |
} |
508 |
|
509 |
return false; |
510 |
} |
511 |
|
512 |
/**
|
513 |
* @see javax.swing.filechooser.FileFilter#getDescription()
|
514 |
*/
|
515 |
public String getDescription() { |
516 |
return description;
|
517 |
} |
518 |
|
519 |
public String[] getExtensions() { |
520 |
return extensiones;
|
521 |
} |
522 |
|
523 |
public boolean isDirectory() { |
524 |
return dirs;
|
525 |
} |
526 |
|
527 |
private String getExtensionOfAFile(File file) { |
528 |
String name;
|
529 |
int dotPos;
|
530 |
name = file.getName(); |
531 |
dotPos = name.lastIndexOf(".");
|
532 |
if (dotPos < 1) { |
533 |
return ""; |
534 |
} |
535 |
return name.substring(dotPos + 1); |
536 |
} |
537 |
|
538 |
public File normalizeExtension(File file) { |
539 |
String ext = getExtensionOfAFile(file);
|
540 |
if (ext.equals("") || !(this.accept(file))) { |
541 |
return new File(file.getAbsolutePath() + "." + extensiones[0]); |
542 |
} |
543 |
return file;
|
544 |
} |
545 |
|
546 |
public String getInfo() { |
547 |
return this.info; |
548 |
} |
549 |
|
550 |
public void setInfo(String info) { |
551 |
this.info = info;
|
552 |
} |
553 |
|
554 |
} |