import java.util.*;
public class nesting_computer {
static {
try {
System.loadLibrary("CadExMTK");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String[] args) {
String aKey = MTKLicenseKey.Value();
if (!LicenseManager.Activate(aKey)) {
System.out.println("Failed to activate Manufacturing Toolkit license.");
System.exit(1);
}
Nesting_Computer aComputer = new Nesting_Computer();
Nesting_ComputerParameters aParams = new Nesting_ComputerParameters();
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);
List<Pattern> aPatterns = Arrays.asList(
new Pattern(CreateRectangle(50.0, 50.0), "Rectangle 50x50", 1),
new Pattern(CreateRectangle(20.0, 10.0), "Rectangle 20x10", 10)
);
PrintPatternsInfo(aPatterns);
for (Pattern aPattern : aPatterns) {
aComputer.AddPattern(aPattern.myDrawingView, aPattern.myNumber);
}
Nesting_Data aData = aComputer.Perform();
PrintNestingInfo(aData);
}
static class Pattern {
public Pattern(CurveSet theShape, String theName, int theNumber) {
myDrawingView.Add(theShape);
myName = theName;
myNumber = theNumber;
}
public View myDrawingView = new View();
public String myName;
public int myNumber;
}
static CurveSet CreateRectangle(double theWidth, double theHeight) {
CurveSet aRectangle = new CurveSet();
Line2d aL1 = new Line2d(new Point2d(0, 0), new Direction2d(1, 0));
aL1.SetTrim(0, theWidth);
Line2d aL2 = new Line2d(new Point2d(theWidth, 0), new Direction2d(0, 1));
aL2.SetTrim(0, theHeight);
Line2d aL3 = new Line2d(new Point2d(theWidth, theHeight), new Direction2d(-1, 0));
aL3.SetTrim(0, theWidth);
Line2d aL4 = new Line2d(new Point2d(0, theHeight), new Direction2d(0, -1));
aL4.SetTrim(0, theHeight);
aRectangle.AddCurve(aL1);
aRectangle.AddCurve(aL2);
aRectangle.AddCurve(aL3);
aRectangle.AddCurve(aL4);
return aRectangle;
}
static void PrintPatternsInfo(List<Pattern> thePatterns) {
System.out.println("------- Patterns Info -------");
for (Pattern aPattern : thePatterns) {
System.out.println(aPattern.myName + ": " + aPattern.myNumber);
}
}
static void PrintNestingInfo(Nesting_Data theData) {
System.out.println();
System.out.println("------- Nesting Info -------");
double aTotalEfficiency = 0.0;
double aTotalScrap = 0.0;
List<Nesting_Sheet> aSheets = theData.Sheets();
for (int i = 0; i < aSheets.size(); ++i) {
System.out.println("# Sheet " + i);
System.out.println(" Nested Parts: " + aSheets.get(i).NestedParts());
aTotalScrap += aSheets.get(i).Scrap();
System.out.println(" Scrap: " + aSheets.get(i).Scrap() * 100 + "%");
aTotalEfficiency += aSheets.get(i).PlacementEfficiency();
System.out.println(" Placement Efficiency: " + aSheets.get(i).PlacementEfficiency() * 100 + "%");
System.out.println();
}
System.out.println("Average Scrap: " + (aTotalScrap / aSheets.size() * 100) + "%");
System.out.println("Average Placement Efficiency: " + (aTotalEfficiency / aSheets.size() * 100) + "%");
}
}
Contains classes, types and enums related to drawings.
Contains classes, types, enums, and functions related to geometric entities.
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.