internal static void CheckPolysAreSimilar(string aGCodeFile, string bGCodeFile) { var aLoadedGcode = TestUtilities.LoadGCodeFile(aGCodeFile); var bLoadedGCode = TestUtilities.LoadGCodeFile(bGCodeFile); var aLayerCount = TestUtilities.LayerCount(aLoadedGcode); Assert.AreEqual(aLayerCount, TestUtilities.LayerCount(bLoadedGCode)); for (int layerIndex = 0; layerIndex < aLayerCount; layerIndex++) { var aLayerGCode = TestUtilities.GetLayer(aLoadedGcode, layerIndex); var bLayerGCode = TestUtilities.GetLayer(bLoadedGCode, layerIndex); var aPolys = TestUtilities.GetExtrusionPolygonsForLayer(aLayerGCode, false); var bPolys = TestUtilities.GetExtrusionPolygonsForLayer(bLayerGCode, false); // 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 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 = default(MovementInfo); // check layer 1 var layer1Info = TestUtilities.GetLayer(gcode, 1); var layer1Polygons = TestUtilities.GetExtrusionPolygonsForLayer(layer1Info, ref movement, false); Assert.AreEqual(2, layer1Polygons.Where(i => i.Count > 2).Count()); // check layer 2 var layer2Info = TestUtilities.GetLayer(gcode, 2); var layer2Polygons = TestUtilities.GetExtrusionPolygonsForLayer(layer2Info, ref movement, false); Assert.AreEqual(2, layer2Polygons.Where(i => i.Count > 2).Count()); }
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.Dispose(); var loadedGCode = TestUtilities.LoadGCodeFile(point3mmGCodeFile); var layers = TestUtilities.LayerCount(loadedGCode); Assert.AreEqual(1, layers); var totalExtrusions = TestUtilities.GetExtrusionPolygonsForLayer(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 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 = default(MovementInfo); // check layer 1 var layer1Info = TestUtilities.GetLayer(gcode, 1); var layer1Polygons = TestUtilities.GetExtrusionPolygonsForLayer(layer1Info, ref movement, false); Assert.AreEqual(2, layer1Polygons.Where(i => i.Count > 2).Count()); // check layer 2 var layer2Info = TestUtilities.GetLayer(gcode, 2); var layer2Polygons = TestUtilities.GetExtrusionPolygonsForLayer(layer2Info, ref movement, false); Assert.AreEqual(2, layer2Polygons.Where(i => i.Count > 2).Count()); }
public void AllInsidesBeforeAnyOutsides() { string thinAttachStlFile = TestUtilities.GetStlPath("Thin Attach"); string thinAttachGCodeFile = TestUtilities.GetTempGCodePath("Thin Attach.gcode"); var config = new ConfigSettings(); config.NumberOfPerimeters = 2; config.InfillPercent = 0; config.NumberOfTopLayers = 0; config.FirstLayerExtrusionWidth = .4; config.NumberOfBottomLayers = 0; var processor = new FffProcessor(config); processor.SetTargetFile(thinAttachGCodeFile); processor.LoadStlFile(thinAttachStlFile); // slice and save it processor.DoProcessing(); processor.Dispose(); string[] gcode = TestUtilities.LoadGCodeFile(thinAttachGCodeFile); // should look like this // ____________ ____________ // | _______ | | _______ | // | | | | | | | | // | | | |___| | | | // | | | ____ | | | // | |______| | | |______| | // |__________| |__________| var movement = default(MovementInfo); { // check layer 1 string[] layer1Info = TestUtilities.GetLayer(gcode, 1); Polygons layer1Polygons = TestUtilities.GetExtrusionPolygonsForLayer(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.GetLayer(gcode, 2); Polygons layer2Polygons = TestUtilities.GetExtrusionPolygonsForLayer(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 OuterPerimeterFirstCorrect() { string box20MmStlFile = TestUtilities.GetStlPath("20mm-box"); string boxGCodeFile = TestUtilities.GetTempGCodePath("20mm-box-perimeter.gcode"); var config = new ConfigSettings(); config.NumberOfPerimeters = 3; config.OutsidePerimetersFirst = true; config.InfillPercent = 0; config.NumberOfTopLayers = 0; config.NumberOfBottomLayers = 0; var processor = new FffProcessor(config); processor.SetTargetFile(boxGCodeFile); processor.LoadStlFile(box20MmStlFile); // slice and save it processor.DoProcessing(); processor.Dispose(); string[] gcode = TestUtilities.LoadGCodeFile(boxGCodeFile); var outerPerimeterIndex = 1; var secondPerimeterIndex = 2; var thirdPerimeterIndex = 0; var movement = default(MovementInfo); { // check layer 1 var layer1Info = TestUtilities.GetLayer(gcode, 1); var layerPolygons = TestUtilities.GetExtrusionPolygonsForLayer(layer1Info, ref movement); // make sure there are 3 Assert.IsTrue(layerPolygons.Count == 3); // perimeters should be in 3 1 2 order so that we have priming happening before the outer perimeter Assert.IsTrue(layerPolygons[outerPerimeterIndex].MinX() < layerPolygons[secondPerimeterIndex].MinX()); Assert.IsTrue(layerPolygons[outerPerimeterIndex].MinX() < layerPolygons[thirdPerimeterIndex].MinX()); Assert.IsTrue(layerPolygons[secondPerimeterIndex].MinX() < layerPolygons[thirdPerimeterIndex].MinX()); } { // check layer 2 var layer2Info = TestUtilities.GetLayer(gcode, 2); var layerPolygons = TestUtilities.GetExtrusionPolygonsForLayer(layer2Info, ref movement); // make sure there are 3 Assert.IsTrue(layerPolygons.Count == 3); // make sure they are in the right order (other layers are inside out) Assert.IsTrue(layerPolygons[outerPerimeterIndex].MinX() < layerPolygons[secondPerimeterIndex].MinX()); Assert.IsTrue(layerPolygons[outerPerimeterIndex].MinX() < layerPolygons[thirdPerimeterIndex].MinX()); Assert.IsTrue(layerPolygons[secondPerimeterIndex].MinX() < layerPolygons[thirdPerimeterIndex].MinX()); } }
/// <summary> /// Get the extrusion polygons for every layer /// </summary> /// <param name="loadedGCode">The source gcode separated by line</param> /// <returns>A list of all the polygons by layer</returns> public static List <Polygons> GetAllExtrusionPolygons(this string[] loadedGCode) { var layerCount = TestUtilities.LayerCount(loadedGCode); var layerPolygons = new List <Polygons>(layerCount); for (int i = 0; i < layerCount; i++) { layerPolygons.Add(TestUtilities.GetExtrusionPolygonsForLayer(loadedGCode.GetGCodeForLayer(i))); } return(layerPolygons); }
/// <summary> /// Get the extrusion polygons for every layer /// </summary> /// <param name="loadedGCode">The source gcode separated by line</param> /// <returns>A list of all the polygons by layer</returns> public static List <Polygons> GetAllLayersExtrusionPolygons(this string[] loadedGCode) { var layerCount = TestUtilities.LayerCount(loadedGCode); var layerPolygons = new List <Polygons>(layerCount); var movementInfo = default(MovementInfo); for (int i = 0; i < layerCount; i++) { layerPolygons.Add(TestUtilities.GetExtrusionPolygonsForLayer(loadedGCode.GetLayer(i), ref movementInfo, false)); } return(layerPolygons); }
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"); var config = new ConfigSettings(); config.NumberOfPerimeters = 3; config.InfillPercent = 0; config.NumberOfTopLayers = 0; config.NumberOfBottomLayers = 0; var processor = new FffProcessor(config); processor.SetTargetFile(boxGCodeFile); processor.LoadStlFile(box20MmStlFile); // slice and save it processor.DoProcessing(); processor.Dispose(); string[] gcode = TestUtilities.LoadGCodeFile(boxGCodeFile); var movement = default(MovementInfo); { // check layer 1 string[] layer1Info = TestUtilities.GetLayer(gcode, 1); Polygons layer1Polygons = TestUtilities.GetExtrusionPolygonsForLayer(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.GetLayer(gcode, 2); Polygons layer2Polygons = TestUtilities.GetExtrusionPolygonsForLayer(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"); var config = new ConfigSettings(); config.InfillPercent = 0; config.NumberOfPerimeters = 1; config.FirstLayerExtrusionWidth = .2; config.LayerThickness = .2; config.NumberOfBottomLayers = 0; config.NumberOfTopLayers = 0; var processor = new FffProcessor(config); processor.SetTargetFile(gCodeFile); processor.LoadStlFile(stlFile); // slice and save it processor.DoProcessing(); processor.Dispose(); string[] gcodeLines = TestUtilities.LoadGCodeFile(gCodeFile); int layerCount = TestUtilities.LayerCount(gcodeLines); Assert.IsTrue(layerCount == expectedLayerCount); var movement = default(MovementInfo); for (int i = 0; i < layerCount - 10; i++) { string[] layerInfo = TestUtilities.GetLayer(gcodeLines, i); if (i > 0) { Polygons layerPolygons = TestUtilities.GetExtrusionPolygonsForLayer(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.GetExtrusionPolygonsForLayer(layerInfo, ref movement); } } }