public void MorePauseHandlingStreamTests()
        {
            string[] inputLines = new string[]
            {
                "; the printer is moving normally",
                "G1 X10 Y10 Z10 E0",
                "G1 X11 Y10 Z10 E10",
                "G1 X12 Y10 Z10 E30",

                "; the printer pauses",
                "@pause",

                "; do_resume",                 // just a marker for us to issue a resume

                // move some more
                "G1 X13 Y10 Z10 E40",
                "G1 X14 Y10 Z10 E50",
                "G1 X15 Y10 Z10 E60",
                null,
            };

            // We should go back to the above code when possible. It requires making pause part and move while paused part of the stream.
            // All communication should go through stream to minimize the difference between printing and controlling while not printing (all printing in essence).
            string[] expected = new string[]
            {
                "; the printer is moving normally",
                "G1 X10 Y10 Z10",
                "G1 X11 E10",
                "G1 X12 E30",
                "; the printer pauses",
                "",
                "",
                "G1 Z20 E20 F12000",
                "G90",
                "M114",
                "",
                "; do_resume",
                "G92 E-10",
                "G1 Z16.67 F3001",
                "G1 X12.01 Y10.01 Z13.34",
                "G1 Z10.01",
                "G1 X12 Y10 Z10 F3000",
                "",
                "G1 Z0 E30.8 F12000",
                "G90",
                "M114",
                "G1 X13 Z10 E40",
                "G1 X14 E50",
                "G1 X15 E60",
                null,
            };

            StaticData.Instance = new MatterHackers.Agg.FileSystemStaticData(Path.Combine("..", "..", "..", "..", "StaticData"));

            MatterControlUtilities.OverrideAppDataLocation();

            // this is the pause and resume from the Eris
            PrinterSettings settings = ActiveSliceSettings.Instance;

            settings.SetValue(SettingsKey.pause_gcode, "G91\nG1 Z10 E - 10 F12000\n  G90");
            settings.SetValue(SettingsKey.resume_gcode, "G91\nG1 Z-10 E10.8 F12000\nG90");

            List <GCodeStream>  streamList;
            GCodeStream         pauseHandlingStream = CreateTestGCodeStream(inputLines, out streamList);
            PauseHandlingStream pauseStream         = null;

            foreach (var stream in streamList)
            {
                if (stream as PauseHandlingStream != null)
                {
                    pauseStream = (PauseHandlingStream)stream;
                    break;
                }
            }

            int    expectedIndex = 0;
            string actualLine    = pauseHandlingStream.ReadLine();
            string expectedLine  = expected[expectedIndex++];

            Assert.AreEqual(expectedLine, actualLine, "Unexpected response from PauseHandlingStream");

            while (actualLine != null)
            {
                expectedLine = expected[expectedIndex++];
                actualLine   = pauseHandlingStream.ReadLine();
                //Debug.WriteLine("\"{0}\",".FormatWith(actualLine));
                if (actualLine == "; do_resume")
                {
                    pauseStream.Resume();
                }

                Assert.AreEqual(expectedLine, actualLine, "Unexpected response from PauseHandlingStream");
            }
        }
Esempio n. 2
0
        public void CorrectEOutputPositions()
        {
            string[] inputLines = new string[]
            {
                "G1 E11 F300",
                // BCN tool change test
                // Before:
                "G92 E0",
                "G91",
                "G1 E - 5 F302",
                "G90",
                // After:
                "G91",
                "G1 E8 F150",
                "G90",
                "G4 P0",
                "G92 E0",
                "G4 P0",
                "G91",
                "G1 E-2 F301",
                "G90",
                null,
            };

            // We should go back to the above code when possible. It requires making pause part and move while paused part of the stream.
            // All communication should go through stream to minimize the difference between printing and controlling while not printing (all printing in essence).
            string[] expected = new string[]
            {
                "G1 E11 F300",
                "G92 E0",
                "",
                "G1 E-1 F302",
                "G1 E-2",
                "G1 E-3",
                "G1 E-4",
                "G1 E-5",
                "G90",
                "",
                "G1 E-4 F150",
                "G1 E-3",
                "G1 E-2",
                "G1 E-1",
                "G1 E0",
                "G1 E1",
                "G1 E2",
                "G1 E3",
                "G90",
                "G4 P0",
                "G92 E0",
                "G4 P0",
                "",
                "G1 E-1 F301",
                "G1 E-2",
                "G90",
                null,
            };

            AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

            var printer = new PrinterConfig(new PrinterSettings());

            GCodeStream testStream = CreateTestGCodeStream(printer, inputLines, out List <GCodeStream> streamList);

            ValidateStreamResponse(expected, testStream);
        }
        public void PauseHandlingStreamTests()
        {
            string[] inputLines = new string[]
            {
                "; the printer is moving normally",
                "G1 X10 Y10 Z10 E0",
                "G1 X10 Y10 Z10 E10",
                "G1 X10 Y10 Z10 E30",

                "; the printer pauses",
                "G91",
                "G1 Z10 E - 10 F12000",
                "G90",

                "; the user moves the printer",

                "; the printer un-pauses",
                "G91",
                "G1 Z-10 E10.8 F12000",
                "G90",
                null,
            };

            // We should go back to the above code when possible. It requires making pause part and move while paused part of the stream.
            // All communication should go through stream to minimize the difference between printing and controlling while not printing (all printing in essence).
            string[] expected = new string[]
            {
                "; the printer is moving normally",
                "G1 X10 Y10 Z10",
                "G1 E10",
                "G1 E30",

                "; the printer pauses",
                "",                  // G91 is removed
                "G1 Z20 E20 F12000", // altered to be absolute
                "G90",

                "; the user moves the printer",

                "; the printer un-pauses",
                "",                 // G91 is removed
                "G1 Z10 E30.8",
                "G90",
                null,
            };

            StaticData.Instance = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

            List <GCodeStream> streamList;
            GCodeStream        pauseHandlingStream = CreateTestGCodeStream(inputLines, out streamList);

            int    expectedIndex = 0;
            string actualLine    = pauseHandlingStream.ReadLine();
            string expectedLine  = expected[expectedIndex++];

            Assert.AreEqual(expectedLine, actualLine, "Unexpected response from PauseHandlingStream");

            while (actualLine != null)
            {
                expectedLine = expected[expectedIndex++];
                actualLine   = pauseHandlingStream.ReadLine();

                Assert.AreEqual(expectedLine, actualLine, "Unexpected response from PauseHandlingStream");
            }
        }
