Beispiel #1
0
        protected void SetItemThumbnail(ImageBuffer thumbnail)
        {
            if (thumbnail != null)
            {
                // Resize canvas to target as fallback
                if (thumbnail.Width < thumbWidth || thumbnail.Height < thumbHeight)
                {
                    thumbnail = ListView.ResizeCanvas(thumbnail, thumbWidth, thumbHeight);
                }
                else if (thumbnail.Width > thumbWidth || thumbnail.Height > thumbHeight)
                {
                    thumbnail = LibraryProviderHelpers.ResizeImage(thumbnail, thumbWidth, thumbHeight);
                }

                if (GuiWidget.DeviceScale != 1)
                {
                    thumbnail = thumbnail.CreateScaledImage(GuiWidget.DeviceScale);
                }

                // TODO: Resolve and implement
                // Allow the container to draw an overlay - use signal interface or add method to interface?
                //var iconWithOverlay = ActiveContainer.DrawOverlay()

                if (thumbnail != null &&
                    this.imageWidget != null &&
                    (this.imageWidget.Image == null ||
                     !thumbnail.Equals(this.imageWidget.Image, 5)))
                {
                    this.imageWidget.Image = thumbnail;
                    this.ImageSet?.Invoke(this, null);
                    this.Invalidate();
                }
            }
        }
Beispiel #2
0
        public ImageBuffer LoadCachedImage(ILibraryItem libraryItem, int width, int height)
        {
            // try to load it from the users cache
            var expectedCachePath = this.CachePath(libraryItem, width, height);

            ImageBuffer cachedItem = LoadImage(expectedCachePath);

            if (cachedItem != null &&
                cachedItem.Width > 0 && cachedItem.Height > 0)
            {
                cachedItem.SetRecieveBlender(new BlenderPreMultBGRA());
                return(cachedItem);
            }

            // if we don't find it see if it in the cache at a bigger size
            foreach (var cacheSize in cacheSizes.Where(s => s > width))
            {
                cachedItem = LoadImage(this.CachePath(libraryItem, cacheSize, cacheSize));
                if (cachedItem != null &&
                    cachedItem.Width > 0 && cachedItem.Height > 0)
                {
                    cachedItem = cachedItem.CreateScaledImage(width, height);
                    cachedItem.SetRecieveBlender(new BlenderPreMultBGRA());

                    ImageIO.SaveImageData(expectedCachePath, cachedItem);

                    return(cachedItem);
                }
            }

            // could not find it in the user cache, try to load it from static data
            var staticDataFilename = Path.Combine("Images", "Thumbnails", CacheFilename(libraryItem, 256, 256));

            if (StaticData.Instance.FileExists(staticDataFilename))
            {
                cachedItem = StaticData.Instance.LoadImage(staticDataFilename);
                cachedItem.SetRecieveBlender(new BlenderPreMultBGRA());

                cachedItem = cachedItem.CreateScaledImage(width, height);

                ImageIO.SaveImageData(expectedCachePath, cachedItem);

                return(cachedItem);
            }

            return(null);
        }
Beispiel #3
0
        public ImageBuffer LoadCachedImage(string cacheId, int width, int height)
        {
            var         expectedCachePath = this.CachePath(cacheId, width, height);
            ImageBuffer cachedItem        = LoadImage(expectedCachePath);

            if (cachedItem != null)
            {
                return(cachedItem);
            }

            // if we don't find it see if it in the cache at a bigger size
            foreach (var cacheSize in cacheSizes.Where(s => s > width))
            {
                cachedItem = LoadImage(this.CachePath(cacheId, cacheSize, cacheSize));
                if (cachedItem != null &&
                    cachedItem.Width > 0 && cachedItem.Height > 0)
                {
                    cachedItem = cachedItem.CreateScaledImage(width, height);
                    cachedItem.SetRecieveBlender(new BlenderPreMultBGRA());

                    AggContext.ImageIO.SaveImageData(expectedCachePath, cachedItem);

                    return(cachedItem);
                }
            }

            // could not find it in the user cache, try to load it from static data
            var staticDataFilename = Path.Combine("Images", "Thumbnails", $"{cacheId}-{256}x{256}.png");

            if (AggContext.StaticData.FileExists(staticDataFilename))
            {
                cachedItem = AggContext.StaticData.LoadImage(staticDataFilename);
                cachedItem.SetRecieveBlender(new BlenderPreMultBGRA());

                cachedItem = cachedItem.CreateScaledImage(width, height);

                AggContext.ImageIO.SaveImageData(expectedCachePath, cachedItem);

                return(cachedItem);
            }

            return(null);
        }
