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 29, 2023
1 parent 3273eb3 commit b827cae
Show file tree
Hide file tree
Showing 42 changed files with 1,773 additions and 88 deletions.
7 changes: 6 additions & 1 deletion build/MTConnect.NET-SysML-Import/CSharp/TemplateRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ public static void Render(MTConnectModel mtconnectModel, string outputPath)

case "Assets.Asset": ((ClassModel)template).IsPartial = true; break;
case "Assets.ComponentConfigurationParameters.ComponentConfigurationParameter": ((ClassModel)template).IsPartial = true; break;
case "Assets.CuttingTools.CuttingTool": ((ClassModel)template).IsPartial = true; break;
case "Assets.CuttingTools.CuttingTool":
((ClassModel)template).IsPartial = true;
((ClassModel)template).Id += "Asset";
((ClassModel)template).Name += "Asset";
if (((ClassModel)template).ParentName != null && ((ClassModel)template).ParentName != "Asset") ((ClassModel)template).ParentName += "Asset";
break;
case "Assets.CuttingTools.CuttingToolLifeCycle": ((ClassModel)template).IsPartial = true; break;
case "Assets.CuttingTools.CuttingItem": ((ClassModel)template).IsPartial = true; break;
case "Assets.CuttingTools.Measurement":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
<None Update="Json-cppagent\Templates\Components.scriban">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Xml\Templates\XmlCuttingToolLifeCycle.scriban">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Xml\Templates\XmlMeasurements.scriban">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
14 changes: 11 additions & 3 deletions build/MTConnect.NET-SysML-Import/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using MTConnect.SysML;
using MTConnect.SysML.CSharp;
using MTConnect.SysML.Json_cppagent;
using System.Text.Json;
using MTConnect.SysML.Xml;

var xmlPath = @"D:\TrakHound\MTConnect\MTConnectSysMLModel.xml";
//var outputPath = @"C:\temp\mtconnect-model-results";
Expand All @@ -19,8 +19,9 @@
//await File.WriteAllTextAsync(@"C:\temp\mtconnect-model.json", json);


RenderCommonClasses();
RenderJsonComponents();
//RenderCommonClasses();
//RenderJsonComponents();
RenderXmlComponents();



Expand All @@ -36,4 +37,11 @@ void RenderJsonComponents()
var outputPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../../../../src/MTConnect.NET-JSON-cppagent");

JsonCppAgentTemplateRenderer.Render(mtconnectModel, outputPath);
}

void RenderXmlComponents()
{
var outputPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../../../../src/MTConnect.NET-XML");

XmlTemplateRenderer.Render(mtconnectModel, outputPath);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using MTConnect.SysML.Models.Assets;

namespace MTConnect.SysML.Xml
{
public class CuttingToolMeasurementsModel
{
public List<MTConnectCuttingToolMeasurementModel> Types { get; set; } = new();
}
}
94 changes: 94 additions & 0 deletions build/MTConnect.NET-SysML-Import/Xml/TemplateRenderer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using MTConnect.SysML.Models.Assets;
using Scriban;

namespace MTConnect.SysML.Xml
{
public static class XmlTemplateRenderer
{
public static void Render(MTConnectModel mtconnectModel, string outputPath)
{
if (mtconnectModel != null && !string.IsNullOrEmpty(outputPath))
{
WriteCuttingToolMeasurements(mtconnectModel, outputPath);
WriteCuttingToolLifeCycle(mtconnectModel, outputPath);
}
}


private static void WriteCuttingToolMeasurements(MTConnectModel mtconnectModel, string outputPath)
{
var measurementsModel = new CuttingToolMeasurementsModel();

var measurements = mtconnectModel.AssetInformationModel.CuttingTools.Classes.Where(o => typeof(MTConnectCuttingToolMeasurementModel).IsAssignableFrom(o.GetType()));
foreach (var measurement in measurements.OrderBy(o => o.Name)) measurementsModel.Types.Add((MTConnectCuttingToolMeasurementModel)measurement);

var templateFilename = $"XmlMeasurements.scriban";
var templatePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "xml", "templates", templateFilename);
if (File.Exists(templatePath))
{
try
{
var templateContents = File.ReadAllText(templatePath);
if (templateContents != null)
{
var template = Template.Parse(templateContents);
var result = template.Render(measurementsModel);
if (result != null)
{
var resultPath = $"Assets/CuttingTools/XmlMeasurements";
resultPath = Path.Combine(outputPath, resultPath);
resultPath = $"{resultPath}.g.cs";

var resultDirectory = Path.GetDirectoryName(resultPath);
if (!Directory.Exists(resultDirectory)) Directory.CreateDirectory(resultDirectory);

File.WriteAllText(resultPath, result);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}

private static void WriteCuttingToolLifeCycle(MTConnectModel mtconnectModel, string outputPath)
{
var measurementsModel = new CuttingToolMeasurementsModel();

var measurements = mtconnectModel.AssetInformationModel.CuttingTools.Classes.Where(o => typeof(MTConnectCuttingToolMeasurementModel).IsAssignableFrom(o.GetType()));
foreach (var measurement in measurements.OrderBy(o => o.Name)) measurementsModel.Types.Add((MTConnectCuttingToolMeasurementModel)measurement);

var templateFilename = $"XmlCuttingToolLifeCycle.scriban";
var templatePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "xml", "templates", templateFilename);
if (File.Exists(templatePath))
{
try
{
var templateContents = File.ReadAllText(templatePath);
if (templateContents != null)
{
var template = Template.Parse(templateContents);
var result = template.Render(measurementsModel);
if (result != null)
{
var resultPath = $"Assets/CuttingTools/XmlCuttingToolLifeCycle";
resultPath = Path.Combine(outputPath, resultPath);
resultPath = $"{resultPath}.g.cs";

var resultDirectory = Path.GetDirectoryName(resultPath);
if (!Directory.Exists(resultDirectory)) Directory.CreateDirectory(resultDirectory);

File.WriteAllText(resultPath, result);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2023 TrakHound Inc., All Rights Reserved.
// TrakHound Inc. licenses this file to you under the MIT license.

using MTConnect.Assets.CuttingTools.Measurements;
using MTConnect.Assets.Xml.CuttingTools;
using System.Collections.Generic;
using System.Xml.Serialization;

namespace MTConnect.Assets.Json.CuttingTools
{
public partial class XmlCuttingToolLifeCycle
{
[XmlArray("Measurements")]
{{- for type in types }}
[XmlArrayItem({{type.name}}.TypeId, typeof(Xml{{type.name}}))]
{{- end }}
public List<XmlMeasurement> Measurements { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) 2023 TrakHound Inc., All Rights Reserved.
// TrakHound Inc. licenses this file to you under the MIT license.

using MTConnect.Assets.CuttingTools.Measurements;

namespace MTConnect.Assets.Xml.CuttingTools
{
{{- for type in types }}
public class Xml{{type.name}} : XmlMeasurement { public Xml{{type.name}}() { Type = {{type.name}}.TypeId; } }
{{ end }}
}
2 changes: 1 addition & 1 deletion src/MTConnect.NET-Common/Assemblies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace MTConnect
{
internal class Assemblies
public static class Assemblies
{
private static Assembly[] _assemblies;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

namespace MTConnect.Assets.CuttingTools
{
public partial class CuttingTool : Asset
public partial class CuttingToolAsset
{
public const string TypeId = "CuttingTool";


public CuttingTool()
public CuttingToolAsset()
{
Type = TypeId;
CuttingToolLifeCycle = new CuttingToolLifeCycle();
Expand All @@ -22,7 +22,7 @@ protected override IAsset OnProcess(Version mtconnectVersion)
{
if (mtconnectVersion != null && mtconnectVersion >= MTConnectVersions.Version12)
{
var asset = new CuttingTool();
var asset = new CuttingToolAsset();
asset.AssetId = AssetId;
asset.InstanceId = InstanceId;
asset.Type = Type;
Expand Down Expand Up @@ -71,7 +71,7 @@ public override string GenerateHash()
return GenerateHash(this);
}

public static string GenerateHash(CuttingTool asset)
public static string GenerateHash(CuttingToolAsset asset)
{
if (asset != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace MTConnect.Assets.CuttingTools
/// <summary>
/// Asset that physically removes the material from the workpiece by shear deformation.
/// </summary>
public partial class CuttingTool : Asset, ICuttingTool
public partial class CuttingToolAsset : Asset, ICuttingToolAsset
{
public new const string DescriptionText = "Asset that physically removes the material from the workpiece by shear deformation.";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) 2023 TrakHound Inc., All Rights Reserved.
// TrakHound Inc. licenses this file to you under the MIT license.

namespace MTConnect.Assets.CuttingTools
{
public static class CuttingToolAssetDescriptions
{
/// <summary>
/// Reference information about the assetId and/or the URL of the data source of CuttingToolArchetype.
/// </summary>
public const string CuttingToolArchetypeReference = "Reference information about the assetId and/or the URL of the data source of CuttingToolArchetype.";

/// <summary>
/// Detailed structure of the cutting tool which is static during its lifecycle. ISO 13399.
/// </summary>
public const string CuttingToolDefinition = "Detailed structure of the cutting tool which is static during its lifecycle. ISO 13399.";

/// <summary>
/// Data regarding the application or use of the tool.This data is provided by various pieces of equipment (i.e. machine tool, presetter) and statistical process control applications. Life cycle data will not remain static, but will change periodically when a tool is used or measured.
/// </summary>
public const string CuttingToolLifeCycle = "Data regarding the application or use of the tool.This data is provided by various pieces of equipment (i.e. machine tool, presetter) and statistical process control applications. Life cycle data will not remain static, but will change periodically when a tool is used or measured.";

/// <summary>
/// Manufacturers of the cutting tool.This will reference the tool item and adaptive items specifically. The cutting itemsmanufacturers’ will be a property of CuttingItem.> Note: In XML, the representation **MUST** be a comma(,) delimited list of manufacturer names. See CuttingTool Schema Diagrams.
/// </summary>
public const string Manufacturers = "Manufacturers of the cutting tool.This will reference the tool item and adaptive items specifically. The cutting itemsmanufacturers’ will be a property of CuttingItem.> Note: In XML, the representation **MUST** be a comma(,) delimited list of manufacturer names. See CuttingTool Schema Diagrams.";

/// <summary>
/// Unique identifier for this assembly.
/// </summary>
public const string SerialNumber = "Unique identifier for this assembly.";

/// <summary>
/// Identifier for a class of cutting tools.
/// </summary>
public const string ToolId = "Identifier for a class of cutting tools.";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace MTConnect.Assets.CuttingTools
/// <summary>
/// Asset that physically removes the material from the workpiece by shear deformation.
/// </summary>
public partial interface ICuttingTool : IAsset
public partial interface ICuttingToolAsset : IAsset
{
/// <summary>
/// Reference information about the assetId and/or the URL of the data source of CuttingToolArchetype.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static Measurement Create(string type, IMeasurement measurement)
}
}

return null;
return new Measurement(measurement);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class JsonCuttingToolAsset

public JsonCuttingToolAsset() { }

public JsonCuttingToolAsset(CuttingTool asset)
public JsonCuttingToolAsset(ICuttingToolAsset asset)
{
if (asset != null)
{
Expand All @@ -73,9 +73,9 @@ public JsonCuttingToolAsset(CuttingTool asset)
}


public CuttingTool ToCuttingToolAsset()
public ICuttingToolAsset ToCuttingToolAsset()
{
var asset = new CuttingTool();
var asset = new CuttingToolAsset();

asset.AssetId = AssetId;
asset.Type = Type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public JsonAssetsDocument(IAssetsResponseDocument assetsDocument)

switch (asset.Type)
{
case "CuttingTool": jsonAsset = new JsonCuttingToolAsset(asset as CuttingTool); break;
case "CuttingTool": jsonAsset = new JsonCuttingToolAsset(asset as CuttingToolAsset); break;
case "File": jsonAsset = new JsonFileAsset(asset as File); break;
case "QIFDocumentWrapper": jsonAsset = new JsonQIFDocumentWrapperAsset(asset as QIFDocumentWrapperAsset); break;
case "RawMaterial": jsonAsset = new JsonRawMaterialAsset(asset as RawMaterialAsset); break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class JsonCuttingToolAsset

public JsonCuttingToolAsset() { }

public JsonCuttingToolAsset(CuttingTool asset)
public JsonCuttingToolAsset(ICuttingToolAsset asset)
{
if (asset != null)
{
Expand All @@ -73,9 +73,9 @@ public JsonCuttingToolAsset(CuttingTool asset)
}


public CuttingTool ToCuttingToolAsset()
public ICuttingToolAsset ToCuttingToolAsset()
{
var asset = new CuttingTool();
var asset = new CuttingToolAsset();

asset.AssetId = AssetId;
asset.Type = Type;
Expand Down
2 changes: 1 addition & 1 deletion src/MTConnect.NET-JSON/Assets/JsonAssetsDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public JsonAssetsDocument(IAssetsResponseDocument assetsDocument)

switch (asset.Type)
{
case "CuttingTool": jsonAsset = new JsonCuttingToolAsset(asset as CuttingTool); break;
case "CuttingTool": jsonAsset = new JsonCuttingToolAsset(asset as CuttingToolAsset); break;
case "File": jsonAsset = new JsonFileAsset(asset as File); break;
case "QIFDocumentWrapper": jsonAsset = new JsonQIFDocumentWrapperAsset(asset as QIFDocumentWrapperAsset); break;
case "RawMaterial": jsonAsset = new JsonRawMaterialAsset(asset as RawMaterialAsset); break;
Expand Down
2 changes: 1 addition & 1 deletion src/MTConnect.NET-JSON/Formatters/JsonEntityFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public string Format(IAsset asset, IEnumerable<KeyValuePair<string, string>> opt
{
switch (asset.Type)
{
case "CuttingTool": return JsonFunctions.Convert(new JsonCuttingToolAsset(asset as CuttingTool));
case "CuttingTool": return JsonFunctions.Convert(new JsonCuttingToolAsset(asset as CuttingToolAsset));
case "File": return JsonFunctions.Convert(new JsonFileAsset(asset as File));
case "QIFDocumentWrapper": return JsonFunctions.Convert(new JsonQIFDocumentWrapperAsset(asset as QIFDocumentWrapperAsset));
case "RawMaterial": return JsonFunctions.Convert(new JsonRawMaterialAsset(asset as RawMaterialAsset));
Expand Down
Loading

0 comments on commit b827cae

Please sign in to comment.