2014-10-30 14:42:00 -07:00
/ *
2018-05-03 23:00:02 -07:00
Copyright ( c ) 2018 , Lars Brubaker , John Lewin
2014-10-30 14:42:00 -07: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-10-30 14:42:00 -07:00
1. Redistributions of source code must retain the above copyright notice , this
2015-04-08 15:20:10 -07:00
list of conditions and the following disclaimer .
2014-10-30 14:42:00 -07:00
2. Redistributions in binary form must reproduce the above copyright notice ,
this list of conditions and the following disclaimer in the documentation
2015-04-08 15:20:10 -07:00
and / or other materials provided with the distribution .
2014-10-30 14:42:00 -07:00
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES
( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ;
LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
The views and conclusions contained in the software and documentation are those
2015-04-08 15:20:10 -07:00
of the authors and should not be interpreted as representing official policies ,
2014-10-30 14:42:00 -07:00
either expressed or implied , of the FreeBSD Project .
* /
2017-07-06 12:22:56 -07:00
using System ;
2018-11-05 12:44:28 -08:00
using System.Collections.Generic ;
2017-08-15 12:32:09 -07:00
using System.Linq ;
2018-10-15 20:08:15 -07:00
using System.Threading.Tasks ;
2014-10-30 14:42:00 -07:00
using MatterHackers.Agg ;
2018-01-03 17:14:30 -08:00
using MatterHackers.Agg.Platform ;
2014-10-30 14:42:00 -07:00
using MatterHackers.Agg.UI ;
using MatterHackers.Localizations ;
2018-11-06 16:07:29 -08:00
using MatterHackers.MatterControl.CustomWidgets ;
2017-11-28 14:37:38 -08:00
using MatterHackers.MatterControl.PartPreviewWindow.PlusTab ;
2018-10-07 11:36:52 -07:00
using MatterHackers.MatterControl.PrintLibrary ;
2014-10-30 14:42:00 -07:00
using MatterHackers.MatterControl.SlicerConfiguration ;
2017-11-11 17:28:03 -08:00
using MatterHackers.VectorMath ;
2018-06-05 12:22:26 -07:00
using Newtonsoft.Json ;
2014-10-30 14:42:00 -07:00
namespace MatterHackers.MatterControl.PartPreviewWindow
{
2018-10-30 14:02:50 -07:00
public class MainViewWidget : FlowLayoutWidget
2015-04-08 15:20:10 -07:00
{
2017-07-27 14:25:21 -07:00
private EventHandler unregisterEvents ;
2018-01-08 13:13:32 -08:00
private ChromeTab printerTab = null ;
2017-11-11 17:28:03 -08:00
private ChromeTabs tabControl ;
2017-09-29 21:30:51 -07:00
2018-10-15 17:14:33 -07:00
private int partCount = 0 ;
2018-10-15 20:08:15 -07:00
private ThemeConfig theme ;
2018-11-05 12:44:28 -08:00
private Toolbar statusBar ;
private FlowLayoutWidget tasksContainer ;
private GuiWidget stretchStatusPanel ;
2018-10-15 17:14:33 -07:00
2018-10-30 14:02:50 -07:00
public MainViewWidget ( ThemeConfig theme )
2017-11-11 17:28:03 -08:00
: base ( FlowDirection . TopToBottom )
2015-04-08 15:20:10 -07:00
{
this . AnchorAll ( ) ;
2018-10-15 20:08:15 -07:00
this . theme = theme ;
2018-10-29 21:47:03 -07:00
this . Name = "PartPreviewContent" ;
2018-11-03 09:50:09 -07:00
this . BackgroundColor = theme . BackgroundColor ;
2018-10-29 21:47:03 -07:00
// Push TouchScreenMode into GuiWidget
GuiWidget . TouchScreenMode = UserSettings . Instance . IsTouchScreen ;
2017-03-15 16:17:06 -07:00
2018-05-16 18:38:46 -07:00
var extensionArea = new LeftClipFlowLayoutWidget ( )
{
BackgroundColor = theme . TabBarBackground ,
2018-05-17 12:41:00 -07:00
VAnchor = VAnchor . Stretch ,
Padding = new BorderDouble ( left : 8 )
2018-05-16 18:38:46 -07:00
} ;
2017-08-15 12:32:09 -07:00
2017-11-11 17:28:03 -08:00
tabControl = new ChromeTabs ( extensionArea , theme )
2017-11-07 14:58:43 -08:00
{
2017-11-11 17:28:03 -08:00
VAnchor = VAnchor . Stretch ,
HAnchor = HAnchor . Stretch ,
2018-11-03 09:50:09 -07:00
BackgroundColor = theme . BackgroundColor ,
2018-01-08 14:28:52 -08:00
BorderColor = theme . MinimalShade ,
Border = new BorderDouble ( left : 1 ) ,
2017-11-11 17:28:03 -08:00
} ;
2018-10-11 15:04:03 -07:00
2018-10-15 17:14:33 -07:00
tabControl . PlusClicked + = ( s , e ) = >
{
2018-10-15 20:22:24 -07:00
UiThread . RunOnIdle ( ( ) = >
2018-10-15 17:14:33 -07:00
{
2018-10-15 20:22:24 -07:00
this . CreatePartTab ( ) . ConfigureAwait ( false ) ;
2018-10-15 17:14:33 -07:00
} ) ;
} ;
2017-11-11 17:28:03 -08:00
tabControl . ActiveTabChanged + = ( s , e ) = >
{
if ( this . tabControl . ActiveTab ? . TabContent is PartTabPage tabPage )
2017-11-07 14:58:43 -08:00
{
var dragDropData = ApplicationController . Instance . DragDropData ;
// Set reference on tab change
dragDropData . View3DWidget = tabPage . view3DWidget ;
dragDropData . SceneContext = tabPage . sceneContext ;
2018-11-07 14:31:51 -08:00
ApplicationController . Instance . PrinterTabSelected = true ;
}
else
{
ApplicationController . Instance . PrinterTabSelected = false ;
2017-11-07 14:58:43 -08:00
}
2018-10-10 17:52:46 -07:00
ApplicationController . Instance . MainTabKey = tabControl . SelectedTabKey ;
2017-11-07 14:58:43 -08:00
} ;
2018-05-17 12:41:00 -07:00
// Force the ActionArea to be as high as ButtonHeight
tabControl . TabBar . ActionArea . MinimumSize = new Vector2 ( 0 , theme . ButtonHeight ) ;
tabControl . TabBar . BackgroundColor = theme . TabBarBackground ;
2018-11-03 09:50:09 -07:00
tabControl . TabBar . BorderColor = theme . BackgroundColor ;
2018-05-17 12:41:00 -07:00
// Force common padding into top region
2018-06-27 22:25:55 -07:00
tabControl . TabBar . Padding = theme . TabbarPadding . Clone ( top : theme . TabbarPadding . Top * 2 , bottom : 0 ) ;
2015-04-08 15:20:10 -07:00
2018-04-25 11:35:33 -07:00
// add in a what's new button
2018-07-11 09:26:54 -07:00
var seeWhatsNewButton = new LinkLabel ( "What's New..." . Localize ( ) , theme )
{
Name = "What's New Link" ,
ToolTipText = "See what's new in this version of MatterControl" . Localize ( ) ,
VAnchor = VAnchor . Center ,
Margin = new BorderDouble ( 10 , 0 ) ,
2018-11-03 09:13:07 -07:00
TextColor = theme . TextColor
2018-07-11 09:26:54 -07:00
} ;
2018-04-25 11:35:33 -07:00
seeWhatsNewButton . Click + = ( s , e ) = > UiThread . RunOnIdle ( ( ) = >
{
2018-06-05 12:22:26 -07:00
UserSettings . Instance . set ( UserSettingsKey . LastReadWhatsNew , JsonConvert . SerializeObject ( DateTime . Now ) ) ;
2018-06-30 23:26:57 -07:00
DialogWindow . Show ( new HelpPage ( "What's New" ) ) ;
2018-04-25 11:35:33 -07:00
} ) ;
tabControl . TabBar . ActionArea . AddChild ( seeWhatsNewButton ) ;
2017-09-05 15:44:22 -07:00
// add in the update available button
2018-07-11 09:26:54 -07:00
var updateAvailableButton = new LinkLabel ( "Update Available" . Localize ( ) , theme )
{
Visible = false ,
2018-10-31 12:28:14 -07:00
Name = "Update Available Link" ,
ToolTipText = "There is a new update available for download" . Localize ( ) ,
VAnchor = VAnchor . Center ,
Margin = new BorderDouble ( 10 , 0 )
2018-07-11 09:26:54 -07:00
} ;
2018-04-25 11:35:33 -07:00
// make the function inline so we don't have to create members for the buttons
2018-09-07 14:27:57 -07:00
EventHandler < StringEventArgs > SetLinkButtonsVisibility = ( s , e ) = >
2018-04-25 11:35:33 -07:00
{
2018-05-16 14:36:01 -07:00
if ( UserSettings . Instance . HasLookedAtWhatsNew ( ) )
2018-04-25 11:35:33 -07:00
{
// hide it
seeWhatsNewButton . Visible = false ;
}
if ( UpdateControlData . Instance . UpdateStatus = = UpdateControlData . UpdateStatusStates . UpdateAvailable )
{
updateAvailableButton . Visible = true ;
// if we are going to show the update link hide the whats new link no matter what
seeWhatsNewButton . Visible = false ;
}
else
{
updateAvailableButton . Visible = false ;
}
} ;
2018-09-07 14:27:57 -07:00
UserSettings . Instance . SettingChanged + = SetLinkButtonsVisibility ;
this . Closed + = ( s , e ) = > UserSettings . Instance . SettingChanged - = SetLinkButtonsVisibility ;
2018-04-26 16:41:51 -07:00
2018-05-16 14:36:01 -07:00
RunningInterval showUpdateInterval = null ;
updateAvailableButton . VisibleChanged + = ( s , e ) = >
{
if ( ! updateAvailableButton . Visible )
{
2018-11-06 16:07:29 -08:00
if ( showUpdateInterval ! = null )
2018-05-16 14:36:01 -07:00
{
2018-11-13 16:52:23 -08:00
UiThread . ClearInterval ( showUpdateInterval ) ;
2018-05-16 14:36:01 -07:00
showUpdateInterval = null ;
}
return ;
}
showUpdateInterval = UiThread . SetInterval ( ( ) = >
{
double displayTime = 1 ;
double pulseTime = 1 ;
double totalSeconds = 0 ;
var textWidgets = updateAvailableButton . Descendants < TextWidget > ( ) . Where ( ( w ) = > w . Visible = = true ) . ToArray ( ) ;
2018-11-03 09:13:07 -07:00
Color startColor = theme . TextColor ;
2018-07-12 22:49:39 -07:00
// Show a highlight on the button as the user did not click it
2018-05-16 14:36:01 -07:00
Animation flashBackground = null ;
flashBackground = new Animation ( )
{
DrawTarget = updateAvailableButton ,
FramesPerSecond = 10 ,
Update = ( s1 , updateEvent ) = >
{
totalSeconds + = updateEvent . SecondsPassed ;
if ( totalSeconds < displayTime )
{
double blend = AttentionGetter . GetFadeInOutPulseRatio ( totalSeconds , pulseTime ) ;
var color = new Color ( startColor , ( int ) ( ( 1 - blend ) * 255 ) ) ;
foreach ( var textWidget in textWidgets )
{
textWidget . TextColor = color ;
}
}
else
{
foreach ( var textWidget in textWidgets )
{
textWidget . TextColor = startColor ;
}
flashBackground . Stop ( ) ;
}
}
} ;
flashBackground . Start ( ) ;
} , 120 ) ;
} ;
2018-07-11 09:26:54 -07:00
SetLinkButtonsVisibility ( this , null ) ;
2017-09-05 15:44:22 -07:00
updateAvailableButton . Click + = ( s , e ) = > UiThread . RunOnIdle ( ( ) = >
{
2018-10-10 08:19:09 -07:00
UpdateControlData . Instance . CheckForUpdate ( ) ;
DialogWindow . Show < CheckForUpdatesPage > ( ) ;
2017-09-05 15:44:22 -07:00
} ) ;
2017-11-11 17:28:03 -08:00
2017-12-26 08:15:28 -08:00
tabControl . TabBar . ActionArea . AddChild ( updateAvailableButton ) ;
2017-09-05 15:44:22 -07:00
2017-08-07 14:19:28 -07:00
this . AddChild ( tabControl ) ;
2017-09-15 09:23:53 -07:00
2017-08-07 14:19:28 -07:00
ApplicationController . Instance . NotifyPrintersTabRightElement ( extensionArea ) ;
2018-10-10 17:52:46 -07:00
var printer = ApplicationController . Instance . ActivePrinter ;
2018-10-15 19:35:11 -07:00
// Store tab
tabControl . AddTab (
2018-10-30 14:02:50 -07:00
new ChromeTab ( "Store" , "Store" . Localize ( ) , tabControl , new StoreTabPage ( theme ) , theme , hasClose : false )
2018-10-15 19:35:11 -07:00
{
MinimumSize = new Vector2 ( 0 , theme . TabButtonHeight ) ,
Name = "Store Tab" ,
Padding = new BorderDouble ( 15 , 0 ) ,
} ) ;
2018-10-07 11:36:52 -07:00
// Library tab
var libraryWidget = new LibraryWidget ( this , theme )
{
2018-11-03 09:50:09 -07:00
BackgroundColor = theme . BackgroundColor
2018-10-07 11:36:52 -07:00
} ;
2018-05-03 23:00:02 -07:00
tabControl . AddTab (
2018-10-15 20:22:24 -07:00
new ChromeTab ( "Library" , "Library" . Localize ( ) , tabControl , libraryWidget , theme , hasClose : false )
2018-05-03 23:00:02 -07:00
{
MinimumSize = new Vector2 ( 0 , theme . TabButtonHeight ) ,
2018-10-07 11:36:52 -07:00
Name = "Library Tab" ,
2018-10-10 17:52:46 -07:00
Padding = new BorderDouble ( 15 , 0 ) ,
2018-05-03 23:00:02 -07:00
} ) ;
2018-04-19 15:53:59 -07:00
2018-10-10 17:52:46 -07:00
// Hardware tab
2018-10-07 11:36:52 -07:00
tabControl . AddTab (
2018-10-16 12:15:27 -07:00
new ChromeTab (
2018-10-15 20:22:24 -07:00
"Hardware" ,
"Hardware" . Localize ( ) ,
tabControl ,
new HardwareTabPage ( theme )
{
2018-11-03 09:50:09 -07:00
BackgroundColor = theme . BackgroundColor
2018-10-15 20:22:24 -07:00
} ,
theme ,
hasClose : false )
2018-11-06 16:07:29 -08:00
{
MinimumSize = new Vector2 ( 0 , theme . TabButtonHeight ) ,
Name = "Hardware Tab" ,
Padding = new BorderDouble ( 15 , 0 ) ,
} ) ;
2018-10-07 11:36:52 -07:00
2018-10-15 19:35:11 -07:00
// Printer tab
if ( printer . Settings . PrinterSelected )
{
this . CreatePrinterTab ( printer , theme ) ;
}
2018-10-15 20:08:15 -07:00
else
{
2018-10-16 16:29:37 -07:00
if ( ApplicationController . Instance . Workspaces . Count = = 0 )
{
this . CreatePartTab ( ) . ConfigureAwait ( false ) ;
}
2018-10-15 20:08:15 -07:00
}
2018-10-07 11:36:52 -07:00
2018-10-10 17:43:53 -07:00
string tabKey = ApplicationController . Instance . MainTabKey ;
if ( string . IsNullOrEmpty ( tabKey ) )
{
if ( printer . Settings . PrinterSelected )
{
tabKey = printer . Settings . GetValue ( SettingsKey . printer_name ) ;
}
else
{
2018-10-10 18:11:56 -07:00
tabKey = "Hardware" ;
2018-10-10 17:43:53 -07:00
}
}
2018-11-07 14:31:51 -08:00
// HACK: Restore to the first printer tab if PrinterTabSelected and tabKey not found. This allows sign in/out to remain on the printer tab across different users
if ( ! tabControl . AllTabs . Any ( t = > t . Key = = tabKey )
& & ApplicationController . Instance . PrinterTabSelected )
{
var key = tabControl . AllTabs . Where ( t = > t . TabContent is PrinterTabPage ) . FirstOrDefault ( ) ? . Key ;
if ( key ! = null )
{
tabKey = key ;
}
}
2018-10-07 11:36:52 -07:00
var brandMenu = new BrandMenuButton ( theme )
2018-04-19 15:53:59 -07:00
{
2018-10-07 11:36:52 -07:00
HAnchor = HAnchor . Fit ,
VAnchor = VAnchor . Fit ,
BackgroundColor = theme . TabBarBackground ,
2018-10-13 17:58:54 -07:00
Padding = theme . TabbarPadding . Clone ( right : theme . DefaultContainerPadding )
2018-10-07 11:36:52 -07:00
} ;
tabControl . TabBar . ActionArea . AddChild ( brandMenu , 0 ) ;
2018-05-03 23:00:02 -07:00
2018-10-15 20:22:24 -07:00
// Restore active tabs
foreach ( var workspace in ApplicationController . Instance . Workspaces )
2018-04-19 15:53:59 -07:00
{
2018-10-15 20:22:24 -07:00
this . CreatePartTab ( workspace ) ;
}
2018-10-10 14:58:37 -07:00
2018-10-23 14:16:54 -07:00
tabControl . SelectedTabKey = tabKey ;
2018-11-05 12:44:28 -08:00
statusBar = new Toolbar ( theme )
{
HAnchor = HAnchor . Stretch ,
VAnchor = VAnchor . Absolute ,
Padding = 1 ,
2018-11-06 16:07:29 -08:00
Height = 22 ,
2018-11-05 12:44:28 -08:00
BackgroundColor = theme . BackgroundColor ,
Border = new BorderDouble ( top : 1 ) ,
BorderColor = theme . BorderColor20 ,
} ;
this . AddChild ( statusBar ) ;
statusBar . ActionArea . VAnchor = VAnchor . Stretch ;
tasksContainer = new FlowLayoutWidget ( FlowDirection . LeftToRight )
{
HAnchor = HAnchor . Fit ,
VAnchor = VAnchor . Stretch ,
BackgroundColor = theme . MinimalShade ,
Name = "runningTasksPanel"
} ;
statusBar . AddChild ( tasksContainer ) ;
var tasks = ApplicationController . Instance . Tasks ;
tasks . TasksChanged + = ( s , e ) = >
{
RenderRunningTasks ( theme , tasks ) ;
} ;
stretchStatusPanel = new GuiWidget ( )
{
HAnchor = HAnchor . Stretch ,
VAnchor = VAnchor . Stretch ,
Padding = new BorderDouble ( right : 3 ) ,
Margin = new BorderDouble ( right : 2 , top : 1 , bottom : 1 ) ,
Border = new BorderDouble ( 1 ) ,
BackgroundColor = theme . MinimalShade . WithAlpha ( 10 ) ,
BorderColor = theme . SlightShade ,
Width = 200
} ;
statusBar . AddChild ( stretchStatusPanel ) ;
2018-11-06 16:07:29 -08:00
var panelBackgroundColor = theme . MinimalShade . WithAlpha ( 10 ) ;
statusBar . AddChild (
this . CreateThemeStatusPanel ( theme , panelBackgroundColor ) ) ;
2018-11-05 12:44:28 -08:00
2018-11-06 16:08:13 -08:00
statusBar . AddChild (
this . CreateNetworkStatusPanel ( theme ) ) ;
2018-11-05 12:44:28 -08:00
this . RenderRunningTasks ( theme , tasks ) ;
2018-10-10 14:58:37 -07:00
UpdateControlData . Instance . UpdateStatusChanged . RegisterEvent ( ( s , e ) = >
{
SetLinkButtonsVisibility ( s , new StringEventArgs ( "Unknown" ) ) ;
} , ref unregisterEvents ) ;
2018-11-12 17:20:59 -08:00
void Printer_SettingChanged ( object s , EventArgs e )
2018-10-10 14:58:37 -07:00
{
var activePrinter = ApplicationController . Instance . ActivePrinter ;
if ( e is StringEventArgs stringEvent
& & stringEvent . Data = = SettingsKey . printer_name
& & printerTab ! = null )
{
printerTab . Text = activePrinter . Settings . GetValue ( SettingsKey . printer_name ) ;
}
2018-11-12 17:20:59 -08:00
}
printer . Settings . SettingChanged + = Printer_SettingChanged ;
2018-11-15 16:16:49 -08:00
this . Closed + = ( s , e ) = > printer . Settings . SettingChanged - = Printer_SettingChanged ;
2018-10-10 14:58:37 -07:00
2018-11-11 21:25:50 -08:00
ApplicationController . Instance . OpenPrintersChanged + = OpenPrinters_Changed ;
2018-10-10 14:58:37 -07:00
2018-11-11 21:25:50 -08:00
ApplicationController . Instance . MainView = this ;
}
private void OpenPrinters_Changed ( object sender , OpenPrintersChangedEventArgs e )
{
var activePrinter = e . Printer ;
2018-10-18 16:25:35 -07:00
2018-11-11 21:25:50 -08:00
if ( e . Operation = = OpenPrintersChangedEventArgs . OperationType . Add )
{
2018-10-18 16:25:35 -07:00
if ( activePrinter . Settings . PrinterSelected )
2018-10-10 14:58:37 -07:00
{
2018-10-18 16:25:35 -07:00
// Create and switch to new printer tab
tabControl . ActiveTab = this . CreatePrinterTab ( activePrinter , theme ) ;
2018-11-11 21:25:50 -08:00
tabControl . RefreshTabPointers ( ) ;
2018-10-10 14:58:37 -07:00
}
2018-11-11 21:25:50 -08:00
}
else
{
// Close existing printer tabs
if ( tabControl . AllTabs . FirstOrDefault ( t = > t . TabContent is PrinterTabPage printerTab
& & printerTab . printer . Settings . ID = = activePrinter . Settings . ID ) is ITab tab
& & tab . TabContent is PrinterTabPage printerPage )
{
tabControl . RemoveTab ( tab ) ;
tabControl . RefreshTabPointers ( ) ;
}
}
2017-08-07 14:19:28 -07:00
}
2018-11-06 16:08:13 -08:00
private GuiWidget CreateNetworkStatusPanel ( ThemeConfig theme )
{
var networkStatus = new GuiWidget ( )
{
HAnchor = HAnchor . Absolute ,
VAnchor = VAnchor . Stretch ,
Padding = new BorderDouble ( right : 3 ) ,
Margin = new BorderDouble ( right : 2 , top : 1 , bottom : 1 ) ,
Border = new BorderDouble ( 1 ) ,
BackgroundColor = theme . MinimalShade . WithAlpha ( 10 ) ,
BorderColor = theme . SlightShade ,
Width = 120
} ;
if ( ApplicationController . ServicesStatusType ! = null )
{
var instance = Activator . CreateInstance ( ApplicationController . ServicesStatusType ) ;
if ( instance is GuiWidget guiWidget )
{
guiWidget . HAnchor = HAnchor . Stretch ;
guiWidget . VAnchor = VAnchor . Stretch ;
networkStatus . AddChild ( guiWidget ) ;
}
}
return networkStatus ;
}
2018-11-06 16:07:29 -08:00
private GuiWidget CreateThemeStatusPanel ( ThemeConfig theme , Color panelBackgroundColor )
{
var themePanel = new GuiWidget ( )
{
HAnchor = HAnchor . Absolute ,
VAnchor = VAnchor . Stretch ,
Padding = new BorderDouble ( right : 3 ) ,
Margin = new BorderDouble ( right : 2 , top : 1 , bottom : 1 ) ,
Border = new BorderDouble ( 1 ) ,
BackgroundColor = panelBackgroundColor ,
BorderColor = theme . SlightShade ,
Cursor = Cursors . Hand ,
ToolTipText = "Theme" . Localize ( ) ,
Width = 40
} ;
themePanel . AddChild (
new ImageWidget ( AggContext . StaticData . LoadIcon ( "theme.png" , 16 , 16 , theme . InvertIcons ) , false )
{
HAnchor = HAnchor . Left | HAnchor . Absolute ,
VAnchor = VAnchor . Center | VAnchor . Absolute ,
Selectable = false
} ) ;
themePanel . AddChild (
new ColorButton ( theme . PrimaryAccentColor )
{
HAnchor = HAnchor . Right | HAnchor . Absolute ,
VAnchor = VAnchor . Center | VAnchor . Absolute ,
Width = 12 ,
Height = 12 ,
Selectable = false
} ) ;
themePanel . Click + = ( s , e ) = >
{
themePanel . BackgroundColor = theme . DropList . Open . BackgroundColor ;
var menuTheme = AppContext . MenuTheme ;
var widget = new GuiWidget ( )
{
HAnchor = HAnchor . Absolute ,
VAnchor = VAnchor . Fit ,
2018-11-08 11:56:09 -08:00
Width = 650 ,
2018-11-06 16:07:29 -08:00
Border = 1 ,
BorderColor = theme . DropList . Open . BackgroundColor ,
// Padding = theme.DefaultContainerPadding,
BackgroundColor = menuTheme . BackgroundColor
} ;
widget . Closed + = ( s2 , e2 ) = >
{
themePanel . BackgroundColor = panelBackgroundColor ;
} ;
var section = ApplicationSettingsPage . CreateThemePanel ( menuTheme ) ;
widget . AddChild ( section ) ;
var systemWindow = this . Parents < SystemWindow > ( ) . FirstOrDefault ( ) ;
systemWindow . ShowPopup (
new MatePoint ( themePanel )
{
Mate = new MateOptions ( MateEdge . Right , MateEdge . Top ) ,
AltMate = new MateOptions ( MateEdge . Right , MateEdge . Top )
} ,
new MatePoint ( widget )
{
Mate = new MateOptions ( MateEdge . Right , MateEdge . Bottom ) ,
AltMate = new MateOptions ( MateEdge . Right , MateEdge . Bottom )
} ) ;
} ;
return themePanel ;
}
2018-05-24 23:09:38 -07:00
public ChromeTabs TabControl = > tabControl ;
2018-07-11 12:40:04 -07:00
private ChromeTab CreatePrinterTab ( PrinterConfig printer , ThemeConfig theme )
2017-09-15 09:23:53 -07:00
{
2018-05-08 15:47:00 -07:00
// Printer page is in fixed position
2018-10-12 15:47:07 -07:00
var tab1 = tabControl . AllTabs . FirstOrDefault ( ) ;
2018-05-08 15:47:00 -07:00
2018-05-16 14:35:15 -07:00
var printerTabPage = tab1 ? . TabContent as PrinterTabPage ;
2018-05-08 15:47:00 -07:00
if ( printerTabPage = = null
| | printerTabPage . printer ! = printer )
2018-05-08 08:53:37 -07:00
{
// TODO - call save before remove
// printerTabPage.sceneContext.SaveChanges();
2018-05-08 15:47:00 -07:00
if ( printerTabPage ! = null )
{
tabControl . RemoveTab ( tab1 ) ;
}
2018-05-08 08:53:37 -07:00
2018-05-08 15:47:00 -07:00
printerTab = new ChromeTab (
2018-09-07 14:49:26 -07:00
printer . Settings . GetValue ( SettingsKey . printer_name ) ,
2018-08-06 13:17:29 -07:00
printer . Settings . GetValue ( SettingsKey . printer_name ) ,
2018-05-08 15:47:00 -07:00
tabControl ,
2018-08-06 13:17:29 -07:00
new PrinterTabPage ( printer , theme , "unused_tab_title" ) ,
2018-05-08 15:47:00 -07:00
theme ,
2018-10-16 17:11:30 -07:00
tabImageUrl : ApplicationController . Instance . GetFavIconUrl ( oemName : printer . Settings . GetValue ( SettingsKey . make ) ) )
2018-05-08 15:47:00 -07:00
{
Name = "3D View Tab" ,
MinimumSize = new Vector2 ( 120 , theme . TabButtonHeight )
} ;
2018-04-17 17:13:18 -07:00
2018-10-16 17:11:30 -07:00
printerTab . CloseClicked + = ( s , e ) = >
{
2018-11-11 21:25:50 -08:00
ApplicationController . Instance . ClosePrinter ( printer ) ;
2018-10-16 17:11:30 -07:00
} ;
2018-11-12 17:20:59 -08:00
void Printer_SettingChanged ( object s , EventArgs e )
2018-08-06 13:17:29 -07:00
{
string settingsName = ( e as StringEventArgs ) ? . Data ;
if ( settingsName ! = null & & settingsName = = SettingsKey . printer_name )
{
printerTab . Title = printer . Settings . GetValue ( SettingsKey . printer_name ) ;
}
2018-11-12 17:20:59 -08:00
}
printer . Settings . SettingChanged + = Printer_SettingChanged ;
2018-11-15 16:16:49 -08:00
this . Closed + = ( s , e ) = > printer . Settings . SettingChanged - = Printer_SettingChanged ;
2018-08-06 13:17:29 -07:00
2018-05-08 15:47:00 -07:00
// Add printer into fixed position
2018-10-07 11:36:52 -07:00
if ( tabControl . AllTabs . Any ( ) )
{
2018-10-15 19:35:11 -07:00
tabControl . AddTab ( printerTab , 3 ) ;
2018-10-07 11:36:52 -07:00
}
else
{
tabControl . AddTab ( printerTab ) ;
}
2018-05-08 15:47:00 -07:00
return printerTab ;
}
else if ( printerTab ! = null )
{
tabControl . ActiveTab = tab1 ;
return tab1 as ChromeTab ;
}
2018-04-17 17:13:18 -07:00
2018-05-08 15:47:00 -07:00
return null ;
2017-09-15 09:23:53 -07:00
}
2018-10-15 20:08:15 -07:00
public async Task < ChromeTab > CreatePartTab ( )
{
2018-10-25 08:35:18 -07:00
var history = ApplicationController . Instance . Library . PlatingHistory ;
2018-10-15 20:08:15 -07:00
var workspace = new PartWorkspace ( )
{
Name = "New Design" . Localize ( ) + ( partCount = = 0 ? "" : $" ({partCount})" ) ,
2018-10-25 08:35:18 -07:00
SceneContext = new BedConfig ( history )
2018-10-15 20:08:15 -07:00
} ;
partCount + + ;
await workspace . SceneContext . LoadContent (
new EditContext ( )
{
2018-10-25 08:35:18 -07:00
ContentStore = ApplicationController . Instance . Library . PlatingHistory ,
SourceItem = history . NewPlatingItem ( )
2018-10-15 20:08:15 -07:00
} ) ;
ApplicationController . Instance . Workspaces . Add ( workspace ) ;
2018-10-18 14:36:59 -07:00
var newTab = CreatePartTab ( workspace ) ;
tabControl . ActiveTab = newTab ;
return newTab ;
2018-10-15 20:08:15 -07:00
}
public ChromeTab CreatePartTab ( PartWorkspace workspace )
2017-09-29 21:30:51 -07:00
{
2018-01-08 13:13:32 -08:00
var partTab = new ChromeTab (
2018-10-15 20:08:15 -07:00
workspace . Name ,
workspace . Name ,
2017-11-11 17:28:03 -08:00
tabControl ,
2018-10-15 20:08:15 -07:00
new PartTabPage ( null , workspace . SceneContext , theme , "" ) ,
2017-11-21 11:11:07 -08:00
theme ,
2018-06-25 08:12:49 -07:00
AggContext . StaticData . LoadIcon ( "cube.png" , 16 , 16 , theme . InvertIcons ) )
2017-11-11 17:28:03 -08:00
{
Name = "newPart" + tabControl . AllTabs . Count ( ) ,
2018-04-14 13:06:28 -07:00
MinimumSize = new Vector2 ( 120 , theme . TabButtonHeight )
2017-11-11 17:28:03 -08:00
} ;
2017-09-29 21:30:51 -07:00
2017-11-11 17:28:03 -08:00
tabControl . AddTab ( partTab ) ;
2017-09-29 21:30:51 -07:00
2018-10-16 17:11:30 -07:00
partTab . CloseClicked + = ( s , e ) = >
{
ApplicationController . Instance . Workspaces . Remove ( workspace ) ;
} ;
2017-09-29 21:30:51 -07:00
return partTab ;
}
2018-08-23 16:44:11 -07:00
public override void OnClosed ( EventArgs e )
2017-08-07 14:19:28 -07:00
{
unregisterEvents ? . Invoke ( this , null ) ;
base . OnClosed ( e ) ;
2017-05-24 19:11:51 -07:00
}
2018-11-05 12:44:28 -08:00
private void RenderRunningTasks ( ThemeConfig theme , RunningTasksConfig tasks )
{
var rows = tasksContainer . Children . OfType < RunningTaskStatusPanel > ( ) . ToList ( ) ;
var displayedTasks = new HashSet < RunningTaskDetails > ( rows . Select ( taskRow = > taskRow . taskDetails ) ) ;
var runningTasks = tasks . RunningTasks ;
// Remove expired items
foreach ( var row in rows )
{
if ( ! runningTasks . Contains ( row . taskDetails ) )
{
row . Close ( ) ;
}
}
var progressBackgroundColor = new Color ( theme . AccentMimimalOverlay , 35 ) ;
// Add new items
foreach ( var taskItem in tasks . RunningTasks . Where ( t = > ! displayedTasks . Contains ( t ) ) )
{
var runningTaskPanel = new RunningTaskStatusPanel ( "" , taskItem , theme )
{
HAnchor = HAnchor . Absolute ,
VAnchor = VAnchor . Stretch ,
2018-11-05 17:27:40 -08:00
Margin = new BorderDouble ( right : 2 , top : 1 , bottom : 1 ) ,
2018-11-05 12:44:28 -08:00
Border = new BorderDouble ( 1 ) ,
BorderColor = theme . SlightShade ,
ProgressBackgroundColor = progressBackgroundColor ,
Width = 200
} ;
tasksContainer . AddChild ( runningTaskPanel ) ;
}
tasksContainer . Invalidate ( ) ;
}
2015-04-08 15:20:10 -07:00
}
}