Beispiel #4
0
        public void RenderMaxSize(ImageBuffer image, double x, double y, double maxX, double maxY, out Vector2 size, bool right = false, bool preScale = false)
        {
            size.X = image.Width;
            size.Y = image.Height;

            if (size.X > maxX)
            {
                size.X = maxX;
                var ratio = size.X / image.Width;
                size.Y = image.Height * ratio;
            }

            if (size.Y > maxY)
            {
                size.Y = maxY;
                var ratio = size.Y / image.Height;
                size.X = image.Width * ratio;
            }

            if (right)
            {
                var expectedRight = x + image.Width;
                if (preScale)
                {
                    this.Render(image.CreateScaledImage(size.X / image.Width), x, y, size.X, size.Y);
                }
                else
                {
                    this.Render(image, expectedRight - size.X, y, size.X, size.Y);
                }
            }
            else
            {
                if (preScale)
                {
                    this.Render(image.CreateScaledImage(size.X / image.Width), x, y, size.X, size.Y);
                }
                else
                {
                    this.Render(image, x, y, size.X, size.Y);
                }
            }
        }
        /// <summary>
        /// Load the specified file from the StaticData/Icons path and scale it to the given size,
        /// adjusting for the device scale in GuiWidget
        /// </summary>
        /// <param name="path">The file path to load</param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <returns></returns>
        public ImageBuffer LoadIcon(string path, int width, int height)
        {
            int         deviceWidth  = (int)(width * GuiWidget.DeviceScale);
            int         deviceHeight = (int)(height * GuiWidget.DeviceScale);
            ImageBuffer scaledImage  = LoadIcon(path);

            scaledImage.SetRecieveBlender(new BlenderPreMultBGRA());
            scaledImage = ImageBuffer.CreateScaledImage(scaledImage, deviceWidth, deviceHeight);

            return(scaledImage);
        }
Beispiel #6
0
        /// <summary>
        /// Load the specified file from the StaticData/Icons path and scale it to the given size,
        /// adjusting for the device scale in GuiWidget
        /// </summary>
        /// <param name="path">The file path to load</param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <returns></returns>
        public ImageBuffer LoadIcon(string path, int width, int height, bool invertImage = false)
        {
            int deviceWidth  = (int)(width * GuiWidget.DeviceScale);
            int deviceHeight = (int)(height * GuiWidget.DeviceScale);

            ImageBuffer image = LoadIcon(path, invertImage);

            image.SetRecieveBlender(new BlenderPreMultBGRA());

            return(image.CreateScaledImage(deviceWidth, deviceHeight));
        }
Beispiel #7
0
            private ImageBuffer ToResizedGrayscale(ImageBuffer image, double onPlateWidth = 0)
            {
                var ratio = onPlateWidth / image.Width;

                var resizedImage = image.CreateScaledImage(ratio);

                var grayImage = resizedImage.ToGrayscale();

                // Render grayscale pixels onto resized image with larger pixel format needed by caller
                resizedImage.NewGraphics2D().Render(grayImage, 0, 0);

                return(resizedImage);
            }
        public Button GenerateEditButton()
        {
            ImageBuffer normalImage = StaticData.Instance.LoadIcon("icon_edit_white_32x32.png");
            int         iconSize    = (int)(16 * TextWidget.GlobalPointSizeScaleRatio);

            normalImage = ImageBuffer.CreateScaledImage(normalImage, iconSize, iconSize);

            Button editButton = new Button(0, 0, new ButtonViewThreeImage(normalImage,
                                                                          WhiteToColor.CreateWhiteToColor(normalImage, RGBA_Bytes.Gray),
                                                                          WhiteToColor.CreateWhiteToColor(normalImage, RGBA_Bytes.Black)));

            editButton.Margin  = new BorderDouble(2, 2, 2, 0);
            editButton.VAnchor = Agg.UI.VAnchor.ParentTop;
            return(editButton);
        }
