cc_ifc API← API reference · Generated from the source by cargo run -p api_doc; edit the doc comments, not this page.
IFC export and import for ConstructCraft.
export maps a cc_core::Project to an IFC4 STEP physical file
(ISO 10303-21): spatial structure (project, site, building, storeys),
walls with openings, doors, windows, slabs, ceilings and roofs as swept
solids, element types, material layer sets, surface styles and base
quantities. The STEP writer and the mapping are implemented here without
third-party IFC libraries. import reads IFC2X3/IFC4 files back into a
project (see the import module).
| Module | Items | Summary |
|---|---|---|
cc_ifc |
0 | IFC export and import for ConstructCraft. |
cc_ifc::export |
19 | Mapping of the ConstructCraft model to IFC4 entities. |
cc_ifc::geometry |
12 | The IFC geometry resource turned into polygon meshes: placements, curves (polylines, indexed curves with arcs, conics, trimmed and composite curves, B-splines), parametric and arbitrary profiles (with voids), swept solids (extrusions, revolutions, swept disks, directrix sweeps), CSG primitives and trees, half-space clipping, boundary representations, face sets and mapped items. |
cc_ifc::guid |
3 | IFC GlobalId: a 128-bit identifier in the 22-character IFC base64 form. |
cc_ifc::import |
5 | IFC import: maps the spatial structure and building elements of an IFC file (IFC2X3 or IFC4) onto a ConstructCraft project. |
cc_ifc::parse |
5 | Reader for STEP physical files (ISO 10303-21): the header schema and the entity instances of the data section. |
cc_ifc::point_list |
2 | Point lists as text, for the property sets that carry a terrain’s points and boundary (export::TOPOGRAPHY_PSET): coordinates separated by spaces, points by ;. |
cc_ifc::schema |
4 | The part of the IFC4 schema needed to write any physical element class back out: the attribute count of each IfcElement subtype, where its PredefinedType sits and which type object goes with it. |
cc_ifc::step |
8 | Minimal writer for STEP physical files (ISO 10303-21). |
cc_ifccrates/cc_ifc/src/lib.rs
Re-exports
pub use export::{ExportOptions, export, export_to_file, ifc_status}pub use guid::guidpub use import::{ImportError, ImportReport, import, import_file}pub use schema::display_namecc_ifc::exportcrates/cc_ifc/src/export.rs
Mapping of the ConstructCraft model to IFC4 entities.
Items: NICHE_PSET · ExportOptions · export · export_to_file · COMPONENT_PSET · DESIGN_OPTION_PSET · PHASING_PSET · CURTAIN_PSET · ROOFING_PSET · COLD_FORMED_CATEGORY · TOPOGRAPHY_PSET · PADS_PSET · PILE_CAP_PSET · PILE_PSET · pile_ifc · REBAR_PSET · ROOFING_SIZES · PHASES_PSET · ifc_status
NICHE_PSETpub const NICHE_PSET: &str
Property set of a niche’s opening element: its sizes, the face of the wall it is in and the volume it takes out.
ExportOptionspub struct ExportOptions
Traits: Debug, Clone, Default, PartialEq
Fields
time_stamp: Option<String>
FILE_NAME time stamp (ISO 8601). The current UTC time when None.
file_name: String
FILE_NAME name, usually the target file name.
exportpub fn export(project: &Project, options: &ExportOptions) -> String
Serialize project as an IFC4 STEP physical file: the main model and
the primary option of each design option set (whatever option is being
edited), the option of each element in DESIGN_OPTION_PSET.
export_to_filepub fn export_to_file(project: &Project, path: &std::path::Path) -> std::io::Result<()>
Export project to an .ifc file at path.
COMPONENT_PSETpub const COMPONENT_PSET: &str
Property set with the instance parameter values of components.
DESIGN_OPTION_PSETpub const DESIGN_OPTION_PSET: &str
Property set of the design option an element belongs to (OptionSet,
Option, Primary).
PHASING_PSETpub const PHASING_PSET: &str
Property set of an element’s construction phases (PhaseCreated, PhaseDemolished).
CURTAIN_PSETpub const CURTAIN_PSET: &str
Property set of a curtain wall’s grid: the type’s System and the wall’s
Edits as text (see cc_core::curtain::to_text), its Height and Bulge.
ROOFING_PSETpub const ROOFING_PSET: &str
Property set of a roof’s covering and framing (see write_roof_framing).
COLD_FORMED_CATEGORYpub const COLD_FORMED_CATEGORY: &str
Category of the material profile of a cold-formed section (rolled and
cold-formed steel share their materials).
TOPOGRAPHY_PSETpub const TOPOGRAPHY_PSET: &str
A terrain’s points, boundary, base depth and type settings, for importers
to rebuild it as terrain (points as x y z and the boundary as x y,
separated by ;).
PADS_PSETpub const PADS_PSET: &str
The building pads of a terrain (see Exporter::pads_set).
PILE_CAP_PSETpub const PILE_CAP_PSET: &str
Property set of a pile cap: its Placement (position in plan and
rotation in degrees), its Cap (thickness and cc_core::pile::PileCap
without the pile type) as text (see cc_core::curtain::to_text), and the
name of its piles’ type (PileType).
PILE_PSETpub const PILE_PSET: &str
Property set of a pile: its Kind (cc_core::pile::PileKind::code), its
Section and Embedment as text, and for a pile of a cap the cap’s
GlobalId (Cap) and the pile’s place in its layout (CapIndex).
pile_ifcpub fn pile_ifc(kind: cc_core::pile::PileKind) -> (&'static str, &'static str, Option<&'static str>)
The IfcPileTypeEnum, IfcPileConstructionEnum and, for a user-defined
type, the object type of a pile kind: bored piles are bored and cast in
place, precast and steel piles driven; augered and micro piles, cast in
place, have no predefined type of their own.
REBAR_PSETpub const REBAR_PSET: &str
What a reinforcement set says of its bars: Partition, BarMark (a mark
given by hand), Mark (the mark its bars have, when they all have one)
and Grade (see Exporter::write_rebar).
ROOFING_SIZESpub const ROOFING_SIZES: [(&str, &str, &str); 4]
The framing’s member sizes in ROOFING_PSET: member, width and height properties.
PHASES_PSETpub const PHASES_PSET: &str
Property set of the project’s phases, in time order (properties 1, 2…).
ifc_statuspub fn ifc_status(project: &Project, e: &Element) -> Option<cc_core::PhaseStatus>
An element’s IFC Status relative to the project’s last phase (an
element demolished before it reads as demolished); None for
annotations and projects without phases.
cc_ifc::geometrycrates/cc_ifc/src/geometry.rs
The IFC geometry resource turned into polygon meshes: placements, curves (polylines, indexed curves with arcs, conics, trimmed and composite curves, B-splines), parametric and arbitrary profiles (with voids), swept solids (extrusions, revolutions, swept disks, directrix sweeps), CSG primitives and trees, half-space clipping, boundary representations, face sets and mapped items. Everything is read from public schema definitions; curved surfaces are approximated by facets. Every walk over references is depth-bounded and malformed values are skipped, so a hostile file yields less geometry, never a panic.
Items: Polygon · Profile · ProfileKind · Extrusion · Solid · subtract · bounds2 · affine · frame · clean_loop · clip_mesh · Geometry
Polygonpub type Polygon = Vec<DVec3>
A planar polygon in world coordinates (counter-clockwise seen from outside).
Profilepub struct Profile
A profile in its plane: outer loop, inner loops and, for parametric rectangles and circles, their exact parameters.
Traits: Debug, Clone
Fields
pts: Vec<DVec2>holes: Vec<Vec<DVec2>>kind: ProfileKindclosed: bool
False for open profiles (a curve swept into a surface).
curves: Option<Vec<SketchCurve>>
The outline and voids as lines, arcs and circles in the profile’s
plane, when every one of them reads so and some are curved (see
plan_curves): pts and holes split the curves.
Methods
pub fn rect(&self) -> (DVec2, DVec2, f64, f64)
Exact rectangle or circle, else the bounding rectangle of the outline.
pub fn is_simple(&self) -> bool
A solid rectangle or circle (what native columns and beams can hold).
ProfileKindpub enum ProfileKind
Traits: Debug, Clone, Copy, PartialEq
Variants
Rect { center: DVec2, x: DVec2, w: f64, h: f64, }
Rectangle w x h centered at center, with its width along x.
Circle { center: DVec2, r: f64, }PolyExtrusionpub struct Extrusion
An extruded profile: its plane and extrusion vector in world coordinates.
Traits: Debug, Clone
Fields
profile: Profilexf: DAffine3
Profile plane to world.
vector: DVec3
Extrusion vector in world coordinates (direction times depth).
source: Option<u32>
The profile definition entity extruded.
Methods
pub fn is_vertical(&self) -> boolpub fn footprint(&self) -> Vec<DVec2>
World XY of the profile outline (the bottom cap of a vertical extrusion).
pub fn z_range(&self) -> (f64, f64)
Lowest and highest z of the extruded profile.
pub fn footprint_curves(&self) -> Option<Vec<SketchCurve>>
Extrusion::footprint and its voids as lines, arcs and circles,
when the profile has them and lies level.
pub fn void_footprints(&self) -> Vec<Vec<DVec2>>
World XY of the profile’s voids, like Extrusion::footprint.
pub fn plane_point(&self, p: DVec2) -> DVec3pub fn plane_vector(&self, v: DVec2) -> DVec3Solidpub struct Solid
A representation item resolved to world coordinates.
Traits: Debug, Clone, Default
Fields
extrusion: Option<Extrusion>
The extruded profile, when the item is a plain extrusion.
mesh: Vec<Polygon>
Faces in world coordinates.
points: Vec<DVec3>
Every vertex of the faces.
item: u32
Representation item (for styles).
clipped: bool
A half space or boolean cut the item (its extrusion is the uncut one).
cuts: Vec<Extrusion>
The plain extrusions a boolean difference subtracted from it (a slab with its shafts cut out of its body).
other_cut: bool
Something other than those extrusions changed it (half spaces, intersections, cutters of other shapes).
disk: Option<(Vec<DVec3>, f64)>
The center line (world) and radius of a disk swept along it (bars).
Methods
pub fn replace_mesh(&mut self, mesh: Vec<Polygon>)
Replace the faces by a cut version of them; a changed solid is marked clipped (its extrusion stays the uncut one).
subtractpub fn subtract(a: &[Polygon], b: &[Polygon]) -> Option<Vec<Polygon>>
a minus b when their bounds overlap (None: nothing to cut or too large to cut).
bounds2pub fn bounds2(pts: &[DVec2]) -> (DVec2, DVec2)
affinepub fn affine(x: DVec3, y: DVec3, z: DVec3, origin: DVec3) -> DAffine3
framepub fn frame(z: Option<DVec3>, x: Option<DVec3>, origin: DVec3) -> DAffine3
A right-handed frame from a Z axis and an approximate X axis.
clean_looppub fn clean_loop<T: Copy + PartialEq>(mut pts: Vec<T>, close: impl Fn(&T, &T) -> bool) -> Vec<T>
Drop a repeated closing point and consecutive duplicates.
clip_meshpub fn clip_mesh(mesh: &[Polygon], point: DVec3, normal: DVec3) -> Vec<Polygon>
Keep the part of mesh on the side of the plane where (p - point)·normal >= 0,
closing the cut with cap faces.
Geometrypub struct Geometry<'a>
Reads geometry from a parsed IFC file.
Fields
f: &'a StepFilescale: f64
Meters per file length unit.
angle: f64
Radians per file plane angle unit.
Some fields are private.
Methods
pub fn new(f: &'a StepFile, scale: f64, angle: f64) -> Selfpub fn measured_curve(&self, param: &Param) -> Vec<DVec3>
A curve whose length is measured (a bar’s center line): its arcs are sampled at 2° rather than at the facets of meshes.
pub fn point(&self, param: &Param) -> Option<DVec3>pub fn direction(&self, param: &Param) -> Option<DVec3>pub fn axis_placement(&self, param: &Param) -> DAffine3
IfcAxis2Placement3D / 2D / IfcAxis1Placement as a transform (identity if unset).
pub fn placement(&self, param: &Param) -> DAffine3
World transform of an object placement chain.
pub fn operator(&self, param: &Param) -> DAffine3
IfcCartesianTransformationOperator2D/3D (uniform or not) as a transform.
pub fn curve(&self, param: &Param, depth: usize) -> Vec<DVec3>
Points of a curve in its own coordinates (2D curves at z = 0).
pub fn plan_curves(&self, param: &Param, depth: usize) -> Option<Vec<SketchCurve>>
A 2D curve as lines, arcs and circles in its own coordinates (polylines,
indexed poly curves, composite curves of those, circles and trimmed
circles and lines); None when any part is something else (ellipses,
splines, offsets) or the curves are too many for a sketch.
pub fn profiles(&self, param: &Param, depth: usize) -> Vec<Profile>
The profiles of a profile definition (several for composite profiles).
pub fn parametric_shape(&self, e: &Entity) -> Option<ProfileShape>
The structural profile shape of a parametric profile definition,
when the shape holds it exactly (in meters, before its position);
None for other definitions and for what the shapes lack (edge
radii, slopes, a hollow rectangle’s own inner radius).
pub fn items(&self, param: &Param, xf: DAffine3, out: &mut Vec<Solid>)
Resolve a representation item into world solids (xf: item coordinates to world).
cc_ifc::guidcrates/cc_ifc/src/guid.rs
IFC GlobalId: a 128-bit identifier in the 22-character IFC base64 form.
encodepub fn encode(n: u128) -> String
Encode a 128-bit value: 2 bits in the first character, 6 in each of the other 21.
decodepub fn decode(s: &str) -> Option<u128>
Decode a 22-character GlobalId (None if malformed).
guidpub fn guid(seed: &str, tag: &str) -> String
Deterministic GlobalId for the object named tag within the project
identified by seed, so repeated exports keep the same ids.
cc_ifc::importcrates/cc_ifc/src/import.rs
IFC import: maps the spatial structure and building elements of an IFC file (IFC2X3 or IFC4) onto a ConstructCraft project. Geometry is read from extruded area solids (the usual representation of walls, slabs, columns and beams), with faceted B-reps, face sets and bounding boxes used for extents. Storeys become levels; walls, doors, windows, slabs, ceilings, roofs, spaces, columns and beams become native elements with matching or new types. Products that cannot be interpreted are counted in the report instead of failing the import.
Items: MAX_IFC_BYTES · ImportReport · ImportError · import_file · import
MAX_IFC_BYTESpub const MAX_IFC_BYTES: u64
Largest IFC file imported, bytes: the parsed instances take many times the file’s size in memory.
ImportReportpub struct ImportReport
What an import brought in.
Traits: Debug, Clone, Default, PartialEq
Fields
schema: String
IFC schema of the file (IFC4, IFC2X3…).
levels: usizeimported: BTreeMap<Category, usize>generic: BTreeMap<String, usize>
Objects brought in as generic components keeping their IFC class, by class.
skipped: BTreeMap<String, usize>
Products that were not imported, by IFC entity name.
Methods
pub fn imported_total(&self) -> usizepub fn skipped_total(&self) -> usizeImportErrorpub enum ImportError
Traits: Debug, std::fmt::Display, std::error::Error
Variants
Io(std::io::Error)Parse(ParseError)NotIfc
The file has no IFCPROJECT.
import_filepub fn import_file(path: &std::path::Path, base: Project) -> Result<(Project, ImportReport), ImportError>
Import the IFC file at path into base (see import).
Files larger than MAX_IFC_BYTES are refused before they are read
(an ImportError::Io of kind FileTooLarge).
importpub fn import(text: &str, base: Project) -> Result<(Project, ImportReport), ImportError>
Import IFC text. base supplies materials, types and project-wide
views (usually the default template); its levels, elements, plans and
sheets are replaced by the imported building.
cc_ifc::parsecrates/cc_ifc/src/parse.rs
Reader for STEP physical files (ISO 10303-21): the header schema and the entity instances of the data section. Malformed input yields an error, never a panic; nesting depth is bounded.
Items: Param · Entity · StepFile · ParseError · parse
Parampub enum Param
A parsed attribute value.
Traits: Debug, Clone, PartialEq
Variants
NullDerivedInt(i64)Real(f64)Str(String)Enum(String)
Enumeration literal without the dots (T, F, ELEMENT…).
Ref(u32)List(Vec<Param>)Typed(String, Box<Param>)
Typed value of a SELECT, such as IFCLABEL('x').
Methods
pub fn as_ref(&self) -> Option<u32>pub fn as_f64(&self) -> Option<f64>
Numeric value (integers widen; typed measures unwrap).
pub fn as_str(&self) -> Option<&str>pub fn as_enum(&self) -> Option<&str>pub fn as_bool(&self) -> Option<bool>pub fn as_list(&self) -> &[Param]Entitypub struct Entity
An entity instance: upper-case type name and attributes. Complex (multi-type) instances are kept with an empty name.
Traits: Debug, Clone, PartialEq
Fields
name: Stringargs: Vec<Param>Methods
pub fn arg(&self, i: usize) -> &Param
Attribute i, or Null when missing.
StepFilepub struct StepFile
A parsed exchange structure.
Traits: Debug, Clone, Default
Fields
schema: String
First schema of FILE_SCHEMA (e.g. IFC4, IFC2X3).
entities: BTreeMap<u32, Entity>
Methods
pub fn get(&self, id: u32) -> Option<&Entity>pub fn deref(&self, param: &Param) -> Option<&Entity>
The instance param refers to.
pub fn of_type<'a>(&'a self, name: &'a str) -> impl Iterator<Item = (u32, &'a Entity)> + 'a
Instances of entity name (upper case), in file order.
ParseErrorpub struct ParseError
Traits: Debug, Clone, PartialEq, Eq, std::fmt::Display, std::error::Error
Fields
offset: usize
Byte offset of the problem.
message: String
parsepub fn parse(text: &str) -> Result<StepFile, ParseError>
Parse a STEP physical file.
cc_ifc::point_listcrates/cc_ifc/src/point_list.rs
Point lists as text, for the property sets that carry a terrain’s points
and boundary (export::TOPOGRAPHY_PSET): coordinates separated by
spaces, points by ;.
encodepub(crate) fn encode(points: impl Iterator<Item = Vec<f64>>) -> String
Points as text: coordinates separated by spaces, points by ;.
decodepub(crate) fn decode(text: &str, dims: usize, max: usize) -> Vec<Vec<f64>>
Points read from encode text, dims numbers each: at most max of
them; malformed or non-finite entries are skipped.
cc_ifc::schemacrates/cc_ifc/src/schema.rs
The part of the IFC4 schema needed to write any physical element class
back out: the attribute count of each IfcElement subtype, where its
PredefinedType sits and which type object goes with it. Taken from the
published IFC4 ADD2 TC1 schema; all the attributes after the common eight
are optional, so the writer fills them with $.
Items: TypeLayout · ElementClass · element_class · display_name
TypeLayoutpub enum TypeLayout
Extra attributes of a type object after the nine of IfcElementType.
Traits: Debug, Clone, Copy, PartialEq, Eq
Variants
Predefined
PredefinedType.
Plain
No further attributes.
Furniture
AssemblyPlace, PredefinedType (furniture).
Door
PredefinedType, OperationType, ParameterTakesPrecedence, UserDefinedOperationType.
Window
PredefinedType, PartitioningType, ParameterTakesPrecedence, UserDefinedPartitioningType.
ElementClasspub struct ElementClass
How an element class is written.
Traits: Debug, Clone, Copy, PartialEq, Eq
Fields
entity: &'static strattrs: usize
Number of attributes of an occurrence.
predefined: Option<usize>
Index of PredefinedType in an occurrence.
type_entity: Option<(&'static str, TypeLayout)>
Type object entity (none when the schema only has an abstract one).
element_classpub fn element_class(entity: &str) -> Option<&'static ElementClass>
How to write occurrences of entity (upper case) in IFC4, if it is a
physical element class there.
display_namepub fn display_name(entity: &str) -> String
Readable class name: IFCPIPESEGMENT → IfcPipeSegment for the classes
in the table, else the entity name with only its first letters capitalized.
cc_ifc::stepcrates/cc_ifc/src/step.rs
Minimal writer for STEP physical files (ISO 10303-21).
Items: Id · Value · opt_str · reals · args · Header · StepWriter · is_type_name
Idpub struct Id(pub u32)
Instance name of an entity in the data section (#n).
Traits: Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash
Valuepub enum Value
An attribute value.
Traits: Debug, Clone, PartialEq, From<f64>, From<i64>, From<bool>, From<&str>, From<String>, From<Id>, From<Option<T>>, From<Vec<T>>
Variants
Null
Unset optional attribute ($).
Derived
Attribute redeclared as derived in a subtype (*).
Bool(bool)Int(i64)Real(f64)Str(String)Enum(&'static str)
Enumeration literal, written as .NAME..
EnumName(String)
Enumeration literal read from data; anything but A-Z, 0-9 and _
is written as NOTDEFINED.
Ref(Id)List(Vec<Value>)Typed(&'static str, Box<Value>)
Typed value for SELECT attributes, such as IFCLABEL('x').
TypedName(String, Box<Value>)
Typed value whose type name comes from data; an invalid name (not
IFC followed by A-Z, 0-9, _) is written as $.
opt_strpub fn opt_str(s: &str) -> Value
A string attribute, or $ when empty.
realspub fn reals(xs: &[f64]) -> Value
A list of reals, for coordinates and direction ratios.
argsmacro_rules! args
Builds the attribute list of an entity instance.
Headerpub struct Header
File header fields (FILE_DESCRIPTION, FILE_NAME, FILE_SCHEMA).
Traits: Debug, Clone, PartialEq
Fields
description: Vec<String>name: Stringtime_stamp: Stringauthor: Vec<String>organization: Vec<String>preprocessor_version: Stringoriginating_system: Stringauthorization: Stringschema: StringStepWriterpub struct StepWriter
Accumulates entity instances and serializes the exchange structure.
Traits: Debug, Default
Some fields are private.
Methods
pub fn new() -> Selfpub fn add(&mut self, entity: &str, args: Vec<Value>) -> Id
Append an instance of entity (upper case, e.g. IFCWALL) and return its name.
pub fn len(&self) -> usizepub fn is_empty(&self) -> boolpub fn finish(self, header: &Header) -> Stringis_type_namepub fn is_type_name(name: &str) -> bool
An IFC type name: IFC followed by upper-case letters, digits and _.