2014-01-29 19:09:30 -08:00
/ *
2014-02-15 18:06:03 -08:00
Copyright ( c ) 2014 , Lars Brubaker
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 .
* /
using MatterHackers.Agg ;
2016-05-10 14:53:40 -07:00
using MatterHackers.Agg.ImageProcessing ;
using MatterHackers.Agg.PlatformAbstract ;
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 ;
2015-04-08 15:20:10 -07:00
using System ;
using System.ComponentModel ;
using System.IO ;
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 } ;
public SolidSlider selectLayerSlider ;
private SetLayerWidget setLayerWidget ;
private LayerNavigationWidget navigationWidget ;
public DoubleSolidSlider layerRenderRatioSlider ;
private TextWidget gcodeProcessingStateInfoText ;
private ViewGcodeWidget gcodeViewWidget ;
private PrintItemWrapper printItem ;
private bool startedSliceFromGenerateButton = false ;
private Button generateGCodeButton ;
private FlowLayoutWidget buttonBottomPanel ;
private FlowLayoutWidget layerSelectionButtonsPanel ;
private FlowLayoutWidget modelOptionsContainer ;
private FlowLayoutWidget displayOptionsContainer ;
private ViewControlsToggle viewControlsToggle ;
private CheckBox expandModelOptions ;
private CheckBox expandDisplayOptions ;
private CheckBox syncToPrint ;
2015-05-22 15:07:48 -07:00
private CheckBox showSpeeds ;
2015-04-08 15:20:10 -07:00
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 ;
public delegate Vector2 GetSizeFunction ( ) ;
private static string slicingErrorMessage = "Slicing Error.\nPlease review your slice settings." . Localize ( ) ;
private static string pressGenerateMessage = "Press 'generate' to view layers" . Localize ( ) ;
private static string fileNotFoundMessage = "File not found on disk." . Localize ( ) ;
2015-05-21 15:09:59 -07:00
private static 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 ;
2016-06-16 10:22:38 -07:00
public ViewGcodeBasic ( PrintItemWrapper printItem , Vector3 viewerVolume , Vector2 bedCenter , BedShape bedShape , WindowMode windowMode )
2015-04-08 15:20:10 -07:00
{
this . viewerVolume = viewerVolume ;
this . bedShape = bedShape ;
this . bedCenter = bedCenter ;
this . windowMode = windowMode ;
this . printItem = printItem ;
2016-04-29 07:45:15 -07:00
if ( UserSettings . Instance . DisplayMode = = ApplicationDisplayType . Touchscreen )
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-04-26 17:15:10 -07:00
SliceSettingsWidget . SettingChanged . RegisterEvent ( CheckSettingChanged , ref unregisterEvents ) ;
2016-07-13 11:45:12 -07:00
ApplicationController . Instance . AdvancedControlsPanelReloading . RegisterEvent ( ( s , e ) = > ClearGCode ( ) , ref unregisterEvents ) ;
2015-04-08 15:20:10 -07:00
2016-04-18 11:31:31 -07:00
ActiveSliceSettings . ActivePrinterChanged . RegisterEvent ( CheckSettingChanged , ref unregisterEvents ) ;
2016-04-26 17:15:10 -07:00
}
2015-04-08 15:20:10 -07:00
2016-04-26 17:15:10 -07:00
private void CheckSettingChanged ( object sender , EventArgs e )
{
StringEventArgs stringEvent = e as StringEventArgs ;
if ( stringEvent ! = null )
{
2016-07-18 10:52:36 -07:00
if ( gcodeViewWidget ? . LoadedGCode ! = null
& & (
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
| | stringEvent . Data = = SettingsKey . bed_shape
| | stringEvent . Data = = SettingsKey . center_part_on_bed )
2016-04-26 17:15:10 -07:00
{
2016-06-21 09:38:37 -07:00
viewerVolume = new Vector3 ( ActiveSliceSettings . Instance . GetValue < Vector2 > ( SettingsKey . bed_size ) , ActiveSliceSettings . Instance . GetValue < double > ( SettingsKey . build_height ) ) ;
2016-06-16 10:22:38 -07:00
bedShape = ActiveSliceSettings . Instance . GetValue < BedShape > ( SettingsKey . bed_shape ) ;
2016-06-21 09:38:37 -07:00
bedCenter = ActiveSliceSettings . Instance . GetValue < Vector2 > ( SettingsKey . print_center ) ;
2016-04-26 17:15:10 -07:00
2016-06-21 09:38:37 -07:00
double buildHeight = ActiveSliceSettings . Instance . GetValue < double > ( SettingsKey . build_height ) ;
2016-04-26 17:15:10 -07:00
UiThread . RunOnIdle ( ( ) = >
{
meshViewerWidget . CreatePrintBed (
viewerVolume ,
bedCenter ,
bedShape ) ;
} ) ;
}
else if ( stringEvent . Data = = "extruder_offset" )
{
ClearGCode ( ) ;
}
}
2015-04-08 15:20:10 -07:00
}
2016-04-26 17:15:10 -07:00
private void ClearGCode ( )
2015-04-08 15:20:10 -07:00
{
if ( gcodeViewWidget ! = null
& & gcodeViewWidget . gCodeRenderer ! = null )
{
gcodeViewWidget . gCodeRenderer . Clear3DGCode ( ) ;
gcodeViewWidget . Invalidate ( ) ;
}
}
2015-06-11 12:06:40 -07:00
private void CreateAndAddChildren ( )
2015-04-08 15:20:10 -07:00
{
TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory ( ) ;
textImageButtonFactory . normalTextColor = ActiveTheme . Instance . PrimaryTextColor ;
textImageButtonFactory . hoverTextColor = ActiveTheme . Instance . PrimaryTextColor ;
textImageButtonFactory . disabledTextColor = ActiveTheme . Instance . PrimaryTextColor ;
textImageButtonFactory . pressedTextColor = ActiveTheme . Instance . PrimaryTextColor ;
2016-01-12 11:20:27 -08:00
CloseAllChildren ( ) ;
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 ;
generateGCodeButton = textImageButtonFactory . Generate ( LocalizedString . Get ( "Generate" ) ) ;
2016-03-03 16:57:43 -08:00
generateGCodeButton . Name = "Generate Gcode Button" ;
2015-04-08 15:20:10 -07:00
generateGCodeButton . Click + = new EventHandler ( generateButton_Click ) ;
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 )
{
Button closeButton = textImageButtonFactory . Generate ( LocalizedString . Get ( "Close" ) ) ;
layerSelectionButtonsPanel . AddChild ( closeButton ) ;
closeButton . Click + = ( sender , e ) = >
{
CloseOnIdle ( ) ;
} ;
}
FlowLayoutWidget centerPartPreviewAndControls = new FlowLayoutWidget ( FlowDirection . LeftToRight ) ;
centerPartPreviewAndControls . AnchorAll ( ) ;
gcodeDisplayWidget = new GuiWidget ( HAnchor . ParentLeftRight , Agg . UI . VAnchor . ParentBottomTop ) ;
2016-01-20 10:12:01 -08:00
string firstProcessingMessage = "Press 'Add' to select an item." . Localize ( ) ;
2015-04-08 15:20:10 -07:00
if ( printItem ! = null )
{
2016-01-20 10:12:01 -08:00
firstProcessingMessage = "Loading G-Code..." . Localize ( ) ;
2015-04-08 15:20:10 -07:00
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
2015-07-21 08:10:05 -07:00
printItem . SlicingOutputMessage + = sliceItem_SlicingOutputMessage ;
printItem . SlicingDone + = sliceItem_Done ;
2015-04-08 15:20:10 -07:00
}
else
{
firstProcessingMessage = string . Format ( "{0}\n'{1}'" , fileNotFoundMessage , printItem . Name ) ;
}
}
}
else
{
generateGCodeButton . Visible = false ;
}
SetProcessingMessage ( firstProcessingMessage ) ;
centerPartPreviewAndControls . AddChild ( gcodeDisplayWidget ) ;
buttonRightPanel = CreateRightButtonPanel ( ) ;
2014-10-27 11:49:59 -07:00
buttonRightPanel . Visible = false ;
2015-04-08 15:20:10 -07:00
centerPartPreviewAndControls . AddChild ( buttonRightPanel ) ;
// add in a spacer
layerSelectionButtonsPanel . AddChild ( new GuiWidget ( HAnchor . ParentLeftRight ) ) ;
buttonBottomPanel . AddChild ( layerSelectionButtonsPanel ) ;
mainContainerTopToBottom . AddChild ( centerPartPreviewAndControls ) ;
mainContainerTopToBottom . AddChild ( buttonBottomPanel ) ;
this . AddChild ( mainContainerTopToBottom ) ;
meshViewerWidget = new MeshViewerWidget ( viewerVolume , bedCenter , bedShape , "" . Localize ( ) ) ;
meshViewerWidget . AnchorAll ( ) ;
meshViewerWidget . AllowBedRenderingWhenEmpty = true ;
gcodeDisplayWidget . AddChild ( meshViewerWidget ) ;
meshViewerWidget . Visible = false ;
meshViewerWidget . TrackballTumbleWidget . DrawGlContent + = new EventHandler ( TrackballTumbleWidget_DrawGlContent ) ;
viewControls2D = new ViewControls2D ( ) ;
AddChild ( viewControls2D ) ;
2015-04-11 15:20:18 -07:00
2015-11-09 12:43:40 -08:00
viewControls2D . ResetView + = ( sender , e ) = >
{
SetDefaultView2D ( ) ;
} ;
2015-04-08 15:20:10 -07:00
viewControls3D = new ViewControls3D ( meshViewerWidget ) ;
viewControls3D . PartSelectVisible = false ;
AddChild ( viewControls3D ) ;
2015-05-29 15:13:56 -07:00
2015-11-09 12:36:47 -08:00
viewControls3D . ResetView + = ( sender , e ) = >
{
2016-02-29 14:04:52 -08:00
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
viewControls3D . Visible = false ;
2015-04-08 15:20:10 -07:00
viewControlsToggle = new ViewControlsToggle ( ) ;
viewControlsToggle . HAnchor = Agg . UI . HAnchor . ParentRight ;
AddChild ( viewControlsToggle ) ;
viewControlsToggle . Visible = false ;
//viewControls3D.translateButton.ClickButton(null);
2016-02-29 14:04:52 -08:00
meshViewerWidget . ResetView ( ) ;
2015-04-08 15:20:10 -07:00
viewControls2D . translateButton . Click + = ( sender , e ) = >
{
gcodeViewWidget . TransformState = ViewGcodeWidget . ETransformState . Move ;
} ;
viewControls2D . scaleButton . Click + = ( sender , e ) = >
{
gcodeViewWidget . TransformState = ViewGcodeWidget . ETransformState . Scale ;
} ;
AddHandlers ( ) ;
}
2015-11-09 12:43:40 -08:00
private void SetDefaultView2D ( )
{
gcodeViewWidget . CenterPartInView ( ) ;
}
2015-04-08 15:20:10 -07:00
private RenderType GetRenderType ( )
{
RenderType renderType = RenderType . Extrusions ;
if ( gcodeViewWidget . RenderMoves )
{
renderType | = RenderType . Moves ;
}
if ( gcodeViewWidget . RenderRetractions )
{
renderType | = RenderType . Retractions ;
}
if ( gcodeViewWidget . RenderSpeeds )
{
renderType | = RenderType . SpeedColors ;
}
2015-12-16 18:14:32 -08:00
if ( gcodeViewWidget . SimulateExtrusion )
{
renderType | = RenderType . SimulateExtrusion ;
}
if ( gcodeViewWidget . TransparentExtrusion )
{
renderType | = RenderType . TransparentExtrusion ;
}
if ( gcodeViewWidget . HideExtruderOffsets )
2015-04-08 15:20:10 -07:00
{
renderType | = RenderType . HideExtruderOffsets ;
}
return renderType ;
}
private void TrackballTumbleWidget_DrawGlContent ( object sender , EventArgs e )
{
GCodeRenderer . ExtrusionColor = ActiveTheme . Instance . PrimaryAccentColor ;
GCodeRenderInfo renderInfo = new GCodeRenderInfo ( 0 ,
Math . Min ( gcodeViewWidget . ActiveLayerIndex + 1 , gcodeViewWidget . LoadedGCode . NumChangesInZ ) ,
gcodeViewWidget . TotalTransform ,
1 ,
GetRenderType ( ) ,
gcodeViewWidget . FeatureToStartOnRatio0To1 ,
gcodeViewWidget . FeatureToEndOnRatio0To1 ,
2016-07-18 14:15:37 -07:00
new Vector2 [ ] { ActiveSliceSettings . Instance . Helpers . ExtruderOffset ( 0 ) , ActiveSliceSettings . Instance . Helpers . ExtruderOffset ( 1 ) } ) ;
2015-04-08 15:20:10 -07:00
gcodeViewWidget . gCodeRenderer . Render3D ( renderInfo ) ;
}
private void SetAnimationPosition ( )
{
int currentLayer = PrinterConnectionAndCommunication . Instance . CurrentlyPrintingLayer ;
if ( currentLayer < = 0 )
{
selectLayerSlider . Value = 0 ;
layerRenderRatioSlider . SecondValue = 0 ;
layerRenderRatioSlider . FirstValue = 0 ;
}
else
{
selectLayerSlider . Value = currentLayer - 1 ;
layerRenderRatioSlider . SecondValue = PrinterConnectionAndCommunication . Instance . RatioIntoCurrentLayer ;
layerRenderRatioSlider . FirstValue = 0 ;
}
}
private FlowLayoutWidget CreateRightButtonPanel ( )
{
FlowLayoutWidget buttonRightPanel = new FlowLayoutWidget ( FlowDirection . TopToBottom ) ;
buttonRightPanel . Width = 200 ;
{
string label = "Model" . Localize ( ) . ToUpper ( ) ;
2016-05-10 14:53:40 -07:00
expandModelOptions = ExpandMenuOptionFactory . GenerateCheckBoxButton ( label , StaticData . Instance . LoadIcon ( "icon_arrow_right_no_border_32x32.png" , 32 , 32 ) . InvertLightness ( ) ) ;
2015-04-08 15:20:10 -07:00
expandModelOptions . Margin = new BorderDouble ( bottom : 2 ) ;
buttonRightPanel . AddChild ( expandModelOptions ) ;
expandModelOptions . Checked = true ;
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
modelOptionsContainer = new FlowLayoutWidget ( FlowDirection . TopToBottom ) ;
modelOptionsContainer . HAnchor = HAnchor . ParentLeftRight ;
//modelOptionsContainer.Visible = false;
buttonRightPanel . AddChild ( modelOptionsContainer ) ;
2014-01-29 19:09:30 -08:00
2016-05-10 14:53:40 -07:00
expandDisplayOptions = ExpandMenuOptionFactory . GenerateCheckBoxButton ( "Display" . Localize ( ) . ToUpper ( ) , StaticData . Instance . LoadIcon ( "icon_arrow_right_no_border_32x32.png" , 32 , 32 ) . InvertLightness ( ) ) ;
2015-04-08 15:20:10 -07:00
expandDisplayOptions . Margin = new BorderDouble ( bottom : 2 ) ;
buttonRightPanel . AddChild ( expandDisplayOptions ) ;
expandDisplayOptions . Checked = false ;
displayOptionsContainer = new FlowLayoutWidget ( FlowDirection . TopToBottom ) ;
displayOptionsContainer . HAnchor = HAnchor . ParentLeftRight ;
displayOptionsContainer . Padding = new BorderDouble ( left : 6 ) ;
displayOptionsContainer . Visible = false ;
buttonRightPanel . AddChild ( displayOptionsContainer ) ;
GuiWidget verticalSpacer = new GuiWidget ( ) ;
verticalSpacer . VAnchor = VAnchor . ParentBottomTop ;
buttonRightPanel . AddChild ( verticalSpacer ) ;
}
buttonRightPanel . Padding = new BorderDouble ( 6 , 6 ) ;
buttonRightPanel . Margin = new BorderDouble ( 0 , 1 ) ;
buttonRightPanel . BackgroundColor = ActiveTheme . Instance . PrimaryBackgroundColor ;
buttonRightPanel . VAnchor = VAnchor . ParentBottomTop ;
return buttonRightPanel ;
}
private void CreateOptionsContent ( )
{
AddModelInfo ( modelOptionsContainer ) ;
AddDisplayControls ( displayOptionsContainer ) ;
}
private void AddModelInfo ( FlowLayoutWidget buttonPanel )
{
2016-01-12 11:20:27 -08:00
buttonPanel . CloseAllChildren ( ) ;
2015-04-08 15:20:10 -07:00
double oldWidth = textImageButtonFactory . FixedWidth ;
2016-05-06 17:56:27 -07:00
textImageButtonFactory . FixedWidth = 44 * GuiWidget . DeviceScale ;
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
FlowLayoutWidget modelInfoContainer = new FlowLayoutWidget ( FlowDirection . TopToBottom ) ;
modelInfoContainer . HAnchor = HAnchor . ParentLeftRight ;
modelInfoContainer . Padding = new BorderDouble ( 5 ) ;
2014-01-29 19:09:30 -08:00
2015-12-16 18:14:32 -08:00
string printTimeLabel = "Print Time" . Localize ( ) ;
2015-04-08 15:20:10 -07:00
string printTimeLabelFull = string . Format ( "{0}:" , printTimeLabel ) ;
// put in the print time
2016-01-28 12:39:14 -08:00
modelInfoContainer . AddChild ( new TextWidget ( printTimeLabelFull , textColor : ActiveTheme . Instance . PrimaryTextColor , pointSize : 9 ) ) ;
2015-04-08 15:20:10 -07:00
{
string timeRemainingText = "---" ;
if ( gcodeViewWidget ! = null & & gcodeViewWidget . LoadedGCode ! = null )
{
int secondsRemaining = ( int ) gcodeViewWidget . LoadedGCode . Instruction ( 0 ) . secondsToEndFromHere ;
int hoursRemaining = ( int ) ( secondsRemaining / ( 60 * 60 ) ) ;
int minutesRemaining = ( int ) ( ( secondsRemaining + 30 ) / 60 - hoursRemaining * 60 ) ; // +30 for rounding
secondsRemaining = secondsRemaining % 60 ;
if ( hoursRemaining > 0 )
{
timeRemainingText = string . Format ( "{0} h, {1} min" , hoursRemaining , minutesRemaining ) ;
}
else
{
timeRemainingText = string . Format ( "{0} min" , minutesRemaining ) ;
}
}
GuiWidget estimatedPrintTime = new TextWidget ( string . Format ( "{0}" , timeRemainingText ) , textColor : ActiveTheme . Instance . PrimaryTextColor , pointSize : 14 ) ;
//estimatedPrintTime.HAnchor = Agg.UI.HAnchor.ParentLeft;
estimatedPrintTime . Margin = new BorderDouble ( 0 , 9 , 0 , 3 ) ;
modelInfoContainer . AddChild ( estimatedPrintTime ) ;
}
//modelInfoContainer.AddChild(new TextWidget("Size:", textColor: ActiveTheme.Instance.PrimaryTextColor));
2015-12-16 18:14:32 -08:00
string filamentLengthLabel = "Filament Length" . Localize ( ) ;
2015-04-08 15:20:10 -07:00
string filamentLengthLabelFull = string . Format ( "{0}:" , filamentLengthLabel ) ;
// show the filament used
modelInfoContainer . AddChild ( new TextWidget ( filamentLengthLabelFull , textColor : ActiveTheme . Instance . PrimaryTextColor , pointSize : 9 ) ) ;
{
2016-07-12 17:46:48 -07:00
double filamentUsed = gcodeViewWidget . 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.HAnchor = Agg.UI.HAnchor.ParentLeft;
estimatedPrintTime . Margin = new BorderDouble ( 0 , 9 , 0 , 3 ) ;
modelInfoContainer . AddChild ( estimatedPrintTime ) ;
}
2014-01-29 19:09:30 -08:00
2015-12-16 18:14:32 -08:00
string filamentVolumeLabel = "Filament Volume" . Localize ( ) ;
2014-04-10 14:07:25 -07:00
string filamentVolumeLabelFull = string . Format ( "{0}:" , filamentVolumeLabel ) ;
2015-04-08 15:20:10 -07:00
modelInfoContainer . AddChild ( new TextWidget ( filamentVolumeLabelFull , textColor : ActiveTheme . Instance . PrimaryTextColor , pointSize : 9 ) ) ;
{
2016-07-12 17:46:48 -07:00
double filamentMm3 = gcodeViewWidget . LoadedGCode . GetFilamentCubicMm ( ActiveSliceSettings . Instance . GetValue < double > ( SettingsKey . filament_diameter ) ) ;
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
GuiWidget estimatedPrintTime = new TextWidget ( string . Format ( "{0:0.00} cm3" , filamentMm3 / 1000 ) , pointSize : 14 , textColor : ActiveTheme . Instance . PrimaryTextColor ) ;
//estimatedPrintTime.HAnchor = Agg.UI.HAnchor.ParentLeft;
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 ( ) ) ;
PrinterConnectionAndCommunication . Instance . CommunicationStateChanged . RegisterEvent ( HookUpGCodeMessagesWhenDonePrinting , ref unregisterEvents ) ;
buttonPanel . AddChild ( modelInfoContainer ) ;
textImageButtonFactory . FixedWidth = oldWidth ;
}
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
2016-07-18 10:52:36 -07:00
return gcodeViewWidget . 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 ) ;
string massLabel = "Estimated Mass" . Localize ( ) ;
string massLabelFull = string . Format ( "{0}:" , massLabel ) ;
estimatedMassInfo . AddChild ( new TextWidget ( massLabelFull , pointSize : 9 , textColor : ActiveTheme . Instance . PrimaryTextColor ) ) ;
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 ) ;
return estimatedCostInfo ;
2015-04-08 15:20:10 -07:00
}
private void AddLayerInfo ( FlowLayoutWidget buttonPanel )
{
double oldWidth = textImageButtonFactory . FixedWidth ;
2016-05-06 17:56:27 -07:00
textImageButtonFactory . FixedWidth = 44 * GuiWidget . DeviceScale ;
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
FlowLayoutWidget layerInfoContainer = new FlowLayoutWidget ( FlowDirection . TopToBottom ) ;
layerInfoContainer . HAnchor = HAnchor . ParentLeftRight ;
layerInfoContainer . Padding = new BorderDouble ( 5 ) ;
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
layerInfoContainer . AddChild ( new TextWidget ( "Layer Number:" , textColor : ActiveTheme . Instance . PrimaryTextColor ) ) ;
layerInfoContainer . AddChild ( new TextWidget ( "Layer Height:" , textColor : ActiveTheme . Instance . PrimaryTextColor ) ) ;
layerInfoContainer . AddChild ( new TextWidget ( "Num GCodes:" , textColor : ActiveTheme . Instance . PrimaryTextColor ) ) ;
layerInfoContainer . AddChild ( new TextWidget ( "Filament Used:" , textColor : ActiveTheme . Instance . PrimaryTextColor ) ) ;
layerInfoContainer . AddChild ( new TextWidget ( "Weight:" , textColor : ActiveTheme . Instance . PrimaryTextColor ) ) ;
layerInfoContainer . AddChild ( new TextWidget ( "Print Time:" , textColor : ActiveTheme . Instance . PrimaryTextColor ) ) ;
layerInfoContainer . AddChild ( new TextWidget ( "Extrude Speeds:" , textColor : ActiveTheme . Instance . PrimaryTextColor ) ) ;
layerInfoContainer . AddChild ( new TextWidget ( "Move Speeds:" , textColor : ActiveTheme . Instance . PrimaryTextColor ) ) ;
layerInfoContainer . AddChild ( new TextWidget ( "Retract Speeds:" , textColor : ActiveTheme . Instance . PrimaryTextColor ) ) ;
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
buttonPanel . AddChild ( layerInfoContainer ) ;
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
textImageButtonFactory . FixedWidth = oldWidth ;
}
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
private void AddDisplayControls ( FlowLayoutWidget buttonPanel )
{
2016-01-12 11:20:27 -08:00
buttonPanel . CloseAllChildren ( ) ;
2014-10-22 11:06:52 -07:00
2015-04-08 15:20:10 -07:00
double oldWidth = textImageButtonFactory . FixedWidth ;
2016-05-06 17:56:27 -07:00
textImageButtonFactory . FixedWidth = 44 * GuiWidget . DeviceScale ;
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
FlowLayoutWidget layerInfoContainer = new FlowLayoutWidget ( FlowDirection . TopToBottom ) ;
layerInfoContainer . HAnchor = HAnchor . ParentLeftRight ;
layerInfoContainer . Padding = new BorderDouble ( 5 ) ;
// put in a show grid check box
{
2015-12-16 18:14:32 -08:00
CheckBox showGrid = new CheckBox ( LocalizedString . Get ( "Print Bed" ) , textColor : ActiveTheme . Instance . PrimaryTextColor ) ;
2015-04-08 15:20:10 -07:00
showGrid . Checked = gcodeViewWidget . RenderGrid ;
meshViewerWidget . RenderBed = showGrid . Checked ;
showGrid . CheckedStateChanged + = ( sender , e ) = >
{
gcodeViewWidget . RenderGrid = showGrid . Checked ;
meshViewerWidget . RenderBed = showGrid . Checked ;
} ;
layerInfoContainer . AddChild ( showGrid ) ;
}
// put in a show moves checkbox
{
CheckBox showMoves = new CheckBox ( LocalizedString . Get ( "Moves" ) , textColor : ActiveTheme . Instance . PrimaryTextColor ) ;
showMoves . Checked = gcodeViewWidget . RenderMoves ;
showMoves . CheckedStateChanged + = ( sender , e ) = >
{
gcodeViewWidget . RenderMoves = showMoves . Checked ;
} ;
layerInfoContainer . AddChild ( showMoves ) ;
}
// put in a show Retractions checkbox
{
CheckBox showRetractions = new CheckBox ( LocalizedString . Get ( "Retractions" ) , textColor : ActiveTheme . Instance . PrimaryTextColor ) ;
showRetractions . Checked = gcodeViewWidget . RenderRetractions ;
showRetractions . CheckedStateChanged + = ( sender , e ) = >
{
gcodeViewWidget . RenderRetractions = showRetractions . Checked ;
} ;
layerInfoContainer . AddChild ( showRetractions ) ;
}
// put in a show speed checkbox
{
2015-05-22 15:07:48 -07:00
showSpeeds = new CheckBox ( LocalizedString . Get ( "Speeds" ) , textColor : ActiveTheme . Instance . PrimaryTextColor ) ;
2015-04-08 15:20:10 -07:00
showSpeeds . Checked = gcodeViewWidget . RenderSpeeds ;
2015-05-22 15:07:48 -07:00
//showSpeeds.Checked = gradient.Visible;
2015-04-08 15:20:10 -07:00
showSpeeds . CheckedStateChanged + = ( sender , e ) = >
{
2015-05-22 15:07:48 -07:00
/ * if ( ! showSpeeds . Checked )
{
gradient . Visible = false ;
}
else
{
gradient . Visible = true ;
} * /
gradientWidget . Visible = showSpeeds . Checked ;
2015-04-13 11:04:17 -07:00
2015-04-08 15:20:10 -07:00
gcodeViewWidget . RenderSpeeds = showSpeeds . Checked ;
} ;
2015-04-13 11:04:17 -07:00
2015-04-08 15:20:10 -07:00
layerInfoContainer . AddChild ( showSpeeds ) ;
}
// put in a simulate extrusion checkbox
{
CheckBox simulateExtrusion = new CheckBox ( LocalizedString . Get ( "Extrusion" ) , textColor : ActiveTheme . Instance . PrimaryTextColor ) ;
simulateExtrusion . Checked = gcodeViewWidget . SimulateExtrusion ;
simulateExtrusion . CheckedStateChanged + = ( sender , e ) = >
{
gcodeViewWidget . SimulateExtrusion = simulateExtrusion . Checked ;
} ;
layerInfoContainer . AddChild ( simulateExtrusion ) ;
}
2015-12-16 18:14:32 -08:00
// put in a render extrusion transparent checkbox
{
CheckBox transparentExtrusion = new CheckBox ( LocalizedString . Get ( "Transparent" ) , textColor : ActiveTheme . Instance . PrimaryTextColor )
{
Checked = gcodeViewWidget . TransparentExtrusion ,
2016-05-06 17:56:27 -07:00
Margin = new BorderDouble ( 5 , 0 , 0 , 0 ) ,
2015-12-16 18:14:32 -08:00
HAnchor = HAnchor . ParentLeft ,
} ;
transparentExtrusion . CheckedStateChanged + = ( sender , e ) = >
{
gcodeViewWidget . TransparentExtrusion = transparentExtrusion . Checked ;
} ;
layerInfoContainer . AddChild ( transparentExtrusion ) ;
}
// put in a simulate extrusion checkbox
2016-06-16 10:31:18 -07:00
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 ) ;
hideExtruderOffsets . Checked = gcodeViewWidget . HideExtruderOffsets ;
hideExtruderOffsets . CheckedStateChanged + = ( sender , e ) = >
{
gcodeViewWidget . HideExtruderOffsets = hideExtruderOffsets . Checked ;
} ;
layerInfoContainer . AddChild ( hideExtruderOffsets ) ;
}
// put in a show 3D view checkbox
{
2014-07-01 19:29:13 -07:00
viewControlsToggle . twoDimensionButton . CheckedStateChanged + = ( sender , e ) = >
2015-04-08 15:20:10 -07:00
{
2014-07-01 19:29:13 -07:00
SetLayerViewType ( ) ;
2015-04-08 15:20:10 -07:00
} ;
2014-07-01 19:29:13 -07:00
viewControlsToggle . threeDimensionButton . CheckedStateChanged + = ( sender , e ) = >
{
SetLayerViewType ( ) ;
} ;
2015-04-08 15:20:10 -07:00
SetLayerViewType ( ) ;
}
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 )
{
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" ) ;
2015-04-08 15:20:10 -07:00
syncToPrint . CheckedStateChanged + = ( sender , e ) = >
{
UserSettings . Instance . set ( "LayerViewSyncToPrint" , syncToPrint . Checked . ToString ( ) ) ;
SetSyncToPrintVisibility ( ) ;
} ;
layerInfoContainer . AddChild ( syncToPrint ) ;
// 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.
if ( PrinterConnectionAndCommunication . Instance . PrinterIsPrinting
& & PrinterConnectionAndCommunication . Instance . ActivePrintItem = = printItem )
{
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 ;
// However if the print finished or is canceled we are going to want to get updates again. So, hook the status event
PrinterConnectionAndCommunication . 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
}
}
//layerInfoContainer.AddChild(new CheckBox("Show Retractions", textColor: ActiveTheme.Instance.PrimaryTextColor));
buttonPanel . AddChild ( layerInfoContainer ) ;
textImageButtonFactory . FixedWidth = oldWidth ;
}
private void SetSyncToPrintVisibility ( )
{
if ( windowMode = = WindowMode . Embeded )
{
bool printerIsRunningPrint = PrinterConnectionAndCommunication . Instance . PrinterIsPaused | | PrinterConnectionAndCommunication . Instance . PrinterIsPrinting ;
if ( syncToPrint . Checked & & printerIsRunningPrint )
{
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 ;
}
}
}
private void SetLayerViewType ( )
2014-07-01 19:29:13 -07:00
{
if ( viewControlsToggle . threeDimensionButton . Checked )
{
2015-04-08 15:20:10 -07:00
UserSettings . Instance . set ( "LayerViewDefault" , "3D Layer" ) ;
2014-07-01 19:29:13 -07:00
viewControls2D . Visible = false ;
gcodeViewWidget . Visible = false ;
viewControls3D . Visible = true ;
meshViewerWidget . Visible = true ;
}
else
{
2015-04-08 15:20:10 -07:00
UserSettings . Instance . set ( "LayerViewDefault" , "2D Layer" ) ;
2014-07-01 19:29:13 -07:00
viewControls2D . Visible = true ;
gcodeViewWidget . Visible = true ;
viewControls3D . Visible = false ;
meshViewerWidget . Visible = false ;
}
}
2015-04-08 15:20:10 -07:00
private void HookUpGCodeMessagesWhenDonePrinting ( object sender , EventArgs e )
{
if ( ! PrinterConnectionAndCommunication . Instance . PrinterIsPaused & & ! PrinterConnectionAndCommunication . Instance . PrinterIsPrinting )
{
// 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 ;
}
SetSyncToPrintVisibility ( ) ;
}
private string partToStartLoadingOnFirstDraw = null ;
private GuiWidget CreateGCodeViewWidget ( string pathAndFileName )
{
gcodeViewWidget = new ViewGcodeWidget ( new Vector2 ( viewerVolume . x , viewerVolume . y ) , bedCenter ) ;
gcodeViewWidget . DoneLoading + = DoneLoadingGCode ;
gcodeViewWidget . LoadingProgressChanged + = LoadingProgressChanged ;
partToStartLoadingOnFirstDraw = pathAndFileName ;
return gcodeViewWidget ;
}
private GuiWidget widgetThatHasKeyDownHooked = null ;
public override void OnDraw ( Graphics2D graphics2D )
{
bool printerIsRunningPrint = PrinterConnectionAndCommunication . Instance . PrinterIsPaused | | PrinterConnectionAndCommunication . Instance . PrinterIsPrinting ;
if ( syncToPrint ! = null
& & syncToPrint . Checked
& & printerIsRunningPrint )
{
SetAnimationPosition ( ) ;
}
EnsureKeyDownHooked ( ) ;
if ( partToStartLoadingOnFirstDraw ! = null )
{
gcodeViewWidget . LoadInBackground ( partToStartLoadingOnFirstDraw ) ;
partToStartLoadingOnFirstDraw = null ;
}
base . OnDraw ( graphics2D ) ;
}
private void EnsureKeyDownHooked ( )
{
// let's just check that we are still hooked up to our parent window (this is to make pop outs work correctly)
if ( widgetThatHasKeyDownHooked ! = null )
{
GuiWidget topParent = Parent ;
while ( topParent as SystemWindow = = null )
{
topParent = topParent . Parent ;
}
if ( topParent ! = widgetThatHasKeyDownHooked )
{
widgetThatHasKeyDownHooked . KeyDown - = Parent_KeyDown ;
widgetThatHasKeyDownHooked = null ;
}
}
if ( widgetThatHasKeyDownHooked = = null )
{
GuiWidget parent = Parent ;
while ( parent as SystemWindow = = null )
{
parent = parent . Parent ;
}
2015-01-20 18:02:45 -08:00
UnHookWidgetThatHasKeyDownHooked ( ) ;
2015-04-08 15:20:10 -07:00
parent . KeyDown + = Parent_KeyDown ;
widgetThatHasKeyDownHooked = parent ;
}
}
2014-01-29 19:09:30 -08:00
2015-04-08 15:20:10 -07:00
private void UnHookWidgetThatHasKeyDownHooked ( )
2015-01-20 18:02:45 -08:00
{
if ( widgetThatHasKeyDownHooked ! = null )
{
widgetThatHasKeyDownHooked . KeyDown - = Parent_KeyDown ;
}
}
2015-04-08 15:20:10 -07:00
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 )
{
gcodeProcessingStateInfoText = new TextWidget ( message ) ;
gcodeProcessingStateInfoText . HAnchor = HAnchor . ParentCenter ;
gcodeProcessingStateInfoText . VAnchor = VAnchor . ParentCenter ;
gcodeProcessingStateInfoText . AutoExpandBoundsToText = true ;
GuiWidget labelContainer = new GuiWidget ( ) ;
labelContainer . AnchorAll ( ) ;
labelContainer . AddChild ( gcodeProcessingStateInfoText ) ;
labelContainer . Selectable = false ;
gcodeDisplayWidget . AddChild ( labelContainer ) ;
}
if ( message = = "" )
{
gcodeProcessingStateInfoText . BackgroundColor = new RGBA_Bytes ( ) ;
}
else
{
gcodeProcessingStateInfoText . BackgroundColor = RGBA_Bytes . White ;
}
gcodeProcessingStateInfoText . Text = message ;
}
private void LoadingProgressChanged ( object sender , ProgressChangedEventArgs e )
{
2016-01-20 10:12:01 -08:00
SetProcessingMessage ( string . Format ( "{0} {1}%..." , "Loading G-Code" . Localize ( ) , e . ProgressPercentage ) ) ;
2015-04-08 15:20:10 -07:00
}
private void CloseIfNotNull ( GuiWidget widget )
{
if ( widget ! = null )
{
widget . Close ( ) ;
}
}
private static bool RunningIn32Bit ( )
2015-01-19 17:33:17 -08:00
{
if ( IntPtr . Size = = 4 )
{
return true ;
}
return false ;
}
2015-04-08 15:20:10 -07:00
private void DoneLoadingGCode ( object sender , EventArgs e )
{
SetProcessingMessage ( "" ) ;
if ( gcodeViewWidget ! = null
2015-01-19 17:33:17 -08:00
& & gcodeViewWidget . LoadedGCode = = null )
{
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
& & gcodeViewWidget . LoadedGCode ! = null
2015-03-25 18:01:57 -07:00
& & gcodeViewWidget . LoadedGCode . LineCount > 0 )
2015-04-08 15:20:10 -07:00
{
2015-05-22 15:07:48 -07:00
CloseIfNotNull ( gradientWidget ) ;
gradientWidget = new ColorGradientWidget ( gcodeViewWidget . LoadedGCode ) ;
AddChild ( gradientWidget ) ;
gradientWidget . Visible = false ;
2015-05-04 17:16:06 -07:00
2015-04-08 15:20:10 -07:00
CreateOptionsContent ( ) ;
2015-05-22 15:07:48 -07:00
setGradientVisibility ( ) ;
2014-10-27 11:49:59 -07:00
buttonRightPanel . Visible = true ;
2015-04-08 15:20:10 -07:00
viewControlsToggle . Visible = true ;
CloseIfNotNull ( setLayerWidget ) ;
setLayerWidget = new SetLayerWidget ( gcodeViewWidget ) ;
setLayerWidget . VAnchor = Agg . UI . VAnchor . ParentTop ;
layerSelectionButtonsPanel . AddChild ( setLayerWidget ) ;
CloseIfNotNull ( navigationWidget ) ;
navigationWidget = new LayerNavigationWidget ( gcodeViewWidget ) ;
navigationWidget . Margin = new BorderDouble ( 0 , 0 , 20 , 0 ) ;
layerSelectionButtonsPanel . AddChild ( navigationWidget ) ;
CloseIfNotNull ( selectLayerSlider ) ;
selectLayerSlider = new SolidSlider ( new Vector2 ( ) , sliderWidth , 0 , gcodeViewWidget . LoadedGCode . NumChangesInZ - 1 , Orientation . Vertical ) ;
selectLayerSlider . ValueChanged + = new EventHandler ( selectLayerSlider_ValueChanged ) ;
gcodeViewWidget . ActiveLayerChanged + = new EventHandler ( gcodeViewWidget_ActiveLayerChanged ) ;
AddChild ( selectLayerSlider ) ;
CloseIfNotNull ( layerRenderRatioSlider ) ;
layerRenderRatioSlider = new DoubleSolidSlider ( new Vector2 ( ) , sliderWidth ) ;
layerRenderRatioSlider . FirstValue = 0 ;
layerRenderRatioSlider . FirstValueChanged + = new EventHandler ( layerStartRenderRatioSlider_ValueChanged ) ;
layerRenderRatioSlider . SecondValue = 1 ;
layerRenderRatioSlider . SecondValueChanged + = new EventHandler ( layerEndRenderRatioSlider_ValueChanged ) ;
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 ;
BoundsChanged + = new EventHandler ( PartPreviewGCode_BoundsChanged ) ;
meshViewerWidget . partProcessingInfo . Visible = false ;
}
}
2015-05-22 15:07:48 -07:00
private void setGradientVisibility ( )
{
if ( showSpeeds . Checked )
{
gradientWidget . Visible = true ;
}
else
{
gradientWidget . Visible = false ;
}
}
2015-05-04 17:16:06 -07:00
2015-04-08 15:20:10 -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 ) ;
}
private void PartPreviewGCode_BoundsChanged ( object sender , EventArgs e )
{
SetSliderSizes ( ) ;
}
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 ;
}
private void AddHandlers ( )
{
2015-04-22 08:43:09 -07:00
expandModelOptions . CheckedStateChanged + = expandModelOptions_CheckedStateChanged ;
expandDisplayOptions . CheckedStateChanged + = expandDisplayOptions_CheckedStateChanged ;
2015-04-08 15:20:10 -07:00
}
private void expandModelOptions_CheckedStateChanged ( object sender , EventArgs e )
{
if ( modelOptionsContainer . Visible = expandModelOptions . Checked )
{
if ( expandModelOptions . Checked = = true )
{
expandDisplayOptions . Checked = false ;
}
modelOptionsContainer . Visible = expandModelOptions . Checked ;
}
}
private void expandDisplayOptions_CheckedStateChanged ( object sender , EventArgs e )
{
if ( displayOptionsContainer . Visible ! = expandDisplayOptions . Checked )
{
if ( expandDisplayOptions . Checked = = true )
{
expandModelOptions . Checked = false ;
}
displayOptionsContainer . Visible = expandDisplayOptions . Checked ;
}
}
public override void OnClosed ( EventArgs e )
{
2015-01-20 18:02:45 -08:00
UnHookWidgetThatHasKeyDownHooked ( ) ;
2014-04-20 22:09:10 -07:00
2015-04-08 15:20:10 -07:00
if ( unregisterEvents ! = null )
{
unregisterEvents ( this , null ) ;
}
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 generateButton_Click ( object sender , EventArgs mouseEvent )
{
UiThread . RunOnIdle ( DoGenerateButton_Click , sender ) ;
}
private void DoGenerateButton_Click ( object state )
{
2016-03-04 11:11:20 -08:00
if ( PrinterConnectionAndCommunication . Instance . ActivePrinter ! = null )
2015-04-08 15:20:10 -07:00
{
2016-03-04 11:11:20 -08:00
if ( ActiveSliceSettings . Instance . IsValid ( ) & & printItem ! = null )
{
( ( Button ) state ) . Visible = false ;
SlicingQueue . Instance . QueuePartForSlicing ( printItem ) ;
startedSliceFromGenerateButton = true ;
}
}
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
}
}
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
UiThread . RunOnIdle ( CreateAndAddChildren ) ;
startedSliceFromGenerateButton = false ;
}
}
public class SetLayerWidget : FlowLayoutWidget
{
private NumberEdit editCurrentLayerIndex ;
private Button setLayerButton ;
private ViewGcodeWidget gcodeViewWidget ;
private TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory ( ) ;
public SetLayerWidget ( ViewGcodeWidget gcodeViewWidget )
: base ( FlowDirection . LeftToRight )
{
this . gcodeViewWidget = gcodeViewWidget ;
textImageButtonFactory . normalTextColor = ActiveTheme . Instance . PrimaryTextColor ;
textImageButtonFactory . hoverTextColor = ActiveTheme . Instance . PrimaryTextColor ;
textImageButtonFactory . disabledTextColor = ActiveTheme . Instance . PrimaryTextColor ;
textImageButtonFactory . pressedTextColor = ActiveTheme . Instance . PrimaryTextColor ;
editCurrentLayerIndex = new NumberEdit ( 1 , pixelWidth : 40 ) ;
editCurrentLayerIndex . VAnchor = VAnchor . ParentCenter ;
editCurrentLayerIndex . Margin = new BorderDouble ( 5 , 0 ) ;
editCurrentLayerIndex . EditComplete + = new EventHandler ( editCurrentLayerIndex_EditComplete ) ;
this . AddChild ( editCurrentLayerIndex ) ;
gcodeViewWidget . ActiveLayerChanged + = new EventHandler ( gcodeViewWidget_ActiveLayerChanged ) ;
2014-01-29 19:09:30 -08:00
2014-03-11 15:24:47 -07:00
setLayerButton = textImageButtonFactory . Generate ( LocalizedString . Get ( "Go" ) ) ;
2015-04-08 15:20:10 -07:00
setLayerButton . VAnchor = Agg . UI . VAnchor . ParentCenter ;
setLayerButton . Click + = new EventHandler ( layerCountTextWidget_EditComplete ) ;
this . AddChild ( setLayerButton ) ;
}
private void gcodeViewWidget_ActiveLayerChanged ( object sender , EventArgs e )
{
editCurrentLayerIndex . Value = gcodeViewWidget . ActiveLayerIndex + 1 ;
}
private void editCurrentLayerIndex_EditComplete ( object sender , EventArgs e )
{
gcodeViewWidget . ActiveLayerIndex = ( ( int ) editCurrentLayerIndex . Value - 1 ) ;
editCurrentLayerIndex . Value = gcodeViewWidget . ActiveLayerIndex + 1 ;
}
private void layerCountTextWidget_EditComplete ( object sender , EventArgs e )
{
gcodeViewWidget . ActiveLayerIndex = ( ( int ) editCurrentLayerIndex . Value - 1 ) ;
}
}
public class LayerNavigationWidget : FlowLayoutWidget
{
private Button prevLayerButton ;
private Button nextLayerButton ;
private TextWidget layerCountTextWidget ;
private ViewGcodeWidget gcodeViewWidget ;
private TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory ( ) ;
public LayerNavigationWidget ( ViewGcodeWidget gcodeViewWidget )
: base ( FlowDirection . LeftToRight )
{
this . gcodeViewWidget = gcodeViewWidget ;
textImageButtonFactory . normalTextColor = ActiveTheme . Instance . PrimaryTextColor ;
textImageButtonFactory . hoverTextColor = ActiveTheme . Instance . PrimaryTextColor ;
textImageButtonFactory . disabledTextColor = ActiveTheme . Instance . PrimaryTextColor ;
textImageButtonFactory . pressedTextColor = ActiveTheme . Instance . PrimaryTextColor ;
prevLayerButton = textImageButtonFactory . Generate ( "<<" ) ;
prevLayerButton . Click + = new EventHandler ( prevLayer_ButtonClick ) ;
this . AddChild ( prevLayerButton ) ;
layerCountTextWidget = new TextWidget ( "/1____" , 12 ) ;
layerCountTextWidget . TextColor = ActiveTheme . Instance . PrimaryTextColor ;
layerCountTextWidget . VAnchor = VAnchor . ParentCenter ;
layerCountTextWidget . AutoExpandBoundsToText = true ;
layerCountTextWidget . Margin = new BorderDouble ( 5 , 0 ) ;
this . AddChild ( layerCountTextWidget ) ;
nextLayerButton = textImageButtonFactory . Generate ( ">>" ) ;
nextLayerButton . Click + = new EventHandler ( nextLayer_ButtonClick ) ;
this . AddChild ( nextLayerButton ) ;
}
private void nextLayer_ButtonClick ( object sender , EventArgs mouseEvent )
{
gcodeViewWidget . ActiveLayerIndex = ( gcodeViewWidget . ActiveLayerIndex + 1 ) ;
}
private void prevLayer_ButtonClick ( object sender , EventArgs mouseEvent )
{
gcodeViewWidget . ActiveLayerIndex = ( gcodeViewWidget . ActiveLayerIndex - 1 ) ;
}
public override void OnDraw ( Graphics2D graphics2D )
{
if ( gcodeViewWidget . LoadedGCode ! = null )
{
layerCountTextWidget . Text = string . Format ( "{0} / {1}" , gcodeViewWidget . ActiveLayerIndex + 1 , gcodeViewWidget . LoadedGCode . NumChangesInZ . ToString ( ) ) ;
}
base . OnDraw ( graphics2D ) ;
}
}
2016-06-27 12:05:14 -07:00
}