public PrinterTabPage(PartWorkspace workspace, ThemeConfig theme, string tabTitle) : base(workspace, theme, tabTitle) { gcodeOptions = sceneContext.RendererOptions; view3DWidget.InteractionLayer.EditorMode = InteractionLayer.EditorType.Printer; 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; } }; viewControls3D.ResetView += (sender, e) => { if (gcode2DWidget?.Visible == true) { gcode2DWidget.CenterPartInView(); } }; var opaqueTrackColor = theme.ResolveColor(theme.BedBackgroundColor, theme.SlightShade); LayerScrollbar = new SliceLayerSelector(printer, theme) { VAnchor = VAnchor.Stretch, HAnchor = HAnchor.Right | HAnchor.Fit, Margin = new BorderDouble(0, 4, 4, 4), Maximum = sceneContext.LoadedGCode?.LayerCount ?? 1 }; LayerScrollbar.SolidSlider.View.TrackColor = opaqueTrackColor; view3DWidget.InteractionLayer.AddChild(LayerScrollbar); layerRenderRatioSlider = new DoubleSolidSlider(new Vector2(), SliceLayerSelector.SliderWidth, theme); layerRenderRatioSlider.FirstValue = 0; layerRenderRatioSlider.FirstValueChanged += (s, e) => { sceneContext.RenderInfo.FeatureToStartOnRatio0To1 = layerRenderRatioSlider.FirstValue; sceneContext.RenderInfo.FeatureToEndOnRatio0To1 = layerRenderRatioSlider.SecondValue; this.Invalidate(); }; layerRenderRatioSlider.SecondValue = 1; layerRenderRatioSlider.SecondValueChanged += (s, e) => { if (printer?.Bed?.RenderInfo != null) { sceneContext.RenderInfo.FeatureToStartOnRatio0To1 = layerRenderRatioSlider.FirstValue; sceneContext.RenderInfo.FeatureToEndOnRatio0To1 = layerRenderRatioSlider.SecondValue; } this.Invalidate(); }; view3DWidget.InteractionLayer.AddChild(layerRenderRatioSlider); theme.ApplySliderStyle(layerRenderRatioSlider); layerRenderRatioSlider.View.TrackColor = opaqueTrackColor; AddSettingsTabBar(leftToRight, view3DWidget); view3DWidget.InteractionLayer.BoundsChanged += (s, e) => { SetSliderSizes(); }; printerActionsBar = new PrinterActionsBar(printer, this, theme); theme.ApplyBottomBorder(printerActionsBar); printerActionsBar.modelViewButton.Enabled = sceneContext.EditableScene; // Must come after we have an instance of View3DWidget an its undo buffer topToBottom.AddChild(printerActionsBar, 0); var trackball = view3DWidget.InteractionLayer.Children <TrackballTumbleWidget>().FirstOrDefault(); tumbleCubeControl = view3DWidget.InteractionLayer.Children <TumbleCubeControl>().FirstOrDefault(); var position = view3DWidget.InteractionLayer.Children.IndexOf(trackball); gcodePanel = new GCodePanel(this, printer, sceneContext, theme) { Name = "GCode3DWidget", HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Stretch, BackgroundColor = theme.InteractionLayerOverlayColor, }; var modelViewSidePanel = view3DWidget.Descendants <VerticalResizeContainer>().FirstOrDefault(); gcodeContainer = new VerticalResizeContainer(theme, GrabBarSide.Left) { Width = printer?.ViewState.SelectedObjectPanelWidth ?? 200, VAnchor = VAnchor.Stretch, HAnchor = HAnchor.Absolute, SplitterBarColor = theme.SplitterBackground, SplitterWidth = theme.SplitterWidth, Visible = false, }; gcodeContainer.AddChild(gcodePanel); gcodeContainer.Resized += (s, e) => { if (printer != null) { printer.ViewState.SelectedObjectPanelWidth = gcodeContainer.Width; } }; modelViewSidePanel.BoundsChanged += (s, e) => { gcodeContainer.Width = modelViewSidePanel.Width; }; gcodeContainer.BoundsChanged += (s, e) => { modelViewSidePanel.Width = gcodeContainer.Width; }; var splitContainer = view3DWidget.FindDescendant("SplitContainer"); splitContainer.AddChild(gcodeContainer); view3DContainer.AddChild(new RunningTasksWidget(theme, printer) { MinimumSize = new Vector2(100, 0), Margin = new BorderDouble(top: printerActionsBar.Height + 1, left: favoritesBar.LocalBounds.Width + favoritesBar.DeviceMarginAndBorder.Width + 1), VAnchor = VAnchor.Top | VAnchor.Fit, HAnchor = HAnchor.Left | HAnchor.Fit, }); // Create and append new widget gcode2DWidget = new GCode2DWidget(printer, theme) { Visible = (printer.ViewState.ViewMode == PartViewMode.Layers2D) }; view3DWidget.InteractionLayer.AddChild(gcode2DWidget, position + 1); SetSliderSizes(); this.SetViewMode(printer.ViewState.ViewMode); this.LayerScrollbar.Margin = LayerScrollbar.Margin.Clone(top: tumbleCubeControl.Height + tumbleCubeControl.Margin.Height + 4); // On load, switch to gcode view if previously editing gcode file. Listeners would normally do this but workspace loads before this UI widget if (this?.printerActionsBar?.modelViewButton is GuiWidget button) { button.Enabled = sceneContext.EditableScene; if (sceneContext.ContentType == "gcode" && this?.printerActionsBar?.layers3DButton is GuiWidget gcodeButton) { gcodeButton.InvokeClick(); } } // Register listeners printer.ViewState.VisibilityChanged += ProcessOptionalTabs; printer.ViewState.ViewModeChanged += ViewState_ViewModeChanged; printer.Bed.RendererOptions.PropertyChanged += RendererOptions_PropertyChanged; // register for communication messages printer.Connection.CommunicationStateChanged += Connection_CommunicationStateChanged; printer.Connection.PauseOnLayer += Connection_PauseOnLayer; printer.Connection.FilamentRunout += Connection_FilamentRunout; ApplicationController.Instance.ApplicationError += ApplicationController_ApplicationError; ApplicationController.Instance.ApplicationEvent += ApplicationController_ApplicationEvent; sceneContext.LoadedGCodeChanged += BedPlate_LoadedGCodeChanged; }
public PrinterTabPage(PrinterConfig printer, ThemeConfig theme, string tabTitle) : base(printer, printer.Bed, theme, tabTitle) { gcodeOptions = sceneContext.RendererOptions; view3DWidget.meshViewerWidget.EditorMode = MeshViewerWidget.EditorType.Printer; 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; } }; viewControls3D.ResetView += (sender, e) => { if (gcode2DWidget?.Visible == true) { gcode2DWidget.CenterPartInView(); } }; printer.ViewState.ViewModeChanged += ViewState_ViewModeChanged; LayerScrollbar = new SliceLayerSelector(printer, sceneContext, theme) { VAnchor = VAnchor.Stretch, HAnchor = HAnchor.Right | HAnchor.Fit, Margin = new BorderDouble(0, 4, 4, 4), Maximum = sceneContext.LoadedGCode?.LayerCount ?? 1 }; view3DWidget.InteractionLayer.AddChild(LayerScrollbar); layerRenderRatioSlider = new DoubleSolidSlider(new Vector2(), SliceLayerSelector.SliderWidth); layerRenderRatioSlider.FirstValue = 0; layerRenderRatioSlider.FirstValueChanged += (s, e) => { sceneContext.RenderInfo.FeatureToStartOnRatio0To1 = layerRenderRatioSlider.FirstValue; sceneContext.RenderInfo.FeatureToEndOnRatio0To1 = layerRenderRatioSlider.SecondValue; this.Invalidate(); }; layerRenderRatioSlider.SecondValue = 1; layerRenderRatioSlider.SecondValueChanged += (s, e) => { if (printer?.Bed?.RenderInfo != null) { sceneContext.RenderInfo.FeatureToStartOnRatio0To1 = layerRenderRatioSlider.FirstValue; sceneContext.RenderInfo.FeatureToEndOnRatio0To1 = layerRenderRatioSlider.SecondValue; } this.Invalidate(); }; view3DWidget.InteractionLayer.AddChild(layerRenderRatioSlider); sceneContext.LoadedGCodeChanged += BedPlate_LoadedGCodeChanged; AddSettingsTabBar(leftToRight, view3DWidget); view3DWidget.InteractionLayer.BoundsChanged += (s, e) => { SetSliderSizes(); }; printerActionsBar = new PrinterActionsBar(printer, this, theme); theme.ApplyBottomBorder(printerActionsBar); printerActionsBar.modelViewButton.Enabled = sceneContext.EditableScene; // Must come after we have an instance of View3DWidget an its undo buffer topToBottom.AddChild(printerActionsBar, 0); var trackball = view3DWidget.InteractionLayer.Children <TrackballTumbleWidget>().FirstOrDefault(); tumbleCubeControl = view3DWidget.InteractionLayer.Children <TumbleCubeControl>().FirstOrDefault(); var position = view3DWidget.InteractionLayer.Children.IndexOf(trackball); gcodePanel = new GCodePanel(printer, sceneContext, theme) { Name = "GCode3DWidget", HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Stretch, BackgroundColor = theme.InteractionLayerOverlayColor, }; var modelViewSidePanel = view3DWidget.Descendants <LeftResizeContainer>().FirstOrDefault(); gcodeContainer = new LeftResizeContainer(theme) { Width = printer?.ViewState.SelectedObjectPanelWidth ?? 200, VAnchor = VAnchor.Stretch, HAnchor = HAnchor.Absolute, SpliterBarColor = theme.SplitterBackground, SplitterWidth = theme.SplitterWidth, Visible = false, }; gcodeContainer.AddChild(gcodePanel); gcodeContainer.Resized += (s, e) => { if (printer != null) { printer.ViewState.SelectedObjectPanelWidth = gcodeContainer.Width; } }; modelViewSidePanel.BoundsChanged += (s, e) => { gcodeContainer.Width = modelViewSidePanel.Width; }; gcodeContainer.BoundsChanged += (s, e) => { modelViewSidePanel.Width = gcodeContainer.Width; }; var splitContainer = view3DWidget.FindNamedChildRecursive("SplitContainer"); splitContainer.AddChild(gcodeContainer); view3DContainer.AddChild(new RunningTasksWidget(theme) { MinimumSize = new Vector2(100, 0), Margin = new BorderDouble(top: printerActionsBar.Height), VAnchor = VAnchor.Top | VAnchor.Fit, HAnchor = HAnchor.Left | HAnchor.Fit, }); // Create and append new widget gcode2DWidget = new GCode2DWidget(printer, theme) { Visible = (printer.ViewState.ViewMode == PartViewMode.Layers2D) }; view3DWidget.InteractionLayer.AddChild(gcode2DWidget, position + 1); SetSliderSizes(); this.SetViewMode(printer.ViewState.ViewMode); printer.ViewState.ConfigurePrinterChanged += ConfigurePrinter_Changed; printer.Bed.RendererOptions.PropertyChanged += RendererOptions_PropertyChanged; printer.Connection.CommunicationStateChanged.RegisterEvent((s, e) => { this.SetSliderVisibility(); }, ref unregisterEvents); }