#include <cadex/LicenseManager_Activate.h>
#include <cadex/Measurements/ValidationProperties.hxx>
#include <cadex/ModelData/Body.hxx>
#include <cadex/ModelData/Model.hxx>
#include <cadex/ModelData/ModelReader.hxx>
#include <cadex/ModelData/Part.hxx>
#include <cadex/ModelData/Shell.hxx>
#include <cadex/ModelData/Solid.hxx>
#include <cadex/SheetMetal_FlatPattern.hxx>
#include <cadex/SheetMetal_Unfolder.hxx>
#include <iostream>
#include <vector>
#include "../../mtk_license.cxx"
using namespace std;
void PrintFlatPatternInfo (const SheetMetal_FlatPattern& theFlatPattern)
{
if (!theFlatPattern) {
cerr << " Failed to create flat pattern.";
return;
}
cout << " Flat Pattern with:" << endl;
cout << " length: " << theFlatPattern.Length() << " mm" << endl;
cout << " width: " << theFlatPattern.Width() << " mm" << endl;
cout << " thickness: " << theFlatPattern.Thickness() << " mm" << endl;
cout << " perimeter: " << theFlatPattern.Perimeter() << " mm" << endl;
}
class PartProcessor : public ModelData::ModelElementVoidVisitor
{
public:
PartProcessor (const UTF16String& theDrawingFolderPath) :
myDrawingFolderPath (theDrawingFolderPath)
{}
void operator() (const ModelData::Part& thePart) override
{
auto aPartName = thePart.Name().IsEmpty() ? "noname" : thePart.Name();
size_t aBodyNumber = 0;
auto aBodies = thePart.Bodies();
for (const auto& aBody : aBodies) {
ModelData::ShapeIterator aShapeIt (aBody);
while (aShapeIt.HasNext()) {
const auto& aShape = aShapeIt.Next();
if (aShape.Type() == ModelData::ShapeType::Solid) {
cout << "Part #" << myPartIndex << " [\"" << aPartName << "\"] - solid #" << std::to_string (aBodyNumber) << " has:" << endl;
ProcessSolid (ModelData::Solid::Cast (aShape), aPartName, aBodyNumber);
} else if (aShape.Type() == ModelData::ShapeType::Shell) {
cout << "Part #" << myPartIndex << " [\"" << aPartName << "\"] - shell #" << std::to_string (aBodyNumber) << " has:" << endl;
ProcessShell (ModelData::Shell::Cast (aShape), aPartName, aBodyNumber);
}
}
++aBodyNumber;
}
++myPartIndex;
}
void ProcessSolid (const ModelData::Solid& theSolid, const UTF16String& , size_t )
{
auto aFlatPattern = myUnfolder.Perform (theSolid);
PrintFlatPatternInfo (aFlatPattern);
}
void ProcessShell (const ModelData::Shell& theShell, const UTF16String& , size_t )
{
auto aFlatPattern = myUnfolder.Perform (theShell);
PrintFlatPatternInfo (aFlatPattern);
}
private:
UTF16String DrawingFileName (
const UTF16String& thePartName, size_t theShapeIndex, const UTF16String& theShapeName)
{
UTF16String aPartName = UTF16String ("Part ") + std::to_string (myPartIndex).c_str() + " [" + thePartName + "]";
UTF16String aShapeName = theShapeName + " " + std::to_string (theShapeIndex).c_str();
UTF16String aFileName = myDrawingFolderPath + "/" + aPartName + " - " + aShapeName + " - drawing.dxf";
return aFileName;
}
SheetMetal_Unfolder myUnfolder;
UTF16String myDrawingFolderPath;
size_t myPartIndex = 0;
};
int main (int argc, char* argv[])
{
auto aKey = MTKLicenseKey::Value();
if (!CADExLicense_Activate (aKey)) {
cerr << "Failed to activate Manufacturing Toolkit license." << endl;
return 1;
}
if (argc != 3) {
cerr << "Usage: " << argv[0] << " <input_file> <output_folder>, where:" << endl;
cerr << " <input_file> is a name of the file to be read" << endl;
cerr << " <output_folder> is a name of the folder where DXF files with drawing to be written" << endl;
return 1;
}
const char* aSource = argv[1];
const char* aDrawingPath = argv[2];
ModelData::Model aModel;
ModelData::ModelReader aReader;
if (!aReader.Read (aSource, aModel)) {
cerr << "Failed to read the file " << aSource << endl;
return 1;
}
cout << "Model: " << aModel.Name() << "\n" << endl;
PartProcessor aPartProcessor (aDrawingPath);
ModelData::ModelElementUniqueVisitor aVisitor (aPartProcessor);
aModel.Accept (aVisitor);
return 0;
}
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.