Exemplo n.º 1
0
        public void LoadMesh(string meshPathAndFileName, CenterPartAfterLoad centerPart, Vector2 bedCenter = new Vector2())
        {
            if (File.Exists(meshPathAndFileName))
            {
                partProcessingInfo.Visible = true;
                partProcessingInfo.progressControl.PercentComplete = 0;

                backgroundWorker = new BackgroundWorker();
                backgroundWorker.WorkerSupportsCancellation = true;

                backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker_RunWorkerCompleted);

                backgroundWorker.DoWork += (object sender, DoWorkEventArgs e) =>
                {
                    List <MeshGroup> loadedMeshGroups = MeshFileIo.Load(meshPathAndFileName, reportProgress0to100);
                    SetMeshAfterLoad(loadedMeshGroups, centerPart, bedCenter);
                    e.Result = loadedMeshGroups;
                };
                backgroundWorker.RunWorkerAsync();
                partProcessingInfo.centeredInfoText.Text = "Loading Mesh...";
            }
            else
            {
                partProcessingInfo.centeredInfoText.Text = string.Format("{0}\n'{1}'", "File not found on disk.", Path.GetFileName(meshPathAndFileName));
            }
        }
Exemplo n.º 2
0
        public UpArrow3D(View3DWidget view3DWidget)
            : base(null, view3DWidget.meshViewerWidget)
        {
            heightDisplay         = new HeightValueDisplay(view3DWidget);
            heightDisplay.Visible = false;

            DrawOnTop = true;

            this.view3DWidget = view3DWidget;
            string arrowFile = Path.Combine("Icons", "3D Icons", "up_pointer.stl");

            if (StaticData.Instance.FileExists(arrowFile))
            {
                using (Stream staticDataStream = StaticData.Instance.OpenSteam(arrowFile))
                {
                    using (MemoryStream arrowStream = new MemoryStream())
                    {
                        staticDataStream.CopyTo(arrowStream, 1 << 16);
                        List <MeshGroup> loadedMeshGroups = MeshFileIo.Load(arrowStream, Path.GetExtension(arrowFile));
                        upArrow = loadedMeshGroups[0].Meshes[0];

                        CollisionVolume = PlatingHelper.CreateTraceDataForMesh(upArrow);
                        //CollisionVolume = new CylinderShape(arrowBounds.XSize / 2, arrowBounds.ZSize, new SolidMaterial(RGBA_Floats.Red, .5, 0, .4));
                        //CollisionVolume = new CylinderShape(arrowBounds.XSize / 2 * 4, arrowBounds.ZSize * 4, new SolidMaterial(RGBA_Floats.Red, .5, 0, .4));
                    }
                }
            }
        }
        private void stlSaveWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            SaveFileDialogParams saveParams = e.Argument as SaveFileDialogParams;

            if (saveParams.FileName != null)
            {
                string filePathToSave = saveParams.FileName;
                if (filePathToSave != null && filePathToSave != "")
                {
                    string extension = Path.GetExtension(filePathToSave);
                    if (extension == "")
                    {
                        File.Delete(filePathToSave);
                        filePathToSave += ".stl";
                    }
                    if (Path.GetExtension(printItemWrapper.FileLocation).ToUpper() == Path.GetExtension(filePathToSave).ToUpper())
                    {
                        File.Copy(printItemWrapper.FileLocation, filePathToSave, true);
                    }
                    else
                    {
                        List <MeshGroup> meshGroups = MeshFileIo.Load(printItemWrapper.FileLocation);
                        MeshFileIo.Save(meshGroups, filePathToSave);
                    }
                    ShowFileIfRequested(filePathToSave);
                }
            }
        }
Exemplo n.º 4
0
 private void SaveStl(SaveFileDialogParams saveParams)
 {
     try
     {
         if (!string.IsNullOrEmpty(saveParams.FileName))
         {
             string filePathToSave = saveParams.FileName;
             if (filePathToSave != null && filePathToSave != "")
             {
                 string extension = Path.GetExtension(filePathToSave);
                 if (extension == "")
                 {
                     File.Delete(filePathToSave);
                     filePathToSave += ".stl";
                 }
                 if (Path.GetExtension(printItemWrapper.FileLocation).ToUpper() == Path.GetExtension(filePathToSave).ToUpper())
                 {
                     File.Copy(printItemWrapper.FileLocation, filePathToSave, true);
                 }
                 else
                 {
                     List <MeshGroup> meshGroups = MeshFileIo.Load(printItemWrapper.FileLocation);
                     MeshFileIo.Save(meshGroups, filePathToSave);
                 }
                 ShowFileIfRequested(filePathToSave);
             }
         }
     }
     catch
     {
     }
 }
 void onExportAmfFileSelected(SaveFileDialogParams saveParams)
 {
     Close();
     if (saveParams.FileName != null)
     {
         string filePathToSave = saveParams.FileName;
         if (filePathToSave != null && filePathToSave != "")
         {
             string extension = Path.GetExtension(filePathToSave);
             if (extension == "")
             {
                 File.Delete(filePathToSave);
                 filePathToSave += ".amf";
             }
             if (Path.GetExtension(printItemWrapper.FileLocation).ToUpper() == Path.GetExtension(filePathToSave).ToUpper())
             {
                 File.Copy(printItemWrapper.FileLocation, filePathToSave, true);
             }
             else
             {
                 List <MeshGroup> meshGroups = MeshFileIo.Load(printItemWrapper.FileLocation);
                 MeshFileIo.Save(meshGroups, filePathToSave);
             }
             ShowFileIfRequested(filePathToSave);
         }
     }
 }
