Пример #1
0
        public PartTabPage(PrinterConfig printer, BedConfig sceneContext, ThemeConfig theme, string tabTitle)
            : base(tabTitle)
        {
            this.sceneContext    = sceneContext;
            this.theme           = theme;
            this.BackgroundColor = theme.ActiveTabColor;
            this.Padding         = 0;
            this.printer         = printer;

            bool isPrinterType = this is PrinterTabPage;

            var favoritesBarAndView3DWidget = new FlowLayoutWidget()
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch
            };

            viewControls3D = new ViewControls3D(sceneContext, theme, sceneContext.Scene.UndoBuffer, isPrinterType, !(this is PrinterTabPage))
            {
                VAnchor = VAnchor.Top | VAnchor.Fit,
                HAnchor = HAnchor.Left | HAnchor.Stretch,
                Visible = true,
            };
            theme.ApplyBottomBorder(viewControls3D, shadedBorder: (this is PrinterTabPage));             // Shade border if toolbar is secondary rather than primary

            viewControls3D.ResetView += (sender, e) =>
            {
                if (view3DWidget.Visible)
                {
                    this.view3DWidget.ResetView();
                }
            };
            viewControls3D.ExtendOverflowMenu  = this.GetViewControls3DOverflowMenu;
            viewControls3D.OverflowButton.Name = "View3D Overflow Menu";

            // The 3D model view
            view3DWidget = new View3DWidget(
                printer,
                sceneContext,
                viewControls3D,
                theme,
                this,
                editorType: (isPrinterType) ? MeshViewerWidget.EditorType.Printer : MeshViewerWidget.EditorType.Part);

            viewControls3D.SetView3DWidget(view3DWidget);

            // Construct and store dictionary of menu actions accessible at workspace level
            view3DWidget.WorkspaceActions = viewControls3D.MenuActions.Where(o => !string.IsNullOrEmpty(o.ID)).ToDictionary(o => o.ID, o => o);

            this.AddChild(topToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch
            });

            topToBottom.AddChild(leftToRight = new FlowLayoutWidget()
            {
                Name    = "View3DContainerParent",
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch
            });

            view3DContainer = new GuiWidget()
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch
            };

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

            toolbarAndView3DWidget.AddChild(viewControls3D);

            var dummyContext = new LibraryConfig()
            {
                ActiveContainer = ApplicationController.Instance.Library.ActiveContainer
            };

            var favoritesBar = new ListView(dummyContext, theme)
            {
                Name = "LibraryView",
                // Drop containers
                ContainerFilter  = (container) => false,
                BackgroundColor  = theme.ActiveTabColor,
                ListContentView  = new IconListView(theme, 22),
                Border           = new BorderDouble(top: 1, right: 1),
                BorderColor      = theme.GetBorderColor(15),
                HAnchor          = HAnchor.Absolute,
                Width            = 33,
                AllowContextMenu = false
            };

            favoritesBarAndView3DWidget.AddChild(favoritesBar);
            favoritesBarAndView3DWidget.AddChild(view3DWidget);
            toolbarAndView3DWidget.AddChild(favoritesBarAndView3DWidget);

            view3DContainer.AddChild(toolbarAndView3DWidget);

            leftToRight.AddChild(view3DContainer);

            if (sceneContext.World.RotationMatrix == Matrix4X4.Identity)
            {
                this.view3DWidget.ResetView();
            }

            this.AnchorAll();
        }
Пример #2
0
        public PrinterConnectButton(PrinterConfig printer, ThemeConfig theme)
        {
            this.printer = printer;
            this.HAnchor = HAnchor.Left | HAnchor.Fit;
            this.VAnchor = VAnchor.Fit;
            this.Margin  = 0;
            this.Padding = 0;

            connectButton = new TextIconButton(
                "Connect".Localize(),
                AggContext.StaticData.LoadIcon("connect.png", 14, 14, theme.InvertIcons),
                theme)
            {
                Name           = "Connect to printer button",
                ToolTipText    = "Connect to the currently selected printer".Localize(),
                MouseDownColor = theme.ToolbarButtonDown,
            };
            connectButton.Click += (s, e) =>
            {
                if (connectButton.Enabled)
                {
                    if (printer.Settings.PrinterSelected)
                    {
                        UserRequestedConnectToActivePrinter();
                    }
                }
            };
            this.AddChild(connectButton);

            theme.ApplyPrimaryActionStyle(connectButton);

            // add the cancel stop button
            cancelConnectButton = new TextIconButton(
                "Cancel".Localize(),
                AggContext.StaticData.LoadIcon("connect.png", 14, 14, theme.InvertIcons),
                theme)
            {
                ToolTipText     = "Stop trying to connect to the printer.".Localize(),
                BackgroundColor = theme.ToolbarButtonBackground,
                HoverColor      = theme.ToolbarButtonHover,
                MouseDownColor  = theme.ToolbarButtonDown,
            };
            cancelConnectButton.Click += (s, e) => UiThread.RunOnIdle(() =>
            {
                listenForConnectFailed = false;
                ApplicationController.Instance.ConditionallyCancelPrint();
                cancelConnectButton.Enabled = false;
            });
            this.AddChild(cancelConnectButton);

            disconnectButton = new TextIconButton(
                "Disconnect".Localize(),
                AggContext.StaticData.LoadIcon("connect.png", 14, 14, theme.InvertIcons),
                theme)
            {
                Name            = "Disconnect from printer button",
                Visible         = false,
                ToolTipText     = "Disconnect from current printer".Localize(),
                BackgroundColor = theme.ToolbarButtonBackground,
                HoverColor      = theme.ToolbarButtonHover,
                MouseDownColor  = theme.ToolbarButtonDown,
            };
            disconnectButton.Click += (s, e) => UiThread.RunOnIdle(() =>
            {
                if (printer.Connection.PrinterIsPrinting)
                {
                    StyledMessageBox.ShowMessageBox(
                        (bool disconnectCancel) =>
                    {
                        if (disconnectCancel)
                        {
                            printer.Connection.Stop(false);
                            printer.Connection.Disable();
                        }
                    },
                        "WARNING: Disconnecting will stop the current print.\n\nAre you sure you want to disconnect?".Localize(),
                        "Disconnect and stop the current print?".Localize(),
                        StyledMessageBox.MessageType.YES_NO,
                        "Disconnect".Localize(),
                        "Stay Connected".Localize());
                }
                else
                {
                    printer.Connection.Disable();
                }
            });
            this.AddChild(disconnectButton);

            foreach (var child in Children)
            {
                child.VAnchor = VAnchor.Center;
                child.Cursor  = Cursors.Hand;
                child.Margin  = theme.ButtonSpacing;
            }

            printer.Connection.EnableChanged.RegisterEvent((s, e) => SetVisibleStates(), ref unregisterEvents);
            printer.Connection.CommunicationStateChanged.RegisterEvent((s, e) => SetVisibleStates(), ref unregisterEvents);
            printer.Connection.ConnectionFailed.RegisterEvent((s, e) =>
            {
#if !__ANDROID__
                // TODO: Someday this functionality should be revised to an awaitable Connect() call in the Connect button that
                // shows troubleshooting on failed attempts, rather than hooking the failed event and trying to determine if the
                // Connect button started the task
                if (listenForConnectFailed &&
                    UiThread.CurrentTimerMs - connectStartMs < 25000)
                {
                    UiThread.RunOnIdle(() =>
                    {
                        // User initiated connect attempt failed, show port selection dialog
                        DialogWindow.Show(new SetupStepComPortOne(printer));
                    });
                }
#endif
                listenForConnectFailed = false;
            }, ref unregisterEvents);

            this.SetVisibleStates();
        }
