Example #1
0
        override protected void AddChildElements()
        {            
            activePrintPreviewImage = new PartThumbnailWidget(null, "part_icon_transparent_100x100.png", "building_thumbnail_100x100.png", new Vector2(115, 115));
            activePrintPreviewImage.VAnchor = VAnchor.ParentTop;
            activePrintPreviewImage.Padding = new BorderDouble(0);
            activePrintPreviewImage.HoverBackgroundColor = new RGBA_Bytes();
            activePrintPreviewImage.BorderWidth = 3;

            FlowLayoutWidget temperatureWidgets = new FlowLayoutWidget(FlowDirection.TopToBottom);
            {
                IndicatorWidget extruderTemperatureWidget = new ExtruderTemperatureWidget();
                IndicatorWidget bedTemperatureWidget = new BedTemperatureWidget();

                temperatureWidgets.AddChild(extruderTemperatureWidget);
                temperatureWidgets.AddChild(bedTemperatureWidget);
            }            
            temperatureWidgets.VAnchor |= VAnchor.ParentTop;
            temperatureWidgets.Margin = new BorderDouble(left: 6);

            FlowLayoutWidget printStatusContainer = getActivePrinterInfo();
            printStatusContainer.VAnchor |= VAnchor.ParentTop;

            FlowLayoutWidget iconContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
            iconContainer.Name = "PrintStatusRow.IconContainer";
            iconContainer.VAnchor |= VAnchor.ParentTop;
            iconContainer.Margin = new BorderDouble(top: 3);
            iconContainer.AddChild(GetAutoLevelIndicator());

            this.AddChild(activePrintPreviewImage);
            this.AddChild(printStatusContainer);
            this.AddChild(iconContainer);
            this.AddChild(temperatureWidgets);

            UpdatePrintStatus();
            UpdatePrintItemName();
        }
		private static void CreateImage(PartThumbnailWidget thumbnailWidget, double Width, double Height)
		{
			thumbnailWidget.thumbnailImage = new ImageBuffer((int)Width, (int)Height);
		}
		private static ImageBuffer LoadImageFromDisk(PartThumbnailWidget thumbnailWidget, string stlHashCode)
		{
			try
			{
				ImageBuffer tempImage = new ImageBuffer(BigRenderSize.x, BigRenderSize.y);
				string imageFileName = GetImageFileName(stlHashCode);

				if (File.Exists(imageFileName))
				{
					if (partExtension == ".png")
					{
						if (ImageIO.LoadImageData(imageFileName, tempImage))
						{
							return tempImage;
						}
					}
					else
					{
						if (ImageTgaIO.LoadImageData(imageFileName, tempImage))
						{
							return tempImage;
						}
					}
				}
			}
			catch
			{

			}

			return null;
		}
 private static void CreateImage(PartThumbnailWidget thumbnailWidget, double Width, double Height)
 {
     thumbnailWidget.thumbnailImage = new ImageBuffer((int)Width, (int)Height, 32, new BlenderBGRA());
 }
        public PrintLibraryListItem(PrintItemWrapper printItem)
        {
            this.printItem = printItem;
            linkButtonFactory.fontSize = 10;
            linkButtonFactory.textColor = RGBA_Bytes.White;

            WidgetTextColor = RGBA_Bytes.Black;
            WidgetBackgroundColor = RGBA_Bytes.White;

            TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;

            SetDisplayAttributes();

            FlowLayoutWidget mainContainer = new FlowLayoutWidget(FlowDirection.LeftToRight);
            mainContainer.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
            {
                GuiWidget selectionCheckBoxContainer = new GuiWidget();
                selectionCheckBoxContainer.VAnchor = VAnchor.Max_FitToChildren_ParentHeight;
                selectionCheckBoxContainer.HAnchor = Agg.UI.HAnchor.FitToChildren;
                selectionCheckBoxContainer.Margin = new BorderDouble(left: 6);
                selectionCheckBox = new CheckBox("");
                selectionCheckBox.VAnchor = VAnchor.ParentCenter;
                selectionCheckBox.HAnchor = HAnchor.ParentCenter;
                selectionCheckBoxContainer.AddChild(selectionCheckBox);
                
                FlowLayoutWidget leftColumn = new FlowLayoutWidget(FlowDirection.TopToBottom);
                leftColumn.VAnchor |= VAnchor.ParentTop;


                FlowLayoutWidget middleColumn = new FlowLayoutWidget(FlowDirection.TopToBottom);
                middleColumn.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
                middleColumn.VAnchor = Agg.UI.VAnchor.ParentBottomTop;
                middleColumn.Padding = new BorderDouble(0,6);
                middleColumn.Margin = new BorderDouble(10,0);
                {
                    string labelName = textInfo.ToTitleCase(printItem.Name);
                    labelName = labelName.Replace('_', ' ');
                    partLabel = new TextWidget(labelName, pointSize: 12);
                    partLabel.TextColor = WidgetTextColor;
                    partLabel.MinimumSize = new Vector2(1, 16);
                    middleColumn.AddChild(partLabel);
                }

                FlowLayoutWidget rightColumn = new FlowLayoutWidget(FlowDirection.TopToBottom);
                rightColumn.VAnchor = Agg.UI.VAnchor.ParentBottomTop;                

                buttonContainer = new FlowLayoutWidget();
                buttonContainer.Margin = new BorderDouble(0,6);
                buttonContainer.HAnchor = Agg.UI.HAnchor.ParentLeftRight; 
                {
					addToQueueLink = linkButtonFactory.Generate(new LocalizedString("Add to Queue").Translated);
                    addToQueueLink.Margin = new BorderDouble(left: 0, right: 10);
                    addToQueueLink.VAnchor = VAnchor.ParentCenter;

                    addToQueueLink.Click += (sender, e) =>
                    {
                        PrintQueueItem queueItem = new PrintQueueItem(this.printItem.Name, this.printItem.FileLocation);
                        PrintQueueControl.Instance.AddChild(queueItem);
                    };

					viewLink = linkButtonFactory.Generate(new LocalizedString("View").Translated);
                    viewLink.Margin = new BorderDouble(left: 0, right:10);
                    viewLink.VAnchor = VAnchor.ParentCenter;                    

					exportLink = linkButtonFactory.Generate(new LocalizedString("Export").Translated);
                    exportLink.Margin = new BorderDouble(left: 0, right: 10);
                    exportLink.VAnchor = VAnchor.ParentCenter;

                    exportLink.Click += (sender, e) =>
                    {
						OpenExportWindow();
                    };

					removeLink = linkButtonFactory.Generate(new LocalizedString("Remove").Translated);
                    removeLink.Margin = new BorderDouble(left: 10, right: 10);
                    removeLink.VAnchor = VAnchor.ParentCenter;

                    buttonContainer.AddChild(addToQueueLink);
                    buttonContainer.AddChild(viewLink);
                    buttonContainer.AddChild(exportLink);
                    buttonContainer.AddChild(removeLink);
                }
                middleColumn.AddChild(buttonContainer);
                //rightColumn.AddChild(buttonContainer);

                mainContainer.AddChild(selectionCheckBoxContainer);
                {
                    PartThumbnailWidget thumbnailWidget = new PartThumbnailWidget(printItem, "part_icon_transparent_40x40.png", "building_thumbnail_40x40.png", new Vector2(50, 50));                    
                    mainContainer.AddChild(thumbnailWidget);
                }
                mainContainer.AddChild(leftColumn);
                mainContainer.AddChild(middleColumn);                
                mainContainer.AddChild(rightColumn);
            }
            this.AddChild(mainContainer);
            AddHandlers();
        }
		private static ImageBuffer LoadImageFromDisk(PartThumbnailWidget thumbnailWidget, string stlHashCode, Point2D size)
		{
			ImageBuffer tempImage = new ImageBuffer(size.x, size.y, 32, new BlenderBGRA());
			string imageFileName = GetFilenameForSize(stlHashCode, size);

			if (File.Exists(imageFileName))
			{
				if (partExtension == ".png")
				{
					if (ImageIO.LoadImageData(imageFileName, tempImage))
					{
						return tempImage;
					}
				}
				else
				{
					if (ImageTgaIO.LoadImageData(imageFileName, tempImage))
					{
						return tempImage;
					}
				}
			}

			return null;
		}
		private void CreateThumbnail(PartThumbnailWidget thumbnailWidget)
		{
			if (thumbnailWidget != null)
			{
				string stlHashCode = thumbnailWidget.PrintItem.FileHashCode.ToString();

				ImageBuffer bigRender = new ImageBuffer();
				if (!File.Exists(thumbnailWidget.PrintItem.FileLocation))
				{
					return;
				}

				List<MeshGroup> loadedMeshGroups = MeshFileIo.Load(thumbnailWidget.PrintItem.FileLocation);

				RenderType renderType = GetRenderType(thumbnailWidget.PrintItem.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);
							thumbnailWidget.thumbnailImage = new ImageBuffer(thumbnailWidget.buildingThumbnailImage);
							thumbnailWidget.thumbnailImage.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0));

							bigRender = new ImageBuffer(bigRenderSize.x, bigRenderSize.y, 32, new BlenderBGRA());

							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(thumbnailWidget.noThumbnailImage);
							}
						}
						break;

					case RenderType.NONE:
					case RenderType.ORTHOGROPHIC:

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

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

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

				ImageBuffer unScaledImage = new ImageBuffer(bigRender.Width, bigRender.Height, 32, new BlenderBGRA());
				unScaledImage.NewGraphics2D().Render(bigRender, 0, 0);
				// If the source image (the one we downloaded) is more than twice as big as our dest image.
				while (unScaledImage.Width > Width * 2)
				{
					// The image sampler we use is a 2x2 filter so we need to scale by a max of 1/2 if we want to get good results.
					// So we scale as many times as we need to to get the Image to be the right size.
					// If this were going to be a non-uniform scale we could do the x and y separatly to get better results.
					ImageBuffer halfImage = new ImageBuffer(unScaledImage.Width / 2, unScaledImage.Height / 2, 32, new BlenderBGRA());
					halfImage.NewGraphics2D().Render(unScaledImage, 0, 0, 0, halfImage.Width / (double)unScaledImage.Width, halfImage.Height / (double)unScaledImage.Height);
					unScaledImage = halfImage;
				}

				thumbnailWidget.thumbnailImage = new ImageBuffer((int)Width, (int)Height, 32, new BlenderBGRA());
				thumbnailWidget.thumbnailImage.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0));
				thumbnailWidget.thumbnailImage.NewGraphics2D().Render(unScaledImage, 0, 0, 0, (double)thumbnailWidget.thumbnailImage.Width / unScaledImage.Width, (double)thumbnailWidget.thumbnailImage.Height / unScaledImage.Height);

				UiThread.RunOnIdle(thumbnailWidget.EnsureImageUpdated);
			}
		}
        private static ImageBuffer LoadImageFromDisk(PartThumbnailWidget thumbnailWidget, string stlHashCode, Point2D size)
        {
            ImageBuffer tempImage = new ImageBuffer(size.x, size.y, 32, new BlenderBGRA());
            string applicationUserDataPath = ApplicationDataStorage.Instance.ApplicationUserDataPath;
            string folderToSavePrintsTo = Path.Combine(applicationUserDataPath, "data", "temp", "thumbnails");
            string tgaFileName = Path.Combine(folderToSavePrintsTo, "{0}_{1}x{2}.tga".FormatWith(stlHashCode, size.x, size.y));

            if (File.Exists(tgaFileName))
            {
                if (ImageTgaIO.LoadImageData(tgaFileName, tempImage))
                {
                    return tempImage;
                }
            }

            return null;
        }