Exemplo n.º 6
0
        public static string[] GetStlFileLocations(string fileToSlice)
        {
            int extruderCount = ActiveSliceSettings.Instance.ExtruderCount;

            switch (Path.GetExtension(fileToSlice).ToUpper())
            {
            case ".STL":
            case ".GCODE":
                return(new string[] { fileToSlice });

            case ".AMF":
                List <MeshGroup> meshGroups         = MeshFileIo.Load(fileToSlice);
                List <MeshGroup> extruderMeshGroups = new List <MeshGroup>();
                for (int extruderIndex = 0; extruderIndex < extruderCount; extruderIndex++)
                {
                    extruderMeshGroups.Add(new MeshGroup());
                }
                int maxExtruderIndex = 0;
                foreach (MeshGroup meshGroup in meshGroups)
                {
                    foreach (Mesh mesh in meshGroup.Meshes)
                    {
                        MeshMaterialData material = MeshMaterialData.Get(mesh);
                        int extruderIndex         = Math.Max(0, material.MaterialIndex - 1);
                        maxExtruderIndex = Math.Max(maxExtruderIndex, extruderIndex);
                        if (extruderIndex >= extruderCount)
                        {
                            extruderMeshGroups[0].Meshes.Add(mesh);
                        }
                        else
                        {
                            extruderMeshGroups[extruderIndex].Meshes.Add(mesh);
                        }
                    }
                }

                List <string> extruderFilesToSlice = new List <string>();
                for (int i = 0; i < extruderMeshGroups.Count; i++)
                {
                    MeshGroup  meshGroup          = extruderMeshGroups[i];
                    List <int> materialsToInclude = new List <int>();
                    materialsToInclude.Add(i + 1);
                    if (i == 0)
                    {
                        for (int j = extruderCount + 1; j < maxExtruderIndex + 2; j++)
                        {
                            materialsToInclude.Add(j);
                        }
                    }

                    extruderFilesToSlice.Add(SaveAndGetFilenameForMaterial(meshGroup, materialsToInclude));
                }
                return(extruderFilesToSlice.ToArray());

            default:
                throw new NotImplementedException();
            }
        }
Exemplo n.º 7
0
        private static void AddStlOrGcode(LibraryProviderSQLite libraryToAddTo, string loadedFileName, string extension)
        {
            PrintItem printItem = new PrintItem();

            printItem.Name                  = Path.GetFileNameWithoutExtension(loadedFileName);
            printItem.FileLocation          = Path.GetFullPath(loadedFileName);
            printItem.PrintItemCollectionID = libraryToAddTo.baseLibraryCollection.Id;
            printItem.Commit();

            if (MeshFileIo.ValidFileExtensions().Contains(extension))
            {
                List <MeshGroup> meshToConvertAndSave = MeshFileIo.Load(loadedFileName);

                try
                {
                    PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem);
                    SaveToLibraryFolder(printItemWrapper, meshToConvertAndSave, false);
                    libraryToAddTo.AddItem(printItemWrapper);
                }
                catch (System.UnauthorizedAccessException)
                {
                    UiThread.RunOnIdle(() =>
                    {
                        //Do something special when unauthorized?
                        StyledMessageBox.ShowMessageBox(null, "Oops! Unable to save changes, unauthorized access", "Unable to save");
                    });
                }
                catch
                {
                    UiThread.RunOnIdle(() =>
                    {
                        StyledMessageBox.ShowMessageBox(null, "Oops! Unable to save changes.", "Unable to save");
                    });
                }
            }
            else             // it is not a mesh so just add it
            {
                PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem);
                if (false)
                {
                    libraryToAddTo.AddItem(printItemWrapper);
                }
                else                 // save a copy to the library and update this to point at it
                {
                    string sourceFileName = printItem.FileLocation;
                    string newFileName    = Path.ChangeExtension(Path.GetRandomFileName(), Path.GetExtension(printItem.FileLocation));
                    string destFileName   = Path.Combine(ApplicationDataStorage.Instance.ApplicationLibraryDataPath, newFileName);

                    File.Copy(sourceFileName, destFileName, true);

                    printItemWrapper.FileLocation = destFileName;
                    printItemWrapper.PrintItem.Commit();

                    // let the queue know that the item has changed so it load the correct part
                    libraryToAddTo.AddItem(printItemWrapper);
                }
            }
        }
