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
3 changes: 3 additions & 0 deletions docs/public-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
4 changes: 2 additions & 2 deletions src/NwcIO.Scene/NwcSceneReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -170,7 +170,7 @@ private static string XRefNames(IReadOnlyList<NwcXRef> 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,
Expand Down
2 changes: 1 addition & 1 deletion src/NwcIO/Model/NwcAssembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions src/NwcIO/NwcDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ private NwcDocument(

internal NwcContainer Container { get; }

internal string? LoadedPath { get; private set; }
private string? _loadedPath;

/// <summary>Returns the full path passed to the file-based reader, or <see langword="null"/> for a stream or an in-memory document.</summary>
/// <remarks>This is the location of the Navisworks file. <see cref="NwcFileInfo.SourcePath"/> comes from the file's metadata.</remarks>
public string? GetLoadedPath() => _loadedPath;

/// <summary>Opens and parses a Navisworks file from disk.</summary>
/// <exception cref="FileNotFoundException">The file does not exist.</exception>
Expand All @@ -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;
}

Expand Down
1 change: 0 additions & 1 deletion src/NwcIO/NwcIO.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

<ItemGroup>
<InternalsVisibleTo Include="NwcIO.Tests" />
<InternalsVisibleTo Include="NwcIO.Scene" />
<InternalsVisibleTo Include="NwcIO.Scene.Tests" />
<InternalsVisibleTo Include="NwcIO.Cli" />
</ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions tests/NwcIO.Scene.Tests/NwcSceneReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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 =>
Expand Down
Loading