/*
* citygml4j - The Open Source Java API for CityGML
* https://github.com/citygml4j
*
* Copyright 2013-2017 Claus Nagel <claus.nagel@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.citygml4j.model.gml.geometry.primitives;
import java.util.ArrayList;
import java.util.List;
import org.citygml4j.builder.copy.CopyBuilder;
import org.citygml4j.model.common.base.ModelObject;
import org.citygml4j.model.common.base.ModelType;
import org.citygml4j.model.common.child.Child;
import org.citygml4j.model.common.copy.Copyable;
import org.citygml4j.model.gml.GMLClass;
import org.citygml4j.model.gml.feature.AbstractFeature;
import org.citygml4j.model.gml.geometry.AbstractGeometry;
import org.citygml4j.model.gml.geometry.SRSReferenceGroup;
public class DirectPosition implements SRSReferenceGroup, Child, Copyable {
private List<Double> value;
private Integer srsDimension;
private String srsName;
private List<String> axisLabels;
private List<String> uomLabels;
private ModelObject parent;
public ModelType getModelType() {
return ModelType.GML;
}
public GMLClass getGMLClass() {
return GMLClass.DIRECT_POSITION;
}
public void addValue(Double value) {
if (this.value == null)
this.value = new ArrayList<Double>();
this.value.add(value);
}
public List<Double> getValue() {
if (value == null)
value = new ArrayList<Double>();
return value;
}
public boolean isSetValue() {
return value != null && !value.isEmpty();
}
public void setValue(List<Double> value) {
this.value = value;
}
public List<Double> toList3d() {
List<Double> tmp = new ArrayList<Double>();
if (isSetValue()) {
tmp.addAll(value);
while (tmp.size() < 3)
tmp.add(0.0);
tmp = tmp.subList(0, 3);
}
return tmp;
}
public List<Double> toList3d(boolean reverseOrder) {
List<Double> tmp = toList3d();
if (reverseOrder) {
List<Double> reversed = new ArrayList<Double>();
for (int i = tmp.size() - 3; i >= 0; i -=3)
reversed.addAll(tmp.subList(i, i + 3));
tmp = reversed;
}
return tmp;
}
public void unsetValue() {
value = null;
}
public Integer getSrsDimension() {
return srsDimension;
}
public String getSrsName() {
return srsName;
}
public String getInheritedSrsName() {
if (srsName == null) {
Child child = this;
ModelObject parent = null;
while ((parent = child.getParent()) != null) {
if (parent instanceof AbstractGeometry)
return ((AbstractGeometry)parent).getInheritedSrsName();
else if (parent instanceof AbstractFeature) {
AbstractFeature feature = (AbstractFeature)parent;
if (feature.isSetBoundedBy()
&& feature.getBoundedBy().isSetEnvelope()
&& feature.getBoundedBy().getEnvelope().isSetSrsName())
return feature.getBoundedBy().getEnvelope().getSrsName();
}
if (parent instanceof Child)
child = (Child)parent;
else
break;
}
}
return srsName;
}
public boolean isSetSrsDimension() {
return srsDimension != null;
}
public boolean isSetSrsName() {
return srsName != null;
}
public void setSrsDimension(Integer srsDimension) {
if (srsDimension > 0)
this.srsDimension = srsDimension;
}
public void setSrsName(String srsName) {
this.srsName = srsName;
}
public void unsetSrsDimension() {
srsDimension = null;
}
public void unsetSrsName() {
srsName = null;
}
public void addAxisLabel(String axisLabel) {
if (axisLabels == null)
axisLabels = new ArrayList<String>();
axisLabels.add(axisLabel);
}
public void addUomLabel(String uomLabel) {
if (uomLabels == null)
uomLabels = new ArrayList<String>();
uomLabels.add(uomLabel);
}
public List<String> getAxisLabels() {
if (axisLabels == null)
axisLabels = new ArrayList<String>();
return axisLabels;
}
public List<String> getUomLabels() {
if (uomLabels == null)
uomLabels = new ArrayList<String>();
return uomLabels;
}
public boolean isSetAxisLabels() {
return axisLabels != null && !axisLabels.isEmpty();
}
public boolean isSetUomLabels() {
return uomLabels != null && !uomLabels.isEmpty();
}
public void setAxisLabels(List<String> axisLabels) {
this.axisLabels = axisLabels;
}
public void setUomLabels(List<String> uomLabels) {
this.uomLabels = uomLabels;
}
public void unsetAxisLabels() {
axisLabels = null;
}
public boolean unsetAxisLabels(String axisLabel) {
return isSetAxisLabels() ? axisLabels.remove(axisLabel) : false;
}
public void unsetUomLabels() {
uomLabels = null;
}
public boolean unsetUomLabels(String uomLabel) {
return isSetUomLabels() ? uomLabels.remove(uomLabel) : false;
}
@SuppressWarnings("unchecked")
public Object copyTo(Object target, CopyBuilder copyBuilder) {
DirectPosition copy = (target == null) ? new DirectPosition() : (DirectPosition)target;
if (isSetValue())
copy.setValue((List<Double>)copyBuilder.copy(value));
if (isSetSrsDimension())
copy.setSrsDimension((Integer)copyBuilder.copy(srsDimension));
if (isSetSrsName())
copy.setSrsName(copyBuilder.copy(srsName));
if (isSetAxisLabels())
copy.setAxisLabels((List<String>)copyBuilder.copy(axisLabels));
if (isSetUomLabels())
copy.setUomLabels((List<String>)copyBuilder.copy(uomLabels));
copy.unsetParent();
return copy;
}
public Object copy(CopyBuilder copyBuilder) {
return copyTo(new DirectPosition(), copyBuilder);
}
public ModelObject getParent() {
return parent;
}
public void setParent(ModelObject parent) {
this.parent = parent;
}
public boolean isSetParent() {
return parent != null;
}
public void unsetParent() {
parent = null;
}
}