pub struct Document { /* private fields */ }Expand description
A model with product structure, appearance and names over it.
The model stays reachable (construction, booleans and measurement all operate on it directly), and the document adds what a model alone does not say: which shapes are products, how they assemble, what they are called and what colour they are.
Implementations§
Source§impl Document
impl Document
Sourcepub fn add_part(&mut self, name: impl Into<String>, shape: Shape) -> ProductId
pub fn add_part(&mut self, name: impl Into<String>, shape: Shape) -> ProductId
Add a part: a named product carrying a shape.
Sourcepub fn add_assembly(&mut self, name: impl Into<String>) -> ProductId
pub fn add_assembly(&mut self, name: impl Into<String>) -> ProductId
Add an empty assembly.
Sourcepub fn add_instance(
&mut self,
assembly: ProductId,
product: ProductId,
at: Transform,
name: Option<String>,
) -> OgeomResult<()>
pub fn add_instance( &mut self, assembly: ProductId, product: ProductId, at: Transform, name: Option<String>, ) -> OgeomResult<()>
Place product inside assembly at at.
The transform becomes a datum in the model’s own store, so the instance’s placement is structural (comparable by identity, shared by every traversal) rather than a matrix to be compared with an epsilon.
§Errors
OgeomError::Construction if
assembly is not an assembly, or placing product there would make a
product contain itself;
OgeomError::Dangling if either id
is not in this document.
Sourcepub fn add_instance_at(
&mut self,
assembly: ProductId,
product: ProductId,
location: Location,
name: Option<String>,
) -> OgeomResult<()>
pub fn add_instance_at( &mut self, assembly: ProductId, product: ProductId, location: Location, name: Option<String>, ) -> OgeomResult<()>
Place product inside assembly at an already-resolved location.
The persistence path: a file carries the instance’s location chain
verbatim, and re-minting a datum for it would renumber what the file
preserved. Checks are as Document::add_instance.
§Errors
Sourcepub fn products(&self) -> impl Iterator<Item = (ProductId, &Product)>
pub fn products(&self) -> impl Iterator<Item = (ProductId, &Product)>
Every product, in the order added.
Sourcepub fn occurrences_of(&self, product: ProductId) -> OgeomResult<Vec<Occurrence>>
pub fn occurrences_of(&self, product: ProductId) -> OgeomResult<Vec<Occurrence>>
Every placed part under product, shapes moved into world space.
The flattening every consumer of an assembly wants: two instances of one part come back as two occurrences whose shapes share a topology node and differ only in their location chains.
§Errors
OgeomError::Dangling if product
is not in this document.
Sourcepub fn set_product_colour(
&mut self,
product: ProductId,
colour: Colour,
) -> OgeomResult<()>
pub fn set_product_colour( &mut self, product: ProductId, colour: Colour, ) -> OgeomResult<()>
Colour a product: the fallback for everything in it.
§Errors
OgeomError::Dangling if product
is not in this document.
Sourcepub fn add_texture(&mut self, texture: Texture) -> TextureId
pub fn add_texture(&mut self, texture: Texture) -> TextureId
Add a texture the document can lay on shapes.
Sourcepub fn set_texture(&mut self, shape: &Shape, texture: TextureId)
pub fn set_texture(&mut self, shape: &Shape, texture: TextureId)
Lay a texture on a shape, replacing whatever was on it.
Sourcepub fn texture_of(&self, shape: &Shape) -> Option<&Texture>
pub fn texture_of(&self, shape: &Shape) -> Option<&Texture>
The texture on a shape, if it has one.
Sourcepub fn textures(&self) -> &[Texture]
pub fn textures(&self) -> &[Texture]
Every texture the document holds, in the order they were added.
Sourcepub fn checkpoint(&mut self)
pub fn checkpoint(&mut self)
Mark the document’s current state as one an undo can return to.
Call it before the change a caller might want back. Anything undone and not redone is dropped at the next checkpoint, which is the usual rule: a new branch replaces the abandoned one.
Sourcepub fn undo_depth(&self) -> (usize, usize)
pub fn undo_depth(&self) -> (usize, usize)
How many steps back are available, and how many forward.
Sourcepub fn product_index(&self, id: ProductId) -> usize
pub fn product_index(&self, id: ProductId) -> usize
The position of a product in write order: how the native format refers to one across a save.
Sourcepub fn add_view(&mut self, view: View) -> usize
pub fn add_view(&mut self, view: View) -> usize
Add a saved view; its index is how STEP and the native format refer to it.
Sourcepub fn set_colour(&mut self, shape: &Shape, colour: Colour)
pub fn set_colour(&mut self, shape: &Shape, colour: Colour)
Colour a shape: a whole part’s shape or one sub-shape of it.
Keyed by the topology node, so every occurrence of an instanced shape shows the colour: the colour belongs to the entity, not to one placement of it.
Sourcepub fn colour_of(&self, shape: &Shape) -> Option<Colour>
pub fn colour_of(&self, shape: &Shape) -> Option<Colour>
The colour set directly on a shape’s node, if any.
Sourcepub fn resolved_colour(&self, part: ProductId, sub: &Shape) -> Option<Colour>
pub fn resolved_colour(&self, part: ProductId, sub: &Shape) -> Option<Colour>
The colour a sub-shape of a part actually shows.
Most specific wins: the sub-shape’s own colour, else the colour of the part’s whole shape, else the product’s, else nothing.
Sourcepub fn set_name(&mut self, shape: &Shape, name: impl Into<String>)
pub fn set_name(&mut self, shape: &Shape, name: impl Into<String>)
Name a shape’s node: a face someone will want to find again.
Sourcepub fn colours(&self) -> impl Iterator<Item = (TShapeId, Colour)> + '_
pub fn colours(&self) -> impl Iterator<Item = (TShapeId, Colour)> + '_
Every node-attached colour, for a writer to carry out.
Sourcepub fn names(&self) -> impl Iterator<Item = (TShapeId, &str)>
pub fn names(&self) -> impl Iterator<Item = (TShapeId, &str)>
Every node-attached name, for a writer to carry out.
Sourcepub fn replace_part_shape(
&mut self,
product: ProductId,
shape: Shape,
) -> OgeomResult<()>
pub fn replace_part_shape( &mut self, product: ProductId, shape: Shape, ) -> OgeomResult<()>
Replace a part’s shape: the modification step of an edit.
The old shape’s node-attached colours, names and PMI stay where they are: entities that survived the modification keep their annotations, entities that did not simply no longer resolve.
§Errors
OgeomError::Construction if
product is not a part;
OgeomError::Dangling if it is not
in this document.
Sourcepub fn set_property(&mut self, shape: &Shape, property: Property)
pub fn set_property(&mut self, shape: &Shape, property: Property)
Pin a user-defined property to a shape. Properties accumulate; a repeated name replaces the earlier value.
Sourcepub fn properties_of(&self, shape: &Shape) -> &[Property]
pub fn properties_of(&self, shape: &Shape) -> &[Property]
The properties pinned to a shape.
Sourcepub fn properties(&self) -> impl Iterator<Item = (TShapeId, &[Property])>
pub fn properties(&self) -> impl Iterator<Item = (TShapeId, &[Property])>
Every shape with properties, for persistence.
Sourcepub fn add_material(&mut self, material: Material) -> MaterialId
pub fn add_material(&mut self, material: Material) -> MaterialId
Add a material to the document’s list.
Sourcepub fn material(&self, id: MaterialId) -> Option<&Material>
pub fn material(&self, id: MaterialId) -> Option<&Material>
A material by id.
Sourcepub fn material_id(&self, index: usize) -> Option<MaterialId>
pub fn material_id(&self, index: usize) -> Option<MaterialId>
The id at a list position, for rebinding persisted references.
Sourcepub fn assign_material(&mut self, shape: &Shape, id: MaterialId)
pub fn assign_material(&mut self, shape: &Shape, id: MaterialId)
Assign a shape its material.
Sourcepub fn material_of(&self, shape: &Shape) -> Option<MaterialId>
pub fn material_of(&self, shape: &Shape) -> Option<MaterialId>
The material a shape is assigned, if any.
Sourcepub fn material_assignments(
&self,
) -> impl Iterator<Item = (TShapeId, MaterialId)> + '_
pub fn material_assignments( &self, ) -> impl Iterator<Item = (TShapeId, MaterialId)> + '_
Every material assignment, for persistence.
Sourcepub fn add_layer(&mut self, name: impl Into<String>) -> LayerId
pub fn add_layer(&mut self, name: impl Into<String>) -> LayerId
Add a layer, visible by default.
Sourcepub fn layer_id(&self, index: usize) -> Option<LayerId>
pub fn layer_id(&self, index: usize) -> Option<LayerId>
The id at a list position, for rebinding persisted references.
Sourcepub fn set_layer_visible(&mut self, id: LayerId, visible: bool)
pub fn set_layer_visible(&mut self, id: LayerId, visible: bool)
Show or hide a layer.
Sourcepub fn place_on_layer(&mut self, shape: &Shape, layer: LayerId)
pub fn place_on_layer(&mut self, shape: &Shape, layer: LayerId)
Put a shape on a layer. A shape may sit on several.
Sourcepub fn layer_memberships(&self) -> impl Iterator<Item = (TShapeId, &[LayerId])>
pub fn layer_memberships(&self) -> impl Iterator<Item = (TShapeId, &[LayerId])>
Every layer membership, for persistence.
Sourcepub fn set_validation(&mut self, shape: &Shape, values: ValidationProperties)
pub fn set_validation(&mut self, shape: &Shape, values: ValidationProperties)
Record validation values for a shape.
Sourcepub fn validation_of(&self, shape: &Shape) -> Option<ValidationProperties>
pub fn validation_of(&self, shape: &Shape) -> Option<ValidationProperties>
The recorded validation values for a shape.
Sourcepub fn validations(
&self,
) -> impl Iterator<Item = (TShapeId, ValidationProperties)> + '_
pub fn validations( &self, ) -> impl Iterator<Item = (TShapeId, ValidationProperties)> + '_
Every validation record, for persistence.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Document
impl RefUnwindSafe for Document
impl Send for Document
impl Sync for Document
impl Unpin for Document
impl UnsafeUnpin for Document
impl UnwindSafe for Document
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.