Revision 32462

View differences:

branches/gvSIG_19_ext3D_osgVP_2_2_0/extensions/ext3Dgui/src/org/gvsig/gvsig3dgui/Extension3D.java
1 1
package org.gvsig.gvsig3dgui;
2 2

  
3
import java.io.File;
4

  
3 5
import javax.swing.JPopupMenu;
4 6

  
7
import org.gvsig.gvsig3d.drivers.GvsigDriverOSG;
5 8
import org.gvsig.gvsig3dgui.preferences.View3DPreferences;
6 9
import org.gvsig.gvsig3dgui.tocMenu.TocEditingLayer;
7 10
import org.gvsig.gvsig3dgui.tocMenu.TocRefreshLayer;
......
9 12

  
10 13
import com.iver.andami.PluginServices;
11 14
import com.iver.andami.plugins.Extension;
15
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
12 16
import com.iver.utiles.extensionPoints.ExtensionPoints;
13 17
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
14 18

  
15

  
16 19
public class Extension3D extends Extension {
17 20

  
18 21
	public void execute(String actionCommand) {
19 22
	}
20 23

  
21 24
	public void initialize() {
22
    	JPopupMenu.setDefaultLightWeightPopupEnabled(false);
25
		JPopupMenu.setDefaultLightWeightPopupEnabled(false);
23 26
		ProjectView3DFactory.register();
24
		
27

  
25 28
		// TODO: registrar aki las opciones del menu contestual del toc
26
		ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
27
	    extensionPoints.add("View_TocActions",PluginServices.getText(this, "Transparency"),new TocTransparencyPanel());
28
	    extensionPoints.add("View_TocActions",PluginServices.getText(this, "Layer_Refresh"),new TocRefreshLayer());
29
	    extensionPoints.add("View_TocActions",PluginServices.getText(this, "Editing_layer"),new TocEditingLayer());
29
		ExtensionPoints extensionPoints = ExtensionPointsSingleton
30
				.getInstance();
31
		extensionPoints.add("View_TocActions", PluginServices.getText(this,
32
				"Transparency"), new TocTransparencyPanel());
33
		extensionPoints.add("View_TocActions", PluginServices.getText(this,
34
				"Layer_Refresh"), new TocRefreshLayer());
35
		extensionPoints.add("View_TocActions", PluginServices.getText(this,
36
				"Editing_layer"), new TocEditingLayer());
30 37

  
31
	    // Registering preferences dialog
32
	    extensionPoints.add("AplicationPreferences","View3DPreferences", new View3DPreferences());
38
		// Registering preferences dialog
39
		extensionPoints.add("AplicationPreferences", "View3DPreferences",
40
				new View3DPreferences());
41
		LayerFactory.getDM().addDriver(
42
				new File(this.getClass().getResource("/lib").getFile()),
43
				"gvSIG OSG Driver", GvsigDriverOSG.class);
33 44
	}
34
	
35
	
36 45

  
37 46
	public void postInitialize() {
38 47
		super.postInitialize();
......
49 58
	public void terminate() {
50 59
		super.terminate();
51 60
	}
52
	
61

  
53 62
}
branches/gvSIG_19_ext3D_osgVP_2_2_0/extensions/ext3Dgui/src/org/gvsig/gvsig3dgui/import3D/MenuImport3D.java
76 76
	}
77 77
	