Exemplo n.º 8
0
        protected virtual void AddStlOrGcode(string loadedFileName, string displayName)
        {
            string extension = Path.GetExtension(loadedFileName).ToUpper();

            PrintItem printItem = new PrintItem();

            printItem.Name                  = displayName;
            printItem.FileLocation          = Path.GetFullPath(loadedFileName);
            printItem.PrintItemCollectionID = this.baseLibraryCollection.Id;
            printItem.Commit();

            if ((extension != "" && MeshFileIo.ValidFileExtensions().Contains(extension)))
            {
                List <MeshGroup> meshToConvertAndSave = MeshFileIo.Load(loadedFileName);

                try
                {
                    PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem, this);
                    SaveToLibraryFolder(printItemWrapper, meshToConvertAndSave, false);
                }
                catch (System.UnauthorizedAccessException)
                {
                    UiThread.RunOnIdle(() =>
                    {
                        //Do something special when unauthorized?
                        StyledMessageBox.ShowMessageBox(null, "Oops! Unable to save changes, unauthorized access", "Unable to save");
                    });
                }
                catch
                {
                    UiThread.RunOnIdle(() =>
                    {
                        StyledMessageBox.ShowMessageBox(null, "Oops! Unable to save changes.", "Unable to save");
                    });
                }
            }
            else             // it is not a mesh so just add it
            {
                PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem, this);
                string           sourceFileName   = printItem.FileLocation;
                string           newFileName      = Path.ChangeExtension(Path.GetRandomFileName(), Path.GetExtension(printItem.FileLocation));
                string           destFileName     = Path.Combine(ApplicationDataStorage.Instance.ApplicationLibraryDataPath, newFileName);

                File.Copy(sourceFileName, destFileName, true);

                printItemWrapper.FileLocation = destFileName;
                printItemWrapper.PrintItem.Commit();
            }
        }
Exemplo n.º 9
0
        public LogoSpinner(GuiWidget widget, double scale = 1.6, double spinSpeed = 0.6, double yOffset = 0.5, double rotateX = -0.1)
        {
            // loading animation stuff
            LightingData lighting = new LightingData();

            Mesh logoMesh;

            using (var logoStream = AggContext.StaticData.OpenStream(Path.Combine("Stls", "MH Logo.stl")))
            {
                logoMesh = MeshFileIo.Load(logoStream, ".stl", CancellationToken.None).Mesh;
            }

            // Position
            var aabb = logoMesh.GetAxisAlignedBoundingBox();

            logoMesh.Transform(Matrix4X4.CreateTranslation(-aabb.Center));

            logoMesh.Transform(Matrix4X4.CreateScale(scale / aabb.XSize));

            var anglePerDraw = 1 / MathHelper.Tau * spinSpeed;
            var angle        = 0.0;

            widget.BeforeDraw += (s, e) =>
            {
                var       screenSpaceBounds = widget.TransformToScreenSpace(widget.LocalBounds);
                WorldView world             = new WorldView(screenSpaceBounds.Width, screenSpaceBounds.Height);
                world.Translate(new Vector3(0, yOffset, 0));
                world.Rotate(Quaternion.FromEulerAngles(new Vector3(rotateX, 0, 0)));

                GLHelper.SetGlContext(world, screenSpaceBounds, lighting);
                GLHelper.Render(logoMesh, this.MeshColor, Matrix4X4.CreateRotationY(angle), RenderTypes.Shaded);
                GLHelper.UnsetGlContext();
            };

            Animation spinAnimation = new Animation()
            {
                DrawTarget      = widget,
                FramesPerSecond = 20
            };

            spinAnimation.Update += (s, time) =>
            {
                if (this.SpinLogo)
                {
                    angle += anglePerDraw;
                }
            };
            spinAnimation.Start();
        }
Exemplo n.º 10
0
        private static void AddStlOrGcode(string loadedFileName, string extension)
        {
            PrintItem printItem = new PrintItem();

            printItem.Name                  = Path.GetFileNameWithoutExtension(loadedFileName);
            printItem.FileLocation          = Path.GetFullPath(loadedFileName);
            printItem.PrintItemCollectionID = LibraryData.Instance.LibraryCollection.Id;
            printItem.Commit();

            if (MeshFileIo.ValidFileExtensions().Contains(extension))
            {
                List <MeshGroup> meshToConvertAndSave = MeshFileIo.Load(loadedFileName);

                try
                {
                    PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem);
                    LibraryData.SaveToLibraryFolder(printItemWrapper, meshToConvertAndSave, false);
                    LibraryData.Instance.AddItem(printItemWrapper);
                }
                catch (System.UnauthorizedAccessException)
                {
                    UiThread.RunOnIdle((state) =>
                    {
                        //Do something special when unauthorized?
                        StyledMessageBox.ShowMessageBox(null, "Oops! Unable to save changes, unauthorized access", "Unable to save");
                    });
                }
                catch
                {
                    UiThread.RunOnIdle((state) =>
                    {
                        StyledMessageBox.ShowMessageBox(null, "Oops! Unable to save changes.", "Unable to save");
                    });
                }
            }
            else             // it is not a mesh so just add it
            {
                PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem);
                LibraryData.Instance.AddItem(printItemWrapper);
            }
        }
