2018-10-03 18:19:35 -07:00
/ *
Copyright ( c ) 2014 , Lars Brubaker
All rights reserved .
Redistribution and use in source and binary forms , with or without
modification , are permitted provided that the following conditions are met :
1. Redistributions of source code must retain the above copyright notice , this
list of conditions and the following disclaimer .
2. Redistributions in binary form must reproduce the above copyright notice ,
this list of conditions and the following disclaimer in the documentation
and / or other materials provided with the distribution .
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES
( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ;
LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies ,
either expressed or implied , of the FreeBSD Project .
* /
using System ;
using System.Collections.Generic ;
using System.Diagnostics ;
2018-11-30 12:53:43 -08:00
using System.Linq ;
2018-10-03 18:19:35 -07:00
using System.Threading ;
using System.Threading.Tasks ;
using MatterHackers.Agg.UI ;
using MatterHackers.GuiAutomation ;
2018-10-05 16:03:31 -07:00
using MatterHackers.MatterControl.PartPreviewWindow ;
2018-10-09 14:29:51 -07:00
using MatterHackers.MatterControl.SlicerConfiguration ;
2018-10-03 18:19:35 -07:00
using MatterHackers.MatterControl.VersionManagement ;
using NUnit.Framework ;
namespace MatterHackers.MatterControl.Tests.Automation
{
[TestFixture, Category("MatterControl.UI.Automation"), RunInApplicationDomain, Apartment(ApartmentState.STA)]
public class ReSliceTests
{
2019-04-29 11:40:16 -07:00
// [Test, Category("Emulator"), Ignore("WIP")]
2018-10-10 09:43:14 -07:00
[Test, Category("Emulator")]
2018-10-03 18:19:35 -07:00
public async Task ReSliceHasCorrectEPositions ( )
{
await MatterControlUtilities . RunTest ( ( testRunner ) = >
{
2019-04-29 11:40:16 -07:00
// testRunner.ClickByName("Connection Wizard Skip Sign In Button");
2018-10-03 18:19:35 -07:00
using ( var emulator = testRunner . LaunchAndConnectToPrinterEmulator ( ) )
{
2020-05-16 09:31:54 -07:00
ApplicationController . Instance . Allow32BitReSlice = true ;
2018-11-30 13:04:25 -08:00
var printer = testRunner . FirstPrinter ( ) ;
2018-11-03 08:45:17 -07:00
printer . Settings . SetValue ( SettingsKey . enable_line_splitting , "0" ) ;
2018-10-09 14:29:51 -07:00
2018-10-05 16:03:31 -07:00
var view3D = testRunner . GetWidgetByName ( "View3DWidget" , out _ ) as View3DWidget ;
2020-09-11 19:59:14 -07:00
var scene = view3D . Object3DControlLayer . Scene ;
2018-10-05 16:03:31 -07:00
2019-04-29 11:40:16 -07:00
// Add a callback to check that every line has an extruder
// distance greater than the largest distance minus the max retraction
2018-10-03 18:19:35 -07:00
// amount and less than some amount that is reasonable
2019-01-16 15:10:08 -08:00
double lastAbsoluteEPosition = 0 ;
2018-10-10 09:43:14 -07:00
double largestAbsoluteEPosition = 0 ;
2018-10-09 14:29:51 -07:00
double largestRetraction = 0 ;
2018-10-24 15:12:38 -07:00
2018-10-03 18:19:35 -07:00
emulator . EPositionChanged + = ( e , s ) = >
{
2018-10-10 09:43:14 -07:00
largestAbsoluteEPosition = Math . Max ( largestAbsoluteEPosition , emulator . CurrentExtruder . AbsoluteEPosition ) ;
2019-01-16 15:10:08 -08:00
var delta = emulator . CurrentExtruder . AbsoluteEPosition - lastAbsoluteEPosition ;
2019-04-29 11:40:16 -07:00
if ( delta < largestRetraction )
2018-10-09 14:29:51 -07:00
{
largestRetraction = delta ;
}
2019-04-29 11:40:16 -07:00
2018-10-10 09:43:14 -07:00
double printerRetraction = 7 + . 1 ; // the airwolf has a retraction of 7 mm
Assert . GreaterOrEqual ( delta , - printerRetraction , "We should never move back more than the retraction amount" ) ;
2018-11-29 13:41:24 -08:00
Assert . GreaterOrEqual ( emulator . CurrentExtruder . AbsoluteEPosition , largestAbsoluteEPosition - printerRetraction , "Never go back more than the retraction amount" ) ;
2019-01-16 15:10:08 -08:00
Assert . LessOrEqual ( emulator . CurrentExtruder . AbsoluteEPosition , lastAbsoluteEPosition + 10 , "We should never move up more than 10 mm" ) ;
lastAbsoluteEPosition = emulator . CurrentExtruder . AbsoluteEPosition ;
2018-10-03 18:19:35 -07:00
} ;
// Add a cube to the bed
2022-03-22 17:26:21 -07:00
testRunner . NavigateToFolder ( "Queue Row Item Collection" )
. ClickByName ( "Row Item cube_20x20x20.stl" )
. ClickByName ( "Print Library Overflow Menu" )
. ClickByName ( "Add to Bed Menu Item" )
. Delay ( )
. ClickByName ( "Print Library Overflow Menu" )
. Delay ( )
. ClickByName ( "Add to Bed Menu Item" )
. Delay ( )
// start the print
. StartPrint ( printer , pauseAtLayers : "50;60" )
// Wait for pause
// the yes button is 'Resume'
. ClickByName ( "No Button" , secondsToWait : 80 )
// Delete the cube
. ClickByName ( "Bed Options Menu" )
. ClickByName ( "Clear Bed Menu Item" )
. Delay ( ) ;
// ensure there is nothing on the bed
2018-10-05 16:03:31 -07:00
Assert . AreEqual ( 0 , scene . Children . Count ) ;
2018-10-03 18:19:35 -07:00
// Add a cylinder
2022-03-22 17:26:21 -07:00
testRunner . NavigateToFolder ( "Queue Row Item Collection" )
. ClickByName ( "Row Item cylinder_5x20.stl" )
. ClickByName ( "Print Library Overflow Menu" )
. ClickByName ( "Add to Bed Menu Item" )
. ClickByName ( "Add Content Menu" )
// re-slice the part
. ClickByName ( "Re-Slice Button" )
// The change to new g-code
. ClickByName ( "Switch Button" , secondsToWait : 10 )
// and resume the print
. ClickByName ( "Resume Task Button" )
// Wait for next pause
. ClickByName ( "No Button" , secondsToWait : 80 )
// Switch back to the cube
// Delete the cylinder
. ClickByName ( "Bed Options Menu" )
. ClickByName ( "Clear Bed Menu Item" ) ;
2018-10-05 16:03:31 -07:00
// ensure there is nothing on the bed
Assert . AreEqual ( 0 , scene . Children . Count ) ;
2018-10-03 18:19:35 -07:00
// add the cube
2022-03-22 17:26:21 -07:00
testRunner . NavigateToFolder ( "Queue Row Item Collection" )
. ClickByName ( "Row Item cube_20x20x20.stl" )
. ClickByName ( "Print Library Overflow Menu" )
. ClickByName ( "Add to Bed Menu Item" )
. ClickByName ( "Add Content Menu" )
// re-slice the part
. ClickByName ( "Re-Slice Button" )
. ClickByName ( "Switch Button" , secondsToWait : 10 )
// and resume the print
. ClickByName ( "Resume Task Button" )
// Wait for done
. WaitForPrintFinished ( printer ) ;
2018-10-09 14:29:51 -07:00
2018-11-29 13:41:24 -08:00
// this will make sure we turned off line splitting and had good data about the extruder position
2018-10-09 14:29:51 -07:00
Assert . AreEqual ( - 7 , largestRetraction , "Airwolf HD has a retraction of 7mm, make sure we had one" ) ;
2018-10-03 18:19:35 -07:00
}
return Task . CompletedTask ;
2019-04-29 11:40:16 -07:00
} ,
2020-10-02 15:03:00 -07:00
maxTimeToRun : 390 ,
2019-04-29 11:40:16 -07:00
queueItemFolderToAdd : QueueTemplate . ReSliceParts ) ;
2018-10-03 18:19:35 -07:00
}
}
}