2017-07-06 12:22:56 -07:00
/ *
2018-05-22 22:06:20 -07:00
Copyright ( c ) 2018 , Lars Brubaker , John Lewin
2017-07-06 12:22:56 -07:00
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 .
* /
2017-07-07 16:50:47 -07:00
using System ;
2017-07-10 12:32:41 -07:00
using System.Linq ;
2017-07-06 12:22:56 -07:00
using MatterHackers.Agg ;
2017-10-30 15:54:16 -07:00
using MatterHackers.Agg.Platform ;
2017-07-06 12:22:56 -07:00
using MatterHackers.Agg.UI ;
using MatterHackers.Localizations ;
2019-01-18 09:49:38 -08:00
using MatterHackers.MatterControl.ConfigurationPage.PrintLeveling ;
2017-07-06 12:22:56 -07:00
using MatterHackers.MatterControl.CustomWidgets ;
2017-10-30 15:54:16 -07:00
using MatterHackers.MatterControl.PrinterCommunication ;
2017-07-06 12:22:56 -07:00
using MatterHackers.MatterControl.SlicerConfiguration ;
using MatterHackers.MeshVisualizer ;
using MatterHackers.VectorMath ;
2019-01-18 09:49:38 -08:00
using static MatterHackers . MatterControl . StyledMessageBox ;
2017-07-06 12:22:56 -07:00
namespace MatterHackers.MatterControl.PartPreviewWindow
{
2017-11-07 14:55:45 -08:00
public class PrinterTabPage : PartTabPage
2017-07-06 12:22:56 -07:00
{
2017-07-10 12:23:02 -07:00
internal GCode2DWidget gcode2DWidget ;
2017-09-15 16:49:21 -07:00
2017-08-16 22:45:46 -07:00
private View3DConfig gcodeOptions ;
2017-07-06 14:41:32 -07:00
private DoubleSolidSlider layerRenderRatioSlider ;
2018-04-23 18:48:17 -07:00
public SliceLayerSelector LayerScrollbar { get ; private set ; }
2018-03-14 15:51:43 -07:00
private GCodePanel gcodePanel ;
2018-10-14 17:50:54 -07:00
internal VerticalResizeContainer gcodeContainer ;
2017-11-29 13:45:01 -08:00
internal PrinterActionsBar printerActionsBar ;
2018-01-03 15:24:55 -08:00
private DockingTabControl sideBar ;
private SliceSettingsWidget sliceSettingsWidget ;
2017-09-15 16:49:21 -07:00
2018-12-12 17:12:06 -08:00
public PrinterTabPage ( PartWorkspace workspace , ThemeConfig theme , string tabTitle )
: base ( workspace , theme , tabTitle )
2017-07-06 12:22:56 -07:00
{
2018-05-22 22:06:20 -07:00
gcodeOptions = sceneContext . RendererOptions ;
2018-04-12 08:42:10 -07:00
2019-01-31 07:33:42 -08:00
view3DWidget . InteractionLayer . EditorMode = InteractionLayer . EditorType . Printer ;
2017-08-17 10:52:47 -07:00
2017-07-10 12:23:02 -07:00
viewControls3D . TransformStateChanged + = ( s , e ) = >
{
switch ( e . TransformMode )
{
case ViewControls3DButtons . Translate :
if ( gcode2DWidget ! = null )
{
gcode2DWidget . TransformState = GCode2DWidget . ETransformState . Move ;
}
break ;
case ViewControls3DButtons . Scale :
if ( gcode2DWidget ! = null )
{
gcode2DWidget . TransformState = GCode2DWidget . ETransformState . Scale ;
}
break ;
}
} ;
2017-07-06 12:22:56 -07:00
viewControls3D . ResetView + = ( sender , e ) = >
{
2017-07-13 15:35:05 -07:00
if ( gcode2DWidget ? . Visible = = true )
2017-07-10 12:23:02 -07:00
{
gcode2DWidget . CenterPartInView ( ) ;
}
2017-07-06 12:22:56 -07:00
} ;
2017-11-27 17:36:36 -08:00
2018-10-21 11:29:59 -07:00
var opaqueTrackColor = theme . ResolveColor ( theme . BedBackgroundColor , theme . SlightShade ) ;
2019-02-01 16:12:50 -08:00
LayerScrollbar = new SliceLayerSelector ( printer , theme )
2017-07-07 16:50:47 -07:00
{
2017-09-13 15:55:12 -07:00
VAnchor = VAnchor . Stretch ,
2018-03-29 13:27:39 -07:00
HAnchor = HAnchor . Right | HAnchor . Fit ,
2018-02-21 18:43:56 -08:00
Margin = new BorderDouble ( 0 , 4 , 4 , 4 ) ,
2017-11-29 16:40:46 -08:00
Maximum = sceneContext . LoadedGCode ? . LayerCount ? ? 1
2017-07-06 14:41:32 -07:00
} ;
2018-10-21 11:29:59 -07:00
LayerScrollbar . SolidSlider . View . TrackColor = opaqueTrackColor ;
2018-04-23 18:48:17 -07:00
view3DWidget . InteractionLayer . AddChild ( LayerScrollbar ) ;
2018-01-03 15:24:55 -08:00
2018-10-15 18:25:53 -07:00
layerRenderRatioSlider = new DoubleSolidSlider ( new Vector2 ( ) , SliceLayerSelector . SliderWidth , theme ) ;
2017-07-06 14:41:32 -07:00
layerRenderRatioSlider . FirstValue = 0 ;
layerRenderRatioSlider . FirstValueChanged + = ( s , e ) = >
{
2017-09-15 16:49:21 -07:00
sceneContext . RenderInfo . FeatureToStartOnRatio0To1 = layerRenderRatioSlider . FirstValue ;
sceneContext . RenderInfo . FeatureToEndOnRatio0To1 = layerRenderRatioSlider . SecondValue ;
2017-07-06 14:41:32 -07:00
this . Invalidate ( ) ;
} ;
layerRenderRatioSlider . SecondValue = 1 ;
layerRenderRatioSlider . SecondValueChanged + = ( s , e ) = >
{
2017-09-01 17:41:43 -07:00
if ( printer ? . Bed ? . RenderInfo ! = null )
{
2017-09-15 16:49:21 -07:00
sceneContext . RenderInfo . FeatureToStartOnRatio0To1 = layerRenderRatioSlider . FirstValue ;
sceneContext . RenderInfo . FeatureToEndOnRatio0To1 = layerRenderRatioSlider . SecondValue ;
2017-09-01 17:41:43 -07:00
}
2017-07-06 14:41:32 -07:00
this . Invalidate ( ) ;
} ;
2018-02-17 10:42:58 -08:00
view3DWidget . InteractionLayer . AddChild ( layerRenderRatioSlider ) ;
2018-10-21 11:29:59 -07:00
theme . ApplySliderStyle ( layerRenderRatioSlider ) ;
layerRenderRatioSlider . View . TrackColor = opaqueTrackColor ;
2017-07-06 14:41:32 -07:00
2017-10-21 20:22:14 -07:00
AddSettingsTabBar ( leftToRight , view3DWidget ) ;
2017-07-07 12:52:00 -07:00
2018-02-20 15:23:55 -08:00
view3DWidget . InteractionLayer . BoundsChanged + = ( s , e ) = >
2017-08-16 22:45:46 -07:00
{
SetSliderSizes ( ) ;
} ;
2017-12-28 12:51:47 -08:00
printerActionsBar = new PrinterActionsBar ( printer , this , theme ) ;
2018-07-15 10:07:30 -07:00
theme . ApplyBottomBorder ( printerActionsBar ) ;
2018-02-07 18:43:09 -08:00
printerActionsBar . modelViewButton . Enabled = sceneContext . EditableScene ;
2017-10-19 09:04:36 -07:00
// Must come after we have an instance of View3DWidget an its undo buffer
topToBottom . AddChild ( printerActionsBar , 0 ) ;
2017-10-30 08:53:53 -07:00
var trackball = view3DWidget . InteractionLayer . Children < TrackballTumbleWidget > ( ) . FirstOrDefault ( ) ;
2018-03-09 08:04:33 -08:00
tumbleCubeControl = view3DWidget . InteractionLayer . Children < TumbleCubeControl > ( ) . FirstOrDefault ( ) ;
2017-10-30 08:53:53 -07:00
var position = view3DWidget . InteractionLayer . Children . IndexOf ( trackball ) ;
2018-03-14 15:49:00 -07:00
gcodePanel = new GCodePanel ( printer , sceneContext , theme )
2017-10-30 08:53:53 -07:00
{
2017-10-30 09:00:14 -07:00
Name = "GCode3DWidget" ,
2017-10-30 08:53:53 -07:00
HAnchor = HAnchor . Stretch ,
VAnchor = VAnchor . Stretch ,
2018-02-16 18:49:36 -08:00
BackgroundColor = theme . InteractionLayerOverlayColor ,
2017-10-30 08:53:53 -07:00
} ;
2018-02-16 18:49:36 -08:00
2018-10-14 17:50:54 -07:00
var modelViewSidePanel = view3DWidget . Descendants < VerticalResizeContainer > ( ) . FirstOrDefault ( ) ;
2018-04-18 09:36:53 -07:00
2018-10-14 17:50:54 -07:00
gcodeContainer = new VerticalResizeContainer ( theme , GrabBarSide . Left )
2018-02-16 18:49:36 -08:00
{
2018-04-18 09:36:53 -07:00
Width = printer ? . ViewState . SelectedObjectPanelWidth ? ? 200 ,
2018-02-16 18:49:36 -08:00
VAnchor = VAnchor . Stretch ,
2018-02-17 10:42:58 -08:00
HAnchor = HAnchor . Absolute ,
2018-10-25 14:43:21 -07:00
SplitterBarColor = theme . SplitterBackground ,
2018-02-16 18:49:36 -08:00
SplitterWidth = theme . SplitterWidth ,
Visible = false ,
} ;
2018-05-30 16:42:17 -07:00
2018-03-14 15:49:00 -07:00
gcodeContainer . AddChild ( gcodePanel ) ;
2018-05-30 16:42:17 -07:00
gcodeContainer . Resized + = ( s , e ) = >
{
if ( printer ! = null )
{
printer . ViewState . SelectedObjectPanelWidth = gcodeContainer . Width ;
}
} ;
2018-02-16 18:49:36 -08:00
2018-04-18 09:36:53 -07:00
modelViewSidePanel . BoundsChanged + = ( s , e ) = >
{
gcodeContainer . Width = modelViewSidePanel . Width ;
} ;
gcodeContainer . BoundsChanged + = ( s , e ) = >
{
modelViewSidePanel . Width = gcodeContainer . Width ;
} ;
2018-12-29 16:37:17 -08:00
var splitContainer = view3DWidget . FindDescendant ( "SplitContainer" ) ;
2018-02-17 10:42:58 -08:00
splitContainer . AddChild ( gcodeContainer ) ;
2017-10-30 08:53:53 -07:00
2018-12-05 13:48:25 -08:00
view3DContainer . AddChild ( new RunningTasksWidget ( theme , printer )
2017-12-11 14:15:50 -08:00
{
MinimumSize = new Vector2 ( 100 , 0 ) ,
2018-10-25 13:22:03 -07:00
Margin = new BorderDouble ( top : printerActionsBar . Height + 1 , left : favoritesBar . LocalBounds . Width + favoritesBar . DeviceMarginAndBorder . Width + 1 ) ,
2018-05-24 12:05:25 -07:00
VAnchor = VAnchor . Top | VAnchor . Fit ,
2017-12-11 14:15:50 -08:00
HAnchor = HAnchor . Left | HAnchor . Fit ,
} ) ;
2017-11-29 14:41:55 -08:00
// Create and append new widget
2018-07-12 09:22:28 -07:00
gcode2DWidget = new GCode2DWidget ( printer , theme )
2017-11-29 14:41:55 -08:00
{
Visible = ( printer . ViewState . ViewMode = = PartViewMode . Layers2D )
} ;
2018-03-09 08:04:33 -08:00
view3DWidget . InteractionLayer . AddChild ( gcode2DWidget , position + 1 ) ;
2017-11-29 14:41:55 -08:00
2017-08-16 22:45:46 -07:00
SetSliderSizes ( ) ;
2017-07-06 12:22:56 -07:00
2017-11-29 15:22:18 -08:00
this . SetViewMode ( printer . ViewState . ViewMode ) ;
2018-01-03 15:24:55 -08:00
2018-09-24 12:21:58 -07:00
this . LayerScrollbar . Margin = LayerScrollbar . Margin . Clone ( top : tumbleCubeControl . Height + tumbleCubeControl . Margin . Height + 4 ) ;
2018-11-27 12:55:30 -08:00
// Register listeners
2018-09-08 12:52:47 -07:00
printer . ViewState . VisibilityChanged + = ProcessOptionalTabs ;
2018-11-27 12:55:30 -08:00
printer . ViewState . ViewModeChanged + = ViewState_ViewModeChanged ;
2019-01-18 09:49:38 -08:00
2018-04-07 23:46:01 -07:00
printer . Bed . RendererOptions . PropertyChanged + = RendererOptions_PropertyChanged ;
2019-01-18 09:49:38 -08:00
// register for communication messages
2018-11-16 08:44:56 -08:00
printer . Connection . CommunicationStateChanged + = Connection_CommunicationStateChanged ;
2019-01-18 09:49:38 -08:00
printer . Connection . PauseOnLayer + = Connection_PauseOnLayer ;
printer . Connection . FilamentRunout + = Connection_FilamentRunout ;
2018-11-27 12:55:30 -08:00
ApplicationController . Instance . ApplicationError + = ApplicationController_ApplicationError ;
2018-11-30 12:35:56 -08:00
ApplicationController . Instance . ApplicationEvent + = ApplicationController_ApplicationEvent ;
2018-11-27 12:55:30 -08:00
sceneContext . LoadedGCodeChanged + = BedPlate_LoadedGCodeChanged ;
}
2019-01-18 09:49:38 -08:00
string pauseCaption = "Printer Paused" . Localize ( ) ;
private void ResumePrint ( bool clickedOk )
{
// They clicked either Resume or Ok
2019-02-06 10:34:19 -08:00
if ( clickedOk & & printer . Connection . Paused )
2019-01-18 09:49:38 -08:00
{
printer . Connection . Resume ( ) ;
}
}
protected GuiWidget CreateTextField ( string text )
{
return new WrappedTextWidget ( text )
{
Margin = new BorderDouble ( left : 10 , top : 10 ) ,
TextColor = theme . TextColor ,
HAnchor = HAnchor . Stretch
} ;
}
private void Connection_FilamentRunout ( object sender , PrintPauseEventArgs e )
{
if ( e is PrintPauseEventArgs printePauseEventArgs )
{
if ( printePauseEventArgs . filamentRunout )
{
2019-01-18 12:13:31 -08:00
UiThread . RunOnIdle ( ( ) = >
2019-01-18 09:49:38 -08:00
{
2019-01-18 12:13:31 -08:00
var unloadFilamentButton = new TextButton ( "Unload Filament" . Localize ( ) , theme )
{
Name = "unload Filament" ,
BackgroundColor = theme . MinimalShade ,
VAnchor = Agg . UI . VAnchor . Absolute ,
HAnchor = Agg . UI . HAnchor . Fit | Agg . UI . HAnchor . Left ,
Margin = new BorderDouble ( 10 , 10 , 0 , 15 )
} ;
2019-02-16 13:55:27 -08:00
unloadFilamentButton . Click + = ( s , e2 ) = > UiThread . RunOnIdle ( ( ) = >
2019-01-18 09:49:38 -08:00
{
2019-02-16 13:55:27 -08:00
unloadFilamentButton . Parents < SystemWindow > ( ) . First ( ) . Close ( ) ;
DialogWindow . Show ( new UnloadFilamentWizard ( printer , extruderIndex : 0 ) ) ;
} ) ;
2019-01-18 12:13:31 -08:00
theme . ApplyPrimaryActionStyle ( unloadFilamentButton ) ;
string filamentPauseMessage = "Your 3D print has been paused.\n\nOut of filament, or jam, detected. Please load more filament or clear the jam." . Localize ( ) ;
var messageBox = new MessageBoxPage ( ResumePrint ,
filamentPauseMessage . FormatWith ( printePauseEventArgs . layerNumber ) ,
pauseCaption ,
StyledMessageBox . MessageType . YES_NO_WITHOUT_HIGHLIGHT ,
null ,
500 ,
400 ,
"Resume" . Localize ( ) ,
"OK" . Localize ( ) ,
ApplicationController . Instance . Theme , false ) ;
messageBox . AddPageAction ( unloadFilamentButton ) ;
DialogWindow . Show ( messageBox ) ;
} ) ;
2019-01-18 09:49:38 -08:00
}
}
}
private void Connection_PauseOnLayer ( object sender , EventArgs e )
{
if ( e is PrintPauseEventArgs printePauseEventArgs )
{
string layerPauseMessage = "Your 3D print has been auto-paused.\n\nLayer{0} reached." . Localize ( ) ;
UiThread . RunOnIdle ( ( ) = > StyledMessageBox . ShowMessageBox ( ResumePrint ,
layerPauseMessage . FormatWith ( printePauseEventArgs . layerNumber ) ,
pauseCaption ,
StyledMessageBox . MessageType . YES_NO ,
"Resume" . Localize ( ) ,
"OK" . Localize ( ) ) ) ;
}
}
2018-11-30 12:35:56 -08:00
private void ApplicationController_ApplicationEvent ( object sender , string e )
{
printer . Connection . TerminalLog . WriteLine ( e ) ;
}
2018-11-27 12:55:30 -08:00
private void ApplicationController_ApplicationError ( object sender , string e )
{
printer . Connection . TerminalLog . WriteLine ( e ) ;
2018-01-03 15:24:55 -08:00
}
2018-04-07 23:46:01 -07:00
private void RendererOptions_PropertyChanged ( object sender , System . ComponentModel . PropertyChangedEventArgs e )
{
if ( e . PropertyName = = nameof ( printer . Bed . RendererOptions . SyncToPrint ) )
{
this . SetSliderVisibility ( ) ;
}
}
2018-04-02 12:59:18 -07:00
private void ViewState_ViewModeChanged ( object sender , ViewModeChangedEventArgs e )
{
this . SetViewMode ( e . ViewMode ) ;
}
2018-09-07 14:49:26 -07:00
private void ProcessOptionalTabs ( object sender , EventArgs e )
2018-01-03 15:24:55 -08:00
{
2018-09-07 14:49:26 -07:00
this . ProcessOptionalTabs ( ) ;
2017-11-29 15:22:18 -08:00
}
2017-07-06 12:22:56 -07:00
2017-11-29 15:22:18 -08:00
private void SetViewMode ( PartViewMode viewMode )
2017-08-16 22:45:46 -07:00
{
2018-03-14 15:49:00 -07:00
if ( gcodePanel = = null | | gcode2DWidget = = null )
2017-07-06 12:22:56 -07:00
{
2017-11-29 15:22:18 -08:00
// Wait for controls to initialize
return ;
}
2017-07-06 12:22:56 -07:00
2017-11-29 15:22:18 -08:00
switch ( viewMode )
{
case PartViewMode . Layers2D :
2018-04-18 14:38:09 -07:00
UserSettings . Instance . set ( UserSettingsKey . LayerViewDefault , "2D Layer" ) ;
2017-11-29 15:22:18 -08:00
gcode2DWidget . Visible = true ;
break ;
case PartViewMode . Layers3D :
2018-04-18 14:38:09 -07:00
UserSettings . Instance . set ( UserSettingsKey . LayerViewDefault , "3D Layer" ) ;
2017-11-29 15:22:18 -08:00
break ;
case PartViewMode . Model :
break ;
}
2017-07-06 12:22:56 -07:00
2017-11-29 15:22:18 -08:00
gcode2DWidget . Visible = viewMode = = PartViewMode . Layers2D ;
2017-07-06 12:22:56 -07:00
2019-02-04 16:17:31 -08:00
view3DWidget . InteractionLayer . DrawOpenGLContent = printer ? . ViewState . ViewMode ! = PartViewMode . Layers2D ;
2019-02-06 09:31:07 -08:00
sceneContext . ViewState . ModelView = viewMode = = PartViewMode . Model ;
2018-03-09 08:04:33 -08:00
gcodeContainer . Visible = viewMode ! = PartViewMode . Model ;
tumbleCubeControl . Visible = ! gcode2DWidget . Visible ;
2018-02-16 18:49:36 -08:00
2018-03-09 08:04:33 -08:00
if ( viewMode = = PartViewMode . Layers3D )
2017-11-29 15:22:18 -08:00
{
printer . Bed . Scene . ClearSelection ( ) ;
2017-08-16 22:45:46 -07:00
}
2017-11-29 15:22:18 -08:00
2018-02-16 15:50:33 -08:00
this . SetSliderVisibility ( ) ;
2017-11-29 15:22:18 -08:00
2018-04-05 15:59:16 -07:00
view3DWidget . modelViewSidePanel . Visible = printer ? . ViewState . ViewMode = = PartViewMode . Model ;
2017-07-06 12:22:56 -07:00
}
2017-07-06 14:41:32 -07:00
private void BedPlate_LoadedGCodeChanged ( object sender , EventArgs e )
{
2018-02-16 15:50:33 -08:00
this . SetSliderVisibility ( ) ;
2017-10-17 12:55:58 -07:00
2018-02-16 15:50:33 -08:00
if ( sceneContext . LoadedGCode = = null )
2017-10-17 12:55:58 -07:00
{
return ;
}
2018-04-23 18:48:17 -07:00
LayerScrollbar . Maximum = sceneContext . LoadedGCode . LayerCount ;
2017-07-06 14:41:32 -07:00
}
2018-02-16 15:50:33 -08:00
private void SetSliderVisibility ( )
2017-07-06 12:22:56 -07:00
{
2019-02-06 10:34:19 -08:00
bool printerIsRunningPrint = printer . Connection . Paused | | printer . Connection . Printing ;
2017-07-06 12:22:56 -07:00
2017-08-16 22:45:46 -07:00
if ( gcodeOptions . SyncToPrint & & printerIsRunningPrint )
2017-07-06 12:22:56 -07:00
{
2017-08-16 22:45:46 -07:00
SetAnimationPosition ( ) ;
layerRenderRatioSlider . Visible = false ;
2018-04-23 18:48:17 -07:00
LayerScrollbar . Visible = false ;
2017-07-06 12:22:56 -07:00
}
else
{
2017-08-16 22:45:46 -07:00
if ( layerRenderRatioSlider ! = null )
{
layerRenderRatioSlider . FirstValue = 0 ;
layerRenderRatioSlider . SecondValue = 1 ;
}
2017-07-06 12:22:56 -07:00
2018-02-16 15:50:33 -08:00
bool hasLayers = printer . Bed . LoadedGCode ? . LayerCount > 0 ;
2018-05-09 08:41:29 -07:00
layerRenderRatioSlider . Visible = hasLayers & & ! sceneContext . ViewState . ModelView ;
LayerScrollbar . Visible = hasLayers & & ! sceneContext . ViewState . ModelView ;
2017-08-16 22:45:46 -07:00
}
2017-07-06 12:22:56 -07:00
}
2017-08-16 22:45:46 -07:00
private void SetSliderSizes ( )
2017-07-06 14:41:32 -07:00
{
2018-04-23 18:48:17 -07:00
if ( LayerScrollbar = = null | | view3DWidget = = null )
2017-07-06 14:41:32 -07:00
{
2017-08-16 22:45:46 -07:00
return ;
}
2017-07-06 14:41:32 -07:00
2018-02-21 18:43:56 -08:00
layerRenderRatioSlider . OriginRelativeParent = new Vector2 ( 4 , 13 ) ;
layerRenderRatioSlider . TotalWidthInPixels = view3DWidget . InteractionLayer . Width - 32 ;
2017-07-06 12:22:56 -07:00
}
2017-10-21 20:22:14 -07:00
2018-04-04 15:58:57 -07:00
private double lastPosition = 0 ;
2018-03-09 08:04:33 -08:00
private TumbleCubeControl tumbleCubeControl ;
2018-02-16 15:50:33 -08:00
private bool SetAnimationPosition ( )
2017-07-07 06:18:58 -07:00
{
2018-04-23 18:48:17 -07:00
LayerScrollbar . Value = printer . Connection . CurrentlyPrintingLayer ;
2018-02-16 15:50:33 -08:00
double currentPosition = printer . Connection . RatioIntoCurrentLayer ;
2018-02-16 14:20:15 -08:00
layerRenderRatioSlider . FirstValue = 0 ;
2018-02-16 15:50:33 -08:00
2018-04-04 15:58:57 -07:00
if ( lastPosition ! = currentPosition )
2018-02-16 15:50:33 -08:00
{
layerRenderRatioSlider . SecondValue = currentPosition ;
2018-04-04 15:58:57 -07:00
lastPosition = currentPosition ;
2018-02-16 15:50:33 -08:00
return true ;
}
return false ;
2017-07-10 12:32:41 -07:00
}
2018-01-21 21:07:14 -08:00
internal void ShowGCodeOverflowMenu ( PopupMenu popupMenu )
2017-07-06 14:41:32 -07:00
{
}
2017-08-16 22:45:46 -07:00
public override void OnDraw ( Graphics2D graphics2D )
2017-07-06 14:41:32 -07:00
{
2019-02-06 10:34:19 -08:00
bool printerIsRunningPrint = printer . Connection . Paused | | printer . Connection . Printing ;
2017-08-16 22:45:46 -07:00
if ( gcodeOptions . SyncToPrint
& & printerIsRunningPrint
2018-03-14 15:55:41 -07:00
& & printer . ViewState . ViewMode ! = PartViewMode . Model )
2017-07-06 14:41:32 -07:00
{
2018-02-16 15:50:33 -08:00
if ( this . SetAnimationPosition ( ) )
{
this . Invalidate ( ) ;
}
2017-08-16 22:45:46 -07:00
}
base . OnDraw ( graphics2D ) ;
}
2018-01-21 21:07:14 -08:00
protected override void GetViewControls3DOverflowMenu ( PopupMenu popupMenu )
2017-08-16 22:45:46 -07:00
{
2018-03-14 13:14:01 -07:00
if ( printer ? . ViewState . ViewMode ! = PartViewMode . Model )
2017-08-16 22:45:46 -07:00
{
2018-03-16 17:44:44 -07:00
view3DWidget . ShowBedViewOptions ( popupMenu ) ;
2018-01-21 21:07:14 -08:00
this . ShowGCodeOverflowMenu ( popupMenu ) ;
2017-07-06 14:41:32 -07:00
}
else
{
2018-01-21 21:07:14 -08:00
view3DWidget . ShowOverflowMenu ( popupMenu ) ;
2017-08-16 22:45:46 -07:00
}
}
2017-07-06 14:41:32 -07:00
2018-08-23 16:44:11 -07:00
public override void OnClosed ( EventArgs e )
2017-07-06 14:41:32 -07:00
{
2018-11-16 08:44:56 -08:00
// Unregister listeners
2017-09-15 16:49:21 -07:00
sceneContext . LoadedGCodeChanged - = BedPlate_LoadedGCodeChanged ;
2018-11-16 08:44:56 -08:00
printer . Connection . CommunicationStateChanged - = Connection_CommunicationStateChanged ;
2019-01-18 09:49:38 -08:00
printer . Connection . PauseOnLayer - = Connection_PauseOnLayer ;
printer . Connection . FilamentRunout - = Connection_FilamentRunout ;
2018-09-08 12:52:47 -07:00
printer . ViewState . VisibilityChanged - = ProcessOptionalTabs ;
2018-04-02 12:59:18 -07:00
printer . ViewState . ViewModeChanged - = ViewState_ViewModeChanged ;
2018-04-07 23:46:01 -07:00
printer . Bed . RendererOptions . PropertyChanged - = RendererOptions_PropertyChanged ;
2018-11-27 12:55:30 -08:00
ApplicationController . Instance . ApplicationError - = ApplicationController_ApplicationError ;
2018-11-30 12:35:56 -08:00
ApplicationController . Instance . ApplicationEvent - = ApplicationController_ApplicationEvent ;
2017-07-06 14:41:32 -07:00
2017-08-16 22:45:46 -07:00
base . OnClosed ( e ) ;
2017-07-06 14:41:32 -07:00
}
2017-08-16 22:45:46 -07:00
private void AddSettingsTabBar ( GuiWidget parent , GuiWidget widgetTodockTo )
{
2018-07-12 09:22:28 -07:00
sideBar = new DockingTabControl ( widgetTodockTo , DockSide . Right , printer , theme )
2017-08-16 22:45:46 -07:00
{
2017-12-27 13:45:47 -08:00
Name = "DockingTabControl" ,
2018-10-14 17:50:54 -07:00
ControlIsPinned = printer . ViewState . SliceSettingsTabPinned ,
MinDockingWidth = 400 * ( int ) GuiWidget . DeviceScale
2017-08-16 22:45:46 -07:00
} ;
sideBar . PinStatusChanged + = ( s , e ) = >
{
2018-07-12 09:22:28 -07:00
printer . ViewState . SliceSettingsTabPinned = sideBar . ControlIsPinned ;
2017-08-16 22:45:46 -07:00
} ;
parent . AddChild ( sideBar ) ;
2017-10-19 10:50:40 -07:00
sideBar . AddPage (
2018-09-07 14:49:26 -07:00
"Slice Settings" ,
2017-10-21 20:22:14 -07:00
"Slice Settings" . Localize ( ) ,
2018-01-03 15:24:55 -08:00
sliceSettingsWidget = new SliceSettingsWidget (
2017-10-21 20:22:14 -07:00
printer ,
2017-10-19 10:50:40 -07:00
new SettingsContext (
printer ,
2017-10-21 20:22:14 -07:00
null ,
2017-10-31 14:37:28 -07:00
NamedSettingsLayers . All ) ,
theme ) ) ;
2017-08-16 22:45:46 -07:00
2018-09-07 14:49:26 -07:00
this . ProcessOptionalTabs ( ) ;
}
private void ProcessOptionalTabs ( )
{
sideBar . RemovePage ( "Controls" , false ) ;
sideBar . RemovePage ( "Terminal" , false ) ;
sideBar . RemovePage ( "Printer" , false ) ;
2017-08-16 22:45:46 -07:00
2018-09-07 14:49:26 -07:00
if ( printer . ViewState . ControlsVisible )
2017-08-24 17:09:10 -07:00
{
2018-09-07 14:49:26 -07:00
sideBar . AddPage ( "Controls" , "Controls" . Localize ( ) , new ManualPrinterControls ( printer , theme ) , false ) ;
}
2018-01-03 15:24:55 -08:00
2018-09-07 14:49:26 -07:00
if ( printer . ViewState . TerminalVisible )
{
2018-10-15 18:25:53 -07:00
sideBar . AddPage ( "Terminal" ,
"Terminal" . Localize ( ) ,
2018-09-07 14:49:26 -07:00
new TerminalWidget ( printer , theme )
{
VAnchor = VAnchor . Stretch ,
HAnchor = HAnchor . Stretch
2018-10-15 18:25:53 -07:00
} ,
2018-09-07 14:49:26 -07:00
false ) ;
}
2018-01-03 15:24:55 -08:00
2018-07-12 09:22:28 -07:00
if ( printer . ViewState . ConfigurePrinterVisible )
2018-01-03 15:24:55 -08:00
{
sideBar . AddPage (
2018-10-15 18:25:53 -07:00
"Printer" ,
2018-01-03 15:24:55 -08:00
"Printer" . Localize ( ) ,
2018-01-14 10:36:05 -08:00
new ConfigurePrinterWidget ( sliceSettingsWidget . settingsContext , printer , theme )
2018-01-03 15:24:55 -08:00
{
HAnchor = HAnchor . Stretch ,
VAnchor = VAnchor . Stretch ,
2018-09-07 14:49:26 -07:00
} ,
false ) ;
2018-01-03 15:24:55 -08:00
}
2018-09-07 14:49:26 -07:00
sideBar . Rebuild ( ) ;
2017-07-06 14:41:32 -07:00
}
2017-10-30 15:54:16 -07:00
2018-11-16 08:44:56 -08:00
private void Connection_CommunicationStateChanged ( object s , EventArgs e )
{
this . SetSliderVisibility ( ) ;
}
2018-04-12 08:42:10 -07:00
public static GuiWidget PrintProgressWidget ( PrinterConfig printer , ThemeConfig theme )
2017-10-30 15:54:16 -07:00
{
2017-12-11 22:22:56 -08:00
var bodyRow = new GuiWidget ( )
2017-10-30 15:54:16 -07:00
{
2018-09-21 13:29:39 -07:00
HAnchor = HAnchor . Stretch ,
2017-12-11 22:22:56 -08:00
VAnchor = VAnchor . Top | VAnchor . Fit ,
2018-07-12 09:22:28 -07:00
//BackgroundColor = new Color(theme.Colors.PrimaryBackgroundColor, 128),
2017-12-11 22:22:56 -08:00
MinimumSize = new Vector2 ( 275 , 140 ) ,
2017-10-30 15:54:16 -07:00
} ;
// Progress section
var expandingContainer = new HorizontalSpacer ( )
{
VAnchor = VAnchor . Fit | VAnchor . Center
} ;
bodyRow . AddChild ( expandingContainer ) ;
var progressContainer = new FlowLayoutWidget ( FlowDirection . TopToBottom )
{
VAnchor = VAnchor . Center | VAnchor . Fit ,
2018-09-21 13:29:39 -07:00
HAnchor = HAnchor . Stretch ,
2017-10-30 15:54:16 -07:00
} ;
expandingContainer . AddChild ( progressContainer ) ;
2018-10-15 18:25:53 -07:00
var progressDial = new ProgressDial ( theme )
2017-10-30 15:54:16 -07:00
{
HAnchor = HAnchor . Center ,
Height = 200 * DeviceScale ,
Width = 200 * DeviceScale
} ;
progressContainer . AddChild ( progressDial ) ;
2018-09-21 13:29:39 -07:00
var bottomRow = new GuiWidget ( )
{
HAnchor = HAnchor . Stretch ,
VAnchor = VAnchor . Fit
} ;
progressContainer . AddChild ( bottomRow ) ;
2017-10-30 15:54:16 -07:00
var timeContainer = new FlowLayoutWidget ( )
{
HAnchor = HAnchor . Center | HAnchor . Fit ,
Margin = 3
} ;
2018-09-21 13:29:39 -07:00
bottomRow . AddChild ( timeContainer ) ;
// we can only reslice on 64 bit, because in 64 bit we always have the gcode loaded
if ( IntPtr . Size = = 8 )
{
var resliceButton = new TextButton ( "Re-Slice" , theme )
{
HAnchor = HAnchor . Right ,
VAnchor = VAnchor . Center ,
2018-10-03 18:19:35 -07:00
Margin = new BorderDouble ( 0 , 0 , 7 , 0 ) ,
Name = "Re-Slice Button"
2018-09-21 13:29:39 -07:00
} ;
bool activelySlicing = false ;
resliceButton . Click + = ( s , e ) = >
{
resliceButton . Enabled = false ;
UiThread . RunOnIdle ( async ( ) = >
{
2019-01-03 16:58:05 -08:00
bool doSlicing = ! activelySlicing & & printer . Bed . EditContext . SourceItem ! = null ;
if ( doSlicing )
{
2019-01-04 18:25:33 -08:00
var errors = printer . ValidateSettings ( ) ;
2019-01-17 16:33:09 -08:00
if ( errors . Any ( err = > err . ErrorLevel = = ValidationErrorLevel . Error ) )
2019-01-03 16:58:05 -08:00
{
doSlicing = false ;
2019-01-04 18:05:10 -08:00
ApplicationController . Instance . ShowValidationErrors ( "Slicing Error" . Localize ( ) , errors ) ;
2019-01-03 16:58:05 -08:00
}
}
2019-01-04 17:09:42 -08:00
2019-01-03 16:58:05 -08:00
if ( doSlicing )
2018-09-21 13:29:39 -07:00
{
activelySlicing = true ;
if ( bottomRow . Name = = null )
{
2018-11-14 14:28:29 -08:00
bottomRow . Name = printer . Bed . EditContext . GCodeFilePath ( printer ) ;
2018-09-21 13:29:39 -07:00
}
2018-11-08 08:13:08 -08:00
2018-12-05 13:48:25 -08:00
await ApplicationController . Instance . Tasks . Execute ( "Saving" . Localize ( ) , printer , printer . Bed . SaveChanges ) ;
2018-11-08 08:13:08 -08:00
// start up a new slice on a background thread
2018-09-21 13:29:39 -07:00
await ApplicationController . Instance . SliceItemLoadOutput (
printer ,
printer . Bed . Scene ,
2018-11-14 14:28:29 -08:00
printer . Bed . EditContext . GCodeFilePath ( printer ) ) ;
2018-11-08 08:13:08 -08:00
2018-09-21 13:29:39 -07:00
// Switch to the 3D layer view if on Model view
if ( printer . ViewState . ViewMode = = PartViewMode . Model )
{
printer . ViewState . ViewMode = PartViewMode . Layers3D ;
}
2018-11-08 08:13:08 -08:00
2018-09-21 13:29:39 -07:00
// when it is done queue it to the change to gcode stream
var message2 = "Would you like to switch to the new G-Code? Before you switch, check that your are seeing the changes you expect." . Localize ( ) ;
var caption2 = "Switch to new G-Code?" . Localize ( ) ;
StyledMessageBox . ShowMessageBox ( async ( clickedOk2 ) = >
{
if ( clickedOk2 )
{
if ( printer . Connection ! = null
2019-02-06 10:34:19 -08:00
& & ( printer . Connection . Printing | | printer . Connection . Paused ) )
2018-09-21 13:29:39 -07:00
{
2018-11-14 14:28:29 -08:00
printer . Connection . SwitchToGCode ( printer . Bed . EditContext . GCodeFilePath ( printer ) ) ;
bottomRow . Name = printer . Bed . EditContext . GCodeFilePath ( printer ) ;
2018-09-21 13:29:39 -07:00
}
}
else
{
await ApplicationController . Instance . SliceItemLoadOutput (
printer ,
printer . Bed . Scene ,
bottomRow . Name ) ;
}
activelySlicing = false ;
resliceButton . Enabled = true ;
} , message2 , caption2 , StyledMessageBox . MessageType . YES_NO , "Switch" . Localize ( ) , "Cancel" . Localize ( ) ) ;
}
else
{
resliceButton . Enabled = true ;
}
} ) ;
} ;
bottomRow . AddChild ( resliceButton ) ;
}
2017-10-30 15:54:16 -07:00
2018-04-12 08:42:10 -07:00
timeContainer . AddChild ( new ImageWidget ( AggContext . StaticData . LoadIcon ( "fa-clock_24.png" , theme . InvertIcons ) )
2017-10-30 15:54:16 -07:00
{
2018-01-18 15:26:49 -08:00
VAnchor = VAnchor . Center
} ) ;
2017-10-30 15:54:16 -07:00
2018-11-03 09:13:07 -07:00
var timeWidget = new TextWidget ( "" , pointSize : 22 , textColor : theme . TextColor )
2017-10-30 15:54:16 -07:00
{
AutoExpandBoundsToText = true ,
Margin = new BorderDouble ( 10 , 0 , 0 , 0 ) ,
VAnchor = VAnchor . Center ,
} ;
timeContainer . AddChild ( timeWidget ) ;
2018-04-11 17:35:34 -07:00
var runningInterval = UiThread . SetInterval (
2018-03-20 18:25:40 -07:00
( ) = >
{
int secondsPrinted = printer . Connection . SecondsPrinted ;
int hoursPrinted = ( int ) ( secondsPrinted / ( 60 * 60 ) ) ;
int minutesPrinted = ( secondsPrinted / 60 - hoursPrinted * 60 ) ;
2018-02-16 15:50:33 -08:00
2018-03-20 18:25:40 -07:00
secondsPrinted = secondsPrinted % 60 ;
2017-10-30 15:54:16 -07:00
2018-03-20 18:25:40 -07:00
// TODO: Consider if the consistency of a common time format would look and feel better than changing formats based on elapsed duration
timeWidget . Text = ( hoursPrinted < = 0 ) ? $"{minutesPrinted}:{secondsPrinted:00}" : $"{hoursPrinted}:{minutesPrinted:00}:{secondsPrinted:00}" ;
2017-10-30 15:54:16 -07:00
2018-03-20 18:25:40 -07:00
progressDial . LayerIndex = printer . Connection . CurrentlyPrintingLayer ;
progressDial . LayerCompletedRatio = printer . Connection . RatioIntoCurrentLayer ;
progressDial . CompletedRatio = printer . Connection . PercentComplete / 100 ;
2017-10-30 15:54:16 -07:00
switch ( printer . Connection . CommunicationState )
{
case CommunicationStates . PreparingToPrint :
case CommunicationStates . Printing :
case CommunicationStates . Paused :
bodyRow . Visible = true ;
break ;
default :
bodyRow . Visible = false ;
break ;
}
2018-04-11 17:35:34 -07:00
} , 1 ) ;
2018-11-13 16:52:23 -08:00
bodyRow . Closed + = ( s , e ) = > UiThread . ClearInterval ( runningInterval ) ;
2017-10-30 15:54:16 -07:00
bodyRow . Visible = false ;
return bodyRow ;
}
2017-08-16 22:45:46 -07:00
}
2017-07-06 12:22:56 -07:00
}