Esempio n. 4
0
 public void TestSetup()
 {
     AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
     MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));
 }
        public async Task AabbCalculatedCorrectlyForPinchedFitObjects()
        {
            AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

            // Automation runner must do as much as program.cs to spin up platform
            string platformFeaturesProvider = "MatterHackers.MatterControl.WindowsPlatformsFeatures, MatterControl.Winforms";

            AppContext.Platform = AggContext.CreateInstanceFrom <INativePlatformFeatures>(platformFeaturesProvider);
            AppContext.Platform.InitPluginFinder();
            AppContext.Platform.ProcessCommandline();

            // build without pinch
            {
                var root = new Object3D();
                var cube = await CubeObject3D.Create(20, 20, 20);

                root.Children.Add(cube);
                Assert.IsTrue(root.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 10)), .001));
                root.Children.Remove(cube);
                var fit = await FitToBoundsObject3D_2.Create(cube);

                fit.SizeX = 50;
                fit.SizeY = 20;
                fit.SizeZ = 20;
                root.Children.Add(fit);
                var rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-25, -10, -10), new Vector3(25, 10, 10)), .001));
            }

            // build with pinch
            {
                var root = new Object3D();
                var cube = await CubeObject3D.Create(20, 20, 20);

                var fit = await FitToBoundsObject3D_2.Create(cube);

                fit.SizeX = 50;
                fit.SizeY = 20;
                fit.SizeZ = 20;

                var pinch = new PinchObject3D_2();
                pinch.Children.Add(fit);
                await pinch.Rebuild();

                root.Children.Add(pinch);
                var rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 10)), .001));
            }

            // build with translate
            {
                var root = new Object3D();
                var cube = await CubeObject3D.Create(20, 20, 20);

                var translate = new TranslateObject3D(cube, 11, 0, 0);

                root.Children.Add(translate);
                var rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(1, -10, -10), new Vector3(21, 10, 10)), .001));
            }

            // build with pinch and translate
            {
                var root = new Object3D();
                var cube = await CubeObject3D.Create(20, 20, 20);

                var translate = new TranslateObject3D(cube, 11, 0, 0);

                var pinch = new PinchObject3D_2();
                pinch.Children.Add(translate);
                root.Children.Add(pinch);
                await pinch.Rebuild();

                var rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(1, -10, -10), new Vector3(21, 10, 10)), .001));
            }

            // build with pinch and translate
            {
                var root = new Object3D();
                var cube = await CubeObject3D.Create(20, 20, 20);

                var fit = await FitToBoundsObject3D_2.Create(cube);

                fit.SizeX = 50;
                fit.SizeY = 20;
                fit.SizeZ = 20;

                var translate = new TranslateObject3D(fit, 11, 0, 0);

                var pinch = new PinchObject3D_2();
                pinch.Children.Add(translate);
                await pinch.Rebuild();

                root.Children.Add(pinch);
                var rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(1, -10, -10), new Vector3(21, 10, 10)), .001));
            }
        }
Esempio n. 6
0
 static LevelingTests()
 {
     MatterControlUtilities.OverrideAppDataLocation();
 }
        public void MorePauseHandlingStreamTests()
        {
            string[] inputLines = new string[]
            {
                "; the printer is moving normally",
                "G1 X10 Y10 Z10 E0",
                "G1 X11 Y10 Z10 E10",
                "G1 X12 Y10 Z10 E30",

                "; the printer pauses",
                "@pause",

                "; do_resume",                 // just a marker for us to issue a resume

                // move some more
                "G1 X13 Y10 Z10 E40",
                null,
            };

            // We should go back to the above code when possible. It requires making pause part and move while paused part of the stream.
            // All communication should go through stream to minimize the difference between printing and controlling while not printing (all printing in essence).
            string[] expected = new string[]
            {
                "; the printer is moving normally",
                "G1 X10 Y10 Z10 E0",
                "G1 X11 E10",
                "G1 X12 E30",
                "; the printer pauses",
                "",
                "",
                "G1 Z20 E20 F12000",
                "G90",
                "M114",
                "",
                "; do_resume",
                "G92 E-10",
                "G1 Z16.67 F3001",
                "G1 X12.01 Y10.01 Z13.34",
                "G1 Z10.01",
                "G1 X12 Y10 Z10 F3000",
                "",
                "G1 Z0 E30.8 F12000",
                "G90",
                "M114",
                "",
                "G1 X12.1 F1800",
                "G1 X12.2",
                "G90",
                "G1 X12.33 Z1.667 E32.333",
                "G1 X12.47 Z3.333 E33.867",
                "G1 X12.6 Z5 E35.4",
                "G1 X12.73 Z6.667 E36.933",
                "G1 X12.87 Z8.333 E38.467",
                "G1 X13 Z10 E40",
                null,
            };

            AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

            // this is the pause and resume from the Eris
            var printer = new PrinterConfig(new PrinterSettings());

            printer.Settings.SetValue(SettingsKey.pause_gcode, "G91\nG1 Z10 E - 10 F12000\n  G90");
            printer.Settings.SetValue(SettingsKey.resume_gcode, "G91\nG1 Z-10 E10.8 F12000\nG90");

            GCodeStream         pauseHandlingStream = CreateTestGCodeStream(printer, inputLines, out List <GCodeStream> streamList);
            PauseHandlingStream pauseStream         = null;

            foreach (var stream in streamList)
            {
                if (stream as PauseHandlingStream != null)
                {
                    pauseStream = (PauseHandlingStream)stream;
                    break;
                }
            }

            int    expectedIndex = 0;
            string actualLine    = pauseHandlingStream.ReadLine();
            string expectedLine  = expected[expectedIndex++];

            Assert.AreEqual(expectedLine, actualLine, "Unexpected response from PauseHandlingStream");

            while (actualLine != null)
            {
                expectedLine = expected[expectedIndex++];
                actualLine   = pauseHandlingStream.ReadLine();
                //Debug.WriteLine("\"{0}\",".FormatWith(actualLine));
                if (actualLine == "; do_resume")
                {
                    pauseStream.Resume();
                }

                Assert.AreEqual(expectedLine, actualLine, "Unexpected response from PauseHandlingStream");
            }
        }
        public async Task AlignObjectHasCorrectPositionsOnXAxis()
        {
            StaticData.RootPath = TestContext.CurrentContext.ResolveProjectPath(4, "StaticData");
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

            // Automation runner must do as much as program.cs to spin up platform
            string platformFeaturesProvider = "MatterHackers.MatterControl.WindowsPlatformsFeatures, MatterControl.Winforms";

            AppContext.Platform = AggContext.CreateInstanceFrom <INativePlatformFeatures>(platformFeaturesProvider);
            AppContext.Platform.ProcessCommandline();

            var scene = new InteractiveScene();

            var cube = await CubeObject3D.Create(20, 20, 20);

            cube.Matrix = Matrix4X4.CreateTranslation(50, 60, 10);
            Assert.IsTrue(cube.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(40, 50, 0), new Vector3(60, 70, 20)), .01));
            scene.Children.Add(cube);

            var bigCube = await CubeObject3D.Create(40, 40, 40);

            bigCube.Matrix = Matrix4X4.CreateTranslation(20, 20, 20);
            Assert.IsTrue(bigCube.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(0, 0, 0), new Vector3(40, 40, 40)), .01));
            scene.Children.Add(bigCube);

            // select them
            scene.SelectedItem = cube;
            scene.AddToSelection(bigCube);

            // create an align of them
            var align = new AlignObject3D();

            align.AddSelectionAsChildren(scene, scene.SelectedItem);

            var unalignedBounds = align.GetAxisAlignedBoundingBox();

            // assert the align in built correctly
            Assert.AreEqual(1, scene.Children.Count);
            Assert.AreEqual(2, align.Children.Count);
            Assert.IsTrue(align.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(0, 0, 0), new Vector3(60, 70, 40)), 1.0));

            align.SelectedChild = new SelectedChildren()
            {
                cube.ID.ToString()
            };

            Assert.IsTrue(align.GetAxisAlignedBoundingBox().Equals(unalignedBounds, 1.0));

            // turn align on
            align.XAlign = Align.Min;
            await align.Rebuild();

            Assert.IsTrue(align.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(40, 0, 0), new Vector3(80, 70, 40)), 1.0));

            // turn it off
            align.XAlign = Align.None;
            await align.Rebuild();

            Assert.IsTrue(align.GetAxisAlignedBoundingBox().Equals(unalignedBounds, 1.0));

            // turn it back on
            align.XAlign = Align.Min;
            await align.Rebuild();

            Assert.IsTrue(align.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(40, 0, 0), new Vector3(80, 70, 40)), 1.0));

            // remove the align and assert stuff moved back to where it started
            align.Remove(null);
            Assert.IsTrue(cube.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(40, 50, 0), new Vector3(60, 70, 20)), .01));
            Assert.IsTrue(bigCube.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(0, 0, 0), new Vector3(40, 40, 40)), .01));
        }
        public async Task NoContentChangedOnLoad()
        {
            AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

            bool onIdlePumpActive = true;

            var uiPump = Task.Run(() =>
            {
                while (onIdlePumpActive)
                {
                    UiThread.InvokePendingActions();
                    Thread.Sleep(10);
                }
                ;

                Console.Write("Exiting");
            });

            // Find and validate all ILibraryContainer types, skipping abstract classes
            foreach (var containerType in PluginFinder.FindTypes <ILibraryContainer>().Where(fieldType => !fieldType.IsAbstract))
            {
                var args = new List <object>();

                if (containerType == typeof(FileSystemContainer))
                {
                    args.Add(TestContext.CurrentContext.ResolveProjectPath(4));
                }
                else if (containerType == typeof(RootLibraryContainer))
                {
                    // TODO: Not sure how to test RootLibrary given content loads after MatterControl init is finished, skipping for now
                    continue;
                }

                if (Activator.CreateInstance(containerType, args.ToArray()) is ILibraryContainer libraryContainer)
                {
                    if (libraryContainer is ZipMemoryContainer zipContainer)
                    {
                        zipContainer.Path = TestContext.CurrentContext.ResolveProjectPath(4, "Tests", "TestData", "TestParts", "Batman.zip");
                        zipContainer.RelativeDirectory = Path.GetDirectoryName(zipContainer.Path);
                    }

                    int changedCount = 0;
                    libraryContainer.ContentChanged += (s, e) =>
                    {
                        changedCount++;
                    };

                    await Task.Run(() =>
                    {
                        libraryContainer.Load();
                    });

                    // Allow time for invalid additional reloads
                    await Task.Delay(300);

                    // Verify Reload is called;
                    Assert.AreEqual(0, changedCount, "Expected reload count not hit - container should fire reload event after acquiring content");
                }
            }

            onIdlePumpActive = false;
        }
