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

View differences:

Object3DMarkerSymbol.java
108 108
package com.iver.ai2.gvsig3d.legend.symbols;
109 109

  
110 110
import java.awt.Graphics2D;
111
import java.awt.Image;
111 112
import java.awt.Rectangle;
112 113
import java.awt.geom.AffineTransform;
114
import java.awt.image.BufferedImage;
115
import java.awt.image.ImagingOpException;
113 116
import java.io.IOException;
114 117
import java.net.MalformedURLException;
115 118
import java.net.URL;
116 119

  
120
import javax.print.attribute.PrintRequestAttributeSet;
117 121
import javax.swing.ImageIcon;
122
import javax.swing.plaf.basic.BasicScrollPaneUI.HSBChangeListener;
118 123

  
119 124
import org.apache.log4j.Logger;
125
import org.gvsig.osgvp.Matrix;
126
import org.gvsig.osgvp.Node;
120 127
import org.gvsig.osgvp.Vec3;
128
import org.gvsig.osgvp.osgDB;
129
import org.gvsig.osgvp.exceptions.image.ImageConversionException;
130
import org.gvsig.osgvp.exceptions.node.LoadNodeException;
131
import org.gvsig.osgvp.viewer.Camera;
132
import org.gvsig.osgvp.viewer.IViewer;
133
import org.gvsig.osgvp.viewer.OSGViewer;
121 134

  
122 135
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
123 136
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps;
124 137
import com.iver.andami.PluginServices;
138
import com.iver.andami.messages.NotificationManager;
125 139
import com.iver.andami.ui.mdiManager.IWindow;
126 140
import com.iver.cit.gvsig.fmap.MapContext;
127 141
import com.iver.cit.gvsig.fmap.Messages;
......
140 154
	private static final float SELECTION_OPACITY_FACTOR = .3F;
141 155
	// transient private Image img;
142 156
	private String object3DPath;
157
	private OSGViewer _osgViewer;
143 158
	private boolean selected;
144 159
	private Vec3 scale;
145 160
	private Vec3 rotation;
......
172 187
	 *            , URL of the image when it is selected in the map
173 188
	 * @throws IOException
174 189
	 */
175
	public Object3DMarkerSymbol(URL object3DURL) throws IOException {
176
		setObject3DPath(object3DURL);
177
	}
