Revision 32462 branches/gvSIG_19_ext3D_osgVP_2_2_0/extensions/ext3Dgui/src/org/gvsig/gvsig3dgui/import3D/ControlImport3D.java

View differences:

ControlImport3D.java
1 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
*/
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 19

  
20

  
21

  
22 20
package org.gvsig.gvsig3dgui.import3D;
23 21

  
24 22
import java.awt.BorderLayout;
......
52 50
import org.gvsig.gvsig3d.cacheservices.OSGCacheService;
53 51
import org.gvsig.gvsig3d.map3d.MapContext3D;
54 52
import org.gvsig.gvsig3dgui.view.View3D;
53
import org.gvsig.osgvp.core.osg.Node;
55 54
import org.gvsig.osgvp.core.osg.Vec3;
56 55
import org.gvsig.osgvp.viewer.Intersections;
57 56
import org.gvsig.osgvp.core.osgdb.osgDB;
57
import org.gvsig.osgvp.core.osgutil.Optimizer;
58 58
import org.gvsig.osgvp.exceptions.node.LoadNodeException;
59
import org.gvsig.osgvp.exceptions.node.NodeException;
59 60

  
60 61
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps;
61 62
import com.iver.andami.PluginServices;
......
67 68
import com.iver.cit.gvsig.project.documents.view.IProjectView;
68 69

  
69 70
/**
70
 * @author �ngel Fraile Gri��n  e-mail: angel.fraile@iver.es
71
 * @author �ngel Fraile Gri��n e-mail: angel.fraile@iver.es
71 72
 * @since 1.1
72 73
 * 
73 74
 */
