|
2 | 2 | //!
|
3 | 3 | //! See [`Layers`].
|
4 | 4 |
|
5 |
| -mod layer; |
6 |
| -mod objects; |
7 |
| -mod validation; |
| 5 | +pub mod objects; |
| 6 | +pub mod validation; |
8 | 7 |
|
9 |
| -use crate::{ |
10 |
| - objects::{AboutToBeStored, AnyObject, Objects}, |
11 |
| - validate::{ValidationConfig, ValidationErrors}, |
12 |
| -}; |
| 8 | +mod layer; |
| 9 | +mod layers; |
13 | 10 |
|
14 | 11 | pub use self::{
|
15 | 12 | layer::{Layer, State},
|
16 |
| - objects::{InsertObject, Operation}, |
17 |
| - validation::{Validation, ValidationCommand, ValidationEvent}, |
| 13 | + layers::Layers, |
18 | 14 | };
|
19 |
| - |
20 |
| -/// # Loosely coupled layers, that together define shapes |
21 |
| -/// |
22 |
| -/// Shapes are not a monolithic thing in Fornjot, but instead are defined by |
23 |
| -/// several, loosely coupled layers. These layers are owned by this struct. |
24 |
| -/// |
25 |
| -/// ## Implementation Note |
26 |
| -/// |
27 |
| -/// It is totally conceivable that one day, this system of layers is extensible |
28 |
| -/// and more layers can be defined by third-party code. The foundation for that, |
29 |
| -/// the loose coupling and inter-layer communication via events, is already |
30 |
| -/// there, conceptually. |
31 |
| -/// |
32 |
| -/// For now, there is no need for this, and all layers are just hardcoded here. |
33 |
| -/// That can be changed, once necessary. |
34 |
| -#[derive(Default)] |
35 |
| -pub struct Layers { |
36 |
| - /// The objects layers |
37 |
| - /// |
38 |
| - /// Manages the stores of topological and geometric objects that make up |
39 |
| - /// shapes. |
40 |
| - pub objects: Layer<Objects>, |
41 |
| - |
42 |
| - /// The validation layer |
43 |
| - /// |
44 |
| - /// Monitors objects and validates them, as they are inserted. |
45 |
| - pub validation: Layer<Validation>, |
46 |
| -} |
47 |
| - |
48 |
| -impl Layers { |
49 |
| - /// Construct an instance of `Layers` |
50 |
| - pub fn new() -> Self { |
51 |
| - Self::default() |
52 |
| - } |
53 |
| - |
54 |
| - /// Construct an instance of `Layers`, using the provided configuration |
55 |
| - pub fn with_validation_config(config: ValidationConfig) -> Self { |
56 |
| - let objects = Layer::default(); |
57 |
| - let validation = Layer::new(Validation::with_validation_config(config)); |
58 |
| - |
59 |
| - Self { |
60 |
| - objects, |
61 |
| - validation, |
62 |
| - } |
63 |
| - } |
64 |
| - |
65 |
| - /// Insert an object into the stores |
66 |
| - pub fn insert_object(&mut self, object: AnyObject<AboutToBeStored>) { |
67 |
| - let mut object_events = Vec::new(); |
68 |
| - self.objects |
69 |
| - .process(Operation::InsertObject { object }, &mut object_events); |
70 |
| - |
71 |
| - for object_event in object_events { |
72 |
| - let command = ValidationCommand::ValidateObject { |
73 |
| - object: object_event.object.into(), |
74 |
| - }; |
75 |
| - self.validation.process(command, &mut Vec::new()); |
76 |
| - } |
77 |
| - } |
78 |
| - |
79 |
| - /// Drop `Layers`; return any unhandled validation error |
80 |
| - pub fn drop_and_validate(self) -> Result<(), ValidationErrors> { |
81 |
| - let errors = self.validation.into_state().into_errors(); |
82 |
| - |
83 |
| - if errors.0.is_empty() { |
84 |
| - Ok(()) |
85 |
| - } else { |
86 |
| - Err(errors) |
87 |
| - } |
88 |
| - } |
89 |
| -} |
0 commit comments