Revision 9888

View differences:

org.gvsig.legend.urbanhorizontalsignage/tags/org.gvsig.legend.urbanhorizontalsignage-1.0.96/org.gvsig.legend.urbanhorizontalsignage.lib/org.gvsig.legend.urbanhorizontalsignage.lib.impl/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
    <modelVersion>4.0.0</modelVersion>
3
    <artifactId>org.gvsig.legend.urbanhorizontalsignage.lib.impl</artifactId>
4
    <name>org.gvsig.legend.urbanhorizontalsignage.lib.impl</name>
5
    <parent>
6
        <groupId>org.gvsig</groupId>
7
        <artifactId>org.gvsig.legend.urbanhorizontalsignage.lib</artifactId>
8
        <version>1.0.96</version>
9
    </parent>
10
    <groupId>org.gvsig</groupId>
11
    <dependencies>
12
        <dependency>
13
            <groupId>org.gvsig</groupId>
14
            <artifactId>org.gvsig.legend.urbanhorizontalsignage.lib.api</artifactId>
15
            <scope>compile</scope>
16
        </dependency>
17
        <dependency>
18
            <groupId>org.gvsig</groupId>
19
            <artifactId>org.gvsig.fmap.dal.api</artifactId>
20
            <scope>compile</scope>
21
        </dependency>
22
        <dependency>
23
            <groupId>org.gvsig</groupId>
24
            <artifactId>org.gvsig.symbology.lib.impl</artifactId>
25
            <scope>compile</scope>
26
        </dependency>
27
        <dependency>
28
            <groupId>org.gvsig</groupId>
29
            <artifactId>org.gvsig.ui</artifactId>
30
            <scope>compile</scope>
31
        </dependency>
32
    
33
        <dependency>
34
            <groupId>org.gvsig</groupId>
35
            <artifactId>org.gvsig.fmap.dal.impl</artifactId>
36
            <scope>test</scope>
37
        </dependency>
38
        <dependency>
39
            <groupId>org.gvsig</groupId>
40
<!--
41
            <artifactId>${org.gvsig.h2spatial.provider}</artifactId>
42
-->
43
            <artifactId>org.gvsig.h2spatial.h2gis132.provider</artifactId>
44
            
45
            <scope>test</scope>
46
        </dependency>
47
        <dependency>
48
            <groupId>org.gvsig</groupId>
49
            <artifactId>${org.gvsig.fmap.geometry.impl}</artifactId>
50
            <scope>test</scope>
51
        </dependency>    
52
        <dependency>
53
            <groupId>org.gvsig</groupId>
54
            <artifactId>org.gvsig.expressionevaluator.lib.impl</artifactId>
55
            <scope>test</scope>
56
        </dependency>    
57
        <dependency>
58
            <groupId>org.gvsig</groupId>
59
            <artifactId>org.gvsig.expressionevaluator.geometry.lib.impl</artifactId>
60
            <scope>test</scope>
61
        </dependency>    
62
        <dependency>
63
            <groupId>org.gvsig</groupId>
64
            <artifactId>${org.gvsig.proj.lib.impl}</artifactId>
65
            <scope>test</scope>
66
        </dependency>
67
        <dependency>
68
            <groupId>org.gvsig</groupId>
69
            <artifactId>org.gvsig.compat.se</artifactId>
70
            <scope>test</scope>
71
        </dependency>
72
        <dependency>
73
            <groupId>org.gvsig</groupId>
74
            <artifactId>org.gvsig.metadata.lib.basic.impl</artifactId>
75
            <scope>test</scope>
76
        </dependency>      
77
        <dependency>
78
            <groupId>org.gvsig</groupId>
79
            <artifactId>org.gvsig.timesupport.lib.impl</artifactId>
80
            <scope>test</scope>
81
        </dependency>
82
        <dependency>
83
            <groupId>org.gvsig</groupId>
84
            <artifactId>org.gvsig.fmap.dal.file.csv</artifactId>
85
            <scope>test</scope>
86
        </dependency>
87
        <dependency>
88
            <groupId>org.gvsig</groupId>
89
            <artifactId>org.gvsig.tools.util.impl</artifactId>
90
            <scope>test</scope>
91
        </dependency>
92
        <dependency>
93
            <groupId>org.gvsig</groupId>
94
            <artifactId>org.gvsig.tools.swing.impl</artifactId>
95
            <scope>test</scope>
96
        </dependency>
97
        <dependency>
98
            <groupId>org.gvsig</groupId>
99
            <artifactId>org.gvsig.fmap.dal.db.jdbc</artifactId>
100
            <scope>compile</scope>
101
        </dependency>
102
    </dependencies>
103
</project>
org.gvsig.legend.urbanhorizontalsignage/tags/org.gvsig.legend.urbanhorizontalsignage-1.0.96/org.gvsig.legend.urbanhorizontalsignage.lib/org.gvsig.legend.urbanhorizontalsignage.lib.impl/src/test/java/org/gvsig/legend/urbanhorizontalsignage/lib/impl/Test01CalculateGeometries.java
1
package org.gvsig.legend.urbanhorizontalsignage.lib.impl;
2

  
3
import org.gvsig.legend.urbanhorizontalsignage.lib.impl.linelegend.SplittedLine;
4
import java.util.List;
5
import junit.framework.TestCase;
6
import org.gvsig.fmap.geom.GeometryUtils;
7
import org.gvsig.fmap.geom.primitive.Line;
8
import org.gvsig.fmap.geom.primitive.Point;
9
import org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData;
10
import org.gvsig.legend.urbanhorizontalsignage.lib.api.UrbanHorizontalSignageLocator;
11
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
12
import org.slf4j.Logger;
13
import org.slf4j.LoggerFactory;
14

  
15
public class Test01CalculateGeometries extends TestCase {
16

  
17
    private static final Logger LOGGER = LoggerFactory.getLogger(Test01CalculateGeometries.class);
18

  
19
    public Test01CalculateGeometries(String testName) {
20
        super(testName);
21
    }
22

  
23
    @Override
24
    protected void setUp() throws Exception {
25
        super.setUp();
26
        new DefaultLibrariesInitializer().fullInitialize();
27
    }
28

  
29
    @Override
30
    protected void tearDown() throws Exception {
31
        super.tearDown();
32
    }
33

  
34
    // TODO add test methods here. The name must begin with 'test'. For example:
35
    // public void testHello() {}
36
    public void test01CalculateIntermediatePoint() {
37
        final String testid = "calculateIntermediatePoint";
38
        Point p1 = GeometryUtils.createPoint(0,0);
39
        Point p2 = GeometryUtils.createPoint(10,0);
40
              
41
        DefaultUrbanHorizontalSignageManager uhsManager = (DefaultUrbanHorizontalSignageManager)UrbanHorizontalSignageLocator.getUrbanHorizontalSignageManager();
42
        try {
43
            for (double lambda = 0; lambda <= 1; lambda += 0.1) {
44
                Point intermediatePoint = uhsManager.calculateIntermediatePoint(p1, p2, lambda);
45
                assertEquals(10*lambda, intermediatePoint.getCoordinateAt(0));
46
                assertEquals(0.0, intermediatePoint.getCoordinateAt(1));
47
            }
48
        } catch (Exception ex) {
49
            //TODO:
50
            fail(ex.getMessage());
51
        }
52
        
53
        
54
    }
55
    
56
    public void test02SplitLine() throws Exception {
57
        final String testid = "splitLine";
58
        
59
        Point p1 = GeometryUtils.createPoint(0,0);
60
        Point p2 = GeometryUtils.createPoint(10,0);
61
        Line line = GeometryUtils.createLine(p1, p2, 0);
62
        
63
        DefaultUrbanHorizontalSignageManager uhsManager = (DefaultUrbanHorizontalSignageManager)UrbanHorizontalSignageLocator.getUrbanHorizontalSignageManager();
64
//        UrbanHorizontalSignageData data = uhsManager.createUrbanHorizontalSignageData();
65

  
66
//        data.setWidth(20);
67
//        data.setContinuity(UrbanHorizontalSignageData.DEFAULT_CONTINUITY_VALUE);
68
//        data.setSegmentsLength(100);
69
//        data.setHolesLength(50);
70
//        data.setGapWith(10);
71
//        data.setSegmentsColor(Color.RED);
72
//        data.setHolesColor(Color.BLACK);
73
//        data.setRoundVertex(false);
74
//        data.setPaintHoles(true);
75
        
76
        SplittedLine splittedLine = uhsManager.splitLine(line, 1, 0.5);
77
        
78
        List<Line> segments = splittedLine.getSegments();
79
        List<Line> holes = splittedLine.getHoles();
80
        
81
        assertEquals(7, segments.size());
82
        assertEquals(6, holes.size());
83
        
84
        double x = 0;
85
        for (Line segment : segments) {
86
            assertEquals(x, segment.getVertex(0).getX());
87
            assertEquals(x+1.0, segment.getVertex(1).getX());
88
            x += 1.50;
89
        }
90
        x = 1.0;
91
        for (Line hole : holes) {
92
            assertEquals(x, hole.getVertex(0).getX());
93
            assertEquals(x+0.5, hole.getVertex(1).getX());
94
            x += 1.50;
95
        }
96
    }
97
    
98
    
99
}
org.gvsig.legend.urbanhorizontalsignage/tags/org.gvsig.legend.urbanhorizontalsignage-1.0.96/org.gvsig.legend.urbanhorizontalsignage.lib/org.gvsig.legend.urbanhorizontalsignage.lib.impl/src/main/resources/org/gvsig/legend/urbanhorizontalsignage/lib/impl/UrbanHorizontalSignagePersistence.xml
1
<?xml version="1.0"?>
2
<definitions>
3
    <version>1.0.0</version>
