From 35d815e8112a2c5507d3fb4d85a838e3323c7585 Mon Sep 17 00:00:00 2001 From: mie Date: Mon, 16 Nov 2026 10:07:37 +0300 Subject: [PATCH 1/2] refactor(cli): merge folder and NWF assembly pipelines Use one ProcessAssembly(NwcAssembly, ...) implementation for both inputs. The folder path only loads NwcAssembly.LoadFromDirectory; the .nwf path only loads NwcAssembly.OpenNwf and computes its default output. Report headers, labels, default output paths and exports stay unchanged; add a regression test that runs both inputs with --report --bvh-stats. --- src/NwcIO.Cli/Program.cs | 350 +++++---------------- tests/NwcIO.Tests/AssemblyPipelineTests.cs | 59 ++++ 2 files changed, 144 insertions(+), 265 deletions(-) create mode 100644 tests/NwcIO.Tests/AssemblyPipelineTests.cs diff --git a/src/NwcIO.Cli/Program.cs b/src/NwcIO.Cli/Program.cs index eaa4b92..16775c5 100644 --- a/src/NwcIO.Cli/Program.cs +++ b/src/NwcIO.Cli/Program.cs @@ -1037,267 +1037,24 @@ private static int ProcessAssemblyDirectory( { var @out = outWriter ?? Console.Out; var @err = errorWriter ?? Console.Error; - TextWriter infoOut = (outputPath == "-") ? @err : @out; - if (outputPath != "-") { outputPath ??= Path.Combine(dirPath, Path.GetFileName(dirPath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)) + "_assembly.glb"); } var assembly = NwcAssembly.LoadFromDirectory(dirPath, options: new NwcReaderOptions { BuildSceneTree = includeTree }); - - if (!string.IsNullOrEmpty(explicitTimeLinerXmlPath)) - { - if (File.Exists(explicitTimeLinerXmlPath)) - { - assembly.ImportTimeLinerXml(explicitTimeLinerXmlPath); - if (printReport) @err.WriteLine($"TimeLiner schedule loaded from XML: '{explicitTimeLinerXmlPath}'."); - } - else - { - EnsureParentDirectory(explicitTimeLinerXmlPath); - assembly.ExportTimeLinerXml(explicitTimeLinerXmlPath); - if (printReport) @err.WriteLine($"TimeLiner schedule exported to XML: '{explicitTimeLinerXmlPath}'."); - } - } - - if (!string.IsNullOrEmpty(explicitTimeLinerMsProjectPath)) - { - if (File.Exists(explicitTimeLinerMsProjectPath)) - { - assembly.ImportTimeLinerMsProject(explicitTimeLinerMsProjectPath); - if (printReport) @err.WriteLine($"TimeLiner schedule loaded from MS Project XML: '{explicitTimeLinerMsProjectPath}'."); - } - else - { - EnsureParentDirectory(explicitTimeLinerMsProjectPath); - assembly.ExportTimeLinerMsProject(explicitTimeLinerMsProjectPath); - if (printReport) @err.WriteLine($"TimeLiner schedule exported to MS Project XML: '{explicitTimeLinerMsProjectPath}'."); - } - } - - if (!string.IsNullOrEmpty(explicitTimeLinerPrimaveraPath)) - { - if (File.Exists(explicitTimeLinerPrimaveraPath)) - { - assembly.ImportTimeLinerPrimavera(explicitTimeLinerPrimaveraPath); - if (printReport) @err.WriteLine($"TimeLiner schedule loaded from Primavera P6 XER: '{explicitTimeLinerPrimaveraPath}'."); - } - else - { - EnsureParentDirectory(explicitTimeLinerPrimaveraPath); - assembly.ExportTimeLinerPrimavera(explicitTimeLinerPrimaveraPath); - if (printReport) @err.WriteLine($"TimeLiner schedule exported to Primavera P6 XER: '{explicitTimeLinerPrimaveraPath}'."); - } - } - - if (linkTimeLiner && assembly.TimeLiner is not null) - { - int linked = Model.TimeLiner.NwcTimeLinerLinker.AutoLink(assembly.TimeLiner, assembly.SelectionSets); - infoOut.WriteLine($"Linked {linked} TimeLiner tasks to assembly elements."); - } - - if (!string.IsNullOrEmpty(explicitProfilerPath)) - { - if (!File.Exists(explicitProfilerPath)) - { - @err.WriteLine($"Error: Appearance profiler file not found: {explicitProfilerPath}"); - return 2; - } - var profiler = Model.Appearance.NwcXmlAppearanceProfilerSerializer.Open(explicitProfilerPath); - int overridden = assembly.ApplyAppearanceProfiler(profiler); - if (printReport) - { - @err.WriteLine($"Appearance profiler applied to assembly: {overridden} elements overridden."); - } - } - - IReadOnlyList? clashes = null; - bool needClashes = checkClashes || - !string.IsNullOrEmpty(explicitBcfPath) || - !string.IsNullOrEmpty(explicitClashHtmlPath) || - outputPath.EndsWith(".bcf", StringComparison.OrdinalIgnoreCase) || - outputPath.EndsWith(".bcfzip", StringComparison.OrdinalIgnoreCase) || - outputPath.EndsWith(".html", StringComparison.OrdinalIgnoreCase) || - outputPath.EndsWith(".htm", StringComparison.OrdinalIgnoreCase); - - if (needClashes) - { - clashes = assembly.FindClashes(); - } - - if (outputPath.EndsWith(".bcf", StringComparison.OrdinalIgnoreCase) || outputPath.EndsWith(".bcfzip", StringComparison.OrdinalIgnoreCase)) - { - EnsureParentDirectory(outputPath); - assembly.SaveBcf(outputPath, clashes); - } - else if (outputPath.EndsWith(".html", StringComparison.OrdinalIgnoreCase) || outputPath.EndsWith(".htm", StringComparison.OrdinalIgnoreCase)) - { - EnsureParentDirectory(outputPath); - assembly.SaveClashReportHtml(outputPath, clashes); - } - else if (outputPath.EndsWith(".ifc", StringComparison.OrdinalIgnoreCase)) - { - EnsureParentDirectory(outputPath); - assembly.SaveIfc(outputPath, ifcOptions); - } - else if (outputPath.EndsWith(".glb", StringComparison.OrdinalIgnoreCase)) - { - EnsureParentDirectory(outputPath); - assembly.SaveGlb(outputPath, worldCoords); - } - else if (outputPath.EndsWith(".obj", StringComparison.OrdinalIgnoreCase)) - { - EnsureParentDirectory(outputPath); - assembly.SaveObj(outputPath, worldCoords); - } - else if (outputPath.EndsWith(".nwc", StringComparison.OrdinalIgnoreCase)) - { - EnsureParentDirectory(outputPath); - var merged = NwcDocument.Create( - fileInfo: new NwcFileInfo { SourcePath = assembly.Name + ".rvt" }, - meshes: assembly.AllMeshes); - merged.Save(outputPath); - } - else if (outputPath == "-") - { - if (stdoutStream != null) - { - assembly.SaveJson(stdoutStream, new NwcJsonExportOptions { Indented = indent }); - stdoutStream.Flush(); - } - else - { - using var stdout = Console.OpenStandardOutput(); - assembly.SaveJson(stdout, new NwcJsonExportOptions { Indented = indent }); - stdout.Flush(); - } - } - else - { - EnsureParentDirectory(outputPath); - assembly.SaveJson(outputPath, new NwcJsonExportOptions { Indented = indent }); - } - - if (!string.IsNullOrEmpty(explicitIfcPath)) { EnsureParentDirectory(explicitIfcPath); assembly.SaveIfc(explicitIfcPath, ifcOptions); } - if (!string.IsNullOrEmpty(explicitNwcPath)) - { - EnsureParentDirectory(explicitNwcPath); - var merged = NwcDocument.Create( - fileInfo: new NwcFileInfo { SourcePath = assembly.Name + ".rvt" }, - meshes: assembly.AllMeshes); - merged.Save(explicitNwcPath); - } - if (!string.IsNullOrEmpty(explicitGlbPath)) { EnsureParentDirectory(explicitGlbPath); assembly.SaveGlb(explicitGlbPath, worldCoords); } - if (!string.IsNullOrEmpty(explicitObjPath)) { EnsureParentDirectory(explicitObjPath); assembly.SaveObj(explicitObjPath, worldCoords); } - if (!string.IsNullOrEmpty(explicitBcfPath)) { EnsureParentDirectory(explicitBcfPath); assembly.SaveBcf(explicitBcfPath, clashes); } - if (!string.IsNullOrEmpty(explicitViewpointsBcfPath)) { EnsureParentDirectory(explicitViewpointsBcfPath); assembly.SaveViewpointsBcf(explicitViewpointsBcfPath); } - if (!string.IsNullOrEmpty(explicitViewpointsXmlPath)) { EnsureParentDirectory(explicitViewpointsXmlPath); assembly.SaveViewpointsXml(explicitViewpointsXmlPath); } - if (!string.IsNullOrEmpty(explicitClashHtmlPath)) { EnsureParentDirectory(explicitClashHtmlPath); assembly.SaveClashReportHtml(explicitClashHtmlPath, clashes); } - if (!string.IsNullOrEmpty(explicitClashXmlPath)) - { - EnsureParentDirectory(explicitClashXmlPath); - var test = assembly.RunClashDetection("Federated Clash Test", clashTolerance); - ApplyClashGrouping(test, clashGroupMode, clashRadius, printReport, @err); - assembly.ExportClashReportXml(explicitClashXmlPath); - } - if (!string.IsNullOrEmpty(explicitClashBcfPath)) - { - EnsureParentDirectory(explicitClashBcfPath); - if (assembly.ClashTests.Count == 0) - { - var test = assembly.RunClashDetection("Federated Clash Test", clashTolerance); - ApplyClashGrouping(test, clashGroupMode, clashRadius, printReport, @err); - } - assembly.ExportClashBcf(explicitClashBcfPath); - } - if (!string.IsNullOrEmpty(explicitHtmlViewerPath)) - { - EnsureParentDirectory(explicitHtmlViewerPath); - assembly.SaveHtmlViewer(explicitHtmlViewerPath); - } - if (!string.IsNullOrEmpty(explicitNwfXmlPath)) - { - EnsureParentDirectory(explicitNwfXmlPath); - assembly.SaveNwf(explicitNwfXmlPath); - } - - bool needMatrix = !string.IsNullOrEmpty(explicitClashMatrixJsonPath) || - !string.IsNullOrEmpty(explicitClashMatrixMdPath) || - !string.IsNullOrEmpty(explicitClashMatrixBcfPath); - - if (needMatrix) - { - assembly.ClashMatrix ??= Model.Clash.NwcClashMatrix.CreateFromAssembly(assembly); - assembly.ClashMatrix.Execute(assembly); - - if (!string.IsNullOrEmpty(explicitClashMatrixJsonPath)) - { - EnsureParentDirectory(explicitClashMatrixJsonPath); - assembly.ExportClashMatrixJson(explicitClashMatrixJsonPath, indent); - if (printReport) @err.WriteLine($"Clash matrix exported to JSON: '{explicitClashMatrixJsonPath}'."); - } - if (!string.IsNullOrEmpty(explicitClashMatrixMdPath)) - { - EnsureParentDirectory(explicitClashMatrixMdPath); - assembly.ExportClashMatrixMarkdown(explicitClashMatrixMdPath); - if (printReport) @err.WriteLine($"Clash matrix summary exported to Markdown: '{explicitClashMatrixMdPath}'."); - } - if (!string.IsNullOrEmpty(explicitClashMatrixBcfPath)) - { - EnsureParentDirectory(explicitClashMatrixBcfPath); - assembly.ExportClashMatrixBcf(explicitClashMatrixBcfPath); - if (printReport) @err.WriteLine($"Clash matrix conflicts exported to BCF 2.1: '{explicitClashMatrixBcfPath}'."); - } - - infoOut.WriteLine(assembly.ClashMatrix.ToMarkdownTable()); - } - - if (!string.IsNullOrEmpty(raycastArg)) - { - ExecuteRaycastTest(assembly.SpatialIndex, raycastArg, infoOut, @err); - } - - if (listViewpoints) - { - PrintViewpoints(assembly.SavedViewpoints, infoOut); - } - - sw.Stop(); - - if (printReport) - { - @err.WriteLine("=== NwcIO Assembly Report ==="); - @err.WriteLine($"Assembly: {assembly.Name}"); - @err.WriteLine($"Models: {assembly.Models.Count}"); - @err.WriteLine($"Total Meshes: {assembly.AllMeshes.Count}"); - @err.WriteLine($"Total Materials: {assembly.AllMaterials.Count}"); - @err.WriteLine($"Saved viewpoints: {assembly.SavedViewpoints.Count}"); - @err.WriteLine($"Bounding Box: {assembly.BoundingBox}"); - if (bvhStats) - { - var idx = assembly.SpatialIndex; - @err.WriteLine($"BVH Nodes: {idx.NodeCount} ({idx.LeafCount} leaves, max depth {idx.MaxDepth})"); - } - if (clashes is not null) - { - @err.WriteLine($"Clashes Detected: {clashes.Count}"); - } - @err.WriteLine($"Elapsed: {sw.ElapsedMilliseconds} ms"); - @err.WriteLine($"Output: {outputPath}"); - } - else - { - infoOut.WriteLine(FormattableString.Invariant( - $"Assembly '{assembly.Name}': {assembly.Models.Count} models, {assembly.AllMeshes.Count} meshes, {assembly.AllMaterials.Count} materials exported to '{outputPath}' in {sw.ElapsedMilliseconds} ms.")); - } - - return 0; + return ProcessAssembly( + dirPath, outputPath!, explicitGlbPath, explicitObjPath, explicitIfcPath, explicitNwcPath, + explicitBcfPath, explicitViewpointsBcfPath, explicitViewpointsXmlPath, explicitClashHtmlPath, explicitProfilerPath, + worldCoords, checkClashes, listViewpoints, bvhStats, raycastArg, printReport, indent, ifcOptions, sw, + explicitClashXmlPath, explicitClashBcfPath, explicitNwfXmlPath, clashTolerance, explicitHtmlViewerPath, clashGroupMode, clashRadius, + explicitTimeLinerXmlPath, linkTimeLiner, explicitClashMatrixJsonPath, explicitClashMatrixMdPath, explicitClashMatrixBcfPath, + explicitTimeLinerMsProjectPath, explicitTimeLinerPrimaveraPath, includeTree, + stdoutStream, @out, @err, preloadedAssembly: assembly, isNwf: false); } - - private static int ProcessNwfAssembly( - string nwfPath, - string? outputPath, + private static int ProcessAssembly( + string sourceLabel, + string outputPath, string? explicitGlbPath, string? explicitObjPath, string? explicitIfcPath, @@ -1333,17 +1090,15 @@ private static int ProcessNwfAssembly( bool includeTree = true, Stream? stdoutStream = null, TextWriter? outWriter = null, - TextWriter? errorWriter = null) + TextWriter? errorWriter = null, + NwcAssembly? preloadedAssembly = null, + bool isNwf = true) { var @out = outWriter ?? Console.Out; var @err = errorWriter ?? Console.Error; TextWriter infoOut = (outputPath == "-") ? @err : @out; - if (outputPath != "-") - { - outputPath ??= Path.ChangeExtension(nwfPath, ".glb"); - } - var assembly = NwcAssembly.OpenNwf(nwfPath, new NwcReaderOptions { BuildSceneTree = includeTree }); + var assembly = preloadedAssembly ?? NwcAssembly.OpenNwf(sourceLabel, new NwcReaderOptions { BuildSceneTree = includeTree }); if (!string.IsNullOrEmpty(explicitTimeLinerXmlPath)) { @@ -1566,10 +1321,18 @@ private static int ProcessNwfAssembly( if (printReport) { - @err.WriteLine("=== NwcIO NWF Assembly Report ==="); - @err.WriteLine($"NWF File: {nwfPath}"); - // Models[0] is the .nwf document itself; report the component files separately. - @err.WriteLine($"Loaded Models: {assembly.Models.Count} (component files: {assembly.Models.Count - 1})"); + @err.WriteLine(isNwf ? "=== NwcIO NWF Assembly Report ===" : "=== NwcIO Assembly Report ==="); + if (isNwf) + { + @err.WriteLine($"NWF File: {sourceLabel}"); + // Models[0] is the .nwf document itself; report the component files separately. + @err.WriteLine($"Loaded Models: {assembly.Models.Count} (component files: {assembly.Models.Count - 1})"); + } + else + { + @err.WriteLine($"Assembly: {assembly.Name}"); + @err.WriteLine($"Models: {assembly.Models.Count}"); + } @err.WriteLine($"Total Meshes: {assembly.AllMeshes.Count}"); @err.WriteLine($"Total Materials: {assembly.AllMaterials.Count}"); @err.WriteLine($"Saved viewpoints: {assembly.SavedViewpoints.Count}"); @@ -1597,12 +1360,69 @@ private static int ProcessNwfAssembly( else { infoOut.WriteLine(FormattableString.Invariant( - $"NWF Assembly '{assembly.Name}': {assembly.Models.Count} models, {assembly.AllMeshes.Count} meshes, {assembly.AllMaterials.Count} materials exported to '{outputPath}' in {sw.ElapsedMilliseconds} ms.")); + $"{(isNwf ? "NWF Assembly" : "Assembly")} '{assembly.Name}': {assembly.Models.Count} models, {assembly.AllMeshes.Count} meshes, {assembly.AllMaterials.Count} materials exported to '{outputPath}' in {sw.ElapsedMilliseconds} ms.")); } return 0; } + private static int ProcessNwfAssembly( + string nwfPath, + string? outputPath, + string? explicitGlbPath, + string? explicitObjPath, + string? explicitIfcPath, + string? explicitNwcPath, + string? explicitBcfPath, + string? explicitViewpointsBcfPath, + string? explicitViewpointsXmlPath, + string? explicitClashHtmlPath, + string? explicitProfilerPath, + bool worldCoords, + bool checkClashes, + bool listViewpoints, + bool bvhStats, + string? raycastArg, + bool printReport, + bool indent, + NwcIfcExportOptions ifcOptions, + Stopwatch sw, + string? explicitClashXmlPath = null, + string? explicitClashBcfPath = null, + string? explicitNwfXmlPath = null, + double clashTolerance = 0.001, + string? explicitHtmlViewerPath = null, + string? clashGroupMode = null, + double clashRadius = 1.0, + string? explicitTimeLinerXmlPath = null, + bool linkTimeLiner = false, + string? explicitClashMatrixJsonPath = null, + string? explicitClashMatrixMdPath = null, + string? explicitClashMatrixBcfPath = null, + string? explicitTimeLinerMsProjectPath = null, + string? explicitTimeLinerPrimaveraPath = null, + bool includeTree = true, + Stream? stdoutStream = null, + TextWriter? outWriter = null, + TextWriter? errorWriter = null) + { + var @out = outWriter ?? Console.Out; + var @err = errorWriter ?? Console.Error; + if (outputPath != "-") + { + outputPath ??= Path.ChangeExtension(nwfPath, ".glb"); + } + + return ProcessAssembly( + nwfPath, outputPath!, explicitGlbPath, explicitObjPath, explicitIfcPath, explicitNwcPath, + explicitBcfPath, explicitViewpointsBcfPath, explicitViewpointsXmlPath, explicitClashHtmlPath, explicitProfilerPath, + worldCoords, checkClashes, listViewpoints, bvhStats, raycastArg, printReport, indent, ifcOptions, sw, + explicitClashXmlPath, explicitClashBcfPath, explicitNwfXmlPath, clashTolerance, explicitHtmlViewerPath, clashGroupMode, clashRadius, + explicitTimeLinerXmlPath, linkTimeLiner, explicitClashMatrixJsonPath, explicitClashMatrixMdPath, explicitClashMatrixBcfPath, + explicitTimeLinerMsProjectPath, explicitTimeLinerPrimaveraPath, includeTree, + stdoutStream, @out, @err, isNwf: true); + } + private static void PrintViewpoints(IReadOnlyList viewpoints, TextWriter? writer = null) { var @out = writer ?? Console.Out; diff --git a/tests/NwcIO.Tests/AssemblyPipelineTests.cs b/tests/NwcIO.Tests/AssemblyPipelineTests.cs new file mode 100644 index 0000000..a44fe77 --- /dev/null +++ b/tests/NwcIO.Tests/AssemblyPipelineTests.cs @@ -0,0 +1,59 @@ +using NwcIO.Internal.Container; +using NwcIO.Model; +using Xunit; + +namespace NwcIO.Tests; + +public sealed class AssemblyPipelineTests +{ + [Fact] + public void FolderAndNwf_UseTheSameReportPipeline() + { + string directory = Path.Combine(Path.GetTempPath(), "nwcio-pipeline-" + Guid.NewGuid().ToString("N")); + Directory.CreateDirectory(directory); + try + { + string model = Path.Combine(directory, "a.nwc"); + NwcDocument.Create().Save(model); + + var folder = Run([directory, Path.Combine(directory, "folder.json"), "--report", "--bvh-stats"]); + Assert.Equal(0, folder.ExitCode); + Assert.Contains("=== NwcIO Assembly Report ===", folder.StdErr); + Assert.Contains("Assembly:", folder.StdErr); + Assert.Contains("Total Materials:", folder.StdErr); + Assert.Contains("BVH Nodes:", folder.StdErr); + + string nwf = Path.Combine(directory, "fed.nwf"); + WriteNwfWithXRefs(nwf, model); + + var nwfRun = Run([nwf, Path.Combine(directory, "nwf.json"), "--report", "--bvh-stats"]); + Assert.Equal(0, nwfRun.ExitCode); + Assert.Contains("=== NwcIO NWF Assembly Report ===", nwfRun.StdErr); + Assert.Contains("Loaded Models:", nwfRun.StdErr); + Assert.Contains("Total Materials:", nwfRun.StdErr); + Assert.Contains("BVH Nodes:", nwfRun.StdErr); + } + finally + { + Directory.Delete(directory, recursive: true); + } + } + + private static (int ExitCode, string StdOut, string StdErr) Run(params string[] args) + { + using var stdout = new StringWriter(); + using var stderr = new StringWriter(); + int exit = NwcIO.Cli.Program.Run(args, stdoutStream: null, outWriter: stdout, errorWriter: stderr); + return (exit, stdout.ToString(), stderr.ToString()); + } + + private static void WriteNwfWithXRefs(string nwfPath, params string[] effectivePaths) + { + string table = string.Join(",", effectivePaths.Select(p => + "{\"OriginalPath\":\"" + p.Replace('\\', '/') + "\",\"RemappedPath\":\"\"}")); + string json = "{\"Type\":\"XRefTable\",\"Version\":1,\"SavedFilename\":\"fed.nwf\",\"Table\":[" + table + "]}"; + byte[] xrefStream = System.Text.Encoding.UTF8.GetBytes(json); + using var fs = File.Create(nwfPath); + NwcContainerWriter.Write(fs, [xrefStream]); + } +} From b9779d1c49558716f131578b8790f2928825f1da Mon Sep 17 00:00:00 2001 From: mie Date: Mon, 16 Nov 2026 10:07:54 +0300 Subject: [PATCH 2/2] docs: note the merged assembly pipeline Record that folder and .nwf inputs now use the same ProcessAssembly implementation. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c818189..bc25b35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to the `NwcIO` library, the CLI and the `NwcIO.Scene` adapte - `NwcIO.Scene` diagnostics for document content the conversion leaves out: `xrefs-skipped` (Warning, with the number of external references, for example the models of a `.nwf` file), `selection-sets-skipped`, `timeliner-skipped` and `clash-tests-skipped` (Warning, each only when the document has that content), and `properties-skipped` (Info, the number of property values left out for a reason other than an unknown unit). A document with none of this content gets none of them. ### Changed +- The CLI folder and `.nwf` assembly paths now share one `ProcessAssembly(NwcAssembly, …)` pipeline. Default output paths and the `NwcIO Assembly Report` / `NwcIO NWF Assembly Report` labels are unchanged; the folder path only loads the assembly and the `.nwf` path only loads the native file before delegating. - The `NwcIO` and `NwcIO.Cli` package tags no longer name the frozen viewer and coordination extras (`clash-detection`, `clash-matrix`, `clash-grouping`, `model-diff`, `diff`, `grid-system`, `grids`, `measure`, `measurement`, `bcf`, `bcfzip`, `html-viewer`, `webgl`, `spatial-index`, `bvh`), and the `NwcIO.Scene` package has its own tags (`navisworks`, `nwc`, `ioscene`, `scene`, `bim`). ### Fixed