Ignore:
Timestamp:
2017-09-23T01:25:16+02:00 (7 years ago)
Author:
donvip
Message:

Edigeo: improve support of NF Z 52-000

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFileSCD.java

    r33649 r33657  
    88
    99import org.openstreetmap.josm.data.osm.DataSet;
     10import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileDIC.AttributeDef;
     11import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileDIC.ObjectDef;
     12import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileDIC.RelationDef;
    1013import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileSCD.ScdBlock;
    1114import org.openstreetmap.josm.plugins.fr.cadastre.edigeo.EdigeoFileTHF.ChildBlock;
     
    2730
    2831    /**
    29      * MCD Object definition.
    30      */
    31     public static class McdObjectDef extends ScdBlock {
    32 
    33         /** DIP */ String dictRef = "";
    34         /** KND */ String kind = "";
     32     * MCD definition with attributes.
     33     */
     34    abstract static class ScdTaggedDef extends ScdBlock {
    3535        /** AAC */ int nAttributes;
    3636        /** AAP */ final List<String> attributes = new ArrayList<>();
    3737        /** QAC */ int nQualities;
    38 
    39         McdObjectDef(Lot lot, String type) {
    40             super(lot, type);
    41         }
    42 
    43         @Override
    44         void processRecord(EdigeoRecord r) {
    45             switch (r.name) {
    46             case "DIP": safeGet(r, s -> dictRef += s); break;
    47             case "KND": safeGet(r, s -> kind += s); break;
     38        // TODO: qualities ?
     39
     40        ScdTaggedDef(Lot lot, String type) {
     41            super(lot, type);
     42        }
     43
     44        @Override
     45        void processRecord(EdigeoRecord r) {
     46            switch (r.name) {
    4847            case "AAC": nAttributes = safeGetInt(r); break;
    4948            case "AAP": safeGet(r, attributes); break;
     
    5352            }
    5453        }
     54
     55        @Override
     56        boolean isValid() {
     57            return super.isValid() && areSameSize(nAttributes, attributes);
     58        }
     59    }
     60
     61    /**
     62     * MCD Object definition.
     63     */
     64    public static class McdObjectDef extends ScdTaggedDef {
     65
     66        enum ObjectKind {
     67            COMPLEX("CPX"),
     68            POINT("PCT"),
     69            LINE("LIN"),
     70            AREA("ARE");
     71
     72            final String code;
     73            ObjectKind(String code) {
     74                this.code = code;
     75            }
     76
     77            public static ObjectKind of(String code) {
     78                for (ObjectKind s : values()) {
     79                    if (s.code.equals(code)) {
     80                        return s;
     81                    }
     82                }
     83                throw new IllegalArgumentException(code);
     84            }
     85        }
     86
     87        /** DIP */ ObjectDef dictRef;
     88        /** KND */ ObjectKind kind;
     89
     90        McdObjectDef(Lot lot, String type) {
     91            super(lot, type);
     92        }
     93
     94        @Override
     95        void processRecord(EdigeoRecord r) {
     96            switch (r.name) {
     97            case "DIP": dictRef = lot.dic.find(r.values, ObjectDef.class); break;
     98            case "KND": safeGet(r, s -> kind = ObjectKind.of(s)); break;
     99            default:
     100                super.processRecord(r);
     101            }
     102        }
     103
     104        @Override
     105        boolean isValid() {
     106            return super.isValid() && areNotNull(dictRef, kind);
     107        }
    55108    }
    56109
     
    60113    public static class McdAttributeDef extends ScdBlock {
    61114
    62         /** DIP */ String dictRef = "";
     115        /** DIP */ AttributeDef dictRef;
    63116        /** CAN */ int nMaxChars;
    64117        /** CAD */ int nMaxDigits;
     
    75128        void processRecord(EdigeoRecord r) {
    76129            switch (r.name) {
    77             case "DIP": safeGet(r, s -> dictRef += s); break;
     130            case "DIP": dictRef = lot.dic.find(r.values, AttributeDef.class); break;
    78131            case "CAN": nMaxChars = safeGetInt(r); break;
    79132            case "CAD": nMaxDigits = safeGetInt(r); break;
     
    86139            }
    87140        }
     141
     142        @Override
     143        boolean isValid() {
     144            return super.isValid() && areNotNull(dictRef);
     145        }
    88146    }
    89147
     
    91149     * MCD Primitive definition.
    92150     */
    93     public static class McdPrimitiveDef extends ScdBlock {
     151    public static class McdPrimitiveDef extends ScdTaggedDef {
    94152
    95153        enum PrimitiveKind {
     
    114172
    115173        /** KND */ PrimitiveKind kind;
    116         /** AAC */ int nAttributes;
    117         /** QAC */ int nQualities;
    118174
    119175        McdPrimitiveDef(Lot lot, String type) {
     
    125181            switch (r.name) {
    126182            case "KND": safeGet(r, s -> kind = PrimitiveKind.of(s)); break;
    127             case "AAC": nAttributes = safeGetInt(r); break;
    128             case "QAC": nQualities = safeGetInt(r); break;
    129             default:
    130                 super.processRecord(r);
    131             }
     183            default:
     184                super.processRecord(r);
     185            }
     186        }
     187
     188        @Override
     189        boolean isValid() {
     190            return super.isValid() && areNotNull(kind);
    132191        }
    133192    }
     
    136195     * MCD Relation definition.
    137196     */
    138     abstract static class McdRelationDef extends ScdBlock {
     197    abstract static class McdRelationDef extends ScdTaggedDef {
    139198
    140199        /** CA1 */ int minCardinal;
     
    143202        /** SCP */ final List<ScdBlock> scdRef = new ArrayList<>();
    144203        /** OCC */ final List<Integer> nOccurences = new ArrayList<>();
    145         /** AAC */ int nAttributes;
    146         /** QAC */ int nQualities;
    147204
    148205        McdRelationDef(Lot lot, String type) {
     
    158215            case "SCP": scdRef.add(lot.scd.find(r.values)); break;
    159216            case "OCC": nOccurences.add(safeGetInt(r)); break;
    160             case "AAC": nAttributes = safeGetInt(r); break;
    161             case "QAC": nQualities = safeGetInt(r); break;
    162             default:
    163                 super.processRecord(r);
    164             }
     217            default:
     218                super.processRecord(r);
     219            }
     220        }
     221
     222        @Override
     223        boolean isValid() {
     224            return super.isValid() && areNotNull(minCardinal, maxCardinal) && areSameSize(nTypes, scdRef, nOccurences);
    165225        }
    166226    }
     
    171231    public static class McdSemanticRelationDef extends McdRelationDef {
    172232
    173         /** DIP */ String dictRef = "";
     233        /** DIP */ RelationDef dictRef;
    174234
    175235        McdSemanticRelationDef(Lot lot, String type) {
     
    180240        void processRecord(EdigeoRecord r) {
    181241            switch (r.name) {
    182             case "DIP": safeGet(r, s -> dictRef += s); break;
    183             default:
    184                 super.processRecord(r);
    185             }
     242            case "DIP": dictRef = lot.dic.find(r.values, RelationDef.class); break;
     243            default:
     244                super.processRecord(r);
     245            }
     246        }
     247
     248        @Override
     249        boolean isValid() {
     250            return super.isValid() && areNotNull(dictRef);
    186251        }
    187252    }
     
    232297            }
    233298        }
     299
     300        @Override
     301        boolean isValid() {
     302            return super.isValid() && areNotNull(kind);
     303        }
    234304    }
    235305
Note: See TracChangeset for help on using the changeset viewer.