Beispiel #9
0
        public ImageBuffer EnsureCorrectThumbnailSizing(ImageBuffer thumbnail, int thumbWidth, int thumbHeight)
        {
            // Resize canvas to target as fallback
            if (thumbnail.Width < thumbWidth || thumbnail.Height < thumbHeight)
            {
                thumbnail = ListView.ResizeCanvas(thumbnail, thumbWidth, thumbHeight);
            }
            else if (thumbnail.Width > thumbWidth || thumbnail.Height > thumbHeight)
            {
                thumbnail = LibraryProviderHelpers.ResizeImage(thumbnail, thumbWidth, thumbHeight);
            }

            if (GuiWidget.DeviceScale != 1)
            {
                thumbnail = thumbnail.CreateScaledImage(GuiWidget.DeviceScale);
            }

            return(thumbnail);
        }
        public GuiWidget GenerateGroupBoxLabelWithEdit(TextWidget textWidget, out Button editButton)
        {
            FlowLayoutWidget groupLableAndEditControl = new FlowLayoutWidget();

            ImageBuffer normalImage = StaticData.Instance.LoadIcon("icon_edit_white_32x32.png");
            int         iconSize    = (int)(16 * TextWidget.GlobalPointSizeScaleRatio);

            normalImage = ImageBuffer.CreateScaledImage(normalImage, iconSize, iconSize);

            editButton = new Button(0, 0, new ButtonViewThreeImage(normalImage,
                                                                   WhiteToColor.CreateWhiteToColor(normalImage, RGBA_Bytes.Gray),
                                                                   WhiteToColor.CreateWhiteToColor(normalImage, RGBA_Bytes.Black)));
            editButton.Margin  = new BorderDouble(2, 2, 2, 0);
            editButton.VAnchor = Agg.UI.VAnchor.ParentBottom;
            textWidget.VAnchor = Agg.UI.VAnchor.ParentBottom;
            groupLableAndEditControl.AddChild(textWidget);
            groupLableAndEditControl.AddChild(editButton);

            return(groupLableAndEditControl);
        }
        /// <summary>
        /// Generates a resized images matching the target bounds
        /// </summary>
        /// <param name="imageBuffer">The ImageBuffer to resize</param>
        /// <param name="targetWidth">The target width</param>
        /// <param name="targetHeight">The target height</param>
        /// <returns>A resized ImageBuffer constrained to the given bounds and centered on the new surface</returns>
        public static ImageBuffer ResizeImage(ImageBuffer imageBuffer, int targetWidth, int targetHeight)
        {
            var expectedSize = new Vector2((int)(targetWidth * GuiWidget.DeviceScale), (int)(targetHeight * GuiWidget.DeviceScale));

            int width  = imageBuffer.Width;
            int height = imageBuffer.Height;

            bool resizeWidth    = width >= height;
            bool resizeRequired = (resizeWidth) ? width != expectedSize.X : height != expectedSize.Y;

            if (resizeRequired)
            {
                var scaledImageBuffer = imageBuffer.CreateScaledImage(targetWidth, targetHeight);
                scaledImageBuffer.SetRecieveBlender(new BlenderPreMultBGRA());

                return(scaledImageBuffer);
            }

            return(imageBuffer);
        }
        private GuiWidget GetMenuContent(string itemName, ImageBuffer leftImage, RGBA_Bytes color)
        {
            var rowContainer = new FlowLayoutWidget()
            {
                HAnchor         = HAnchor.ParentLeftRight | HAnchor.FitToChildren,
                VAnchor         = VAnchor.FitToChildren,
                BackgroundColor = color
            };

            var textWidget = new TextWidget(itemName)
            {
                Margin    = MenuItemsPadding,
                TextColor = MenuItemsTextColor
            };

            if (UseLeftIcons || leftImage != null)
            {
                if (leftImage != null)
                {
                    int         size        = (int)(20 * GuiWidget.DeviceScale + .5);
                    ImageBuffer scaledImage = ImageBuffer.CreateScaledImage(leftImage, size, size);
                    rowContainer.AddChild(new ImageWidget(scaledImage)
                    {
                        VAnchor = VAnchor.ParentCenter,
                        Margin  = new BorderDouble(MenuItemsPadding.Left, MenuItemsPadding.Bottom, 3, MenuItemsPadding.Top),
                    });
                    textWidget.Margin = new BorderDouble(0, MenuItemsPadding.Bottom, MenuItemsPadding.Right, MenuItemsPadding.Top);
                }
                else
                {
                    textWidget.Margin = new BorderDouble(MenuItemsPadding.Left + 20 + 3, MenuItemsPadding.Bottom, MenuItemsPadding.Right, MenuItemsPadding.Top);
                }
            }
            rowContainer.AddChild(textWidget);

            return(rowContainer);
        }
        public static ImageBuffer GetImageForItem(PrintItemWrapper itemWrapper, int width, int height)
        {
            if (itemWrapper == null)
            {
                return(StaticData.Instance.LoadIcon("part_icon_transparent_100x100.png"));
            }

            ImageBuffer thumbnailImage = new ImageBuffer((int)width, (int)height);

            if (itemWrapper.FileLocation == QueueData.SdCardFileName)
            {
                ImageBuffer sdCardImage = StaticData.Instance.LoadIcon(Path.ChangeExtension("icon_sd_card_115x115", partExtension)).InvertLightness();
                thumbnailImage.SetRecieveBlender(new BlenderPreMultBGRA());
                Graphics2D graphics = thumbnailImage.NewGraphics2D();
                graphics.Render(sdCardImage, width / 2 - sdCardImage.Width / 2, height / 2 - sdCardImage.Height / 2);
                Ellipse outline = new Ellipse(new Vector2(width / 2.0, height / 2.0), width / 2 - width / 12);
                graphics.Render(new Stroke(outline, width / 12), RGBA_Bytes.White);
                return(thumbnailImage);
            }
            else if (Path.GetExtension(itemWrapper.FileLocation).ToUpper() == ".GCODE")
            {
                thumbnailImage.SetRecieveBlender(new BlenderPreMultBGRA());
                Graphics2D graphics = thumbnailImage.NewGraphics2D();
                Vector2    center   = new Vector2(width / 2.0, height / 2.0);
                Ellipse    outline  = new Ellipse(center, width / 2 - width / 12);
                graphics.Render(new Stroke(outline, width / 12), RGBA_Bytes.White);
                graphics.DrawString("GCode", center.x, center.y, 8 * width / 50, Agg.Font.Justification.Center, Agg.Font.Baseline.BoundsCenter, color: RGBA_Bytes.White);
                return(thumbnailImage);
            }
            else if (!File.Exists(itemWrapper.FileLocation))
            {
                thumbnailImage.SetRecieveBlender(new BlenderPreMultBGRA());
                Graphics2D graphics = thumbnailImage.NewGraphics2D();
                Vector2    center   = new Vector2(width / 2.0, height / 2.0);
                graphics.DrawString("Missing", center.x, center.y, 8 * width / 50, Agg.Font.Justification.Center, Agg.Font.Baseline.BoundsCenter, color: RGBA_Bytes.White);
                return(thumbnailImage);
            }
            else if (MeshIsTooBigToLoad(itemWrapper.FileLocation))
            {
                thumbnailImage.SetRecieveBlender(new BlenderPreMultBGRA());
                Graphics2D graphics = thumbnailImage.NewGraphics2D();
                Vector2    center   = new Vector2(width / 2.0, height / 2.0);
                double     yOffset  = 8 * width / 50 * GuiWidget.DeviceScale * 2;
                graphics.DrawString("Reduce\nPolygons\nto\nRender", center.x, center.y + yOffset, 8 * width / 50, Agg.Font.Justification.Center, Agg.Font.Baseline.BoundsCenter, color: RGBA_Bytes.White);
                return(thumbnailImage);
            }

            string stlHashCode = itemWrapper.FileHashCode.ToString();

            if (stlHashCode != "0")
            {
                ImageBuffer bigRender = LoadImageFromDisk(stlHashCode);
                if (bigRender != null)
                {
                    thumbnailImage = bigRender;
                }

                bigRender.SetRecieveBlender(new BlenderPreMultBGRA());

                thumbnailImage = ImageBuffer.CreateScaledImage(bigRender, (int)width, (int)height);
            }

            thumbnailImage.MarkImageChanged();
            return(thumbnailImage);
        }