Esempio n. 10
0
        public void SoftwareEndstopstreamTests()
        {
            string[] inputLines = new string[]
            {
                // test x min
                // move without extrusion
                "G1 X100Y100Z0E0",         // start at the bed center
                "G1 X-100",                // move left off the bed
                "G1 Y110",                 // move while outside bounds
                "G1 X100",                 // move back on

                // move with extrusion
                "G1 X100Y100Z0E0",            // start at the bed center
                "G1 X-100E10",                // move left off the bed
                "G1 Y110E20",                 // move while outside bounds
                "G1 X100E30",                 // move back on

                // test x max
                // test y min
                // test y max
                // test z min
                // test z max

                null,
            };

            // We should go back to the above code when possible. It requires making pause part and move while paused part of the stream.
            // All communication should go through stream to minimize the difference between printing and controlling while not printing (all printing in essence).
            string[] expected = new string[]
            {
                // move without extrusion
                "G1 X100 Y100 Z0 E0", // strat position
                "G1 X0",              // clamped x
                "",                   // move while outside
                "G1 Y110",            // first position back in bounds
                "G1 X100",            // move to requested x

                // move with extrusion
                "G1 X100Y100Z0E0",            // start at the bed center
                "G1 X-100E10",                // move left off the bed
                "G1 Y110E20",                 // move while outside bounds
                "G1 X100E30",                 // move back on

                null,
            };

            AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

            var printer             = new PrinterConfig(new PrinterSettings());
            var pauseHandlingStream = new SoftwareEndstopsStream(printer, new TestGCodeStream(printer, inputLines));

            int    expectedIndex = 0;
            string actualLine    = pauseHandlingStream.ReadLine();
            string expectedLine  = expected[expectedIndex++];

            Assert.AreEqual(expectedLine, actualLine, "Unexpected response from PauseHandlingStream");

            while (actualLine != null)
            {
                expectedLine = expected[expectedIndex++];
                actualLine   = pauseHandlingStream.ReadLine();

                Assert.AreEqual(expectedLine, actualLine, "Unexpected response from PauseHandlingStream");
            }
        }
        public async Task AddFiresContentChangedEvent()
        {
            AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

            string filePath = TestContext.CurrentContext.ResolveProjectPath(4, "Tests", "TestData", "TestParts", "Batman.stl");

            bool onIdlePumpActive = true;

            var uiPump = Task.Run(() =>
            {
                while (onIdlePumpActive)
                {
                    UiThread.InvokePendingActions();
                    Thread.Sleep(10);
                }
                ;

                Console.Write("Exiting");
            });

            Type writable = typeof(ILibraryWritableContainer);

            // Find and validate all ILibraryContainer types, skipping abstract classes
            foreach (var containerType in PluginFinder.FindTypes <ILibraryContainer>().Where(fieldType => !fieldType.IsAbstract))
            {
                var args = new List <object>();

                if (containerType == typeof(FileSystemContainer))
                {
                    Directory.CreateDirectory(ApplicationDataStorage.Instance.ApplicationTempDataPath);
                    args.Add(ApplicationDataStorage.Instance.ApplicationTempDataPath);
                }
                else if (containerType == typeof(RootLibraryContainer) ||
                         !writable.IsAssignableFrom(containerType))
                {
                    // TODO: Not sure how to test RootLibrary given content loads after MatterControl init is finished, skipping for now
                    continue;
                }

                if (Activator.CreateInstance(containerType, args.ToArray()) is ILibraryWritableContainer libraryContainer)
                {
                    if (!libraryContainer.AllowAction(ContainerActions.AddItems))
                    {
                        continue;
                    }

                    if (libraryContainer is ZipMemoryContainer zipContainer)
                    {
                        zipContainer.Path = TestContext.CurrentContext.ResolveProjectPath(4, "Tests", "TestData", "TestParts", "Batman.zip");
                        zipContainer.RelativeDirectory = Path.GetDirectoryName(zipContainer.Path);
                    }

                    int changedCount = 0;
                    libraryContainer.ContentChanged += (s, e) =>
                    {
                        changedCount++;
                    };

                    var waitUntil = DateTime.Now.AddSeconds(15);

                    var result = Task.Run(() =>
                    {
                        libraryContainer.Load();
                        libraryContainer.Add(new[] { new FileSystemFileItem(filePath) });
                    });

                    // Wait for reload
                    while (DateTime.Now <= waitUntil)
                    {
                        if (changedCount > 0)
                        {
                            break;
                        }

                        await Task.Delay(200);
                    }

                    // Allow time for invalid additional reloads
                    await Task.Delay(300);

                    Console.WriteLine($"ContentChanged for {containerType.Name}");

                    // Verify Reload is called;
                    Assert.AreEqual(1, changedCount, $"Expected reload count for {containerType.Name} not hit - container should fire reload event after acquiring content");
                }
            }

            onIdlePumpActive = false;
        }
Esempio n. 12
0
        public async Task ResavedSceneRemainsConsistent()
        {
#if !__ANDROID__
            // Set the static data to point to the directory of MatterControl
            AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));
