2017-07-06 12:22:56 -07:00
/ *
Copyright ( c ) 2017 , Lars Brubaker , John Lewin
All rights reserved .
Redistribution and use in source and binary forms , with or without
modification , are permitted provided that the following conditions are met :
1. Redistributions of source code must retain the above copyright notice , this
list of conditions and the following disclaimer .
2. Redistributions in binary form must reproduce the above copyright notice ,
this list of conditions and the following disclaimer in the documentation
and / or other materials provided with the distribution .
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES
( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ;
LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies ,
either expressed or implied , of the FreeBSD Project .
* /
2017-07-07 16:50:47 -07:00
using System ;
2017-07-10 12:32:41 -07:00
using System.Linq ;
2017-07-06 12:22:56 -07:00
using MatterHackers.Agg ;
2017-07-10 14:00:27 -07:00
using MatterHackers.Agg.OpenGlGui ;
2017-07-06 12:22:56 -07:00
using MatterHackers.Agg.UI ;
2017-07-07 16:50:47 -07:00
using MatterHackers.GCodeVisualizer ;
2017-07-06 12:22:56 -07:00
using MatterHackers.Localizations ;
using MatterHackers.MatterControl.CustomWidgets ;
2017-07-07 16:50:47 -07:00
using MatterHackers.MatterControl.PrinterCommunication ;
using MatterHackers.MatterControl.PrinterControls ;
2017-07-06 12:22:56 -07:00
using MatterHackers.MatterControl.PrintQueue ;
using MatterHackers.MatterControl.SlicerConfiguration ;
using MatterHackers.MeshVisualizer ;
using MatterHackers.VectorMath ;
namespace MatterHackers.MatterControl.PartPreviewWindow
{
public class PrinterTabPage : GuiWidget
{
2017-07-10 14:00:27 -07:00
internal View3DWidget modelViewer ;
2017-07-10 12:23:02 -07:00
internal GCode2DWidget gcode2DWidget ;
2017-07-06 12:22:56 -07:00
private PrintItemWrapper printItem ;
private ViewControls3D viewControls3D ;
2017-07-06 14:41:32 -07:00
private DoubleSolidSlider layerRenderRatioSlider ;
private SolidSlider selectLayerSlider ;
private PrinterConfig printer ;
private View3DConfig gcodeOptions ;
private GuiWidget view3DContainer ;
2017-07-07 16:50:47 -07:00
private TextWidget layerCountText ;
private TextWidget layerStartText ;
private ValueDisplayInfo currentLayerInfo ;
2017-07-10 12:23:02 -07:00
private Vector3 viewerVolume ;
private Vector2 bedCenter ;
2017-07-10 12:32:41 -07:00
private SystemWindow parentSystemWindow ;
2017-07-06 12:22:56 -07:00
public PrinterTabPage ( PrinterSettings activeSettings , PrintItemWrapper printItem )
{
2017-07-06 14:41:32 -07:00
printer = ApplicationController . Instance . Printer ;
2017-07-07 12:52:00 -07:00
2017-07-06 14:41:32 -07:00
gcodeOptions = printer . BedPlate . RendererOptions ;
2017-07-06 12:22:56 -07:00
this . BackgroundColor = ApplicationController . Instance . Theme . TabBodyBackground ;
this . Padding = new BorderDouble ( top : 3 ) ;
double buildHeight = activeSettings . GetValue < double > ( SettingsKey . build_height ) ;
viewControls3D = new ViewControls3D ( ApplicationController . Instance . Theme . ViewControlsButtonFactory )
{
PartSelectVisible = false ,
VAnchor = VAnchor . ParentTop | VAnchor . FitToChildren | VAnchor . AbsolutePosition ,
HAnchor = HAnchor . ParentLeft | HAnchor . FitToChildren ,
Visible = true ,
Margin = new BorderDouble ( 11 , 0 , 0 , 50 )
} ;
2017-07-06 18:15:53 -07:00
viewControls3D . ViewModeChanged + = ( s , e ) = >
{
2017-07-07 06:18:58 -07:00
this . ViewMode = e . ViewMode ;
2017-07-06 18:15:53 -07:00
} ;
2017-07-10 12:23:02 -07:00
viewControls3D . TransformStateChanged + = ( s , e ) = >
{
switch ( e . TransformMode )
{
case ViewControls3DButtons . Translate :
if ( gcode2DWidget ! = null )
{
gcode2DWidget . TransformState = GCode2DWidget . ETransformState . Move ;
}
break ;
case ViewControls3DButtons . Scale :
if ( gcode2DWidget ! = null )
{
gcode2DWidget . TransformState = GCode2DWidget . ETransformState . Scale ;
}
break ;
}
} ;
2017-07-06 12:22:56 -07:00
viewControls3D . ResetView + = ( sender , e ) = >
{
2017-07-10 12:23:02 -07:00
if ( gcode2DWidget . Visible )
{
gcode2DWidget . CenterPartInView ( ) ;
}
else if ( modelViewer . Visible )
{
2017-07-10 14:00:27 -07:00
this . modelViewer . ResetView ( ) ;
2017-07-10 12:23:02 -07:00
}
2017-07-06 12:22:56 -07:00
} ;
viewControls3D . OverflowButton . DynamicPopupContent = ( ) = >
{
2017-07-10 14:00:27 -07:00
if ( modelViewer . gcodeViewer . Visible )
2017-07-06 12:22:56 -07:00
{
2017-07-06 14:41:32 -07:00
return this . ShowGCodeOverflowMenu ( ) ;
2017-07-06 12:22:56 -07:00
}
else
{
return modelViewer . ShowOverflowMenu ( ) ;
}
} ;
2017-07-06 14:41:32 -07:00
int sliderWidth = ( UserSettings . Instance . IsTouchScreen ) ? 20 : 10 ;
2017-07-07 16:50:47 -07:00
layerCountText = new TextWidget ( "" , pointSize : 9 , textColor : ActiveTheme . Instance . PrimaryTextColor )
{
Visible = false ,
AutoExpandBoundsToText = true
} ;
layerStartText = new TextWidget ( "1" , pointSize : 9 , textColor : ActiveTheme . Instance . PrimaryTextColor )
{
Visible = false ,
AutoExpandBoundsToText = true
} ;
2017-07-06 14:41:32 -07:00
selectLayerSlider = new SolidSlider ( new Vector2 ( ) , sliderWidth , 0 , 1 , Orientation . Vertical ) ;
selectLayerSlider . ValueChanged + = ( s , e ) = >
{
// TODO: Why would these need to be updated here as well as in the horizontal slider?
printer . BedPlate . RenderInfo . FeatureToStartOnRatio0To1 = layerRenderRatioSlider . FirstValue ;
printer . BedPlate . RenderInfo . FeatureToEndOnRatio0To1 = layerRenderRatioSlider . SecondValue ;
printer . BedPlate . ActiveLayerIndex = ( int ) ( selectLayerSlider . Value + . 5 ) ;
2017-07-07 12:52:00 -07:00
// show the layer info next to the slider
2017-07-06 14:41:32 -07:00
this . Invalidate ( ) ;
} ;
layerRenderRatioSlider = new DoubleSolidSlider ( new Vector2 ( ) , sliderWidth ) ;
layerRenderRatioSlider . FirstValue = 0 ;
layerRenderRatioSlider . FirstValueChanged + = ( s , e ) = >
{
printer . BedPlate . RenderInfo . FeatureToStartOnRatio0To1 = layerRenderRatioSlider . FirstValue ;
printer . BedPlate . RenderInfo . FeatureToEndOnRatio0To1 = layerRenderRatioSlider . SecondValue ;
this . Invalidate ( ) ;
} ;
layerRenderRatioSlider . SecondValue = 1 ;
layerRenderRatioSlider . SecondValueChanged + = ( s , e ) = >
{
printer . BedPlate . RenderInfo . FeatureToStartOnRatio0To1 = layerRenderRatioSlider . FirstValue ;
printer . BedPlate . RenderInfo . FeatureToEndOnRatio0To1 = layerRenderRatioSlider . SecondValue ;
this . Invalidate ( ) ;
} ;
SetSliderSizes ( ) ;
2017-07-10 12:23:02 -07:00
this . viewerVolume = new Vector3 ( activeSettings . GetValue < Vector2 > ( SettingsKey . bed_size ) , buildHeight ) ;
this . bedCenter = activeSettings . GetValue < Vector2 > ( SettingsKey . print_center ) ;
2017-07-06 12:22:56 -07:00
// The 3D model view
modelViewer = new View3DWidget ( printItem ,
2017-07-10 12:23:02 -07:00
this . viewerVolume ,
this . bedCenter ,
2017-07-06 12:22:56 -07:00
activeSettings . GetValue < BedShape > ( SettingsKey . bed_shape ) ,
View3DWidget . WindowMode . Embeded ,
View3DWidget . AutoRotate . Disabled ,
viewControls3D ,
ApplicationController . Instance . Theme ,
View3DWidget . OpenMode . Editing ) ;
2017-07-06 15:04:44 -07:00
modelViewer . BoundsChanged + = ( s , e ) = >
{
SetSliderSizes ( ) ;
} ;
2017-07-06 12:22:56 -07:00
var topToBottom = new FlowLayoutWidget ( FlowDirection . TopToBottom ) ;
topToBottom . AnchorAll ( ) ;
this . AddChild ( topToBottom ) ;
// Must come after we have an instance of View3DWidget an its undo buffer
topToBottom . AddChild ( new PrinterActionsBar ( modelViewer , this )
{
Padding = new BorderDouble ( bottom : 2 )
} ) ;
var leftToRight = new FlowLayoutWidget ( ) ;
leftToRight . AnchorAll ( ) ;
topToBottom . AddChild ( leftToRight ) ;
2017-07-06 14:41:32 -07:00
view3DContainer = new GuiWidget ( ) ;
view3DContainer . AnchorAll ( ) ;
view3DContainer . AddChild ( modelViewer ) ;
2017-07-06 12:22:56 -07:00
2017-07-06 14:41:32 -07:00
leftToRight . AddChild ( view3DContainer ) ;
2017-07-06 12:22:56 -07:00
2017-07-06 14:41:32 -07:00
view3DContainer . AddChild ( layerRenderRatioSlider ) ;
view3DContainer . AddChild ( selectLayerSlider ) ;
2017-07-07 16:50:47 -07:00
view3DContainer . AddChild ( layerCountText ) ;
view3DContainer . AddChild ( layerStartText ) ;
2017-07-06 14:41:32 -07:00
2017-07-07 16:50:47 -07:00
//currentLayerInfo = new ValueDisplayInfo("1000", Agg.Font.Justification.Right)
currentLayerInfo = new ValueDisplayInfo ( "1000" )
2017-07-07 12:52:00 -07:00
{
2017-07-07 16:50:47 -07:00
GetDisplayString = ( value ) = > $"{value + 1}"
2017-07-07 12:52:00 -07:00
} ;
currentLayerInfo . EditComplete + = ( s , e ) = >
{
2017-07-07 16:50:47 -07:00
printer . BedPlate . ActiveLayerIndex = ( int ) currentLayerInfo . Value - 1 ;
2017-07-07 12:52:00 -07:00
} ;
2017-07-07 16:50:47 -07:00
printer . BedPlate . ActiveLayerChanged + = SetPositionAndValue ;
selectLayerSlider . MouseEnter + = SetPositionAndValue ;
2017-07-07 12:52:00 -07:00
currentLayerInfo . Visible = false ;
view3DContainer . AddChild ( currentLayerInfo ) ;
2017-07-06 14:41:32 -07:00
printer . BedPlate . ActiveLayerChanged + = ActiveLayer_Changed ;
2017-07-06 12:22:56 -07:00
AddSettingsTabBar ( leftToRight , modelViewer ) ;
modelViewer . BackgroundColor = ActiveTheme . Instance . TertiaryBackgroundColor ;
if ( ApplicationController . Instance . PartPreviewState . RotationMatrix = = Matrix4X4 . Identity )
{
2017-07-10 14:00:27 -07:00
this . modelViewer . ResetView ( ) ;
2017-07-06 12:22:56 -07:00
2017-07-11 08:10:57 -07:00
ApplicationController . Instance . PartPreviewState . RotationMatrix = modelViewer . World . RotationMatrix ;
ApplicationController . Instance . PartPreviewState . TranslationMatrix = modelViewer . World . TranslationMatrix ;
2017-07-06 12:22:56 -07:00
}
else
{
2017-07-11 08:10:57 -07:00
modelViewer . World . RotationMatrix = ApplicationController . Instance . PartPreviewState . RotationMatrix ;
modelViewer . World . TranslationMatrix = ApplicationController . Instance . PartPreviewState . TranslationMatrix ;
2017-07-06 12:22:56 -07:00
}
2017-07-06 14:41:32 -07:00
printer . BedPlate . LoadedGCodeChanged + = BedPlate_LoadedGCodeChanged ;
2017-07-06 15:58:14 -07:00
2017-07-06 14:41:32 -07:00
this . ShowSliceLayers = false ;
2017-07-06 12:22:56 -07:00
this . printItem = printItem ;
this . AddChild ( viewControls3D ) ;
this . AnchorAll ( ) ;
}
2017-07-07 16:50:47 -07:00
private void SetPositionAndValue ( object sender , EventArgs e )
{
UiThread . RunOnIdle ( ( ) = >
{
currentLayerInfo . Value = printer . BedPlate . ActiveLayerIndex ;
//currentLayerInfo.DebugShowBounds = true;
currentLayerInfo . OriginRelativeParent = selectLayerSlider . OriginRelativeParent
+ new Vector2 ( - currentLayerInfo . Width - 10 , selectLayerSlider . PositionPixelsFromFirstValue - currentLayerInfo . Height / 2 ) ;
currentLayerInfo . Visible = true ;
} ) ;
}
2017-07-06 14:41:32 -07:00
private void BedPlate_LoadedGCodeChanged ( object sender , EventArgs e )
{
2017-07-07 16:50:47 -07:00
var layerCount = printer . BedPlate . LoadedGCode . LayerCount ;
selectLayerSlider . Maximum = layerCount - 1 ;
layerCountText . Text = layerCount . ToString ( ) ;
layerCountText . Visible = true ;
layerStartText . Visible = true ;
2017-07-06 15:58:14 -07:00
// ResetRenderInfo
printer . BedPlate . RenderInfo = new GCodeRenderInfo (
0 ,
1 ,
Agg . Transform . Affine . NewIdentity ( ) ,
1 ,
0 ,
1 ,
new Vector2 [ ]
{
ActiveSliceSettings . Instance . Helpers . ExtruderOffset ( 0 ) ,
ActiveSliceSettings . Instance . Helpers . ExtruderOffset ( 1 )
} ,
this . GetRenderType ,
MeshViewerWidget . GetMaterialColor ) ;
2017-07-10 12:23:02 -07:00
// Close and remove any existing widget reference
gcode2DWidget ? . Close ( ) ;
// Create and append new widget
gcode2DWidget = new GCode2DWidget ( new Vector2 ( viewerVolume . x , viewerVolume . y ) , this . bedCenter )
{
Visible = ( this . ViewMode = = PartViewMode . Layers2D )
} ;
view3DContainer . AddChild ( gcode2DWidget ) ;
viewControls3D . Layers2DButton . Enabled = true ;
2017-07-06 15:58:14 -07:00
}
private RenderType GetRenderType ( )
{
RenderType renderType = RenderType . Extrusions ;
if ( gcodeOptions . RenderMoves )
{
renderType | = RenderType . Moves ;
}
if ( gcodeOptions . RenderRetractions )
{
renderType | = RenderType . Retractions ;
}
if ( gcodeOptions . RenderSpeeds )
{
renderType | = RenderType . SpeedColors ;
}
if ( gcodeOptions . SimulateExtrusion )
{
renderType | = RenderType . SimulateExtrusion ;
}
if ( gcodeOptions . TransparentExtrusion )
{
renderType | = RenderType . TransparentExtrusion ;
}
if ( gcodeOptions . HideExtruderOffsets )
{
renderType | = RenderType . HideExtruderOffsets ;
}
return renderType ;
2017-07-06 14:41:32 -07:00
}
2017-07-06 12:22:56 -07:00
private void AddSettingsTabBar ( GuiWidget parent , GuiWidget widgetTodockTo )
{
var sideBar = new DockingTabControl ( widgetTodockTo , DockSide . Right )
{
ControlIsPinned = ApplicationController . Instance . PrintSettingsPinned
} ;
sideBar . PinStatusChanged + = ( s , e ) = >
{
ApplicationController . Instance . PrintSettingsPinned = sideBar . ControlIsPinned ;
} ;
parent . AddChild ( sideBar ) ;
if ( ActiveSliceSettings . Instance . PrinterSelected )
{
sideBar . AddPage ( "Slice Settings" . Localize ( ) , new SliceSettingsWidget ( ) ) ;
}
else
{
sideBar . AddPage ( "Slice Settings" . Localize ( ) , new NoSettingsWidget ( ) ) ;
}
sideBar . AddPage ( "Controls" . Localize ( ) , new ManualPrinterControls ( ) ) ;
var terminalControls = new TerminalControls ( ) ;
terminalControls . VAnchor | = VAnchor . ParentBottomTop ;
sideBar . AddPage ( "Terminal" . Localize ( ) , terminalControls ) ;
}
2017-07-06 15:58:14 -07:00
private GCodeFile loadedGCode = > printer . BedPlate . LoadedGCode ;
2017-07-06 14:41:32 -07:00
private bool showSliceLayers ;
2017-07-07 06:18:58 -07:00
private bool ShowSliceLayers
2017-07-06 14:41:32 -07:00
{
get = > showSliceLayers ;
set
{
showSliceLayers = value ;
2017-07-10 14:00:27 -07:00
modelViewer . gcodeViewer . Visible = value ;
2017-07-06 14:41:32 -07:00
modelViewer . meshViewerWidget . IsActive = ! value ;
if ( showSliceLayers )
{
modelViewer . Scene . ClearSelection ( ) ;
}
var slidersVisible = printer . BedPlate . RenderInfo ! = null & & value ;
selectLayerSlider . Visible = slidersVisible ;
layerRenderRatioSlider . Visible = slidersVisible ;
modelViewer . selectedObjectPanel . Visible = ! showSliceLayers ;
}
2017-07-06 12:22:56 -07:00
}
2017-07-07 06:18:58 -07:00
private PartViewMode viewMode ;
public PartViewMode ViewMode
{
get = > viewMode ;
set
{
if ( viewMode ! = value )
{
viewMode = value ;
viewControls3D . ViewMode = viewMode ;
switch ( viewMode )
{
case PartViewMode . Layers2D :
UserSettings . Instance . set ( "LayerViewDefault" , "2D Layer" ) ;
2017-07-10 12:23:02 -07:00
if ( gcode2DWidget ! = null )
2017-07-07 06:18:58 -07:00
{
2017-07-10 12:23:02 -07:00
gcode2DWidget . Visible = true ;
2017-07-07 06:18:58 -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
2017-07-10 12:23:02 -07:00
UiThread . RunOnIdle ( gcode2DWidget . CenterPartInView ) ;
2017-07-07 06:18:58 -07:00
}
this . ShowSliceLayers = true ;
break ;
case PartViewMode . Layers3D :
UserSettings . Instance . set ( "LayerViewDefault" , "3D Layer" ) ;
2017-07-10 12:23:02 -07:00
if ( gcode2DWidget ! = null )
2017-07-07 06:18:58 -07:00
{
2017-07-10 12:23:02 -07:00
gcode2DWidget . Visible = false ;
2017-07-07 06:18:58 -07:00
}
this . ShowSliceLayers = true ;
break ;
case PartViewMode . Model :
this . ShowSliceLayers = false ;
break ;
}
}
}
}
2017-07-06 12:22:56 -07:00
private async void LoadActivePrintItem ( )
{
await modelViewer . ClearBedAndLoadPrintItemWrapper ( printItem ) ;
}
public override void OnLoad ( EventArgs args )
{
ApplicationController . Instance . ActiveView3DWidget = modelViewer ;
LoadActivePrintItem ( ) ;
2017-07-10 12:32:41 -07:00
// Find and hook the parent system window KeyDown event
if ( this . Parents < SystemWindow > ( ) . FirstOrDefault ( ) is SystemWindow systemWindow )
{
systemWindow . KeyDown + = Parent_KeyDown ;
parentSystemWindow = systemWindow ;
}
2017-07-06 12:22:56 -07:00
base . OnLoad ( args ) ;
}
2017-07-10 12:32:41 -07:00
private void Parent_KeyDown ( object sender , KeyEventArgs keyEvent )
{
2017-07-10 14:00:27 -07:00
if ( modelViewer . gcodeViewer . Visible )
2017-07-10 12:32:41 -07:00
{
switch ( keyEvent . KeyCode )
{
case Keys . Up :
printer . BedPlate . ActiveLayerIndex + = 1 ;
break ;
case Keys . Down :
printer . BedPlate . ActiveLayerIndex - = 1 ;
break ;
}
}
}
2017-07-06 14:41:32 -07:00
public override void OnDraw ( Graphics2D graphics2D )
{
bool printerIsRunningPrint = PrinterConnection . Instance . PrinterIsPaused | | PrinterConnection . Instance . PrinterIsPrinting ;
if ( gcodeOptions . SyncToPrint
& & printerIsRunningPrint
2017-07-10 14:00:27 -07:00
& & modelViewer . gcodeViewer . Visible )
2017-07-06 14:41:32 -07:00
{
SetAnimationPosition ( ) ;
this . Invalidate ( ) ;
}
base . OnDraw ( graphics2D ) ;
}
2017-07-06 12:22:56 -07:00
public override void OnClosed ( ClosedEventArgs e )
{
2017-07-06 14:41:32 -07:00
// Store active transforms on close
2017-07-11 08:10:57 -07:00
ApplicationController . Instance . PartPreviewState . RotationMatrix = modelViewer . World . RotationMatrix ;
ApplicationController . Instance . PartPreviewState . TranslationMatrix = modelViewer . World . TranslationMatrix ;
2017-07-06 12:22:56 -07:00
2017-07-10 12:32:41 -07:00
// Find and unhook the parent system window KeyDown event
if ( parentSystemWindow ! = null )
{
parentSystemWindow . KeyDown - = Parent_KeyDown ;
}
2017-07-06 14:41:32 -07:00
printer . BedPlate . ActiveLayerChanged - = ActiveLayer_Changed ;
printer . BedPlate . LoadedGCodeChanged - = BedPlate_LoadedGCodeChanged ;
2017-07-07 16:50:47 -07:00
printer . BedPlate . ActiveLayerChanged - = SetPositionAndValue ;
selectLayerSlider . MouseEnter - = SetPositionAndValue ;
2017-07-06 12:22:56 -07:00
base . OnClosed ( e ) ;
}
2017-07-06 14:41:32 -07:00
internal GuiWidget ShowGCodeOverflowMenu ( )
{
var textColor = RGBA_Bytes . Black ;
var popupContainer = new FlowLayoutWidget ( FlowDirection . TopToBottom )
{
HAnchor = HAnchor . ParentLeftRight ,
Padding = 12 ,
BackgroundColor = RGBA_Bytes . White
} ;
// put in a show grid check box
CheckBox showGrid = new CheckBox ( "Print Bed" . Localize ( ) , textColor : textColor ) ;
showGrid . Checked = gcodeOptions . RenderGrid ;
showGrid . CheckedStateChanged + = ( sender , e ) = >
{
// TODO: How (if at all) do we disable bed rendering on GCode2D?
gcodeOptions . RenderGrid = showGrid . Checked ;
} ;
popupContainer . AddChild ( showGrid ) ;
// put in a show moves checkbox
var showMoves = new CheckBox ( "Moves" . Localize ( ) , textColor : textColor ) ;
showMoves . Checked = gcodeOptions . RenderMoves ;
showMoves . CheckedStateChanged + = ( sender , e ) = >
{
gcodeOptions . RenderMoves = showMoves . Checked ;
} ;
popupContainer . AddChild ( showMoves ) ;
// put in a show Retractions checkbox
CheckBox showRetractions = new CheckBox ( "Retractions" . Localize ( ) , textColor : textColor ) ;
showRetractions . Checked = gcodeOptions . RenderRetractions ;
showRetractions . CheckedStateChanged + = ( sender , e ) = >
{
gcodeOptions . RenderRetractions = showRetractions . Checked ;
} ;
popupContainer . AddChild ( showRetractions ) ;
// Speeds checkbox
var showSpeeds = new CheckBox ( "Speeds" . Localize ( ) , textColor : textColor ) ;
showSpeeds . Checked = gcodeOptions . RenderSpeeds ;
showSpeeds . CheckedStateChanged + = ( sender , e ) = >
{
//gradientWidget.Visible = showSpeeds.Checked;
gcodeOptions . RenderSpeeds = showSpeeds . Checked ;
} ;
popupContainer . AddChild ( showSpeeds ) ;
// Extrusion checkbox
var simulateExtrusion = new CheckBox ( "Extrusion" . Localize ( ) , textColor : textColor ) ;
simulateExtrusion . Checked = gcodeOptions . SimulateExtrusion ;
simulateExtrusion . CheckedStateChanged + = ( sender , e ) = >
{
gcodeOptions . SimulateExtrusion = simulateExtrusion . Checked ;
} ;
popupContainer . AddChild ( simulateExtrusion ) ;
// Transparent checkbox
var transparentExtrusion = new CheckBox ( "Transparent" . Localize ( ) , textColor : textColor )
{
Checked = gcodeOptions . TransparentExtrusion ,
Margin = new BorderDouble ( 5 , 0 , 0 , 0 ) ,
HAnchor = HAnchor . ParentLeft ,
} ;
transparentExtrusion . CheckedStateChanged + = ( sender , e ) = >
{
gcodeOptions . TransparentExtrusion = transparentExtrusion . Checked ;
} ;
popupContainer . AddChild ( transparentExtrusion ) ;
// Extrusion checkbox
if ( ActiveSliceSettings . Instance . GetValue < int > ( SettingsKey . extruder_count ) > 1 )
{
CheckBox hideExtruderOffsets = new CheckBox ( "Hide Offsets" , textColor : textColor ) ;
hideExtruderOffsets . Checked = gcodeOptions . HideExtruderOffsets ;
hideExtruderOffsets . CheckedStateChanged + = ( sender , e ) = >
{
gcodeOptions . HideExtruderOffsets = hideExtruderOffsets . Checked ;
} ;
popupContainer . AddChild ( hideExtruderOffsets ) ;
}
// Sync To Print checkbox
{
var syncToPrint = new CheckBox ( "Sync To Print" . Localize ( ) , textColor : textColor ) ;
syncToPrint . Checked = ( UserSettings . Instance . get ( "LayerViewSyncToPrint" ) = = "True" ) ;
syncToPrint . Name = "Sync To Print Checkbox" ;
syncToPrint . CheckedStateChanged + = ( s , e ) = >
{
gcodeOptions . SyncToPrint = syncToPrint . Checked ;
SetSyncToPrintVisibility ( ) ;
} ;
popupContainer . AddChild ( syncToPrint ) ;
}
return popupContainer ;
}
2017-07-07 16:50:47 -07:00
2017-07-06 14:41:32 -07:00
private void SetSyncToPrintVisibility ( )
{
bool printerIsRunningPrint = PrinterConnection . Instance . PrinterIsPaused | | PrinterConnection . Instance . PrinterIsPrinting ;
if ( gcodeOptions . SyncToPrint & & printerIsRunningPrint )
{
SetAnimationPosition ( ) ;
layerRenderRatioSlider . Visible = false ;
selectLayerSlider . Visible = false ;
}
else
{
if ( layerRenderRatioSlider ! = null )
{
layerRenderRatioSlider . FirstValue = 0 ;
layerRenderRatioSlider . SecondValue = 1 ;
}
layerRenderRatioSlider . Visible = true ;
selectLayerSlider . Visible = true ;
}
}
private void SetSliderSizes ( )
{
2017-07-06 15:04:44 -07:00
if ( selectLayerSlider = = null | | modelViewer = = null )
2017-07-06 14:41:32 -07:00
{
return ;
}
2017-07-06 15:04:44 -07:00
selectLayerSlider . OriginRelativeParent = new Vector2 ( modelViewer . Width - 20 , 78 ) ;
2017-07-07 16:50:47 -07:00
selectLayerSlider . TotalWidthInPixels = modelViewer . Height - 100 ;
2017-07-06 14:41:32 -07:00
layerRenderRatioSlider . OriginRelativeParent = new Vector2 ( 11 , 65 ) ;
2017-07-06 15:04:44 -07:00
layerRenderRatioSlider . TotalWidthInPixels = modelViewer . Width - 45 ;
2017-07-07 16:50:47 -07:00
layerCountText . OriginRelativeParent = new Vector2 ( modelViewer . Width - 26 + ( layerCountText . Width / 2 ) , modelViewer . Height - 15 ) ;
layerStartText . OriginRelativeParent = new Vector2 ( modelViewer . Width - 26 + ( layerStartText . Width / 2 ) , 63 ) ;
2017-07-06 14:41:32 -07:00
}
private void SetAnimationPosition ( )
{
int currentLayer = PrinterConnection . Instance . CurrentlyPrintingLayer ;
if ( currentLayer < = 0 )
{
selectLayerSlider . Value = 0 ;
layerRenderRatioSlider . SecondValue = 0 ;
layerRenderRatioSlider . FirstValue = 0 ;
}
else
{
selectLayerSlider . Value = currentLayer - 1 ;
layerRenderRatioSlider . SecondValue = PrinterConnection . Instance . RatioIntoCurrentLayer ;
layerRenderRatioSlider . FirstValue = 0 ;
}
}
private void ActiveLayer_Changed ( object sender , EventArgs e )
{
if ( selectLayerSlider ! = null
& & printer . BedPlate . ActiveLayerIndex ! = ( int ) ( selectLayerSlider . Value + . 5 ) )
{
selectLayerSlider . Value = printer . BedPlate . ActiveLayerIndex ;
}
}
2017-07-06 12:22:56 -07:00
}
}