ecitygml_core/operations/
visitor.rs

1use crate::model::building::{Building, BuildingConstructiveElement};
2use crate::model::city_furniture::CityFurniture;
3use crate::model::city_model::CitygmlModel;
4use crate::model::construction::{
5    DoorSurface, GroundSurface, RoofSurface, WallSurface, WindowSurface,
6};
7use crate::model::solitary_vegetation_object::SolitaryVegetationObject;
8use crate::model::transportation::{
9    AuxiliaryTrafficArea, AuxiliaryTrafficSpace, Intersection, Road, Section, TrafficArea,
10    TrafficSpace,
11};
12
13pub trait Visitable {
14    fn accept<V: CityObjectVisitor>(&self, visitor: &mut V);
15}
16
17pub trait CityObjectVisitor {
18    type Result;
19
20    fn visit_city_model(&mut self, v: &CitygmlModel) -> Self::Result;
21
22    fn visit_city_furniture(&mut self, v: &CityFurniture) -> Self::Result;
23
24    fn visit_building(&mut self, v: &Building) -> Self::Result;
25    fn visit_building_constructive_element(
26        &mut self,
27        v: &BuildingConstructiveElement,
28    ) -> Self::Result;
29    fn visit_roof_surface(&mut self, v: &RoofSurface) -> Self::Result;
30    fn visit_ground_surface(&mut self, v: &GroundSurface) -> Self::Result;
31    fn visit_wall_surface(&mut self, v: &WallSurface) -> Self::Result;
32    fn visit_window_surface(&mut self, v: &WindowSurface) -> Self::Result;
33    fn visit_door_surface(&mut self, v: &DoorSurface) -> Self::Result;
34
35    fn visit_solitary_vegetation_object(&mut self, v: &SolitaryVegetationObject) -> Self::Result;
36
37    fn visit_road(&mut self, v: &Road) -> Self::Result;
38    fn visit_section(&mut self, v: &Section) -> Self::Result;
39    fn visit_intersection(&mut self, v: &Intersection) -> Self::Result;
40    fn visit_traffic_space(&mut self, v: &TrafficSpace) -> Self::Result;
41    fn visit_auxiliary_traffic_space(&mut self, v: &AuxiliaryTrafficSpace) -> Self::Result;
42    fn visit_traffic_area(&mut self, v: &TrafficArea) -> Self::Result;
43    fn visit_auxiliary_traffic_area(&mut self, v: &AuxiliaryTrafficArea) -> Self::Result;
44}
45
46pub struct Interpreter;
47
48impl Default for Interpreter {
49    fn default() -> Self {
50        Self::new()
51    }
52}
53
54impl Interpreter {
55    pub fn new() -> Self {
56        Self {}
57    }
58}
59impl CityObjectVisitor for Interpreter {
60    type Result = ();
61
62    fn visit_city_model(&mut self, v: &CitygmlModel) -> Self::Result {
63        println!("hello city_model");
64    }
65
66    fn visit_city_furniture(&mut self, v: &CityFurniture) -> Self::Result {
67        println!(
68            "hello city_furniture {}",
69            v.occupied_space.space.city_object.abstract_gml.id
70        );
71    }
72
73    fn visit_building(&mut self, v: &Building) -> Self::Result {
74        println!(
75            "hello building {}",
76            v.occupied_space.space.city_object.abstract_gml.id
77        );
78    }
79
80    fn visit_building_constructive_element(
81        &mut self,
82        v: &BuildingConstructiveElement,
83    ) -> Self::Result {
84        println!(
85            "hello building_constructive_element {}",
86            v.occupied_space.space.city_object.abstract_gml.id
87        );
88    }
89
90    fn visit_roof_surface(&mut self, v: &RoofSurface) -> Self::Result {
91        println!(
92            "hello roof_surface {}",
93            v.thematic_surface.city_object.abstract_gml.id
94        );
95    }
96
97    fn visit_ground_surface(&mut self, v: &GroundSurface) -> Self::Result {
98        println!(
99            "hello ground_surface {}",
100            v.thematic_surface.city_object.abstract_gml.id
101        );
102    }
103
104    fn visit_wall_surface(&mut self, v: &WallSurface) -> Self::Result {
105        println!(
106            "hello wall_surface {}",
107            v.thematic_surface.city_object.abstract_gml.id
108        );
109    }
110
111    fn visit_window_surface(&mut self, v: &WindowSurface) -> Self::Result {
112        println!(
113            "hello window_surface {}",
114            v.occupied_space.space.city_object.abstract_gml.id
115        );
116    }
117
118    fn visit_door_surface(&mut self, v: &DoorSurface) -> Self::Result {
119        println!(
120            "hello door_surface {}",
121            v.occupied_space.space.city_object.abstract_gml.id
122        );
123    }
124
125    fn visit_solitary_vegetation_object(&mut self, v: &SolitaryVegetationObject) -> Self::Result {
126        println!(
127            "hello solitary_vegetation_object {}",
128            v.occupied_space.space.city_object.abstract_gml.id
129        );
130    }
131
132    fn visit_road(&mut self, v: &Road) -> Self::Result {
133        println!("hello road {}", v.space.city_object.abstract_gml.id);
134    }
135
136    fn visit_section(&mut self, v: &Section) -> Self::Result {
137        println!("hello section {}", v.space.city_object.abstract_gml.id);
138    }
139
140    fn visit_intersection(&mut self, v: &Intersection) -> Self::Result {
141        println!("hello intersection {}", v.space.city_object.abstract_gml.id);
142    }
143
144    fn visit_traffic_space(&mut self, v: &TrafficSpace) -> Self::Result {
145        println!(
146            "hello traffic_space {}",
147            v.space.city_object.abstract_gml.id
148        );
149    }
150
151    fn visit_auxiliary_traffic_space(&mut self, v: &AuxiliaryTrafficSpace) -> Self::Result {
152        println!(
153            "hello auxiliary_traffic_space {}",
154            v.space.city_object.abstract_gml.id
155        );
156    }
157
158    fn visit_traffic_area(&mut self, v: &TrafficArea) -> Self::Result {
159        println!(
160            "hello traffic_area {}",
161            v.thematic_surface.city_object.abstract_gml.id
162        );
163    }
164
165    fn visit_auxiliary_traffic_area(&mut self, v: &AuxiliaryTrafficArea) -> Self::Result {
166        println!(
167            "hello auxiliary_traffic_area {}",
168            v.thematic_surface.city_object.abstract_gml.id
169        );
170    }
171}