public void SliceFileWithLeadingLowercaseN() { // Stl with leading n - tests past regression due to c:\path\name.stl where \n in path breaks during stuff/unstuff behavior string stlPath = TestUtilities.GetStlPath("name-with-leading-n"); string gcodePath = TestUtilities.GetTempGCodePath(nameof(SliceFileWithLeadingLowercaseN)); // Create config file var configFilePath = Path.ChangeExtension(gcodePath, "ini"); using (var stream = new StreamWriter(configFilePath)) { stream.WriteLine($"additionalArgsToProcess = -m \"1,0,0,0,0,1,0,0,0,0,1,0,5,0,0,1\" \"{stlPath}\""); } // Slice file MatterSlice.ProcessArgs($"-v -o \"{gcodePath}\" -c \"{configFilePath}\""); // Load and validate generated GCode string[] gcode = TestUtilities.LoadGCodeFile(gcodePath); var movement = new MovementInfo(); // check layer 1 var layer1Info = TestUtilities.GetGCodeForLayer(gcode, 1); var layer1Polygons = TestUtilities.GetExtrusionPolygons(layer1Info, ref movement); Assert.AreEqual(4, layer1Polygons.Count); // check layer 2 var layer2Info = TestUtilities.GetGCodeForLayer(gcode, 2); var layer2Polygons = TestUtilities.GetExtrusionPolygons(layer2Info, ref movement); Assert.AreEqual(4, layer2Polygons.Count); }
public void SliceFileWithSpaceInGCodePath() { // GCode file with space in file name string gcodePath = TestUtilities.GetTempGCodePath("gcode file with space"); string stlPath = TestUtilities.GetStlPath("Box Left"); // Create config file var configFilePath = Path.ChangeExtension(gcodePath, "ini"); using (var stream = new StreamWriter(configFilePath)) { stream.WriteLine($"additionalArgsToProcess = -m \"1,0,0,0,0,1,0,0,0,0,1,0,5,0,0,1\" \"{stlPath}\""); } // Slice file MatterSlice.ProcessArgs($"-v -o \"{gcodePath}\" -c \"{configFilePath}\""); // Load and validate generated GCode string[] gcode = TestUtilities.LoadGCodeFile(gcodePath); var movement = new MovementInfo(); // check layer 1 var layer1Info = TestUtilities.GetGCodeForLayer(gcode, 1); var layer1Polygons = TestUtilities.GetExtrusionPolygons(layer1Info, ref movement); Assert.AreEqual(4, layer1Polygons.Count); // check layer 2 var layer2Info = TestUtilities.GetGCodeForLayer(gcode, 2); var layer2Polygons = TestUtilities.GetExtrusionPolygons(layer2Info, ref movement); Assert.AreEqual(4, layer2Polygons.Count); }
public void AllPerimetersGoInPolgonDirection() { string thinWallsSTL = TestUtilities.GetStlPath("ThinWallsRect.stl"); string thinWallsGCode = TestUtilities.GetTempGCodePath("ThinWallsRect.stl"); { // load a model that is correctly manifold ConfigSettings config = new ConfigSettings(); config.ExpandThinWalls = true; FffProcessor processor = new FffProcessor(config); processor.SetTargetFile(thinWallsGCode); processor.LoadStlFile(thinWallsSTL); // slice and save it processor.DoProcessing(); processor.Finalize(); string[] thinWallsGCodeContent = TestUtilities.LoadGCodeFile(thinWallsGCode); int layerCount = TestUtilities.CountLayers(thinWallsGCodeContent); for (int i = 2; i < layerCount - 2; i++) { var layerGCode = TestUtilities.GetGCodeForLayer(thinWallsGCodeContent, i); var polygons = TestUtilities.GetExtrusionPolygons(layerGCode, 1000); foreach (var polygon in polygons) { Assert.AreEqual(1, polygon.GetWindingDirection()); } } } }
internal static void CheckPolysAreSimilar(string aGCodeFile, string bGCodeFile) { var aLoadedGcode = TestUtilities.LoadGCodeFile(aGCodeFile); var bLoadedGCode = TestUtilities.LoadGCodeFile(bGCodeFile); var aLayerCount = TestUtilities.CountLayers(aLoadedGcode); Assert.AreEqual(aLayerCount, TestUtilities.CountLayers(bLoadedGCode)); for (int layerIndex = 0; layerIndex < aLayerCount; layerIndex++) { var aLayerGCode = TestUtilities.GetGCodeForLayer(aLoadedGcode, layerIndex); var bLayerGCode = TestUtilities.GetGCodeForLayer(bLoadedGCode, layerIndex); var aPolys = TestUtilities.GetExtrusionPolygons(aLayerGCode); var bPolys = TestUtilities.GetExtrusionPolygons(bLayerGCode); // Assert.AreEqual(aPolys.Count, bPolys.Count); if (aPolys.Count > 0) { var aPoly = aPolys[0]; var bPoly = bPolys[0]; for (int aPointIndex = 0; aPointIndex < aPoly.Count; aPointIndex++) { var found = false; for (int bPointIndex = 0; bPointIndex < bPoly.Count; bPointIndex++) { if ((aPoly[aPointIndex] - bPoly[bPointIndex]).Length() < 10) { found = true; break; } } Assert.IsTrue(found); } } } }
public void SingleLayerCreated() { string point3mmStlFile = TestUtilities.GetStlPath("Point3mm"); string point3mmGCodeFile = TestUtilities.GetTempGCodePath("Point3mm.gcode"); var config = new ConfigSettings(); config.FirstLayerThickness = .25; config.LayerThickness = .25; config.NumberOfSkirtLoops = 0; var processor = new FffProcessor(config); processor.SetTargetFile(point3mmGCodeFile); processor.LoadStlFile(point3mmStlFile); // slice and save it processor.DoProcessing(); processor.Finalize(); var loadedGCode = TestUtilities.LoadGCodeFile(point3mmGCodeFile); var layers = TestUtilities.CountLayers(loadedGCode); Assert.AreEqual(1, layers); var totalExtrusions = TestUtilities.GetExtrusionPolygons(loadedGCode); #if __ANDROID__ Assert.IsTrue(totalExtrusions.Count > 0); Assert.IsTrue(totalExtrusions[0].PolygonLength() > 100); #else Assert.Greater(totalExtrusions.Count, 0); Assert.Greater(totalExtrusions[0].PolygonLength(), 100); #endif }
public void AllInsidesBeforeAnyOutsides() { string thinAttachStlFile = TestUtilities.GetStlPath("Thin Attach"); string thinAttachGCodeFile = TestUtilities.GetTempGCodePath("Thin Attach.gcode"); ConfigSettings config = new ConfigSettings(); config.NumberOfPerimeters = 2; config.InfillPercent = 0; config.NumberOfTopLayers = 0; config.FirstLayerExtrusionWidth = .4; config.NumberOfBottomLayers = 0; FffProcessor processor = new FffProcessor(config); processor.SetTargetFile(thinAttachGCodeFile); processor.LoadStlFile(thinAttachStlFile); // slice and save it processor.DoProcessing(); processor.Finalize(); string[] gcode = TestUtilities.LoadGCodeFile(thinAttachGCodeFile); // should look like this // ____________ ____________ // | _______ | | _______ | // | | | | | | | | // | | | |___| | | | // | | | ____ | | | // | |______| | | |______| | // |__________| |__________| MovementInfo movement = new MovementInfo(); { // check layer 1 string[] layer1Info = TestUtilities.GetGCodeForLayer(gcode, 1); Polygons layer1Polygons = TestUtilities.GetExtrusionPolygons(layer1Info, ref movement); // make sure there are 5 Assert.IsTrue(layer1Polygons.Count == 3); // make sure they are in the right order (two inner polygons print first) Assert.IsTrue(layer1Polygons[0].MinX() > layer1Polygons[1].MinX()); Assert.IsTrue(layer1Polygons[0].MinX() > layer1Polygons[2].MinX()); } { // check layer 2 string[] layer2Info = TestUtilities.GetGCodeForLayer(gcode, 2); Polygons layer2Polygons = TestUtilities.GetExtrusionPolygons(layer2Info, ref movement); // make sure there are 3 Assert.IsTrue(layer2Polygons.Count == 3); // make sure they are in the right order (two inner polygons print first) Assert.IsTrue(layer2Polygons[0].MinX() > layer2Polygons[1].MinX()); Assert.IsTrue(layer2Polygons[0].MinX() > layer2Polygons[2].MinX()); } }
public void InnerPerimeterFirstCorrect() { // By default we need to do the inner perimeters first string box20MmStlFile = TestUtilities.GetStlPath("20mm-box"); string boxGCodeFile = TestUtilities.GetTempGCodePath("20mm-box-perimeter.gcode"); ConfigSettings config = new ConfigSettings(); config.NumberOfPerimeters = 3; config.InfillPercent = 0; config.NumberOfTopLayers = 0; config.NumberOfBottomLayers = 0; FffProcessor processor = new FffProcessor(config); processor.SetTargetFile(boxGCodeFile); processor.LoadStlFile(box20MmStlFile); // slice and save it processor.DoProcessing(); processor.Finalize(); string[] gcode = TestUtilities.LoadGCodeFile(boxGCodeFile); MovementInfo movement = new MovementInfo(); { // check layer 1 string[] layer1Info = TestUtilities.GetGCodeForLayer(gcode, 1); Polygons layer1Polygons = TestUtilities.GetExtrusionPolygons(layer1Info, ref movement); // make sure there are 3 Assert.IsTrue(layer1Polygons.Count == 3); // make sure they are in the right order (first layer is outside in) Assert.IsTrue(layer1Polygons[0].MinX() > layer1Polygons[1].MinX()); } { // check layer 2 string[] layer2Info = TestUtilities.GetGCodeForLayer(gcode, 2); Polygons layer2Polygons = TestUtilities.GetExtrusionPolygons(layer2Info, ref movement); // make sure there are 3 Assert.IsTrue(layer2Polygons.Count == 3); // make sure they are in the right order (other layers are inside out) Assert.IsTrue(layer2Polygons[0].MinX() > layer2Polygons[1].MinX()); } }
public void DoHas2WallRingsAllTheWayUp(string fileName, int expectedLayerCount, bool checkRadius = false) { string stlFile = TestUtilities.GetStlPath(fileName); string gCodeFile = TestUtilities.GetTempGCodePath(fileName + ".gcode"); ConfigSettings config = new ConfigSettings(); config.InfillPercent = 0; config.NumberOfPerimeters = 1; config.FirstLayerExtrusionWidth = .2; config.LayerThickness = .2; config.NumberOfBottomLayers = 0; config.NumberOfTopLayers = 0; FffProcessor processor = new FffProcessor(config); processor.SetTargetFile(gCodeFile); processor.LoadStlFile(stlFile); // slice and save it processor.DoProcessing(); processor.Finalize(); string[] gcodeLines = TestUtilities.LoadGCodeFile(gCodeFile); int layerCount = TestUtilities.CountLayers(gcodeLines); Assert.IsTrue(layerCount == expectedLayerCount); MovementInfo movement = new MovementInfo(); for (int i = 0; i < layerCount - 5; i++) { string[] layerInfo = TestUtilities.GetGCodeForLayer(gcodeLines, i); if (i > 0) { Polygons layerPolygons = TestUtilities.GetExtrusionPolygons(layerInfo, ref movement); Assert.IsTrue(layerPolygons.Count == 2); if (checkRadius) { Assert.IsTrue(layerPolygons[0].Count > 10); Assert.IsTrue(layerPolygons[1].Count > 10); if (false) { foreach (var polygon in layerPolygons) { double radiusForPolygon = polygon[0].LengthMm(); foreach (var point in polygon) { Assert.AreEqual(radiusForPolygon, point.LengthMm(), 15); } } } } } else { TestUtilities.GetExtrusionPolygons(layerInfo, ref movement); } } }