2014-02-15 18:06:03 -08: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 ;
2014-01-29 19:09:30 -08:00
using System.Collections.Generic ;
using MatterHackers.Agg ;
using MatterHackers.Agg.Font ;
2014-02-05 17:47:13 -08:00
using MatterHackers.Agg.UI ;
2014-04-09 18:45:29 -07:00
using MatterHackers.Agg.VertexSource ;
2014-01-29 19:09:30 -08:00
using MatterHackers.Localizations ;
2014-06-11 14:52:58 -07:00
using MatterHackers.MatterControl.PrinterCommunication ;
2014-02-05 17:47:13 -08:00
using MatterHackers.VectorMath ;
2014-01-29 19:09:30 -08:00
2014-02-15 18:06:03 -08:00
namespace MatterHackers.MatterControl.SlicerConfiguration
2014-01-29 19:09:30 -08:00
{
public class SliceSettingsWidget : GuiWidget
{
2014-07-26 13:43:55 -07:00
static List < string > settingToReloadUiWhenChanged = new List < string > ( )
2014-01-29 19:09:30 -08:00
{
2014-07-26 13:43:55 -07:00
"has_fan" ,
"has_heated_bed" ,
2014-09-25 11:01:15 -07:00
"has_sd_card_reader" ,
"extruder_count" ,
2014-10-14 14:39:46 -07:00
"extruders_share_temperature" ,
2014-07-26 13:43:55 -07:00
} ;
2014-01-29 19:09:30 -08:00
2014-07-26 13:43:55 -07:00
const string SliceSettingsShowHelpEntry = "SliceSettingsShowHelp" ;
const string SliceSettingsLevelEntry = "SliceSettingsLevel" ;
TextImageButtonFactory buttonFactory = new TextImageButtonFactory ( ) ;
2014-01-29 19:09:30 -08:00
TabControl categoryTabs ;
2014-09-18 17:06:45 -07:00
AltGroupBox noConnectionMessageContainer ;
2014-01-29 19:09:30 -08:00
FlowLayoutWidget settingsControlBar ;
CheckBox showHelpBox ;
CheckBox showAllDetails ;
2014-07-26 13:43:55 -07:00
public SliceSettingsWidget ( SliceSettingsWidgetUiState uiState )
2014-01-29 19:09:30 -08:00
{
int minSettingNameWidth = 220 ;
2014-04-09 18:45:29 -07:00
buttonFactory . FixedHeight = 20 ;
buttonFactory . fontSize = 10 ;
buttonFactory . normalFillColor = RGBA_Bytes . White ;
2014-04-10 16:42:06 -07:00
buttonFactory . normalTextColor = RGBA_Bytes . DarkGray ;
2014-01-29 19:09:30 -08:00
2014-03-27 19:23:00 -07:00
showHelpBox = new CheckBox ( 0 , 0 , LocalizedString . Get ( "Show Help" ) , textSize : 10 ) ;
2014-04-03 18:27:37 -07:00
showHelpBox . Checked = UserSettings . Instance . get ( SliceSettingsShowHelpEntry ) = = "true" ;
2014-01-29 19:09:30 -08:00
2014-04-21 15:00:32 -07:00
showAllDetails = new CheckBox ( 0 , 0 , LocalizedString . Get ( "Show All Settings" ) , textSize : 10 ) ;
showAllDetails . Checked = UserSettings . Instance . get ( SliceSettingsLevelEntry ) = = "Advanced" ;
2014-01-29 19:09:30 -08:00
FlowLayoutWidget pageTopToBottomLayout = new FlowLayoutWidget ( FlowDirection . TopToBottom , vAnchor : Agg . UI . VAnchor . ParentTop ) ;
pageTopToBottomLayout . AnchorAll ( ) ;
pageTopToBottomLayout . Padding = new BorderDouble ( 3 , 0 ) ;
this . AddChild ( pageTopToBottomLayout ) ;
settingsControlBar = new SettingsControlBar ( ) ;
pageTopToBottomLayout . AddChild ( settingsControlBar ) ;
2014-10-05 16:07:06 -07:00
noConnectionMessageContainer = new AltGroupBox ( new TextWidget ( LocalizedString . Get ( "No Printer Selected" ) , pointSize : 18 , textColor : ActiveTheme . Instance . SecondaryAccentColor ) ) ;
2014-01-29 19:09:30 -08:00
noConnectionMessageContainer . Margin = new BorderDouble ( top : 10 ) ;
noConnectionMessageContainer . BorderColor = ActiveTheme . Instance . PrimaryTextColor ;
2014-04-09 18:45:29 -07:00
noConnectionMessageContainer . HAnchor = Agg . UI . HAnchor . ParentLeftRight ;
2014-01-29 19:09:30 -08:00
noConnectionMessageContainer . Height = 80 ;
2014-09-18 17:06:45 -07:00
TextWidget noConnectionMessage = new TextWidget ( LocalizedString . Get ( "No printer is currently selected. Select a printer to edit slice settings." ) , pointSize : 10 ) ;
2014-01-29 19:09:30 -08:00
noConnectionMessage . Margin = new BorderDouble ( 5 ) ;
noConnectionMessage . TextColor = ActiveTheme . Instance . PrimaryTextColor ;
noConnectionMessage . VAnchor = VAnchor . ParentCenter ;
noConnectionMessageContainer . AddChild ( noConnectionMessage ) ;
pageTopToBottomLayout . AddChild ( noConnectionMessageContainer ) ;
categoryTabs = new TabControl ( ) ;
2014-03-22 10:04:31 -07:00
categoryTabs . TabBar . BorderColor = ActiveTheme . Instance . PrimaryTextColor ;
2014-01-29 19:09:30 -08:00
categoryTabs . Margin = new BorderDouble ( top : 8 ) ;
categoryTabs . AnchorAll ( ) ;
List < TabBar > sideTabBarsListForLayout = new List < TabBar > ( ) ;
for ( int categoryIndex = 0 ; categoryIndex < SliceSettingsOrganizer . Instance . UserLevels [ UserLevel ] . CategoriesList . Count ; categoryIndex + + )
{
OrganizerCategory category = SliceSettingsOrganizer . Instance . UserLevels [ UserLevel ] . CategoriesList [ categoryIndex ] ;
2014-04-21 15:00:32 -07:00
string categoryPageLabel = LocalizedString . Get ( category . Name ) ;
TabPage categoryPage = new TabPage ( categoryPageLabel ) ;
2014-06-10 11:44:16 -07:00
SimpleTextTabWidget textTabWidget = new SimpleTextTabWidget ( categoryPage , category . Name + " Tab" , 16 ,
2014-01-29 19:09:30 -08:00
ActiveTheme . Instance . TabLabelSelected , new RGBA_Bytes ( ) , ActiveTheme . Instance . TabLabelUnselected , new RGBA_Bytes ( ) ) ;
categoryPage . AnchorAll ( ) ;
categoryTabs . AddTab ( textTabWidget ) ;
TabControl sideTabs = CreateSideTabsAndPages ( minSettingNameWidth , category , uiState ) ;
sideTabBarsListForLayout . Add ( sideTabs . TabBar ) ;
categoryPage . AddChild ( sideTabs ) ;
}
2014-02-15 18:06:03 -08:00
if ( showAllDetails . Checked & & ActivePrinterProfile . Instance . ActiveSliceEngineType = = ActivePrinterProfile . SlicingEngineTypes . Slic3r )
2014-01-29 19:09:30 -08:00
{
TabPage extraSettingsPage = new TabPage ( "Other" ) ;
2014-06-10 11:44:16 -07:00
SimpleTextTabWidget extraSettingsTextTabWidget = new SimpleTextTabWidget ( extraSettingsPage , "Other Tab" , 16 ,
2014-01-29 19:09:30 -08:00
ActiveTheme . Instance . TabLabelSelected , new RGBA_Bytes ( ) , ActiveTheme . Instance . TabLabelUnselected , new RGBA_Bytes ( ) ) ;
extraSettingsPage . AnchorAll ( ) ;
int count ;
TabControl extraSettingsSideTabs = CreateExtraSettingsSideTabsAndPages ( minSettingNameWidth , categoryTabs , out count ) ;
if ( count > 0 )
{
categoryTabs . AddTab ( extraSettingsTextTabWidget ) ;
sideTabBarsListForLayout . Add ( extraSettingsSideTabs . TabBar ) ;
extraSettingsPage . AddChild ( extraSettingsSideTabs ) ;
}
}
double sideTabBarsMinimumWidth = 0 ;
foreach ( TabBar tabBar in sideTabBarsListForLayout )
{
sideTabBarsMinimumWidth = Math . Max ( sideTabBarsMinimumWidth , tabBar . Width ) ;
}
foreach ( TabBar tabBar in sideTabBarsListForLayout )
{
tabBar . MinimumSize = new Vector2 ( sideTabBarsMinimumWidth , tabBar . MinimumSize . y ) ;
}
// space before checkboxes (hold the right aligned)
{
GuiWidget hSpacer = new GuiWidget ( ) ;
hSpacer . HAnchor = HAnchor . ParentLeftRight ;
categoryTabs . TabBar . AddChild ( hSpacer ) ;
}
// add in the ability to turn on and off all details settings
{
2014-03-22 10:04:31 -07:00
showAllDetails . TextColor = ActiveTheme . Instance . PrimaryTextColor ;
2014-01-29 19:09:30 -08:00
showAllDetails . Margin = new BorderDouble ( right : 8 ) ;
showAllDetails . VAnchor = VAnchor . ParentCenter ;
showAllDetails . Cursor = Cursors . Hand ;
showAllDetails . CheckedStateChanged + = new CheckBox . CheckedStateChangedEventHandler ( RebuildSlicerSettings ) ;
categoryTabs . TabBar . AddChild ( showAllDetails ) ;
}
// add in the ability to turn on and off help text
{
2014-03-22 10:04:31 -07:00
showHelpBox . TextColor = ActiveTheme . Instance . PrimaryTextColor ;
2014-01-29 19:09:30 -08:00
showHelpBox . Margin = new BorderDouble ( right : 3 ) ;
showHelpBox . VAnchor = VAnchor . ParentCenter ;
showHelpBox . Cursor = Cursors . Hand ;
showHelpBox . CheckedStateChanged + = new CheckBox . CheckedStateChangedEventHandler ( RebuildSlicerSettings ) ;
2014-04-21 15:00:32 -07:00
categoryTabs . TabBar . AddChild ( showHelpBox ) ;
2014-01-29 19:09:30 -08:00
}
pageTopToBottomLayout . AddChild ( categoryTabs ) ;
AddHandlers ( ) ;
SetVisibleControls ( ) ;
if ( ! categoryTabs . SelectTab ( uiState . selectedCategory . name ) )
{
categoryTabs . SelectTab ( uiState . selectedCategory . index ) ;
}
2014-10-13 15:25:27 -07:00
this . AnchorAll ( ) ;
2014-01-29 19:09:30 -08:00
}
2014-04-21 15:00:32 -07:00
public bool ShowingHelp
{
get { return showHelpBox . Checked ; }
}
public string UserLevel
{
2014-07-26 13:43:55 -07:00
get
2014-04-21 15:00:32 -07:00
{
if ( showAllDetails . Checked )
{
return "Advanced" ;
}
2014-07-26 13:43:55 -07:00
return "Beginner" ;
2014-04-21 15:00:32 -07:00
}
}
public void CurrentlyActiveCategory ( out int index , out string name )
{
index = categoryTabs . SelectedTabIndex ;
name = categoryTabs . SelectedTabName ;
}
public void CurrentlyActiveGroup ( out int index , out string name )
{
index = 0 ;
name = "" ;
TabPage currentPage = categoryTabs . GetActivePage ( ) ;
TabControl currentGroup = null ;
if ( currentPage . Children . Count > 0 )
{
currentGroup = currentPage . Children [ 0 ] as TabControl ;
}
if ( currentGroup ! = null )
{
index = currentGroup . SelectedTabIndex ;
name = currentGroup . SelectedTabName ;
}
}
2014-01-29 19:09:30 -08:00
void RebuildSlicerSettings ( object sender , EventArgs e )
{
2014-04-03 18:27:37 -07:00
UserSettings . Instance . set ( SliceSettingsShowHelpEntry , showHelpBox . Checked . ToString ( ) . ToLower ( ) ) ;
2014-07-26 13:43:55 -07:00
if ( showAllDetails . Checked )
2014-04-03 18:27:37 -07:00
{
UserSettings . Instance . set ( SliceSettingsLevelEntry , "Advanced" ) ;
}
else
{
UserSettings . Instance . set ( SliceSettingsLevelEntry , "Beginner" ) ;
}
2014-07-26 13:43:55 -07:00
2014-01-29 19:09:30 -08:00
CheckBox checkBox = sender as CheckBox ;
if ( checkBox ! = null )
{
2014-09-19 19:17:12 -07:00
ApplicationController . Instance . ReloadAdvancedControlsPanel ( ) ;
2014-01-29 19:09:30 -08:00
}
}
internal class ExtraSettingTextWidget : MHTextEditWidget
{
internal string itemKey { get ; set ; }
internal ExtraSettingTextWidget ( string itemKey , string itemValue )
: base ( itemValue )
{
this . itemKey = itemKey ;
}
}
event EventHandler unregisterEvents ;
private void AddHandlers ( )
{
2014-06-11 14:52:58 -07:00
PrinterConnectionAndCommunication . Instance . CommunicationStateChanged . RegisterEvent ( onPrinterStatusChanged , ref unregisterEvents ) ;
2014-04-21 15:00:32 -07:00
ActivePrinterProfile . Instance . ActivePrinterChanged . RegisterEvent ( APP_onPrinterStatusChanged , ref unregisterEvents ) ;
2014-06-11 14:52:58 -07:00
PrinterConnectionAndCommunication . Instance . EnableChanged . RegisterEvent ( onPrinterStatusChanged , ref unregisterEvents ) ;
2014-01-29 19:09:30 -08:00
}
public override void OnClosed ( EventArgs e )
{
if ( unregisterEvents ! = null )
{
unregisterEvents ( this , null ) ;
}
base . OnClosed ( e ) ;
}
private void onPrinterStatusChanged ( object sender , EventArgs e )
{
SetVisibleControls ( ) ;
this . Invalidate ( ) ;
}
2014-04-21 15:00:32 -07:00
private void APP_onPrinterStatusChanged ( object sender , EventArgs e )
{
SetVisibleControls ( ) ;
this . Invalidate ( ) ;
}
2014-01-29 19:09:30 -08:00
private void SetVisibleControls ( )
{
2014-02-14 12:06:44 -08:00
if ( ActivePrinterProfile . Instance . ActivePrinter ! = null )
2014-01-29 19:09:30 -08:00
{
categoryTabs . Visible = true ;
settingsControlBar . Visible = true ;
noConnectionMessageContainer . Visible = false ;
}
else
{
categoryTabs . Visible = false ;
settingsControlBar . Visible = false ;
noConnectionMessageContainer . Visible = true ;
}
}
int tabIndexForItem = 0 ;
2014-07-26 13:43:55 -07:00
private TabControl CreateSideTabsAndPages ( int minSettingNameWidth , OrganizerCategory category , SliceSettingsWidgetUiState uiState )
2014-01-29 19:09:30 -08:00
{
TabControl groupTabs = new TabControl ( Orientation . Vertical ) ;
groupTabs . Margin = new BorderDouble ( 0 , 0 , 0 , 5 ) ;
2014-03-22 10:04:31 -07:00
groupTabs . TabBar . BorderColor = ActiveTheme . Instance . PrimaryTextColor ;
2014-01-29 19:09:30 -08:00
foreach ( OrganizerGroup group in category . GroupsList )
{
tabIndexForItem = 0 ;
2014-07-26 13:43:55 -07:00
string groupTabLabel = LocalizedString . Get ( group . Name ) ;
TabPage groupTabPage = new TabPage ( groupTabLabel ) ;
2014-04-09 18:45:29 -07:00
groupTabPage . HAnchor = HAnchor . ParentLeftRight ;
2014-06-10 11:44:16 -07:00
SimpleTextTabWidget groupTabWidget = new SimpleTextTabWidget ( groupTabPage , group . Name + " Tab" , 14 ,
2014-01-29 19:09:30 -08:00
ActiveTheme . Instance . TabLabelSelected , new RGBA_Bytes ( ) , ActiveTheme . Instance . TabLabelUnselected , new RGBA_Bytes ( ) ) ;
2014-04-09 18:45:29 -07:00
groupTabWidget . HAnchor = Agg . UI . HAnchor . ParentLeftRight ;
2014-01-29 19:09:30 -08:00
FlowLayoutWidget subGroupLayoutTopToBottom = new FlowLayoutWidget ( FlowDirection . TopToBottom ) ;
subGroupLayoutTopToBottom . AnchorAll ( ) ;
bool needToAddSubGroup = false ;
foreach ( OrganizerSubGroup subGroup in group . SubGroupsList )
{
2014-09-25 11:01:15 -07:00
string subGroupTitle = subGroup . Name ;
int numberOfCopies = 1 ;
if ( subGroup . Name = = "Extruder X" )
{
2014-09-26 17:52:54 -07:00
numberOfCopies = ActiveSliceSettings . Instance . ExtruderCount ;
2014-09-25 11:01:15 -07:00
}
2014-01-29 19:09:30 -08:00
2014-09-25 11:01:15 -07:00
for ( int copyIndex = 0 ; copyIndex < numberOfCopies ; copyIndex + + )
2014-01-29 19:09:30 -08:00
{
2014-09-25 11:01:15 -07:00
if ( subGroup . Name = = "Extruder X" )
2014-01-29 19:09:30 -08:00
{
2014-09-29 17:59:57 -07:00
subGroupTitle = "{0} {1}" . FormatWith ( "Extruder" . Localize ( ) , copyIndex + 1 ) ;
2014-09-25 11:01:15 -07:00
}
bool addedSettingToSubGroup = false ;
FlowLayoutWidget topToBottomSettings = new FlowLayoutWidget ( FlowDirection . TopToBottom ) ;
topToBottomSettings . HAnchor = Agg . UI . HAnchor . ParentLeftRight ;
2014-01-29 19:09:30 -08:00
2014-09-25 11:01:15 -07:00
foreach ( OrganizerSettingsData settingInfo in subGroup . SettingDataList )
{
if ( ActivePrinterProfile . Instance . ActiveSliceEngine . MapContains ( settingInfo . SlicerConfigName ) )
2014-01-29 19:09:30 -08:00
{
2014-09-25 11:01:15 -07:00
addedSettingToSubGroup = true ;
GuiWidget controlsForThisSetting = CreateSettingInfoUIControls ( settingInfo , minSettingNameWidth , copyIndex ) ;
topToBottomSettings . AddChild ( controlsForThisSetting ) ;
if ( showHelpBox . Checked )
{
AddInHelpText ( topToBottomSettings , settingInfo ) ;
}
2014-01-29 19:09:30 -08:00
}
}
2014-09-25 11:01:15 -07:00
if ( addedSettingToSubGroup )
{
needToAddSubGroup = true ;
2014-09-29 17:59:57 -07:00
string groupBoxLabel = subGroupTitle ;
2014-09-25 11:01:15 -07:00
AltGroupBox groupBox = new AltGroupBox ( groupBoxLabel ) ;
groupBox . TextColor = ActiveTheme . Instance . PrimaryTextColor ;
groupBox . BorderColor = ActiveTheme . Instance . PrimaryTextColor ;
groupBox . AddChild ( topToBottomSettings ) ;
groupBox . HAnchor = Agg . UI . HAnchor . ParentLeftRight ;
groupBox . Margin = new BorderDouble ( 3 , 3 , 3 , 0 ) ;
subGroupLayoutTopToBottom . AddChild ( groupBox ) ;
}
2014-01-29 19:09:30 -08:00
}
}
if ( needToAddSubGroup )
{
2014-04-09 18:45:29 -07:00
SliceSettingListControl scrollOnGroupTab = new SliceSettingListControl ( ) ;
2014-01-29 19:09:30 -08:00
subGroupLayoutTopToBottom . VAnchor = VAnchor . FitToChildren ;
2014-04-09 18:45:29 -07:00
subGroupLayoutTopToBottom . HAnchor = Agg . UI . HAnchor . ParentLeftRight ;
2014-07-26 13:43:55 -07:00
2014-01-29 19:09:30 -08:00
scrollOnGroupTab . AddChild ( subGroupLayoutTopToBottom ) ;
groupTabPage . AddChild ( scrollOnGroupTab ) ;
groupTabs . AddTab ( groupTabWidget ) ;
}
}
if ( ! groupTabs . SelectTab ( uiState . selectedGroup . name ) )
{
groupTabs . SelectTab ( uiState . selectedGroup . index ) ;
}
return groupTabs ;
}
private void AddInHelpText ( FlowLayoutWidget topToBottomSettings , OrganizerSettingsData settingInfo )
{
FlowLayoutWidget allText = new FlowLayoutWidget ( FlowDirection . TopToBottom ) ;
double textRegionWidth = 380 ;
allText . Margin = new BorderDouble ( 3 ) ;
allText . Padding = new BorderDouble ( 5 ) ;
allText . BackgroundColor = ActiveTheme . Instance . TransparentDarkOverlay ;
double helpPointSize = 10 ;
2014-02-04 13:30:42 -08:00
2014-04-08 17:22:03 -07:00
EnglishTextWrapping wrapper = new EnglishTextWrapping ( helpPointSize ) ;
string [ ] wrappedText = wrapper . WrapText ( settingInfo . HelpText , textRegionWidth - allText . Padding . Width ) ;
2014-07-26 13:43:55 -07:00
foreach ( string line in wrappedText )
2014-01-29 19:09:30 -08:00
{
GuiWidget helpWidget = new TextWidget ( line , pointSize : helpPointSize , textColor : RGBA_Bytes . White ) ;
2014-04-25 16:57:57 -07:00
helpWidget . Margin = new BorderDouble ( 5 , 0 , 0 , 0 ) ;
2014-04-24 12:57:03 -07:00
helpWidget . HAnchor = HAnchor . ParentLeft ;
2014-01-29 19:09:30 -08:00
allText . AddChild ( helpWidget ) ;
}
allText . MinimumSize = new Vector2 ( textRegionWidth , allText . MinimumSize . y ) ;
if ( wrappedText . Length > 0 )
{
topToBottomSettings . AddChild ( allText ) ;
}
}
private TabControl CreateExtraSettingsSideTabsAndPages ( int minSettingNameWidth , TabControl categoryTabs , out int count )
{
count = 0 ;
TabControl sideTabs = new TabControl ( Orientation . Vertical ) ;
sideTabs . Margin = new BorderDouble ( 0 , 0 , 0 , 5 ) ;
sideTabs . TabBar . BorderColor = RGBA_Bytes . White ;
{
TabPage groupTabPage = new TabPage ( "Extra Settings" ) ;
2014-06-10 11:44:16 -07:00
SimpleTextTabWidget groupTabWidget = new SimpleTextTabWidget ( groupTabPage , "Extra Settings Tab" , 14 ,
2014-01-29 19:09:30 -08:00
ActiveTheme . Instance . TabLabelSelected , new RGBA_Bytes ( ) , ActiveTheme . Instance . TabLabelUnselected , new RGBA_Bytes ( ) ) ;
sideTabs . AddTab ( groupTabWidget ) ;
FlowLayoutWidget subGroupLayoutTopToBottom = new FlowLayoutWidget ( FlowDirection . TopToBottom ) ;
subGroupLayoutTopToBottom . HAnchor = Agg . UI . HAnchor . Max_FitToChildren_ParentWidth ;
subGroupLayoutTopToBottom . VAnchor = VAnchor . FitToChildren ;
FlowLayoutWidget topToBottomSettings = new FlowLayoutWidget ( FlowDirection . TopToBottom ) ;
topToBottomSettings . HAnchor = Agg . UI . HAnchor . Max_FitToChildren_ParentWidth ;
foreach ( KeyValuePair < string , DataStorage . SliceSetting > item in ActiveSliceSettings . Instance . DefaultSettings )
{
if ( ! SliceSettingsOrganizer . Instance . Contains ( UserLevel , item . Key ) )
{
OrganizerSettingsData settingInfo = new OrganizerSettingsData ( item . Key , item . Key , OrganizerSettingsData . DataEditTypes . STRING ) ;
2014-09-25 11:01:15 -07:00
GuiWidget controlsForThisSetting = CreateSettingInfoUIControls ( settingInfo , minSettingNameWidth , 0 ) ;
2014-01-29 19:09:30 -08:00
topToBottomSettings . AddChild ( controlsForThisSetting ) ;
count + + ;
}
}
2014-09-18 17:06:45 -07:00
AltGroupBox groupBox = new AltGroupBox ( LocalizedString . Get ( "Extra" ) ) ;
2014-01-29 19:09:30 -08:00
groupBox . TextColor = ActiveTheme . Instance . PrimaryTextColor ;
groupBox . BorderColor = ActiveTheme . Instance . PrimaryTextColor ;
groupBox . AddChild ( topToBottomSettings ) ;
groupBox . VAnchor = VAnchor . FitToChildren ;
groupBox . HAnchor = Agg . UI . HAnchor . Max_FitToChildren_ParentWidth ;
subGroupLayoutTopToBottom . AddChild ( groupBox ) ;
2014-04-09 18:45:29 -07:00
SliceSettingListControl scrollOnGroupTab = new SliceSettingListControl ( ) ;
2014-01-29 19:09:30 -08:00
scrollOnGroupTab . AnchorAll ( ) ;
scrollOnGroupTab . AddChild ( subGroupLayoutTopToBottom ) ;
groupTabPage . AddChild ( scrollOnGroupTab ) ;
}
return sideTabs ;
}
private TextWidget getSettingInfoData ( OrganizerSettingsData settingData )
{
string extraSettings = settingData . ExtraSettings ;
extraSettings = extraSettings . Replace ( "\\n" , "\n" ) ;
2014-09-18 17:06:45 -07:00
TextWidget dataTypeInfo = new TextWidget ( extraSettings , pointSize : 8 ) ;
2014-01-29 19:09:30 -08:00
dataTypeInfo . TextColor = ActiveTheme . Instance . PrimaryTextColor ;
dataTypeInfo . Margin = new BorderDouble ( 5 , 0 ) ;
return dataTypeInfo ;
}
2014-10-02 14:42:18 -07:00
static Dictionary < string , RootedObjectEventHandler > functionsToCallOnChange = new Dictionary < string , RootedObjectEventHandler > ( ) ;
public static void RegisterForSettingsChange ( string settingName , EventHandler functionToCallOnChange , ref EventHandler functionThatWillBeCalledToUnregisterEvent )
{
if ( ! functionsToCallOnChange . ContainsKey ( settingName ) )
{
functionsToCallOnChange . Add ( settingName , new RootedObjectEventHandler ( ) ) ;
}
RootedObjectEventHandler rootedEvent = functionsToCallOnChange [ settingName ] ;
rootedEvent . RegisterEvent ( functionToCallOnChange , ref functionThatWillBeCalledToUnregisterEvent ) ;
}
2014-07-26 13:43:55 -07:00
private void CallEventsOnSettingsChange ( OrganizerSettingsData settingData )
2014-07-25 17:13:42 -07:00
{
2014-10-02 14:42:18 -07:00
foreach ( KeyValuePair < string , RootedObjectEventHandler > keyValue in functionsToCallOnChange )
2014-07-26 13:43:55 -07:00
{
2014-10-02 14:42:18 -07:00
if ( keyValue . Key = = settingData . SlicerConfigName )
{
keyValue . Value . CallEvents ( null , null ) ;
}
2014-07-26 13:43:55 -07:00
}
2014-07-25 17:13:42 -07:00
2014-10-02 14:42:18 -07:00
if ( settingToReloadUiWhenChanged . Contains ( settingData . SlicerConfigName ) )
2014-07-26 13:43:55 -07:00
{
2014-10-02 14:42:18 -07:00
ApplicationController . Instance . ReloadAll ( null , null ) ;
2014-07-26 13:43:55 -07:00
}
}
2014-07-24 14:11:10 -07:00
2014-09-25 11:01:15 -07:00
private GuiWidget CreateSettingInfoUIControls ( OrganizerSettingsData settingData , double minSettingNameWidth , int extruderIndex )
2014-01-29 19:09:30 -08:00
{
2014-07-26 13:43:55 -07:00
GuiWidget container = new GuiWidget ( ) ;
2014-01-29 19:09:30 -08:00
FlowLayoutWidget leftToRightLayout = new FlowLayoutWidget ( ) ;
2014-04-09 18:45:29 -07:00
bool addQualityOverlay = false ;
bool addMaterialOverlay = false ;
2014-04-12 13:56:04 -07:00
RGBA_Bytes qualityOverlayColor = new RGBA_Bytes ( 255 , 255 , 0 , 40 ) ;
RGBA_Bytes materialOverlayColor = new RGBA_Bytes ( 255 , 127 , 0 , 40 ) ;
2014-04-09 18:45:29 -07:00
2014-07-24 14:11:10 -07:00
2014-01-29 19:09:30 -08:00
if ( ActiveSliceSettings . Instance . Contains ( settingData . SlicerConfigName ) )
{
int intEditWidth = 60 ;
int doubleEditWidth = 60 ;
int vectorXYEditWidth = 60 ;
int multiLineEditHeight = 60 ;
string sliceSettingValue = ActiveSliceSettings . Instance . GetActiveValue ( settingData . SlicerConfigName ) ;
2014-04-09 18:45:29 -07:00
leftToRightLayout . Margin = new BorderDouble ( 0 , 2 ) ;
leftToRightLayout . Padding = new BorderDouble ( 3 ) ;
leftToRightLayout . HAnchor = Agg . UI . HAnchor . ParentLeftRight ;
2014-01-29 19:09:30 -08:00
if ( settingData . DataEditType ! = OrganizerSettingsData . DataEditTypes . MULTI_LINE_TEXT )
{
string convertedNewLines = settingData . PresentationName . Replace ( "\\n " , "\n" ) ;
convertedNewLines = convertedNewLines . Replace ( "\\n" , "\n" ) ;
2014-07-26 13:43:55 -07:00
convertedNewLines = LocalizedString . Get ( convertedNewLines ) ;
2014-09-18 17:06:45 -07:00
TextWidget settingName = new TextWidget ( convertedNewLines , pointSize : 10 ) ;
2014-01-29 19:09:30 -08:00
settingName . TextColor = ActiveTheme . Instance . PrimaryTextColor ;
2014-09-18 17:06:45 -07:00
settingName . VAnchor = Agg . UI . VAnchor . ParentCenter ;
2014-04-09 18:45:29 -07:00
if ( ActiveSliceSettings . Instance . SettingExistsInLayer ( settingData . SlicerConfigName , 3 ) )
{
2014-07-26 13:43:55 -07:00
addMaterialOverlay = true ;
2014-04-09 18:45:29 -07:00
}
else if ( ActiveSliceSettings . Instance . SettingExistsInLayer ( settingData . SlicerConfigName , 2 ) )
{
2014-04-12 13:56:04 -07:00
addQualityOverlay = true ;
2014-04-09 18:45:29 -07:00
}
2014-07-26 13:43:55 -07:00
2014-01-29 19:09:30 -08:00
settingName . Width = minSettingNameWidth ;
//settingName.MinimumSize = new Vector2(minSettingNameWidth, settingName.MinimumSize.y);
leftToRightLayout . AddChild ( settingName ) ;
}
2014-07-26 13:43:55 -07:00
2014-01-29 19:09:30 -08:00
switch ( settingData . DataEditType )
{
case OrganizerSettingsData . DataEditTypes . INT :
{
int currentValue = 0 ;
int . TryParse ( sliceSettingValue , out currentValue ) ;
MHNumberEdit intEditWidget = new MHNumberEdit ( currentValue , pixelWidth : intEditWidth , tabIndex : tabIndexForItem + + ) ;
2014-07-26 13:43:55 -07:00
intEditWidget . ActuallNumberEdit . EditComplete + = ( sender , e ) = >
{
SaveSetting ( settingData . SlicerConfigName , ( ( NumberEdit ) sender ) . Value . ToString ( ) ) ;
CallEventsOnSettingsChange ( settingData ) ;
} ;
2014-01-29 19:09:30 -08:00
leftToRightLayout . AddChild ( intEditWidget ) ;
leftToRightLayout . AddChild ( getSettingInfoData ( settingData ) ) ;
}
break ;
case OrganizerSettingsData . DataEditTypes . DOUBLE :
{
double currentValue = 0 ;
double . TryParse ( sliceSettingValue , out currentValue ) ;
MHNumberEdit doubleEditWidget = new MHNumberEdit ( currentValue , allowNegatives : true , allowDecimals : true , pixelWidth : doubleEditWidth , tabIndex : tabIndexForItem + + ) ;
2014-07-26 13:43:55 -07:00
doubleEditWidget . ActuallNumberEdit . EditComplete + = ( sender , e ) = >
{
SaveSetting ( settingData . SlicerConfigName , ( ( NumberEdit ) sender ) . Value . ToString ( ) ) ;
CallEventsOnSettingsChange ( settingData ) ;
} ;
2014-01-29 19:09:30 -08:00
leftToRightLayout . AddChild ( doubleEditWidget ) ;
leftToRightLayout . AddChild ( getSettingInfoData ( settingData ) ) ;
}
break ;
2014-03-25 12:14:03 -07:00
case OrganizerSettingsData . DataEditTypes . POSITIVE_DOUBLE :
2014-01-29 19:09:30 -08:00
{
double currentValue = 0 ;
double . TryParse ( sliceSettingValue , out currentValue ) ;
MHNumberEdit doubleEditWidget = new MHNumberEdit ( currentValue , allowDecimals : true , pixelWidth : doubleEditWidth , tabIndex : tabIndexForItem + + ) ;
2014-07-26 13:43:55 -07:00
doubleEditWidget . ActuallNumberEdit . EditComplete + = ( sender , e ) = >
{
SaveSetting ( settingData . SlicerConfigName , ( ( NumberEdit ) sender ) . Value . ToString ( ) ) ;
CallEventsOnSettingsChange ( settingData ) ;
} ;
2014-01-29 19:09:30 -08:00
leftToRightLayout . AddChild ( doubleEditWidget ) ;
leftToRightLayout . AddChild ( getSettingInfoData ( settingData ) ) ;
}
break ;
case OrganizerSettingsData . DataEditTypes . OFFSET :
{
double currentValue = 0 ;
double . TryParse ( sliceSettingValue , out currentValue ) ;
MHNumberEdit doubleEditWidget = new MHNumberEdit ( currentValue , allowDecimals : true , allowNegatives : true , pixelWidth : doubleEditWidth , tabIndex : tabIndexForItem + + ) ;
2014-07-26 13:43:55 -07:00
doubleEditWidget . ActuallNumberEdit . EditComplete + = ( sender , e ) = >
{
SaveSetting ( settingData . SlicerConfigName , ( ( NumberEdit ) sender ) . Value . ToString ( ) ) ;
CallEventsOnSettingsChange ( settingData ) ;
} ;
2014-01-29 19:09:30 -08:00
leftToRightLayout . AddChild ( doubleEditWidget ) ;
leftToRightLayout . AddChild ( getSettingInfoData ( settingData ) ) ;
}
break ;
case OrganizerSettingsData . DataEditTypes . DOUBLE_OR_PERCENT :
{
2014-09-18 17:06:45 -07:00
MHTextEditWidget stringEdit = new MHTextEditWidget ( sliceSettingValue , pixelWidth : doubleEditWidth - 2 , tabIndex : tabIndexForItem + + ) ;
2014-01-29 19:09:30 -08:00
stringEdit . ActualTextEditWidget . EditComplete + = ( sender , e ) = >
{
TextEditWidget textEditWidget = ( TextEditWidget ) sender ;
string text = textEditWidget . Text ;
text = text . Trim ( ) ;
bool isPercent = text . Contains ( "%" ) ;
2014-07-26 13:43:55 -07:00
if ( isPercent )
2014-01-29 19:09:30 -08:00
{
text = text . Substring ( 0 , text . IndexOf ( "%" ) ) ;
}
double result ;
double . TryParse ( text , out result ) ;
text = result . ToString ( ) ;
if ( isPercent )
{
text + = "%" ;
}
textEditWidget . Text = text ;
SaveSetting ( settingData . SlicerConfigName , textEditWidget . Text ) ;
2014-07-26 13:43:55 -07:00
CallEventsOnSettingsChange ( settingData ) ;
2014-01-29 19:09:30 -08:00
} ;
leftToRightLayout . AddChild ( stringEdit ) ;
leftToRightLayout . AddChild ( getSettingInfoData ( settingData ) ) ;
}
break ;
case OrganizerSettingsData . DataEditTypes . CHECK_BOX :
{
CheckBox checkBoxWidget = new CheckBox ( "" ) ;
checkBoxWidget . VAnchor = Agg . UI . VAnchor . ParentBottom ;
checkBoxWidget . TextColor = ActiveTheme . Instance . PrimaryTextColor ;
checkBoxWidget . Checked = ( sliceSettingValue = = "1" ) ;
checkBoxWidget . CheckedStateChanged + = ( sender , e ) = >
{
if ( ( ( CheckBox ) sender ) . Checked )
{
SaveSetting ( settingData . SlicerConfigName , "1" ) ;
}
else
{
SaveSetting ( settingData . SlicerConfigName , "0" ) ;
}
2014-07-26 13:43:55 -07:00
CallEventsOnSettingsChange ( settingData ) ;
2014-01-29 19:09:30 -08:00
} ;
leftToRightLayout . AddChild ( checkBoxWidget ) ;
}
break ;
case OrganizerSettingsData . DataEditTypes . STRING :
{
MHTextEditWidget stringEdit = new MHTextEditWidget ( sliceSettingValue , pixelWidth : 120 , tabIndex : tabIndexForItem + + ) ;
2014-07-26 13:43:55 -07:00
stringEdit . ActualTextEditWidget . EditComplete + = ( sender , e ) = >
{
SaveSetting ( settingData . SlicerConfigName , ( ( TextEditWidget ) sender ) . Text ) ;
CallEventsOnSettingsChange ( settingData ) ;
} ;
2014-01-29 19:09:30 -08:00
leftToRightLayout . AddChild ( stringEdit ) ;
}
break ;
case OrganizerSettingsData . DataEditTypes . MULTI_LINE_TEXT :
{
string convertedNewLines = sliceSettingValue . Replace ( "\\n" , "\n" ) ;
MHTextEditWidget stringEdit = new MHTextEditWidget ( convertedNewLines , pixelWidth : 320 , pixelHeight : multiLineEditHeight , multiLine : true , tabIndex : tabIndexForItem + + ) ;
2014-07-26 13:43:55 -07:00
stringEdit . ActualTextEditWidget . EditComplete + = ( sender , e ) = >
{
SaveSetting ( settingData . SlicerConfigName , ( ( TextEditWidget ) sender ) . Text . Replace ( "\n" , "\\n" ) ) ;
CallEventsOnSettingsChange ( settingData ) ;
} ;
2014-01-29 19:09:30 -08:00
leftToRightLayout . AddChild ( stringEdit ) ;
}
break ;
case OrganizerSettingsData . DataEditTypes . LIST :
{
2014-05-07 16:12:46 -07:00
StyledDropDownList selectableOptions = new StyledDropDownList ( "None" , maxHeight : 200 ) ;
2014-01-29 19:09:30 -08:00
selectableOptions . Margin = new BorderDouble ( ) ;
2014-07-26 13:43:55 -07:00
2014-01-29 19:09:30 -08:00
string [ ] listItems = settingData . ExtraSettings . Split ( ',' ) ;
2014-07-26 13:43:55 -07:00
2014-01-29 19:09:30 -08:00
foreach ( string listItem in listItems )
{
MenuItem newItem = selectableOptions . AddItem ( listItem ) ;
if ( newItem . Text = = sliceSettingValue )
{
2014-04-06 19:25:58 -07:00
selectableOptions . SelectedLabel = sliceSettingValue ;
2014-01-29 19:09:30 -08:00
}
newItem . Selected + = ( sender , e ) = >
{
MenuItem menuItem = ( ( MenuItem ) sender ) ;
SaveSetting ( settingData . SlicerConfigName , menuItem . Text ) ;
2014-07-26 13:43:55 -07:00
CallEventsOnSettingsChange ( settingData ) ;
2014-01-29 19:09:30 -08:00
} ;
}
leftToRightLayout . AddChild ( selectableOptions ) ;
}
break ;
2014-06-19 11:25:28 -07:00
case OrganizerSettingsData . DataEditTypes . HARDWARE_PRESENT :
{
CheckBox checkBoxWidget = new CheckBox ( "" ) ;
checkBoxWidget . VAnchor = Agg . UI . VAnchor . ParentBottom ;
checkBoxWidget . TextColor = ActiveTheme . Instance . PrimaryTextColor ;
checkBoxWidget . Checked = ( sliceSettingValue = = "1" ) ;
checkBoxWidget . CheckedStateChanged + = ( sender , e ) = >
{
if ( ( ( CheckBox ) sender ) . Checked )
{
SaveSetting ( settingData . SlicerConfigName , "1" ) ;
// Now show all of the settings that this control is associated with.
}
else
{
SaveSetting ( settingData . SlicerConfigName , "0" ) ;
// Now hide all of the settings that this control is associated with.
}
2014-07-26 13:43:55 -07:00
CallEventsOnSettingsChange ( settingData ) ;
2014-06-19 11:25:28 -07:00
} ;
leftToRightLayout . AddChild ( checkBoxWidget ) ;
}
break ;
2014-01-29 19:09:30 -08:00
case OrganizerSettingsData . DataEditTypes . VECTOR2 :
{
string [ ] xyValueStrings = sliceSettingValue . Split ( ',' ) ;
if ( xyValueStrings . Length ! = 2 )
{
xyValueStrings = new string [ ] { "0" , "0" } ;
}
2014-07-26 13:43:55 -07:00
double currentXValue = 0 ;
double . TryParse ( xyValueStrings [ 0 ] , out currentXValue ) ;
MHNumberEdit xEditWidget = new MHNumberEdit ( currentXValue , allowDecimals : true , pixelWidth : vectorXYEditWidth , tabIndex : tabIndexForItem + + ) ;
2014-07-23 17:38:47 -07:00
2014-07-26 13:43:55 -07:00
double currentYValue = 0 ;
double . TryParse ( xyValueStrings [ 1 ] , out currentYValue ) ;
MHNumberEdit yEditWidget = new MHNumberEdit ( currentYValue , allowDecimals : true , pixelWidth : vectorXYEditWidth , tabIndex : tabIndexForItem + + ) ;
xEditWidget . ActuallNumberEdit . EditComplete + = ( sender , e ) = >
{
SaveSetting ( settingData . SlicerConfigName , xEditWidget . ActuallNumberEdit . Value . ToString ( ) + "," + yEditWidget . ActuallNumberEdit . Value . ToString ( ) ) ;
CallEventsOnSettingsChange ( settingData ) ;
} ;
leftToRightLayout . AddChild ( xEditWidget ) ;
TextWidget xText = new TextWidget ( "x" ) ;
xText . TextColor = ActiveTheme . Instance . PrimaryTextColor ;
xText . Margin = new BorderDouble ( 5 , 0 ) ;
leftToRightLayout . AddChild ( xText ) ;
yEditWidget . ActuallNumberEdit . EditComplete + = ( sender , e ) = >
{
SaveSetting ( settingData . SlicerConfigName , xEditWidget . ActuallNumberEdit . Value . ToString ( ) + "," + yEditWidget . ActuallNumberEdit . Value . ToString ( ) ) ;
CallEventsOnSettingsChange ( settingData ) ;
} ;
leftToRightLayout . AddChild ( yEditWidget ) ;
TextWidget yText = new TextWidget ( "y" ) ;
yText . TextColor = ActiveTheme . Instance . PrimaryTextColor ;
yText . Margin = new BorderDouble ( 5 , 0 ) ;
leftToRightLayout . AddChild ( yText ) ;
2014-07-23 17:38:47 -07:00
2014-01-29 19:09:30 -08:00
}
break ;
case OrganizerSettingsData . DataEditTypes . OFFSET2 :
{
2014-09-29 17:59:57 -07:00
Vector2 offset = ActiveSliceSettings . Instance . GetOffset ( extruderIndex ) ;
MHNumberEdit xEditWidget = new MHNumberEdit ( offset . x , allowDecimals : true , allowNegatives : true , pixelWidth : vectorXYEditWidth , tabIndex : tabIndexForItem + + ) ;
MHNumberEdit yEditWidget = new MHNumberEdit ( offset . y , allowDecimals : true , allowNegatives : true , pixelWidth : vectorXYEditWidth , tabIndex : tabIndexForItem + + ) ;
2014-01-29 19:09:30 -08:00
{
2014-07-26 13:43:55 -07:00
xEditWidget . ActuallNumberEdit . EditComplete + = ( sender , e ) = >
{
2014-09-25 11:01:15 -07:00
int extruderIndexLocal = extruderIndex ;
2014-09-29 17:59:57 -07:00
SaveCommaSeparatedIndexSetting ( extruderIndexLocal , settingData . SlicerConfigName , xEditWidget . ActuallNumberEdit . Value . ToString ( ) + "x" + yEditWidget . ActuallNumberEdit . Value . ToString ( ) ) ;
2014-07-26 13:43:55 -07:00
CallEventsOnSettingsChange ( settingData ) ;
} ;
2014-01-29 19:09:30 -08:00
leftToRightLayout . AddChild ( xEditWidget ) ;
TextWidget xText = new TextWidget ( "x" ) ;
xText . TextColor = ActiveTheme . Instance . PrimaryTextColor ;
xText . Margin = new BorderDouble ( 5 , 0 ) ;
leftToRightLayout . AddChild ( xText ) ;
}
{
2014-07-26 13:43:55 -07:00
yEditWidget . ActuallNumberEdit . EditComplete + = ( sender , e ) = >
{
2014-09-25 11:01:15 -07:00
int extruderIndexLocal = extruderIndex ;
2014-09-29 17:59:57 -07:00
SaveCommaSeparatedIndexSetting ( extruderIndexLocal , settingData . SlicerConfigName , xEditWidget . ActuallNumberEdit . Value . ToString ( ) + "x" + yEditWidget . ActuallNumberEdit . Value . ToString ( ) ) ;
2014-07-26 13:43:55 -07:00
CallEventsOnSettingsChange ( settingData ) ;
} ;
2014-01-29 19:09:30 -08:00
leftToRightLayout . AddChild ( yEditWidget ) ;
TextWidget yText = new TextWidget ( "y" ) ;
yText . TextColor = ActiveTheme . Instance . PrimaryTextColor ;
yText . Margin = new BorderDouble ( 5 , 0 ) ;
leftToRightLayout . AddChild ( yText ) ;
}
}
break ;
default :
TextWidget missingSetting = new TextWidget ( String . Format ( "Missing the setting for '{0}'." , settingData . DataEditType . ToString ( ) ) ) ;
missingSetting . TextColor = ActiveTheme . Instance . PrimaryTextColor ;
missingSetting . BackgroundColor = RGBA_Bytes . Red ;
leftToRightLayout . AddChild ( missingSetting ) ;
break ;
}
}
else // the setting we think we are adding is not in the config.ini it may have been depricated
{
TextWidget settingName = new TextWidget ( String . Format ( "Setting '{0}' not found in config.ini" , settingData . SlicerConfigName ) ) ;
settingName . TextColor = ActiveTheme . Instance . PrimaryTextColor ;
settingName . MinimumSize = new Vector2 ( minSettingNameWidth , settingName . MinimumSize . y ) ;
leftToRightLayout . AddChild ( settingName ) ;
leftToRightLayout . BackgroundColor = RGBA_Bytes . Red ;
}
2014-04-09 18:45:29 -07:00
container . HAnchor = HAnchor . ParentLeftRight ;
container . VAnchor = VAnchor . FitToChildren ;
container . AddChild ( leftToRightLayout ) ;
if ( addQualityOverlay | | addMaterialOverlay )
2014-07-26 13:43:55 -07:00
{
2014-04-09 18:45:29 -07:00
SettingPresetOverlay overlay = new SettingPresetOverlay ( ) ;
overlay . HAnchor = HAnchor . ParentLeftRight ;
overlay . VAnchor = Agg . UI . VAnchor . ParentBottomTop ;
SettingPresetClick clickToEdit = new SettingPresetClick ( ) ;
clickToEdit . HAnchor = HAnchor . ParentLeftRight ;
clickToEdit . VAnchor = Agg . UI . VAnchor . ParentBottomTop ;
clickToEdit . Visible = false ;
Button editButton = buttonFactory . Generate ( "Edit Preset" . Localize ( ) . ToUpper ( ) ) ;
editButton . HAnchor = Agg . UI . HAnchor . ParentCenter ;
editButton . VAnchor = Agg . UI . VAnchor . ParentCenter ;
clickToEdit . AddChild ( editButton ) ;
if ( addQualityOverlay )
{
overlay . OverlayColor = qualityOverlayColor ;
clickToEdit . OverlayColor = qualityOverlayColor ;
editButton . Click + = ( sender , e ) = >
{
2014-09-19 19:17:12 -07:00
if ( ApplicationController . Instance . EditQualityPresetsWindow = = null )
2014-04-09 18:45:29 -07:00
{
2014-09-19 19:17:12 -07:00
ApplicationController . Instance . EditQualityPresetsWindow = new SlicePresetsWindow ( ReloadOptions , "Quality" , "quality" , false , ActivePrinterProfile . Instance . ActiveQualitySettingsID ) ;
ApplicationController . Instance . EditQualityPresetsWindow . Closed + = ( popupWindowSender , popupWindowSenderE ) = > { ApplicationController . Instance . EditQualityPresetsWindow = null ; } ;
2014-04-09 18:45:29 -07:00
}
else
{
2014-09-19 19:17:12 -07:00
ApplicationController . Instance . EditQualityPresetsWindow . ChangeToSlicePresetFromID ( ActivePrinterProfile . Instance . ActiveQualitySettingsID ) ;
ApplicationController . Instance . EditQualityPresetsWindow . BringToFront ( ) ;
2014-04-09 18:45:29 -07:00
}
} ;
}
else if ( addMaterialOverlay )
{
overlay . OverlayColor = materialOverlayColor ;
clickToEdit . OverlayColor = materialOverlayColor ;
editButton . Click + = ( sender , e ) = >
2014-07-26 13:43:55 -07:00
{
2014-09-19 19:17:12 -07:00
if ( ApplicationController . Instance . EditMaterialPresetsWindow = = null )
2014-04-09 18:45:29 -07:00
{
2014-09-19 19:17:12 -07:00
ApplicationController . Instance . EditMaterialPresetsWindow = new SlicePresetsWindow ( ReloadOptions , "Material" , "material" , false , ActivePrinterProfile . Instance . GetMaterialSetting ( 1 ) ) ;
ApplicationController . Instance . EditMaterialPresetsWindow . Closed + = ( popupWindowSender , popupWindowSenderE ) = > { ApplicationController . Instance . EditMaterialPresetsWindow = null ; } ;
2014-04-09 18:45:29 -07:00
}
else
{
2014-09-19 19:17:12 -07:00
ApplicationController . Instance . EditMaterialPresetsWindow . ChangeToSlicePresetFromID ( ActivePrinterProfile . Instance . GetMaterialSetting ( 1 ) ) ;
ApplicationController . Instance . EditMaterialPresetsWindow . BringToFront ( ) ;
2014-07-26 13:43:55 -07:00
}
2014-04-09 18:45:29 -07:00
} ;
2014-07-26 13:43:55 -07:00
}
2014-04-09 18:45:29 -07:00
container . MouseEnterBounds + = ( sender , e ) = >
{
UiThread . RunOnIdle ( ( state ) = >
{
overlay . Visible = false ;
clickToEdit . Visible = true ;
} ) ;
} ;
container . MouseLeaveBounds + = ( sender , e ) = >
{
UiThread . RunOnIdle ( ( state ) = >
{
overlay . Visible = true ;
clickToEdit . Visible = false ;
} ) ;
} ;
container . AddChild ( overlay ) ;
2014-07-26 13:43:55 -07:00
container . AddChild ( clickToEdit ) ;
2014-04-09 18:45:29 -07:00
}
return container ;
}
2014-09-29 17:59:57 -07:00
private void SaveCommaSeparatedIndexSetting ( int extruderIndexLocal , string slicerConfigName , string newSingleValue )
{
string [ ] settings = ActiveSliceSettings . Instance . GetActiveValue ( slicerConfigName ) . Split ( ',' ) ;
if ( settings . Length > extruderIndexLocal )
{
settings [ extruderIndexLocal ] = newSingleValue ;
}
else
{
string [ ] newSettings = new string [ extruderIndexLocal + 1 ] ;
for ( int i = 0 ; i < extruderIndexLocal + 1 ; i + + )
{
newSettings [ i ] = "" ;
if ( i < settings . Length )
{
newSettings [ i ] = settings [ i ] ;
}
else if ( i = = extruderIndexLocal )
{
newSettings [ i ] = newSingleValue ;
}
}
settings = newSettings ;
}
string newValue = string . Join ( "," , settings ) ;
SaveSetting ( slicerConfigName , newValue ) ;
}
2014-04-09 18:45:29 -07:00
protected void ReloadOptions ( object sender , EventArgs e )
{
2014-09-19 19:17:12 -07:00
ApplicationController . Instance . ReloadAdvancedControlsPanel ( ) ;
2014-01-29 19:09:30 -08:00
}
private void SaveSetting ( string slicerConfigName , string value )
{
//Hacky solution prevents saves when no printer is loaded
2014-02-14 12:06:44 -08:00
if ( ActivePrinterProfile . Instance . ActivePrinter ! = null )
2014-01-29 19:09:30 -08:00
{
SliceSettingsLayerSelector . Instance . SaveSetting ( slicerConfigName , value ) ;
}
}
public override void OnDraw ( Graphics2D graphics2D )
2014-07-26 13:43:55 -07:00
{
2014-01-29 19:09:30 -08:00
base . OnDraw ( graphics2D ) ;
}
}
2014-04-09 18:45:29 -07:00
class SettingPresetClick : ClickWidget
{
public RGBA_Bytes OverlayColor ;
public override void OnDraw ( Graphics2D graphics2D )
{
2014-07-26 13:43:55 -07:00
2014-04-09 18:45:29 -07:00
RoundedRect rect = new RoundedRect ( LocalBounds , 0 ) ;
graphics2D . Render ( rect , new RGBA_Bytes ( OverlayColor , 220 ) ) ;
base . OnDraw ( graphics2D ) ;
}
}
class SettingPresetOverlay : GuiWidget
{
public RGBA_Bytes OverlayColor ;
2014-07-26 13:43:55 -07:00
2014-04-09 18:45:29 -07:00
public override void OnDraw ( Graphics2D graphics2D )
{
base . OnDraw ( graphics2D ) ;
2014-07-26 13:43:55 -07:00
RoundedRect rect = new RoundedRect ( LocalBounds , 0 ) ;
graphics2D . Render ( rect , new RGBA_Bytes ( OverlayColor , 50 ) ) ;
graphics2D . Render ( new Stroke ( rect , 3 ) , OverlayColor ) ;
2014-04-09 18:45:29 -07:00
}
}
class SliceSettingListControl : ScrollableWidget
{
FlowLayoutWidget topToBottomItemList ;
public SliceSettingListControl ( )
{
this . AnchorAll ( ) ;
this . AutoScroll = true ;
this . ScrollArea . HAnchor | = Agg . UI . HAnchor . ParentLeftRight ;
topToBottomItemList = new FlowLayoutWidget ( FlowDirection . TopToBottom ) ;
topToBottomItemList . HAnchor = Agg . UI . HAnchor . Max_FitToChildren_ParentWidth ;
topToBottomItemList . Margin = new BorderDouble ( top : 3 ) ;
base . AddChild ( topToBottomItemList ) ;
}
public override void AddChild ( GuiWidget child , int indexInChildrenList = - 1 )
{
FlowLayoutWidget itemHolder = new FlowLayoutWidget ( ) ;
itemHolder . Margin = new BorderDouble ( 0 , 0 , 0 , 0 ) ;
itemHolder . HAnchor = Agg . UI . HAnchor . Max_FitToChildren_ParentWidth ;
itemHolder . AddChild ( child ) ;
itemHolder . VAnchor = VAnchor . FitToChildren ;
topToBottomItemList . AddChild ( itemHolder , indexInChildrenList ) ;
}
}
2014-01-29 19:09:30 -08:00
}