#endif
            AssetObject3D.AssetManager = new AssetManager();

            var sceneContext = new BedConfig(null);

            var scene = sceneContext.Scene;
            scene.Children.Add(new Object3D
            {
                Mesh = PlatonicSolids.CreateCube(20, 20, 20)
            });

            string tempPath = GetSceneTempPath();
            string filePath = Path.Combine(tempPath, "some.mcx");

            // Set directory for asset resolution
            Object3D.AssetsPath = Path.Combine(tempPath, "Assets");
            Directory.CreateDirectory(Object3D.AssetsPath);

            // Empty temp folder
            foreach (string tempFile in Directory.GetFiles(Object3D.AssetsPath).ToList())
            {
                File.Delete(tempFile);
            }

            scene.Save(filePath);
            Assert.AreEqual(1, Directory.GetFiles(tempPath).Length, "Only .mcx file should exists");
            Assert.AreEqual(1, Directory.GetFiles(Path.Combine(tempPath, "Assets")).Length, "Only 1 asset should exist");

            var originalFiles = Directory.GetFiles(tempPath).ToArray();

            // Load the file from disk
            IObject3D loadedItem = Object3D.Load(filePath, CancellationToken.None);
            Assert.AreEqual(1, loadedItem.Children.Count);

            // Ensure the UI scene is cleared
            scene.Children.Modify(list => list.Clear());

            // Reload the model
            await Task.Run(() =>
            {
                sceneContext.Scene.Load(Object3D.Load(filePath, CancellationToken.None));
            });

            // Serialize and compare the two trees
            string onDiskData   = loadedItem.ToJson();
            string inMemoryData = scene.ToJson();

            //File.WriteAllText(@"c:\temp\file-a.txt", onDiskData);
            //File.WriteAllText(@"c:\temp\file-b.txt", inMemoryData);

            Assert.AreEqual(inMemoryData, onDiskData, "Serialized content should match");
            Object3D.AssetsPath = Path.Combine(tempPath, "Assets");

            // Save the scene a second time, validate that things remain the same
            scene.Save(filePath);
            onDiskData = loadedItem.ToJson();

            Assert.IsTrue(inMemoryData == onDiskData);

            // Verify that no additional files get created on second save
            Assert.AreEqual(1, Directory.GetFiles(tempPath).Length, "Only .mcx file should exists");
            Assert.AreEqual(1, Directory.GetFiles(Path.Combine(tempPath, "Assets")).Length, "Only 1 asset should exist");
        }
 public void TestSetup()
 {
     StaticData.RootPath = TestContext.CurrentContext.ResolveProjectPath(4, "StaticData");
     MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));
 }
Esempio n. 14
0
        public void PauseHandlingStreamTests()
        {
            int readX = 50;

            // Validate that the number parsing code is working as expected, specifically ignoring data that appears in comments
            // This is a regression that we saw in the Lulzbot Mini profile after adding macro processing.
            GCodeFile.GetFirstNumberAfter("X", "G1 Z10 E - 10 F12000 ; suck up XXmm of filament", ref readX);
            // did not change
            Assert.AreEqual(50, readX, "Don't change the x if it is after a comment");

            // a comments that looks more like a valid line
            GCodeFile.GetFirstNumberAfter("X", "G1 Z10 E - 10 F12000 ; X33", ref readX);
            // did not change
            Assert.AreEqual(50, readX, "Don't change the x if it is after a comment");
            // a line that should parse
            GCodeFile.GetFirstNumberAfter("X", "G1 Z10 E - 10 F12000 X33", ref readX);
            // did change
            Assert.AreEqual(33, readX, "not in a comment, do a change");

            string[] inputLines = new string[]
            {
                "; the printer is moving normally",
                "G1 X10 Y10 Z10 E0",
                "G1 X10 Y10 Z10 E10",
                "G1 X10 Y10 Z10 E30",

                "; the printer pauses",
                "G91",
                "G1 Z10 E - 10 F12000 ; suck up XXmm of filament",
                "G90",

                "; the user moves the printer",

                "; the printer un-pauses",
                "G91",
                "G1 Z-10 E10.8 F12000",
                "G90",
                null,
            };

            // We should go back to the above code when possible. It requires making pause part and move while paused part of the stream.
            // All communication should go through stream to minimize the difference between printing and controlling while not printing (all printing in essence).
            string[] expected = new string[]
            {
                "; the printer is moving normally",
                "G1 X10 Y10 Z10 E0",
                "G1 E10",
                "G1 E30",

                "; the printer pauses",
                "",                  // G91 is removed
                "G1 Z20 E20 F12000", // altered to be absolute
                "G90",

                "; the user moves the printer",

                "; the printer un-pauses",
                "",                 // G91 is removed
                "G1 Z10 E30.8",
                "G90",
                null,
            };

            AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

            var         printer             = new PrinterConfig(new PrinterSettings());
            GCodeStream pauseHandlingStream = CreateTestGCodeStream(printer, inputLines, out List <GCodeStream> streamList);

            ValidateStreamResponse(expected, pauseHandlingStream);
        }
Esempio n. 15
0
        public void ExportStreamG30Tests()
        {
            string[] inputLines = new string[]
            {
                "M117 Starting Print",
                "M104 S0",
                "; comment line",
                "G28 ; home all axes",
                "G0 Z10 F1800",
                "G0 Z11 F1800",
                "G0 X1Y0Z9 F1800",
                "G0 Z10 F1801",
                "G30 Z0",
                "M114",
                "G0 Z10 F1800",
                "M114",
                "M109 S[temperature]",
                null,
            };

            // We should go back to the above code when possible. It requires making pause part and move while paused part of the stream.
            // All communication should go through stream to minimize the difference between printing and controlling while not printing (all printing in essence).
            string[] expected = new string[]
            {
                "M117 Starting Print",
                "M104 S0",
                "; comment line",
                "G28 ; home all axes",
                "G1 Z10 F1800",
                "G1 Z11",
                "G1 X1 Y0 Z9",
                "G1 Z10 F1801",
                "G30 Z0",
                "M114",
                "G1 Z10 F1800",
                "M114",
                "M109 S[temperature]",
                null,
            };

            AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

            var printer = new PrinterConfig(new PrinterSettings());

            var testStream = GCodeExport.GetExportStream(printer, new TestGCodeStream(printer, inputLines), true);

            int    expectedIndex = 0;
            string actualLine    = testStream.ReadLine();
            string expectedLine  = expected[expectedIndex++];

            Assert.AreEqual(expectedLine, actualLine, "Unexpected response from testStream");
            Debug.WriteLine(actualLine);

            while (actualLine != null)
            {
                actualLine = testStream.ReadLine();
                if (actualLine == "G92 E0")
                {
                    testStream.SetPrinterPosition(new PrinterMove(new Vector3(), 0, 300));
                }

                expectedLine = expected[expectedIndex++];

                Debug.WriteLine(actualLine);
                Assert.AreEqual(expectedLine, actualLine, "Unexpected response from testStream");
            }
        }
Esempio n. 16
0
        public void MorePauseHandlingStreamTests()
        {
            string[] inputLines = new string[]
            {
                "; the printer is moving normally",
                "G1 X10 Y10 Z10 E0",
                "G1 X11 Y10 Z10 E10",
                "G1 X12 Y10 Z10 E30",

                "; the printer pauses",
                "@pause",

                "; do_resume",                 // just a marker for us to issue a resume

                // move some more
                "G1 X13 Y10 Z10 E40",
                null,
            };

            // We should go back to the above code when possible. It requires making pause part and move while paused part of the stream.
            // All communication should go through stream to minimize the difference between printing and controlling while not printing (all printing in essence).
            string[] expected = new string[]
            {
                "; the printer is moving normally",
                "G1 X10 Y10 Z10 E0",
                "G1 X11 E10",
                "G1 X12 E30",
                "; the printer pauses",
                "",
                "",
                "G1 Z20 E20 F12000",
                "G90",
                "M114",
                "",
                "; do_resume",
                "G92 E-10",
                "G1 Z16.67 F3001",
                "G1 X12.01 Y10.01 Z13.34",
                "G1 Z10.01",
                "G1 X12 Y10 Z10 F3000",
                "",
                "G1 Z0 E30.8 F12000",
                "G90",
                "M114",
                "",
                "G1 X12.1 F1800",
                "G1 X12.2",
                "G90",
                "G1 X12.33 Z1.667 E32.333",
                "G1 X12.47 Z3.333 E33.867",
                "G1 X12.6 Z5 E35.4",
                "G1 X12.73 Z6.667 E36.933",
                "G1 X12.87 Z8.333 E38.467",
                "G1 X13 Z10 E40",
                null,
            };

            AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

            // this is the pause and resume from the Eris
            var printer = new PrinterConfig(new PrinterSettings());

            printer.Settings.SetValue(SettingsKey.pause_gcode, "G91\nG1 Z10 E - 10 F12000\n  G90");
            printer.Settings.SetValue(SettingsKey.resume_gcode, "G91\nG1 Z-10 E10.8 F12000\nG90");

            GCodeStream pauseHandlingStream = CreateTestGCodeStream(printer, inputLines, out List <GCodeStream> streamList);

            ValidateStreamResponse(expected, pauseHandlingStream, streamList);
        }