Example #9
0
        void createThumbnailWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            PartThumbnailWidget thumbnailWidget = e.Argument as PartThumbnailWidget;

            if (thumbnailWidget != null)
            {
                if (thumbnailWidget.printItem == null)
                {
                    thumbnailWidget.tumbnailImage = new ImageBuffer(thumbnailWidget.noThumbnailImage);
                    thumbnailWidget.Invalidate();
                    return;
                }

                string stlHashCode = thumbnailWidget.PrintItem.StlFileHashCode.ToString();

                Point2D     bigRenderSize = new Point2D(460, 460);
                ImageBuffer bigRender     = LoadImageFromDisk(thumbnailWidget, stlHashCode, bigRenderSize);
                if (bigRender == null)
                {
                    Mesh loadedMesh = StlProcessing.Load(thumbnailWidget.PrintItem.FileLocation);

                    thumbnailWidget.tumbnailImage = new ImageBuffer(thumbnailWidget.buildingThumbnailImage);
                    thumbnailWidget.tumbnailImage.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0));
                    bigRender = BuildImageFromSTL(loadedMesh, stlHashCode, bigRenderSize);
                    if (bigRender == null)
                    {
                        bigRender = new ImageBuffer(thumbnailWidget.noThumbnailImage);
                    }
                }

                switch (thumbnailWidget.Size)
                {
                case ImageSizes.Size50x50:
                {
                    ImageBuffer halfWay1 = new ImageBuffer(200, 200, 32, new BlenderBGRA());
                    halfWay1.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0));
                    halfWay1.NewGraphics2D().Render(bigRender, 0, 0, 0, (double)halfWay1.Width / bigRender.Width, (double)halfWay1.Height / bigRender.Height);

                    ImageBuffer halfWay2 = new ImageBuffer(100, 100, 32, new BlenderBGRA());
                    halfWay2.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0));
                    halfWay2.NewGraphics2D().Render(halfWay1, 0, 0, 0, (double)halfWay2.Width / halfWay1.Width, (double)halfWay2.Height / halfWay1.Height);

                    thumbnailWidget.tumbnailImage = new ImageBuffer(50, 50, 32, new BlenderBGRA());
                    thumbnailWidget.tumbnailImage.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0));
                    thumbnailWidget.tumbnailImage.NewGraphics2D().Render(halfWay2, 0, 0, 0, (double)thumbnailWidget.tumbnailImage.Width / halfWay2.Width, (double)thumbnailWidget.tumbnailImage.Height / halfWay2.Height);
                }
                break;

                case ImageSizes.Size115x115:
                {
                    ImageBuffer halfWay1 = new ImageBuffer(230, 230, 32, new BlenderBGRA());
                    halfWay1.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0));
                    halfWay1.NewGraphics2D().Render(bigRender, 0, 0, 0, (double)halfWay1.Width / bigRender.Width, (double)halfWay1.Height / bigRender.Height);

                    thumbnailWidget.tumbnailImage = new ImageBuffer(115, 115, 32, new BlenderBGRA());
                    thumbnailWidget.tumbnailImage.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0));
                    thumbnailWidget.tumbnailImage.NewGraphics2D().Render(halfWay1, 0, 0, 0, (double)thumbnailWidget.tumbnailImage.Width / halfWay1.Width, (double)thumbnailWidget.tumbnailImage.Height / halfWay1.Height);
                }
                break;

                default:
                    throw new NotImplementedException();
                }

                UiThread.RunOnIdle(thumbnailWidget.EnsureImageUpdated);
            }
        }