4
    <classes>
5
        <class name="DefaultUrbanHorizontalSignageLegend">
6
            <extends>
7
                <class name="VectorialLegend" namespace="persistence"/>
8
            </extends>
9
            <fields>
10
                <field name="config" type="Object" ClassOfValue="org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageConfig" mandatory="false">
11
                    <description></description>
12
                </field>
13
            </fields>
14
        </class>
15
        
16
        <class name="DefaultUrbanHorizontalSignageConfig">
17
            <extends>
18
            </extends>
19
            <fields>
20
                <field name="widthFieldName" type="String" defaultValue="">
21
                    <description></description>
22
                </field>
23
                <field name="continuityFieldName" type="String" defaultValue="">
24
                    <description></description>
25
                </field>
26
                <field name="segmentsColorFieldName" type="String" defaultValue="">
27
                    <description></description>
28
                </field>
29
                <field name="segmentsLengthFieldName" type="String" defaultValue="">
30
                    <description></description>
31
                </field>
32
                <field name="holesLengthFieldName" type="String" defaultValue="">
33
                    <description></description>
34
                </field>
35
                <field name="paintHolesFieldName" type="String" defaultValue="">
36
                    <description></description>
37
                </field>
38
                <field name="holesColorFieldName" type="String" defaultValue="">
39
                    <description></description>
40
                </field>
41
                <field name="roundVertexFieldName" type="String" defaultValue="">
42
                    <description></description>
43
                </field>
44
                <field name="gapWidth" type="Integer" defaultValue="15">
45
                    <description></description>
46
                </field>
47

  
48
            </fields>
49
        </class>
50

  
51

  
52
        <class name="UrbanHorizontalSignageSymbol">
53
            <extends>
54
                <class name="Symbol" namespace="persistence"/>
55
            </extends>
56
            <fields>
57
                <field name="width" type="Double" defaultValue="0.15" mandatory="false">
58
                    <description></description>
59
                </field>
60
                <field name="continuity" type="Integer" defaultValue="1" mandatory="false">
61
                    <description></description>
62
                </field>
63
                <field name="segmentsColor" type="Object" ClassOfValue="java.awt.Color" defaultValue="blue" mandatory="false">
64
                    <description></description>
65
                </field>
66
                <field name="segmentsLength" type="Double" defaultValue="0.5" mandatory="false">
67
                    <description></description>
68
                </field>
69
                <field name="holesColor" type="Object" ClassOfValue="java.awt.Color" defaultValue="black" mandatory="false">
70
                    <description></description>
71
                </field>
72
                <field name="holesLength" type="Double" defaultValue="0.5" mandatory="false">
73
                    <description></description>
74
                </field>
75
                <field name="paintHoles" type="Boolean" defaultValue="false" mandatory="false">
76
                    <description></description>
77
                </field>
78
                <field name="gapWidth" type="Double" defaultValue="0.15" mandatory="false">
79
                    <description></description>
80
                </field>
81
                <field name="roundVertex" type="Boolean" defaultValue="false" mandatory="false">
82
                    <description></description>
83
                </field>
84
                <field name="transparency" type="Double" defaultValue="1.0" mandatory="false">
85
                    <description></description>
86
                </field>
87
                <field name="mustDrawOriginalGeometry" type="Boolean" defaultValue="false" mandatory="false">
88
                    <description></description>
89
                </field>
90
                <field name="colorForOriginalGeometry" type="Object" ClassOfValue="java.awt.Color" defaultValue="yellow" mandatory="false">
91
                    <description></description>
92
                </field>
93
            </fields>
94
        </class>
95

  
96
    </classes>
