예제 #1
0
        public SliceLayerSelector(PrinterConfig printer, BedConfig sceneContext, ThemeConfig theme)
        {
            this.sceneContext = sceneContext;

            this.AddChild(layerScrollbar = new LayerScrollbar(printer, sceneContext, theme)
            {
                VAnchor = VAnchor.Stretch,
                HAnchor = HAnchor.Right
            });

            layerSlider = layerScrollbar.layerSlider;
            theme.ApplySliderStyle(layerSlider);

            var tagContainer = new HorizontalTag()
            {
                HAnchor  = HAnchor.Fit | HAnchor.Right,
                VAnchor  = VAnchor.Fit,
                Padding  = new BorderDouble(6, 4, 10, 4),
                Margin   = new BorderDouble(right: layerScrollbar.Width + layerScrollbar.Margin.Width),
                TagColor = (theme.IsDarkTheme) ? theme.Shade : theme.SlightShade
            };

            currentLayerInfo = new InlineEditControl("1000")
            {
                Name             = "currentLayerInfo",
                TextColor        = theme.TextColor,
                GetDisplayString = (value) => $"{value}",
                HAnchor          = HAnchor.Right | HAnchor.Fit,
                VAnchor          = VAnchor.Absolute | VAnchor.Fit,
            };
            currentLayerInfo.EditComplete += (s, e) =>
            {
                layerScrollbar.Value = currentLayerInfo.Value - 1;
            };

            tagContainer.AddChild(currentLayerInfo);
            this.AddChild(tagContainer);

            currentLayerInfo.Visible = true;
            layerInfoHalfHeight      = currentLayerInfo.Height / 2;
            currentLayerInfo.Visible = false;

            layerSlider.ValueChanged += (s, e) =>
            {
                currentLayerInfo.StopEditing();
                currentLayerInfo.Position = new Vector2(0, (double)(layerSlider.Position.Y + layerSlider.PositionPixelsFromFirstValue - layerInfoHalfHeight));
            };

            // Set initial position
            currentLayerInfo.Position = new Vector2(0, (double)(layerSlider.Position.Y + layerSlider.PositionPixelsFromFirstValue - layerInfoHalfHeight));

            sceneContext.ActiveLayerChanged += SetPositionAndValue;
            layerScrollbar.MouseEnter       += SetPositionAndValue;
        }
