Skip to content
Draft
1 change: 1 addition & 0 deletions CadRevealComposer/CadRevealComposer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<PackageReference Include="protobuf-net" Version="3.2.30" />
<PackageReference Include="SharpGLTF.Core" Version="1.0.0-alpha0029" />
<PackageReference Include="System.Drawing.Common" Version="8.0.4" />
<PackageReference Include="CsvHelper" Version="30.0.1" />
</ItemGroup>

</Project>
33 changes: 33 additions & 0 deletions CadRevealComposer/CadRevealComposerRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -27,6 +29,7 @@ IReadOnlyList<IModelFormatProvider> modelFormatProviders
)
{
var totalTimeElapsed = Stopwatch.StartNew();

if (composerParameters.DevPrimitiveCacheFolder != null)
{
var primitiveCache = new DevPrimitiveCacheFolder(composerParameters.DevPrimitiveCacheFolder);
Expand All @@ -42,6 +45,7 @@ IReadOnlyList<IModelFormatProvider> 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."
);
Expand Down Expand Up @@ -83,6 +87,34 @@ IReadOnlyList<IModelFormatProvider> 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();

Expand Down Expand Up @@ -121,6 +153,7 @@ IReadOnlyList<IModelFormatProvider> modelFormatProviders
var devCache = new DevPrimitiveCacheFolder(composerParameters.DevPrimitiveCacheFolder);
devCache.WriteToPrimitiveCache(geometriesToProcessArray, inputFolderPath);
}

ProcessPrimitives(geometriesToProcessArray, outputDirectory, modelParameters, composerParameters);

if (!exportHierarchyDatabaseTask.IsCompleted)
Expand Down
39 changes: 39 additions & 0 deletions CadRevealComposer/SurfaceUnits/SurfaceUnit.cs
Original file line number Diff line number Diff line change
@@ -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!;
}
97 changes: 97 additions & 0 deletions CadRevealComposer/SurfaceUnits/SurfaceUnitMetaDataWriter.cs
Original file line number Diff line number Diff line change
@@ -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<CadRevealNode> 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<SurfaceUnit>().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);
}
}