97
</definitions>
org.gvsig.legend.urbanhorizontalsignage/tags/org.gvsig.legend.urbanhorizontalsignage-1.0.96/org.gvsig.legend.urbanhorizontalsignage.lib/org.gvsig.legend.urbanhorizontalsignage.lib.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.legend.urbanhorizontalsignage.lib.impl.UrbanHorizontalSignageLibraryImpl
org.gvsig.legend.urbanhorizontalsignage/tags/org.gvsig.legend.urbanhorizontalsignage-1.0.96/org.gvsig.legend.urbanhorizontalsignage.lib/org.gvsig.legend.urbanhorizontalsignage.lib.impl/src/main/java/org/gvsig/legend/urbanhorizontalsignage/lib/impl/DefaultUrbanHorizontalSignageManager.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2015 gvSIG Association
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., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.legend.urbanhorizontalsignage.lib.impl;
24

  
25
import org.gvsig.legend.urbanhorizontalsignage.lib.impl.linelegend.DefaultUrbanHorizontalSignageLegend;
26
import org.gvsig.legend.urbanhorizontalsignage.lib.impl.linelegend.DefaultUrbanHorizontalSignageData;
27
import org.gvsig.legend.urbanhorizontalsignage.lib.impl.linelegend.SplittedLine;
28
import java.io.File;
29
import java.util.Iterator;
30
import java.util.List;
31
import java.util.UUID;
32
import org.apache.commons.lang3.StringUtils;
33
import org.gvsig.fmap.dal.DALLocator;
34
import org.gvsig.fmap.dal.DataManager;
35
import org.gvsig.fmap.dal.DataStoreParameters;
36
import org.gvsig.fmap.dal.exception.DataException;
37
import org.gvsig.fmap.dal.feature.EditableFeature;
38
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
39
import org.gvsig.fmap.dal.feature.EditableFeatureType;
40
import org.gvsig.fmap.dal.feature.Feature;
41
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
42
import org.gvsig.fmap.dal.feature.FeatureSet;
43
import org.gvsig.fmap.dal.feature.FeatureStore;
44
import org.gvsig.fmap.dal.store.jdbc.JDBCNewStoreParameters;
45
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
46
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer;
47
import org.gvsig.fmap.geom.DataTypes;
48
import org.gvsig.fmap.geom.Geometry;
49
import static org.gvsig.fmap.geom.Geometry.JOIN_STYLE_MITRE;
50
import static org.gvsig.fmap.geom.Geometry.JOIN_STYLE_ROUND;
51
import org.gvsig.fmap.geom.GeometryLocator;
52
import org.gvsig.fmap.geom.GeometryManager;
53
import org.gvsig.fmap.geom.GeometryUtils;
54
import org.gvsig.fmap.geom.aggregate.MultiLine;
55
import org.gvsig.fmap.geom.aggregate.MultiPolygon;
56
import org.gvsig.fmap.geom.exception.CreateGeometryException;
57
import org.gvsig.fmap.geom.operation.GeometryOperationException;
58
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
59
import org.gvsig.fmap.geom.primitive.Line;
60
import org.gvsig.fmap.geom.primitive.Point;
61
import org.gvsig.fmap.geom.primitive.Polygon;
62
import org.gvsig.fmap.geom.type.GeometryType;
63
import org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageConfig;
64
import org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData;
65
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.CONTINUITY_MODE_CONT;
66
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.CONTINUITY_MODE_CONT_CONT;
67
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.CONTINUITY_MODE_CONT_DISC;
68
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.CONTINUITY_MODE_DISC;
69
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.CONTINUITY_MODE_DISC_CONT;
70
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.CONTINUITY_MODE_DISC_DISC;
71
import org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageLegend;
72
import org.gvsig.legend.urbanhorizontalsignage.lib.api.UrbanHorizontalSignageLocator;
73
import org.gvsig.legend.urbanhorizontalsignage.lib.api.UrbanHorizontalSignageManager;
74
import org.gvsig.tools.ToolsLocator;
75
import org.gvsig.tools.folders.FoldersManager;
76
import org.gvsig.tools.task.SimpleTaskStatus;
77
import org.gvsig.tools.util.HasAFile;
78
import org.slf4j.LoggerFactory;
79

  
80
@SuppressWarnings("UseSpecificCatch")
81
public class DefaultUrbanHorizontalSignageManager implements UrbanHorizontalSignageManager {
82

  
83
    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(DefaultUrbanHorizontalSignageManager.class);
84

  
85
    @Override
86
    public UrbanHorizontalSignageLegend createUrbanHorizontalSignageLegend() {
87
        return new DefaultUrbanHorizontalSignageLegend();
88
    }
89

  
90
    @Override
91
    public Class<? extends UrbanHorizontalSignageLegend> getUrbanHorizontalSignageLegendClass() {
92
        return DefaultUrbanHorizontalSignageLegend.class;
93
    }
94

  
95
    @Override
96
    public UrbanHorizontalSignageData createUrbanHorizontalSignageData() {
97
        return new DefaultUrbanHorizontalSignageData();
98
    }
99

  
100
    @Override
101
    public void calculateGeometries(Geometry originalGeometry, UrbanHorizontalSignageData data) {
102
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
103
        try {
104
            MultiPolygon segments = geomManager.createMultiPolygon(originalGeometry.getGeometryType().getSubType());
105
            MultiPolygon holes = geomManager.createMultiPolygon(originalGeometry.getGeometryType().getSubType());
106
            MultiLine lineSegments = geomManager.createMultiLine(originalGeometry.getGeometryType().getSubType());
107
            MultiLine lineHoles = geomManager.createMultiLine(originalGeometry.getGeometryType().getSubType());
108
            MultiLine lines = originalGeometry.toLines();
109
            final double offsetValueInMeters = Math.abs(data.getGapWidth() / 2.0 + data.getWidth() / 2.0);
110
            final double bufferValueInMeters = Math.abs(data.getWidth() / 2.0);
111
            for (Geometry geom : lines) {
112
                Line line = (Line) geom;
113
                switch (data.getContinuity()) {
114
                    case CONTINUITY_MODE_CONT:
115
                    default:
116
                        Geometry buffer = line.buffer(
117
                                bufferValueInMeters,
118
                                data.isRoundVertex() ? JOIN_STYLE_ROUND : JOIN_STYLE_MITRE,
119
                                true
120
                        );
121
                        if (buffer != null) {
122
                            segments.addPrimitives(buffer);
123
                            lineSegments.addPrimitives(line);
124
                        }
125
                        break;
126

  
127
                    case CONTINUITY_MODE_DISC:
128
                        SplittedLine splittedLine = splitLine(line, data.getSegmentsLength(), data.getHolesLength());
129
                        List<Line> splittedSegments = splittedLine.getSegments();
130
                        List<Line> splittedHoles = splittedLine.getHoles();
131
                        for (Line segment : splittedSegments) {
132
                            buffer = segment.buffer(bufferValueInMeters,
133
                                    data.isRoundVertex() ? JOIN_STYLE_ROUND : JOIN_STYLE_MITRE,
134
                                    true
135
                            );
136
                            if (buffer != null) {
137
                                segments.addPrimitives(buffer);
138
                                lineSegments.addPrimitives(segment);
139
                            }
140
                        }
141
                        for (Line hole : splittedHoles) {
142
                            buffer = hole.buffer(
143
                                    bufferValueInMeters,
144
                                    data.isRoundVertex() ? JOIN_STYLE_ROUND : JOIN_STYLE_MITRE,
145
                                    true
146
                            );
147
                            if (buffer != null) {
148
                                holes.addPrimitives(buffer);
149
                                lineHoles.addPrimitives(hole);
150
                            }
151
                        }
152
                        break;
153

  
154
                    case CONTINUITY_MODE_CONT_CONT:
155
                        //Left
156
                        addOffsetedAndBufferedSegment(segments, lineSegments, line, offsetValueInMeters, bufferValueInMeters, data.isRoundVertex());
157
                        //Right
158
                        addOffsetedAndBufferedSegment(segments, lineSegments, line, -offsetValueInMeters, bufferValueInMeters, data.isRoundVertex());
159
                        break;
160

  
161
                    case CONTINUITY_MODE_CONT_DISC:
162
                        //Left
163
                        addOffsetedAndBufferedSegment(segments, lineSegments, line, offsetValueInMeters, bufferValueInMeters, data.isRoundVertex());
164
                        //Right
165
                        splittedLine = splitLine(line, data.getSegmentsLength(), data.getHolesLength());
166
                        splittedSegments = splittedLine.getSegments();
167
                        splittedHoles = splittedLine.getHoles();
168
                        for (Line segment : splittedSegments) {
169
                            addOffsetedAndBufferedSegment(segments, lineSegments, segment, -offsetValueInMeters, bufferValueInMeters, true);
170
                        }
171
                        for (Line hole : splittedHoles) {
172
                            addOffsetedAndBufferedSegment(holes, lineHoles, hole, -offsetValueInMeters, bufferValueInMeters, true);
173
                        }
174
                        break;
175

  
176
                    case CONTINUITY_MODE_DISC_CONT:
177
                        //Left
178
                        splittedLine = splitLine(line, data.getSegmentsLength(), data.getHolesLength());
179
                        splittedSegments = splittedLine.getSegments();
180
                        splittedHoles = splittedLine.getHoles();
181
                        for (Line segment : splittedSegments) {
182
                            addOffsetedAndBufferedSegment(segments, lineSegments, segment, offsetValueInMeters, bufferValueInMeters, true);
183
                        }
184
                        for (Line hole : splittedHoles) {
185
                            addOffsetedAndBufferedSegment(holes, lineHoles, hole, offsetValueInMeters, bufferValueInMeters, true);
186
                        }
187
                        //Right
188
                        addOffsetedAndBufferedSegment(segments, lineSegments, line, -offsetValueInMeters, bufferValueInMeters, data.isRoundVertex());
189
                        break;
190

  
191
                    case CONTINUITY_MODE_DISC_DISC:
192
                        splittedLine = splitLine(line, data.getSegmentsLength(), data.getHolesLength());
193
                        splittedSegments = splittedLine.getSegments();
194
                        splittedHoles = splittedLine.getHoles();
195
                        //Left
196
                        for (Line segment : splittedSegments) {
197
                            addOffsetedAndBufferedSegment(segments, lineSegments, segment, offsetValueInMeters, bufferValueInMeters, true);
198
                        }
199
                        for (Line hole : splittedHoles) {
200
                            addOffsetedAndBufferedSegment(holes, lineHoles, hole, offsetValueInMeters, bufferValueInMeters, true);
201
                        }
202
                        //Right
203
                        for (Line segment : splittedSegments) {
204
                            addOffsetedAndBufferedSegment(segments, lineSegments, segment, -offsetValueInMeters, bufferValueInMeters, true);
205
                        }
206
                        for (Line hole : splittedHoles) {
207
                            addOffsetedAndBufferedSegment(holes, lineHoles, hole, -offsetValueInMeters, bufferValueInMeters, true);
208
                        }
209
                        break;
210

  
211
                }
212

  
213
            }
214
            data.setSegmentsGeometry(segments);
215
            data.setHolesGeometry(holes);
216
            data.setLineSegmentsGeometry(lineSegments);
217
            data.setLineHolesGeometry(lineHoles);
218
        } catch (Exception ex) {
219
            LOGGER.warn("Can't calculate geometries.", ex);
220
//            Logger.getLogger(DefaultUrbanHorizontalSignageManager.class.getName()).log(Level.SEVERE, null, ex);
221
        }
222

  
223
    }
224

  
225
    protected void addOffsetedAndBufferedSegment(MultiPolygon segments, MultiLine lineSegments, Line segment, final double offsetValueInMeters, final double bufferValueInMeters, boolean roundVertex) throws GeometryOperationException, GeometryOperationNotSupportedException {
226
        Geometry buffer;
227
        final int joinStyle = roundVertex ? JOIN_STYLE_ROUND : JOIN_STYLE_MITRE;
228

  
229
        Geometry segmentOffset;
230
        if (segment.isClosed() && segment.getNumVertices() > 2 && segment.isCCW()) {
231
            Line cloned = segment.cloneGeometry();
232
            cloned.flip();
233
            segmentOffset = cloned.offset(
234
                    joinStyle,
235
                    -offsetValueInMeters
236
            );
237
        } else {
238
            segmentOffset = segment.cloneGeometry().offset(
239
                    joinStyle,
240
                    offsetValueInMeters
241
            );
242
        }
243
        if (segmentOffset == null) {
244
            return;
245
        }
246
        buffer = segmentOffset.buffer(bufferValueInMeters, joinStyle,
247
                true
248
        );
249
        if (buffer != null) {
250
            segments.addPrimitives(buffer);
251
            lineSegments.addPrimitives(segmentOffset);
252
        }
253
    }
254

  
255
    /*
256
        segmentLength & holesLenght in meters
257
     */
258
 /*friend*/
259
    SplittedLine splitLine(Line line, double segmentLength, double holesLength) throws CreateGeometryException, GeometryOperationNotSupportedException, GeometryOperationException, CloneNotSupportedException {
260
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
261
        SplittedLine res = new SplittedLine();
262

  
263
        Point previousPoint = null;
264
        double previousLength = 0;
265
        Line currentSegment = geomManager.createLine(line.getGeometryType().getSubType());
266
        boolean isHole = false;
267
        boolean advanceToNext = true;
268
        Point currentPoint = null;
269
        Iterator<Point> it = line.iterator();
270
        while (it.hasNext() || !advanceToNext) {
271
            if (advanceToNext) {
272
                currentPoint = it.next();
273
            }
274
            if (previousPoint == null) {
275
                previousPoint = currentPoint.clone();
276
                currentSegment.addVertex(previousPoint);
277
                advanceToNext = true;
278
                continue;
279
            }
280
            double distance = previousPoint.distance(currentPoint);
281
            if (!isHole) {
282
                if (previousLength + distance < segmentLength) {
283
                    previousLength += distance;
284
                    if (distance > 0.0) {
285
                        currentSegment.addVertex(currentPoint);
286
                    }
287
                    previousPoint = currentPoint.cloneGeometry();
288
                    advanceToNext = true;
289
//                    continue;
290
                } else {
291
                    //buscar punto dentro del segmento a una distancia = segmentLengthMeters-previousLength
292
                    Point point = calculateIntermediatePoint(previousPoint, currentPoint, (segmentLength - previousLength) / distance);
293
                    //agregarlo al currentSegment,
294
                    currentSegment.addVertex(point);
295
                    //agregar  el currentSegment a la lista de segmentos
296
                    res.addSegment(currentSegment.cloneGeometry());
297
                    //crear un nuevo currentSegment y meter el punto como primero
298
                    currentSegment = geomManager.createLine(line.getGeometryType().getSubType());
299
                    currentSegment.addVertex(point);
300
                    //cambiar modo ==> isHole = true
301
                    isHole = !isHole;
302
                    previousPoint = point.clone();
303
                    previousLength = 0;
304
                    advanceToNext = false;
305
//                    continue;
306
                }
307
            } else {
308
                if (previousLength + distance < holesLength) {
309
                    previousLength += distance;
310
                    if (distance > 0.0) {
311
                        currentSegment.addVertex(currentPoint);
312
                    }
313
                    previousPoint = currentPoint.cloneGeometry();
314
                    advanceToNext = true;
315
//                    continue;
316
                } else {
317
                    //buscar punto dentro del segmento a una distancia = segmentLengthMeters-previousLength
318
                    Point point = calculateIntermediatePoint(previousPoint, currentPoint, (holesLength - previousLength) / distance);
319
                    //agregarlo al currentSegment,
320
                    currentSegment.addVertex(point);
321
                    //agregar  el surrentSegment a la lista de segmentos
322
                    res.addHole(currentSegment.cloneGeometry());
323
                    //crear un nuevo currentSegment y meter el punto como primero
324
                    currentSegment = geomManager.createLine(line.getGeometryType().getSubType());
325
                    currentSegment.addVertex(point);
326
                    //Cambiar modo Segment <==> Hole
327
                    isHole = !isHole;
328
                    previousPoint = point.clone();
329
                    previousLength = 0;
330
                    advanceToNext = false;
331
//                    continue;
332
                }
333
            }
334
        }
335

  
336
        if (currentSegment.getNumVertices() > 1) {
337
            if (isHole) {
338
                res.addHole(currentSegment.cloneGeometry());
339
            } else {
340
                res.addSegment(currentSegment.cloneGeometry());
341
            }
342
        }
343

  
344
        return res;
345
    }
346

  
347
    /**
348
     * @deprecated
349
     * use {@link GeometryUtils.calculateLambdaPoint}
350
     * 
351
     * @param p1
352
     * @param p2
353
     * @param lambda
354
     * @return
355
     * @throws CreateGeometryException
356
     * @throws GeometryOperationNotSupportedException
357
     * @throws GeometryOperationException
358
     * @deprecated
359
     */
360
    @Deprecated 
361
    Point calculateIntermediatePoint(Point p1, Point p2, double lambda) throws CreateGeometryException, GeometryOperationNotSupportedException, GeometryOperationException {
362
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
363
        GeometryType geomType = p1.getGeometryType();
364
        int subtype = geomType.getSubType();
365
        int dimension = geomType.getDimension();
366
        double[] coords = new double[dimension];
367
        Point p = geomManager.createPoint(0, 0, subtype);
368
        double distance = p1.distance(p2);
369
        for (int d = 0; d < dimension; d++) {
370
            p.setCoordinateAt(
371
                    d,
372
                    p1.getCoordinateAt(d) + (p2.getCoordinateAt(d) - p1.getCoordinateAt(d)) * lambda);
373
        }
374

  
375
        return p;
376
    }
377

  
378
    @Override
379
    public FeatureStore createTemporaryPolygonsFromLines(UrbanHorizontalSignageConfig config, FeatureSet lines, SimpleTaskStatus status) {
380

  
381
        //TODO: el status....
382
        UrbanHorizontalSignageManager uhsManager = UrbanHorizontalSignageLocator.getUrbanHorizontalSignageManager();
383
        EditableFeatureType targetFeatureType = createTargetFeatureType(lines.getFeatureStore());
384
        FeatureStore targetStore = createTemporalStore(targetFeatureType);
385
        try {
386
            targetStore.edit(FeatureStore.MODE_APPEND);
387

  
388
            for (Feature feature : lines) {
389

  
390
                Geometry originalGeometry = feature.getDefaultGeometry();
391

  
392
                UrbanHorizontalSignageData data = config.getValues(feature);
393

  
394
                uhsManager.calculateGeometries(originalGeometry, data);
395

  
396
                MultiPolygon multiGeom = data.getSegmentsGeometry();
397
                MultiLine multiLine = data.getLineSegmentsGeometry();
398
                insertPolygonsOfLine(multiGeom, multiLine, targetStore, feature, config, config.getSegmentsColorFieldName());
399

  
400
                switch (data.getContinuity()) {
401
                    case CONTINUITY_MODE_CONT_DISC:
402
                    case CONTINUITY_MODE_DISC_CONT:
403
                    case CONTINUITY_MODE_DISC:
404
                    case CONTINUITY_MODE_DISC_DISC:
405
                        if (data.isPaintHoles()) {
406
                            multiGeom = data.getHolesGeometry();
407
                            multiLine = data.getLineHolesGeometry();
408
                            insertPolygonsOfLine(multiGeom, multiLine, targetStore, feature, config, config.getHolesColorFieldName());
409
                        }
410
                }
411

  
412
            }
413

  
414
            targetStore.finishEditing();
415
            return targetStore;
416

  
417
        } catch (Exception e) {
418
            LOGGER.debug("Can't create temporary polygons store.", e);
419
        }
420

  
421
        return null;
422
    }
423

  
424
    private void insertPolygonsOfLine(MultiPolygon multiGeom, MultiLine multiLine, FeatureStore targetStore, Feature feature, UrbanHorizontalSignageConfig config, String colorFieldName) throws GeometryOperationNotSupportedException, GeometryOperationException, DataException {
425
        if (multiGeom != null && multiGeom.getPrimitivesNumber() > 0) {
426
            for (int i = 0; i < multiGeom.getPrimitivesNumber(); i++) {
427
                Polygon polygon = (Polygon) multiGeom.getPrimitiveAt(i);
428
                Line line = (Line) multiLine.getPrimitiveAt(i);
429
                EditableFeature targetFeature = targetStore.createNewFeature();
430
                targetFeature.copyFrom(feature, (FeatureAttributeDescriptor t) -> !(t.isPrimaryKey() || (t.isIndexed() && !t.allowIndexDuplicateds()) || t.getType() == DataTypes.GEOMETRY));
431

  
432
                if (StringUtils.isNotBlank(config.getTargetColorFieldName())) {
433
                    targetFeature.set(config.getTargetColorFieldName(), feature.get(colorFieldName));
434
                }
435

  
436
                if (StringUtils.isNotBlank(config.getTargetLenghtFieldName())) {
437
                    targetFeature.set(config.getTargetLenghtFieldName(), line.perimeter());
438
                }
439

  
440
                if (StringUtils.isNotBlank(config.getTargetAreaFieldName())) {
441
                    targetFeature.set(config.getTargetAreaFieldName(), polygon.area());
442
                }
443

  
444
                targetFeature.setDefaultGeometry(polygon);
445
                targetStore.insert(targetFeature);
446
            }
447
        }
448
    }
449

  
450
    private EditableFeatureType createTargetFeatureType(FeatureStore store) {
451
        DataManager dataManager = DALLocator.getDataManager();
452

  
453
        EditableFeatureType featureType = dataManager.createFeatureType();
454
        featureType.addAll(store.getDefaultFeatureTypeQuietly());
455
        for (FeatureAttributeDescriptor attr : featureType) {
456
            EditableFeatureAttributeDescriptor eattr = (EditableFeatureAttributeDescriptor) attr;
457
            eattr.setIsPrimaryKey(false);
458
            eattr.setIsIndexed(false);
459
            eattr.setAllowNull(true);
460
        }
461

  
462
        EditableFeatureAttributeDescriptor attr = (EditableFeatureAttributeDescriptor) featureType.getDefaultGeometryAttribute();
463
        attr.setGeometryType(Geometry.TYPES.POLYGON, Geometry.SUBTYPES.GEOM2D);
464

  
465
        return featureType;
466
    }
467

  
468
    private FeatureStore createTemporalStore(EditableFeatureType featType) {
469
        if (featType.getStore() != null) {
470
            throw new IllegalArgumentException("Can't create temporal store from a feature type of a already existent store.");
471
        }
472
        try {
473
            // crear ruta de archivo temporal
474
            FoldersManager foldersManager = ToolsLocator.getFoldersManager();
475
            File tempFile = foldersManager.getUniqueTemporaryFile("urbanHorizontalSignage_temporal_store_" + UUID.randomUUID().toString());
476

  
477
            // crear SERVER STORE
478
            DataManager dataManager = DALLocator.getDataManager();
479
            JDBCServerExplorerParameters serverParameters = (JDBCServerExplorerParameters) dataManager.createServerExplorerParameters("H2Spatial");
480
            ((HasAFile) serverParameters).setFile(tempFile);
481
            JDBCServerExplorer serverExplorer = (JDBCServerExplorer) dataManager.openServerExplorer("H2Spatial", serverParameters);
482

  
483
            //Crear tablas en server store
484
            JDBCNewStoreParameters parametersResults = serverExplorer.getAddParameters();
485
            parametersResults.setDynValue("Table", "results");
486

  
487
            parametersResults.setDefaultFeatureType(featType);
488
            serverExplorer.add("H2Spatial", parametersResults, true);
489

  
490
            DataStoreParameters storeParametersResults = dataManager.createStoreParameters("H2Spatial");
491
            storeParametersResults.setDynValue("database_file", tempFile);
492
            storeParametersResults.setDynValue("Table", "results");
493

  
494
            //Creaci?n del store con los resultados
495
            FeatureStore storeResults = (FeatureStore) dataManager.openStore("H2Spatial", storeParametersResults);
496

  
497
            return storeResults;
498
        } catch (Exception ex) {
499
            LOGGER.debug("Can't create temporal store.", ex);
500
            return null;
501
        }
502
    }
503

  
504
    @Override
505
    public void convertLinesToPolygons(
506
            UrbanHorizontalSignageConfig config,
507
            FeatureSet source,
508
            FeatureStore targetStore,
509
            boolean deleteSourceAtFinish,
510
            SimpleTaskStatus status
511
    ) {
512

  
513
        boolean needFinishEditing = !(targetStore.isEditing() || targetStore.isAppending());
514
        try {
515
            if (needFinishEditing) {
516
                targetStore.edit();
517
            }
518
            for (Feature feature : source) {
519
                Geometry geom = feature.getDefaultGeometry();
520
                UrbanHorizontalSignageData data = config.getValues(feature);
521
                calculateGeometries(geom, data);
522

  
523
                MultiPolygon multiGeom = data.getSegmentsGeometry();
524
                MultiLine multiLine = data.getLineSegmentsGeometry();
525
                insertPolygonsOfLine(multiGeom, multiLine, targetStore, feature, config, config.getSegmentsColorFieldName());
526

  
527
                switch (data.getContinuity()) {
528
                    case CONTINUITY_MODE_CONT_DISC:
529
                    case CONTINUITY_MODE_DISC_CONT:
530
                    case CONTINUITY_MODE_DISC:
531
                    case CONTINUITY_MODE_DISC_DISC:
532
                        if (data.isPaintHoles()) {
533
                            multiGeom = data.getHolesGeometry();
534
                            multiLine = data.getLineHolesGeometry();
535
                            insertPolygonsOfLine(multiGeom, multiLine, targetStore, feature, config, config.getHolesColorFieldName());
536
                        }
537
                }
538
            }
539
            if (needFinishEditing) {
540
                targetStore.finishEditing();
541
            }
542

  
543
        } catch (Exception ex) {
544
            FeatureStore.cancelEditingQuietly(targetStore);
545
            throw new RuntimeException("Can't convert lines to polygons\n"+ex.getLocalizedMessage(), ex);
546
        }
547
        if (deleteSourceAtFinish) {
548
            FeatureStore sourceStore = null;
549
            try {
550
                sourceStore = source.getFeatureStore();
551
                needFinishEditing = !(sourceStore.isEditing() || sourceStore.isAppending());
552
                if (needFinishEditing) {
553
                    sourceStore.edit();
554
                }
555
                for (Feature feature : source) {
556
                    source.delete(feature);
557
                }
558
                if (needFinishEditing) {
559
                    sourceStore.finishEditing();
560
                }
561
            } catch (Exception ex) {
562
                FeatureStore.cancelEditingQuietly(sourceStore);
563
                throw new RuntimeException("Can't delete source lines", ex);
564
            }
565
        }
566
    }
567
    
568
}
org.gvsig.legend.urbanhorizontalsignage/tags/org.gvsig.legend.urbanhorizontalsignage-1.0.96/org.gvsig.legend.urbanhorizontalsignage.lib/org.gvsig.legend.urbanhorizontalsignage.lib.impl/src/main/java/org/gvsig/legend/urbanhorizontalsignage/lib/impl/UrbanHorizontalSignageLibraryImpl.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2015 gvSIG Association
5
 *
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
 * as published by the Free Software Foundation; either version 2
9
 * 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
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.legend.urbanhorizontalsignage.lib.impl;
26

  
27
import org.gvsig.legend.urbanhorizontalsignage.lib.impl.linelegend.DefaultUrbanHorizontalSignageLegend;
28
import org.gvsig.legend.urbanhorizontalsignage.lib.impl.linelegend.UrbanHorizontalSignageSymbol;
29
import org.gvsig.legend.urbanhorizontalsignage.lib.impl.linelegend.DefaultUrbanHorizontalSignageConfig;
30
import java.io.InputStream;
31
import java.util.Map;
32
import org.gvsig.fmap.mapcontext.MapContextLibrary;
33
import org.gvsig.fmap.mapcontext.MapContextLocator;
34
import org.gvsig.fmap.mapcontext.MapContextManager;
35
import org.gvsig.legend.urbanhorizontalsignage.lib.api.UrbanHorizontalSignageLibrary;
36
import org.gvsig.legend.urbanhorizontalsignage.lib.api.UrbanHorizontalSignageLocator;
37
import org.gvsig.symbology.impl.SymbologyDefaultImplLibrary;
38
import org.gvsig.tools.ToolsLocator;
39
import org.gvsig.tools.dynobject.DynStruct;
40
import org.gvsig.tools.library.AbstractLibrary;
41
import org.gvsig.tools.library.LibraryException;
42
import org.gvsig.tools.persistence.PersistenceManager;
43

  
44
public class UrbanHorizontalSignageLibraryImpl extends AbstractLibrary {
45

  
46
    @Override
47
    public void doRegistration() {
48
        registerAsImplementationOf(UrbanHorizontalSignageLibrary.class);
49
        this.require(MapContextLibrary.class);
50
        this.require(SymbologyDefaultImplLibrary.class);
51
    }
52

  
53
    @Override
54
    protected void doInitialize() throws LibraryException {
55
        UrbanHorizontalSignageLocator.registerUrbanHorizontalSignageManager(DefaultUrbanHorizontalSignageManager.class);
56
        MapContextManager mcmanager = MapContextLocator.getMapContextManager();
57
        mcmanager.registerLegend("UrbanHorizontalSignageLegend", DefaultUrbanHorizontalSignageLegend.class);
58
    }
59

  
60
    @Override
61
    protected void doPostInitialize() throws LibraryException {
62
        PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager();
63
        InputStream is = this.getClass().getResourceAsStream("UrbanHorizontalSignagePersistence.xml");
64
        Map<String,DynStruct> definitions;
65
        try {
66
            definitions = ToolsLocator.getDynObjectManager().importDynClassDefinitions(is, this.getClass().getClassLoader());
67
        } catch (Exception ex) {
68
            throw new LibraryException(this.getClass(), ex);
69
        }
70
        
71
        persistenceManager.addDefinition(
72
                DefaultUrbanHorizontalSignageLegend.class,
73
                "DefaultUrbanHorizontalSignageLegend",
74
                definitions,
75
                null,
76
                null);
77
        persistenceManager.addDefinition(
78
                UrbanHorizontalSignageSymbol.class,
79
                "UrbanHorizontalSignageSymbol",
80
                definitions,
81
                null,
82
                null
83
        );
84
        persistenceManager.addDefinition(
85
                DefaultUrbanHorizontalSignageConfig.class,
86
                "DefaultUrbanHorizontalSignageConfig",
87
                definitions,
88
                null,
89
                null
90
        );
91
    }
92

  
93
}
org.gvsig.legend.urbanhorizontalsignage/tags/org.gvsig.legend.urbanhorizontalsignage-1.0.96/org.gvsig.legend.urbanhorizontalsignage.lib/org.gvsig.legend.urbanhorizontalsignage.lib.impl/src/main/java/org/gvsig/legend/urbanhorizontalsignage/lib/impl/linelegend/DefaultUrbanHorizontalSignageConfig.java
1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
package org.gvsig.legend.urbanhorizontalsignage.lib.impl.linelegend;
7

  
8
import java.awt.Color;
9
import org.gvsig.fmap.dal.feature.Feature;
10
import org.gvsig.fmap.dal.feature.FeatureType;
11
import org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageConfig;
12
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageConfig.DEFAULT_GAP_WIDTH_VALUE;
13
import org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData;
14
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.DEFAULT_CONTINUITY_VALUE;
15
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.DEFAULT_HOLES_COLOR_VALUE;
16
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.DEFAULT_HOLES_LENGTH_VALUE;
17
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.DEFAULT_PAINT_HOLES_VALUE;
18
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.DEFAULT_ROUND_VERTEX_VALUE;
19
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.DEFAULT_SEGMENT_COLOR_VALUE;
20
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.DEFAULT_SEGMENT_LENGTH_VALUE;
21
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.DEFAULT_WIDTH_VALUE;
22
import org.gvsig.tools.ToolsLocator;
23
import org.gvsig.tools.dataTypes.DataTypesManager;
24
import org.gvsig.tools.persistence.PersistentState;
25
import org.gvsig.tools.persistence.exception.PersistenceException;
26
import org.gvsig.tools.swing.api.DataTypes;
27
import org.slf4j.Logger;
28
import org.slf4j.LoggerFactory;
29

  
30
/**
31
 *
32
 * @author fdiaz
33
 */
