2017-08-23 23:59:45 -07:00
/ *
2019-05-06 12:53:06 -07:00
Copyright ( c ) 2019 , Lars Brubaker , John Lewin
2017-08-23 23:59:45 -07:00
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 .
* /
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
using MatterHackers.Agg ;
using MatterHackers.Agg.UI ;
using MatterHackers.Localizations ;
2019-05-14 15:18:08 -07:00
using MatterHackers.MatterControl.CustomWidgets ;
2022-03-15 17:51:28 -07:00
using MatterHackers.MatterControl.Library.Widgets ;
2016-04-18 11:31:31 -07:00
using MatterHackers.MatterControl.SlicerConfiguration ;
2014-01-29 19:09:30 -08:00
namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
2015-04-08 15:20:10 -07:00
{
2019-05-06 12:53:06 -07:00
// Normally step one of the setup process
2017-11-08 15:56:37 -08:00
public class SetupStepMakeModelName : DialogPage
2015-04-08 15:20:10 -07:00
{
2020-12-15 18:01:49 -08:00
private readonly TextButton nextButton ;
private readonly AddPrinterWidget printerPanel ;
2015-04-08 15:20:10 -07:00
2020-12-15 18:01:49 -08:00
private readonly RadioButton createPrinterRadioButton = null ;
private readonly RadioButton signInRadioButton ;
2018-10-13 17:40:59 -07:00
2022-01-06 16:55:55 -08:00
public SetupStepMakeModelName ( bool filterToPulse )
2015-04-08 15:20:10 -07:00
{
2018-10-13 17:40:59 -07:00
bool userIsLoggedIn = ! ApplicationController . GuestUserActive ? . Invoke ( ) ? ? false ;
this . HeaderText = this . WindowTitle = "Printer Setup" . Localize ( ) ;
2020-08-13 11:17:48 -07:00
this . WindowSize = new VectorMath . Vector2 ( 800 * GuiWidget . DeviceScale , 600 * GuiWidget . DeviceScale ) ;
2018-10-13 17:40:59 -07:00
2019-05-14 15:18:08 -07:00
contentRow . BackgroundColor = theme . SectionBackgroundColor ;
nextButton = theme . CreateDialogButton ( "Next" . Localize ( ) ) ;
2016-06-01 14:00:47 -07:00
2022-01-20 14:52:03 -08:00
printerPanel = new AddPrinterWidget ( nextButton , theme , ( enabled ) = >
2020-12-15 18:01:49 -08:00
{
nextButton . Enabled = enabled ;
2022-01-06 16:55:55 -08:00
} , filterToPulse )
2015-04-08 15:20:10 -07:00
{
2017-08-07 15:47:27 -07:00
HAnchor = HAnchor . Stretch ,
2019-05-14 15:18:08 -07:00
VAnchor = VAnchor . Stretch
2016-06-01 14:00:47 -07:00
} ;
2018-10-13 17:40:59 -07:00
if ( userIsLoggedIn )
{
2019-05-14 15:18:08 -07:00
contentRow . AddChild ( printerPanel ) ;
2019-06-11 17:43:17 -07:00
contentRow . Padding = 0 ;
2018-10-13 17:40:59 -07:00
}
else
2018-10-07 11:36:52 -07:00
{
2019-05-14 15:18:08 -07:00
contentRow . Padding = theme . DefaultContainerPadding ;
printerPanel . Margin = new BorderDouble ( left : 15 , top : theme . DefaultContainerPadding ) ;
2018-10-13 17:40:59 -07:00
var commonMargin = new BorderDouble ( 4 , 2 ) ;
// Create export button for each plugin
2018-11-03 09:13:07 -07:00
signInRadioButton = new RadioButton ( new RadioButtonViewText ( "Sign in to access your existing printers" . Localize ( ) , theme . TextColor ) )
2018-10-07 11:36:52 -07:00
{
2018-10-13 17:40:59 -07:00
HAnchor = HAnchor . Left ,
Margin = commonMargin . Clone ( bottom : 10 ) ,
Cursor = Cursors . Hand ,
Name = "Sign In Radio Button" ,
2018-10-07 11:36:52 -07:00
} ;
2018-11-03 10:12:27 -07:00
contentRow . AddChild ( signInRadioButton ) ;
2018-10-07 11:36:52 -07:00
2018-11-03 09:13:07 -07:00
createPrinterRadioButton = new RadioButton ( new RadioButtonViewText ( "Create a new printer" , theme . TextColor ) )
2018-10-13 17:40:59 -07:00
{
HAnchor = HAnchor . Left ,
Margin = commonMargin ,
Cursor = Cursors . Hand ,
Name = "Create Printer Radio Button" ,
Checked = true
} ;
2018-11-03 10:12:27 -07:00
contentRow . AddChild ( createPrinterRadioButton ) ;
2018-10-07 11:36:52 -07:00
2018-10-13 17:40:59 -07:00
createPrinterRadioButton . CheckedStateChanged + = ( s , e ) = >
{
2019-05-14 15:18:08 -07:00
printerPanel . Enabled = createPrinterRadioButton . Checked ;
2018-10-13 17:40:59 -07:00
this . SetElementVisibility ( ) ;
} ;
2019-05-14 15:18:08 -07:00
contentRow . AddChild ( printerPanel ) ;
2018-10-13 17:40:59 -07:00
}
nextButton . Name = "Next Button" ;
nextButton . Click + = ( s , e ) = > UiThread . RunOnIdle ( async ( ) = >
{
if ( signInRadioButton ? . Checked = = true )
2018-10-07 11:36:52 -07:00
{
2018-10-16 16:00:06 -07:00
var authContext = new AuthenticationContext ( ) ;
authContext . SignInComplete + = ( s2 , e2 ) = >
{
2018-11-12 08:30:03 -08:00
this . DialogWindow . ChangeToPage ( new OpenPrinterPage ( "Finish" . Localize ( ) ) ) ;
2018-10-16 16:00:06 -07:00
} ;
this . DialogWindow . ChangeToPage ( ApplicationController . GetAuthPage ( authContext ) ) ;
2018-10-13 17:40:59 -07:00
}
else
2016-04-18 11:31:31 -07:00
{
2019-05-14 15:18:08 -07:00
bool controlsValid = printerPanel . ValidateControls ( ) ;
if ( controlsValid
& & printerPanel . SelectedPrinter is AddPrinterWidget . MakeModelInfo selectedPrinter )
2016-10-04 14:40:59 -07:00
{
2019-05-14 15:18:08 -07:00
var printer = await ProfileManager . CreatePrinterAsync ( selectedPrinter . Make , selectedPrinter . Model , printerPanel . NewPrinterName ) ;
2018-10-13 17:40:59 -07:00
if ( printer = = null )
{
2019-05-14 15:18:08 -07:00
printerPanel . SetError ( "Error creating profile" . Localize ( ) ) ;
2018-10-13 17:40:59 -07:00
return ;
}
2016-10-04 14:40:59 -07:00
2018-10-13 17:40:59 -07:00
UiThread . RunOnIdle ( ( ) = >
{
2018-12-15 08:53:46 -08:00
DialogWindow . ChangeToPage ( AppContext . Platform . GetConnectDevicePage ( printer ) as DialogPage ) ;
2018-10-13 17:40:59 -07:00
} ) ;
}
2016-04-18 11:31:31 -07:00
}
2018-10-13 17:40:59 -07:00
} ) ;
2014-01-29 19:09:30 -08:00
2021-01-05 20:47:01 -08:00
var printerNotListedButton = theme . CreateDialogButton ( "Define New" . Localize ( ) ) ;
2020-12-15 18:01:49 -08:00
printerNotListedButton . ToolTipText = "Select this option only if your printer does not appear in the list" . Localize ( ) ;
printerNotListedButton . Click + = async ( s , e ) = >
{
var printer = await ProfileManager . CreatePrinterAsync ( "Other" , "Other" , "Custom Printer" ) ;
if ( printer = = null )
{
printerPanel . SetError ( "Error creating profile" . Localize ( ) ) ;
return ;
}
UiThread . RunOnIdle ( ( ) = >
{
DialogWindow . ChangeToPage ( new SetupCustomPrinter ( printer ) as DialogPage ) ;
} ) ;
} ;
2020-12-31 09:33:43 -08:00
this . AddPageAction ( printerNotListedButton , false ) ;
2017-08-23 17:27:30 -07:00
this . AddPageAction ( nextButton ) ;
2014-01-29 19:09:30 -08:00
2016-04-18 11:31:31 -07:00
SetElementVisibility ( ) ;
2015-04-08 15:20:10 -07:00
}
2014-01-29 19:09:30 -08:00
2016-04-18 11:31:31 -07:00
private void SetElementVisibility ( )
2015-04-08 15:20:10 -07:00
{
2019-05-14 15:18:08 -07:00
nextButton . Enabled = signInRadioButton ? . Checked = = true
| | printerPanel . SelectedPrinter ! = null ;
2015-04-08 15:20:10 -07:00
}
2020-12-15 18:01:49 -08:00
}
2015-04-08 15:20:10 -07:00
2020-12-15 18:01:49 -08:00
public class SetupCustomPrinter : DialogPage
{
public SetupCustomPrinter ( PrinterConfig printer )
2020-12-16 11:20:13 -08:00
: base ( "Done" . Localize ( ) )
2015-04-08 15:20:10 -07:00
{
2020-12-16 11:20:13 -08:00
var scrollable = new ScrollableWidget ( autoScroll : true )
{
HAnchor = HAnchor . Stretch ,
VAnchor = VAnchor . Stretch ,
} ;
scrollable . ScrollArea . HAnchor = HAnchor . Stretch ;
contentRow . AddChild ( scrollable ) ;
2020-12-15 18:01:49 -08:00
var settingsContainer = new FlowLayoutWidget ( FlowDirection . TopToBottom )
2016-04-18 11:31:31 -07:00
{
2020-12-15 18:01:49 -08:00
HAnchor = HAnchor . Stretch
2016-04-18 11:31:31 -07:00
} ;
2020-12-16 11:20:13 -08:00
scrollable . AddChild ( settingsContainer ) ;
2014-01-29 19:09:30 -08:00
2020-12-15 18:01:49 -08:00
var settingsContext = new SettingsContext ( printer , null , NamedSettingsLayers . All ) ;
var menuTheme = ApplicationController . Instance . MenuTheme ;
var tabIndex = 0 ;
2014-01-29 19:09:30 -08:00
2020-12-16 11:20:13 -08:00
void AddSettingsRow ( string key )
2016-04-18 11:31:31 -07:00
{
2020-12-15 18:01:49 -08:00
var settingsRow = SliceSettingsTabView . CreateItemRow (
PrinterSettings . SettingsData [ key ] ,
settingsContext ,
printer ,
menuTheme ,
ref tabIndex ) ;
settingsContainer . AddChild ( settingsRow ) ;
}
2016-04-18 11:31:31 -07:00
2020-12-16 11:20:13 -08:00
void AddSettingsRows ( string [ ] keys )
{
foreach ( var key in keys )
{
AddSettingsRow ( key ) ;
}
}
settingsContainer . AddChild (
new WrappedTextWidget (
2020-12-16 14:24:47 -08:00
"Set the information below to configure your printer. After completing this step, you can customize additional settings under the 'Settings' and 'Printer' options for this printer." . Localize ( ) ,
2020-12-16 11:20:13 -08:00
pointSize : theme . DefaultFontSize ,
textColor : theme . TextColor )
{
Margin = new BorderDouble ( 5 , 5 , 5 , 15 )
} ) ;
// turn off the port wizard button in this context
AddSettingsRow ( SettingsKey . printer_name ) ;
settingsContainer . AddChild ( new WrappedTextWidget ( "Bed Settings" . Localize ( ) + ":" , pointSize : theme . DefaultFontSize , textColor : theme . TextColor )
{
Margin = new BorderDouble ( 5 , 5 , 5 , 15 )
} ) ;
AddSettingsRows ( new [ ] { SettingsKey . bed_shape , SettingsKey . bed_size , SettingsKey . print_center , SettingsKey . build_height , SettingsKey . has_heated_bed } ) ;
settingsContainer . AddChild ( new WrappedTextWidget ( "Filament Settings" . Localize ( ) + ":" , pointSize : theme . DefaultFontSize , textColor : theme . TextColor )
{
Margin = new BorderDouble ( 5 , 5 , 5 , 15 )
} ) ;
AddSettingsRows ( new [ ] { SettingsKey . nozzle_diameter , SettingsKey . filament_diameter } ) ;
2015-04-08 15:20:10 -07:00
}
}
}