# HG changeset patch # User Felix Wolfsteller # Date 1323767448 0 # Node ID b30e1710df1d62f8f27db1c745b3cb9ebc61001a # Parent cdeb31ef20a1cc01e5d8f448fe16b240bfb60b90 Server-side of interactive cross-section diagrams. flys-artifacts/trunk@3394 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r cdeb31ef20a1 -r b30e1710df1d flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Tue Dec 13 08:56:52 2011 +0000 +++ b/flys-artifacts/ChangeLog Tue Dec 13 09:10:48 2011 +0000 @@ -1,3 +1,23 @@ +2011-12-13 Felix Wolfsteller + + Server-side of newer Cross-Section diagram construction architecture. + + * src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java + (searchCrossSectionKmLine, getCrossSectionSnapKm), + (getCrossSectionData): Removed, most functionality contained in + CrossSectionArtifact. + (getWaterLines): Now get CrossSectionLines to calculate water line. + + * src/main/java/de/intevation/flys/artifacts/model/CrossSectionWaterLineFacet.java: + Get a CrossSectionLine from blackboard. + + * src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java: + Hard TODO, commented out function needed for subtitle to allow + compilation. + + * src/main/java/de/intevation/flys/exports/StyledSeriesBuilder.java: + Added Empty-Dataset- guard. + 2011-12-13 Felix Wolfsteller Cosmetics. diff -r cdeb31ef20a1 -r b30e1710df1d flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Tue Dec 13 08:56:52 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Tue Dec 13 09:10:48 2011 +0000 @@ -672,96 +672,14 @@ /** - * Get CrossSectionLine spatially closest to what is specified in the data - * "cross_section.km" (and from "cross_section.index"). - * - * @return CrossSectionLine closest to "cross_section.km". - */ - protected CrossSectionLine searchCrossSectionKmLine() { - double wishKM = 0.0f; - try { - wishKM = Double.parseDouble(getDataAsString("cross_section.km")); - } - catch (Exception e) { - logger.warn("Exception when parsing cross_section.km", e); - } - - int crossSectionIdx = 0; - - List sections = getCrossSections(); - if (sections.size() < crossSectionIdx) { - logger.error("Cross-section not found: " + crossSectionIdx); - return null; - } - if (sections.size() == 0 - || sections.get(crossSectionIdx).getLines().size() == 0) - { - return null; - } - - // Get the cross section closest to requested km. - // Naive, linear approach. - List crossSectionLines = - sections.get(crossSectionIdx).getLines(); - CrossSectionLine oldLine = crossSectionLines.get(0); - double oldDiff = Math.abs(wishKM - oldLine.getKm().doubleValue()); - for (CrossSectionLine line: crossSectionLines) { - double diff = Math.abs(wishKM - line.getKm().doubleValue()); - if (diff > oldDiff) { - break; - } - oldDiff = diff; - oldLine = line; - } - return oldLine; - } - - - /** - * Get km for which a CrossSection is actually available (this may vary - * from the user picked "cross_section.km" data). - * - * @return km for which cross section is calculated. - */ - public double getCrossSectionSnapKm() { - // Note that this is this triggers a linear search. - CrossSectionLine line = searchCrossSectionKmLine(); - if (line == null) { - logger.warn("No Cross Section for given km found."); - return 0.0f; - } - else { - return line.getKm().doubleValue(); - } - } - - - /** - * Get points of Profile of cross section. - * - * @return an array holding coordinates of points of profile ( - * in the form {{x1, x2} {y1, y2}} ). - */ - public double [][] getCrossSectionData() { - logger.info("getCrossSectionData() for cross_section.km " - + getDataAsString("cross_section.km")); - CrossSectionLine line = searchCrossSectionKmLine(); - - return line != null - ? line.fetchCrossSectionProfile() - : null; - } - - - /** * 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) { - logger.debug("getWaterLines()"); - CrossSectionLine csl = searchCrossSectionKmLine(); + public double [][] getWaterLines(int idx, CrossSectionLine csl) { + logger.debug("getWaterLines(" + idx + ")"); + List points = csl.fetchCrossSectionLinesPoints(); // Need W at km @@ -780,14 +698,8 @@ WQKms triple = wqkms[idx]; // Find index of km. - double wishKM = 0.0f; + double wishKM = csl.getKm().doubleValue(); int old_idx = 0; - try { - wishKM = Double.parseDouble(getDataAsString("cross_section.km")); - } - catch (Exception e) { - logger.warn("Exception when trying to get cross_section.km", e); - } if (triple.size() == 0) { logger.warn("Calculation of waterline is empty."); @@ -815,6 +727,7 @@ * @return list of names of cross-sections. */ public List getCrossSectionNames() { + logger.debug("getCrossSectionNames"); List names = new ArrayList(); for (CrossSection section: getCrossSections()) { diff -r cdeb31ef20a1 -r b30e1710df1d flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionWaterLineFacet.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionWaterLineFacet.java Tue Dec 13 08:56:52 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionWaterLineFacet.java Tue Dec 13 09:10:48 2011 +0000 @@ -2,11 +2,16 @@ import org.apache.log4j.Logger; +import java.util.List; + +import de.intevation.flys.model.CrossSectionLine; + import de.intevation.artifacts.Artifact; import de.intevation.artifacts.CallContext; import de.intevation.artifactdatabase.state.DefaultFacet; import de.intevation.artifactdatabase.state.Facet; +import de.intevation.artifacts.DataProvider; import de.intevation.flys.artifacts.WINFOArtifact; @@ -28,24 +33,35 @@ /** - * Gets dummy data. + * Gets waterline (crossed with cross section) of waterlevel. */ public Object getData(Artifact artifact, CallContext context) { logger.debug("Get data for cross section water line"); + List providers = context. + getDataProvider(CrossSectionFacet.BLACKBOARD_CS_MASTER_DATA); + if (providers.size() < 1) { + logger.warn("Could not find Cross-Section data provider."); + return new double[][] {}; + } + + Object crossSection = providers.get(0) + .provideData(CrossSectionFacet.BLACKBOARD_CS_MASTER_DATA, null, context); + WINFOArtifact winfo = (WINFOArtifact)artifact; - return winfo.getWaterLines(this.getIndex()); + return winfo.getWaterLines(this.getIndex(), (CrossSectionLine) crossSection); } /** Do a deep copy. */ @Override public Facet deepCopy() { - CrossSectionWaterLineFacet copy = new CrossSectionWaterLineFacet(this.getIndex(), this.description); + CrossSectionWaterLineFacet copy = new CrossSectionWaterLineFacet( + this.getIndex(), + this.description); copy.set(this); return copy; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : - diff -r cdeb31ef20a1 -r b30e1710df1d flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java Tue Dec 13 08:56:52 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java Tue Dec 13 09:10:48 2011 +0000 @@ -92,7 +92,9 @@ protected Double getKm() { try { WINFOArtifact winfo = (WINFOArtifact) master; - return winfo.getCrossSectionSnapKm(); + // TODO get km of "master cross section." + //return winfo.getCrossSectionSnapKm(0); + return 0.0d; } catch (Exception e) { logger.error("Cannot convert cross_section.km to double"); diff -r cdeb31ef20a1 -r b30e1710df1d flys-artifacts/src/main/java/de/intevation/flys/exports/StyledSeriesBuilder.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/StyledSeriesBuilder.java Tue Dec 13 08:56:52 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/StyledSeriesBuilder.java Tue Dec 13 09:10:48 2011 +0000 @@ -30,6 +30,9 @@ * to 2nd dim. */ public static void addPoints(XYSeries series, double[][] points) { + if (points == null || points.length == 0) { + return; + } double [] xPoints = points[0]; double [] yPoints = points[1]; for (int i = 0; i < xPoints.length; i++) {