34
public class DefaultUrbanHorizontalSignageConfig implements UrbanHorizontalSignageConfig {
35

  
36
    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultUrbanHorizontalSignageConfig.class);
37

  
38
    private String widthFieldName;
39
    private String continuityFieldName;
40
    private String holesLengthFieldName;
41
    private String holesColorFieldName;
42
    private String paintHolesFieldName;
43
    private String segmentsLengthFieldName;
44
    private String segmentsColorFieldName;
45
    private String roundVertexFieldName;
46
    private int gapWidth;
47
    private String targetColorFieldName;
48
    private String targetLenghtFieldName;
49
    private String targetAreaFieldName;
50
    
51
    public DefaultUrbanHorizontalSignageConfig() {
52
        this.gapWidth = DEFAULT_GAP_WIDTH_VALUE;
53
    }
54

  
55
    @Override
56
    public void loadFromState(PersistentState state) throws PersistenceException {
57

  
58
        this.widthFieldName = state.getString("widthFieldName");
59
        this.continuityFieldName = state.getString("continuityFieldName");
60
        this.holesLengthFieldName = state.getString("holesLengthFieldName");
61
        this.holesColorFieldName = state.getString("holesColorFieldName");
62
        this.paintHolesFieldName = state.getString("paintHolesFieldName");
63
        this.segmentsLengthFieldName = state.getString("segmentsLengthFieldName");
64
        this.segmentsColorFieldName = state.getString("segmentsColorFieldName");
65
        this.roundVertexFieldName = state.getString("roundVertexFieldName");
66
        this.gapWidth = state.getInt("gapWidth", DEFAULT_GAP_WIDTH_VALUE);
67
    }