Exemplo n.º 11
0
 private void SaveStl(SaveFileDialogParams saveParams)
 {
     try
     {
         if (!string.IsNullOrEmpty(saveParams.FileName))
         {
             string filePathToSave = saveParams.FileName;
             if (filePathToSave != null && filePathToSave != "")
             {
                 string extension = Path.GetExtension(filePathToSave);
                 if (extension == "")
                 {
                     File.Delete(filePathToSave);
                     filePathToSave += ".stl";
                 }
                 if (Path.GetExtension(printItemWrapper.FileLocation).ToUpper() == Path.GetExtension(filePathToSave).ToUpper())
                 {
                     File.Copy(printItemWrapper.FileLocation, filePathToSave, true);
                 }
                 else
                 {
                     List <MeshGroup> meshGroups = MeshFileIo.Load(printItemWrapper.FileLocation);
                     if (!MeshFileIo.Save(meshGroups, filePathToSave))
                     {
                         UiThread.RunOnIdle(() => {
                             StyledMessageBox.ShowMessageBox(null, "AMF to STL conversion failed", "Couldn't save file".Localize());
                         });
                     }
                 }
                 ShowFileIfRequested(filePathToSave);
             }
         }
     }
     catch (Exception e)
     {
         UiThread.RunOnIdle(() => {
             StyledMessageBox.ShowMessageBox(null, e.Message, "Couldn't save file".Localize());
         });
     }
 }
Exemplo n.º 12
0
        void mergeAndSavePartsBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            string[] fileList = e.Argument as string[];
            foreach (string loadedFileName in fileList)
            {
                PrintItem printItem = new PrintItem();
                printItem.Name                  = Path.GetFileNameWithoutExtension(loadedFileName);
                printItem.FileLocation          = Path.GetFullPath(loadedFileName);
                printItem.PrintItemCollectionID = LibraryData.Instance.LibraryCollection.Id;
                printItem.Commit();

                List <MeshGroup> meshToConvertAndSave = MeshFileIo.Load(loadedFileName);

                try
                {
                    PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem);
                    LibraryData.SaveToLibraryFolder(printItemWrapper, meshToConvertAndSave);
                    LibraryData.Instance.AddItem(printItemWrapper);
                }
                catch (System.UnauthorizedAccessException)
                {
                    UiThread.RunOnIdle((state) =>
                    {
                        //Do something special when unauthorized?
                        StyledMessageBox.ShowMessageBox(null, "Oops! Unable to save changes, unauthorized access", "Unable to save");
                    });
                }
                catch
                {
                    UiThread.RunOnIdle((state) =>
                    {
                        StyledMessageBox.ShowMessageBox(null, "Oops! Unable to save changes.", "Unable to save");
                    });
                }
            }
        }
