Ejemplo n.º 1
0
        public GCode2DWidget(PrinterConfig printer, ThemeConfig theme)
        {
            this.printer = printer;
            options      = printer.Bed.RendererOptions;

            this.LocalBounds = new RectangleDouble(0, 0, 100, 100);
            this.AnchorAll();

            // Register listeners
            printer.Bed.LoadedGCodeChanged  += LoadedGCodeChanged;
            printer.Settings.SettingChanged += Printer_SettingChanged;

            Printer_SettingChanged(this, null);

            this.gridSizeMm   = printer.Settings.GetValue <Vector2>(SettingsKey.bed_size);
            this.gridCenterMm = printer.Settings.GetValue <Vector2>(SettingsKey.print_center);

            // Acquire the bed image
            bedImage = BedMeshGenerator.CreatePrintBedImage(printer);

            // Create a semi-transparent overlay with the theme color
            var overlay = new ImageBuffer(bedImage.Width, bedImage.Height);

            overlay.NewGraphics2D().Clear(new Color(theme.BackgroundColor, 100));

            // Render the overlay onto the bedImage to tint it and reduce its default overbearing light on dark contrast
            bedImage.NewGraphics2D().Render(overlay, 0, 0);

            // Preload GL texture for 2D bed image and use MipMaps
            UiThread.RunOnIdle(() =>
            {
                ImageGlPlugin.GetImageGlPlugin(bedImage, createAndUseMipMaps: true);
            });
        }
Ejemplo n.º 2
0
        public GCode2DWidget(PrinterConfig printer, ThemeConfig theme)
        {
            this.printer = printer;
            options      = printer.Bed.RendererOptions;

            this.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;

            this.LocalBounds = new RectangleDouble(0, 0, 100, 100);
            this.AnchorAll();

            printer.Bed.LoadedGCodeChanged += LoadedGCodeChanged;

            // make sure we have good settings

            PrinterSettings.SettingChanged.RegisterEvent(Printer_SettingChanged, ref unregisterEvents);
            Printer_SettingChanged(this, null);

            this.gridSizeMm   = printer.Settings.GetValue <Vector2>(SettingsKey.bed_size);
            this.gridCenterMm = printer.Settings.GetValue <Vector2>(SettingsKey.print_center);

            bedImage = BedMeshGenerator.CreatePrintBedImage(printer).Multiply(theme.TabBodyBackground);
        }
Ejemplo n.º 3
0
        public GCodeOptionsPanel(BedConfig sceneContext, PrinterConfig printer, ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            gcodeOptions = sceneContext.RendererOptions;

            var buttonPanel = new FlowLayoutWidget()
            {
                HAnchor = HAnchor.Fit,
                VAnchor = VAnchor.Fit
            };

            var buttonGroup = new ObservableCollection <GuiWidget>();

            speedsButton = new RadioIconButton(AggContext.StaticData.LoadIcon("speeds.png", theme.InvertIcons), theme)
            {
                SiblingRadioButtonList = buttonGroup,
                Name        = "Speeds Button",
                Checked     = gcodeOptions.GCodeLineColorStyle == "Speeds",
                ToolTipText = "Show Speeds".Localize(),
                Margin      = theme.ButtonSpacing
            };
            speedsButton.Click += SwitchColorModes_Click;
            buttonGroup.Add(speedsButton);

            buttonPanel.AddChild(speedsButton);

            materialsButton = new RadioIconButton(AggContext.StaticData.LoadIcon("materials.png", theme.InvertIcons), theme)
            {
                SiblingRadioButtonList = buttonGroup,
                Name        = "Materials Button",
                Checked     = gcodeOptions.GCodeLineColorStyle == "Materials",
                ToolTipText = "Show Materials".Localize(),
                Margin      = theme.ButtonSpacing
            };
            materialsButton.Click += SwitchColorModes_Click;
            buttonGroup.Add(materialsButton);

            buttonPanel.AddChild(materialsButton);

            noColorButton = new RadioIconButton(AggContext.StaticData.LoadIcon("no-color.png", theme.InvertIcons), theme)
            {
                SiblingRadioButtonList = buttonGroup,
                Name        = "No Color Button",
                Checked     = gcodeOptions.GCodeLineColorStyle == "None",
                ToolTipText = "No Color".Localize(),
                Margin      = theme.ButtonSpacing
            };
            noColorButton.Click += SwitchColorModes_Click;
            buttonGroup.Add(noColorButton);

            buttonPanel.AddChild(noColorButton);

            this.AddChild(
                new SettingsItem(
                    "Color View".Localize(),
                    theme,
                    optionalControls: buttonPanel,
                    enforceGutter: false));

            buttonPanel = new FlowLayoutWidget()
            {
                HAnchor = HAnchor.Fit,
                VAnchor = VAnchor.Fit
            };

            // Reset to new button group
            buttonGroup = new ObservableCollection <GuiWidget>();

            solidButton = new RadioIconButton(AggContext.StaticData.LoadIcon("solid.png", theme.InvertIcons), theme)
            {
                SiblingRadioButtonList = buttonGroup,
                Name        = "Solid Button",
                Checked     = gcodeOptions.GCodeModelView == "Semi-Transparent",
                ToolTipText = "Show Semi-Transparent Model".Localize(),
                Margin      = theme.ButtonSpacing
            };
            solidButton.Click += SwitchModelModes_Click;
            buttonGroup.Add(solidButton);

            buttonPanel.AddChild(solidButton);

            materialsButton = new RadioIconButton(AggContext.StaticData.LoadIcon("wireframe.png", theme.InvertIcons), theme)
            {
                SiblingRadioButtonList = buttonGroup,
                Name        = "Wireframe Button",
                Checked     = gcodeOptions.GCodeModelView == "Wireframe",
                ToolTipText = "Show Wireframe Model".Localize(),
                Margin      = theme.ButtonSpacing
            };
            materialsButton.Click += SwitchModelModes_Click;
            buttonGroup.Add(materialsButton);

            buttonPanel.AddChild(materialsButton);

            noColorButton = new RadioIconButton(AggContext.StaticData.LoadIcon("no-color.png", theme.InvertIcons), theme)
            {
                SiblingRadioButtonList = buttonGroup,
                Name        = "No Model Button",
                Checked     = gcodeOptions.GCodeModelView == "None",
                ToolTipText = "No Model".Localize(),
                Margin      = theme.ButtonSpacing
            };
            noColorButton.Click += SwitchModelModes_Click;
            buttonGroup.Add(noColorButton);

            buttonPanel.AddChild(noColorButton);

            this.AddChild(
                new SettingsItem(
                    "Model View".Localize(),
                    buttonPanel,
                    theme,
                    enforceGutter: false));

            gcodeOptions = sceneContext.RendererOptions;

            var viewOptions = sceneContext.GetBaseViewOptions();

            viewOptions.AddRange(new[]
            {
                new BoolOption(
                    "Moves".Localize(),
                    () => gcodeOptions.RenderMoves,
                    (value) => gcodeOptions.RenderMoves = value),
                new BoolOption(
                    "Retractions".Localize(),
                    () => gcodeOptions.RenderRetractions,
                    (value) => gcodeOptions.RenderRetractions = value),
                new BoolOption(
                    "Extrusion".Localize(),
                    () => gcodeOptions.SimulateExtrusion,
                    (value) => gcodeOptions.SimulateExtrusion = value),
                new BoolOption(
                    "Transparent".Localize(),
                    () => gcodeOptions.TransparentExtrusion,
                    (value) => gcodeOptions.TransparentExtrusion = value),
                new BoolOption(
                    "Hide Offsets".Localize(),
                    () => gcodeOptions.HideExtruderOffsets,
                    (value) => gcodeOptions.HideExtruderOffsets = value,
                    () => printer.Settings.GetValue <int>(SettingsKey.extruder_count) > 1),
                new BoolOption(
                    "Sync To Print".Localize(),
                    () => gcodeOptions.SyncToPrint,
                    (value) =>
                {
                    gcodeOptions.SyncToPrint = value;
                    if (!gcodeOptions.SyncToPrint)
                    {
                        // If we are turning off sync to print, set the slider to full.
                        //layerRenderRatioSlider.SecondValue = 1;
                    }
                })
            });

            var optionsContainer = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit
            };

            this.AddChild(optionsContainer);

            void BuildMenu()
            {
                foreach (var option in viewOptions.Where(option => option.IsVisible()))
                {
                    var settingsItem = new SettingsItem(
                        option.Title,
                        theme,
                        new SettingsItem.ToggleSwitchConfig()
                    {
                        Name         = option.Title + " Toggle",
                        Checked      = option.IsChecked(),
                        ToggleAction = option.SetValue
                    },
                        enforceGutter: false);

                    settingsItem.Padding = settingsItem.Padding.Clone(right: 8);

                    optionsContainer.AddChild(settingsItem);
                }
            }

            BuildMenu();

            PropertyChangedEventHandler syncProperties = (s, e) =>
            {
                if (e.PropertyName == nameof(gcodeOptions.RenderBed) ||
                    e.PropertyName == nameof(gcodeOptions.RenderBuildVolume))
                {
                    optionsContainer.CloseAllChildren();
                    BuildMenu();
                }
            };

            gcodeOptions.PropertyChanged += syncProperties;

            optionsContainer.Closed += (s, e) =>
            {
                gcodeOptions.PropertyChanged -= syncProperties;
            };
        }
Ejemplo n.º 4
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;
        }
Ejemplo n.º 5
0
        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);
        }