2014-02-15 18:06:03 -08:00
/ *
2016-04-18 11:31:31 -07:00
Copyright ( c ) 2016 , Lars Brubaker , John Lewin
2014-02-15 18:06:03 -08:00
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-02-15 18:06:03 -08: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-02-15 18:06:03 -08: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-02-15 18:06:03 -08: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-02-15 18:06:03 -08:00
either expressed or implied , of the FreeBSD Project .
* /
2014-01-29 19:09:30 -08:00
using MatterHackers.Agg ;
2016-04-22 15:05:21 -07:00
using MatterHackers.Agg.Image ;
2016-04-22 19:10:41 -07:00
using MatterHackers.Agg.PlatformAbstract ;
2014-02-05 17:47:13 -08:00
using MatterHackers.Agg.UI ;
2014-01-29 19:09:30 -08:00
using MatterHackers.Localizations ;
2014-11-03 12:13:03 -08:00
using MatterHackers.MatterControl.CustomWidgets ;
2015-04-08 15:20:10 -07:00
using MatterHackers.MatterControl.PrinterCommunication ;
2016-05-02 16:10:20 -07:00
using MatterHackers.SerialPortCommunication.FrostedSerial ;
2014-02-05 17:47:13 -08:00
using MatterHackers.VectorMath ;
2015-04-08 15:20:10 -07:00
using System ;
using System.Collections.Generic ;
2016-04-04 14:25:54 -07:00
using System.Linq ;
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
{
2016-04-18 11:31:31 -07:00
public class NoSettingsWidget : FlowLayoutWidget
{
public NoSettingsWidget ( ) : base ( FlowDirection . TopToBottom , vAnchor : VAnchor . ParentTop )
{
this . AnchorAll ( ) ;
this . Padding = new BorderDouble ( 3 , 0 ) ;
var noConnectionMessageContainer = new AltGroupBox ( new TextWidget ( LocalizedString . Get ( "No Printer Selected" ) , pointSize : 18 , textColor : ActiveTheme . Instance . SecondaryAccentColor ) ) ;
noConnectionMessageContainer . Margin = new BorderDouble ( top : 10 ) ;
noConnectionMessageContainer . BorderColor = ActiveTheme . Instance . PrimaryTextColor ;
noConnectionMessageContainer . HAnchor = Agg . UI . HAnchor . ParentLeftRight ;
noConnectionMessageContainer . Height = 90 ;
string noConnectionString = LocalizedString . Get ( "No printer is currently selected. Please select a printer to edit slice settings." ) ;
noConnectionString + = "\n\n" + LocalizedString . Get ( "NOTE: You need to select a printer, but do not need to connect to it." ) ;
TextWidget noConnectionMessage = new TextWidget ( noConnectionString , pointSize : 10 ) ;
noConnectionMessage . Margin = new BorderDouble ( 5 ) ;
noConnectionMessage . TextColor = ActiveTheme . Instance . PrimaryTextColor ;
noConnectionMessage . VAnchor = VAnchor . ParentCenter ;
noConnectionMessageContainer . AddChild ( noConnectionMessage ) ;
this . AddChild ( noConnectionMessageContainer ) ;
}
}
2015-04-08 15:20:10 -07:00
public class SliceSettingsWidget : GuiWidget
{
private static List < string > settingToReloadUiWhenChanged = new List < string > ( )
2016-04-21 17:24:56 -07:00
{
"extruder_count" ,
"extruders_share_temperature" ,
"has_fan" ,
"has_heated_bed" ,
"has_sd_card_reader" ,
2015-05-22 11:11:32 -07:00
"center_part_on_bed" ,
2016-04-20 11:53:08 -07:00
"has_hardware_leveling" ,
2016-03-07 14:11:36 -08:00
"include_firmware_updater" ,
2016-04-20 11:53:08 -07:00
"print_leveling_required_to_print" ,
"show_reset_connection" ,
2016-04-21 17:24:56 -07:00
} ;
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
private TextImageButtonFactory buttonFactory = new TextImageButtonFactory ( ) ;
private SliceSettingsDetailControl sliceSettingsDetailControl ;
2014-01-29 19:09:30 -08:00
2016-05-12 18:42:19 -07:00
private TabControl topCategoryTabs ;
2015-04-08 15:20:10 -07:00
private AltGroupBox noConnectionMessageContainer ;
2016-04-18 11:31:31 -07:00
internal SettingsControlBar settingsControlBar ;
2016-04-21 17:24:56 -07:00
2016-04-18 11:31:31 -07:00
private TextImageButtonFactory textImageButtonFactory ;
2014-12-31 14:17:18 -08:00
2016-05-16 16:21:42 -07:00
private List < SettingsLayer > layerCascade = null ;
2016-04-18 11:31:31 -07:00
private SettingsLayer persistenceLayer = null ;
private NamedSettingsLayers viewFilter ;
2016-05-16 16:21:42 -07:00
public SliceSettingsWidget ( List < SettingsLayer > layerCascade = null , NamedSettingsLayers viewFilter = NamedSettingsLayers . All )
2015-04-08 15:20:10 -07:00
{
2016-05-16 16:21:42 -07:00
this . layerCascade = layerCascade ;
2016-04-18 11:31:31 -07:00
this . viewFilter = viewFilter ;
// The last layer of the layerFilters is the target persistence layer
2016-05-16 16:21:42 -07:00
persistenceLayer = layerCascade ? . First ( ) ? ? ActiveSliceSettings . Instance . UserLayer ;
2016-04-18 11:31:31 -07:00
textImageButtonFactory = new TextImageButtonFactory ( ) ;
textImageButtonFactory . normalFillColor = RGBA_Bytes . Transparent ;
2016-05-06 17:56:27 -07:00
textImageButtonFactory . FixedHeight = 15 * GuiWidget . DeviceScale ;
2016-04-18 11:31:31 -07:00
textImageButtonFactory . fontSize = 8 ;
textImageButtonFactory . borderWidth = 1 ;
textImageButtonFactory . normalBorderColor = new RGBA_Bytes ( ActiveTheme . Instance . PrimaryTextColor , 200 ) ;
textImageButtonFactory . hoverBorderColor = new RGBA_Bytes ( ActiveTheme . Instance . PrimaryTextColor , 200 ) ;
this . textImageButtonFactory . disabledTextColor = RGBA_Bytes . Gray ;
this . textImageButtonFactory . hoverTextColor = ActiveTheme . Instance . PrimaryTextColor ;
this . textImageButtonFactory . normalTextColor = ActiveTheme . Instance . SecondaryTextColor ;
this . textImageButtonFactory . pressedTextColor = ActiveTheme . Instance . PrimaryTextColor ;
2016-05-06 17:56:27 -07:00
buttonFactory . FixedHeight = 20 * GuiWidget . DeviceScale ;
2015-04-08 15:20:10 -07:00
buttonFactory . fontSize = 10 ;
buttonFactory . normalFillColor = RGBA_Bytes . White ;
buttonFactory . normalTextColor = RGBA_Bytes . DarkGray ;
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
FlowLayoutWidget pageTopToBottomLayout = new FlowLayoutWidget ( FlowDirection . TopToBottom , vAnchor : Agg . UI . VAnchor . ParentTop ) ;
pageTopToBottomLayout . AnchorAll ( ) ;
pageTopToBottomLayout . Padding = new BorderDouble ( 3 , 0 ) ;
this . AddChild ( pageTopToBottomLayout ) ;
2014-01-29 19:09:30 -08:00
2016-03-30 18:33:29 -07:00
settingsControlBar = new SettingsControlBar ( )
{
HAnchor = HAnchor . ParentLeftRight ,
BackgroundColor = ActiveTheme . Instance . TransparentDarkOverlay ,
Padding = new BorderDouble ( 8 , 12 , 8 , 8 )
} ;
2014-01-29 19:09:30 -08:00
2016-03-30 18:33:29 -07:00
pageTopToBottomLayout . AddChild ( settingsControlBar ) ;
2016-04-21 17:24:56 -07:00
2016-04-22 17:30:34 -07:00
noConnectionMessageContainer = new AltGroupBox ( new TextWidget ( "No Printer Selected" . Localize ( ) , pointSize : 18 , textColor : ActiveTheme . Instance . SecondaryAccentColor ) ) ;
2015-04-08 15:20:10 -07:00
noConnectionMessageContainer . Margin = new BorderDouble ( top : 10 ) ;
noConnectionMessageContainer . BorderColor = ActiveTheme . Instance . PrimaryTextColor ;
noConnectionMessageContainer . HAnchor = Agg . UI . HAnchor . ParentLeftRight ;
noConnectionMessageContainer . Height = 90 ;
2016-04-22 17:30:34 -07:00
string noConnectionString = "No printer is currently selected. Please select a printer to edit slice settings." . Localize ( ) ;
noConnectionString + = "\n\n" + "NOTE: You need to select a printer, but do not need to connect to it." . Localize ( ) ;
2015-04-08 15:20:10 -07:00
TextWidget noConnectionMessage = new TextWidget ( noConnectionString , pointSize : 10 ) ;
noConnectionMessage . Margin = new BorderDouble ( 5 ) ;
noConnectionMessage . TextColor = ActiveTheme . Instance . PrimaryTextColor ;
noConnectionMessage . VAnchor = VAnchor . ParentCenter ;
noConnectionMessageContainer . AddChild ( noConnectionMessage ) ;
pageTopToBottomLayout . AddChild ( noConnectionMessageContainer ) ;
2016-05-12 18:42:19 -07:00
topCategoryTabs = new TabControl ( ) ;
topCategoryTabs . TabBar . BorderColor = ActiveTheme . Instance . PrimaryTextColor ;
topCategoryTabs . Margin = new BorderDouble ( top : 8 ) ;
topCategoryTabs . AnchorAll ( ) ;
2015-04-08 15:20:10 -07:00
sliceSettingsDetailControl = new SliceSettingsDetailControl ( ) ;
List < TabBar > sideTabBarsListForLayout = new List < TabBar > ( ) ;
2016-05-12 18:42:19 -07:00
for ( int topCategoryIndex = 0 ; topCategoryIndex < SliceSettingsOrganizer . Instance . UserLevels [ UserLevel ] . CategoriesList . Count ; topCategoryIndex + + )
2015-04-08 15:20:10 -07:00
{
2016-05-12 18:42:19 -07:00
OrganizerCategory category = SliceSettingsOrganizer . Instance . UserLevels [ UserLevel ] . CategoriesList [ topCategoryIndex ] ;
2016-04-22 17:30:34 -07:00
string categoryPageLabel = category . Name . Localize ( ) ;
2015-04-08 15:20:10 -07:00
TabPage categoryPage = new TabPage ( categoryPageLabel ) ;
SimpleTextTabWidget textTabWidget = new SimpleTextTabWidget ( categoryPage , category . Name + " Tab" , 16 ,
ActiveTheme . Instance . TabLabelSelected , new RGBA_Bytes ( ) , ActiveTheme . Instance . TabLabelUnselected , new RGBA_Bytes ( ) ) ;
categoryPage . AnchorAll ( ) ;
2016-05-12 18:42:19 -07:00
topCategoryTabs . AddTab ( textTabWidget ) ;
2015-04-08 15:20:10 -07:00
2016-05-16 17:11:49 -07:00
TabControl sideTabs = CreateSideTabsAndPages ( category ) ;
2015-04-08 15:20:10 -07:00
sideTabBarsListForLayout . Add ( sideTabs . TabBar ) ;
categoryPage . AddChild ( sideTabs ) ;
}
2016-05-12 18:42:19 -07:00
topCategoryTabs . TabBar . AddChild ( new HorizontalSpacer ( ) ) ;
topCategoryTabs . TabBar . AddChild ( sliceSettingsDetailControl ) ;
2015-04-08 15:20:10 -07:00
2016-04-28 09:41:27 -07:00
if ( sliceSettingsDetailControl . SelectedValue = = "Advanced" & & ActiveSliceSettings . Instance . ActiveSliceEngineType ( ) = = SlicingEngineTypes . Slic3r )
2015-04-08 15:20:10 -07:00
{
TabPage extraSettingsPage = new TabPage ( "Other" ) ;
SimpleTextTabWidget extraSettingsTextTabWidget = new SimpleTextTabWidget ( extraSettingsPage , "Other Tab" , 16 ,
ActiveTheme . Instance . TabLabelSelected , new RGBA_Bytes ( ) , ActiveTheme . Instance . TabLabelUnselected , new RGBA_Bytes ( ) ) ;
extraSettingsPage . AnchorAll ( ) ;
int count ;
2016-05-16 17:11:49 -07:00
TabControl extraSettingsSideTabs = CreateExtraSettingsSideTabsAndPages ( topCategoryTabs , out count ) ;
2015-04-08 15:20:10 -07:00
if ( count > 0 )
{
2016-05-12 18:42:19 -07:00
topCategoryTabs . AddTab ( extraSettingsTextTabWidget ) ;
2015-04-08 15:20:10 -07:00
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 ) ;
}
2016-05-12 18:42:19 -07:00
// check if there is only one left side tab. If so hide the left tabs and expand the content.
foreach ( var tabList in sideTabBarsListForLayout )
2015-04-08 15:20:10 -07:00
{
2016-05-12 18:42:19 -07:00
if ( tabList . CountVisibleChildren ( ) = = 1 )
{
tabList . MinimumSize = new Vector2 ( 0 , 0 ) ;
tabList . Width = 0 ;
}
2015-04-08 15:20:10 -07:00
}
2016-05-12 18:42:19 -07:00
pageTopToBottomLayout . AddChild ( topCategoryTabs ) ;
2015-04-08 15:20:10 -07:00
AddHandlers ( ) ;
SetVisibleControls ( ) ;
2015-04-16 18:08:43 -07:00
// Make sure we are on the right tab when we create this view
2015-04-08 15:20:10 -07:00
{
2015-04-16 18:08:43 -07:00
string settingsName = "SliceSettingsWidget_CurrentTab" ;
string selectedTab = UserSettings . Instance . get ( settingsName ) ;
2016-05-12 18:42:19 -07:00
topCategoryTabs . SelectTab ( selectedTab ) ;
2015-04-16 18:08:43 -07:00
2016-05-12 18:42:19 -07:00
topCategoryTabs . TabBar . TabIndexChanged + = ( object sender , EventArgs e ) = >
2015-04-16 18:08:43 -07:00
{
2016-05-12 18:42:19 -07:00
UserSettings . Instance . set ( settingsName , topCategoryTabs . TabBar . SelectedTabName ) ;
2015-04-16 18:08:43 -07:00
} ;
2015-04-08 15:20:10 -07:00
}
2015-04-16 18:08:43 -07:00
2014-10-13 15:25:27 -07:00
this . AnchorAll ( ) ;
2014-12-31 14:17:18 -08:00
}
2015-04-08 15:20:10 -07:00
public string UserLevel
{
get
{
if ( SliceSettingsOrganizer . Instance . UserLevels . ContainsKey ( sliceSettingsDetailControl . SelectedValue ) )
{
return sliceSettingsDetailControl . SelectedValue ;
}
2014-04-21 15:00:32 -07:00
2015-04-08 15:20:10 -07:00
return "Simple" ;
}
}
public void CurrentlyActiveCategory ( out int index , out string name )
{
2016-05-12 18:42:19 -07:00
index = topCategoryTabs . SelectedTabIndex ;
name = topCategoryTabs . SelectedTabName ;
2015-04-08 15:20:10 -07:00
}
public void CurrentlyActiveGroup ( out int index , out string name )
{
index = 0 ;
name = "" ;
2016-05-12 18:42:19 -07:00
TabPage currentPage = topCategoryTabs . GetActivePage ( ) ;
2015-04-08 15:20:10 -07:00
TabControl currentGroup = null ;
if ( currentPage . Children . Count > 0 )
{
currentGroup = currentPage . Children [ 0 ] as TabControl ;
}
if ( currentGroup ! = null )
{
index = currentGroup . SelectedTabIndex ;
name = currentGroup . SelectedTabName ;
}
}
internal class ExtraSettingTextWidget : MHTextEditWidget
{
internal string itemKey { get ; set ; }
internal ExtraSettingTextWidget ( string itemKey , string itemValue )
: base ( itemValue )
{
this . itemKey = itemKey ;
}
}
private event EventHandler unregisterEvents ;
private void AddHandlers ( )
{
PrinterConnectionAndCommunication . Instance . CommunicationStateChanged . RegisterEvent ( onPrinterStatusChanged , ref unregisterEvents ) ;
2016-04-18 11:31:31 -07:00
ActiveSliceSettings . ActivePrinterChanged . RegisterEvent ( APP_onPrinterStatusChanged , ref unregisterEvents ) ;
2015-04-08 15:20:10 -07:00
PrinterConnectionAndCommunication . Instance . EnableChanged . RegisterEvent ( onPrinterStatusChanged , ref unregisterEvents ) ;
}
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
public override void OnClosed ( EventArgs e )
{
2016-04-18 11:31:31 -07:00
unregisterEvents ? . Invoke ( this , null ) ;
2015-04-08 15:20:10 -07:00
base . OnClosed ( e ) ;
}
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
private void onPrinterStatusChanged ( object sender , EventArgs e )
{
SetVisibleControls ( ) ;
this . Invalidate ( ) ;
}
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
private void APP_onPrinterStatusChanged ( object sender , EventArgs e )
{
SetVisibleControls ( ) ;
this . Invalidate ( ) ;
}
2014-04-21 15:00:32 -07:00
2015-04-08 15:20:10 -07:00
private void SetVisibleControls ( )
{
2016-04-18 11:31:31 -07:00
if ( ActiveSliceSettings . Instance ! = null )
2015-04-08 15:20:10 -07:00
{
2016-05-12 18:42:19 -07:00
topCategoryTabs . Visible = true ;
2015-04-08 15:20:10 -07:00
settingsControlBar . Visible = true ;
noConnectionMessageContainer . Visible = false ;
}
else
{
2016-05-12 18:42:19 -07:00
topCategoryTabs . Visible = false ;
2015-04-08 15:20:10 -07:00
settingsControlBar . Visible = false ;
noConnectionMessageContainer . Visible = true ;
}
}
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
private int tabIndexForItem = 0 ;
2016-05-16 17:11:49 -07:00
private TabControl CreateSideTabsAndPages ( OrganizerCategory category )
2015-04-08 15:20:10 -07:00
{
2016-05-12 18:42:19 -07:00
TabControl leftSideGroupTabs = new TabControl ( Orientation . Vertical ) ;
leftSideGroupTabs . Margin = new BorderDouble ( 0 , 0 , 0 , 5 ) ;
leftSideGroupTabs . TabBar . BorderColor = ActiveTheme . Instance . PrimaryTextColor ;
2015-04-08 15:20:10 -07:00
foreach ( OrganizerGroup group in category . GroupsList )
{
tabIndexForItem = 0 ;
2016-04-22 17:30:34 -07:00
string groupTabLabel = group . Name . Localize ( ) ;
2015-04-08 15:20:10 -07:00
TabPage groupTabPage = new TabPage ( groupTabLabel ) ;
groupTabPage . HAnchor = HAnchor . ParentLeftRight ;
2014-09-25 11:01:15 -07:00
2016-03-30 18:33:29 -07:00
//Side Tabs
2015-04-08 15:20:10 -07:00
SimpleTextTabWidget groupTabWidget = new SimpleTextTabWidget ( groupTabPage , group . Name + " Tab" , 14 ,
ActiveTheme . Instance . TabLabelSelected , new RGBA_Bytes ( ) , ActiveTheme . Instance . TabLabelUnselected , new RGBA_Bytes ( ) ) ;
groupTabWidget . HAnchor = Agg . UI . HAnchor . ParentLeftRight ;
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
FlowLayoutWidget subGroupLayoutTopToBottom = new FlowLayoutWidget ( FlowDirection . TopToBottom ) ;
subGroupLayoutTopToBottom . AnchorAll ( ) ;
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
bool needToAddSubGroup = false ;
foreach ( OrganizerSubGroup subGroup in group . SubGroupsList )
{
string subGroupTitle = subGroup . Name ;
int numberOfCopies = 1 ;
2016-04-21 17:24:56 -07:00
2015-04-08 15:20:10 -07:00
if ( subGroup . Name = = "Extruder X" )
{
2016-04-27 18:57:51 -07:00
numberOfCopies = ActiveSliceSettings . Instance . ExtruderCount ( ) ;
2015-04-08 15:20:10 -07:00
}
for ( int copyIndex = 0 ; copyIndex < numberOfCopies ; copyIndex + + )
{
if ( subGroup . Name = = "Extruder X" )
{
subGroupTitle = "{0} {1}" . FormatWith ( "Extruder" . Localize ( ) , copyIndex + 1 ) ;
}
bool addedSettingToSubGroup = false ;
FlowLayoutWidget topToBottomSettings = new FlowLayoutWidget ( FlowDirection . TopToBottom ) ;
topToBottomSettings . HAnchor = Agg . UI . HAnchor . ParentLeftRight ;
2016-05-16 17:11:49 -07:00
this . HAnchor = HAnchor . ParentLeftRight ;
2016-06-08 09:25:20 -07:00
foreach ( OrganizerSettingsData settingData in subGroup . SettingDataList )
2015-04-08 15:20:10 -07:00
{
2016-06-08 09:25:20 -07:00
bool settingShouldBeShown = CheckIfShouldBeShown ( settingData ) ;
2016-01-29 15:25:14 -08:00
2016-06-08 09:25:20 -07:00
if ( ActiveSliceSettings . Instance . ActiveSliceEngine ( ) . MapContains ( settingData . SlicerConfigName )
2016-01-29 15:25:14 -08:00
& & settingShouldBeShown )
2015-04-08 15:20:10 -07:00
{
addedSettingToSubGroup = true ;
2016-06-06 12:06:08 -07:00
bool addControl ;
2016-06-08 17:59:03 -07:00
GuiWidget controlsForThisSetting = CreateSettingInfoUIControls ( settingData , layerCascade , persistenceLayer , viewFilter , copyIndex , out addControl , ref tabIndexForItem ) ;
2016-06-06 12:06:08 -07:00
if ( addControl )
{
topToBottomSettings . AddChild ( controlsForThisSetting ) ;
2016-06-08 09:25:20 -07:00
GuiWidget helpBox = AddInHelpText ( topToBottomSettings , settingData ) ;
if ( ! sliceSettingsDetailControl . ShowingHelp )
{
helpBox . Visible = false ;
}
sliceSettingsDetailControl . ShowHelpChanged + = ( s , e ) = >
{
helpBox . Visible = sliceSettingsDetailControl . ShowingHelp ;
} ;
topToBottomSettings . AddChild ( helpBox ) ;
2016-06-06 12:06:08 -07:00
}
2015-04-08 15:20:10 -07:00
}
}
if ( addedSettingToSubGroup )
{
needToAddSubGroup = true ;
2016-01-08 17:55:42 -08:00
string groupBoxLabel = subGroupTitle . Localize ( ) ;
2015-04-08 15:20:10 -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
2015-04-08 15:20:10 -07:00
if ( needToAddSubGroup )
{
SliceSettingListControl scrollOnGroupTab = new SliceSettingListControl ( ) ;
2014-04-09 18:45:29 -07:00
2015-04-08 15:20:10 -07:00
subGroupLayoutTopToBottom . VAnchor = VAnchor . FitToChildren ;
subGroupLayoutTopToBottom . HAnchor = Agg . UI . HAnchor . ParentLeftRight ;
2014-07-26 13:43:55 -07:00
2015-04-08 15:20:10 -07:00
scrollOnGroupTab . AddChild ( subGroupLayoutTopToBottom ) ;
groupTabPage . AddChild ( scrollOnGroupTab ) ;
2016-05-12 18:42:19 -07:00
leftSideGroupTabs . AddTab ( groupTabWidget ) ;
2015-04-16 18:08:43 -07:00
// Make sure we have the right scroll position when we create this view
// This code is not working yet. Scroll widgets get a scroll event when the tab becomes visible that is always reseting them.
// So it is not usefull to enable this and in fact makes the tabs inconsistently scrolled. It is just here for reference. // 2015 04 16, LBB
2016-04-21 17:24:56 -07:00
if ( false )
2015-04-16 18:08:43 -07:00
{
string settingsScrollPosition = "SliceSettingsWidget_{0}_{1}_ScrollPosition" . FormatWith ( category . Name , group . Name ) ;
2016-04-21 17:24:56 -07:00
UiThread . RunOnIdle ( ( ) = >
2015-04-16 18:08:43 -07:00
{
int scrollPosition = UserSettings . Instance . Fields . GetInt ( settingsScrollPosition , - 100000 ) ;
if ( scrollPosition ! = - 100000 )
{
scrollOnGroupTab . ScrollPosition = new Vector2 ( 0 , scrollPosition ) ;
}
} ) ;
scrollOnGroupTab . ScrollPositionChanged + = ( object sender , EventArgs e ) = >
{
if ( scrollOnGroupTab . CanSelect )
{
UserSettings . Instance . Fields . SetInt ( settingsScrollPosition , ( int ) scrollOnGroupTab . ScrollPosition . y ) ;
}
} ;
}
2015-04-08 15:20:10 -07:00
}
}
2014-01-29 19:09:30 -08:00
2015-04-16 18:08:43 -07:00
// Make sure we are on the right tab when we create this view
2015-04-08 15:20:10 -07:00
{
2015-04-16 18:08:43 -07:00
string settingsTypeName = "SliceSettingsWidget_{0}_CurrentTab" . FormatWith ( category . Name ) ;
string selectedTab = UserSettings . Instance . get ( settingsTypeName ) ;
2016-05-12 18:42:19 -07:00
leftSideGroupTabs . SelectTab ( selectedTab ) ;
2015-04-16 18:08:43 -07:00
2016-05-12 18:42:19 -07:00
leftSideGroupTabs . TabBar . TabIndexChanged + = ( object sender , EventArgs e ) = >
2015-04-16 18:08:43 -07:00
{
2016-05-12 18:42:19 -07:00
UserSettings . Instance . set ( settingsTypeName , leftSideGroupTabs . TabBar . SelectedTabName ) ;
2015-04-16 18:08:43 -07:00
} ;
2015-04-08 15:20:10 -07:00
}
2015-04-16 18:08:43 -07:00
2016-05-12 18:42:19 -07:00
return leftSideGroupTabs ;
2015-04-08 15:20:10 -07:00
}
2014-01-29 19:09:30 -08:00
2016-06-08 09:25:20 -07:00
private bool CheckIfShouldBeShown ( OrganizerSettingsData settingData )
2016-04-20 11:53:08 -07:00
{
bool settingShouldBeShown = true ;
2016-06-08 09:25:20 -07:00
if ( settingData . ShowIfSet ! = null
& & settingData . ShowIfSet ! = "" )
2016-04-20 11:53:08 -07:00
{
string showValue = "0" ;
2016-06-08 09:25:20 -07:00
string checkName = settingData . ShowIfSet ;
2016-04-20 11:53:08 -07:00
if ( checkName . StartsWith ( "!" ) )
{
showValue = "1" ;
checkName = checkName . Substring ( 1 ) ;
}
2016-05-16 16:21:42 -07:00
string sliceSettingValue = GetActiveValue ( checkName , layerCascade ) ;
2016-04-20 11:53:08 -07:00
if ( sliceSettingValue = = showValue )
{
settingShouldBeShown = false ;
}
}
2016-06-08 09:25:20 -07:00
if ( viewFilter = = NamedSettingsLayers . Material | | viewFilter = = NamedSettingsLayers . Quality )
{
2016-06-08 11:18:53 -07:00
if ( ! settingData . ShowAsOverride )
2016-06-08 09:25:20 -07:00
{
settingShouldBeShown = false ;
}
}
2016-04-20 11:53:08 -07:00
return settingShouldBeShown ;
}
2016-06-08 09:25:20 -07:00
private GuiWidget AddInHelpText ( FlowLayoutWidget topToBottomSettings , OrganizerSettingsData settingData )
2015-04-08 15:20:10 -07:00
{
FlowLayoutWidget allText = new FlowLayoutWidget ( FlowDirection . TopToBottom ) ;
allText . HAnchor = HAnchor . ParentLeftRight ;
2016-05-06 17:56:27 -07:00
double textRegionWidth = 380 * GuiWidget . DeviceScale ;
2016-04-28 12:48:56 -07:00
allText . Margin = new BorderDouble ( 0 ) ;
2015-04-08 15:20:10 -07:00
allText . Padding = new BorderDouble ( 5 ) ;
allText . BackgroundColor = ActiveTheme . Instance . TransparentDarkOverlay ;
double helpPointSize = 10 ;
2016-06-08 09:25:20 -07:00
GuiWidget helpWidget = new WrappedTextWidget ( settingData . HelpText , textRegionWidth , pointSize : helpPointSize , textColor : RGBA_Bytes . White ) ;
2015-04-08 15:20:10 -07:00
helpWidget . Margin = new BorderDouble ( 5 , 0 , 0 , 0 ) ;
//helpWidget.HAnchor = HAnchor.ParentLeft;
allText . AddChild ( helpWidget ) ;
2016-04-26 15:10:51 -07:00
allText . MinimumSize = new Vector2 ( 0 , allText . MinimumSize . y ) ;
return allText ;
2015-04-08 15:20:10 -07:00
}
2016-05-16 17:11:49 -07:00
private TabControl CreateExtraSettingsSideTabsAndPages ( TabControl categoryTabs , out int count )
2015-04-08 15:20:10 -07:00
{
2016-05-16 17:11:49 -07:00
int rightContentWidth = ( int ) ( 280 * GuiWidget . DeviceScale + . 5 ) ;
2015-04-08 15:20:10 -07:00
count = 0 ;
2016-05-12 18:42:19 -07:00
TabControl leftSideGroupTabs = new TabControl ( Orientation . Vertical ) ;
leftSideGroupTabs . Margin = new BorderDouble ( 0 , 0 , 0 , 5 ) ;
leftSideGroupTabs . TabBar . BorderColor = RGBA_Bytes . White ;
2015-04-08 15:20:10 -07:00
{
TabPage groupTabPage = new TabPage ( "Extra Settings" ) ;
SimpleTextTabWidget groupTabWidget = new SimpleTextTabWidget ( groupTabPage , "Extra Settings Tab" , 14 ,
ActiveTheme . Instance . TabLabelSelected , new RGBA_Bytes ( ) , ActiveTheme . Instance . TabLabelUnselected , new RGBA_Bytes ( ) ) ;
2016-05-12 18:42:19 -07:00
leftSideGroupTabs . AddTab ( groupTabWidget ) ;
2015-04-08 15:20:10 -07:00
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 ;
2016-05-16 17:11:49 -07:00
this . HAnchor = HAnchor . ParentLeftRight ;
2016-04-29 15:00:10 -07:00
foreach ( var keyValue in ActiveSliceSettings . Instance . BaseLayer )
2015-04-08 15:20:10 -07:00
{
2016-04-29 15:00:10 -07:00
if ( ! SliceSettingsOrganizer . Instance . Contains ( UserLevel , keyValue . Key ) )
2015-04-08 15:20:10 -07:00
{
2016-06-08 09:25:20 -07:00
OrganizerSettingsData settingData = new OrganizerSettingsData ( keyValue . Key , keyValue . Key , OrganizerSettingsData . DataEditTypes . STRING ) ;
if ( ActiveSliceSettings . Instance . ActiveSliceEngine ( ) . MapContains ( settingData . SlicerConfigName ) )
2015-10-13 13:40:35 -07:00
{
2016-06-06 12:06:08 -07:00
bool addControl ;
2016-06-08 17:59:03 -07:00
GuiWidget controlsForThisSetting = CreateSettingInfoUIControls ( settingData , layerCascade , persistenceLayer , viewFilter , 0 , out addControl , ref tabIndexForItem ) ;
2016-06-06 12:06:08 -07:00
if ( addControl )
{
topToBottomSettings . AddChild ( controlsForThisSetting ) ;
}
2015-10-13 13:40:35 -07:00
count + + ;
}
2015-04-08 15:20:10 -07:00
}
}
2016-04-22 17:30:34 -07:00
AltGroupBox groupBox = new AltGroupBox ( "Extra" . Localize ( ) ) ;
2015-04-08 15:20:10 -07: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 ) ;
SliceSettingListControl scrollOnGroupTab = new SliceSettingListControl ( ) ;
scrollOnGroupTab . AnchorAll ( ) ;
scrollOnGroupTab . AddChild ( subGroupLayoutTopToBottom ) ;
groupTabPage . AddChild ( scrollOnGroupTab ) ;
}
2016-05-12 18:42:19 -07:00
return leftSideGroupTabs ;
2015-04-08 15:20:10 -07:00
}
2016-06-08 17:59:03 -07:00
private static GuiWidget GetExtraSettingsWidget ( OrganizerSettingsData settingData )
2015-04-08 15:20:10 -07:00
{
2016-04-28 12:48:56 -07:00
var nameHolder = new GuiWidget ( HAnchor . ParentLeftRight , VAnchor . FitToChildren | VAnchor . ParentCenter )
{
Padding = new BorderDouble ( 5 , 0 ) ,
HAnchor = HAnchor . ParentLeftRight ,
} ;
nameHolder . AddChild ( new WrappedTextWidget ( settingData . ExtraSettings . Localize ( ) , 0 , pointSize : 8 , textColor : ActiveTheme . Instance . PrimaryTextColor ) ) ;
return nameHolder ;
2015-04-08 15:20:10 -07:00
}
2016-04-26 17:15:10 -07:00
public static RootedObjectEventHandler SettingChanged = new RootedObjectEventHandler ( ) ;
2015-04-08 15:20:10 -07:00
2016-06-08 17:59:03 -07:00
static private void OnSettingsChanged ( OrganizerSettingsData settingData )
2015-04-08 15:20:10 -07:00
{
2016-06-08 17:59:03 -07:00
SettingChanged . CallEvents ( null , new StringEventArgs ( settingData . SlicerConfigName ) ) ;
2015-04-08 15:20:10 -07:00
if ( settingToReloadUiWhenChanged . Contains ( settingData . SlicerConfigName ) )
{
ApplicationController . Instance . ReloadAll ( null , null ) ;
}
}
2016-04-18 11:31:31 -07:00
private class SettingsRow : FlowLayoutWidget
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
public string SettingsKey { get ; set ; }
public string SettingsValue { get ; set ; }
2016-06-09 14:53:20 -07:00
private event EventHandler unregisterEvents ;
2015-04-08 15:20:10 -07:00
2016-05-06 18:50:38 -07:00
/// <summary>
/// Gets or sets the delegate to be invoked when the settings values need to be refreshed. The implementation should
/// take the passed in text value and update its editor to reflect the latest value
/// </summary>
2016-04-18 11:31:31 -07:00
public Action < string > ValueChanged { get ; set ; }
public Action UpdateStyle { get ; set ; }
2016-04-04 14:25:54 -07:00
2016-06-09 14:53:20 -07:00
public SettingsRow ( IEnumerable < SettingsLayer > layerCascade )
2016-04-18 11:31:31 -07:00
{
Margin = new BorderDouble ( 0 , 2 ) ;
Padding = new BorderDouble ( 3 ) ;
HAnchor = Agg . UI . HAnchor . ParentLeftRight ;
2016-06-09 14:53:20 -07:00
SettingChanged . RegisterEvent ( ( s , e ) = >
{
if ( ( ( StringEventArgs ) e ) . Data = = SettingsKey )
{
string setting = ActiveSliceSettings . Instance . GetActiveValue ( SettingsKey , layerCascade ) ;
if ( SettingsValue ! = setting )
{
SettingsValue = setting ;
ValueChanged ? . Invoke ( setting ) ;
}
UpdateStyle ? . Invoke ( ) ;
}
} , ref unregisterEvents ) ;
}
public override void OnClosed ( EventArgs e )
{
unregisterEvents ? . Invoke ( this , null ) ;
base . OnClosed ( e ) ;
2016-04-18 11:31:31 -07:00
}
2016-05-16 16:21:42 -07:00
public void RefreshValue ( IEnumerable < SettingsLayer > layerFilters )
2016-04-18 11:31:31 -07:00
{
2016-05-16 16:21:42 -07:00
string latestValue = GetActiveValue ( this . SettingsKey , layerFilters ) ;
2016-04-18 11:31:31 -07:00
//if(latestValue != SettingsValue)
{
ValueChanged ? . Invoke ( latestValue ) ;
}
UpdateStyle ? . Invoke ( ) ;
SettingsValue = latestValue ;
}
}
private static readonly RGBA_Bytes materialSettingBackgroundColor = new RGBA_Bytes ( 255 , 127 , 0 , 108 ) ;
private static readonly RGBA_Bytes userSettingBackgroundColor = new RGBA_Bytes ( 68 , 95 , 220 , 108 ) ;
private static readonly RGBA_Bytes qualitySettingBackgroundColor = new RGBA_Bytes ( 255 , 255 , 0 , 108 ) ;
2016-05-16 16:21:42 -07:00
private static string GetActiveValue ( string slicerConfigName , IEnumerable < SettingsLayer > layerCascade )
{
return ActiveSliceSettings . Instance . GetActiveValue ( slicerConfigName , layerCascade ) ;
}
2016-06-08 17:59:03 -07:00
public static GuiWidget CreateSettingControl ( string sliceSettingsKey , ref int tabIndex )
{
bool addControl ;
GuiWidget settingsRow = CreateSettingInfoUIControls (
SliceSettingsOrganizer . Instance . GetSettingsData ( sliceSettingsKey ) ,
null ,
ActiveSliceSettings . Instance . UserLayer ,
NamedSettingsLayers . All ,
0 ,
out addControl ,
ref tabIndex
) ;
if ( addControl )
{
return settingsRow ;
}
return null ;
}
private static GuiWidget CreateSettingInfoUIControls ( OrganizerSettingsData settingData , List < SettingsLayer > layerCascade , SettingsLayer persistenceLayer ,
NamedSettingsLayers viewFilter ,
int extruderIndex , out bool addControl , ref int tabIndexForItem )
2016-04-18 11:31:31 -07:00
{
2016-06-06 12:06:08 -07:00
addControl = true ;
2016-04-18 11:31:31 -07:00
GuiWidget container = new GuiWidget ( ) ;
2016-04-04 14:25:54 -07:00
2016-05-16 16:21:42 -07:00
string sliceSettingValue = GetActiveValue ( settingData . SlicerConfigName , layerCascade ) ;
2016-04-26 17:15:10 -07:00
2016-04-28 12:48:56 -07:00
GuiWidget nameArea = new GuiWidget ( HAnchor . ParentLeftRight , VAnchor . FitToChildren | VAnchor . ParentCenter ) ;
var dataArea = new FlowLayoutWidget ( ) ;
GuiWidget unitsArea = new GuiWidget ( HAnchor . AbsolutePosition , VAnchor . FitToChildren | VAnchor . ParentCenter )
{
2016-05-06 17:56:27 -07:00
Width = 50 * GuiWidget . DeviceScale ,
2016-04-28 12:48:56 -07:00
} ;
GuiWidget restoreArea = new GuiWidget ( HAnchor . AbsolutePosition , VAnchor . FitToChildren | VAnchor . ParentCenter )
{
2016-05-06 17:56:27 -07:00
Width = 30 * GuiWidget . DeviceScale ,
2016-04-28 12:48:56 -07:00
} ;
2016-05-07 21:05:53 -07:00
2016-06-09 14:53:20 -07:00
var settingsRow = new SettingsRow ( layerCascade )
2016-04-18 11:31:31 -07:00
{
SettingsKey = settingData . SlicerConfigName ,
2016-04-28 12:48:56 -07:00
SettingsValue = sliceSettingValue ,
2016-04-18 11:31:31 -07:00
} ;
2016-05-07 21:05:53 -07:00
settingsRow . AddChild ( nameArea ) ;
settingsRow . AddChild ( dataArea ) ;
settingsRow . AddChild ( unitsArea ) ;
settingsRow . AddChild ( restoreArea ) ;
2016-05-29 09:19:46 -07:00
settingsRow . Name = settingData . SlicerConfigName + " Edit Field" ;
2016-04-18 11:31:31 -07:00
2016-04-30 18:18:15 -07:00
if ( ! ActiveSliceSettings . Instance . KnownSettings . Contains ( settingData . SlicerConfigName ) )
2016-04-18 11:31:31 -07:00
{
// the setting we think we are adding is not in the config.ini it may have been deprecated
TextWidget settingName = new TextWidget ( String . Format ( "Setting '{0}' not found in config.ini" , settingData . SlicerConfigName ) ) ;
settingName . TextColor = ActiveTheme . Instance . PrimaryTextColor ;
2016-04-28 12:48:56 -07:00
//settingName.MinimumSize = new Vector2(minSettingNameWidth, settingName.MinimumSize.y);
nameArea . AddChild ( settingName ) ;
nameArea . BackgroundColor = RGBA_Bytes . Red ;
2016-04-18 11:31:31 -07:00
}
else
2015-04-08 15:20:10 -07:00
{
2016-05-06 17:56:27 -07:00
int intEditWidth = ( int ) ( 60 * GuiWidget . DeviceScale + . 5 ) ;
int doubleEditWidth = ( int ) ( 60 * GuiWidget . DeviceScale + . 5 ) ;
int vectorXYEditWidth = ( int ) ( 60 * GuiWidget . DeviceScale + . 5 ) ;
int multiLineEditHeight = ( int ) ( 120 * GuiWidget . DeviceScale + . 5 ) ;
2015-04-08 15:20:10 -07:00
if ( settingData . DataEditType ! = OrganizerSettingsData . DataEditTypes . MULTI_LINE_TEXT )
{
2016-04-28 12:48:56 -07:00
var nameHolder = new GuiWidget ( HAnchor . ParentLeftRight , VAnchor . FitToChildren | VAnchor . ParentCenter )
2016-04-22 17:30:34 -07:00
{
Padding = new BorderDouble ( 0 , 0 , 5 , 0 ) ,
2016-04-28 12:48:56 -07:00
HAnchor = HAnchor . ParentLeftRight ,
2016-04-22 17:30:34 -07:00
} ;
2016-04-28 12:48:56 -07:00
nameHolder . AddChild ( new WrappedTextWidget ( settingData . PresentationName . Localize ( ) , 0 , pointSize : 10 , textColor : ActiveTheme . Instance . PrimaryTextColor ) ) ;
2016-04-22 17:30:34 -07:00
2016-04-28 12:48:56 -07:00
nameArea . AddChild ( nameHolder ) ;
2015-05-20 12:43:01 -07:00
}
2015-04-08 15:20:10 -07:00
switch ( settingData . DataEditType )
{
case OrganizerSettingsData . DataEditTypes . INT :
{
2016-05-12 18:42:19 -07:00
FlowLayoutWidget content = new FlowLayoutWidget ( ) ;
2016-04-18 11:31:31 -07:00
int currentValue ;
2015-04-08 15:20:10 -07:00
int . TryParse ( sliceSettingValue , out currentValue ) ;
2016-04-18 11:31:31 -07:00
var intEditWidget = new MHNumberEdit ( currentValue , pixelWidth : intEditWidth , tabIndex : tabIndexForItem + + )
2016-04-26 17:15:10 -07:00
{
2016-04-18 11:31:31 -07:00
ToolTipText = settingData . HelpText ,
2016-05-13 14:23:33 -07:00
SelectAllOnFocus = true ,
Name = settingData . PresentationName + " Edit" ,
2016-04-26 17:15:10 -07:00
} ;
2016-04-21 18:02:02 -07:00
intEditWidget . ActuallNumberEdit . EditComplete + = ( sender , e ) = >
2015-04-08 15:20:10 -07:00
{
2016-06-08 17:59:03 -07:00
SaveSetting ( settingData . SlicerConfigName , ( ( NumberEdit ) sender ) . Value . ToString ( ) , persistenceLayer ) ;
2016-05-07 21:05:53 -07:00
settingsRow . UpdateStyle ( ) ;
2016-04-18 11:31:31 -07:00
OnSettingsChanged ( settingData ) ;
2015-04-08 15:20:10 -07:00
} ;
2016-05-12 18:42:19 -07:00
content . AddChild ( intEditWidget ) ;
2016-04-28 12:48:56 -07:00
unitsArea . AddChild ( GetExtraSettingsWidget ( settingData ) ) ;
2016-04-18 11:31:31 -07:00
2016-05-12 18:42:19 -07:00
if ( settingData . QuickMenuSettings . Count > 0 )
{
2016-06-08 17:59:03 -07:00
dataArea . AddChild ( CreateQuickMenu ( settingData , persistenceLayer , content , intEditWidget . ActuallNumberEdit . InternalTextEditWidget , layerCascade ) ) ;
2016-05-12 18:42:19 -07:00
}
else
{
dataArea . AddChild ( content ) ;
}
2016-05-12 10:57:41 -07:00
settingsRow . ValueChanged = ( text ) = >
{
intEditWidget . Text = text ;
OnSettingsChanged ( settingData ) ;
} ;
2015-04-08 15:20:10 -07:00
}
break ;
case OrganizerSettingsData . DataEditTypes . DOUBLE :
{
2016-04-18 11:31:31 -07:00
double currentValue ;
2015-04-08 15:20:10 -07:00
double . TryParse ( sliceSettingValue , out currentValue ) ;
2016-04-18 11:31:31 -07:00
var doubleEditWidget = new MHNumberEdit ( currentValue , allowNegatives : true , allowDecimals : true , pixelWidth : doubleEditWidth , tabIndex : tabIndexForItem + + )
2016-04-26 17:15:10 -07:00
{
2016-04-18 11:31:31 -07:00
ToolTipText = settingData . HelpText ,
SelectAllOnFocus = true
2016-04-26 17:15:10 -07:00
} ;
2015-04-08 15:20:10 -07:00
doubleEditWidget . ActuallNumberEdit . EditComplete + = ( sender , e ) = >
{
2016-06-08 17:59:03 -07:00
SaveSetting ( settingData . SlicerConfigName , ( ( NumberEdit ) sender ) . Value . ToString ( ) , persistenceLayer ) ;
2016-05-07 21:05:53 -07:00
settingsRow . UpdateStyle ( ) ;
2016-04-18 11:31:31 -07:00
OnSettingsChanged ( settingData ) ;
} ;
2016-04-28 12:48:56 -07:00
dataArea . AddChild ( doubleEditWidget ) ;
unitsArea . AddChild ( GetExtraSettingsWidget ( settingData ) ) ;
2016-04-18 11:31:31 -07:00
2016-05-07 21:05:53 -07:00
settingsRow . ValueChanged = ( text ) = >
2016-04-18 11:31:31 -07:00
{
double currentValue2 = 0 ;
double . TryParse ( text , out currentValue2 ) ;
doubleEditWidget . ActuallNumberEdit . Value = currentValue2 ;
2016-05-12 10:57:41 -07:00
OnSettingsChanged ( settingData ) ;
2015-04-08 15:20:10 -07:00
} ;
}
break ;
case OrganizerSettingsData . DataEditTypes . POSITIVE_DOUBLE :
{
2015-05-02 10:50:14 -07:00
const string multiValuesAreDiffernt = "-" ;
2015-04-08 15:20:10 -07:00
FlowLayoutWidget content = new FlowLayoutWidget ( ) ;
2016-04-18 11:31:31 -07:00
var doubleEditWidget = new MHNumberEdit ( 0 , allowDecimals : true , pixelWidth : doubleEditWidth , tabIndex : tabIndexForItem + + )
{
ToolTipText = settingData . HelpText ,
Name = settingData . PresentationName + " Textbox" ,
SelectAllOnFocus = true
} ;
2015-05-01 18:44:43 -07:00
2016-04-18 11:31:31 -07:00
double currentValue ;
2015-05-02 10:50:14 -07:00
bool ChangesMultipleOtherSettings = settingData . SetSettingsOnChange . Count > 0 ;
if ( ChangesMultipleOtherSettings )
2015-05-01 18:44:43 -07:00
{
bool allTheSame = true ;
2016-05-16 16:21:42 -07:00
string setting = GetActiveValue ( settingData . SetSettingsOnChange [ 0 ] , layerCascade ) ;
2015-05-01 18:44:43 -07:00
for ( int i = 1 ; i < settingData . SetSettingsOnChange . Count ; i + + )
{
2016-05-16 16:21:42 -07:00
string nextSetting = GetActiveValue ( settingData . SetSettingsOnChange [ i ] , layerCascade ) ;
2015-05-01 18:44:43 -07:00
if ( setting ! = nextSetting )
{
allTheSame = false ;
break ;
}
}
if ( allTheSame & & setting . EndsWith ( "mm" ) )
{
2016-04-21 17:24:56 -07:00
double . TryParse ( setting . Substring ( 0 , setting . Length - 2 ) , out currentValue ) ;
2015-05-01 18:44:43 -07:00
doubleEditWidget . ActuallNumberEdit . Value = currentValue ;
}
else
{
2015-05-02 10:50:14 -07:00
doubleEditWidget . ActuallNumberEdit . InternalNumberEdit . Text = multiValuesAreDiffernt ;
2015-05-01 18:44:43 -07:00
}
}
2016-04-22 13:19:26 -07:00
else // just set the setting normally
2015-05-01 18:44:43 -07:00
{
double . TryParse ( sliceSettingValue , out currentValue ) ;
doubleEditWidget . ActuallNumberEdit . Value = currentValue ;
}
doubleEditWidget . ActuallNumberEdit . InternalTextEditWidget . MarkAsStartingState ( ) ;
2016-04-18 11:31:31 -07:00
2016-04-21 18:02:02 -07:00
doubleEditWidget . ActuallNumberEdit . EditComplete + = ( sender , e ) = >
2015-04-08 15:20:10 -07:00
{
2015-05-01 18:44:43 -07:00
NumberEdit numberEdit = ( NumberEdit ) sender ;
// If this setting sets other settings, then do that.
2015-05-02 10:50:14 -07:00
if ( ChangesMultipleOtherSettings
& & numberEdit . Text ! = multiValuesAreDiffernt )
2015-05-01 18:44:43 -07:00
{
foreach ( string setting in settingData . SetSettingsOnChange )
{
2016-06-08 17:59:03 -07:00
SaveSetting ( setting , numberEdit . Value . ToString ( ) + "mm" , persistenceLayer ) ;
2015-05-01 18:44:43 -07:00
}
}
2016-04-04 14:25:54 -07:00
2015-05-02 10:50:14 -07:00
// also always save to the local setting
2016-06-08 17:59:03 -07:00
SaveSetting ( settingData . SlicerConfigName , numberEdit . Value . ToString ( ) , persistenceLayer ) ;
2016-05-07 21:05:53 -07:00
settingsRow . UpdateStyle ( ) ;
2016-04-18 11:31:31 -07:00
OnSettingsChanged ( settingData ) ;
2015-04-08 15:20:10 -07:00
} ;
content . AddChild ( doubleEditWidget ) ;
2016-04-28 12:48:56 -07:00
unitsArea . AddChild ( GetExtraSettingsWidget ( settingData ) ) ;
2015-04-08 15:20:10 -07:00
if ( settingData . QuickMenuSettings . Count > 0 )
{
2016-06-08 17:59:03 -07:00
dataArea . AddChild ( CreateQuickMenu ( settingData , persistenceLayer , content , doubleEditWidget . ActuallNumberEdit . InternalTextEditWidget , layerCascade ) ) ;
2015-04-08 15:20:10 -07:00
}
else
{
2016-04-28 12:48:56 -07:00
dataArea . AddChild ( content ) ;
2015-04-08 15:20:10 -07:00
}
2016-04-18 11:31:31 -07:00
2016-05-07 21:05:53 -07:00
settingsRow . ValueChanged = ( text ) = >
2016-04-18 11:31:31 -07:00
{
double currentValue2 = 0 ;
double . TryParse ( text , out currentValue2 ) ;
doubleEditWidget . ActuallNumberEdit . Value = currentValue2 ;
2016-05-12 10:57:41 -07:00
OnSettingsChanged ( settingData ) ;
2016-04-18 11:31:31 -07:00
} ;
2015-04-08 15:20:10 -07:00
}
break ;
case OrganizerSettingsData . DataEditTypes . OFFSET :
{
2016-04-18 11:31:31 -07:00
double currentValue ;
2015-04-08 15:20:10 -07:00
double . TryParse ( sliceSettingValue , out currentValue ) ;
2016-04-18 11:31:31 -07:00
var doubleEditWidget = new MHNumberEdit ( currentValue , allowDecimals : true , allowNegatives : true , pixelWidth : doubleEditWidth , tabIndex : tabIndexForItem + + )
2016-04-26 17:15:10 -07:00
{
2016-04-18 11:31:31 -07:00
ToolTipText = settingData . HelpText ,
SelectAllOnFocus = true
2016-04-26 17:15:10 -07:00
} ;
2016-04-21 18:02:02 -07:00
doubleEditWidget . ActuallNumberEdit . EditComplete + = ( sender , e ) = >
2016-04-18 11:31:31 -07:00
{
2016-06-08 17:59:03 -07:00
SaveSetting ( settingData . SlicerConfigName , ( ( NumberEdit ) sender ) . Value . ToString ( ) , persistenceLayer ) ;
2016-05-07 21:05:53 -07:00
settingsRow . UpdateStyle ( ) ;
2016-04-18 11:31:31 -07:00
OnSettingsChanged ( settingData ) ;
} ;
2016-04-28 12:48:56 -07:00
dataArea . AddChild ( doubleEditWidget ) ;
unitsArea . AddChild ( GetExtraSettingsWidget ( settingData ) ) ;
2016-04-18 11:31:31 -07:00
2016-05-07 21:05:53 -07:00
settingsRow . ValueChanged = ( text ) = >
2016-04-18 11:31:31 -07:00
{
double currentValue2 ;
double . TryParse ( text , out currentValue2 ) ;
doubleEditWidget . ActuallNumberEdit . Value = currentValue2 ;
2016-05-12 10:57:41 -07:00
OnSettingsChanged ( settingData ) ;
2016-04-18 11:31:31 -07:00
} ;
2015-04-08 15:20:10 -07:00
}
break ;
case OrganizerSettingsData . DataEditTypes . DOUBLE_OR_PERCENT :
{
FlowLayoutWidget content = new FlowLayoutWidget ( ) ;
2016-04-18 11:31:31 -07:00
var stringEdit = new MHTextEditWidget ( sliceSettingValue , pixelWidth : doubleEditWidth - 2 , tabIndex : tabIndexForItem + + )
2016-04-26 17:15:10 -07:00
{
2016-04-18 11:31:31 -07:00
ToolTipText = settingData . HelpText ,
SelectAllOnFocus = true
2016-04-26 17:15:10 -07:00
} ;
2016-04-21 18:02:02 -07:00
stringEdit . ActualTextEditWidget . EditComplete + = ( sender , e ) = >
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
var textEditWidget = ( TextEditWidget ) sender ;
string text = textEditWidget . Text . Trim ( ) ;
2015-04-08 15:20:10 -07:00
bool isPercent = text . Contains ( "%" ) ;
if ( isPercent )
{
text = text . Substring ( 0 , text . IndexOf ( "%" ) ) ;
}
double result ;
double . TryParse ( text , out result ) ;
text = result . ToString ( ) ;
if ( isPercent )
{
text + = "%" ;
}
textEditWidget . Text = text ;
2016-06-08 17:59:03 -07:00
SaveSetting ( settingData . SlicerConfigName , textEditWidget . Text , persistenceLayer ) ;
2016-05-07 21:05:53 -07:00
settingsRow . UpdateStyle ( ) ;
2016-04-18 11:31:31 -07:00
OnSettingsChanged ( settingData ) ;
2015-04-08 15:20:10 -07:00
} ;
2015-04-24 13:09:25 -07:00
stringEdit . ActualTextEditWidget . InternalTextEditWidget . AllSelected + = ( sender , e ) = >
{
2016-04-22 13:19:26 -07:00
// select everything up to the % (if present)
2015-04-24 13:09:25 -07:00
InternalTextEditWidget textEditWidget = ( InternalTextEditWidget ) sender ;
int percentIndex = textEditWidget . Text . IndexOf ( "%" ) ;
if ( percentIndex ! = - 1 )
{
2016-04-21 17:24:56 -07:00
textEditWidget . SetSelection ( 0 , percentIndex - 1 ) ;
2015-04-24 13:09:25 -07:00
}
} ;
2016-04-21 17:24:56 -07:00
2015-04-24 13:09:25 -07:00
content . AddChild ( stringEdit ) ;
2016-04-28 12:48:56 -07:00
unitsArea . AddChild ( GetExtraSettingsWidget ( settingData ) ) ;
2015-04-24 13:09:25 -07:00
if ( settingData . QuickMenuSettings . Count > 0 )
{
2016-06-08 17:59:03 -07:00
dataArea . AddChild ( CreateQuickMenu ( settingData , persistenceLayer , content , stringEdit . ActualTextEditWidget . InternalTextEditWidget , layerCascade ) ) ;
2015-04-24 13:09:25 -07:00
}
else
{
2016-04-28 12:48:56 -07:00
dataArea . AddChild ( content ) ;
2015-04-24 13:09:25 -07:00
}
2016-04-18 11:31:31 -07:00
2016-05-12 10:57:41 -07:00
settingsRow . ValueChanged = ( text ) = >
{
stringEdit . Text = text ;
OnSettingsChanged ( settingData ) ;
} ;
2015-04-24 13:09:25 -07:00
}
break ;
case OrganizerSettingsData . DataEditTypes . INT_OR_MM :
{
FlowLayoutWidget content = new FlowLayoutWidget ( ) ;
2016-04-18 11:31:31 -07:00
var stringEdit = new MHTextEditWidget ( sliceSettingValue , pixelWidth : doubleEditWidth - 2 , tabIndex : tabIndexForItem + + )
2016-04-26 17:15:10 -07:00
{
2016-04-18 11:31:31 -07:00
ToolTipText = settingData . HelpText ,
SelectAllOnFocus = true
2016-04-26 17:15:10 -07:00
} ;
2016-04-18 11:31:31 -07:00
2015-10-19 18:32:23 -07:00
string startingText = stringEdit . Text ;
2016-04-21 18:02:02 -07:00
stringEdit . ActualTextEditWidget . EditComplete + = ( sender , e ) = >
2015-04-24 13:09:25 -07:00
{
TextEditWidget textEditWidget = ( TextEditWidget ) sender ;
2015-10-19 18:32:23 -07:00
// only validate when we lose focus
if ( ! textEditWidget . ContainsFocus )
2015-04-24 13:09:25 -07:00
{
2015-10-19 18:32:23 -07:00
string text = textEditWidget . Text ;
text = text . Trim ( ) ;
bool isMm = text . Contains ( "mm" ) ;
if ( isMm )
{
text = text . Substring ( 0 , text . IndexOf ( "mm" ) ) ;
}
double result ;
double . TryParse ( text , out result ) ;
2015-04-24 13:09:25 -07:00
text = result . ToString ( ) ;
2015-10-19 18:32:23 -07:00
if ( isMm )
{
text + = "mm" ;
}
else
{
result = ( int ) result ;
text = result . ToString ( ) ;
}
textEditWidget . Text = text ;
startingText = stringEdit . Text ;
2015-04-24 13:09:25 -07:00
}
2016-06-08 17:59:03 -07:00
SaveSetting ( settingData . SlicerConfigName , textEditWidget . Text , persistenceLayer ) ;
2016-05-07 21:05:53 -07:00
settingsRow . UpdateStyle ( ) ;
2016-04-18 11:31:31 -07:00
OnSettingsChanged ( settingData ) ;
2015-10-19 18:32:23 -07:00
// make sure we are still looking for the final validation before saving.
if ( textEditWidget . ContainsFocus )
{
UiThread . RunOnIdle ( ( ) = >
{
string currentText = textEditWidget . Text ;
int cursorIndex = textEditWidget . InternalTextEditWidget . CharIndexToInsertBefore ;
textEditWidget . Text = startingText ;
textEditWidget . InternalTextEditWidget . MarkAsStartingState ( ) ;
textEditWidget . Text = currentText ;
textEditWidget . InternalTextEditWidget . CharIndexToInsertBefore = cursorIndex ;
} ) ;
}
2015-04-24 13:09:25 -07:00
} ;
stringEdit . ActualTextEditWidget . InternalTextEditWidget . AllSelected + = ( sender , e ) = >
{
2016-04-22 13:19:26 -07:00
// select everything up to the mm (if present)
2015-04-24 13:09:25 -07:00
InternalTextEditWidget textEditWidget = ( InternalTextEditWidget ) sender ;
int mMIndex = textEditWidget . Text . IndexOf ( "mm" ) ;
if ( mMIndex ! = - 1 )
{
2016-04-21 17:24:56 -07:00
textEditWidget . SetSelection ( 0 , mMIndex - 1 ) ;
2015-04-24 13:09:25 -07:00
}
} ;
2015-04-08 15:20:10 -07:00
content . AddChild ( stringEdit ) ;
2016-04-28 12:48:56 -07:00
unitsArea . AddChild ( GetExtraSettingsWidget ( settingData ) ) ;
2015-04-08 15:20:10 -07:00
if ( settingData . QuickMenuSettings . Count > 0 )
{
2016-06-08 17:59:03 -07:00
dataArea . AddChild ( CreateQuickMenu ( settingData , persistenceLayer , content , stringEdit . ActualTextEditWidget . InternalTextEditWidget , layerCascade ) ) ;
2015-04-08 15:20:10 -07:00
}
else
{
2016-04-28 12:48:56 -07:00
dataArea . AddChild ( content ) ;
2015-04-08 15:20:10 -07:00
}
2016-04-18 11:31:31 -07:00
2016-05-12 10:57:41 -07:00
settingsRow . ValueChanged = ( text ) = >
{
stringEdit . Text = text ;
OnSettingsChanged ( settingData ) ;
} ;
2015-04-08 15:20:10 -07:00
}
break ;
case OrganizerSettingsData . DataEditTypes . CHECK_BOX :
{
2016-04-18 11:31:31 -07:00
var checkBoxWidget = new CheckBox ( "" )
2016-04-26 17:15:10 -07:00
{
2016-04-18 11:31:31 -07:00
Name = settingData . PresentationName + " Checkbox" ,
ToolTipText = settingData . HelpText ,
VAnchor = Agg . UI . VAnchor . ParentBottom ,
TextColor = ActiveTheme . Instance . PrimaryTextColor ,
Checked = sliceSettingValue = = "1"
2016-04-26 17:15:10 -07:00
} ;
2016-05-02 10:27:20 -07:00
checkBoxWidget . Click + = ( sender , e ) = >
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
bool isChecked = ( ( CheckBox ) sender ) . Checked ;
2016-06-08 17:59:03 -07:00
SaveSetting ( settingData . SlicerConfigName , isChecked ? "1" : "0" , persistenceLayer ) ;
2016-05-07 21:05:53 -07:00
settingsRow . UpdateStyle ( ) ;
2016-04-26 17:15:10 -07:00
2016-04-18 11:31:31 -07:00
OnSettingsChanged ( settingData ) ;
2015-04-08 15:20:10 -07:00
} ;
2016-04-01 17:01:07 -07:00
2016-04-28 12:48:56 -07:00
dataArea . AddChild ( checkBoxWidget ) ;
2016-04-18 11:31:31 -07:00
2016-05-12 10:57:41 -07:00
settingsRow . ValueChanged = ( text ) = >
{
checkBoxWidget . Checked = text = = "1" ;
OnSettingsChanged ( settingData ) ;
} ;
2015-04-08 15:20:10 -07:00
}
break ;
case OrganizerSettingsData . DataEditTypes . STRING :
{
2016-05-13 14:23:33 -07:00
var stringEdit = new MHTextEditWidget ( sliceSettingValue , pixelWidth : 120 , tabIndex : tabIndexForItem + + )
{
Name = settingData . PresentationName + " Edit" ,
} ;
2015-08-10 10:59:45 -07:00
stringEdit . ToolTipText = settingData . HelpText ;
2016-05-13 14:23:33 -07:00
2016-04-21 18:02:02 -07:00
stringEdit . ActualTextEditWidget . EditComplete + = ( sender , e ) = >
2015-04-08 15:20:10 -07:00
{
2016-06-08 17:59:03 -07:00
SaveSetting ( settingData . SlicerConfigName , ( ( TextEditWidget ) sender ) . Text , persistenceLayer ) ;
2016-05-07 21:05:53 -07:00
settingsRow . UpdateStyle ( ) ;
2016-04-26 17:15:10 -07:00
2016-04-18 11:31:31 -07:00
OnSettingsChanged ( settingData ) ;
2015-04-08 15:20:10 -07:00
} ;
2016-04-01 17:01:07 -07:00
2016-04-28 12:48:56 -07:00
dataArea . AddChild ( stringEdit ) ;
2016-04-18 11:31:31 -07:00
2016-05-12 10:57:41 -07:00
settingsRow . ValueChanged = ( text ) = >
{
stringEdit . Text = text ;
OnSettingsChanged ( settingData ) ;
} ;
2015-04-08 15:20:10 -07:00
}
break ;
case OrganizerSettingsData . DataEditTypes . MULTI_LINE_TEXT :
{
string convertedNewLines = sliceSettingValue . Replace ( "\\n" , "\n" ) ;
2016-04-28 12:48:56 -07:00
var stringEdit = new MHTextEditWidget ( convertedNewLines , pixelWidth : 320 , pixelHeight : multiLineEditHeight , multiLine : true , tabIndex : tabIndexForItem + + )
{
HAnchor = HAnchor . ParentLeftRight ,
} ;
2016-04-18 11:31:31 -07:00
2015-04-08 15:20:10 -07:00
stringEdit . ActualTextEditWidget . EditComplete + = ( sender , e ) = >
{
2016-06-08 17:59:03 -07:00
SaveSetting ( settingData . SlicerConfigName , ( ( TextEditWidget ) sender ) . Text . Replace ( "\n" , "\\n" ) , persistenceLayer ) ;
2016-05-07 21:05:53 -07:00
settingsRow . UpdateStyle ( ) ;
2016-04-26 17:15:10 -07:00
2016-04-18 11:31:31 -07:00
OnSettingsChanged ( settingData ) ;
2015-04-08 15:20:10 -07:00
} ;
2016-04-01 17:01:07 -07:00
2016-04-28 12:48:56 -07:00
nameArea . HAnchor = HAnchor . AbsolutePosition ;
nameArea . Width = 0 ;
dataArea . AddChild ( stringEdit ) ;
dataArea . HAnchor = HAnchor . ParentLeftRight ;
2016-04-18 11:31:31 -07:00
2016-05-12 10:57:41 -07:00
settingsRow . ValueChanged = ( text ) = >
{
stringEdit . Text = text . Replace ( "\\n" , "\n" ) ;
OnSettingsChanged ( settingData ) ;
} ;
2015-04-08 15:20:10 -07:00
}
break ;
2016-05-02 16:10:20 -07:00
case OrganizerSettingsData . DataEditTypes . COM_PORT :
{
2016-06-06 12:06:08 -07:00
#if __ANDROID__
addControl = false ;
#endif
2016-05-06 18:50:38 -07:00
// The COM_PORT control is unique in its approach to the SlicerConfigName. It uses "MatterControl.ComPort" settings name to
// bind to a context that will place it in the SliceSetting view but it binds its values to a machine
// specific dictionary key that is not exposed in the UI. At runtime we lookup and store to "MatterControl.<machine>.ComPort"
// ensuring that a single printer can be shared across different devices and we'll select the correct ComPort in each case
2016-06-03 18:11:51 -07:00
var selectableOptions = new DropDownList ( "None" , maxHeight : 200 )
2016-05-02 16:10:20 -07:00
{
ToolTipText = settingData . HelpText ,
Margin = new BorderDouble ( )
} ;
2016-05-09 18:07:35 -07:00
selectableOptions . Click + = ( s , e ) = >
2016-05-02 16:10:20 -07:00
{
2016-06-08 17:59:03 -07:00
AddComMenuItems ( settingData , persistenceLayer , settingsRow , selectableOptions ) ;
2016-05-09 18:07:35 -07:00
} ;
2016-05-02 16:10:20 -07:00
2016-06-08 17:59:03 -07:00
AddComMenuItems ( settingData , persistenceLayer , settingsRow , selectableOptions ) ;
2016-05-02 16:10:20 -07:00
dataArea . AddChild ( selectableOptions ) ;
2016-05-07 21:05:53 -07:00
settingsRow . ValueChanged = ( text ) = >
2016-05-06 18:50:38 -07:00
{
// Lookup the machine specific comport value rather than the passed in text value
selectableOptions . SelectedLabel = ActiveSliceSettings . Instance . ComPort ( ) ;
2016-05-12 10:57:41 -07:00
OnSettingsChanged ( settingData ) ;
2016-05-06 18:50:38 -07:00
} ;
2016-05-02 16:10:20 -07:00
}
break ;
2016-05-17 15:50:43 -07:00
case OrganizerSettingsData . DataEditTypes . DELETE_PRINTER :
{
// This is a place holder type to allow us to put in the control that will allow the deletion of a printer profile
TextImageButtonFactory buttonFactory = new TextImageButtonFactory ( ) ;
buttonFactory . normalTextColor = RGBA_Bytes . Red ;
var button = buttonFactory . Generate ( "Delete Printer" . Localize ( ) ) ;
button . Click + = ( s , e ) = >
{
StyledMessageBox . ShowMessageBox ( ( doDelete ) = >
{
if ( doDelete )
{
2016-05-17 18:27:08 -07:00
SettingsProfile activePrinter = ActiveSliceSettings . Instance ;
string printerID = activePrinter . ID ;
var printerInfo = ActiveSliceSettings . ProfileData . Profiles . Where ( profile = > profile . Id = = printerID ) . FirstOrDefault ( ) ;
if ( printerInfo ! = null )
{
ActiveSliceSettings . ProfileData . Profiles . Remove ( printerInfo ) ;
}
2016-05-17 15:50:43 -07:00
}
} , "Are you sure you want to delete your currently selected printer?" . Localize ( ) , "Delete Printer?" . Localize ( ) , StyledMessageBox . MessageType . YES_NO , "Delete Printer" . Localize ( ) ) ;
} ;
dataArea . AddChild ( button ) ;
}
break ;
2015-04-08 15:20:10 -07:00
case OrganizerSettingsData . DataEditTypes . LIST :
{
2016-06-03 18:11:51 -07:00
var selectableOptions = new DropDownList ( "None" , maxHeight : 200 )
2016-04-26 17:15:10 -07:00
{
2016-04-18 11:31:31 -07:00
ToolTipText = settingData . HelpText ,
Margin = new BorderDouble ( )
2016-04-26 17:15:10 -07:00
} ;
2015-04-08 15:20:10 -07:00
2016-04-18 11:31:31 -07:00
foreach ( string listItem in settingData . ExtraSettings . Split ( ',' ) )
2015-04-08 15:20:10 -07:00
{
MenuItem newItem = selectableOptions . AddItem ( listItem ) ;
if ( newItem . Text = = sliceSettingValue )
{
selectableOptions . SelectedLabel = sliceSettingValue ;
}
newItem . Selected + = ( sender , e ) = >
{
MenuItem menuItem = ( ( MenuItem ) sender ) ;
2016-06-08 17:59:03 -07:00
SaveSetting ( settingData . SlicerConfigName , menuItem . Text , persistenceLayer ) ;
2016-04-26 17:15:10 -07:00
2016-05-07 21:05:53 -07:00
settingsRow . UpdateStyle ( ) ;
2016-04-18 11:31:31 -07:00
OnSettingsChanged ( settingData ) ;
2015-04-08 15:20:10 -07:00
} ;
}
2016-04-21 17:24:56 -07:00
2016-04-28 12:48:56 -07:00
dataArea . AddChild ( selectableOptions ) ;
2016-04-18 11:31:31 -07:00
2016-05-12 10:57:41 -07:00
settingsRow . ValueChanged = ( text ) = >
{
selectableOptions . SelectedLabel = text ;
OnSettingsChanged ( settingData ) ;
} ;
2015-04-08 15:20:10 -07:00
}
break ;
case OrganizerSettingsData . DataEditTypes . HARDWARE_PRESENT :
{
2016-04-18 11:31:31 -07:00
var checkBoxWidget = new CheckBox ( "" )
2016-04-26 17:15:10 -07:00
{
2016-04-18 11:31:31 -07:00
Name = settingData . PresentationName + " Checkbox" ,
ToolTipText = settingData . HelpText ,
VAnchor = Agg . UI . VAnchor . ParentBottom ,
TextColor = ActiveTheme . Instance . PrimaryTextColor ,
Checked = sliceSettingValue = = "1"
2016-04-26 17:15:10 -07:00
} ;
2016-04-18 11:31:31 -07:00
2015-04-08 15:20:10 -07:00
checkBoxWidget . CheckedStateChanged + = ( sender , e ) = >
{
2016-04-18 11:31:31 -07:00
bool isChecked = ( ( CheckBox ) sender ) . Checked ;
2016-06-08 17:59:03 -07:00
SaveSetting ( settingData . SlicerConfigName , isChecked ? "1" : "0" , persistenceLayer ) ;
2016-04-26 17:15:10 -07:00
2016-05-07 21:05:53 -07:00
settingsRow . UpdateStyle ( ) ;
2016-04-18 11:31:31 -07:00
OnSettingsChanged ( settingData ) ;
2015-04-08 15:20:10 -07:00
} ;
2016-04-01 17:01:07 -07:00
2016-04-28 12:48:56 -07:00
dataArea . AddChild ( checkBoxWidget ) ;
2016-04-18 11:31:31 -07:00
2016-05-12 10:57:41 -07:00
settingsRow . ValueChanged = ( text ) = >
{
checkBoxWidget . Checked = text = = "1" ;
OnSettingsChanged ( settingData ) ;
} ;
2015-04-08 15:20:10 -07:00
}
break ;
case OrganizerSettingsData . DataEditTypes . VECTOR2 :
{
string [ ] xyValueStrings = sliceSettingValue . Split ( ',' ) ;
if ( xyValueStrings . Length ! = 2 )
{
xyValueStrings = new string [ ] { "0" , "0" } ;
}
2016-04-18 11:31:31 -07:00
double currentXValue ;
2015-04-08 15:20:10 -07:00
double . TryParse ( xyValueStrings [ 0 ] , out currentXValue ) ;
2016-04-18 11:31:31 -07:00
var xEditWidget = new MHNumberEdit ( currentXValue , allowDecimals : true , pixelWidth : vectorXYEditWidth , tabIndex : tabIndexForItem + + )
{
ToolTipText = settingData . HelpText ,
SelectAllOnFocus = true
} ;
double currentYValue ;
2015-04-08 15:20:10 -07:00
double . TryParse ( xyValueStrings [ 1 ] , out currentYValue ) ;
2016-04-18 11:31:31 -07:00
var yEditWidget = new MHNumberEdit ( currentYValue , allowDecimals : true , pixelWidth : vectorXYEditWidth , tabIndex : tabIndexForItem + + )
2016-04-26 17:15:10 -07:00
{
2016-04-18 11:31:31 -07:00
ToolTipText = settingData . HelpText ,
2016-04-28 13:25:02 -07:00
SelectAllOnFocus = true ,
2016-05-06 17:56:27 -07:00
Margin = new BorderDouble ( 20 , 0 , 0 , 0 ) ,
2016-04-18 11:31:31 -07:00
} ;
xEditWidget . ActuallNumberEdit . EditComplete + = ( sender , e ) = >
{
2016-06-08 17:59:03 -07:00
SaveSetting ( settingData . SlicerConfigName , xEditWidget . ActuallNumberEdit . Value . ToString ( ) + "," + yEditWidget . ActuallNumberEdit . Value . ToString ( ) , persistenceLayer ) ;
2016-04-18 11:31:31 -07:00
2016-05-07 21:05:53 -07:00
settingsRow . UpdateStyle ( ) ;
2016-04-18 11:31:31 -07:00
OnSettingsChanged ( settingData ) ;
} ;
2016-04-28 12:48:56 -07:00
dataArea . AddChild ( xEditWidget ) ;
2016-05-18 12:51:39 -07:00
dataArea . AddChild ( new TextWidget ( "X" , pointSize : 10 , textColor : ActiveTheme . Instance . PrimaryTextColor )
2016-04-28 13:25:02 -07:00
{
VAnchor = VAnchor . ParentCenter ,
Margin = new BorderDouble ( 5 , 0 ) ,
} ) ;
2016-04-18 11:31:31 -07:00
yEditWidget . ActuallNumberEdit . EditComplete + = ( sender , e ) = >
{
2016-06-08 17:59:03 -07:00
SaveSetting ( settingData . SlicerConfigName , xEditWidget . ActuallNumberEdit . Value . ToString ( ) + "," + yEditWidget . ActuallNumberEdit . Value . ToString ( ) , persistenceLayer ) ;
2016-04-18 11:31:31 -07:00
2016-05-07 21:05:53 -07:00
settingsRow . UpdateStyle ( ) ;
2016-04-18 11:31:31 -07:00
OnSettingsChanged ( settingData ) ;
} ;
2016-04-28 12:48:56 -07:00
dataArea . AddChild ( yEditWidget ) ;
2016-04-28 13:25:02 -07:00
var yLabel = new GuiWidget ( HAnchor . ParentLeftRight , VAnchor . FitToChildren | VAnchor . ParentCenter )
{
Padding = new BorderDouble ( 5 , 0 ) ,
HAnchor = HAnchor . ParentLeftRight ,
} ;
2016-05-18 12:51:39 -07:00
yLabel . AddChild ( new WrappedTextWidget ( "Y" , 0 , pointSize : 9 , textColor : ActiveTheme . Instance . PrimaryTextColor ) ) ;
2016-04-28 13:25:02 -07:00
unitsArea . AddChild ( yLabel ) ;
2016-04-18 11:31:31 -07:00
2016-05-07 21:05:53 -07:00
settingsRow . ValueChanged = ( text ) = >
2016-04-18 11:31:31 -07:00
{
double currentValue2 ;
string [ ] xyValueStrings2 = text . Split ( ',' ) ;
2016-04-26 17:15:10 -07:00
if ( xyValueStrings2 . Length ! = 2 )
{
xyValueStrings2 = new string [ ] { "0" , "0" } ;
}
double . TryParse ( xyValueStrings2 [ 0 ] , out currentValue2 ) ;
xEditWidget . ActuallNumberEdit . Value = currentValue2 ;
double . TryParse ( xyValueStrings2 [ 1 ] , out currentValue2 ) ;
yEditWidget . ActuallNumberEdit . Value = currentValue2 ;
2016-05-12 10:57:41 -07:00
OnSettingsChanged ( settingData ) ;
2016-04-18 11:31:31 -07:00
} ;
}
break ;
case OrganizerSettingsData . DataEditTypes . OFFSET2 :
{
2016-04-27 18:57:51 -07:00
Vector2 offset = ActiveSliceSettings . Instance . ExtruderOffset ( extruderIndex ) ;
2016-04-18 11:31:31 -07:00
var xEditWidget = new MHNumberEdit ( offset . x , allowDecimals : true , allowNegatives : true , pixelWidth : vectorXYEditWidth , tabIndex : tabIndexForItem + + )
{
ToolTipText = settingData . HelpText ,
SelectAllOnFocus = true ,
} ;
var yEditWidget = new MHNumberEdit ( offset . y , allowDecimals : true , allowNegatives : true , pixelWidth : vectorXYEditWidth , tabIndex : tabIndexForItem + + )
{
ToolTipText = settingData . HelpText ,
2016-04-28 13:25:02 -07:00
SelectAllOnFocus = true ,
2016-05-06 17:56:27 -07:00
Margin = new BorderDouble ( 20 , 0 , 0 , 0 ) ,
2016-04-26 17:15:10 -07:00
} ;
2016-04-21 18:02:02 -07:00
xEditWidget . ActuallNumberEdit . EditComplete + = ( sender , e ) = >
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
int extruderIndexLocal = extruderIndex ;
2016-06-08 17:59:03 -07:00
SaveCommaSeparatedIndexSetting ( extruderIndexLocal , layerCascade , settingData . SlicerConfigName , xEditWidget . ActuallNumberEdit . Value . ToString ( ) + "x" + yEditWidget . ActuallNumberEdit . Value . ToString ( ) , persistenceLayer ) ;
2016-04-26 17:15:10 -07:00
2016-05-07 21:05:53 -07:00
settingsRow . UpdateStyle ( ) ;
2016-04-18 11:31:31 -07:00
OnSettingsChanged ( settingData ) ;
2015-04-08 15:20:10 -07:00
} ;
2016-04-28 12:48:56 -07:00
dataArea . AddChild ( xEditWidget ) ;
2016-05-18 12:51:39 -07:00
dataArea . AddChild ( new TextWidget ( "X" , pointSize : 10 , textColor : ActiveTheme . Instance . PrimaryTextColor )
2016-04-28 13:25:02 -07:00
{
VAnchor = VAnchor . ParentCenter ,
Margin = new BorderDouble ( 5 , 0 ) ,
} ) ;
2016-04-21 18:02:02 -07:00
yEditWidget . ActuallNumberEdit . EditComplete + = ( sender , e ) = >
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
int extruderIndexLocal = extruderIndex ;
2016-06-08 17:59:03 -07:00
SaveCommaSeparatedIndexSetting ( extruderIndexLocal , layerCascade , settingData . SlicerConfigName , xEditWidget . ActuallNumberEdit . Value . ToString ( ) + "x" + yEditWidget . ActuallNumberEdit . Value . ToString ( ) , persistenceLayer ) ;
2016-04-18 11:31:31 -07:00
2016-05-07 21:05:53 -07:00
settingsRow . UpdateStyle ( ) ;
2016-04-26 17:15:10 -07:00
2016-04-18 11:31:31 -07:00
OnSettingsChanged ( settingData ) ;
2015-04-08 15:20:10 -07:00
} ;
2016-04-28 12:48:56 -07:00
dataArea . AddChild ( yEditWidget ) ;
2016-04-28 13:25:02 -07:00
var yLabel = new GuiWidget ( HAnchor . ParentLeftRight , VAnchor . FitToChildren | VAnchor . ParentCenter )
{
Padding = new BorderDouble ( 5 , 0 ) ,
HAnchor = HAnchor . ParentLeftRight ,
} ;
2016-05-18 12:51:39 -07:00
yLabel . AddChild ( new WrappedTextWidget ( "Y" , 0 , pointSize : 9 , textColor : ActiveTheme . Instance . PrimaryTextColor ) ) ;
2016-04-28 13:25:02 -07:00
unitsArea . AddChild ( yLabel ) ;
2015-04-08 15:20:10 -07:00
2016-05-07 21:05:53 -07:00
settingsRow . ValueChanged = ( text ) = >
2016-04-26 17:15:10 -07:00
{
2016-04-27 18:57:51 -07:00
Vector2 offset2 = ActiveSliceSettings . Instance . ExtruderOffset ( extruderIndex ) ;
2016-04-26 17:15:10 -07:00
xEditWidget . ActuallNumberEdit . Value = offset2 . x ;
yEditWidget . ActuallNumberEdit . Value = offset2 . y ;
2016-05-12 10:57:41 -07:00
OnSettingsChanged ( settingData ) ;
2016-04-26 17:15:10 -07:00
} ;
2015-04-08 15:20:10 -07:00
}
break ;
default :
2016-04-18 11:31:31 -07:00
var missingSetting = new TextWidget ( String . Format ( "Missing the setting for '{0}'." , settingData . DataEditType . ToString ( ) ) )
{
TextColor = ActiveTheme . Instance . PrimaryTextColor ,
BackgroundColor = RGBA_Bytes . Red
} ;
2016-04-28 12:48:56 -07:00
dataArea . AddChild ( missingSetting ) ;
2015-04-08 15:20:10 -07:00
break ;
}
}
2014-07-26 13:43:55 -07:00
2015-04-08 15:20:10 -07:00
container . HAnchor = HAnchor . ParentLeftRight ;
container . VAnchor = VAnchor . FitToChildren ;
2016-04-18 11:31:31 -07:00
2016-06-08 09:25:20 -07:00
Button restoreButton = null ;
2016-06-08 11:18:53 -07:00
if ( settingData . ShowAsOverride )
2016-04-26 17:15:10 -07:00
{
2016-06-08 09:25:20 -07:00
restoreButton = new Button ( new ButtonViewStates ( new ImageWidget ( restoreNormal ) , new ImageWidget ( restoreHover ) , new ImageWidget ( restorePressed ) , new ImageWidget ( restoreNormal ) ) )
{
Name = "Restore " + settingData . SlicerConfigName ,
VAnchor = VAnchor . ParentCenter ,
Margin = new BorderDouble ( 0 , 0 , 5 , 0 ) ,
ToolTipText = "Restore Default" . Localize ( )
} ;
2014-01-29 19:09:30 -08:00
2016-06-08 09:25:20 -07:00
restoreButton . Click + = ( sender , e ) = >
{
2016-04-18 11:31:31 -07:00
// Revert the user override
if ( persistenceLayer = = null )
2016-06-08 09:25:20 -07:00
{
ActiveSliceSettings . Instance . ClearValue ( settingData . SlicerConfigName ) ;
}
else
{
ActiveSliceSettings . Instance . ClearValue ( settingData . SlicerConfigName , persistenceLayer ) ;
}
2016-04-18 11:31:31 -07:00
2016-06-08 09:25:20 -07:00
settingsRow . RefreshValue ( layerCascade ) ;
} ;
2016-04-18 11:31:31 -07:00
2016-06-08 09:25:20 -07:00
restoreArea . AddChild ( restoreButton ) ;
}
2016-04-18 11:31:31 -07:00
2016-05-07 21:05:53 -07:00
container . AddChild ( settingsRow ) ;
2016-04-18 11:31:31 -07:00
// Define the UpdateStyle implementation
2016-05-07 21:05:53 -07:00
settingsRow . UpdateStyle = ( ) = >
2016-04-18 11:31:31 -07:00
{
if ( persistenceLayer . ContainsKey ( settingData . SlicerConfigName ) )
{
2016-06-08 17:59:03 -07:00
switch ( viewFilter )
2016-04-18 11:31:31 -07:00
{
case NamedSettingsLayers . All :
2016-06-08 11:18:53 -07:00
if ( settingData . ShowAsOverride )
2016-06-08 09:25:20 -07:00
{
settingsRow . BackgroundColor = userSettingBackgroundColor ;
}
2016-04-18 11:31:31 -07:00
break ;
case NamedSettingsLayers . Material :
2016-05-07 21:05:53 -07:00
settingsRow . BackgroundColor = materialSettingBackgroundColor ;
2016-04-18 11:31:31 -07:00
break ;
case NamedSettingsLayers . Quality :
2016-05-07 21:05:53 -07:00
settingsRow . BackgroundColor = qualitySettingBackgroundColor ;
2016-04-18 11:31:31 -07:00
break ;
}
2016-06-08 09:25:20 -07:00
if ( restoreButton ! = null ) restoreButton . Visible = true ;
2016-04-18 11:31:31 -07:00
}
2016-05-16 16:21:42 -07:00
else if ( layerCascade = = null )
2016-04-18 11:31:31 -07:00
{
if ( ActiveSliceSettings . Instance . SettingExistsInLayer ( settingData . SlicerConfigName , NamedSettingsLayers . Material ) )
{
2016-05-07 21:05:53 -07:00
settingsRow . BackgroundColor = materialSettingBackgroundColor ;
2016-04-18 11:31:31 -07:00
}
else if ( ActiveSliceSettings . Instance . SettingExistsInLayer ( settingData . SlicerConfigName , NamedSettingsLayers . Quality ) )
{
2016-05-07 21:05:53 -07:00
settingsRow . BackgroundColor = qualitySettingBackgroundColor ;
2016-04-18 11:31:31 -07:00
}
else
{
2016-05-07 21:05:53 -07:00
settingsRow . BackgroundColor = RGBA_Bytes . Transparent ;
2016-04-18 11:31:31 -07:00
}
2016-06-08 09:25:20 -07:00
if ( restoreButton ! = null ) restoreButton . Visible = false ;
2016-04-18 11:31:31 -07:00
}
else
{
2016-06-08 09:25:20 -07:00
if ( restoreButton ! = null ) restoreButton . Visible = false ;
2016-05-07 21:05:53 -07:00
settingsRow . BackgroundColor = RGBA_Bytes . Transparent ;
2016-04-18 11:31:31 -07:00
}
} ;
// Invoke the UpdateStyle implementation
2016-05-07 21:05:53 -07:00
settingsRow . UpdateStyle ( ) ;
2016-04-26 17:15:10 -07:00
2015-04-08 15:20:10 -07:00
return container ;
}
2014-01-29 19:09:30 -08:00
2016-06-08 17:59:03 -07:00
private static void AddComMenuItems ( OrganizerSettingsData settingData , SettingsLayer persistenceLayer , SettingsRow settingsRow , DropDownList selectableOptions )
2016-05-09 18:07:35 -07:00
{
selectableOptions . MenuItems . Clear ( ) ;
string machineSpecificComPortValue = ActiveSliceSettings . Instance . ComPort ( ) ;
foreach ( string listItem in FrostedSerialPort . GetPortNames ( ) )
{
MenuItem newItem = selectableOptions . AddItem ( listItem ) ;
if ( newItem . Text = = machineSpecificComPortValue )
{
selectableOptions . SelectedLabel = machineSpecificComPortValue ;
}
newItem . Selected + = ( sender , e ) = >
{
MenuItem menuItem = ( ( MenuItem ) sender ) ;
// Directly set the ComPort
if ( persistenceLayer = = null )
{
ActiveSliceSettings . Instance . SetComPort ( menuItem . Text ) ;
}
else
{
ActiveSliceSettings . Instance . SetComPort ( menuItem . Text , persistenceLayer ) ;
}
settingsRow . UpdateStyle ( ) ;
OnSettingsChanged ( settingData ) ;
} ;
}
}
2016-04-22 15:05:21 -07:00
static ImageBuffer restoreNormal = EnsureRestoreButtonImages ( ) ;
static ImageBuffer restoreHover ;
static ImageBuffer restorePressed ;
2016-04-18 11:31:31 -07:00
2016-04-22 15:05:21 -07:00
static ImageBuffer EnsureRestoreButtonImages ( )
{
2016-05-06 17:56:27 -07:00
int size = ( int ) ( 16 * GuiWidget . DeviceScale ) ;
2016-04-22 15:05:21 -07:00
2016-04-22 19:10:41 -07:00
restoreNormal = ColorCirle ( size , new RGBA_Bytes ( 128 , 128 , 128 ) ) ;
if ( OsInformation . OperatingSystem = = OSType . Android )
{
restoreNormal = ColorCirle ( size , new RGBA_Bytes ( 200 , 0 , 0 ) ) ;
}
restoreHover = ColorCirle ( size , new RGBA_Bytes ( 200 , 0 , 0 ) ) ;
restorePressed = ColorCirle ( size , new RGBA_Bytes ( 255 , 0 , 0 ) ) ;
2016-04-22 15:05:21 -07:00
return restoreNormal ;
}
private static ImageBuffer ColorCirle ( int size , RGBA_Bytes color )
{
ImageBuffer imageBuffer = new ImageBuffer ( size , size , 32 , new BlenderBGRA ( ) ) ;
Graphics2D normalGraphics = imageBuffer . NewGraphics2D ( ) ;
Vector2 center = new Vector2 ( size / 2.0 , size / 2.0 ) ;
normalGraphics . Circle ( center , size / 2.0 , color ) ;
2016-05-06 17:56:27 -07:00
normalGraphics . Line ( center + new Vector2 ( - size / 4.0 , - size / 4.0 ) , center + new Vector2 ( size / 4.0 , size / 4.0 ) , RGBA_Bytes . White , 2 * GuiWidget . DeviceScale ) ;
normalGraphics . Line ( center + new Vector2 ( - size / 4.0 , size / 4.0 ) , center + new Vector2 ( size / 4.0 , - size / 4.0 ) , RGBA_Bytes . White , 2 * GuiWidget . DeviceScale ) ;
2016-04-22 15:05:21 -07:00
return imageBuffer ;
}
2016-06-08 17:59:03 -07:00
private static GuiWidget CreateQuickMenu ( OrganizerSettingsData settingData , SettingsLayer persistenceLayer , GuiWidget content , InternalTextEditWidget internalTextWidget , List < SettingsLayer > layerCascade )
2015-04-08 15:20:10 -07:00
{
2016-05-16 16:21:42 -07:00
string sliceSettingValue = GetActiveValue ( settingData . SlicerConfigName , layerCascade ) ;
2015-04-08 15:20:10 -07:00
FlowLayoutWidget totalContent = new FlowLayoutWidget ( ) ;
2014-06-19 11:25:28 -07:00
2016-06-03 18:11:51 -07:00
DropDownList selectableOptions = new DropDownList ( "Custom" , maxHeight : 200 ) ;
2015-04-08 15:20:10 -07:00
selectableOptions . Margin = new BorderDouble ( 0 , 0 , 10 , 0 ) ;
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
foreach ( QuickMenuNameValue nameValue in settingData . QuickMenuSettings )
{
string valueLocal = nameValue . Value ;
2014-04-09 18:45:29 -07:00
2015-04-08 15:20:10 -07:00
MenuItem newItem = selectableOptions . AddItem ( nameValue . MenuName ) ;
if ( sliceSettingValue = = valueLocal )
{
selectableOptions . SelectedLabel = nameValue . MenuName ;
}
2014-04-09 18:45:29 -07:00
2015-04-08 15:20:10 -07:00
newItem . Selected + = ( sender , e ) = >
{
2016-06-08 17:59:03 -07:00
SaveSetting ( settingData . SlicerConfigName , valueLocal , persistenceLayer ) ;
2016-04-18 11:31:31 -07:00
OnSettingsChanged ( settingData ) ;
2015-04-08 15:20:10 -07:00
internalTextWidget . Text = valueLocal ;
2015-05-02 10:50:14 -07:00
internalTextWidget . OnEditComplete ( null ) ;
2015-04-08 15:20:10 -07:00
} ;
}
2014-04-09 18:45:29 -07:00
2015-04-08 15:20:10 -07:00
// put in the custom menu to allow direct editing
MenuItem customMenueItem = selectableOptions . AddItem ( "Custom" ) ;
2014-04-09 18:45:29 -07:00
2015-04-08 15:20:10 -07:00
totalContent . AddChild ( selectableOptions ) ;
content . VAnchor = VAnchor . ParentCenter ;
totalContent . AddChild ( content ) ;
2014-11-24 22:24:30 -08:00
2016-06-08 17:59:03 -07:00
EventHandler localUnregisterEvents = null ;
2016-05-12 18:42:19 -07:00
SettingChanged . RegisterEvent ( ( sender , e ) = >
2015-04-08 15:20:10 -07:00
{
bool foundSetting = false ;
foreach ( QuickMenuNameValue nameValue in settingData . QuickMenuSettings )
{
string localName = nameValue . MenuName ;
2016-05-16 16:21:42 -07:00
string newSliceSettingValue = GetActiveValue ( settingData . SlicerConfigName , layerCascade ) ;
2015-04-08 15:20:10 -07:00
if ( newSliceSettingValue = = nameValue . Value )
{
selectableOptions . SelectedLabel = localName ;
foundSetting = true ;
break ;
}
}
if ( ! foundSetting )
{
selectableOptions . SelectedLabel = "Custom" ;
}
2016-06-08 17:59:03 -07:00
} , ref localUnregisterEvents ) ;
totalContent . Closed + = ( s , e ) = >
{
localUnregisterEvents ? . Invoke ( s , e ) ;
} ;
2014-11-24 22:24:30 -08:00
2015-04-08 15:20:10 -07:00
return totalContent ;
}
2014-11-20 10:36:03 -08:00
2016-06-08 17:59:03 -07:00
private static void SaveCommaSeparatedIndexSetting ( int extruderIndexLocal , List < SettingsLayer > layerCascade , string slicerConfigName , string newSingleValue , SettingsLayer persistenceLayer )
2015-04-08 15:20:10 -07:00
{
2016-05-16 16:21:42 -07:00
string [ ] settings = GetActiveValue ( slicerConfigName , layerCascade ) . Split ( ',' ) ;
2015-04-08 15:20:10 -07:00
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 ;
}
}
2014-09-29 17:59:57 -07:00
2015-04-08 15:20:10 -07:00
settings = newSettings ;
}
2014-09-29 17:59:57 -07:00
2015-04-08 15:20:10 -07:00
string newValue = string . Join ( "," , settings ) ;
2016-06-08 17:59:03 -07:00
SaveSetting ( slicerConfigName , newValue , persistenceLayer ) ;
2015-04-08 15:20:10 -07:00
}
2014-09-29 17:59:57 -07:00
2015-04-08 15:20:10 -07:00
protected void ReloadOptions ( object sender , EventArgs e )
{
ApplicationController . Instance . ReloadAdvancedControlsPanel ( ) ;
}
2014-01-29 19:09:30 -08:00
2016-06-08 17:59:03 -07:00
private static void SaveSetting ( string name , string value , SettingsLayer persistenceLayer )
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
if ( persistenceLayer = = null )
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
ActiveSliceSettings . Instance . SetActiveValue ( name , value ) ;
}
else
{
ActiveSliceSettings . Instance . SetActiveValue ( name , value , persistenceLayer ) ;
2015-04-08 15:20:10 -07:00
}
}
2014-04-09 18:45:29 -07:00
2015-04-08 15:20:10 -07:00
public override void OnDraw ( Graphics2D graphics2D )
{
base . OnDraw ( graphics2D ) ;
}
}
2014-04-09 18:45:29 -07:00
2015-04-08 15:20:10 -07:00
internal class SliceSettingListControl : ScrollableWidget
{
private FlowLayoutWidget topToBottomItemList ;
2014-04-09 18:45:29 -07:00
2015-04-08 15:20:10 -07:00
public SliceSettingListControl ( )
{
this . AnchorAll ( ) ;
this . AutoScroll = true ;
this . ScrollArea . HAnchor | = Agg . UI . HAnchor . ParentLeftRight ;
2014-04-09 18:45:29 -07:00
2015-04-08 15:20:10 -07:00
topToBottomItemList = new FlowLayoutWidget ( FlowDirection . TopToBottom ) ;
topToBottomItemList . HAnchor = Agg . UI . HAnchor . Max_FitToChildren_ParentWidth ;
topToBottomItemList . Margin = new BorderDouble ( top : 3 ) ;
2014-04-09 18:45:29 -07:00
2015-04-08 15:20:10 -07:00
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 ) ;
}
}
}