diff --git a/docs/public-api.md b/docs/public-api.md index 8a6aafc..6b0d786 100644 --- a/docs/public-api.md +++ b/docs/public-api.md @@ -30,6 +30,9 @@ The supported surface is the `NwcIO` and `NwcIO.Model.*` namespaces listed here | `Vector3d`, `Quaterniond`, `BoundingBox3d`, `RgbaColor` | Double-precision geometry primitives and RGBA colour. | | `NwcClash` | Simple pairwise clash check between two meshes. Frozen: bug fixes only. | +`NwcDocument.GetLoadedPath()` returns the full path of a document opened by filename. It returns `null` for +documents opened from a stream or created in memory. `NwcFileInfo.SourcePath` is the source path stored in the file. + ## Coordination & Clash Detection (`NwcIO.Model.Clash`) | Type | Description | diff --git a/src/NwcIO.Scene/NwcSceneReader.cs b/src/NwcIO.Scene/NwcSceneReader.cs index a4c2d5c..b2a4c54 100644 --- a/src/NwcIO.Scene/NwcSceneReader.cs +++ b/src/NwcIO.Scene/NwcSceneReader.cs @@ -119,7 +119,7 @@ public static NwcSceneResult Read(NwcAssembly assembly, NwcSceneOptions? options nameof(assembly)); } - var result = ConvertInto(scene, document, key, document.LoadedPath, options, modelId: scene.Models.Count + 1, usedKeys, nextSuffix); + var result = ConvertInto(scene, document, key, document.GetLoadedPath(), options, modelId: scene.Models.Count + 1, usedKeys, nextSuffix); diagnostics.AddRange(result.Diagnostics.Select(d => new SceneDiagnostic( d.Severity, d.Code, @@ -170,7 +170,7 @@ private static string XRefNames(IReadOnlyList references) => string.Join(", ", references.Take(5).Select(r => r.EffectivePath)) + (references.Count > 5 ? $" and {references.Count - 5} more" : ""); private static string? DocumentPath(NwcDocument document) => - document.LoadedPath ?? document.FileInfo.SourcePath; + document.GetLoadedPath() ?? document.FileInfo.SourcePath; private static string ModelKey( NwcDocument document, diff --git a/src/NwcIO/Model/NwcAssembly.cs b/src/NwcIO/Model/NwcAssembly.cs index 6bd85b9..4358546 100644 --- a/src/NwcIO/Model/NwcAssembly.cs +++ b/src/NwcIO/Model/NwcAssembly.cs @@ -597,7 +597,7 @@ public Clash.NwcNwfManifest ToNwfManifest() var manifest = new Clash.NwcNwfManifest(Name); for (int i = 0; i < Models.Count; i++) { - var p = Models[i].LoadedPath; + var p = Models[i].GetLoadedPath(); if (string.IsNullOrEmpty(p)) { p = Models[i].FileInfo.SourcePath; diff --git a/src/NwcIO/NwcDocument.cs b/src/NwcIO/NwcDocument.cs index 9e9f6df..f65827d 100644 --- a/src/NwcIO/NwcDocument.cs +++ b/src/NwcIO/NwcDocument.cs @@ -112,7 +112,11 @@ private NwcDocument( internal NwcContainer Container { get; } - internal string? LoadedPath { get; private set; } + private string? _loadedPath; + + /// Returns the full path passed to the file-based reader, or for a stream or an in-memory document. + /// This is the location of the Navisworks file. comes from the file's metadata. + public string? GetLoadedPath() => _loadedPath; /// Opens and parses a Navisworks file from disk. /// The file does not exist. @@ -138,7 +142,7 @@ public static NwcDocument Open( cancellationToken.ThrowIfCancellationRequested(); using var stream = File.OpenRead(path); var document = Open(stream, options, Path.GetFileNameWithoutExtension(path), progress, cancellationToken); - document.LoadedPath = Path.GetFullPath(path); + document._loadedPath = Path.GetFullPath(path); return document; } diff --git a/src/NwcIO/NwcIO.csproj b/src/NwcIO/NwcIO.csproj index 615c916..705cbfa 100644 --- a/src/NwcIO/NwcIO.csproj +++ b/src/NwcIO/NwcIO.csproj @@ -11,7 +11,6 @@ - diff --git a/tests/NwcIO.Scene.Tests/NwcSceneReaderTests.cs b/tests/NwcIO.Scene.Tests/NwcSceneReaderTests.cs index 8152f91..8119b7b 100644 --- a/tests/NwcIO.Scene.Tests/NwcSceneReaderTests.cs +++ b/tests/NwcIO.Scene.Tests/NwcSceneReaderTests.cs @@ -649,6 +649,7 @@ public void Read_Assembly_ConvertsEachDocumentWithUniqueIds() Model("A.nwc", 1, 0), Model("B.nwc", 2, 10)); + Assert.All(assembly.Models, model => Assert.Null(model.GetLoadedPath())); var result = NwcSceneReader.Read(assembly, new NwcSceneOptions { LengthUnit = NwcLengthUnit.Meters }); Assert.Equal([1, 2], result.Document.Models.Select(m => m.Id)); @@ -921,6 +922,11 @@ public void Read_AssemblyLoadedFromDirectory_UsesFileNamesForKeysAndPaths() var assembly = NwcAssembly.LoadFromDirectory(directory); var result = Valid(NwcSceneReader.Read(assembly)); + Assert.All(assembly.Models, model => + { + Assert.Equal("Tower.rvt", model.FileInfo.SourcePath); + Assert.Equal(Path.GetFullPath(directory), Path.GetDirectoryName(model.GetLoadedPath())); + }); Assert.Equal(["Arch.nwc", "Struct.nwc"], result.Document.Models.Select(model => model.Key).OrderBy(key => key, StringComparer.Ordinal)); Assert.All(result.Document.Models, model =>