Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/states/FloodMapState.java @ 7647:786ff139de5e
issue1020: When preparing wsts for wsplgen handle other than standard wqkms calculations.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Thu, 05 Dec 2013 15:38:35 +0100 |
parents | f603a53e45dc |
children | 2e1392067986 |
comparison
equal
deleted
inserted
replaced
7646:f603a53e45dc | 7647:786ff139de5e |
---|---|
28 import org.dive4elements.artifacts.CallContext; | 28 import org.dive4elements.artifacts.CallContext; |
29 import org.dive4elements.artifacts.CallMeta; | 29 import org.dive4elements.artifacts.CallMeta; |
30 import org.dive4elements.artifacts.GlobalContext; | 30 import org.dive4elements.artifacts.GlobalContext; |
31 import org.dive4elements.artifacts.common.utils.FileTools; | 31 import org.dive4elements.artifacts.common.utils.FileTools; |
32 import org.dive4elements.river.artifacts.D4EArtifact; | 32 import org.dive4elements.river.artifacts.D4EArtifact; |
33 import org.dive4elements.river.artifacts.StaticWKmsArtifact; | |
33 import org.dive4elements.river.artifacts.access.DGMAccess; | 34 import org.dive4elements.river.artifacts.access.DGMAccess; |
34 import org.dive4elements.river.artifacts.access.RangeAccess; | 35 import org.dive4elements.river.artifacts.access.RangeAccess; |
35 import org.dive4elements.river.artifacts.context.RiverContext; | 36 import org.dive4elements.river.artifacts.context.RiverContext; |
36 import org.dive4elements.river.artifacts.model.CalculationMessage; | 37 import org.dive4elements.river.artifacts.model.CalculationMessage; |
37 import org.dive4elements.river.artifacts.model.CalculationResult; | 38 import org.dive4elements.river.artifacts.model.CalculationResult; |
38 import org.dive4elements.river.artifacts.model.FacetTypes; | 39 import org.dive4elements.river.artifacts.model.FacetTypes; |
39 import org.dive4elements.river.artifacts.model.LayerInfo; | 40 import org.dive4elements.river.artifacts.model.LayerInfo; |
41 import org.dive4elements.river.artifacts.model.WKms; | |
40 import org.dive4elements.river.artifacts.model.WQKms; | 42 import org.dive4elements.river.artifacts.model.WQKms; |
43 import org.dive4elements.river.artifacts.model.fixings.FixRealizingResult; | |
41 import org.dive4elements.river.artifacts.model.map.HWS; | 44 import org.dive4elements.river.artifacts.model.map.HWS; |
42 import org.dive4elements.river.artifacts.model.map.HWSContainer; | 45 import org.dive4elements.river.artifacts.model.map.HWSContainer; |
43 import org.dive4elements.river.artifacts.model.map.HWSFactory; | 46 import org.dive4elements.river.artifacts.model.map.HWSFactory; |
44 import org.dive4elements.river.artifacts.model.map.WMSLayerFacet; | 47 import org.dive4elements.river.artifacts.model.map.WMSLayerFacet; |
45 import org.dive4elements.river.artifacts.model.map.WSPLGENCalculation; | 48 import org.dive4elements.river.artifacts.model.map.WSPLGENCalculation; |
934 try { | 937 try { |
935 idx = Integer.parseInt(parts[2]); | 938 idx = Integer.parseInt(parts[2]); |
936 } | 939 } |
937 catch (NumberFormatException nfe) { /* do nothing */ } | 940 catch (NumberFormatException nfe) { /* do nothing */ } |
938 | 941 |
939 // issue1020: Other kinds of artifacts might calculate other stuff than | |
940 // WQKms or provide data in more static manner (shiver). | |
941 | |
942 D4EArtifact src = otherArtifact != null | 942 D4EArtifact src = otherArtifact != null |
943 ? RiverUtils.getArtifact(otherArtifact, cc) | 943 ? RiverUtils.getArtifact(otherArtifact, cc) |
944 : flys; | 944 : flys; |
945 | 945 |
946 logger.debug("Use waterlevel provided by Artifact: " + src.identifier()); | 946 logger.debug("Use waterlevel provided by Artifact: " + src.identifier()); |
947 | 947 |
948 CalculationResult rawData = (CalculationResult) src.compute( | 948 // The state actually depends on the kind of artifact. E.g. StaticWQKmsArtifact needs other state |
949 Object computed = src.compute( | |
949 cc, | 950 cc, |
950 null, | 951 //null, |
951 WINFO_WSP_STATE_ID, | 952 //WINFO_WSP_STATE_ID, |
952 ComputeType.ADVANCE, | 953 ComputeType.ADVANCE, |
953 false); | 954 false); |
954 | 955 |
955 WQKms[] wqkms = (WQKms[]) rawData.getData(); | 956 // Depending on the artifact and calculation we have different results |
956 | 957 // in place. Note that the same conditions exist in |
957 return wqkms == null || idx == -1 || idx >= wqkms.length | 958 // WaterlevelSelectState#getLabel . |
958 ? null | 959 |
959 : wqkms[idx]; | 960 // Regular WSP calculation |
961 if (computed instanceof CalculationResult) { | |
962 CalculationResult rawData = (CalculationResult) computed; | |
963 WQKms[] wqkms; | |
964 if (rawData.getData() instanceof FixRealizingResult) { | |
965 wqkms = (WQKms[]) ((FixRealizingResult) rawData.getData()).getWQKms(); | |
966 } | |
967 else { | |
968 wqkms = (WQKms[]) rawData.getData(); | |
969 } | |
970 return wqkms == null || idx == -1 || idx >= wqkms.length | |
971 ? null | |
972 : wqkms[idx]; | |
973 } | |
974 else if (computed instanceof WQKms) { | |
975 // e.g. Fixations | |
976 WQKms wqkms = (WQKms) computed; | |
977 return (WQKms) computed; | |
978 } | |
979 else if (computed == null && src instanceof StaticWKmsArtifact) { | |
980 // Floodmarks and protection. | |
981 WQKms wqkms = WQKms.fromWKms(((StaticWKmsArtifact) src).getWKms(0), 1d); | |
982 return wqkms; | |
983 } | |
984 | |
985 logger.warn("getWQKms cannot handle " + computed.getClass() + " " + src.getClass()); | |
986 return null; | |
960 } | 987 } |
961 | 988 |
962 | 989 |
963 protected void setWsp( | 990 protected void setWsp( |
964 D4EArtifact artifact, | 991 D4EArtifact artifact, |
988 if (writeWspTag) { | 1015 if (writeWspTag) { |
989 job.setWspTag(data.getName()); | 1016 job.setWspTag(data.getName()); |
990 writeWspTag = false; | 1017 writeWspTag = false; |
991 } | 1018 } |
992 | 1019 |
993 // TODO issue1020: data might be something different than wqkms, | |
994 // abstract this here a little away. | |
995 for (int i = 0, num = data.size(); i < num; i++) { | 1020 for (int i = 0, num = data.size(); i < num; i++) { |
996 data.get(i, buf); | 1021 data.get(i, buf); |
997 writer.add(buf); | 1022 writer.add(buf); |
998 } | 1023 } |
999 | 1024 |