pub struct StyleIndex<'m, 's> { /* private fields */ }Expand description
Every style assignment of a model, indexed once, for colour lookups by item and by material.
StyleView::resolve_item_style
scans the model per item, which is fine for one item and quadratic for
every item of every product; the index finds an item’s IfcStyledItems
and layers, and a material’s IfcMaterialDefinitionRepresentations,
through the entities that reference them (#608). A malformed record is
refused by the lookups that reach it, not by new. Several records on
one item or material are read in ascending id.
§Precedence
A viewer paints a surface with the colour of an IfcSurfaceStyle’s
IfcSurfaceStyleShading (or its IfcSurfaceStyleRendering subtype).
The style reaches a representation item in one of three ways, and
StyleIndex answers each of them separately:
- The item. An
IfcStyledItemwhoseItemis the representation item (StyleIndex::item_colour,ColourSource::StyledItem). - Its presentation layer. An
IfcPresentationLayerWithStylewhoseAssignedItemsinclude it (StyleIndex::item_colour,ColourSource::PresentationLayer). - Its material. The
IfcMaterialDefinitionRepresentationof theIfcMaterialthe element is made of: itsIfcStyledRepresentations holdIfcStyledItems with noItemwhose styles present the material (StyleIndex::material_colour,ColourSource::Material).
The precedence is that order. The item over the layer is the
standard’s: “If the styled item has style information assigned […]
then it overrides the style provided by the
IfcPresentationLayerAssignmentWithStyle” (IFC4 ADD2 TC1,
IfcPresentationLayerWithStyle, second note), and it is the cascade
StyleView::resolve_item_style
already applies. The material comes last because it is the general
case: IfcStyledItem “holds presentation style information for
products, either explicitly for an IfcGeometricRepresentationItem being
part of an IfcShapeRepresentation assigned to a product, or by assigning
presentation information to IfcMaterial being assigned as other
representation for a product” (IFC4 ADD2 TC1, IfcStyledItem), and
IfcMaterialDefinitionRepresentation “defines presentation information
relating to IfcMaterial” used at element occurrences and types (IFC4
ADD2 TC1, IfcMaterialDefinitionRepresentation; the entity is new in
IFC2x3 and unchanged in IFC4X3 ADD2). The standard states no order
between a layer style and a material style; this one is IfcOpenShell’s
(mapping.cpp, find_style before the material fallback) and the
one #449 fixes.
The precedence is per colour, not per style: a level that states no surface colour (a styled item with only a curve style, say) does not hide the next one. The layer note says a styled item on a layer “inherits the style information from the layer”, omitting “its own style information” for the styles it does not state.
Which IfcMaterial an element is made of (a layer of a set, a
constituent) is the material domain’s question, not this crate’s: the
caller resolves it and passes the material here. The openbim-ifc
facade joins the two (product_colour).
Implementations§
Source§impl<'m, 's> StyleIndex<'m, 's>
impl<'m, 's> StyleIndex<'m, 's>
Sourcepub fn new(view: StyleView<'m, 's>) -> StyleResult<Self>
pub fn new(view: StyleView<'m, 's>) -> StyleResult<Self>
Index view’s model for style lookups.
Uses the model’s reverse index if something built it; otherwise
reads once the IfcStyledItem, IfcPresentationLayerAssignment and
IfcMaterialDefinitionRepresentation records and nothing else, and
keeps no index behind (#608). The cost of a lookup is the records
that name what it asks about, not the model.
§Errors
None today: the signature keeps the Result of the version that
validated every assignment here. A malformed
IfcStyledItem.Item, IfcPresentationLayerAssignment.AssignedItems
or IfcMaterialDefinitionRepresentation.RepresentedMaterial is
raised by the lookup it reaches, with the error
StyleView::resolve_item_style
gives.
Sourcepub fn item_colour(&self, item: EntityId) -> StyleResult<Option<SurfaceColour>>
pub fn item_colour(&self, item: EntityId) -> StyleResult<Option<SurfaceColour>>
The surface colour item states itself: its own IfcStyledItem
first, then its presentation layers (see the precedence).
None when neither states a surface colour.
§Errors
StyleError::AmbiguousStyleAssignment for two IfcStyledItems on
item, as resolve_item_style refuses it;
StyleError::AmbiguousSurfaceColour when one styled item, or the
layers together, state two different surface colours; and the
projection errors of a malformed style.
Sourcepub fn material_colour(
&self,
material: EntityId,
) -> StyleResult<Option<SurfaceColour>>
pub fn material_colour( &self, material: EntityId, ) -> StyleResult<Option<SurfaceColour>>
The surface colour material’s IfcMaterialDefinitionRepresentation
states, over every one of its IfcStyledRepresentations (one per
representation context). None when the material has no
representation or none states a surface colour.
§Errors
StyleError::AmbiguousSurfaceColour when its styled items state
two different surface colours (in two contexts, say);
StyleError::ReferenceType for a representation that is no
IfcStyledRepresentation or an item that is no IfcStyledItem
(both rules of the standard); and the projection errors of a
malformed style.
Source§impl StyleIndex<'_, '_>
impl StyleIndex<'_, '_>
Sourcepub fn material_fill(
&self,
material: EntityId,
units: StyleUnits,
) -> StyleResult<Option<MaterialFill>>
pub fn material_fill( &self, material: EntityId, units: StyleUnits, ) -> StyleResult<Option<MaterialFill>>
The cut fill material’s IfcMaterialDefinitionRepresentation states,
over every one of its IfcStyledRepresentations (one per
representation context), as hatch line families in metres and
radians (see MaterialFill). None when the material has no
representation or none states an IfcFillAreaStyle.
The traversal is that of StyleIndex::material_colour. Fills in
different contexts must draw the same: equal flag, background and
hatch lines (as a set, compared exactly); the first one, in
ascending order of representation and item, is returned.
A material that states different fills per context (cut and
projection) is ambiguous here: see StyleIndex::material_fills and
StyleIndex::material_fill_for_view.
§Errors
StyleError::AmbiguousFill when one styled item, or the material
across its styled items, states fills that differ;
StyleError::UnsupportedFill for tiles, an externally defined
hatch style, a predefined curve font other than ‘continuous’ and a
‘by layer’ colour or width; StyleError::UnitUndeclared when a
measure needs a unit units does not state (a colour-only fill needs
none); StyleError::InvalidValue and StyleError::OutOfRange
for a fill that breaks a rule of the standard (MaxOneColour, a
non-positive distance, a vector along the hatch lines, …);
StyleError::UnknownEntity for a dangling style;
StyleError::ReferenceType for a representation that is no
IfcStyledRepresentation or an item that is no IfcStyledItem; and
the projection errors of a malformed style.
Sourcepub fn material_fills(
&self,
material: EntityId,
units: StyleUnits,
) -> StyleResult<Vec<ContextFill>>
pub fn material_fills( &self, material: EntityId, units: StyleUnits, ) -> StyleResult<Vec<ContextFill>>
The fills material states per representation context, one
ContextFill for each context that carries a fill area style, in
ascending order of the lowest IfcStyledRepresentation in it.
This is how one material gives several fills, e.g. a cut fill in a
SECTION_VIEW sub-context and a projection fill in an
ELEVATION_VIEW one. StyleIndex::material_fill over the same
material refuses that as StyleError::AmbiguousFill: use this
method for per-view fills, or StyleIndex::material_fill_for_view
for one view.
One refused context fails the whole call;
StyleIndex::material_fills_by_context keeps refusals apart.
Fills agree as in material_fill, but only within a context: the
styled items of one representation must agree, then the
representations of one context. Of agreeing representations the
lowest is reported.
§Errors
StyleError::AmbiguousFill with the representation as owner when
its styled items differ, and with the context as owner when two
representations in it differ; every other error of
StyleIndex::material_fill; and the projection errors of a missing
or malformed representation context.
Sourcepub fn material_fills_by_context(
&self,
material: EntityId,
units: StyleUnits,
) -> StyleResult<Vec<ContextFillResult>>
pub fn material_fills_by_context( &self, material: EntityId, units: StyleUnits, ) -> StyleResult<Vec<ContextFillResult>>
What material states per representation context, like
StyleIndex::material_fills, but a refusal that belongs to one
context stays in that context’s entry: one ContextFillResult for
each context that carries a fill area style or was refused, in order
of the lowest IfcStyledRepresentation in it that states a fill or
was refused.
Within a context the first refusal, in ascending order of
representation, is the entry’s; a later representation cannot
replace it. Fills agree as in material_fills.
When material_fills returns Ok, this returns the same contexts
in the same order, each Ok with equal fields. When it returns an
error, this returns an error, or at least one refused entry.
§Errors
Only refusals no context owns fail the call: the definitions and
their Representations (a member that is no IfcStyledRepresentation
included), the ContextOfItems of a representation that states a fill
or was refused, and the record of a context that has an entry
(ContextIdentifier, ContextType, a missing or invalid TargetView,
UserDefinedTargetView, ParentContext). Everything else lands in
ContextFillResult::fill: the errors of a representation’s items
and styles, StyleError::AmbiguousFill owned by a styled item, a
representation, or a context whose representations differ.
Sourcepub fn material_fill_for_view(
&self,
material: EntityId,
target_view: &str,
units: StyleUnits,
) -> StyleResult<Option<MaterialFill>>
pub fn material_fill_for_view( &self, material: EntityId, target_view: &str, units: StyleUnits, ) -> StyleResult<Option<MaterialFill>>
The fill material states in the representation contexts whose
TargetView is target_view ("SECTION_VIEW", without dots): the
fill they agree on, None when no such context carries one.
A plain IfcGeometricRepresentationContext matches no view, not even
MODEL_VIEW; USERDEFINED matches every user-defined sub-context
without comparing UserDefinedTargetView. Fills agree as in
StyleIndex::material_fill, so contexts that differ give
StyleError::AmbiguousFill owned by the material.
§Errors
StyleError::UnknownTargetView (before anything is read) when
target_view is no IfcGeometricProjectionEnum literal: the match is
exact and case-sensitive. The refusal of the first matching context
that was refused, and the whole-call errors of
StyleIndex::material_fills_by_context. A refusal in a context of
another view does not matter here.
Sourcepub fn fill_area_style(
&self,
style: EntityId,
units: StyleUnits,
) -> StyleResult<MaterialFill>
pub fn fill_area_style( &self, style: EntityId, units: StyleUnits, ) -> StyleResult<MaterialFill>
The fill a bare IfcFillAreaStyle states, as StyleIndex::material_fill
resolves it, for a style nothing may reference (a pattern library).
MaterialFill::styled_item is None.
§Errors
StyleError::UnknownEntity for a missing entity;
StyleError::WrongEntityType when style is no IfcFillAreaStyle;
and the errors of StyleIndex::material_fill for the style itself.
Trait Implementations§
Source§impl<'m, 's> Clone for StyleIndex<'m, 's>
impl<'m, 's> Clone for StyleIndex<'m, 's>
Source§fn clone(&self) -> StyleIndex<'m, 's>
fn clone(&self) -> StyleIndex<'m, 's>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more