svn-gvsig-desktop / trunk / libraries / lib3DMap-share / src / main / java / com / iver / ai2 / gvsig3d / legend / symbols / Object3DMarkerSymbol.java @ 28936
History | View | Annotate | Download (10.2 KB)
1 | 23168 | jcampos | /* 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 | 25860 | jcampos | package com.iver.ai2.gvsig3d.legend.symbols; |
109 | 23168 | jcampos | |
110 | import java.awt.Graphics2D; |
||
111 | import java.awt.Rectangle; |
||
112 | import java.awt.geom.AffineTransform; |
||
113 | import java.io.IOException; |
||
114 | import java.net.MalformedURLException; |
||
115 | import java.net.URL; |
||
116 | |||
117 | import javax.swing.ImageIcon; |
||
118 | |||
119 | import org.apache.log4j.Logger; |
||
120 | import org.gvsig.osgvp.Vec3; |
||
121 | |||
122 | import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
||
123 | import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps; |
||
124 | import com.iver.andami.PluginServices; |
||
125 | import com.iver.andami.ui.mdiManager.IWindow; |
||
126 | import com.iver.cit.gvsig.fmap.MapContext; |
||
127 | import com.iver.cit.gvsig.fmap.Messages; |
||
128 | import com.iver.cit.gvsig.fmap.core.FShape; |
||
129 | import com.iver.cit.gvsig.fmap.core.IGeometry; |
||
130 | import com.iver.cit.gvsig.fmap.core.symbols.AbstractMarkerSymbol; |
||
131 | import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
||
132 | import com.iver.cit.gvsig.fmap.core.symbols.SymbolDrawingException; |
||
133 | import com.iver.cit.gvsig.fmap.layers.FLayer; |
||
134 | import com.iver.cit.gvsig.fmap.layers.FLayers; |
||
135 | import com.iver.cit.gvsig.project.documents.view.gui.BaseView; |
||
136 | import com.iver.utiles.XMLEntity; |
||
137 | import com.iver.utiles.swing.threads.Cancellable; |
||
138 | |||
139 | public class Object3DMarkerSymbol extends AbstractMarkerSymbol { |
||
140 | private static final float SELECTION_OPACITY_FACTOR = .3F; |
||
141 | // transient private Image img;
|
||
142 | private String object3DPath; |
||
143 | private boolean selected; |
||
144 | private Vec3 scale;
|
||
145 | private Vec3 rotation;
|
||
146 | private boolean autoRotate = false; |
||
147 | 23302 | jcampos | private String tempScreenshotimage; |
148 | 23168 | jcampos | |
149 | // transient private Image selImg;
|
||
150 | |||
151 | public boolean isAutoRotate() { |
||
152 | return autoRotate;
|
||
153 | } |
||
154 | |||
155 | public void setAutoRotate(boolean autoRotate) { |
||
156 | this.autoRotate = autoRotate;
|
||
157 | } |
||
158 | |||
159 | /**
|
||
160 | * Constructor method
|
||
161 | */
|
||
162 | public Object3DMarkerSymbol() {
|
||
163 | super();
|
||
164 | } |
||
165 | |||
166 | /**
|
||
167 | * Constructor method
|
||
168 | *
|
||
169 | * @param imageURL
|
||
170 | * , URL of the normal image
|
||
171 | * @param selImageURL
|
||
172 | * , URL of the image when it is selected in the map
|
||
173 | * @throws IOException
|
||
174 | */
|
||
175 | public Object3DMarkerSymbol(URL object3DURL) throws IOException { |
||
176 | setObject3DPath(object3DURL); |
||
177 | } |
||
178 | |||
179 | public Object3DMarkerSymbol(String object3DPath) throws IOException { |
||
180 | this.object3DPath = object3DPath;
|
||
181 | } |
||
182 | |||
183 | /**
|
||
184 | * Sets the file for the image to be used as a marker symbol
|
||
185 | *
|
||
186 | * @param imageFile
|
||
187 | * , File
|
||
188 | * @throws IOException
|
||
189 | */
|
||
190 | public void setObject3DPath(URL Object3DUrl) throws IOException { |
||
191 | object3DPath = Object3DUrl.toString(); |
||
192 | } |
||
193 | |||
194 | public ISymbol getSymbolForSelection() {
|
||
195 | return null; |
||
196 | } |
||
197 | |||
198 | public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp, |
||
199 | 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 | |||
225 | } |
||
226 | |||
227 | 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);
|
||
232 | |||
233 | ImageIcon image;
|
||
234 | // Setting the size symbol
|
||
235 | int size = 30; |
||
236 | |||
237 | // Generating the image
|
||
238 | 23302 | jcampos | // image = new ImageIcon(
|
239 | // "c:/Documents and Settings/Julio.IVER/Escritorio/img.png");
|
||
240 | image = new ImageIcon(tempScreenshotimage); |
||
241 | 23168 | jcampos | int x = 0; |
242 | int y = 0; |
||
243 | if (g.getClipBounds() != null) { |
||
244 | x = (int) (g.getClipBounds().getCenterX() - (size / 2)); |
||
245 | y = (int) (g.getClipBounds().getCenterY() - (size / 2)); |
||
246 | } |
||
247 | g.drawImage(image.getImage(), x, y, size, size, null, null); |
||
248 | |||
249 | } |
||
250 | |||
251 | public XMLEntity getXMLEntity() {
|
||
252 | XMLEntity xml = new XMLEntity();
|
||
253 | xml.putProperty("className", getClassName());
|
||
254 | xml.putProperty("isShapeVisible", isShapeVisible());
|
||
255 | xml.putProperty("desc", getDescription());
|
||
256 | xml.putProperty("imagePath", object3DPath);
|
||
257 | 23302 | jcampos | xml.putProperty("tempScreenshotimage",tempScreenshotimage);
|
258 | 23168 | jcampos | |
259 | xml.putProperty("scalex", scale.x());
|
||
260 | xml.putProperty("scaley", scale.y());
|
||
261 | xml.putProperty("scalez", scale.z());
|
||
262 | |||
263 | xml.putProperty("rotationx", rotation.x());
|
||
264 | xml.putProperty("rotationy", rotation.y());
|
||
265 | xml.putProperty("rotationz", rotation.z());
|
||
266 | |||
267 | xml.putProperty("autoRotate", isAutoRotate());
|
||
268 | |||
269 | |||
270 | return xml;
|
||
271 | } |
||
272 | |||
273 | @Override
|
||
274 | public boolean isSuitableFor(IGeometry geom) { |
||
275 | boolean suitable = false; |
||
276 | com.iver.andami.ui.mdiManager.IWindow[] f = PluginServices
|
||
277 | .getMDIManager().getAllWindows(); |
||
278 | if (f == null) { |
||
279 | return false; |
||
280 | } |
||
281 | for (int i = 0; i < f.length; i++) { |
||
282 | if (f[i] instanceof BaseView) { |
||
283 | BaseView view = (BaseView) f[i]; |
||
284 | MapContext mapContext = view.getMapControl().getMapContext(); |
||
285 | FLayers layer = mapContext.getLayers(); |
||
286 | FLayer[] actives = layer.getActives();
|
||
287 | if (actives.length == 1) { |
||
288 | Layer3DProps props3D = Layer3DProps |
||
289 | .getLayer3DProps(actives[0]);
|
||
290 | if ((props3D != null) |
||
291 | && (props3D.getType() == Layer3DProps.layer3DVector)) { |
||
292 | suitable = true;
|
||
293 | } else {
|
||
294 | suitable = false;
|
||
295 | } |
||
296 | } |
||
297 | } |
||
298 | |||
299 | } |
||
300 | System.out.println("is suitable " + suitable); |
||
301 | return suitable;
|
||
302 | } |
||
303 | |||
304 | public String getClassName() { |
||
305 | return getClass().getName();
|
||
306 | } |
||
307 | |||
308 | public void setXMLEntity(XMLEntity xml) { |
||
309 | setDescription(xml.getStringProperty("desc"));
|
||
310 | setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
|
||
311 | object3DPath = xml.getStringProperty("imagePath");
|
||
312 | 23302 | jcampos | tempScreenshotimage = xml.getStringProperty("tempScreenshotimage");
|
313 | 23168 | jcampos | // setRotation(xml.getDoubleProperty("rotation"));
|
314 | |||
315 | this.scale = new Vec3(); |
||
316 | scale.setX(xml.getDoubleProperty("scalex"));
|
||
317 | scale.setY(xml.getDoubleProperty("scaley"));
|
||
318 | scale.setZ(xml.getDoubleProperty("scalez"));
|
||
319 | |||
320 | this.rotation = new Vec3(); |
||
321 | rotation.setX(xml.getDoubleProperty("rotationx"));
|
||
322 | rotation.setY(xml.getDoubleProperty("rotationy"));
|
||
323 | rotation.setZ(xml.getDoubleProperty("rotationz"));
|
||
324 | |||
325 | setAutoRotate(xml.getBooleanProperty("autoRotate"));
|
||
326 | |||
327 | |||
328 | try {
|
||
329 | setObject3DPath(new URL(object3DPath)); |
||
330 | } catch (MalformedURLException e) { |
||
331 | Logger.getLogger(getClass()).error(
|
||
332 | Messages.getString("invalid_url"));
|
||
333 | } catch (IOException e) { |
||
334 | Logger.getLogger(getClass()).error(
|
||
335 | Messages.getString("invalid_url"));
|
||
336 | |||
337 | } |
||
338 | |||
339 | } |
||
340 | |||
341 | public void print(Graphics2D g, AffineTransform at, FShape shape) |
||
342 | throws ReadDriverException {
|
||
343 | // TODO Implement it
|
||
344 | throw new Error("Not yet implemented!"); |
||
345 | |||
346 | } |
||
347 | |||
348 | /**
|
||
349 | * Returns the path of the image that is used as a marker symbol
|
||
350 | *
|
||
351 | * @return imagePath,String
|
||
352 | */
|
||
353 | public String getObject3DPath() { |
||
354 | return object3DPath;
|
||
355 | } |
||
356 | |||
357 | public void setScale(Vec3 scale) { |
||
358 | this.scale = scale;
|
||
359 | |||
360 | } |
||
361 | |||
362 | public void setRotation(Vec3 rotation) { |
||
363 | this.rotation = rotation;
|
||
364 | |||
365 | } |
||
366 | |||
367 | public Vec3 getScale() {
|
||
368 | return this.scale; |
||
369 | } |
||
370 | |||
371 | public Vec3 getRotationObject() {
|
||
372 | return this.rotation; |
||
373 | |||
374 | } |
||
375 | |||
376 | 23302 | jcampos | public void setSnapshot(String tempScreenshotimage) { |
377 | this.tempScreenshotimage = tempScreenshotimage;
|
||
378 | |||
379 | } |
||
380 | |||
381 | 23168 | jcampos | } |