178

  
179
	public Object3DMarkerSymbol(String object3DPath) throws IOException {
190
	// public Object3DMarkerSymbol(URL object3DURL) throws IOException {
191
	// setObject3DPath(object3DURL);
192
	// }
193
	public Object3DMarkerSymbol(String object3DPath, IViewer viewer)
194
			throws IOException {
195
		super();
196
		// System.out.println("NEW 3DMARKERSYMBOL");
180 197
		this.object3DPath = object3DPath;
198
		_osgViewer = (OSGViewer) viewer;
181 199
	}
182 200

  
183 201
	/**
......
197 215

  
198 216
	public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp,
199 217
			Cancellable cancel) {
200
		// FPoint2D p = (FPoint2D) shp;
201
		// double x, y;
202
		// int size = (int) Math.round(getSize());
203
		// double halfSize = getSize()/2;
204
		// x = p.getX() - halfSize;
205
		// y = p.getY() - halfSize;
206
		// int xOffset = (int) getOffset().getX();
207
		// int yOffset = (int) getOffset().getY();
208
		//
209
		// if (size > 0) {
210
		// BackgroundFileStyle bg = (!selected) ? bgImage : bgSelImage ;
211
		// Rectangle rect = new Rectangle( size, size );
212
		// g.translate(x+xOffset, y+yOffset);
213
		// g.rotate(getRotation(), halfSize, halfSize);
214
		// try {
215
		// bg.drawInsideRectangle(g, rect);
216
		// } catch (SymbolDrawingException e) {
217
		// Logger.getLogger(getClass()).warn(Messages.getString(
218
		// "label_style_could_not_be_painted"), e);
219
		// }
220
		// g.rotate(-getRotation(), halfSize, halfSize);
221
		// g.translate(-(x+xOffset), -(y+yOffset));
222
		//
223
		// }
224 218

  
225 219
	}
226 220

  
227 221
	public void drawInsideRectangle(Graphics2D g,
228
			AffineTransform scaleInstance, Rectangle r)
229
			throws SymbolDrawingException {
230
		// TODO Auto-generated method stub
231
		// super.drawInsideRectangle(g, scaleInstance, r);
222
			AffineTransform scaleInstance, Rectangle r,
223
			PrintRequestAttributeSet properties) throws SymbolDrawingException {
232 224

  
233
		ImageIcon image;
234
		// Setting the size symbol
235
		int size = 30;
225
		if (_osgViewer == null || _osgViewer.getSceneData() == null) {
236 226

  
237
		// Generating the image
238
//		image = new ImageIcon(
239
//				"c:/Documents and Settings/Julio.IVER/Escritorio/img.png");
240
		image = new ImageIcon(tempScreenshotimage);
227
			try {
228

  
229
				_osgViewer = new OSGViewer();
230
				Node node = osgDB.readNodeFile(object3DPath);
231
				_osgViewer.setSceneData(node);
232

  
233
			} catch (IOException e) {
234
				Logger.getLogger(getClass()).error(
235
						Messages.getString("invalid_url"));
236

  
237
			} catch (LoadNodeException e) {
238
				// TODO Auto-generated catch block
239
				e.printStackTrace();
240
			}
241

  
242
		}
243

  
244
		int xSize = r.width;
245
		int ySize = r.height;
246

  
241 247
		int x = 0;
242 248
		int y = 0;
243 249
		if (g.getClipBounds() != null) {
244
			x = (int) (g.getClipBounds().getCenterX() - (size / 2));
245
			y = (int) (g.getClipBounds().getCenterY() - (size / 2));
250
			x = (int) (g.getClipBounds().getCenterX() - (xSize / 2));
251
			y = (int) (g.getClipBounds().getCenterY() - (ySize / 2));
246 252
		}
247
		g.drawImage(image.getImage(), x, y, size, size, null, null);
248 253

  
254
		OSGViewer canvasoff = new OSGViewer();
255
		canvasoff.setSceneData(_osgViewer.getSceneData());
256
		canvasoff.setUpViewerInBackground(0, 0, xSize, ySize);
257

  
258
		Camera refCam = _osgViewer.getCamera();
259
		Matrix refView = refCam.getViewMatrix();
260
		Matrix refProy = refCam.getProjectionMatrix();
261
		Matrix.Perspective pers = refProy.getPerspective();
262
		Camera viewCam = new Camera();
263

  
264
		viewCam.setProjectionMatrixAsPerspective(pers.fovy, xSize / ySize,
265
				pers.zNear, pers.zFar);
266
		viewCam.setViewMatrix(refView);
267

  
268
		canvasoff.setCamera(viewCam);
269
		canvasoff.setViewport(0, 0, xSize, ySize);
270
		canvasoff.takeScreenshotToMemory();
271
		canvasoff.takeScreenshot(tempScreenshotimage);
272
		canvasoff.frame();
273
		org.gvsig.osgvp.Image osgImage = canvasoff.getScreenshotImage();
274

  
275
		BufferedImage bi = null;
276
		try {
277
			bi = osgImage.getBufferedImage();
278
		} catch (ImageConversionException e) {
279

  
280
			e.printStackTrace();
281
			return;
282
		} catch (IOException e) {
283

  
284
			e.printStackTrace();
285
			return;
286
		}
287

  
288
		double scalex = xSize / bi.getWidth(null);
289
		double scaley = ySize / bi.getHeight(null);
290
		try {
291
			AffineTransform xform = AffineTransform.getScaleInstance(scalex,
292
					scaley);
293
			AffineTransform xpos = AffineTransform.getTranslateInstance(x, y);
294
			xpos.concatenate(xform);
295
			g.drawRenderedImage(bi, xpos);
296
		} catch (ImagingOpException e) {
297
			NotificationManager.addError("Dibujando FFramePicture", e);
298
		}
299

  
249 300
	}
250 301

  
251 302
	public XMLEntity getXMLEntity() {
......
254 305
		xml.putProperty("isShapeVisible", isShapeVisible());
255 306
		xml.putProperty("desc", getDescription());
256 307
		xml.putProperty("imagePath", object3DPath);
257
		xml.putProperty("tempScreenshotimage",tempScreenshotimage);
308
		xml.putProperty("tempScreenshotimage", tempScreenshotimage);
258 309

  
259 310
		xml.putProperty("scalex", scale.x());
260 311
		xml.putProperty("scaley", scale.y());
261 312
		xml.putProperty("scalez", scale.z());
262
		
313

  
263 314
		xml.putProperty("rotationx", rotation.x());
264 315
		xml.putProperty("rotationy", rotation.y());
265 316
		xml.putProperty("rotationz", rotation.z());
266
		
317

  
267 318
		xml.putProperty("autoRotate", isAutoRotate());
268
		
269 319

  
270 320
		return xml;
271 321
	}
......
310 360
		setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
311 361
		object3DPath = xml.getStringProperty("imagePath");
312 362
		tempScreenshotimage = xml.getStringProperty("tempScreenshotimage");
313
//		setRotation(xml.getDoubleProperty("rotation"));
314
		
363
		// setRotation(xml.getDoubleProperty("rotation"));
364

  
315 365
		this.scale = new Vec3();
316 366
		scale.setX(xml.getDoubleProperty("scalex"));
317 367
		scale.setY(xml.getDoubleProperty("scaley"));
......
321 371
		rotation.setX(xml.getDoubleProperty("rotationx"));
322 372
		rotation.setY(xml.getDoubleProperty("rotationy"));
323 373
		rotation.setZ(xml.getDoubleProperty("rotationz"));
324
		
374

  
325 375
		setAutoRotate(xml.getBooleanProperty("autoRotate"));
326
		
327 376

  
328 377
		try {
329 378
			setObject3DPath(new URL(object3DPath));
379
			_osgViewer = new OSGViewer();
380
			Node node = osgDB.readNodeFile(object3DPath);
381
			_osgViewer.setSceneData(node);
330 382
		} catch (MalformedURLException e) {
331 383
			Logger.getLogger(getClass()).error(
332 384
					Messages.getString("invalid_url"));
......
334 386
			Logger.getLogger(getClass()).error(
335 387
					Messages.getString("invalid_url"));
336 388

  
389
		} catch (LoadNodeException e) {
390
			// TODO Auto-generated catch block
391
			e.printStackTrace();
337 392
		}
338 393

  
339 394
	}
......
356 411

  
357 412
	public void setScale(Vec3 scale) {
358 413
		this.scale = scale;
359
		
414

  
360 415
	}
361 416

  
362 417
	public void setRotation(Vec3 rotation) {
363 418
		this.rotation = rotation;
364
		
419

  
365 420
	}
366 421

  
367 422
	public Vec3 getScale() {
......
370 425

  
371 426
	public Vec3 getRotationObject() {
372 427
		return this.rotation;
373
	
428

  
374 429
	}
375 430

  
376 431
	public void setSnapshot(String tempScreenshotimage) {
377 432
		this.tempScreenshotimage = tempScreenshotimage;
378
		
433

  
379 434
	}
380 435

  
381 436
}

Also available in: Unified diff