001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.plugins.streetside;
003
004import java.util.List;
005
006import org.openstreetmap.josm.data.coor.LatLon;
007import org.openstreetmap.josm.plugins.streetside.cubemap.CubemapUtils;
008import org.openstreetmap.josm.plugins.streetside.model.UserProfile;
009
010/**
011 * A StreetsideImage object represents each of the images stored in Streetside.
012 *
013 * @author nokutu
014 * @author renerr18
015 *
016 * @see StreetsideSequence
017 * @see StreetsideData
018 */
019public class StreetsideImage extends StreetsideAbstractImage {
020  /**
021   * Rn is a Bing Streetside image attribute - currently not
022   * used, mapped or supported in the Streetside plugin -
023   * left out initially because it's an unrequired complex object.
024   */
025  public static class Rn {
026          // placeholder for Rn attribute (undocumented streetside complex inner type)
027  }
028
029  // latitude of the Streetside image
030  private double la;
031
032  //longitude of the Streetside image
033  private double lo;
034
035  // The bubble altitude, in meters above the WGS84 ellipsoid
036  private double al;
037
038  // Roll
039  private double ro;
040
041  // Pitch
042  private double pi;
043
044  // Blurring instructions - not currently used by the plugin
045  private String bl;
046
047  // Undocumented Attributes
048  private int ml;
049  private List<String> nbn;
050  private List<String> pbn;
051  private int ad;
052  private Rn rn;
053
054  /**
055   * Main constructor of the class StreetsideImage
056   *
057   * @param id     The unique identifier of the image.
058   * @param latLon The latitude and longitude where it is positioned.
059   * @param he     The direction of the images in degrees, meaning 0 north.
060   */
061  public StreetsideImage(String id, LatLon latLon, double he) {
062    super(id, latLon, he);
063  }
064
065  public StreetsideImage(String id, LatLon latLon) {
066    super(id, latLon, 0.0);
067  }
068
069  public StreetsideImage(String id, double la, double lo) {
070    super(id, new LatLon(la,lo), 0.0);
071  }
072
073  public StreetsideImage(String id) {
074            super(id);
075  }
076
077  // Default constructor for Jackson/JSON Deserializattion
078  public StreetsideImage() {
079    super(CubemapUtils.IMPORTED_ID, null, 0.0);
080  }
081
082  /**
083   * Returns the unique identifier of the object.
084   *
085   * @return A {@code String} containing the unique identifier of the object.
086   */
087  @Override
088public String getId() {
089    return String.valueOf(id);
090  }
091
092  public UserProfile getUser() {
093            return getSequence().getUser();
094  }
095
096  @Override
097  public String toString() {
098    return String.format(
099      // TODO: format date cd (Gradle build error command line)
100      "Image[id=%s,lat=%f,lon=%f,he=%f,user=%s]",
101      id, latLon.lat(), latLon.lon(), he, "null"//, cd
102    );
103  }
104
105  @Override
106  public boolean equals(Object object) {
107    return object instanceof StreetsideImage && id.equals(((StreetsideImage) object).getId());
108  }
109
110  @Override
111  public int compareTo(StreetsideAbstractImage image) {
112    if (image instanceof StreetsideImage) {
113      return id.compareTo(((StreetsideImage) image).getId());
114    }
115    return hashCode() - image.hashCode();
116  }
117
118  @Override
119  public int hashCode() {
120    return id.hashCode();
121  }
122
123  @Override
124  public void stopMoving() {
125    super.stopMoving();
126    checkModified();
127  }
128
129  private void checkModified() {
130    if (StreetsideLayer.hasInstance()) {
131      if (isModified()) {
132        StreetsideLayer.getInstance().getLocationChangeset().add(this);
133      } else {
134        StreetsideLayer.getInstance().getLocationChangeset().remove(this);
135      }
136    }
137  }
138
139  @Override
140  public void turn(double ca) {
141    super.turn(ca);
142    checkModified();
143  }
144
145  /**
146   * @return the altitude
147   */
148  public double getAl() {
149    return al;
150  }
151
152  /**
153   * @param altitude the altitude to set
154   */
155  public void setAl(double altitude) {
156    al = altitude;
157  }
158
159  /**
160   * @return the roll
161   */
162  public double getRo() {
163    return ro;
164  }
165
166  /**
167   * @param roll the roll to set
168   */
169  public void setRo(double roll) {
170    ro = roll;
171  }
172
173  /**
174   * @return the pi
175   */
176  public double getPi() {
177    return pi;
178  }
179
180  /**
181   * @param pitch the pi to set
182   */
183  public void setPi(double pitch) {
184    pi = pitch;
185  }
186
187  /**
188   * @return the burringl
189   */
190  public String getBl() {
191    return bl;
192  }
193
194  /**
195   * @param blurring the blurring to set
196   */
197  public void setBl(String blurring) {
198    bl = blurring;
199  }
200
201  /**
202   * @return the ml
203   */
204  public int getMl() {
205    return ml;
206  }
207
208  /**
209   * @param ml the ml to set
210   */
211  public void setMl(int ml) {
212    this.ml = ml;
213  }
214
215  /**
216   * @return the nbn
217   */
218  public List<String> getNbn() {
219    return nbn;
220  }
221
222  /**
223   * @param nbn the nbn to set
224   */
225  public void setNbn(List<String> nbn) {
226    this.nbn = nbn;
227  }
228
229  /**
230   * @return the pbn
231   */
232  public List<String> getPbn() {
233    return pbn;
234  }
235
236  /**
237   * @param pbn the pbn to set
238   */
239  public void setPbn(List<String> pbn) {
240    this.pbn = pbn;
241  }
242
243  /**
244   * @return the ad
245   */
246  public int getAd() {
247    return ad;
248  }
249
250  /**
251   * @param ad the ad to set
252   */
253  public void setAd(int ad) {
254    this.ad = ad;
255  }
256
257  /**
258   * @return the la
259   */
260  public double getLa() {
261    return la;
262  }
263
264  /**
265   * @param la the la to set
266   */
267  public void setLa(double la) {
268    this.la = la;
269  }
270
271  /**
272   * @return the lo
273   */
274  public double getLo() {
275    return lo;
276  }
277
278  /**
279   * @param lo the lo to set
280   */
281  public void setLo(double lo) {
282    this.lo = lo;
283  }
284
285  /**
286   * @param id the id to set
287   */
288  @Override
289public void setId(String id) {
290    this.id = id;
291  }
292
293  /**
294   * @return the rn
295   */
296  public Rn getRn() {
297    return rn;
298  }
299
300  /**
301   * @param rn the rn to set
302   */
303  public void setRn(Rn rn) {
304    this.rn = rn;
305  }
306}