Exemplo n.º 13
0
        public void SavingFunction()
        {
            currentlySaving        = true;
            countThatHaveBeenSaved = 0;
            // first create images for all the parts
            foreach (FileNameAndPresentationName queuePartFileName in queuPartFilesToAdd)
            {
                List <MeshGroup> loadedMeshGroups = null;
                if (File.Exists(queuePartFileName.fileName))
                {
                    loadedMeshGroups = MeshFileIo.Load(queuePartFileName.fileName);
                }

                if (loadedMeshGroups != null)
                {
                    bool firstMeshGroup         = true;
                    AxisAlignedBoundingBox aabb = null;
                    foreach (MeshGroup meshGroup in loadedMeshGroups)
                    {
                        if (firstMeshGroup)
                        {
                            aabb           = meshGroup.GetAxisAlignedBoundingBox();
                            firstMeshGroup = false;
                        }
                        else
                        {
                            aabb = AxisAlignedBoundingBox.Union(aabb, meshGroup.GetAxisAlignedBoundingBox());
                        }
                    }
                    RectangleDouble bounds2D    = new RectangleDouble(aabb.minXYZ.x, aabb.minXYZ.y, aabb.maxXYZ.x, aabb.maxXYZ.y);
                    double          widthInMM   = bounds2D.Width + PartMarginMM * 2;
                    double          textSpaceMM = 5;
                    double          heightMM    = textSpaceMM + bounds2D.Height + PartMarginMM * 2;

                    TypeFacePrinter typeFacePrinter = new TypeFacePrinter(queuePartFileName.presentationName, 28, Vector2.Zero, Justification.Center, Baseline.BoundsCenter);
                    double          sizeOfNameX     = typeFacePrinter.GetSize().x + PartMarginPixels * 2;
                    Vector2         sizeOfRender    = new Vector2(widthInMM * PixelPerMM, heightMM * PixelPerMM);

                    ImageBuffer imageOfPart = new ImageBuffer((int)(Math.Max(sizeOfNameX, sizeOfRender.x)), (int)(sizeOfRender.y), 32, new BlenderBGRA());
                    typeFacePrinter.Origin = new Vector2(imageOfPart.Width / 2, (textSpaceMM / 2) * PixelPerMM);

                    Graphics2D partGraphics2D = imageOfPart.NewGraphics2D();

                    RectangleDouble rectBounds  = new RectangleDouble(0, 0, imageOfPart.Width, imageOfPart.Height);
                    double          strokeWidth = .5 * PixelPerMM;
                    rectBounds.Inflate(-strokeWidth / 2);
                    RoundedRect rect = new RoundedRect(rectBounds, PartMarginMM * PixelPerMM);
                    partGraphics2D.Render(rect, RGBA_Bytes.LightGray);
                    Stroke rectOutline = new Stroke(rect, strokeWidth);
                    partGraphics2D.Render(rectOutline, RGBA_Bytes.DarkGray);

                    foreach (MeshGroup meshGroup in loadedMeshGroups)
                    {
                        foreach (Mesh loadedMesh in meshGroup.Meshes)
                        {
                            PolygonMesh.Rendering.OrthographicZProjection.DrawTo(partGraphics2D, loadedMesh, new Vector2(-bounds2D.Left + PartMarginMM, -bounds2D.Bottom + textSpaceMM + PartMarginMM), PixelPerMM, RGBA_Bytes.Black);
                        }
                    }
                    partGraphics2D.Render(typeFacePrinter, RGBA_Bytes.Black);

                    partImagesToPrint.Add(new PartImage(imageOfPart));

                    countThatHaveBeenSaved++;
                }

                if (UpdateRemainingItems != null)
                {
                    UpdateRemainingItems(this, new StringEventArgs(Path.GetFileName(queuePartFileName.presentationName)));
                }
            }

            partImagesToPrint.Sort(BiggestToLittlestImages);

            PdfDocument document = new PdfDocument();

            document.Info.Title    = "MatterHackers Parts Sheet";
            document.Info.Author   = "MatterHackers Inc.";
            document.Info.Subject  = "This is a list of the parts that are in a queue from MatterControl.";
            document.Info.Keywords = "MatterControl, STL, 3D Printing";

            int  nextPartToPrintIndex = 0;
            int  plateNumber          = 1;
            bool done = false;

            while (!done && nextPartToPrintIndex < partImagesToPrint.Count)
            {
                PdfPage pdfPage = document.AddPage();
                CreateOnePage(plateNumber++, ref nextPartToPrintIndex, pdfPage);
            }
            try
            {
                // save the final document
                document.Save(pathAndFileToSaveTo);
                // Now try and open the document. This will lanch whatever PDF viewer is on the system and ask it
                // to show the file (at least on Windows).
                Process.Start(pathAndFileToSaveTo);
            }
            catch (Exception)
            {
            }

            OnDoneSaving();
            currentlySaving = false;
        }
        /// <summary>
        /// Creates a database PrintItem entity, if forceAMF is set, converts to AMF otherwise just copies
        /// the source file to a new library path and updates the PrintItem to point at the new target
        /// </summary>
        private void AddItem(Stream stream, string extension, string displayName, bool forceAMF = true)
        {
            // Create a new entity in the database
            PrintItem printItem = new PrintItem();

            printItem.Name = displayName;
            printItem.PrintItemCollectionID = this.baseLibraryCollection.Id;
            printItem.Commit();

            // Special load processing for mesh data, simple copy below for non-mesh
            if (forceAMF &&
                (extension != "" && MeshFileIo.ValidFileExtensions().Contains(extension.ToUpper())))
            {
                try
                {
                    // Load mesh
                    List <MeshGroup> meshToConvertAndSave = MeshFileIo.Load(stream, extension);

                    // Create a new PrintItemWrapper

                    if (!printItem.FileLocation.Contains(ApplicationDataStorage.Instance.ApplicationLibraryDataPath))
                    {
                        string[] metaData = { "Created By", "MatterControl" };
                        if (false)                         //AbsolutePositioned
                        {
                            metaData = new string[] { "Created By", "MatterControl", "BedPosition", "Absolute" };
                        }

                        // save a copy to the library and update this to point at it
                        printItem.FileLocation = CreateLibraryPath(".amf");
                        var outputInfo = new MeshOutputSettings(MeshOutputSettings.OutputType.Binary, metaData);
                        MeshFileIo.Save(meshToConvertAndSave, printItem.FileLocation, outputInfo);
                        printItem.Commit();
                    }
                }
                catch (System.UnauthorizedAccessException)
                {
                    UiThread.RunOnIdle(() =>
                    {
                        //Do something special when unauthorized?
                        StyledMessageBox.ShowMessageBox(null, "Oops! Unable to save changes, unauthorized access", "Unable to save");
                    });
                }
                catch
                {
                    UiThread.RunOnIdle(() =>
                    {
                        StyledMessageBox.ShowMessageBox(null, "Oops! Unable to save changes.", "Unable to save");
                    });
                }
            }
            else             // it is not a mesh so just add it
            {
                // Non-mesh content - copy stream to new Library path
                printItem.FileLocation = CreateLibraryPath(extension);
                using (var outStream = File.Create(printItem.FileLocation))
                {
                    stream.CopyTo(outStream);
                }
                printItem.Commit();
            }
        }