Beispiel #14
0
        public virtual FlowLayoutWidget GetPulldownContainer()
        {
            DropDownList = CreateDropdown();

            FlowLayoutWidget container = new FlowLayoutWidget();

            container.HAnchor = HAnchor.ParentLeftRight;
            container.Padding = new BorderDouble(6, 0);

            ImageBuffer normalImage = StaticData.Instance.LoadIcon("icon_edit_white_32x32.png");
            int         iconSize    = (int)(16 * TextWidget.GlobalPointSizeScaleRatio);

            normalImage = ImageBuffer.CreateScaledImage(normalImage, iconSize, iconSize);

            editButton = imageButtonFactory.Generate(normalImage, WhiteToColor.CreateWhiteToColor(normalImage, RGBA_Bytes.Gray));

            editButton.VAnchor = VAnchor.ParentCenter;
            editButton.Margin  = new BorderDouble(right: 6);
            editButton.Click  += (sender, e) =>
            {
#if DO_IN_PLACE_EDIT
                if (filterTag == "quality")
                {
                    SliceSettingsWidget.SettingsIndexBeingEdited = 2;
                }
                else
                {
                    SliceSettingsWidget.SettingsIndexBeingEdited = 3;
                }
                // If there is a setting selected then reload the silce setting widget with the presetIndex to edit.
                ApplicationController.Instance.ReloadAdvancedControlsPanel();
                // If no setting selected then call onNewItemSelect(object sender, EventArgs e)
#else
                if (filterTag == "material")
                {
                    if (ApplicationController.Instance.EditMaterialPresetsWindow == null)
                    {
                        ApplicationController.Instance.EditMaterialPresetsWindow         = new SlicePresetsWindow(ReloadOptions, filterLabel, filterTag);
                        ApplicationController.Instance.EditMaterialPresetsWindow.Closed += (popupWindowSender, popupWindowSenderE) => { ApplicationController.Instance.EditMaterialPresetsWindow = null; };
                    }
                    else
                    {
                        ApplicationController.Instance.EditMaterialPresetsWindow.BringToFront();
                    }
                }

                if (filterTag == "quality")
                {
                    if (ApplicationController.Instance.EditQualityPresetsWindow == null)
                    {
                        ApplicationController.Instance.EditQualityPresetsWindow         = new SlicePresetsWindow(ReloadOptions, filterLabel, filterTag);
                        ApplicationController.Instance.EditQualityPresetsWindow.Closed += (popupWindowSender, popupWindowSenderE) => { ApplicationController.Instance.EditQualityPresetsWindow = null; };
                    }
                    else
                    {
                        ApplicationController.Instance.EditQualityPresetsWindow.BringToFront();
                    }
                }
#endif
            };

            container.AddChild(editButton);
            container.AddChild(DropDownList);
            return(container);
        }
        private bool SetImageFast()
        {
            if (this.ItemWrapper == null)
            {
                this.thumbnailImage = new ImageBuffer(this.noThumbnailImage);
                this.Invalidate();
                return(true);
            }

            if (this.ItemWrapper.FileLocation == QueueData.SdCardFileName)
            {
                switch (this.Size)
                {
                case ImageSizes.Size115x115:
                {
                    StaticData.Instance.LoadIcon(Path.ChangeExtension("icon_sd_card_115x115", partExtension), this.thumbnailImage);
                }
                break;

                case ImageSizes.Size50x50:
                {
                    StaticData.Instance.LoadIcon(Path.ChangeExtension("icon_sd_card_50x50", partExtension), this.thumbnailImage);
                }
                break;

                default:
                    throw new NotImplementedException();
                }
                this.thumbnailImage.SetRecieveBlender(new BlenderPreMultBGRA());
                Graphics2D graphics = this.thumbnailImage.NewGraphics2D();
                Ellipse    outline  = new Ellipse(new Vector2(Width / 2.0, Height / 2.0), Width / 2 - Width / 12);
                graphics.Render(new Stroke(outline, Width / 12), RGBA_Bytes.White);

                UiThread.RunOnIdle(this.EnsureImageUpdated);
                return(true);
            }
            else if (Path.GetExtension(this.ItemWrapper.FileLocation).ToUpper() == ".GCODE")
            {
                CreateImage(this, Width, Height);
                this.thumbnailImage.SetRecieveBlender(new BlenderPreMultBGRA());
                Graphics2D graphics = this.thumbnailImage.NewGraphics2D();
                Vector2    center   = new Vector2(Width / 2.0, Height / 2.0);
                Ellipse    outline  = new Ellipse(center, Width / 2 - Width / 12);
                graphics.Render(new Stroke(outline, Width / 12), RGBA_Bytes.White);
                graphics.DrawString("GCode", center.x, center.y, 8 * Width / 50, Agg.Font.Justification.Center, Agg.Font.Baseline.BoundsCenter, color: RGBA_Bytes.White);

                UiThread.RunOnIdle(this.EnsureImageUpdated);
                return(true);
            }
            else if (!File.Exists(this.ItemWrapper.FileLocation))
            {
                CreateImage(this, Width, Height);
                this.thumbnailImage.SetRecieveBlender(new BlenderPreMultBGRA());
                Graphics2D graphics = this.thumbnailImage.NewGraphics2D();
                Vector2    center   = new Vector2(Width / 2.0, Height / 2.0);
                graphics.DrawString("Missing", center.x, center.y, 8 * Width / 50, Agg.Font.Justification.Center, Agg.Font.Baseline.BoundsCenter, color: RGBA_Bytes.White);

                UiThread.RunOnIdle(this.EnsureImageUpdated);
                return(true);
            }
            else if (MeshIsTooBigToLoad(this.ItemWrapper.FileLocation))
            {
                CreateImage(this, Width, Height);
                this.thumbnailImage.SetRecieveBlender(new BlenderPreMultBGRA());
                Graphics2D graphics = this.thumbnailImage.NewGraphics2D();
                Vector2    center   = new Vector2(Width / 2.0, Height / 2.0);
                double     yOffset  = 8 * Width / 50 * GuiWidget.DeviceScale * 2;
                graphics.DrawString("Reduce\nPolygons\nto\nRender", center.x, center.y + yOffset, 8 * Width / 50, Agg.Font.Justification.Center, Agg.Font.Baseline.BoundsCenter, color: RGBA_Bytes.White);

                UiThread.RunOnIdle(this.EnsureImageUpdated);
                return(true);
            }

            string stlHashCode = this.ItemWrapper.FileHashCode.ToString();

            if (stlHashCode != "0")
            {
                ImageBuffer bigRender = LoadImageFromDisk(this, stlHashCode);
                if (bigRender == null)
                {
                    this.thumbnailImage = new ImageBuffer(buildingThumbnailImage);
                    return(false);
                }

                bigRender.SetRecieveBlender(new BlenderPreMultBGRA());

                this.thumbnailImage = ImageBuffer.CreateScaledImage(bigRender, (int)Width, (int)Height);

                UiThread.RunOnIdle(this.EnsureImageUpdated);

                return(true);
            }

            return(false);
        }
        private void CreateThumbnail()
        {
            string stlHashCode = this.ItemWrapper.FileHashCode.ToString();

            ImageBuffer bigRender = new ImageBuffer();

            if (!File.Exists(this.ItemWrapper.FileLocation))
            {
                return;
            }

            List <MeshGroup> loadedMeshGroups = MeshFileIo.Load(this.ItemWrapper.FileLocation);

            RenderType renderType = GetRenderType(this.ItemWrapper.FileLocation);

            switch (renderType)
            {
            case RenderType.RAY_TRACE:
            {
                ThumbnailTracer tracer = new ThumbnailTracer(loadedMeshGroups, BigRenderSize.x, BigRenderSize.y);
                tracer.DoTrace();

                bigRender = tracer.destImage;
            }
            break;

            case RenderType.PERSPECTIVE:
            {
                ThumbnailTracer tracer = new ThumbnailTracer(loadedMeshGroups, BigRenderSize.x, BigRenderSize.y);
                this.thumbnailImage = new ImageBuffer(this.buildingThumbnailImage);
                this.thumbnailImage.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0));

                bigRender = new ImageBuffer(BigRenderSize.x, BigRenderSize.y);

                foreach (MeshGroup meshGroup in loadedMeshGroups)
                {
                    double minZ = double.MaxValue;
                    double maxZ = double.MinValue;
                    foreach (Mesh loadedMesh in meshGroup.Meshes)
                    {
                        tracer.GetMinMaxZ(loadedMesh, ref minZ, ref maxZ);
                    }

                    foreach (Mesh loadedMesh in meshGroup.Meshes)
                    {
                        tracer.DrawTo(bigRender.NewGraphics2D(), loadedMesh, RGBA_Bytes.White, minZ, maxZ);
                    }
                }

                if (bigRender == null)
                {
                    bigRender = new ImageBuffer(this.noThumbnailImage);
                }
            }
            break;

            case RenderType.NONE:
            case RenderType.ORTHOGROPHIC:

                this.thumbnailImage = new ImageBuffer(this.buildingThumbnailImage);
                this.thumbnailImage.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0));
                bigRender = BuildImageFromMeshGroups(loadedMeshGroups, stlHashCode, BigRenderSize);
                if (bigRender == null)
                {
                    bigRender = new ImageBuffer(this.noThumbnailImage);
                }
                break;
            }

            // and save it to disk
            string imageFileName = GetImageFileName(stlHashCode);

            if (partExtension == ".png")
            {
                ImageIO.SaveImageData(imageFileName, bigRender);
            }
            else
            {
                ImageTgaIO.SaveImageData(imageFileName, bigRender);
            }

            bigRender.SetRecieveBlender(new BlenderPreMultBGRA());

            this.thumbnailImage = ImageBuffer.CreateScaledImage(bigRender, (int)Width, (int)Height);

            UiThread.RunOnIdle(this.EnsureImageUpdated);

            OnDoneRendering();
        }
