gvsig-projects-pool / org.gvsig.topology / trunk / org.gvsig.topology / org.gvsig.topology.lib / org.gvsig.topology.lib.impl / src / main / java / org / gvsig / topology / lib / impl / DefaultTopologyReport.java @ 760
History | View | Annotate | Download (6.36 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 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 3
|
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 |
package org.gvsig.topology.lib.impl; |
25 |
|
26 |
import java.util.ArrayList; |
27 |
import java.util.Collections; |
28 |
import java.util.List; |
29 |
import org.gvsig.expressionevaluator.Code; |
30 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
31 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
32 |
import org.gvsig.expressionevaluator.MutableSymbolTable; |
33 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
34 |
import org.gvsig.fmap.geom.Geometry; |
35 |
import org.gvsig.tools.task.SimpleTaskStatus; |
36 |
import org.gvsig.topology.lib.api.TopologyDataSet; |
37 |
import org.gvsig.topology.lib.api.TopologyPlan; |
38 |
import org.gvsig.topology.lib.api.TopologyReport; |
39 |
import org.gvsig.topology.lib.api.TopologyReportLine; |
40 |
import org.gvsig.topology.lib.api.TopologyReportLineSet; |
41 |
import org.gvsig.topology.lib.api.TopologyRule; |
42 |
import org.slf4j.Logger; |
43 |
import org.slf4j.LoggerFactory; |
44 |
|
45 |
/**
|
46 |
*
|
47 |
* @author jjdelcerro
|
48 |
*/
|
49 |
@SuppressWarnings("UseSpecificCatch") |
50 |
public class DefaultTopologyReport |
51 |
extends AbstractTopologyReportLineSet
|
52 |
implements TopologyReport
|
53 |
{ |
54 |
|
55 |
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultTopologyReport.class); |
56 |
|
57 |
private class DefaultTopologyReportLineSet extends AbstractTopologyReportLineSet { |
58 |
|
59 |
public DefaultTopologyReportLineSet() {
|
60 |
super();
|
61 |
} |
62 |
|
63 |
public void polulate(List<TopologyReportLine> allLines, String filter) { |
64 |
this.lines.clear();
|
65 |
if (filter == null) { |
66 |
this.lines.addAll(allLines);
|
67 |
this.completed = true; |
68 |
return;
|
69 |
} |
70 |
SimpleTaskStatus theTaskStatus = plan.getTaskStatus(); |
71 |
try {
|
72 |
theTaskStatus.push(); |
73 |
theTaskStatus.restart(); |
74 |
theTaskStatus.message("Preparing filter");
|
75 |
theTaskStatus.setAutoremove(true);
|
76 |
theTaskStatus.setIndeterminate(); |
77 |
|
78 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
79 |
|
80 |
TopologyReportLineSymbolTable lineSymbolTable = new TopologyReportLineSymbolTable();
|
81 |
MutableSymbolTable symbolTable = manager.createSymbolTable(); |
82 |
symbolTable.addSymbolTable(lineSymbolTable); |
83 |
|
84 |
Code code = manager.compile(filter); |
85 |
code = manager.optimize(symbolTable, code); |
86 |
|
87 |
theTaskStatus.setRangeOfValues(0, allLines.size());
|
88 |
theTaskStatus.setCurValue(0);
|
89 |
for (TopologyReportLine line : allLines) {
|
90 |
lineSymbolTable.setLine(line); |
91 |
Object value = manager.evaluate(symbolTable, code);
|
92 |
if (value instanceof Boolean && ((Boolean) value)) { |
93 |
this.lines.add(line);
|
94 |
this.changeListenerHelper.fireEvent();
|
95 |
} |
96 |
theTaskStatus.incrementCurrentValue(); |
97 |
} |
98 |
|
99 |
} catch (Exception ex) { |
100 |
LOGGER.warn("Problems filtering.", ex);
|
101 |
theTaskStatus.abort(); |
102 |
} finally {
|
103 |
if (theTaskStatus.isRunning()) {
|
104 |
theTaskStatus.terminate(); |
105 |
} |
106 |
theTaskStatus.pop(); |
107 |
this.completed = true; |
108 |
} |
109 |
} |
110 |
|
111 |
|
112 |
} |
113 |
|
114 |
// TODO: Habria que meter las lineas del report en disco
|
115 |
private final TopologyPlan plan; |
116 |
|
117 |
public DefaultTopologyReport(TopologyPlan plan) {
|
118 |
this.plan = plan;
|
119 |
} |
120 |
|
121 |
@Override
|
122 |
public TopologyReportLine addLine(TopologyRule rule, TopologyDataSet dataSet1,
|
123 |
TopologyDataSet dataSet2, Geometry geometry, Geometry error, |
124 |
FeatureReference feature1, FeatureReference feature2, |
125 |
boolean exception, String description |
126 |
) { |
127 |
TopologyReportLine line = new DefaultTopologyReportLine(
|
128 |
this, rule, dataSet1, dataSet2, geometry, error, feature1,
|
129 |
feature2, exception, description |
130 |
); |
131 |
this.lines.add(line);
|
132 |
this.fireChangeEvent();
|
133 |
return line;
|
134 |
} |
135 |
|
136 |
@Override
|
137 |
public void removeAllLines() { |
138 |
this.lines.clear();
|
139 |
this.fireChangeEvent();
|
140 |
} |
141 |
|
142 |
@Override
|
143 |
public TopologyReportLineSet getLineSet(final String filter) { |
144 |
final DefaultTopologyReportLineSet set = new DefaultTopologyReportLineSet(); |
145 |
Thread th = new Thread(new Runnable() { |
146 |
@Override
|
147 |
public void run() { |
148 |
set.polulate(lines, filter); |
149 |
} |
150 |
}); |
151 |
th.start(); |
152 |
return set;
|
153 |
} |
154 |
|
155 |
@Override
|
156 |
public List<TopologyReportLine> getLines(String filter) { |
157 |
if (filter == null) { |
158 |
return Collections.unmodifiableList(this.lines); |
159 |
} |
160 |
List<TopologyReportLine> ll = new ArrayList<>(); |
161 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
162 |
|
163 |
TopologyReportLineSymbolTable lineSymbolTable = new TopologyReportLineSymbolTable();
|
164 |
MutableSymbolTable symbolTable = manager.createSymbolTable(); |
165 |
symbolTable.addSymbolTable(lineSymbolTable); |
166 |
|
167 |
Code code = manager.compile(filter); |
168 |
code = manager.optimize(symbolTable, code); |
169 |
|
170 |
for (TopologyReportLine line : this.lines) { |
171 |
lineSymbolTable.setLine(line); |
172 |
Object value = manager.evaluate(symbolTable, code);
|
173 |
if (value instanceof Boolean && ((Boolean) value)) { |
174 |
ll.add(line); |
175 |
} |
176 |
} |
177 |
return Collections.unmodifiableList(ll); |
178 |
} |
179 |
} |