Commit f3d751f6 authored by Luna Riegel's avatar Luna Riegel
Browse files

Refactor: Extract abstraction for bridge objects

parent 68e915d0
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package de.hft.stuttgart.citydoctor2.datastructure;
import de.hft.stuttgart.citydoctor2.check.CheckableVisitor;
import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
import de.hft.stuttgart.citydoctor2.utils.CityGmlUtils;
import javafx.scene.paint.Color;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.citygml4j.core.model.bridge.AbstractBridge;
import org.citygml4j.core.model.bridge.BridgeInstallation;
import org.citygml4j.core.model.bridge.BridgeInstallationProperty;
import org.citygml4j.core.model.core.AbstractSpaceBoundaryProperty;
import org.citygml4j.core.util.geometry.GeometryFactory;
import org.xmlobjects.gml.model.geometry.aggregates.MultiSurface;
import org.xmlobjects.gml.model.geometry.aggregates.MultiSurfaceProperty;
import org.xmlobjects.gml.model.geometry.primitives.Solid;
import org.xmlobjects.gml.model.geometry.primitives.SolidProperty;
import java.io.Serial;
import java.util.ArrayList;
import java.util.List;
/**
* Bridge representation object of CityGML bridge objects
*
* @author Matthias Betz
*/
public abstract class AbstractBridgeObject extends CityObject implements ConstructionObject{
@Serial
private static final long serialVersionUID = -355778397393226057L;
private static final Logger logger = LogManager.getLogger(AbstractBridgeObject.class);
private final List<BridgeConstructiveElement> elements = new ArrayList<>(2);
private final List<BoundarySurface> boundarySurfaces = new ArrayList<>(2);
private final List<Installation> bridgeInstallations = new ArrayList<>(2);
private final List<BridgeRoomFurniture> bridgeFurniture = new ArrayList<>(2);
private final List<BridgeRoom> bridgeRooms = new ArrayList<>(2);
private AbstractBridge ab;
private BridgeType type;
public enum BridgeType {
BRIDGE, BRIDGE_PART
}
protected AbstractBridgeObject(BridgeType type, AbstractBridge ab) {
this.ab = ab;
this.type = type;
}
@Override
public FeatureType getFeatureType() {
return FeatureType.BRIDGE;
}
@Override
public List<BoundarySurface> getBoundarySurfaces() {
return boundarySurfaces;
}
@Override
public List<BridgeConstructiveElement> getConstructiveElements() {
return elements;
}
@Override
public List<Installation> getInstallations() {
return bridgeInstallations;
}
@Override
public List<BridgeRoom> getRooms() {
return bridgeRooms;
}
@Override
public List<BridgeRoomFurniture> getFurniture() {
return bridgeFurniture;
}
@Override
public Color getRenderColor() {
return Color.LIGHTSTEELBLUE;
}
@Override
public void rebuildGeometries(GeometryFactory factory, ParserConfiguration config) {
for (Geometry geom : getGeometries()) {
if (geom instanceof ImplicitGeometryHolder) {
continue;
}
if (geom.getType() == GeometryType.MULTI_SURFACE) {
MultiSurface ms = CityGmlUtils.createMultiSurface(geom, factory, config);
setMultiSurfaceAccordingToLod(geom, ms);
} else {
Solid solid = CityGmlUtils.createSolid(geom, factory, config);
setSolidAccordingToLod(geom, solid);
}
}
removeEmptyBoundarySurfaces();
}
private void removeEmptyBoundarySurfaces() {
for (BoundarySurface bs : boundarySurfaces) {
if (bs.getGeometries().isEmpty()) {
for (AbstractSpaceBoundaryProperty bsp : ab.getBoundaries()) {
if (bsp.getObject() != null && bsp.getObject() == bs.getGmlObject()) {
logger.warn("Found empty boundary surface: {}, removing from bridge", bs.getGmlId());
ab.getBoundaries().remove(bsp);
break;
}
}
}
}
}
private void setMultiSurfaceAccordingToLod(Geometry geom, MultiSurface ms) {
switch (geom.getLod()) {
case LOD0:
ab.setLod0MultiSurface(new MultiSurfaceProperty(ms));
break;
case LOD1:
ab.getDeprecatedProperties().setLod1MultiSurface(new MultiSurfaceProperty(ms));
break;
case LOD2:
ab.setLod2MultiSurface(new MultiSurfaceProperty(ms));
break;
case LOD3:
ab.setLod3MultiSurface(new MultiSurfaceProperty(ms));
break;
case LOD4:
ab.getDeprecatedProperties().setLod4MultiSurface(new MultiSurfaceProperty(ms));
break;
default:
throw new IllegalStateException("Cannot add " + geom.getLod() + " multi surface to bridges");
}
}
private void setSolidAccordingToLod(Geometry geom, Solid solid) {
switch (geom.getLod()) {
case LOD1:
ab.setLod1Solid(new SolidProperty(solid));
break;
case LOD2:
ab.setLod2Solid(new SolidProperty(solid));
break;
case LOD3:
ab.setLod3Solid(new SolidProperty(solid));
break;
case LOD4:
ab.getDeprecatedProperties().setLod4Solid(new SolidProperty(solid));
break;
default:
throw new IllegalStateException("Cannot add " + geom.getLod() + " solid to bridges");
}
}
public void addInstallation(Installation coBi) {
bridgeInstallations.add(coBi);
coBi.setParent(this);
}
public void addRoom(BridgeRoom room) {
bridgeRooms.add(room);
}
public void addFurniture(BridgeRoomFurniture furniture){
bridgeFurniture.add(furniture);
furniture.setParent(this);
}
public void addBoundarySurface(BoundarySurface bs) {
boundarySurfaces.add(bs);
bs.setParent(this);
}
@Override
public void accept(CheckableVisitor c) {
super.accept(c);
if (c.canExecute(this)) {
c.check(this);
}
for (BoundarySurface bs : boundarySurfaces) {
bs.accept(c);
}
for (Installation bi : bridgeInstallations) {
bi.accept(c);
}
for (BridgeConstructiveElement ele : elements) {
ele.accept(c);
}
for (BridgeRoom br : bridgeRooms) {
br.accept(c);
}
for (BridgeRoomFurniture bri : bridgeFurniture) {
bri.accept(c);
}
}
/**
* Getter method for type
*
* @return the type
*/
public BridgeType getType() {
return type;
}
/**
* Setter Method for type
*
* @param type the type to set
*/
protected void setType(BridgeType type) {
this.type = type;
}
protected void setGmlObject(AbstractBridge gmlObject) {
this.ab = gmlObject;
}
@Override
public AbstractBridge getGmlObject() {
return ab;
}
@Override
public void unsetGmlGeometries() {
ab.setLod1Solid(null);
ab.setLod2Solid(null);
ab.setLod3Solid(null);
ab.getDeprecatedProperties().setLod4Solid(null);
ab.setLod0MultiSurface(null);
ab.getDeprecatedProperties().setLod1MultiSurface(null);
ab.setLod2MultiSurface(null);
ab.setLod3MultiSurface(null);
ab.getDeprecatedProperties().setLod4MultiSurface(null);
}
@Override
public String toString() {
return "BridgeObject [type=" + type + ", id=" + getGmlId() + "]";
}
public void anonymize() {
for (Geometry geom : getGeometries()) {
geom.anonymize();
}
org.citygml4j.core.model.bridge.Bridge gmlB = new org.citygml4j.core.model.bridge.Bridge();
gmlB.setId(GmlId.generateId().getGmlString());
for (Installation bi : getInstallations()) {
bi.anonymize();
gmlB.getBridgeInstallations().add(new BridgeInstallationProperty((BridgeInstallation) bi.getGmlObject()));
}
for (BoundarySurface bs : getBoundarySurfaces()) {
bs.anonymize();
gmlB.addBoundary(new AbstractSpaceBoundaryProperty(bs.getGmlObject()));
}
this.ab = gmlB;
}
public void addConstructiveElement(BridgeConstructiveElement element) {
getConstructiveElements().add(element);
element.setParent(this);
}
}
...@@ -25,6 +25,7 @@ import javafx.scene.paint.Color; ...@@ -25,6 +25,7 @@ import javafx.scene.paint.Color;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.citygml4j.core.model.bridge.AbstractBridge; import org.citygml4j.core.model.bridge.AbstractBridge;
import org.citygml4j.core.model.bridge.Bridge;
import org.citygml4j.core.model.bridge.BridgeInstallation; import org.citygml4j.core.model.bridge.BridgeInstallation;
import org.citygml4j.core.model.bridge.BridgeInstallationProperty; import org.citygml4j.core.model.bridge.BridgeInstallationProperty;
import org.citygml4j.core.model.core.AbstractSpaceBoundaryProperty; import org.citygml4j.core.model.core.AbstractSpaceBoundaryProperty;
...@@ -48,267 +49,37 @@ public class BridgeObject extends AbstractBridgeObject implements ConstructionOb ...@@ -48,267 +49,37 @@ public class BridgeObject extends AbstractBridgeObject implements ConstructionOb
@Serial @Serial
private static final long serialVersionUID = 6301112640328373842L; private static final long serialVersionUID = 6301112640328373842L;
private static final Logger logger = LogManager.getLogger(BridgeObject.class); private final List<BridgeObjectPart> parts = new ArrayList<>(2);
private final List<BridgeObject> parts = new ArrayList<>(2);
private final List<BridgeConstructiveElement> elements = new ArrayList<>(2);
private final List<BoundarySurface> boundarySurfaces = new ArrayList<>(2);
private final List<Installation> bridgeInstallations = new ArrayList<>(2);
private final List<BridgeRoomFurniture> bridgeFurniture = new ArrayList<>(2);
private final List<BridgeRoom> bridgeRooms = new ArrayList<>(2);
private AbstractBridge ab;
private BridgeType type;
private BridgeObject parent;
public BridgeObject(AbstractBridge ab) {
this(BridgeType.BRIDGE, ab, null);
}
public BridgeObject(AbstractBridge ab, BridgeObject parent) {
this(BridgeType.BRIDGE_PART, ab, parent);
}
private BridgeObject(BridgeType type, AbstractBridge ab, BridgeObject parent) {
this.ab = ab;
this.type = type;
this.parent = parent;
}
@Override
public FeatureType getFeatureType() {
return FeatureType.BRIDGE;
}
public List<BridgeConstructiveElement> getConstructiveElements() {
return elements;
}
public List<Installation> getBridgeInstallations() {
return bridgeInstallations;
}
public List<BridgeRoom> getBridgeRooms() {
return bridgeRooms;
}
public List<BridgeRoomFurniture> getBridgeFurniture() {
return bridgeFurniture;
}
@Override
public Color getRenderColor() {
return Color.LIGHTSTEELBLUE;
}
@Override @Override
public void rebuildGeometries(GeometryFactory factory, ParserConfiguration config) { public void accept(CheckableVisitor c){
for (Geometry geom : getGeometries()) {
if (geom instanceof ImplicitGeometryHolder) {
continue;
}
if (geom.getType() == GeometryType.MULTI_SURFACE) {
MultiSurface ms = CityGmlUtils.createMultiSurface(geom, factory, config);
setMultiSurfaceAccordingToLod(geom, ms);
} else {
Solid solid = CityGmlUtils.createSolid(geom, factory, config);
setSolidAccordingToLod(geom, solid);
}
}
removeEmptyBoundarySurfaces();
}
private void removeEmptyBoundarySurfaces() {
for (BoundarySurface bs : boundarySurfaces) {
if (bs.getGeometries().isEmpty()) {
for (AbstractSpaceBoundaryProperty bsp : ab.getBoundaries()) {
if (bsp.getObject() != null && bsp.getObject() == bs.getGmlObject()) {
logger.warn("Found empty boundary surface: {}, removing from bridge", bs.getGmlId());
ab.getBoundaries().remove(bsp);
break;
}
}
}
}
}
private void setMultiSurfaceAccordingToLod(Geometry geom, MultiSurface ms) {
switch (geom.getLod()) {
case LOD0:
ab.setLod0MultiSurface(new MultiSurfaceProperty(ms));
break;
case LOD1:
ab.getDeprecatedProperties().setLod1MultiSurface(new MultiSurfaceProperty(ms));
break;
case LOD2:
ab.setLod2MultiSurface(new MultiSurfaceProperty(ms));
break;
case LOD3:
ab.setLod3MultiSurface(new MultiSurfaceProperty(ms));
break;
case LOD4:
ab.getDeprecatedProperties().setLod4MultiSurface(new MultiSurfaceProperty(ms));
break;
default:
throw new IllegalStateException("Cannot add " + geom.getLod() + " multi surface to bridges");
}
}
private void setSolidAccordingToLod(Geometry geom, Solid solid) {
switch (geom.getLod()) {
case LOD1:
ab.setLod1Solid(new SolidProperty(solid));
break;
case LOD2:
ab.setLod2Solid(new SolidProperty(solid));
break;
case LOD3:
ab.setLod3Solid(new SolidProperty(solid));
break;
case LOD4:
ab.getDeprecatedProperties().setLod4Solid(new SolidProperty(solid));
break;
default:
throw new IllegalStateException("Cannot add " + geom.getLod() + " solid to bridges");
}
}
public void addBridgeInstallation(Installation coBi) {
bridgeInstallations.add(coBi);
coBi.setParent(this);
}
public void addBridgeRoom(BridgeRoom room) {
bridgeRooms.add(room);
}
public void addBridgeFurniture(BridgeRoomFurniture furniture){
bridgeFurniture.add(furniture);
furniture.setParent(this);
}
@Override
public void accept(CheckableVisitor c) {
super.accept(c); super.accept(c);
if (c.canExecute(this)) { for (BridgeObjectPart part : parts) {
c.check(this);
}
for (BoundarySurface bs : boundarySurfaces) {
bs.accept(c);
}
for (Installation bi : bridgeInstallations) {
bi.accept(c);
}
for (BridgeObject part : parts) {
part.accept(c); part.accept(c);
} }
for (BridgeConstructiveElement ele : elements) {
ele.accept(c);
}
for (BridgeRoom br : bridgeRooms) {
br.accept(c);
}
for (BridgeRoomFurniture bri : bridgeFurniture) {
bri.accept(c);
}
}
/**
* Getter method for type
*
* @return the type
*/
public BridgeType getType() {
return type;
}
/**
* Setter Method for type
*
* @param type the type to set
*/
public void setType(BridgeType type) {
this.type = type;
}
public void addBoundarySurface(BoundarySurface bs) {
boundarySurfaces.add(bs);
bs.setParent(this);
} }
@Override public BridgeObject(Bridge ab) {
public AbstractBridge getGmlObject() { super(BridgeType.BRIDGE, ab);
return ab;
} }
public void setGmlObject(AbstractBridge aBridge) { public void setGmlObject(Bridge aBridge) {
ab = aBridge; super.setGmlObject(aBridge);
} }
@Override
public void unsetGmlGeometries() {
ab.setLod1Solid(null);
ab.setLod2Solid(null);
ab.setLod3Solid(null);
ab.getDeprecatedProperties().setLod4Solid(null);
ab.setLod0MultiSurface(null);
ab.getDeprecatedProperties().setLod1MultiSurface(null);
ab.setLod2MultiSurface(null);
ab.setLod3MultiSurface(null);
ab.getDeprecatedProperties().setLod4MultiSurface(null);
}
@Override @Override
public CityObject getTopLevelCityObject() { public CityObject getTopLevelCityObject() {
if (parent != null){
return parent.getTopLevelCityObject();
}
return this; return this;
} }
@Override public List<BridgeObjectPart> getParts() {
public String toString() {
return "BridgeObject [type=" + type + ", id=" + getGmlId() + "]";
}
public void anonymize() {
for (Geometry geom : getGeometries()) {
geom.anonymize();
}
org.citygml4j.core.model.bridge.Bridge gmlB = new org.citygml4j.core.model.bridge.Bridge();
gmlB.setId(GmlId.generateId().getGmlString());
for (Installation bi : getBridgeInstallations()) {
bi.anonymize();
gmlB.getBridgeInstallations().add(new BridgeInstallationProperty((BridgeInstallation) bi.getGmlObject()));
}
for (BoundarySurface bs : getBoundarySurfaces()) {
bs.anonymize();
gmlB.addBoundary(new AbstractSpaceBoundaryProperty(bs.getGmlObject()));
}
this.ab = gmlB;
}
public List<BoundarySurface> getBoundarySurfaces() {
return boundarySurfaces;
}
public void addConstructiveElement(BridgeConstructiveElement element) {
getConstructiveElements().add(element);
element.setParent(this);
}
public List<BridgeObject> getParts() {
return parts; return parts;
} }
public void addBridgePart(BridgeObject bPart) { public void addBridgePart(BridgeObjectPart bPart) {
getParts().add(bPart); parts.add(bPart);
} }
public enum BridgeType {
BRIDGE, BRIDGE_PART
}
} }
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package de.hft.stuttgart.citydoctor2.datastructure;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.citygml4j.core.model.bridge.AbstractBridge;
import org.citygml4j.core.model.bridge.BridgePart;
import java.io.Serial;
/**
* Bridge representation object of CityGML bridge objects
*
* @author Matthias Betz
*/
public class BridgeObjectPart extends AbstractBridgeObject implements ConstructionObject{
@Serial
private static final long serialVersionUID = 4436106259059669499L;
private BridgeObject parent;
public BridgeObjectPart(BridgePart bp) {
super(BridgeType.BRIDGE_PART, bp);
}
public void setParent(BridgeObject parent) {
this.parent = parent;
}
public BridgeObject getParent() {
return parent;
}
@Override
public CityObject getTopLevelCityObject() {
return parent.getTopLevelCityObject();
}
}
...@@ -44,7 +44,7 @@ import de.hft.stuttgart.citydoctor2.check.CheckId; ...@@ -44,7 +44,7 @@ import de.hft.stuttgart.citydoctor2.check.CheckId;
import de.hft.stuttgart.citydoctor2.check.CheckResult; import de.hft.stuttgart.citydoctor2.check.CheckResult;
import de.hft.stuttgart.citydoctor2.check.CheckableUtilsVisitor; import de.hft.stuttgart.citydoctor2.check.CheckableUtilsVisitor;
import de.hft.stuttgart.citydoctor2.check.ResultStatus; import de.hft.stuttgart.citydoctor2.check.ResultStatus;
import de.hft.stuttgart.citydoctor2.datastructure.BridgeObject.BridgeType; import de.hft.stuttgart.citydoctor2.datastructure.AbstractBridgeObject.BridgeType;
import de.hft.stuttgart.citydoctor2.datastructure.Geometry.Orientation; import de.hft.stuttgart.citydoctor2.datastructure.Geometry.Orientation;
import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration; import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
import de.hft.stuttgart.citydoctor2.utils.visitors.UnsetGeometriesVisitor; import de.hft.stuttgart.citydoctor2.utils.visitors.UnsetGeometriesVisitor;
...@@ -85,7 +85,7 @@ public class BridgeObjectTest { ...@@ -85,7 +85,7 @@ public class BridgeObjectTest {
public void testVisitorPropagation() { public void testVisitorPropagation() {
BridgeObject bo = new BridgeObject(mock(AbstractBridge.class)); BridgeObject bo = new BridgeObject(mock(AbstractBridge.class));
BridgeObject partMock = mock(BridgeObject.class); BridgeObjectPart partMock = mock(BridgeObjectPart.class);
BridgeRoom mockRoom = mock(BridgeRoom.class); BridgeRoom mockRoom = mock(BridgeRoom.class);
BridgeRoomFurniture mockFurn = mock(BridgeRoomFurniture.class); BridgeRoomFurniture mockFurn = mock(BridgeRoomFurniture.class);
BridgeConstructiveElement ceMock = mock(BridgeConstructiveElement.class); BridgeConstructiveElement ceMock = mock(BridgeConstructiveElement.class);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment