Subversion Repositories display

Rev

Rev 307 | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*
 * Copyright (C) 2008 Steve Ratcliffe
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 or
 * version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

package test.elements;

import java.util.ArrayList;
import java.util.List;

import uk.me.parabola.imgfmt.app.Label;
import uk.me.parabola.imgfmt.app.trergn.Subdivision;

/**
 * @author Steve Ratcliffe
 */

public abstract class MapObject {

        // All lines are in a division and many aspects of it are with respect to
        // the division.
        private Subdivision subdiv;

        // The label(s) for this object
        private Label label;
        private List<Label> refLabels;

        // The type of road etc.
        private int type;

        // These long and lat values are relative to the subdivision center.
        // Must be shifted depending on the zoom level.
        private int deltaLong;
        private int deltaLat;

        // The number of this point within its subdivision.  Set on read only.
        private int number;

        int getDeltaLat() {
                return deltaLat;
        }

        protected int getDeltaLong() {
                return deltaLong;
        }

        public void setLabel(Label label) {
                this.label = label;
        }

        public void addRefLabel(Label refLabel) {
                if(refLabels == null)
                        refLabels = new ArrayList<Label>();
                refLabels.add(refLabel);
        }

        public int getType() {
                return type;
        }

        public void setType(int type) {
                this.type = type;
        }

        public boolean hasExtendedType() {
                return hasExtendedType(type);
        }

        public static boolean hasExtendedType(int type) {
                return type >= 0x010000;
        }

        /**
         * Set an ordinary unshifted latitude.  It will be calculated
         * relative to the subdivision.
         *
         * @param lat The original latitude.
         */

        public void setLatitude(int lat) {
                Subdivision div = getSubdiv();

                int diff = div.roundLatToLocalShifted(lat);

                setDeltaLat(diff);
        }

        /**
         * Set an ordinary unshifted longitude.  It will be calculated
         * relative to the subdivision.
         *
         * @param lon The original longitude.
         */

        public void setLongitude(int lon) {
                Subdivision div = getSubdiv();

                int diff = div.roundLonToLocalShifted(lon);

                setDeltaLong(diff);
        }

        // directly setting shouldn't be done, unless reading from a file
        public void setDeltaLat(int deltaLat) {
                assert deltaLat >= -0x8000 && deltaLat <= 0x7fff : "deltaLat = " + deltaLat;
                this.deltaLat = deltaLat;
        }

        // directly setting shouldn't be done, unless reading from a file
        public void setDeltaLong(int deltaLong) {
                assert deltaLong >= -0x8000 && deltaLong <= 0x7fff : "deltaLong = " + deltaLong;
                this.deltaLong = deltaLong;
        }

        public Subdivision getSubdiv() {
                return subdiv;
        }

        protected void setSubdiv(Subdivision subdiv) {
                this.subdiv = subdiv;
        }

        public Label getLabel() {
                return label;
        }

        public List<Label> getRefLabels() {
                return refLabels;
        }

        public String toString() {
                return "Type=" + type + ", l=" + label;
        }

        public int getNumber() {
                return number;
        }

        public void setNumber(int number) {
                this.number = number;
        }
}