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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
path: coverage/**/coverage.cobertura.xml
if-no-files-found: error
- run: dotnet pack NwcIO.slnx -c Release --no-build -o artifacts
- run: dotnet build src/NwcIO.Scene/NwcIO.Scene.csproj -c Release -p:BuildNativeCoreOnly=true --artifacts-path native-core-check
- uses: actions/upload-artifact@v7
with:
name: packages-${{ matrix.os }}
Expand Down
15 changes: 12 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,22 @@ Report security vulnerabilities privately through the **Security** tab.
## Library boundaries

The native reader, writer and JSON output follow the Navisworks file model.
The frozen convenience methods on `NwcDocument` and `NwcAssembly` are in
`src/NwcIO/Compatibility`. They keep their existing signatures and assembly
so applications can continue using them while replacements are developed.
The frozen exports, viewer, coordination and XML federation manifest live in
`src/NwcIO/Compatibility`. The regular library keeps their signatures,
namespaces and assembly identity. Binary NWF reading stays with the engine.
Keep new native-format operations with the reader or writer.
The CLI uses the public APIs of NwcIO and NwcIO.Scene. Command-specific
presentation, such as model labels in raycast output, belongs to the CLI.

CI also compiles the native library and its scene adapter with the compatibility
sources excluded.
Use a separate artifact path for this compile check. It keeps the regular
build available for testing and produces no NuGet package.

```sh
dotnet build src/NwcIO.Scene/NwcIO.Scene.csproj -c Release -p:BuildNativeCoreOnly=true --artifacts-path ./artifacts/native-core-check
```

## Test Fixtures

Tests requiring real Navisworks files are skipped automatically unless the environment variable `NWCIO_TEST_FILES` is set to a directory containing private test models. The repository ships no proprietary Navisworks models.
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ NwcIO reads and writes its own format. These extras are frozen: they receive bug

JSON export (`NwcDocument.SaveJson`, `nwcio model.nwc model.json`) is not frozen: it is core and grows with the reader.

