Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesCrossSectionProcessor.java @ 9514:ee6508687e3f
Added default vegetation zones tzo iota result map.
author | gernotbelger |
---|---|
date | Mon, 01 Oct 2018 13:03:42 +0200 |
parents | 6146358c4842 |
children | 7c8d62867876 |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesCrossSectionProcessor.java Mon Oct 01 13:01:55 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesCrossSectionProcessor.java Mon Oct 01 13:03:42 2018 +0200 @@ -18,13 +18,14 @@ import org.dive4elements.artifactdatabase.state.Facet; import org.dive4elements.artifacts.Artifact; import org.dive4elements.artifacts.CallContext; +import org.dive4elements.artifacts.CallMeta; import org.dive4elements.artifacts.DataProvider; import org.dive4elements.river.artifacts.D4EArtifact; -import org.dive4elements.river.artifacts.common.AbstractProcessor; +import org.dive4elements.river.artifacts.access.RiverAccess; import org.dive4elements.river.artifacts.model.CrossSectionFacetUtils; import org.dive4elements.river.artifacts.model.river.MainWstValuesCalculator; +import org.dive4elements.river.artifacts.resources.Resources; import org.dive4elements.river.exports.CrossSectionGenerator; -import org.dive4elements.river.exports.DiagramGenerator; import org.dive4elements.river.jfree.StripedAreaDataset; import org.dive4elements.river.jfree.StripedAreaDataset.Stripe; import org.dive4elements.river.model.FastCrossSectionLine; @@ -35,17 +36,25 @@ * @author Domenico Nardi Tironi * */ -public class VegetationZonesCrossSectionProcessor extends AbstractProcessor { +public final class VegetationZonesCrossSectionProcessor { private static final String MAIN_VALUE_MQ = "mq"; - public static final String FACET_VEGETATION_ZONES_CROSS_SECTION = "uinfo_facet_vegetation_zones_cross_section"; + private static final String FACET_VEGETATION_ZONES_CROSS_SECTION = "uinfo_facet_vegetation_zones_cross_section"; + private static final String FACET_DEFAULT_VEGETATION_ZONES_CROSS_SECTION = "uinfo_facet_default_vegetation_zones_cross_section"; + + private static final String DEFAULT_VEGZONES_DESCRIPTION = "uinfo_facet_vegetation_default_zones_cross_section.description"; private static final Set<String> HANDLED_FACET_TYPES = new HashSet<>(); static { HANDLED_FACET_TYPES.add(FACET_VEGETATION_ZONES_CROSS_SECTION); + HANDLED_FACET_TYPES.add(FACET_DEFAULT_VEGETATION_ZONES_CROSS_SECTION); + } + + public static final boolean canHandle(final String facettype) { + return HANDLED_FACET_TYPES.contains(facettype); } public static Facet createVegetationZonesCrossSectionFacet(final String description) { @@ -53,6 +62,13 @@ return new VegetationZonesCrossSectionFacet(FACET_VEGETATION_ZONES_CROSS_SECTION, description); } + public static Facet createDefaultVegetationZonesCrossSectionFacet(final CallMeta callMeta) { + + final String description = Resources.getMsg(callMeta, DEFAULT_VEGZONES_DESCRIPTION); + + return new VegetationZonesCrossSectionFacet(FACET_DEFAULT_VEGETATION_ZONES_CROSS_SECTION, description); + } + public static void generateSeries(final CrossSectionGenerator generator, final ArtifactAndFacet bundle, final CallContext context, final ThemeDocument theme, final boolean visible) { @@ -62,27 +78,39 @@ return; final double currentStation = crossSection.getKm(); + final RiverAccess rAccess = new RiverAccess((D4EArtifact) bundle.getArtifact()); + final River river = rAccess.getRiver(); + + final List<VegetationZoneServerClientXChange> zones = findZonesData(bundle, context, river); + + final StripedAreaDataset dataset = new StripedAreaDataset(theme); + + for (final VegetationZoneServerClientXChange zone : zones) { + + final double lower = uefdToHeight(context, river, currentStation, zone.getLowerFromTo()); + final double upper = uefdToHeight(context, river, currentStation, zone.getUpperFromTo()); + + final Color color = Color.decode(zone.getHexColor()); + final String label = String.format("%s (%dd-%dd)", zone.getZoneName(), zone.getLowerFromTo(), zone.getUpperFromTo()); + dataset.addStripe(new Stripe(label, color, lower, upper)); + } + + generator.addAxisDataset(dataset, 0, visible); + return; + } + + private static List<VegetationZoneServerClientXChange> findZonesData(final ArtifactAndFacet bundle, final CallContext context, final River river) { + if (bundle.getFacetName().equals(FACET_VEGETATION_ZONES_CROSS_SECTION)) { - final StripedAreaDataset dataset = new StripedAreaDataset(theme); - final Artifact artifact = bundle.getArtifact(); final VegetationzonesAccess vAccess = new VegetationzonesAccess((D4EArtifact) artifact); - final River river = vAccess.getRiver(); - final List<VegetationZoneServerClientXChange> zones = VegetationZoneServerClientXChange.parse(vAccess.getVegZones()); - - for (final VegetationZoneServerClientXChange zone : zones) { + return VegetationZoneServerClientXChange.parse(vAccess.getVegZones()); + } - final double lower = uefdToHeight(context, river, currentStation, zone.getLowerFromTo()); - final double upper = uefdToHeight(context, river, currentStation, zone.getUpperFromTo()); + if (bundle.getFacetName().equals(FACET_DEFAULT_VEGETATION_ZONES_CROSS_SECTION)) { - final Color color = Color.decode(zone.getHexColor()); - final String label = String.format("%s (%dd-%dd)", zone.getZoneName(), zone.getLowerFromTo(), zone.getUpperFromTo()); - dataset.addStripe(new Stripe(label, color, lower, upper)); - } - - generator.addAxisDataset(dataset, 0, visible); - return; + return VegetationZoneServerClientXChange.getStandardList(river, context); } throw new UnsupportedOperationException(); @@ -90,6 +118,7 @@ private static double uefdToHeight(final CallContext context, final River river, final double station, final int uefd) { + // FIXME: cache me final MainWstValuesCalculator mainWstValues = MainWstValuesCalculator.forRiver(context, river, null, MAIN_VALUE_MQ); final double mw = mainWstValues.interpolateW(station, MAIN_VALUE_MQ); @@ -101,16 +130,4 @@ final double dgm = Math.exp((uefd - f2) / f1) + mw - 0.5; return dgm; } - - public VegetationZonesCrossSectionProcessor() { - super(CrossSectionGenerator.I18N_YAXIS_LABEL, HANDLED_FACET_TYPES); - - throw new UnsupportedOperationException(); - } - - @Override - protected String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) { - throw new UnsupportedOperationException(); - } - } \ No newline at end of file