Mercurial > dive4elements > river
changeset 1981:bf62cc7052d4
Implement and use WaterLineArtifact interface.
flys-artifacts/trunk@3411 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 14 Dec 2011 10:44:00 +0000 |
parents | d377b89d2827 |
children | 8afd6a9bb244 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionWaterLineFacet.java |
diffstat | 4 files changed, 88 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Wed Dec 14 10:40:30 2011 +0000 +++ b/flys-artifacts/ChangeLog Wed Dec 14 10:44:00 2011 +0000 @@ -1,3 +1,18 @@ +2011-12-14 Felix Wolfsteller <felix.wolfsteller@intevation.de> + + Implement new WaterLineArtifact where needed so far. + + * src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java: + Declare that we implement WaterLineArtifact. + + * src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java: + (getWaterLines): Implement to fulfil new WaterLineArtifact- + interface-impl. Also generate new Facet. + + + * src/main/java/de/intevation/flys/artifacts/model/CrossSectionWaterLineFacet.java: + Do not depend on WINFOArtifacts, but on WaterLineArtifacts instead. + 2011-12-14 Felix Wolfsteller <felix.wolfsteller@intevation.de> Added interface WaterLineArtifact to be implemented by artifacts
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java Wed Dec 14 10:40:30 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java Wed Dec 14 10:44:00 2011 +0000 @@ -7,6 +7,8 @@ import org.w3c.dom.Document; +import java.awt.geom.Point2D; + import de.intevation.artifactdatabase.state.Facet; import de.intevation.artifactdatabase.state.DefaultOutput; import de.intevation.artifactdatabase.state.State; @@ -16,6 +18,7 @@ import de.intevation.artifacts.ArtifactNamespaceContext; import de.intevation.artifacts.CallMeta; +import de.intevation.flys.artifacts.model.CrossSectionWaterLineFacet; import de.intevation.flys.artifacts.model.FacetTypes; import de.intevation.flys.artifacts.model.WKms; import de.intevation.flys.artifacts.model.WKmsFacet; @@ -26,6 +29,9 @@ import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.flys.geom.Lines; +import de.intevation.flys.model.CrossSectionLine; + /** * Artifact to access additional "waterlevel"-type of data, like the height * of protective measures (dikes). @@ -35,7 +41,7 @@ */ public class StaticWKmsArtifact extends StaticFLYSArtifact -implements FacetTypes +implements FacetTypes, WaterLineArtifact { /** The logger for this class. */ private static Logger logger = @@ -86,13 +92,23 @@ String [] parts = code.split("-"); if (parts.length >= 4) { - int col = Integer.valueOf(parts[2]); + int col = -1; int wst = Integer.valueOf(parts[3]); + if (!parts[2].equals("A")) { + col = Integer.valueOf(parts[2]); + } + addStringData("col_pos", parts[2]); addStringData("wst_id", parts[3]); - String wkmsName = WKmsFactory.getWKmsName(col, wst); + String wkmsName; + if (col > 0) { + wkmsName = WKmsFactory.getWKmsName(col, wst); + } + else { + wkmsName = WKmsFactory.getWKmsName(wst); + } String name; if (parts[0].equals(HEIGHTMARKS_POINTS)) { @@ -102,13 +118,15 @@ name = STATIC_WKMS; } - Facet facet = new WKmsFacet( + String facetDescription = Resources.getMsg( + callMeta, wkmsName, wkmsName); + Facet wKmsFacet = new WKmsFacet( name, - Resources.getMsg( - callMeta, - wkmsName, - wkmsName)); - fs.add(facet); + facetDescription); + Facet csFacet = new CrossSectionWaterLineFacet(0, + facetDescription); + fs.add(wKmsFacet); + fs.add(csFacet); facets.put(state.getID(), fs); } } @@ -216,6 +234,49 @@ /** + * Returns W at Km of WKms, searching linearly. + * Returns -1 if not found. + */ + public double getWAtKm(WKms wkms, double km) { + // Uninformed search. + int size = wkms.size(); + for (int i = 0; i < size; i++) { + if (wkms.getKm(i) == km) { + return wkms.getW(i); + } + } + + return -1; + } + + + /** + * Get points of line describing the surface of water at cross section. + * + * @return an array holding coordinates of points of surface of water ( + * in the form {{x1, x2} {y1, y2}} ). + */ + public double [][] getWaterLines(int idx, CrossSectionLine csl) { + logger.debug("getWaterLines(" + idx + ")"); + + List<Point2D> points = csl.fetchCrossSectionLinesPoints(); + + WKms wkms = getWKms(0); + + double km = csl.getKm().doubleValue(); + + // Find W at km. + double wAtKm = getWAtKm(wkms, km); + if (wAtKm == -1) { + logger.warn("Waterlevel at km " + km + " unknown."); + return new double[][] {{}}; + } + + return Lines.createWaterLines(points, wAtKm); + } + + + /** * Determines Facets initial disposition regarding activity (think of * selection in Client ThemeList GUI). This will be checked one time * when the facet enters a collections describe document.
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Wed Dec 14 10:40:30 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Wed Dec 14 10:44:00 2011 +0000 @@ -75,7 +75,7 @@ */ public class WINFOArtifact extends FLYSArtifact -implements FacetTypes { +implements FacetTypes, WaterLineArtifact { /** The logger for this class. */ private static Logger logger = Logger.getLogger(WINFOArtifact.class);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionWaterLineFacet.java Wed Dec 14 10:40:30 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionWaterLineFacet.java Wed Dec 14 10:44:00 2011 +0000 @@ -13,7 +13,7 @@ import de.intevation.artifactdatabase.state.Facet; import de.intevation.artifacts.DataProvider; -import de.intevation.flys.artifacts.WINFOArtifact; +import de.intevation.flys.artifacts.WaterLineArtifact; /** @@ -48,7 +48,7 @@ Object crossSection = providers.get(0) .provideData(CrossSectionFacet.BLACKBOARD_CS_MASTER_DATA, null, context); - WINFOArtifact winfo = (WINFOArtifact)artifact; + WaterLineArtifact winfo = (WaterLineArtifact)artifact; return winfo.getWaterLines(this.getIndex(), (CrossSectionLine) crossSection); }