# HG changeset patch # User Felix Wolfsteller # Date 1320150239 0 # Node ID 51e59f221333df8a8786f9b66af3ab51eec755ed # Parent 26d7077e42d2b5583d0c8afcfdfbfa624297e4d2 Minor preparations for WINFO/CrossSection to handle multiple cross-sections. flys-artifacts/trunk@3128 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 26d7077e42d2 -r 51e59f221333 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Tue Nov 01 10:40:05 2011 +0000 +++ b/flys-artifacts/ChangeLog Tue Nov 01 12:23:59 2011 +0000 @@ -1,3 +1,23 @@ +2011-11-01 Felix Wolfsteller + + Minor preparations to handle multiple cross sections in one + diagram/artifact, faking certain aspects (e.g. ability to display + multiple cross sections, but let these fetch the exactly same data + for now). + + * src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java: + Parameterize but fake access to cross-section (always take first + one). + (getCrossSectionName,getCrossSectionNames): Renamed, access names + of all cross-sections, so that at least facets with different names + are created (they will still deliver the same data). + + * src/main/java/de/intevation/flys/artifacts/model/CrossSectionFacet.java: + Allow indexing. + + * src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java: + Index created cross-sections. + 2011-11-01 Felix Wolfsteller Show multiple water lines and facets in cross-section diagram if @@ -14,7 +34,6 @@ * src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java: Add one Facet for each of the computed waterlevels. - 2011-10-31 Sascha L. Teichmann * src/main/java/de/intevation/flys/artifacts/geom/VectorUtils.java: diff -r 26d7077e42d2 -r 51e59f221333 flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Tue Nov 01 10:40:05 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Tue Nov 01 12:23:59 2011 +0000 @@ -670,7 +670,7 @@ /** * Get CrossSectionLine spatially closest to what is specified in the data - * "cross_section.km". + * "cross_section.km" (and from "cross_section.index"). * * @return CrossSectionLine closest to "cross_section.km". */ @@ -680,17 +680,26 @@ wishKM = Double.parseDouble(getDataAsString("cross_section.km")); } catch (Exception e) { - logger.warn(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 sections = getCrossSections(); - if (sections.size() == 0 || sections.get(0).getLines().size() == 0) { - return null; - } List crossSectionLines = - sections.get(0).getLines(); + sections.get(crossSectionIdx).getLines(); CrossSectionLine oldLine = crossSectionLines.get(0); double oldDiff = Math.abs(wishKM - oldLine.getKm().doubleValue()); for (CrossSectionLine line: crossSectionLines) { @@ -734,7 +743,10 @@ logger.info("getCrossSectionData() for cross_section.km " + getDataAsString("cross_section.km")); CrossSectionLine line = searchCrossSectionKmLine(); - return line != null ? line.fetchCrossSectionProfile() : null; + + return line != null + ? line.fetchCrossSectionProfile() + : null; } @@ -771,7 +783,7 @@ wishKM = Double.parseDouble(getDataAsString("cross_section.km")); } catch (Exception e) { - logger.warn(e); + logger.warn("Exception when trying to get cross_section.km", e); } if (triple.size() == 0) { @@ -796,17 +808,17 @@ /** - * Get name of cross section. + * Get name of cross sections. + * @return list of names of cross-sections. */ - public String getCrossSectionName() { - List sections = getCrossSections(); + public List getCrossSectionNames() { + List names = new ArrayList(); - if (sections.size() > 0) { - return sections.get(0).getDescription(); + for (CrossSection section: getCrossSections()) { + names.add(section.getDescription()); } - else { - return ""; - } + + return names; } diff -r 26d7077e42d2 -r 51e59f221333 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionFacet.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionFacet.java Tue Nov 01 10:40:05 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionFacet.java Tue Nov 01 12:23:59 2011 +0000 @@ -25,8 +25,8 @@ protected ComputeType type; /** Trivial constructor, set (maybe localized) description. */ - public CrossSectionFacet(String description) { - super(0, CROSS_SECTION, description); + public CrossSectionFacet(int idx, String description) { + super(idx, CROSS_SECTION, description); type = ComputeType.ADVANCE; } @@ -46,7 +46,7 @@ /** Do a deep copy. */ @Override public Facet deepCopy() { - CrossSectionFacet copy = new CrossSectionFacet(this.description); + CrossSectionFacet copy = new CrossSectionFacet(this.index, this.description); copy.set(this); return copy; } diff -r 26d7077e42d2 -r 51e59f221333 flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java Tue Nov 01 10:40:05 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java Tue Nov 01 12:23:59 2011 +0000 @@ -85,8 +85,11 @@ facets.add(wst); facets.add(csv); - // Also register the CrossSectionFacet (added to respective out). - facets.add(new CrossSectionFacet(winfo.getCrossSectionName())); + // Also register the CrossSectionFacets. + int idx = 0; + for (String name: winfo.getCrossSectionNames()) { + facets.add(new CrossSectionFacet(idx++, name)); + } } if (res.getReport().hasProblems()) {