Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ All notable changes to the `IfcIO` library are documented in this file.
## [Unreleased]

### Fixed
- IFC import recognizes IFC4.3 separately and reports unknown, missing and multiple schema identifiers. IFC4.3
is read as a subset and is not silently rewritten as IFC4.
- Element factories allocate IDs across the model rather than per storey; the writer avoids generated GlobalId
collisions, and clash storey filters no longer confuse distinct elements that share a caller-assigned ID.
- IFC export declares feet and inches as conversion-based length units and respects the selected plane angle unit.
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ The documentation site with API references and guides is at <https://ioextend.gi
## Supported files

Reads and writes ISO 10303-21 STEP physical files conforming to **IFC2x3 Coordination View V2.0** and **IFC4 Design Transfer / Reference View**, compressed PKZip `.ifczip` archives, and buildingSMART BCF 2.1 `.bcfzip` packages.
**IFC4.3** (`IFC4X3`, `IFC4X3_ADD1`, `IFC4X3_ADD2`) can be read for inspection and supported geometry, but cannot be
rewritten as IFC. Unknown, missing, or multiple IFC schema identifiers are reported rather than guessed.

## Limitations

Expand Down
6 changes: 6 additions & 0 deletions docs/public-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ This page summarizes the public types and entry points of the `IfcIO` package.
| `IfcBuildingStorey`, `IfcSpace` | Storeys hold elements and spaces and carry elevations. The model does not expose separate `IfcSite`, `IfcBuilding`, or `IfcProject` objects. |
| `IfcGuid` | buildingSMART 22-character compressed GlobalId encoder/decoder with bidirectional conversion to 128-bit .NET `Guid`. |

`IfcModel.SourceSchemaIdentifier` preserves the file's `FILE_SCHEMA` identifier, including any appended numeric
object identifier. `IfcSchema.Ifc4x3` means subset import only: not every IFC4.3 entity is interpreted.
Representations and ports with unsupported placements are omitted and counted in `UnsupportedPlacementCount`.
IFC output and schema migration are not supported for these models, including after extraction.
Unknown, missing or multiple schema identifiers fail model import.

`IfcModel.LengthUnit` controls the declared unit of geometry and storey elevations. IFC import keeps recognised
millimetres, metres, feet and inches in the model; other supported length scales are converted to metres.
`IfcModel.AngleUnit` controls the IFC plane angle unit, but `IfcRevolvedAreaSolid.Angle` is always in radians in memory.
Expand Down
47 changes: 36 additions & 11 deletions src/IfcIO.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ private static int ExecuteInfo(string[] args)

var sw = Stopwatch.StartNew();
var model = IfcModel.Open(inputPath);
WarnOnPartialIfc4x3Import(model);
sw.Stop();

int elementCount = 0;
Expand Down Expand Up @@ -213,7 +214,8 @@ private static int ExecuteInfo(string[] args)

Console.WriteLine($" File size: {sizeMb:F2} MB ({fileInfo.Length:N0} bytes)");
Console.WriteLine($" Parsed in: {sw.ElapsedMilliseconds} ms");
Console.WriteLine($" Schema: {model.Schema}");
string schemaLabel = model.Schema == IfcSchema.Ifc4x3 ? $"Ifc4x3 ({model.SourceSchemaIdentifier}, subset import)" : model.Schema.ToString();
Console.WriteLine($" Schema: {schemaLabel}");
Console.WriteLine($" Project Name: {model.ProjectName}");
Console.WriteLine($" Building Name: {model.BuildingName}");
Console.WriteLine($" Storeys: {model.Storeys.Count}");
Expand Down Expand Up @@ -303,7 +305,7 @@ private static int ExecuteExport(string[] args)
string? objPath = GetOptionValue(args, "--obj");
string? ifcPath = GetOptionValue(args, "--ifc");
string? ifczipPath = GetOptionValue(args, "--ifczip");
string? schemaOpt = GetOptionValue(args, "--schema");
IfcSchema? schemaOpt = GetWritableSchemaOption(args, "--schema");

