2014-01-29 19:09:30 -08:00
/ *
2017-05-24 19:11:51 -07:00
Copyright ( c ) 2017 , Lars Brubaker , John Lewin
2014-01-29 19:09:30 -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-01-29 19:09:30 -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-01-29 19:09:30 -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-01-29 19:09:30 -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-01-29 19:09:30 -08:00
either expressed or implied , of the FreeBSD Project .
* /
2017-05-24 19:11:51 -07:00
using System ;
using System.IO ;
2014-01-29 19:09:30 -08:00
using MatterHackers.Agg ;
2014-07-01 18:32:39 -07:00
using MatterHackers.Agg.UI ;
2015-04-08 15:20:10 -07:00
using MatterHackers.GCodeVisualizer ;
2014-02-04 13:30:42 -08:00
using MatterHackers.Localizations ;
2014-06-11 14:52:58 -07:00
using MatterHackers.MatterControl.PrinterCommunication ;
2014-04-15 18:13:27 -07:00
using MatterHackers.MatterControl.PrintQueue ;
using MatterHackers.MatterControl.SlicerConfiguration ;
2014-06-11 14:52:58 -07:00
using MatterHackers.MeshVisualizer ;
2014-04-15 18:13:27 -07:00
using MatterHackers.VectorMath ;
2014-01-29 19:09:30 -08:00
namespace MatterHackers.MatterControl.PartPreviewWindow
{
2015-04-08 15:20:10 -07:00
public class ViewGcodeBasic : PartPreview3DWidget
{
public enum WindowMode { Embeded , StandAlone } ;
2017-05-25 17:58:20 -07:00
public SolidSlider selectLayerSlider ;
2015-04-08 15:20:10 -07:00
2017-05-25 17:58:20 -07:00
private SetLayerWidget setLayerWidget ;
private LayerNavigationWidget navigationWidget ;
public DoubleSolidSlider layerRenderRatioSlider ;
2015-04-08 15:20:10 -07:00
private TextWidget gcodeProcessingStateInfoText ;
private ViewGcodeWidget gcodeViewWidget ;
2017-06-16 18:04:47 -07:00
private PrintItemWrapper printItem = > ApplicationController . Instance . ActivePrintItem ;
2015-04-08 15:20:10 -07:00
private bool startedSliceFromGenerateButton = false ;
private Button generateGCodeButton ;
private FlowLayoutWidget buttonBottomPanel ;
private FlowLayoutWidget layerSelectionButtonsPanel ;
private ViewControlsToggle viewControlsToggle ;
private GuiWidget gcodeDisplayWidget ;
2015-05-22 15:07:48 -07:00
private ColorGradientWidget gradientWidget ;
2015-04-13 11:04:17 -07:00
2015-04-08 15:20:10 -07:00
private EventHandler unregisterEvents ;
private WindowMode windowMode ;
2017-06-20 14:56:36 -07:00
private string partToStartLoadingOnFirstDraw = null ;
private string gcodeLoading = "Loading G-Code" . Localize ( ) ;
2015-04-08 15:20:10 -07:00
public delegate Vector2 GetSizeFunction ( ) ;
2017-03-01 13:48:49 -08:00
private string slicingErrorMessage = "Slicing Error.\nPlease review your slice settings." . Localize ( ) ;
private string pressGenerateMessage = "Press 'generate' to view layers" . Localize ( ) ;
private string fileNotFoundMessage = "File not found on disk." . Localize ( ) ;
private string fileTooBigToLoad = "GCode file too big to preview ({0})." . Localize ( ) ;
2015-04-08 15:20:10 -07:00
private Vector2 bedCenter ;
private Vector3 viewerVolume ;
2016-06-16 10:22:38 -07:00
private BedShape bedShape ;
2015-04-08 15:20:10 -07:00
private int sliderWidth ;
2017-05-26 20:07:42 -07:00
private PartViewMode activeViewMode = PartViewMode . Layers3D ;
2017-06-24 10:30:11 -07:00
private View3DConfig options ;
2017-06-19 09:17:57 -07:00
2017-06-24 10:30:11 -07:00
private PrinterConfig printer ;
2017-06-24 08:32:09 -07:00
2017-06-19 09:17:57 -07:00
public ViewGcodeBasic ( Vector3 viewerVolume , Vector2 bedCenter , BedShape bedShape , WindowMode windowMode , ViewControls3D viewControls3D , ThemeConfig theme )
2017-05-25 17:58:20 -07:00
: base ( viewControls3D )
2015-04-08 15:20:10 -07:00
{
2017-06-24 10:30:11 -07:00
options = ApplicationController . Instance . Options . View3D ;
printer = ApplicationController . Instance . Printer ;
2017-06-19 09:17:57 -07:00
2015-04-08 15:20:10 -07:00
this . viewerVolume = viewerVolume ;
this . bedShape = bedShape ;
this . bedCenter = bedCenter ;
this . windowMode = windowMode ;
2017-02-16 14:00:21 -08:00
if ( UserSettings . Instance . IsTouchScreen )
2015-04-08 15:20:10 -07:00
{
sliderWidth = 20 ;
}
else
{
sliderWidth = 10 ;
}
2015-06-11 12:06:40 -07:00
CreateAndAddChildren ( ) ;
2015-04-08 15:20:10 -07:00
2016-12-06 16:22:28 -08:00
ActiveSliceSettings . SettingChanged . RegisterEvent ( CheckSettingChanged , ref unregisterEvents ) ;
2017-06-24 10:45:02 -07:00
// TODO: Why do we clear GCode on AdvancedControlsPanelReloading - assume some slice settings should invalidate. If so, code should be more specific and bound to slice settings changed
ApplicationController . Instance . AdvancedControlsPanelReloading . RegisterEvent ( ( s , e ) = > printer . BedPlate . GCodeRenderer ? . Clear3DGCode ( ) , ref unregisterEvents ) ;
2017-05-24 19:11:51 -07:00
}
2017-03-15 16:17:06 -07:00
2017-06-24 10:30:11 -07:00
private GCodeFile loadedGCode = > printer . BedPlate . LoadedGCode ;
2016-04-26 17:15:10 -07:00
private void CheckSettingChanged ( object sender , EventArgs e )
{
StringEventArgs stringEvent = e as StringEventArgs ;
if ( stringEvent ! = null )
{
2017-06-24 10:30:11 -07:00
if ( loadedGCode ! = null
2016-07-18 10:52:36 -07:00
& & (
stringEvent . Data = = SettingsKey . filament_cost
| | stringEvent . Data = = SettingsKey . filament_diameter
| | stringEvent . Data = = SettingsKey . filament_density )
)
{
UpdateMassText ( ) ;
UpdateEstimatedCost ( ) ;
}
2016-06-21 09:38:37 -07:00
if ( stringEvent . Data = = SettingsKey . bed_size
| | stringEvent . Data = = SettingsKey . print_center
| | stringEvent . Data = = SettingsKey . build_height
2017-06-08 14:42:32 -07:00
| | stringEvent . Data = = SettingsKey . bed_shape )
2016-04-26 17:15:10 -07:00
{
2017-05-25 17:58:20 -07:00
viewerVolume = new Vector3 ( ActiveSliceSettings . Instance . GetValue < Vector2 > ( SettingsKey . bed_size ) , ActiveSliceSettings . Instance . GetValue < double > ( SettingsKey . build_height ) ) ;
bedShape = ActiveSliceSettings . Instance . GetValue < BedShape > ( SettingsKey . bed_shape ) ;
bedCenter = ActiveSliceSettings . Instance . GetValue < Vector2 > ( SettingsKey . print_center ) ;
2017-03-15 16:17:06 -07:00
2017-05-25 17:58:20 -07:00
double buildHeight = ActiveSliceSettings . Instance . GetValue < double > ( SettingsKey . build_height ) ;
2017-03-15 16:17:06 -07:00
2017-05-25 17:58:20 -07:00
UiThread . RunOnIdle ( ( ) = >
2017-05-26 20:07:42 -07:00
{
meshViewerWidget . CreatePrintBed (
viewerVolume ,
bedCenter ,
bedShape ) ;
} ) ;
2017-05-25 17:58:20 -07:00
}
else if ( stringEvent . Data = = "extruder_offset" )
2017-03-15 16:17:06 -07:00
{
2017-06-24 10:45:02 -07:00
printer . BedPlate . GCodeRenderer . Clear3DGCode ( ) ;
2017-03-15 16:17:06 -07:00
}
}
}
2015-06-11 12:06:40 -07:00
private void CreateAndAddChildren ( )
2015-04-08 15:20:10 -07:00
{
2016-01-12 11:20:27 -08:00
CloseAllChildren ( ) ;
2017-06-02 06:45:04 -07:00
2017-06-24 10:28:33 -07:00
var buttonFactory = ApplicationController . Instance . Theme . BreadCrumbButtonFactory ;
2017-06-02 06:45:04 -07:00
if ( meshViewerWidget ! = null )
{
meshViewerWidget . Closed - = MeshViewerWidget_Closed ;
meshViewerWidget . TrackballTumbleWidget . DrawGlContent - = TrackballTumbleWidget_DrawGlContent ;
}
meshViewerWidget = null ;
2015-04-08 15:20:10 -07:00
gcodeViewWidget = null ;
gcodeProcessingStateInfoText = null ;
FlowLayoutWidget mainContainerTopToBottom = new FlowLayoutWidget ( FlowDirection . TopToBottom ) ;
mainContainerTopToBottom . HAnchor = Agg . UI . HAnchor . Max_FitToChildren_ParentWidth ;
mainContainerTopToBottom . VAnchor = Agg . UI . VAnchor . Max_FitToChildren_ParentHeight ;
buttonBottomPanel = new FlowLayoutWidget ( FlowDirection . LeftToRight ) ;
buttonBottomPanel . HAnchor = HAnchor . ParentLeftRight ;
buttonBottomPanel . Padding = new BorderDouble ( 3 , 3 ) ;
buttonBottomPanel . BackgroundColor = ActiveTheme . Instance . PrimaryBackgroundColor ;
2017-06-24 10:28:33 -07:00
generateGCodeButton = buttonFactory . Generate ( "Generate" . Localize ( ) ) ;
2016-03-03 16:57:43 -08:00
generateGCodeButton . Name = "Generate Gcode Button" ;
2017-05-24 19:11:51 -07:00
generateGCodeButton . Click + = ( s , e ) = >
{
UiThread . RunOnIdle ( ( ) = >
{
if ( ActiveSliceSettings . Instance . PrinterSelected )
{
2017-06-05 09:27:30 -07:00
// Save any pending changes before starting the print
ApplicationController . Instance . ActiveView3DWidget . PersistPlateIfNeeded ( ) . ContinueWith ( ( t ) = >
2017-05-24 19:11:51 -07:00
{
2017-06-05 09:27:30 -07:00
if ( ActiveSliceSettings . Instance . IsValid ( ) & & printItem ! = null )
{
generateGCodeButton . Visible = false ;
SlicingQueue . Instance . QueuePartForSlicing ( printItem ) ;
startedSliceFromGenerateButton = true ;
}
} ) ;
2017-05-24 19:11:51 -07:00
}
else
{
StyledMessageBox . ShowMessageBox ( null , "Oops! Please select a printer in order to continue slicing." , "Select Printer" , StyledMessageBox . MessageType . OK ) ;
}
} ) ;
} ;
2015-04-08 15:20:10 -07:00
buttonBottomPanel . AddChild ( generateGCodeButton ) ;
layerSelectionButtonsPanel = new FlowLayoutWidget ( FlowDirection . RightToLeft ) ;
layerSelectionButtonsPanel . HAnchor = HAnchor . ParentLeftRight ;
layerSelectionButtonsPanel . Padding = new BorderDouble ( 0 ) ;
GuiWidget holdPanelOpen = new GuiWidget ( 1 , generateGCodeButton . Height ) ;
layerSelectionButtonsPanel . AddChild ( holdPanelOpen ) ;
if ( windowMode = = WindowMode . StandAlone )
{
2017-06-24 10:28:33 -07:00
Button closeButton = buttonFactory . Generate ( "Close" . Localize ( ) ) ;
2015-04-08 15:20:10 -07:00
layerSelectionButtonsPanel . AddChild ( closeButton ) ;
closeButton . Click + = ( sender , e ) = >
{
CloseOnIdle ( ) ;
} ;
}
2017-02-01 16:39:24 -08:00
gcodeDisplayWidget = new GuiWidget ( )
{
HAnchor = HAnchor . ParentLeftRight ,
VAnchor = VAnchor . ParentBottomTop
} ;
2016-01-20 10:12:01 -08:00
string firstProcessingMessage = "Press 'Add' to select an item." . Localize ( ) ;
2017-05-25 17:58:20 -07:00
if ( printItem ! = null )
{
firstProcessingMessage = "Loading G-Code..." . Localize ( ) ;
if ( Path . GetExtension ( printItem . FileLocation ) . ToUpper ( ) = = ".GCODE" )
{
gcodeDisplayWidget . AddChild ( CreateGCodeViewWidget ( printItem . FileLocation ) ) ;
}
else
{
if ( File . Exists ( printItem . FileLocation ) )
{
string gcodePathAndFileName = printItem . GetGCodePathAndFileName ( ) ;
bool gcodeFileIsComplete = printItem . IsGCodeFileComplete ( gcodePathAndFileName ) ;
if ( printItem . SlicingHadError )
{
firstProcessingMessage = slicingErrorMessage ;
}
else
{
firstProcessingMessage = pressGenerateMessage ;
}
if ( File . Exists ( gcodePathAndFileName ) & & gcodeFileIsComplete )
{
gcodeDisplayWidget . AddChild ( CreateGCodeViewWidget ( gcodePathAndFileName ) ) ;
}
// we only hook these up to make sure we can regenerate the gcode when we want
printItem . SlicingOutputMessage + = sliceItem_SlicingOutputMessage ;
printItem . SlicingDone + = sliceItem_Done ;
}
else
{
firstProcessingMessage = string . Format ( "{0}\n'{1}'" , fileNotFoundMessage , printItem . Name ) ;
}
}
}
else
{
generateGCodeButton . Visible = false ;
}
2015-04-08 15:20:10 -07:00
SetProcessingMessage ( firstProcessingMessage ) ;
2017-06-24 08:32:09 -07:00
mainContainerTopToBottom . AddChild ( gcodeDisplayWidget ) ;
2015-04-08 15:20:10 -07:00
// add in a spacer
2017-02-01 16:39:24 -08:00
layerSelectionButtonsPanel . AddChild ( new GuiWidget ( )
{
HAnchor = HAnchor . ParentLeftRight
} ) ;
2015-04-08 15:20:10 -07:00
buttonBottomPanel . AddChild ( layerSelectionButtonsPanel ) ;
mainContainerTopToBottom . AddChild ( buttonBottomPanel ) ;
this . AddChild ( mainContainerTopToBottom ) ;
2017-06-02 06:45:04 -07:00
meshViewerWidget = new MeshViewerWidget ( viewerVolume , bedCenter , bedShape , "" )
{
Visible = ( activeViewMode = = PartViewMode . Layers3D ) ,
AllowBedRenderingWhenEmpty = true
} ;
2015-04-08 15:20:10 -07:00
meshViewerWidget . AnchorAll ( ) ;
gcodeDisplayWidget . AddChild ( meshViewerWidget ) ;
2017-06-02 06:45:04 -07:00
meshViewerWidget . TrackballTumbleWidget . DrawGlContent + = TrackballTumbleWidget_DrawGlContent ;
meshViewerWidget . Closed + = MeshViewerWidget_Closed ;
// Apply active world view if initialized
if ( ApplicationController . Instance . PartPreviewState . RotationMatrix ! = Matrix4X4 . Identity )
{
meshViewerWidget . World . RotationMatrix = ApplicationController . Instance . PartPreviewState . RotationMatrix ;
meshViewerWidget . World . TranslationMatrix = ApplicationController . Instance . PartPreviewState . TranslationMatrix ;
}
2015-04-08 15:20:10 -07:00
2015-11-09 12:36:47 -08:00
viewControls3D . ResetView + = ( sender , e ) = >
{
2017-05-26 21:28:35 -07:00
if ( gcodeDisplayWidget . Visible )
{
gcodeViewWidget . CenterPartInView ( ) ;
}
else
{
meshViewerWidget . ResetView ( ) ;
}
2015-11-09 12:36:47 -08:00
} ;
2015-05-29 15:13:56 -07:00
viewControls3D . ActiveButton = ViewControls3DButtons . Rotate ;
2014-07-01 19:29:13 -07:00
2017-06-02 06:45:04 -07:00
viewControlsToggle = new ViewControlsToggle ( ApplicationController . Instance . Theme . ViewControlsButtonFactory , activeViewMode )
{
Visible = false ,
HAnchor = HAnchor . ParentRight
} ;
2015-04-08 15:20:10 -07:00
AddChild ( viewControlsToggle ) ;
2017-05-26 21:28:35 -07:00
viewControls3D . TransformStateChanged + = ( s , e ) = >
2015-04-08 15:20:10 -07:00
{
2017-05-26 21:28:35 -07:00
switch ( e . TransformMode )
{
case ViewControls3DButtons . Translate :
2017-05-27 17:48:32 -07:00
if ( gcodeViewWidget ! = null )
{
gcodeViewWidget . TransformState = ViewGcodeWidget . ETransformState . Move ;
}
2017-05-26 21:28:35 -07:00
meshViewerWidget . TrackballTumbleWidget . TransformState = TrackBallController . MouseDownType . Translation ;
break ;
case ViewControls3DButtons . Scale :
2017-05-27 17:48:32 -07:00
if ( gcodeViewWidget ! = null )
{
gcodeViewWidget . TransformState = ViewGcodeWidget . ETransformState . Scale ;
}
2017-05-26 21:28:35 -07:00
meshViewerWidget . TrackballTumbleWidget . TransformState = TrackBallController . MouseDownType . Scale ;
break ;
case ViewControls3DButtons . Rotate :
meshViewerWidget . TrackballTumbleWidget . TransformState = TrackBallController . MouseDownType . Rotation ;
break ;
}
2015-04-08 15:20:10 -07:00
} ;
}
2017-06-02 06:45:04 -07:00
private void MeshViewerWidget_Closed ( object sender , ClosedEventArgs e )
{
if ( meshViewerWidget . Visible )
{
ApplicationController . Instance . PartPreviewState . RotationMatrix = meshViewerWidget . World . RotationMatrix ;
ApplicationController . Instance . PartPreviewState . TranslationMatrix = meshViewerWidget . World . TranslationMatrix ;
}
}
2015-04-08 15:20:10 -07:00
private RenderType GetRenderType ( )
{
2017-06-24 08:32:09 -07:00
var options = ApplicationController . Instance . Options . View3D ;
2015-04-08 15:20:10 -07:00
RenderType renderType = RenderType . Extrusions ;
2017-06-24 08:32:09 -07:00
if ( options . RenderMoves )
2015-04-08 15:20:10 -07:00
{
renderType | = RenderType . Moves ;
}
2017-06-24 08:32:09 -07:00
if ( options . RenderRetractions )
2015-04-08 15:20:10 -07:00
{
renderType | = RenderType . Retractions ;
}
2017-06-24 08:32:09 -07:00
if ( options . RenderSpeeds )
2015-04-08 15:20:10 -07:00
{
renderType | = RenderType . SpeedColors ;
}
2017-06-24 08:32:09 -07:00
if ( options . SimulateExtrusion )
2017-05-25 17:58:20 -07:00
{
renderType | = RenderType . SimulateExtrusion ;
}
2017-06-24 08:32:09 -07:00
if ( options . TransparentExtrusion )
2017-05-25 17:58:20 -07:00
{
renderType | = RenderType . TransparentExtrusion ;
}
2017-06-24 08:32:09 -07:00
if ( options . HideExtruderOffsets )
2015-04-08 15:20:10 -07:00
{
renderType | = RenderType . HideExtruderOffsets ;
}
return renderType ;
}
private void TrackballTumbleWidget_DrawGlContent ( object sender , EventArgs e )
{
2017-06-24 10:38:08 -07:00
if ( loadedGCode = = null | | printer . BedPlate . GCodeRenderer = = null )
2017-05-26 15:40:48 -07:00
{
return ;
}
2015-04-08 15:20:10 -07:00
GCodeRenderer . ExtrusionColor = ActiveTheme . Instance . PrimaryAccentColor ;
GCodeRenderInfo renderInfo = new GCodeRenderInfo ( 0 ,
2017-06-24 10:30:11 -07:00
Math . Min ( gcodeViewWidget . ActiveLayerIndex + 1 , loadedGCode . NumChangesInZ ) ,
2015-04-08 15:20:10 -07:00
gcodeViewWidget . TotalTransform ,
1 ,
GetRenderType ( ) ,
gcodeViewWidget . FeatureToStartOnRatio0To1 ,
gcodeViewWidget . FeatureToEndOnRatio0To1 ,
2017-06-21 23:26:20 -07:00
new Vector2 [ ] { ActiveSliceSettings . Instance . Helpers . ExtruderOffset ( 0 ) , ActiveSliceSettings . Instance . Helpers . ExtruderOffset ( 1 ) } ,
MeshViewerWidget . GetMaterialColor ) ;
2015-04-08 15:20:10 -07:00
2017-06-24 10:38:08 -07:00
printer . BedPlate . GCodeRenderer . Render3D ( renderInfo ) ;
2015-04-08 15:20:10 -07:00
}
2017-05-25 17:58:20 -07:00
private void SetAnimationPosition ( )
{
2017-06-13 17:22:49 -07:00
int currentLayer = PrinterConnection . Instance . CurrentlyPrintingLayer ;
2017-05-25 17:58:20 -07:00
if ( currentLayer < = 0 )
{
selectLayerSlider . Value = 0 ;
layerRenderRatioSlider . SecondValue = 0 ;
layerRenderRatioSlider . FirstValue = 0 ;
}
else
{
selectLayerSlider . Value = currentLayer - 1 ;
2017-06-13 17:22:49 -07:00
layerRenderRatioSlider . SecondValue = PrinterConnection . Instance . RatioIntoCurrentLayer ;
2017-05-25 17:58:20 -07:00
layerRenderRatioSlider . FirstValue = 0 ;
}
}
2015-04-08 15:20:10 -07:00
2017-06-24 08:32:09 -07:00
private FlowLayoutWidget CreateModelInfo ( )
2015-04-08 15:20:10 -07:00
{
2017-06-24 08:32:09 -07:00
var modelInfoContainer = new FlowLayoutWidget ( FlowDirection . TopToBottom )
{
Padding = new BorderDouble ( 5 ) ,
Margin = new BorderDouble ( 0 , 0 , 35 , 5 ) ,
BackgroundColor = new RGBA_Bytes ( 0 , 0 , 0 , ViewControlsBase . overlayAlpha ) ,
HAnchor = HAnchor . ParentRight | HAnchor . AbsolutePosition ,
VAnchor = VAnchor . ParentTop | VAnchor . FitToChildren ,
Width = 150
} ;
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
// put in the print time
2017-06-24 08:32:09 -07:00
modelInfoContainer . AddChild ( new TextWidget ( "Print Time" . Localize ( ) + ":" , textColor : ActiveTheme . Instance . PrimaryTextColor , pointSize : 9 ) ) ;
2015-04-08 15:20:10 -07:00
{
string timeRemainingText = "---" ;
2017-06-24 10:30:11 -07:00
if ( gcodeViewWidget ! = null & & loadedGCode ! = null )
2015-04-08 15:20:10 -07:00
{
2017-06-24 10:30:11 -07:00
int secondsRemaining = ( int ) loadedGCode . Instruction ( 0 ) . secondsToEndFromHere ;
2015-04-08 15:20:10 -07:00
int hoursRemaining = ( int ) ( secondsRemaining / ( 60 * 60 ) ) ;
int minutesRemaining = ( int ) ( ( secondsRemaining + 30 ) / 60 - hoursRemaining * 60 ) ; // +30 for rounding
secondsRemaining = secondsRemaining % 60 ;
if ( hoursRemaining > 0 )
{
2017-06-24 08:32:09 -07:00
timeRemainingText = $"{hoursRemaining} h, {minutesRemaining} min" ;
2015-04-08 15:20:10 -07:00
}
else
{
2017-06-24 08:32:09 -07:00
timeRemainingText = $"{minutesRemaining} min" ;
2015-04-08 15:20:10 -07:00
}
}
2017-06-24 08:32:09 -07:00
GuiWidget estimatedPrintTime = new TextWidget ( timeRemainingText , textColor : ActiveTheme . Instance . PrimaryTextColor , pointSize : 14 ) ;
2015-04-08 15:20:10 -07:00
estimatedPrintTime . Margin = new BorderDouble ( 0 , 9 , 0 , 3 ) ;
modelInfoContainer . AddChild ( estimatedPrintTime ) ;
}
// show the filament used
2017-06-24 08:32:09 -07:00
modelInfoContainer . AddChild ( new TextWidget ( "Filament Length" . Localize ( ) + ":" , textColor : ActiveTheme . Instance . PrimaryTextColor , pointSize : 9 ) ) ;
2015-04-08 15:20:10 -07:00
{
2017-06-24 10:30:11 -07:00
double filamentUsed = loadedGCode . GetFilamentUsedMm ( ActiveSliceSettings . Instance . GetValue < double > ( SettingsKey . filament_diameter ) ) ;
2015-04-08 15:20:10 -07:00
GuiWidget estimatedPrintTime = new TextWidget ( string . Format ( "{0:0.0} mm" , filamentUsed ) , pointSize : 14 , textColor : ActiveTheme . Instance . PrimaryTextColor ) ;
estimatedPrintTime . Margin = new BorderDouble ( 0 , 9 , 0 , 3 ) ;
modelInfoContainer . AddChild ( estimatedPrintTime ) ;
}
2014-01-29 19:09:30 -08:00
2017-06-24 08:32:09 -07:00
modelInfoContainer . AddChild ( new TextWidget ( "Filament Volume" . Localize ( ) + ":" , textColor : ActiveTheme . Instance . PrimaryTextColor , pointSize : 9 ) ) ;
2015-04-08 15:20:10 -07:00
{
2017-06-24 10:30:11 -07:00
double filamentMm3 = loadedGCode . GetFilamentCubicMm ( ActiveSliceSettings . Instance . GetValue < double > ( SettingsKey . filament_diameter ) ) ;
2014-01-29 19:09:30 -08:00
2016-08-17 15:34:04 -07:00
GuiWidget estimatedPrintTime = new TextWidget ( string . Format ( "{0:0.00} cm³" , filamentMm3 / 1000 ) , pointSize : 14 , textColor : ActiveTheme . Instance . PrimaryTextColor ) ;
2015-04-08 15:20:10 -07:00
estimatedPrintTime . Margin = new BorderDouble ( 0 , 9 , 0 , 3 ) ;
modelInfoContainer . AddChild ( estimatedPrintTime ) ;
}
2014-01-29 19:09:30 -08:00
2016-07-18 10:52:36 -07:00
modelInfoContainer . AddChild ( GetEstimatedMassInfo ( ) ) ;
modelInfoContainer . AddChild ( GetEstimatedCostInfo ( ) ) ;
2017-06-24 08:32:09 -07:00
// TODO: Every time you click Generate we wire up a listener - only when we close do they get released. This is a terrible pattern that has a good chance of creating a high leak scenario. Since RootedEventHandlers are normally only cleared when a widget is closed, we should **only** register them in widget constructors
2017-06-13 17:22:49 -07:00
PrinterConnection . Instance . CommunicationStateChanged . RegisterEvent ( HookUpGCodeMessagesWhenDonePrinting , ref unregisterEvents ) ;
2017-05-25 17:58:20 -07:00
2017-06-24 08:32:09 -07:00
return modelInfoContainer ;
2016-07-18 10:52:36 -07:00
}
2016-06-27 13:02:37 -07:00
2016-07-18 10:52:36 -07:00
double totalMass
{
get
2015-04-08 15:20:10 -07:00
{
2016-07-18 10:52:36 -07:00
double filamentDiameter = ActiveSliceSettings . Instance . GetValue < double > ( SettingsKey . filament_diameter ) ;
double filamentDensity = ActiveSliceSettings . Instance . GetValue < double > ( SettingsKey . filament_density ) ;
2016-06-27 13:02:37 -07:00
2017-06-24 10:30:11 -07:00
return loadedGCode . GetFilamentWeightGrams ( filamentDiameter , filamentDensity ) ;
2015-04-08 15:20:10 -07:00
}
2016-07-18 10:52:36 -07:00
}
2015-04-08 15:20:10 -07:00
2016-07-18 10:52:36 -07:00
double totalCost
{
get
2016-06-27 13:02:37 -07:00
{
2016-07-18 10:52:36 -07:00
double filamentCost = ActiveSliceSettings . Instance . GetValue < double > ( SettingsKey . filament_cost ) ;
return totalMass / 1000 * filamentCost ;
}
}
2016-06-27 13:02:37 -07:00
2016-07-18 10:52:36 -07:00
TextWidget massTextWidget ;
2016-07-05 12:24:00 -07:00
2016-07-18 10:52:36 -07:00
void UpdateMassText ( )
{
if ( totalMass ! = 0 )
{
massTextWidget . Text = string . Format ( "{0:0.00} g" , totalMass ) ;
}
else
{
massTextWidget . Text = "Unknown" ;
2016-06-27 13:02:37 -07:00
}
2016-07-18 10:52:36 -07:00
}
private GuiWidget GetEstimatedMassInfo ( )
{
FlowLayoutWidget estimatedMassInfo = new FlowLayoutWidget ( FlowDirection . TopToBottom ) ;
2017-05-26 00:59:47 -07:00
estimatedMassInfo . AddChild ( new TextWidget ( "Estimated Mass" . Localize ( ) + ":" , pointSize : 9 , textColor : ActiveTheme . Instance . PrimaryTextColor ) ) ;
2016-07-18 10:52:36 -07:00
massTextWidget = new TextWidget ( "" , pointSize : 14 , textColor : ActiveTheme . Instance . PrimaryTextColor )
{
AutoExpandBoundsToText = true ,
} ;
massTextWidget . Margin = new BorderDouble ( 0 , 9 , 0 , 3 ) ;
estimatedMassInfo . AddChild ( massTextWidget ) ;
2016-06-27 13:02:37 -07:00
2016-07-18 10:52:36 -07:00
UpdateMassText ( ) ;
2015-04-08 15:20:10 -07:00
2016-07-18 10:52:36 -07:00
return estimatedMassInfo ;
}
2015-04-08 15:20:10 -07:00
2016-07-18 10:52:36 -07:00
FlowLayoutWidget estimatedCostInfo ;
TextWidget costTextWidget ;
void UpdateEstimatedCost ( )
{
costTextWidget . Text = string . Format ( "${0:0.00}" , totalCost ) ;
if ( totalCost = = 0 )
{
estimatedCostInfo . Visible = false ;
}
else
{
estimatedCostInfo . Visible = true ;
}
}
private GuiWidget GetEstimatedCostInfo ( )
{
estimatedCostInfo = new FlowLayoutWidget ( FlowDirection . TopToBottom ) ;
string costLabel = "Estimated Cost" . Localize ( ) ;
string costLabelFull = string . Format ( "{0}:" , costLabel ) ;
estimatedCostInfo . AddChild ( new TextWidget ( costLabelFull , pointSize : 9 , textColor : ActiveTheme . Instance . PrimaryTextColor ) ) ;
costTextWidget = new TextWidget ( "" , pointSize : 14 , textColor : ActiveTheme . Instance . PrimaryTextColor )
{
AutoExpandBoundsToText = true ,
} ;
costTextWidget . Margin = new BorderDouble ( 0 , 9 , 0 , 3 ) ;
estimatedCostInfo . AddChild ( costTextWidget ) ;
2016-07-25 18:30:35 -07:00
UpdateEstimatedCost ( ) ;
2016-07-18 10:52:36 -07:00
return estimatedCostInfo ;
2015-04-08 15:20:10 -07:00
}
2017-06-24 08:32:09 -07:00
internal GuiWidget ShowOverflowMenu ( )
2015-04-08 15:20:10 -07:00
{
2017-06-24 08:32:09 -07:00
var popupContainer = new FlowLayoutWidget ( FlowDirection . TopToBottom )
{
HAnchor = HAnchor . ParentLeftRight ,
Padding = 12 ,
BackgroundColor = RGBA_Bytes . White
} ;
2015-04-08 15:20:10 -07:00
// put in a show grid check box
2017-06-24 08:32:09 -07:00
CheckBox showGrid = new CheckBox ( "Print Bed" . Localize ( ) , textColor : ActiveTheme . Instance . PrimaryTextColor ) ;
showGrid . Checked = options . RenderGrid ;
meshViewerWidget . RenderBed = showGrid . Checked ;
showGrid . CheckedStateChanged + = ( sender , e ) = >
2015-04-08 15:20:10 -07:00
{
2017-06-24 08:32:09 -07:00
options . RenderGrid = showGrid . Checked ;
} ;
popupContainer . AddChild ( showGrid ) ;
2015-04-08 15:20:10 -07:00
// put in a show moves checkbox
2017-06-24 08:32:09 -07:00
var showMoves = new CheckBox ( "Moves" . Localize ( ) , textColor : ActiveTheme . Instance . PrimaryTextColor ) ;
showMoves . Checked = options . RenderMoves ;
showMoves . CheckedStateChanged + = ( sender , e ) = >
2015-04-08 15:20:10 -07:00
{
2017-06-24 08:32:09 -07:00
options . RenderMoves = showMoves . Checked ;
} ;
popupContainer . AddChild ( showMoves ) ;
2015-04-08 15:20:10 -07:00
// put in a show Retractions checkbox
2017-06-24 08:32:09 -07:00
CheckBox showRetractions = new CheckBox ( "Retractions" . Localize ( ) , textColor : ActiveTheme . Instance . PrimaryTextColor ) ;
showRetractions . Checked = options . RenderRetractions ;
showRetractions . CheckedStateChanged + = ( sender , e ) = >
2015-04-08 15:20:10 -07:00
{
2017-06-24 08:32:09 -07:00
options . RenderRetractions = showRetractions . Checked ;
} ;
popupContainer . AddChild ( showRetractions ) ;
2015-04-08 15:20:10 -07:00
// put in a show speed checkbox
2017-06-24 08:32:09 -07:00
var showSpeeds = new CheckBox ( "Speeds" . Localize ( ) , textColor : ActiveTheme . Instance . PrimaryTextColor ) ;
showSpeeds . Checked = options . RenderSpeeds ;
//showSpeeds.Checked = gradient.Visible;
showSpeeds . CheckedStateChanged + = ( sender , e ) = >
2015-04-08 15:20:10 -07:00
{
2017-06-24 08:32:09 -07:00
gradientWidget . Visible = showSpeeds . Checked ;
options . RenderSpeeds = showSpeeds . Checked ;
} ;
2015-04-13 11:04:17 -07:00
2017-06-24 08:32:09 -07:00
popupContainer . AddChild ( showSpeeds ) ;
2015-04-08 15:20:10 -07:00
// put in a simulate extrusion checkbox
2017-06-24 08:32:09 -07:00
var simulateExtrusion = new CheckBox ( "Extrusion" . Localize ( ) , textColor : ActiveTheme . Instance . PrimaryTextColor ) ;
simulateExtrusion . Checked = options . SimulateExtrusion ;
simulateExtrusion . CheckedStateChanged + = ( sender , e ) = >
2015-04-08 15:20:10 -07:00
{
2017-06-24 08:32:09 -07:00
options . SimulateExtrusion = simulateExtrusion . Checked ;
} ;
popupContainer . AddChild ( simulateExtrusion ) ;
2015-04-08 15:20:10 -07:00
2017-05-25 17:58:20 -07:00
// put in a render extrusion transparent checkbox
2017-06-24 08:32:09 -07:00
var transparentExtrusion = new CheckBox ( "Transparent" . Localize ( ) , textColor : ActiveTheme . Instance . PrimaryTextColor )
2017-05-25 17:58:20 -07:00
{
2017-06-24 08:32:09 -07:00
Checked = options . TransparentExtrusion ,
Margin = new BorderDouble ( 5 , 0 , 0 , 0 ) ,
HAnchor = HAnchor . ParentLeft ,
} ;
2017-05-25 17:58:20 -07:00
2017-06-24 08:32:09 -07:00
transparentExtrusion . CheckedStateChanged + = ( sender , e ) = >
{
options . TransparentExtrusion = transparentExtrusion . Checked ;
} ;
popupContainer . AddChild ( transparentExtrusion ) ;
2017-05-25 17:58:20 -07:00
// put in a simulate extrusion checkbox
if ( ActiveSliceSettings . Instance . GetValue < int > ( SettingsKey . extruder_count ) > 1 )
2015-04-08 15:20:10 -07:00
{
CheckBox hideExtruderOffsets = new CheckBox ( "Hide Offsets" , textColor : ActiveTheme . Instance . PrimaryTextColor ) ;
2017-06-24 08:32:09 -07:00
hideExtruderOffsets . Checked = options . HideExtruderOffsets ;
2015-04-08 15:20:10 -07:00
hideExtruderOffsets . CheckedStateChanged + = ( sender , e ) = >
{
2017-06-24 08:32:09 -07:00
options . HideExtruderOffsets = hideExtruderOffsets . Checked ;
2015-04-08 15:20:10 -07:00
} ;
2017-06-24 08:32:09 -07:00
popupContainer . AddChild ( hideExtruderOffsets ) ;
2015-04-08 15:20:10 -07:00
}
2017-05-26 20:07:42 -07:00
// Respond to user driven view mode change events and store and switch to the new mode
viewControlsToggle . ViewModeChanged + = ( s , e ) = >
2015-04-08 15:20:10 -07:00
{
2017-05-26 20:07:42 -07:00
activeViewMode = e . ViewMode ;
SwitchViewModes ( ) ;
} ;
// Switch to the most recent view mode, defaulting to Layers3D
SwitchViewModes ( ) ;
2014-05-25 11:11:11 -07:00
2015-04-08 15:20:10 -07:00
// Put in the sync to print checkbox
if ( windowMode = = WindowMode . Embeded )
{
2017-06-24 08:32:09 -07:00
var syncToPrint = new CheckBox ( "Sync To Print" . Localize ( ) , textColor : ActiveTheme . Instance . PrimaryTextColor ) ;
2014-07-02 10:13:40 -07:00
syncToPrint . Checked = ( UserSettings . Instance . get ( "LayerViewSyncToPrint" ) = = "True" ) ;
2016-09-20 14:32:22 -07:00
syncToPrint . Name = "Sync To Print Checkbox" ;
2017-06-24 08:32:09 -07:00
syncToPrint . CheckedStateChanged + = ( s , e ) = >
2015-04-08 15:20:10 -07:00
{
2017-06-24 08:32:09 -07:00
options . SyncToPrint = syncToPrint . Checked ;
2015-04-08 15:20:10 -07:00
SetSyncToPrintVisibility ( ) ;
} ;
2017-06-24 08:32:09 -07:00
popupContainer . AddChild ( syncToPrint ) ;
2015-04-08 15:20:10 -07:00
// The idea here is we just got asked to rebuild the window (and it is being created now)
// because the gcode finished creating for the print that is printing.
// We don't want to be notified if any other updates happen to this gcode while it is printing.
2017-06-13 17:22:49 -07:00
if ( PrinterConnection . Instance . PrinterIsPrinting
2017-06-16 18:04:47 -07:00
& & ApplicationController . Instance . ActivePrintItem = = printItem )
2015-04-08 15:20:10 -07:00
{
2015-07-21 08:10:05 -07:00
printItem . SlicingOutputMessage - = sliceItem_SlicingOutputMessage ;
printItem . SlicingDone - = sliceItem_Done ;
2015-04-08 15:20:10 -07:00
generateGCodeButton . Visible = false ;
2017-06-24 08:32:09 -07:00
// TODO: Bad pattern - figure out how to revise
2015-04-08 15:20:10 -07:00
// However if the print finished or is canceled we are going to want to get updates again. So, hook the status event
2017-06-13 17:22:49 -07:00
PrinterConnection . Instance . CommunicationStateChanged . RegisterEvent ( HookUpGCodeMessagesWhenDonePrinting , ref unregisterEvents ) ;
2015-06-11 12:06:40 -07:00
UiThread . RunOnIdle ( SetSyncToPrintVisibility ) ;
2015-04-08 15:20:10 -07:00
}
}
2017-06-24 08:32:09 -07:00
return popupContainer ;
2015-04-08 15:20:10 -07:00
}
2017-05-25 17:58:20 -07:00
private void SetSyncToPrintVisibility ( )
{
if ( windowMode = = WindowMode . Embeded )
{
2017-06-13 17:22:49 -07:00
bool printerIsRunningPrint = PrinterConnection . Instance . PrinterIsPaused | | PrinterConnection . Instance . PrinterIsPrinting ;
2017-05-25 17:58:20 -07:00
2017-06-24 08:32:09 -07:00
if ( options . SyncToPrint & & printerIsRunningPrint )
2017-05-25 17:58:20 -07:00
{
SetAnimationPosition ( ) ;
//navigationWidget.Visible = false;
//setLayerWidget.Visible = false;
layerRenderRatioSlider . Visible = false ;
selectLayerSlider . Visible = false ;
}
else
{
if ( layerRenderRatioSlider ! = null )
{
layerRenderRatioSlider . FirstValue = 0 ;
layerRenderRatioSlider . SecondValue = 1 ;
}
navigationWidget . Visible = true ;
setLayerWidget . Visible = true ;
layerRenderRatioSlider . Visible = true ;
selectLayerSlider . Visible = true ;
}
}
}
2015-04-08 15:20:10 -07:00
2017-05-26 20:07:42 -07:00
private void SwitchViewModes ( )
2014-07-01 19:29:13 -07:00
{
2017-05-26 20:07:42 -07:00
bool inLayers3DMode = activeViewMode = = PartViewMode . Layers3D ;
if ( inLayers3DMode )
2014-07-01 19:29:13 -07:00
{
2015-04-08 15:20:10 -07:00
UserSettings . Instance . set ( "LayerViewDefault" , "3D Layer" ) ;
2014-07-01 19:29:13 -07:00
}
else
{
2015-04-08 15:20:10 -07:00
UserSettings . Instance . set ( "LayerViewDefault" , "2D Layer" ) ;
2014-07-01 19:29:13 -07:00
2017-05-26 20:07:42 -07:00
// HACK: Getting the Layer2D view to show content only works if CenterPartInView is called after the control is visible and after some cycles have passed
UiThread . RunOnIdle ( gcodeViewWidget . CenterPartInView ) ;
2014-07-01 19:29:13 -07:00
}
2017-05-26 20:07:42 -07:00
meshViewerWidget . Visible = inLayers3DMode ;
gcodeViewWidget . Visible = ! inLayers3DMode ;
2014-07-01 19:29:13 -07:00
}
2015-04-08 15:20:10 -07:00
private void HookUpGCodeMessagesWhenDonePrinting ( object sender , EventArgs e )
{
2017-06-13 17:22:49 -07:00
if ( ! PrinterConnection . Instance . PrinterIsPaused & & ! PrinterConnection . Instance . PrinterIsPrinting )
2015-04-08 15:20:10 -07:00
{
// unregister first to make sure we don't double up in error (should not be needed but no harm)
2015-07-21 08:10:05 -07:00
printItem . SlicingOutputMessage - = sliceItem_SlicingOutputMessage ;
printItem . SlicingDone - = sliceItem_Done ;
2015-04-08 15:20:10 -07:00
// register for done slicing and slicing messages
2015-07-21 08:10:05 -07:00
printItem . SlicingOutputMessage + = sliceItem_SlicingOutputMessage ;
printItem . SlicingDone + = sliceItem_Done ;
2015-04-08 15:20:10 -07:00
generateGCodeButton . Visible = true ;
}
2017-05-25 17:58:20 -07:00
SetSyncToPrintVisibility ( ) ;
2015-04-08 15:20:10 -07:00
}
2017-06-20 14:56:36 -07:00
private void LoadProgress_Changed ( double progress0To1 , string processingState , out bool continueProcessing )
{
SetProcessingMessage ( string . Format ( "{0} {1:0}%..." , gcodeLoading , progress0To1 * 100 ) ) ;
continueProcessing = ! this . HasBeenClosed ;
}
2015-04-08 15:20:10 -07:00
private GuiWidget CreateGCodeViewWidget ( string pathAndFileName )
{
2017-06-20 14:56:36 -07:00
gcodeViewWidget = new ViewGcodeWidget ( new Vector2 ( viewerVolume . x , viewerVolume . y ) , bedCenter , LoadProgress_Changed ) ;
2015-04-08 15:20:10 -07:00
gcodeViewWidget . DoneLoading + = DoneLoadingGCode ;
2017-05-26 20:07:42 -07:00
gcodeViewWidget . Visible = ( activeViewMode = = PartViewMode . Layers2D ) ;
2015-04-08 15:20:10 -07:00
partToStartLoadingOnFirstDraw = pathAndFileName ;
return gcodeViewWidget ;
}
public override void OnDraw ( Graphics2D graphics2D )
{
2017-06-13 17:22:49 -07:00
bool printerIsRunningPrint = PrinterConnection . Instance . PrinterIsPaused | | PrinterConnection . Instance . PrinterIsPrinting ;
2017-06-24 08:32:09 -07:00
if ( options . SyncToPrint
2015-04-08 15:20:10 -07:00
& & printerIsRunningPrint )
{
2017-05-25 17:58:20 -07:00
SetAnimationPosition ( ) ;
2015-04-08 15:20:10 -07:00
}
if ( partToStartLoadingOnFirstDraw ! = null )
{
gcodeViewWidget . LoadInBackground ( partToStartLoadingOnFirstDraw ) ;
partToStartLoadingOnFirstDraw = null ;
}
base . OnDraw ( graphics2D ) ;
}
private void Parent_KeyDown ( object sender , KeyEventArgs keyEvent )
{
if ( keyEvent . KeyCode = = Keys . Up )
{
if ( gcodeViewWidget ! = null )
{
gcodeViewWidget . ActiveLayerIndex = ( gcodeViewWidget . ActiveLayerIndex + 1 ) ;
}
}
else if ( keyEvent . KeyCode = = Keys . Down )
{
if ( gcodeViewWidget ! = null )
{
gcodeViewWidget . ActiveLayerIndex = ( gcodeViewWidget . ActiveLayerIndex - 1 ) ;
}
}
}
private void SetProcessingMessage ( string message )
{
if ( gcodeProcessingStateInfoText = = null )
{
2017-06-20 14:56:36 -07:00
gcodeProcessingStateInfoText = new TextWidget ( message )
{
HAnchor = HAnchor . ParentCenter ,
VAnchor = VAnchor . ParentCenter ,
AutoExpandBoundsToText = true
} ;
2015-04-08 15:20:10 -07:00
2017-06-20 14:56:36 -07:00
var labelContainer = new GuiWidget ( ) ;
labelContainer . Selectable = false ;
2015-04-08 15:20:10 -07:00
labelContainer . AnchorAll ( ) ;
labelContainer . AddChild ( gcodeProcessingStateInfoText ) ;
gcodeDisplayWidget . AddChild ( labelContainer ) ;
}
if ( message = = "" )
{
2017-06-20 14:56:36 -07:00
gcodeProcessingStateInfoText . BackgroundColor = RGBA_Bytes . Transparent ;
2015-04-08 15:20:10 -07:00
}
else
{
gcodeProcessingStateInfoText . BackgroundColor = RGBA_Bytes . White ;
}
gcodeProcessingStateInfoText . Text = message ;
}
2017-05-25 17:58:20 -07:00
private void DoneLoadingGCode ( object sender , EventArgs e )
2015-04-08 15:20:10 -07:00
{
SetProcessingMessage ( "" ) ;
if ( gcodeViewWidget ! = null
2017-06-24 10:30:11 -07:00
& & loadedGCode = = null )
2015-01-19 17:33:17 -08:00
{
2015-12-17 16:26:54 -08:00
// If we have finished loading the gcode and the source file exists but we don't have any loaded gcode it is because the loader decided to not load it.
2015-05-20 12:36:34 -07:00
if ( File . Exists ( printItem . FileLocation ) )
2015-01-19 17:33:17 -08:00
{
2015-02-21 16:30:29 -08:00
SetProcessingMessage ( string . Format ( fileTooBigToLoad , printItem . Name ) ) ;
2015-01-19 17:33:17 -08:00
}
else
{
SetProcessingMessage ( string . Format ( "{0}\n'{1}'" , fileNotFoundMessage , Path . GetFileName ( printItem . FileLocation ) ) ) ;
}
}
2015-04-08 15:20:10 -07:00
if ( gcodeViewWidget ! = null
2017-06-24 10:30:11 -07:00
& & loadedGCode ? . LineCount > 0 )
2015-04-08 15:20:10 -07:00
{
2017-06-20 14:56:36 -07:00
// TODO: Shouldn't we be clearing children from some known container and rebuilding?
gradientWidget ? . Close ( ) ;
2017-06-24 10:30:11 -07:00
gradientWidget = new ColorGradientWidget ( loadedGCode ) ;
2015-05-22 15:07:48 -07:00
AddChild ( gradientWidget ) ;
gradientWidget . Visible = false ;
2015-05-04 17:16:06 -07:00
2017-06-24 08:32:09 -07:00
gradientWidget . Visible = options . RenderSpeeds ;
2015-04-08 15:20:10 -07:00
viewControlsToggle . Visible = true ;
2017-06-20 14:56:36 -07:00
setLayerWidget ? . Close ( ) ;
2017-06-24 08:59:14 -07:00
setLayerWidget = new SetLayerWidget ( gcodeViewWidget , ApplicationController . Instance . Theme . GCodeLayerButtons ) ;
2015-04-08 15:20:10 -07:00
setLayerWidget . VAnchor = Agg . UI . VAnchor . ParentTop ;
layerSelectionButtonsPanel . AddChild ( setLayerWidget ) ;
2017-06-24 08:53:19 -07:00
2017-06-20 14:56:36 -07:00
navigationWidget ? . Close ( ) ;
2017-06-24 08:53:19 -07:00
navigationWidget = new LayerNavigationWidget ( gcodeViewWidget , ApplicationController . Instance . Theme . GCodeLayerButtons ) ;
2015-04-08 15:20:10 -07:00
navigationWidget . Margin = new BorderDouble ( 0 , 0 , 20 , 0 ) ;
layerSelectionButtonsPanel . AddChild ( navigationWidget ) ;
2017-06-20 14:56:36 -07:00
selectLayerSlider ? . Close ( ) ;
2017-06-24 10:30:11 -07:00
selectLayerSlider = new SolidSlider ( new Vector2 ( ) , sliderWidth , 0 , loadedGCode . NumChangesInZ - 1 , Orientation . Vertical ) ;
2017-05-25 17:58:20 -07:00
selectLayerSlider . ValueChanged + = new EventHandler ( selectLayerSlider_ValueChanged ) ;
gcodeViewWidget . ActiveLayerChanged + = new EventHandler ( gcodeViewWidget_ActiveLayerChanged ) ;
2015-04-08 15:20:10 -07:00
AddChild ( selectLayerSlider ) ;
2017-06-20 14:56:36 -07:00
layerRenderRatioSlider ? . Close ( ) ;
2017-05-25 17:58:20 -07:00
layerRenderRatioSlider = new DoubleSolidSlider ( new Vector2 ( ) , sliderWidth ) ;
2015-04-08 15:20:10 -07:00
layerRenderRatioSlider . FirstValue = 0 ;
2017-05-25 17:58:20 -07:00
layerRenderRatioSlider . FirstValueChanged + = new EventHandler ( layerStartRenderRatioSlider_ValueChanged ) ;
2015-04-08 15:20:10 -07:00
layerRenderRatioSlider . SecondValue = 1 ;
2017-05-25 17:58:20 -07:00
layerRenderRatioSlider . SecondValueChanged + = new EventHandler ( layerEndRenderRatioSlider_ValueChanged ) ;
2015-04-08 15:20:10 -07:00
AddChild ( layerRenderRatioSlider ) ;
SetSliderSizes ( ) ;
// let's change the active layer so that it is set to the first layer with data
gcodeViewWidget . ActiveLayerIndex = gcodeViewWidget . ActiveLayerIndex + 1 ;
gcodeViewWidget . ActiveLayerIndex = gcodeViewWidget . ActiveLayerIndex - 1 ;
2017-05-25 17:58:20 -07:00
BoundsChanged + = new EventHandler ( PartPreviewGCode_BoundsChanged ) ;
2015-04-08 15:20:10 -07:00
2017-06-24 08:32:09 -07:00
this . AddChild ( CreateModelInfo ( ) ) ;
2015-04-08 15:20:10 -07:00
2017-06-24 08:32:09 -07:00
meshViewerWidget . partProcessingInfo . Visible = false ;
2015-05-22 15:07:48 -07:00
}
}
2015-05-04 17:16:06 -07:00
2017-05-25 17:58:20 -07:00
private void layerStartRenderRatioSlider_ValueChanged ( object sender , EventArgs e )
{
gcodeViewWidget . FeatureToStartOnRatio0To1 = layerRenderRatioSlider . FirstValue ;
gcodeViewWidget . FeatureToEndOnRatio0To1 = layerRenderRatioSlider . SecondValue ;
gcodeViewWidget . Invalidate ( ) ;
}
private void layerEndRenderRatioSlider_ValueChanged ( object sender , EventArgs e )
{
gcodeViewWidget . FeatureToStartOnRatio0To1 = layerRenderRatioSlider . FirstValue ;
gcodeViewWidget . FeatureToEndOnRatio0To1 = layerRenderRatioSlider . SecondValue ;
gcodeViewWidget . Invalidate ( ) ;
}
private void gcodeViewWidget_ActiveLayerChanged ( object sender , EventArgs e )
{
if ( gcodeViewWidget . ActiveLayerIndex ! = ( int ) ( selectLayerSlider . Value + . 5 ) )
{
selectLayerSlider . Value = gcodeViewWidget . ActiveLayerIndex ;
}
}
private void selectLayerSlider_ValueChanged ( object sender , EventArgs e )
{
gcodeViewWidget . ActiveLayerIndex = ( int ) ( selectLayerSlider . Value + . 5 ) ;
}
2015-04-08 15:20:10 -07:00
private void PartPreviewGCode_BoundsChanged ( object sender , EventArgs e )
{
SetSliderSizes ( ) ;
}
2017-05-25 17:58:20 -07:00
private void SetSliderSizes ( )
{
selectLayerSlider . OriginRelativeParent = new Vector2 ( gcodeDisplayWidget . Width - 20 , 70 ) ;
selectLayerSlider . TotalWidthInPixels = gcodeDisplayWidget . Height - 80 ;
layerRenderRatioSlider . OriginRelativeParent = new Vector2 ( 60 , 70 ) ;
layerRenderRatioSlider . TotalWidthInPixels = gcodeDisplayWidget . Width - 100 ;
}
2017-02-03 13:06:08 -08:00
public override void OnClosed ( ClosedEventArgs e )
2015-04-08 15:20:10 -07:00
{
2017-05-25 17:58:20 -07:00
unregisterEvents ? . Invoke ( this , null ) ;
2015-04-08 15:20:10 -07:00
if ( printItem ! = null )
{
2015-07-21 08:10:05 -07:00
printItem . SlicingOutputMessage - = sliceItem_SlicingOutputMessage ;
printItem . SlicingDone - = sliceItem_Done ;
2015-04-08 15:20:10 -07:00
if ( startedSliceFromGenerateButton & & printItem . CurrentlySlicing )
{
SlicingQueue . Instance . CancelCurrentSlicing ( ) ;
}
}
base . OnClosed ( e ) ;
}
private void sliceItem_SlicingOutputMessage ( object sender , EventArgs e )
{
StringEventArgs message = e as StringEventArgs ;
if ( message ! = null & & message . Data ! = null )
{
SetProcessingMessage ( message . Data ) ;
}
else
{
SetProcessingMessage ( "" ) ;
}
}
private void sliceItem_Done ( object sender , EventArgs e )
{
// We can add this while we have it open (when we are done loading).
// So we need to make sure we only have it added once. This will be ok to run when
// not added or when added and will ensure we only have one hook.
2015-07-21 08:10:05 -07:00
printItem . SlicingOutputMessage - = sliceItem_SlicingOutputMessage ;
printItem . SlicingDone - = sliceItem_Done ;
2015-04-08 15:20:10 -07:00
2017-05-25 17:58:20 -07:00
UiThread . RunOnIdle ( CreateAndAddChildren ) ;
2015-04-08 15:20:10 -07:00
startedSliceFromGenerateButton = false ;
}
}
2016-06-27 12:05:14 -07:00
}