- Refer to the MTK Converter Example.
MTKConverter_PartProcessor.cs
using System.Collections.Generic;
namespace mtkconverter
{
class MTKConverter_ProcessData
{
protected MTKConverter_ProcessData(
Part thePart)
{
myPart = thePart;
mySourceSheets = new List<Sheet>();
}
protected MTKConverter_ProcessData(List<Sheet> theSheets)
{
mySourceSheets = theSheets;
}
public List<Sheet> mySourceSheets;
}
{
protected MTKConverter_PartProcessor()
{
myData = new List<MTKConverter_ProcessData>();
}
public List<MTKConverter_ProcessData> myData;
public override void Apply(
Part thePart)
{
bool aPartWasProcessed = false;
var aProcessData = CreateProcessData(thePart);
foreach (var aBody
in thePart.
Bodies())
{
{
if (ProcessMeshBody(aProcessData,
MeshBody.
Cast(aBody)))
{
aPartWasProcessed = true;
}
}
else if (ProcessBRepBody(aProcessData, aBody))
{
aPartWasProcessed = true;
}
}
if (aPartWasProcessed)
{
PostProcessPart(thePart);
myData.Add(aProcessData);
}
}
private bool ProcessBRepBody(MTKConverter_ProcessData theProcessData,
Body theBody)
{
bool aBodyWasProcessed = false;
foreach (var aShape in aShapeIt)
{
{
ProcessSolid(theProcessData,
Solid.
Cast(aShape));
aBodyWasProcessed = true;
}
{
ProcessShell(theProcessData,
Shell.
Cast(aShape));
aBodyWasProcessed = true;
}
}
return aBodyWasProcessed;
}
private bool ProcessMeshBody(MTKConverter_ProcessData theProcessData,
MeshBody theBody)
{
bool aBodyWasProcessed = false;
foreach (var aMeshShape in theBody.Shapes()) {
aBodyWasProcessed = true;
}
}
return aBodyWasProcessed;
}
public abstract MTKConverter_ProcessData CreateProcessData(
Part thePart);
public abstract void ProcessSolid(MTKConverter_ProcessData theProcessData,
Solid theSolid);
public abstract void ProcessShell(MTKConverter_ProcessData theProcessData,
Shell theShell);
public abstract void ProcessMesh(MTKConverter_ProcessData theProcessData,
IndexedTriangleSet theMesh);
public abstract void PostProcessPart(
Part thePart);
}
abstract class MTKConverter_VoidPartProcessor : MTKConverter_PartProcessor
{
public MTKConverter_VoidPartProcessor() : base() { }
public override void ProcessSolid(MTKConverter_ProcessData theProcessData,
Solid theSolid) { }
public override void ProcessShell(MTKConverter_ProcessData theProcessData,
Shell theShell) { }
public override void ProcessMesh(MTKConverter_ProcessData theProcessData,
IndexedTriangleSet theMesh) { }
public override void PostProcessPart(
Part thePart) { }
}
}
Provides a base body class.
Definition Body.cs:19
Defines a polygonal shape consisting of triangles.
Definition IndexedTriangleSet.cs:81
Defines a body that represents a polygonal mesh (faceted or tessellated).
Definition MeshBody.cs:19
Element visitor with empty implementation.
Definition ModelElementVoidVisitor.cs:20
Defines a leaf node in the scene graph hierarchy.
Definition Part.cs:23
Iterates over subshapes in a shape.
Definition ShapeIterator.cs:58
Defines a connected set of faces.
Definition Shell.cs:29
Defines a topological solid.
Definition Solid.cs:25
Defines a Unicode (UTF-16) string wrapping a standard string.
Definition UTF16String.cs:17
Contains classes, types and enums related to drawings.
Definition AngularDimension.cs:12
Defines classes, types, enums, and functions related to topological entities and scene graph elements...
Definition AngleUnit.cs:12
ShapeType
Defines shape type.
Definition ShapeType.cs:17
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.
Definition BaseObject.cs:12
MTKConverter_DrawingProcessor.cs
using System.Collections.Generic;
namespace mtkconverter
{
abstract class MTKConverter_DrawingProcessor
{
protected MTKConverter_DrawingProcessor()
{
myData = new List<MTKConverter_ProcessData>();
}
public abstract bool Apply(
Drawing theDrawing);
public static List<Sheet> ExtractDrawingSheets(
Drawing theDrawing)
{
List<Sheet> aSheets = new List<Sheet>();
while (aSheetIt.HasNext())
{
aSheets.Add(aSheetIt.Next());
}
return aSheets;
}
{
if (theSrc == null)
{
return;
}
if (theDst == null)
{
theDst = theSrc;
return;
}
while (anIt.HasNext())
{
theDst.AddSheet(anIt.Next());
}
}
public List<MTKConverter_ProcessData> myData;
}
}
Iterator over sheets of a drawing.
Definition Drawing.cs:108
Represents a single 2D drawing of a model.
Definition Drawing.cs:33
MTKConverter_MachiningProcessor.cs
namespace mtkconverter
{
class MTKConverter_MachiningData : MTKConverter_ProcessData
{
public MTKConverter_MachiningData(
Part thePart) : base(thePart)
{
}
}
class MTKConverter_MachiningProcessor : MTKConverter_VoidPartProcessor
{
{
myOperation = theOperation;
}
public override MTKConverter_ProcessData CreateProcessData(
Part thePart)
{
return new MTKConverter_MachiningData(thePart);
}
public override void ProcessSolid(MTKConverter_ProcessData theProcessData,
Solid theSolid)
{
var aMachiningData = theProcessData as MTKConverter_MachiningData;
aMachiningData.myOperation = myOperation;
anAnalyzer.
AddTool(aFeatureRecognizer);
{
return;
}
aMachiningData.myFeatureList.Append(aData.
FeatureList());
aMachiningData.myIssueList.Append(aDrillingAnalyzer.
Perform(theSolid, aData));
for (uint i = 0; i < aMillingIssueList.
Size(); ++i)
{
{
continue;
}
aMachiningData.myIssueList.Append(anIssue);
}
{
for (uint i = 0; i < aTurningIssueList.
Size(); ++i)
{
aMachiningData.myIssueList.Append(anIssue);
}
}
}
}
}
Provides an interface to run DFM Machining analysis.
Definition DFMMachining_Analyzer.cs:44
cadex.MTKBase_FeatureList Perform(cadex.ModelData.Solid theSolid, cadex.ProgressStatus theProgressStatus)
Runs analyzing process.
Definition DFMMachining_Analyzer.cs:106
Describes deep pocket issue found during cnc machining milling design analysis.
Definition DFMMachining_DeepPocketIssue.cs:39
static new bool CompareType(cadex.MTKBase_Feature theFeature)
Returns true if theFeature is a DFM deep pocket issue.
Definition DFMMachining_DeepPocketIssue.cs:154
Defines parameters used in cnc machining drilling design analysis.
Definition DFMMachining_DrillingAnalyzerParameters.cs:19
Defines parameters used in cnc machining milling design analysis.
Definition DFMMachining_MillingAnalyzerParameters.cs:19
Defines parameters used in cnc machining turning design analysis.
Definition DFMMachining_TurningAnalyzerParameters.cs:19
Describes a base class of MTK based features.
Definition MTKBase_Feature.cs:21
Defines a list of features.
Definition MTKBase_FeatureList.cs:20
uint Size()
Returns the number of elements in the list.
Definition MTKBase_FeatureList.cs:110
cadex.MTKBase_Feature Feature(uint theIndex)
Access specified element.
Definition MTKBase_FeatureList.cs:99
Provides an interface to run several analyzer tools for different types of machining processing.
Definition Machining_Analyzer.cs:21
cadex.Machining_Data Perform(cadex.ModelData.Solid theSolid, cadex.ProgressStatus theProgressStatus)
Runs the analyzing process.
Definition Machining_Analyzer.cs:79
void AddTool(cadex.Machining_AnalyzerTool theTool)
Adds additional tool to run during analyzing process.
Definition Machining_Analyzer.cs:102
Defines data used in Machining analysis.
Definition Machining_Data.cs:19
cadex.MTKBase_FeatureList FeatureList()
Returns the feature list found during machining feature recognizing process.
Definition Machining_Data.cs:79
bool IsEmpty()
Returns true if the data is empty.
Definition Machining_Data.cs:85
Provides an interface to recognizing machining features tool.
Definition Machining_FeatureRecognizer.cs:25
cadex.Machining_FeatureRecognizerParameters Parameters()
Returns reference to parameters.
Definition Machining_FeatureRecognizer.cs:116
void SetOperation(cadex.Machining_OperationType theOperation)
Sets machining operation type.
Definition Machining_FeatureRecognizerParameters.cs:208
Machining_OperationType
Defines an operation type in machining.
Definition Machining_OperationType.cs:19
MTKConverter_MoldingProcessor.cs
using System.Collections.Generic;
namespace mtkconverter
{
class MTKConverter_MoldingData : MTKConverter_ProcessData
{
public MTKConverter_MoldingData(
Part thePart) : base(thePart)
{
}
}
class MTKConverter_MoldingProcessor : MTKConverter_VoidPartProcessor
{
public MTKConverter_MoldingProcessor(
Model theExtraDataModel) : base()
{
myExtraDataModel = theExtraDataModel;
}
private Model myExtraDataModel;
public override MTKConverter_ProcessData CreateProcessData(
Part thePart)
{
return new MTKConverter_MoldingData(thePart);
}
{
var aFaceIdSet = new HashSet<ulong>();
{
foreach (var aFace in aFaceIt)
{
aFaceIdSet.Add(aFace.Id());
}
}
for (uint i = 0; i < theFeatureList.
Size(); ++i)
{
foreach (var aFace in aFaceIt)
{
if (!aFaceIdSet.Contains(aFace.Id()))
{
myCurrentNewFaces.
Append(
Face.
Cast(aFace));
}
}
}
}
public override void ProcessSolid(MTKConverter_ProcessData theProcessData,
Solid theSolid)
{
var aMoldingData = theProcessData as MTKConverter_MoldingData;
anAnalyzer.
AddTool(aFeatureRecognizer);
{
return;
}
AddNewFacesFromFeatures(aFeatureList, theSolid);
aMoldingData.myFeatureList.Append(aFeatureList);
aMoldingData.myIssueList.Append(aAnalyzer.
Perform(aData));
}
public override void PostProcessPart(
Part thePart)
{
if (myCurrentNewFaces.
Shapes().Count == 0)
{
return;
}
anExtraDataPart.
AddBody(myCurrentNewFaces);
myExtraDataModel.
AddRoot(anExtraDataPart);
}
}
}
Provides an interface to run DFM Molding analysis.
Definition DFMMolding_Analyzer.cs:20
cadex.MTKBase_FeatureList Perform(cadex.ModelData.Solid theSolid, cadex.ProgressStatus theProgressStatus)
Runs DFM analysis process.
Definition DFMMolding_Analyzer.cs:95
Defines parameters used in injection molding design analysis.
Definition DFMMolding_AnalyzerParameters.cs:19
Describes a feature with assigned shape.
Definition MTKBase_ShapeFeature.cs:21
Defines a topological face.
Definition Face.cs:120
static cadex.ModelData.Face Cast(cadex.ModelData.Shape theShape)
Casts theShape to a face.
Definition Face.cs:260
cadex.UTF16String Name()
Returns empty string if the model element has no name (by default).
Definition ModelElement.cs:67
void SetUuid(System.Guid theUuid)
Sets an object uuid.
Definition ModelElement.cs:73
System.Guid Uuid()
Returns an object uuid.
Definition ModelElement.cs:86
Provides MTK data model.
Definition Model.cs:31
void AddRoot(cadex.ModelData.ModelElement theElement)
This function adds theElement as a root element in the model.
Definition Model.cs:133
void AddBody(cadex.ModelData.Body theBody)
Adds a body.
Definition Part.cs:69
Provides a sheet body composed of faces and shells.
Definition SheetBody.cs:19
Provides an interface to run several analyzer tools for different types of Molding processing.
Definition Molding_Analyzer.cs:21
void AddTool(cadex.Molding_AnalyzerTool theTool)
Adds additional tool to run during analyzing process.
Definition Molding_Analyzer.cs:103
cadex.Molding_Data Perform(cadex.ModelData.Solid theSolid, cadex.ProgressStatus theProgressStatus)
Runs the analyzing process.
Definition Molding_Analyzer.cs:80
Defines data used in Molding analysis.
Definition Molding_Data.cs:19
bool IsEmpty()
Returns true if the data is empty.
Definition Molding_Data.cs:85
cadex.MTKBase_FeatureList FeatureList()
Returns the feature list found during Molding feature recognizing process.
Definition Molding_Data.cs:79
Provides an interface to recognizing molding features.
Definition Molding_FeatureRecognizer.cs:21
MTKConverter_SheetMetalProcessor.cs
using System;
using System.Collections.Generic;
namespace mtkconverter
{
class MTKConverter_UnfoldedPartData
{
public MTKConverter_UnfoldedPartData()
{
myFlatPatterns = new List<SheetMetal_FlatPattern>();
}
public bool IsInit() { return myFlatPatterns.Count > 0; }
public List<SheetMetal_FlatPattern> myFlatPatterns;
}
class MTKConverter_SheetMetalData : MTKConverter_ProcessData
{
public MTKConverter_SheetMetalData(
Part thePart) : base(thePart)
{
myUnfoldedPartData = new MTKConverter_UnfoldedPartData();
}
public bool myIsSheetMetalPart = false;
public MTKConverter_UnfoldedPartData myUnfoldedPartData;
}
class MTKConverter_SheetMetalProcessor : MTKConverter_VoidPartProcessor
{
public MTKConverter_SheetMetalProcessor(
Model theUnfoldedModel) : base()
{
myUnfoldedModel = theUnfoldedModel;
}
private Model myUnfoldedModel;
public override MTKConverter_ProcessData CreateProcessData(
Part thePart)
{
return new MTKConverter_SheetMetalData(thePart);
}
public override void ProcessSolid(MTKConverter_ProcessData theProcessData,
Solid theSolid)
{
Process(theProcessData, anSMData);
}
public override void ProcessShell(MTKConverter_ProcessData theProcessData,
Shell theShell)
{
Process(theProcessData, anSMData);
}
public override void PostProcessPart(
Part thePart)
{
if (myCurrentUnfoldedBody.Shapes().Count == 0)
{
return;
}
anUnfoldedPart.
AddBody(myCurrentUnfoldedBody);
myUnfoldedModel.
AddRoot(anUnfoldedPart);
}
public void Process(MTKConverter_ProcessData theProcessData,
SheetMetal_Data theData)
{
{
return;
}
var anSMData = theProcessData as MTKConverter_SheetMetalData;
anSMData.myIsSheetMetalPart = true;
MTKConverter_UnfoldedPartData anUnfoldedData = anSMData.myUnfoldedPartData;
if (anUnfoldedShell != null)
{
myCurrentUnfoldedBody.Append(anUnfoldedShell);
anUnfoldedData.myFlatPatterns.Add(aFlatPattern);
aDrawingParams.SetIsIgnoreBendingLines(true);
Drawing aFlatPatternDrawing = aFlatPattern.
ToDrawing(aDrawingParams);
if (aFlatPatternDrawing != null)
{
while (aSheetIt.HasNext())
{
Sheet aSheet = aSheetIt.Next();
aSheet.
SetUuid(anSMData.myPart.Uuid());
}
Drawing aDrawing = myUnfoldedModel.
Drawing();
if (aDrawing == null)
{
myUnfoldedModel.
SetDrawing(aFlatPatternDrawing);
}
else
{
MTKConverter_DrawingProcessor.AddSheets(aFlatPatternDrawing, ref aDrawing);
myUnfoldedModel.SetDrawing(aDrawing);
}
}
}
for (uint i = 0; i < anIssueList.
Size(); ++i)
{
if (anUnfoldedData.IsInit()
{
anUnfoldedData.myIssueList.Append(anIssue);
}
else
{
anSMData.myIssueList.Append(anIssue);
}
}
}
}
}
Represents a single sheet of a model drawing.
Definition Sheet.cs:33
MTKConverter_NestingProcessor.cs
using System;
using System.Collections.Generic;
namespace mtkconverter
{
class MTKConverter_NestingData : MTKConverter_ProcessData
{
public MTKConverter_NestingData(List<Sheet> theSheets) : base(theSheets)
{
myPatterns = new List<View>();
}
public List<View> myPatterns;
public uint myPatternCountTotal = 0;
}
class MTKConverter_NestingProcessor : MTKConverter_DrawingProcessor
{
private static List<View> ExtractPatternViews(
Sheet theSheet)
{
List<View> aPatterns = new List<View>();
while (aViewIt.HasNext())
{
aPatterns.Add(aViewIt.Next());
}
return aPatterns;
}
private static void AssignSheetUuids(
Drawing theDrawing)
{
while (aSheetIt.HasNext())
{
Sheet aSheet = aSheetIt.Next();
aSheet.SetUuid(Guid.NewGuid());
}
}
{
double aDx = theEnd.
X() - theStart.X();
double aDy = theEnd.
Y() - theStart.Y();
double aLength = Math.Sqrt(aDx * aDx + aDy * aDy);
return aLine;
}
private static void AddNestingSheetFrames(
Drawing theDrawing)
{
while (aSheetIt.HasNext())
{
Sheet aSheet = aSheetIt.Next();
double aWidth = aSheet.
Width();
double aHeight = aSheet.
Height();
aFrameContour.
AddCurve(MakeTrimmedLine(aP1, aP2));
aFrameContour.
AddCurve(MakeTrimmedLine(aP2, aP3));
aFrameContour.
AddCurve(MakeTrimmedLine(aP3, aP4));
aFrameContour.
AddCurve(MakeTrimmedLine(aP4, aP1));
aFrameView.
Add(aFrameContour);
}
}
public MTKConverter_NestingProcessor(
MTKConverter_NestingParameters theNestingParameters) : base()
{
myProcessModel = theProcessModel;
myNestingParameters = theNestingParameters;
}
private MTKConverter_NestingData CreateProcessData(List<Sheet> theSheets)
{
return new MTKConverter_NestingData(theSheets);
}
private void Process(MTKConverter_NestingData theNestingData)
{
aComputer.
SetParameters(myNestingParameters.myComputerParameters);
myNestingParameters.myMaterialParameters.myLength,
myNestingParameters.myMaterialParameters.myWidth,
myNestingParameters.myMaterialParameters.myCount);
theNestingData.myPatternCountTotal =
(uint)(theNestingData.myPatterns.Count * myNestingParameters.myPatternRepeatCount);
foreach (
View aPattern
in theNestingData.myPatterns)
{
aComputer.AddPattern(aPattern, myNestingParameters.myPatternRepeatCount);
}
theNestingData.myNestingResult = aComputer.Perform();
}
private bool ProcessAllSheets(List<Sheet> theSourceSheets)
{
MTKConverter_NestingData aNestingData = CreateProcessData(theSourceSheets);
foreach (
Sheet aSourceSheet
in theSourceSheets)
{
List<View> aSheetPatterns = ExtractPatternViews(aSourceSheet);
aNestingData.myPatterns.AddRange(aSheetPatterns);
}
Process(aNestingData);
Drawing aResultNestingDrawing = aNestingData.myNestingResult.ToDrawing();
if (aResultNestingDrawing != null)
{
AddNestingSheetFrames(aResultNestingDrawing);
AssignSheetUuids(aResultNestingDrawing);
aNestingData.myResultDrawing = aResultNestingDrawing;
}
myProcessModel.SetDrawing(aResultNestingDrawing);
myData.Add(aNestingData);
return true;
}
private bool ProcessPerSheet(List<Sheet> theSourceSheets)
{
foreach (
Sheet aSourceSheet
in theSourceSheets)
{
MTKConverter_NestingData aNestingData = CreateProcessData(new List<Sheet> { aSourceSheet });
aNestingData.myPatterns = ExtractPatternViews(aSourceSheet);
Process(aNestingData);
Drawing aSourceNestingDrawing = aNestingData.myNestingResult.ToDrawing();
if (aSourceNestingDrawing != null)
{
AddNestingSheetFrames(aSourceNestingDrawing);
AssignSheetUuids(aSourceNestingDrawing);
aNestingData.myResultDrawing = aSourceNestingDrawing;
MTKConverter_DrawingProcessor.AddSheets(aSourceNestingDrawing, ref aResultNestingDrawing);
}
myData.Add(aNestingData);
}
myProcessModel.SetDrawing(aResultNestingDrawing);
return true;
}
public override bool Apply(
Drawing theDrawing)
{
myData.Clear();
List<Sheet> aSourceSheets = MTKConverter_DrawingProcessor.ExtractDrawingSheets(theDrawing);
if (aSourceSheets.Count == 0)
{
Console.WriteLine("\nERROR: Nesting requires at least one sheet in the source drawing.");
return false;
}
if (myNestingParameters.myMode == MTKConverter_NestingParameters.NestingMode.AllSheets)
{
return ProcessAllSheets(aSourceSheets);
}
return ProcessPerSheet(aSourceSheets);
}
private Model myProcessModel;
private MTKConverter_NestingParameters myNestingParameters;
}
}
Definition BaseObject.cs:68
Base class for all public classes.
Definition BaseObject.cs:21
Describes drawing elements composed connected 2D curves.
Definition PiecewiseContour.cs:20
bool AddCurve(cadex.Geom.Curve2d theCurve)
Adds a trimmed curve or a B-spline curve to the element.
Definition PiecewiseContour.cs:68
Iterates over views of a drawing sheet.
Definition Sheet.cs:176
double Height()
Returns the height of the sheet.
Definition Sheet.cs:127
void AddView(cadex.Drawing.View theView)
Adds a view to the sheet.
Definition Sheet.cs:161
double Width()
Returns the width of the sheet.
Definition Sheet.cs:117
Represents a view on a drawing sheet.
Definition View.cs:24
void Add(cadex.Drawing.Element theElement)
Adds an element to the view.
Definition View.cs:139
void SetTrim(double theFirst, double theLast)
Trims curve with [theFirst, theLast] section.
Definition Curve2d.cs:122
Defines a 2D Direction.
Definition Direction2d.cs:17
Defines 2D line.
Definition Line2d.cs:19
Defines a 3D point.
Definition Point2d.cs:17
The nesting analyzing tool.
Definition Nesting_Computer.cs:24
void AddMaterial(double theLength, double theWidth, uint theQuantity)
Configure material in which the patterns will be nested.
Definition Nesting_Computer.cs:94
Contains information about nesting sheets.
Definition Nesting_Data.cs:20
Contains classes, types, enums, and functions related to geometric entities.
Definition Axis1d.cs:12
MTKConverter_WallThicknessProcessor.cs
using mesh_colorizer;
namespace mtkconverter
{
class MTKConverter_WallThicknessData : MTKConverter_ProcessData
{
public MTKConverter_WallThicknessData(
Part thePart) : base(thePart)
{
}
public bool myIsInit = false;
public double myMinThickness = double.MaxValue;
public double myMaxThickness = -double.MaxValue;
public double myAvgThickness = 0.0;
public uint myThicknessPointCount = 0;
public PointPairType myMinThicknessPoints;
public PointPairType myMaxThicknessPoints;
}
class MTKConverter_WallThicknessProcessor : MTKConverter_VoidPartProcessor
{
public MTKConverter_WallThicknessProcessor(
MTKConverter_WallThicknessParameters theWallThicknessParameters) : base()
{
myColorizer = new MeshColorizer(theWallThicknessParameters.myColorSmoothness);
myExtraDataModel = theExtraDataModel;
}
private MeshColorizer myColorizer;
private Model myExtraDataModel;
public override MTKConverter_ProcessData CreateProcessData(
Part thePart)
{
return new MTKConverter_WallThicknessData(thePart);
}
{
{
return;
}
var aWTData = theProcessData as MTKConverter_WallThicknessData;
aWTData.myIsInit = true;
{
aWTData.myMinThicknessPoints = new PointPairType(aFirstPoint, aSecondPoint);
}
{
aWTData.myMaxThicknessPoints = new PointPairType(aFirstPoint, aSecondPoint);
}
double aThicknessSum = 0.0;
if (!aThicknessList.
IsEmpty())
{
uint aThicknessListSize = aThicknessList.
Size();
for (uint i = 0; i < aThicknessListSize; ++i)
{
aThicknessSum += aThicknessList.
Value(i);
}
uint aPrevThicknessPointCount = aWTData.myThicknessPointCount;
uint aTotalThicknessPointCount = aPrevThicknessPointCount + aThicknessListSize;
aWTData.myAvgThickness =
aWTData.myAvgThickness * ((double)aPrevThicknessPointCount / aTotalThicknessPointCount)
+ aThicknessSum / aTotalThicknessPointCount;
aWTData.myThicknessPointCount = aTotalThicknessPointCount;
}
var aColoredITS = myColorizer.Perform (theMesh, theResult);
if (myColoredITS != null)
{
}
else
{
myColoredITS = aColoredITS;
}
}
public override void ProcessSolid(MTKConverter_ProcessData theProcessData,
Solid theSolid)
{
if (aMesh != null)
{
}
}
public override void ProcessMesh(MTKConverter_ProcessData theProcessData,
IndexedTriangleSet theMesh)
{
ProcessResult(theProcessData, theMesh, aWTData);
}
public override void PostProcessPart(
Part thePart)
{
if (myColoredITS == null) {
return;
}
var anExtraDataPart =
new Part(thePart.
Name());
anExtraDataPart.SetUuid (thePart.
Uuid());
var aMeshBody =
new MeshBody(myColoredITS);
anExtraDataPart.AddBody(aMeshBody);
myExtraDataModel.
AddRoot(anExtraDataPart);
myColoredITS = null;
}
}
}
Defines a 3D point.
Definition Point.cs:17
Defines a list of double values.
Definition MTKBase_DoubleList.cs:20
uint Size()
Returns the number of elements in the list.
Definition MTKBase_DoubleList.cs:104
double Value(uint theIndex)
Access specified element.
Definition MTKBase_DoubleList.cs:93
Computes a bounding box for theShape, takes its maximum dimension and multiplies by thePrec.
Definition MeshGenerator.cs:36
void Generate(cadex.ModelData.Model theModel, bool theEnforceGeneration)
Generates a mesh for the model.
Definition MeshGenerator.cs:94
bool AddTriangles(cadex.Collections.PointList theVertices, cadex.Collections.IntList theVertexIndices)
The number of values ​​in theVertexIndices must be a multiple of three, since each triplet defines a ...
Definition IndexedTriangleSet.cs:128
The wall thickness analyzing tool.
Definition WallThickness_Analyzer.cs:22
Contains information about minimum and maximum wall thicknesses.
Definition WallThickness_Data.cs:17
cadex.MTKBase_DoubleList ThicknessList()
Returns full range of different thickness values found during wall thickness analysis.
Definition WallThickness_Data.cs:107
double MaxThickness()
Returns the maximum wall thickness in mm.
Definition WallThickness_Data.cs:78
bool IsEmpty()
Returns true if WallThickness_Data is empty.
Definition WallThickness_Data.cs:145
void PointsOfMaxThickness(cadex.Geom.Point theFirstPoint, cadex.Geom.Point theSecondPoint)
Returns points of maximum thickness.
Definition WallThickness_Data.cs:98
double MinThickness()
Returns the minimum wall thickness in mm.
Definition WallThickness_Data.cs:72
void PointsOfMinThickness(cadex.Geom.Point theFirstPoint, cadex.Geom.Point theSecondPoint)
Returns points of minimum thickness.
Definition WallThickness_Data.cs:88
Contains classes and functions related to model processing.
Definition MeshGenerator.cs:12
MTKConverter_Report.cs
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace mtkconverter
{
{
public Point(
double theX,
double theY,
double theZ)
{
X = theX;
Y = theY;
Z = theZ;
}
public double X { get; }
public double Y { get; }
public double Z { get; }
public override string ToString() => $"({FormattedString(X)}, {FormattedString(Y)}, {FormattedString(Z)})";
private string FormattedString(double theValue)
{
System.Globalization.CultureInfo aCI = new System.Globalization.CultureInfo("en-US");
return string.Format(aCI, "{0:0.00}", theValue);
}
}
class MTKConverter_Report
{
public MTKConverter_Report()
{
myData = new List<MTKConverter_ProcessData>();
}
private List<MTKConverter_ProcessData> myData;
public void AddData(MTKConverter_ProcessData theData)
{
myData.Add(theData);
}
private void WriteParameter<T>(JSONWriter theWriter, string theParamName, string theParamUnits, T theParamValue)
{
theWriter.OpenSection();
theWriter.WriteData("name", theParamName);
theWriter.WriteData("units", theParamUnits);
theWriter.WriteData("value", theParamValue);
theWriter.CloseSection();
}
private bool WriteFeatures(
JSONWriter theWriter,
string theGroupName,
string theSubgroupName,
string theMessageForEmptyList)
{
theWriter.OpenSection(theSubgroupName);
theWriter.WriteData("name", theGroupName);
if (theFeatures.
IsEmpty())
{
theWriter.WriteData("message", theMessageForEmptyList);
}
else
{
aParams.
SetStartIndentLevel(theWriter.NestingLevel());
string aFeaturesJSON = aJSONSerializer.
Serialize(theFeatures);
theWriter.WriteRawData(aFeaturesJSON);
}
theWriter.CloseSection();
return true;
}
{
switch (theOperation)
{
default: break;
}
return "CNC Machining";
}
{
for (int i = 0, n = theBodies.Count; i < n; ++i)
{
Body aBody = theBodies[i];
{
return true;
}
}
return false;
}
private void WriteThicknessNode(
JSONWriter theWriter,
string theParamName,
double theParamValue,
PointPairType thePoints,
string theNodeName)
{
theWriter.OpenSection(theNodeName);
theWriter.WriteData("name", theParamName);
theWriter.WriteData("units", "mm");
theWriter.WriteData("value", theParamValue);
theWriter.WriteData(
"firstPoint",
new Point(aFirstPoint.
X(), aFirstPoint.
Y(), aFirstPoint.
Z()));
theWriter.WriteData(
"secondPoint",
new Point(aSecondPoint.X(), aSecondPoint.Y(), aSecondPoint.Z()));
theWriter.CloseSection();
}
private void WriteWallThicknessData(JSONWriter theWriter, MTKConverter_WallThicknessData theData)
{
WriteThicknessNode(theWriter, "Minimum Thickness", theData.myMinThickness, theData.myMinThicknessPoints, "minThickness");
WriteThicknessNode(theWriter, "Maximum Thickness", theData.myMaxThickness, theData.myMaxThicknessPoints, "maxThickness");
theWriter.OpenArraySection("parameters");
WriteParameter(theWriter, "Minimum Thickness", "mm", theData.myMinThickness);
WriteParameter(theWriter, "Maximum Thickness", "mm", theData.myMaxThickness);
WriteParameter(theWriter, "Average Thickness", "mm", theData.myAvgThickness);
theWriter.CloseArraySection();
}
private void WriteUnfoldedPartFeatures(JSONWriter theWriter, MTKConverter_UnfoldedPartData theData)
{
theWriter.OpenSection("featureRecognitionUnfolded");
theWriter.WriteData("name", "Feature Recognition");
if (theData.IsInit())
{
aParams.SetStartIndentLevel(4);
string aFeaturesJSON = aJSONSerializer.Serialize(theData.myFlatPatterns[0]);
theWriter.WriteRawData(aFeaturesJSON);
}
else
{
theWriter.WriteData("message", "Unfolded part wasn't generated.");
}
theWriter.CloseSection();
}
private void WriteNestingData(
JSONWriter theWriter,
List<Sheet> theResultSheets,
List<double> theFreeSpaces,
uint thePatternCountTotal,
List<uint> theNestedPatternCounts)
{
theWriter.OpenSection("nesting");
theWriter.OpenArraySection("sheets");
for (int i = 0; i < theResultSheets.Count; ++i)
{
Sheet aResultSheet = theResultSheets[i];
double aFreeSpace = i < theFreeSpaces.Count ? theFreeSpaces[i] : 0.0;
uint aNestedPatternCount = i < theNestedPatternCounts.Count ? theNestedPatternCounts[i] : 0;
theWriter.OpenSection();
theWriter.WriteData(
"sheetId", aResultSheet.
Uuid());
theWriter.OpenArraySection("parameters");
WriteParameter(theWriter,
"Sheet Length",
"mm", aResultSheet.
Height());
WriteParameter(theWriter,
"Sheet Width",
"mm", aResultSheet.
Width());
WriteParameter(theWriter, "Free Space", "mm^2", aFreeSpace);
WriteParameter(theWriter, "Requested Pattern Count", "pcs", thePatternCountTotal);
WriteParameter(theWriter, "Nested Pattern Count", "pcs", aNestedPatternCount);
theWriter.CloseArraySection();
theWriter.CloseSection();
}
theWriter.CloseArraySection();
theWriter.CloseSection();
}
private void WriteUuidArray(JSONWriter theWriter, string theName, List<System.Guid> theUuids)
{
StringBuilder aStream = new StringBuilder();
string aCurrentIndent = new string(' ', theWriter.NestingLevel() * 4);
string aArrayValueIndent = new string(' ', (theWriter.NestingLevel() + 1) * 4);
aStream.Append(aCurrentIndent).Append('"').Append(theName).Append("\": [");
if (theUuids.Count > 0)
{
aStream.AppendLine();
for (int i = 0; i < theUuids.Count; ++i)
{
aStream.Append(aArrayValueIndent).Append('"').Append(theUuids[i]).Append('"');
if (i + 1 < theUuids.Count)
{
aStream.Append(",");
}
aStream.AppendLine();
}
aStream.Append(aCurrentIndent);
}
aStream.Append("]");
theWriter.WriteRawData(aStream.ToString());
}
private bool IsSheetProcessData(MTKConverter_ProcessData theProcessData)
{
return theProcessData is MTKConverter_NestingData;
}
private void WritePartProcessData(JSONWriter theWriter, MTKConverter_ProcessData theProcessData)
{
bool aRes = false;
theWriter.WriteData("partId", theProcessData.myPart.Uuid());
string anErrorMsg = "An error occurred while processing the part.";
if (theProcessData is MTKConverter_MachiningData)
{
MTKConverter_MachiningData aMD = (MTKConverter_MachiningData)theProcessData;
theWriter.WriteData("process", MachiningProcessName(aMD.myOperation));
cadex.Collections.BodyList aBodies = aMD.myPart.Bodies();
if (!aMD.myFeatureList.IsEmpty())
{
WriteFeatures(theWriter, "Feature Recognition", "featureRecognition", aMD.myFeatureList, "");
WriteFeatures(
theWriter,
"Design for Manufacturing",
"dfm",
aMD.myIssueList,
"Part contains no DFM improvement suggestions.");
aRes = true;
}
else if (!HasShapes(aBodies,
ShapeType.Solid))
{
anErrorMsg = "The part can't be analyzed due to lack of: BRep representation or solids in BRep representation.";
}
}
else if (theProcessData is MTKConverter_WallThicknessData)
{
MTKConverter_WallThicknessData aWTD = (MTKConverter_WallThicknessData)theProcessData;
theWriter.WriteData("process", "Wall Thickness Analysis");
cadex.Collections.BodyList aBodies = aWTD.myPart.Bodies();
if (aWTD.myIsInit)
{
WriteWallThicknessData(theWriter, aWTD);
aRes = true;
}
else if (!HasShapes(aBodies,
ShapeType.Solid))
{
anErrorMsg =
"The part can't be analyzed due to lack of: " +
"BRep representation, solids in BRep representation.";
}
}
else if (theProcessData is MTKConverter_MoldingData)
{
MTKConverter_MoldingData aMoldingData = (MTKConverter_MoldingData)theProcessData;
cadex.Collections.BodyList aBodies = aMoldingData.myPart.Bodies();
if (!aMoldingData.myFeatureList.IsEmpty())
{
theWriter.WriteData("process", "Molding Analysis");
WriteFeatures(theWriter, "Feature Recognition", "featureRecognition", aMoldingData.myFeatureList, "");
WriteFeatures(
theWriter,
"Design for Manufacturing",
"dfm",
aMoldingData.myIssueList,
"Part contains no DFM improvement suggestions.");
aRes = true;
}
else if (!HasShapes(aBodies,
ShapeType.Solid))
{
anErrorMsg =
"The part can't be analyzed due to lack of: " +
"BRep representation or solids in BRep representation.";
}
}
else if (theProcessData is MTKConverter_SheetMetalData)
{
MTKConverter_SheetMetalData aSMD = (MTKConverter_SheetMetalData)theProcessData;
theWriter.WriteData("process", "Sheet Metal");
cadex.Collections.BodyList aBodies = aSMD.myPart.Bodies();
if (aSMD.myIsSheetMetalPart)
{
WriteFeatures(
theWriter,
"Feature Recognition",
"featureRecognition",
aSMD.myFeatureList,
"Part contains no features.");
WriteFeatures(
theWriter,
"Design for Manufacturing",
"dfm",
aSMD.myIssueList,
"Part contains no DFM improvement suggestions.");
MTKConverter_UnfoldedPartData anUnfoldedPartData = aSMD.myUnfoldedPartData;
WriteUnfoldedPartFeatures(theWriter, anUnfoldedPartData);
if (anUnfoldedPartData.IsInit())
{
WriteFeatures(
theWriter,
"Design for Manufacturing",
"dfmUnfolded",
anUnfoldedPartData.myIssueList,
"Unfolded part contains no DFM improvement suggestions.");
}
aRes = true;
}
{
anErrorMsg =
"The part can't be analyzed due to lack of: " +
"BRep representation, solids and shells in BRep representation.";
}
else
{
anErrorMsg = "The part wasn't recognized as a sheet metal part.";
}
}
else
{
anErrorMsg = "Unrecognized process";
}
if (!aRes)
{
theWriter.WriteData("error", anErrorMsg);
}
}
private void WriteSheetProcessData(JSONWriter theWriter, MTKConverter_ProcessData theProcessData)
{
bool aRes = false;
if (theProcessData is MTKConverter_NestingData)
{
MTKConverter_NestingData aND = (MTKConverter_NestingData)theProcessData;
List<System.Guid> aSourceSheetUuids = new List<System.Guid>();
foreach (
Sheet aSheet
in aND.mySourceSheets)
{
aSourceSheetUuids.Add(aSheet.Uuid());
}
WriteUuidArray(theWriter, "sourceIds", aSourceSheetUuids);
List<Sheet> aResultSheets = MTKConverter_DrawingProcessor.ExtractDrawingSheets(aND.myResultDrawing);
List<double> aSheetFreeSpaces = new List<double>();
List<uint> aNestedPatternCounts = new List<uint>();
cadex.Collections.Nesting_SheetList aSheets = aND.myNestingResult.Sheets();
for (
int i = 0; i < aSheets.
Count; ++i)
{
var aSheet = aSheets[i];
aSheetFreeSpaces.
Add(aSheet.Scrap() * aSheet.SheetArea());
aNestedPatternCounts.Add(aSheet.NestedParts());
}
if (aResultSheets.Count > 0)
{
theWriter.WriteData("process", "Nesting");
WriteNestingData(
theWriter,
aResultSheets,
aSheetFreeSpaces,
aND.myPatternCountTotal,
aNestedPatternCounts);
aRes = true;
}
}
if (!aRes)
{
theWriter.WriteData("error", "An error occurred while processing the sheet.");
}
}
{
string aPath = thePath.
ToString();
if (File.Exists(aPath))
{
File.Delete(aPath);
}
try
{
using (StreamWriter aStream = File.CreateText(aPath))
{
JSONWriter aWriter = new JSONWriter(aStream);
aWriter.OpenSection();
aWriter.WriteData("version", "1");
if (myData.Count == 0)
{
aWriter.WriteData("error", "The model doesn't contain any parts.");
}
else
{
bool aHasPartProcessData = false;
bool aHasSheetProcessData = false;
foreach (MTKConverter_ProcessData aProcessData in myData)
{
if (IsSheetProcessData(aProcessData))
{
aHasSheetProcessData = true;
}
else
{
aHasPartProcessData = true;
}
}
if (aHasPartProcessData)
{
aWriter.OpenArraySection("parts");
foreach (MTKConverter_ProcessData aProcessData in myData)
{
if (IsSheetProcessData(aProcessData))
{
continue;
}
aWriter.OpenSection();
WritePartProcessData(aWriter, aProcessData);
aWriter.CloseSection();
}
aWriter.CloseArraySection();
}
if (aHasSheetProcessData)
{
aWriter.OpenArraySection("sheets");
foreach (MTKConverter_ProcessData aProcessData in myData)
{
if (!IsSheetProcessData(aProcessData))
{
continue;
}
aWriter.OpenSection();
WriteSheetProcessData(aWriter, aProcessData);
aWriter.CloseSection();
}
aWriter.CloseArraySection();
}
}
aWriter.CloseSection();
}
}
catch
{
return false;
}
return true;
}
}
}
Definition BodyList.cs:15
Serializes MTK entities into a JSON report.
Definition JSONSerializer.cs:17
Configuration for JSON serialization.
Definition JSONSerializerParameters.cs:21
Definition ArrayDouble2.cs:12
Contains utility classes that can be useful for debugging or configuring global settings.
Definition JSONSerializer.cs:12
MTKConverter_Application.cs
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
namespace mtkconverter
{
enum MTKConverter_ReturnCode
{
Ok = 0,
UnknownError = 1,
GeneralException = 2,
NoValidLicense = 3,
InvalidArgumentsNumber = 4,
InvalidArgument = 5,
UnsupportedVersion = 100,
UnexpectedFormat = 101,
UnsupportedFileVariant = 102,
ImportError = 103,
ProcessError = 200,
ExportError = 300
}
enum MTKConverter_ProcessType
{
Undefined = -1,
WallThickness = 0,
MachiningMilling,
MachiningTurning,
Molding,
SheetMetal,
Nesting
}
enum MTKConverter_ArgumentType
{
Neutral,
Import,
Process,
Export
}
class MTKConverter_Argument
{
public MTKConverter_Argument(MTKConverter_ArgumentType theType, string theValue)
{
myArgumentType = theType;
myValue = theValue;
}
public MTKConverter_ArgumentType myArgumentType;
public string myValue;
}
class MTKConverter_ImportParameters
{
public MTKConverter_ImportParameters()
{
myReaderParameters.SetReadPMI(false);
myReaderParameters.SetReadDrawing(false);
myReaderParameters.SetEnableAnalyticalRecognition(true);
}
}
class MTKConverter_NestingParameters
{
public enum NestingMode
{
PerSheet = 0,
AllSheets = 1
}
public class MaterialParameters
{
public double myLength = 500.0;
public double myWidth = 500.0;
public uint myCount = 1;
}
public MTKConverter_NestingParameters()
{
myComputerParameters = new Nesting_ComputerParameters();
myComputerParameters.SetIterationCount(20);
myComputerParameters.SetGenerationSize(3);
myComputerParameters.SetMutationRate(2.0);
myComputerParameters.SetCurveTolerance(100.0);
myComputerParameters.SetPartToPartDistance(0);
myComputerParameters.SetPartToSheetBoundaryDistance(0);
myComputerParameters.SetRotationCount(4);
myComputerParameters.SetMirrorControl(false);
myComputerParameters.SetNestingInHoles(false);
}
public MaterialParameters myMaterialParameters = new MaterialParameters();
public uint myPatternRepeatCount = 4;
public NestingMode myMode = NestingMode.PerSheet;
public Nesting_ComputerParameters myComputerParameters;
}
class MTKConverter_WallThicknessParameters
{
public MTKConverter_WallThicknessParameters() {
var aVoxelizationParameters = myAnalyzerParameters.VoxelizationParameters();
aVoxelizationParameters.SetResolution (800);
}
public double myColorSmoothness = 0.75;
}
class MTKConverter_ExportParameters
{
public bool myIsScreenshotGenerationEnabled = true;
public bool myIsExportMTKEnabled = false;
}
class MTKConverter_Parameters
{
public MTKConverter_ImportParameters myImportParameters = new MTKConverter_ImportParameters();
public MTKConverter_NestingParameters myNestingParameters = new MTKConverter_NestingParameters();
public MTKConverter_WallThicknessParameters myWallThicknessParameters = new MTKConverter_WallThicknessParameters();
public MTKConverter_ExportParameters myExportParameters = new MTKConverter_ExportParameters();
}
class MTKConverter_Application
{
private MTKConverter_ProcessType FindProcessType(string theProcessName)
{
var aProcessDictionary = new Dictionary<string, MTKConverter_ProcessType>()
{
{ "wall_thickness", MTKConverter_ProcessType.WallThickness },
{ "machining_milling", MTKConverter_ProcessType.MachiningMilling },
{ "machining_turning", MTKConverter_ProcessType.MachiningTurning },
{ "molding", MTKConverter_ProcessType.Molding },
{ "sheet_metal", MTKConverter_ProcessType.SheetMetal },
{ "nesting", MTKConverter_ProcessType.Nesting }
};
MTKConverter_ProcessType aProcessType;
if (aProcessDictionary.TryGetValue(theProcessName, out aProcessType))
{
return aProcessType;
}
return MTKConverter_ProcessType.Undefined;
}
private MTKConverter_ReturnCode Import(
string theFilePath,
MTKConverter_ImportParameters theImportParameters)
{
Console.Write($"Importing {theFilePath}...");
aReader.
SetParameters(theImportParameters.myReaderParameters);
if (!aReader.
Read(aFilePath, theModel))
{
Console.WriteLine($"\nERROR: Failed to import {theFilePath}. Exiting");
return MTKConverter_ReturnCode.ImportError;
}
return MTKConverter_ReturnCode.Ok;
}
private MTKConverter_ReturnCode ApplyPartProcessorToModel(
MTKConverter_Report theReport,
MTKConverter_PartProcessor theProcessor)
{
foreach (MTKConverter_ProcessData i in theProcessor.myData)
{
theReport.AddData(i);
}
return MTKConverter_ReturnCode.Ok;
}
private MTKConverter_ReturnCode ApplyDrawingProcessorToModel(
MTKConverter_Report theReport,
MTKConverter_DrawingProcessor theProcessor)
{
Drawing aDrawing = theProcessModel.Drawing();
if (aDrawing == null)
{
aDrawing = theModel.Drawing();
}
if (aDrawing == null)
{
Console.WriteLine("\nERROR: Drawing is required, but none was found in the process/source model.");
return MTKConverter_ReturnCode.ProcessError;
}
if (!theProcessor.Apply(aDrawing))
{
return MTKConverter_ReturnCode.ProcessError;
}
foreach (MTKConverter_ProcessData i in theProcessor.myData)
{
theReport.AddData(i);
}
return MTKConverter_ReturnCode.Ok;
}
private MTKConverter_ReturnCode Process(
string theProcess,
MTKConverter_Report theReport,
MTKConverter_Parameters theParameters)
{
Console.Write($"Processing {theProcess}...");
switch (FindProcessType(theProcess))
{
case MTKConverter_ProcessType.WallThickness:
{
MTKConverter_WallThicknessProcessor aProcessor =
new MTKConverter_WallThicknessProcessor(
theProcessModel,
theParameters.myWallThicknessParameters);
return ApplyPartProcessorToModel(theModel, theReport, aProcessor);
}
case MTKConverter_ProcessType.MachiningMilling:
{
MTKConverter_MachiningProcessor aProcessor =
return ApplyPartProcessorToModel(theModel, theReport, aProcessor);
}
case MTKConverter_ProcessType.MachiningTurning:
{
MTKConverter_MachiningProcessor aProcessor =
return ApplyPartProcessorToModel(theModel, theReport, aProcessor);
}
case MTKConverter_ProcessType.Molding:
{
MTKConverter_MoldingProcessor aProcessor = new MTKConverter_MoldingProcessor(theProcessModel);
return ApplyPartProcessorToModel(theModel, theReport, aProcessor);
}
case MTKConverter_ProcessType.SheetMetal:
{
MTKConverter_SheetMetalProcessor aProcessor = new MTKConverter_SheetMetalProcessor(theProcessModel);
return ApplyPartProcessorToModel(theModel, theReport, aProcessor);
}
case MTKConverter_ProcessType.Nesting:
{
MTKConverter_NestingProcessor aProcessor =
new MTKConverter_NestingProcessor(
theProcessModel,
theParameters.myNestingParameters);
return ApplyDrawingProcessorToModel(theModel, theProcessModel, theReport, aProcessor);
}
default:
return MTKConverter_ReturnCode.InvalidArgument;
}
}
private bool CreateOriginModelThumbnail(
UTF16String theFilePath,
Model theModel)
{
aParameters.
SetImageHeight(800);
aParameters.
SetImageWidth(600);
aParameters.
SetViewCameraProjection(CameraProjectionType.Perspective);
aParameters.
SetViewCameraPosition(CameraPositionType.Default);
aParameters.
SetViewIsFitAll(
true);
aParameters.
SetViewAntialiasing(AntialiasingMode.High);
aWriter.
SetParameters(aParameters);
return aWriter.
WriteFile(theModel, theFilePath);
}
private bool ExportMTKWEB(
string theFolderPath,
{
{
Console.WriteLine($"\nERROR: Failed to export {aPath}. Exiting");
return false;
}
return true;
}
private bool ExportMTK(
string theFolderPath,
{
string aSanitizedBaseName = theBaseName.ToString().Replace('.', '_');
{
Console.WriteLine($"\nERROR: Failed to save MTK model {aPath}. Exiting");
return false;
}
return true;
}
private MTKConverter_ReturnCode Export(
string theFolderPath,
MTKConverter_ExportParameters theExportParameters,
MTKConverter_Report theReport,
{
Console.Write($"Exporting {theFolderPath}...");
Directory.CreateDirectory(theFolderPath);
if (!ExportMTKWEB(theFolderPath, theModel, aModelBaseName))
{
return MTKConverter_ReturnCode.ExportError;
}
if (theExportParameters.myIsScreenshotGenerationEnabled && !CreateOriginModelThumbnail(aThumbnailPath, theModel))
{
Console.WriteLine($"\nERROR: Failed to create thumbnail {aThumbnailPath}. Exiting");
return MTKConverter_ReturnCode.ExportError;
}
if (!theProcessModel.
IsEmpty() || theProcessModel.Drawing() !=
null)
{
if (!ExportMTKWEB(theFolderPath, theProcessModel, aProcessedBaseName))
{
return MTKConverter_ReturnCode.ExportError;
}
if (theExportParameters.myIsExportMTKEnabled)
{
if (!ExportMTK(theFolderPath, theProcessModel, aProcessedBaseName))
{
return MTKConverter_ReturnCode.ExportError;
}
}
}
if (!theReport.WriteToJSON(aJsonPath))
{
Console.WriteLine($"\nERROR: Failed to create JSON file {aJsonPath}. Exiting");
return MTKConverter_ReturnCode.ExportError;
}
return MTKConverter_ReturnCode.Ok;
}
private MTKConverter_ReturnCode ParseArguments(
string[] args,
MTKConverter_Parameters theParameters,
List<MTKConverter_Argument> theArguments)
{
MTKConverter_ArgumentType anArgumentType = MTKConverter_ArgumentType.Neutral;
for (int i = 0; i < args.Length; ++i)
{
string anArgument = args[i];
if (anArgument == "--no-screenshot")
{
theParameters.myExportParameters.myIsScreenshotGenerationEnabled = false;
}
else if (anArgument == "--export_mtk")
{
theParameters.myExportParameters.myIsExportMTKEnabled = true;
}
else if (anArgument == "--sheet_size")
{
if (i + 2 >= args.Length)
{
Console.WriteLine("ERROR: Missing values for --sheet_size. Use --sheet_size <L> <W> with values > 0.");
return MTKConverter_ReturnCode.InvalidArgument;
}
double aSheetLength;
double aSheetWidth;
if (!double.TryParse(args[++i], NumberStyles.Float, CultureInfo.InvariantCulture, out aSheetLength) ||
!double.TryParse(args[++i], NumberStyles.Float, CultureInfo.InvariantCulture, out aSheetWidth) ||
aSheetLength <= 0.0 || aSheetWidth <= 0.0)
{
Console.WriteLine("ERROR: Invalid sheet size. Use --sheet_size <L> <W> with values > 0.");
return MTKConverter_ReturnCode.InvalidArgument;
}
theParameters.myNestingParameters.myMaterialParameters.myLength = aSheetLength;
theParameters.myNestingParameters.myMaterialParameters.myWidth = aSheetWidth;
}
else if (anArgument == "--pattern_count")
{
if (i + 1 >= args.Length)
{
Console.WriteLine("ERROR: Missing value for --pattern_count. Use --pattern_count <N> with value > 0.");
return MTKConverter_ReturnCode.InvalidArgument;
}
int aPatternRepeatCount;
if (!int.TryParse(args[++i], NumberStyles.Integer, CultureInfo.InvariantCulture, out aPatternRepeatCount) ||
aPatternRepeatCount <= 0)
{
Console.WriteLine("ERROR: Invalid pattern count. Use --pattern_count <N> with value > 0.");
return MTKConverter_ReturnCode.InvalidArgument;
}
theParameters.myNestingParameters.myPatternRepeatCount = (uint)aPatternRepeatCount;
}
else if (anArgument == "--nesting_mode")
{
if (i + 1 >= args.Length)
{
Console.WriteLine("ERROR: Missing value for --nesting_mode. Use --nesting_mode per_sheet|all_sheets.");
return MTKConverter_ReturnCode.InvalidArgument;
}
string aModeArg = args[++i];
if (aModeArg == "per_sheet")
{
theParameters.myNestingParameters.myMode = MTKConverter_NestingParameters.NestingMode.PerSheet;
}
else if (aModeArg == "all_sheets")
{
theParameters.myNestingParameters.myMode = MTKConverter_NestingParameters.NestingMode.AllSheets;
}
else
{
Console.WriteLine($"ERROR: Invalid nesting mode \"{aModeArg}\". Use --nesting_mode per_sheet|all_sheets.");
return MTKConverter_ReturnCode.InvalidArgument;
}
}
else if (anArgument == "-i")
{
anArgumentType = MTKConverter_ArgumentType.Import;
}
else if (anArgument == "-p")
{
anArgumentType = MTKConverter_ArgumentType.Process;
}
else if (anArgument == "-e")
{
anArgumentType = MTKConverter_ArgumentType.Export;
}
else
{
switch (anArgumentType)
{
case MTKConverter_ArgumentType.Import:
theArguments.Add(new MTKConverter_Argument(MTKConverter_ArgumentType.Import, anArgument));
break;
case MTKConverter_ArgumentType.Process:
{
MTKConverter_ProcessType aProcessType = FindProcessType(anArgument);
if (aProcessType == MTKConverter_ProcessType.Undefined)
{
Console.WriteLine($"ERROR: Unknown process \"{anArgument}\".");
Console.WriteLine("Type -h for recognized processes.");
return MTKConverter_ReturnCode.InvalidArgument;
}
if (aProcessType == MTKConverter_ProcessType.Nesting)
{
theParameters.myImportParameters.myReaderParameters.SetReadDrawing(true);
}
theArguments.Add(new MTKConverter_Argument(MTKConverter_ArgumentType.Process, anArgument));
break;
}
case MTKConverter_ArgumentType.Export:
theArguments.Add(new MTKConverter_Argument(MTKConverter_ArgumentType.Export, anArgument));
break;
default:
Console.WriteLine($"ERROR!: Invalid argument {anArgument}. Exiting");
Console.WriteLine("Type -h for help.");
return MTKConverter_ReturnCode.InvalidArgument;
}
}
}
if (theArguments.Count == 0)
{
Console.WriteLine("ERROR: No commands specified. Use -i/-p/-e.");
return MTKConverter_ReturnCode.InvalidArgument;
}
return MTKConverter_ReturnCode.Ok;
}
private MTKConverter_ReturnCode Execute(
List<MTKConverter_Argument> theArguments,
MTKConverter_Parameters theParameters)
{
MTKConverter_Report aReport = new MTKConverter_Report();
MTKConverter_ReturnCode aResultCode = MTKConverter_ReturnCode.Ok;
foreach (MTKConverter_Argument anArgument in theArguments)
{
if (aResultCode != MTKConverter_ReturnCode.Ok)
{
break;
}
try
{
switch (anArgument.myArgumentType)
{
case MTKConverter_ArgumentType.Import:
aProcessModel =
new Model();
aResultCode = Import(anArgument.myValue, aModel, theParameters.myImportParameters);
if (aResultCode == MTKConverter_ReturnCode.Ok)
{
aModel.AssignUuids();
}
break;
case MTKConverter_ArgumentType.Process:
aResultCode = Process(anArgument.myValue, aModel, aReport, aProcessModel, theParameters);
break;
case MTKConverter_ArgumentType.Export:
aResultCode = Export(
anArgument.myValue,
theParameters.myExportParameters,
aModel,
aReport,
aProcessModel);
break;
default:
aResultCode = MTKConverter_ReturnCode.InvalidArgument;
break;
}
if (aResultCode == MTKConverter_ReturnCode.Ok)
{
Console.WriteLine("Done.");
}
}
catch
{
Console.WriteLine("Failed.\nERROR: Unhandled exception caught.");
return MTKConverter_ReturnCode.GeneralException;
}
}
return aResultCode;
}
public MTKConverter_ReturnCode Run(string[] args)
{
if (args.Length == 0 ||
args[0] == "-?" || args[0] == "/?" || args[0] == "-h" || args[0] == "--help")
{
PrintUsage();
return MTKConverter_ReturnCode.Ok;
}
if (args.Length < 6)
{
Console.WriteLine("Invalid number of arguments. Please use \"-h\" or \"--help\" for usage information.");
return MTKConverter_ReturnCode.InvalidArgumentsNumber;
}
MTKConverter_Parameters aParameters = new MTKConverter_Parameters();
List<MTKConverter_Argument> anArguments = new List<MTKConverter_Argument>();
MTKConverter_ReturnCode aParseRes = ParseArguments(args, aParameters, anArguments);
if (aParseRes != MTKConverter_ReturnCode.Ok)
{
return aParseRes;
}
return Execute(anArguments, aParameters);
}
public void PrintUsage()
{
Console.WriteLine("Usage:");
Console.WriteLine("MTKConverter -i <import_file> -p <process> ... -e <export_target> [options]");
Console.WriteLine();
Console.WriteLine("Arguments:");
Console.WriteLine(" <import_file> - import file name");
Console.WriteLine(" <process> - manufacturing process or algorithm name");
Console.WriteLine(" <export_target> - export folder name");
Console.WriteLine();
Console.WriteLine("Export Options:");
Console.WriteLine(" --no-screenshot - disable screenshot generation (optional)");
Console.WriteLine(" --export_mtk - additionally save process model as *.mtk in <export_target>");
Console.WriteLine();
Console.WriteLine("Example:");
Console.WriteLine("MTKConverter -i C:\\models\\test.step -p machining_milling -e C:\\models\\out");
Console.WriteLine("MTKConverter -i C:\\models\\test.step -p nesting -e C:\\models\\out --export_mtk");
Console.WriteLine(
"MTKConverter -i C:\\models\\test.step -p sheet_metal -e C:\\models\\out -p nesting --nesting_mode all_sheets --sheet_size 500 500 --pattern_count 4 -e C:\\models\\out --export_mtk");
Console.WriteLine();
Console.WriteLine("Recognized processes:");
Console.WriteLine(" wall_thickness :\t Wall Thickness analysis");
Console.WriteLine(" machining_milling:\t CNC Machining Milling feature recognition and DFM analysis");
Console.WriteLine(" machining_turning:\t CNC Machining Lathe+Milling feature recognition and DFM analysis");
Console.WriteLine(" molding :\t Molding feature recognition and DFM analysis");
Console.WriteLine(" sheet_metal :\t Sheet Metal feature recognition, unfolding and DFM analysis");
Console.WriteLine(" nesting :\t Nesting using source drawing or sheet metal unfolding drawing");
Console.WriteLine(" parameters :\t --sheet_size <L> <W> (default: 500 500)");
Console.WriteLine(" :\t --pattern_count <N> (default: 4)");
Console.WriteLine(" :\t --nesting_mode per_sheet|all_sheets (default: per_sheet)");
}
}
}
Defines an RGBA color (with alpha channel).
Definition Color.cs:19
Defines a visitor that visits each unique element only once.
Definition ModelElementUniqueVisitor.cs:25
void Accept(cadex.ModelData.ModelElementVisitor theVisitor)
Accepts a visitor.
Definition Model.cs:179
FileFormatType
Defines supported formats for export.
Definition Model.cs:242
void SetName(cadex.UTF16String theName)
Accepts a string as a unicode string.
Definition Model.cs:81
bool IsEmpty()
Returns true if the model has no roots, i.e.
Definition Model.cs:100
cadex.UTF16String Name()
Returns empty string if the model has no name (by default).
Definition Model.cs:90
Reads supported formats, see Import section.
Definition ModelReader.cs:17
bool Read(cadex.UTF16String theFilePath, cadex.ModelData.Model theModel)
Reads the file at the specified path into the specified model.
Definition ModelReader.cs:82
Defines parameters of the ModelReader.
Definition ModelReaderParameters.cs:19
Defines color background style.
Definition ColorBackgroundStyle.cs:17
Writes an image file with graphical content of a model.
Definition ImageWriter.cs:17
Defines parameters of the ImageWriter.
Definition ImageWriterParameters.cs:17
The wall thickness analyzer parameters.
Definition WallThickness_AnalyzerParameters.cs:19
Contains classes, types, enums, and functions related to image generation.
Definition AntialiasingMode.cs:12
Program.cs
using System;
namespace mtkconverter
{
class Program
{
static int Main(string[] args)
{
string aKey = MTKLicenseKey.Value();
{
Console.WriteLine("Failed to activate Manufacturing Toolkit license.");
return 1;
}
MTKConverter_Application anApp = new MTKConverter_Application();
return (int)anApp.Run(args);
}
}
}
Activates the license key.
Definition LicenseManager.cs:48