2014-03-17 14:41:26 -07:00
/ *
Copyright ( c ) 2014 , Kevin Pope
All rights reserved .
Redistribution and use in source and binary forms , with or without
modification , are permitted provided that the following conditions are met :
1. Redistributions of source code must retain the above copyright notice , this
list of conditions and the following disclaimer .
2. Redistributions in binary form must reproduce the above copyright notice ,
this list of conditions and the following disclaimer in the documentation
and / or other materials provided with the distribution .
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES
( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ;
LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies ,
either expressed or implied , of the FreeBSD Project .
* /
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Text ;
using MatterHackers.Agg ;
using MatterHackers.Agg.Transform ;
using MatterHackers.Agg.Image ;
using MatterHackers.Agg.VertexSource ;
using MatterHackers.Agg.UI ;
using MatterHackers.Agg.Font ;
using MatterHackers.VectorMath ;
using MatterHackers.MatterControl ;
using MatterHackers.MatterControl.PrintQueue ;
using MatterHackers.MatterControl.SlicerConfiguration ;
2014-12-08 18:18:38 -08:00
using MatterHackers.MatterControl.SettingsManagement ;
2014-03-17 14:41:26 -07:00
using MatterHackers.MatterControl.PrintLibrary ;
using MatterHackers.MatterControl.DataStorage ;
2014-04-10 19:08:02 -07:00
using MatterHackers.MatterControl.CustomWidgets ;
2014-03-17 14:41:26 -07:00
using MatterHackers.Localizations ;
using MatterHackers.MatterControl.PartPreviewWindow ;
2014-06-11 14:52:58 -07:00
using MatterHackers.MatterControl.PrinterCommunication ;
2014-03-17 14:41:26 -07:00
namespace MatterHackers.MatterControl
2014-04-19 10:35:53 -07:00
{
2014-08-19 11:41:13 -07:00
public class WidescreenPanel : FlowLayoutWidget
2014-04-24 12:51:01 -07:00
{
2014-12-15 15:44:26 -08:00
static readonly int ColumnOneFixedWidth = 590 ;
2014-07-03 09:49:16 -07:00
static int lastNumberOfVisiblePanels ;
2014-03-17 14:41:26 -07:00
TextImageButtonFactory advancedControlsButtonFactory = new TextImageButtonFactory ( ) ;
RGBA_Bytes unselectedTextColor = ActiveTheme . Instance . TabLabelUnselected ;
FlowLayoutWidget ColumnOne ;
FlowLayoutWidget ColumnTwo ;
2014-09-11 17:16:12 -07:00
double Force1PanelWidth = 990 * TextWidget . GlobalPointSizeScaleRatio ;
double Force2PanelWidth = 1590 * TextWidget . GlobalPointSizeScaleRatio ;
2014-03-17 14:41:26 -07:00
2014-12-15 14:04:27 -08:00
GuiWidget leftBorderLine ;
2014-04-16 12:01:01 -07:00
2014-04-27 16:16:47 -07:00
event EventHandler unregisterEvents ;
2014-09-18 17:06:45 -07:00
public static RootedObjectEventHandler PreChangePanels = new RootedObjectEventHandler ( ) ;
2014-07-02 19:35:35 -07:00
2014-04-16 12:01:01 -07:00
QueueDataView queueDataView = null ;
2014-04-11 13:41:34 -07:00
2014-03-17 14:41:26 -07:00
public WidescreenPanel ( )
: base ( FlowDirection . LeftToRight )
{
Name = "WidescreenPanel" ;
2014-04-27 16:16:47 -07:00
AnchorAll ( ) ;
BackgroundColor = ActiveTheme . Instance . PrimaryBackgroundColor ;
Padding = new BorderDouble ( 4 ) ;
2014-03-17 14:41:26 -07:00
ActivePrinterProfile . Instance . ActivePrinterChanged . RegisterEvent ( LoadSettingsOnPrinterChanged , ref unregisterEvents ) ;
2014-06-11 14:52:58 -07:00
PrinterConnectionAndCommunication . Instance . ActivePrintItemChanged . RegisterEvent ( onActivePrintItemChanged , ref unregisterEvents ) ;
2014-09-19 19:17:12 -07:00
ApplicationController . Instance . ReloadAdvancedControlsPanelTrigger . RegisterEvent ( ReloadAdvancedControlsPanelTrigger , ref unregisterEvents ) ;
2014-04-27 16:16:47 -07:00
this . BoundsChanged + = new EventHandler ( onBoundsChanges ) ;
}
2014-03-17 14:41:26 -07:00
2014-08-19 11:41:13 -07:00
public void ReloadAdvancedControlsPanelTrigger ( object sender , EventArgs e )
2014-08-10 12:30:49 -07:00
{
2014-08-19 11:41:13 -07:00
UiThread . RunOnIdle ( ReloadAdvancedControlsPanel ) ;
2014-08-10 12:30:49 -07:00
}
2014-04-27 16:16:47 -07:00
public override void OnParentChanged ( EventArgs e )
{
2014-07-03 09:49:16 -07:00
lastNumberOfVisiblePanels = 0 ;
2014-04-27 17:19:06 -07:00
RecreateAllPanels ( ) ;
2014-04-27 16:16:47 -07:00
base . OnParentChanged ( e ) ;
2014-03-17 14:41:26 -07:00
}
void onBoundsChanges ( Object sender , EventArgs e )
{
2014-07-03 09:49:16 -07:00
if ( NumberOfVisiblePanels ( ) ! = lastNumberOfVisiblePanels )
2014-04-27 16:16:47 -07:00
{
2014-04-27 17:19:06 -07:00
RecreateAllPanels ( ) ;
2014-04-27 16:16:47 -07:00
}
2014-03-17 14:41:26 -07:00
}
void onMouseEnterBoundsAdvancedControlsLink ( Object sender , EventArgs e )
{
HelpTextWidget . Instance . ShowHoverText ( "View Manual Printer Controls and Slicing Settings" ) ;
}
void onMouseLeaveBoundsAdvancedControlsLink ( Object sender , EventArgs e )
{
HelpTextWidget . Instance . HideHoverText ( ) ;
}
void onMouseEnterBoundsPrintQueueLink ( Object sender , EventArgs e )
{
HelpTextWidget . Instance . ShowHoverText ( "View Queue and Library" ) ;
}
void onMouseLeaveBoundsPrintQueueLink ( Object sender , EventArgs e )
{
HelpTextWidget . Instance . HideHoverText ( ) ;
}
public override void OnClosed ( EventArgs e )
{
if ( unregisterEvents ! = null )
{
unregisterEvents ( this , null ) ;
}
base . OnClosed ( e ) ;
}
void onActivePrintItemChanged ( object sender , EventArgs e )
{
2014-06-26 12:55:43 -07:00
if ( NumberOfVisiblePanels ( ) > 1 )
{
UiThread . RunOnIdle ( LoadColumnTwo ) ;
}
2014-03-17 14:41:26 -07:00
}
2015-01-07 16:11:12 -08:00
CompactSlidePanel compactSlidePanel ;
2014-04-15 18:13:27 -07:00
void LoadCompactView ( )
{
2014-04-16 12:01:01 -07:00
queueDataView = new QueueDataView ( ) ;
2014-04-15 18:13:27 -07:00
ColumnOne . RemoveAllChildren ( ) ;
ColumnOne . AddChild ( new ActionBarPlus ( queueDataView ) ) ;
2015-01-07 16:11:12 -08:00
compactSlidePanel = new CompactSlidePanel ( queueDataView ) ;
ColumnOne . AddChild ( compactSlidePanel ) ;
2014-04-15 18:13:27 -07:00
ColumnOne . AnchorAll ( ) ;
}
2014-04-17 13:23:44 -07:00
void LoadColumnTwo ( object state = null )
2014-04-27 16:16:47 -07:00
{
2015-01-07 12:44:39 -08:00
ColumnTwo . CloseAndRemoveAllChildren ( ) ;
2015-01-07 12:18:15 -08:00
2015-01-07 12:44:39 -08:00
PartPreviewContent partViewContent = new PartPreviewContent ( PrinterConnectionAndCommunication . Instance . ActivePrintItem , View3DWidget . WindowMode . Embeded , View3DWidget . AutoRotate . Enabled ) ;
partViewContent . AnchorAll ( ) ;
ColumnTwo . AddChild ( partViewContent ) ;
ColumnTwo . AnchorAll ( ) ;
2014-03-17 14:41:26 -07:00
}
2014-04-27 17:19:06 -07:00
int NumberOfVisiblePanels ( )
2014-04-19 10:35:53 -07:00
{
2014-09-11 17:16:12 -07:00
if ( this . Width < Force1PanelWidth )
2014-03-20 18:10:23 -07:00
{
2014-04-27 16:16:47 -07:00
return 1 ;
2014-03-20 18:10:23 -07:00
}
2014-12-15 15:44:26 -08:00
return 2 ;
2014-04-27 16:16:47 -07:00
}
2014-03-20 18:10:23 -07:00
2014-07-03 16:39:36 -07:00
public void RecreateAllPanels ( object state = null )
2014-04-27 16:16:47 -07:00
{
if ( Width = = 0 )
{
return ;
}
2014-03-20 18:10:23 -07:00
2014-04-27 17:19:06 -07:00
int numberOfPanels = NumberOfVisiblePanels ( ) ;
2014-03-20 18:10:23 -07:00
2014-09-18 17:06:45 -07:00
PreChangePanels . CallEvents ( this , null ) ;
2014-07-03 14:43:56 -07:00
RemovePanelsAndCreateEmpties ( ) ;
2014-04-27 17:19:06 -07:00
switch ( numberOfPanels )
2014-03-20 18:10:23 -07:00
{
2014-04-27 16:16:47 -07:00
case 1 :
2014-10-31 14:10:03 -07:00
ApplicationController . Instance . WidescreenMode = false ;
LoadCompactView ( ) ;
2014-04-27 17:19:06 -07:00
break ;
2014-10-31 14:10:03 -07:00
case 2 :
2014-12-15 15:44:26 -08:00
ApplicationController . Instance . WidescreenMode = false ;
LoadCompactView ( ) ;
LoadColumnTwo ( ) ;
2014-04-27 17:19:06 -07:00
break ;
}
2014-10-31 14:10:03 -07:00
SetColumnVisibility ( ) ;
2014-04-27 17:19:06 -07:00
2014-07-03 09:49:16 -07:00
lastNumberOfVisiblePanels = numberOfPanels ;
2014-04-27 17:19:06 -07:00
}
2014-05-05 09:07:46 -07:00
void SetColumnVisibility ( object state = null )
2014-04-27 17:19:06 -07:00
{
int numberOfPanels = NumberOfVisiblePanels ( ) ;
2014-04-27 16:16:47 -07:00
2014-04-27 17:19:06 -07:00
switch ( numberOfPanels )
{
case 1 :
{
2014-04-27 16:16:47 -07:00
ColumnTwo . Visible = false ;
ColumnOne . Visible = true ;
Padding = new BorderDouble ( 0 ) ;
2014-12-15 14:04:27 -08:00
leftBorderLine . Visible = false ;
2014-04-27 16:16:47 -07:00
}
break ;
case 2 :
2014-05-05 09:07:46 -07:00
Padding = new BorderDouble ( 4 ) ;
ColumnOne . Visible = true ;
2014-12-15 15:44:26 -08:00
ColumnTwo . Visible = true ;
2014-12-15 14:04:27 -08:00
ColumnOne . HAnchor = Agg . UI . HAnchor . None ;
2014-12-15 15:44:26 -08:00
ColumnOne . Width = ColumnOneFixedWidth ; // it can hold the slice settings so it needs to be bigger.
2015-01-07 16:11:12 -08:00
ColumnOne . MinimumSize = new Vector2 ( Math . Max ( compactSlidePanel . TabBarWidth , ColumnOneFixedWidth ) , 0 ) ; //Ordering here matters - must go after children are added
2014-04-27 16:16:47 -07:00
break ;
}
}
2014-04-11 13:41:34 -07:00
2014-04-27 16:16:47 -07:00
public override void OnDraw ( Graphics2D graphics2D )
{
base . OnDraw ( graphics2D ) ;
}
2014-03-20 15:54:27 -07:00
2014-04-27 17:19:06 -07:00
private void RemovePanelsAndCreateEmpties ( )
2014-04-27 16:16:47 -07:00
{
2014-07-01 18:18:27 -07:00
CloseAndRemoveAllChildren ( ) ;
2014-03-20 15:54:27 -07:00
2014-04-27 16:16:47 -07:00
ColumnOne = new FlowLayoutWidget ( FlowDirection . TopToBottom ) ;
ColumnTwo = new FlowLayoutWidget ( FlowDirection . TopToBottom ) ;
2014-03-17 14:41:26 -07:00
2014-04-27 16:16:47 -07:00
AddChild ( ColumnOne ) ;
2014-12-15 14:04:27 -08:00
leftBorderLine = new GuiWidget ( vAnchor : VAnchor . ParentBottomTop ) ;
leftBorderLine . Width = 15 ;
leftBorderLine . DrawBefore + = ( widget , graphics2D ) = >
{
RectangleDouble bounds = widget . LocalBounds ;
bounds . Left + = 3 ;
bounds . Right - = 8 ;
graphics2D . graphics2D . FillRectangle ( bounds , new RGBA_Bytes ( 160 , 160 , 160 ) ) ;
} ;
AddChild ( leftBorderLine ) ;
2014-04-27 16:16:47 -07:00
AddChild ( ColumnTwo ) ;
2014-03-17 14:41:26 -07:00
}
2014-08-10 12:30:49 -07:00
public void ReloadAdvancedControlsPanel ( object state )
2014-03-17 14:41:26 -07:00
{
2014-09-18 17:06:45 -07:00
PreChangePanels . CallEvents ( this , null ) ;
2014-03-17 14:41:26 -07:00
}
public void LoadSettingsOnPrinterChanged ( object sender , EventArgs e )
{
2014-04-08 19:33:09 -07:00
ActiveSliceSettings . Instance . LoadAllSettings ( ) ;
2014-10-18 13:23:53 -07:00
ApplicationController . Instance . ReloadAll ( null , null ) ;
2014-03-17 14:41:26 -07:00
}
2014-04-11 13:41:34 -07:00
}
2014-03-17 14:41:26 -07:00
class NotificationWidget : GuiWidget
{
public NotificationWidget ( )
: base ( 12 , 12 )
{
}
public override void OnDraw ( Graphics2D graphics2D )
{
graphics2D . Circle ( Width / 2 , Height / 2 , Width / 2 , RGBA_Bytes . White ) ;
graphics2D . Circle ( Width / 2 , Height / 2 , Width / 2 - 1 , RGBA_Bytes . Red ) ;
graphics2D . FillRectangle ( Width / 2 - 1 , Height / 2 - 3 , Width / 2 + 1 , Height / 2 + 3 , RGBA_Bytes . White ) ;
base . OnDraw ( graphics2D ) ;
}
}
}