......
75 76
		MouseListener {
76 77

  
77 78
	private static final long serialVersionUID = 8557746972654979029L;
78
	
79
	private JPanel 			panelOpcionesObjeto;
80
	private TitledBorder 	borderOpcionesObjeto;
81
	private JLabel 			labelLatitud;
82
	private DataInputField 	textLatitud;
83
	private JLabel 			labelLongitud;
84
	private DataInputField 	textLongitud;
85
	private JLabel 			labelEscaladoX;
86
	private JLabel 			labelEscaladoY;
87
	private JLabel 			labelEscaladoZ;
88
	private DataInputField 	textEscaladoX;
89
	private DataInputField 	textEscaladoY;
90
	private DataInputField 	textEscaladoZ;
91
	private JLabel 			labelRotacionX;
92
	private JLabel 			labelRotacionY;
93
	private JLabel 			labelRotacionZ;
94
	private DataInputField 	textRotacionX;
95
	private DataInputField 	textRotacionY;
96
	private DataInputField 	textRotacionZ;
97
	private JPanel 			panelImportar;
98
	private TitledBorder 	borderImportar;
99
	private JButton 		buttonImportar;
100
	private int 			tipoObjectImport;
101
	private JTextField 		textFile;
102
	private TitledBorder 	border;
103
	private JPanel 			panelPath;
104
	private Hashtable 		iveExtensionsSupported = null;
105
	private Hashtable 		osgExtensionsSupported = null;
106
	private String 			lastPath = null;
107
	private JLabel 			labelAltura;
108
	private DataInputField 	textAltura;
109
	private JPanel 			panelButtons;
110
	private JButton 		buttonAccept;
111
	private JButton 		buttonCancel;
112
	private JPanel 			panelAux;
113
	private JLabel 			labelX;
114
	private DataInputField 	textX;
115
	private JLabel 			labelY;
116
	private DataInputField 	textY;
117 79

  
118
	private View3D 			_view3D;
119
	private File 			_fileOSG = null;
80
	private JPanel panelOpcionesObjeto;
81
	private TitledBorder borderOpcionesObjeto;
82
	private JLabel labelLatitud;
83
	private DataInputField textLatitud;
84
	private JLabel labelLongitud;
85
	private DataInputField textLongitud;
86
	private JLabel labelEscaladoX;
87
	private JLabel labelEscaladoY;
88
	private JLabel labelEscaladoZ;
89
	private DataInputField textEscaladoX;
90
	private DataInputField textEscaladoY;
91
	private DataInputField textEscaladoZ;
92
	private JLabel labelRotacionX;
93
	private JLabel labelRotacionY;
94
	private JLabel labelRotacionZ;
95
	private DataInputField textRotacionX;
96
	private DataInputField textRotacionY;
97
	private DataInputField textRotacionZ;
98
	private JPanel panelImportar;
99
	private TitledBorder borderImportar;
100
	private JButton buttonImportar;
101
	private int tipoObjectImport;
102
	private JTextField textFile;
103
	private TitledBorder border;
104
	private JPanel panelPath;
105
	private Hashtable iveExtensionsSupported = null;
106
	private Hashtable osgExtensionsSupported = null;
107
	private String lastPath = null;
108
	private JLabel labelAltura;
109
	private DataInputField textAltura;
110
	private JPanel panelButtons;
111
	private JButton buttonAccept;
112
	private JButton buttonCancel;
113
	private JPanel panelAux;
114
	private JLabel labelX;
115
	private DataInputField textX;
116
	private JLabel labelY;
117
	private DataInputField textY;
118

  
119
	private View3D _view3D;
120
	private File _fileOSG = null;
120 121
	private FileInputStream _fileInput = null;
121
	private Vec3 			_position = new Vec3(0,0,0);
122
	private Vec3 _position = new Vec3(0, 0, 0);
122 123

  
123
	
124 124
	/**
125 125
	 * Building the panel options
126 126
	 * 
127 127
	 * @param tipoObjeto
128
	 * @param vista3D: actual 3D view selected
128
	 * @param vista3D
129
	 *            : actual 3D view selected
129 130
	 */
130 131
	public ControlImport3D(int tipoObjeto, View3D view3D) {
131 132

  
......
152 153
		this.textEscaladoY.setValue("1");
153 154
		this.textEscaladoZ = new DataInputField();
154 155
		this.textEscaladoZ.setValue("1");
155
		this.labelEscaladoX = new JLabel(PluginServices
156
				.getText(this, "EscaladoX"), JLabel.RIGHT);
157
		this.labelEscaladoY = new JLabel(PluginServices
158
				.getText(this, "EscaladoY"), JLabel.RIGHT);
159
		this.labelEscaladoZ = new JLabel(PluginServices
160
				.getText(this, "EscaladoZ"), JLabel.RIGHT);
156
		this.labelEscaladoX = new JLabel(PluginServices.getText(this,
157
				"EscaladoX"), JLabel.RIGHT);
158
		this.labelEscaladoY = new JLabel(PluginServices.getText(this,
159
				"EscaladoY"), JLabel.RIGHT);
160
		this.labelEscaladoZ = new JLabel(PluginServices.getText(this,
161
				"EscaladoZ"), JLabel.RIGHT);
161 162

  
162 163
		this.textRotacionX = new DataInputField();
163 164
		this.textRotacionY = new DataInputField();
......
303 304
	 */
304 305
	private void actionPerformedAccept() {
305 306

  
306

  
307 307
		if (_fileOSG == null) {// of the user write the file
308
			if(getJTextFieldFichero().equals("")) {
309
				JOptionPane.showMessageDialog(null, PluginServices.getText(this,"root_in"),
310
						PluginServices.getText(this,"no_file"), JOptionPane.WARNING_MESSAGE);
308
			if (getJTextFieldFichero().equals("")) {
309
				JOptionPane.showMessageDialog(null, PluginServices.getText(
310
						this, "root_in"), PluginServices.getText(this,
311
						"no_file"), JOptionPane.WARNING_MESSAGE);
311 312
				return;
312
			}
313
			else {
314
					_fileOSG = new File(getJTextFieldFichero());
315
				if(!_fileOSG.exists()){
316
					JOptionPane.showMessageDialog(null,PluginServices.getText(this,"no_root"),
317
							PluginServices.getText(this,"no_file2"), JOptionPane.WARNING_MESSAGE);
313
			} else {
314
				_fileOSG = new File(getJTextFieldFichero());
315
				if (!_fileOSG.exists()) {
316
					JOptionPane.showMessageDialog(null, PluginServices.getText(
317
							this, "no_root"), PluginServices.getText(this,
318
							"no_file2"), JOptionPane.WARNING_MESSAGE);
318 319
					_fileOSG = null;
319 320
					this.setTextFieldFichero();
320 321
					return;
......
323 324

  
324 325
		} else {
325 326
			try {
326
				if(!_fileOSG.exists()){
327
					JOptionPane.showMessageDialog(null, PluginServices.getText(this,"root_in"),
328
							PluginServices.getText(this,"no_file"), JOptionPane.WARNING_MESSAGE);
327
				if (!_fileOSG.exists()) {
328
					JOptionPane.showMessageDialog(null, PluginServices.getText(
329
							this, "root_in"), PluginServices.getText(this,
330
							"no_file"), JOptionPane.WARNING_MESSAGE);
329 331
					return;
330 332
				}
331 333
				_fileInput = new FileInputStream(_fileOSG);
332
				
334

  
333 335
			} catch (FileNotFoundException e) {
334 336
				e.printStackTrace();
335 337
			}
336 338
		}
337 339

  
338
//		OSGDriver _osgDriver = new OSGDriver();
339
//		OSGParser parser = new OSGParser("OSG", "OSG File Formats Parser");
340
//		parser.parse(_osgDriver, null, _fileOSG.toURI());
341
//		MultiGeometry root = _osgDriver.getRootFeature();
340
		// OSGDriver _osgDriver = new OSGDriver();
341
		// OSGParser parser = new OSGParser("OSG", "OSG File Formats Parser");
342
		// parser.parse(_osgDriver, null, _fileOSG.toURI());
343
		// MultiGeometry root = _osgDriver.getRootFeature();
342 344

  
343 345
		IProjectView model = _view3D.getModel();
344 346
		MapContext mapContext = model.getMapContext();
......
346 348
		FLayer[] actives = layers.getActives();
347 349
		if (actives.length == 1
348 350
				&& Layer3DProps.getLayer3DProps(actives[0]).getType() == Layer3DProps.layer3DOSG) {
349
			OSGCacheService osgCache = (OSGCacheService) Layer3DProps.getLayer3DProps(actives[0]).getCacheService();
350
			Vec3 scale = new Vec3(Double.parseDouble(textEscaladoX.getValue()), Double.parseDouble(textEscaladoY.getValue()), Double.parseDouble(textEscaladoZ.getValue()));
351
			Vec3 rotation = new Vec3(Double.parseDouble(textRotacionX.getValue()), Double.parseDouble(textRotacionY.getValue()), Double.parseDouble(textRotacionZ.getValue()));
352
			//osgCache.AddGeometryToLayer(root,_position,rotation,scale);
353
			
351
			OSGCacheService osgCache = (OSGCacheService) Layer3DProps
352
					.getLayer3DProps(actives[0]).getCacheService();
353
			Vec3 scale = new Vec3(Double.parseDouble(textEscaladoX.getValue()),
354
					Double.parseDouble(textEscaladoY.getValue()), Double
355
							.parseDouble(textEscaladoZ.getValue()));
356
			Vec3 rotation = new Vec3(Double.parseDouble(textRotacionX
357
					.getValue()), Double.parseDouble(textRotacionY.getValue()),
358
					Double.parseDouble(textRotacionZ.getValue()));
359
			// osgCache.AddGeometryToLayer(root,_position,rotation,scale);
360

  
354 361
			try {
355
				osgCache.AddNodeToLayer(osgDB.readNodeFile(_fileOSG.toString()), _position, rotation, scale);
362
				Optimizer opt = new Optimizer();
363
				Node n = osgDB.readNodeFile(_fileOSG.toString());
364
				opt.optimize(n);
365
				osgCache.AddNodeToLayer(n, _position, rotation, scale);
356 366
			} catch (LoadNodeException e) {
357 367
				// TODO Auto-generated catch block
358 368
				e.printStackTrace();
359 369
			} catch (FileNotFoundException e) {
360 370
				// TODO Auto-generated catch block
361 371
				e.printStackTrace();
372
			} catch (NodeException e) {
373
				// TODO Auto-generated catch block
374
				e.printStackTrace();
362 375
			}
363
		
364
		}else {
365
			JOptionPane.showMessageDialog(null, PluginServices.getText(this,"editable_layer_select_info"),
366
					PluginServices.getText(this,"editable_layer_select"), JOptionPane.WARNING_MESSAGE);
376

  
377
		} else {
378
			JOptionPane.showMessageDialog(null, PluginServices.getText(this,
379
					"editable_layer_select_info"), PluginServices.getText(this,
380
					"editable_layer_select"), JOptionPane.WARNING_MESSAGE);
367 381
			return;
368 382
		}
369
		
383

  
370 384
		_view3D.getCanvas3d().removeMouseListener(this);
371 385
		PluginServices.getMDIManager().closeWindow(this);
372 386
	}
......
389 403
				PluginServices.getText(this, "Ficheros *.dae"), "dae"));
390 404
		iveExtensionsSupported.put("3ds", new MyFileFilter("3ds",
391 405
				PluginServices.getText(this, "Ficheros *.3ds"), "3ds"));
392
		iveExtensionsSupported.put("*", new MyFileFilter("*",
393
				PluginServices.getText(this, "Ficheros *.*"), "*.*"));
394
		
406
		iveExtensionsSupported.put("*", new MyFileFilter("*", PluginServices
407
				.getText(this, "Ficheros *.*"), "*.*"));
408

  
395 409
		Iterator iter = osgExtensionsSupported.values().iterator();
396
		
410

  
397 411
		while (iter.hasNext()) {
398 412
			jfc.addChoosableFileFilter((FileFilter) iter.next());
399 413
		}
......
412 426
				_fileOSG = filter.normalizeExtension(_fileOSG);
413 427
				textFile.setText(_fileOSG.getAbsolutePath());
414 428
			} else {
415
				JOptionPane.showMessageDialog(null,PluginServices.getText(this,"no_root"),
416
						PluginServices.getText(this,"no_file2"), JOptionPane.WARNING_MESSAGE);
429
				JOptionPane.showMessageDialog(null, PluginServices.getText(
430
						this, "no_root"), PluginServices.getText(this,
431
						"no_file2"), JOptionPane.WARNING_MESSAGE);
417 432
				return;
418 433
			}
419 434
		}// If aprove option.
......
425 440
	public String getJTextFieldFichero() {
426 441
		return textFile.getText();
427 442
	}
428
	
443

  
429 444
	public void setTextFieldFichero() {
430 445
		textFile.setText(null);
431 446
	}
447

  
432 448
	/*
433 449
	 * All MouseListener methods
434
	 * 
435 450
	 */
436 451
	public void mouseClicked(MouseEvent e) {
437 452
		// TODO Auto-generated method stub
......
507 522

  
508 523
}
509 524

  
510

  
511 525
/**
512 526
 * 
513 527
 * @version 14/08/2007

Also available in: Unified diff