예제 #2
0
        private AdjustmentControls(PrinterConfig printer, ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            double sliderWidth      = 300 * GuiWidget.DeviceScale;
            double sliderThumbWidth = 10 * GuiWidget.DeviceScale;

            this.printer = printer;

            SettingsRow settingsRow;

            {
                this.AddChild(settingsRow = new SettingsRow(
                                  "Speed Multiplier".Localize(),
                                  null,
                                  theme));

                // Remove the HorizontalSpacer
                settingsRow.Children.Last().Close();

                feedRateRatioSlider = new SolidSlider(new Vector2(), sliderThumbWidth, theme, minFeedRateRatio, maxFeedRateRatio)
                {
                    Name               = "Feed Rate Slider",
                    Margin             = new BorderDouble(5, 0),
                    Value              = FeedRateMultiplyerStream.FeedRateRatio,
                    HAnchor            = HAnchor.Stretch,
                    VAnchor            = VAnchor.Center,
                    TotalWidthInPixels = sliderWidth,
                };
                theme.ApplySliderStyle(feedRateRatioSlider);
                feedRateRatioSlider.ValueChanged += (sender, e) =>
                {
                    feedRateValue.ActuallNumberEdit.Value = Math.Round(feedRateRatioSlider.Value, 2);
                };
                feedRateRatioSlider.SliderReleased += (s, e) =>
                {
                    // Update state for runtime use
                    FeedRateMultiplyerStream.FeedRateRatio = Math.Round(feedRateRatioSlider.Value, 2);

                    // Persist data for future use
                    printer.Settings.SetValue(
                        SettingsKey.feedrate_ratio,
                        FeedRateMultiplyerStream.FeedRateRatio.ToString());
                };
                settingsRow.AddChild(feedRateRatioSlider);

                feedRateValue = new MHNumberEdit(Math.Round(FeedRateMultiplyerStream.FeedRateRatio, 2), theme, allowDecimals: true, minValue: minFeedRateRatio, maxValue: maxFeedRateRatio, pixelWidth: 40 * GuiWidget.DeviceScale)
                {
                    Name             = "Feed Rate NumberEdit",
                    SelectAllOnFocus = true,
                    Margin           = new BorderDouble(0, 0, 5, 0),
                    VAnchor          = VAnchor.Center | VAnchor.Fit,
                    Padding          = 0
                };
                feedRateValue.ActuallNumberEdit.EditComplete += (sender, e) =>
                {
                    feedRateRatioSlider.Value = feedRateValue.ActuallNumberEdit.Value;

                    // Update state for runtime use
                    FeedRateMultiplyerStream.FeedRateRatio = Math.Round(feedRateRatioSlider.Value, 2);

                    // Persist data for future use
                    printer.Settings.SetValue(
                        SettingsKey.feedrate_ratio,
                        FeedRateMultiplyerStream.FeedRateRatio.ToString());
                };
                settingsRow.AddChild(feedRateValue);
            }

            {
                this.AddChild(settingsRow = new SettingsRow(
                                  "Extrusion Multiplier".Localize(),
                                  null,
                                  theme));

                // Remove the HorizontalSpacer
                settingsRow.Children.Last().Close();

                extrusionRatioSlider = new SolidSlider(new Vector2(), sliderThumbWidth, theme, minExtrutionRatio, maxExtrusionRatio, Orientation.Horizontal)
                {
                    Name = "Extrusion Multiplier Slider",
                    TotalWidthInPixels = sliderWidth,
                    HAnchor            = HAnchor.Stretch,
                    VAnchor            = VAnchor.Center,
                    Margin             = new BorderDouble(5, 0),
                    Value = ExtrusionMultiplyerStream.ExtrusionRatio
                };
                theme.ApplySliderStyle(extrusionRatioSlider);
                extrusionRatioSlider.ValueChanged += (sender, e) =>
                {
                    extrusionValue.ActuallNumberEdit.Value = Math.Round(extrusionRatioSlider.Value, 2);
                };
                extrusionRatioSlider.SliderReleased += (s, e) =>
                {
                    // Update state for runtime use
                    ExtrusionMultiplyerStream.ExtrusionRatio = Math.Round(extrusionRatioSlider.Value, 2);

                    // Persist data for future use
                    printer.Settings.SetValue(
                        SettingsKey.extrusion_ratio,
                        ExtrusionMultiplyerStream.ExtrusionRatio.ToString());
                };
                settingsRow.AddChild(extrusionRatioSlider);

                extrusionValue = new MHNumberEdit(Math.Round(ExtrusionMultiplyerStream.ExtrusionRatio, 2), theme, allowDecimals: true, minValue: minExtrutionRatio, maxValue: maxExtrusionRatio, pixelWidth: 40 * GuiWidget.DeviceScale)
                {
                    Name             = "Extrusion Multiplier NumberEdit",
                    SelectAllOnFocus = true,
                    Margin           = new BorderDouble(0, 0, 5, 0),
                    VAnchor          = VAnchor.Center | VAnchor.Fit,
                    Padding          = 0
                };
                extrusionValue.ActuallNumberEdit.EditComplete += (sender, e) =>
                {
                    extrusionRatioSlider.Value = extrusionValue.ActuallNumberEdit.Value;

                    // Update state for runtime use
                    ExtrusionMultiplyerStream.ExtrusionRatio = Math.Round(extrusionRatioSlider.Value, 2);

                    // Persist data for future use
                    printer.Settings.SetValue(
                        SettingsKey.extrusion_ratio,
                        ExtrusionMultiplyerStream.ExtrusionRatio.ToString());
                };
                settingsRow.AddChild(extrusionValue);
            }

            // Register listeners
            printer.Settings.SettingChanged += Printer_SettingChanged;
        }
예제 #3
0
        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;
        }