Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / lib3DMap-share / src / main / java / com / iver / ai2 / gvsig3d / legend / Object3DMarkerSymbol.java @ 25190

History | View | Annotate | Download (10.2 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;
109

    
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
        private String tempScreenshotimage;
148

    
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
        @Override
228
        public void drawInsideRectangle(Graphics2D g,
229
                        AffineTransform scaleInstance, Rectangle r)
230
                        throws SymbolDrawingException {
231
                // TODO Auto-generated method stub
232
                // super.drawInsideRectangle(g, scaleInstance, r);
233

    
234
                ImageIcon image;
235
                // Setting the size symbol
236
                int size = 30;
237

    
238
                // Generating the image
239
//                image = new ImageIcon(
240
//                                "c:/Documents and Settings/Julio.IVER/Escritorio/img.png");
241
                image = new ImageIcon(tempScreenshotimage);
242
                int x = 0;
243
                int y = 0;
244
                if (g.getClipBounds() != null) {
245
                        x = (int) (g.getClipBounds().getCenterX() - (size / 2));
246
                        y = (int) (g.getClipBounds().getCenterY() - (size / 2));
247
                }
248
                g.drawImage(image.getImage(), x, y, size, size, null, null);
249

    
250
        }
251

    
252
        public XMLEntity getXMLEntity() {
253
                XMLEntity xml = new XMLEntity();
254
                xml.putProperty("className", getClassName());
255
                xml.putProperty("isShapeVisible", isShapeVisible());
256
                xml.putProperty("desc", getDescription());
257
                xml.putProperty("imagePath", object3DPath);
258
                xml.putProperty("tempScreenshotimage",tempScreenshotimage);
259

    
260
                xml.putProperty("scalex", scale.x());
261
                xml.putProperty("scaley", scale.y());
262
                xml.putProperty("scalez", scale.z());
263
                
264
                xml.putProperty("rotationx", rotation.x());
265
                xml.putProperty("rotationy", rotation.y());
266
                xml.putProperty("rotationz", rotation.z());
267
                
268
                xml.putProperty("autoRotate", isAutoRotate());
269
                
270

    
271
                return xml;
272
        }
273

    
274
        @Override
275
        public boolean isSuitableFor(IGeometry geom) {
276
                boolean suitable = false;
277
                com.iver.andami.ui.mdiManager.IWindow[] f = PluginServices
278
                                .getMDIManager().getAllWindows();
279
                if (f == null) {
280
                        return false;
281
                }
282
                for (int i = 0; i < f.length; i++) {
283
                        if (f[i] instanceof BaseView) {
284
                                BaseView view = (BaseView) f[i];
285
                                MapContext mapContext = view.getMapControl().getMapContext();
286
                                FLayers layer = mapContext.getLayers();
287
                                FLayer[] actives = layer.getActives();
288
                                if (actives.length == 1) {
289
                                        Layer3DProps props3D = Layer3DProps
290
                                                        .getLayer3DProps(actives[0]);
291
                                        if ((props3D != null)
292
                                                        && (props3D.getType() == Layer3DProps.layer3DVector)) {
293
                                                suitable = true;
294
                                        } else {
295
                                                suitable = false;
296
                                        }
297
                                }
298
                        }
299

    
300
                }
301
                System.out.println("is suitable " + suitable);
302
                return suitable;
303
        }
304

    
305
        public String getClassName() {
306
                return getClass().getName();
307
        }
308

    
309
        public void setXMLEntity(XMLEntity xml) {
310
                setDescription(xml.getStringProperty("desc"));
311
                setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
312
                object3DPath = xml.getStringProperty("imagePath");
313
                tempScreenshotimage = xml.getStringProperty("tempScreenshotimage");
314
//                setRotation(xml.getDoubleProperty("rotation"));
315
                
316
                this.scale = new Vec3();
317
                scale.setX(xml.getDoubleProperty("scalex"));
318
                scale.setY(xml.getDoubleProperty("scaley"));
319
                scale.setZ(xml.getDoubleProperty("scalez"));
320

    
321
                this.rotation = new Vec3();
322
                rotation.setX(xml.getDoubleProperty("rotationx"));
323
                rotation.setY(xml.getDoubleProperty("rotationy"));
324
                rotation.setZ(xml.getDoubleProperty("rotationz"));
325
                
326
                setAutoRotate(xml.getBooleanProperty("autoRotate"));
327
                
328

    
329
                try {
330
                        setObject3DPath(new URL(object3DPath));
331
                } catch (MalformedURLException e) {
332
                        Logger.getLogger(getClass()).error(
333
                                        Messages.getString("invalid_url"));
334
                } catch (IOException e) {
335
                        Logger.getLogger(getClass()).error(
336
                                        Messages.getString("invalid_url"));
337

    
338
                }
339

    
340
        }
341

    
342
        public void print(Graphics2D g, AffineTransform at, FShape shape)
343
                        throws ReadDriverException {
344
                // TODO Implement it
345
                throw new Error("Not yet implemented!");
346

    
347
        }
348

    
349
        /**
350
         * Returns the path of the image that is used as a marker symbol
351
         * 
352
         * @return imagePath,String
353
         */
354
        public String getObject3DPath() {
355
                return object3DPath;
356
        }
357

    
358
        public void setScale(Vec3 scale) {
359
                this.scale = scale;
360
                
361
        }
362

    
363
        public void setRotation(Vec3 rotation) {
364
                this.rotation = rotation;
365
                
366
        }
367

    
368
        public Vec3 getScale() {
369
                return this.scale;
370
        }
371

    
372
        public Vec3 getRotationObject() {
373
                return this.rotation;
374
        
375
        }
376

    
377
        public void setSnapshot(String tempScreenshotimage) {
378
                this.tempScreenshotimage = tempScreenshotimage;
379
                
380
        }
381

    
382
}