svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.symbology / org.gvsig.symbology.lib / org.gvsig.symbology.lib.impl / src / main / java / org / gvsig / symbology / fmap / mapcontext / rendering / symbol / line / impl / PictureLineSymbol.java @ 47790
History | View | Annotate | Download (22.5 KB)
1 | 40560 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40560 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | 40560 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * of the License, or (at your option) any later version.
|
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | 40560 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | * MA 02110-1301, USA.
|
||
20 | 40435 | jjdelcerro | *
|
21 | 40560 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | package org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.impl; |
||
25 | |||
26 | import java.awt.BasicStroke; |
||
27 | 46451 | fdiaz | import java.awt.Color; |
28 | 47476 | fdiaz | import java.awt.Dimension; |
29 | 40435 | jjdelcerro | import java.awt.Graphics2D; |
30 | 47476 | fdiaz | import java.awt.Point; |
31 | 40435 | jjdelcerro | import java.awt.Rectangle; |
32 | import java.awt.Shape; |
||
33 | import java.awt.geom.AffineTransform; |
||
34 | import java.awt.geom.PathIterator; |
||
35 | import java.awt.geom.Point2D; |
||
36 | import java.io.IOException; |
||
37 | import java.net.URL; |
||
38 | 43156 | jjdelcerro | import org.apache.batik.ext.awt.geom.DefaultPathLength; |
39 | 47476 | fdiaz | import org.apache.commons.lang3.StringUtils; |
40 | 40435 | jjdelcerro | import org.gvsig.compat.print.PrintAttributes; |
41 | 47476 | fdiaz | import org.gvsig.expressionevaluator.ExpressionUtils; |
42 | import org.gvsig.expressionevaluator.SymbolTable; |
||
43 | import org.gvsig.fmap.dal.DALLocator; |
||
44 | import org.gvsig.fmap.dal.exception.DataException; |
||
45 | import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
||
46 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.feature.Feature; |
47 | 47476 | fdiaz | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
48 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
49 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
50 | 40435 | jjdelcerro | import org.gvsig.fmap.geom.Geometry; |
51 | import org.gvsig.fmap.mapcontext.MapContextLocator; |
||
52 | 47476 | fdiaz | import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport; |
53 | 40435 | jjdelcerro | import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
54 | import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException; |
||
55 | import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager; |
||
56 | import org.gvsig.i18n.Messages; |
||
57 | 43156 | jjdelcerro | import org.gvsig.symbology.PathLength; |
58 | 40435 | jjdelcerro | import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.IPictureLineSymbol; |
59 | import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.BackgroundFileStyle; |
||
60 | 46451 | fdiaz | import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IMask; |
61 | 40435 | jjdelcerro | import org.gvsig.tools.ToolsLocator; |
62 | import org.gvsig.tools.dynobject.DynStruct; |
||
63 | import org.gvsig.tools.persistence.PersistenceManager; |
||
64 | import org.gvsig.tools.persistence.PersistentState; |
||
65 | import org.gvsig.tools.persistence.exception.PersistenceException; |
||
66 | import org.gvsig.tools.task.Cancellable; |
||
67 | import org.gvsig.tools.util.Callable; |
||
68 | import org.slf4j.Logger; |
||
69 | import org.slf4j.LoggerFactory; |
||
70 | |||
71 | |||
72 | /**
|
||
73 | * PictureLineSymbol allows to use any symbol defined as an image (by an image file)
|
||
74 | * supported by gvSIG.This symbol will be used as an initial object.The line will be
|
||
75 | * painted as a succession of puntual symbols through the path defined by it(the line).
|
||
76 | */
|
||
77 | public class PictureLineSymbol extends AbstractLineSymbol implements IPictureLineSymbol { |
||
78 | |||
79 | private static final Logger logger = LoggerFactory.getLogger(PictureLineSymbol.class); |
||
80 | |||
81 | public static final String PICTURE_LINE_SYMBOL_PERSISTENCE_DEFINITION_NAME = |
||
82 | "PictureLineSymbol";
|
||
83 | private static final String SELECTED = "selected"; |
||
84 | private static final String SELECTION_SYMBOL = "selectionSym"; |
||
85 | private static final String BACKGROUND_IMAGE = "bgImage"; |
||
86 | private static final String BACKGROUND_SELECTION_IMAGE = "bgSelImage"; |
||
87 | private static final String WIDTH = "width"; |
||
88 | 47476 | fdiaz | private static final String FIELD_SIZE_EXPRESSION = "sizeExpression"; |
89 | 40435 | jjdelcerro | |
90 | 47476 | fdiaz | |
91 | 40435 | jjdelcerro | transient private PictureLineSymbol selectionSym; |
92 | private double width; |
||
93 | private boolean selected; |
||
94 | |||
95 | private BackgroundFileStyle bgImage;
|
||
96 | private BackgroundFileStyle bgSelImage;
|
||
97 | private PrintAttributes properties;
|
||
98 | 47476 | fdiaz | |
99 | private double rotation; |
||
100 | private Point2D offset = new Point2D.Double(); |
||
101 | private IMask mask;
|
||
102 | 40435 | jjdelcerro | |
103 | 47476 | fdiaz | private Color lineToOffsetColor; |
104 | private boolean drawLineToOffset; |
||
105 | |||
106 | private String sizeExpression; |
||
107 | private String offsetXExpression; |
||
108 | private String offsetYExpression; |
||
109 | private String rotationExpression; |
||
110 | private String lineToOffsetColorExpression; |
||
111 | |||
112 | |||
113 | 40435 | jjdelcerro | /**
|
114 | * Constructor method
|
||
115 | *
|
||
116 | */
|
||
117 | public PictureLineSymbol() {
|
||
118 | super();
|
||
119 | } |
||
120 | /**
|
||
121 | * Constructor method
|
||
122 | * @param imageURL, URL of the normal image
|
||
123 | * @param selImageURL, URL of the image when it is selected in the map
|
||
124 | * @throws IOException
|
||
125 | */
|
||
126 | 47476 | fdiaz | public PictureLineSymbol(URL imageURL, URL selImageURL) throws IOException { |
127 | setImage(imageURL); |
||
128 | if (selImageURL != null) { |
||
129 | setSelImage(selImageURL); |
||
130 | } else {
|
||
131 | setSelImage(imageURL); |
||
132 | } |
||
133 | } |
||
134 | |||
135 | 40435 | jjdelcerro | /**
|
136 | * Sets the URL for the image to be used as a picture line symbol
|
||
137 | * @param imageFile, File
|
||
138 | * @throws IOException
|
||
139 | */
|
||
140 | 47476 | fdiaz | @Override
|
141 | 40435 | jjdelcerro | public void setImage(URL imageUrl) throws IOException{ |
142 | |||
143 | bgImage= BackgroundFileStyle.createStyleByURL(imageUrl); |
||
144 | } |
||
145 | /**
|
||
146 | * Sets the URL for the image to be used as a picture line symbol (when it is selected in the map)
|
||
147 | * @param imageFile, File
|
||
148 | * @throws IOException
|
||
149 | */
|
||
150 | 47476 | fdiaz | @Override
|
151 | 40435 | jjdelcerro | public void setSelImage(URL selImageUrl) throws IOException{ |
152 | 47476 | fdiaz | bgSelImage= BackgroundFileStyle.createStyleByURL(selImageUrl); |
153 | 40435 | jjdelcerro | } |
154 | |||
155 | |||
156 | 47476 | fdiaz | @Override
|
157 | 40435 | jjdelcerro | public void setLineWidth(double width) { |
158 | this.width = width;
|
||
159 | getLineStyle().setLineWidth((float) width);
|
||
160 | } |
||
161 | |||
162 | 47476 | fdiaz | @Override
|
163 | 40435 | jjdelcerro | public double getLineWidth() { |
164 | return width;
|
||
165 | } |
||
166 | |||
167 | 47476 | fdiaz | @Override
|
168 | 47790 | fdiaz | public ISymbol getSymbolForSelection(Color selectionColor) { |
169 | 40435 | jjdelcerro | if (selectionSym == null) { |
170 | 47790 | fdiaz | selectionSym = (PictureLineSymbol) cloneForSelection(selectionColor); |
171 | 40435 | jjdelcerro | selectionSym.selected=true;
|
172 | selectionSym.selectionSym = selectionSym; // avoid too much lazy creations
|
||
173 | 42439 | dmartinezizquierdo | }else{
|
174 | 47790 | fdiaz | selectionSym.setColor(selectionColor); |
175 | 40435 | jjdelcerro | } |
176 | 47476 | fdiaz | if (selectionSym instanceof CartographicSupport) { |
177 | ((CartographicSupport) selectionSym).setUnit(this.getUnit());
|
||
178 | } |
||
179 | 40435 | jjdelcerro | return selectionSym;
|
180 | |||
181 | } |
||
182 | |||
183 | 47476 | fdiaz | @Override
|
184 | public void draw(Graphics2D g, AffineTransform affineTransform, Geometry geom, Feature f, Cancellable cancel, Rectangle r) { |
||
185 | 40435 | jjdelcerro | |
186 | 47476 | fdiaz | if(r != null){ |
187 | geom = getSampleGeometry(r); |
||
188 | } |
||
189 | 40435 | jjdelcerro | |
190 | 47476 | fdiaz | double effectiveSize = getEfectiveSize(f);
|
191 | double scale = getScale(effectiveSize);
|
||
192 | if (scale <= 0 ) { |
||
193 | return;
|
||
194 | } |
||
195 | |||
196 | Shape geom_transf_clip = geom.getShape(affineTransform);
|
||
197 | 40435 | jjdelcerro | |
198 | 47476 | fdiaz | BackgroundFileStyle bg = (!selected) ? bgImage : bgSelImage; |
199 | 42439 | dmartinezizquierdo | |
200 | 47476 | fdiaz | Rectangle bounds = bg.getBounds();
|
201 | final double imageHeight = effectiveSize; //getCartographicSize(); //toCartographicUnits(getSize()); |
||
202 | final double imageWidth = bounds.getWidth() * scale; |
||
203 | 42439 | dmartinezizquierdo | |
204 | 47476 | fdiaz | if (imageWidth <= 0 || imageHeight <= 0) { |
205 | return;
|
||
206 | } |
||
207 | int height = (int) imageHeight; //csWidth; |
||
208 | float csWidth = height; //(float) toCartographicUnits(getLineStyle().getLineWidth()); |
||
209 | 42439 | dmartinezizquierdo | |
210 | 47476 | fdiaz | BasicStroke bs = new BasicStroke( |
211 | (float) csWidth,
|
||
212 | BasicStroke.CAP_ROUND,
|
||
213 | BasicStroke.CAP_ROUND);
|
||
214 | 40435 | jjdelcerro | |
215 | 47476 | fdiaz | g.setClip(bs.createStrokedShape(geom_transf_clip)); |
216 | 40435 | jjdelcerro | |
217 | 47476 | fdiaz | PathLength pl = new DefaultPathLength(geom_transf_clip);
|
218 | PathIterator iterator = geom_transf_clip.getPathIterator(null, 0.8); |
||
219 | double[] theData = new double[6]; |
||
220 | Point2D firstPoint = null, startPoint = null, endPoint = null; |
||
221 | if (!iterator.isDone()) {
|
||
222 | if (iterator.currentSegment(theData) != PathIterator.SEG_CLOSE) { |
||
223 | firstPoint = new Point2D.Double(theData[0], theData[1]); |
||
224 | } |
||
225 | } |
||
226 | float currentPathLength = 1; |
||
227 | 40435 | jjdelcerro | |
228 | 47476 | fdiaz | Rectangle rect = new Rectangle(); |
229 | 40435 | jjdelcerro | |
230 | 47476 | fdiaz | while ((cancel == null || !cancel.isCanceled()) && !iterator.isDone()) { |
231 | 40435 | jjdelcerro | |
232 | 47476 | fdiaz | int theType = iterator.currentSegment(theData);
|
233 | switch (theType) {
|
||
234 | case PathIterator.SEG_MOVETO: |
||
235 | startPoint = new Point2D.Double(theData[0], theData[1]); |
||
236 | 40435 | jjdelcerro | |
237 | 47476 | fdiaz | endPoint = null;
|
238 | iterator.next(); |
||
239 | 40435 | jjdelcerro | |
240 | 47476 | fdiaz | continue;
|
241 | 40435 | jjdelcerro | |
242 | 47476 | fdiaz | case PathIterator.SEG_LINETO: |
243 | case PathIterator.SEG_QUADTO: |
||
244 | case PathIterator.SEG_CUBICTO: |
||
245 | endPoint = new Point2D.Double(theData[0], theData[1]); |
||
246 | 40435 | jjdelcerro | |
247 | 47476 | fdiaz | break;
|
248 | case PathIterator.SEG_CLOSE: |
||
249 | endPoint = startPoint; |
||
250 | startPoint = firstPoint; |
||
251 | break;
|
||
252 | } |
||
253 | 40435 | jjdelcerro | |
254 | 47476 | fdiaz | double a = endPoint.getX() - startPoint.getX();
|
255 | double b = endPoint.getY() - startPoint.getY();
|
||
256 | double theta = pl.angleAtLength(currentPathLength);
|
||
257 | if(this.getEfectiveRotationInRadians(f) != 0.0){ |
||
258 | theta += this.getEfectiveRotationInRadians(f);
|
||
259 | } |
||
260 | 40435 | jjdelcerro | |
261 | 47476 | fdiaz | double x = startPoint.getX();
|
262 | double y = startPoint.getY();
|
||
263 | 40435 | jjdelcerro | |
264 | 47476 | fdiaz | // Theorem of Pythagoras
|
265 | float segmentLength = (float) Math.sqrt(a * a + b * b); |
||
266 | 40435 | jjdelcerro | |
267 | 47476 | fdiaz | // compute how many times the image has to be drawn
|
268 | // to completely cover this segment's length
|
||
269 | int count = (int) Math.ceil(segmentLength / imageWidth); |
||
270 | 40435 | jjdelcerro | |
271 | 47476 | fdiaz | for (int i = 0; (cancel == null || !cancel.isCanceled()) && i < count; i++) { |
272 | g.translate(x, y); |
||
273 | g.rotate(theta); |
||
274 | 40435 | jjdelcerro | |
275 | 47476 | fdiaz | double xOffsetTranslation = imageWidth * i;
|
276 | g.translate(xOffsetTranslation, -csWidth); |
||
277 | 40435 | jjdelcerro | |
278 | 47476 | fdiaz | rect.setBounds(0, (int) Math.round(height * .5), (int) Math.ceil(imageWidth), height); |
279 | Dimension rectSize = rect.getSize();
|
||
280 | if(rectSize.getHeight() > 0 && rectSize.getWidth() > 0) { |
||
281 | try {
|
||
282 | bg.drawInsideRectangle(g, rect, false);
|
||
283 | } catch (SymbolDrawingException e) {
|
||
284 | logger.warn(Messages.getText("label_style_could_not_be_painted"), e);
|
||
285 | } |
||
286 | } |
||
287 | g.translate(-xOffsetTranslation, csWidth); |
||
288 | 40435 | jjdelcerro | |
289 | 47476 | fdiaz | g.rotate(-theta); |
290 | g.translate(-x, -y); |
||
291 | } |
||
292 | 40435 | jjdelcerro | |
293 | 47476 | fdiaz | startPoint = endPoint; |
294 | currentPathLength += segmentLength; |
||
295 | iterator.next(); |
||
296 | } |
||
297 | g.setClip(null);
|
||
298 | } |
||
299 | |||
300 | protected double getAdjustedSize(Rectangle r, double size) { |
||
301 | if (r == null) { |
||
302 | return size;
|
||
303 | } |
||
304 | double min = Math.min(r.getHeight(), r.getWidth()); |
||
305 | if (size > min) {
|
||
306 | size = min; |
||
307 | } |
||
308 | return size;
|
||
309 | } |
||
310 | 40435 | jjdelcerro | |
311 | public String getClassName() { |
||
312 | return getClass().getName();
|
||
313 | } |
||
314 | |||
315 | /**
|
||
316 | * Returns the URL of the image that is used as a picture line symbol (when it
|
||
317 | * is selected in the map)
|
||
318 | * @return selimagePath,URL
|
||
319 | */
|
||
320 | 47476 | fdiaz | @Override
|
321 | 40435 | jjdelcerro | public URL getSelectedSource(){ |
322 | return bgSelImage.getSource();
|
||
323 | } |
||
324 | /**
|
||
325 | * Returns the URL of the image that is used as a picture line symbol
|
||
326 | * @return imagePath,URL
|
||
327 | */
|
||
328 | 47476 | fdiaz | @Override
|
329 | 40435 | jjdelcerro | public URL getSource() { |
330 | return bgImage.getSource();
|
||
331 | } |
||
332 | 42439 | dmartinezizquierdo | |
333 | 40435 | jjdelcerro | /**
|
334 | * Returns the yscale for the picture line symbol
|
||
335 | * @param yScale
|
||
336 | */
|
||
337 | 47476 | fdiaz | private double getScale(double size) { |
338 | BackgroundFileStyle image; |
||
339 | if(selected){
|
||
340 | image = bgSelImage; |
||
341 | } else {
|
||
342 | image = bgImage; |
||
343 | } |
||
344 | return size/image.getBounds().getHeight();
|
||
345 | 40435 | jjdelcerro | } |
346 | |||
347 | 47476 | fdiaz | @Override
|
348 | 40435 | jjdelcerro | public Object clone() throws CloneNotSupportedException { |
349 | PictureLineSymbol copy = (PictureLineSymbol) super.clone();
|
||
350 | |||
351 | // clone selection
|
||
352 | if (selectionSym != null) { |
||
353 | //to avoid an infinite loop
|
||
354 | if (this == selectionSym){ |
||
355 | copy.selectionSym = copy; |
||
356 | } else {
|
||
357 | copy.selectionSym = (PictureLineSymbol) selectionSym.clone(); |
||
358 | } |
||
359 | } |
||
360 | |||
361 | // clone brackground image
|
||
362 | if (bgImage != null) { |
||
363 | copy.bgImage = (BackgroundFileStyle) bgImage.clone(); |
||
364 | } |
||
365 | |||
366 | // clone selection brackground image
|
||
367 | if (bgSelImage != null) { |
||
368 | copy.bgSelImage = (BackgroundFileStyle) bgSelImage.clone(); |
||
369 | } |
||
370 | |||
371 | // FIXME: clone properties
|
||
372 | 42439 | dmartinezizquierdo | |
373 | 40435 | jjdelcerro | return copy;
|
374 | } |
||
375 | |||
376 | 47476 | fdiaz | @Override
|
377 | 40435 | jjdelcerro | public void loadFromState(PersistentState state) throws PersistenceException { |
378 | // Set parent style properties
|
||
379 | super.loadFromState(state);
|
||
380 | |||
381 | this.selected = (Boolean) state.get(SELECTED); |
||
382 | this.selectionSym = (PictureLineSymbol) state.get(SELECTION_SYMBOL);
|
||
383 | this.bgImage = (BackgroundFileStyle) state.get(BACKGROUND_IMAGE);
|
||
384 | this.bgSelImage =
|
||
385 | (BackgroundFileStyle) state.get(BACKGROUND_SELECTION_IMAGE); |
||
386 | this.setLineWidth(state.getDouble(WIDTH));
|
||
387 | 47476 | fdiaz | this.setLineWidth(state.getDouble(WIDTH));
|
388 | this.setSizeExpression(state.getString(FIELD_SIZE_EXPRESSION));
|
||
389 | 40435 | jjdelcerro | } |
390 | |||
391 | 47476 | fdiaz | @Override
|
392 | 40435 | jjdelcerro | public void saveToState(PersistentState state) throws PersistenceException { |
393 | // Save parent fill symbol properties
|
||
394 | super.saveToState(state);
|
||
395 | |||
396 | // Save own properties
|
||
397 | state.set(SELECTED, this.selected);
|
||
398 | state.set(SELECTION_SYMBOL, this.getSymbolForSelection());
|
||
399 | state.set(BACKGROUND_IMAGE, this.bgImage);
|
||
400 | state.set(BACKGROUND_SELECTION_IMAGE, this.bgSelImage);
|
||
401 | state.set(WIDTH, width); |
||
402 | 47476 | fdiaz | state.set(FIELD_SIZE_EXPRESSION, this.getSizeExpression());
|
403 | 40435 | jjdelcerro | } |
404 | 47476 | fdiaz | |
405 | private FeatureSymbolTable symbolTable = null; |
||
406 | 40435 | jjdelcerro | |
407 | 47476 | fdiaz | protected SymbolTable getSymbolTable(Feature f) {
|
408 | if (symbolTable == null) { |
||
409 | this.symbolTable = DALLocator.getManager().createFeatureSymbolTable();
|
||
410 | this.symbolTable.addSymbolTable(ExpressionUtils.createSymbolTable());
|
||
411 | } |
||
412 | symbolTable.setFeature(f); |
||
413 | return symbolTable;
|
||
414 | } |
||
415 | |||
416 | |||
417 | 46451 | fdiaz | @Override
|
418 | public Color getEfectiveLineToOffsetColor(Feature f) { |
||
419 | 47476 | fdiaz | if (f == null) { |
420 | f = this.getFeature();
|
||
421 | } |
||
422 | if (f == null || StringUtils.isBlank(this.lineToOffsetColorExpression)) { |
||
423 | return this.getLineToOffsetColor(); |
||
424 | } |
||
425 | Color theColor = ExpressionUtils.parseColor(
|
||
426 | this.getSymbolTable(f),
|
||
427 | this.lineToOffsetColorExpression,
|
||
428 | this.getLineToOffsetColor()
|
||
429 | ); |
||
430 | return theColor;
|
||
431 | 46451 | fdiaz | } |
432 | |||
433 | @Override
|
||
434 | public Point2D getEfectiveOffset(Feature f) { |
||
435 | 47476 | fdiaz | if (f == null) { |
436 | f = this.getFeature();
|
||
437 | } |
||
438 | Point2D p;
|
||
439 | if (f == null || StringUtils.isBlank(this.offsetXExpression) || StringUtils.isBlank(this.offsetYExpression)) { |
||
440 | p = this.getOffset();
|
||
441 | p = new Point2D.Double( |
||
442 | toCartographicUnits(p.getX()), |
||
443 | toCartographicUnits(p.getY()) |
||
444 | ); |
||
445 | } else {
|
||
446 | double offsetX = toCartographicUnits(ExpressionUtils.parseDouble(
|
||
447 | this.getSymbolTable(f),
|
||
448 | offsetXExpression, |
||
449 | (int) this.getOffset().getX() |
||
450 | )); |
||
451 | double offsetY = toCartographicUnits(ExpressionUtils.parseDouble(
|
||
452 | this.getSymbolTable(f),
|
||
453 | offsetYExpression, |
||
454 | (int) this.getOffset().getY() |
||
455 | )); |
||
456 | p = new Point2D.Double(offsetX, offsetY); |
||
457 | } |
||
458 | return p;
|
||
459 | 46451 | fdiaz | } |
460 | |||
461 | @Override
|
||
462 | public double getEfectiveRotationInDegres(Feature f) { |
||
463 | 47476 | fdiaz | if (StringUtils.isBlank(this.rotationExpression)) { |
464 | return Math.toDegrees(this.getRotation()); |
||
465 | } |
||
466 | // Por defecto vedra en grados.
|
||
467 | if (f == null) { |
||
468 | f = this.getFeature();
|
||
469 | } |
||
470 | if (f == null) { |
||
471 | return Math.toDegrees(this.getRotation()); |
||
472 | } |
||
473 | double r = ExpressionUtils.parseDouble(
|
||
474 | this.getSymbolTable(f),
|
||
475 | rotationExpression, |
||
476 | this.getRotation()
|
||
477 | ); |
||
478 | return r;
|
||
479 | 46451 | fdiaz | } |
480 | |||
481 | @Override
|
||
482 | public double getEfectiveRotationInRadians(Feature f) { |
||
483 | 47476 | fdiaz | // Pillamos el valor por defecto que es en grados y lo transformamos a radianes.
|
484 | if (StringUtils.isBlank(this.rotationExpression)) { |
||
485 | return this.getRotation(); |
||
486 | } |
||
487 | double r = this.getEfectiveRotationInDegres(f); |
||
488 | if (r == 0) { |
||
489 | return 0; |
||
490 | } |
||
491 | r = Math.toRadians(r);
|
||
492 | return r;
|
||
493 | 46451 | fdiaz | } |
494 | |||
495 | 47476 | fdiaz | private double getCartographicSize() { |
496 | return toCartographicUnits(getSize());
|
||
497 | } |
||
498 | |||
499 | 46451 | fdiaz | @Override
|
500 | public double getEfectiveSize(Feature f) { |
||
501 | 47476 | fdiaz | if (StringUtils.isBlank(this.sizeExpression)) { |
502 | return this.getCartographicSize(); |
||
503 | } |
||
504 | if (f == null) { |
||
505 | f = this.getFeature();
|
||
506 | } |
||
507 | if (f == null) { |
||
508 | return this.getCartographicSize(); |
||
509 | } |
||
510 | double sz = ExpressionUtils.parseDouble(
|
||
511 | this.getSymbolTable(f),
|
||
512 | this.sizeExpression,
|
||
513 | -1
|
||
514 | ); |
||
515 | if (sz < 0) { |
||
516 | return this.getCartographicSize(); |
||
517 | } |
||
518 | return toCartographicUnits(sz);
|
||
519 | 46451 | fdiaz | } |
520 | |||
521 | @Override
|
||
522 | public Color getLineToOffsetColor() { |
||
523 | 47476 | fdiaz | return this.lineToOffsetColor; |
524 | 46451 | fdiaz | } |
525 | |||
526 | @Override
|
||
527 | public String getLineToOffsetColorExpression() { |
||
528 | 47476 | fdiaz | return this.lineToOffsetColorExpression; |
529 | 46451 | fdiaz | } |
530 | |||
531 | @Override
|
||
532 | public String getOffsetXExpression() { |
||
533 | 47476 | fdiaz | return offsetXExpression;
|
534 | 46451 | fdiaz | } |
535 | |||
536 | @Override
|
||
537 | public String getOffsetYExpression() { |
||
538 | 47476 | fdiaz | return offsetYExpression;
|
539 | 46451 | fdiaz | } |
540 | |||
541 | @Override
|
||
542 | public String getRotationExpression() { |
||
543 | 47476 | fdiaz | return rotationExpression;
|
544 | 46451 | fdiaz | } |
545 | |||
546 | @Override
|
||
547 | public String getSizeExpression() { |
||
548 | 47476 | fdiaz | return sizeExpression;
|
549 | 46451 | fdiaz | } |
550 | |||
551 | @Override
|
||
552 | public boolean isDrawLineToOffset() { |
||
553 | 47476 | fdiaz | return this.drawLineToOffset; |
554 | 46451 | fdiaz | } |
555 | |||
556 | @Override
|
||
557 | public void setDrawLineToOffset(boolean drawLineToOffset) { |
||
558 | 47476 | fdiaz | this.drawLineToOffset = drawLineToOffset;
|
559 | 46451 | fdiaz | } |
560 | |||
561 | @Override
|
||
562 | public void setLineToOffsetColor(Color color) { |
||
563 | 47476 | fdiaz | this.lineToOffsetColor = color;
|
564 | 46451 | fdiaz | } |
565 | |||
566 | @Override
|
||
567 | public void setLineToOffsetColorExpression(String lineToOffsetColorExpression) { |
||
568 | 47476 | fdiaz | this.lineToOffsetColorExpression = StringUtils.trimToNull(lineToOffsetColorExpression);
|
569 | 46451 | fdiaz | } |
570 | |||
571 | @Override
|
||
572 | public void setOffsetXExpression(String offsetXExpression) { |
||
573 | 47476 | fdiaz | this.offsetXExpression = StringUtils.trimToNull(offsetXExpression);
|
574 | 46451 | fdiaz | } |
575 | |||
576 | @Override
|
||
577 | public void setOffsetYExpression(String offsetYExpression) { |
||
578 | 47476 | fdiaz | this.offsetYExpression = StringUtils.trimToNull(offsetYExpression);
|
579 | 46451 | fdiaz | } |
580 | |||
581 | @Override
|
||
582 | public void setRotationExpression(String rotationExpression) { |
||
583 | 47476 | fdiaz | this.rotationExpression = StringUtils.trimToNull(rotationExpression);
|
584 | 46451 | fdiaz | } |
585 | |||
586 | @Override
|
||
587 | public void setSizeExpression(String sizeExpression) { |
||
588 | 47476 | fdiaz | this.sizeExpression = StringUtils.trimToNull(sizeExpression);
|
589 | 46451 | fdiaz | } |
590 | |||
591 | @Override
|
||
592 | public double getRotation() { |
||
593 | 47476 | fdiaz | return rotation;
|
594 | 46451 | fdiaz | } |
595 | |||
596 | @Override
|
||
597 | 47476 | fdiaz | public void setRotation(double r) { |
598 | this.rotation = r;
|
||
599 | this.setRotationExpression(null); |
||
600 | 46451 | fdiaz | } |
601 | |||
602 | @Override
|
||
603 | public Point2D getOffset() { |
||
604 | 47476 | fdiaz | if (offset == null) { |
605 | offset = new Point(); |
||
606 | } |
||
607 | return offset;
|
||
608 | 46451 | fdiaz | } |
609 | |||
610 | @Override
|
||
611 | public void setOffset(Point2D offset) { |
||
612 | 47476 | fdiaz | this.offset = offset;
|
613 | 46451 | fdiaz | } |
614 | |||
615 | @Override
|
||
616 | public double getSize() { |
||
617 | 47476 | fdiaz | return getLineWidth();
|
618 | 46451 | fdiaz | } |
619 | |||
620 | @Override
|
||
621 | public void setSize(double size) { |
||
622 | 47476 | fdiaz | this.setSizeExpression(null); |
623 | this.setLineWidth(size);
|
||
624 | 46451 | fdiaz | } |
625 | |||
626 | @Override
|
||
627 | public IMask getMask() {
|
||
628 | 47476 | fdiaz | return mask;
|
629 | 46451 | fdiaz | } |
630 | |||
631 | @Override
|
||
632 | public void setMask(IMask mask) { |
||
633 | 47476 | fdiaz | this.mask = mask;
|
634 | 46451 | fdiaz | } |
635 | 47476 | fdiaz | |
636 | @Override
|
||
637 | public String[] getRequiredFeatureAttributeNames(FeatureStore featureStore) throws DataException { |
||
638 | // By default only need the default Geometry
|
||
639 | FeatureType ftype = featureStore.getDefaultFeatureTypeQuietly(); |
||
640 | String[] res = new String[ftype.size()]; |
||
641 | int cont = 0; |
||
642 | for (FeatureAttributeDescriptor attr : ftype) {
|
||
643 | res[cont++]=attr.getName(); |
||
644 | } |
||
645 | return res;
|
||
646 | } |
||
647 | 46451 | fdiaz | |
648 | 40435 | jjdelcerro | public static class RegisterPersistence implements Callable { |
649 | |||
650 | 47476 | fdiaz | @Override
|
651 | 40435 | jjdelcerro | public Object call() throws Exception { |
652 | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
||
653 | if (manager.getDefinition(PICTURE_LINE_SYMBOL_PERSISTENCE_DEFINITION_NAME) == null) { |
||
654 | DynStruct definition = |
||
655 | manager.addDefinition(PictureLineSymbol.class, |
||
656 | PICTURE_LINE_SYMBOL_PERSISTENCE_DEFINITION_NAME, |
||
657 | PICTURE_LINE_SYMBOL_PERSISTENCE_DEFINITION_NAME |
||
658 | + " Persistence definition",
|
||
659 | null,
|
||
660 | null);
|
||
661 | |||
662 | // Extend the Style base definition
|
||
663 | definition.extend(manager.getDefinition(LINE_SYMBOL_PERSISTENCE_DEFINITION_NAME)); |
||
664 | |||
665 | definition.addDynFieldBoolean(SELECTED).setMandatory(false);
|
||
666 | definition.addDynFieldObject(SELECTION_SYMBOL) |
||
667 | .setClassOfValue(PictureLineSymbol.class).setMandatory(false);
|
||
668 | definition.addDynFieldObject(BACKGROUND_IMAGE) |
||
669 | .setClassOfValue(BackgroundFileStyle.class).setMandatory(false);
|
||
670 | definition.addDynFieldObject(BACKGROUND_SELECTION_IMAGE) |
||
671 | .setClassOfValue(BackgroundFileStyle.class).setMandatory(false);
|
||
672 | 42439 | dmartinezizquierdo | |
673 | 40435 | jjdelcerro | definition.addDynFieldObject(WIDTH) |
674 | .setClassOfValue(Double.class).setMandatory(true); |
||
675 | 47476 | fdiaz | definition.addDynFieldString(FIELD_SIZE_EXPRESSION) |
676 | .setMandatory(false);
|
||
677 | 40435 | jjdelcerro | } |
678 | return Boolean.TRUE; |
||
679 | } |
||
680 | } |
||
681 | 42439 | dmartinezizquierdo | |
682 | 40435 | jjdelcerro | public static class RegisterSymbol implements Callable { |
683 | |||
684 | 47476 | fdiaz | @Override
|
685 | 40435 | jjdelcerro | public Object call() throws Exception { |
686 | SymbolManager manager = MapContextLocator.getSymbolManager(); |
||
687 | |||
688 | manager.registerSymbol(PICTURE_LINE_SYMBOL_PERSISTENCE_DEFINITION_NAME, |
||
689 | PictureLineSymbol.class); |
||
690 | |||
691 | return Boolean.TRUE; |
||
692 | } |
||
693 | } |
||
694 | 47476 | fdiaz | |
695 | // @Override
|
||
696 | // public void getPixExtentPlus(Geometry geom, float[] distances, ViewPort viewPort, int dpi) {
|
||
697 | // super.getPixExtentPlus(geom, distances, viewPort, dpi);
|
||
698 | // double pixWidth = toCartographicUnits(width);
|
||
699 | // distances[0] += pixWidth/2;
|
||
700 | // distances[1] += pixWidth/2;
|
||
701 | // }
|
||
702 | |||
703 | |||
704 | 40435 | jjdelcerro | } |