Example #10
0
        static void CreateThumbnailsThread()
        {
            while (true)
            {
                if (listOfWidgetsNeedingThumbnails.Count > 0)
                {
                    PartThumbnailWidget thumbnailWidget = listOfWidgetsNeedingThumbnails[0];
                    if (thumbnailWidget.printItem == null)
                    {
                        thumbnailWidget.image = new ImageBuffer(thumbnailWidget.noThumbnailImage);
                    }
                    else // generate the image
                    {
                        Mesh loadedMesh = StlProcessing.Load(thumbnailWidget.printItem.FileLocation);

                        thumbnailWidget.image = new ImageBuffer(thumbnailWidget.buildingThumbnailImage);
                        thumbnailWidget.Invalidate();

                        if (loadedMesh != null)
                        {
                            ImageBuffer tempImage      = new ImageBuffer(thumbnailWidget.image.Width, thumbnailWidget.image.Height, 32, new BlenderBGRA());
                            Graphics2D  partGraphics2D = tempImage.NewGraphics2D();

                            List <MeshEdge> nonManifoldEdges = loadedMesh.GetNonManifoldEdges();
                            if (nonManifoldEdges.Count > 0)
                            {
                                if (File.Exists("RunUnitTests.txt"))
                                {
                                    partGraphics2D.Circle(4, 4, 4, RGBA_Bytes.Red);
                                }
                            }

                            AxisAlignedBoundingBox aabb = loadedMesh.GetAxisAlignedBoundingBox();
                            double          maxSize     = Math.Max(aabb.XSize, aabb.YSize);
                            double          scale       = thumbnailWidget.image.Width / (maxSize * 1.2);
                            RectangleDouble bounds2D    = new RectangleDouble(aabb.minXYZ.x, aabb.minXYZ.y, aabb.maxXYZ.x, aabb.maxXYZ.y);
                            PolygonMesh.Rendering.OrthographicZProjection.DrawTo(partGraphics2D, loadedMesh,
                                                                                 new Vector2((thumbnailWidget.image.Width / scale - bounds2D.Width) / 2 - bounds2D.Left,
                                                                                             (thumbnailWidget.image.Height / scale - bounds2D.Height) / 2 - bounds2D.Bottom),
                                                                                 scale,
                                                                                 thumbnailWidget.FillColor);

                            thumbnailWidget.image = new ImageBuffer(tempImage);
                        }
                        else
                        {
                            thumbnailWidget.image = new ImageBuffer(thumbnailWidget.noThumbnailImage);
                        }
                    }
                    thumbnailWidget.Invalidate();

                    using (TimedLock.Lock(listOfWidgetsNeedingThumbnails, "CreateThumbnailsThread()"))
                    {
                        listOfWidgetsNeedingThumbnails.RemoveAt(0);

                        foreach (PartThumbnailWidget part in listOfWidgetsNeedingThumbnails)
                        {
                            // mark them so we try to add them again if needed
                            part.thumbNailHasBeenRequested = false;
                        }

                        listOfWidgetsNeedingThumbnails.Clear();
                    }
                }
                Thread.Sleep(100);
            }
        }