BridgeObject.java 10.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*-
 *  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;

Matthias Betz's avatar
Matthias Betz committed
21
import java.util.ArrayList;
22
23
import java.util.List;

Matthias Betz's avatar
Matthias Betz committed
24
25
26
27
28
29
import org.citygml4j.core.model.bridge.AbstractBridge;
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;
30
31
32
33
34
35

import de.hft.stuttgart.citydoctor2.check.Check;
import de.hft.stuttgart.citydoctor2.check.CheckError;
import de.hft.stuttgart.citydoctor2.check.CheckId;
import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
import de.hft.stuttgart.citydoctor2.utils.CityGmlUtils;
Matthias Betz's avatar
Matthias Betz committed
36
37
import de.hft.stuttgart.citydoctor2.utils.CopyHandler;
import de.hft.stuttgart.citydoctor2.utils.Copyable;
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

/**
 * Bridge representation object of CityGML bridge objects
 * 
 * @author Matthias Betz
 *
 */
public class BridgeObject extends CityObject {

	private static final long serialVersionUID = 6301112640328373842L;

	public enum BridgeType {
		BRIDGE, BRIDGE_PART
	}

	private AbstractBridge ab;
	private BridgeType type;
Matthias Betz's avatar
Matthias Betz committed
55
56
	
	private List<BridgeObject> parts = null;
Matthias Betz's avatar
Matthias Betz committed
57
	private List<BridgeConstructiveElement> elements = null;
58

Matthias Betz's avatar
Matthias Betz committed
59
	private List<BoundarySurface> boundarySurfaces = new ArrayList<>(2);
Matthias Betz's avatar
Matthias Betz committed
60
	
61
62
63
64
65
66
67
68
69
	public BridgeObject(BridgeType type, AbstractBridge ab) {
		this.ab = ab;
		this.type = type;
	}

	@Override
	public FeatureType getFeatureType() {
		return FeatureType.BRIDGE;
	}
Matthias Betz's avatar
Matthias Betz committed
70
71
72
73
74
75
76
	
	public List<BridgeConstructiveElement> getConstructiveElements() {
		if (elements == null) {
			elements = new ArrayList<>(2);
		}
		return elements;
	}
77
78

	@Override
Matthias Betz's avatar
Matthias Betz committed
79
	public void reCreateGeometries(GeometryFactory factory, ParserConfiguration config) {
80
81
82
83
84
85
86
87
88
		for (Geometry geom : getGeometries()) {
			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);
			}
		}
89
90
91
		for (BoundarySurface bs : boundarySurfaces) {
			bs.reCreateGeometries(factory, config);
		}
Matthias Betz's avatar
Matthias Betz committed
92
93
94
95
96
97
98
99
100
101
		if (parts != null) {
			for (BridgeObject part : parts) {
				part.reCreateGeometries(factory, config);
			}
		}
		if (elements != null) {
			for (BridgeConstructiveElement ele : elements) {
				ele.reCreateGeometries(factory, config);
			}
		}
