001/*
002 * (C) Copyright 2006-2016 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Tiago Cardoso <tcardoso@nuxeo.com>
018 */
019package org.nuxeo.ecm.platform.threed.service;
020
021import org.nuxeo.common.xmap.annotation.XNode;
022import org.nuxeo.common.xmap.annotation.XObject;
023
024import static java.lang.Math.abs;
025
026/**
027 * Object representing a registered render view conversion on the {@link ThreeDService}. An {@code RenderView}
028 * references the spherical coordinates and if it should be a Rendition.
029 *
030 * @since 8.4
031 */
032@XObject("renderView")
033public class RenderView implements Comparable<RenderView> {
034
035    @XNode("@name")
036    protected String name;
037
038    @XNode("@zenith")
039    protected Integer zenith;
040
041    @XNode("@azimuth")
042    protected Integer azimuth;
043
044    @XNode("@width")
045    protected Integer width;
046
047    @XNode("@height")
048    protected Integer height;
049
050    @XNode("@enabled")
051    protected Boolean enabled;
052
053    @XNode("@rendition")
054    protected Boolean rendition;
055
056    @XNode("@renditionVisible")
057    protected Boolean renditionVisible;
058
059    public RenderView(RenderView other) {
060        name = other.name;
061        zenith = other.zenith;
062        azimuth = other.azimuth;
063        width = other.width;
064        height = other.height;
065        enabled = other.enabled;
066        rendition = other.rendition;
067        renditionVisible = other.renditionVisible;
068    }
069
070    public RenderView() {
071        super();
072    }
073
074    public String getName() {
075        return name;
076    }
077
078    public void setName(String name) {
079        this.name = name;
080    }
081
082    public Integer getZenith() {
083        return zenith;
084    }
085
086    public void setZenith(Integer zenith) {
087        this.zenith = zenith;
088    }
089
090    public Integer getAzimuth() {
091        return azimuth;
092    }
093
094    public void setAzimuth(Integer azimuth) {
095        this.azimuth = azimuth;
096    }
097
098    public Integer getWidth() {
099        return width;
100    }
101
102    public void setWidth(Integer width) {
103        this.width = width;
104    }
105
106    public Integer getHeight() {
107        return height;
108    }
109
110    public void setHeight(Integer height) {
111        this.height = height;
112    }
113
114    public boolean isEnabled() {
115        return (enabled == null) || enabled;
116    }
117
118    public void setEnabled(boolean enabled) {
119        this.enabled = enabled;
120    }
121
122    public boolean isRendition() {
123        return (rendition == null) || rendition;
124    }
125
126    public void setRendition(boolean rendition) {
127        this.rendition = rendition;
128    }
129
130    public boolean isRenditionVisible() {
131        return (renditionVisible == null) || renditionVisible;
132    }
133
134    public void setRenditionVisible(boolean renditionVisible) {
135        this.renditionVisible = renditionVisible;
136    }
137
138    public void merge(RenderView src) {
139        if (src.enabled != null) {
140            enabled = src.enabled;
141        }
142        if (src.rendition != null) {
143            rendition = src.rendition;
144        }
145        if (src.renditionVisible != null) {
146            renditionVisible = src.renditionVisible;
147        }
148        if (src.zenith != null) {
149            zenith = src.zenith;
150        }
151        if (src.azimuth != null) {
152            azimuth = src.azimuth;
153        }
154        if (src.width != null) {
155            width = src.width;
156        }
157        if (src.height != null) {
158            height = src.height;
159        }
160    }
161
162    public String getId() {
163        return String.valueOf(abs(name.hashCode()));
164    }
165
166    @Override
167    public int compareTo(RenderView o) {
168        return getId().compareTo(o.getId());
169    }
170}