fj_core/layers/layers.rs
1use crate::{
2 geometry::Geometry,
3 objects::Objects,
4 presentation::Presentation,
5 validation::{Validation, ValidationConfig},
6};
7
8use super::Layer;
9
10/// # Loosely coupled layers, that together define shapes
11///
12/// Shapes are not a monolithic thing in Fornjot, but instead are defined by
13/// several, loosely coupled layers. These layers are owned by this struct.
14///
15/// ## Implementation Note
16///
17/// It is totally conceivable that one day, this system of layers is extensible
18/// and more layers can be defined by third-party code. The foundation for that,
19/// the loose coupling and inter-layer communication via events, is already
20/// there, conceptually.
21///
22/// For now, there is no need for this, and all layers are just hardcoded here.
23/// That can be changed, once necessary.
24pub struct Layers {
25 /// The objects layer
26 ///
27 /// Manages the stores of topological and geometric objects that make up
28 /// shapes.
29 pub objects: Layer<Objects>,
30
31 /// The geometry layer
32 ///
33 /// Manages geometric information that applies to topological objects.
34 pub geometry: Layer<Geometry>,
35
36 /// The validation layer
37 ///
38 /// Monitors objects and validates them, as they are inserted.
39 pub validation: Layer<Validation>,
40
41 /// The presentation layer
42 ///
43 /// Stores data concerning the presentation of objects.
44 pub presentation: Layer<Presentation>,
45}
46
47impl Layers {
48 /// Construct an instance of `Layers`
49 pub fn new() -> Self {
50 let objects = Objects::new();
51 let geometry = Geometry::new(&objects);
52
53 Self {
54 objects: Layer::new(objects),
55 geometry: Layer::new(geometry),
56 validation: Layer::default(),
57 presentation: Layer::default(),
58 }
59 }
60
61 /// Construct an instance of `Layers`, using the provided configuration
62 pub fn with_validation_config(config: ValidationConfig) -> Self {
63 Self {
64 validation: Layer::new(Validation::with_validation_config(config)),
65 ..Self::new()
66 }
67 }
68}
69
70impl Default for Layers {
71 fn default() -> Self {
72 Self::new()
73 }
74}