IModelExtension#
Extension on IModel interface implementing convenient functions for instance creation. This extension also serves as an example of how to implement generic methods that are schema-agnostic.
Properties#
isIfc extension no setter#
Returns true if the model is a IFC model, false otherwise.
Available on IModel, provided by the IModelExtension extension
Implementation
bool get isIfc => isIfcSchema(schemaEnum);
Methods#
addInstanceRef() extension#
add instance reference and clean up the old reference. and return the old referenced instance
Available on IModel, provided by the IModelExtension extension
Implementation
IInstance addInstanceRef(IInstance instance, IInstance ref,
{String? attName, int? attIndex, bool addInverse = false}) {
if (instance.isNull || ref.isNull) {
return createNullInstance();
}
final prevRef = instance.getInstance(attIndex: attIndex, attName: attName);
IInstance prev = createNullInstance();
if (!prevRef.isNull && prevRef.isInstanceReference) {
prev = getInstance(prevRef.instanceHandle);
}
if (!prev.isNull) {
prev.removeInverse(instance.instanceId);
}
instance.addInstanceRef(ref,
attName: attName, attIndex: attIndex, addInverse: addInverse);
return prev;
}
axis2Placement3dFromMatrix() extension#
Creates an Axis2Placement3D from a transformation matrix.
Extracts the location, axis, and reference direction from the matrix columns:
- Location: column 3 (translation component)
- Axis: column 2 (Z-axis direction)
- Reference direction: column 0 (X-axis direction)
Available on IModel, provided by the IModelExtension extension
Implementation
IInstance axis2Placement3dFromMatrix(Matrix4 mat) {
final location = mat.getColumn(3);
final ref = mat.getColumn(0);
final axis = mat.getColumn(2);
return createAxis2Placement3D(
[location[0], location[1], location[2]],
[axis[0], axis[1], axis[2]],
[ref[0], ref[1], ref[2]],
);
}
createAxis2Placement2D() extension#
Creates an Axis2Placement2D from location and reference direction.
The location parameter must contain 2 coordinates.
The ref parameter is optional but must contain 2 coordinates if provided.
Returns a null instance if any coordinate list has an invalid length.
Available on IModel, provided by the IModelExtension extension
Implementation
IInstance createAxis2Placement2D(List<double> location, [List<double>? ref]) {
if (location.length != 2) {
return createNullInstance();
}
final placement = createInstance(
typeName: isIfc ? kIfcAxis2Placement2d : kAxis2Placement2d)
..setAttribute(createCartesianPoint(location), attName: 'location');
ref ??= [1.0, 0];
if (ref.length != 2) {
return createNullInstance();
}
final refDir = createDirection(ref);
placement.setAttribute(refDir,
attName: isIfc ? 'refdirection' : 'ref_direction');
return placement;
}
createAxis2Placement3D() extension#
Creates an Axis2Placement3D from location, axis, and reference direction.
The location parameter must contain 3 coordinates.
The axis and ref parameters are optional but must contain 3 coordinates if provided.
Returns a null instance if any coordinate list has an invalid length.
Available on IModel, provided by the IModelExtension extension
Implementation
IInstance createAxis2Placement3D(List<double> location,
[List<double>? axis, List<double>? ref]) {
if (location.length != 3) {
return createNullInstance();
}
final placement = createInstance(
typeName: isIfc ? kIfcAxis2Placement3d : kAxis2Placement3d)
..setAttribute(createCartesianPoint(location), attName: 'location');
axis ??= [0, 0, 1.0];
if (axis.length != 3) {
return createNullInstance();
}
placement.setAttribute(createDirection(axis), attName: 'axis');
ref ??= [1.0, 0, 0];
if (ref.length != 3) {
return createNullInstance();
}
placement.setAttribute(createDirection(ref),
attName: isIfc ? 'RefDirection' : 'ref_direction');
return placement;
}
createCartesianPoint() extension#
Creates a Cartesian point from coordinates.
The coordinates list must contain either 2 or 3 values for 2D or 3D points respectively. Returns a null instance if the coordinate list length is invalid.
Available on IModel, provided by the IModelExtension extension
Implementation
IInstance createCartesianPoint(List<double> coords) {
final length = coords.length;
if (length != 2 && length != 3) {
return createNullInstance();
}
final inst =
createInstance(typeName: isIfc ? kIfcCartesianPoint : kCartesianPoint)
..setAttribute(coords, attName: 'coordinates');
return inst;
}
createDirection() extension#
Creates a direction vector from direction ratios.
The direction ratios list must contain either 2 or 3 values for 2D or 3D directions respectively. Returns a null instance if the ratios list length is invalid.
Available on IModel, provided by the IModelExtension extension
Implementation
IInstance createDirection(List<double> coords) {
final length = coords.length;
if (length != 2 && length != 3) {
return createNullInstance();
}
return createInstance(typeName: isIfc ? kIfcDirection : kDirection)
..setAttribute(coords,
attName: isIfc ? 'DirectionRatios' : 'direction_ratios');
}
createHeader() extension#
Creates the header instance from PIModelHeader structure. The header instance captures all information in the header section of the Part 21 CSV file: HEADER; header information. ENDSEC; The header instance has three instance attributes:
- file_description
- file_name
- file_schema
Available on IModel, provided by the IModelExtension extension
Implementation
IInstance createHeader(PIModelHeader header) {
final fileDescription =
createInstance(typeName: 'file_description', setId: false)
..setAttribute(header.description, attName: 'description')
..setAttribute(
header.implementation_level.isEmpty
? kImplementationLevel
: header.implementation_level,
attName: 'implementation_level');
final fileName = createInstance(typeName: 'file_name', setId: false)
..setAttribute(header.name, attName: 'name')
..setAttribute(PIModelHeader.getTimeStamp(), attName: 'time_stamp')
..setAttribute(header.author.isEmpty ? [kAuthor] : header.author,
attName: 'author')
..setAttribute(header.organization, attName: 'organization')
..setAttribute(
header.preprocessor_version.isEmpty
? kProcessorVersion
: header.preprocessor_version,
attName: 'preprocessor_version')
..setAttribute(header.originating_system, attName: 'originating_system')
..setAttribute(header.authorization, attName: 'authorization');
final schemas = [header.schema_identifier.toUpperCase()];
final fileSchema = createInstance(typeName: 'file_schema', setId: false)
..setAttribute(schemas, attIndex: 0);
final headerInst = createInstance(typeName: 'file_header', setId: false)
..setAttribute(fileDescription, attIndex: 0)
..setAttribute(fileName, attIndex: 1)
..setAttribute(fileSchema, attIndex: 2);
headerInst.setAttribute(header.schemaEnum.index, attName: 'schema_enum');
return headerInst;
}
setInstanceRef() extension#
Available on IModel, provided by the IModelExtension extension
Implementation
IInstance setInstanceRef(IInstance instance, IInstance ref,
{String? attName, int? attIndex, bool addInverse = false}) {
if (instance.isNull || ref.isNull) {
return createNullInstance();
}
final prevRef = instance.getInstance(attIndex: attIndex, attName: attName);
IInstance prev = createNullInstance();
if (!prevRef.isNull && prevRef.isInstanceReference) {
prev = getInstance(prevRef.instanceHandle);
}
if (!prev.isNull) {
prev.removeInverse(instance.instanceId);
}
instance.setInstanceRef(ref,
attName: attName, attIndex: attIndex, addInverse: addInverse);
return prev;
}