68

  
69
    @Override
70
    public void saveToState(PersistentState state) throws PersistenceException {
71
        state.set("widthFieldName", this.widthFieldName);
72
        state.set("continuityFieldName", this.continuityFieldName);
73
        state.set("holesLengthFieldName", this.holesLengthFieldName);
74
        state.set("holesColorFieldName", this.holesColorFieldName);
75
        state.set("paintHolesFieldName", this.paintHolesFieldName);
76
        state.set("segmentsLengthFieldName", this.segmentsLengthFieldName);
77
        state.set("segmentsColorFieldName", this.segmentsColorFieldName);
78
        state.set("roundVertexFieldName", this.roundVertexFieldName);
79
        state.set("gapWidth", this.gapWidth);
80
    }
81

  
82
    @Override
83
    public String getWidthFieldName() {
84
        return this.widthFieldName;
85
    }
86

  
87
    @Override
88
    public void setWidthFieldName(String fieldName) {
89
        this.widthFieldName = fieldName;
90
    }
91

  
92
    @Override
93
    public String getContinuityFieldName() {
94
        return this.continuityFieldName;
95
    }
96

  
97
    @Override
98
    public void setContinuityFieldName(String fieldName) {
99
        this.continuityFieldName = fieldName;
100
    }
101

  
102
    @Override