Пример #3
0
 public WaitForTempStream(PrinterConfig printer, GCodeStream internalStream)
     : base(printer, internalStream)
 {
     state = State.passthrough;
 }
Пример #4
0
 public ExtrusionMultiplyerStream(PrinterConfig printer, GCodeStream internalStream)
     : base(printer, internalStream)
 {
 }
Пример #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 <VerticalResizeContainer>().FirstOrDefault();

            gcodeContainer = new VerticalResizeContainer(theme, GrabBarSide.Left)
            {
                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);

            this.LayerScrollbar.Margin = LayerScrollbar.Margin.Clone(top: tumbleCubeControl.Height + tumbleCubeControl.Margin.Height + 4);

            printer.ViewState.VisibilityChanged += ProcessOptionalTabs;

            printer.Bed.RendererOptions.PropertyChanged += RendererOptions_PropertyChanged;

            printer.Connection.CommunicationStateChanged.RegisterEvent((s, e) =>
            {
                this.SetSliderVisibility();
            }, ref unregisterEvents);
        }
Пример #6
0
 public void Initialize(PrinterConfig printer)
 {
 }
Пример #7
0
        private void CreateProductDataWidgets(PrinterSettings printerSettings, ProductSkuData product)
        {
            var row = new FlowLayoutWidget()
            {
                HAnchor = HAnchor.Stretch,
                Margin  = new BorderDouble(top: theme.DefaultContainerPadding)
            };

            productDataContainer.AddChild(row);

            var image = new ImageBuffer(150, 10);

            row.AddChild(new ImageWidget(image)
            {
                Margin  = new BorderDouble(right: theme.DefaultContainerPadding),
                VAnchor = VAnchor.Top
            });

            WebCache.RetrieveImageAsync(image, product.FeaturedImage.ImageUrl, scaleToImageX: true);

            var descriptionBackground = new GuiWidget()
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit | VAnchor.Top,
                Padding = theme.DefaultContainerPadding
            };

            var description = new MarkdownWidget(theme)
            {
                MinimumSize = new VectorMath.Vector2(350, 0),
                HAnchor     = HAnchor.Stretch,
                VAnchor     = VAnchor.Fit,
                Markdown    = product.ProductDescription.Trim()
            };

            descriptionBackground.AddChild(description);
            descriptionBackground.BeforeDraw += (s, e) =>
            {
                var rect = new RoundedRect(descriptionBackground.LocalBounds, 3);
                e.Graphics2D.Render(rect, theme.SlightShade);
            };

            row.AddChild(descriptionBackground);

            var padding = theme.DefaultContainerPadding;

            var addonsColumn = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                Padding = new BorderDouble(padding, padding, padding, 0),
                HAnchor = HAnchor.Stretch
            };

            var addonsSection = new SectionWidget("Upgrades and Accessories", addonsColumn, theme);

            productDataContainer.AddChild(addonsSection);
            theme.ApplyBoxStyle(addonsSection);
            addonsSection.Margin = addonsSection.Margin.Clone(left: 0);

            foreach (var item in product.ProductListing.AddOns)
            {
                var icon = new ImageBuffer(80, 0);
                WebCache.RetrieveImageAsync(icon, item.FeaturedImage.ImageUrl, scaleToImageX: true);

                var addOnRow = new AddOnRow(item.AddOnTitle, theme, null, icon)
                {
                    HAnchor = HAnchor.Stretch,
                    Cursor  = Cursors.Hand
                };

                foreach (var child in addOnRow.Children)
                {
                    child.Selectable = false;
                }

                addOnRow.Click += (s, e) =>
                {
                    ApplicationController.Instance.LaunchBrowser($"https://www.matterhackers.com/store/l/{item.AddOnListingReference}/sk/{item.AddOnSkuReference}");
                };

                addonsColumn.AddChild(addOnRow);
            }

            if (false)
            {
                var settingsPanel = new GuiWidget()
                {
                    HAnchor         = HAnchor.Stretch,
                    VAnchor         = VAnchor.Stretch,
                    MinimumSize     = new VectorMath.Vector2(20, 20),
                    DebugShowBounds = true
                };

                settingsPanel.Load += (s, e) =>
                {
                    var printer = new PrinterConfig(printerSettings);

                    var settingsContext = new SettingsContext(
                        printer,
                        null,
                        NamedSettingsLayers.All);

                    settingsPanel.AddChild(
                        new ConfigurePrinterWidget(settingsContext, printer, theme)
                    {
                        HAnchor = HAnchor.Stretch,
                        VAnchor = VAnchor.Stretch,
                    });
                };

                this.AddChild(new SectionWidget("Settings", settingsPanel, theme, expanded: false, setContentVAnchor: false)
                {
                    VAnchor = VAnchor.Stretch
                });
            }
        }
