/*
* 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;
import java.util.ArrayList;
import java.util.List;
import org.citygml4j.builder.copy.CopyBuilder;
import org.citygml4j.geometry.BoundingBox;
import org.citygml4j.model.common.base.ModelObject;
import org.citygml4j.model.common.child.Child;
import org.citygml4j.model.common.visitor.GeometryFunctor;
import org.citygml4j.model.common.visitor.GeometryVisitor;
import org.citygml4j.model.gml.base.AbstractGML;
import org.citygml4j.model.gml.feature.AbstractFeature;
public abstract class AbstractGeometry extends AbstractGML implements SRSReferenceGroup {
private String gid;
private Integer srsDimension;
private String srsName;
private List<String> axisLabels;
private List<String> uomLabels;
public String getGid() {
return gid;
}
public boolean isSetGid() {
return gid != null;
}
public void setGid(String gid) {
this.gid = gid;
}
public void unsetGid() {
gid = 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")
@Override
public Object copyTo(Object target, CopyBuilder copyBuilder) {
if (target == null)
throw new IllegalArgumentException("Target argument must not be null for abstract copyable classes.");
AbstractGeometry copy = (AbstractGeometry)target;
super.copyTo(copy, copyBuilder);
if (isSetGid())
copy.setGid(copyBuilder.copy(gid));
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));
return copy;
}
public abstract BoundingBox calcBoundingBox();
public abstract void accept(GeometryVisitor visitor);
public abstract <T> T accept(GeometryFunctor<T> visitor);
}