Skip to main content

egml_core/model/base/
association_attributes_access.rs

1use crate::model::base::AssociationAttributes;
2use crate::model::basic_types::NilReason;
3use crate::model::xlink::{ActuateType, HRef, ShowType};
4
5/// Read-only access to the `gml:AssociationAttributeGroup` on a property element.
6pub trait HasAssociationAttributes {
7    fn association(&self) -> &AssociationAttributes;
8
9    /// `xlink:href` — reference to the geometry object, if not inline.
10    fn href(&self) -> Option<&HRef> {
11        self.association().href.as_ref()
12    }
13
14    /// Bare GML `gml:id` when `href` is a local fragment reference.
15    fn local_id(&self) -> Option<&str> {
16        self.association().local_id()
17    }
18
19    /// `gml:nilReason` — explanation for a missing value.
20    fn nil_reason(&self) -> Option<&NilReason> {
21        self.association().nil_reason.as_ref()
22    }
23
24    /// `xlink:title` — human-readable label for the linked resource.
25    fn title(&self) -> Option<&str> {
26        self.association().title.as_deref()
27    }
28
29    /// `xlink:role` — URI identifying the semantic role of the linked resource.
30    fn role(&self) -> Option<&str> {
31        self.association().role.as_deref()
32    }
33
34    /// `xlink:arcrole` — URI identifying the role of the link arc.
35    fn arcrole(&self) -> Option<&str> {
36        self.association().arcrole.as_deref()
37    }
38
39    /// `xlink:show` — how the linked resource should be presented on traversal.
40    fn show(&self) -> Option<&ShowType> {
41        self.association().show.as_ref()
42    }
43
44    /// `xlink:actuate` — when link traversal should be triggered.
45    fn actuate(&self) -> Option<&ActuateType> {
46        self.association().actuate.as_ref()
47    }
48}
49
50/// Mutable access to the `gml:AssociationAttributeGroup` on a property element.
51pub trait HasAssociationAttributesMut: HasAssociationAttributes {
52    fn association_mut(&mut self) -> &mut AssociationAttributes;
53
54    /// Sets `xlink:href`.
55    fn set_href(&mut self, href: HRef) {
56        self.association_mut().href = Some(href);
57    }
58
59    /// Sets or clears `xlink:href`.
60    fn set_href_opt(&mut self, href: Option<HRef>) {
61        self.association_mut().href = href;
62    }
63
64    /// Clears `xlink:href`.
65    fn clear_href(&mut self) {
66        self.association_mut().href = None;
67    }
68
69    /// Sets `gml:nilReason`.
70    fn set_nil_reason(&mut self, nil_reason: NilReason) {
71        self.association_mut().nil_reason = Some(nil_reason);
72    }
73
74    /// Sets or clears `gml:nilReason`.
75    fn set_nil_reason_opt(&mut self, nil_reason: Option<NilReason>) {
76        self.association_mut().nil_reason = nil_reason;
77    }
78
79    /// Clears `gml:nilReason`.
80    fn clear_nil_reason(&mut self) {
81        self.association_mut().nil_reason = None;
82    }
83
84    /// Sets `xlink:title`.
85    fn set_title(&mut self, title: impl Into<String>) {
86        self.association_mut().title = Some(title.into());
87    }
88
89    /// Sets or clears `xlink:title`.
90    fn set_title_opt(&mut self, title: Option<String>) {
91        self.association_mut().title = title;
92    }
93
94    /// Clears `xlink:title`.
95    fn clear_title(&mut self) {
96        self.association_mut().title = None;
97    }
98
99    /// Sets `xlink:role`.
100    fn set_role(&mut self, role: impl Into<String>) {
101        self.association_mut().role = Some(role.into());
102    }
103
104    /// Sets or clears `xlink:role`.
105    fn set_role_opt(&mut self, role: Option<String>) {
106        self.association_mut().role = role;
107    }
108
109    /// Clears `xlink:role`.
110    fn clear_role(&mut self) {
111        self.association_mut().role = None;
112    }
113
114    /// Sets `xlink:arcrole`.
115    fn set_arcrole(&mut self, arcrole: impl Into<String>) {
116        self.association_mut().arcrole = Some(arcrole.into());
117    }
118
119    /// Sets or clears `xlink:arcrole`.
120    fn set_arcrole_opt(&mut self, arcrole: Option<String>) {
121        self.association_mut().arcrole = arcrole;
122    }
123
124    /// Clears `xlink:arcrole`.
125    fn clear_arcrole(&mut self) {
126        self.association_mut().arcrole = None;
127    }
128
129    /// Sets `xlink:show`.
130    fn set_show(&mut self, show: ShowType) {
131        self.association_mut().show = Some(show);
132    }
133
134    /// Sets or clears `xlink:show`.
135    fn set_show_opt(&mut self, show: Option<ShowType>) {
136        self.association_mut().show = show;
137    }
138
139    /// Clears `xlink:show`.
140    fn clear_show(&mut self) {
141        self.association_mut().show = None;
142    }
143
144    /// Sets `xlink:actuate`.
145    fn set_actuate(&mut self, actuate: ActuateType) {
146        self.association_mut().actuate = Some(actuate);
147    }
148
149    /// Sets or clears `xlink:actuate`.
150    fn set_actuate_opt(&mut self, actuate: Option<ActuateType>) {
151        self.association_mut().actuate = actuate;
152    }
153
154    /// Clears `xlink:actuate`.
155    fn clear_actuate(&mut self) {
156        self.association_mut().actuate = None;
157    }
158}