if (glbPath is null && objPath is null && ifcPath is null && ifczipPath is null)
{
Expand All @@ -315,12 +317,13 @@ private static int ExecuteExport(string[] args)
var sw = Stopwatch.StartNew();
var model = IfcModel.Open(inputPath);

if (schemaOpt is not null)
if (model.Schema == IfcSchema.Ifc4x3 && (ifcPath is not null || ifczipPath is not null))
{
model.Schema = schemaOpt.Equals("ifc4", StringComparison.OrdinalIgnoreCase)
? IfcSchema.Ifc4
: IfcSchema.Ifc2x3;
Console.Error.WriteLine("Error: IFC4X3 is supported for subset import only. Rewriting it as IFC is not supported.");
return 1;
}
WarnOnPartialIfc4x3Import(model);
if (schemaOpt is { } requested) model.Schema = requested;

if (glbPath is not null)
{
Expand Down Expand Up @@ -644,6 +647,25 @@ private static string PhysicalPath(string path)
return null;
}

private static IfcSchema? GetWritableSchemaOption(string[] args, string option)
{
if (!args.Contains(option, StringComparer.OrdinalIgnoreCase)) return null;
return GetOptionValue(args, option)?.ToUpperInvariant() switch
{
"IFC2X3" => IfcSchema.Ifc2x3,
"IFC4" => IfcSchema.Ifc4,
_ => throw new ArgumentException($"{option} requires ifc2x3 or ifc4. Other IFC output schemas are not supported."),
};
}

private static void WarnOnPartialIfc4x3Import(IfcModel model)
{
if (model.Schema != IfcSchema.Ifc4x3) return;
Console.Error.WriteLine($"Warning: {model.SourceSchemaIdentifier} is read as a subset. Uninterpreted content is omitted.");
if (model.UnsupportedPlacementCount > 0)
Console.Error.WriteLine($"Warning: omitted {model.UnsupportedPlacementCount} representations or ports with unsupported placements.");
}

private static int ExecuteQuery(string[] args)
{
if (args.Length < 2)
Expand Down Expand Up @@ -715,7 +737,10 @@ private static int ExecutePatch(string[] args)
string? extractQuery = GetOptionValue(args, "--extract");
string? offsetStr = GetOptionValue(args, "--offset");
string? scaleStr = GetOptionValue(args, "--scale");
string? schemaStr = GetOptionValue(args, "--migrate") ?? (string.Equals(recipe, "migrate", StringComparison.OrdinalIgnoreCase) ? GetOptionValue(args, "--schema") : null);
IfcSchema? targetSchema = GetWritableSchemaOption(args, "--migrate");
if (targetSchema is null && string.Equals(recipe, "migrate", StringComparison.OrdinalIgnoreCase))
targetSchema = GetWritableSchemaOption(args, "--schema")
?? throw new ArgumentException("--recipe migrate requires --schema ifc2x3 or ifc4.");

Geometry.IfcVector3? manualOffset = null;
if (args.Contains("--offset", StringComparer.OrdinalIgnoreCase))
Expand Down Expand Up @@ -774,11 +799,10 @@ private static int ExecutePatch(string[] args)
Console.WriteLine($" * Scaled model vertices by factor: {scaleFactor:G}");
}

if (!string.IsNullOrEmpty(schemaStr))
if (targetSchema is { } requestedSchema)
{
var targetSchema = schemaStr.Contains('4') ? IfcSchema.Ifc4 : IfcSchema.Ifc2x3;
Patch.IfcPatch.MigrateSchema(model, targetSchema);
Console.WriteLine($" * Migrated model schema to: {targetSchema}");
Patch.IfcPatch.MigrateSchema(model, requestedSchema);
Console.WriteLine($" * Migrated model schema to: {requestedSchema}");
}

model.Save(outputPath);
Expand Down Expand Up @@ -1182,6 +1206,7 @@ private static int ExecuteView(string[] args)

var sw = Stopwatch.StartNew();
var model = IfcModel.Open(inputPath);
WarnOnPartialIfc4x3Import(model);

if (gridsPath is not null)
{
Expand Down
23 changes: 22 additions & 1 deletion src/IfcIO/Core/StepReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ public sealed class StepFile
public string? OriginatingSystem { get; set; }
public string? Authorization { get; set; }
public string? Schema { get; set; }
/// <summary>All identifiers declared in FILE_SCHEMA.</summary>
public IReadOnlyList<string> SchemaIdentifiers { get; internal set; } = [];
internal bool HasSchemaDeclaration { get; set; }

public Dictionary<int, StepEntity> Entities { get; } = new(4096);

Expand Down Expand Up @@ -284,7 +287,25 @@ IEnumerable<string> Strings(int index)
switch (statement[..open].TrimEnd().ToUpperInvariant())
{
case "FILE_SCHEMA":
file.Schema = Strings(0).FirstOrDefault();
if (file.HasSchemaDeclaration)
throw new InvalidDataException("The STEP header contains more than one FILE_SCHEMA declaration.");
file.HasSchemaDeclaration = true;
if (arguments.Count != 1 || arguments[0] is not { Length: >= 2 } list
|| list[0] != '(' || list[^1] != ')')
throw new InvalidDataException("FILE_SCHEMA must contain one list of schema identifiers.");
var schemaTokens = StepEntity.ParseArguments(list[1..^1]);
if (schemaTokens.Count == 0 || list.AsSpan(1, list.Length - 2).TrimEnd().EndsWith(","))
throw new InvalidDataException("FILE_SCHEMA must contain a nonempty list of schema identifiers.");
var identifiers = new List<string>(schemaTokens.Count);
foreach (string token in schemaTokens)
{
if (token.Length < 2 || token[0] != '\'' || token[^1] != '\''
|| StepEntity.DecodeString(token) is not { Length: > 0 } identifier)
throw new InvalidDataException("FILE_SCHEMA identifiers must be nonempty STEP strings.");
identifiers.Add(identifier);
}
file.SchemaIdentifiers = identifiers.AsReadOnly();
file.Schema = identifiers[0];
break;
case "FILE_DESCRIPTION":
file.Descriptions = Strings(0).ToArray();
Expand Down
Loading