Exemplo n.º 15
0
        void createThumbnailWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            PartThumbnailWidget thumbnailWidget = e.Argument as PartThumbnailWidget;

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

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

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

                    default:
                        throw new NotImplementedException();
                    }
                    thumbnailWidget.thumbnailImage.SetRecieveBlender(new BlenderPreMultBGRA());
                    Graphics2D graphics = thumbnailWidget.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(thumbnailWidget.EnsureImageUpdated);
                    return;
                }
                else if (Path.GetExtension(thumbnailWidget.PrintItem.FileLocation).ToUpper() == ".GCODE")
                {
                    CreateImage(thumbnailWidget, Width, Height);
                    thumbnailWidget.thumbnailImage.SetRecieveBlender(new BlenderPreMultBGRA());
                    Graphics2D graphics = thumbnailWidget.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(thumbnailWidget.EnsureImageUpdated);
                    return;
                }
                else if (!File.Exists(thumbnailWidget.PrintItem.FileLocation))
                {
                    CreateImage(thumbnailWidget, Width, Height);
                    thumbnailWidget.thumbnailImage.SetRecieveBlender(new BlenderPreMultBGRA());
                    Graphics2D graphics = thumbnailWidget.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(thumbnailWidget.EnsureImageUpdated);
                    return;
                }

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

                Point2D     bigRenderSize = new Point2D(460, 460);
                ImageBuffer bigRender     = LoadImageFromDisk(thumbnailWidget, stlHashCode, bigRenderSize);
                if (bigRender == null)
                {
                    if (!File.Exists(thumbnailWidget.PrintItem.FileLocation))
                    {
                        return;
                    }
                    List <MeshGroup> loadedMeshGroups = MeshFileIo.Load(thumbnailWidget.PrintItem.FileLocation);

                    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);
                    }
                }

                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.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(halfWay2, 0, 0, 0, (double)thumbnailWidget.thumbnailImage.Width / halfWay2.Width, (double)thumbnailWidget.thumbnailImage.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.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(halfWay1, 0, 0, 0, (double)thumbnailWidget.thumbnailImage.Width / halfWay1.Width, (double)thumbnailWidget.thumbnailImage.Height / halfWay1.Height);
                }
                break;

                default:
                    throw new NotImplementedException();
                }

                UiThread.RunOnIdle(thumbnailWidget.EnsureImageUpdated);
            }
        }
