diff --git a/CadRevealComposer/CadRevealComposer.csproj b/CadRevealComposer/CadRevealComposer.csproj index 3d4effa81..39e0a2a1f 100644 --- a/CadRevealComposer/CadRevealComposer.csproj +++ b/CadRevealComposer/CadRevealComposer.csproj @@ -18,6 +18,7 @@ + diff --git a/CadRevealComposer/CadRevealComposerRunner.cs b/CadRevealComposer/CadRevealComposerRunner.cs index 5f4bcc8d8..68172b3cd 100644 --- a/CadRevealComposer/CadRevealComposerRunner.cs +++ b/CadRevealComposer/CadRevealComposerRunner.cs @@ -7,12 +7,14 @@ using Operations; using Operations.SectorSplitting; using Primitives; +using SurfaceUnits; using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text.Json; +using System.Text.RegularExpressions; using System.Threading.Tasks; using Utils; @@ -27,6 +29,7 @@ IReadOnlyList modelFormatProviders ) { var totalTimeElapsed = Stopwatch.StartNew(); + if (composerParameters.DevPrimitiveCacheFolder != null) { var primitiveCache = new DevPrimitiveCacheFolder(composerParameters.DevPrimitiveCacheFolder); @@ -42,6 +45,7 @@ IReadOnlyList modelFormatProviders ); return; } + Console.WriteLine( "Did not find a Primitive Cache file for the current input folder. Processing as normal, and saving a new cache for next run." ); @@ -83,6 +87,34 @@ IReadOnlyList modelFormatProviders // collect all nodes for later sector division of the entire scene nodesToExport.AddRange(cadRevealNodes); + // Adding Surface Unit Volume Attributes for Sleipner T + var regex = new Regex(@"^\/\d+[A-Z]\d+$"); + foreach (CadRevealNode cadRevealNode in cadRevealNodes) + { + if (cadRevealNode.Parent?.Name.Contains("/A00-AREA") == true) + { + if (regex.IsMatch(cadRevealNode.Name)) + { + cadRevealNode.Attributes.Add("SurfaceUnitVolume", "true"); + cadRevealNode.Attributes.Add(cadRevealNode.Name.TrimStart('/'), "true"); + } + } + } + + // Add Surface Unit Metadata + var files = Directory + .GetFiles(inputFolderPath.FullName, "surface_units*.csv", SearchOption.TopDirectoryOnly) + .ToList(); + if (files.Count > 0) + { + using (new TeamCityLogBlock("Surface Unit Metadata")) + { + foreach (var file in files) + { + SurfaceUnitMetaDataWriter.AddMetaData(cadRevealNodes, file); + } + } + } var inputGeometries = cadRevealNodes.AsParallel().AsOrdered().SelectMany(x => x.Geometries).ToArray(); @@ -121,6 +153,7 @@ IReadOnlyList modelFormatProviders var devCache = new DevPrimitiveCacheFolder(composerParameters.DevPrimitiveCacheFolder); devCache.WriteToPrimitiveCache(geometriesToProcessArray, inputFolderPath); } + ProcessPrimitives(geometriesToProcessArray, outputDirectory, modelParameters, composerParameters); if (!exportHierarchyDatabaseTask.IsCompleted) diff --git a/CadRevealComposer/SurfaceUnits/SurfaceUnit.cs b/CadRevealComposer/SurfaceUnits/SurfaceUnit.cs new file mode 100644 index 000000000..0c0088cd6 --- /dev/null +++ b/CadRevealComposer/SurfaceUnits/SurfaceUnit.cs @@ -0,0 +1,39 @@ +namespace CadRevealComposer.SurfaceUnits; + +using CsvHelper.Configuration.Attributes; + +public class SurfaceUnit +{ + [Name("Surface Unit 1")] + public string SurfaceUnit1 { get; set; } = null!; + + [Name("Surface Unit 2")] + public string SurfaceUnit2 { get; set; } = null!; + + [Name("Surface Unit 3")] + public string SurfaceUnit3 { get; set; } = null!; + + [Name("Surface Unit 4"), Optional] + public string SurfaceUnit4 { get; set; } = null!; + + [Name("Surface Unit 5"), Optional] + public string SurfaceUnit5 { get; set; } = null!; + + [Name("Surface Unit 6"), Optional] + public string SurfaceUnit6 { get; set; } = null!; + + [Name("Surface Unit 7"), Optional] + public string SurfaceUnit7 { get; set; } = null!; + + [Name("Surface Unit 8"), Optional] + public string SurfaceUnit8 { get; set; } = null!; + + [Name("Surface Unit 9"), Optional] + public string SurfaceUnit9 { get; set; } = null!; + + [Name("Surface Unit 10"), Optional] + public string SurfaceUnit10 { get; set; } = null!; + + [Name("E3D Reference")] + public string E3DReference { get; set; } = null!; +} diff --git a/CadRevealComposer/SurfaceUnits/SurfaceUnitMetaDataWriter.cs b/CadRevealComposer/SurfaceUnits/SurfaceUnitMetaDataWriter.cs new file mode 100644 index 000000000..38f52b0c0 --- /dev/null +++ b/CadRevealComposer/SurfaceUnits/SurfaceUnitMetaDataWriter.cs @@ -0,0 +1,97 @@ +namespace CadRevealComposer.SurfaceUnits; + +using CsvHelper; +using CsvHelper.Configuration; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; + +public static class SurfaceUnitMetaDataWriter +{ + public static void AddMetaData(IEnumerable allNodes, string filePath) + { + Console.WriteLine("Adding Surface Unit Metadata to nodes from file " + filePath); + var rvmNodes = allNodes + .Where(n => n.Attributes.ContainsKey("RefNo")) + .ToDictionary((k) => k.Attributes["RefNo"], (v) => v); + + var config = new CsvConfiguration(CultureInfo.InvariantCulture) { Delimiter = ";", }; + using var reader = new StreamReader(filePath); + using var csv = new CsvReader(reader, config); + var records = csv.GetRecords().ToList(); + + Console.WriteLine("Found " + rvmNodes.Count + " nodes with RefNo attribute."); + Console.WriteLine("Found " + records.Count + " records in file."); + int count = 0; + + foreach (var record in records) + { + try + { + var node = rvmNodes.TryGetValue(record.E3DReference, out var nodeValue) ? nodeValue : null; + if (node == null) + { + continue; + } + + node.Attributes.Add("SurfaceUnit", record.SurfaceUnit1); + node.Attributes.Add($"SU-{record.SurfaceUnit1}", "true"); + + if (!String.IsNullOrEmpty(record.SurfaceUnit2)) + { + node.Attributes.Add($"SU-{record.SurfaceUnit2}", "true"); + } + + if (!String.IsNullOrEmpty(record.SurfaceUnit3)) + { + node.Attributes.Add($"SU-{record.SurfaceUnit3}", "true"); + } + + if (!String.IsNullOrEmpty(record.SurfaceUnit4)) + { + node.Attributes.Add($"SU-{record.SurfaceUnit4}", "true"); + } + + if (!String.IsNullOrEmpty(record.SurfaceUnit5)) + { + node.Attributes.Add($"SU-{record.SurfaceUnit5}", "true"); + } + + if (!String.IsNullOrEmpty(record.SurfaceUnit6)) + { + node.Attributes.Add($"SU-{record.SurfaceUnit6}", "true"); + } + + if (!String.IsNullOrEmpty(record.SurfaceUnit7)) + { + node.Attributes.Add($"SU-{record.SurfaceUnit7}", "true"); + } + + if (!String.IsNullOrEmpty(record.SurfaceUnit8)) + { + node.Attributes.Add($"SU-{record.SurfaceUnit8}", "true"); + } + + if (!String.IsNullOrEmpty(record.SurfaceUnit9)) + { + node.Attributes.Add($"SU-{record.SurfaceUnit9}", "true"); + } + + if (!String.IsNullOrEmpty(record.SurfaceUnit10)) + { + node.Attributes.Add($"SU-{record.SurfaceUnit10}", "true"); + } + + count++; + } + catch (Exception e) + { + Console.WriteLine("Error adding metadata to node " + record.E3DReference + ": " + e.Message); + } + } + + Console.WriteLine("Added Surface Unit Metadata to {0} nodes.", count); + } +}