Beispiel #17
0
        public PrintingWindow(Action onCloseCallback, bool mockMode = false)
            : base(1280, 750)
        {
            this.BackgroundColor = new RGBA_Bytes(35, 40, 49);
            this.onCloseCallback = onCloseCallback;
            this.Title           = "Print Monitor".Localize();

            var topToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                VAnchor = VAnchor.ParentBottomTop,
                HAnchor = HAnchor.ParentLeftRight
            };

            this.AddChild(topToBottom);

            var actionBar = new FlowLayoutWidget(FlowDirection.LeftToRight)
            {
                VAnchor         = VAnchor.ParentTop | VAnchor.FitToChildren,
                HAnchor         = HAnchor.ParentLeftRight,
                BackgroundColor = new RGBA_Bytes(34, 38, 46),
                //DebugShowBounds = true
            };

            topToBottom.AddChild(actionBar);

            var logo = new ImageWidget(StaticData.Instance.LoadIcon(Path.Combine("Screensaver", "logo.png")));

            actionBar.AddChild(logo);

            actionBar.AddChild(new HorizontalSpacer());

            var pauseButton  = CreateButton("Pause".Localize().ToUpper());
            var resumeButton = CreateButton("Resume".Localize().ToUpper());

            pauseButton.Click += (s, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    //PrinterConnectionAndCommunication.Instance.RequestPause();
                    pauseButton.Visible  = false;
                    resumeButton.Visible = true;
                });
            };
            actionBar.AddChild(pauseButton);

            resumeButton.Visible = false;
            resumeButton.Click  += (s, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    //PrinterConnectionAndCommunication.Instance.Resume();
                    resumeButton.Visible = false;
                    pauseButton.Visible  = true;
                });
            };
            actionBar.AddChild(resumeButton);

            actionBar.AddChild(CreateVerticalLine());

            var cancelButton = CreateButton("Cancel".Localize().ToUpper());

            //cancelButton.Click += (sender, e) => UiThread.RunOnIdle(CancelButton_Click);
            actionBar.AddChild(cancelButton);

            actionBar.AddChild(CreateVerticalLine());

            var advancedButton = CreateButton("Advanced".Localize().ToUpper());

            actionBar.AddChild(advancedButton);

            var bodyContainer = new GuiWidget()
            {
                VAnchor         = VAnchor.ParentBottomTop,
                HAnchor         = HAnchor.ParentLeftRight,
                Padding         = new BorderDouble(50),
                BackgroundColor = new RGBA_Bytes(35, 40, 49),
            };

            topToBottom.AddChild(bodyContainer);

            var bodyRow = new FlowLayoutWidget(FlowDirection.LeftToRight)
            {
                VAnchor = VAnchor.ParentBottomTop,
                HAnchor = HAnchor.ParentLeftRight,
                //BackgroundColor = new RGBA_Bytes(125, 255, 46, 20),
            };

            bodyContainer.AddChild(bodyRow);

            // Thumbnail section
            {
                ImageBuffer imageBuffer = null;

                string stlHashCode = PrinterConnectionAndCommunication.Instance.ActivePrintItem?.FileHashCode.ToString();
                if (!string.IsNullOrEmpty(stlHashCode) && stlHashCode != "0")
                {
                    imageBuffer = PartThumbnailWidget.LoadImageFromDisk(stlHashCode);
                    if (imageBuffer != null)
                    {
                        imageBuffer = ImageBuffer.CreateScaledImage(imageBuffer, 500, 500);
                    }
                }

                if (imageBuffer == null)
                {
                    imageBuffer = StaticData.Instance.LoadIcon(Path.Combine("Screensaver", "part_thumbnail.png"));
                }

                var partThumbnail = new ImageWidget(imageBuffer)
                {
                    VAnchor = VAnchor.ParentCenter,
                    Margin  = new BorderDouble(right: 50)
                };
                bodyRow.AddChild(partThumbnail);
            }

            bodyRow.AddChild(CreateVerticalLine());

            // Progress section
            {
                var expandingContainer = new HorizontalSpacer()
                {
                    VAnchor = VAnchor.FitToChildren | VAnchor.ParentCenter
                };
                bodyRow.AddChild(expandingContainer);

                var progressContainer = new FlowLayoutWidget(FlowDirection.TopToBottom)
                {
                    Margin  = new BorderDouble(50, 0),
                    VAnchor = VAnchor.ParentCenter | VAnchor.FitToChildren,
                    HAnchor = HAnchor.ParentCenter | HAnchor.FitToChildren,
                    //BackgroundColor = new RGBA_Bytes(125, 255, 46, 20),
                };
                expandingContainer.AddChild(progressContainer);

                progressDial = new ProgressDial()
                {
                    HAnchor = HAnchor.ParentCenter,
                    Height  = 200,
                    Width   = 200
                };
                progressContainer.AddChild(progressDial);

                var timeContainer = new FlowLayoutWidget()
                {
                    HAnchor = HAnchor.ParentLeftRight,
                    Margin  = new BorderDouble(50, 3)
                };
                progressContainer.AddChild(timeContainer);

                var timeImage = new ImageWidget(StaticData.Instance.LoadIcon(Path.Combine("Screensaver", "time.png")));
                timeContainer.AddChild(timeImage);

                timeWidget = new TextWidget("", pointSize: 16, textColor: ActiveTheme.Instance.PrimaryTextColor)
                {
                    AutoExpandBoundsToText = true,
                    Margin = new BorderDouble(10, 0)
                };

                timeContainer.AddChild(timeWidget);

                printerName = new TextWidget(ActiveSliceSettings.Instance.GetValue(SettingsKey.printer_name), pointSize: 16, textColor: ActiveTheme.Instance.PrimaryTextColor)
                {
                    AutoExpandBoundsToText = true,
                    HAnchor = HAnchor.ParentLeftRight,
                    Margin  = new BorderDouble(50, 3)
                };

                progressContainer.AddChild(printerName);

                partName = new TextWidget(PrinterConnectionAndCommunication.Instance.ActivePrintItem.GetFriendlyName(), pointSize: 16, textColor: ActiveTheme.Instance.PrimaryTextColor)
                {
                    AutoExpandBoundsToText = true,
                    HAnchor = HAnchor.ParentLeftRight,
                    Margin  = new BorderDouble(50, 3)
                };
                progressContainer.AddChild(partName);
            }

            bodyRow.AddChild(CreateVerticalLine());

            // ZControls
            {
                var widget = new ZAxisControls()
                {
                    Margin  = new BorderDouble(left: 50),
                    VAnchor = VAnchor.ParentCenter,
                    Width   = 120
                };
                bodyRow.AddChild(widget);
            }

            var footerBar = new FlowLayoutWidget(FlowDirection.LeftToRight)
            {
                VAnchor         = VAnchor.ParentBottom | VAnchor.FitToChildren,
                HAnchor         = HAnchor.ParentCenter | HAnchor.FitToChildren,
                BackgroundColor = new RGBA_Bytes(35, 40, 49),
                Margin          = new BorderDouble(bottom: 30)
            };

            topToBottom.AddChild(footerBar);

            int extruderCount = mockMode ? 3 : ActiveSliceSettings.Instance.GetValue <int>(SettingsKey.extruder_count);

            var borderColor = bodyContainer.BackgroundColor.AdjustLightness(1.5).GetAsRGBA_Bytes();

            extruderStatusWidgets = Enumerable.Range(0, extruderCount).Select((i) => new ExtruderStatusWidget(i)
            {
                BorderColor = borderColor
            }).ToList();

            if (extruderCount == 1)
            {
                footerBar.AddChild(extruderStatusWidgets[0]);
            }
            else
            {
                var columnA = new FlowLayoutWidget(FlowDirection.TopToBottom);
                footerBar.AddChild(columnA);

                var columnB = new FlowLayoutWidget(FlowDirection.TopToBottom);
                footerBar.AddChild(columnB);

                // Add each status widget into the scene, placing into the appropriate column
                for (var i = 0; i < extruderCount; i++)
                {
                    var widget = extruderStatusWidgets[i];
                    if (i % 2 == 0)
                    {
                        widget.Margin = new BorderDouble(right: 20);
                        columnA.AddChild(widget);
                    }
                    else
                    {
                        columnB.AddChild(widget);
                    }
                }
            }

            UiThread.RunOnIdle(() =>
            {
                if (mockMode)
                {
                    MockProgress();
                }
                else
                {
                    CheckOnPrinter();
                }
            });

            PrinterConnectionAndCommunication.Instance.ExtruderTemperatureRead.RegisterEvent((s, e) =>
            {
                var eventArgs = e as TemperatureEventArgs;
                if (eventArgs != null && eventArgs.Index0Based < extruderStatusWidgets.Count)
                {
                    extruderStatusWidgets[eventArgs.Index0Based].UpdateTemperatures();
                }
            }, ref unregisterEvents);
        }