Exemplo n.º 16
0
        public static string[] GetStlFileLocations(string fileToSlice, bool doMergeInSlicer, ref string mergeRules)
        {
            extrudersUsed.Clear();

            int extruderCount = ActiveSliceSettings.Instance.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 (ActiveSliceSettings.Instance.GetValue <bool>("support_material"))
            {
                if (ActiveSliceSettings.Instance.GetValue <int>("support_material_extruder") != 0)
                {
                    int supportExtruder = Math.Max(0, Math.Min(ActiveSliceSettings.Instance.GetValue <int>(SettingsKey.extruder_count) - 1, ActiveSliceSettings.Instance.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 (ActiveSliceSettings.Instance.GetValue <bool>("create_raft"))
            {
                if (ActiveSliceSettings.Instance.GetValue <int>("raft_extruder") != 0)
                {
                    int raftExtruder = Math.Max(0, Math.Min(ActiveSliceSettings.Instance.GetValue <int>(SettingsKey.extruder_count) - 1, ActiveSliceSettings.Instance.GetValue <int>("raft_extruder") - 1));
                    extrudersUsed[raftExtruder] = true;
                }
            }

            switch (Path.GetExtension(fileToSlice).ToUpper())
            {
            case ".STL":
            case ".GCODE":
                extrudersUsed[0] = true;
                return(new string[] { fileToSlice });

            case ".AMF":
                List <MeshGroup> meshGroups = MeshFileIo.Load(fileToSlice);
                if (meshGroups != null)
                {
                    List <MeshGroup> extruderMeshGroups = new List <MeshGroup>();
                    for (int extruderIndex = 0; extruderIndex < extruderCount; extruderIndex++)
                    {
                        extruderMeshGroups.Add(new MeshGroup());
                    }
                    int maxExtruderIndex = 0;
                    foreach (MeshGroup meshGroup in meshGroups)
                    {
                        foreach (Mesh mesh in meshGroup.Meshes)
                        {
                            MeshMaterialData material = MeshMaterialData.Get(mesh);
                            int extruderIndex         = Math.Max(0, material.MaterialIndex - 1);
                            maxExtruderIndex = Math.Max(maxExtruderIndex, extruderIndex);
                            if (extruderIndex >= extruderCount)
                            {
                                extrudersUsed[0] = true;
                                extruderMeshGroups[0].Meshes.Add(mesh);
                            }
                            else
                            {
                                extrudersUsed[extruderIndex] = true;
                                extruderMeshGroups[extruderIndex].Meshes.Add(mesh);
                            }
                        }
                    }

                    int           savedStlCount        = 0;
                    List <string> extruderFilesToSlice = new List <string>();
                    for (int extruderIndex = 0; extruderIndex < extruderMeshGroups.Count; extruderIndex++)
                    {
                        MeshGroup  meshGroup          = extruderMeshGroups[extruderIndex];
                        List <int> materialsToInclude = new List <int>();
                        materialsToInclude.Add(extruderIndex + 1);
                        if (extruderIndex == 0)
                        {
                            for (int j = extruderCount + 1; j < maxExtruderIndex + 2; j++)
                            {
                                materialsToInclude.Add(j);
                            }
                        }

                        if (doMergeInSlicer)
                        {
                            int meshCount = meshGroup.Meshes.Count;
                            for (int meshIndex = 0; meshIndex < meshCount; meshIndex++)
                            {
                                Mesh mesh = meshGroup.Meshes[meshIndex];
                                if ((meshIndex % 2) == 0)
                                {
                                    mergeRules += "({0}".FormatWith(savedStlCount);
                                }
                                else
                                {
                                    if (meshIndex < meshCount - 1)
                                    {
                                        mergeRules += ",({0}".FormatWith(savedStlCount);
                                    }
                                    else
                                    {
                                        mergeRules += ",{0}".FormatWith(savedStlCount);
                                    }
                                }
                                int currentMeshMaterialIntdex = MeshMaterialData.Get(mesh).MaterialIndex;
                                if (materialsToInclude.Contains(currentMeshMaterialIntdex))
                                {
                                    extruderFilesToSlice.Add(SaveAndGetFilenameForMesh(mesh));
                                }
                                savedStlCount++;
                            }
                            for (int i = 0; i < meshCount - 1; i++)
                            {
                                mergeRules += ")";
                            }
                        }
                        else
                        {
                            extruderFilesToSlice.Add(SaveAndGetFilenameForMaterial(meshGroup, materialsToInclude));
                        }
                    }
                    return(extruderFilesToSlice.ToArray());
                }
                return(new string[] { "" });

            default:
                return(new string[] { "" });
            }
        }
Exemplo n.º 17
0
        public static string[] GetStlFileLocations(string fileToSlice)
        {
            extrudersUsed.Clear();

            int extruderCount = ActiveSliceSettings.Instance.ExtruderCount;

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

            // If we have support enabled and and are using an extruder other than 0 for it
            if (ActiveSliceSettings.Instance.SupportEnabled)
            {
                if (ActiveSliceSettings.Instance.SupportExtruder != 0)
                {
                    int supportExtruder = Math.Max(0, Math.Min(ActiveSliceSettings.Instance.ExtruderCount - 1, ActiveSliceSettings.Instance.SupportExtruder - 1));
                    extrudersUsed[supportExtruder] = true;
                }
            }

            // If we have raft enabled and are using an extruder other than 0 for it
            if (ActiveSliceSettings.Instance.RaftEnabled)
            {
                if (ActiveSliceSettings.Instance.RaftExtruder != 0)
                {
                    int raftExtruder = Math.Max(0, Math.Min(ActiveSliceSettings.Instance.ExtruderCount - 1, ActiveSliceSettings.Instance.RaftExtruder - 1));
                    extrudersUsed[raftExtruder] = true;
                }
            }

            switch (Path.GetExtension(fileToSlice).ToUpper())
            {
            case ".STL":
            case ".GCODE":
                extrudersUsed[0] = true;
                return(new string[] { fileToSlice });

            case ".AMF":
                List <MeshGroup> meshGroups         = MeshFileIo.Load(fileToSlice);
                List <MeshGroup> extruderMeshGroups = new List <MeshGroup>();
                for (int extruderIndex = 0; extruderIndex < extruderCount; extruderIndex++)
                {
                    extruderMeshGroups.Add(new MeshGroup());
                }
                int maxExtruderIndex = 0;
                foreach (MeshGroup meshGroup in meshGroups)
                {
                    foreach (Mesh mesh in meshGroup.Meshes)
                    {
                        MeshMaterialData material = MeshMaterialData.Get(mesh);
                        int extruderIndex         = Math.Max(0, material.MaterialIndex - 1);
                        maxExtruderIndex = Math.Max(maxExtruderIndex, extruderIndex);
                        if (extruderIndex >= extruderCount)
                        {
                            extrudersUsed[0] = true;
                            extruderMeshGroups[0].Meshes.Add(mesh);
                        }
                        else
                        {
                            extrudersUsed[extruderIndex] = true;
                            extruderMeshGroups[extruderIndex].Meshes.Add(mesh);
                        }
                    }
                }

                List <string> extruderFilesToSlice = new List <string>();
                for (int i = 0; i < extruderMeshGroups.Count; i++)
                {
                    MeshGroup  meshGroup          = extruderMeshGroups[i];
                    List <int> materialsToInclude = new List <int>();
                    materialsToInclude.Add(i + 1);
                    if (i == 0)
                    {
                        for (int j = extruderCount + 1; j < maxExtruderIndex + 2; j++)
                        {
                            materialsToInclude.Add(j);
                        }
                    }

                    extruderFilesToSlice.Add(SaveAndGetFilenameForMaterial(meshGroup, materialsToInclude));
                }
                return(extruderFilesToSlice.ToArray());

            default:
                throw new NotImplementedException();
            }
        }
Exemplo n.º 18
0
        public MoveInZControl(IInteractionVolumeContext context)
            : base(context)
        {
            Name = "MoveInZControl";
            zHeightDisplayInfo = new InlineEditControl()
            {
                ForceHide = () =>
                {
                    var selectedItem = InteractionContext.Scene.RootSelectedItem;
                    // if the selection changes
                    if (selectedItem != ActiveSelectedItem)
                    {
                        return(true);
                    }

                    // if another control gets a hover
                    if (InteractionContext.HoveredInteractionVolume != this &&
                        InteractionContext.HoveredInteractionVolume != null)
                    {
                        return(true);
                    }

                    // if we clicked on the control
                    if (HadClickOnControl)
                    {
                        return(false);
                    }

                    return(false);
                }
                ,
                GetDisplayString = (value) => "{0:0.0#}mm".FormatWith(value)
            };

            zHeightDisplayInfo.VisibleChanged += (s, e) =>
            {
                if (!zHeightDisplayInfo.Visible)
                {
                    HadClickOnControl = false;
                }
            };

            zHeightDisplayInfo.EditComplete += (s, e) =>
            {
                var selectedItem = InteractionContext.Scene.RootSelectedItem;

                Matrix4X4 startingTransform = selectedItem.Matrix;

                var newZPosition = zHeightDisplayInfo.Value;

                if (InteractionContext.SnapGridDistance > 0)
                {
                    // snap this position to the grid
                    double snapGridDistance = InteractionContext.SnapGridDistance;

                    // snap this position to the grid
                    newZPosition = ((int)((newZPosition / snapGridDistance) + .5)) * snapGridDistance;
                }

                AxisAlignedBoundingBox originalSelectedBounds = selectedItem.GetAxisAlignedBoundingBox(Matrix4X4.Identity);
                var moveAmount = newZPosition - originalSelectedBounds.minXYZ.Z;

                if (moveAmount != 0)
                {
                    selectedItem.Matrix = selectedItem.Matrix * Matrix4X4.CreateTranslation(0, 0, moveAmount);
                    Invalidate();
                }

                context.AddTransformSnapshot(startingTransform);
            };

            InteractionContext.GuiSurface.AddChild(zHeightDisplayInfo);

            DrawOnTop = true;

            string arrowFile = Path.Combine("Icons", "3D Icons", "up_pointer.stl");

            using (Stream arrowStream = AggContext.StaticData.OpenStream(arrowFile))
            {
                upArrowMesh = MeshFileIo.Load(arrowStream, Path.GetExtension(arrowFile), CancellationToken.None).Mesh;
            }

            CollisionVolume = upArrowMesh.CreateTraceData();

            InteractionContext.GuiSurface.AfterDraw += InteractionLayer_AfterDraw;
        }
Exemplo n.º 19
0
        private void CreateThumbnail()
        {
            string stlHashCode = this.PrintItem.FileHashCode.ToString();

            ImageBuffer bigRender = new ImageBuffer();

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

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

            RenderType renderType = GetRenderType(this.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);
                this.thumbnailImage = new ImageBuffer(this.buildingThumbnailImage);
                this.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(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);
            }

            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;
            }

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

            UiThread.RunOnIdle(this.EnsureImageUpdated);

            OnDoneRendering();
        }
        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();
        }
Exemplo n.º 21
0
        public override IEnumerable <PrintItemAction> GetMenuItems()
        {
            return(new List <PrintItemAction>()
            {
                new PrintItemAction()
                {
                    SingleItemOnly = false,
                    Title = "Merge".Localize() + "...",
                    Action = (items, queueDataWidget) =>
                    {
                        List <QueueRowItem> allRowItems = new List <QueueRowItem>(items);
                        if (allRowItems.Count > 1)
                        {
                            RenameItemWindow renameItemWindow = new RenameItemWindow(allRowItems[0].PrintItemWrapper.Name, (returnInfo) =>
                            {
                                Task.Run(() =>
                                {
                                    List <MeshGroup> combinedMeshes = new List <MeshGroup>();

                                    // Load up all the parts and merge them together
                                    foreach (QueueRowItem item in allRowItems)
                                    {
                                        List <MeshGroup> loadedMeshGroups = MeshFileIo.Load(item.PrintItemWrapper.FileLocation);
                                        combinedMeshes.AddRange(loadedMeshGroups);
                                    }

                                    // save them out
                                    string[] metaData = { "Created By", "MatterControl", "BedPosition", "Absolute" };
                                    MeshOutputSettings outputInfo = new MeshOutputSettings(MeshOutputSettings.OutputType.Binary, metaData);
                                    string libraryDataPath = ApplicationDataStorage.Instance.ApplicationLibraryDataPath;
                                    if (!Directory.Exists(libraryDataPath))
                                    {
                                        Directory.CreateDirectory(libraryDataPath);
                                    }

                                    string tempFileNameToSaveTo = Path.Combine(libraryDataPath, Path.ChangeExtension(Path.GetRandomFileName(), "amf"));
                                    bool savedSuccessfully = MeshFileIo.Save(combinedMeshes, tempFileNameToSaveTo, outputInfo);

                                    // Swap out the files if the save operation completed successfully
                                    if (savedSuccessfully && File.Exists(tempFileNameToSaveTo))
                                    {
                                        // create a new print item
                                        // add it to the queue
                                        PrintItemWrapper newPrintItem = new PrintItemWrapper(new PrintItem(returnInfo.newName, tempFileNameToSaveTo));
                                        QueueData.Instance.AddItem(newPrintItem, 0);

                                        // select the part we added, if possible
                                        QueueData.Instance.SelectedIndex = 0;

                                        queueDataWidget.LeaveEditMode();
                                    }
                                });
                            }, "Set Name".Localize())
                            {
                                Title = "MatterHackers - Set Name".Localize(),
                                ElementHeader = "Set Name".Localize(),
                            };
                        }
                    }
                }
            });
        }