2014-06-05 11:45:40 -07:00
/ *
Copyright ( c ) 2014 , Lars Brubaker
All rights reserved .
Redistribution and use in source and binary forms , with or without
2015-04-08 15:20:10 -07:00
modification , are permitted provided that the following conditions are met :
2014-06-05 11:45:40 -07:00
1. Redistributions of source code must retain the above copyright notice , this
2015-04-08 15:20:10 -07:00
list of conditions and the following disclaimer .
2014-06-05 11:45:40 -07:00
2. Redistributions in binary form must reproduce the above copyright notice ,
this list of conditions and the following disclaimer in the documentation
2015-04-08 15:20:10 -07:00
and / or other materials provided with the distribution .
2014-06-05 11:45:40 -07:00
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
2015-04-08 15:20:10 -07:00
of the authors and should not be interpreted as representing official policies ,
2014-06-05 11:45:40 -07:00
either expressed or implied , of the FreeBSD Project .
* /
using MatterHackers.Agg ;
2015-08-01 14:44:53 -07:00
using MatterHackers.GCodeVisualizer ;
2014-06-05 11:45:40 -07:00
using MatterHackers.Localizations ;
2015-08-01 14:44:53 -07:00
using MatterHackers.MatterControl.PrinterCommunication ;
2014-06-05 11:45:40 -07:00
using MatterHackers.MatterControl.SlicerConfiguration ;
2015-04-08 15:20:10 -07:00
using MatterHackers.VectorMath ;
using System.Collections.Generic ;
2014-06-05 11:45:40 -07:00
2014-06-06 16:05:18 -07:00
namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
2014-06-05 11:45:40 -07:00
{
2015-04-08 15:20:10 -07:00
public class LevelWizard3Point : LevelWizardBase
{
private string pageOneStepText = "Print Leveling Overview" . Localize ( ) ;
private string pageOneInstructionsTextOne = LocalizedString . Get ( "Welcome to the print leveling wizard. Here is a quick overview on what we are going to do." ) ;
private string pageOneInstructionsTextTwo = LocalizedString . Get ( "'Home' the printer" ) ;
private string pageOneInstructionsTextThree = LocalizedString . Get ( "Sample the bed at three points" ) ;
private string pageOneInstructionsTextFour = LocalizedString . Get ( "Turn auto leveling on" ) ;
private string pageOneInstructionsText5 = LocalizedString . Get ( "You should be done in about 3 minutes." ) ;
private string pageOneInstructionsText6 = LocalizedString . Get ( "Note: Be sure the tip of the extrude is clean." ) ;
private string pageOneInstructionsText7 = LocalizedString . Get ( "Click 'Next' to continue." ) ;
public LevelWizard3Point ( LevelWizardBase . RuningState runningState )
: base ( 500 , 370 , 9 )
{
bool allowLessThanZero = ActiveSliceSettings . Instance . GetActiveValue ( "z_can_be_negative" ) = = "1" ;
string printLevelWizardTitle = LocalizedString . Get ( "MatterControl" ) ;
string printLevelWizardTitleFull = LocalizedString . Get ( "Print Leveling Wizard" ) ;
Title = string . Format ( "{0} - {1}" , printLevelWizardTitle , printLevelWizardTitleFull ) ;
ProbePosition [ ] probePositions = new ProbePosition [ 3 ] ;
probePositions [ 0 ] = new ProbePosition ( ) ;
probePositions [ 1 ] = new ProbePosition ( ) ;
probePositions [ 2 ] = new ProbePosition ( ) ;
printLevelWizard = new WizardControl ( ) ;
AddChild ( printLevelWizard ) ;
if ( runningState = = LevelWizardBase . RuningState . InitialStartupCalibration )
{
string requiredPageInstructions = "{0}\n\n{1}" . FormatWith ( requiredPageInstructions1 , requiredPageInstructions2 ) ;
printLevelWizard . AddPage ( new FirstPageInstructions ( initialPrinterSetupStepText , requiredPageInstructions ) ) ;
}
string pageOneInstructions = string . Format ( "{0}\n\n\t• {1}\n\t• {2}\n\t• {3}\n\n{4}\n\n{5}\n\n{6}" , pageOneInstructionsTextOne , pageOneInstructionsTextTwo , pageOneInstructionsTextThree , pageOneInstructionsTextFour , pageOneInstructionsText5 , pageOneInstructionsText6 , pageOneInstructionsText7 ) ;
printLevelWizard . AddPage ( new FirstPageInstructions ( pageOneStepText , pageOneInstructions ) ) ;
string homingPageInstructions = string . Format ( "{0}:\n\n\t• {1}\n\n{2}" , homingPageInstructionsTextOne , homingPageInstructionsTextTwo , homingPageInstructionsTextThree ) ;
printLevelWizard . AddPage ( new HomePrinterPage ( homingPageStepText , homingPageInstructions ) ) ;
2015-08-01 14:44:53 -07:00
string positionLabel = LocalizedString . Get ( "Position" ) ;
2015-04-08 15:20:10 -07:00
string lowPrecisionLabel = LocalizedString . Get ( "Low Precision" ) ;
string medPrecisionLabel = LocalizedString . Get ( "Medium Precision" ) ;
string highPrecisionLabel = LocalizedString . Get ( "High Precision" ) ;
2015-08-01 14:44:53 -07:00
Vector2 probeBackCenter = LevelWizardBase . GetPrintLevelPositionToSample ( 0 ) ;
printLevelWizard . AddPage ( new GetCoarseBedHeight ( printLevelWizard , new Vector3 ( probeBackCenter , 10 ) , string . Format ( "{0} {1} 1 - {2}" , GetStepString ( ) , positionLabel , lowPrecisionLabel ) , probePositions [ 0 ] , allowLessThanZero ) ) ;
printLevelWizard . AddPage ( new GetFineBedHeight ( string . Format ( "{0} {1} 1 - {2}" , GetStepString ( ) , positionLabel , medPrecisionLabel ) , probePositions [ 0 ] , allowLessThanZero ) ) ;
printLevelWizard . AddPage ( new GetUltraFineBedHeight ( string . Format ( "{0} {1} 1 - {2}" , GetStepString ( ) , positionLabel , highPrecisionLabel ) , probePositions [ 0 ] , allowLessThanZero ) ) ;
2015-04-08 15:20:10 -07:00
Vector2 probeFrontLeft = LevelWizardBase . GetPrintLevelPositionToSample ( 1 ) ;
2015-08-01 14:44:53 -07:00
printLevelWizard . AddPage ( new GetCoarseBedHeight ( printLevelWizard , new Vector3 ( probeFrontLeft , 10 ) , string . Format ( "{0} {1} 2 - {2}" , GetStepString ( ) , positionLabel , lowPrecisionLabel ) , probePositions [ 1 ] , allowLessThanZero ) ) ;
printLevelWizard . AddPage ( new GetFineBedHeight ( string . Format ( "{0} {1} 2 - {2}" , GetStepString ( ) , positionLabel , medPrecisionLabel ) , probePositions [ 1 ] , allowLessThanZero ) ) ;
printLevelWizard . AddPage ( new GetUltraFineBedHeight ( string . Format ( "{0} {1} 2 - {2}" , GetStepString ( ) , positionLabel , highPrecisionLabel ) , probePositions [ 1 ] , allowLessThanZero ) ) ;
2015-04-08 15:20:10 -07:00
Vector2 probeFrontRight = LevelWizardBase . GetPrintLevelPositionToSample ( 2 ) ;
2015-08-01 14:44:53 -07:00
printLevelWizard . AddPage ( new GetCoarseBedHeight ( printLevelWizard , new Vector3 ( probeFrontRight , 10 ) , string . Format ( "{0} {1} 3 - {2}" , GetStepString ( ) , positionLabel , lowPrecisionLabel ) , probePositions [ 2 ] , allowLessThanZero ) ) ;
printLevelWizard . AddPage ( new GetFineBedHeight ( string . Format ( "{0} {1} 3 - {2}" , GetStepString ( ) , positionLabel , medPrecisionLabel ) , probePositions [ 2 ] , allowLessThanZero ) ) ;
printLevelWizard . AddPage ( new GetUltraFineBedHeight ( string . Format ( "{0} {1} 3 - {2}" , GetStepString ( ) , positionLabel , highPrecisionLabel ) , probePositions [ 2 ] , allowLessThanZero ) ) ;
2015-04-08 15:20:10 -07:00
string doneInstructions = string . Format ( "{0}\n\n\t• {1}\n\n{2}" , doneInstructionsText , doneInstructionsTextTwo , doneInstructionsTextThree ) ;
printLevelWizard . AddPage ( new LastPage3PointInstructions ( "Done" . Localize ( ) , doneInstructions , probePositions ) ) ;
}
2015-08-01 14:44:53 -07:00
public static string ApplyLeveling ( string lineBeingSent , Vector3 currentDestination , PrinterMachineInstruction . MovementTypes movementMode )
{
if ( PrinterConnectionAndCommunication . Instance . ActivePrinter ! = null
& & PrinterConnectionAndCommunication . Instance . ActivePrinter . DoPrintLeveling
& & ( lineBeingSent . StartsWith ( "G0 " ) | | lineBeingSent . StartsWith ( "G1 " ) ) )
{
lineBeingSent = PrintLevelingPlane . Instance . ApplyLeveling ( currentDestination , movementMode , lineBeingSent ) ;
}
return lineBeingSent ;
}
2015-04-08 15:20:10 -07:00
public static List < string > ProcessCommand ( string lineBeingSent )
{
int commentIndex = lineBeingSent . IndexOf ( ';' ) ;
if ( commentIndex > 0 ) // there is content in front of the ;
{
lineBeingSent = lineBeingSent . Substring ( 0 , commentIndex ) . Trim ( ) ;
}
List < string > lines = new List < string > ( ) ;
lines . Add ( lineBeingSent ) ;
2015-11-23 15:45:35 -08:00
if ( lineBeingSent . StartsWith ( "G28" )
| | lineBeingSent . StartsWith ( "G29" ) )
2015-04-08 15:20:10 -07:00
{
lines . Add ( "M114" ) ;
}
return lines ;
}
}
}