svn-gvsig-desktop / trunk / libraries / lib3DMap-share / src / main / java / com / iver / ai2 / gvsig3d / legend / symbols / Object3DMarkerSymbol.java @ 30106
History | View | Annotate | Download (11.8 KB)
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 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib��ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
|
42 |
/* CVS MESSAGES:
|
43 |
*
|
44 |
* $Id: PictureMarkerSymbol.java 15593 2007-10-29 13:01:13Z jdominguez $
|
45 |
* $Log$
|
46 |
* Revision 1.17 2007-09-21 12:25:32 jaume
|
47 |
* cancellation support extended down to the IGeometry and ISymbol level
|
48 |
*
|
49 |
* Revision 1.16 2007/09/19 16:22:04 jaume
|
50 |
* removed unnecessary imports
|
51 |
*
|
52 |
* Revision 1.15 2007/09/11 07:46:55 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
* Revision 1.14 2007/08/16 06:55:19 jvidal
|
56 |
* javadoc updated
|
57 |
*
|
58 |
* Revision 1.13 2007/08/09 06:42:24 jvidal
|
59 |
* javadoc
|
60 |
*
|
61 |
* Revision 1.12 2007/08/08 12:05:17 jvidal
|
62 |
* javadoc
|
63 |
*
|
64 |
* Revision 1.11 2007/07/18 06:54:35 jaume
|
65 |
* continuing with cartographic support
|
66 |
*
|
67 |
* Revision 1.10 2007/07/03 10:58:29 jaume
|
68 |
* first refactor on CartographicSupport
|
69 |
*
|
70 |
* Revision 1.9 2007/06/29 13:07:01 jaume
|
71 |
* +PictureLineSymbol
|
72 |
*
|
73 |
* Revision 1.8 2007/06/11 12:25:48 jaume
|
74 |
* ISymbol drawing integration tests (markers and lines)
|
75 |
*
|
76 |
* Revision 1.7 2007/06/07 06:50:40 jaume
|
77 |
* *** empty log message ***
|
78 |
*
|
79 |
* Revision 1.6 2007/05/29 15:46:37 jaume
|
80 |
* *** empty log message ***
|
81 |
*
|
82 |
* Revision 1.5 2007/05/08 08:47:40 jaume
|
83 |
* *** empty log message ***
|
84 |
*
|
85 |
* Revision 1.4 2007/03/21 17:36:22 jaume
|
86 |
* *** empty log message ***
|
87 |
*
|
88 |
* Revision 1.3 2007/03/09 11:20:57 jaume
|
89 |
* Advanced symbology (start committing)
|
90 |
*
|
91 |
* Revision 1.1.2.4 2007/02/21 07:34:09 jaume
|
92 |
* labeling starts working
|
93 |
*
|
94 |
* Revision 1.1.2.3 2007/02/16 10:54:12 jaume
|
95 |
* multilayer splitted to multilayerline, multilayermarker,and multilayerfill
|
96 |
*
|
97 |
* Revision 1.1.2.2 2007/02/15 16:23:44 jaume
|
98 |
* *** empty log message ***
|
99 |
*
|
100 |
* Revision 1.1.2.1 2007/02/09 07:47:05 jaume
|
101 |
* Isymbol moved
|
102 |
*
|
103 |
* Revision 1.1 2007/01/24 17:58:22 jaume
|
104 |
* new features and architecture error fixes
|
105 |
*
|
106 |
*
|
107 |
*/
|
108 |
package com.iver.ai2.gvsig3d.legend.symbols; |
109 |
|
110 |
import java.awt.Graphics2D; |
111 |
import java.awt.Image; |
112 |
import java.awt.Rectangle; |
113 |
import java.awt.geom.AffineTransform; |
114 |
import java.awt.image.BufferedImage; |
115 |
import java.awt.image.ImagingOpException; |
116 |
import java.io.IOException; |
117 |
import java.net.MalformedURLException; |
118 |
import java.net.URL; |
119 |
|
120 |
import javax.print.attribute.PrintRequestAttributeSet; |
121 |
import javax.swing.ImageIcon; |
122 |
import javax.swing.plaf.basic.BasicScrollPaneUI.HSBChangeListener; |
123 |
|
124 |
import org.apache.log4j.Logger; |
125 |
import org.gvsig.osgvp.Matrix; |
126 |
import org.gvsig.osgvp.Node; |
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; |
134 |
|
135 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
136 |
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps; |
137 |
import com.iver.andami.PluginServices; |
138 |
import com.iver.andami.messages.NotificationManager; |
139 |
import com.iver.andami.ui.mdiManager.IWindow; |
140 |
import com.iver.cit.gvsig.fmap.MapContext; |
141 |
import com.iver.cit.gvsig.fmap.Messages; |
142 |
import com.iver.cit.gvsig.fmap.core.FShape; |
143 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
144 |
import com.iver.cit.gvsig.fmap.core.symbols.AbstractMarkerSymbol; |
145 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
146 |
import com.iver.cit.gvsig.fmap.core.symbols.SymbolDrawingException; |
147 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
148 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
149 |
import com.iver.cit.gvsig.project.documents.view.gui.BaseView; |
150 |
import com.iver.utiles.XMLEntity; |
151 |
import com.iver.utiles.swing.threads.Cancellable; |
152 |
|
153 |
public class Object3DMarkerSymbol extends AbstractMarkerSymbol { |
154 |
private static final float SELECTION_OPACITY_FACTOR = .3F; |
155 |
// transient private Image img;
|
156 |
private String object3DPath; |
157 |
private OSGViewer _osgViewer;
|
158 |
private boolean selected; |
159 |
private Vec3 scale;
|
160 |
private Vec3 rotation;
|
161 |
private boolean autoRotate = false; |
162 |
private String tempScreenshotimage; |
163 |
|
164 |
// transient private Image selImg;
|
165 |
|
166 |
public boolean isAutoRotate() { |
167 |
return autoRotate;
|
168 |
} |
169 |
|
170 |
public void setAutoRotate(boolean autoRotate) { |
171 |
this.autoRotate = autoRotate;
|
172 |
} |
173 |
|
174 |
/**
|
175 |
* Constructor method
|
176 |
*/
|
177 |
public Object3DMarkerSymbol() {
|
178 |
super();
|
179 |
} |
180 |
|
181 |
/**
|
182 |
* Constructor method
|
183 |
*
|
184 |
* @param imageURL
|
185 |
* , URL of the normal image
|
186 |
* @param selImageURL
|
187 |
* , URL of the image when it is selected in the map
|
188 |
* @throws IOException
|
189 |
*/
|
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");
|
197 |
this.object3DPath = object3DPath;
|
198 |
_osgViewer = (OSGViewer) viewer; |
199 |
} |
200 |
|
201 |
/**
|
202 |
* Sets the file for the image to be used as a marker symbol
|
203 |
*
|
204 |
* @param imageFile
|
205 |
* , File
|
206 |
* @throws IOException
|
207 |
*/
|
208 |
public void setObject3DPath(URL Object3DUrl) throws IOException { |
209 |
object3DPath = Object3DUrl.toString(); |
210 |
} |
211 |
|
212 |
public ISymbol getSymbolForSelection() {
|
213 |
return null; |
214 |
} |
215 |
|
216 |
public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp, |
217 |
Cancellable cancel) { |
218 |
|
219 |
} |
220 |
|
221 |
public void drawInsideRectangle(Graphics2D g, |
222 |
AffineTransform scaleInstance, Rectangle r, |
223 |
PrintRequestAttributeSet properties) throws SymbolDrawingException { |
224 |
|
225 |
if (_osgViewer == null || _osgViewer.getSceneData() == null) { |
226 |
|
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 |
|
247 |
int x = 0; |
248 |
int y = 0; |
249 |
if (g.getClipBounds() != null) { |
250 |
x = (int) (g.getClipBounds().getCenterX() - (xSize / 2)); |
251 |
y = (int) (g.getClipBounds().getCenterY() - (ySize / 2)); |
252 |
} |
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 |
|
300 |
} |
301 |
|
302 |
public XMLEntity getXMLEntity() {
|
303 |
XMLEntity xml = new XMLEntity();
|
304 |
xml.putProperty("className", getClassName());
|
305 |
xml.putProperty("isShapeVisible", isShapeVisible());
|
306 |
xml.putProperty("desc", getDescription());
|
307 |
xml.putProperty("imagePath", object3DPath);
|
308 |
xml.putProperty("tempScreenshotimage", tempScreenshotimage);
|
309 |
|
310 |
xml.putProperty("scalex", scale.x());
|
311 |
xml.putProperty("scaley", scale.y());
|
312 |
xml.putProperty("scalez", scale.z());
|
313 |
|
314 |
xml.putProperty("rotationx", rotation.x());
|
315 |
xml.putProperty("rotationy", rotation.y());
|
316 |
xml.putProperty("rotationz", rotation.z());
|
317 |
|
318 |
xml.putProperty("autoRotate", isAutoRotate());
|
319 |
|
320 |
return xml;
|
321 |
} |
322 |
|
323 |
@Override
|
324 |
public boolean isSuitableFor(IGeometry geom) { |
325 |
boolean suitable = false; |
326 |
com.iver.andami.ui.mdiManager.IWindow[] f = PluginServices
|
327 |
.getMDIManager().getAllWindows(); |
328 |
if (f == null) { |
329 |
return false; |
330 |
} |
331 |
for (int i = 0; i < f.length; i++) { |
332 |
if (f[i] instanceof BaseView) { |
333 |
BaseView view = (BaseView) f[i]; |
334 |
MapContext mapContext = view.getMapControl().getMapContext(); |
335 |
FLayers layer = mapContext.getLayers(); |
336 |
FLayer[] actives = layer.getActives();
|
337 |
if (actives.length == 1) { |
338 |
Layer3DProps props3D = Layer3DProps |
339 |
.getLayer3DProps(actives[0]);
|
340 |
if ((props3D != null) |
341 |
&& (props3D.getType() == Layer3DProps.layer3DVector)) { |
342 |
suitable = true;
|
343 |
} else {
|
344 |
suitable = false;
|
345 |
} |
346 |
} |
347 |
} |
348 |
|
349 |
} |
350 |
System.out.println("is suitable " + suitable); |
351 |
return suitable;
|
352 |
} |
353 |
|
354 |
public String getClassName() { |
355 |
return getClass().getName();
|
356 |
} |
357 |
|
358 |
public void setXMLEntity(XMLEntity xml) { |
359 |
setDescription(xml.getStringProperty("desc"));
|
360 |
setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
|
361 |
object3DPath = xml.getStringProperty("imagePath");
|
362 |
tempScreenshotimage = xml.getStringProperty("tempScreenshotimage");
|
363 |
// setRotation(xml.getDoubleProperty("rotation"));
|
364 |
|
365 |
this.scale = new Vec3(); |
366 |
scale.setX(xml.getDoubleProperty("scalex"));
|
367 |
scale.setY(xml.getDoubleProperty("scaley"));
|
368 |
scale.setZ(xml.getDoubleProperty("scalez"));
|
369 |
|
370 |
this.rotation = new Vec3(); |
371 |
rotation.setX(xml.getDoubleProperty("rotationx"));
|
372 |
rotation.setY(xml.getDoubleProperty("rotationy"));
|
373 |
rotation.setZ(xml.getDoubleProperty("rotationz"));
|
374 |
|
375 |
setAutoRotate(xml.getBooleanProperty("autoRotate"));
|
376 |
|
377 |
try {
|
378 |
setObject3DPath(new URL(object3DPath)); |
379 |
_osgViewer = new OSGViewer();
|
380 |
Node node = osgDB.readNodeFile(object3DPath); |
381 |
_osgViewer.setSceneData(node); |
382 |
} catch (MalformedURLException e) { |
383 |
Logger.getLogger(getClass()).error(
|
384 |
Messages.getString("invalid_url"));
|
385 |
} catch (IOException e) { |
386 |
Logger.getLogger(getClass()).error(
|
387 |
Messages.getString("invalid_url"));
|
388 |
|
389 |
} catch (LoadNodeException e) {
|
390 |
// TODO Auto-generated catch block
|
391 |
e.printStackTrace(); |
392 |
} |
393 |
|
394 |
} |
395 |
|
396 |
public void print(Graphics2D g, AffineTransform at, FShape shape) |
397 |
throws ReadDriverException {
|
398 |
// TODO Implement it
|
399 |
throw new Error("Not yet implemented!"); |
400 |
|
401 |
} |
402 |
|
403 |
/**
|
404 |
* Returns the path of the image that is used as a marker symbol
|
405 |
*
|
406 |
* @return imagePath,String
|
407 |
*/
|
408 |
public String getObject3DPath() { |
409 |
return object3DPath;
|
410 |
} |
411 |
|
412 |
public void setScale(Vec3 scale) { |
413 |
this.scale = scale;
|
414 |
|
415 |
} |
416 |
|
417 |
public void setRotation(Vec3 rotation) { |
418 |
this.rotation = rotation;
|
419 |
|
420 |
} |
421 |
|
422 |
public Vec3 getScale() {
|
423 |
return this.scale; |
424 |
} |
425 |
|
426 |
public Vec3 getRotationObject() {
|
427 |
return this.rotation; |
428 |
|
429 |
} |
430 |
|
431 |
public void setSnapshot(String tempScreenshotimage) { |
432 |
this.tempScreenshotimage = tempScreenshotimage;
|
433 |
|
434 |
} |
435 |
|
436 |
} |