Skip to content

Commit

Permalink
Update SysML Import
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickRitchie committed Oct 30, 2023
1 parent 6fdc255 commit 29025f5
Show file tree
Hide file tree
Showing 21 changed files with 582 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static void Render(MTConnectModel mtconnectModel, string outputPath)
case "UNIT_VECTOR_3D": property.DataType = "MTConnect.UnitVector3D"; break;
case "POSITION_3D": property.DataType = "MTConnect.Position3D"; break;
case "DEGREE_3D": property.DataType = "MTConnect.Degree3D"; break;
case "MILLIMETER_3D": property.DataType = "MTConnect.Millimeter3D"; break;
default:

var classMatch = dClassModels.GetValueOrDefault(property.DataType);
Expand Down
13 changes: 7 additions & 6 deletions build/MTConnect.NET-SysML-Import/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using MTConnect.SysML.CSharp;
using MTConnect.SysML.Json_cppagent;
using MTConnect.SysML.Xml;
using System.Text.Json;

var xmlPath = @"D:\TrakHound\MTConnect\MTConnectSysMLModel.xml";
//var outputPath = @"C:\temp\mtconnect-model-results";
Expand All @@ -10,13 +11,13 @@
var mtconnectModel = MTConnectModel.Parse(xmlPath);


//var jsonOptions = new JsonSerializerOptions();
//jsonOptions.WriteIndented = true;
//jsonOptions.DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault;
//jsonOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
var jsonOptions = new JsonSerializerOptions();
jsonOptions.WriteIndented = true;
jsonOptions.DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault;
jsonOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;

//var json = JsonSerializer.Serialize(mtconnectModel, options: jsonOptions);
//await File.WriteAllTextAsync(@"C:\temp\mtconnect-model.json", json);
var json = JsonSerializer.Serialize(mtconnectModel, options: jsonOptions);
await File.WriteAllTextAsync(@"C:\temp\mtconnect-model.json", json);


RenderCommonClasses();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface IMaterial
/// <summary>
/// Manufacturing date of the material from the material manufacturer.
/// </summary>
System.DateTime ManufacturingDate { get; }
System.DateTime? ManufacturingDate { get; }

/// <summary>
/// ASTM standard code that the material complies with.
Expand Down
20 changes: 10 additions & 10 deletions src/MTConnect.NET-Common/Assets/RawMaterials/IRawMaterialAsset.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ public partial interface IRawMaterialAsset : IAsset
/// <summary>
/// Dimension of material currently in raw material.
/// </summary>
System.Collections.Generic.IEnumerable<string> CurrentDimensions { get; }
MTConnect.Millimeter3D CurrentDimension { get; }

/// <summary>
/// Quantity of material currently in raw material.
/// </summary>
int CurrentQuantity { get; }
int? CurrentQuantity { get; }

/// <summary>
/// Amount of material currently in raw material.
/// </summary>
string CurrentVolume { get; }
double? CurrentVolume { get; }

/// <summary>
/// Date raw material was first used.
/// </summary>
System.DateTime FirstUseDate { get; }
System.DateTime? FirstUseDate { get; }

/// <summary>
/// Form of the raw material.
Expand All @@ -41,32 +41,32 @@ public partial interface IRawMaterialAsset : IAsset
/// <summary>
/// Material has existing usable volume.
/// </summary>
bool HasMaterial { get; }
bool? HasMaterial { get; }

/// <summary>
/// Dimension of material initially placed in raw material when manufactured.
/// </summary>
System.Collections.Generic.IEnumerable<string> InitialDimensions { get; }
MTConnect.Millimeter3D InitialDimension { get; }

/// <summary>
/// Quantity of material initially placed in raw material when manufactured.
/// </summary>
int InitialQuantity { get; }
int? InitialQuantity { get; }

/// <summary>
/// Amount of material initially placed in raw material when manufactured.
/// </summary>
string InitialVolume { get; }
double? InitialVolume { get; }

/// <summary>
/// Date raw material was last used.
/// </summary>
System.DateTime LastUseDate { get; }
System.DateTime? LastUseDate { get; }

/// <summary>
/// Date the raw material was created.
/// </summary>
System.DateTime ManufacturingDate { get; }
System.DateTime? ManufacturingDate { get; }

/// <summary>
/// Material used as the RawMaterial.
Expand Down
2 changes: 1 addition & 1 deletion src/MTConnect.NET-Common/Assets/RawMaterials/Material.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class Material : IMaterial
/// <summary>
/// Manufacturing date of the material from the material manufacturer.
/// </summary>
public System.DateTime ManufacturingDate { get; set; }
public System.DateTime? ManufacturingDate { get; set; }

/// <summary>
/// ASTM standard code that the material complies with.
Expand Down
73 changes: 73 additions & 0 deletions src/MTConnect.NET-Common/Assets/RawMaterials/RawMaterialAsset.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright (c) 2023 TrakHound Inc., All Rights Reserved.
// TrakHound Inc. licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;

