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 System ;
2015-04-08 15:20:10 -07:00
using System.Collections.Generic ;
2015-04-17 20:14:20 -07:00
using System.Linq ;
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 ;
2017-08-20 02:34:39 -07:00
using MatterHackers.Agg.Platform ;
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.UI ;
using MatterHackers.Localizations ;
2016-04-25 13:35:36 -07:00
using MatterHackers.MatterControl.CustomWidgets ;
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.MatterControl.SettingsManagement ;
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
{
//Normally step one of the setup process
2016-06-08 09:31:26 -07:00
public class SetupStepMakeModelName : ConnectionWizardPage
2015-04-08 15:20:10 -07:00
{
private FlowLayoutWidget printerModelContainer ;
private FlowLayoutWidget printerMakeContainer ;
private MHTextEditWidget printerNameInput ;
private TextWidget printerNameError ;
private Button nextButton ;
private bool usingDefaultName ;
2016-06-01 14:00:47 -07:00
private static BorderDouble elementMargin = new BorderDouble ( top : 3 ) ;
private BoundDropList printerManufacturerSelector ;
private BoundDropList printerModelSelector ;
2016-06-14 11:28:13 -07:00
string activeMake ;
string activeModel ;
string activeName ;
2016-06-07 15:45:50 -07:00
public SetupStepMakeModelName ( )
2015-04-08 15:20:10 -07:00
{
2016-06-01 14:00:47 -07:00
printerManufacturerSelector = new BoundDropList ( string . Format ( "- {0} -" , "Select Make" . Localize ( ) ) , maxHeight : 200 )
2015-04-08 15:20:10 -07:00
{
2017-08-07 15:47:27 -07:00
HAnchor = HAnchor . Stretch ,
2016-06-01 14:00:47 -07:00
Margin = elementMargin ,
Name = "Select Make" ,
2016-09-29 14:27:42 -07:00
ListSource = OemSettings . Instance . AllOems ,
TabStop = true
2016-06-01 14:00:47 -07:00
} ;
2015-04-08 15:20:10 -07:00
2016-06-01 14:00:47 -07:00
printerManufacturerSelector . SelectionChanged + = ManufacturerDropList_SelectionChanged ;
printerMakeContainer = CreateSelectionContainer (
"Make" . Localize ( ) + ":" ,
"Select the printer manufacturer" . Localize ( ) ,
printerManufacturerSelector ) ;
printerModelSelector = new BoundDropList ( string . Format ( "- {0} -" , "Select Model" . Localize ( ) ) , maxHeight : 200 )
2015-04-08 15:20:10 -07:00
{
2016-06-01 14:00:47 -07:00
Name = "Select Model" ,
2017-08-07 15:47:27 -07:00
HAnchor = HAnchor . Stretch ,
2016-06-01 14:00:47 -07:00
Margin = elementMargin ,
2016-09-29 14:27:42 -07:00
TabStop = true
2016-06-01 14:00:47 -07:00
} ;
printerModelSelector . SelectionChanged + = ModelDropList_SelectionChanged ;
2016-09-22 16:34:06 -07:00
printerModelContainer = CreateSelectionContainer ( "Model" . Localize ( ) + ":" , "Select the printer model" . Localize ( ) , printerModelSelector ) ;
2016-06-01 14:00:47 -07:00
2015-04-08 15:20:10 -07:00
//Add inputs to main container
contentRow . AddChild ( printerMakeContainer ) ;
contentRow . AddChild ( printerModelContainer ) ;
2016-06-06 12:43:05 -07:00
contentRow . AddChild ( createPrinterNameContainer ( ) ) ;
2015-04-08 15:20:10 -07:00
//Construct buttons
2016-06-01 14:00:47 -07:00
nextButton = textImageButtonFactory . Generate ( "Save & Continue" . Localize ( ) ) ;
2015-12-31 12:57:00 -08:00
nextButton . Name = "Save & Continue Button" ;
2016-09-01 10:53:10 -07:00
nextButton . Click + = async ( s , e ) = >
2016-04-18 11:31:31 -07:00
{
2016-10-04 14:40:59 -07:00
bool controlsValid = this . ValidateControls ( ) ;
if ( controlsValid )
2016-04-18 11:31:31 -07:00
{
2016-10-04 14:40:59 -07:00
bool profileCreated = await ProfileManager . CreateProfileAsync ( activeMake , activeModel , activeName ) ;
if ( ! profileCreated )
{
this . printerNameError . Text = "Error creating profile" . Localize ( ) ;
this . printerNameError . Visible = true ;
return ;
}
LoadCalibrationPrints ( ) ;
2016-06-07 14:27:37 -07:00
#if __ANDROID__
2016-12-09 12:09:28 -08:00
UiThread . RunOnIdle ( WizardWindow . ChangeToPage < AndroidConnectDevicePage > ) ;
2016-06-07 14:27:37 -07:00
#else
2017-08-20 02:34:39 -07:00
if ( AggContext . OperatingSystem = = OSType . Windows )
2016-07-28 12:04:43 -07:00
{
2017-08-23 15:51:29 -07:00
UiThread . RunOnIdle ( ( ) = >
{
WizardWindow . ChangeToPage < SetupStepInstallDriver > ( ) ;
} ) ;
2016-07-28 12:04:43 -07:00
}
else
{
2017-08-23 15:51:29 -07:00
UiThread . RunOnIdle ( ( ) = >
{
WizardWindow . ChangeToPage < SetupStepComPortOne > ( ) ;
} ) ;
2016-07-28 12:04:43 -07:00
}
2016-06-07 14:27:37 -07:00
#endif
2016-04-18 11:31:31 -07:00
}
} ;
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
//Add buttons to buttonContainer
footerRow . AddChild ( nextButton ) ;
2016-04-25 13:35:36 -07:00
footerRow . AddChild ( new HorizontalSpacer ( ) ) ;
2016-11-30 13:31:19 -08:00
footerRow . AddChild ( cancelButton ) ;
2014-01-29 19:09:30 -08:00
2014-10-31 09:36:30 -07:00
usingDefaultName = true ;
2016-11-28 15:56:17 -08:00
if ( printerManufacturerSelector . MenuItems . Count = = 1 )
{
printerManufacturerSelector . SelectedIndex = 0 ;
}
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
{
2016-06-14 11:28:13 -07:00
nextButton . Visible = ( activeModel ! = null & & this . activeMake ! = null ) ;
2015-04-08 15:20:10 -07:00
}
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
private FlowLayoutWidget createPrinterNameContainer ( )
{
2016-04-18 11:31:31 -07:00
TextWidget printerNameLabel = new TextWidget ( "Name" . Localize ( ) + ":" , 0 , 0 , 12 )
{
TextColor = ActiveTheme . Instance . PrimaryTextColor ,
2017-08-07 15:47:27 -07:00
HAnchor = HAnchor . Stretch ,
2016-09-22 16:34:06 -07:00
Margin = new BorderDouble ( 0 , 4 , 0 , 1 )
2016-04-18 11:31:31 -07:00
} ;
2014-01-29 19:09:30 -08:00
2016-06-07 17:39:17 -07:00
printerNameInput = new MHTextEditWidget ( "" )
2016-04-18 11:31:31 -07:00
{
2017-08-07 15:47:27 -07:00
HAnchor = HAnchor . Stretch ,
2016-04-18 11:31:31 -07:00
} ;
printerNameInput . KeyPressed + = ( s , e ) = > this . usingDefaultName = false ;
2014-01-29 19:09:30 -08:00
2016-05-03 18:22:59 -07:00
printerNameError = new TextWidget ( "" , 0 , 0 , 10 )
2016-04-18 11:31:31 -07:00
{
TextColor = ActiveTheme . Instance . PrimaryTextColor ,
2017-08-07 15:47:27 -07:00
HAnchor = HAnchor . Stretch ,
2016-04-18 11:31:31 -07:00
Margin = new BorderDouble ( top : 3 )
} ;
2015-04-08 15:20:10 -07:00
2016-04-18 11:31:31 -07:00
FlowLayoutWidget container = new FlowLayoutWidget ( FlowDirection . TopToBottom ) ;
container . Margin = new BorderDouble ( 0 , 5 ) ;
2015-04-08 15:20:10 -07:00
container . AddChild ( printerNameLabel ) ;
container . AddChild ( printerNameInput ) ;
container . AddChild ( printerNameError ) ;
2017-08-07 15:47:27 -07:00
container . HAnchor = HAnchor . Stretch ;
2016-04-18 11:31:31 -07:00
2015-04-08 15:20:10 -07:00
return container ;
}
2016-06-03 18:11:51 -07:00
private FlowLayoutWidget CreateSelectionContainer ( string labelText , string validationMessage , Agg . UI . DropDownList selector )
2015-04-08 15:20:10 -07:00
{
2016-06-01 14:00:47 -07:00
var sectionLabel = new TextWidget ( labelText , 0 , 0 , 12 )
2016-04-18 11:31:31 -07:00
{
TextColor = ActiveTheme . Instance . PrimaryTextColor ,
2017-08-07 15:47:27 -07:00
HAnchor = HAnchor . Stretch ,
2016-04-18 11:31:31 -07:00
Margin = elementMargin
} ;
2014-01-29 19:09:30 -08:00
2016-06-01 14:00:47 -07:00
var validationTextWidget = new TextWidget ( validationMessage , 0 , 0 , 10 )
2016-04-18 11:31:31 -07:00
{
2016-05-03 18:22:59 -07:00
TextColor = ActiveTheme . Instance . SecondaryAccentColor ,
2017-08-07 15:47:27 -07:00
HAnchor = HAnchor . Stretch ,
2016-04-18 11:31:31 -07:00
Margin = elementMargin
} ;
2014-01-29 19:09:30 -08:00
2016-06-01 14:00:47 -07:00
selector . SelectionChanged + = ( s , e ) = >
2016-04-18 11:31:31 -07:00
{
2016-06-01 14:00:47 -07:00
validationTextWidget . Visible = selector . SelectedLabel . StartsWith ( "-" ) ; // The default values have "- Title -"
2016-04-18 11:31:31 -07:00
} ;
2014-01-29 19:09:30 -08:00
2016-06-01 14:00:47 -07:00
var container = new FlowLayoutWidget ( FlowDirection . TopToBottom )
2016-04-18 11:31:31 -07:00
{
2016-06-01 14:00:47 -07:00
Margin = new BorderDouble ( 0 , 5 ) ,
2017-08-07 15:47:27 -07:00
HAnchor = HAnchor . Stretch
2016-04-18 11:31:31 -07:00
} ;
2015-04-08 15:20:10 -07:00
2016-06-01 14:00:47 -07:00
container . AddChild ( sectionLabel ) ;
container . AddChild ( selector ) ;
container . AddChild ( validationTextWidget ) ;
2016-04-18 11:31:31 -07:00
2015-04-08 15:20:10 -07:00
return container ;
}
private void ManufacturerDropList_SelectionChanged ( object sender , EventArgs e )
{
2016-07-29 13:47:58 -07:00
activeMake = ( ( DropDownList ) sender ) . SelectedValue ;
2016-06-14 11:28:13 -07:00
activeModel = null ;
2015-04-08 15:20:10 -07:00
2016-07-29 13:47:58 -07:00
// Select the dictionary containing the printerName->printerToken mappings for the current OEM
2016-09-01 17:24:09 -07:00
Dictionary < string , PublicDevice > printers ;
2016-06-14 11:28:13 -07:00
if ( ! OemSettings . Instance . OemProfiles . TryGetValue ( activeMake , out printers ) )
2016-06-02 14:19:24 -07:00
{
2016-07-29 13:47:58 -07:00
// Fall back to an empty dictionary if no match
2016-09-01 17:24:09 -07:00
printers = new Dictionary < string , PublicDevice > ( ) ;
2016-06-02 14:19:24 -07:00
}
2016-06-01 14:00:47 -07:00
2016-07-29 13:47:58 -07:00
// Models - sort dictionary results by key and assign to .ListSource
2016-09-01 17:24:09 -07:00
printerModelSelector . ListSource = printers . OrderBy ( p = > p . Key ) . Select ( p = > new KeyValuePair < string , string > ( p . Key , p . Value . ProfileToken ) ) . ToList ( ) ;
2016-07-15 17:15:25 -07:00
if ( printerModelSelector . MenuItems . Count = = 1 )
{
printerModelSelector . SelectedIndex = 0 ;
}
2015-11-02 17:54:26 -08:00
2015-04-08 15:20:10 -07:00
contentRow . Invalidate ( ) ;
2016-06-01 14:00:47 -07:00
SetElementVisibility ( ) ;
2015-04-08 15:20:10 -07:00
}
private void ModelDropList_SelectionChanged ( object sender , EventArgs e )
{
2015-06-11 12:06:40 -07:00
UiThread . RunOnIdle ( ( ) = >
2015-04-08 15:20:10 -07:00
{
2016-06-03 18:11:51 -07:00
DropDownList dropList = ( DropDownList ) sender ;
2016-06-14 11:28:13 -07:00
activeModel = dropList . SelectedLabel ;
2016-04-18 11:31:31 -07:00
SetElementVisibility ( ) ;
2015-04-08 15:20:10 -07:00
if ( usingDefaultName )
{
2016-06-14 11:28:13 -07:00
// Use ManufacturerDropList.SelectedLabel instead of activeMake to ensure the mapped Unicode values are picked up
2016-06-01 14:00:47 -07:00
string mappedMakeText = printerManufacturerSelector . SelectedLabel ;
2016-02-04 12:13:56 -08:00
2016-10-04 18:35:24 -07:00
var existingPrinterNames = ProfileManager . Instance . ActiveProfiles . Select ( p = > p . Name ) ;
printerNameInput . Text = agg_basics . GetNonCollidingName ( existingPrinterNames , $"{mappedMakeText} {activeModel}" ) ;
2015-04-08 15:20:10 -07:00
}
} ) ;
}
2014-01-29 19:09:30 -08:00
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
// TODO: Do we still want to do this - constantly adding items to the queue as printers are added? What about a LibraryContainer for '[PrinterName] Calibration Files' - much cleaner to implement, never an extra files on disk or one-time processing that remain becomes inconsistent over time
2016-09-01 10:53:10 -07:00
public void LoadCalibrationPrints ( )
{
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
/ *
2016-09-01 10:53:10 -07:00
// Load the calibration file names
string calibrationFiles = ActiveSliceSettings . Instance . GetValue ( "calibration_files" ) ;
if ( string . IsNullOrEmpty ( calibrationFiles ) )
{
return ;
}
string [ ] calibrationPrintFileNames = calibrationFiles . Split ( ';' ) ;
if ( calibrationPrintFileNames . Length < 1 )
{
return ;
}
var queueItems = QueueData . Instance . GetItemNames ( ) ;
// Finally, ensure missing calibration parts are added to the queue if missing
var filenamesWithoutExtensions = calibrationPrintFileNames . Select ( f = > Path . GetFileNameWithoutExtension ( f ) ) ;
foreach ( string nameOnly in filenamesWithoutExtensions )
{
if ( queueItems . Contains ( nameOnly ) )
{
continue ;
}
// Find the first library item with the given name and add it to the queue
PrintItem libraryItem = libraryProvider . GetLibraryItems ( nameOnly ) . FirstOrDefault ( ) ;
if ( libraryItem ! = null )
{
QueueData . Instance . AddItem ( new PrintItemWrapper ( libraryItem ) ) ;
}
}
libraryProvider . Dispose ( ) ;
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
* /
2016-09-01 10:53:10 -07:00
}
2016-10-04 14:40:59 -07:00
private bool ValidateControls ( )
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
if ( ! string . IsNullOrEmpty ( printerNameInput . Text ) )
2015-04-08 15:20:10 -07:00
{
2016-06-14 11:28:13 -07:00
activeName = printerNameInput . Text ;
2016-04-18 11:31:31 -07:00
2016-06-14 11:28:13 -07:00
if ( this . activeMake = = null | | activeModel = = null )
2015-04-08 15:20:10 -07:00
{
return false ;
}
else
{
return true ;
}
}
else
{
this . printerNameError . TextColor = RGBA_Bytes . Red ;
2016-10-04 14:40:59 -07:00
this . printerNameError . Text = "Printer name cannot be blank" . Localize ( ) ;
2015-04-08 15:20:10 -07:00
this . printerNameError . Visible = true ;
2016-04-18 11:31:31 -07:00
2015-04-08 15:20:10 -07:00
return false ;
}
}
}
}