/*
* 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.citygml.bridge;
import java.util.List;
import org.citygml4j.builder.copy.CopyBuilder;
import org.citygml4j.model.citygml.ade.ADEComponent;
import org.citygml4j.model.citygml.core.AbstractCityObject;
import org.citygml4j.model.citygml.core.LodRepresentation;
import org.citygml4j.model.common.child.ChildList;
import org.citygml4j.model.gml.feature.BoundingShape;
import org.citygml4j.model.gml.geometry.AbstractGeometry;
import org.citygml4j.model.gml.geometry.GeometryProperty;
import org.citygml4j.model.gml.geometry.aggregates.MultiSurfaceProperty;
import org.citygml4j.model.module.citygml.BridgeModule;
public abstract class AbstractBoundarySurface extends AbstractCityObject implements BridgeModuleComponent {
private MultiSurfaceProperty lod2MultiSurface;
private MultiSurfaceProperty lod3MultiSurface;
private MultiSurfaceProperty lod4MultiSurface;
private List<OpeningProperty> opening;
private List<ADEComponent> ade;
private BridgeModule module;
public AbstractBoundarySurface() {
}
public AbstractBoundarySurface(BridgeModule module) {
this.module = module;
}
public void addGenericApplicationPropertyOfBoundarySurface(ADEComponent ade) {
if (this.ade == null)
this.ade = new ChildList<ADEComponent>(this);
this.ade.add(ade);
}
public void addOpening(OpeningProperty opening) {
if (this.opening == null)
this.opening = new ChildList<OpeningProperty>(this);
this.opening.add(opening);
}
public List<ADEComponent> getGenericApplicationPropertyOfBoundarySurface() {
if (ade == null)
ade = new ChildList<ADEComponent>(this);
return ade;
}
public MultiSurfaceProperty getLod2MultiSurface() {
return lod2MultiSurface;
}
public MultiSurfaceProperty getLod3MultiSurface() {
return lod3MultiSurface;
}
public MultiSurfaceProperty getLod4MultiSurface() {
return lod4MultiSurface;
}
public List<OpeningProperty> getOpening() {
if (opening == null)
opening = new ChildList<OpeningProperty>(this);
return opening;
}
public boolean isSetGenericApplicationPropertyOfBoundarySurface() {
return ade != null && !ade.isEmpty();
}
public boolean isSetLod2MultiSurface() {
return lod2MultiSurface != null;
}
public boolean isSetLod3MultiSurface() {
return lod3MultiSurface != null;
}
public boolean isSetLod4MultiSurface() {
return lod4MultiSurface != null;
}
public boolean isSetOpening() {
return opening != null && !opening.isEmpty();
}
public void setGenericApplicationPropertyOfBoundarySurface(List<ADEComponent> ade) {
this.ade = new ChildList<ADEComponent>(this, ade);
}
public void setLod2MultiSurface(MultiSurfaceProperty lod2MultiSurface) {
if (lod2MultiSurface != null)
lod2MultiSurface.setParent(this);
this.lod2MultiSurface = lod2MultiSurface;
}
public void setLod3MultiSurface(MultiSurfaceProperty lod3MultiSurface) {
if (lod3MultiSurface != null)
lod3MultiSurface.setParent(this);
this.lod3MultiSurface = lod3MultiSurface;
}
public void setLod4MultiSurface(MultiSurfaceProperty lod4MultiSurface) {
if (lod4MultiSurface != null)
lod4MultiSurface.setParent(this);
this.lod4MultiSurface = lod4MultiSurface;
}
public void setOpening(List<OpeningProperty> opening) {
this.opening = new ChildList<OpeningProperty>(this, opening);
}
public void unsetGenericApplicationPropertyOfBoundarySurface() {
if (isSetGenericApplicationPropertyOfBoundarySurface())
ade.clear();
ade = null;
}
public boolean unsetGenericApplicationPropertyOfBoundarySurface(ADEComponent ade) {
return isSetGenericApplicationPropertyOfBoundarySurface() ? this.ade.remove(ade) : false;
}
public void unsetLod2MultiSurface() {
if (isSetLod2MultiSurface())
lod2MultiSurface.unsetParent();
lod2MultiSurface = null;
}
public void unsetLod3MultiSurface() {
if (isSetLod3MultiSurface())
lod3MultiSurface.unsetParent();
lod3MultiSurface = null;
}
public void unsetLod4MultiSurface() {
if (isSetLod4MultiSurface())
lod4MultiSurface.unsetParent();
lod4MultiSurface = null;
}
public void unsetOpening() {
if (isSetOpening())
opening.clear();
opening = null;
}
public boolean unsetOpening(OpeningProperty opening) {
return isSetOpening() ? this.opening.remove(opening) : false;
}
public final BridgeModule getCityGMLModule() {
return module;
}
public boolean isSetCityGMLModule() {
return module != null;
}
@Override
public BoundingShape calcBoundedBy(boolean setBoundedBy) {
BoundingShape boundedBy = new BoundingShape();
MultiSurfaceProperty multiSurfaceProperty = null;
for (int lod = 2; lod < 5; lod++) {
switch (lod) {
case 2:
multiSurfaceProperty = lod2MultiSurface;
break;
case 3:
multiSurfaceProperty = lod3MultiSurface;
break;
case 4:
multiSurfaceProperty = lod4MultiSurface;
break;
}
if (multiSurfaceProperty != null) {
if (multiSurfaceProperty.isSetMultiSurface()) {
calcBoundedBy(boundedBy, multiSurfaceProperty.getMultiSurface());
} else {
// xlink
}
}
}
if (boundedBy.isSetEnvelope()) {
if (setBoundedBy)
setBoundedBy(boundedBy);
return boundedBy;
} else
return null;
}
@Override
public LodRepresentation getLodRepresentation() {
LodRepresentation lodRepresentation = new LodRepresentation();
GeometryProperty<? extends AbstractGeometry> property = null;
for (int lod = 2; lod < 5; lod++) {
switch (lod) {
case 2:
property = lod2MultiSurface;
break;
case 3:
property = lod3MultiSurface;
break;
case 4:
property = lod4MultiSurface;
break;
}
if (property != null)
lodRepresentation.getLodGeometry(lod).add(property);
}
return lodRepresentation;
}
@Override
public Object copyTo(Object target, CopyBuilder copyBuilder) {
if (target == null)
throw new IllegalArgumentException("Target argument must not be null for abstract copyable classes.");
AbstractBoundarySurface copy = (AbstractBoundarySurface)target;
super.copyTo(copy, copyBuilder);
if (isSetLod2MultiSurface()) {
copy.setLod2MultiSurface((MultiSurfaceProperty)copyBuilder.copy(lod2MultiSurface));
if (copy.getLod2MultiSurface() == lod2MultiSurface)
lod2MultiSurface.setParent(this);
}
if (isSetLod3MultiSurface()) {
copy.setLod3MultiSurface((MultiSurfaceProperty)copyBuilder.copy(lod3MultiSurface));
if (copy.getLod3MultiSurface() == lod3MultiSurface)
lod3MultiSurface.setParent(this);
}
if (isSetLod4MultiSurface()) {
copy.setLod4MultiSurface((MultiSurfaceProperty)copyBuilder.copy(lod4MultiSurface));
if (copy.getLod4MultiSurface() == lod4MultiSurface)
lod4MultiSurface.setParent(this);
}
if (isSetOpening()) {
for (OpeningProperty part : opening) {
OpeningProperty copyPart = (OpeningProperty)copyBuilder.copy(part);
copy.addOpening(copyPart);
if (part != null && copyPart == part)
part.setParent(this);
}
}
if (isSetGenericApplicationPropertyOfBoundarySurface()) {
for (ADEComponent part : ade) {
ADEComponent copyPart = (ADEComponent)copyBuilder.copy(part);
copy.addGenericApplicationPropertyOfBoundarySurface(copyPart);
if (part != null && copyPart == part)
part.setParent(this);
}
}
return copy;
}
}