Viewing will move to [IOViewer](https://github.com/IOExtend/IOViewer) through the `NwcIO.Scene` adapter over the shared `IOScene` model. Coordination features such as clash, measure, diff, and BCF will move to a planned `IOCoord` package, and GLB export to a shared GLB writer in a planned `IOScene.Formats` package. `IOCoord` and `IOScene.Formats` are not published yet. The frozen features stay available and are removed no earlier than NwcIO 1.0, and only after a published replacement exists.
For viewing through [IOViewer](https://github.com/IOExtend/IOViewer), use `NwcIO.Scene` in .NET or export the scene with
`nwcio model.nwc --scene model.scene.json`. The [IOScene tools source previews](https://github.com/IOExtend/IOScene/blob/main/docs/tools.md)
provide a shared GLB writer in `IOScene.Formats` and coordination queries and BCF export in `IOCoord`. The existing frozen
features stay in the regular `NwcIO` package and are removed no earlier than NwcIO 1.0, and only after a published replacement exists.

## Build from source and tests

Expand Down
14 changes: 14 additions & 0 deletions src/NwcIO.Scene/Compatibility/NwcSceneReader.Compatibility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using IOScene;

namespace NwcIO.Scene;

public static partial class NwcSceneReader
{
static partial void ReportLegacyClashTests(NwcDocument document, List<SceneDiagnostic> diagnostics)
{
if (document.ClashTests.Count > 0)
{
diagnostics.Add(new SceneDiagnostic(SceneSeverity.Warning, "clash-tests-skipped", "Clash tests are not converted."));
}
}
}
8 changes: 8 additions & 0 deletions src/NwcIO.Scene/NwcIO.Scene.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
<NoWarn>$(NoWarn);NU5104</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(BuildNativeCoreOnly)' == 'true'">
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup Condition="'$(BuildNativeCoreOnly)' == 'true'">
<Compile Remove="Compatibility/**/*.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\NwcIO\NwcIO.csproj" />
<PackageReference Include="IOScene" />
Expand Down
7 changes: 3 additions & 4 deletions src/NwcIO.Scene/NwcSceneReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -524,10 +524,7 @@ private static NwcSceneResult ConvertInto(
diagnostics.Add(new SceneDiagnostic(SceneSeverity.Warning, "timeliner-skipped", "The TimeLiner schedule is not converted."));
}

if (document.ClashTests.Count > 0)
{
diagnostics.Add(new SceneDiagnostic(SceneSeverity.Warning, "clash-tests-skipped", "Clash tests are not converted."));
}
ReportLegacyClashTests(document, diagnostics);

if (propertyValuesSkipped > 0)
{
Expand All @@ -548,6 +545,8 @@ private static NwcSceneResult ConvertInto(
};
}

static partial void ReportLegacyClashTests(NwcDocument document, List<SceneDiagnostic> diagnostics);

// OST_Grids (-2000220) in the element's own LcRevitData_Element tab.
private static bool IsGrid(NwcNode node) =>
node.PropertyTabs.Any(t => t.InternalName == "LcRevitData_Element"
Expand Down
File renamed without changes.
123 changes: 123 additions & 0 deletions src/NwcIO/Compatibility/NwcAssembly.Compatibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,129 @@ namespace NwcIO.Model;

public sealed partial class NwcAssembly
{
/// <summary>Multi-discipline clash coordination matrix associated with the assembly.</summary>
public Clash.NwcClashMatrix? ClashMatrix { get; set; }

/// <summary>
/// Opens a federation manifest (.nwf.xml) and loads the .nwc/.nwd models it lists.
/// Relative paths are resolved under the manifest folder; an absolute path is tried as written first
/// and then by its trailing segments under the manifest folder. Backslashes in stored paths are read as
/// directory separators on every platform. Only the model list is read: viewpoints, sets, appearance
/// rules and clash tests of the manifest are not loaded.
/// Missing and unsupported entries are recorded on <see cref="UnresolvedXRefs"/>
/// and <see cref="SkippedXRefs"/>.
/// </summary>
/// <exception cref="FileNotFoundException">The manifest is missing, or none of its models could be resolved.</exception>
public static NwcAssembly OpenManifest(string manifestPath, NwcReaderOptions? options = null)
=> OpenManifest(manifestPath, options, null, default);

/// <summary>
/// Opens a federation manifest with cancellation and progress for each listed model.
/// </summary>
public static NwcAssembly OpenManifest(
string manifestPath,
NwcReaderOptions? options,
IProgress<NwcProgress>? progress,
CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(manifestPath);
if (!File.Exists(manifestPath))
{
throw new FileNotFoundException($"Manifest file not found: {manifestPath}", manifestPath);
}

var manifest = Clash.NwcNwfManifest.Open(manifestPath);
var baseDir = Path.GetDirectoryName(Path.GetFullPath(manifestPath)) ?? ".";
var loadedDocs = new List<NwcDocument>();
var loadedPaths = new HashSet<string>(OperatingSystem.IsWindows()
? StringComparer.OrdinalIgnoreCase
: StringComparer.Ordinal);
var unresolved = new List<NwcXRef>();
var skipped = new List<NwcXRef>();

int processed = 0;
foreach (var modelPath in manifest.ModelPaths)
{
cancellationToken.ThrowIfCancellationRequested();
progress?.Report(new NwcProgress("load-models", processed++, manifest.ModelPaths.Count));
var xref = new NwcXRef(modelPath.Replace('\\', Path.DirectorySeparatorChar), "");
if (!xref.TryResolve(baseDir, out string resolved))
{
unresolved.Add(xref);
continue;
}

if (!resolved.EndsWith(".nwc", StringComparison.OrdinalIgnoreCase) &&
!resolved.EndsWith(".nwd", StringComparison.OrdinalIgnoreCase))
{
skipped.Add(xref);
continue;
}

if (loadedPaths.Add(Path.GetFullPath(resolved)))
{
loadedDocs.Add(NwcDocument.Open(resolved, options, null, cancellationToken));
}
}

if (loadedDocs.Count == 0)
{
throw new FileNotFoundException(
$"No .nwc or .nwd models listed in manifest '{manifestPath}' could be resolved.");
}

progress?.Report(new NwcProgress("load-models", manifest.ModelPaths.Count, manifest.ModelPaths.Count));
string fileName = Path.GetFileNameWithoutExtension(manifestPath);
string assemblyName = fileName.EndsWith(".nwf", StringComparison.OrdinalIgnoreCase)
? Path.GetFileNameWithoutExtension(fileName)
: fileName;
var assembly = Create(assemblyName, loadedDocs);
assembly.UnresolvedXRefs = unresolved;
assembly.SkippedXRefs = skipped;
return assembly;
}

/// <summary>Creates a Navisworks Federated Project Manifest (NWF) representation of this assembly.</summary>
public Clash.NwcNwfManifest ToNwfManifest()
{
var manifest = new Clash.NwcNwfManifest(Name);
for (int i = 0; i < Models.Count; i++)
{
var p = Models[i].GetLoadedPath();
if (string.IsNullOrEmpty(p))
{
p = Models[i].FileInfo.SourcePath;
}
if (!string.IsNullOrEmpty(p))
{
manifest.ModelPaths.Add(p);
}
}
manifest.SavedViewpoints.AddRange(SavedViewpoints);
manifest.Sets.AddRange(SelectionSets);
foreach (var model in Models)
{
if (model.AppearanceProfiler is not null)
{
manifest.AppearanceProfiler.Rules.AddRange(model.AppearanceProfiler.Rules);
}
}
manifest.ClashTests.AddRange(ClashTests);
return manifest;
}

/// <summary>Saves the assembly coordination manifest as a Navisworks NWF coordination file (.nwf.xml).</summary>
public void SaveNwf(string path)
{
var manifest = ToNwfManifest();
var directory = Path.GetDirectoryName(Path.GetFullPath(path))!;
for (var i = 0; i < manifest.ModelPaths.Count; i++)
{
manifest.ModelPaths[i] = Path.GetRelativePath(directory, manifest.ModelPaths[i]);
}
manifest.Save(path);
}

/// <summary>
/// Applies an appearance profiler across all contributing models in the federated assembly.
/// </summary>
Expand Down
13 changes: 5 additions & 8 deletions src/NwcIO/Compatibility/NwcDocument.Compatibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ namespace NwcIO;

public sealed partial class NwcDocument
{
/// <summary>Applies an appearance profiler to colorize the document based on property rules.</summary>
/// <returns>The total number of scene nodes and meshes whose appearance was overridden.</returns>
public int ApplyAppearanceProfiler(Model.Appearance.NwcAppearanceProfiler profiler)
{
ArgumentNullException.ThrowIfNull(profiler);
AppearanceProfiler = profiler;
return profiler.Apply(this);
}
/// <summary>Configured Clash Detective tests and results for this document.</summary>
public List<Model.Clash.NwcClashTest> ClashTests { get; } = [];

/// <summary>Spatial grid system (axes and levels) associated with the document.</summary>
public Model.Grids.NwcGridSystem? GridSystem { get; set; }

/// <summary>Exports the document appearance profiler rules to a Navisworks XML format (.xml).</summary>
public void ExportAppearanceProfilerXml(string path)
Expand Down
16 changes: 16 additions & 0 deletions src/NwcIO/Compatibility/NwcDocumentBuilder.Compatibility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace NwcIO;

public sealed partial class NwcDocumentBuilder
{
private readonly List<Model.Clash.NwcClashTest> _clashTests = [];

/// <summary>Adds a Clash Detective test to the document.</summary>
public NwcDocumentBuilder AddClashTest(Model.Clash.NwcClashTest test)
{
ArgumentNullException.ThrowIfNull(test);
_clashTests.Add(test);
return this;
}

partial void AddConfiguredClashTests(NwcDocument document) => document.ClashTests.AddRange(_clashTests);
}
Loading
Loading