102
103
104
105
106
	}

	private void setMultiSurfaceAccordingToLod(Geometry geom, MultiSurface ms) {
		switch (geom.getLod()) {
		case LOD1:
Matthias Betz's avatar
Matthias Betz committed
107
			ab.getDeprecatedProperties().setLod1MultiSurface(new MultiSurfaceProperty(ms));
108
109
110
111
112
113
114
115
			break;
		case LOD2:
			ab.setLod2MultiSurface(new MultiSurfaceProperty(ms));
			break;
		case LOD3:
			ab.setLod3MultiSurface(new MultiSurfaceProperty(ms));
			break;
		case LOD4:
Matthias Betz's avatar
Matthias Betz committed
116
			ab.getDeprecatedProperties().setLod4MultiSurface(new MultiSurfaceProperty(ms));
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
			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:
Matthias Betz's avatar
Matthias Betz committed
135
			ab.getDeprecatedProperties().setLod4Solid(new SolidProperty(solid));
136
137
138
139
140
141
142
143
144
145
146
147
			break;
		default:
			throw new IllegalStateException("Cannot add " + geom.getLod() + " solid to bridges");
		}
	}

	@Override
	public void clearAllContainedCheckResults() {
		super.clearAllContainedCheckResults();
		for (BoundarySurface bs : boundarySurfaces) {
			bs.clearAllContainedCheckResults();
		}
Matthias Betz's avatar
Matthias Betz committed
148
149
150
151
152
153
154
155
156
157
		if (parts != null) {
			for (BridgeObject part : parts) {
				part.clearAllContainedCheckResults();
			}
		}
		if (elements != null) {
			for (BridgeConstructiveElement ele : elements) {
				ele.clearAllContainedCheckResults();
			}
		}
158
159
160
161
162
163
164
165
	}

	@Override
	public void collectContainedErrors(List<CheckError> errors) {
		super.collectContainedErrors(errors);
		for (BoundarySurface bs : boundarySurfaces) {
			bs.collectContainedErrors(errors);
		}
Matthias Betz's avatar
Matthias Betz committed
166
167
168
169
170
171
172
173
174
175
		if (parts != null) {
			for (BridgeObject part : parts) {
				part.collectContainedErrors(errors);
			}
		}
		if (elements != null) {
			for (BridgeConstructiveElement ele : elements) {
				ele.collectContainedErrors(errors);
			}
		}
176
177
178
179
180
181
182
183
184
185
186
187
188
	}

	@Override
	public boolean containsAnyError() {
		boolean hasError = super.containsAnyError();
		if (hasError) {
			return true;
		}
		for (BoundarySurface bs : boundarySurfaces) {
			if (bs.containsAnyError()) {
				return true;
			}
		}
Matthias Betz's avatar
Matthias Betz committed
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
		if (doPartsContainAnyError()) {
			return true;
		}
		if (elements != null) {
			for (BridgeConstructiveElement ele : elements) {
				if (ele.containsAnyError()) {
					return true;
				}
			}
		}
		return false;
	}

	private boolean doPartsContainAnyError() {
		if (parts != null) {
			for (BridgeObject part : parts) {
				if (part.containsAnyError()) {
					return true;
				}
			}
		}
210
211
212
213
214
215
216
217
218
219
220
221
222
223
		return false;
	}

	@Override
	public boolean containsError(CheckId checkIdentifier) {
		boolean hasError = super.containsError(checkIdentifier);
		if (hasError) {
			return true;
		}
		for (BoundarySurface bs : boundarySurfaces) {
			if (bs.containsError(checkIdentifier)) {
				return true;
			}
		}
Matthias Betz's avatar
Matthias Betz committed
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
		if (doPartsContainError(checkIdentifier)) {
			return true;
		}
		if (elements != null) {
			for (BridgeConstructiveElement ele : elements) {
				if (ele.containsError(checkIdentifier)) {
					return true;
				}
			}
		}
		return false;
	}

	private boolean doPartsContainError(CheckId checkIdentifier) {
		if (parts != null) {
			for (BridgeObject part : parts) {
				if (part.containsError(checkIdentifier)) {
					return true;
				}
			}
		}
245
246
247
248
249
250
251
252
253
		return false;
	}

	@Override
	public void accept(Check c) {
		super.accept(c);
		if (c.canExecute(this)) {
			c.check(this);
		}
254
255
256
		for (BoundarySurface bs : boundarySurfaces) {
			bs.accept(c);
		}
Matthias Betz's avatar
Matthias Betz committed
257
258
259
260
261
262
263
264
265
266
		if (parts != null) {
			for (BridgeObject part : parts) {
				part.accept(c);
			}
		}
		if (elements != null) {
			for (BridgeConstructiveElement ele : elements) {
				ele.accept(c);
			}
		}
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
	}

	/**
	 * 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 AbstractBridge getGmlObject() {
		return ab;
	}

	@Override
	public void unsetGmlGeometries() {
Matthias Betz's avatar
Matthias Betz committed
299
300
301
302
303
304
305
306
		ab.setLod1Solid(null);
		ab.setLod2Solid(null);
		ab.setLod3Solid(null);
		ab.setLod2MultiSurface(null);
		ab.setLod3MultiSurface(null);
		ab.getDeprecatedProperties().setLod1MultiSurface(null);
		ab.getDeprecatedProperties().setLod4MultiSurface(null);
		ab.getDeprecatedProperties().setLod4Solid(null);
307
308
309
		for (BoundarySurface bs : boundarySurfaces) {
			bs.unsetGmlGeometries();
		}
Matthias Betz's avatar
Matthias Betz committed
310
311
312
313
314
315
316
317
318
319
		if (parts != null) {
			for (BridgeObject part : parts) {
				part.unsetGmlGeometries();
			}
		}
		if (elements != null) {
			for (BridgeConstructiveElement ele : elements) {
				ele.unsetGmlGeometries();
			}
		}
320
321
322
323
324
325
326
327
328
329
	}

	public void setGmlObject(AbstractBridge aBridge) {
		ab = aBridge;
	}

	@Override
	public String toString() {
		return "BridgeObject [type=" + type + ", id=" + getGmlId() + "]";
	}
330

331
332
333
334
335
336
337
	@Override
	public void prepareForChecking() {
		super.prepareForChecking();
		for (BoundarySurface bs : boundarySurfaces) {
			bs.prepareForChecking();
		}
	}
338

339
340
341
342
343
344
	@Override
	public void clearMetaInformation() {
		super.clearMetaInformation();
		for (BoundarySurface bs : boundarySurfaces) {
			bs.clearMetaInformation();
		}
Matthias Betz's avatar
Matthias Betz committed
345
346
347
348
349
350
351
352
353
354
		if (parts != null) {
			for (BridgeObject part : parts) {
				part.clearMetaInformation();
			}
		}
		if (elements != null) {
			for (BridgeConstructiveElement ele : elements) {
				ele.clearMetaInformation();
			}
		}
355
	}
Matthias Betz's avatar
Matthias Betz committed
356
357
358
359
360
361
362
	
	@Override
	public void collectInstances(CopyHandler handler) {
		super.collectInstances(handler);
		for (BoundarySurface bs : boundarySurfaces) {
			handler.addInstance(bs);
		}
Matthias Betz's avatar
Matthias Betz committed
363
364
365
366
367
368
369
370
371
372
		if (parts != null) {
			for (BridgeObject part : parts) {
				handler.addInstance(part);
			}
		}
		if (elements != null) {
			for (BridgeConstructiveElement ele : elements) {
				handler.addInstance(ele);
			}
		}
Matthias Betz's avatar
Matthias Betz committed
373
374
375
376
377
378
379
380
381
	}
	
	@Override
	public void fillValues(Copyable original, CopyHandler handler) {
		super.fillValues(original, handler);
		BridgeObject originalBo = (BridgeObject) original;
		for (BoundarySurface originalBs : originalBo.boundarySurfaces) {
			boundarySurfaces.add(handler.getCopyInstance(originalBs));
		}
Matthias Betz's avatar
Matthias Betz committed
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
		if (parts != null) {
			for (BridgeObject part : parts) {
				handler.addInstance(part);
			}
		}
		if (elements != null) {
			for (BridgeConstructiveElement ele : elements) {
				handler.addInstance(ele);
			}
		}
	}
	
	public List<BoundarySurface> getBoundarySurfaces() {
		return boundarySurfaces;
	}
	
	public void addConstructiveElement(BridgeConstructiveElement element) {
		getConstructiveElements().add(element);
Matthias Betz's avatar
Matthias Betz committed
400
401
402
403
404
405
	}

	@Override
	public Copyable createCopyInstance() {
		return new BridgeObject(type, ab);
	}
Matthias Betz's avatar
Matthias Betz committed
406
407
408
409
410
411
412
413
414
	
	public List<BridgeObject> getParts() {
		if (parts == null) {
			parts  = new ArrayList<>(2);
		}
		return parts;
	}

	public void addBridgePart(BridgeObject bPart) {
Matthias Betz's avatar
Matthias Betz committed
415
		getParts().add(bPart);
Matthias Betz's avatar
Matthias Betz committed
416
	}
Matthias Betz's avatar
Matthias Betz committed
417
	
418
}