Revision 30106 trunk/libraries/lib3DMap-share/src/main/java/com/iver/ai2/gvsig3d/legend/symbols/Object3DMarker.java

View differences:

Object3DMarker.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
1
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
2 2
 *
3 3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4 4
 *
......
20 20
 *
21 21
 *  Generalitat Valenciana
22 22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
23
 *   Av. Blasco Ib��ez, 50
24 24
 *   46010 VALENCIA
25 25
 *   SPAIN
26 26
 *
......
40 40
 */
41 41
package com.iver.ai2.gvsig3d.legend.symbols;
42 42

  
43
import java.awt.Checkbox;
44 43
import java.awt.Component;
45 44
import java.awt.Dimension;
46
import java.awt.Font;
47 45
import java.awt.GridBagConstraints;
48 46
import java.awt.GridBagLayout;
49 47
import java.awt.event.ActionEvent;
50 48
import java.awt.event.ActionListener;
49
import java.awt.event.MouseEvent;
50
import java.awt.event.MouseListener;
51 51
import java.io.File;
52 52
import java.io.FileNotFoundException;
53 53
import java.io.IOException;
......
64 64
import javax.swing.JTextField;
65 65
import javax.swing.filechooser.FileFilter;
66 66

  
67
import org.gvsig.osgvp.Group;
67 68
import org.gvsig.osgvp.Node;
68 69
import org.gvsig.osgvp.Vec3;
69 70
import org.gvsig.osgvp.osgDB;
......
111 112
	private JButton btn;
112 113
	private File fileOSG;
113 114
	private String filePath = "";
114
	
115
	private double _scaleX = 1.0, _scaleY = 1.0, _scaleZ = 1.0, _rotX, _rotY,
116
			_rotZ;
117

  
115 118
	private static String lastPath = "";
116 119

  
117 120
	public String getFilePath() {
......
124 127

  
125 128
	private ActionListener chooseAction = new ActionListener() {
126 129

  
127

  
128 130
		public void actionPerformed(ActionEvent e) {
129 131

  
130 132
			JFileChooser jfc = new JFileChooser(lastPath);
131 133
			jfc.removeChoosableFileFilter(jfc.getAcceptAllFileFilter());
132
			
133
			
134
			List filterListFile =  new ArrayList<MyFileFilter3D>();
135
			
136
			filterListFile.add(new MyFileFilter3D("ive",
137
					PluginServices.getText(this, "Ficheros *.ive"), "ive"));
138
			filterListFile.add(new MyFileFilter3D("3ds",
139
					PluginServices.getText(this, "Ficheros *.3ds"), "3ds"));
140
			filterListFile.add(new MyFileFilter3D("obj",
141
					PluginServices.getText(this, "Ficheros *.obj"), "obj"));
142
			filterListFile.add(new MyFileFilter3D("osg",
143
					PluginServices.getText(this, "Ficheros *.osg"), "osg"));
144 134

  
145
			Iterator iter = filterListFile.iterator();
135
			List<MyFileFilter3D> filterListFile = new ArrayList<MyFileFilter3D>();
136

  
137
			filterListFile.add(new MyFileFilter3D("ive", PluginServices
138
					.getText(this, "Ficheros *.ive"), "ive"));
139
			filterListFile.add(new MyFileFilter3D("3ds", PluginServices
140
					.getText(this, "Ficheros *.3ds"), "3ds"));
141
			filterListFile.add(new MyFileFilter3D("obj", PluginServices
142
					.getText(this, "Ficheros *.obj"), "obj"));
143
			filterListFile.add(new MyFileFilter3D("osg", PluginServices
144
					.getText(this, "Ficheros *.osg"), "osg"));
145

  
146
			Iterator<MyFileFilter3D> iter = filterListFile.iterator();
146 147
			while (iter.hasNext()) {
147 148
				jfc.addChoosableFileFilter((FileFilter) iter.next());
148 149
			}
......
157 158
					fileOSG = filter.normalizeExtension(fileOSG);
158 159
					filePath = fileOSG.getAbsolutePath();
159 160
					filePathTextField.setText(filePath);
160
					updatePreview();
161
					loadFile();
161 162
					lastPath = fileOSG.getPath();
163
					fireSymbolChangedEvent();
162 164
				} else {
163 165
					JOptionPane.showMessageDialog(null,
164 166
							"El fichero no existe.", "Fichero no encontrado",
......
186 188

  
187 189
	public Object3DMarker(SymbolEditor owner) {
188 190
		super(owner);
191

  
189 192
		initialize();
190
		
191
	
193

  
192 194
	}
193 195

  
194
	
195 196
	@Override
196 197
	protected void finalize() throws Throwable {
197
		// TODO Auto-generated method stub
198 198
		super.finalize();
199
		// this part is for test
199

  
200 200
		ViewerFactory.getInstance().stopAnimator();
201 201
		_canvas3d.dispose();
202
		///////////////////////////
202

  
203 203
	}
204 204

  
205 205
	/**
......
239 239
		rigthBottomPanelConstrain.weightx = 0.5;
240 240
		rigthBottomPanelConstrain.weighty = 1.0;
241 241
		myTab.add(getRigthBottomPanel(), rigthBottomPanelConstrain);
242
		
243
	
242

  
244 243
		tabs.add(myTab);
245
		
246
		
244

  
247 245
		PluginServices core = PluginServices.getPluginServices("com.iver.core");
248
		if (core!= null){
249
			if (core.getPersistentXML().contains("DataFolder")){
250
				
251
				lastPath = core.getPersistentXML().getStringProperty("DataFolder");
246
		if (core != null) {
247
			if (core.getPersistentXML().contains("DataFolder")) {
248

  
249
				lastPath = core.getPersistentXML().getStringProperty(
250
						"DataFolder");
252 251
			}
253 252
		}
254 253
	}
......
264 263
			gridBagConstraints.insets = new java.awt.Insets(2, 5, 2, 5);
265 264
			// picture file label
266 265
			lblFileName = new JLabel("Seleccione fihero :");
267
//			lblFileName.setFont(lblFileName.getFont().deriveFont(Font.BOLD));
266
			// lblFileName.setFont(lblFileName.getFont().deriveFont(Font.BOLD));
268 267

  
269 268
			topPanel.add(lblFileName, gridBagConstraints);
270 269

  
......
277 276

  
278 277
			filePathTextField = new JTextField();
279 278
			topPanel.add(filePathTextField, gridBagConstraints);
279
			if (lastPath != null) {
280
				filePathTextField.setText(lastPath);
281
				setFilePath(lastPath);
282
			}
280 283

  
281 284
			gridBagConstraints.gridx = 1;
282 285
			gridBagConstraints.gridy = 1;
......
287 290
			// button browse
288 291
			btn = new JButton(PluginServices.getText(this, "browse"));
289 292
			btn.addActionListener(chooseAction);
290
			
293

  
291 294
			topPanel.add(btn, gridBagConstraints);
292
			
295

  
293 296
			gridBagConstraints.gridx = 0;
294 297
			gridBagConstraints.gridy = 2;
295 298
			gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
296
//			gridBagConstraints.weightx = 0.25;
297
			
299
			// gridBagConstraints.weightx = 0.25;
300

  
298 301
			autorotate = new JCheckBox();
299 302
			autorotate.setSelected(false);
300 303
			autorotate.setText("Autorotate");
301
			
302
			
304

  
303 305
			topPanel.add(autorotate, gridBagConstraints);
304 306

  
305 307
		}
......
340 342
			scaleTextFieldX = new JTextField();
341 343
			// scaleTextFieldX.setName(); // NOI18N
342 344
			scaleTextFieldX.setText("1");
345

  
343 346
			gridBagConstraints = new java.awt.GridBagConstraints();
344 347
			gridBagConstraints.gridx = 1;
345 348
			gridBagConstraints.gridy = 1;
......
348 351
			gridBagConstraints.insets = new java.awt.Insets(2, 5, 2, 5);
349 352
			leftBottomPanel.add(scaleTextFieldX, gridBagConstraints);
350 353

  
351
			// Rotation Y
354
			// Scale Y
352 355
			Component scaleYLabel = new JLabel("Escalado Y");
353 356
			scaleYLabel.setName("jLabel5"); // NOI18N
354 357
			gridBagConstraints = new java.awt.GridBagConstraints();
......
358 361
			leftBottomPanel.add(scaleYLabel, gridBagConstraints);
359 362

  
360 363
			scaleTextFieldY = new JTextField();
361
//			scaleTextFieldY.setName("0"); // NOI18N
364
			// scaleTextFieldY.setName("0"); // NOI18N
362 365
			scaleTextFieldY.setText("1");
366

  
363 367
			gridBagConstraints = new java.awt.GridBagConstraints();
364 368
			gridBagConstraints.gridx = 1;
365 369
			gridBagConstraints.gridy = 2;
......
368 372
			gridBagConstraints.insets = new java.awt.Insets(2, 5, 2, 5);
369 373
			leftBottomPanel.add(scaleTextFieldY, gridBagConstraints);
370 374

  
371
			// Rotation Z
375
			// Scale Z
372 376
			Component scaleZLabel = new JLabel("Escalado Z");
373 377
			scaleZLabel.setName("jLabel5"); // NOI18N
374 378
			gridBagConstraints = new java.awt.GridBagConstraints();
......
378 382
			leftBottomPanel.add(scaleZLabel, gridBagConstraints);
379 383

  
380 384
			scaleTextFieldZ = new JTextField();
381
//			scaleTextFieldZ.setName("0"); // NOI18N
385
			// scaleTextFieldZ.setName("0"); // NOI18N
382 386
			scaleTextFieldZ.setText("1");
387

  
383 388
			gridBagConstraints = new java.awt.GridBagConstraints();
384 389
			gridBagConstraints.gridx = 1;
385 390
			gridBagConstraints.gridy = 3;
......
398 403
			leftBottomPanel.add(rotationXLabel, gridBagConstraints);
399 404

  
400 405
			rotationTextFieldX = new JTextField();
401
//			rotationTextFieldX.setName("0"); // NOI18N
406
			// rotationTextFieldX.setName("0"); // NOI18N
402 407
			rotationTextFieldX.setText("0");
408

  
403 409
			gridBagConstraints = new java.awt.GridBagConstraints();
404 410
			gridBagConstraints.gridx = 1;
405 411
			gridBagConstraints.gridy = 4;
......
420 426
			rotationTextFieldY = new JTextField();
421 427
			rotationTextFieldY.setName("0"); // NOI18N
422 428
			rotationTextFieldY.setText("0");
429

  
423 430
			gridBagConstraints = new java.awt.GridBagConstraints();
424 431
			gridBagConstraints.gridx = 1;
425 432
			gridBagConstraints.gridy = 5;
......
431 438
			// Rotation Z
432 439
			Component rotationZlabel = new JLabel("Rotacion Z");
433 440
			rotationZlabel.setName("jLabel4"); // NOI18N
441

  
434 442
			gridBagConstraints = new java.awt.GridBagConstraints();
435 443
			gridBagConstraints.gridx = 0;
436 444
			gridBagConstraints.gridy = 6;
......
438 446
			leftBottomPanel.add(rotationZlabel, gridBagConstraints);
439 447

  
440 448
			rotationTextFieldZ = new JTextField();
441
//			rotationTextFieldZ.setName("0"); // NOI18N
449
			// rotationTextFieldZ.setName("0"); // NOI18N
442 450
			rotationTextFieldZ.setText("0");
451

  
443 452
			gridBagConstraints = new java.awt.GridBagConstraints();
444 453
			gridBagConstraints.gridx = 1;
445 454
			gridBagConstraints.gridy = 6;
......
471 480
			ViewerFactory.getInstance().startAnimator();
472 481

  
473 482
			_canvas3d.setSize(size, size);
474
			
475
			updatePreview();
476 483

  
484
			loadFile();
485

  
477 486
			constrain.gridx = 0;
478 487
			constrain.gridy = 1;
479 488
			aux3.add((Component) _canvas3d);
480 489
			rigthBottomPanel.add(aux3, constrain);
481
			
482
			
490

  
491
			_canvas3d.addMouseListener(new MouseListener() {
492

  
493
				public void mouseClicked(MouseEvent arg0) {
494

  
495
				}
496

  
497
				public void mouseEntered(MouseEvent arg0) {
498

  
499
				}
500

  
501
				public void mouseExited(MouseEvent arg0) {
502

  
503
				}
504

  
505
				public void mousePressed(MouseEvent arg0) {
506

  
507
				}
508

  
509
				public void mouseReleased(MouseEvent arg0) {
510

  
511
					if (_canvas3d.getOSGViewer().getSceneData() != null)
512
						fireSymbolChangedEvent();
513

  
514
				}
515

  
516
			});
517

  
483 518
		}
484 519
		return rigthBottomPanel;
485 520
	}
486
	
487
	
488
	private void updatePreview(){
521

  
522
	private void loadFile() {
489 523
		try {
490 524
			Node node = null;
491 525
			if (this.getFilePath() == "") {
492
				node = osgDB.readNodeFile("D:/modelos3d/cow.ive");
526
				node = new Group();
493 527
			} else {
494 528
				node = osgDB.readNodeFile(filePath);
495 529
			}
530

  
496 531
			_canvas3d.getOSGViewer().setSceneData(node);
497
			tempScreenshotimage = System.getenv("TMP")+"/tempScreenshotimage.png";
532

  
533
			_canvas3d.getOSGViewer().getCameraManipulator()
534
					.computeHomePosition();
535

  
536
			tempScreenshotimage = System.getProperty("java.io.tmpdir")
537
					+ "/tempScreenshotimage.png";
538
			// tempScreenshotimage = System.getenv("TMP")
539
			// + "/tempScreenshotimage.png";
498 540
			System.err.println("screenshot del simbolo " + tempScreenshotimage);
499 541
			_canvas3d.getOSGViewer().takeScreenshot(tempScreenshotimage);
542

  
500 543
		} catch (LoadNodeException e) {
501
			// TODO Auto-generated catch block
544

  
502 545
			e.printStackTrace();
503 546
		} catch (FileNotFoundException e) {
504
			// TODO Auto-generated catch block
547

  
505 548
			e.printStackTrace();
506 549
		}
507 550
	}
......
512 555
		try {
513 556
			Object3DMarkerSymbol symbol = null;
514 557

  
515
			if (this.getFilePath().equals(""))
516
				symbol = null;
517
			else {
518
				symbol = new Object3DMarkerSymbol(this.getFilePath());
519
				symbol.setScale(new Vec3(Double.parseDouble(scaleTextFieldX
520
						.getText()), Double.parseDouble(scaleTextFieldY
521
						.getText()), Double.parseDouble(scaleTextFieldZ
522
						.getText())));
523
				symbol.setRotation(new Vec3(Double
524
						.parseDouble(rotationTextFieldX.getText()), Double
525
						.parseDouble(rotationTextFieldY.getText()), Double
526
						.parseDouble(rotationTextFieldZ.getText())));
527
				
528
				symbol.setAutoRotate(autorotate.isSelected());
529
				symbol.setSnapshot(tempScreenshotimage);
530
			}
558
			// if (this.getFilePath().equals(""))
559
			// symbol = new Object3DMarkerSymbol(this.getFilePath(), _canvas3d
560
			// .getOSGViewer());
561
			// else {
562
			symbol = new Object3DMarkerSymbol(this.getFilePath(), _canvas3d
563
					.getOSGViewer());
564
			symbol.setScale(new Vec3(Double.parseDouble(scaleTextFieldX
565
					.getText()), Double.parseDouble(scaleTextFieldY.getText()),
566
					Double.parseDouble(scaleTextFieldZ.getText())));
567
			symbol.setRotation(new Vec3(Double.parseDouble(rotationTextFieldX
568
					.getText()), Double.parseDouble(rotationTextFieldY
569
					.getText()), Double.parseDouble(rotationTextFieldZ
570
					.getText())));
531 571

  
532
			
572
			symbol.setAutoRotate(autorotate.isSelected());
573
			symbol.setSnapshot(tempScreenshotimage);
574
			// }
575

  
533 576
			return symbol;
534 577
		} catch (IOException e) {
535 578
			return SymbologyFactory.getWarningSymbol(PluginServices.getText(

Also available in: Unified diff