Esempio n. 17
0
        public void CsgCylinderMinusCylinder()
        {
            AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

            AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(5, "MatterControl", "StaticData"));
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(5));

            // check that we subtarct two 3 sideh cylinders
            {
                double    topHeight = 10;
                int       sides     = 3;
                IObject3D keep      = CylinderObject3D.Create(20, topHeight * 2, sides);
                IObject3D subtract  = CylinderObject3D.Create(10, topHeight * 2, sides);

                var keepMesh     = keep.Mesh;
                var subtractMesh = subtract.Mesh;

                if (false)
                {
                    var split1 = new DebugFace()
                    {
                        EvaluateHeight = topHeight,
                        FileName       = "Split1"
                    };

                    BooleanModeller.Object1SplitFace    = split1.Split;
                    BooleanModeller.Object1SplitResults = split1.Result;

                    BooleanModeller.Object1ClassifyFace = split1.Classify1;
                    BooleanModeller.Object2ClassifyFace = split1.Classify2;
                }

                var resultMesh = keepMesh.Subtract(subtractMesh, null, CancellationToken.None);

                // this is for debuging the opperation
                //split1.FinishOutput();
                //resultMesh.Save("c:/temp/mesh1.stl", CancellationToken.None);

                var topZero = new Vector3(0, 0, topHeight);
                foreach (var topVertex in keepMesh.Vertices
                         .Where((v) => v.Position.Z == topHeight && v.Position != topZero)
                         .Select((gv) => gv.Position))
                {
                    Assert.IsTrue(resultMesh.Vertices.Where((v) => v.Position == topVertex).Any(), "Have all top vertexes");
                }
                foreach (var topVertex in subtractMesh.Vertices
                         .Where((v) => v.Position.Z == topHeight && v.Position != topZero)
                         .Select((gv) => gv.Position))
                {
                    Assert.IsTrue(resultMesh.Vertices.Where((v) => v.Position == topVertex).Any(), "Have all top vertexes");
                }
            }

            // check that we subtarct two 3 sideh cylinders
            {
                int       sides    = 3;
                IObject3D keep     = CylinderObject3D.Create(20, 20, sides);
                IObject3D subtract = CylinderObject3D.Create(10, 22, sides);

                var keepMesh     = keep.Mesh;
                var subtractMesh = subtract.Mesh;

                if (false)
                {
                    var split1 = new DebugFace()
                    {
                        EvaluateHeight = 10,
                        FileName       = "Split2"
                    };

                    BooleanModeller.Object1SplitFace    = split1.Split;
                    BooleanModeller.Object1SplitResults = split1.Result;
                }

                var resultMesh = keepMesh.Subtract(subtractMesh, null, CancellationToken.None);

                // this is for debuging the opperation
                //split1.FinishOutput();
                //resultMesh.Save("c:/temp/mesh2.stl", CancellationToken.None);

                foreach (var topVertex in keepMesh.Vertices
                         .Where((v) => v.Position.Z == 10 && v.Position != new Vector3(0, 0, 10))
                         .Select((gv) => gv.Position))
                {
                    Assert.IsTrue(resultMesh.Vertices.Where((v) => v.Position == topVertex).Any(), "Have all top vertexes");
                }
                foreach (var topVertex in subtractMesh.Vertices
                         .Where((v) => v.Position.Z == 11 && v.Position != new Vector3(0, 0, 11))
                         .Select((gv) => gv.Position))
                {
                    Assert.IsTrue(resultMesh.Vertices
                                  .Where((v) => v.Position.Equals(new Vector3(topVertex.X, topVertex.Y, 10), .0001))
                                  .Any(), "Have all top vertexes");
                }
            }
        }
        public void LibraryProviderFileSystem_NavigationWorking()
        {
            StaticData.Instance = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

            string meshFileName        = "Box20x20x10.stl";
            string meshPathAndFileName = TestContext.CurrentContext.ResolveProjectPath(5, "MatterControl", "Tests", "TestData", "TestMeshes", "LibraryProviderData", meshFileName);
            int    dataReloadedCount   = 0;

            string downloadsDirectory   = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads");
            string testLibraryDirectory = Path.Combine(downloadsDirectory, "LibraryProviderFileSystemTest");

            if (Directory.Exists(testLibraryDirectory))
            {
                Directory.Delete(testLibraryDirectory, true);
            }

            Directory.CreateDirectory(testLibraryDirectory);

            LibraryProviderFileSystem testProvider = new LibraryProviderFileSystem(testLibraryDirectory, "TestPath", null, null);

            testProvider.DataReloaded += (s, e) => { dataReloadedCount++; };

            AutomationRunner.StaticDelay(() => { return(dataReloadedCount > 0); }, 1);
            dataReloadedCount = 0;

            Assert.IsTrue(testProvider.CollectionCount == 0, "Start with a new database for these tests.");
            Assert.IsTrue(testProvider.ItemCount == 0, "Start with a new database for these tests.");

            // create a collection and make sure it is on disk
            Assert.AreEqual(0, dataReloadedCount);             // it has been loaded for the default set of parts

            string collectionName   = "Collection1";
            string createdDirectory = Path.Combine(testLibraryDirectory, collectionName);

            Assert.IsFalse(Directory.Exists(createdDirectory), "CreatedDirectory should *not* exist");
            Assert.AreEqual(0, dataReloadedCount, "Reload should *not* have occurred");

            testProvider.AddCollectionToLibrary(collectionName);
            AutomationRunner.StaticDelay(() => { return(testProvider.CollectionCount == 1); }, 1);

            Assert.AreEqual(1, testProvider.CollectionCount, "Incorrect collection count");
            Assert.IsTrue(dataReloadedCount > 0, "Reload should *have* occurred");
            Assert.IsTrue(Directory.Exists(createdDirectory), "CreatedDirectory *should* exist");

            // add an item works correctly
            LibraryProvider subProvider = testProvider.GetProviderForCollection(testProvider.GetCollectionItem(0));

            subProvider.DataReloaded += (sender, e) => { dataReloadedCount++; };
            dataReloadedCount         = 0;
            string subPathAndFile = Path.Combine(createdDirectory, meshFileName);

            Assert.IsFalse(File.Exists(subPathAndFile), "File should *not* exist: " + subPathAndFile);
            Assert.AreEqual(0, dataReloadedCount, "Reload should *not* have occurred");

            // WIP: saving the name incorrectly for this location (does not need to be changed).
            subProvider.AddFilesToLibrary(new string[] { meshPathAndFileName });
            AutomationRunner.StaticDelay(() => { return(subProvider.ItemCount == 1); }, 1);

            PrintItemWrapper itemAtRoot = subProvider.GetPrintItemWrapperAsync(0).Result;

            Assert.IsTrue(subProvider.ItemCount == 1);
            Assert.IsTrue(dataReloadedCount > 0);
            //Assert.IsTrue(itemAdded == true);
            Assert.IsTrue(File.Exists(subPathAndFile));

            // make sure the provider locater is correct

            // remove item works
            dataReloadedCount = 0;
            Assert.IsTrue(dataReloadedCount == 0);
            subProvider.RemoveItem(0);
            AutomationRunner.StaticDelay(() => { return(subProvider.ItemCount == 0); }, 1);
            Assert.IsTrue(dataReloadedCount > 0);
            Assert.IsTrue(!File.Exists(subPathAndFile));

            // remove collection gets rid of it
            dataReloadedCount = 0;
            testProvider.RemoveCollection(0);
            AutomationRunner.StaticDelay(() => { return(testProvider.CollectionCount == 0); }, 1);
            Assert.IsTrue(dataReloadedCount > 0);
            Assert.IsTrue(testProvider.CollectionCount == 0);
            Assert.IsTrue(!Directory.Exists(createdDirectory));

            if (Directory.Exists(testLibraryDirectory))
            {
                Directory.Delete(testLibraryDirectory, true);
            }
        }
        public void CheckIfShouldBeShownParseTests()
        {
            AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

            // test single if set to 0
            {
                string[] settings = new string[] { SettingsKey.has_heated_bed, "0" };
                var      profile  = GetProfile(settings);
                Assert.IsFalse(profile.ParseShowString("has_heated_bed"));
                Assert.IsTrue(profile.ParseShowString("!has_heated_bed"));
            }

            // test single >
            {
                string[] settings = new string[] { SettingsKey.extruder_count, "1" };
                var      profile  = GetProfile(settings);
                Assert.IsFalse(profile.ParseShowString("extruder_count>1"));
                Assert.IsTrue(profile.ParseShowString("extruder_count>0"));
            }

            // test single >
            {
                string[] settings = new string[] { SettingsKey.extruder_count, "2" };
                var      profile  = GetProfile(settings);
                Assert.IsFalse(profile.ParseShowString("extruder_count>3"));
                Assert.IsFalse(profile.ParseShowString("extruder_count>2"));
                Assert.IsTrue(profile.ParseShowString("extruder_count>1"));
                Assert.IsTrue(profile.ParseShowString("extruder_count>0"));
            }

            // test single if set to 1
            {
                string[] settings = new string[] { SettingsKey.has_heated_bed, "1" };
                var      profile  = GetProfile(settings);
                Assert.IsTrue(profile.ParseShowString("has_heated_bed"));
                Assert.IsFalse(profile.ParseShowString("!has_heated_bed"));
            }

            // test & with set to 0 and 0
            {
                string[] settings = new string[] { SettingsKey.has_heated_bed, "0", SettingsKey.auto_connect, "0" };
                var      profile  = GetProfile(settings);
                Assert.IsFalse(profile.ParseShowString("has_heated_bed&auto_connect"));
                Assert.IsFalse(profile.ParseShowString("has_heated_bed&!auto_connect"));
                Assert.IsFalse(profile.ParseShowString("!has_heated_bed&auto_connect"));
                Assert.IsTrue(profile.ParseShowString("!has_heated_bed&!auto_connect"));
            }

            // test & with 0 and 1
            {
                string[] settings = new string[] { SettingsKey.has_heated_bed, "0", SettingsKey.auto_connect, "1" };
                var      profile  = GetProfile(settings);
                Assert.IsFalse(profile.ParseShowString("has_heated_bed&auto_connect"));
                Assert.IsFalse(profile.ParseShowString("has_heated_bed&!auto_connect"));
                Assert.IsTrue(profile.ParseShowString("!has_heated_bed&auto_connect"));
                Assert.IsFalse(profile.ParseShowString("!has_heated_bed&!auto_connect"));
            }

            // test & with 1 and 0
            {
                string[] settings = new string[] { SettingsKey.has_heated_bed, "1", SettingsKey.auto_connect, "0" };
                var      profile  = GetProfile(settings);
                Assert.IsFalse(profile.ParseShowString("has_heated_bed&auto_connect"));
                Assert.IsTrue(profile.ParseShowString("has_heated_bed&!auto_connect"));
                Assert.IsFalse(profile.ParseShowString("!has_heated_bed&auto_connect"));
                Assert.IsFalse(profile.ParseShowString("!has_heated_bed&!auto_connect"));
            }

            // test & with 1 and 1
            {
                string[] settings = new string[] { SettingsKey.has_heated_bed, "1", SettingsKey.auto_connect, "1" };
                var      profile  = GetProfile(settings);
                Assert.IsTrue(profile.ParseShowString("has_heated_bed&auto_connect"));
                Assert.IsFalse(profile.ParseShowString("has_heated_bed&!auto_connect"));
                Assert.IsFalse(profile.ParseShowString("!has_heated_bed&auto_connect"));
                Assert.IsFalse(profile.ParseShowString("!has_heated_bed&!auto_connect"));
            }

            // test 3 &s
            {
                string[] settings = new string[] { SettingsKey.has_heated_bed, "1", SettingsKey.auto_connect, "1", SettingsKey.has_fan, "1" };
                var      profile  = GetProfile(settings);
                Assert.IsTrue(profile.ParseShowString("has_heated_bed&auto_connect&has_fan"));
                Assert.IsTrue(profile.ParseShowString("has_heated_bed&auto_connect&has_fan|!has_sdcard"));
                Assert.IsTrue(profile.ParseShowString("has_heated_bed&auto_connect&!has_sdcard|has_fan"));
                Assert.IsTrue(profile.ParseShowString("has_heated_bed&auto_connect&has_sdcard|has_fan"));
                Assert.IsFalse(profile.ParseShowString("has_heated_bed&auto_connect&!has_fan"));
                Assert.IsFalse(profile.ParseShowString("has_heated_bed&!auto_connect&has_fan"));
                Assert.IsFalse(profile.ParseShowString("!has_heated_bed&auto_connect&has_fan"));
            }

            // test list setting value
            {
                string[] settings = new string[] { SettingsKey.has_hardware_leveling, "0",
                                                   SettingsKey.print_leveling_solution, "3 Point Plane",
                                                   SettingsKey.extruder_count, "2" };
                var profile = GetProfile(settings);
                Assert.IsTrue(profile.ParseShowString("!has_hardware_leveling&print_leveling_solution=3 Point Plane"));
                Assert.IsTrue(profile.ParseShowString("!has_hardware_leveling&print_leveling_solution=3 Point Plane|print_leveling_solution=3x3 Mesh"));
                Assert.IsTrue(profile.ParseShowString("!has_hardware_leveling&print_leveling_solution=3x3 Mesh|print_leveling_solution=3 Point Plane"));
                Assert.IsTrue(profile.ParseShowString("!has_hardware_leveling&!print_leveling_solution=7 Point Disk"));
                Assert.IsFalse(profile.ParseShowString("has_hardware_leveling&print_leveling_solution=3 Point Plane"));
                Assert.IsFalse(profile.ParseShowString("!has_hardware_leveling&!print_leveling_solution=3 Point Plane"));
                Assert.IsFalse(profile.ParseShowString("!has_hardware_leveling&print_leveling_solution=7 Point Disk"));

                Assert.IsFalse(profile.ParseShowString("!has_hardware_leveling&print_leveling_solution=3 Point Plane&extruder_count>2"));
                Assert.IsFalse(profile.ParseShowString("!has_hardware_leveling&print_leveling_solution=3 Point Plane&extruder_count>2"));
                Assert.IsTrue(profile.ParseShowString("!has_hardware_leveling&print_leveling_solution=3 Point Plane&extruder_count>1"));
                Assert.IsTrue(profile.ParseShowString("!has_hardware_leveling&print_leveling_solution=3 Point Plane&extruder_count>0"));
            }
        }