Пример #8
0
        public static List <(Matrix4X4 matrix, string fileName)> GetStlFileLocations(IObject3D object3D, ref string mergeRules, PrinterConfig printer, IProgress <ProgressStatus> progressReporter, CancellationToken cancellationToken)
        {
            var progressStatus = new ProgressStatus();

            extrudersUsed.Clear();

            int extruderCount = printer.Settings.GetValue <int>(SettingsKey.extruder_count);

            for (int extruderIndex = 0; extruderIndex < extruderCount; extruderIndex++)
            {
                extrudersUsed.Add(false);
            }

            // If we have support enabled and are using an extruder other than 0 for it
            if (printer.Settings.GetValue <bool>("support_material"))
            {
                if (printer.Settings.GetValue <int>("support_material_extruder") != 0)
                {
                    int supportExtruder = Math.Max(0, Math.Min(printer.Settings.GetValue <int>(SettingsKey.extruder_count) - 1, printer.Settings.GetValue <int>("support_material_extruder") - 1));
                    extrudersUsed[supportExtruder] = true;
                }
            }

            // If we have raft enabled and are using an extruder other than 0 for it
            if (printer.Settings.GetValue <bool>("create_raft"))
            {
                if (printer.Settings.GetValue <int>("raft_extruder") != 0)
                {
                    int raftExtruder = Math.Max(0, Math.Min(printer.Settings.GetValue <int>(SettingsKey.extruder_count) - 1, printer.Settings.GetValue <int>("raft_extruder") - 1));
                    extrudersUsed[raftExtruder] = true;
                }
            }

            {
                // TODO: Once graph parsing is added to MatterSlice we can remove and avoid this flattening
                meshPrintOutputSettings.Clear();

                // Flatten the scene, filtering out items outside of the build volume
                var meshItemsOnBuildPlate = printer.PrintableItems(object3D);
                if (meshItemsOnBuildPlate.Any())
                {
                    int maxExtruderIndex = 0;

                    var itemsByExtruder = new List <IEnumerable <IObject3D> >();
                    for (int extruderIndexIn = 0; extruderIndexIn < extruderCount; extruderIndexIn++)
                    {
                        var extruderIndex     = extruderIndexIn;
                        var itemsThisExtruder = meshItemsOnBuildPlate.Where((item) =>
                                                                            (File.Exists(item.MeshPath) || // Drop missing files
                                                                             File.Exists(Path.Combine(Object3D.AssetsPath, item.MeshPath))) &&
                                                                            (item.WorldMaterialIndex() == extruderIndex ||
                                                                             (extruderIndex == 0 &&
                                                                              (item.WorldMaterialIndex() >= extruderCount || item.WorldMaterialIndex() == -1))) &&
                                                                            (item.WorldOutputType() == PrintOutputTypes.Solid || item.WorldOutputType() == PrintOutputTypes.Default));

                        itemsByExtruder.Add(itemsThisExtruder);
                        extrudersUsed[extruderIndex] |= itemsThisExtruder.Any();
                        if (extrudersUsed[extruderIndex])
                        {
                            maxExtruderIndex = extruderIndex;
                        }
                    }

                    var outputOptions = new List <(Matrix4X4 matrix, string fileName)>();

                    int  savedStlCount = 0;
                    bool first         = true;
                    for (int extruderIndex = 0; extruderIndex < itemsByExtruder.Count; extruderIndex++)
                    {
                        if (!first)
                        {
                            mergeRules += ",";
                            first       = false;
                        }

                        mergeRules += AddObjectsForExtruder(itemsByExtruder[extruderIndex], outputOptions, ref savedStlCount);
                    }

                    var supportObjects = meshItemsOnBuildPlate.Where((item) => item.WorldOutputType() == PrintOutputTypes.Support);

                    // if we added user generated support
                    if (supportObjects.Any())
                    {
                        // add a flag to the merge rules to let us know there was support
                        mergeRules += "," + AddObjectsForExtruder(supportObjects, outputOptions, ref savedStlCount) + "S";
                    }

                    mergeRules += " ";

                    return(outputOptions);
                }
            }

            return(new List <(Matrix4X4 matrix, string fileName)>());
        }
Пример #9
0
        public SliceSettingsRow(PrinterConfig printer, SettingsContext settingsContext, SliceSettingData settingData, ThemeConfig theme, bool fullRowSelect = false)
            : base(settingData.PresentationName.Localize(), settingData.HelpText.Localize(), theme, fullRowSelect: fullRowSelect)
        {
            this.printer         = printer;
            this.settingData     = settingData;
            this.settingsContext = settingsContext;

            using (this.LayoutLock())
            {
                this.AddChild(dataArea = new FlowLayoutWidget
                {
                    VAnchor         = VAnchor.Fit | VAnchor.Center,
                    DebugShowBounds = debugLayout
                });

                this.AddChild(unitsArea = new GuiWidget()
                {
                    HAnchor         = HAnchor.Absolute,
                    VAnchor         = VAnchor.Fit | VAnchor.Center,
                    Width           = 50 * GuiWidget.DeviceScale,
                    DebugShowBounds = debugLayout
                });

                // Populate unitsArea as appropriate
                // List elements contain list values in the field which normally contains label details, skip generation of invalid labels
                if (settingData.DataEditType != SliceSettingData.DataEditTypes.LIST &&
                    settingData.DataEditType != SliceSettingData.DataEditTypes.HARDWARE_PRESENT)
                {
                    unitsArea.AddChild(
                        new WrappedTextWidget(settingData.Units.Localize(), pointSize: theme.FontSize8, textColor: theme.TextColor)
                    {
                        Margin = new BorderDouble(5, 0),
                    });
                }

                restoreArea = new GuiWidget()
                {
                    HAnchor         = HAnchor.Absolute,
                    VAnchor         = VAnchor.Fit | VAnchor.Center,
                    Width           = 20 * GuiWidget.DeviceScale,
                    DebugShowBounds = debugLayout
                };
                this.AddChild(restoreArea);

                this.Name = settingData.SlicerConfigName + " Row";

                if (settingData.ShowAsOverride)
                {
                    restoreButton             = theme.CreateSmallResetButton();
                    restoreButton.HAnchor     = HAnchor.Right;
                    restoreButton.Margin      = 0;
                    restoreButton.Name        = "Restore " + settingData.SlicerConfigName;
                    restoreButton.ToolTipText = "Restore Default".Localize();
                    restoreButton.Click      += (sender, e) =>
                    {
                        // Revert the user override
                        settingsContext.ClearValue(settingData.SlicerConfigName);
                    };

                    restoreArea.AddChild(restoreButton);

                    restoreArea.Selectable = true;
                }
            }

            this.PerformLayout();
        }
        public PrinterConnectButton(PrinterConfig printer, ThemeConfig theme)
        {
            this.printer = printer;
            this.HAnchor = HAnchor.Left | HAnchor.Fit;
            this.VAnchor = VAnchor.Fit;
            this.Margin  = 0;
            this.Padding = 0;

            connectButton = new TextIconButton(
                "Connect".Localize(),
                StaticData.Instance.LoadIcon("connect.png", 14, 14, theme.InvertIcons),
                theme)
            {
                Name           = "Connect to printer button",
                ToolTipText    = "Connect to the currently selected printer".Localize(),
                MouseDownColor = theme.ToolbarButtonDown,
            };
            connectButton.Click += (s, e) =>
            {
                if (connectButton.Enabled)
                {
                    ApplicationController.Instance.ConnectToPrinter(printer);
                }
            };
            this.AddChild(connectButton);

            theme.ApplyPrimaryActionStyle(connectButton);

            // add the cancel stop button
            cancelConnectButton = new TextIconButton(
                "Cancel".Localize(),
                StaticData.Instance.LoadIcon("connect.png", 14, 14, theme.InvertIcons),
                theme)
            {
                ToolTipText     = "Stop trying to connect to the printer.".Localize(),
                BackgroundColor = theme.ToolbarButtonBackground,
                HoverColor      = theme.ToolbarButtonHover,
                MouseDownColor  = theme.ToolbarButtonDown,
            };
            cancelConnectButton.Click += (s, e) => UiThread.RunOnIdle(() =>
            {
                printer.CancelPrint();
                cancelConnectButton.Enabled = false;
            });
            this.AddChild(cancelConnectButton);

            disconnectButton = new TextIconButton(
                "Disconnect".Localize(),
                StaticData.Instance.LoadIcon("connect.png", 14, 14, theme.InvertIcons),
                theme)
            {
                Name            = "Disconnect from printer button",
                Visible         = false,
                ToolTipText     = "Disconnect from current printer".Localize(),
                BackgroundColor = theme.ToolbarButtonBackground,
                HoverColor      = theme.ToolbarButtonHover,
                MouseDownColor  = theme.ToolbarButtonDown,
            };
            disconnectButton.Click += (s, e) => UiThread.RunOnIdle(() =>
            {
                if (printer.Connection.Printing)
                {
                    StyledMessageBox.ShowMessageBox(
                        (bool disconnectCancel) =>
                    {
                        if (disconnectCancel)
                        {
                            printer.Connection.Stop(false);
                            printer.Connection.Disable();
                        }
                    },
                        "WARNING: Disconnecting will stop the current print.\n\nAre you sure you want to disconnect?".Localize(),
                        "Disconnect and stop the current print?".Localize(),
                        StyledMessageBox.MessageType.YES_NO,
                        "Disconnect".Localize(),
                        "Stay Connected".Localize());
                }
                else
                {
                    printer.Connection.Disable();
                }
            });
            this.AddChild(disconnectButton);

            foreach (var child in Children)
            {
                child.VAnchor = VAnchor.Center;
                child.Cursor  = Cursors.Hand;
                child.Margin  = theme.ButtonSpacing;
            }

            // Register listeners
            printer.Connection.CommunicationStateChanged += Connection_CommunicationStateChanged;

            this.SetVisibleStates();
        }
Пример #11
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(default(Vector2), sliderThumbWidth, theme, minFeedRateRatio, maxFeedRateRatio)
                {
                    Name               = "Feed Rate Slider",
                    Margin             = new BorderDouble(5, 0),
                    Value              = printer.Settings.GetValue <double>(SettingsKey.feedrate_ratio),
                    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
                    printer.Connection.FeedRateMultiplierStream.FeedRateRatio = Math.Round(feedRateRatioSlider.Value, 2);

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

                feedRateValue = new MHNumberEdit(Math.Round(printer.Settings.GetValue <double>(SettingsKey.feedrate_ratio), 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,
                };
                feedRateValue.ActuallNumberEdit.EditComplete += (sender, e) =>
                {
                    feedRateRatioSlider.Value = feedRateValue.ActuallNumberEdit.Value;

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

                    // Persist data for future use
                    printer.Settings.SetValue(
                        SettingsKey.feedrate_ratio,
                        printer.Connection.FeedRateMultiplierStream.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(default(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 = printer.Settings.GetValue <double>(SettingsKey.extrusion_ratio)
                };

                theme.ApplySliderStyle(extrusionRatioSlider);
                extrusionRatioSlider.ValueChanged += (sender, e) =>
                {
                    extrusionValue.ActuallNumberEdit.Value = Math.Round(extrusionRatioSlider.Value, 2);
                };
                extrusionRatioSlider.SliderReleased += (s, e) =>
                {
                    // Update state for runtime use
                    printer.Connection.ExtrusionMultiplierStream.ExtrusionRatio = Math.Round(extrusionRatioSlider.Value, 2);

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

                extrusionValue = new MHNumberEdit(Math.Round(printer.Settings.GetValue <double>(SettingsKey.extrusion_ratio), 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,
                };
                extrusionValue.ActuallNumberEdit.EditComplete += (sender, e) =>
                {
                    extrusionRatioSlider.Value = extrusionValue.ActuallNumberEdit.Value;

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

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

            // Register listeners
            printer.Settings.SettingChanged += Printer_SettingChanged;
            printer.Disposed += (s, e) => printer.Settings.SettingChanged -= Printer_SettingChanged;
        }
Пример #12
0
 public UnloadFilamentWizard(PrinterConfig printer, int extruderIndex)
     : base(printer)
 {
     this.Title         = "Unload Filament".Localize();
     this.extruderIndex = extruderIndex;
 }
Пример #13
0
 public GCodeStreamProxy(PrinterConfig printer, GCodeStream internalStream)
     : base(printer)
 {
     this.internalStream = internalStream;
 }
Пример #14
0
 public Slice3rBedShape(PrinterConfig printer, string canonicalSettingsName)
     : base(printer, canonicalSettingsName, canonicalSettingsName)
 {
 }
Пример #15
0
        public PrinterActionsBar(PrinterConfig printer, PrinterTabPage printerTabPage, ThemeConfig theme)
            : base(theme)
        {
            this.printer        = printer;
            this.printerTabPage = printerTabPage;

            this.HAnchor = HAnchor.Stretch;
            this.VAnchor = VAnchor.Fit;

            var defaultMargin = theme.ButtonSpacing;

            var printerType = printer.Settings.Slicer.PrinterType;

            if (printerType == PrinterType.FFF)
            {
                // add the reset button first (if there is one)
                if (printer.Settings.GetValue <bool>(SettingsKey.show_reset_connection))
                {
                    var resetConnectionButton = new TextIconButton(
                        "Reset".Localize(),
                        StaticData.Instance.LoadIcon("e_stop.png", 14, 14).SetToColor(theme.TextColor),
                        theme)
                    {
                        ToolTipText = "Reboots the firmware on the controller".Localize(),
                        Margin      = defaultMargin
                    };
                    resetConnectionButton.Click += (s, e) =>
                    {
                        UiThread.RunOnIdle(printer.Connection.RebootBoard);
                    };
                    this.AddChild(resetConnectionButton);
                }

                this.AddChild(new PrinterConnectButton(printer, theme));

                // add the start print button
                GuiWidget startPrintButton;
                this.AddChild(startPrintButton = new PrintPopupMenu(printer, theme)
                {
                    Margin = theme.ButtonSpacing
                });

                void SetPrintButtonStyle(object s, EventArgs e)
                {
                    switch (printer.Connection.CommunicationState)
                    {
                    case CommunicationStates.FinishedPrint:
                    case CommunicationStates.Connected:
                        theme.ApplyPrimaryActionStyle(startPrintButton);
                        break;

                    default:
                        theme.RemovePrimaryActionStyle(startPrintButton);
                        break;
                    }
                }

                // make sure the buttons state is set correctly
                printer.Connection.CommunicationStateChanged += SetPrintButtonStyle;
                startPrintButton.Closed += (s, e) => printer.Connection.CommunicationStateChanged -= SetPrintButtonStyle;

                // and set the style right now
                SetPrintButtonStyle(this, null);
            }
            else
            {
                var exportButton = new ExportSlaPopupMenu(printer, theme)
                {
                    Margin = theme.ButtonSpacing
                };
                // add the SLA export button
                this.AddChild(exportButton);

                theme.ApplyPrimaryActionStyle(exportButton);
            }

            this.AddChild(new SliceButton(printer, printerTabPage, theme)
            {
                Name   = "Generate Gcode Button",
                Margin = theme.ButtonSpacing,
            });

            // Add vertical separator
            this.AddChild(new ToolbarSeparator(theme.GetBorderColor(50), theme.SeparatorMargin)
            {
                VAnchor = VAnchor.Absolute,
                Height  = theme.ButtonHeight,
            });

            var buttonGroupB = new ObservableCollection <GuiWidget>();

            var iconPath = Path.Combine("ViewTransformControls", "model.png");

            modelViewButton = new RadioIconButton(StaticData.Instance.LoadIcon(iconPath, 16, 16).SetToColor(theme.TextColor), theme)
            {
                SiblingRadioButtonList = buttonGroupB,
                Name             = "Model View Button",
                Checked          = printer?.ViewState.ViewMode == PartViewMode.Model || printer == null,
                ToolTipText      = "Model View".Localize(),
                BackgroundRadius = theme.ButtonRadius,
                Margin           = theme.ButtonSpacing
            };
            modelViewButton.Click += SwitchModes_Click;
            buttonGroupB.Add(modelViewButton);
            AddChild(modelViewButton);

            viewModes.Add(PartViewMode.Model, modelViewButton);

            iconPath       = Path.Combine("ViewTransformControls", "gcode_3d.png");
            layers3DButton = new RadioIconButton(StaticData.Instance.LoadIcon(iconPath, 16, 16).SetToColor(theme.TextColor), theme)
            {
                SiblingRadioButtonList = buttonGroupB,
                Name             = "Layers3D Button",
                Checked          = printer?.ViewState.ViewMode == PartViewMode.Layers3D,
                ToolTipText      = "3D Layer View".Localize(),
                BackgroundRadius = theme.ButtonRadius,
                Margin           = theme.ButtonSpacing
            };
            layers3DButton.Click += SwitchModes_Click;
            buttonGroupB.Add(layers3DButton);

            viewModes.Add(PartViewMode.Layers3D, layers3DButton);

            this.AddChild(layers3DButton);

            iconPath       = Path.Combine("ViewTransformControls", "gcode_2d.png");
            layers2DButton = new RadioIconButton(StaticData.Instance.LoadIcon(iconPath, 16, 16).SetToColor(theme.TextColor), theme)
            {
                SiblingRadioButtonList = buttonGroupB,
                Name             = "Layers2D Button",
                Checked          = printer?.ViewState.ViewMode == PartViewMode.Layers2D,
                ToolTipText      = "2D Layer View".Localize(),
                BackgroundRadius = theme.ButtonRadius,
                Margin           = theme.ButtonSpacing,
            };
            layers2DButton.Click += SwitchModes_Click;
            buttonGroupB.Add(layers2DButton);
            this.AddChild(layers2DButton);

            viewModes.Add(PartViewMode.Layers2D, layers2DButton);

            this.AddChild(new HorizontalSpacer());

            if (printerType == PrinterType.FFF)
            {
                int hotendCount = printer.Settings.Helpers.HotendCount();

                for (int extruderIndex = 0; extruderIndex < hotendCount; extruderIndex++)
                {
                    this.AddChild(new TemperatureWidgetHotend(printer, extruderIndex, theme, hotendCount)
                    {
                        Margin = new BorderDouble(right: 10)
                    });
                }

                if (printer.Settings.GetValue <bool>(SettingsKey.has_heated_bed))
                {
                    this.AddChild(new TemperatureWidgetBed(printer, theme));
                }

                // Register listeners
                printer.Connection.ConnectionSucceeded += CheckForPrintRecovery;

                // if we are already connected than check if there is a print recovery right now
                if (printer.Connection.CommunicationState == CommunicationStates.Connected)
                {
                    CheckForPrintRecovery(null, null);
                }
            }

            this.OverflowButton.Name        = "Printer Overflow Menu";
            this.OverflowButton.ToolTipText = "Printer Options".Localize();
            this.ExtendOverflowMenu         = (popupMenu) =>
            {
                this.GeneratePrinterOverflowMenu(popupMenu, ApplicationController.Instance.MenuTheme);
            };

            printer.ViewState.ViewModeChanged += (s, e) =>
            {
                if (viewModes[e.ViewMode] is RadioIconButton activeButton &&
                    viewModes[e.PreviousMode] is RadioIconButton previousButton &&
                    !buttonIsBeingClicked)
                {
                    // Show slide to animation from previous to current, on completion update view to current by setting active.Checked
                    previousButton.SlideToNewState(
                        activeButton,
                        this,
                        () =>
                    {
                        activeButton.Checked = true;
                    },
                        theme);
                }
            };
        }
Пример #16
0
        public PrintPopupMenu(PrinterConfig printer, ThemeConfig theme)
        {
            this.printer         = printer;
            this.DrawArrow       = true;
            this.BackgroundColor = theme.ToolbarButtonBackground;
            this.HoverColor      = theme.ToolbarButtonHover;
            this.MouseDownColor  = theme.ToolbarButtonDown;
            this.Name            = "PrintPopupMenu";
            this.HAnchor         = HAnchor.Fit;
            this.VAnchor         = VAnchor.Fit;

            settingsContext = new SettingsContext(printer, null, NamedSettingsLayers.All);

            this.DynamicPopupContent = () =>
            {
                var menuTheme = ApplicationController.Instance.MenuTheme;

                int tabIndex = 0;

                allUiFields.Clear();

                var column = new FlowLayoutWidget(FlowDirection.TopToBottom)
                {
                    Padding         = 10,
                    BackgroundColor = menuTheme.Colors.PrimaryBackgroundColor
                };

                column.AddChild(new TextWidget("Options".Localize(), textColor: menuTheme.Colors.PrimaryTextColor)
                {
                    HAnchor = HAnchor.Left
                });

                var optionsPanel = new IgnoredFlowLayout()
                {
                    Name        = "PrintPopupMenu Panel",
                    HAnchor     = HAnchor.Fit | HAnchor.Left,
                    VAnchor     = VAnchor.Fit,
                    Padding     = 5,
                    MinimumSize = new Vector2(400, 65),
                    Margin      = new BorderDouble(top: 10),
                };
                column.AddChild(optionsPanel);

                foreach (var key in new[] { "layer_height", "fill_density", "support_material", "create_raft" })
                {
                    var settingsData = SettingsOrganizer.Instance.GetSettingsData(key);
                    var row          = SliceSettingsTabView.CreateItemRow(settingsData, settingsContext, printer, menuTheme, ref tabIndex, allUiFields);

                    SliceSettingsRow.AddBordersToEditFields(row);

                    optionsPanel.AddChild(row);
                }

                var subPanel = new FlowLayoutWidget(FlowDirection.TopToBottom);

                var sectionWidget = new SectionWidget("Advanced", subPanel, menuTheme, expanded: true)
                {
                    Name    = "Advanced Section",
                    HAnchor = HAnchor.Stretch,
                    VAnchor = VAnchor.Fit,
                    Margin  = 0
                };
                column.AddChild(sectionWidget);

                bool anySettingOverridden = false;
                anySettingOverridden |= printer.Settings.GetValue <bool>(SettingsKey.spiral_vase);
                anySettingOverridden |= !string.IsNullOrWhiteSpace(printer.Settings.GetValue(SettingsKey.layer_to_pause));

                sectionWidget.Load += (s, e) =>
                {
                    sectionWidget.Checkbox.Checked = anySettingOverridden;
                };

                foreach (var key in new[] { SettingsKey.spiral_vase, SettingsKey.layer_to_pause })
                {
                    var settingsData = SettingsOrganizer.Instance.GetSettingsData(key);
                    var row          = SliceSettingsTabView.CreateItemRow(settingsData, settingsContext, printer, menuTheme, ref tabIndex, allUiFields);

                    SliceSettingsRow.AddBordersToEditFields(row);

                    subPanel.AddChild(row);
                }

                theme.ApplyBoxStyle(sectionWidget);

                sectionWidget.Margin = new BorderDouble(0, 10);
                sectionWidget.ContentPanel.Children <SettingsRow>().First().Border = new BorderDouble(0, 1);
                sectionWidget.ContentPanel.Children <SettingsRow>().Last().Border  = 0;

                var button = new TextButton("Start Print".Localize(), menuTheme)
                {
                    Name    = "Start Print Button",
                    HAnchor = HAnchor.Right,
                    VAnchor = VAnchor.Absolute,
                };
                button.Click += (s, e) =>
                {
                    if (!printer.Bed.Scene.Children.Any())
                    {
                        return;
                    }

                    UiThread.RunOnIdle(async() =>
                    {
                        // Save any pending changes before starting print operation
                        await ApplicationController.Instance.Tasks.Execute("Saving Changes".Localize(), printer.Bed.SaveChanges);

                        await ApplicationController.Instance.PrintPart(
                            printer.Bed.EditContext,
                            printer,
                            null,
                            CancellationToken.None);
                    });
                };
                column.AddChild(button);

                theme.ApplyPrimaryActionStyle(button);

                return(column);
            };

            this.AddChild(new TextButton("Print".Localize(), theme)
            {
                Selectable = false,
                Padding    = theme.TextButtonPadding.Clone(right: 5)
            });

            ActiveSliceSettings.SettingChanged.RegisterEvent((s, e) =>
            {
                if (e is StringEventArgs stringEvent)
                {
                    string settingsKey = stringEvent.Data;
                    if (allUiFields.TryGetValue(settingsKey, out UIField uifield))
                    {
                        string currentValue = settingsContext.GetValue(settingsKey);
                        if (uifield.Value != currentValue ||
                            settingsKey == "com_port")
                        {
                            uifield.SetValue(
                                currentValue,
                                userInitiated: false);
                        }
                    }
                }
            },
                                                             ref unregisterEvents);
        }
Пример #17
0
        public SetupStepComPortOne(PrinterConfig printer)
        {
            this.WindowTitle = "Setup Wizard".Localize();

            var container = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                VAnchor = VAnchor.Stretch,
                Margin  = new BorderDouble(5),
                HAnchor = HAnchor.Stretch
            };

            var elementMargin = new BorderDouble(top: 5);

            var printerMessageOne = new TextWidget("MatterControl will now attempt to auto-detect printer.".Localize(), 0, 0, 10)
            {
                TextColor = theme.TextColor,
                HAnchor   = HAnchor.Stretch,
                Margin    = elementMargin
            };

            container.AddChild(printerMessageOne);

            var printerMessageTwo = new TextWidget(string.Format("1.) {0} ({1}).", "Disconnect printer".Localize(), "if currently connected".Localize()), 0, 0, 12)
            {
                TextColor = theme.TextColor,
                HAnchor   = HAnchor.Stretch,
                Margin    = elementMargin
            };

            container.AddChild(printerMessageTwo);

            var printerMessageThree = new TextWidget(string.Format("2.) {0} '{1}'.", "Press".Localize(), "Continue".Localize()), 0, 0, 12)
            {
                TextColor = theme.TextColor,
                HAnchor   = HAnchor.Stretch,
                Margin    = elementMargin
            };

            container.AddChild(printerMessageThree);

            var removeImage = StaticData.Instance.LoadImage(Path.Combine("Images", "remove usb.png"));

            removeImage.SetRecieveBlender(new BlenderPreMultBGRA());
            container.AddChild(new ImageWidget(removeImage)
            {
                HAnchor = HAnchor.Center,
                Margin  = new BorderDouble(0, 10),
            });

            GuiWidget vSpacer = new GuiWidget();

            vSpacer.VAnchor = VAnchor.Stretch;
            container.AddChild(vSpacer);

            var setupManualConfigurationOrSkipConnectionWidget = new TextWidget("You can also".Localize() + ":", 0, 0, 10)
            {
                TextColor = theme.TextColor,
                HAnchor   = HAnchor.Stretch,
                Margin    = elementMargin
            };

            container.AddChild(setupManualConfigurationOrSkipConnectionWidget);

            var manualLink = new LinkLabel("Manually Configure Connection".Localize(), theme)
            {
                Margin    = new BorderDouble(0, 5),
                TextColor = theme.TextColor
            };

            manualLink.Click += (s, e) => UiThread.RunOnIdle(() =>
            {
                DialogWindow.ChangeToPage(new SetupStepComPortManual(printer));
            });
            container.AddChild(manualLink);

            var printerMessageFour = new TextWidget("or".Localize(), 0, 0, 10)
            {
                TextColor = theme.TextColor,
                HAnchor   = HAnchor.Stretch,
                Margin    = elementMargin
            };

            container.AddChild(printerMessageFour);

            var skipConnectionLink = new LinkLabel("Skip Connection Setup".Localize(), theme)
            {
                Margin    = new BorderDouble(0, 8),
                TextColor = theme.TextColor
            };

            skipConnectionLink.Click += (s, e) =>
            {
                printer.Connection.HaltConnectionThread();
                Parent.Close();
            };
            container.AddChild(skipConnectionLink);

            contentRow.AddChild(container);

            // Construct buttons
            var nextButton = theme.CreateDialogButton("Continue".Localize());

            nextButton.Click += (s, e) =>
            {
                DialogWindow.ChangeToPage(new SetupStepComPortTwo(printer));
            };

            this.AddPageAction(nextButton);
        }
Пример #18
0
 public static string FilamentUsed(this GCodeFile loadedGCode, PrinterConfig printer)
 {
     return(string.Format("{0:0.0} mm", loadedGCode.GetFilamentUsedMm(printer.Settings.GetValue <double>(SettingsKey.filament_diameter))));
 }
 public ProcessWriteRegexStream(PrinterConfig printer, GCodeStream internalStream, QueuedCommandsStream queueStream)
     : base(printer, internalStream)
 {
     this.queueStream = queueStream;
 }
Пример #20
0
 public static string FilamentVolume(this GCodeFile loadedGCode, PrinterConfig printer)
 {
     return(string.Format("{0:0.00} cm³", loadedGCode.GetFilamentCubicMm(printer.Settings.GetValue <double>(SettingsKey.filament_diameter)) / 1000));
 }
Пример #21
0
        public PauseHandlingStream(PrinterConfig printer, GCodeStream internalStream)
            : base(printer, internalStream)
        {
            // if we have a runout sensor, register to listen for lines to check it
            if (printer.Settings.GetValue <bool>(SettingsKey.filament_runout_sensor))
            {
                printer.Connection.LineReceived += (s, line) =>
                {
                    if (line != null)
                    {
                        if (line.Contains("ros_"))
                        {
                            if (line.Contains("TRIGGERED"))
                            {
                                readOutOfFilament = true;
                            }
                        }

                        if (line.Contains("pos_"))
                        {
                            double sensorDistance  = 0;
                            double stepperDistance = 0;
                            if (GCodeFile.GetFirstNumberAfter("SENSOR:", line, ref sensorDistance))
                            {
                                if (sensorDistance < -1 || sensorDistance > 1)
                                {
                                    printer.Connection.FilamentPositionSensorDetected = true;
                                }

                                if (printer.Connection.FilamentPositionSensorDetected)
                                {
                                    GCodeFile.GetFirstNumberAfter("STEPPER:", line, ref stepperDistance);

                                    var stepperDelta = Math.Abs(stepperDistance - positionSensorData.LastStepperDistance);

                                    // if we think we should have move the filament by more than 1mm
                                    if (stepperDelta > 1)
                                    {
                                        var sensorDelta = Math.Abs(sensorDistance - positionSensorData.LastSensorDistance);
                                        // check if the sensor data is within a tolerance of the stepper data

                                        var deltaRatio = sensorDelta / stepperDelta;
                                        if (deltaRatio < .5 || deltaRatio > 2)
                                        {
                                            // we have a repartable discrepency set a runout state
                                            positionSensorData.ExtrusionDiscrepency++;
                                            if (positionSensorData.ExtrusionDiscrepency > 2)
                                            {
                                                readOutOfFilament = true;
                                                positionSensorData.ExtrusionDiscrepency = 0;
                                            }
                                        }
                                        else
                                        {
                                            positionSensorData.ExtrusionDiscrepency = 0;
                                        }

                                        // and recard this position
                                        positionSensorData.LastSensorDistance  = sensorDistance;
                                        positionSensorData.LastStepperDistance = stepperDistance;
                                    }
                                }
                            }
                        }
                    }
                };
            }
        }
Пример #22
0
        public static string EstimatedCost(this GCodeFile loadedGCode, PrinterConfig printer)
        {
            var totalMass = TotalCost(loadedGCode, printer);

            return(totalMass <= 0 ? "Unknown" : string.Format("${0:0.00}", totalMass));
        }
Пример #23
0
        public static GuiWidget PrintProgressWidget(PrinterConfig printer, ThemeConfig theme)
        {
            var bodyRow = new GuiWidget()
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Top | VAnchor.Fit,
                //BackgroundColor = new Color(theme.Colors.PrimaryBackgroundColor, 128),
                MinimumSize = new Vector2(275, 140),
            };

            // Progress section
            var expandingContainer = new HorizontalSpacer()
            {
                VAnchor = VAnchor.Fit | VAnchor.Center
            };

            bodyRow.AddChild(expandingContainer);

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

            expandingContainer.AddChild(progressContainer);

            var progressDial = new ProgressDial()
            {
                HAnchor = HAnchor.Center,
                Height  = 200 * DeviceScale,
                Width   = 200 * DeviceScale
            };

            progressContainer.AddChild(progressDial);

            var bottomRow = new GuiWidget()
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit
            };

            progressContainer.AddChild(bottomRow);

            var timeContainer = new FlowLayoutWidget()
            {
                HAnchor = HAnchor.Center | HAnchor.Fit,
                Margin  = 3
            };

            bottomRow.AddChild(timeContainer);

            // we can only reslice on 64 bit, because in 64 bit we always have the gcode loaded
            if (IntPtr.Size == 8)
            {
                var resliceButton = new TextButton("Re-Slice", theme)
                {
                    HAnchor = HAnchor.Right,
                    VAnchor = VAnchor.Center,
                    Margin  = new BorderDouble(0, 0, 7, 0),
                    Name    = "Re-Slice Button"
                };
                bool activelySlicing = false;
                resliceButton.Click += (s, e) =>
                {
                    resliceButton.Enabled = false;
                    UiThread.RunOnIdle(async() =>
                    {
                        if (!activelySlicing &&
                            printer.Settings.IsValid() &&
                            printer.Bed.EditContext.SourceItem != null)
                        {
                            activelySlicing = true;
                            if (bottomRow.Name == null)
                            {
                                bottomRow.Name = printer.Bed.EditContext.GCodeFilePath;
                            }
                            await ApplicationController.Instance.Tasks.Execute("Saving".Localize(), printer.Bed.SaveChanges);
                            // start up a new slice on a backgroud thread
                            await ApplicationController.Instance.SliceItemLoadOutput(
                                printer,
                                printer.Bed.Scene,
                                printer.Bed.EditContext.GCodeFilePath);
                            // Switch to the 3D layer view if on Model view
                            if (printer.ViewState.ViewMode == PartViewMode.Model)
                            {
                                printer.ViewState.ViewMode = PartViewMode.Layers3D;
                            }
                            // when it is done queue it to the change to gcode stream
                            var message2 = "Would you like to switch to the new G-Code? Before you switch, check that your are seeing the changes you expect.".Localize();
                            var caption2 = "Switch to new G-Code?".Localize();
                            StyledMessageBox.ShowMessageBox(async(clickedOk2) =>
                            {
                                if (clickedOk2)
                                {
                                    if (printer.Connection != null &&
                                        (printer.Connection.PrinterIsPrinting || printer.Connection.PrinterIsPaused))
                                    {
                                        printer.Connection.SwitchToGCode(printer.Bed.EditContext.GCodeFilePath);
                                        bottomRow.Name = printer.Bed.EditContext.GCodeFilePath;
                                    }
                                }
                                else
                                {
                                    await ApplicationController.Instance.SliceItemLoadOutput(
                                        printer,
                                        printer.Bed.Scene,
                                        bottomRow.Name);
                                }
                                activelySlicing       = false;
                                resliceButton.Enabled = true;
                            }, message2, caption2, StyledMessageBox.MessageType.YES_NO, "Switch".Localize(), "Cancel".Localize());
                        }
                        else
                        {
                            resliceButton.Enabled = true;
                        }
                    });
                };
                bottomRow.AddChild(resliceButton);
            }

            timeContainer.AddChild(new ImageWidget(AggContext.StaticData.LoadIcon("fa-clock_24.png", theme.InvertIcons))
            {
                VAnchor = VAnchor.Center
            });

            var timeWidget = new TextWidget("", pointSize: 22, textColor: theme.Colors.PrimaryTextColor)
            {
                AutoExpandBoundsToText = true,
                Margin  = new BorderDouble(10, 0, 0, 0),
                VAnchor = VAnchor.Center,
            };

            timeContainer.AddChild(timeWidget);

            var runningInterval = UiThread.SetInterval(
                () =>
            {
                int secondsPrinted = printer.Connection.SecondsPrinted;
                int hoursPrinted   = (int)(secondsPrinted / (60 * 60));
                int minutesPrinted = (secondsPrinted / 60 - hoursPrinted * 60);

                secondsPrinted = secondsPrinted % 60;

                // TODO: Consider if the consistency of a common time format would look and feel better than changing formats based on elapsed duration
                timeWidget.Text = (hoursPrinted <= 0) ? $"{minutesPrinted}:{secondsPrinted:00}" : $"{hoursPrinted}:{minutesPrinted:00}:{secondsPrinted:00}";

                progressDial.LayerIndex          = printer.Connection.CurrentlyPrintingLayer;
                progressDial.LayerCompletedRatio = printer.Connection.RatioIntoCurrentLayer;
                progressDial.CompletedRatio      = printer.Connection.PercentComplete / 100;

                switch (printer.Connection.CommunicationState)
                {
                case CommunicationStates.PreparingToPrint:
                case CommunicationStates.Printing:
                case CommunicationStates.Paused:
                    bodyRow.Visible = true;
                    break;

                default:
                    bodyRow.Visible = false;
                    break;
                }
            }, 1);

            bodyRow.Closed += (s, e) => runningInterval.Continue = false;

            bodyRow.Visible = false;

            return(bodyRow);
        }
Пример #24
0
        public static double TotalCost(this GCodeFile loadedGCode, PrinterConfig printer)
        {
            double filamentCost = printer.Settings.GetValue <double>(SettingsKey.filament_cost);

            return(loadedGCode.TotalMass(printer) / 1000 * filamentCost);
        }
Пример #25
0
 public FeedRateMultiplyerStream(PrinterConfig printer, GCodeStream internalStream)
     : base(printer, internalStream)
 {
 }
Пример #26
0
 public NotPrintingStream(PrinterConfig printer)
     : base(printer)
 {
 }
Пример #27
0
 public MapStartGCode(PrinterConfig printer, string canonicalSettingsName, string exportedName, bool escapeNewlineCharacters)
     : base(printer, canonicalSettingsName, exportedName)
 {
     this.escapeNewlineCharacters = escapeNewlineCharacters;
 }
Пример #28
0
 public DropMenuWrappedField(UIField uiField, SliceSettingData settingData, Color textColor, ThemeConfig theme, PrinterConfig printer)
 {
     this.printer     = printer;
     this.settingData = settingData;
     this.uiField     = uiField;
     this.textColor   = textColor;
     this.theme       = theme;
 }
Пример #29
0
        private void Init()
        {
            printConfig = new PrinterConfig();
            txtBoxBevaragePrinterName.Text = printConfig.BeveragePrinterName;
            txtBoxKitchenPrinterName.Text = printConfig.KitchenPrinterName;
            txtBoxClientPrinterName.Text = printConfig.ClientPrinterName;
            txtBoxotherPrinterName.Text = printConfig.OtherPrinter;
            txtBoxothernonfoodPrinterNametextBox.Text = printConfig.OtherNonFoodPrinter;
            radioButtonYex.Checked = printConfig.EnableSerialPortPrinting;

            //if (printConfig.BeveragePrintPaperSize == 38)
            //{
            //    rdbBevaragePrintSize38.Checked = true;
            //}
            //else if (printConfig.BeveragePrintPaperSize == 26)
            //{
            //    rdbBevaragePrintSize26.Checked = true;
            //}

            //if (printConfig.KitchenPrintPaperSize == 38)
            //{
            //    rdbKitchenPaperSize38.Checked = true;
            //}
            //else if (printConfig.KitchenPrintPaperSize == 26)
            //{
            //    rdbKitchenPaperSize26.Checked = true;
            //}
        }
Пример #30
0
 public void Initialize(PrinterConfig printer)
 {
     this.printer         = printer;
     printerSetupRequired = PrinterCalibrationWizard.SetupRequired(printer, requiresLoadedFilament: false);
 }