namespace MTConnect.Assets.RawMaterials
{
public partial class RawMaterialAsset
{
public const string TypeId = "RawMaterial";


public RawMaterialAsset()
{
Type = TypeId;
}


//protected override IAsset OnProcess(Version mtconnectVersion)
//{
// if (mtconnectVersion != null && mtconnectVersion >= MTConnectVersions.Version18)
// {
// return this;
// }

// return null;
//}

//public override AssetValidationResult IsValid(Version mtconnectVersion)
//{
// var message = "";
// var result = true;

// if (string.IsNullOrEmpty(Form))
// {
// message = "Form property is Required";
// result = false;
// }
// else
// {
// if (Material != null && string.IsNullOrEmpty(Material.Type))
// {
// message = "Material Type property is Required";
// result = false;
// }
// }

// return new AssetValidationResult(result, message);
//}

//public override string GenerateHash()
//{
// return GenerateHash(this);
//}

//public static string GenerateHash(FileAsset asset)
//{
// if (asset != null)
// {
// var ids = new List<string>();

// ids.Add(ObjectExtensions.GetHashPropertyString(asset).ToSHA1Hash());

// // Need to include CuttingItems

// return StringFunctions.ToSHA1Hash(ids.ToArray());
// }

// return null;
//}
}
}
20 changes: 10 additions & 10 deletions src/MTConnect.NET-Common/Assets/RawMaterials/RawMaterialAsset.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ public partial class RawMaterialAsset : Asset, IRawMaterialAsset
/// <summary>
/// Dimension of material currently in raw material.
/// </summary>
public System.Collections.Generic.IEnumerable<string> CurrentDimensions { get; set; }
public MTConnect.Millimeter3D CurrentDimension { get; set; }

/// <summary>
/// Quantity of material currently in raw material.
/// </summary>
public int CurrentQuantity { get; set; }
public int? CurrentQuantity { get; set; }

/// <summary>
/// Amount of material currently in raw material.
/// </summary>
public string CurrentVolume { get; set; }
public double? CurrentVolume { get; set; }

/// <summary>
/// Date raw material was first used.
/// </summary>
public System.DateTime FirstUseDate { get; set; }
public System.DateTime? FirstUseDate { get; set; }

/// <summary>
/// Form of the raw material.
Expand All @@ -46,32 +46,32 @@ public partial class RawMaterialAsset : Asset, IRawMaterialAsset
/// <summary>
/// Material has existing usable volume.
/// </summary>
public bool HasMaterial { get; set; }
public bool? HasMaterial { get; set; }

/// <summary>
/// Dimension of material initially placed in raw material when manufactured.
/// </summary>
public System.Collections.Generic.IEnumerable<string> InitialDimensions { get; set; }
public MTConnect.Millimeter3D InitialDimension { get; set; }

/// <summary>
/// Quantity of material initially placed in raw material when manufactured.
/// </summary>
public int InitialQuantity { get; set; }
public int? InitialQuantity { get; set; }

/// <summary>
/// Amount of material initially placed in raw material when manufactured.
/// </summary>
public string InitialVolume { get; set; }
public double? InitialVolume { get; set; }

/// <summary>
/// Date raw material was last used.
/// </summary>
public System.DateTime LastUseDate { get; set; }
public System.DateTime? LastUseDate { get; set; }

/// <summary>
/// Date the raw material was created.
/// </summary>
public System.DateTime ManufacturingDate { get; set; }
public System.DateTime? ManufacturingDate { get; set; }

/// <summary>
/// Material used as the RawMaterial.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static class RawMaterialAssetDescriptions
/// <summary>
/// Dimension of material currently in raw material.
/// </summary>
public const string CurrentDimensions = "Dimension of material currently in raw material.";
public const string CurrentDimension = "Dimension of material currently in raw material.";

/// <summary>
/// Quantity of material currently in raw material.
Expand Down Expand Up @@ -43,7 +43,7 @@ public static class RawMaterialAssetDescriptions
/// <summary>
/// Dimension of material initially placed in raw material when manufactured.
/// </summary>
public const string InitialDimensions = "Dimension of material initially placed in raw material when manufactured.";
public const string InitialDimension = "Dimension of material initially placed in raw material when manufactured.";

/// <summary>
/// Quantity of material initially placed in raw material when manufactured.
Expand Down
1 change: 0 additions & 1 deletion src/MTConnect.NET-Common/MTConnect.NET-Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@
<ItemGroup>
<Folder Include="Assets\CuttingTools\Measurements\" />
<Folder Include="Assets\QIF\" />
<Folder Include="Assets\RawMaterials\" />
</ItemGroup>

</Project>
54 changes: 54 additions & 0 deletions src/MTConnect.NET-Common/Millimeter3D.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) 2023 TrakHound Inc., All Rights Reserved.
// TrakHound Inc. licenses this file to you under the MIT license.

using System.Text.RegularExpressions;

namespace MTConnect
{
public class Millimeter3D
{
private static readonly Regex _regex = new Regex(@"([0-9\.]*) ([0-9\.]*) ([0-9\.]*)");


public double X { get; set; }

public double Y { get; set; }

public double Z { get; set; }


public Millimeter3D(double x, double y, double z)
{
X = x;
Y = y;
Z = z;
}

public override string ToString()
{
return $"{X} {Y} {Z}";
}

public static Millimeter3D FromString(string input)
{
if (!string.IsNullOrEmpty(input))
{
var match = _regex.Match(input);
if (match.Success)
{
double x = 0;
double y = 0;
double z = 0;

if (match.Groups[1].Success) x = match.Groups[1].Value.ToDouble();
if (match.Groups[2].Success) y = match.Groups[2].Value.ToDouble();
if (match.Groups[3].Success) z = match.Groups[3].Value.ToDouble();

return new Millimeter3D(x, y, z);
}
}

return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class JsonMaterial
public string Manufacturer { get; set; }

[JsonPropertyName("manufacturingDate")]
public DateTime ManufacturingDate { get; set; }
public DateTime? ManufacturingDate { get; set; }

[JsonPropertyName("manufacturingCode")]
public string ManufacturingCode { get; set; }
Expand Down
Loading

0 comments on commit 29025f5

Please sign in to comment.