Esempio n. 20
0
        public void LevelingMesh3x3CorectInterpolation()
        {
            AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

            var printerSettings = new PrinterSettings();

            printerSettings.SetValue(SettingsKey.z_probe_z_offset, "0");

            var printer = new PrinterConfig(printerSettings);

            // a 2 x 2 mesh that goes form 0 on the left to 10 on the right
            {
                var levelingData = new PrintLevelingData();

                // put them in left to right - bottom to top
                levelingData.SampledPositions = new List <Vector3>();
                levelingData.SampledPositions.Add(new Vector3(0, 0, 0));
                levelingData.SampledPositions.Add(new Vector3(10, 0, 10));
                levelingData.SampledPositions.Add(new Vector3(0, 10, 0));
                levelingData.SampledPositions.Add(new Vector3(10, 10, 10));

                LevelingFunctions levelingFunctionsMesh2x2 = new LevelingFunctions(printer, levelingData);

                // check on points
                AssertMeshLevelPoint(new Vector3(0, 0, 0), new Vector3(0, 0, 0), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(10, 0, 0), new Vector3(10, 0, 10), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(10, 10, 0), new Vector3(10, 10, 10), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(0, 10, 0), new Vector3(0, 10, 0), levelingFunctionsMesh2x2);

                // check raised on points
                AssertMeshLevelPoint(new Vector3(0, 0, 5), new Vector3(0, 0, 5), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(10, 0, 5), new Vector3(10, 0, 15), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(10, 10, 5), new Vector3(10, 10, 15), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(0, 10, 5), new Vector3(0, 10, 5), levelingFunctionsMesh2x2);

                // check between points
                AssertMeshLevelPoint(new Vector3(5, 0, 0), new Vector3(5, 0, 5), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(5, 0, 5), new Vector3(5, 0, 10), levelingFunctionsMesh2x2);

                // check outside points
                AssertMeshLevelPoint(new Vector3(-5, 0, 0), new Vector3(-5, 0, -5), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(-5, 0, 5), new Vector3(-5, 0, 0), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(15, 0, 0), new Vector3(15, 0, 15), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(15, 0, 5), new Vector3(15, 0, 20), levelingFunctionsMesh2x2);
            }

            // a 3 x 3 mesh that goes form 0 on the left to 10 on the right
            {
                var levelingData = new PrintLevelingData();

                // put them in left to right - bottom to top
                levelingData.SampledPositions = new List <Vector3>();
                levelingData.SampledPositions.Add(new Vector3(0, 0, 0));
                levelingData.SampledPositions.Add(new Vector3(5, 0, 5));
                levelingData.SampledPositions.Add(new Vector3(10, 0, 10));
                levelingData.SampledPositions.Add(new Vector3(0, 5, 0));
                levelingData.SampledPositions.Add(new Vector3(5, 5, 5));
                levelingData.SampledPositions.Add(new Vector3(10, 5, 10));
                levelingData.SampledPositions.Add(new Vector3(0, 10, 0));
                levelingData.SampledPositions.Add(new Vector3(5, 10, 5));
                levelingData.SampledPositions.Add(new Vector3(10, 10, 10));

                LevelingFunctions levelingFunctionsMesh2x2 = new LevelingFunctions(printer, levelingData);

                // check on points
                AssertMeshLevelPoint(new Vector3(0, 0, 0), new Vector3(0, 0, 0), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(10, 0, 0), new Vector3(10, 0, 10), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(10, 10, 0), new Vector3(10, 10, 10), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(0, 10, 0), new Vector3(0, 10, 0), levelingFunctionsMesh2x2);

                // check raised on points
                AssertMeshLevelPoint(new Vector3(0, 0, 5), new Vector3(0, 0, 5), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(10, 0, 5), new Vector3(10, 0, 15), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(10, 10, 5), new Vector3(10, 10, 15), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(0, 10, 5), new Vector3(0, 10, 5), levelingFunctionsMesh2x2);

                // check between points
                AssertMeshLevelPoint(new Vector3(5, 0, 0), new Vector3(5, 0, 5), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(5, 0, 5), new Vector3(5, 0, 10), levelingFunctionsMesh2x2);

                // check outside points
                AssertMeshLevelPoint(new Vector3(-5, 0, 0), new Vector3(-5, 0, -5), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(-5, 0, 5), new Vector3(-5, 0, 0), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(15, 0, 0), new Vector3(15, 0, 15), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(15, 0, 5), new Vector3(15, 0, 20), levelingFunctionsMesh2x2);
            }
        }
        public void CorrectEOutputPositions()
        {
            string[] inputLines = new string[]
            {
                "G1 E11 F300",
                // BCN tool change test
                // Before:
                "G92 E0",
                "G91",
                "G1 E - 5 F302",
                "G90",
                // After:
                "G91",
                "G1 E8 F150",
                "G90",
                "G4 P0",
                "G92 E0",
                "G4 P0",
                "G91",
                "G1 E-2 F301",
                "G90",
                null,
            };

            // We should go back to the above code when possible. It requires making pause part and move while paused part of the stream.
            // All communication should go through stream to minimize the difference between printing and controlling while not printing (all printing in essence).
            string[] expected = new string[]
            {
                "G1 E1 F300",
                "G1 E2",
                "G1 E3",
                "G1 E4",
                "G1 E5",
                "G1 E6",
                "G1 E7",
                "G1 E8",
                "G1 E9",
                "G1 E10",
                "G1 E11",
                "G92 E0",
                "",
                "G1 E-1 F302",
                "G1 E-2",
                "G1 E-3",
                "G1 E-4",
                "G1 E-5",
                "G90",
                "",
                "G1 E-4 F150",
                "G1 E-3",
                "G1 E-2",
                "G1 E-1",
                "G1 E0",
                "G1 E1",
                "G1 E2",
                "G1 E3",
                "G90",
                "G4 P0",
                "G92 E0",
                "G4 P0",
                "",
                "G1 E-1 F301",
                "G1 E-2",
                "G90",
                null,
            };

            AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

            List <GCodeStream> streamList;
            GCodeStream        testStream = CreateTestGCodeStream(inputLines, out streamList);

            int    expectedIndex = 0;
            string actualLine    = testStream.ReadLine();
            string expectedLine  = expected[expectedIndex++];

            Assert.AreEqual(expectedLine, actualLine, "Unexpected response from testStream");
            Debug.WriteLine(actualLine);

            while (actualLine != null)
            {
                actualLine = testStream.ReadLine();
                if (actualLine == "G92 E0")
                {
                    testStream.SetPrinterPosition(new PrinterMove(new Vector3(), 0, 300));
                }

                expectedLine = expected[expectedIndex++];

                Debug.WriteLine(actualLine);
                Assert.AreEqual(expectedLine, actualLine, "Unexpected response from testStream");
            }
        }