78 78
	public void postInitialize() {
79
		LayerFactory.getDM().addDriver(new File(this.getClass().getResource(
80
        "/lib").getFile()),"gvSIG OSG Driver",GvsigDriverOSG.class);
81
		
82 79
		// Inicializing the geometry factory 3D
83 80
		GeometryManager.getInstance().registerGeometryFactory(new GeometryFactory3D());
84 81
		
......
98 95
		//Layer3DProps props3D = Layer3DProps.getLayer3DProps(actives[0]);
99 96
		if (actives.length == 1
100 97
				&&Layer3DProps.getLayer3DProps(actives[0])!=null && Layer3DProps.getLayer3DProps(actives[0]).getType() == Layer3DProps.layer3DOSG) {
101
			OSGCacheService osgCache = (OSGCacheService) Layer3DProps.getLayer3DProps(actives[0]).getCacheService();
98
		//	OSGCacheService osgCache = (OSGCacheService) Layer3DProps.getLayer3DProps(actives[0]).getCacheService();
102 99
			return true;
103 100
		}else
104 101
			return false;
branches/gvSIG_19_ext3D_osgVP_2_2_0/extensions/ext3Dgui/src/org/gvsig/gvsig3dgui/import3D/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
branches/gvSIG_19_ext3D_osgVP_2_2_0/extensions/ext3Dgui/src/org/gvsig/gvsig3dgui/import3D/CreateNewLayerOSG.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 20
package org.gvsig.gvsig3dgui.import3D;
21 21

  
22
import java.awt.Component;
23
import java.io.File;
24
import java.util.Hashtable;
25
import java.util.Iterator;
26

  
27
import javax.swing.JFileChooser;
28
import javax.swing.JOptionPane;
29
import javax.swing.filechooser.FileFilter;
30

  
31
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
22 32
import org.gvsig.gvsig3d.cacheservices.OSGCacheService;
23 33
import org.gvsig.gvsig3d.drivers.GvsigDriverOSG;
24 34
import org.gvsig.gvsig3d.map3d.MapContext3D;
25 35
import org.gvsig.gvsig3dgui.view.View3D;
26 36

  
37
import com.hardcode.gdbms.driver.exceptions.OpenDriverException;
38
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
27 39
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps;
28 40
import com.iver.andami.PluginServices;
29 41
import com.iver.andami.plugins.Extension;
30 42
import com.iver.cit.gvsig.exceptions.layers.LegendLayerException;
31 43
import com.iver.cit.gvsig.fmap.core.FShape;
44

  
32 45
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
46
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
47
import com.iver.cit.gvsig.fmap.layers.LayerListener;
33 48
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter;
34 49
import com.iver.cit.gvsig.fmap.layers.VectorialDefaultAdapter;
50
import com.iver.cit.gvsig.fmap.layers.VectorialFileAdapter;
51
import com.iver.cit.gvsig.fmap.rendering.IVectorLegend;
35 52
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend;
36 53
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend;
54
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.AttrInTableLabelingStrategy;
37 55
import com.iver.cit.gvsig.project.documents.view.IProjectView;
38 56

  
39 57
/**
40
 * @author �ngel Fraile Gri��n  e-mail: angel.fraile@iver.es
58
 * @author �ngel Fraile Gri��n e-mail: angel.fraile@iver.es
41 59
 * @since 1.1
42 60
 * 
43 61
 */
44 62
public class CreateNewLayerOSG extends Extension {
45
	private FLyrVect _layerOSG;
63
	protected FLyrVect _layerOSG;
64
	private Hashtable _iveExtensionsSupported = null;
65
	private Hashtable _osgExtensionsSupported = null;
46 66

  
47
	
48 67
	/**
49 68
	 * Creating a new layer OSG editable, ready to insert OSG objects
50 69
	 */
......
55 74
					.getMDIManager().getActiveWindow();
56 75

  
57 76
			if (activeWindow instanceof View3D) {
77
				// Create a file chooser
78

  
79
				JFileChooser jfc = new JFileChooser();
80
				jfc.removeChoosableFileFilter(jfc.getAcceptAllFileFilter());
81
				_iveExtensionsSupported = new Hashtable();
82
				_osgExtensionsSupported = new Hashtable();
83
				_iveExtensionsSupported.put("ive", new MyFileFilter("ive",
84
						PluginServices.getText(this, "Ficheros *.ive"), "ive"));
85
				_osgExtensionsSupported.put("osg", new MyFileFilter("osg",
86
						PluginServices.getText(this, "Ficheros *.osg"), "osg"));
87

  
88
				Iterator iter = _osgExtensionsSupported.values().iterator();
89
				while (iter.hasNext()) {
90
					jfc.addChoosableFileFilter((FileFilter) iter.next());
91
				}
92

  
93
				iter = _iveExtensionsSupported.values().iterator();
94
				while (iter.hasNext()) {
95
					jfc.addChoosableFileFilter((FileFilter) iter.next());
96
				}
97
				File f = null;
98
				if (jfc.showSaveDialog((Component) PluginServices
99
						.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
100
					f = jfc.getSelectedFile();
101
					if (f.exists()) {// file exists in the directory.
102
						int resp = JOptionPane
103
								.showConfirmDialog(
104
										(Component) PluginServices
105
												.getMainFrame(),
106
										PluginServices
107
												.getText(this,
108
														"fichero_ya_existe_seguro_desea_guardarlo")
109
												+ "\n" + f.getAbsolutePath(),
110
										PluginServices.getText(this, "guardar"),
111
										JOptionPane.YES_NO_OPTION);
112
						if (resp != JOptionPane.YES_OPTION) {// cancel pressed.
113
							return;
114
						}
115
					}// if exits.
116
					MyFileFilter filter = (MyFileFilter) jfc.getFileFilter();// ive,
117
																				// osg
118
					f = filter.normalizeExtension(f);
119
				}
58 120
				GvsigDriverOSG d = new GvsigDriverOSG();
59
				VectorialAdapter adapter = new VectorialDefaultAdapter();
121
				try {
122
					d.open(f);
123
				} catch (OpenDriverException e2) {
124
					// TODO Auto-generated catch block
125
					e2.printStackTrace();
126
				}
127
				try {
128
					d.initialize();
129
				} catch (ReadDriverException e1) {
130
					// TODO Auto-generated catch block
131
					e1.printStackTrace();
132
				}
133
				VectorialAdapter adapter = new VectorialFileAdapter(f);
60 134
				adapter.setDriver(d);
61

  
62
				_layerOSG = new FLyrVect() {
63
					@Override
64
					public boolean isPropertiesMenuVisible() {
65
						// TODO Auto-generated method stub
66
						return false;
67
					}
68
				};
135
				// LayerFactory.registerLayerClassForName("com.iver.ai2.gvsig3d.map3d.layers.OSGFLyrVect",
136
				// OSGFLyrVect.class);
137
				_layerOSG = new FLyrVect(); // {
138
				// @Override
139
				// public boolean isPropertiesMenuVisible() {
140
				// // TODO Auto-generated method stub
141
				// return false;
142
				// }
143
				// };
69 144
				View3D vista = (View3D) PluginServices.getMDIManager()
70 145
						.getActiveWindow();
71 146
				IProjectView model = vista.getModel();
72 147

  
73 148
				MapContext3D mapa = (MapContext3D) model.getMapContext();
74
				_layerOSG.setName("defaultLayerOSG");
149
				_layerOSG.setName(f.getName());
75 150
				_layerOSG.setSource(adapter);
76

  
151
				try {
152
					_layerOSG.setLegend((IVectorLegend) d.getDefaultLegend());
153
					_layerOSG.setLabelingStrategy(d
154
							.getDefaultLabelingStrategy());
155
				} catch (LegendLayerException e) {
156
					// TODO Auto-generated catch block
157
					e.printStackTrace();
158
				}
77 159
				// add 3D properties, mainly to keep track of hooked state
78 160
				Layer3DProps props3D = new Layer3DProps();
79 161
				props3D.setType(Layer3DProps.layer3DOSG);
......
83 165
				_layerOSG.setProperty("3DLayerExtension", props3D);
84 166
				_layerOSG.setProjection(mapa.getProjection());
85 167
				mapa.getLayers().addLayer(_layerOSG);
86

  
87 168
				OSGCacheService osgCacheService = (OSGCacheService) props3D
88 169
						.getCacheService();
89 170
				osgCacheService.startEditing();
......
129 210
		return false;
130 211

  
131 212
	}
132
	
133
	
134 213

  
135 214
}
branches/gvSIG_19_ext3D_osgVP_2_2_0/extensions/ext3Dgui/src/org/gvsig/gvsig3dgui/import3D/SaveLayerOSG.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 20
package org.gvsig.gvsig3dgui.import3D;
21 21

  
......
29 29
import javax.swing.filechooser.FileFilter;
30 30

  
31 31
import org.gvsig.gvsig3d.cacheservices.OSGCacheService;
32
import org.gvsig.gvsig3d.drivers.GvsigDriverOSG;
32 33
import org.gvsig.gvsig3dgui.view.View3D;
33 34
import org.gvsig.osgvp.core.osg.Group;
34 35
import org.gvsig.osgvp.core.osgdb.osgDB;
35 36
import org.gvsig.osgvp.exceptions.node.NodeException;
36 37
import org.gvsig.osgvp.exceptions.node.SaveNodeException;
37 38

  
39
import com.hardcode.gdbms.driver.exceptions.OpenDriverException;
38 40
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps;
39 41
import com.iver.andami.PluginServices;
40 42
import com.iver.andami.plugins.Extension;
41 43
import com.iver.cit.gvsig.fmap.MapContext;
42 44
import com.iver.cit.gvsig.fmap.layers.FLayer;
43 45
import com.iver.cit.gvsig.fmap.layers.FLayers;
46
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
47
import com.iver.cit.gvsig.fmap.layers.XMLException;
44 48
import com.iver.cit.gvsig.project.documents.view.IProjectView;
45 49

  
46

  
47 50
/**
48
 * @author �ngel Fraile Gri��n  e-mail: angel.fraile@iver.es
51
 * @author �ngel Fraile Gri��n e-mail: angel.fraile@iver.es
49 52
 * @since 1.1
50 53
 * 
51 54
 */
52
public class SaveLayerOSG extends Extension{
55
public class SaveLayerOSG extends Extension {
53 56

  
57
	private Hashtable _iveExtensionsSupported = null;
58
	private Hashtable _osgExtensionsSupported = null;
59
	private String _lastPath = null;
54 60

  
55
	private Hashtable 	_iveExtensionsSupported = null;
56
	private Hashtable 	_osgExtensionsSupported = null;
57
	private String 		_lastPath = null;
58
	
59 61
	/**
60 62
	 * Creating save panel options
61 63
	 */
62 64
	public void execute(String actionCommand) {
63 65
		if (actionCommand.equals("SALVARCAPA")) {
64 66
			com.iver.andami.ui.mdiManager.IWindow activeWindow = PluginServices
65
			.getMDIManager().getActiveWindow();
66
			
67
			
68
			JFileChooser jfc = new JFileChooser(_lastPath);
69
			jfc.removeChoosableFileFilter(jfc.getAcceptAllFileFilter());
70
			_iveExtensionsSupported = new Hashtable();
71
			_osgExtensionsSupported = new Hashtable();
72
			_iveExtensionsSupported.put("ive", new MyFileFilter("ive",
73
					PluginServices.getText(this, "Ficheros *.ive"), "ive"));
74
			_osgExtensionsSupported.put("osg", new MyFileFilter("osg",
75
					PluginServices.getText(this, "Ficheros *.osg"), "osg"));
67
					.getMDIManager().getActiveWindow();
76 68

  
77
			Iterator iter = _osgExtensionsSupported.values().iterator();
78
			while (iter.hasNext()) {
79
				jfc.addChoosableFileFilter((FileFilter) iter.next());
80
			}
69
			// JFileChooser jfc = new JFileChooser(_lastPath);
70
			// jfc.removeChoosableFileFilter(jfc.getAcceptAllFileFilter());
71
			// _iveExtensionsSupported = new Hashtable();
72
			// _osgExtensionsSupported = new Hashtable();
73
			// _iveExtensionsSupported.put("ive", new MyFileFilter("ive",
74
			// PluginServices.getText(this, "Ficheros *.ive"), "ive"));
75
			// _osgExtensionsSupported.put("osg", new MyFileFilter("osg",
76
			// PluginServices.getText(this, "Ficheros *.osg"), "osg"));
77
			//
78
			// Iterator iter = _osgExtensionsSupported.values().iterator();
79
			// while (iter.hasNext()) {
80
			// jfc.addChoosableFileFilter((FileFilter) iter.next());
81
			// }
82
			//
83
			// iter = _iveExtensionsSupported.values().iterator();
84
			// while (iter.hasNext()) {
85
			// jfc.addChoosableFileFilter((FileFilter) iter.next());
86
			// }
87
			//
88
			// if (jfc.showSaveDialog((Component) PluginServices.getMainFrame())
89
			// == JFileChooser.APPROVE_OPTION) {
90
			// File f = jfc.getSelectedFile();
91
			// if (f.exists()){//file exists in the directory.
92
			// int resp = JOptionPane.showConfirmDialog(
93
			// (Component) PluginServices.getMainFrame(),
94
			// PluginServices.getText(this,
95
			// "fichero_ya_existe_seguro_desea_guardarlo")+
96
			// "\n"+
97
			// f.getAbsolutePath(),
98
			// PluginServices.getText(this,"guardar"),
99
			// JOptionPane.YES_NO_OPTION);
100
			// if (resp != JOptionPane.YES_OPTION) {//cancel pressed.
101
			// return;
102
			// }
103
			// }//if exits.
104
			// if (activeWindow instanceof View3D ) {
105
			//
106
			// MyFileFilter filter = (MyFileFilter)jfc.getFileFilter();// ive,
107
			// osg
108
			// f = filter.normalizeExtension(f);
81 109

  
82
			iter = _iveExtensionsSupported.values().iterator();
83
			while (iter.hasNext()) {
84
				jfc.addChoosableFileFilter((FileFilter) iter.next());
110
			View3D vista = (View3D) PluginServices.getMDIManager()
111
					.getActiveWindow();
112
			IProjectView model = vista.getModel();
113
			MapContext mapContext = model.getMapContext();
114
			FLayers layers = mapContext.getLayers();
115
			FLayer[] actives = layers.getActives();
116
			OSGCacheService osgCache = null;
117
			if (actives.length == 1
118
					&& Layer3DProps.getLayer3DProps(actives[0]).getType() == Layer3DProps.layer3DOSG) {
119
				osgCache = (OSGCacheService) Layer3DProps.getLayer3DProps(
120
						actives[0]).getCacheService();
121

  
85 122
			}
123
			try {
124
				Group node = osgCache.getLayerNode();
125
				File f = ((GvsigDriverOSG) ((FLyrVect) actives[0]).getSource()
126
						.getDriver()).getFile();
127
				osgDB.writeNodeFile(node, f.getAbsolutePath());
128
				
129
				// ((GvsigDriverOSG
130
				// )((FLyrVect)actives[0]).getSource().getDriver()).open(f);
131
				// /actives[0].getXMLEntity().putProperty("file",f.getAbsolutePath());
86 132

  
87
			if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
88
					File f = jfc.getSelectedFile();
89
						if (f.exists()){//file exists in the directory.
90
							int resp = JOptionPane.showConfirmDialog(
91
									(Component) PluginServices.getMainFrame(),
92
									PluginServices.getText(this,
93
											"fichero_ya_existe_seguro_desea_guardarlo")+
94
											"\n"+
95
											f.getAbsolutePath(),
96
									PluginServices.getText(this,"guardar"), JOptionPane.YES_NO_OPTION);
97
							if (resp != JOptionPane.YES_OPTION) {//cancel pressed.
98
								return;
99
							}
100
						}//if exits.
101
						if (activeWindow instanceof View3D ) {
133
				// setProperty("file", f.getAbsolutePath());
134
			} catch (SaveNodeException e) {
135
				// TODO Auto-generated catch block
136
				e.printStackTrace();
137
			} catch (NodeException e) {
138
				// TODO Auto-generated catch block
139
				e.printStackTrace();
102 140

  
103
							MyFileFilter filter = (MyFileFilter)jfc.getFileFilter();// ive, osg
104
							f = filter.normalizeExtension(f);
105
							
106
							View3D vista = (View3D) PluginServices.getMDIManager().getActiveWindow();
107
							IProjectView model = vista.getModel();
108
							MapContext mapContext = model.getMapContext();
109
							FLayers layers = mapContext.getLayers();
110
							FLayer[] actives = layers.getActives();
111
							OSGCacheService osgCache = null;
112
							if (actives.length == 1
113
									&& Layer3DProps.getLayer3DProps(actives[0]).getType() == Layer3DProps.layer3DOSG) {
114
								osgCache = (OSGCacheService) Layer3DProps.getLayer3DProps(actives[0]).getCacheService();
115
								
116
							}
117
							try {
118
								Group node = osgCache.getLayerNode();
119
								osgDB.writeNodeFile(node, f.getAbsolutePath());
120
							} catch (SaveNodeException e) {
121
								// TODO Auto-generated catch block
122
								e.printStackTrace();
123
							} catch (NodeException e) {
124
								// TODO Auto-generated catch block
125
								e.printStackTrace();
126
							}
127
							
128
						//screen snapshop.
129
					}//if activeWindow.
130
				}//If aprove option.
131
			
132 141
			}
133
	}
142
			// screen snapshop.
143
		}// if activeWindow.
144
	}// If aprove option.
134 145

  
146
	// }
147
	// }
148

  
135 149
	public void initialize() {
136 150
		PluginServices.getIconTheme().registerDefault(
137 151
				"save_layer_OSG",
138 152
				this.getClass().getClassLoader().getResource(
139
				"images/plugin_edit.png"));
153
						"images/plugin_edit.png"));
140 154
	}
141 155

  
142 156
	/**
143
	 * Enable options.
144
	 * Enabled when a layer is selected and this type layer is layer3DOSG 
157
	 * Enable options. Enabled when a layer is selected and this type layer is
158
	 * layer3DOSG
145 159
	 */
146 160
	public boolean isEnabled() {
147
		
148
		View3D vista = (View3D) PluginServices.getMDIManager().getActiveWindow();
161

  
162
		View3D vista = (View3D) PluginServices.getMDIManager()
163
				.getActiveWindow();
149 164
		IProjectView model = vista.getModel();
150 165
		MapContext mapContext = model.getMapContext();
151 166
		FLayers layers = mapContext.getLayers();
152 167
		FLayer[] actives = layers.getActives();
153
		if (actives.length == 1 && Layer3DProps.getLayer3DProps(actives[0])!= null && Layer3DProps.getLayer3DProps(actives[0]).getType() == Layer3DProps.layer3DOSG) {
154
			OSGCacheService osgCache = (OSGCacheService) Layer3DProps.getLayer3DProps(actives[0]).getCacheService();
168
		if (actives.length == 1
169
				&& Layer3DProps.getLayer3DProps(actives[0]) != null
170
				&& Layer3DProps.getLayer3DProps(actives[0]).getType() == Layer3DProps.layer3DOSG) {
171

  
155 172
			return true;
156
		}else
173
		} else
157 174
			return false;
158 175
	}
159 176

  
160 177
	public boolean isVisible() {
161 178
		com.iver.andami.ui.mdiManager.IWindow f = PluginServices
162
		.getMDIManager().getActiveWindow();
179
				.getMDIManager().getActiveWindow();
163 180

  
164 181
		if (f == null) {
165 182
			return false;

Also available in: Unified diff