diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1ff0c42..0000000 --- a/.gitattributes +++ /dev/null @@ -1,63 +0,0 @@ -############################################################################### -# Set default behavior to automatically normalize line endings. -############################################################################### -* text=auto - -############################################################################### -# Set default behavior for command prompt diff. -# -# This is need for earlier builds of msysgit that does not have it on by -# default for csharp files. -# Note: This is only used by command line -############################################################################### -#*.cs diff=csharp - -############################################################################### -# Set the merge driver for project and solution files -# -# Merging from the command prompt will add diff markers to the files if there -# are conflicts (Merging from VS is not affected by the settings below, in VS -# the diff markers are never inserted). Diff markers may cause the following -# file extensions to fail to load in VS. An alternative would be to treat -# these files as binary and thus will always conflict and require user -# intervention with every merge. To do so, just uncomment the entries below -############################################################################### -#*.sln merge=binary -#*.csproj merge=binary -#*.vbproj merge=binary -#*.vcxproj merge=binary -#*.vcproj merge=binary -#*.dbproj merge=binary -#*.fsproj merge=binary -#*.lsproj merge=binary -#*.wixproj merge=binary -#*.modelproj merge=binary -#*.sqlproj merge=binary -#*.wwaproj merge=binary - -############################################################################### -# behavior for image files -# -# image files are treated as binary by default. -############################################################################### -#*.jpg binary -#*.png binary -#*.gif binary - -############################################################################### -# diff behavior for common document formats -# -# Convert binary document formats to text before diffing them. This feature -# is only available from the command line. Turn it on by uncommenting the -# entries below. -############################################################################### -#*.doc diff=astextplain -#*.DOC diff=astextplain -#*.docx diff=astextplain -#*.DOCX diff=astextplain -#*.dot diff=astextplain -#*.DOT diff=astextplain -#*.pdf diff=astextplain -#*.PDF diff=astextplain -#*.rtf diff=astextplain -#*.RTF diff=astextplain diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..32466d7 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,31 @@ +name: CI + +on: [push, pull_request] + +jobs: + + linux: + runs-on: ubuntu-latest + strategy: + matrix: + configuration: ['Debug', 'Release'] + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-dotnet@v1.0.2 + with: + dotnet-version: '3.0.100' + - name: Build and test + run: ./build-and-test.sh --configuration ${{ matrix.configuration }} + + windows: + runs-on: windows-latest + strategy: + matrix: + configuration: ['Debug', 'Release'] + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-dotnet@v1.0.2 + with: + dotnet-version: '3.0.100' + - name: Build and test + run: .\build-and-test.cmd -c ${{ matrix.configuration }} diff --git a/.gitignore b/.gitignore index 150b238..f085025 100644 --- a/.gitignore +++ b/.gitignore @@ -1,134 +1,7 @@ -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. - -# User-specific files +# ignore VS files *.suo *.user -*.sln.docstates -.vs - -# Build results - -[Dd]ebug/ -[Rr]elease/ -x64/ -[Bb]in/ -[Oo]bj/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -*_i.c -*_p.c -*_i.h -*.ilk -*.meta -*.obj -*.pch -*.pdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.log -*.svclog -*.scc - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opensdf -*.sdf -*.cachefile - -# Visual Studio profiler -*.psess -*.vsp -*.vspx - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper -*.DotSettings.user - -# Click-Once directory -publish/ - -# Publish Web Output -*.Publish.xml -*.pubxml -*.azurePubxml - -# NuGet Packages Directory -## TODO: If you have NuGet Package Restore enabled, uncomment the next line -packages/ -## TODO: If the tool you use requires repositories.config, also uncomment the next line -!packages/repositories.config - -# Windows Azure Build Output -csx/ -*.build.csdef - -# Windows Store app package directory -AppPackages/ - -# Others -sql/ -*.Cache -ClientBin/ -[Ss]tyle[Cc]op.* -![Ss]tyle[Cc]op.targets -~$* -*~ -*.dbmdl -*.[Pp]ublish.xml - -*.publishsettings - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file to a newer -# Visual Studio version. Backup files are not needed, because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm - -# SQL Server files -App_Data/*.mdf -App_Data/*.ldf - -# ========================= -# Windows detritus -# ========================= - -# Windows image file caches -Thumbs.db -ehthumbs.db - -# Folder config file -Desktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Mac desktop service store files -.DS_Store +.vs/ -_NCrunch* \ No newline at end of file +# ignore artifacts +artifacts/ diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..d057d11 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,28 @@ +{ + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceRoot}/src/IxMilia.Step.Test/bin/Debug/netcoreapp1.0/IxMilia.Step.Test.dll", + "args": [], + "cwd": "${workspaceRoot}/src/IxMilia.Step.Test", + // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window + "console": "internalConsole", + "stopAtEntry": false, + "internalConsoleOptions": "openOnSessionStart" + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..4bde8f7 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,16 @@ +{ + "version": "0.1.0", + "command": "dotnet", + "isShellCommand": true, + "args": [], + "tasks": [ + { + "taskName": "build", + "args": [ + "${workspaceRoot}/src/IxMilia.Step.Test/IxMilia.Step.Test.csproj" + ], + "isBuildCommand": true, + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000..c8dc8ab --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,13 @@ + + + + $([System.IO.File]::ReadAllText('$(MSBuildThisFileDirectory)version.txt').Trim()) + $(MSBuildThisFileDirectory)artifacts + $(ArtifactsDir)\packages + $(ArtifactsDir)\bin\$(MSBuildProjectName) + $(ArtifactsDir)\obj\$(MSBuildProjectName) + $(ArtifactsPackagesDir)\$(Configuration) + embedded + + + diff --git a/Directory.Build.targets b/Directory.Build.targets new file mode 100644 index 0000000..fe18a13 --- /dev/null +++ b/Directory.Build.targets @@ -0,0 +1,7 @@ + + + + $(Version) + + + diff --git a/Items/StepAdvancedBrepShapeRepresentation.cs b/Items/StepAdvancedBrepShapeRepresentation.cs deleted file mode 100644 index c5a5cd0..0000000 --- a/Items/StepAdvancedBrepShapeRepresentation.cs +++ /dev/null @@ -1,65 +0,0 @@ -using StepParser.Syntax; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Xml; - -namespace StepParser.Items -{ - public class StepAdvancedBrepShapeRepresentation: StepRepresentationItem - { - public override StepItemType ItemType => StepItemType.AdvancedBrepShapeRepresentation; - public List UsedSolidBrepList { get; set; } = new List(); - public List UsedStyledItems { get; set; } = new List(); - - private StepAdvancedBrepShapeRepresentation() - : base(string.Empty, 0) - { - } - - public void SetStyledItems(List _styledItems) - { - UsedStyledItems = _styledItems; - } - - internal override IEnumerable GetParameters(StepWriter writer) - { - foreach (var parameter in base.GetParameters(writer)) - { - yield return parameter; - } - } - internal static StepAdvancedBrepShapeRepresentation CreateFromSyntaxList(StepBinder binder, StepSyntaxList syntaxList, int id) - { - var advancedBrepShapeRepresentation = new StepAdvancedBrepShapeRepresentation(); - syntaxList.AssertListCount(3); - advancedBrepShapeRepresentation.Id = id; - advancedBrepShapeRepresentation.Name = syntaxList.Values[0].GetStringValue(); - - var referList = syntaxList.Values[1].GetValueList(); - advancedBrepShapeRepresentation.UsedSolidBrepList.Clear(); - advancedBrepShapeRepresentation.UsedSolidBrepList.AddRange(Enumerable.Range(0, referList.Values.Count).Select(_ => (StepManifoldSolidBrep)null)); - for (int i = 0; i < referList.Values.Count; i++) - { - var j = i; - binder.BindValue(referList.Values[j], v => advancedBrepShapeRepresentation.UsedSolidBrepList[j] = v.AsType()); - } - - return advancedBrepShapeRepresentation; - } - - internal override void WriteXML(XmlWriter writer) - { - foreach(var solidBrep in UsedSolidBrepList) - { - solidBrep.WriteXML(writer); - } - - foreach (var styledItem in UsedStyledItems) - { - styledItem.WriteXML(writer); - } - } - } -} diff --git a/Items/StepBoundedCurve.cs b/Items/StepBoundedCurve.cs deleted file mode 100644 index 331ef0e..0000000 --- a/Items/StepBoundedCurve.cs +++ /dev/null @@ -1,11 +0,0 @@ - -namespace StepParser.Items -{ - public abstract class StepBoundedCurve : StepCurve - { - protected StepBoundedCurve(string name) - : base(name) - { - } - } -} diff --git a/Items/StepClosedShell.cs b/Items/StepClosedShell.cs deleted file mode 100644 index 873f091..0000000 --- a/Items/StepClosedShell.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Xml; -using StepParser.Syntax; - -namespace StepParser.Items -{ - public class StepClosedShell : StepRepresentationItem - { - public override StepItemType ItemType => StepItemType.ClosedShell; - public List AdvancedFaces { get; set; } = new List(); - - public StepClosedShell(string name, int id) - : base(name, id) - { - } - - private StepClosedShell() - : base(string.Empty, 0) - { - } - - internal override IEnumerable GetParameters(StepWriter writer) - { - foreach (var parameter in base.GetParameters(writer)) - { - yield return parameter; - } - } - internal static StepClosedShell CreateFromSyntaxList(StepBinder binder, StepSyntaxList syntaxList, int id) - { - var closedShell = new StepClosedShell(); - syntaxList.AssertListCount(2); - closedShell.Id = id; - closedShell.Name = syntaxList.Values[0].GetStringValue(); - - var referList = syntaxList.Values[1].GetValueList(); - closedShell.AdvancedFaces.Clear(); - closedShell.AdvancedFaces.AddRange(Enumerable.Range(0, referList.Values.Count).Select(_ => (StepAdvancedFace)null)); - for (int i = 0; i < referList.Values.Count; i++) - { - var j = i; // capture to avoid rebinding - binder.BindValue(referList.Values[j], v => closedShell.AdvancedFaces[j] = v.AsType()); - } - - return closedShell; - } - - internal override void WriteXML(XmlWriter writer) - { - writer.WriteStartElement("AdvancedFaces"); - writer.WriteAttributeString("id", '#' + Id.ToString()); - for(int idx = 0; idx < AdvancedFaces.Count; idx++) - { - AdvancedFaces[idx].WriteXML(writer); - } - writer.WriteEndElement(); - } - } -} diff --git a/Items/StepColourRGB.cs b/Items/StepColourRGB.cs deleted file mode 100644 index 246e587..0000000 --- a/Items/StepColourRGB.cs +++ /dev/null @@ -1,50 +0,0 @@ -using StepParser.Syntax; -using System; -using System.Collections.Generic; -using System.Text; -using System.Xml; - -namespace StepParser.Items -{ - public class StepColourRGB: StepRepresentationItem - { - public override StepItemType ItemType => StepItemType.ColourRGB; - public double R { get; set; } - public double G { get; set; } - public double B { get; set; } - - private StepColourRGB() - : base(string.Empty, 0) - { - } - - internal override IEnumerable GetParameters(StepWriter writer) - { - foreach (var parameter in base.GetParameters(writer)) - { - yield return parameter; - } - } - internal static StepColourRGB CreateFromSyntaxList(StepBinder binder, StepSyntaxList syntaxList, int id) - { - var colourRGB = new StepColourRGB(); - syntaxList.AssertListCount(4); - colourRGB.Id = id; - colourRGB.Name = syntaxList.Values[0].GetStringValue(); - colourRGB.R = syntaxList.Values[1].GetRealVavlue(); - colourRGB.G = syntaxList.Values[2].GetRealVavlue(); - colourRGB.B = syntaxList.Values[3].GetRealVavlue(); - - return colourRGB; - } - - internal override void WriteXML(XmlWriter writer) - { - writer.WriteStartElement("Color"); - writer.WriteAttributeString("r", R.ToString()); - writer.WriteAttributeString("g", G.ToString()); - writer.WriteAttributeString("b", B.ToString()); - writer.WriteEndElement(); - } - } -} diff --git a/Items/StepComponentAssemble.cs b/Items/StepComponentAssemble.cs deleted file mode 100644 index 333e5d4..0000000 --- a/Items/StepComponentAssemble.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Xml; - -namespace StepParser.Items -{ - public abstract class StepComponentAssemble: StepRepresentationItem - { - private string _description; - - public string Description - { - get { return _description; } - set - { - if (value == null) - { - throw new ArgumentNullException(); - } - - _description = value; - } - } - - protected StepComponentAssemble(string name, int id) - : base(name, id) - { - } - - internal override void WriteXML(XmlWriter writer) - { - } - } -} diff --git a/Items/StepConic.cs b/Items/StepConic.cs deleted file mode 100644 index 86a03e7..0000000 --- a/Items/StepConic.cs +++ /dev/null @@ -1,11 +0,0 @@ - -namespace StepParser.Items -{ - public abstract class StepConic : StepCurve - { - protected StepConic(string name) - : base(name) - { - } - } -} diff --git a/Items/StepCurve.cs b/Items/StepCurve.cs deleted file mode 100644 index 47c1179..0000000 --- a/Items/StepCurve.cs +++ /dev/null @@ -1,11 +0,0 @@ - -namespace StepParser.Items -{ - public abstract class StepCurve : StepGeometricRepresentationItem - { - protected StepCurve(string name) - : base(name, 0) - { - } - } -} diff --git a/Items/StepFillAreaStyle.cs b/Items/StepFillAreaStyle.cs deleted file mode 100644 index bb512a4..0000000 --- a/Items/StepFillAreaStyle.cs +++ /dev/null @@ -1,58 +0,0 @@ -using StepParser.Syntax; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Xml; - -namespace StepParser.Items -{ - public class StepFillAreaStyle: StepRepresentationItem - { - public override StepItemType ItemType => StepItemType.FillAreaStyle; - public string Description { get; set; } - public List FillAreaStyleColours { get; set; } = new List(); - - private StepFillAreaStyle() - : base(string.Empty, 0) - { - } - - internal override IEnumerable GetParameters(StepWriter writer) - { - foreach (var parameter in base.GetParameters(writer)) - { - yield return parameter; - } - } - internal static StepFillAreaStyle CreateFromSyntaxList(StepBinder binder, StepSyntaxList syntaxList, int id) - { - var fillAreaStyle = new StepFillAreaStyle(); - syntaxList.AssertListCount(2); - fillAreaStyle.Id = id; - fillAreaStyle.Name = syntaxList.Values[0].GetStringValue(); - - var referList = syntaxList.Values[1].GetValueList(); - fillAreaStyle.FillAreaStyleColours.Clear(); - fillAreaStyle.FillAreaStyleColours.AddRange(Enumerable.Range(0, referList.Values.Count).Select(_ => (StepFillAreaStyleColour)null)); - for (int i = 0; i < referList.Values.Count; i++) - { - var j = i; - binder.BindValue(referList.Values[j], v => fillAreaStyle.FillAreaStyleColours[j] = v.AsType()); - } - - return fillAreaStyle; - } - - internal override void WriteXML(XmlWriter writer) - { - writer.WriteStartElement("Element"); - writer.WriteAttributeString("type", "FILL_AREA"); - foreach (var fillAreaStyleColour in FillAreaStyleColours) - { - fillAreaStyleColour.WriteXML(writer); - } - writer.WriteEndElement(); - } - } -} diff --git a/Items/StepFillAreaStyleColour.cs b/Items/StepFillAreaStyleColour.cs deleted file mode 100644 index 302a09d..0000000 --- a/Items/StepFillAreaStyleColour.cs +++ /dev/null @@ -1,45 +0,0 @@ -using StepParser.Syntax; -using System; -using System.Collections.Generic; -using System.Text; -using System.Xml; - -namespace StepParser.Items -{ - public class StepFillAreaStyleColour: StepRepresentationItem - { - public override StepItemType ItemType => StepItemType.FillAreaStyleColour; - public StepColourRGB Colour { get; set; } - - private StepFillAreaStyleColour() - : base(string.Empty, 0) - { - } - - internal override IEnumerable GetParameters(StepWriter writer) - { - foreach (var parameter in base.GetParameters(writer)) - { - yield return parameter; - } - } - internal static StepFillAreaStyleColour CreateFromSyntaxList(StepBinder binder, StepSyntaxList syntaxList, int id) - { - var fillAreaStyleColor = new StepFillAreaStyleColour(); - syntaxList.AssertListCount(2); - fillAreaStyleColor.Id = id; - fillAreaStyleColor.Name = syntaxList.Values[0].GetStringValue(); - - binder.BindValue(syntaxList.Values[1], v => fillAreaStyleColor.Colour = v.AsType()); - - return fillAreaStyleColor; - } - - internal override void WriteXML(XmlWriter writer) - { - writer.WriteStartElement("FillStyle"); - Colour.WriteXML(writer); - writer.WriteEndElement(); - } - } -} diff --git a/Items/StepItemType.cs b/Items/StepItemType.cs deleted file mode 100644 index bb24496..0000000 --- a/Items/StepItemType.cs +++ /dev/null @@ -1,183 +0,0 @@ -// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Globalization; - -namespace StepParser.Items -{ - public enum StepItemType - { - Product, - ProductDefinition, - ProductDefinitionShape, - ProductDefinitionFormationWithSpecifiedSource, - ShapeDefinitionRepresentation, - ShapeRepresentationRelationship, - ShapeRepresentation, - AdvancedBrepShapeRepresentation, - ManiFoldSolidBrep, - ClosedShell, - AdvancedFace, - AxisPlacement2D, - AxisPlacement3D, - BSplineCurveWithKnots, - CartesianPoint, - Circle, - CylindricalSurface, - Direction, - EdgeCurve, - EdgeLoop, - Ellipse, - FaceBound, - FaceOuterBound, - Line, - OrientedEdge, - Plane, - Vector, - VertexPoint, - StyledItem, - PresentationStyleAssignment, - SurfaceStyleUsage, - SurfaceSideStyle, - SurfaceStyleFillArea, - FillAreaStyle, - FillAreaStyleColour, - ColourRGB, - NextAssemblyUsageOccurrence - } - - internal static class StepItemTypeExtensions - { - public const string ProductText = "PRODUCT"; - public const string ProductDefinitionText = "PRODUCT_DEFINITION"; - public const string ProductDefinitionShapeText = "PRODUCT_DEFINITION_SHAPE"; - public const string ProductDefinitionFormationWithSpecifiedSourceText = "PRODUCT_DEFINITION_FORMATION_WITH_SPECIFIED_SOURCE"; - public const string ShapeDefinitionRepresentationText = "SHAPE_DEFINITION_REPRESENTATION"; - public const string ShapeRepresentationRelationshipText = "SHAPE_REPRESENTATION_RELATIONSHIP"; - public const string ShapeRepresentationText = "SHAPE_REPRESENTATION"; - public const string AdvancedBrepShapeRepresentationText = "ADVANCED_BREP_SHAPE_REPRESENTATION"; - public const string ManiFoldSolidBrepText = "MANIFOLD_SOLID_BREP"; - public const string ClosedShellText = "CLOSED_SHELL"; - public const string AdvancedFaceText = "ADVANCED_FACE"; - public const string Axis2Placement2DText = "AXIS2_PLACEMENT_2D"; - public const string Axis2Placement3DText = "AXIS2_PLACEMENT_3D"; - public const string BSplineCurveWithKnotsText = "B_SPLINE_CURVE_WITH_KNOTS"; - public const string CartesianPointText = "CARTESIAN_POINT"; - public const string CircleText = "CIRCLE"; - public const string CylindricalSurfaceText = "CYLINDRICAL_SURFACE"; - public const string DirectionText = "DIRECTION"; - public const string EdgeCurveText = "EDGE_CURVE"; - public const string EdgeLoopText = "EDGE_LOOP"; - public const string EllipseText = "ELLIPSE"; - public const string FaceBoundText = "FACE_BOUND"; - public const string FaceOuterBoundText = "FACE_OUTER_BOUND"; - public const string LineText = "LINE"; - public const string OrientedEdgeText = "ORIENTED_EDGE"; - public const string PlaneText = "PLANE"; - public const string VectorText = "VECTOR"; - public const string VertexPointText = "VERTEX_POINT"; - public const string StyledItemText = "STYLED_ITEM"; - public const string PresentationStyleAssignmentText = "PRESENTATION_STYLE_ASSIGNMENT"; - public const string SurfaceStyleUsageText = "SURFACE_STYLE_USAGE"; - public const string SurfaceSideStyleText = "SURFACE_SIDE_STYLE"; - public const string SurfaceStyleFillAreaText = "SURFACE_STYLE_FILL_AREA"; - public const string FillAreaStyleText = "FILL_AREA_STYLE"; - public const string FillAreaStyleColourText = "FILL_AREA_STYLE_COLOUR"; - public const string ColourRGBText = "COLOUR_RGB"; - public const string NextAssemblyUsageOccurrenceText = "NEXT_ASSEMBLY_USAGE_OCCURRENCE"; - - - public static string GetItemTypeString(this StepItemType type) - { - switch (type) - { - case StepItemType.Product: - return ProductText; - case StepItemType.ProductDefinition: - return ProductDefinitionText; - case StepItemType.ProductDefinitionShape: - return ProductDefinitionShapeText; - case StepItemType.ProductDefinitionFormationWithSpecifiedSource: - return ProductDefinitionFormationWithSpecifiedSourceText; - case StepItemType.ShapeDefinitionRepresentation: - return ShapeDefinitionRepresentationText; - case StepItemType.ShapeRepresentationRelationship: - return ShapeRepresentationRelationshipText; - case StepItemType.ShapeRepresentation: - return ShapeRepresentationText; - case StepItemType.AdvancedBrepShapeRepresentation: - return AdvancedBrepShapeRepresentationText; - case StepItemType.ManiFoldSolidBrep: - return ManiFoldSolidBrepText; - case StepItemType.ClosedShell: - return ClosedShellText; - case StepItemType.AdvancedFace: - return AdvancedFaceText; - case StepItemType.AxisPlacement2D: - return Axis2Placement2DText; - case StepItemType.AxisPlacement3D: - return Axis2Placement3DText; - case StepItemType.BSplineCurveWithKnots: - return BSplineCurveWithKnotsText; - case StepItemType.CartesianPoint: - return CartesianPointText; - case StepItemType.Circle: - return CircleText; - case StepItemType.CylindricalSurface: - return CylindricalSurfaceText; - case StepItemType.Direction: - return DirectionText; - case StepItemType.EdgeCurve: - return EdgeCurveText; - case StepItemType.EdgeLoop: - return EdgeLoopText; - case StepItemType.Ellipse: - return EllipseText; - case StepItemType.FaceBound: - return FaceBoundText; - case StepItemType.FaceOuterBound: - return FaceOuterBoundText; - case StepItemType.Line: - return LineText; - case StepItemType.OrientedEdge: - return OrientedEdgeText; - case StepItemType.Plane: - return PlaneText; - case StepItemType.Vector: - return VectorText; - case StepItemType.VertexPoint: - return VertexPointText; - case StepItemType.StyledItem: - return StyledItemText; - case StepItemType.PresentationStyleAssignment: - return PresentationStyleAssignmentText; - case StepItemType.SurfaceStyleUsage: - return SurfaceStyleUsageText; - case StepItemType.SurfaceSideStyle: - return SurfaceSideStyleText; - case StepItemType.SurfaceStyleFillArea: - return SurfaceStyleFillAreaText; - case StepItemType.FillAreaStyle: - return FillAreaStyleText; - case StepItemType.FillAreaStyleColour: - return FillAreaStyleColourText; - case StepItemType.ColourRGB: - return ColourRGBText; - case StepItemType.NextAssemblyUsageOccurrence: - return NextAssemblyUsageOccurrenceText; - default: - throw new InvalidOperationException("Unexpected item type " + type); - } - } - - public static string GetItemTypeElementString(this StepItemType type) - { - return ToCamel(GetItemTypeString(type)); - } - - private static string ToCamel(string input) - { - return new CultureInfo("en").TextInfo.ToTitleCase(input.ToLower().Replace("_", " ")).Replace(" ", ""); - } - } -} diff --git a/Items/StepLoop.cs b/Items/StepLoop.cs deleted file mode 100644 index 4dd1520..0000000 --- a/Items/StepLoop.cs +++ /dev/null @@ -1,11 +0,0 @@ - -namespace StepParser.Items -{ - public abstract class StepLoop : StepTopologicalRepresentationItem - { - public StepLoop(string name) - : base(name, 0) - { - } - } -} diff --git a/Items/StepManifoldSolidBrep.cs b/Items/StepManifoldSolidBrep.cs deleted file mode 100644 index b523a8d..0000000 --- a/Items/StepManifoldSolidBrep.cs +++ /dev/null @@ -1,42 +0,0 @@ -using StepParser.Syntax; -using System; -using System.Collections.Generic; -using System.Text; -using System.Xml; - -namespace StepParser.Items -{ - public class StepManifoldSolidBrep: StepRepresentationItem - { - public override StepItemType ItemType => StepItemType.ManiFoldSolidBrep; - public StepClosedShell ClosedShell { get; set; } - - private StepManifoldSolidBrep() - : base(string.Empty, 0) - { - } - - internal override IEnumerable GetParameters(StepWriter writer) - { - foreach (var parameter in base.GetParameters(writer)) - { - yield return parameter; - } - } - internal static StepManifoldSolidBrep CreateFromSyntaxList(StepBinder binder, StepSyntaxList syntaxList, int id) - { - var manifoldSolidBrep = new StepManifoldSolidBrep(); - syntaxList.AssertListCount(2); - manifoldSolidBrep.Id = id; - manifoldSolidBrep.Name = syntaxList.Values[0].GetStringValue(); - binder.BindValue(syntaxList.Values[1], v => manifoldSolidBrep.ClosedShell = v.AsType()); - - return manifoldSolidBrep; - } - - internal override void WriteXML(XmlWriter writer) - { - ClosedShell.WriteXML(writer); - } - } -} diff --git a/Items/StepNextAssemblyUsageOccrrence.cs b/Items/StepNextAssemblyUsageOccrrence.cs deleted file mode 100644 index 7708f0d..0000000 --- a/Items/StepNextAssemblyUsageOccrrence.cs +++ /dev/null @@ -1,47 +0,0 @@ -using StepParser.Syntax; -using System; -using System.Collections.Generic; -using System.Text; -using System.Xml; - -namespace StepParser.Items -{ - class StepNextAssemblyUsageOccrrence: StepComponentAssemble - { - public override StepItemType ItemType => StepItemType.NextAssemblyUsageOccurrence; - public string AssembleId { get; set; } - public StepProductDefinition Parent { get; set; } - public StepProductDefinition Child { get; set; } - - private StepNextAssemblyUsageOccrrence() - : base(string.Empty, 0) - { - } - - internal override IEnumerable GetParameters(StepWriter writer) - { - foreach (var parameter in base.GetParameters(writer)) - { - yield return parameter; - } - } - internal static StepNextAssemblyUsageOccrrence CreateFromSyntaxList(StepBinder binder, StepSyntaxList syntaxList, int id) - { - var assemblyUsageOccrrence = new StepNextAssemblyUsageOccrrence(); - syntaxList.AssertListCount(6); - assemblyUsageOccrrence.Id = id; - assemblyUsageOccrrence.AssembleId = syntaxList.Values[0].GetStringValue(); - assemblyUsageOccrrence.Name = syntaxList.Values[1].GetStringValue(); - assemblyUsageOccrrence.Description = syntaxList.Values[2].GetStringValue(); - - binder.BindValue(syntaxList.Values[3], v => assemblyUsageOccrrence.Parent = v.AsType()); - binder.BindValue(syntaxList.Values[4], v => assemblyUsageOccrrence.Child = v.AsType()); - - return assemblyUsageOccrrence; - } - - internal override void WriteXML(XmlWriter writer) - { - } - } -} diff --git a/Items/StepPlacement.cs b/Items/StepPlacement.cs deleted file mode 100644 index 7ec4bd7..0000000 --- a/Items/StepPlacement.cs +++ /dev/null @@ -1,11 +0,0 @@ - -namespace StepParser.Items -{ - public abstract class StepPlacement : StepGeometricRepresentationItem - { - protected StepPlacement(string name) - : base(name, 0) - { - } - } -} diff --git a/Items/StepPresentationStyleAssignment.cs b/Items/StepPresentationStyleAssignment.cs deleted file mode 100644 index 588c6f2..0000000 --- a/Items/StepPresentationStyleAssignment.cs +++ /dev/null @@ -1,56 +0,0 @@ -using StepParser.Syntax; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Xml; - -namespace StepParser.Items -{ - public class StepPresentationStyleAssignment: StepRepresentationItem - { - public override StepItemType ItemType => StepItemType.PresentationStyleAssignment; - public List StyleUsageList { get; set; } = new List(); - - private StepPresentationStyleAssignment() - : base(string.Empty, 0) - { - } - - internal override IEnumerable GetParameters(StepWriter writer) - { - foreach (var parameter in base.GetParameters(writer)) - { - yield return parameter; - } - } - internal static StepPresentationStyleAssignment CreateFromSyntaxList(StepBinder binder, StepSyntaxList syntaxList, int id) - { - var presentationStyleAssignment = new StepPresentationStyleAssignment(); - syntaxList.AssertListCount(1); - presentationStyleAssignment.Id = id; - - var referList = syntaxList.Values[0].GetValueList(); - presentationStyleAssignment.StyleUsageList.Clear(); - presentationStyleAssignment.StyleUsageList.AddRange(Enumerable.Range(0, referList.Values.Count).Select(_ => (StepSurfaceStyleUsage)null)); - for (int i = 0; i < referList.Values.Count; i++) - { - var j = i; - binder.BindValue(referList.Values[j], v => presentationStyleAssignment.StyleUsageList[j] = v.AsType()); - } - - return presentationStyleAssignment; - } - - internal override void WriteXML(XmlWriter writer) - { - writer.WriteStartElement("StyleAssignment"); - writer.WriteAttributeString("id", "#" + Id.ToString()); - foreach (var styleUsage in StyleUsageList) - { - styleUsage.WriteXML(writer); - } - writer.WriteEndElement(); - } - } -} diff --git a/Items/StepProduct.cs b/Items/StepProduct.cs deleted file mode 100644 index 824bade..0000000 --- a/Items/StepProduct.cs +++ /dev/null @@ -1,61 +0,0 @@ -using StepParser.Syntax; -using System; -using System.Collections.Generic; -using System.Text; -using System.Xml; - -namespace StepParser.Items -{ - public class StepProduct: StepComponentAssemble - { - public override StepItemType ItemType => StepItemType.Product; - private StepProduct() - : base(string.Empty, 0) - { - } - - internal override IEnumerable GetParameters(StepWriter writer) - { - foreach (var parameter in base.GetParameters(writer)) - { - yield return parameter; - } - } - internal static StepProduct CreateFromSyntaxList(StepBinder binder, StepSyntaxList syntaxList, int id) - { - var product = new StepProduct(); - syntaxList.AssertListCount(4); - product.Id = id; - product.Name = syntaxList.Values[0].GetStringValue(); - product.Description = syntaxList.Values[1].GetStringValue(); - - return product; - } - - internal override void WriteXML(XmlWriter writer) - { - writer.WriteStartElement("ID"); - writer.WriteString('#' + Id.ToString()); - writer.WriteEndElement(); - - writer.WriteStartElement("Name"); - writer.WriteString(Name); - writer.WriteEndElement(); - - writer.WriteStartElement("Description"); - writer.WriteString(Description); - writer.WriteEndElement(); - } - - public void WriteXMLGroup(XmlWriter writer) - { - writer.WriteAttributeString("id", "#" + Id.ToString()); - writer.WriteAttributeString("name", Name); - } - - public void WriteXMLOroderPart(XmlWriter writer) - { - writer.WriteString("#" + Id.ToString()); - } - } -} diff --git a/Items/StepProductDefFormationWithSpecSource.cs b/Items/StepProductDefFormationWithSpecSource.cs deleted file mode 100644 index 14edc88..0000000 --- a/Items/StepProductDefFormationWithSpecSource.cs +++ /dev/null @@ -1,54 +0,0 @@ -using StepParser.Syntax; -using System; -using System.Collections.Generic; -using System.Text; -using System.Xml; - -namespace StepParser.Items -{ - public class StepProductDefFormationWithSpecSource: StepComponentAssemble - { - public override StepItemType ItemType => StepItemType.ProductDefinitionFormationWithSpecifiedSource; - public StepProduct Product { get; set; } - - private StepProductDefFormationWithSpecSource() - : base(string.Empty, 0) - { - } - - internal override IEnumerable GetParameters(StepWriter writer) - { - foreach (var parameter in base.GetParameters(writer)) - { - yield return parameter; - } - } - internal static StepProductDefFormationWithSpecSource CreateFromSyntaxList(StepBinder binder, StepSyntaxList syntaxList, int id) - { - var productDefFormationWithSpecSource = new StepProductDefFormationWithSpecSource(); - syntaxList.AssertListCount(4); - productDefFormationWithSpecSource.Id = id; - productDefFormationWithSpecSource.Name = syntaxList.Values[0].GetStringValue(); - productDefFormationWithSpecSource.Description = syntaxList.Values[1].GetStringValue(); - - binder.BindValue(syntaxList.Values[2], v => productDefFormationWithSpecSource.Product = v.AsType()); - - return productDefFormationWithSpecSource; - } - - internal override void WriteXML(XmlWriter writer) - { - Product.WriteXML(writer); - } - - public void WriteXMLGroup(XmlWriter writer) - { - Product.WriteXMLGroup(writer); - } - - public void WriteXMLOroderPart(XmlWriter writer) - { - Product.WriteXMLOroderPart(writer); - } - } -} diff --git a/Items/StepProductDefinition.cs b/Items/StepProductDefinition.cs deleted file mode 100644 index 4f5fe78..0000000 --- a/Items/StepProductDefinition.cs +++ /dev/null @@ -1,117 +0,0 @@ -using StepParser.Syntax; -using System; -using System.Collections.Generic; -using System.Text; -using System.Xml; - -namespace StepParser.Items -{ - public class StepProductDefinition : StepComponentAssemble - { - public override StepItemType ItemType => StepItemType.ProductDefinition; - public StepProductDefFormationWithSpecSource DefinitionFormation { get; set; } - private List _children; - public int Count { get; set; } = 0; - - public List Children - { - get { return _children; } - set - { - if (value == null) - { - throw new ArgumentNullException(); - } - - _children = value; - } - } - - - public StepProductDefinition(string name, int id) - : base(name, id) - { - } - - private StepProductDefinition() - : base(string.Empty, 0) - { - } - - internal override IEnumerable GetParameters(StepWriter writer) - { - foreach (var parameter in base.GetParameters(writer)) - { - yield return parameter; - } - } - internal static StepProductDefinition CreateFromSyntaxList(StepBinder binder, StepSyntaxList syntaxList, int id) - { - var productDefinition = new StepProductDefinition(); - syntaxList.AssertListCount(4); - productDefinition.Id = id; - productDefinition.Name = syntaxList.Values[0].GetStringValue(); - productDefinition.Description = syntaxList.Values[1].GetStringValue(); - - binder.BindValue(syntaxList.Values[2], v => productDefinition.DefinitionFormation = v.AsType()); - - return productDefinition; - } - - internal override void WriteXML(XmlWriter writer) - { - if (DefinitionFormation != null) - { - DefinitionFormation.WriteXML(writer); - } - } - - public void WriteXMLGroup(XmlWriter writer) - { - if (_children.Count > 0) - { - writer.WriteStartElement("Group"); - //writer.WriteAttributeString("id", "#" + Id.ToString()); - //writer.WriteAttributeString("name", Name); - DefinitionFormation.WriteXMLGroup(writer); - foreach (var child in _children) - { - child.WriteXMLGroup(writer); - } - writer.WriteEndElement(); - } - else - { - Count++; - writer.WriteStartElement("Part"); - //writer.WriteAttributeString("id", "#" + Id.ToString()); - //writer.WriteAttributeString("name", Name); - DefinitionFormation.WriteXMLGroup(writer); - writer.WriteEndElement(); - } - } - - public void WriteXMLOroderPart(XmlWriter writer) - { - if (Count > 0) - { - writer.WriteStartElement("OrderPart"); - writer.WriteAttributeString("Amount", Count.ToString()); - DefinitionFormation.WriteXMLOroderPart(writer); - writer.WriteEndElement(); - } - } - - public bool HasProduct(StepProductDefinition item) - { - foreach (var child in _children) - { - if (child.Id == item.Id) - { - return true; - } - } - return false; - } - } -} diff --git a/Items/StepProductDefinitionShape.cs b/Items/StepProductDefinitionShape.cs deleted file mode 100644 index dadc55b..0000000 --- a/Items/StepProductDefinitionShape.cs +++ /dev/null @@ -1,44 +0,0 @@ -using StepParser.Syntax; -using System; -using System.Collections.Generic; -using System.Text; -using System.Xml; - -namespace StepParser.Items -{ - public class StepProductDefinitionShape: StepComponentAssemble - { - public override StepItemType ItemType => StepItemType.ProductDefinitionShape; - public StepComponentAssemble Definition { get; set; } - - private StepProductDefinitionShape() - : base(string.Empty, 0) - { - } - - internal override IEnumerable GetParameters(StepWriter writer) - { - foreach (var parameter in base.GetParameters(writer)) - { - yield return parameter; - } - } - internal static StepProductDefinitionShape CreateFromSyntaxList(StepBinder binder, StepSyntaxList syntaxList, int id) - { - var productDefinitionShape = new StepProductDefinitionShape(); - syntaxList.AssertListCount(3); - productDefinitionShape.Id = id; - productDefinitionShape.Name = syntaxList.Values[0].GetStringValue(); - productDefinitionShape.Description = syntaxList.Values[1].GetStringValue(); - - binder.BindValue(syntaxList.Values[2], v => productDefinitionShape.Definition = v.AsType()); - - return productDefinitionShape; - } - - internal override void WriteXML(XmlWriter writer) - { - Definition.WriteXML(writer); - } - } -} diff --git a/Items/StepShapeDefinitionRepresentation.cs b/Items/StepShapeDefinitionRepresentation.cs deleted file mode 100644 index f94f882..0000000 --- a/Items/StepShapeDefinitionRepresentation.cs +++ /dev/null @@ -1,66 +0,0 @@ -using StepParser.Syntax; -using System; -using System.Collections.Generic; -using System.Text; -using System.Xml; - -namespace StepParser.Items -{ - public class StepShapeDefinitionRepresentation: StepRepresentationItem - { - public override StepItemType ItemType => StepItemType.ShapeDefinitionRepresentation; - public StepProductDefinitionShape DefinitionShape { get; set; } - public StepShapeRepresentation UsedRepresentation { get; set; } - public StepShapeRepresentationRelationShip UsedRepresentationRelationShip { get; set; } - - private StepShapeDefinitionRepresentation() - : base(string.Empty, 0) - { - } - - public void SetShapePresentationRelationShip(StepShapeRepresentationRelationShip _relationShip) - { - UsedRepresentationRelationShip = _relationShip; - } - - internal override IEnumerable GetParameters(StepWriter writer) - { - foreach (var parameter in base.GetParameters(writer)) - { - yield return parameter; - } - } - internal static StepShapeDefinitionRepresentation CreateFromSyntaxList(StepBinder binder, StepSyntaxList syntaxList, int id) - { - var shapeDefinitionRepresentation = new StepShapeDefinitionRepresentation(); - syntaxList.AssertListCount(2); - shapeDefinitionRepresentation.Id = id; - - binder.BindValue(syntaxList.Values[0], v => shapeDefinitionRepresentation.DefinitionShape = v.AsType()); - binder.BindValue(syntaxList.Values[1], v => shapeDefinitionRepresentation.UsedRepresentation = v.AsType()); - - return shapeDefinitionRepresentation; - } - - internal override void WriteXML(XmlWriter writer) - { - if (DefinitionShape.Definition.ItemType == StepItemType.ProductDefinition) - { - if (((StepProductDefinition)DefinitionShape.Definition).Children.Count == 0) - { - writer.WriteStartElement("Part"); - - DefinitionShape.WriteXML(writer); - - if (UsedRepresentationRelationShip != null) - { - UsedRepresentationRelationShip.WriteXML(writer); - } - - writer.WriteEndElement(); - } - } - - } - } -} diff --git a/Items/StepShapeRepresentation.cs b/Items/StepShapeRepresentation.cs deleted file mode 100644 index ef1b624..0000000 --- a/Items/StepShapeRepresentation.cs +++ /dev/null @@ -1,49 +0,0 @@ -using StepParser.Syntax; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Xml; - -namespace StepParser.Items -{ - public class StepShapeRepresentation: StepRepresentationItem - { - public override StepItemType ItemType => StepItemType.ShapeRepresentation; - public List UsedRepresentationItems { get; set; } = new List(); - - private StepShapeRepresentation() - : base(string.Empty, 0) - { - } - - internal override IEnumerable GetParameters(StepWriter writer) - { - foreach (var parameter in base.GetParameters(writer)) - { - yield return parameter; - } - } - internal static StepShapeRepresentation CreateFromSyntaxList(StepBinder binder, StepSyntaxList syntaxList, int id) - { - var shapeRepresentation = new StepShapeRepresentation(); - syntaxList.AssertListCount(3); - shapeRepresentation.Id = id; - shapeRepresentation.Name = syntaxList.Values[0].GetStringValue(); - var referList = syntaxList.Values[1].GetValueList(); - shapeRepresentation.UsedRepresentationItems.Clear(); - shapeRepresentation.UsedRepresentationItems.AddRange(Enumerable.Range(0, referList.Values.Count).Select(_ => (StepRepresentationItem)null)); - for (int i = 0; i < referList.Values.Count; i++) - { - var j = i; - binder.BindValue(referList.Values[j], v => shapeRepresentation.UsedRepresentationItems[j] = v.AsType()); - } - - return shapeRepresentation; - } - - internal override void WriteXML(XmlWriter writer) - { - } - } -} diff --git a/Items/StepShapeRepresentationRelationShip.cs b/Items/StepShapeRepresentationRelationShip.cs deleted file mode 100644 index 2c1efe6..0000000 --- a/Items/StepShapeRepresentationRelationShip.cs +++ /dev/null @@ -1,46 +0,0 @@ -using StepParser.Syntax; -using System; -using System.Collections.Generic; -using System.Text; -using System.Xml; - -namespace StepParser.Items -{ - public class StepShapeRepresentationRelationShip: StepComponentAssemble - { - public override StepItemType ItemType => StepItemType.ShapeRepresentationRelationship; - public StepShapeRepresentation UsedRepresentation { get; set; } - public StepAdvancedBrepShapeRepresentation AdvancedBrepShapeRepresentation { get; set; } - - private StepShapeRepresentationRelationShip() - : base(string.Empty, 0) - { - } - - internal override IEnumerable GetParameters(StepWriter writer) - { - foreach (var parameter in base.GetParameters(writer)) - { - yield return parameter; - } - } - internal static StepShapeRepresentationRelationShip CreateFromSyntaxList(StepBinder binder, StepSyntaxList syntaxList, int id) - { - var shapeRepresentationRelationShip = new StepShapeRepresentationRelationShip(); - syntaxList.AssertListCount(4); - shapeRepresentationRelationShip.Id = id; - shapeRepresentationRelationShip.Name = syntaxList.Values[0].GetStringValue(); - shapeRepresentationRelationShip.Description = syntaxList.Values[1].GetStringValue(); - - binder.BindValue(syntaxList.Values[2], v => shapeRepresentationRelationShip.UsedRepresentation = v.AsType()); - binder.BindValue(syntaxList.Values[3], v => shapeRepresentationRelationShip.AdvancedBrepShapeRepresentation = v.AsType()); - - return shapeRepresentationRelationShip; - } - - internal override void WriteXML(XmlWriter writer) - { - AdvancedBrepShapeRepresentation.WriteXML(writer); - } - } -} diff --git a/Items/StepStyledItem.cs b/Items/StepStyledItem.cs deleted file mode 100644 index ef5fbd5..0000000 --- a/Items/StepStyledItem.cs +++ /dev/null @@ -1,59 +0,0 @@ -using StepParser.Syntax; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Xml; - -namespace StepParser.Items -{ - public class StepStyledItem: StepRepresentationItem - { - public override StepItemType ItemType => StepItemType.StyledItem; - public List StyleAssignments { get; set; } = new List(); - public StepManifoldSolidBrep UsedSolidBrep { get; set; } - - private StepStyledItem() - : base(string.Empty, 0) - { - } - - internal override IEnumerable GetParameters(StepWriter writer) - { - foreach (var parameter in base.GetParameters(writer)) - { - yield return parameter; - } - } - internal static StepStyledItem CreateFromSyntaxList(StepBinder binder, StepSyntaxList syntaxList, int id) - { - var styledItem = new StepStyledItem(); - syntaxList.AssertListCount(3); - styledItem.Id = id; - styledItem.Name = syntaxList.Values[0].GetStringValue(); - - var referList = syntaxList.Values[1].GetValueList(); - styledItem.StyleAssignments.Clear(); - styledItem.StyleAssignments.AddRange(Enumerable.Range(0, referList.Values.Count).Select(_ => (StepPresentationStyleAssignment)null)); - for (int i = 0; i < referList.Values.Count; i++) - { - var j = i; // capture to avoid rebinding - binder.BindValue(referList.Values[j], v => styledItem.StyleAssignments[j] = v.AsType()); - } - - binder.BindValue(syntaxList.Values[2], v => styledItem.UsedSolidBrep = v.AsType()); - - return styledItem; - } - - internal override void WriteXML(XmlWriter writer) - { - writer.WriteStartElement("StyleAssignments"); - foreach (var styleAssignment in StyleAssignments) - { - styleAssignment.WriteXML(writer); - } - writer.WriteEndElement(); - } - } -} diff --git a/Items/StepSurfaceSideStyle.cs b/Items/StepSurfaceSideStyle.cs deleted file mode 100644 index bc644ae..0000000 --- a/Items/StepSurfaceSideStyle.cs +++ /dev/null @@ -1,57 +0,0 @@ -using StepParser.Syntax; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Xml; - -namespace StepParser.Items -{ - public class StepSurfaceSideStyle: StepRepresentationItem - { - public override StepItemType ItemType => StepItemType.SurfaceSideStyle; - public List SurfaceStyleFillAreaList { get; set; } = new List(); - - private StepSurfaceSideStyle() - : base(string.Empty, 0) - { - } - - internal override IEnumerable GetParameters(StepWriter writer) - { - foreach (var parameter in base.GetParameters(writer)) - { - yield return parameter; - } - } - internal static StepSurfaceSideStyle CreateFromSyntaxList(StepBinder binder, StepSyntaxList syntaxList, int id) - { - var surfaceSideStyle = new StepSurfaceSideStyle(); - syntaxList.AssertListCount(2); - surfaceSideStyle.Id = id; - surfaceSideStyle.Name = syntaxList.Values[0].GetStringValue(); - - var referList = syntaxList.Values[1].GetValueList(); - surfaceSideStyle.SurfaceStyleFillAreaList.Clear(); - surfaceSideStyle.SurfaceStyleFillAreaList.AddRange(Enumerable.Range(0, referList.Values.Count).Select(_ => (StepSurfaceStyleFillArea)null)); - for (int i = 0; i < referList.Values.Count; i++) - { - var j = i; // capture to avoid rebinding - binder.BindValue(referList.Values[j], v => surfaceSideStyle.SurfaceStyleFillAreaList[j] = v.AsType()); - } - - return surfaceSideStyle; - } - - internal override void WriteXML(XmlWriter writer) - { - writer.WriteStartElement("Style"); - writer.WriteAttributeString("predefined", "false"); - foreach (var styleFillAare in SurfaceStyleFillAreaList) - { - styleFillAare.WriteXML(writer); - } - writer.WriteEndElement(); - } - } -} diff --git a/Items/StepSurfaceStyleFillArea.cs b/Items/StepSurfaceStyleFillArea.cs deleted file mode 100644 index 59e7e9d..0000000 --- a/Items/StepSurfaceStyleFillArea.cs +++ /dev/null @@ -1,42 +0,0 @@ -using StepParser.Syntax; -using System; -using System.Collections.Generic; -using System.Text; -using System.Xml; - -namespace StepParser.Items -{ - public class StepSurfaceStyleFillArea: StepRepresentationItem - { - public override StepItemType ItemType => StepItemType.SurfaceStyleFillArea; - public StepFillAreaStyle FillAreaStyle { get; set; } - - private StepSurfaceStyleFillArea() - : base(string.Empty, 0) - { - } - - internal override IEnumerable GetParameters(StepWriter writer) - { - foreach (var parameter in base.GetParameters(writer)) - { - yield return parameter; - } - } - internal static StepSurfaceStyleFillArea CreateFromSyntaxList(StepBinder binder, StepSyntaxList syntaxList, int id) - { - var surfaceStyleFillArea = new StepSurfaceStyleFillArea(); - syntaxList.AssertListCount(1); - surfaceStyleFillArea.Id = id; - - binder.BindValue(syntaxList.Values[0], v => surfaceStyleFillArea.FillAreaStyle = v.AsType()); - - return surfaceStyleFillArea; - } - - internal override void WriteXML(XmlWriter writer) - { - FillAreaStyle.WriteXML(writer); - } - } -} diff --git a/Items/StepSurfaceStyleUsage.cs b/Items/StepSurfaceStyleUsage.cs deleted file mode 100644 index abf34a0..0000000 --- a/Items/StepSurfaceStyleUsage.cs +++ /dev/null @@ -1,48 +0,0 @@ -using StepParser.Syntax; -using System; -using System.Collections.Generic; -using System.Text; -using System.Xml; - -namespace StepParser.Items -{ - public class StepSurfaceStyleUsage: StepRepresentationItem - { - public override StepItemType ItemType => StepItemType.SurfaceStyleUsage; - public string Side { get; set; } - public StepSurfaceSideStyle SurfaceSideStyle { get; set; } - - private StepSurfaceStyleUsage() - : base(string.Empty, 0) - { - } - - internal override IEnumerable GetParameters(StepWriter writer) - { - foreach (var parameter in base.GetParameters(writer)) - { - yield return parameter; - } - } - internal static StepSurfaceStyleUsage CreateFromSyntaxList(StepBinder binder, StepSyntaxList syntaxList, int id) - { - var surfaceStyleUsage = new StepSurfaceStyleUsage(); - syntaxList.AssertListCount(2); - surfaceStyleUsage.Id = id; - surfaceStyleUsage.Side = syntaxList.Values[0].GetEnumerationValue(); - - binder.BindValue(syntaxList.Values[1], v => surfaceStyleUsage.SurfaceSideStyle = v.AsType()); - - return surfaceStyleUsage; - } - - internal override void WriteXML(XmlWriter writer) - { - writer.WriteAttributeString("type", ItemType.GetItemTypeString()); - writer.WriteAttributeString("side", Side); - writer.WriteStartElement("Styles"); - SurfaceSideStyle.WriteXML(writer); - writer.WriteEndElement(); - } - } -} diff --git a/Items/StepVertex.cs b/Items/StepVertex.cs deleted file mode 100644 index 33b5db2..0000000 --- a/Items/StepVertex.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace StepParser.Items -{ - public abstract class StepVertex : StepTopologicalRepresentationItem - { - protected StepVertex(string name) - : base(name, 0) - { - } - } -} diff --git a/License.txt b/License.txt new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/License.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/Program.cs b/Program.cs deleted file mode 100644 index 812b07c..0000000 --- a/Program.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System; -using System.IO; -using System.Text; -using System.Xml; - -namespace StepParser -{ - class Program - { - static void Main(string[] args) - { - if (args.Length > 0) - { - if (File.Exists(args[0])) - { - string fullPath = Path.GetFullPath(args[0]); - string onlyPath = Directory.GetParent(fullPath).FullName; - string fileName = Path.GetFileNameWithoutExtension(args[0]); - Console.WriteLine("Loading STP file..."); - StepFile stepFile; - using (FileStream fs = new FileStream(fullPath, FileMode.Open)) - { - stepFile = StepFile.Load(fs); - } - - XmlDocument doc = new XmlDocument(); - XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null); - - Console.WriteLine("Writing XML file..."); - XmlWriterSettings settings = new XmlWriterSettings - { - ConformanceLevel = ConformanceLevel.Fragment, - Indent = true, - IndentChars = " ", - OmitXmlDeclaration = false, - CloseOutput = false, - Encoding = Encoding.Unicode - }; - XmlWriter xmlWriter = XmlWriter.Create(onlyPath + "/" + fileName + ".xml", settings); - StepWriter stepWriter = new StepWriter(stepFile, false, xmlWriter); - stepWriter.Save(); - - xmlWriter.Flush(); - xmlWriter.Close(); - - Console.WriteLine("Success!"); - } - else - { - Console.WriteLine("File Not Exists"); - } - } - else - { - Console.WriteLine("No STP File found"); - } - } - } -} diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json deleted file mode 100644 index a1138b0..0000000 --- a/Properties/launchSettings.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "profiles": { - "StepParser": { - "commandName": "Project", - "commandLineArgs": "D:\\stp\\test.stp" - } - } -} \ No newline at end of file diff --git a/README.md b/README.md index e65ab1c..d8d6da6 100644 --- a/README.md +++ b/README.md @@ -1,52 +1,79 @@ -# step-parser +IxMilia.Step +============ -## 1. Code Structure -Totally, it has 3 parts -- Loading file and parsing syntax -- Bind syntax with proper item -- Write XML with loop all items +A portable .NET library for reading and writing STEP CAD files. -![image-fileStructure](./screenshots/file_structure.png) +## Usage -### Items -`Itmes` includes item classes +Open a STEP file: -For example, `PRODUCT_DEFINITION`, `CLOSED_SHELL` etc +``` C# +using System.IO; +using IxMilia.Step; +using IxMilia.Step.Items; +// ... -`StepReader` and `StepBinder` is reading stp file and create proper class from item classes -### Syntax +//------------------------------------------------------------ read from a file +StepFile stepFile; +using (FileStream fs = new FileStream(@"C:\Path\To\File.stp", FileMode.Open)) +{ + stepFile = StepFile.Load(fs); +} -`Syntax` includes utility for handling syntax +// if on >= NETStandard1.3 you can use: +// StepFile stepFile = StepFile.Load(@"C:\Path\To\File.stp"); -For example, `.F.` This is boolean type and it's value is `false` +//---------------------------------------------- or read directly from a string +StepFile stepFile = StepFile.Parse(@"ISO-10303-21; +HEADER; +... +END-ISO-103030-21;"); +//----------------------------------------------------------------------------- -And also `(#1, #234, #22)` This is array type - -### Tokens -`Tokens` includes utility for parsing stp file -``` -#208=AXIS2_PLACEMENT_3D('',#381,#382,#383); +foreach (StepRepresentationItem item in stepFile.Items) +{ + switch (item.ItemType) + { + case StepItemType.Line: + StepLine line = (StepLine)item; + // ... + break; + // ... + } +} ``` -`#` - Beginning hash -`208` - Id -`AXIS2_PLACEMENT_3D` - Entity Name (will be matched with item class in Items) -the values are in bracket it attributes -Token classes will be parsing above information +Save a STEP file: -## 2. How to install on local and execute +``` C# +using System.IO; +using IxMilia.Step; +using IxMilia.Step.Items; +// ... -1. Install Visual Studio -2. Open `StepPraser.sln` -3. It will install Nuget Package automatically. It's C# console application based on Net.2.2 so VS will loading `MicroSoft.NetCore.App (2.2.0) -4. Go to Project Setting and put argument manually -![image-20200226033800862](./screenshots/image-20200226033800862.png) -5. Click Debug for executing Current application +StepFile stepFile = new StepFile(); +stepFile.Items.Add(new StepDirection("direction-label", 1.0, 0.0, 0.0)); +// ... -## 3. How to build +//------------------------------------------------------------- write to a file +using (FileStream fs = new FileStream(@"C:\Path\To\File.stp", FileMode.Create)) +{ + stepFile.Save(fs); +} -It's using NetCore 2.2 so it's useful to build with command line +// if on >= NETStandard1.3 you can use +// stepFile.Save(@"C:\Path\To\File.stp"); +//------------------------------------------------------- or output as a string +string contents = stepFile.GetContentsAsString(); ``` -dotnet publish -c Debug -r win10-x64 -``` + +## Building locally + +To build locally, install the [latest .NET Core 3.0 SDK](https://dotnet.microsoft.com/download). + +## Specification + +Using spec from steptools.com [here](http://www.steptools.com/library/standard/IS_final_p21e3.html). + +STEP Application Protocols [here](http://www.steptools.com/support/stdev_docs/express/). diff --git a/StepParser.csproj b/StepParser.csproj deleted file mode 100644 index 2eba7d9..0000000 --- a/StepParser.csproj +++ /dev/null @@ -1,8 +0,0 @@ - - - - Exe - netcoreapp2.2 - - - diff --git a/StepParser.sln b/StepParser.sln deleted file mode 100644 index 06f8a8b..0000000 --- a/StepParser.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.28729.10 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StepParser", "StepParser.csproj", "{FDB6954E-D535-4B5F-B019-7A497E57C843}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {FDB6954E-D535-4B5F-B019-7A497E57C843}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FDB6954E-D535-4B5F-B019-7A497E57C843}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FDB6954E-D535-4B5F-B019-7A497E57C843}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FDB6954E-D535-4B5F-B019-7A497E57C843}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {9103C877-4E78-4FB2-8F6C-C19CDB2370D0} - EndGlobalSection -EndGlobal diff --git a/StepWriter.cs b/StepWriter.cs deleted file mode 100644 index 3eeb385..0000000 --- a/StepWriter.cs +++ /dev/null @@ -1,257 +0,0 @@ -using StepParser.Items; -using StepParser.Syntax; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Xml; - -namespace StepParser -{ - internal class StepWriter - { - private StepFile _file; - private bool _inlineReferences; - private Dictionary _itemMap; - private XmlWriter _xmlWriter; - - public StepWriter(StepFile stepFile, bool inlineReferences, XmlWriter xmlWriter) - { - _file = stepFile; - _itemMap = new Dictionary(); - _inlineReferences = inlineReferences; - _xmlWriter = xmlWriter; - - SetRelationShip(); - } - - public void Save() - { - // output header - WriteHeader(); - - // data section - // Write Parts Section - _xmlWriter.WriteStartElement("Parts"); - foreach (var item in _file.Items) - { - if (item.ItemType == StepItemType.ShapeDefinitionRepresentation) - { - item.WriteXML(_xmlWriter); - } - } - _xmlWriter.WriteEndElement(); - - // Write Group Section - - _xmlWriter.WriteStartElement("Structure"); - var rootGroups = GetRootGroups(); - foreach (var item in rootGroups) - { - WriteGroup(item); - } - _xmlWriter.WriteEndElement(); - - // Write Orders - - _xmlWriter.WriteStartElement("OrderList"); - foreach (var item in _file.Items) - { - if (item.ItemType == StepItemType.ProductDefinition) - { - ((StepProductDefinition)item).WriteXMLOroderPart(_xmlWriter); - } - } - _xmlWriter.WriteEndElement(); - } - - private void WriteHeader() - { - _xmlWriter.WriteStartElement("BasicData"); - WriteXmlElement("FileName", _file.Name); - WriteXmlElement("ISO", StepFile.MagicHeader); - WriteXmlElement("Standard", _file.Description); - WriteXmlElement("DateTime", _file.Timestamp.ToString()); - _xmlWriter.WriteEndElement(); - } - - private void WriteXmlElement(string name, string value) - { - _xmlWriter.WriteStartElement(name); - _xmlWriter.WriteString(value); - _xmlWriter.WriteEndElement(); - } - - private void WriteGroup(StepRepresentationItem item) - { - if (item.ItemType == StepItemType.ProductDefinition) - { - ((StepProductDefinition)item).WriteXMLGroup(_xmlWriter); - } - } - - private List GetRootGroups() - { - var rootGroups = new List(); - - foreach (var item in _file.Items) - { - bool isRoot = true; - if (item.ItemType == StepItemType.ProductDefinition) - { - foreach(var subItem in _file.Items) - { - if (subItem.ItemType == StepItemType.ProductDefinition) - { - if (((StepProductDefinition)subItem).HasProduct((StepProductDefinition)item)) - { - isRoot = false; - } - } - } - if (isRoot == true) - { - rootGroups.Add((StepProductDefinition)item); - } - } - } - - return rootGroups; - } - - public void SetRelationShip() - { - for(int idx = 0; idx < _file.Items.Count; idx++) - { - if (_file.Items[idx].ItemType == StepItemType.ShapeDefinitionRepresentation) - { - var relationShip = GetShapeRelationShip((StepShapeDefinitionRepresentation)_file.Items[idx]); - if (relationShip != null) - { - ((StepShapeDefinitionRepresentation)_file.Items[idx]).SetShapePresentationRelationShip(relationShip); - } - - } - else if (_file.Items[idx].ItemType == StepItemType.AdvancedBrepShapeRepresentation) - { - List styledItems = GetStyledItems((StepAdvancedBrepShapeRepresentation)_file.Items[idx]); - ((StepAdvancedBrepShapeRepresentation)_file.Items[idx]).SetStyledItems(styledItems); - } - else if (_file.Items[idx].ItemType == StepItemType.ProductDefinition) - { - List nextComponents = GetNextComponent((StepProductDefinition)_file.Items[idx]); - ((StepProductDefinition)_file.Items[idx]).Children = nextComponents; - } - } - - } - - public StepShapeRepresentationRelationShip GetShapeRelationShip(StepShapeDefinitionRepresentation item) - { - foreach (var eachItem in _file.Items) - { - if (eachItem.ItemType == StepItemType.ShapeRepresentationRelationship) - { - var itemInstance = (StepShapeRepresentationRelationShip)eachItem; - if (itemInstance.UsedRepresentation != null && itemInstance.UsedRepresentation.Id == item.UsedRepresentation.Id) - { - return itemInstance; - } - } - } - return null; - } - - public List GetStyledItems(StepAdvancedBrepShapeRepresentation item) - { - var styledItems = new List(); - if (item.UsedSolidBrepList != null && item.UsedSolidBrepList.Count > 0) - { - foreach(var solidBrep in item.UsedSolidBrepList) - { - foreach (var eachItem in _file.Items) - { - if (eachItem.ItemType == StepItemType.StyledItem) - { - var itemInstance = (StepStyledItem)eachItem; - if (itemInstance.UsedSolidBrep != null && itemInstance.UsedSolidBrep.Id == solidBrep.Id) - { - styledItems.Add(itemInstance); - } - } - } - } - } - - return styledItems; - } - - public List GetNextComponent(StepProductDefinition item) - { - var nextComponents = new List(); - foreach (var eachItem in _file.Items) - { - if (eachItem.ItemType == StepItemType.NextAssemblyUsageOccurrence) - { - var itemInstance = (StepNextAssemblyUsageOccrrence)eachItem; - if (itemInstance.Parent != null && itemInstance.Parent.Id == item.Id) - { - nextComponents.Add(itemInstance.Child); - } - } - } - return nextComponents; - } - - public StepSyntax GetItemSyntax(StepRepresentationItem item) - { - if (_inlineReferences) - { - var parameters = new StepSyntaxList(-1, -1, item.GetParameters(this)); - return new StepSimpleItemSyntax(item.ItemType.GetItemTypeString(), parameters, item.Id); - } - else - { - return new StepEntityInstanceReferenceSyntax(_itemMap[item]); - } - } - - public StepSyntax GetItemSyntaxOrAuto(StepRepresentationItem item) - { - return item == null - ? new StepAutoSyntax() - : GetItemSyntax(item); - } - - public static StepEnumerationValueSyntax GetBooleanSyntax(bool value) - { - var text = value ? "T" : "F"; - return new StepEnumerationValueSyntax(text); - } - - internal static IEnumerable SplitStringIntoParts(string str, int maxLength = 256) - { - var parts = new List(); - if (str != null) - { - int offset = 0; - while (offset < str.Length) - { - var length = Math.Min(maxLength, str.Length - offset); - parts.Add(str.Substring(offset, length)); - offset += length; - } - } - else - { - parts.Add(string.Empty); - } - - return parts; - } - - private string toCamel(string input) - { - return new CultureInfo("en").TextInfo.ToTitleCase(input.ToLower().Replace("_", " ")).Replace(" ", ""); - } - } -} diff --git a/Syntax/StepItemSyntax.cs b/Syntax/StepItemSyntax.cs deleted file mode 100644 index 5dd6b47..0000000 --- a/Syntax/StepItemSyntax.cs +++ /dev/null @@ -1,11 +0,0 @@ - -namespace StepParser.Syntax -{ - internal abstract class StepItemSyntax : StepSyntax - { - protected StepItemSyntax(int line, int column) - : base(line, column) - { - } - } -} diff --git a/build-and-test.cmd b/build-and-test.cmd new file mode 100644 index 0000000..9efd6c2 --- /dev/null +++ b/build-and-test.cmd @@ -0,0 +1,38 @@ +@echo off +setlocal + +set thisdir=%~dp0 +set configuration=Debug +set runtests=true + +:parseargs +if "%1" == "" goto argsdone +if /i "%1" == "-c" ( + set configuration=%2 + shift + shift + goto parseargs +) +if /i "%1" == "-notest" ( + set runtests=false + shift + goto parseargs +) + +echo Unsupported argument: %1 +goto error + +:argsdone + +:: build +set SOLUTION=%~dp0src\IxMilia.Step.sln +dotnet restore %SOLUTION% +if errorlevel 1 exit /b 1 +dotnet build %SOLUTION% -c %configuration% +if errorlevel 1 exit /b 1 + +:: test +if /i "%runtests%" == "true" ( + dotnet test "%SOLUTION%" -c %configuration% --no-restore --no-build + if errorlevel 1 goto error +) diff --git a/build-and-test.sh b/build-and-test.sh new file mode 100644 index 0000000..afbd3bc --- /dev/null +++ b/build-and-test.sh @@ -0,0 +1,33 @@ +#!/bin/sh -e + +_SCRIPT_DIR="$( cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P )" + +CONFIGURATION=Debug +RUNTESTS=true + +while [ $# -gt 0 ]; do + case "$1" in + --configuration|-c) + CONFIGURATION=$2 + shift + ;; + --notest) + RUNTESTS=false + ;; + *) + echo "Invalid argument: $1" + exit 1 + ;; + esac + shift +done + +# build +SOLUTION=$_SCRIPT_DIR/src/IxMilia.Step.sln +dotnet restore $SOLUTION +dotnet build $SOLUTION -c $CONFIGURATION + +# test +if [ "$RUNTESTS" = "true" ]; then + dotnet test $SOLUTION -c $CONFIGURATION --no-restore --no-build +fi diff --git a/screenshots/file_structure.png b/screenshots/file_structure.png deleted file mode 100644 index 8238e1e..0000000 Binary files a/screenshots/file_structure.png and /dev/null differ diff --git a/screenshots/image-20200226033800862.png b/screenshots/image-20200226033800862.png deleted file mode 100644 index 0b4d3d9..0000000 Binary files a/screenshots/image-20200226033800862.png and /dev/null differ diff --git a/src/IxMilia.Step.Test/IxMilia.Step.Test.csproj b/src/IxMilia.Step.Test/IxMilia.Step.Test.csproj new file mode 100644 index 0000000..9ce615f --- /dev/null +++ b/src/IxMilia.Step.Test/IxMilia.Step.Test.csproj @@ -0,0 +1,24 @@ + + + + + + Exe + netcoreapp3.0 + + + + + + + + + + + + + + + + + diff --git a/src/IxMilia.Step.Test/StepFileTests.cs b/src/IxMilia.Step.Test/StepFileTests.cs new file mode 100644 index 0000000..461a4b6 --- /dev/null +++ b/src/IxMilia.Step.Test/StepFileTests.cs @@ -0,0 +1,39 @@ +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.IO; +using System.Linq; +using IxMilia.Step.Items; +using Xunit; + +namespace IxMilia.Step.Test +{ + public class StepFileTests : StepTestBase + { + [Fact] + public void FileSystemAPITest() + { + var filePath = Path.GetTempFileName(); + var stepFile = new StepFile(); + var point = new StepCartesianPoint("some-label", 1.0, 2.0, 3.0); + stepFile.Items.Add(point); + + // round trip + stepFile.Save(filePath); + var stepFile2 = StepFile.Load(filePath); + + var point2 = (StepCartesianPoint)stepFile2.Items.Single(); + Assert.Equal(point.Name, point2.Name); + Assert.Equal(point.X, point2.X); + Assert.Equal(point.Y, point2.Y); + Assert.Equal(point.Z, point2.Z); + + try + { + File.Delete(filePath); + } + catch + { + } + } + } +} diff --git a/src/IxMilia.Step.Test/StepHeaderTests.cs b/src/IxMilia.Step.Test/StepHeaderTests.cs new file mode 100644 index 0000000..cafe5a7 --- /dev/null +++ b/src/IxMilia.Step.Test/StepHeaderTests.cs @@ -0,0 +1,140 @@ +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Linq; +using Xunit; + +namespace IxMilia.Step.Test +{ + public class StepHeaderTests : StepTestBase + { + private StepFile ReadFileFromHeader(string header) + { + var file = $@" +{StepFile.MagicHeader}; +{StepFile.HeaderText}; +{header.Trim()} +{StepFile.EndSectionText}; +{StepFile.DataText}; +{StepFile.EndSectionText}; +{StepFile.MagicFooter}; +"; + return StepFile.Parse(file.Trim()); + } + + [Fact] + public void FileDescriptionTest() + { + var file = ReadFileFromHeader("FILE_DESCRIPTION(('some description'), '2;1');"); + Assert.Equal("some description", file.Description); + Assert.Equal("2;1", file.ImplementationLevel); + } + + [Fact] + public void FileDescriptionWithMultiplePartsTest() + { + var file = ReadFileFromHeader("FILE_DESCRIPTION(('some description', ', ', 'more description'), '2;1');"); + Assert.Equal("some description, more description", file.Description); + Assert.Equal("2;1", file.ImplementationLevel); + } + + [Fact] + public void FullHeaderTest() + { + var file = ReadFileFromHeader(@" +FILE_DESCRIPTION(('description'), '2;1'); +FILE_NAME('file-name', '2010-01-01T', ('author'), ('organization'), 'preprocessor', 'originator', 'authorization'); +FILE_SCHEMA(('EXPLICIT_DRAUGHTING')); +"); + Assert.Equal("description", file.Description); + Assert.Equal("2;1", file.ImplementationLevel); + Assert.Equal("file-name", file.Name); + Assert.Equal(new DateTime(2010, 1, 1), file.Timestamp); + Assert.Equal("author", file.Author); + Assert.Equal("organization", file.Organization); + Assert.Equal("preprocessor", file.PreprocessorVersion); + Assert.Equal("originator", file.OriginatingSystem); + Assert.Equal("authorization", file.Authorization); + Assert.Equal(StepSchemaTypes.ExplicitDraughting, file.Schemas.Single()); + } + + [Fact] + public void ReadDifferentTimeStampsTest() + { + var file = ReadFileFromHeader(@"FILE_NAME('', '2016-06-26T13:59:52+02:00', (), (), '', '', '');"); + Assert.Equal(2016, file.Timestamp.Year); + Assert.Equal(6, file.Timestamp.Month); + } + + [Fact] + public void ReadTimeStampMonthWithoutLeadingZerosTest() + { + var file = ReadFileFromHeader(@"FILE_NAME('', '2004-3-17T2:58:55 PM+8:00', (), (), '', '', '');"); + Assert.Equal(2004, file.Timestamp.Year); + Assert.Equal(3, file.Timestamp.Month); + } + + [Fact] + public void WriteHeaderTest() + { + var file = new StepFile(); + file.Description = "some description"; + file.ImplementationLevel = "2;1"; + file.Name = "file-name"; + file.Timestamp = new DateTime(2010, 1, 1); + file.Author = "author"; + file.Organization = "organization"; + file.PreprocessorVersion = "preprocessor"; + file.OriginatingSystem = "originator"; + file.Authorization = "authorization"; + file.Schemas.Add(StepSchemaTypes.ExplicitDraughting); + AssertFileIs(file, @" +ISO-10303-21; +HEADER; +FILE_DESCRIPTION(('some description'),'2;1'); +FILE_NAME('file-name','2010-01-01T00:00:00.0000000',('author'),('organization'),'preprocessor','originator','authorization'); +FILE_SCHEMA(('EXPLICIT_DRAUGHTING')); +ENDSEC; +DATA; +ENDSEC; +END-ISO-10303-21; +".TrimStart()); + } + + [Fact] + public void WriteHeaderWithLongDescriptionTest() + { + var file = new StepFile(); + file.Description = new string('a', 257); + file.Timestamp = new DateTime(2010, 1, 1); + file.Schemas.Add(StepSchemaTypes.ExplicitDraughting); + AssertFileIs(file, $@" +ISO-10303-21; +HEADER; +FILE_DESCRIPTION(('{new string('a', 256)}','a'),''); +FILE_NAME('','2010-01-01T00:00:00.0000000',(''),(''),'','',''); +FILE_SCHEMA(('EXPLICIT_DRAUGHTING')); +ENDSEC; +DATA; +ENDSEC; +END-ISO-10303-21; +".TrimStart()); + } + + [Fact] + public void ReadHeaderWithUnsupportedSchemaTest() + { + var file = ReadFileFromHeader(@"FILE_SCHEMA(('EXPLICIT_DRAUGHTING','UNSUPPORTED_SCHEMA'));"); + Assert.Single(file.Schemas); + Assert.Single(file.UnsupportedSchemas); + } + + [Fact] + public void WriteHeaderWithUnsupportedSchemaTest() + { + var file = new StepFile(); + file.UnsupportedSchemas.Add("UNSUPPORTED_SCHEMA"); + AssertFileContains(file, "FILE_SCHEMA(('UNSUPPORTED_SCHEMA'));"); + } + } +} diff --git a/src/IxMilia.Step.Test/StepItemTests.cs b/src/IxMilia.Step.Test/StepItemTests.cs new file mode 100644 index 0000000..b49cba1 --- /dev/null +++ b/src/IxMilia.Step.Test/StepItemTests.cs @@ -0,0 +1,591 @@ +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Linq; +using IxMilia.Step.Items; +using Xunit; + +namespace IxMilia.Step.Test +{ + public class StepItemTests : StepTestBase + { + private StepFile ReadFile(string data) + { + var text = $@" +ISO-10303-21; +HEADER; +ENDSEC; +DATA; +{data.Trim()} +ENDSEC; +END-ISO-10303-21; +"; + var file = StepFile.Parse(text.Trim()); + return file; + } + + private StepRepresentationItem ReadTopLevelItem(string data) + { + var file = ReadFile(data); + return file.GetTopLevelItems().Single(); + } + + private void AssertFileContains(StepRepresentationItem item, string expected) + { + var file = new StepFile(); + file.Items.Add(item); + AssertFileContains(file, expected); + } + + [Fact] + public void ReadCartesianPointTest1() + { + var point = (StepCartesianPoint)ReadTopLevelItem("#1=CARTESIAN_POINT('name',(1.0,2.0,3.0));"); + Assert.Equal("name", point.Name); + Assert.Equal(1.0, point.X); + Assert.Equal(2.0, point.Y); + Assert.Equal(3.0, point.Z); + } + + [Fact] + public void ReadCartesianPointTest2() + { + var point = (StepCartesianPoint)ReadTopLevelItem("#1=CARTESIAN_POINT('name',(1.0));"); + Assert.Equal("name", point.Name); + Assert.Equal(1.0, point.X); + Assert.Equal(0.0, point.Y); + Assert.Equal(0.0, point.Z); + } + + [Fact] + public void ReadCartesianPointWithOmittedNameTest() + { + var point = (StepCartesianPoint)ReadTopLevelItem("#1=CARTESIAN_POINT($,(0.0,0.0,0.0));"); + Assert.Equal(string.Empty, point.Name); + } + + [Fact] + public void ReadDirectionTest() + { + var direction = (StepDirection)ReadTopLevelItem("#1=DIRECTION('name',(1.0,2.0,3.0));"); + Assert.Equal("name", direction.Name); + Assert.Equal(1.0, direction.X); + Assert.Equal(2.0, direction.Y); + Assert.Equal(3.0, direction.Z); + } + + [Fact] + public void ReadSubReferencedItemTest() + { + var vector = (StepVector)ReadTopLevelItem("#1=VECTOR('name',DIRECTION('',(0.0,0.0,1.0)),15.0);"); + Assert.Equal(new StepDirection("", 0.0, 0.0, 1.0), vector.Direction); + Assert.Equal(15.0, vector.Length); + } + + [Fact] + public void ReadPreviouslyReferencedItemsTest() + { + var vector = (StepVector)ReadTopLevelItem(@" +#1=DIRECTION('',(0.0,0.0,1.0)); +#2=VECTOR('',#1,15.0); +"); + Assert.Equal(new StepDirection("", 0.0, 0.0, 1.0), vector.Direction); + Assert.Equal(15.0, vector.Length); + } + + [Fact] + public void ReadPostReferencedItemTest() + { + var vector = (StepVector)ReadTopLevelItem(@" +#1=VECTOR('',#2,15.0); +#2=DIRECTION('',(0.0,0.0,1.0)); +"); + Assert.Equal(new StepDirection("", 0.0, 0.0, 1.0), vector.Direction); + Assert.Equal(15.0, vector.Length); + } + + [Fact] + public void ReadLineTest() + { + var line = (StepLine)ReadTopLevelItem(@" +#1=CARTESIAN_POINT('',(1.0,2.0,3.0)); +#2=DIRECTION('',(0.0,0.0,1.0)); +#3=VECTOR('',#2,15.0); +#4=LINE('',#1,#3); +"); + Assert.Equal(new StepCartesianPoint("", 1.0, 2.0, 3.0), line.Point); + Assert.Equal(15.0, line.Vector.Length); + Assert.Equal(new StepDirection("", 0.0, 0.0, 1.0), line.Vector.Direction); + } + + [Fact] + public void WriteLineTest() + { + var file = new StepFile(); + file.Items.Add(new StepLine("", new StepCartesianPoint("", 1.0, 2.0, 3.0), new StepVector("", new StepDirection("", 1.0, 0.0, 0.0), 4.0))); + AssertFileContains(file, @" +#1=CARTESIAN_POINT('',(1.0,2.0,3.0)); +#2=DIRECTION('',(1.0,0.0,0.0)); +#3=VECTOR('',#2,4.0); +#4=LINE('',#1,#3); +"); + } + + [Fact] + public void WriteLineWithInlineReferencesTest() + { + var file = new StepFile(); + file.Items.Add(new StepLine("", new StepCartesianPoint("", 1.0, 2.0, 3.0), new StepVector("", new StepDirection("", 1.0, 0.0, 0.0), 4.0))); + AssertFileContains(file, @" +#1=LINE('',CARTESIAN_POINT('',(1.0,2.0,3.0)),VECTOR('',DIRECTION('',(1.0,0.0,0.0 +)),4.0)); +", inlineReferences: true); + } + + [Fact] + public void ReadCircleTest() + { + var circle = (StepCircle)ReadTopLevelItem(@" +#1=CARTESIAN_POINT('',(1.0,2.0,3.0)); +#2=DIRECTION('',(0.0,0.0,1.0)); +#3=AXIS2_PLACEMENT_2D('',#1,#2); +#4=CIRCLE('',#3,5.0); +"); + Assert.Equal(new StepCartesianPoint("", 1.0, 2.0, 3.0), ((StepAxis2Placement2D)circle.Position).Location); + Assert.Equal(new StepDirection("", 0.0, 0.0, 1.0), ((StepAxis2Placement2D)circle.Position).RefDirection); + Assert.Equal(5.0, circle.Radius); + } + + [Fact] + public void WriteCircleTest() + { + var circle = new StepCircle("", new StepAxis2Placement2D("", new StepCartesianPoint("", 1.0, 2.0, 3.0), new StepDirection("", 0.0, 0.0, 1.0)), 5.0); + AssertFileContains(circle, @" +#1=CARTESIAN_POINT('',(1.0,2.0,3.0)); +#2=DIRECTION('',(0.0,0.0,1.0)); +#3=AXIS2_PLACEMENT_2D('',#1,#2); +#4=CIRCLE('',#3,5.0); +"); + } + + [Fact] + public void ReadEllipseTest() + { + var ellipse = (StepEllipse)ReadTopLevelItem(@" +#1=CARTESIAN_POINT('',(1.0,2.0,3.0)); +#2=DIRECTION('',(0.0,0.0,1.0)); +#3=AXIS2_PLACEMENT_2D('',#1,#2); +#4=ELLIPSE('',#3,3.0,4.0); +"); + Assert.Equal(new StepCartesianPoint("", 1.0, 2.0, 3.0), ellipse.Position.Location); + Assert.Equal(new StepDirection("", 0.0, 0.0, 1.0), ellipse.Position.RefDirection); + Assert.Equal(3.0, ellipse.SemiAxis1); + Assert.Equal(4.0, ellipse.SemiAxis2); + } + + [Fact] + public void ReadTopLevelReferencedItemsTest() + { + var file = ReadFile(@" +#1=CARTESIAN_POINT('',(1.0,2.0,3.0)); +#2=DIRECTION('',(0.0,0.0,1.0)); +#3=AXIS2_PLACEMENT_2D('',#1,#2); +#4=ELLIPSE('',#3,3.0,4.0); +"); + + Assert.Equal(4, file.Items.Count); + + // only ELLIPSE() isn't referenced by another item + var ellipse = (StepEllipse)file.GetTopLevelItems().Single(); + } + + [Fact] + public void ReadTopLevelInlinedItemsTest() + { + var file = ReadFile("#1=ELLIPSE('',AXIS2_PLACEMENT_2D('',CARTESIAN_POINT('',(1.0,2.0,3.0)),DIRECTION('',(0.0,0.0,1.0))),3.0,4.0);"); + + Assert.Single(file.Items); + + // only ELLIPSE() isn't referenced by another item + var ellipse = (StepEllipse)file.GetTopLevelItems().Single(); + } + + [Fact] + public void ReadBSplineWithKnotsItemsTest() + { + var spline = (StepBSplineCurveWithKnots)ReadTopLevelItem(@" +#1=CARTESIAN_POINT('Ctrl Pts',(-2.09228759117738,32.4775276519752,7.66388871568773)); +#2=CARTESIAN_POINT('Ctrl Pts',(-2.09228759389655,30.5382976972817,7.66388872564781)); +#3=CARTESIAN_POINT('Ctrl Pts',(-2.09228913953809,28.5997370344523,7.66389438721404)); +#4=CARTESIAN_POINT('Ctrl Pts',(-2.09228986816456,26.5173645163537,7.66389705611683)); +#5=CARTESIAN_POINT('Ctrl Pts',(-2.09228981902238,26.4462306775892,7.6638968761128)); +#6=CARTESIAN_POINT('Ctrl Pts',(-2.0922902432834,25.9015378442672,7.66389843014835)); +#7=CARTESIAN_POINT('Ctrl Pts',(-2.11494520023805,24.945781133428,7.74688179710576)); +#8=CARTESIAN_POINT('Ctrl Pts',(-2.21905874762543,23.5389919187115,8.1282417231202)); +#9=CARTESIAN_POINT('Ctrl Pts',(-2.39215391928761,22.2144888644552,8.76227603964325)); +#10=CARTESIAN_POINT('Ctrl Pts',(-2.62666223390231,21.041382550633,9.62126198100665)); +#11=CARTESIAN_POINT('Ctrl Pts',(-2.81820100260438,20.3836711077483,10.3228537766386)); +#12=CARTESIAN_POINT('Ctrl Pts',(-2.91923318155533,20.0960030522361,10.6929268867829)); +#13=B_SPLINE_CURVE_WITH_KNOTS('',3,(#1,#2,#3,#4,#5,#6,#7,#8,#9,#10,#11,#12) +,.UNSPECIFIED.,.F.,.F.,(4,2,2,1,1,1,1,4),(0.00162506910839039,0.4223270995939, +0.437186866643407,0.53596295034332,0.634739034043234,0.733515117743147, +0.832291201443061,0.927367642384199),.UNSPECIFIED.); +"); + Assert.Equal(12, spline.ControlPointsList.Count); + Assert.Equal(8, spline.Knots.Count); + Assert.Equal(8, spline.KnotMultiplicities.Count); + Assert.Equal(3, spline.Degree); + } + + [Fact] + public void WriteEllipseTest() + { + var ellipse = new StepEllipse("", new StepAxis2Placement2D("", new StepCartesianPoint("", 1.0, 2.0, 3.0), new StepDirection("", 0.0, 0.0, 1.0)), 3.0, 4.0); + AssertFileContains(ellipse, @" +#1=CARTESIAN_POINT('',(1.0,2.0,3.0)); +#2=DIRECTION('',(0.0,0.0,1.0)); +#3=AXIS2_PLACEMENT_2D('',#1,#2); +#4=ELLIPSE('',#3,3.0,4.0); +"); + } + + [Fact] + public void ReadEdgeCurveTest() + { + var edgeCurve = (StepEdgeCurve)ReadTopLevelItem(@" +#1=CIRCLE('',AXIS2_PLACEMENT_2D('',CARTESIAN_POINT('',(0.0,0.0,0.0)),DIRECTION('',(0.0,0.0,1.0))),5.0); +#2=EDGE_CURVE('',VERTEX_POINT('',CARTESIAN_POINT('',(1.0,2.0,3.0))),VERTEX_POINT('',CARTESIAN_POINT('',(4.0,5.0,6.0))),#1,.T.); +"); + Assert.IsType(edgeCurve.EdgeGeometry); + Assert.True(edgeCurve.IsSameSense); + } + + [Fact] + public void WriteEdgeCurveTest() + { + var edgeCurve = new StepEdgeCurve( + "", + new StepVertexPoint("", new StepCartesianPoint("", 1.0, 2.0, 3.0)), + new StepVertexPoint("", new StepCartesianPoint("", 4.0, 5.0, 6.0)), + new StepCircle("", + new StepAxis2Placement2D("", new StepCartesianPoint("", 7.0, 8.0, 9.0), new StepDirection("", 0.0, 0.0, 1.0)), + 5.0), + true); + AssertFileContains(edgeCurve, @" +#1=CARTESIAN_POINT('',(1.0,2.0,3.0)); +#2=VERTEX_POINT('',#1); +#3=CARTESIAN_POINT('',(4.0,5.0,6.0)); +#4=VERTEX_POINT('',#3); +#5=CARTESIAN_POINT('',(7.0,8.0,9.0)); +#6=DIRECTION('',(0.0,0.0,1.0)); +#7=AXIS2_PLACEMENT_2D('',#5,#6); +#8=CIRCLE('',#7,5.0); +#9=EDGE_CURVE('',#2,#4,#8,.T.); +"); + } + + [Fact] + public void ReadPlaneTest() + { + var plane = (StepPlane)ReadTopLevelItem(@" +#1=CARTESIAN_POINT('',(0.0,0.0,0.0)); +#2=DIRECTION('',(0.0,0.0,1.0)); +#3=DIRECTION('',(1.0,0.0,0.0)); +#4=AXIS2_PLACEMENT_3D('',#1,#2,#3); +#5=PLANE('',#4); +"); + } + + [Fact] + public void WritePlaneTest() + { + var plane = new StepPlane( + "", + new StepAxis2Placement3D("", new StepCartesianPoint("", 1.0, 2.0, 3.0), new StepDirection("", 0.0, 0.0, 1.0), new StepDirection("", 1.0, 0.0, 0.0))); + AssertFileContains(plane, @" +#1=CARTESIAN_POINT('',(1.0,2.0,3.0)); +#2=DIRECTION('',(0.0,0.0,1.0)); +#3=DIRECTION('',(1.0,0.0,0.0)); +#4=AXIS2_PLACEMENT_3D('',#1,#2,#3); +#5=PLANE('',#4); +"); + } + + [Fact] + public void ReadOrientedEdgeTest() + { + var orientedEdge = (StepOrientedEdge)ReadTopLevelItem(@" +#1=CIRCLE('',AXIS2_PLACEMENT_2D('',CARTESIAN_POINT('',(0.0,0.0,0.0)),DIRECTION('',(0.0,0.0,1.0))),5.0); +#2=EDGE_CURVE('',VERTEX_POINT('',CARTESIAN_POINT('',(1.0,2.0,3.0))),VERTEX_POINT('',CARTESIAN_POINT('',(4.0,5.0,6.0))),#1,.T.); +#3=ORIENTED_EDGE('',*,*,#2,.T.); +"); + Assert.True(orientedEdge.Orientation); + } + + [Fact] + public void WriteOrientedEdgeTest() + { + var orientedEdge = new StepOrientedEdge( + "", + null, + null, + new StepEdgeCurve( + "", + new StepVertexPoint("", new StepCartesianPoint("", 1.0, 2.0, 3.0)), + new StepVertexPoint("", new StepCartesianPoint("", 4.0, 5.0, 6.0)), + new StepCircle("", + new StepAxis2Placement2D("", new StepCartesianPoint("", 7.0, 8.0, 9.0), new StepDirection("", 0.0, 0.0, 1.0)), + 5.0), + true), + true); + AssertFileContains(orientedEdge, @" +#1=CARTESIAN_POINT('',(1.0,2.0,3.0)); +#2=VERTEX_POINT('',#1); +#3=CARTESIAN_POINT('',(4.0,5.0,6.0)); +#4=VERTEX_POINT('',#3); +#5=CARTESIAN_POINT('',(7.0,8.0,9.0)); +#6=DIRECTION('',(0.0,0.0,1.0)); +#7=AXIS2_PLACEMENT_2D('',#5,#6); +#8=CIRCLE('',#7,5.0); +#9=EDGE_CURVE('',#2,#4,#8,.T.); +#10=ORIENTED_EDGE('',*,*,#9,.T.); +"); + } + + [Fact] + public void ReadEdgeLoopTest() + { + var edgeLoop = (StepEdgeLoop)ReadTopLevelItem(@" +#1=CARTESIAN_POINT('',(1.0,2.0,3.0)); +#2=DIRECTION('',(0.58,0.58,0.58)); +#3=VECTOR('',#2,5.2); +#4=LINE('',#1,#3); +#5=EDGE_CURVE('',*,*,#4,.T.); +#6=ORIENTED_EDGE('',*,*,#5,.T.); +#7=CARTESIAN_POINT('',(7.0,8.0,9.0)); +#8=VECTOR('',#2,5.2); +#9=LINE('',#7,#8); +#10=EDGE_CURVE('',*,*,#9,.F.); +#11=EDGE_LOOP('',(#6,#12)); +/* ensure that forward references are resolved when binding */ +#12=ORIENTED_EDGE('',*,*,#10,.F.); +"); + Assert.Equal(2, edgeLoop.EdgeList.Count); + Assert.NotNull(edgeLoop.EdgeList[0]); + Assert.NotNull(edgeLoop.EdgeList[1]); + } + + [Fact] + public void ReadAdvancedFaceTest() + { + var file = ReadFile(@" +#1=FACE_OUTER_BOUND('',#2,.T.); +#2=EDGE_LOOP('',(#12,#13,#14,#15)); +#3=LINE('',#31,#4); +#4=VECTOR('',#24,2.5); +#5=CIRCLE('',#18,2.5); +#6=CIRCLE('',#19,2.5); +#7=VERTEX_POINT('',#28); +#8=VERTEX_POINT('',#30); +#9=EDGE_CURVE('',#7,#7,#5,.T.); +#10=EDGE_CURVE('',#7,#8,#3,.T.); +#11=EDGE_CURVE('',#8,#8,#6,.T.); +#12=ORIENTED_EDGE('',*,*,#9,.F.); +#13=ORIENTED_EDGE('',*,*,#10,.T.); +#14=ORIENTED_EDGE('',*,*,#11,.F.); +#15=ORIENTED_EDGE('',*,*,#10,.F.); +#16=CYLINDRICAL_SURFACE('',#17,2.5); +#17=AXIS2_PLACEMENT_3D('',#27,#20,#21); +#18=AXIS2_PLACEMENT_3D('',#29,#22,#23); +#19=AXIS2_PLACEMENT_3D('',#32,#25,#26); +#20=DIRECTION('center_axis',(0.,0.,-1.)); +#21=DIRECTION('ref_axis',(-1.,0.,0.)); +#22=DIRECTION('center_axis',(0.,0.,-1.)); +#23=DIRECTION('ref_axis',(-1.,0.,0.)); +#24=DIRECTION('',(0.,0.,-1.)); +#25=DIRECTION('center_axis',(0.,0.,1.)); +#26=DIRECTION('ref_axis',(-1.,0.,0.)); +#27=CARTESIAN_POINT('Origin',(0.,0.,5.)); +#28=CARTESIAN_POINT('',(2.5,3.06161699786838E-16,5.)); +#29=CARTESIAN_POINT('Origin',(0.,0.,5.)); +#30=CARTESIAN_POINT('',(2.5,3.06161699786838E-16,0.)); +#31=CARTESIAN_POINT('',(2.5,-3.06161699786838E-16,5.)); +#32=CARTESIAN_POINT('Origin',(0.,0.,0.)); +#33=ADVANCED_FACE('',(#1),#16,.F.); +"); + var face = file.GetTopLevelItems().OfType().FirstOrDefault(); + Assert.NotNull(face); + Assert.NotNull(face.FaceGeometry); + Assert.Single(face.Bounds); + } + + [Fact] + public void WriteEdgeLoopTest() + { + var edgeLoop = new StepEdgeLoop( + "", + new StepOrientedEdge("", null, null, new StepEdgeCurve("", null, null, StepLine.FromPoints(1.0, 2.0, 3.0, 4.0, 5.0, 6.0), true), true), + new StepOrientedEdge("", null, null, new StepEdgeCurve("", null, null, StepLine.FromPoints(7.0, 8.0, 9.0, 10.0, 11.0, 12.0), false), false)); + AssertFileContains(edgeLoop, @" +#1=CARTESIAN_POINT('',(1.0,2.0,3.0)); +#2=DIRECTION('',(0.58,0.58,0.58)); +#3=VECTOR('',#2,5.2); +#4=LINE('',#1,#3); +#5=EDGE_CURVE('',*,*,#4,.T.); +#6=ORIENTED_EDGE('',*,*,#5,.T.); +#7=CARTESIAN_POINT('',(7.0,8.0,9.0)); +#8=VECTOR('',#2,5.2); +#9=LINE('',#7,#8); +#10=EDGE_CURVE('',*,*,#9,.F.); +#11=ORIENTED_EDGE('',*,*,#10,.F.); +#12=EDGE_LOOP('',(#6,#11)); +"); + } + + [Fact] + public void ReadFaceBoundTest() + { + var faceBound = (StepFaceBound)ReadTopLevelItem(@" +#1=CARTESIAN_POINT('',(0.0,0.0,0.0)); +#2=DIRECTION('',(1.0,0.0,0.0)); +#3=VECTOR('',#2,1.0); +#4=LINE('',#1,#3); +#5=EDGE_CURVE('',*,*,#4,.T.); +#6=ORIENTED_EDGE('',*,*,#5,.T.); +#7=EDGE_LOOP('',(#6)); +#8=FACE_BOUND('',#7,.T.); +"); + Assert.True(faceBound.Orientation); + } + + [Fact] + public void WriteFaceBoundTest() + { + var faceBound = new StepFaceBound( + "", + new StepEdgeLoop( + "", + new StepOrientedEdge( + "", + null, + null, + new StepEdgeCurve( + "", + null, + null, + StepLine.FromPoints(0.0, 0.0, 0.0, 1.0, 0.0, 0.0), + true), + true)), + true); + AssertFileContains(faceBound, @" +#1=CARTESIAN_POINT('',(0.0,0.0,0.0)); +#2=DIRECTION('',(1.0,0.0,0.0)); +#3=VECTOR('',#2,1.0); +#4=LINE('',#1,#3); +#5=EDGE_CURVE('',*,*,#4,.T.); +#6=ORIENTED_EDGE('',*,*,#5,.T.); +#7=EDGE_LOOP('',(#6)); +#8=FACE_BOUND('',#7,.T.); +"); + } + + [Fact] + public void ReadFaceOuterBoundTest() + { + var faceOuterBound = (StepFaceOuterBound)ReadTopLevelItem(@" +#1=CARTESIAN_POINT('',(0.0,0.0,0.0)); +#2=DIRECTION('',(1.0,0.0,0.0)); +#3=VECTOR('',#2,1.0); +#4=LINE('',#1,#3); +#5=EDGE_CURVE('',*,*,#4,.T.); +#6=ORIENTED_EDGE('',*,*,#5,.T.); +#7=EDGE_LOOP('',(#6)); +#8=FACE_OUTER_BOUND('',#7,.T.); +"); + Assert.True(faceOuterBound.Orientation); + } + + [Fact] + public void WriteFaceOuterBoundTest() + { + var faceOuterBound = new StepFaceOuterBound( + "", + new StepEdgeLoop( + "", + new StepOrientedEdge( + "", + null, + null, + new StepEdgeCurve( + "", + null, + null, + StepLine.FromPoints(0.0, 0.0, 0.0, 1.0, 0.0, 0.0), + true), + true)), + true); + AssertFileContains(faceOuterBound, @" +#1=CARTESIAN_POINT('',(0.0,0.0,0.0)); +#2=DIRECTION('',(1.0,0.0,0.0)); +#3=VECTOR('',#2,1.0); +#4=LINE('',#1,#3); +#5=EDGE_CURVE('',*,*,#4,.T.); +#6=ORIENTED_EDGE('',*,*,#5,.T.); +#7=EDGE_LOOP('',(#6)); +#8=FACE_OUTER_BOUND('',#7,.T.); +"); + } + + [Fact] + public void ReadCylindricalSurfaceTest() + { + var surface = (StepCylindricalSurface)ReadTopLevelItem(@" +#1=CARTESIAN_POINT('',(1.0,2.0,3.0)); +#2=DIRECTION('',(0.0,0.0,1.0)); +#3=DIRECTION('',(1.0,0.0,0.0)); +#4=AXIS2_PLACEMENT_3D('',#1,#2,#3); +#5=CYLINDRICAL_SURFACE('',#4,12.0); +"); + Assert.Equal(12.0, surface.Radius); + } + + [Fact] + public void WriteCylindricalSurfaceTest() + { + var surface = new StepCylindricalSurface( + "", + new StepAxis2Placement3D( + "", + new StepCartesianPoint("", 1.0, 2.0, 3.0), + new StepDirection("", 0.0, 0.0, 1.0), + new StepDirection("", 1.0, 0.0, 0.0)), + 12.0); + AssertFileContains(surface, @" +#1=CARTESIAN_POINT('',(1.0,2.0,3.0)); +#2=DIRECTION('',(0.0,0.0,1.0)); +#3=DIRECTION('',(1.0,0.0,0.0)); +#4=AXIS2_PLACEMENT_3D('',#1,#2,#3); +#5=CYLINDRICAL_SURFACE('',#4,12.0); +"); + } + + [Fact] + public void WriteBSplineWithKnotsTest() + { + var spline = new StepBSplineCurveWithKnots( + "", + new StepCartesianPoint("", 0.0, 0.0, 0.0), + new StepCartesianPoint("", 1.0, 0.0, 0.0), + new StepCartesianPoint("", 1.0, 2.0, 0.0)); + spline.KnotMultiplicities.Add(1); + spline.Knots.Add(2.0); + + AssertFileContains(spline, @" +#1=CARTESIAN_POINT('',(0.0,0.0,0.0)); +#2=CARTESIAN_POINT('',(1.0,0.0,0.0)); +#3=CARTESIAN_POINT('',(1.0,2.0,0.0)); +#4=B_SPLINE_CURVE_WITH_KNOTS('',0,(#1,#2,#3),.UNSPECIFIED.,.F.,.F.,(1),(2.0), +.UNSPECIFIED.); +"); + } + } +} diff --git a/src/IxMilia.Step.Test/StepTestBase.cs b/src/IxMilia.Step.Test/StepTestBase.cs new file mode 100644 index 0000000..5b24d1f --- /dev/null +++ b/src/IxMilia.Step.Test/StepTestBase.cs @@ -0,0 +1,30 @@ +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Linq; +using Xunit; + +namespace IxMilia.Step.Test +{ + public abstract class StepTestBase + { + protected static string NormalizeLineEndings(string str) + { + var lines = str.Split('\n').Select(l => l.TrimEnd('\r')); + return string.Join("\r\n", lines); + } + + protected void AssertFileIs(StepFile file, string expected, bool inlineReferences = false) + { + var actual = file.GetContentsAsString(inlineReferences); + var expectedNormalizedLines = NormalizeLineEndings(expected); + Assert.Equal(expectedNormalizedLines, actual); + } + + protected void AssertFileContains(StepFile file, string expected, bool inlineReferences = false) + { + var actual = file.GetContentsAsString(inlineReferences); + var expectedNormalizedLines = NormalizeLineEndings(expected); + Assert.Contains(expectedNormalizedLines, actual); + } + } +} diff --git a/src/IxMilia.Step.Test/StepTokenTests.cs b/src/IxMilia.Step.Test/StepTokenTests.cs new file mode 100644 index 0000000..15a8de7 --- /dev/null +++ b/src/IxMilia.Step.Test/StepTokenTests.cs @@ -0,0 +1,193 @@ +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Text; +using IxMilia.Step.Tokens; +using Xunit; + +namespace IxMilia.Step.Test +{ + public class StepTokenTests : StepTestBase + { + private StepToken[] GetTokens(string text) + { + using (var stream = new MemoryStream()) + using (var writer = new StreamWriter(stream)) + { + writer.Write(text); + writer.Flush(); + stream.Seek(0, SeekOrigin.Begin); + var tokenizer = new StepTokenizer(stream); + return tokenizer.GetTokens().ToArray(); + } + } + + delegate bool TokenVerifier(StepToken token); + + private TokenVerifier WithKind(StepTokenKind kind) + { + return token => token.Kind == kind; + } + + private TokenVerifier Semicolon() + { + return WithKind(StepTokenKind.Semicolon); + } + + private TokenVerifier Keyword(string keyword) + { + return token => WithKind(StepTokenKind.Keyword)(token) && ((StepKeywordToken)token).Value == keyword; + } + + private TokenVerifier Enumeration(string enumName) + { + return token => WithKind(StepTokenKind.Enumeration)(token) && ((StepEnumerationToken)token).Value == enumName; + } + + private TokenVerifier Real(double value) + { + return token => WithKind(StepTokenKind.Real)(token) && ((StepRealToken)token).Value == value; + } + + private TokenVerifier Integer(int value) + { + return token => WithKind(StepTokenKind.Integer)(token) && ((StepIntegerToken)token).Value == value; + } + + private void VerifyTokens(string text, params TokenVerifier[] expected) + { + var actual = GetTokens(text); + var upper = Math.Min(actual.Length, expected.Length); + for (int i = 0; i < upper; i++) + { + Assert.True(expected[i](actual[i])); + } + } + + [Fact] + public void SpecialTokenTest() + { + VerifyTokens("ISO-10303-21;", + Keyword("ISO-10303-21"), Semicolon()); + } + + [Fact] + public void EmptyFileTest() + { + VerifyTokens(@" +ISO-10303-21; +HEADER; +ENDSEC; +DATA; +ENDSEC; +END-ISO-10303-21;", + Keyword("ISO-10303-21"), Semicolon(), + Keyword("HEADER"), Semicolon(), + Keyword("ENDSEC"), Semicolon(), + Keyword("DATA"), Semicolon(), + Keyword("ENDSEC"), Semicolon(), + Keyword("END-ISO-10303-21"), Semicolon()); + } + + [Fact] + public void TokensWithCommentsTest1() + { + VerifyTokens(@" +HEADER; +/* comment DATA; (comment's end is on the same line) */ +ENDSEC;", + Keyword("HEADER"), Semicolon(), + Keyword("ENDSEC"), Semicolon()); + } + + [Fact] + public void TokensWithCommentsTest2() + { + VerifyTokens(@" +HEADER; +/* comment (comment's end is on another line) +DATA; */ +ENDSEC;", + Keyword("HEADER"), Semicolon(), + Keyword("ENDSEC"), Semicolon()); + } + + [Fact] + public void TokensWithCommentsTest3() + { + VerifyTokens(@" +HEADER; + /* comment + (comment's end is on another line and farther back) +DATA; */ +ENDSEC;", + Keyword("HEADER"), Semicolon(), + Keyword("ENDSEC"), Semicolon()); + } + + [Fact] + public void TokensWithEmptylines() + { + VerifyTokens(@" + +HEADER; + +ENDSEC; + +", + Keyword("HEADER"), Semicolon(), + Keyword("ENDSEC"), Semicolon()); + } + + [Fact] + public void ParseEnumTokensTest() + { + VerifyTokens(".SOME_ENUM_VALUE.", Enumeration("SOME_ENUM_VALUE")); + } + + [Fact] + public void ParseInvarianCultureTest() + { + var existingCulture = CultureInfo.CurrentCulture; + try + { + CultureInfo.CurrentCulture = new CultureInfo("de-DE"); + VerifyTokens("1.8", Real(1.8)); + VerifyTokens("54", Integer(54)); + } + finally + { + CultureInfo.CurrentCulture = existingCulture; + } + } + + [Fact] + public void WriteTokensPastLineLengthTest() + { + var tokens = new List(); + var maxItems = 22; + for (int i = 0; i < maxItems; i++) + { + tokens.Add(new StepRealToken(0.0, -1, -1)); + if (i < maxItems - 1) + { + tokens.Add(StepCommaToken.Instance); + } + } + + // should wrap at 80 characters + var writer = new StepWriter(null, false); + var sb = new StringBuilder(); + writer.WriteTokens(tokens, sb); + var expected = NormalizeLineEndings(@" +0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0, +0.0,0.0 +".Trim()); + Assert.Equal(expected, sb.ToString()); + } + } +} diff --git a/src/IxMilia.Step.sln b/src/IxMilia.Step.sln new file mode 100644 index 0000000..aa159f3 --- /dev/null +++ b/src/IxMilia.Step.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.24720.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IxMilia.Step", "IxMilia.Step\IxMilia.Step.csproj", "{7BEB4FB6-8A3E-4690-B06C-357130AB4226}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IxMilia.Step.Test", "IxMilia.Step.Test\IxMilia.Step.Test.csproj", "{078EDA8D-F0BB-4D60-A7BD-1782A9CF713C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7BEB4FB6-8A3E-4690-B06C-357130AB4226}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7BEB4FB6-8A3E-4690-B06C-357130AB4226}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7BEB4FB6-8A3E-4690-B06C-357130AB4226}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7BEB4FB6-8A3E-4690-B06C-357130AB4226}.Release|Any CPU.Build.0 = Release|Any CPU + {078EDA8D-F0BB-4D60-A7BD-1782A9CF713C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {078EDA8D-F0BB-4D60-A7BD-1782A9CF713C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {078EDA8D-F0BB-4D60-A7BD-1782A9CF713C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {078EDA8D-F0BB-4D60-A7BD-1782A9CF713C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Items/StepAdvancedFace.cs b/src/IxMilia.Step/Items/StepAdvancedFace.cs similarity index 66% rename from Items/StepAdvancedFace.cs rename to src/IxMilia.Step/Items/StepAdvancedFace.cs index cf5f25c..e8d69e9 100644 --- a/Items/StepAdvancedFace.cs +++ b/src/IxMilia.Step/Items/StepAdvancedFace.cs @@ -1,8 +1,9 @@ -using System.Linq; -using System.Xml; -using StepParser.Syntax; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Items +using System.Linq; +using IxMilia.Step.Syntax; + +namespace IxMilia.Step.Items { public class StepAdvancedFace : StepFaceSurface { @@ -18,11 +19,10 @@ private StepAdvancedFace() public override StepItemType ItemType => StepItemType.AdvancedFace; - internal static StepAdvancedFace CreateFromSyntaxList(StepBinder binder, StepSyntaxList syntaxList, int id) + internal static StepAdvancedFace CreateFromSyntaxList(StepBinder binder, StepSyntaxList syntaxList) { var face = new StepAdvancedFace(); syntaxList.AssertListCount(4); - face.Id = id; face.Name = syntaxList.Values[0].GetStringValue(); var boundsList = syntaxList.Values[1].GetValueList(); @@ -38,17 +38,5 @@ internal static StepAdvancedFace CreateFromSyntaxList(StepBinder binder, StepSyn return face; } - - internal override void WriteXML(XmlWriter writer) - { - writer.WriteStartElement(ItemType.GetItemTypeElementString()); - writer.WriteAttributeString("id", '#' + Id.ToString()); - for (int idx = 0; idx < Bounds.Count; idx++) - { - Bounds[idx].WriteXML(writer); - } - base.WriteXML(writer); - writer.WriteEndElement(); - } } } diff --git a/Items/StepAxis2Placement.cs b/src/IxMilia.Step/Items/StepAxis2Placement.cs similarity index 68% rename from Items/StepAxis2Placement.cs rename to src/IxMilia.Step/Items/StepAxis2Placement.cs index 2604e4e..957a55b 100644 --- a/Items/StepAxis2Placement.cs +++ b/src/IxMilia.Step/Items/StepAxis2Placement.cs @@ -1,7 +1,8 @@ -using System; -using System.Xml; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Items +using System; + +namespace IxMilia.Step.Items { public abstract class StepAxis2Placement : StepPlacement { @@ -40,16 +41,5 @@ protected StepAxis2Placement(string name) : base(name) { } - - internal override void WriteXML(XmlWriter writer) - { - writer.WriteStartElement("Location"); - _location.WriteXML(writer); - writer.WriteEndElement(); - - writer.WriteStartElement("RefDirection"); - _refDirection.WriteXML(writer); - writer.WriteEndElement(); - } } } diff --git a/Items/StepAxis2Placement2D.cs b/src/IxMilia.Step/Items/StepAxis2Placement2D.cs similarity index 82% rename from Items/StepAxis2Placement2D.cs rename to src/IxMilia.Step/Items/StepAxis2Placement2D.cs index f171198..65075f4 100644 --- a/Items/StepAxis2Placement2D.cs +++ b/src/IxMilia.Step/Items/StepAxis2Placement2D.cs @@ -1,8 +1,9 @@ -using System.Collections.Generic; -using System.Xml; -using StepParser.Syntax; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Items +using System.Collections.Generic; +using IxMilia.Step.Syntax; + +namespace IxMilia.Step.Items { public class StepAxis2Placement2D : StepAxis2Placement { @@ -46,12 +47,5 @@ internal static StepAxis2Placement2D CreateFromSyntaxList(StepBinder binder, Ste binder.BindValue(syntaxList.Values[2], v => axis.RefDirection = v.AsType()); return axis; } - - internal override void WriteXML(XmlWriter writer) - { - writer.WriteStartElement(ItemType.GetItemTypeElementString()); - base.WriteXML(writer); - writer.WriteEndElement(); - } } } diff --git a/Items/StepAxis2Placement3D.cs b/src/IxMilia.Step/Items/StepAxis2Placement3D.cs similarity index 84% rename from Items/StepAxis2Placement3D.cs rename to src/IxMilia.Step/Items/StepAxis2Placement3D.cs index 67db551..f516f98 100644 --- a/Items/StepAxis2Placement3D.cs +++ b/src/IxMilia.Step/Items/StepAxis2Placement3D.cs @@ -2,10 +2,9 @@ using System; using System.Collections.Generic; -using System.Xml; -using StepParser.Syntax; +using IxMilia.Step.Syntax; -namespace StepParser.Items +namespace IxMilia.Step.Items { public class StepAxis2Placement3D : StepAxis2Placement { @@ -69,17 +68,5 @@ internal static StepAxis2Placement3D CreateFromSyntaxList(StepBinder binder, Ste binder.BindValue(syntaxList.Values[3], v => axis.RefDirection = v.AsType()); return axis; } - - internal override void WriteXML(XmlWriter writer) - { - writer.WriteStartElement(ItemType.GetItemTypeElementString()); - - base.WriteXML(writer); - writer.WriteStartElement("Axis"); - Axis.WriteXML(writer); - writer.WriteEndElement(); - - writer.WriteEndElement(); - } } } diff --git a/Items/StepBSplineCurve.cs b/src/IxMilia.Step/Items/StepBSplineCurve.cs similarity index 86% rename from Items/StepBSplineCurve.cs rename to src/IxMilia.Step/Items/StepBSplineCurve.cs index 826c3db..02683b5 100644 --- a/Items/StepBSplineCurve.cs +++ b/src/IxMilia.Step/Items/StepBSplineCurve.cs @@ -1,10 +1,11 @@ -using System; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; using System.Collections.Generic; using System.Linq; -using System.Xml; -using StepParser.Syntax; +using IxMilia.Step.Syntax; -namespace StepParser.Items +namespace IxMilia.Step.Items { public enum StepBSplineCurveForm { @@ -103,21 +104,5 @@ protected static string GetCurveFormString(StepBSplineCurveForm form) throw new NotImplementedException(); } - - internal override void WriteXML(XmlWriter writer) - { - writer.WriteStartElement("Type"); - writer.WriteString(ItemType.GetItemTypeElementString()); - writer.WriteEndElement(); - - writer.WriteStartElement("Degree"); - writer.WriteString(Degree.ToString()); - writer.WriteEndElement(); - - writer.WriteStartElement("ControlPointsList"); - writer.WriteEndElement(); - - //_vector.WriteXML(writer); - } } } diff --git a/Items/StepBSplineCurveWithKnots.cs b/src/IxMilia.Step/Items/StepBSplineCurveWithKnots.cs similarity index 95% rename from Items/StepBSplineCurveWithKnots.cs rename to src/IxMilia.Step/Items/StepBSplineCurveWithKnots.cs index 4f8542b..d94559e 100644 --- a/Items/StepBSplineCurveWithKnots.cs +++ b/src/IxMilia.Step/Items/StepBSplineCurveWithKnots.cs @@ -1,9 +1,11 @@ -using System; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; using System.Collections.Generic; using System.Linq; -using StepParser.Syntax; +using IxMilia.Step.Syntax; -namespace StepParser.Items +namespace IxMilia.Step.Items { public enum StepKnotType { diff --git a/src/IxMilia.Step/Items/StepBoundedCurve.cs b/src/IxMilia.Step/Items/StepBoundedCurve.cs new file mode 100644 index 0000000..6a67741 --- /dev/null +++ b/src/IxMilia.Step/Items/StepBoundedCurve.cs @@ -0,0 +1,12 @@ +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace IxMilia.Step.Items +{ + public abstract class StepBoundedCurve : StepCurve + { + protected StepBoundedCurve(string name) + : base(name) + { + } + } +} diff --git a/Items/StepCartesianPoint.cs b/src/IxMilia.Step/Items/StepCartesianPoint.cs similarity index 66% rename from Items/StepCartesianPoint.cs rename to src/IxMilia.Step/Items/StepCartesianPoint.cs index 4462331..27af0ce 100644 --- a/Items/StepCartesianPoint.cs +++ b/src/IxMilia.Step/Items/StepCartesianPoint.cs @@ -1,7 +1,8 @@ -using StepParser.Syntax; -using System.Xml; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Items +using IxMilia.Step.Syntax; + +namespace IxMilia.Step.Items { public class StepCartesianPoint : StepTriple { @@ -21,12 +22,5 @@ internal static StepCartesianPoint CreateFromSyntaxList(StepSyntaxList syntaxLis { return (StepCartesianPoint)AssignTo(new StepCartesianPoint(), syntaxList); } - - internal override void WriteXML(XmlWriter writer) - { - writer.WriteStartElement(ItemType.GetItemTypeElementString()); - base.WriteXML(writer); - writer.WriteEndElement(); - } } } diff --git a/Items/StepCircle.cs b/src/IxMilia.Step/Items/StepCircle.cs similarity index 75% rename from Items/StepCircle.cs rename to src/IxMilia.Step/Items/StepCircle.cs index aaebebf..e951f43 100644 --- a/Items/StepCircle.cs +++ b/src/IxMilia.Step/Items/StepCircle.cs @@ -1,9 +1,10 @@ -using System; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; using System.Collections.Generic; -using System.Xml; -using StepParser.Syntax; +using IxMilia.Step.Syntax; -namespace StepParser.Items +namespace IxMilia.Step.Items { public class StepCircle : StepConic { @@ -64,20 +65,5 @@ internal static StepCircle CreateFromSyntaxList(StepBinder binder, StepSyntaxLis circle.Radius = syntaxList.Values[2].GetRealVavlue(); return circle; } - - internal override void WriteXML(XmlWriter writer) - { - writer.WriteStartElement("Type"); - writer.WriteString(ItemType.GetItemTypeElementString()); - writer.WriteEndElement(); - - writer.WriteStartElement("Position"); - _position.WriteXML(writer); - writer.WriteEndElement(); - - writer.WriteStartElement("Radius"); - writer.WriteString(Radius.ToString()); - writer.WriteEndElement(); - } } } diff --git a/src/IxMilia.Step/Items/StepConic.cs b/src/IxMilia.Step/Items/StepConic.cs new file mode 100644 index 0000000..908cc35 --- /dev/null +++ b/src/IxMilia.Step/Items/StepConic.cs @@ -0,0 +1,12 @@ +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace IxMilia.Step.Items +{ + public abstract class StepConic : StepCurve + { + protected StepConic(string name) + : base(name) + { + } + } +} diff --git a/src/IxMilia.Step/Items/StepCurve.cs b/src/IxMilia.Step/Items/StepCurve.cs new file mode 100644 index 0000000..67e973a --- /dev/null +++ b/src/IxMilia.Step/Items/StepCurve.cs @@ -0,0 +1,12 @@ +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace IxMilia.Step.Items +{ + public abstract class StepCurve : StepGeometricRepresentationItem + { + protected StepCurve(string name) + : base(name) + { + } + } +} diff --git a/Items/StepCylindricalSurface.cs b/src/IxMilia.Step/Items/StepCylindricalSurface.cs similarity index 66% rename from Items/StepCylindricalSurface.cs rename to src/IxMilia.Step/Items/StepCylindricalSurface.cs index 8f6619e..9a6b3d1 100644 --- a/Items/StepCylindricalSurface.cs +++ b/src/IxMilia.Step/Items/StepCylindricalSurface.cs @@ -1,8 +1,9 @@ -using System.Collections.Generic; -using System.Xml; -using StepParser.Syntax; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Items +using System.Collections.Generic; +using IxMilia.Step.Syntax; + +namespace IxMilia.Step.Items { public class StepCylindricalSurface : StepElementarySurface { @@ -31,28 +32,14 @@ internal override IEnumerable GetParameters(StepWriter writer) yield return new StepRealSyntax(Radius); } - internal static StepRepresentationItem CreateFromSyntaxList(StepBinder binder, StepSyntaxList syntaxList, int id) + internal static StepRepresentationItem CreateFromSyntaxList(StepBinder binder, StepSyntaxList syntaxList) { syntaxList.AssertListCount(3); var surface = new StepCylindricalSurface(); - surface.Id = id; surface.Name = syntaxList.Values[0].GetStringValue(); binder.BindValue(syntaxList.Values[1], v => surface.Position = v.AsType()); surface.Radius = syntaxList.Values[2].GetRealVavlue(); return surface; } - - internal override void WriteXML(XmlWriter writer) - { - writer.WriteStartElement("Type"); - writer.WriteString(ItemType.GetItemTypeElementString()); - writer.WriteEndElement(); - - writer.WriteStartElement("Radius"); - writer.WriteString(Radius.ToString()); - writer.WriteEndElement(); - - base.WriteXML(writer); - } } } diff --git a/Items/StepDirection.cs b/src/IxMilia.Step/Items/StepDirection.cs similarity index 64% rename from Items/StepDirection.cs rename to src/IxMilia.Step/Items/StepDirection.cs index 3432839..a945ae0 100644 --- a/Items/StepDirection.cs +++ b/src/IxMilia.Step/Items/StepDirection.cs @@ -1,7 +1,8 @@ -using StepParser.Syntax; -using System.Xml; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Items +using IxMilia.Step.Syntax; + +namespace IxMilia.Step.Items { public class StepDirection : StepTriple { @@ -21,12 +22,5 @@ internal static StepDirection CreateFromSyntaxList(StepSyntaxList syntaxList) { return (StepDirection)AssignTo(new StepDirection(), syntaxList); } - - internal override void WriteXML(XmlWriter writer) - { - writer.WriteStartElement(ItemType.GetItemTypeElementString()); - base.WriteXML(writer); - writer.WriteEndElement(); - } } } diff --git a/Items/StepEdge.cs b/src/IxMilia.Step/Items/StepEdge.cs similarity index 70% rename from Items/StepEdge.cs rename to src/IxMilia.Step/Items/StepEdge.cs index f661d49..55b680c 100644 --- a/Items/StepEdge.cs +++ b/src/IxMilia.Step/Items/StepEdge.cs @@ -1,10 +1,9 @@ // Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; -using System.Xml; -using StepParser.Syntax; +using IxMilia.Step.Syntax; -namespace StepParser.Items +namespace IxMilia.Step.Items { public abstract class StepEdge : StepTopologicalRepresentationItem { @@ -12,12 +11,12 @@ public abstract class StepEdge : StepTopologicalRepresentationItem public StepVertex EdgeEnd { get; set; } protected StepEdge() - : base(string.Empty, 0) + : base(string.Empty) { } protected StepEdge(string name, StepVertex edgeStart, StepVertex edgeEnd) - : base(name, 0) + : base(name) { EdgeStart = edgeStart; EdgeEnd = edgeEnd; @@ -46,18 +45,5 @@ internal override IEnumerable GetParameters(StepWriter writer) yield return writer.GetItemSyntaxOrAuto(EdgeStart); yield return writer.GetItemSyntaxOrAuto(EdgeEnd); } - - internal override void WriteXML(XmlWriter writer) - { - // Start Point - writer.WriteStartElement("StartPoint"); - EdgeStart.WriteXML(writer); - writer.WriteEndElement(); - - // End Point - writer.WriteStartElement("EndPoint"); - EdgeStart.WriteXML(writer); - writer.WriteEndElement(); - } } } diff --git a/Items/StepEdgeCurve.cs b/src/IxMilia.Step/Items/StepEdgeCurve.cs similarity index 88% rename from Items/StepEdgeCurve.cs rename to src/IxMilia.Step/Items/StepEdgeCurve.cs index 147b82a..772ef0f 100644 --- a/Items/StepEdgeCurve.cs +++ b/src/IxMilia.Step/Items/StepEdgeCurve.cs @@ -2,10 +2,9 @@ using System; using System.Collections.Generic; -using System.Xml; -using StepParser.Syntax; +using IxMilia.Step.Syntax; -namespace StepParser.Items +namespace IxMilia.Step.Items { public class StepEdgeCurve : StepEdge { @@ -73,13 +72,5 @@ internal static StepEdgeCurve CreateFromSyntaxList(StepBinder binder, StepSyntax edgeCurve.IsSameSense = syntaxList.Values[4].GetBooleanValue(); return edgeCurve; } - - internal override void WriteXML(XmlWriter writer) - { - base.WriteXML(writer); - writer.WriteStartElement("CurveGeometry"); - _edgeGeometry.WriteXML(writer); - writer.WriteEndElement(); - } } } diff --git a/Items/StepEdgeLoop.cs b/src/IxMilia.Step/Items/StepEdgeLoop.cs similarity index 81% rename from Items/StepEdgeLoop.cs rename to src/IxMilia.Step/Items/StepEdgeLoop.cs index 6442abe..873a593 100644 --- a/Items/StepEdgeLoop.cs +++ b/src/IxMilia.Step/Items/StepEdgeLoop.cs @@ -2,10 +2,9 @@ using System.Collections.Generic; using System.Linq; -using System.Xml; -using StepParser.Syntax; +using IxMilia.Step.Syntax; -namespace StepParser.Items +namespace IxMilia.Step.Items { public class StepEdgeLoop : StepLoop { @@ -47,21 +46,11 @@ internal static StepEdgeLoop CreateFromSyntaxList(StepBinder binder, StepSyntaxL edgeLoop.Name = syntaxList.Values[0].GetStringValue(); for (int i = 0; i < edgeSyntaxList.Values.Count; i++) { - var j = i; + var j = i; // capture to avoid rebinding binder.BindValue(edgeSyntaxList.Values[j], v => edgeLoop.EdgeList[j] = v.AsType()); } return edgeLoop; } - - internal override void WriteXML(XmlWriter writer) - { - writer.WriteStartElement(ItemType.GetItemTypeElementString()); - for (int idx = 0; idx < EdgeList.Count; idx++) - { - EdgeList[idx].WriteXML(writer); - } - writer.WriteEndElement(); - } } } diff --git a/Items/StepElementarySurface.cs b/src/IxMilia.Step/Items/StepElementarySurface.cs similarity index 79% rename from Items/StepElementarySurface.cs rename to src/IxMilia.Step/Items/StepElementarySurface.cs index 2ad3605..d0c66b6 100644 --- a/Items/StepElementarySurface.cs +++ b/src/IxMilia.Step/Items/StepElementarySurface.cs @@ -1,9 +1,10 @@ -using System; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; using System.Collections.Generic; -using System.Xml; -using StepParser.Syntax; +using IxMilia.Step.Syntax; -namespace StepParser.Items +namespace IxMilia.Step.Items { public abstract class StepElementarySurface : StepSurface { @@ -48,12 +49,5 @@ internal override IEnumerable GetParameters(StepWriter writer) yield return writer.GetItemSyntax(Position); } - - internal override void WriteXML(XmlWriter writer) - { - writer.WriteStartElement("Position"); - _position.WriteXML(writer); - writer.WriteEndElement(); - } } } diff --git a/Items/StepEllipse.cs b/src/IxMilia.Step/Items/StepEllipse.cs similarity index 73% rename from Items/StepEllipse.cs rename to src/IxMilia.Step/Items/StepEllipse.cs index 1fe7e83..981a4ae 100644 --- a/Items/StepEllipse.cs +++ b/src/IxMilia.Step/Items/StepEllipse.cs @@ -1,9 +1,10 @@ -using System; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; using System.Collections.Generic; -using System.Xml; -using StepParser.Syntax; +using IxMilia.Step.Syntax; -namespace StepParser.Items +namespace IxMilia.Step.Items { public class StepEllipse : StepConic { @@ -68,25 +69,5 @@ internal static StepEllipse CreateFromSyntaxList(StepBinder binder, StepSyntaxLi ellipse.SemiAxis2 = syntaxList.Values[3].GetRealVavlue(); return ellipse; } - - internal override void WriteXML(XmlWriter writer) - { - writer.WriteStartElement("Type"); - writer.WriteString(ItemType.GetItemTypeElementString()); - writer.WriteEndElement(); - - writer.WriteStartElement("Position"); - _position.WriteXML(writer); - writer.WriteEndElement(); - - writer.WriteStartElement("MajorAxis"); - writer.WriteString(SemiAxis1.ToString()); - writer.WriteEndElement(); - - writer.WriteStartElement("MinorAxis"); - writer.WriteString(SemiAxis2.ToString()); - writer.WriteEndElement(); - - } } } diff --git a/Items/StepFace.cs b/src/IxMilia.Step/Items/StepFace.cs similarity index 67% rename from Items/StepFace.cs rename to src/IxMilia.Step/Items/StepFace.cs index d38966f..8d08354 100644 --- a/Items/StepFace.cs +++ b/src/IxMilia.Step/Items/StepFace.cs @@ -1,15 +1,17 @@ -using System.Collections.Generic; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; using System.Linq; -using StepParser.Syntax; +using IxMilia.Step.Syntax; -namespace StepParser.Items +namespace IxMilia.Step.Items { public abstract class StepFace : StepTopologicalRepresentationItem { public List Bounds { get; } = new List(); public StepFace(string name) - : base(name, 0) + : base(name) { } diff --git a/Items/StepFaceBound.cs b/src/IxMilia.Step/Items/StepFaceBound.cs similarity index 80% rename from Items/StepFaceBound.cs rename to src/IxMilia.Step/Items/StepFaceBound.cs index 047f5a3..3d4d34d 100644 --- a/Items/StepFaceBound.cs +++ b/src/IxMilia.Step/Items/StepFaceBound.cs @@ -1,10 +1,9 @@ // Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; -using System.Xml; -using StepParser.Syntax; +using IxMilia.Step.Syntax; -namespace StepParser.Items +namespace IxMilia.Step.Items { public class StepFaceBound : StepTopologicalRepresentationItem { @@ -14,12 +13,12 @@ public class StepFaceBound : StepTopologicalRepresentationItem public bool Orientation { get; set; } protected StepFaceBound() - : base(string.Empty, 0) + : base(string.Empty) { } public StepFaceBound(string name, StepLoop bound, bool orientation) - : base(name, 0) + : base(name) { Bound = bound; Orientation = orientation; @@ -50,13 +49,5 @@ internal static StepFaceBound CreateFromSyntaxList(StepBinder binder, StepSyntax faceBound.Orientation = syntaxList.Values[2].GetBooleanValue(); return faceBound; } - - internal override void WriteXML(XmlWriter writer) - { - Bound.WriteXML(writer); - writer.WriteStartElement("Orientation"); - writer.WriteString(Orientation ? "true" : "false"); - writer.WriteEndElement(); - } } } diff --git a/Items/StepFaceOuterBound.cs b/src/IxMilia.Step/Items/StepFaceOuterBound.cs similarity index 80% rename from Items/StepFaceOuterBound.cs rename to src/IxMilia.Step/Items/StepFaceOuterBound.cs index 45031df..fc54416 100644 --- a/Items/StepFaceOuterBound.cs +++ b/src/IxMilia.Step/Items/StepFaceOuterBound.cs @@ -1,6 +1,8 @@ -using StepParser.Syntax; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Items +using IxMilia.Step.Syntax; + +namespace IxMilia.Step.Items { public class StepFaceOuterBound : StepFaceBound { diff --git a/Items/StepFaceSurface.cs b/src/IxMilia.Step/Items/StepFaceSurface.cs similarity index 55% rename from Items/StepFaceSurface.cs rename to src/IxMilia.Step/Items/StepFaceSurface.cs index 285bdeb..73f9ae0 100644 --- a/Items/StepFaceSurface.cs +++ b/src/IxMilia.Step/Items/StepFaceSurface.cs @@ -1,8 +1,9 @@ -using System.Collections.Generic; -using System.Xml; -using StepParser.Syntax; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Items +using System.Collections.Generic; +using IxMilia.Step.Syntax; + +namespace IxMilia.Step.Items { public abstract class StepFaceSurface : StepFace { @@ -25,16 +26,5 @@ internal override IEnumerable GetParameters(StepWriter writer) yield return writer.GetItemSyntax(FaceGeometry); yield return StepWriter.GetBooleanSyntax(!SameSense); } - - internal override void WriteXML(XmlWriter writer) - { - if (FaceGeometry != null) - { - writer.WriteStartElement("Surface"); - writer.WriteAttributeString("id", '#' + FaceGeometry.Id.ToString()); - FaceGeometry.WriteXML(writer); - writer.WriteEndElement(); - } - } } } diff --git a/Items/StepGeometricRepresentationItem.cs b/src/IxMilia.Step/Items/StepGeometricRepresentationItem.cs similarity index 68% rename from Items/StepGeometricRepresentationItem.cs rename to src/IxMilia.Step/Items/StepGeometricRepresentationItem.cs index a7305a0..01dbced 100644 --- a/Items/StepGeometricRepresentationItem.cs +++ b/src/IxMilia.Step/Items/StepGeometricRepresentationItem.cs @@ -1,11 +1,11 @@ // Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Items +namespace IxMilia.Step.Items { public abstract class StepGeometricRepresentationItem : StepRepresentationItem { - protected StepGeometricRepresentationItem(string name, int id) - : base(name, id) + protected StepGeometricRepresentationItem(string name) + : base(name) { } } diff --git a/src/IxMilia.Step/Items/StepItemType.cs b/src/IxMilia.Step/Items/StepItemType.cs new file mode 100644 index 0000000..7e91e3e --- /dev/null +++ b/src/IxMilia.Step/Items/StepItemType.cs @@ -0,0 +1,95 @@ +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace IxMilia.Step.Items +{ + public enum StepItemType + { + AdvancedFace, + AxisPlacement2D, + AxisPlacement3D, + BSplineCurveWithKnots, + CartesianPoint, + Circle, + CylindricalSurface, + Direction, + EdgeCurve, + EdgeLoop, + Ellipse, + FaceBound, + FaceOuterBound, + Line, + OrientedEdge, + Plane, + Vector, + VertexPoint + } + + internal static class StepItemTypeExtensions + { + public const string AdvancedFaceText = "ADVANCED_FACE"; + public const string Axis2Placement2DText = "AXIS2_PLACEMENT_2D"; + public const string Axis2Placement3DText = "AXIS2_PLACEMENT_3D"; + public const string BSplineCurveWithKnotsText = "B_SPLINE_CURVE_WITH_KNOTS"; + public const string CartesianPointText = "CARTESIAN_POINT"; + public const string CircleText = "CIRCLE"; + public const string CylindricalSurfaceText = "CYLINDRICAL_SURFACE"; + public const string DirectionText = "DIRECTION"; + public const string EdgeCurveText = "EDGE_CURVE"; + public const string EdgeLoopText = "EDGE_LOOP"; + public const string EllipseText = "ELLIPSE"; + public const string FaceBoundText = "FACE_BOUND"; + public const string FaceOuterBoundText = "FACE_OUTER_BOUND"; + public const string LineText = "LINE"; + public const string OrientedEdgeText = "ORIENTED_EDGE"; + public const string PlaneText = "PLANE"; + public const string VectorText = "VECTOR"; + public const string VertexPointText = "VERTEX_POINT"; + + public static string GetItemTypeString(this StepItemType type) + { + switch (type) + { + case StepItemType.AdvancedFace: + return AdvancedFaceText; + case StepItemType.AxisPlacement2D: + return Axis2Placement2DText; + case StepItemType.AxisPlacement3D: + return Axis2Placement3DText; + case StepItemType.BSplineCurveWithKnots: + return BSplineCurveWithKnotsText; + case StepItemType.CartesianPoint: + return CartesianPointText; + case StepItemType.Circle: + return CircleText; + case StepItemType.CylindricalSurface: + return CylindricalSurfaceText; + case StepItemType.Direction: + return DirectionText; + case StepItemType.EdgeCurve: + return EdgeCurveText; + case StepItemType.EdgeLoop: + return EdgeLoopText; + case StepItemType.Ellipse: + return EllipseText; + case StepItemType.FaceBound: + return FaceBoundText; + case StepItemType.FaceOuterBound: + return FaceOuterBoundText; + case StepItemType.Line: + return LineText; + case StepItemType.OrientedEdge: + return OrientedEdgeText; + case StepItemType.Plane: + return PlaneText; + case StepItemType.Vector: + return VectorText; + case StepItemType.VertexPoint: + return VertexPointText; + default: + throw new InvalidOperationException("Unexpected item type " + type); + } + } + } +} diff --git a/Items/StepLine.cs b/src/IxMilia.Step/Items/StepLine.cs similarity index 86% rename from Items/StepLine.cs rename to src/IxMilia.Step/Items/StepLine.cs index f0627c3..b8371cb 100644 --- a/Items/StepLine.cs +++ b/src/IxMilia.Step/Items/StepLine.cs @@ -2,10 +2,9 @@ using System; using System.Collections.Generic; -using System.Xml; -using StepParser.Syntax; +using IxMilia.Step.Syntax; -namespace StepParser.Items +namespace IxMilia.Step.Items { public class StepLine : StepCurve { @@ -94,18 +93,5 @@ internal static StepLine CreateFromSyntaxList(StepBinder binder, StepSyntaxList binder.BindValue(syntaxList.Values[2], v => line.Vector = v.AsType()); return line; } - - internal override void WriteXML(XmlWriter writer) - { - writer.WriteStartElement("Type"); - writer.WriteString(ItemType.GetItemTypeElementString()); - writer.WriteEndElement(); - - writer.WriteStartElement("Point"); - _point.WriteXML(writer); - writer.WriteEndElement(); - - _vector.WriteXML(writer); - } } } diff --git a/src/IxMilia.Step/Items/StepLoop.cs b/src/IxMilia.Step/Items/StepLoop.cs new file mode 100644 index 0000000..13830d1 --- /dev/null +++ b/src/IxMilia.Step/Items/StepLoop.cs @@ -0,0 +1,12 @@ +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace IxMilia.Step.Items +{ + public abstract class StepLoop : StepTopologicalRepresentationItem + { + public StepLoop(string name) + : base(name) + { + } + } +} diff --git a/Items/StepOrientedEdge.cs b/src/IxMilia.Step/Items/StepOrientedEdge.cs similarity index 88% rename from Items/StepOrientedEdge.cs rename to src/IxMilia.Step/Items/StepOrientedEdge.cs index 650080e..4fb7178 100644 --- a/Items/StepOrientedEdge.cs +++ b/src/IxMilia.Step/Items/StepOrientedEdge.cs @@ -2,10 +2,9 @@ using System; using System.Collections.Generic; -using System.Xml; -using StepParser.Syntax; +using IxMilia.Step.Syntax; -namespace StepParser.Items +namespace IxMilia.Step.Items { public class StepOrientedEdge : StepEdge { @@ -72,12 +71,5 @@ internal static StepOrientedEdge CreateFromSyntaxList(StepBinder binder, StepSyn orientedEdge.Orientation = syntaxList.Values[4].GetBooleanValue(); return orientedEdge; } - - internal override void WriteXML(XmlWriter writer) - { - writer.WriteStartElement(_edgeElement.ItemType.GetItemTypeElementString()); - _edgeElement.WriteXML(writer); - writer.WriteEndElement(); - } } } diff --git a/src/IxMilia.Step/Items/StepPlacement.cs b/src/IxMilia.Step/Items/StepPlacement.cs new file mode 100644 index 0000000..4f8bc3b --- /dev/null +++ b/src/IxMilia.Step/Items/StepPlacement.cs @@ -0,0 +1,12 @@ +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace IxMilia.Step.Items +{ + public abstract class StepPlacement : StepGeometricRepresentationItem + { + protected StepPlacement(string name) + : base(name) + { + } + } +} diff --git a/Items/StepPlane.cs b/src/IxMilia.Step/Items/StepPlane.cs similarity index 68% rename from Items/StepPlane.cs rename to src/IxMilia.Step/Items/StepPlane.cs index 0b3cef9..aff7b0d 100644 --- a/Items/StepPlane.cs +++ b/src/IxMilia.Step/Items/StepPlane.cs @@ -1,7 +1,8 @@ -using StepParser.Syntax; -using System.Xml; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Items +using IxMilia.Step.Syntax; + +namespace IxMilia.Step.Items { public class StepPlane : StepElementarySurface { @@ -25,14 +26,5 @@ internal static StepPlane CreateFromSyntaxList(StepBinder binder, StepSyntaxList binder.BindValue(syntaxList.Values[1], v => plane.Position = v.AsType()); return plane; } - - internal override void WriteXML(XmlWriter writer) - { - writer.WriteStartElement("Type"); - writer.WriteString(ItemType.GetItemTypeElementString()); - writer.WriteEndElement(); - - base.WriteXML(writer); - } } } diff --git a/Items/StepPoint.cs b/src/IxMilia.Step/Items/StepPoint.cs similarity index 84% rename from Items/StepPoint.cs rename to src/IxMilia.Step/Items/StepPoint.cs index 6eeda9d..b6e2577 100644 --- a/Items/StepPoint.cs +++ b/src/IxMilia.Step/Items/StepPoint.cs @@ -1,11 +1,11 @@ // Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Items +namespace IxMilia.Step.Items { public abstract class StepPoint : StepGeometricRepresentationItem { protected StepPoint(string name) - : base(name, 0) + : base(name) { } } diff --git a/Items/StepRepresentationItem.cs b/src/IxMilia.Step/Items/StepRepresentationItem.cs similarity index 62% rename from Items/StepRepresentationItem.cs rename to src/IxMilia.Step/Items/StepRepresentationItem.cs index 0694dc2..9cd7f8e 100644 --- a/Items/StepRepresentationItem.cs +++ b/src/IxMilia.Step/Items/StepRepresentationItem.cs @@ -1,21 +1,19 @@ -using System.Collections.Generic; -using System.Xml; -using StepParser.Syntax; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Items +using System.Collections.Generic; +using IxMilia.Step.Syntax; + +namespace IxMilia.Step.Items { public abstract partial class StepRepresentationItem { public abstract StepItemType ItemType { get; } - public int Id { get; set; } - public string Name { get; set; } - protected StepRepresentationItem(string name, int id) + protected StepRepresentationItem(string name) { Name = name; - Id = id; } internal virtual IEnumerable GetReferencedItems() @@ -27,9 +25,5 @@ internal virtual IEnumerable GetParameters(StepWriter writer) { yield return new StepStringSyntax(Name); } - - internal virtual void WriteXML(XmlWriter writer) - { - } } } diff --git a/Items/StepRepresentationItem_FromTypedParameter.cs b/src/IxMilia.Step/Items/StepRepresentationItem_FromTypedParameter.cs similarity index 50% rename from Items/StepRepresentationItem_FromTypedParameter.cs rename to src/IxMilia.Step/Items/StepRepresentationItem_FromTypedParameter.cs index 3f453be..0b5c993 100644 --- a/Items/StepRepresentationItem_FromTypedParameter.cs +++ b/src/IxMilia.Step/Items/StepRepresentationItem_FromTypedParameter.cs @@ -1,14 +1,16 @@ -using System.Collections.Generic; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; using System.Diagnostics; -using StepParser.Syntax; +using IxMilia.Step.Syntax; -namespace StepParser.Items +namespace IxMilia.Step.Items { public abstract partial class StepRepresentationItem { internal static HashSet UnsupportedItemTypes { get; } = new HashSet(); - internal static StepRepresentationItem FromTypedParameter(StepBinder binder, StepItemSyntax itemSyntax, int id) + internal static StepRepresentationItem FromTypedParameter(StepBinder binder, StepItemSyntax itemSyntax) { StepRepresentationItem item = null; if (itemSyntax is StepSimpleItemSyntax) @@ -16,38 +18,8 @@ internal static StepRepresentationItem FromTypedParameter(StepBinder binder, Ste var simpleItem = (StepSimpleItemSyntax)itemSyntax; switch (simpleItem.Keyword) { - case StepItemTypeExtensions.ProductDefinitionFormationWithSpecifiedSourceText: - item = StepProductDefFormationWithSpecSource.CreateFromSyntaxList(binder, simpleItem.Parameters, id); - break; - case StepItemTypeExtensions.ProductText: - item = StepProduct.CreateFromSyntaxList(binder, simpleItem.Parameters, id); - break; - case StepItemTypeExtensions.ProductDefinitionText: - item = StepProductDefinition.CreateFromSyntaxList(binder, simpleItem.Parameters, id); - break; - case StepItemTypeExtensions.ShapeDefinitionRepresentationText: - item = StepShapeDefinitionRepresentation.CreateFromSyntaxList(binder, simpleItem.Parameters, id); - break; - case StepItemTypeExtensions.ProductDefinitionShapeText: - item = StepProductDefinitionShape.CreateFromSyntaxList(binder, simpleItem.Parameters, id); - break; - case StepItemTypeExtensions.ShapeRepresentationRelationshipText: - item = StepShapeRepresentationRelationShip.CreateFromSyntaxList(binder, simpleItem.Parameters, id); - break; - case StepItemTypeExtensions.ShapeRepresentationText: - item = StepShapeRepresentation.CreateFromSyntaxList(binder, simpleItem.Parameters, id); - break; - case StepItemTypeExtensions.AdvancedBrepShapeRepresentationText: - item = StepAdvancedBrepShapeRepresentation.CreateFromSyntaxList(binder, simpleItem.Parameters, id); - break; - case StepItemTypeExtensions.ManiFoldSolidBrepText: - item = StepManifoldSolidBrep.CreateFromSyntaxList(binder, simpleItem.Parameters, id); - break; - case StepItemTypeExtensions.ClosedShellText: - item = StepClosedShell.CreateFromSyntaxList(binder, simpleItem.Parameters, id); - break; case StepItemTypeExtensions.AdvancedFaceText: - item = StepAdvancedFace.CreateFromSyntaxList(binder, simpleItem.Parameters, id); + item = StepAdvancedFace.CreateFromSyntaxList(binder, simpleItem.Parameters); break; case StepItemTypeExtensions.Axis2Placement2DText: item = StepAxis2Placement2D.CreateFromSyntaxList(binder, simpleItem.Parameters); @@ -65,7 +37,7 @@ internal static StepRepresentationItem FromTypedParameter(StepBinder binder, Ste item = StepCircle.CreateFromSyntaxList(binder, simpleItem.Parameters); break; case StepItemTypeExtensions.CylindricalSurfaceText: - item = StepCylindricalSurface.CreateFromSyntaxList(binder, simpleItem.Parameters, id); + item = StepCylindricalSurface.CreateFromSyntaxList(binder, simpleItem.Parameters); break; case StepItemTypeExtensions.DirectionText: item = StepDirection.CreateFromSyntaxList(simpleItem.Parameters); @@ -100,33 +72,6 @@ internal static StepRepresentationItem FromTypedParameter(StepBinder binder, Ste case StepItemTypeExtensions.VertexPointText: item = StepVertexPoint.CreateFromSyntaxList(binder, simpleItem.Parameters); break; - case StepItemTypeExtensions.StyledItemText: - item = StepStyledItem.CreateFromSyntaxList(binder, simpleItem.Parameters, id); - break; - case StepItemTypeExtensions.PresentationStyleAssignmentText: - item = StepPresentationStyleAssignment.CreateFromSyntaxList(binder, simpleItem.Parameters, id); - break; - case StepItemTypeExtensions.SurfaceStyleUsageText: - item = StepSurfaceStyleUsage.CreateFromSyntaxList(binder, simpleItem.Parameters, id); - break; - case StepItemTypeExtensions.SurfaceSideStyleText: - item = StepSurfaceSideStyle.CreateFromSyntaxList(binder, simpleItem.Parameters, id); - break; - case StepItemTypeExtensions.SurfaceStyleFillAreaText: - item = StepSurfaceStyleFillArea.CreateFromSyntaxList(binder, simpleItem.Parameters, id); - break; - case StepItemTypeExtensions.FillAreaStyleText: - item = StepFillAreaStyle.CreateFromSyntaxList(binder, simpleItem.Parameters, id); - break; - case StepItemTypeExtensions.FillAreaStyleColourText: - item = StepFillAreaStyleColour.CreateFromSyntaxList(binder, simpleItem.Parameters, id); - break; - case StepItemTypeExtensions.ColourRGBText: - item = StepColourRGB.CreateFromSyntaxList(binder, simpleItem.Parameters, id); - break; - case StepItemTypeExtensions.NextAssemblyUsageOccurrenceText: - item = StepNextAssemblyUsageOccrrence.CreateFromSyntaxList(binder, simpleItem.Parameters, id); - break; default: if (UnsupportedItemTypes.Add(simpleItem.Keyword)) { diff --git a/Items/StepSurface.cs b/src/IxMilia.Step/Items/StepSurface.cs similarity index 84% rename from Items/StepSurface.cs rename to src/IxMilia.Step/Items/StepSurface.cs index ed6cf7d..60a849b 100644 --- a/Items/StepSurface.cs +++ b/src/IxMilia.Step/Items/StepSurface.cs @@ -1,11 +1,11 @@ // Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Items +namespace IxMilia.Step.Items { public abstract class StepSurface : StepGeometricRepresentationItem { public StepSurface(string name) - : base(name, 0) + : base(name) { } } diff --git a/Items/StepTopologicalRepresentationItem.cs b/src/IxMilia.Step/Items/StepTopologicalRepresentationItem.cs similarity index 68% rename from Items/StepTopologicalRepresentationItem.cs rename to src/IxMilia.Step/Items/StepTopologicalRepresentationItem.cs index 3f8864a..faebac3 100644 --- a/Items/StepTopologicalRepresentationItem.cs +++ b/src/IxMilia.Step/Items/StepTopologicalRepresentationItem.cs @@ -1,11 +1,11 @@ // Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Items +namespace IxMilia.Step.Items { public abstract class StepTopologicalRepresentationItem : StepRepresentationItem { - protected StepTopologicalRepresentationItem(string name, int id) - : base(name, id) + protected StepTopologicalRepresentationItem(string name) + : base(name) { } } diff --git a/Items/StepTriple.cs b/src/IxMilia.Step/Items/StepTriple.cs similarity index 83% rename from Items/StepTriple.cs rename to src/IxMilia.Step/Items/StepTriple.cs index ed48969..88a8cba 100644 --- a/Items/StepTriple.cs +++ b/src/IxMilia.Step/Items/StepTriple.cs @@ -1,10 +1,9 @@ // Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; -using System.Xml; -using StepParser.Syntax; +using IxMilia.Step.Syntax; -namespace StepParser.Items +namespace IxMilia.Step.Items { public abstract class StepTriple : StepPoint { @@ -92,18 +91,5 @@ public override int GetHashCode() { return !(left == right); } - - internal override void WriteXML(XmlWriter writer) - { - writer.WriteStartElement("x"); - writer.WriteString(X.ToString()); - writer.WriteEndElement(); - writer.WriteStartElement("y"); - writer.WriteString(Y.ToString()); - writer.WriteEndElement(); - writer.WriteStartElement("z"); - writer.WriteString(Z.ToString()); - writer.WriteEndElement(); - } } } diff --git a/Items/StepVector.cs b/src/IxMilia.Step/Items/StepVector.cs similarity index 82% rename from Items/StepVector.cs rename to src/IxMilia.Step/Items/StepVector.cs index bd0bbb9..17a43ef 100644 --- a/Items/StepVector.cs +++ b/src/IxMilia.Step/Items/StepVector.cs @@ -1,10 +1,10 @@ - +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System; using System.Collections.Generic; -using System.Xml; -using StepParser.Syntax; +using IxMilia.Step.Syntax; -namespace StepParser.Items +namespace IxMilia.Step.Items { public class StepVector : StepGeometricRepresentationItem { @@ -27,12 +27,12 @@ public StepDirection Direction public double Length { get; set; } private StepVector() - : base(string.Empty, 0) + : base(string.Empty) { } public StepVector(string name, StepDirection direction, double length) - : base(name, 0) + : base(name) { Direction = direction; Length = length; @@ -63,12 +63,5 @@ internal static StepVector CreateFromSyntaxList(StepBinder binder, StepSyntaxLis vector.Length = syntaxList.Values[2].GetRealVavlue(); return vector; } - - internal override void WriteXML(XmlWriter writer) - { - writer.WriteStartElement(ItemType.GetItemTypeElementString()); - _direction.WriteXML(writer); - writer.WriteEndElement(); - } } } diff --git a/src/IxMilia.Step/Items/StepVertex.cs b/src/IxMilia.Step/Items/StepVertex.cs new file mode 100644 index 0000000..b5977b2 --- /dev/null +++ b/src/IxMilia.Step/Items/StepVertex.cs @@ -0,0 +1,12 @@ +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace IxMilia.Step.Items +{ + public abstract class StepVertex : StepTopologicalRepresentationItem + { + protected StepVertex(string name) + : base(name) + { + } + } +} diff --git a/Items/StepVertexPoint.cs b/src/IxMilia.Step/Items/StepVertexPoint.cs similarity index 87% rename from Items/StepVertexPoint.cs rename to src/IxMilia.Step/Items/StepVertexPoint.cs index 49a9430..f8b1605 100644 --- a/Items/StepVertexPoint.cs +++ b/src/IxMilia.Step/Items/StepVertexPoint.cs @@ -1,9 +1,10 @@ -using System; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; using System.Collections.Generic; -using System.Xml; -using StepParser.Syntax; +using IxMilia.Step.Syntax; -namespace StepParser.Items +namespace IxMilia.Step.Items { public class StepVertexPoint : StepVertex { @@ -59,10 +60,5 @@ internal static StepVertexPoint CreateFromSyntaxList(StepBinder binder, StepSynt binder.BindValue(syntaxList.Values[1], v => vertex.Location = v.AsType()); return vertex; } - - internal override void WriteXML(XmlWriter writer) - { - _location.WriteXML(writer); - } } } diff --git a/src/IxMilia.Step/IxMilia.Step.csproj b/src/IxMilia.Step/IxMilia.Step.csproj new file mode 100644 index 0000000..7510345 --- /dev/null +++ b/src/IxMilia.Step/IxMilia.Step.csproj @@ -0,0 +1,29 @@ + + + + A portable .NET library for reading and writing STEP CAD files. + Copyright 2017 + IxMilia.Step + IxMilia + netstandard1.0;netstandard1.3 + IxMilia.Step + IxMilia.Step + CAD;STEP;STP + https://github.com/ixmilia/step + http://www.apache.org/licenses/LICENSE-2.0 + + + true + true + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + + + + $(DefineConstants);HAS_FILESYSTEM_ACCESS + + + + + + + diff --git a/src/IxMilia.Step/Properties/AssemblyInfo.cs b/src/IxMilia.Step/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..fa8df40 --- /dev/null +++ b/src/IxMilia.Step/Properties/AssemblyInfo.cs @@ -0,0 +1,5 @@ +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("IxMilia.Step.Test")] diff --git a/StepBinder.cs b/src/IxMilia.Step/StepBinder.cs similarity index 73% rename from StepBinder.cs rename to src/IxMilia.Step/StepBinder.cs index 79c26b9..859cf17 100644 --- a/StepBinder.cs +++ b/src/IxMilia.Step/StepBinder.cs @@ -1,11 +1,12 @@ -using StepParser.Items; -using StepParser.Syntax; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System; using System.Collections.Generic; using System.Linq; -using System.Text; +using IxMilia.Step.Items; +using IxMilia.Step.Syntax; -namespace StepParser +namespace IxMilia.Step { internal class StepBinder { @@ -22,7 +23,7 @@ public void BindValue(StepSyntax syntax, Action bindAction) if (syntax is StepSimpleItemSyntax) { var typedParameter = (StepSimpleItemSyntax)syntax; - var item = StepRepresentationItem.FromTypedParameter(this, typedParameter, typedParameter.Id); + var item = StepRepresentationItem.FromTypedParameter(this, typedParameter); var boundItem = new StepBoundItem(item, syntax); bindAction(boundItem); } @@ -63,8 +64,7 @@ public void BindRemainingValues() if (!_itemMap.ContainsKey(id)) { var syntax = _unboundPointers[id].First().Item1; - continue; - //throw new StepReadException($"Cannot bind undefined pointer {id}", syntax.Line, syntax.Column); + throw new StepReadException($"Cannot bind undefined pointer {id}", syntax.Line, syntax.Column); } var item = _itemMap[id]; @@ -75,21 +75,5 @@ public void BindRemainingValues() } } } - - public void BindRelationShip(StepRepresentationItem item, Action bindAction) - { - for(int i=0; i<_itemMap.Count; i++) - { - if (_itemMap[i] is StepShapeRepresentationRelationShip) - { - var itemInstance = (StepShapeRepresentationRelationShip)_itemMap[i]; - if (itemInstance.UsedRepresentation != null && itemInstance.UsedRepresentation.Id == item.Id) - { - var boundItem = new StepBoundItem(_itemMap[itemInstance.Id]); - bindAction(boundItem); - } - } - } - } } } diff --git a/StepBoundItem.cs b/src/IxMilia.Step/StepBoundItem.cs similarity index 82% rename from StepBoundItem.cs rename to src/IxMilia.Step/StepBoundItem.cs index 8945f39..19d859f 100644 --- a/StepBoundItem.cs +++ b/src/IxMilia.Step/StepBoundItem.cs @@ -1,10 +1,9 @@ -using StepParser.Items; -using StepParser.Syntax; -using System; -using System.Collections.Generic; -using System.Text; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser +using IxMilia.Step.Items; +using IxMilia.Step.Syntax; + +namespace IxMilia.Step { internal class StepBoundItem { @@ -12,11 +11,6 @@ internal class StepBoundItem public StepRepresentationItem Item { get; } public bool IsAuto { get; private set; } - public StepBoundItem(StepRepresentationItem item) - { - Item = item; - } - public StepBoundItem(StepRepresentationItem item, StepSyntax creatingSyntax) { CreatingSyntax = creatingSyntax; diff --git a/StepFile.cs b/src/IxMilia.Step/StepFile.cs similarity index 82% rename from StepFile.cs rename to src/IxMilia.Step/StepFile.cs index 523a28e..2f2569c 100644 --- a/StepFile.cs +++ b/src/IxMilia.Step/StepFile.cs @@ -1,12 +1,13 @@ -using StepParser.Items; -using StepParser.Syntax; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; +using IxMilia.Step.Items; +using IxMilia.Step.Syntax; -namespace StepParser +namespace IxMilia.Step { public class StepFile { @@ -14,7 +15,6 @@ public class StepFile internal const string MagicFooter = "END-" + MagicHeader; internal const string HeaderText = "HEADER"; internal const string EndSectionText = "ENDSEC"; - internal const string DataText = "DATA"; internal const string FileDescriptionText = "FILE_DESCRIPTION"; @@ -48,7 +48,7 @@ public StepFile() Items = new List(); } - #if HAS_FILESYSTEM_ACCESS +#if HAS_FILESYSTEM_ACCESS public static StepFile Load(string path) { using (var stream = new FileStream(path, FileMode.Open)) @@ -56,7 +56,7 @@ public static StepFile Load(string path) return Load(stream); } } - #endif +#endif public static StepFile Load(Stream stream) { @@ -75,6 +75,31 @@ public static StepFile Parse(string data) } } + public string GetContentsAsString(bool inlineReferences = false) + { + var writer = new StepWriter(this, inlineReferences); + return writer.GetContents(); + } + +#if HAS_FILESYSTEM_ACCESS + public void Save(string path, bool inlineReferences = false) + { + using (var stream = new FileStream(path, FileMode.Create)) + { + Save(stream, inlineReferences); + } + } +#endif + + public void Save(Stream stream, bool inlineReferences = false) + { + using (var streamWriter = new StreamWriter(stream)) + { + streamWriter.Write(GetContentsAsString(inlineReferences)); + streamWriter.Flush(); + } + } + /// /// Gets all top-level items (i.e., not referenced by any other item) in the file. /// diff --git a/StepLexer.cs b/src/IxMilia.Step/StepLexer.cs similarity index 97% rename from StepLexer.cs rename to src/IxMilia.Step/StepLexer.cs index 0143c8e..b730ed2 100644 --- a/StepLexer.cs +++ b/src/IxMilia.Step/StepLexer.cs @@ -1,10 +1,10 @@ -using StepParser.Syntax; -using StepParser.Tokens; -using System; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System.Collections.Generic; -using System.Text; +using IxMilia.Step.Syntax; +using IxMilia.Step.Tokens; -namespace StepParser +namespace IxMilia.Step { internal class StepLexer { @@ -224,7 +224,7 @@ private StepSimpleItemSyntax LexSimpleItem() MoveNext(); var parameters = LexSyntaxList(); - return new StepSimpleItemSyntax(keyword, parameters, 0); + return new StepSimpleItemSyntax(keyword, parameters); } private StepComplexItemSyntax LexComplexItem() diff --git a/StepReadException.cs b/src/IxMilia.Step/StepReadException.cs similarity index 62% rename from StepReadException.cs rename to src/IxMilia.Step/StepReadException.cs index 52b8ec7..01e97dc 100644 --- a/StepReadException.cs +++ b/src/IxMilia.Step/StepReadException.cs @@ -1,8 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Text; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser +using System; + +namespace IxMilia.Step { public class StepReadException : Exception { diff --git a/StepReader.cs b/src/IxMilia.Step/StepReader.cs similarity index 92% rename from StepReader.cs rename to src/IxMilia.Step/StepReader.cs index 58f4f41..a72c4ff 100644 --- a/StepReader.cs +++ b/src/IxMilia.Step/StepReader.cs @@ -1,15 +1,15 @@ -using StepParser.Items; -using StepParser.Syntax; -using System; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; -using System.Text; +using IxMilia.Step.Items; +using IxMilia.Step.Syntax; -namespace StepParser +namespace IxMilia.Step { - public class StepReader + internal class StepReader { private StepLexer _lexer; private StepFile _file; @@ -39,7 +39,7 @@ public StepFile ReadFile() throw new StepReadException("Duplicate item instance", itemInstance.Line, itemInstance.Column); } - var item = StepRepresentationItem.FromTypedParameter(binder, itemInstance.SimpleItemInstance, itemInstance.Id); + var item = StepRepresentationItem.FromTypedParameter(binder, itemInstance.SimpleItemInstance); if (item != null) { itemMap.Add(itemInstance.Id, item); diff --git a/StepSchemaTypes.cs b/src/IxMilia.Step/StepSchemaTypes.cs similarity index 97% rename from StepSchemaTypes.cs rename to src/IxMilia.Step/StepSchemaTypes.cs index 20ddb00..19dd34f 100644 --- a/StepSchemaTypes.cs +++ b/src/IxMilia.Step/StepSchemaTypes.cs @@ -1,8 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Text; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser +using System; + +namespace IxMilia.Step { public enum StepSchemaTypes { diff --git a/StepTokenizer.cs b/src/IxMilia.Step/StepTokenizer.cs similarity index 98% rename from StepTokenizer.cs rename to src/IxMilia.Step/StepTokenizer.cs index cd35b39..a0efae8 100644 --- a/StepTokenizer.cs +++ b/src/IxMilia.Step/StepTokenizer.cs @@ -1,11 +1,13 @@ -using StepParser.Tokens; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Text; +using IxMilia.Step.Tokens; -namespace StepParser +namespace IxMilia.Step { internal class StepTokenizer { diff --git a/src/IxMilia.Step/StepWriter.cs b/src/IxMilia.Step/StepWriter.cs new file mode 100644 index 0000000..5e8a823 --- /dev/null +++ b/src/IxMilia.Step/StepWriter.cs @@ -0,0 +1,196 @@ +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Text; +using IxMilia.Step.Items; +using IxMilia.Step.Syntax; +using IxMilia.Step.Tokens; + +namespace IxMilia.Step +{ + internal class StepWriter + { + private StepFile _file; + private int _currentLineLength; + private bool _honorLineLength = true; + private bool _inlineReferences; + private Dictionary _itemMap; + private int _nextId; + + private const int MaxLineLength = 80; + + public StepWriter(StepFile stepFile, bool inlineReferences) + { + _file = stepFile; + _itemMap = new Dictionary(); + _inlineReferences = inlineReferences; + } + + public string GetContents() + { + var builder = new StringBuilder(); + + _honorLineLength = false; + WriteDelimitedLine(StepFile.MagicHeader, builder); + + // output header + WriteDelimitedLine(StepFile.HeaderText, builder); + var headerSyntax = _file.GetHeaderSyntax(); + foreach (var macro in headerSyntax.Macros) + { + WriteHeaderMacro(macro, builder); + } + + WriteDelimitedLine(StepFile.EndSectionText, builder); + + _honorLineLength = true; + + // data section + WriteDelimitedLine(StepFile.DataText, builder); + foreach (var item in _file.Items) + { + WriteItem(item, builder); + } + + WriteDelimitedLine(StepFile.EndSectionText, builder); + WriteDelimitedLine(StepFile.MagicFooter, builder); + + return builder.ToString(); + } + + private void WriteHeaderMacro(StepHeaderMacroSyntax macro, StringBuilder builder) + { + WriteText(macro.Name, builder); + WriteTokens(macro.Values.GetTokens(), builder); + WriteToken(StepSemicolonToken.Instance, builder); + WriteNewLine(builder); + } + + private int WriteItem(StepRepresentationItem item, StringBuilder builder) + { + if (!_inlineReferences) + { + // not inlining references, need to write out entities as we see them + foreach (var referencedItem in item.GetReferencedItems()) + { + if (!_itemMap.ContainsKey(referencedItem)) + { + var refid = WriteItem(referencedItem, builder); + } + } + } + + var id = ++_nextId; + var syntax = GetItemSyntax(item, id); + WriteToken(new StepEntityInstanceToken(id, -1, -1), builder); + WriteToken(StepEqualsToken.Instance, builder); + WriteTokens(syntax.GetTokens(), builder); + WriteToken(StepSemicolonToken.Instance, builder); + WriteNewLine(builder); + return id; + } + + /// + /// Internal for testing. + /// + internal void WriteTokens(IEnumerable tokens, StringBuilder builder) + { + foreach (var token in tokens) + { + WriteToken(token, builder); + } + } + + private void WriteToken(StepToken token, StringBuilder builder) + { + WriteText(token.ToString(this), builder); + } + + private void WriteDelimitedLine(string text, StringBuilder builder) + { + WriteText(text, builder); + WriteToken(StepSemicolonToken.Instance, builder); + WriteNewLine(builder); + } + + private void WriteText(string text, StringBuilder builder) + { + if (_honorLineLength && _currentLineLength + text.Length > MaxLineLength) + { + WriteNewLine(builder); + } + + builder.Append(text); + _currentLineLength += text.Length; + } + + private void WriteNewLine(StringBuilder builder) + { + builder.Append("\r\n"); + _currentLineLength = 0; + } + + private StepSyntax GetItemSyntax(StepRepresentationItem item, int expectedId) + { + if (!_itemMap.ContainsKey(item)) + { + var parameters = new StepSyntaxList(-1, -1, item.GetParameters(this)); + var syntax = new StepSimpleItemSyntax(item.ItemType.GetItemTypeString(), parameters); + _itemMap.Add(item, expectedId); + return syntax; + } + else + { + return GetItemSyntax(item); + } + } + + public StepSyntax GetItemSyntax(StepRepresentationItem item) + { + if (_inlineReferences) + { + var parameters = new StepSyntaxList(-1, -1, item.GetParameters(this)); + return new StepSimpleItemSyntax(item.ItemType.GetItemTypeString(), parameters); + } + else + { + return new StepEntityInstanceReferenceSyntax(_itemMap[item]); + } + } + + public StepSyntax GetItemSyntaxOrAuto(StepRepresentationItem item) + { + return item == null + ? new StepAutoSyntax() + : GetItemSyntax(item); + } + + public static StepEnumerationValueSyntax GetBooleanSyntax(bool value) + { + var text = value ? "T" : "F"; + return new StepEnumerationValueSyntax(text); + } + + internal static IEnumerable SplitStringIntoParts(string str, int maxLength = 256) + { + var parts = new List(); + if (str != null) + { + int offset = 0; + while (offset < str.Length) + { + var length = Math.Min(maxLength, str.Length - offset); + parts.Add(str.Substring(offset, length)); + offset += length; + } + } + else + { + parts.Add(string.Empty); + } + + return parts; + } + } +} diff --git a/Syntax/StepAutoSyntax.cs b/src/IxMilia.Step/Syntax/StepAutoSyntax.cs similarity index 68% rename from Syntax/StepAutoSyntax.cs rename to src/IxMilia.Step/Syntax/StepAutoSyntax.cs index 16cc41e..67de9a8 100644 --- a/Syntax/StepAutoSyntax.cs +++ b/src/IxMilia.Step/Syntax/StepAutoSyntax.cs @@ -1,7 +1,9 @@ -using System.Collections.Generic; -using StepParser.Tokens; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Syntax +using System.Collections.Generic; +using IxMilia.Step.Tokens; + +namespace IxMilia.Step.Syntax { internal class StepAutoSyntax : StepSyntax { diff --git a/Syntax/StepComplexItemSyntax.cs b/src/IxMilia.Step/Syntax/StepComplexItemSyntax.cs similarity index 70% rename from Syntax/StepComplexItemSyntax.cs rename to src/IxMilia.Step/Syntax/StepComplexItemSyntax.cs index 9555b10..1922055 100644 --- a/Syntax/StepComplexItemSyntax.cs +++ b/src/IxMilia.Step/Syntax/StepComplexItemSyntax.cs @@ -1,8 +1,10 @@ -using System.Collections.Generic; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; using System.Linq; -using StepParser.Tokens; +using IxMilia.Step.Tokens; -namespace StepParser.Syntax +namespace IxMilia.Step.Syntax { internal class StepComplexItemSyntax : StepItemSyntax { diff --git a/Syntax/StepDataSectionSyntax.cs b/src/IxMilia.Step/Syntax/StepDataSectionSyntax.cs similarity index 72% rename from Syntax/StepDataSectionSyntax.cs rename to src/IxMilia.Step/Syntax/StepDataSectionSyntax.cs index cd3a01e..8b0e501 100644 --- a/Syntax/StepDataSectionSyntax.cs +++ b/src/IxMilia.Step/Syntax/StepDataSectionSyntax.cs @@ -1,9 +1,11 @@ -using System; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; using System.Collections.Generic; using System.Linq; -using StepParser.Tokens; +using IxMilia.Step.Tokens; -namespace StepParser.Syntax +namespace IxMilia.Step.Syntax { internal class StepDataSectionSyntax : StepSyntax { diff --git a/Syntax/StepEntityInstanceReferenceSyntax.cs b/src/IxMilia.Step/Syntax/StepEntityInstanceReferenceSyntax.cs similarity index 72% rename from Syntax/StepEntityInstanceReferenceSyntax.cs rename to src/IxMilia.Step/Syntax/StepEntityInstanceReferenceSyntax.cs index d9d038b..b8bc2ee 100644 --- a/Syntax/StepEntityInstanceReferenceSyntax.cs +++ b/src/IxMilia.Step/Syntax/StepEntityInstanceReferenceSyntax.cs @@ -1,7 +1,9 @@ -using System.Collections.Generic; -using StepParser.Tokens; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Syntax +using System.Collections.Generic; +using IxMilia.Step.Tokens; + +namespace IxMilia.Step.Syntax { internal class StepEntityInstanceReferenceSyntax : StepSyntax { diff --git a/Syntax/StepEntityInstanceSyntax.cs b/src/IxMilia.Step/Syntax/StepEntityInstanceSyntax.cs similarity index 75% rename from Syntax/StepEntityInstanceSyntax.cs rename to src/IxMilia.Step/Syntax/StepEntityInstanceSyntax.cs index f61e933..e701b12 100644 --- a/Syntax/StepEntityInstanceSyntax.cs +++ b/src/IxMilia.Step/Syntax/StepEntityInstanceSyntax.cs @@ -1,7 +1,9 @@ -using System.Collections.Generic; -using StepParser.Tokens; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Syntax +using System.Collections.Generic; +using IxMilia.Step.Tokens; + +namespace IxMilia.Step.Syntax { internal class StepEntityInstanceSyntax : StepSyntax { diff --git a/Syntax/StepEnumerationValueSyntax.cs b/src/IxMilia.Step/Syntax/StepEnumerationValueSyntax.cs similarity index 71% rename from Syntax/StepEnumerationValueSyntax.cs rename to src/IxMilia.Step/Syntax/StepEnumerationValueSyntax.cs index ae72cdf..8abed2c 100644 --- a/Syntax/StepEnumerationValueSyntax.cs +++ b/src/IxMilia.Step/Syntax/StepEnumerationValueSyntax.cs @@ -1,7 +1,9 @@ -using System.Collections.Generic; -using StepParser.Tokens; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Syntax +using System.Collections.Generic; +using IxMilia.Step.Tokens; + +namespace IxMilia.Step.Syntax { internal class StepEnumerationValueSyntax : StepSyntax { diff --git a/Syntax/StepFileSyntax.cs b/src/IxMilia.Step/Syntax/StepFileSyntax.cs similarity index 72% rename from Syntax/StepFileSyntax.cs rename to src/IxMilia.Step/Syntax/StepFileSyntax.cs index bdfec07..b511713 100644 --- a/Syntax/StepFileSyntax.cs +++ b/src/IxMilia.Step/Syntax/StepFileSyntax.cs @@ -1,8 +1,10 @@ -using System; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; using System.Collections.Generic; -using StepParser.Tokens; +using IxMilia.Step.Tokens; -namespace StepParser.Syntax +namespace IxMilia.Step.Syntax { internal class StepFileSyntax : StepSyntax { diff --git a/Syntax/StepHeaderMacroSyntax.cs b/src/IxMilia.Step/Syntax/StepHeaderMacroSyntax.cs similarity index 71% rename from Syntax/StepHeaderMacroSyntax.cs rename to src/IxMilia.Step/Syntax/StepHeaderMacroSyntax.cs index 65e7ff6..f345149 100644 --- a/Syntax/StepHeaderMacroSyntax.cs +++ b/src/IxMilia.Step/Syntax/StepHeaderMacroSyntax.cs @@ -1,8 +1,10 @@ -using System; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; using System.Collections.Generic; -using StepParser.Tokens; +using IxMilia.Step.Tokens; -namespace StepParser.Syntax +namespace IxMilia.Step.Syntax { internal class StepHeaderMacroSyntax : StepSyntax { diff --git a/Syntax/StepHeaderSectionSyntax.cs b/src/IxMilia.Step/Syntax/StepHeaderSectionSyntax.cs similarity index 71% rename from Syntax/StepHeaderSectionSyntax.cs rename to src/IxMilia.Step/Syntax/StepHeaderSectionSyntax.cs index b03f40e..7dc3c3d 100644 --- a/Syntax/StepHeaderSectionSyntax.cs +++ b/src/IxMilia.Step/Syntax/StepHeaderSectionSyntax.cs @@ -1,9 +1,11 @@ -using System; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; using System.Collections.Generic; using System.Linq; -using StepParser.Tokens; +using IxMilia.Step.Tokens; -namespace StepParser.Syntax +namespace IxMilia.Step.Syntax { internal class StepHeaderSectionSyntax : StepSyntax { diff --git a/Syntax/StepIntegerSyntax.cs b/src/IxMilia.Step/Syntax/StepIntegerSyntax.cs similarity index 70% rename from Syntax/StepIntegerSyntax.cs rename to src/IxMilia.Step/Syntax/StepIntegerSyntax.cs index cd2822d..538595c 100644 --- a/Syntax/StepIntegerSyntax.cs +++ b/src/IxMilia.Step/Syntax/StepIntegerSyntax.cs @@ -1,7 +1,9 @@ -using System.Collections.Generic; -using StepParser.Tokens; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Syntax +using System.Collections.Generic; +using IxMilia.Step.Tokens; + +namespace IxMilia.Step.Syntax { internal class StepIntegerSyntax : StepSyntax { diff --git a/src/IxMilia.Step/Syntax/StepItemSyntax.cs b/src/IxMilia.Step/Syntax/StepItemSyntax.cs new file mode 100644 index 0000000..99b934a --- /dev/null +++ b/src/IxMilia.Step/Syntax/StepItemSyntax.cs @@ -0,0 +1,12 @@ +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace IxMilia.Step.Syntax +{ + internal abstract class StepItemSyntax : StepSyntax + { + protected StepItemSyntax(int line, int column) + : base(line, column) + { + } + } +} diff --git a/Syntax/StepOmittedSyntax.cs b/src/IxMilia.Step/Syntax/StepOmittedSyntax.cs similarity index 61% rename from Syntax/StepOmittedSyntax.cs rename to src/IxMilia.Step/Syntax/StepOmittedSyntax.cs index 66b8c5b..26bc2cc 100644 --- a/Syntax/StepOmittedSyntax.cs +++ b/src/IxMilia.Step/Syntax/StepOmittedSyntax.cs @@ -1,7 +1,9 @@ -using System.Collections.Generic; -using StepParser.Tokens; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Syntax +using System.Collections.Generic; +using IxMilia.Step.Tokens; + +namespace IxMilia.Step.Syntax { internal class StepOmittedSyntax : StepSyntax { diff --git a/Syntax/StepRealSyntax.cs b/src/IxMilia.Step/Syntax/StepRealSyntax.cs similarity index 69% rename from Syntax/StepRealSyntax.cs rename to src/IxMilia.Step/Syntax/StepRealSyntax.cs index 737d497..83e4c72 100644 --- a/Syntax/StepRealSyntax.cs +++ b/src/IxMilia.Step/Syntax/StepRealSyntax.cs @@ -1,7 +1,9 @@ -using System.Collections.Generic; -using StepParser.Tokens; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Syntax +using System.Collections.Generic; +using IxMilia.Step.Tokens; + +namespace IxMilia.Step.Syntax { internal class StepRealSyntax : StepSyntax { diff --git a/Syntax/StepSimpleItemSyntax.cs b/src/IxMilia.Step/Syntax/StepSimpleItemSyntax.cs similarity index 75% rename from Syntax/StepSimpleItemSyntax.cs rename to src/IxMilia.Step/Syntax/StepSimpleItemSyntax.cs index 7a6e875..be36ef3 100644 --- a/Syntax/StepSimpleItemSyntax.cs +++ b/src/IxMilia.Step/Syntax/StepSimpleItemSyntax.cs @@ -1,30 +1,29 @@ -using System.Collections.Generic; -using StepParser.Tokens; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Syntax +using System.Collections.Generic; +using IxMilia.Step.Tokens; + +namespace IxMilia.Step.Syntax { internal class StepSimpleItemSyntax : StepItemSyntax { public override StepSyntaxType SyntaxType => StepSyntaxType.SimpleItem; - public int Id { get; } public string Keyword { get; } public StepSyntaxList Parameters { get; } - public StepSimpleItemSyntax(string keyword, StepSyntaxList parameters, int id) + public StepSimpleItemSyntax(string keyword, StepSyntaxList parameters) : base(-1, -1) { Keyword = keyword; Parameters = parameters; - Id = id; } - public StepSimpleItemSyntax(StepKeywordToken keyword, StepSyntaxList parameters, int id) + public StepSimpleItemSyntax(StepKeywordToken keyword, StepSyntaxList parameters) : base(keyword.Line, keyword.Column) { Keyword = keyword.Value; Parameters = parameters; - Id = id; } public override IEnumerable GetTokens() diff --git a/Syntax/StepStringSyntax.cs b/src/IxMilia.Step/Syntax/StepStringSyntax.cs similarity index 70% rename from Syntax/StepStringSyntax.cs rename to src/IxMilia.Step/Syntax/StepStringSyntax.cs index e951181..4dd6338 100644 --- a/Syntax/StepStringSyntax.cs +++ b/src/IxMilia.Step/Syntax/StepStringSyntax.cs @@ -1,7 +1,9 @@ -using System.Collections.Generic; -using StepParser.Tokens; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Syntax +using System.Collections.Generic; +using IxMilia.Step.Tokens; + +namespace IxMilia.Step.Syntax { internal class StepStringSyntax : StepSyntax { diff --git a/Syntax/StepSyntax.cs b/src/IxMilia.Step/Syntax/StepSyntax.cs similarity index 59% rename from Syntax/StepSyntax.cs rename to src/IxMilia.Step/Syntax/StepSyntax.cs index 6aa5185..21b4be5 100644 --- a/Syntax/StepSyntax.cs +++ b/src/IxMilia.Step/Syntax/StepSyntax.cs @@ -1,7 +1,9 @@ -using System.Collections.Generic; -using StepParser.Tokens; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Syntax +using System.Collections.Generic; +using IxMilia.Step.Tokens; + +namespace IxMilia.Step.Syntax { internal abstract class StepSyntax { diff --git a/Syntax/StepSyntaxExtensions.cs b/src/IxMilia.Step/Syntax/StepSyntaxExtensions.cs similarity index 93% rename from Syntax/StepSyntaxExtensions.cs rename to src/IxMilia.Step/Syntax/StepSyntaxExtensions.cs index 36b3fe8..f2fab4c 100644 --- a/Syntax/StepSyntaxExtensions.cs +++ b/src/IxMilia.Step/Syntax/StepSyntaxExtensions.cs @@ -4,11 +4,15 @@ using System.Globalization; using System.Linq; -namespace StepParser.Syntax +namespace IxMilia.Step.Syntax { internal static class StepSyntaxExtensions { - public const string DateTimeFormat = "yyyy-MM-ddT"; + public static readonly string[] DateTimeFormats = new string[] + { + "yyyy-MM-ddT", + "yyyy-M-dTh:mm:ss ttzzz", + }; public static void AssertListCount(this StepSyntaxList syntaxList, int count) { @@ -44,7 +48,7 @@ public static DateTime GetDateTimeValue(this StepSyntax syntax) { var str = syntax.GetStringValue(); DateTime result; - if (DateTime.TryParseExact(str, DateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out result)) + if (DateTime.TryParseExact(str, DateTimeFormats, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out result)) { return result; } diff --git a/Syntax/StepSyntaxList.cs b/src/IxMilia.Step/Syntax/StepSyntaxList.cs similarity index 81% rename from Syntax/StepSyntaxList.cs rename to src/IxMilia.Step/Syntax/StepSyntaxList.cs index 747348c..3455c65 100644 --- a/Syntax/StepSyntaxList.cs +++ b/src/IxMilia.Step/Syntax/StepSyntaxList.cs @@ -1,8 +1,10 @@ -using System.Collections.Generic; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; using System.Linq; -using StepParser.Tokens; +using IxMilia.Step.Tokens; -namespace StepParser.Syntax +namespace IxMilia.Step.Syntax { internal class StepSyntaxList : StepSyntax { diff --git a/Syntax/StepSyntaxType.cs b/src/IxMilia.Step/Syntax/StepSyntaxType.cs similarity index 63% rename from Syntax/StepSyntaxType.cs rename to src/IxMilia.Step/Syntax/StepSyntaxType.cs index 04340b3..ac0497b 100644 --- a/Syntax/StepSyntaxType.cs +++ b/src/IxMilia.Step/Syntax/StepSyntaxType.cs @@ -1,4 +1,6 @@ -namespace StepParser.Syntax +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace IxMilia.Step.Syntax { internal enum StepSyntaxType { diff --git a/Tokens/StepAsteriskToken.cs b/src/IxMilia.Step/Tokens/StepAsteriskToken.cs similarity index 95% rename from Tokens/StepAsteriskToken.cs rename to src/IxMilia.Step/Tokens/StepAsteriskToken.cs index b4d6b55..9224a5f 100644 --- a/Tokens/StepAsteriskToken.cs +++ b/src/IxMilia.Step/Tokens/StepAsteriskToken.cs @@ -1,6 +1,6 @@ // Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Tokens +namespace IxMilia.Step.Tokens { internal class StepAsteriskToken : StepToken { diff --git a/Tokens/StepCommaToken.cs b/src/IxMilia.Step/Tokens/StepCommaToken.cs similarity index 95% rename from Tokens/StepCommaToken.cs rename to src/IxMilia.Step/Tokens/StepCommaToken.cs index 682c624..f75fa58 100644 --- a/Tokens/StepCommaToken.cs +++ b/src/IxMilia.Step/Tokens/StepCommaToken.cs @@ -1,6 +1,6 @@ // Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Tokens +namespace IxMilia.Step.Tokens { internal class StepCommaToken : StepToken { diff --git a/Tokens/StepConstantInstanceToken.cs b/src/IxMilia.Step/Tokens/StepConstantInstanceToken.cs similarity index 95% rename from Tokens/StepConstantInstanceToken.cs rename to src/IxMilia.Step/Tokens/StepConstantInstanceToken.cs index 32a9a56..aa17c96 100644 --- a/Tokens/StepConstantInstanceToken.cs +++ b/src/IxMilia.Step/Tokens/StepConstantInstanceToken.cs @@ -1,6 +1,6 @@ // Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Tokens +namespace IxMilia.Step.Tokens { internal class StepConstantInstanceToken : StepToken { diff --git a/Tokens/StepConstantValueToken.cs b/src/IxMilia.Step/Tokens/StepConstantValueToken.cs similarity index 95% rename from Tokens/StepConstantValueToken.cs rename to src/IxMilia.Step/Tokens/StepConstantValueToken.cs index 20057b1..243c84b 100644 --- a/Tokens/StepConstantValueToken.cs +++ b/src/IxMilia.Step/Tokens/StepConstantValueToken.cs @@ -1,6 +1,6 @@ // Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Tokens +namespace IxMilia.Step.Tokens { internal class StepConstantValueToken : StepToken { diff --git a/Tokens/StepEntityInstanceToken.cs b/src/IxMilia.Step/Tokens/StepEntityInstanceToken.cs similarity index 95% rename from Tokens/StepEntityInstanceToken.cs rename to src/IxMilia.Step/Tokens/StepEntityInstanceToken.cs index fcc3a37..4b1fc27 100644 --- a/Tokens/StepEntityInstanceToken.cs +++ b/src/IxMilia.Step/Tokens/StepEntityInstanceToken.cs @@ -1,6 +1,6 @@ // Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Tokens +namespace IxMilia.Step.Tokens { internal class StepEntityInstanceToken : StepToken { diff --git a/Tokens/StepEnumerationToken.cs b/src/IxMilia.Step/Tokens/StepEnumerationToken.cs similarity index 69% rename from Tokens/StepEnumerationToken.cs rename to src/IxMilia.Step/Tokens/StepEnumerationToken.cs index 9ce4657..60dcf2e 100644 --- a/Tokens/StepEnumerationToken.cs +++ b/src/IxMilia.Step/Tokens/StepEnumerationToken.cs @@ -1,5 +1,6 @@ - -namespace StepParser.Tokens +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace IxMilia.Step.Tokens { internal class StepEnumerationToken : StepToken { diff --git a/Tokens/StepEqualsToken.cs b/src/IxMilia.Step/Tokens/StepEqualsToken.cs similarity index 68% rename from Tokens/StepEqualsToken.cs rename to src/IxMilia.Step/Tokens/StepEqualsToken.cs index e6fbfee..46da6d6 100644 --- a/Tokens/StepEqualsToken.cs +++ b/src/IxMilia.Step/Tokens/StepEqualsToken.cs @@ -1,5 +1,6 @@ - -namespace StepParser.Tokens +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace IxMilia.Step.Tokens { internal class StepEqualsToken : StepToken { diff --git a/Tokens/StepInstanceValueToken.cs b/src/IxMilia.Step/Tokens/StepInstanceValueToken.cs similarity index 68% rename from Tokens/StepInstanceValueToken.cs rename to src/IxMilia.Step/Tokens/StepInstanceValueToken.cs index eabae7e..b7d527a 100644 --- a/Tokens/StepInstanceValueToken.cs +++ b/src/IxMilia.Step/Tokens/StepInstanceValueToken.cs @@ -1,5 +1,6 @@ - -namespace StepParser.Tokens +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace IxMilia.Step.Tokens { internal class StepInstanceValueToken : StepToken { diff --git a/Tokens/StepIntegerToken.cs b/src/IxMilia.Step/Tokens/StepIntegerToken.cs similarity index 68% rename from Tokens/StepIntegerToken.cs rename to src/IxMilia.Step/Tokens/StepIntegerToken.cs index 90ce13d..0724eea 100644 --- a/Tokens/StepIntegerToken.cs +++ b/src/IxMilia.Step/Tokens/StepIntegerToken.cs @@ -1,5 +1,6 @@ - -namespace StepParser.Tokens +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace IxMilia.Step.Tokens { internal class StepIntegerToken : StepToken { diff --git a/Tokens/StepKeywordToken.cs b/src/IxMilia.Step/Tokens/StepKeywordToken.cs similarity index 67% rename from Tokens/StepKeywordToken.cs rename to src/IxMilia.Step/Tokens/StepKeywordToken.cs index e1a924c..d19f3d1 100644 --- a/Tokens/StepKeywordToken.cs +++ b/src/IxMilia.Step/Tokens/StepKeywordToken.cs @@ -1,5 +1,6 @@ - -namespace StepParser.Tokens +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace IxMilia.Step.Tokens { internal class StepKeywordToken : StepToken { diff --git a/Tokens/StepLeftParenToken.cs b/src/IxMilia.Step/Tokens/StepLeftParenToken.cs similarity index 68% rename from Tokens/StepLeftParenToken.cs rename to src/IxMilia.Step/Tokens/StepLeftParenToken.cs index b587e28..1de2768 100644 --- a/Tokens/StepLeftParenToken.cs +++ b/src/IxMilia.Step/Tokens/StepLeftParenToken.cs @@ -1,5 +1,6 @@ - -namespace StepParser.Tokens +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace IxMilia.Step.Tokens { internal class StepLeftParenToken : StepToken { diff --git a/Tokens/StepOmittedToken.cs b/src/IxMilia.Step/Tokens/StepOmittedToken.cs similarity index 68% rename from Tokens/StepOmittedToken.cs rename to src/IxMilia.Step/Tokens/StepOmittedToken.cs index 3bfc5c1..23bc1f8 100644 --- a/Tokens/StepOmittedToken.cs +++ b/src/IxMilia.Step/Tokens/StepOmittedToken.cs @@ -1,5 +1,6 @@ - -namespace StepParser.Tokens +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace IxMilia.Step.Tokens { internal class StepOmittedToken : StepToken { diff --git a/Tokens/StepRealToken.cs b/src/IxMilia.Step/Tokens/StepRealToken.cs similarity index 68% rename from Tokens/StepRealToken.cs rename to src/IxMilia.Step/Tokens/StepRealToken.cs index 62844d4..1523d4d 100644 --- a/Tokens/StepRealToken.cs +++ b/src/IxMilia.Step/Tokens/StepRealToken.cs @@ -1,5 +1,6 @@ - -namespace StepParser.Tokens +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace IxMilia.Step.Tokens { internal class StepRealToken : StepToken { diff --git a/Tokens/StepRightParenToken.cs b/src/IxMilia.Step/Tokens/StepRightParenToken.cs similarity index 69% rename from Tokens/StepRightParenToken.cs rename to src/IxMilia.Step/Tokens/StepRightParenToken.cs index c082d4f..9093ae9 100644 --- a/Tokens/StepRightParenToken.cs +++ b/src/IxMilia.Step/Tokens/StepRightParenToken.cs @@ -1,4 +1,6 @@ -namespace StepParser.Tokens +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace IxMilia.Step.Tokens { internal class StepRightParenToken : StepToken { diff --git a/Tokens/StepSemiColonToken.cs b/src/IxMilia.Step/Tokens/StepSemiColonToken.cs similarity index 68% rename from Tokens/StepSemiColonToken.cs rename to src/IxMilia.Step/Tokens/StepSemiColonToken.cs index 3f5faf8..71c9211 100644 --- a/Tokens/StepSemiColonToken.cs +++ b/src/IxMilia.Step/Tokens/StepSemiColonToken.cs @@ -1,4 +1,6 @@ -namespace StepParser.Tokens +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace IxMilia.Step.Tokens { internal class StepSemicolonToken : StepToken { diff --git a/Tokens/StepStringToken.cs b/src/IxMilia.Step/Tokens/StepStringToken.cs similarity index 59% rename from Tokens/StepStringToken.cs rename to src/IxMilia.Step/Tokens/StepStringToken.cs index 95a0344..3171563 100644 --- a/Tokens/StepStringToken.cs +++ b/src/IxMilia.Step/Tokens/StepStringToken.cs @@ -1,4 +1,6 @@ -namespace StepParser.Tokens +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace IxMilia.Step.Tokens { internal class StepStringToken : StepToken { @@ -14,7 +16,8 @@ public StepStringToken(string value, int line, int column) public override string ToString() { - return Value; + // TODO: escaping + return "'" + Value + "'"; } } } diff --git a/Tokens/StepToken.cs b/src/IxMilia.Step/Tokens/StepToken.cs similarity index 68% rename from Tokens/StepToken.cs rename to src/IxMilia.Step/Tokens/StepToken.cs index 2d83309..b7920c9 100644 --- a/Tokens/StepToken.cs +++ b/src/IxMilia.Step/Tokens/StepToken.cs @@ -1,8 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Text; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Tokens +namespace IxMilia.Step.Tokens { internal abstract class StepToken { diff --git a/Tokens/StepTokenKind.cs b/src/IxMilia.Step/Tokens/StepTokenKind.cs similarity index 64% rename from Tokens/StepTokenKind.cs rename to src/IxMilia.Step/Tokens/StepTokenKind.cs index b194392..97570d0 100644 --- a/Tokens/StepTokenKind.cs +++ b/src/IxMilia.Step/Tokens/StepTokenKind.cs @@ -1,8 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Text; +// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace StepParser.Tokens +namespace IxMilia.Step.Tokens { internal enum StepTokenKind { diff --git a/src/create-package.cmd b/src/create-package.cmd new file mode 100644 index 0000000..102fb02 --- /dev/null +++ b/src/create-package.cmd @@ -0,0 +1,14 @@ +@echo off + +set PROJECT_NAME=IxMilia.Step +set CONFIGURATION=Release +set PROJECT=%~dp0\%PROJECT_NAME%\%PROJECT_NAME%.csproj + +dotnet restore "%PROJECT%" +if errorlevel 1 exit /b 1 + +dotnet build "%PROJECT%" --configuration %CONFIGURATION% +if errorlevel 1 exit /b 1 + +dotnet pack --no-restore --no-build --configuration %CONFIGURATION% "%PROJECT%" +if errorlevel 1 exit /b 1 diff --git a/src/create-package.sh b/src/create-package.sh new file mode 100644 index 0000000..0dce81c --- /dev/null +++ b/src/create-package.sh @@ -0,0 +1,10 @@ +#!/bin/sh -e + +_SCRIPT_DIR="$( cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P )" +PROJECT_NAME=IxMilia.Step +CONFIGURATION=Release +PROJECT=$_SCRIPT_DIR/$PROJECT_NAME/$PROJECT_NAME.csproj + +dotnet restore "$PROJECT" +dotnet build "$PROJECT" --configuration $CONFIGURATION +dotnet pack --no-restore --no-build --configuration $CONFIGURATION "$PROJECT" diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..6e8bf73 --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +0.1.0