Esempio n. 22
0
        public void Leveling7PointsCorectInterpolation()
        {
            StaticData.Instance = new MatterHackers.Agg.FileSystemStaticData(Path.Combine("..", "..", "..", "..", "StaticData"));

            MatterControlUtilities.OverrideAppDataLocation();

            var levelingData = new PrintLevelingData(ActiveSliceSettings.Instance);

            double radius = 100;

            levelingData.SampledPositions = new List <Vector3>();
            Vector2 currentEdgePoint = new Vector2(radius, 0);

            for (int i = 0; i < 6; i++)
            {
                levelingData.SampledPositions.Add(new Vector3(currentEdgePoint, i));
                currentEdgePoint.Rotate(MathHelper.Tau / 6);
            }

            levelingData.SampledPositions.Add(new Vector3(0, 0, 6));

            Vector2 bedCenter = Vector2.Zero;

            RadialLevlingFunctions levelingFunctions7Point = new RadialLevlingFunctions(6, levelingData, bedCenter);

            for (int curPoint = 0; curPoint < 6; curPoint++)
            {
                int nextPoint = curPoint < 5 ? curPoint + 1 : 0;

                // test actual sample position
                Vector2 currentTestPoint = new Vector2(radius, 0);
                currentTestPoint.Rotate(MathHelper.Tau / 6 * curPoint);
                Vector3 destPosition = new Vector3(currentTestPoint, 0);
                Vector3 outPosition  = levelingFunctions7Point.GetPositionWithZOffset(destPosition);
                Assert.AreEqual(outPosition.z, levelingData.SampledPositions[curPoint].z, .001);
                string outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Absolute);
                Assert.AreEqual(GetGCodeString(outPosition), outPositionString);

                // test mid point between samples
                Vector3 midPoint = (levelingData.SampledPositions[curPoint] + levelingData.SampledPositions[nextPoint]) / 2;
                currentTestPoint = new Vector2(midPoint.x, midPoint.y);
                destPosition     = new Vector3(currentTestPoint, 0);
                outPosition      = levelingFunctions7Point.GetPositionWithZOffset(destPosition);
                Assert.AreEqual(outPosition.z, midPoint.z, .001);
                outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Absolute);
                Assert.AreEqual(GetGCodeString(outPosition), outPositionString);

                // test mid point between samples with offset
                Vector3 midPointWithOffset = (levelingData.SampledPositions[curPoint] + levelingData.SampledPositions[nextPoint]) / 2 + new Vector3(0, 0, 3);
                currentTestPoint = new Vector2(midPointWithOffset.x, midPointWithOffset.y);
                destPosition     = new Vector3(currentTestPoint, 3);
                outPosition      = levelingFunctions7Point.GetPositionWithZOffset(destPosition);
                Assert.AreEqual(outPosition.z, midPointWithOffset.z, .001);
                outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Absolute);
                Assert.AreEqual(GetGCodeString(outPosition), outPositionString);

                // test 1/2 angles (mid way between samples on radius)
                currentTestPoint = new Vector2(radius, 0);
                currentTestPoint.Rotate(MathHelper.Tau / 6 * (curPoint + .5));
                destPosition = new Vector3(currentTestPoint, 0);
                outPosition  = levelingFunctions7Point.GetPositionWithZOffset(destPosition);
                // the center is the higest point so the point on the radius has to be less than the mid point of the sample points (it is lower)
                Assert.IsTrue(outPosition.z < (levelingData.SampledPositions[curPoint].z + levelingData.SampledPositions[nextPoint].z) / 2 - .001);
                outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Absolute);
                Assert.AreEqual(GetGCodeString(outPosition), outPositionString);

                // test 1/2 to center
                currentTestPoint = new Vector2(radius / 2, 0);
                currentTestPoint.Rotate(MathHelper.Tau / 6 * curPoint);
                destPosition = new Vector3(currentTestPoint, 0);
                outPosition  = levelingFunctions7Point.GetPositionWithZOffset(destPosition);
                Assert.AreEqual(outPosition.z, (levelingData.SampledPositions[curPoint].z + levelingData.SampledPositions[6].z) / 2, .001);
                outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Absolute);
                Assert.AreEqual(GetGCodeString(outPosition), outPositionString);
            }

            // prove that relative offsets work
            {
                Vector2 prevTestPoint         = new Vector2(radius, 0);
                Vector3 prevDestPosition      = new Vector3(prevTestPoint, 0);
                Vector3 prevOutPosition       = levelingFunctions7Point.GetPositionWithZOffset(prevDestPosition);
                string  prevOutPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(prevDestPosition), prevDestPosition, PrinterMachineInstruction.MovementTypes.Absolute);

                for (int curPoint = 1; curPoint < 6; curPoint++)
                {
                    // test actual sample position
                    Vector2 currentTestPoint = new Vector2(radius, 0);
                    currentTestPoint.Rotate(MathHelper.Tau / 6 * curPoint);
                    Vector3 destPosition = new Vector3(currentTestPoint, 0);
                    Vector3 outPosition  = levelingFunctions7Point.GetPositionWithZOffset(destPosition);

                    string  outPositionString      = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Relative);
                    Vector3 delatFromPrevToCurrent = outPosition - prevOutPosition;
                    Assert.AreEqual(GetGCodeString(delatFromPrevToCurrent), outPositionString);

                    prevTestPoint    = currentTestPoint;
                    prevDestPosition = destPosition;
                    prevOutPosition  = outPosition;
                }
            }

            Vector3 outPosition2 = levelingFunctions7Point.GetPositionWithZOffset(Vector3.Zero);

            Assert.AreEqual(outPosition2.z, levelingData.SampledPositions[6].z, .001);
        }
