Commit 2459496d authored by Riegel's avatar Riegel
Browse files

Merge branch 'dev_gui_features_zip_loading' into 'dev'

Add ZIP-archive support

See merge request !26
parents ca7fe768 b75c2602
Pipeline #10995 passed with stage
in 1 minute and 29 seconds
......@@ -50,6 +50,11 @@ public class BuildingRoom extends AbstractRoom {
parent = handler.getCopyInstance(oRoom.getParent());
}
@Override
public CityObject getTopLevelCityObject() {
return getParent().getTopLevelCityObject();
}
@Override
public void collectInstances(CopyHandler handler) {
super.collectInstances(handler);
......
......@@ -126,4 +126,8 @@ public class BuildingUnit extends AbstractBuildingSubdivision {
}
this.abs = originalBu.abs;
}
public List<Storey> getStoreys() {
return storeys;
}
}
......@@ -50,6 +50,11 @@ public class CityFurniture extends CityObject {
cgmlCityFurniture.getDeprecatedProperties().setLod4Geometry(null);
}
@Override
public CityObject getTopLevelCityObject() {
return this;
}
@Override
public void reCreateGeometries(GeometryFactory factory, ParserConfiguration config) {
for (Geometry geom : getGeometries()) {
......@@ -71,12 +76,18 @@ public class CityFurniture extends CityObject {
case LOD0:
cgmlCityFurniture.setLod0MultiSurface(new MultiSurfaceProperty(ms));
break;
case LOD1:
cgmlCityFurniture.getDeprecatedProperties().setLod1Geometry(new MultiSurfaceProperty(ms));
break;
case LOD2:
cgmlCityFurniture.setLod2MultiSurface(new MultiSurfaceProperty(ms));
break;
case LOD3:
cgmlCityFurniture.setLod3MultiSurface(new MultiSurfaceProperty(ms));
break;
case LOD4:
cgmlCityFurniture.getDeprecatedProperties().setLod4Geometry(new MultiSurfaceProperty(ms));
break;
default:
throw new IllegalStateException("Cannot add " + geom.getLod() + " multi surface to buildings");
}
......@@ -93,6 +104,8 @@ public class CityFurniture extends CityObject {
case LOD3:
cgmlCityFurniture.setLod3Solid(new SolidProperty(solid));
break;
case LOD4:
cgmlCityFurniture.getDeprecatedProperties().setLod4Geometry(new SolidProperty(solid));
default:
throw new IllegalStateException("Cannot add " + geom.getLod() + " solid to buildings");
}
......
......@@ -102,6 +102,11 @@ public abstract class CityObject extends GmlElement {
return highestLodGeometry;
}
/**
* Returns the top-level CityObject (like Building or Tunnel) belonging to this object.
*/
public abstract CityObject getTopLevelCityObject();
public void addGenericAttribute(GenericAttribute genericAttribute) {
genericAttributeList.add(genericAttribute);
}
......
......@@ -2,6 +2,7 @@ package de.hft.stuttgart.citydoctor2.datastructure;
import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
......@@ -9,7 +10,7 @@ import java.util.List;
*
* @author Riegel
*/
public final class CompositeCollection {
public final class CompositeCollection implements Serializable {
@Serial
private static final long serialVersionUID = -1867197873443341287L;
......@@ -31,6 +32,7 @@ public final class CompositeCollection {
return childComposites;
}
//TODO stream
public List<ConcretePolygon> getCompositeMembers() {
List<ConcretePolygon> copy = new ArrayList<>(compositeMembers);
for (CompositeCollection c : childComposites) {
......
......@@ -26,7 +26,7 @@ public class GenericAttribute {
if (attributeProperty.getObject() instanceof StringAttribute sa) {
type = "StringAttribute";
value = sa.getValue();
value = String.format("\"%s\"", sa.getValue());
} else if (attributeProperty.getObject() instanceof IntAttribute ia) {
type = "IntAttribute";
value = ia.getValue().toString();
......@@ -41,10 +41,10 @@ public class GenericAttribute {
value = ua.getValue();
} else if (attributeProperty.getObject() instanceof MeasureAttribute ma) {
type = "MeasureAttribute";
value = ma.getValue().toString();
value = String.format("%s %s", ma.getValue().getValue().toString(), ma.getValue().getUom());
} else if (attributeProperty.getObject() instanceof CodeAttribute ca) {
type = "CodeAttribute";
value = ca.getValue().toString();
type = String.format("CodeAttribute (%s)", ca.getValue().getLanguage());
value = String.format("'''%s''' %n CodeSpace: %s", ca.getValue().getValue(), ca.getValue().getCodeSpace());
} else {
logger.warn("GenericAttribute {} is of unknown type {}", attributeProperty, attributeProperty.getObject());
value = attributeProperty.getObject().getValue().toString();
......
......@@ -84,14 +84,20 @@ public class GenericCityObject extends CityObject {
case LOD0:
cgmlGos.setLod0MultiSurface(new MultiSurfaceProperty(ms));
break;
case LOD1:
cgmlGos.getDeprecatedProperties().setLod1Geometry(new MultiSurfaceProperty(ms));
break;
case LOD2:
cgmlGos.setLod2MultiSurface(new MultiSurfaceProperty(ms));
break;
case LOD3:
cgmlGos.setLod3MultiSurface(new MultiSurfaceProperty(ms));
break;
case LOD4:
cgmlGos.getDeprecatedProperties().setLod4Geometry(new MultiSurfaceProperty(ms));
break;
default:
throw new IllegalStateException("Cannot add " + geom.getLod() + " multi surface to buildings");
throw new IllegalStateException("Cannot add " + geom.getLod() + " multi surface to generic city object");
}
}
......@@ -106,6 +112,9 @@ public class GenericCityObject extends CityObject {
case LOD3:
cgmlGos.setLod3Solid(new SolidProperty(solid));
break;
case LOD4:
cgmlGos.getDeprecatedProperties().setLod4Geometry(new SolidProperty(solid));
break;
default:
throw new IllegalStateException("Cannot add " + geom.getLod() + " solid to buildings");
}
......@@ -213,6 +222,11 @@ public class GenericCityObject extends CityObject {
}
}
@Override
public CityObject getTopLevelCityObject() {
return this;
}
public void setGmlObject(org.citygml4j.core.model.generics.GenericOccupiedSpace gos) {
this.cgmlGos = gos;
}
......
......@@ -195,6 +195,11 @@ public class Installation extends CityObject {
}
}
@Override
public CityObject getTopLevelCityObject() {
return getParent().getTopLevelCityObject();
}
private void removeGeometriesFromBridgeInstallation(BridgeInstallation localBi) {
localBi.getDeprecatedProperties().setLod2Geometry(null);
localBi.getDeprecatedProperties().setLod3Geometry(null);
......
......@@ -105,6 +105,11 @@ public class LandObject extends CityObject {
lu.getDeprecatedProperties().setLod4MultiSurface(null);
}
@Override
public CityObject getTopLevelCityObject() {
return this;
}
public void setGmlObject(LandUse landUse) {
lu = landUse;
}
......
......@@ -4,10 +4,12 @@ import de.hft.stuttgart.citydoctor2.parser.CityGmlParseException;
import de.hft.stuttgart.citydoctor2.parser.CityGmlParser;
import de.hft.stuttgart.citydoctor2.parser.InvalidGmlFileException;
import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
import de.hft.stuttgart.citydoctor2.zip.CityGmlZipEntry;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.Serial;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
......@@ -27,53 +29,86 @@ public class LibraryObject extends Geometry {
private static Map<String, LibraryObject> libraryObjects = new ConcurrentHashMap<>();
public static LibraryObject of(Path path, ParserConfiguration config) {
if (libraryObjects.containsKey(path.toString())) {
return libraryObjects.get(path.toString());
}
Geometry protoGeom = parseFile(path, config);
if (protoGeom == null) {
return null;
}
LibraryObject libOb = new LibraryObject(protoGeom.getType(), protoGeom.getLod());
protoGeom.getPolygons().forEach(libOb::addPolygon);
libOb.updateEdgesAndVertices();
libraryObjects.put(path.toString(), libOb);
return libOb;
}
public static LibraryObject of(Path path, ParserConfiguration config) {
if (libraryObjects.containsKey(path.toString())) {
return libraryObjects.get(path.toString());
}
Geometry protoGeom = parseFile(path, config);
if (protoGeom == null) {
return null;
}
LibraryObject libOb = new LibraryObject(protoGeom.getType(), protoGeom.getLod());
protoGeom.getPolygons().forEach(libOb::addPolygon);
libOb.updateEdgesAndVertices();
libraryObjects.put(path.toString(), libOb);
return libOb;
}
private LibraryObject(GeometryType type, Lod lod) {
super(type, lod);
}
public static LibraryObject of(CityGmlZipEntry entry, ParserConfiguration config) {
String fileName = entry.getEntrySubPath();
if (libraryObjects.containsKey(fileName)){
return libraryObjects.get(fileName);
}
Geometry protoGeom = parseZipEntry(entry, config);
if (protoGeom == null) {
return null;
}
LibraryObject libOb = new LibraryObject(protoGeom.getType(), protoGeom.getLod());
protoGeom.getPolygons().forEach(libOb::addPolygon);
libOb.updateEdgesAndVertices();
libraryObjects.put(fileName, libOb);
return libOb;
}
private static Geometry parseFile(Path path, ParserConfiguration config) {
Geometry geo = null;
if (path.toFile().exists()) {
try {
CityGmlParser.gagLogger(true);
CityDoctorModel model = CityGmlParser.parseCityGmlFile(path.toString(), config);
List<CityObject> objects = model.createFeatureStream().toList();
if (objects.isEmpty()) {
throw new InvalidGmlFileException(
"Referenced library-object's gml file does not contain a CityGML object!");
} else if (objects.size() > 1) {
throw new InvalidGmlFileException(
"Referenced library-object's gml file contains more than one CityGML object!");
}
geo = objects.get(0).getHighestLodGeometry();
} catch (CityGmlParseException e) {
logger.error("Encountered an error while parsing library object {}", path);
logger.error(e.getStackTrace());
} catch (InvalidGmlFileException e) {
logger.error(e.getStackTrace());
} finally {
// Failsafe to remove gag should parsing fail
CityGmlParser.gagLogger(false);
}
} else {
logger.error("Implicit geometry references non-existing library object file {}.", path);
}
return geo;
}
private LibraryObject(GeometryType type, Lod lod) {
super(type, lod);
}
private static Geometry parseFile(Path path, ParserConfiguration config) {
Geometry geo = null;
if (Files.exists(path)) {
try {
geo = getProtoGeometry(CityGmlParser.parseCityGmlFileSilently(path.toString(), config));
} catch (CityGmlParseException e) {
logger.error(String.format(
"Encountered an error while parsing library object %s", path));
logger.error(e.getStackTrace());
} catch (InvalidGmlFileException e) {
logger.error(e.getStackTrace());
}
} else {
logger.error(String.format("Implicit geometry references non-existing library object file %s.", path));
}
return geo;
}
private static Geometry parseZipEntry(CityGmlZipEntry entry, ParserConfiguration config) {
Geometry geo = null;
try {
entry.loadEntry(config);
geo = getProtoGeometry(entry.getModel());
} catch (InvalidGmlFileException e) {
logger.error(e.getStackTrace());
} catch (CityGmlParseException e) {
logger.error(String.format(
"Encountered an error while parsing library object %s", entry.getEntrySubPath()));
logger.error(e.getStackTrace());
}
return geo;
}
private static Geometry getProtoGeometry(CityDoctorModel model) throws InvalidGmlFileException, CityGmlParseException {
if (model == null) {
throw new CityGmlParseException("CityDoctorModel of referenced LibraryObject is null");
}
List<CityObject> objects = model.createFeatureStream().toList();
if (objects.isEmpty()) {
throw new InvalidGmlFileException("Referenced library-object gml file does not contain any CityGML objects!");
} else if (objects.size() > 1) {
throw new InvalidGmlFileException("Referenced library-object gml file contains more than one CityGML object!");
}
return objects.get(0).getHighestLodGeometry();
}
}
......@@ -135,6 +135,11 @@ public class Opening extends CityObject {
ao.getDeprecatedProperties().setLod4MultiSurface(null);
}
@Override
public CityObject getTopLevelCityObject() {
return partOf.getTopLevelCityObject();
}
@Override
public String toString() {
return "Opening [type=" + type + ", id=" + getGmlId() + "]";
......
......@@ -146,6 +146,11 @@ public class ReliefObject extends CityObject {
// no geometries
}
@Override
public CityObject getTopLevelCityObject() {
return this;
}
@Override
public FeatureType getFeatureType() {
return FeatureType.LAND;
......
......@@ -125,4 +125,8 @@ public class Storey extends AbstractBuildingSubdivision {
}
this.abs = originalSt.abs;
}
public List<BuildingUnit> getBuildingUnits() {
return buildingUnits;
}
}
......@@ -91,6 +91,11 @@ public class TinObject extends CityObject {
gmlRelief.setTin(null);
}
@Override
public CityObject getTopLevelCityObject() {
return this;
}
@Override
public FeatureType getFeatureType() {
return FeatureType.LAND;
......
......@@ -267,6 +267,11 @@ public class TransportationObject extends CityObject {
}
}
@Override
public CityObject getTopLevelCityObject() {
return this;
}
public void setGmlObject(AbstractCityObject tc) {
ato = tc;
}
......
......@@ -34,6 +34,11 @@ public class Tunnel extends AbstractTunnel {
}
}
@Override
public CityObject getTopLevelCityObject() {
return this;
}
@Override
public void accept(Check c) {
super.accept(c);
......
......@@ -31,12 +31,20 @@ public class TunnelConstructiveElement extends CityObject {
private final org.citygml4j.core.model.tunnel.TunnelConstructiveElement gmlTunnelElement;
private final List<BoundarySurface> boundarySurfaceList = new ArrayList<>();
private AbstractTunnel parent;
public TunnelConstructiveElement(org.citygml4j.core.model.tunnel.TunnelConstructiveElement gmlObject) {
this.gmlTunnelElement = gmlObject;
}
public void setParent(AbstractTunnel parent) {
this.parent = parent;
}
public AbstractTunnel getParent() {
return parent;
}
@Override
public Copyable createCopyInstance() {
return new TunnelConstructiveElement(gmlTunnelElement);
......@@ -188,6 +196,11 @@ public class TunnelConstructiveElement extends CityObject {
}
}
@Override
public CityObject getTopLevelCityObject() {
return getParent().getTopLevelCityObject();
}
@Override
public FeatureType getFeatureType() {
return FeatureType.TUNNEL_CONSTRUCTION_ELEMENT;
......
......@@ -43,6 +43,11 @@ public class TunnelHollow extends AbstractRoom {
parent = handler.getCopyInstance(oHollow.getParent());
}
@Override
public CityObject getTopLevelCityObject() {
return getParent().getTopLevelCityObject();
}
@Override
public void collectInstances(CopyHandler handler) {
super.collectInstances(handler);
......
......@@ -22,6 +22,11 @@ public class TunnelPart extends AbstractTunnel {
return parent;
}
@Override
public CityObject getTopLevelCityObject() {
return getParent().getTopLevelCityObject();
}
@Override
public FeatureType getFeatureType() {
return FeatureType.TUNNEL_PART;
......
......@@ -198,6 +198,11 @@ public class Vegetation extends CityObject {
}
}
@Override
public CityObject getTopLevelCityObject() {
return this;
}
public void setGmlObject(AbstractVegetationObject avo) {
citygmlVegetation = avo;
}
......
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