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 ;
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
{
2018-10-10 09:43:14 -07:00
//[Test, Category("Emulator"), Ignore("WIP")]
[Test, Category("Emulator")]
2018-10-03 18:19:35 -07:00
public async Task ReSliceHasCorrectEPositions ( )
{
await MatterControlUtilities . RunTest ( ( testRunner ) = >
{
//testRunner.ClickByName("Connection Wizard Skip Sign In Button");
using ( var emulator = testRunner . LaunchAndConnectToPrinterEmulator ( ) )
{
2018-10-09 14:29:51 -07:00
var printer = ApplicationController . Instance . ActivePrinter ;
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 ;
var scene = view3D . InteractionLayer . Scene ;
2018-10-03 18:19:35 -07:00
testRunner . OpenPrintPopupMenu ( ) ;
// Add a pause on layer(in the center)
testRunner . ClickByName ( "Layer(s) To Pause Field" ) ;
testRunner . Type ( "50;60" ) ;
// Add a callback to check that every line has an extruder
// distance greater than the largest distance minus the max retraction
// amount and less than some amount that is reasonable
2018-10-08 09:44:06 -07:00
double lastAbsoluteEPostion = 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
emulator . RecievedInstruction + = ( e , s ) = >
{
if ( s . Contains ( "G92" ) )
{
int a = 0 ;
}
} ;
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 ) ;
2018-10-09 14:29:51 -07:00
var delta = emulator . CurrentExtruder . AbsoluteEPosition - lastAbsoluteEPostion ;
if ( delta < largestRetraction )
{
largestRetraction = delta ;
}
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" ) ;
Assert . GreaterOrEqual ( emulator . CurrentExtruder . AbsoluteEPosition , largestAbsoluteEPosition - printerRetraction , "Never go back more than the retaction amount" ) ;
2018-10-08 18:24:17 -07:00
Assert . LessOrEqual ( emulator . CurrentExtruder . AbsoluteEPosition , lastAbsoluteEPostion + 10 , "We should never move up more than 10 mm" ) ;
2018-10-08 09:44:06 -07:00
lastAbsoluteEPostion = emulator . CurrentExtruder . AbsoluteEPosition ;
2018-10-03 18:19:35 -07:00
} ;
// Add a cube to the bed
testRunner . NavigateToFolder ( "Print Queue Row Item Collection" ) ;
testRunner . ClickByName ( "Row Item cube_20x20x20" ) ;
testRunner . ClickByName ( "Print Library Overflow Menu" ) ;
2018-10-12 17:25:00 -07:00
testRunner . ClickByName ( "Add to Bed Menu Item" ) ;
2018-10-09 14:29:51 -07:00
testRunner . ClickByName ( "Print Library Overflow Menu" ) ;
2018-10-12 17:25:00 -07:00
testRunner . ClickByName ( "Add to Bed Menu Item" ) ;
2018-10-03 18:19:35 -07:00
// start the print
testRunner . StartPrint ( ) ;
// Wait for pause
2018-10-19 13:29:57 -07:00
testRunner . WaitForName ( "No Button" , 80 ) ; // the yes button is 'Resume'
2018-10-03 18:19:35 -07:00
testRunner . ClickByName ( "No Button" ) ;
// Delete the cube
testRunner . ClickByName ( "Bed Options Menu" ) ;
testRunner . ClickByName ( "Clear Bed Menu Item" ) ;
2018-10-08 18:24:17 -07:00
testRunner . Delay ( ) ;
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 a cylinder
2018-10-19 13:29:57 -07:00
testRunner . NavigateToFolder ( "Print Queue Row Item Collection" ) ;
2018-10-03 18:19:35 -07:00
testRunner . ClickByName ( "Row Item cylinder_5x20" ) ;
testRunner . ClickByName ( "Print Library Overflow Menu" ) ;
2018-10-12 17:25:00 -07:00
testRunner . ClickByName ( "Add to Bed Menu Item" ) ;
2018-10-19 17:27:49 -07:00
testRunner . ClickByName ( "Add Content Menu" ) ;
2018-10-03 18:19:35 -07:00
// re-slice the part
testRunner . ClickByName ( "Re-Slice Button" ) ;
2018-10-19 17:27:49 -07:00
testRunner . WaitForName ( "Yes Button" , 10 ) ; // The change to new g-code
2018-10-03 18:19:35 -07:00
testRunner . ClickByName ( "Yes Button" ) ;
// and resume the print
testRunner . ClickByName ( "Resume Task Button" ) ;
// Wait for next pause
2018-10-19 13:29:57 -07:00
testRunner . WaitForName ( "No Button" , 80 ) ; // the yes button is 'Resume'
2018-10-03 18:19:35 -07:00
testRunner . ClickByName ( "No Button" ) ;
// Switch back to the cube
// Delete the cylinder
testRunner . ClickByName ( "Bed Options Menu" ) ;
testRunner . 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
2018-10-19 13:29:57 -07:00
testRunner . NavigateToFolder ( "Print Queue Row Item Collection" ) ;
2018-10-03 18:19:35 -07:00
testRunner . ClickByName ( "Row Item cube_20x20x20" ) ;
testRunner . ClickByName ( "Print Library Overflow Menu" ) ;
2018-10-12 17:25:00 -07:00
testRunner . ClickByName ( "Add to Bed Menu Item" ) ;
2018-10-19 17:27:49 -07:00
testRunner . ClickByName ( "Add Content Menu" ) ;
2018-10-03 18:19:35 -07:00
// re-slice the part
testRunner . ClickByName ( "Re-Slice Button" ) ;
2018-10-19 17:27:49 -07:00
testRunner . WaitForName ( "Yes Button" , 10 ) ; // The change to new g-code
2018-10-03 18:19:35 -07:00
testRunner . ClickByName ( "Yes Button" ) ;
// and resume the print
testRunner . ClickByName ( "Resume Task Button" ) ;
// Wait for done
testRunner . WaitForPrintFinished ( ) ;
2018-10-09 14:29:51 -07:00
// this will make sure we turned off line spliting and had good data about the extruder position
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 ;
2018-10-19 13:29:57 -07:00
} , maxTimeToRun : 290 , queueItemFolderToAdd : QueueTemplate . ReSliceParts ) ;
2018-10-03 18:19:35 -07:00
}
}
}