Skip to main content

StyleIndex

Struct StyleIndex 

Source
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:

  1. The item. An IfcStyledItem whose Item is the representation item (StyleIndex::item_colour, ColourSource::StyledItem).
  2. Its presentation layer. An IfcPresentationLayerWithStyle whose AssignedItems include it (StyleIndex::item_colour, ColourSource::PresentationLayer).
  3. Its material. The IfcMaterialDefinitionRepresentation of the IfcMaterial the element is made of: its IfcStyledRepresentations hold IfcStyledItems with no Item whose 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>

Source

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.

Source

pub fn view(&self) -> StyleView<'m, 's>

The view the index reads through.

Source

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.

Source

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<'_, '_>

Source

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.

Source

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.

Source

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.

Source

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.

Source

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>

Source§

fn clone(&self) -> StyleIndex<'m, 's>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'m, 's> Debug for StyleIndex<'m, 's>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'m, 's> !RefUnwindSafe for StyleIndex<'m, 's>

§

impl<'m, 's> !UnwindSafe for StyleIndex<'m, 's>

§

impl<'m, 's> Freeze for StyleIndex<'m, 's>

§

impl<'m, 's> Send for StyleIndex<'m, 's>

§

impl<'m, 's> Sync for StyleIndex<'m, 's>

§

impl<'m, 's> Unpin for StyleIndex<'m, 's>

§

impl<'m, 's> UnsafeUnpin for StyleIndex<'m, 's>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.