Refer to the MTK Converter Example
MTKConverter_PartProcessor.hxx
#ifndef _MTKConverter_PartProcessor_HeaderFile
#define _MTKConverter_PartProcessor_HeaderFile
#include <cadex/ModelData/Model.hxx>
#include <cadex/ModelData/Part.hxx>
#include <deque>
namespace ModelData {
class Shell;
class Solid;
}
}
class MTKConverter_ProcessData
{
protected:
{}
public:
virtual ~MTKConverter_ProcessData() {}
};
{
public:
typedef std::shared_ptr<MTKConverter_ProcessData> DataType;
virtual ~MTKConverter_PartProcessor() {}
std::deque<DataType> myData;
protected:
};
class MTKConverter_VoidPartProcessor : public MTKConverter_PartProcessor
{
protected:
};
#endif
Element visitor with empty implementation.
Definition ModelElementVoidVisitor.cs:20
Defines a leaf node in the scene graph hierarchy.
Definition Part.cs:23
Defines a connected set of faces.
Definition Shell.cs:29
Defines a topological solid.
Definition Solid.cs:25
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.
Definition BaseObject.cs:12
MTKConverter_PartProcessor.cxx
#include <cadex/ModelData/Body.hxx>
#include <cadex/ModelData/Shell.hxx>
#include <cadex/ModelData/Solid.hxx>
#include <MTKConverter_PartProcessor.hxx>
void MTKConverter_PartProcessor::operator() (
const ModelData::Part& thePart)
{
bool aPartWasProcessed = false;
auto aProcessData = CreateProcessData (thePart);
const auto& aBodies = thePart.
Bodies();
for (const auto& aBody : aBodies) {
while (aShapeIt.
HasNext()) {
const auto& aShape = aShapeIt.
Next();
if (aShape.Type() == ModelData::ShapeType::Solid) {
ProcessSolid (aProcessData, ModelData::Solid::Cast (aShape));
aPartWasProcessed = true;
} else if (aShape.Type() == ModelData::ShapeType::Shell) {
ProcessShell (aProcessData, ModelData::Shell::Cast (aShape));
aPartWasProcessed = true;
}
}
}
if (aPartWasProcessed) {
PostProcessPart (thePart);
myData.push_back (aProcessData);
}
}
Iterates over subshapes in a shape.
Definition ShapeIterator.cs:58
MTKConverter_MachiningProcessor.hxx
#ifndef _MTKConverter_MachiningProcessor_HeaderFile
#define _MTKConverter_MachiningProcessor_HeaderFile
#include <cadex/Machining_OperationType.hxx>
#include <cadex/MTKBase_FeatureList.hxx>
#include <MTKConverter_PartProcessor.hxx>
namespace ModelData {
class Part;
class Solid;
}
}
class MTKConverter_MachiningData : public MTKConverter_ProcessData
{
public:
{}
};
class MTKConverter_MachiningProcessor : public MTKConverter_VoidPartProcessor
{
public:
{}
protected:
};
#endif
Defines a list of features.
Definition MTKBase_FeatureList.cs:20
Machining_OperationType
Defines an operation type in machining.
Definition Machining_OperationType.cs:19
MTKConverter_MachiningProcessor.cxx
#include <cadex/DFMMachining_Analyzer.hxx>
#include <cadex/DFMMachining_DeepPocketIssue.hxx>
#include <cadex/DFMMachining_DrillingAnalyzerParameters.hxx>
#include <cadex/DFMMachining_MillingAnalyzerParameters.hxx>
#include <cadex/DFMMachining_TurningAnalyzerParameters.hxx>
#include <cadex/Machining_Analyzer.hxx>
#include <cadex/Machining_Data.hxx>
#include <cadex/Machining_FeatureRecognizer.hxx>
#include <cadex/Machining_FeatureRecognizerParameters.hxx>
#include <cadex/ModelData/Solid.hxx>
#include <cadex/MTKBase_FeatureList.hxx>
#include <MTKConverter_MachiningProcessor.hxx>
MTKConverter_MachiningProcessor::DataType
MTKConverter_MachiningProcessor::CreateProcessData (
const ModelData::Part& thePart)
const
{
return std::make_shared<MTKConverter_MachiningData> (thePart);
}
void MTKConverter_MachiningProcessor::ProcessSolid (DataType& theProcessData,
const ModelData::Solid& theSolid)
{
auto aMachiningData = std::static_pointer_cast<MTKConverter_MachiningData> (theProcessData);
aMachiningData->myOperation = myOperation;
anAnalyzer.
AddTool (aFeatureRecognizer);
auto aData = anAnalyzer.
Perform (theSolid);
if (aData.IsEmpty()) {
return;
}
aMachiningData->myFeatureList.Append (aData.FeatureList());
aMachiningData->myIssueList.Append (aDrillingAnalyzer.Perform (theSolid, aData));
for (
size_t i = 0; i < aMillingIssueList.
Size(); ++i) {
const auto& anIssue = aMillingIssueList[i];
if (myOperation == Machining_OT_LatheMilling
continue;
}
aMachiningData->myIssueList.
Append (anIssue);
}
if (myOperation == Machining_OT_LatheMilling) {
for (
size_t i = 0; i < aTurningIssueList.
Size(); ++i) {
const auto& anIssue = aTurningIssueList[i];
aMachiningData->myIssueList.Append (anIssue);
}
}
}
Provides an interface to run DFM Machining analysis.
Definition DFMMachining_Analyzer.cs:43
Describes deep pocket issue found during cnc machining milling design analysis.
Definition DFMMachining_DeepPocketIssue.cs:39
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
uint Size()
Returns the number of elements in the list.
Definition MTKBase_FeatureList.cs:110
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:81
void AddTool(cadex.Machining_AnalyzerTool theTool)
Adds additional tool to run during analyzing process.
Definition Machining_Analyzer.cs:108
Provides an interface to recognizing machining features tool.
Definition Machining_FeatureRecognizer.cs:24
cadex.Machining_FeatureRecognizerParameters Parameters()
Definition Machining_FeatureRecognizer.cs:115
void SetOperation(cadex.Machining_OperationType theOperation)
Definition Machining_FeatureRecognizerParameters.cs:208
MTKConverter_SheetMetalProcessor.hxx
#ifndef _MTKConverter_SheetMetalProcessor_HeaderFile
#define _MTKConverter_SheetMetalProcessor_HeaderFile
#include <cadex/ModelData/SheetBody.hxx>
#include <cadex/ModelData/Shell.hxx>
#include <cadex/MTKBase_FeatureList.hxx>
#include <cadex/SheetMetal_Analyzer.hxx>
#include <cadex/SheetMetal_Data.hxx>
#include <cadex/SheetMetal_FlatPattern.hxx>
#include <MTKConverter_PartProcessor.hxx>
class MTKConverter_UnfoldedPartData
{
public:
MTKConverter_UnfoldedPartData()
{}
bool IsInit() const { return !myFlatPatterns.empty(); }
std::deque<cadex::SheetMetal_FlatPattern> myFlatPatterns;
};
class MTKConverter_SheetMetalData : public MTKConverter_ProcessData
{
public:
bool myIsSheetMetalPart = false;
MTKConverter_UnfoldedPartData myUnfoldedPartData;
};
class MTKConverter_SheetMetalProcessor : public MTKConverter_VoidPartProcessor
{
public:
protected:
};
#endif
Provides MTK data model.
Definition Model.cs:30
Provides a sheet body composed of faces and shells.
Definition SheetBody.cs:19
MTKConverter_SheetMetalProcessor.cxx
#include <cadex/DFMSheetMetal_Analyzer.hxx>
#include <cadex/DFMSheetMetal_FlatPatternInterferenceIssue.hxx>
#include <cadex/DFMSheetMetal_NonStandardSheetSizeIssue.hxx>
#include <cadex/DFMSheetMetal_NonStandardSheetThicknessIssue.hxx>
#include <cadex/Geom/Transformation.hxx>
#include <cadex/Measurements/BoundingBox.hxx>
#include <cadex/Measurements/ValidationProperties.hxx>
#include <cadex/Measurements/ValidationPropertyData.hxx>
#include <cadex/ModelData/Box.hxx>
#include <cadex/ModelData/Shell.hxx>
#include <cadex/ModelData/SheetBody.hxx>
#include <cadex/ModelData/Solid.hxx>
#include <cadex/SheetMetal_Analyzer.hxx>
#include <cadex/SheetMetal_Data.hxx>
#include <cadex/SheetMetal_FeatureRecognizer.hxx>
#include <cadex/SheetMetal_FlatPattern.hxx>
#include <cadex/SheetMetal_Unfolder.hxx>
#include <MTKConverter_SheetMetalProcessor.hxx>
#include <vector>
MTKConverter_ProcessData (thePart)
{}
myUnfoldedModel (theUnfoldedModel)
{
}
MTKConverter_SheetMetalProcessor::DataType
MTKConverter_SheetMetalProcessor::CreateProcessData (
const ModelData::Part& thePart)
const
{
return std::make_shared<MTKConverter_SheetMetalData> (thePart);
}
void MTKConverter_SheetMetalProcessor::ProcessSolid (DataType& theProcessData,
{
auto anSMData = myAnalyzer.Perform (theSolid);
Process (theProcessData, anSMData);
}
void MTKConverter_SheetMetalProcessor::ProcessShell (DataType& theProcessData,
{
auto anSMData = myAnalyzer.Perform (theShell);
Process (theProcessData, anSMData);
}
void MTKConverter_SheetMetalProcessor::PostProcessPart (
const ModelData::Part& thePart)
{
if (myCurrentUnfoldedBody.Shapes().empty()) {
return;
}
anUnfoldedPart.SetUuid (thePart.
Uuid());
anUnfoldedPart.AddBody (myCurrentUnfoldedBody);
myUnfoldedModel.AddRoot (anUnfoldedPart);
}
void MTKConverter_SheetMetalProcessor::Process (DataType& theProcessData,
{
return;
}
auto anSMData = std::static_pointer_cast<MTKConverter_SheetMetalData> (theProcessData);
anSMData->myIsSheetMetalPart = true;
anSMData->myFeatureList.Append (theData.
FeatureList());
auto& anUnfoldedData = anSMData->myUnfoldedPartData;
if (anUnfoldedShell) {
myCurrentUnfoldedBody.Append (anUnfoldedShell);
anUnfoldedData.myFlatPatterns.push_back (aFlatPattern);
}
auto anIssueList = aDFMAnalyzer.
Perform (theData);
for (size_t i = 0; i < anIssueList.Size(); ++i) {
const auto& anIssue = anIssueList[i];
if (anUnfoldedData.IsInit()
anUnfoldedData.myIssueList.Append (anIssue);
} else {
anSMData->myIssueList.Append (anIssue);
}
}
}
cadex.UTF16String Name()
Returns a name.
Definition ModelElement.cs:67
System.Guid Uuid()
Returns an object uuid.
Definition ModelElement.cs:86
MTKConverter_Report.hxx
#ifndef _MTKConverter_Report_HeaderFile
#define _MTKConverter_Report_HeaderFile
#include <deque>
#include <memory>
class UTF16String;
}
class MTKConverter_ProcessData;
class MTKConverter_Report
{
public:
typedef std::shared_ptr<MTKConverter_ProcessData> DataType;
void AddData (const DataType& theData) { myData.push_back (theData); }
private:
std::deque<DataType> myData;
};
#endif
Defines a Unicode (UTF-16) string wrapping a standard string.
Definition UTF16String.cs:17
MTKConverter_Report.cxx
#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif
#include <cadex/Utilities/JSONSerializer.hxx>
#include <MTKConverter_Report.hxx>
#include <MTKConverter_MachiningProcessor.hxx>
#include <MTKConverter_MoldingProcessor.hxx>
#include <MTKConverter_SheetMetalProcessor.hxx>
#include <MTKConverter_WallThicknessProcessor.hxx>
#include <../../helpers/JSONWriter.hxx>
#include <fstream>
#include <iomanip>
#include <sstream>
namespace Geom {
inline std::ostream& operator<< (std::ostream& theStream, const Point& thePoint)
{
return theStream << "(" << thePoint.X() << ", " << thePoint.Y() << ", " << thePoint.Z() << ")";
}
}}
namespace {
template <typename T>
void WriteParameter (JSONWriter& theWriter, const char* theParamName, const char* theParamUnits, const T& theParamValue)
{
theWriter.OpenSection();
theWriter.WriteData ("name", theParamName);
theWriter.WriteData ("units", theParamUnits);
theWriter.WriteData ("value", theParamValue);
theWriter.CloseSection();
}
bool WriteFeatures (JSONWriter& theWriter,
const char* theGroupName,
const char* theSubgroupName,
const char* theMessageForEmptyList)
{
theWriter.OpenSection (theSubgroupName);
theWriter.WriteData ("name", theGroupName);
if (theFeatures.
IsEmpty()) {
theWriter.WriteData ("message", theMessageForEmptyList);
} else {
aParams.
SetStartIndentLevel (theWriter.NestingLevel());
auto aFeaturesJSON = aJSONSerializer.Serialize (theFeatures);
theWriter.WriteRawData (aFeaturesJSON);
}
theWriter.CloseSection();
return true;
}
{
switch (theOperation) {
default:
break;
}
return "CNC Machining";
}
{
for (const auto& aBody : theBodies) {
if (aShapeIt.HasNext()) {
return true;
}
}
return false;
}
void WriteThicknessNode (JSONWriter& theWriter,
const char* theParamName,
double theParamValue,
const PointPairType& thePoints,
const char* theNodeName)
{
std::stringstream aStream;
aStream << std::fixed << std::setprecision (2);
JSONWriter aWriter (aStream, 3);
aWriter.OpenSection (theNodeName);
aWriter.WriteData ("name", theParamName);
aWriter.WriteData ("units", "mm");
aWriter.WriteData ("value", theParamValue);
aWriter.WriteData ("firstPoint", thePoints.first);
aWriter.WriteData ("secondPoint", thePoints.second);
aWriter.CloseSection();
theWriter.WriteRawData (aStream.str());
}
void WriteWallThicknessData (JSONWriter& theWriter, const std::shared_ptr<MTKConverter_WallThicknessData>& theWTData)
{
WriteThicknessNode (theWriter, "Minimum Thickness", theWTData->myMinThickness, theWTData->myMinThicknessPoints, "minThickness");
WriteThicknessNode (theWriter, "Maximum Thickness", theWTData->myMaxThickness, theWTData->myMaxThicknessPoints, "maxThickness");
theWriter.OpenArraySection ("parameters");
WriteParameter (theWriter, "Minimum Thickness", "mm", theWTData->myMinThickness);
WriteParameter (theWriter, "Maximum Thickness", "mm", theWTData->myMaxThickness);
WriteParameter (theWriter, "Average Thickness", "mm", theWTData->myAvgThickness);
theWriter.CloseArraySection();
}
void WriteUnfoldedPartFeatures (JSONWriter& theWriter,
const MTKConverter_UnfoldedPartData& theData)
{
theWriter.OpenSection ("featureRecognitionUnfolded");
theWriter.WriteData ("name", "Feature Recognition");
if (theData.IsInit()) {
aParams.SetStartIndentLevel (4);
auto aFeaturesJSON = aJSONSerializer.Serialize (theData.myFlatPatterns[0]);
theWriter.WriteRawData (aFeaturesJSON);
} else {
theWriter.WriteData ("message", "Unfolded part wasn't generated.");
}
theWriter.CloseSection();
}
typedef std::shared_ptr<MTKConverter_ProcessData> DataType;
void WritePartProcessData (JSONWriter& theWriter, const DataType& theProcessData)
{
bool aRes = false;
theWriter.WriteData ("partId", theProcessData->myPart.Uuid());
std::string anErrorMsg = "An error occurred while processing the part.";
if (theProcessData) {
if (auto aMD = std::dynamic_pointer_cast<MTKConverter_MachiningData> (theProcessData)) {
theWriter.WriteData ("process", MachiningProcessName (aMD->myOperation));
const auto& 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 (aBodies.empty() || !HasShapes (aBodies, ModelData::ShapeType::Solid)) {
anErrorMsg = "The part can't be analyzed due to lack of: "
"BRep representation or solids in BRep representation.";
}
} else if (auto aWTD = std::dynamic_pointer_cast<MTKConverter_WallThicknessData> (theProcessData)) {
theWriter.WriteData ("process", "Wall Thickness Analysis");
const auto& aBodies = aWTD->myPart.Bodies();
if (aWTD->myIsInit) {
WriteWallThicknessData (theWriter, aWTD);
aRes = true;
} else if ((aBodies.empty() || !HasShapes (aBodies, ModelData::ShapeType::Solid))) {
anErrorMsg = "The part can't be analyzed due to lack of: "
"BRep representation, solids in BRep representation.";
}
} else if (auto aMoldingData = std::dynamic_pointer_cast<MTKConverter_MoldingData> (theProcessData)) {
const auto& 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 (aBodies.empty() || !HasShapes (aBodies, ModelData::ShapeType::Solid)) {
anErrorMsg = "The part can't be analyzed due to lack of: "
"BRep representation or solids in BRep representation.";
}
} else if (auto aSMD = std::dynamic_pointer_cast<MTKConverter_SheetMetalData> (theProcessData)) {
theWriter.WriteData ("process", "Sheet Metal");
const auto& 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.");
const auto& 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;
} else if (aBodies.empty() || (!HasShapes (aBodies, ModelData::ShapeType::Solid) && !HasShapes (aBodies, ModelData::ShapeType::Shell))) {
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);
}
}
}
bool MTKConverter_Report::WriteToJSON (
const UTF16String& thePath)
const
{
std::ofstream aFile (thePath.
ToString());
if (!aFile) {
return false;
}
JSONWriter aWriter (aFile);
aWriter.OpenSection();
aWriter.WriteData ("version", "1");
if (myData.empty()) {
aWriter.WriteData ("error", "The model doesn't contain any parts.");
} else {
aWriter.OpenArraySection ("parts");
for (const auto& aProcessData : myData) {
aWriter.OpenSection();
WritePartProcessData (aWriter, aProcessData);
aWriter.CloseSection();
}
aWriter.CloseArraySection();
}
aWriter.CloseSection();
return true;
}
Serializes MTK entities into a JSON report.
Definition JSONSerializer.cs:17
Configuration for JSON serialization.
Definition JSONSerializerParameters.cs:20
ShapeType
Defines shape type.
Definition ShapeType.cs:17
Contains utility classes that can be useful for debugging or configuring global settings.
Definition JSONSerializer.cs:12
@ Machining_OT_LatheMilling
Lathe + Milling operation type.
@ Machining_OT_Milling
Milling operation type.
MTKConverter_Application.hxx
#ifndef _MTKConverter_Application_HeaderFile
#define _MTKConverter_Application_HeaderFile
enum MTKConverter_ReturnCode
{
MTKConverter_RC_OK = 0,
MTKConverter_RC_UnknownError = 1,
MTKConverter_RC_GeneralException = 2,
MTKConverter_RC_NoValidLicense = 3,
MTKConverter_RC_InvalidArgumentsNumber = 4,
MTKConverter_RC_InvalidArgument = 5,
MTKConverter_RC_UnsupportedVersion = 100,
MTKConverter_RC_UnexpectedFormat = 101,
MTKConverter_RC_UnsupportedFileVariant = 102,
MTKConverter_RC_ImportError = 103,
MTKConverter_RC_ProcessError = 200,
MTKConverter_RC_ExportError = 300,
};
class MTKConverter_Application
{
public:
MTKConverter_Application();
MTKConverter_ReturnCode Run (int argc, char *argv[]) const;
void PrintUsage() const;
};
#endif
MTKConverter_Application.cxx
#include <cadex/Materials/Color.hxx>
#include <cadex/ModelData/Model.hxx>
#include <cadex/ModelData/ModelReader.hxx>
#include <cadex/View/ImageWriter.hxx>
#include <cadex/View/ImageWriterParameters.hxx>
#include <MTKConverter_Application.hxx>
#include <MTKConverter_MachiningProcessor.hxx>
#include <MTKConverter_MoldingProcessor.hxx>
#include <MTKConverter_Report.hxx>
#include <MTKConverter_SheetMetalProcessor.hxx>
#include <MTKConverter_WallThicknessProcessor.hxx>
#include <cstring>
#include <iostream>
#include <unordered_map>
#if defined(__GNUC__)
#include <sys/stat.h>
#elif !defined(_MSC_VER) || _MSC_VER > 1900
#include <filesystem>
#endif
namespace {
enum MTKConverter_ProcessType
{
MTKConverter_PT_Undefined = -1,
MTKConverter_PT_WallThickness = 0,
MTKConverter_PT_MachiningMilling,
MTKConverter_PT_MachiningTurning,
MTKConverter_PT_Molding,
MTKConverter_PT_SheetMetal
};
MTKConverter_ProcessType ProcessType (
const UTF16String& theProcessName)
{
static std::unordered_map<UTF16String, MTKConverter_ProcessType, UTF16StringHash> aProcessMap
{
{"wall_thickness" , MTKConverter_PT_WallThickness},
{"machining_milling", MTKConverter_PT_MachiningMilling},
{"machining_turning", MTKConverter_PT_MachiningTurning},
{"molding" , MTKConverter_PT_Molding},
{"sheet_metal" , MTKConverter_PT_SheetMetal}
};
auto aRes = aProcessMap.find (theProcessName);
if (aRes != aProcessMap.end()) {
return aRes->second;
}
return MTKConverter_PT_Undefined;
}
{
std::cout << "Importing " << theFilePath << "..." << std::flush;
if (!aReader.
Read (theFilePath, theModel)) {
std::cerr << std::endl << "ERROR: Failed to import " << theFilePath << ". Exiting" << std::endl;
return MTKConverter_RC_ImportError;
}
return MTKConverter_RC_OK;
}
{
auto aParameters = aWriter.
Parameters();
aParameters.
SetImageHeight (800);
aParameters.SetImageWidth (600);
aParameters.SetViewCameraProjection (View::CameraProjectionType::Perspective);
aParameters.SetViewCameraPosition (View::CameraPositionType::Default);
aParameters.SetViewIsFitAll (true);
aParameters.SetViewAntialiasing (View::AntialiasingMode::High);
aWriter.
SetParameters (aParameters);
bool aRes = aWriter.
WriteFile (theModel, theFilePath);
return aRes;
}
MTKConverter_ReturnCode Process (
const UTF16String& theProcess,
MTKConverter_Report& theReport,
{
std::cout << "Processing " << theProcess << "..." << std::flush;
auto ApplyProcessorToModel = [&theModel, &theReport] (MTKConverter_PartProcessor& theProcessor) {
for (const auto& i : theProcessor.myData) {
theReport.AddData (i);
}
};
auto aProcessType = ProcessType (theProcess);
switch (aProcessType) {
case MTKConverter_PT_WallThickness:
{
MTKConverter_WallThicknessProcessor aProcessor (theProcessModel, 800);
ApplyProcessorToModel (aProcessor);
break;
}
case MTKConverter_PT_MachiningMilling:
{
MTKConverter_MachiningProcessor aProcessor (Machining_OT_Milling);
ApplyProcessorToModel (aProcessor);
break;
}
case MTKConverter_PT_MachiningTurning:
{
MTKConverter_MachiningProcessor aProcessor (Machining_OT_LatheMilling);
ApplyProcessorToModel (aProcessor);
break;
}
case MTKConverter_PT_Molding:
{
MTKConverter_MoldingProcessor aProcessor (theProcessModel);
ApplyProcessorToModel (aProcessor);
break;
}
case MTKConverter_PT_SheetMetal:
{
theProcessModel.
SetName (theModel.
Name() +
"_unfolded");
MTKConverter_SheetMetalProcessor aProcessor (theProcessModel);
ApplyProcessorToModel (aProcessor);
break;
}
case MTKConverter_PT_Undefined:
default : return MTKConverter_RC_InvalidArgument;
}
return MTKConverter_RC_OK;
}
MTKConverter_ReturnCode Export (
const UTF16String& theFolderPath,
const bool theToGenerateScreenshot,
const MTKConverter_Report& theReport,
{
std::cout << "Exporting " << theFolderPath << "..." << std::flush;
#if defined(_MSC_VER) && _MSC_VER < 1910
(void)theReport;
(void)theModel;
(void)theProcessModel;
std::cout << "Use the Microsoft Visual C++ 2019 (VC14.2) compiler or newer." << std::flush;
return MTKConverter_RC_OK;
#else
#if defined(__GNUC__)
mkdir (theFolderPath.ToString().c_str(), 0755);
#else
std::filesystem::create_directory (theFolderPath.ToString());
#endif
UTF16String aModelPath = theFolderPath +
"/" + theModel.
Name() +
".mtkweb" +
"/scenegraph.mtkweb";
if (!theModel.
Save (aModelPath, ModelData::Model::FileFormatType::MTKWEB)) {
std::cerr << std::endl << "ERROR: Failed to export " << aModelPath << ". Exiting" << std::endl;
return MTKConverter_RC_ExportError;
}
UTF16String aThumbnailPath = theFolderPath +
"/thumbnail.png";
if (theToGenerateScreenshot && !CreateOriginModelThumbnail (aThumbnailPath, theModel)) {
std::cerr << std::endl << "ERROR: Failed to create thumbnail " << aThumbnailPath << ". Exiting" << std::endl;
return MTKConverter_RC_ExportError;
}
UTF16String aProcessModelPath = theFolderPath +
"/" + theProcessModel.
Name() +
".mtkweb" +
"/scenegraph.mtkweb";
if (!theProcessModel.Save (aProcessModelPath, ModelData::Model::FileFormatType::MTKWEB)) {
std::cerr << std::endl << "ERROR: Failed to export " << aProcessModelPath << ". Exiting" << std::endl;
return MTKConverter_RC_ExportError;
}
}
UTF16String aJsonPath = theFolderPath +
"/process_data.json";
if (!theReport.WriteToJSON (aJsonPath)) {
std::cerr << std::endl << "ERROR: Failed to create JSON file " << aJsonPath << ". Exiting" << std::endl;
return MTKConverter_RC_ExportError;
}
return MTKConverter_RC_OK;
#endif
}
}
MTKConverter_Application::MTKConverter_Application()
{
}
MTKConverter_ReturnCode MTKConverter_Application::Run (int argc, char *argv[]) const
{
if (argc == 1 || (
!strcmp (argv[1], "-?") || !strcmp (argv[1], "/?") ||
!strcmp (argv[1], "-h") || !strcmp (argv[1], "--help"))) {
PrintUsage();
return MTKConverter_RC_OK;
}
if (argc < 6) {
std::cerr << "Invalid number of arguments. Please use \"-h\" or \"--help\" for usage information." << std::endl;
return MTKConverter_RC_InvalidArgumentsNumber;
}
enum Mode { NeutralMode, ImportMode, ProcessMode, ExportMode };
auto aMode = NeutralMode;
MTKConverter_Report aReport;
auto aRes = MTKConverter_RC_OK;
bool aToGenerateScreenshot = true;
for(int i = 1; (i < argc) && (aRes == MTKConverter_RC_OK); ++i) {
if (anArgument == "--no-screenshot") {
aToGenerateScreenshot = false;
} else if(anArgument == "-i") {
aMode = ImportMode;
} else if (anArgument == "-p") {
aMode = ProcessMode;
} else if (anArgument == "-e") {
aMode = ExportMode;
} else {
try {
if (aMode == ImportMode) {
aRes = Import (anArgument, aModel);
} else if (aMode == ProcessMode) {
aRes = Process (anArgument, aModel, aReport, aProcessModel);
} else if(aMode == ExportMode) {
aRes = Export (anArgument, aToGenerateScreenshot, aModel, aReport, aProcessModel);
} else {
std::cerr << "ERROR!: Invalid argument " << anArgument << ". Exiting" << std::endl;
std::cerr << "Type " << argv[0] << " -h for help." << std::endl;
return MTKConverter_RC_InvalidArgument;
}
std::cout << "Done." << std::endl;
} catch (...) {
std::cerr << "Failed.\nERROR: Unhandled exception caught." << std::endl;
return MTKConverter_RC_GeneralException;
}
}
}
return aRes;
}
void MTKConverter_Application::PrintUsage() const
{
std::cout << "Usage:" << std::endl;
std::cout << "MTKConverter -i <import_file> -p <process> --no-screenshot -e <export_folder>" << std::endl << std::endl;
std::cout << "Arguments:" << std::endl;
std::cout << " <import_file> - import file name" << std::endl;
std::cout << " <process> - manufacturing process or algorithm name" << std::endl;
std::cout << " <export_folder> - export folder name" << std::endl;
std::cout << " --no-screenshot - disable screenshot generation (optional)" << std::endl;
std::cout << "Example:" << std::endl;
std::cout << "MTKConverter -i C:\\models\\test.step -p machining_milling -e C:\\models\\test" << std::endl;
std::cout << std::endl << "Recognized processes:" << std::endl;
std::cout << " wall_thickness :\t Wall Thickness analysis" << std::endl;
std::cout << " machining_milling:\t CNC Machining Milling feature recognition and DFM analysis" << std::endl;
std::cout << " machining_turning:\t CNC Machining Lathe+Milling feature recognition and DFM analysis" << std::endl;
std::cout << " molding :\t Molding feature recognition and DFM analysis" << std::endl;
std::cout << " sheet_metal :\t Sheet Metal feature recognition, unfolding and DFM analysis" << std::endl;
}
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
void AssignUuids()
Assigns uuid's (persistent id's) to scene graph elements and part representations (if not assigned ye...
Definition Model.cs:174
void SetName(cadex.UTF16String theName)
Sets a model name.
Definition Model.cs:84
bool IsEmpty()
Returns true if the model is empty.
Definition Model.cs:103
cadex.UTF16String Name()
Returns a model name.
Definition Model.cs:93
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:86
Defines color background style.
Definition ColorBackgroundStyle.cs:17
Writes an image file with graphical content of a model.
Definition ImageWriter.cs:17
main.cxx
#include <cadex/LicenseManager_Activate.h>
#include <MTKConverter_Application.hxx>
#include <iostream>
#include "../../mtk_license.cxx"
using namespace std;
int main (int argc, char* argv[])
{
auto aKey = MTKLicenseKey::Value();
if (!CADExLicense_Activate (aKey)) {
cerr << "Failed to activate Manufacturing Toolkit license." << endl;
return 1;
}
MTKConverter_Application anApp;
return anApp.Run (argc, argv);
}