103
    public String getSegmentsColorFieldName() {
104
        return this.segmentsColorFieldName;
105
    }
106

  
107
    @Override
108
    public void setSegmentsColorFieldName(String fieldName) {
109
        this.segmentsColorFieldName = fieldName;
110
    }
111

  
112
    @Override
113
    public String getSegmentsLengthFieldName() {
114
        return this.segmentsLengthFieldName;
115
    }
116

  
117
    @Override
118
    public void setSegmentsLengthFieldName(String fieldName) {
119
        this.segmentsLengthFieldName = fieldName;
120
    }
121

  
122
    @Override
123
    public String getPaintHolesFieldName() {
124
        return this.paintHolesFieldName;
125
    }
126

  
127
    @Override
128
    public void setPaintHolesFieldName(String fieldName) {
129
        this.paintHolesFieldName = fieldName;
130
    }
131

  
132
    @Override
133
    public String getHolesColorFieldName() {
134
        return this.holesColorFieldName;
135
    }
136

  
137
    @Override
138
    public void setHolesColorFieldName(String fieldName) {
139
        this.holesColorFieldName = fieldName;
140
    }
141

  
142
    @Override
143
    public String getHolesLengthFieldName() {
144
        return this.holesLengthFieldName;
145
    }
146

  
147
    @Override
148
    public void setHolesLengthFieldName(String fieldName) {
149
        this.holesLengthFieldName = fieldName;
150
    }
151
    
152
    @Override
153
    public String getRoundVertexFieldName() {
154
        return this.roundVertexFieldName;
155
    }
156

  
157
    @Override
158
    public void setRoundVertexFieldName(String fieldName) {
159
        this.roundVertexFieldName = fieldName;
160
    }
161
    
162
    @Override
163
    public int getGapWidth() {
164
        return this.gapWidth;
165
    }
166

  
167
    @Override
168
    public void setGapWith(int value) {
169
        this.gapWidth = value;
170
    }
171

  
172
    @Override
173
    public UrbanHorizontalSignageData getValues(Feature feature) {
174
        UrbanHorizontalSignageData data = new DefaultUrbanHorizontalSignageData();
175
        DataTypesManager manager = ToolsLocator.getDataTypesManager();
176
        FeatureType ftype = feature.getType();
177
        double valueDouble = feature.getIntOrDefault( this.widthFieldName, (int)DEFAULT_WIDTH_VALUE*100 )/100.0;
178
        data.setWidth(valueDouble);
179
        int valueInt = feature.getIntOrDefault( this.continuityFieldName, DEFAULT_CONTINUITY_VALUE );
180
        data.setContinuity(valueInt);
181
        Color valueColor = (Color)feature.getOrDefault( this.segmentsColorFieldName, DataTypes.COLOR, DEFAULT_SEGMENT_COLOR_VALUE );
182
        data.setSegmentsColor(valueColor);
183
        valueDouble = feature.getIntOrDefault( this.segmentsLengthFieldName, (int)DEFAULT_SEGMENT_LENGTH_VALUE*100 )/100.0;
184
        data.setSegmentsLength(valueDouble);
185
        valueDouble = feature.getIntOrDefault( this.holesLengthFieldName, (int)DEFAULT_HOLES_LENGTH_VALUE*100 )/100.0;
186
        data.setHolesLength(valueDouble);
187
        boolean valueBoolean = feature.getBooleanOrDefault( this.paintHolesFieldName, DEFAULT_PAINT_HOLES_VALUE );
188
        data.setPaintHoles(valueBoolean);
189
        valueColor = (Color) feature.getOrDefault( this.holesColorFieldName, DataTypes.COLOR, DEFAULT_HOLES_COLOR_VALUE );
190
        data.setHolesColor(valueColor);
191
        valueBoolean = feature.getBooleanOrDefault( this.roundVertexFieldName, DEFAULT_ROUND_VERTEX_VALUE );
192
        data.setRoundVertex(valueBoolean);
193

  
194
        data.setGapWidth(this.getGapWidth()/100.0);
195
        
196
        return data;
197
    }
198

  
199
    @Override
200
    public String getTargetColorFieldName() {
201
        return this.targetColorFieldName;
202
    }
203

  
204
    @Override
205
    public void setTargetColorFieldName(String fieldName) {
206
        this.targetColorFieldName = fieldName;
207
    }
208

  
209
    @Override
210
    public String getTargetLenghtFieldName() {
211
        return this.targetLenghtFieldName;
212
    }
213

  
214
    @Override
215
    public void setTargetLenghtFieldName(String fieldName) {
216
        this.targetLenghtFieldName = fieldName;
217
    }
218

  
219
    @Override
220
    public String getTargetAreaFieldName() {
221
        return this.targetAreaFieldName;
222
    }
223

  
224
    @Override
225
    public void setTargetAreaFieldName(String fieldName) {
226
        this.targetAreaFieldName = fieldName;
227
    }
228

  
229
    @Override
230
    public UrbanHorizontalSignageConfig clone() throws CloneNotSupportedException {
231
        return (UrbanHorizontalSignageConfig) super.clone(); 
232
    }
233

  
234
}
org.gvsig.legend.urbanhorizontalsignage/tags/org.gvsig.legend.urbanhorizontalsignage-1.0.96/org.gvsig.legend.urbanhorizontalsignage.lib/org.gvsig.legend.urbanhorizontalsignage.lib.impl/src/main/java/org/gvsig/legend/urbanhorizontalsignage/lib/impl/linelegend/DefaultUrbanHorizontalSignageData.java
1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
package org.gvsig.legend.urbanhorizontalsignage.lib.impl.linelegend;
7

  
8
import java.awt.Color;
9
import org.gvsig.fmap.geom.Geometry;
10
import org.gvsig.fmap.geom.aggregate.MultiLine;
11
import org.gvsig.fmap.geom.aggregate.MultiPolygon;
12
import org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData;
13

  
14
/**
15
 *
16
 * @author fdiaz
17
 */
