#include <cadex/Base/UTF16String.hxx>
#include <cadex/Drawing/Drawing.hxx>
#include <cadex/Drawing/Geometry.hxx>
#include <cadex/Drawing/View.hxx>
#include <cadex/Geom/Line2d.hxx>
#include <cadex/Geom/Point2d.hxx>
#include <cadex/LicenseManager_Activate.h>
#include <cadex/Nesting_Computer.hxx>
#include <cadex/Nesting_ComputerParameters.hxx>
#include <cadex/Nesting_Data.hxx>
#include <iostream>
#include <vector>
#include "../../mtk_license.cxx"
using namespace std;
class Pattern
{
public:
Pattern (const Drawing::CurveSet theShape, const UTF16String theName, size_t theNumber) :
myName (theName),
myNumber (theNumber)
{
myDrawingView.Add (theShape);
}
Drawing::View myDrawingView;
UTF16String myName;
size_t myNumber;
};
using PatternVector = vector<Pattern>;
Drawing::CurveSet CreateRectangle (double theWidth, double theHeight)
{
Drawing::CurveSet aRectangle;
Geom::Line2d aL1 (Geom::Point2d (0, 0), Geom::Direction2d (1, 0));
aL1.SetTrim (0, theWidth);
Geom::Line2d aL2 (Geom::Point2d (theWidth, 0), Geom::Direction2d (0, 1));
aL2.SetTrim (0, theHeight);
Geom::Line2d aL3 (Geom::Point2d (theWidth, theHeight), Geom::Direction2d (-1, 0));
aL3.SetTrim (0, theWidth);
Geom::Line2d aL4 (Geom::Point2d (0, theHeight), Geom::Direction2d (0, -1));
aL4.SetTrim (0, theHeight);
aRectangle.AddCurve (aL1);
aRectangle.AddCurve (aL2);
aRectangle.AddCurve (aL3);
aRectangle.AddCurve (aL4);
return aRectangle;
}
void PrintPatternsInfo (const PatternVector& thePatterns)
{
cout << "------- Patterns Info -------" << endl;
for (const auto& aPattern : thePatterns) {
cout << aPattern.myName << ": " << aPattern.myNumber << endl;
}
}
void PrintNestingInfo (const Nesting_Data& theData)
{
cout << endl;
cout << "------- Nesting Info -------" << endl;
double aTotalEfficiency = 0.0;
double aTotalScrap = 0.0;
const auto& aSheets = theData.Sheets();
for (size_t i = 0; i < aSheets.size(); ++i) {
cout << "#" << i << " Sheet" << endl;
cout << " Nested Parts: " << aSheets[i].NestedParts() << endl;
aTotalScrap += aSheets[i].Scrap();
cout << " Scrap: " << aSheets[i].Scrap() * 100 << "%" << endl;
aTotalEfficiency += aSheets[i].PlacementEfficiency();
cout << " Placement Efficiency: " << aSheets[i].PlacementEfficiency() * 100 << "%" << endl;
cout << endl;
}
cout << "Average Scrap: " << aTotalScrap / aSheets.size() * 100 << "%" << endl;
cout << "Average Placement Efficiency: " << aTotalEfficiency / aSheets.size() * 100 << "%" << endl;
}
int main()
{
auto aKey = MTKLicenseKey::Value();
if (!CADExLicense_Activate (aKey)) {
cerr << "Failed to activate Manufacturing Toolkit license." << endl;
return 1;
}
Nesting_Computer aComputer;
Nesting_ComputerParameters aParams;
aParams.SetIterationCount (10);
aParams.SetGenerationSize (10);
aParams.SetMutationRate (0.5);
aParams.SetPartToPartDistance (1.0);
aParams.SetPartToSheetBoundaryDistance (1.0);
aParams.SetMirrorControl (false);
aParams.SetRotationCount (4);
aParams.SetCurveTolerance (10);
aComputer.SetParameters (aParams);
aComputer.AddMaterial (100.0, 100.0, 1);
auto aPatterns = PatternVector{Pattern (CreateRectangle (50.0, 50.0), "Rectangle 50x50", 1),
Pattern (CreateRectangle (20.0, 10.0), "Rectangle 20x10", 10)};
PrintPatternsInfo (aPatterns);
for (const auto& aPattern : aPatterns) {
aComputer.AddPattern (aPattern.myDrawingView, aPattern.myNumber);
}
Nesting_Data aData = aComputer.Perform();
PrintNestingInfo (aData);
return 0;
}
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.