Esempio n. 23
0
        public void DownloadsExportButtonExportsGcode()
        {
            // Run a copy of MatterControl
            Action <AutomationTesterHarness> testToRun = (AutomationTesterHarness resultsHarness) =>
            {
                AutomationRunner testRunner = new AutomationRunner(MatterControlUtilities.DefaultTestImages);
                {
                    //Add printer profile so that we can export gcode
                    //TODO: Seperate this logic out into a seperate function so we dont have to re-write code

                    testRunner.ClickByName("Select a Printer Button");
                    testRunner.Wait(1);

                    testRunner.ClickByName("Select Make");
                    testRunner.Wait(1);

                    testRunner.ClickByName("Airwolf 3D Menu Item");
                    testRunner.Wait(1);

                    testRunner.ClickByName("Select Model");
                    testRunner.Wait(1);

                    testRunner.ClickByName("HD Menu Item");
                    testRunner.Wait(1);

                    testRunner.ClickByName("Save & Continue Button");
                    testRunner.Wait(1);

                    testRunner.ClickByName("Setup Connection Cancel Button");
                    testRunner.Wait(1);

                    testRunner.ClickByName("Airwolf 3D HD Profile");
                    testRunner.Wait(1);


                    string firstItemName = "Row Item " + "Batman";

                    //Navigate to Downloads Library Provider
                    testRunner.ClickByName("Library Tab");
                    MatterControlUtilities.NavigateToFolder(testRunner, "Downloads Row Item Collection");
                    testRunner.ClickByName("Library Add Button");
                    testRunner.Wait(2);

                    //Get parts to add
                    string rowItemPath = MatterControlUtilities.PathToQueueItemsFolder("Batman.stl");

                    //Get files to delete from Downloads once each test has completed and then add them to List
                    string firstFileToDelete = Path.Combine(MatterControlUtilities.PathToDownloadsFolder, "Batman.stl");
                    addedFiles.Add(firstFileToDelete);

                    //Add STL part items to Downloads and then type paths into file dialogue
                    testRunner.Wait(2);
                    testRunner.Type(rowItemPath);
                    testRunner.Wait(1);
                    testRunner.Type("{Enter}");

                    //Get test results
                    bool firstRowItemWasAdded = testRunner.WaitForName(firstItemName, 2);
                    resultsHarness.AddTestResult(firstRowItemWasAdded == true);

                    testRunner.ClickByName("Library Edit Button");
                    testRunner.ClickByName(firstItemName);
                    testRunner.ClickByName("Library Export Button");
                    testRunner.Wait(2);

                    //testRunner.WaitForName("Export Item Window", 2);
                    testRunner.ClickByName("Export as GCode Button");
                    testRunner.Wait(2);

                    string gcodeExportPath = MatterControlUtilities.PathToExportGcodeFolder;
                    testRunner.Type(gcodeExportPath);
                    testRunner.Type("{Enter}");
                    testRunner.Wait(2);

                    bool gcodeExported = false;

                    if (File.Exists(gcodeExportPath))
                    {
                        gcodeExported = true;
                    }

                    resultsHarness.AddTestResult(gcodeExported == true);


                    MatterControlUtilities.CloseMatterControl(testRunner);
                }
            };

            AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun);

            MatterControlUtilities.CleanUpDownloadsDirectoryAfterTest(addedFiles);

            Assert.IsTrue(testHarness.AllTestsPassed);
            Assert.IsTrue(testHarness.TestCount == 2);             // make sure we ran all our tests
        }