18
public class DefaultUrbanHorizontalSignageData implements UrbanHorizontalSignageData {
19
    
20
    private double width;
21
    private int continuity;
22
    private Color segmentsColor;
23
    private double segmentsLength;
24
    private MultiPolygon segmentsGeometry;
25
    private boolean isPaintHoles;
26
    private Color holesColor;
27
    private double holesLength;
28
    private MultiPolygon holesGeometry;
29
    private double gapWidth;
30
    private Geometry originalGeometry;
31
    private boolean roundVertex;
32
    private MultiLine lineSegmentsGeometry;
33
    private MultiLine lineHolesGeometry;
34

  
35
    public DefaultUrbanHorizontalSignageData() {
36
        width = DEFAULT_WIDTH_VALUE;
37
        continuity = DEFAULT_CONTINUITY_VALUE;
38
        segmentsColor = DEFAULT_SEGMENT_COLOR_VALUE;
39
        segmentsLength = DEFAULT_SEGMENT_LENGTH_VALUE;
40
        isPaintHoles = DEFAULT_PAINT_HOLES_VALUE;
41
        holesColor = DEFAULT_HOLES_COLOR_VALUE;
42
        holesLength = DEFAULT_HOLES_LENGTH_VALUE;
43
        gapWidth = DEFAULT_GAP_WIDTH_VALUE;
44
        roundVertex = DEFAULT_ROUND_VERTEX_VALUE;
45
    }
46

  
47
    @Override
48
    public double getWidth() {
49
        return this.width;
50
    }
51

  
52
    @Override
53
    public void setWidth(double value) {
54
        this.width = value;
55
    }
56

  
57
    @Override
58
    public int getContinuity() {
59
        return this.continuity;
60
    }
61

  
62
    @Override
63
    public void setContinuity(int value) {
64
        this.continuity = value;
65
    }
66

  
67
    @Override
68
    public Color getSegmentsColor() {
69
        return this.segmentsColor;
70
    }
71

  
72
    @Override
73
    public void setSegmentsColor(Color value) {
74
        this.segmentsColor = value;
75
    }
76

  
77
    @Override
78
    public double getSegmentsLength() {
79
        return this.segmentsLength;
80
    }
81

  
82
    @Override
83
    public void setSegmentsLength(double value) {
84
        this.segmentsLength = value;
85
    }
86

  
87
    @Override
88
    public MultiPolygon getSegmentsGeometry() {
89
        return this.segmentsGeometry;
90
    }
91

  
92
    @Override
93
    public void setSegmentsGeometry(MultiPolygon value) {
94
        this.segmentsGeometry = value;
95
    }
96

  
97
    @Override
98
    public boolean isPaintHoles() {
99
        return this.isPaintHoles;
100
    }
101

  
102
    @Override
103
    public void setPaintHoles(boolean value) {
104
        this.isPaintHoles = value;
105
    }
106

  
107
    @Override
108
    public Color getHolesColor() {
109
        return this.holesColor;
110
    }
111

  
112
    @Override
113
    public void setHolesColor(Color value) {
114
        this.holesColor = value;
115
    }
116

  
117
    @Override
118
    public double getHolesLength() {
119
        return this.holesLength;
120
    }
121

  
122
    @Override
123
    public void setHolesLength(double value) {
124
        this.holesLength = value;
125
    }
126

  
127
    @Override
128
    public MultiPolygon getHolesGeometry() {
129
        return this.holesGeometry;
130
    }
131

  
132
    @Override
133
    public void setHolesGeometry(MultiPolygon value) {
134
        this.holesGeometry = value;
135
    }
136

  
137
    @Override
138
    public double getGapWidth() {
139
        return this.gapWidth;
140
    }
141

  
142
    @Override
143
    public void setGapWidth(double value) {
144
        this.gapWidth = value;
145
    }
146
    
147
    public boolean isRoundVertex(){
148
        return this.roundVertex;
149
    }
150

  
151
    public void setRoundVertex(boolean value){
152
        this.roundVertex = value;
153
    }
154

  
155
    @Override
156
    public MultiLine getLineSegmentsGeometry() {
157
        return this.lineSegmentsGeometry;
158
    }
159

  
160
    @Override
161
    public void setLineSegmentsGeometry(MultiLine value) {
162
        this.lineSegmentsGeometry = value;
163
    }
164

  
165
    @Override
166
    public MultiLine getLineHolesGeometry() {
167
        return this.lineHolesGeometry;
168
    }
169

  
170
    @Override
171
    public void setLineHolesGeometry(MultiLine value) {
172
        this.lineHolesGeometry = value;
173
    }
174
}
org.gvsig.legend.urbanhorizontalsignage/tags/org.gvsig.legend.urbanhorizontalsignage-1.0.96/org.gvsig.legend.urbanhorizontalsignage.lib/org.gvsig.legend.urbanhorizontalsignage.lib.impl/src/main/java/org/gvsig/legend/urbanhorizontalsignage/lib/impl/linelegend/SplittedLine.java
1
package org.gvsig.legend.urbanhorizontalsignage.lib.impl.linelegend;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5
import org.gvsig.fmap.geom.primitive.Line;
6

  
7
/**
8
 *
9
 * @author gvSIG Team
10
 */
11
public class SplittedLine {
12
    
13
    List<Line> segments;
14
    List<Line> holes;
15

  
16
    public SplittedLine() {
17
        segments = new ArrayList<>();
18
        holes = new ArrayList<>();
19
    }
20

  
21
    public List<Line> getSegments() {
22
        return this.segments;
23
    }
24

  
25
    public List<Line> getHoles() {
26
        return this.holes;
27
    }
28

  
29
    public void addSegment(Line segment) {
30
        this.segments.add(segment);
31
    }
32

  
33
    public void addHole(Line hole) {
34
        this.holes.add(hole);
35
    }
36
    
37
}
org.gvsig.legend.urbanhorizontalsignage/tags/org.gvsig.legend.urbanhorizontalsignage-1.0.96/org.gvsig.legend.urbanhorizontalsignage.lib/org.gvsig.legend.urbanhorizontalsignage.lib.impl/src/main/java/org/gvsig/legend/urbanhorizontalsignage/lib/impl/linelegend/DefaultUrbanHorizontalSignageLegend.java
1
package org.gvsig.legend.urbanhorizontalsignage.lib.impl.linelegend;
2

  
3
import java.awt.Image;
4
import java.util.ArrayList;
5
import java.util.List;
6
import org.apache.commons.lang3.StringUtils;
7
import org.gvsig.fmap.dal.exception.DataException;
8
import org.gvsig.fmap.dal.feature.Feature;
9
import org.gvsig.fmap.dal.feature.FeatureStore;
10
import org.gvsig.fmap.geom.Geometry;
11
import org.gvsig.fmap.geom.GeometryUtils;
12
import org.gvsig.fmap.mapcontext.MapContextException;
13
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
14
import org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageConfig;
15
import org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData;
16
import org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageLegend;
17
import org.gvsig.symbology.SymbologyLocator;
18
import org.gvsig.symbology.SymbologyManager;
19
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractVectorialLegend;
20
import org.gvsig.tools.persistence.PersistentState;
21
import org.gvsig.tools.persistence.exception.PersistenceException;
22
import org.slf4j.Logger;
23
import org.slf4j.LoggerFactory;
24

  
25
public class DefaultUrbanHorizontalSignageLegend 
26
        extends AbstractVectorialLegend 
27
        implements UrbanHorizontalSignageLegend //, IHasImageLegend 
28
{
29
    
30
    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultUrbanHorizontalSignageLegend.class);
31

  
32
    private final UrbanHorizontalSignageSymbol defaultSymbol;
33
    
34
    private UrbanHorizontalSignageConfig config;
35
    
36
    private Image imageLegend;
37
    
38
    public DefaultUrbanHorizontalSignageLegend() {
39
        
40
        SymbologyManager symbologyManager = SymbologyLocator.getSymbologyManager();
41
        this.defaultSymbol = new UrbanHorizontalSignageSymbol();
42
        DefaultUrbanHorizontalSignageData data = new DefaultUrbanHorizontalSignageData();
43
        data.setContinuity(UrbanHorizontalSignageData.CONTINUITY_MODE_DISC_CONT);
44
        this.defaultSymbol.setData(new DefaultUrbanHorizontalSignageData());
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff