Revision 5878 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/FGeometry.java

View differences:

FGeometry.java
73 73
 * @author FJP
74 74
 */
75 75
public class FGeometry implements IGeometry3D {
76
	/**
77
	 *
78
	 */
79
	private static final long serialVersionUID = 5431865770186523337L;
80
	private FShape shp;
81
	private Rectangle2D bounds2D;
76
    /**
77
     *
78
     */
79
    private static final long serialVersionUID = 5431865770186523337L;
80
    private FShape shp;
81
    private Rectangle2D bounds2D;
82
    private int type=FShape.LINE;
82 83

  
83
	/**
84
	 * Crea un nuevo FGeometry.
85
	 *
86
	 * @param shp DOCUMENT ME!
87
	 */
88
	FGeometry(FShape shp) {
89
		this.shp = shp;
90
	}
84
    /**
85
     * Crea un nuevo FGeometry.
86
     *
87
     * @param shp DOCUMENT ME!
88
     */
89
    FGeometry(FShape shp) {
90
        this.shp = shp;
91
    }
91 92

  
92
	/* (non-Javadoc)
93
	 * @see com.iver.cit.gvsig.fmap.core.IGeometry#draw(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, org.geotools.renderer.style.Style2D)
94
	 */
95
	public void draw(Graphics2D g, ViewPort vp, FStyle2D symbol) {
96
		// OJO CON LA PRECISION. DEBERIAMOS USAR: ((GeneralPathX) shp.m_Polyline).transform(mT);
97
		// O HACER UNA FUNCION DE TRANSFORMACI?N QUE USE LOS DOUBLES DEL
98
		// SHAPE
99
		// Shape shpTrans = vp.getAffineTransform().createTransformedShape(shp);
100
		transform(vp.getAffineTransform());
93
    /* (non-Javadoc)
94
     * @see com.iver.cit.gvsig.fmap.core.IGeometry#draw(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, org.geotools.renderer.style.Style2D)
95
     */
96
    public void draw(Graphics2D g, ViewPort vp, FStyle2D symbol) {
97
        // OJO CON LA PRECISION. DEBERIAMOS USAR: ((GeneralPathX) shp.m_Polyline).transform(mT);
98
        // O HACER UNA FUNCION DE TRANSFORMACI?N QUE USE LOS DOUBLES DEL
99
        // SHAPE
100
        // Shape shpTrans = vp.getAffineTransform().createTransformedShape(shp);
101
        transform(vp.getAffineTransform());
101 102

  
102
		switch (shp.getShapeType()) {
103
			case FShape.POINT:
104
				shpPainter.paint(g, shp, symbol.getPointStyle2D(), 0);
103
        switch (shp.getShapeType()) {
104
            case FShape.POINT:
105
                shpPainter.paint(g, shp, symbol.getPointStyle2D(), 0);
105 106

  
106
				break;
107
                break;
107 108

  
108
			case FShape.LINE:
109
				shpPainter.paint(g, shp, symbol.getLineStyle2D(), 0);
109
            case FShape.LINE:
110
                shpPainter.paint(g, shp, symbol.getLineStyle2D(), 0);
110 111

  
111
				break;
112
                break;
112 113

  
113
			case FShape.POLYGON:
114
				shpPainter.paint(g, shp, symbol.getPolygonStyle2D(), 0);
114
            case FShape.POLYGON:
115
                shpPainter.paint(g, shp, symbol.getPolygonStyle2D(), 0);
115 116

  
116
				break;
117
                break;
117 118

  
118
			case FShape.TEXT:
119
				shpPainter.paint(g, shp, symbol.getTextStyle2D(), 0);
120
		}
121
	}
119
            case FShape.TEXT:
120
                shpPainter.paint(g, shp, symbol.getTextStyle2D(), 0);
121
        }
122
    }
122 123

  
123
	/**
124
	 * Dibuja la geometria actual en el graphics que se le pasa como par?metro,
125
	 * aplicandole las caracter?sticas del s?mbolo.
126
	 *
127
	 * @param g Graphics2D.
128
	 * @param vp ViewPort.
129
	 * @param symbol S?mbolo.
130
	 */
131
	public void draw(Graphics2D g, ViewPort vp, FSymbol symbol) {
132
		// OJO CON LA PRECISION. DEBERIAMOS USAR: ((GeneralPathX) shp.m_Polyline).transform(mT);
133
		// O HACER UNA FUNCION DE TRANSFORMACI?N QUE USE LOS DOUBLES DEL
134
		// SHAPE
135
		// Shape shpTrans = vp.getAffineTransform().createTransformedShape(shp);
136
		transform(vp.getAffineTransform());
137
		FGraphicUtilities.DrawShape(g, vp.getAffineTransform(), shp, symbol);
138
	}
124
    /**
125
     * Dibuja la geometria actual en el graphics que se le pasa como par?metro,
126
     * aplicandole las caracter?sticas del s?mbolo.
127
     *
128
     * @param g Graphics2D.
129
     * @param vp ViewPort.
130
     * @param symbol S?mbolo.
131
     */
132
    public void draw(Graphics2D g, ViewPort vp, FSymbol symbol) {
133
        // OJO CON LA PRECISION. DEBERIAMOS USAR: ((GeneralPathX) shp.m_Polyline).transform(mT);
134
        // O HACER UNA FUNCION DE TRANSFORMACI?N QUE USE LOS DOUBLES DEL
135
        // SHAPE
136
        // Shape shpTrans = vp.getAffineTransform().createTransformedShape(shp);
137
        transform(vp.getAffineTransform());
138
        FGraphicUtilities.DrawShape(g, vp.getAffineTransform(), shp, symbol);
139
    }
139 140

  
140 141
    /* (non-Javadoc)
141 142
     * @see com.iver.cit.gvsig.fmap.core.IGeometry#drawInts(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.cit.gvsig.fmap.core.v02.FSymbol)
......
145 146
        FGraphicUtilities.DrawShape(g, vp.getAffineTransform(), decimatedShape, symbol);
146 147
    }
147 148

  
148
	/**
149
	 * Aplica la transformaci?n a la geometr?a de la matriz de transformaci?n
150
	 * que se pasa como par?metro.
151
	 *
152
	 * @param at Matriz de transformaci?n.
153
	 */
154
	public void transform(AffineTransform at) {
155
		shp.transform(at);
156
	}
149
    /**
150
     * Aplica la transformaci?n a la geometr?a de la matriz de transformaci?n
151
     * que se pasa como par?metro.
152
     *
153
     * @param at Matriz de transformaci?n.
154
     */
155
    public void transform(AffineTransform at) {
156
        shp.transform(at);
157
    }
157 158

  
158
	/* (non-Javadoc)
159
	 * @see com.iver.cit.gvsig.fmap.core.IGeometry#intersects(java.awt.geom.Rectangle2D)
160
	 */
161
	public boolean intersects(Rectangle2D r) {
162
		return shp.intersects(r);
163
	}
159
    /* (non-Javadoc)
160
     * @see com.iver.cit.gvsig.fmap.core.IGeometry#intersects(java.awt.geom.Rectangle2D)
161
     */
162
    public boolean intersects(Rectangle2D r) {
163
    	if (getGeometryType()==FShape.LINE && shp.getShapeType()==FShape.POLYGON) {
164
        	return shp.intersects(r) && !shp.contains(r);
165
        }
166
        return shp.intersects(r);
167
    }
164 168

  
165
	/* (non-Javadoc)
166
	 * @see com.iver.cit.gvsig.fmap.core.IGeometry#getBounds2D()
167
	 */
168
	public Rectangle2D getBounds2D() {
169
		if (bounds2D == null)
170
		{
171
			bounds2D = shp.getBounds2D();
172
		}
173
		// return shp.getBounds2D();
174
		return bounds2D;
175
	}
176
	
177
	public Rectangle2D reCalculateBounds2D()
178
	{
179
		return shp.getBounds2D();
180
	}
169
    /* (non-Javadoc)
170
     * @see com.iver.cit.gvsig.fmap.core.IGeometry#getBounds2D()
171
     */
172
    public Rectangle2D getBounds2D() {
173
        if (bounds2D == null)
174
        {
175
            bounds2D = shp.getBounds2D();
176
        }
177
        // return shp.getBounds2D();
178
        return bounds2D;
179
    }
181 180

  
182
	/* (non-Javadoc)
183
	 * @see com.iver.cit.gvsig.fmap.core.IGeometry#toJTSGeometry()
184
	 */
185
	public Geometry toJTSGeometry() {
186
		return FConverter.java2d_to_jts(shp);
187
	}
181
    public Rectangle2D reCalculateBounds2D()
182
    {
183
        return shp.getBounds2D();
184
    }
188 185

  
189
	/* (non-Javadoc)
190
	 * @see com.iver.cit.gvsig.fmap.core.IGeometry#createLabels(int, boolean)
191
	 */
192
	public FLabel[] createLabels(int position, boolean duplicates) {
193
		FLabel[] aux = new FLabel[1];
194
		aux[0] = FLabel.createFLabel(shp);
186
    /* (non-Javadoc)
187
     * @see com.iver.cit.gvsig.fmap.core.IGeometry#toJTSGeometry()
188
     */
189
    public Geometry toJTSGeometry() {
190
        return FConverter.java2d_to_jts(shp);
191
    }
195 192

  
196
		return aux;
197
	}
193
    /* (non-Javadoc)
194
     * @see com.iver.cit.gvsig.fmap.core.IGeometry#createLabels(int, boolean)
195
     */
196
    public FLabel[] createLabels(int position, boolean duplicates) {
197
        FLabel[] aux = new FLabel[1];
198
        aux[0] = FLabel.createFLabel(shp);
198 199

  
199
	/**
200
	 * @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeometryType()
201
	 */
202
	public int getGeometryType() {
203
		return shp.getShapeType();
204
	}
200
        return aux;
201
    }
205 202

  
206
	/* (non-Javadoc)
207
	 * @see com.iver.cit.gvsig.fmap.core.IGeometry#cloneGeometry()
208
	 */
209
	public IGeometry cloneGeometry() {
210
		return new FGeometry(shp.cloneFShape());
211
	}
203
    /**
204
     * @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeometryType()
205
     */
206
    public int getGeometryType() {
207
        return type;
208
    }
212 209

  
213
	/* (non-Javadoc)
214
	 * @see com.iver.cit.gvsig.fmap.core.IGeometry#reProject(org.cresques.cts.ICoordTrans)
215
	 */
216
	public void reProject(ICoordTrans ct) {
217
		shp.reProject(ct);
218
	}
210
    /* (non-Javadoc)
211
     * @see com.iver.cit.gvsig.fmap.core.IGeometry#cloneGeometry()
212
     */
213
    public IGeometry cloneGeometry() {
214
        IGeometry geom=new FGeometry(shp.cloneFShape());
215
        geom.setGeometryType(type);
216
        return geom;
217
    }
219 218

  
220
	/**
221
	 * @see com.iver.cit.gvsig.fmap.core.IGeometry#getPathIterator(AffineTransform)
222
	 */
223
	public PathIterator getPathIterator(AffineTransform at) {
224
		return (GeneralPathXIterator)shp.getPathIterator(null);
225
	}
219
    /* (non-Javadoc)
220
     * @see com.iver.cit.gvsig.fmap.core.IGeometry#reProject(org.cresques.cts.ICoordTrans)
221
     */
222
    public void reProject(ICoordTrans ct) {
223
        shp.reProject(ct);
224
    }
226 225

  
226
    /**
227
     * @see com.iver.cit.gvsig.fmap.core.IGeometry#getPathIterator(AffineTransform)
228
     */
229
    public PathIterator getPathIterator(AffineTransform at) {
230
        return (GeneralPathXIterator)shp.getPathIterator(null);
231
    }
227 232

  
228
	
233

  
234

  
229 235
    /* (non-Javadoc)
230 236
     * @see com.iver.cit.gvsig.fmap.core.IGeometry#fastIntersects(double, double, double, double)
231 237
     */
......
237 243
        return WKBEncoder.encodeGeometry(toJTSGeometry());
238 244
    }
239 245
    /**
240
	 * Devuelve un array con todos los valores de Z.
241
	 *
242
	 * @return Array de Zs.
243
	 */
244
	public double[] getZs() {
245
		return ((FShape3D) shp).getZs();
246
	}
247
	/**
248
	 * @see com.iver.cit.gvsig.fmap.core.IGeometry#getHandlers()
249
	 */
250
	public Handler[] getHandlers(int type) {
251
		if (type==STRETCHINGHANDLER){
252
		return shp.getStretchingHandlers();
253
		}else if (type==SELECTHANDLER){
254
			return shp.getSelectHandlers();
255
		}
256
		return null;
257
	}
246
     * Devuelve un array con todos los valores de Z.
247
     *
248
     * @return Array de Zs.
249
     */
250
    public double[] getZs() {
251
        return ((FShape3D) shp).getZs();
252
    }
253
    /**
254
     * @see com.iver.cit.gvsig.fmap.core.IGeometry#getHandlers()
255
     */
256
    public Handler[] getHandlers(int type) {
257
        if (type==STRETCHINGHANDLER){
258
        return shp.getStretchingHandlers();
259
        }else if (type==SELECTHANDLER){
260
            return shp.getSelectHandlers();
261
        }
262
        return null;
263
    }
258 264

  
259
	/* (non-Javadoc)
260
	 * @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeneralPathXIterator(java.awt.geom.AffineTransform, double)
261
	 */
262
	public PathIterator getPathIterator(AffineTransform at, double flatness) {
263
		return shp.getPathIterator(at, flatness);
264
	}
265
    /* (non-Javadoc)
266
     * @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeneralPathXIterator(java.awt.geom.AffineTransform, double)
267
     */
268
    public PathIterator getPathIterator(AffineTransform at, double flatness) {
269
        return shp.getPathIterator(at, flatness);
270
    }
265 271

  
266
	public boolean contains(double x, double y) {
267
		return shp.contains(x,y);
268
	}
272
    public boolean contains(double x, double y) {
273
        return shp.contains(x,y);
274
    }
269 275

  
270
	public boolean contains(double x, double y, double w, double h) {
271
		return shp.contains(x,y,w,h);
272
	}
276
    public boolean contains(double x, double y, double w, double h) {
277
        return shp.contains(x,y,w,h);
278
    }
273 279

  
274
	public boolean intersects(double x, double y, double w, double h) {
275
		return shp.intersects(x,y,w,h);
276
	}
280
    public boolean intersects(double x, double y, double w, double h) {
281
    	if (getGeometryType()==FShape.LINE && shp.getShapeType()==FShape.POLYGON) {
282
        	return shp.intersects(x,y,w,h) && !shp.contains(x,y,w,h);
283
        }
284
        return shp.intersects(x,y,w,h);
285
    }
277 286

  
278
	public Rectangle getBounds() {
279
		return shp.getBounds();
280
	}
287
    public Rectangle getBounds() {
288
        return shp.getBounds();
289
    }
281 290

  
282
	public boolean contains(Point2D p) {
283
		return shp.contains(p);
284
	}
291
    public boolean contains(Point2D p) {
292
        return shp.contains(p);
293
    }
285 294

  
286
	public boolean contains(Rectangle2D r) {
287
		return shp.contains(r);
288
	}
295
    public boolean contains(Rectangle2D r) {
296
        return shp.contains(r);
297
    }
289 298

  
290
	public Shape getInternalShape() {
291
		return shp;
292
	}
299
    public Shape getInternalShape() {
300
        return shp;
301
    }
293 302

  
294
	/* public void move(double x, double y) {
295
		AffineTransform at = new AffineTransform();
296
		at.translate(x, y);
297
		transform(at);
298
	}
299
	public void rotate(double r, double x, double y) {
300
		AffineTransform at = new AffineTransform();
301
		at.rotate(r, x, y);
302
		transform(at);
303
	}
304
	public void scale(Point2D point,double x, double y) {
305
		AffineTransform at = new AffineTransform();
306
		at.setToTranslation(point.getX(),point.getY());
307
		at.scale(x,y);
308
		at.translate(-point.getX(),-point.getY());
309
		transform(at);
310
	} */
303
    public int getOriginalGeometryType() {
304
        return shp.getShapeType();
305
    }
306

  
307
    public void setGeometryType(int type) {
308
        this.type=type;
309

  
310
    }
311

  
312
    /* public void move(double x, double y) {
313
        AffineTransform at = new AffineTransform();
314
        at.translate(x, y);
315
        transform(at);
316
    }
317
    public void rotate(double r, double x, double y) {
318
        AffineTransform at = new AffineTransform();
319
        at.rotate(r, x, y);
320
        transform(at);
321
    }
322
    public void scale(Point2D point,double x, double y) {
323
        AffineTransform at = new AffineTransform();
324
        at.setToTranslation(point.getX(),point.getY());
325
        at.scale(x,y);
326
        at.translate(-point.getX(),-point.getY());
327
        transform(at);
328
    } */
311 329
}

Also available in: Unified diff