BridgeConstructiveElement.java 5.67 KB
Newer Older
Matthias Betz's avatar
Matthias Betz committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*-
 *  Copyright 2022 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.citygml4j.core.model.deprecated.bridge.DeprecatedPropertiesOfBridgeConstructiveElement;
import org.citygml4j.core.util.geometry.GeometryFactory;
import org.xmlobjects.gml.model.geometry.GeometryProperty;
import org.xmlobjects.gml.model.geometry.aggregates.MultiSurface;
import org.xmlobjects.gml.model.geometry.aggregates.MultiSurfaceProperty;
import org.xmlobjects.gml.model.geometry.complexes.CompositeSurface;
import org.xmlobjects.gml.model.geometry.primitives.Solid;
import org.xmlobjects.gml.model.geometry.primitives.SolidProperty;

import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
import de.hft.stuttgart.citydoctor2.utils.CityGmlUtils;
import de.hft.stuttgart.citydoctor2.utils.Copyable;

public class BridgeConstructiveElement extends CityObject {

	private static final String CANNOT_ADD = "Cannot add ";

	private static final long serialVersionUID = 7353233899458901155L;

	private org.citygml4j.core.model.bridge.BridgeConstructiveElement gmlBridgeElement;

	public BridgeConstructiveElement(org.citygml4j.core.model.bridge.BridgeConstructiveElement gmlObject) {
		this.gmlBridgeElement = gmlObject;
	}

	@Override
	public Copyable createCopyInstance() {
		return new BridgeConstructiveElement(gmlBridgeElement);
	}

	@Override
	public void reCreateGeometries(GeometryFactory factory, ParserConfiguration config) {
		// only handles CityGML2 for now
		// unknown which CityGML is handled here
		// need context information to decide
		for (Geometry geom : getGeometries()) {
			switch (geom.getType()) {
			case SOLID:
				Solid solid = CityGmlUtils.createSolid(geom, factory, config);
				setSolidAccordingToLod(geom, solid);
				break;
			case MULTI_SURFACE:
				MultiSurface ms = CityGmlUtils.createMultiSurface(geom, factory, config);
				setMultiSurfaceAccordingToLod(geom, ms);
				break;
			case COMPOSITE_SURFACE:
				CompositeSurface cs = CityGmlUtils.createCompositeSurface(geom, factory, config);
				setCompositeSurfaceAccordingToLod(geom, cs);
				break;
			}
		}
	}

	private void setCompositeSurfaceAccordingToLod(Geometry geom, CompositeSurface cs) {
		switch (geom.getLod()) {
		case LOD1:
			gmlBridgeElement.getDeprecatedProperties().setLod1Geometry(new GeometryProperty<>(cs));
			break;
		case LOD2:
			gmlBridgeElement.getDeprecatedProperties().setLod2Geometry(new GeometryProperty<>(cs));
			break;
		case LOD3:
			gmlBridgeElement.getDeprecatedProperties().setLod3Geometry(new GeometryProperty<>(cs));
			break;
		case LOD4:
			gmlBridgeElement.getDeprecatedProperties().setLod4Geometry(new GeometryProperty<>(cs));
			break;
		default:
			throw new IllegalStateException(CANNOT_ADD + geom.getLod() + " composite surface to buildings");
		}		
	}

	private void setSolidAccordingToLod(Geometry geom, Solid solid) {
		switch (geom.getLod()) {
		case LOD1:
			gmlBridgeElement.getDeprecatedProperties().setLod1Geometry(new SolidProperty(solid));
			break;
		case LOD2:
			gmlBridgeElement.getDeprecatedProperties().setLod2Geometry(new SolidProperty(solid));
			break;
		case LOD3:
			gmlBridgeElement.getDeprecatedProperties().setLod3Geometry(new SolidProperty(solid));
			break;
		case LOD4:
			gmlBridgeElement.getDeprecatedProperties().setLod4Geometry(new SolidProperty(solid));
			break;
		default:
			throw new IllegalStateException(CANNOT_ADD + geom.getLod() + " solid to buildings");
		}
	}
	
	private void setMultiSurfaceAccordingToLod(Geometry geom, MultiSurface ms) {
		switch (geom.getLod()) {
		case LOD0:
			gmlBridgeElement.getDeprecatedProperties().setLod1Geometry(new MultiSurfaceProperty(ms));
			break;
		case LOD1:
			gmlBridgeElement.getDeprecatedProperties().setLod1Geometry(new MultiSurfaceProperty(ms));
			break;
		case LOD2:
			gmlBridgeElement.getDeprecatedProperties().setLod1Geometry(new MultiSurfaceProperty(ms));
			break;
		case LOD3:
			gmlBridgeElement.getDeprecatedProperties().setLod1Geometry(new MultiSurfaceProperty(ms));
			break;
		case LOD4:
			gmlBridgeElement.getDeprecatedProperties().setLod1Geometry(new MultiSurfaceProperty(ms));
			break;
		default:
			throw new IllegalStateException(CANNOT_ADD + geom.getLod() + " multi surface to buildings");
		}
	}

	@Override
	public org.citygml4j.core.model.bridge.BridgeConstructiveElement getGmlObject() {
		return gmlBridgeElement;
	}

	@Override
	public void unsetGmlGeometries() {
		gmlBridgeElement.setLod0MultiSurface(null);
		gmlBridgeElement.setLod2MultiSurface(null);
		gmlBridgeElement.setLod3MultiSurface(null);
		DeprecatedPropertiesOfBridgeConstructiveElement depProps = gmlBridgeElement.getDeprecatedProperties();
		depProps.setLod1Geometry(null);
		depProps.setLod2Geometry(null);
		depProps.setLod3Geometry(null);
		depProps.setLod4Geometry(null);
		gmlBridgeElement.setLod1Solid(null);
		gmlBridgeElement.setLod2Solid(null);
		gmlBridgeElement.setLod3Solid(null);
	}

	@Override
	public FeatureType getFeatureType() {
		return FeatureType.BRIDGE_CONSTRUCTION_ELEMENT;
	}

}