private void OpenSaveAsWindow() { if (saveAsWindow == null) { List<ProviderLocatorNode> providerLocator = null; if (printItemWrapper.SourceLibraryProvider != null) { providerLocator = printItemWrapper.SourceLibraryProvider.GetProviderLocator(); } saveAsWindow = new SaveAsWindow(MergeAndSavePartsToNewMeshFile, providerLocator); saveAsWindow.Closed += new EventHandler(SaveAsWindow_Closed); } else { saveAsWindow.BringToFront(); } }
private void SaveAsWindow_Closed(object sender, EventArgs e) { this.saveAsWindow = null; }
private void addToLibraryButton_Click(object sender, EventArgs mouseEvent) { SaveAsWindow saveAsWindow = new SaveAsWindow(DoAddToSpecificLibrary, null, false, false); }
private void MergeAndSavePartsToNewMeshFile(SaveAsWindow.SaveAsReturnInfo returnInfo) { editorThatRequestedSave = true; if (MeshGroups.Count > 0) { string progressSavingPartsLabel = "Saving".Localize(); string progressSavingPartsLabelFull = "{0}:".FormatWith(progressSavingPartsLabel); processingProgressControl.ProcessType = progressSavingPartsLabelFull; processingProgressControl.Visible = true; processingProgressControl.PercentComplete = 0; LockEditControls(); BackgroundWorker mergeAndSavePartsBackgroundWorker = new BackgroundWorker(); mergeAndSavePartsBackgroundWorker.DoWork += new DoWorkEventHandler(mergeAndSavePartsBackgroundWorker_DoWork); mergeAndSavePartsBackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(mergeAndSavePartsBackgroundWorker_RunWorkerCompleted); mergeAndSavePartsBackgroundWorker.RunWorkerAsync(returnInfo); } }
private void MergeAndSavePartsDoWork(SaveAsWindow.SaveAsReturnInfo returnInfo) { if (returnInfo != null) { PrintItem printItem = new PrintItem(); printItem.Name = returnInfo.newName; printItem.FileLocation = Path.GetFullPath(returnInfo.fileNameAndPath); printItemWrapper = new PrintItemWrapper(printItem, returnInfo.destinationLibraryProvider.GetProviderLocator()); } // we sent the data to the async lists but we will not pull it back out (only use it as a temp holder). PushMeshGroupDataToAsynchLists(TraceInfoOpperation.DO_COPY); Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; try { // push all the transforms into the meshes for (int i = 0; i < asyncMeshGroups.Count; i++) { asyncMeshGroups[i].Transform(asyncMeshGroupTransforms[i]); bool continueProcessing; ReportProgressChanged((i + 1) * .4 / asyncMeshGroups.Count, "", out continueProcessing); } string[] metaData = { "Created By", "MatterControl", "BedPosition", "Absolute" }; MeshOutputSettings outputInfo = new MeshOutputSettings(MeshOutputSettings.OutputType.Binary, metaData); // If null we are replacing a file from the current print item wrapper if (returnInfo == null) { var fileInfo = new FileInfo(printItemWrapper.FileLocation); bool requiresTypeChange = !fileInfo.Extension.Equals(".amf", StringComparison.OrdinalIgnoreCase); if (requiresTypeChange && !printItemWrapper.UseIncrementedNameDuringTypeChange) { // Not using incremented file name, simply change to AMF printItemWrapper.FileLocation = Path.ChangeExtension(printItemWrapper.FileLocation, ".amf"); } else if (requiresTypeChange) { string newFileName; string incrementedFileName; // Switching from .stl, .obj or similar to AMF. Save the file and update the // the filename with an incremented (n) value to reflect the extension change in the UI string fileName = Path.GetFileNameWithoutExtension(fileInfo.Name); // Drop bracketed number sections from our source filename to ensure we don't generate something like "file (1) (1).amf" if (fileName.Contains("(")) { fileName = fileNameNumberMatch.Replace(fileName, "").Trim(); } // Generate and search for an incremented file name until no match is found at the target directory int foundCount = 0; do { newFileName = string.Format("{0} ({1})", fileName, ++foundCount); incrementedFileName = Path.Combine(fileInfo.DirectoryName, newFileName + ".amf"); // Continue incrementing while any matching file exists } while (Directory.GetFiles(fileInfo.DirectoryName, newFileName + ".*").Any()); // Change the FileLocation to the new AMF file printItemWrapper.FileLocation = incrementedFileName; } try { // get a new location to save to string tempFileNameToSaveTo = ApplicationDataStorage.Instance.GetTempFileName("amf"); // save to the new temp location bool savedSuccessfully = MeshFileIo.Save(asyncMeshGroups, tempFileNameToSaveTo, outputInfo, ReportProgressChanged); // Swap out the files if the save operation completed successfully if (savedSuccessfully && File.Exists(tempFileNameToSaveTo)) { // Ensure the target path is clear if(File.Exists(printItemWrapper.FileLocation)) { File.Delete(printItemWrapper.FileLocation); } // Move the newly saved file back into place File.Move(tempFileNameToSaveTo, printItemWrapper.FileLocation); // Once the file is swapped back into place, update the PrintItem to account for extension change printItemWrapper.PrintItem.Commit(); } } catch(Exception ex) { Trace.WriteLine("Error saving file: ", ex.Message); } } else // we are saving a new file and it will not exist until we are done { MeshFileIo.Save(asyncMeshGroups, printItemWrapper.FileLocation, outputInfo, ReportProgressChanged); } // Wait for a second to report the file changed to give the OS a chance to finish closing it. UiThread.RunOnIdle(printItemWrapper.ReportFileChange, 3); if (returnInfo != null && returnInfo.destinationLibraryProvider != null) { // save this part to correct library provider LibraryProvider libraryToSaveTo = returnInfo.destinationLibraryProvider; if (libraryToSaveTo != null) { libraryToSaveTo.AddItem(printItemWrapper); libraryToSaveTo.Dispose(); } } else // we have already saved it and the library should pick it up { } saveSucceded = true; } catch (System.UnauthorizedAccessException e2) { Debug.Print(e2.Message); GuiWidget.BreakInDebugger(); saveSucceded = false; UiThread.RunOnIdle(() => { //Do something special when unauthorized? StyledMessageBox.ShowMessageBox(null, "Oops! Unable to save changes.", "Unable to save"); }); } catch (Exception e) { Debug.Print(e.Message); GuiWidget.BreakInDebugger(); saveSucceded = false; UiThread.RunOnIdle(() => { StyledMessageBox.ShowMessageBox(null, "Oops! Unable to save changes.", "Unable to save"); }); } }
private async void MergeAndSavePartsToNewMeshFile(SaveAsWindow.SaveAsReturnInfo returnInfo) { editorThatRequestedSave = true; if (MeshGroups.Count > 0) { string progressSavingPartsLabel = "Saving".Localize(); string progressSavingPartsLabelFull = "{0}:".FormatWith(progressSavingPartsLabel); processingProgressControl.ProcessType = progressSavingPartsLabelFull; processingProgressControl.Visible = true; processingProgressControl.PercentComplete = 0; LockEditControls(); await Task.Run(() => MergeAndSavePartsDoWork(returnInfo)); MergeAndSavePartsDoCompleted(); } }
void DoAddToSpecificLibrary(SaveAsWindow.SaveAsReturnInfo returnInfo) { if (returnInfo != null) { List<QueueRowItem> selectedItems = new List<QueueRowItem>(queueDataView.SelectedItems); LibraryProvider libraryToSaveTo = returnInfo.destinationLibraryProvider; if (libraryToSaveTo != null) { foreach (QueueRowItem queueItem in selectedItems) { if (File.Exists(queueItem.PrintItemWrapper.FileLocation)) { PrintItemWrapper printItemWrapper = new PrintItemWrapper(new PrintItem(queueItem.PrintItemWrapper.PrintItem.Name, queueItem.PrintItemWrapper.FileLocation), returnInfo.destinationLibraryProvider.GetProviderLocator()); libraryToSaveTo.AddItem(printItemWrapper); } } libraryToSaveTo.Dispose(); } } }
private void MergeAndSavePartsDoWork(SaveAsWindow.SaveAsReturnInfo returnInfo) { if (returnInfo != null) { PrintItem printItem = new PrintItem(); printItem.Name = returnInfo.newName; printItem.FileLocation = Path.GetFullPath(returnInfo.fileNameAndPath); printItemWrapper = new PrintItemWrapper(printItem, returnInfo.destinationLibraryProvider.GetProviderLocator()); } // we sent the data to the asynch lists but we will not pull it back out (only use it as a temp holder). PushMeshGroupDataToAsynchLists(TraceInfoOpperation.DO_COPY); Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; try { // push all the transforms into the meshes for (int i = 0; i < asynchMeshGroups.Count; i++) { asynchMeshGroups[i].Transform(asynchMeshGroupTransforms[i].TotalTransform); bool continueProcessing; ReportProgressChanged((i + 1) * .4 / asynchMeshGroups.Count, "", out continueProcessing); } saveSucceded = true; string[] metaData = { "Created By", "MatterControl", "BedPosition", "Absolute" }; MeshOutputSettings outputInfo = new MeshOutputSettings(MeshOutputSettings.OutputType.Binary, metaData); if (Path.GetExtension(printItemWrapper.FileLocation).ToUpper() == ".STL") { printItemWrapper.FileLocation = Path.ChangeExtension(printItemWrapper.FileLocation, ".AMF"); } MeshFileIo.Save(asynchMeshGroups, printItemWrapper.FileLocation, outputInfo); printItemWrapper.ReportFileChange(); if (returnInfo != null && returnInfo.destinationLibraryProvider != null) { // save this part to correct library provider LibraryProvider libraryToSaveTo = returnInfo.destinationLibraryProvider; if (libraryToSaveTo != null) { libraryToSaveTo.AddItem(printItemWrapper); libraryToSaveTo.Dispose(); } } else // we have already save it and the library should pick it up { } } catch (System.UnauthorizedAccessException e2) { Debug.Print(e2.Message); GuiWidget.BreakInDebugger(); saveSucceded = false; UiThread.RunOnIdle(() => { //Do something special when unauthorized? StyledMessageBox.ShowMessageBox(null, "Oops! Unable to save changes.", "Unable to save"); }); } catch(Exception e) { Debug.Print(e.Message); GuiWidget.BreakInDebugger(); saveSucceded = false; UiThread.RunOnIdle(() => { StyledMessageBox.ShowMessageBox(null, "Oops! Unable to save changes.", "Unable to save"); }); } }
private void SaveAs_Click(object sender, RoutedEventArgs e) { SaveAsWindow window = new SaveAsWindow(); window.ShowDialog(); if (window.DialogResult.Value) Editor.Controller.SaveAs(window.SaveName); }
void DoAddToSpecificLibrary(SaveAsWindow.SaveAsReturnInfo returnInfo) { if (returnInfo != null) { LibraryProvider libraryToSaveTo = returnInfo.destinationLibraryProvider; if (libraryToSaveTo != null) { foreach (var queueItemIndex in QueueData.Instance.SelectedIndexes) { var queueItem = queueDataView.GetQueueRowItem(queueItemIndex); if (queueItem != null) { if (File.Exists(queueItem.PrintItemWrapper.FileLocation)) { PrintItemWrapper printItemWrapper = new PrintItemWrapper(new PrintItem(queueItem.PrintItemWrapper.PrintItem.Name, queueItem.PrintItemWrapper.FileLocation), returnInfo.destinationLibraryProvider.GetProviderLocator()); libraryToSaveTo.AddItem(printItemWrapper); } } } libraryToSaveTo.Dispose(); } } }
private FlowLayoutWidget CreateSaveButtons() { FlowLayoutWidget saveButtons = new FlowLayoutWidget(); //Create Save Button double oldWidth = whiteButtonFactory.FixedWidth; whiteButtonFactory.FixedWidth = 56 * TextWidget.GlobalPointSizeScaleRatio; Button saveButton = whiteButtonFactory.Generate("Save".Localize(), centerText: true); saveButton.Cursor = Cursors.Hand; saveButtons.AddChild(saveButton); saveButton.Click += (sender, e) => { MergeAndSavePartsToCurrentMeshFile(); }; //Create Save As Button whiteButtonFactory.FixedWidth = SideBarButtonWidth - whiteButtonFactory.FixedWidth - 2; Button saveAsButton = whiteButtonFactory.Generate("Save As".Localize(), centerText: true); whiteButtonFactory.FixedWidth = oldWidth; saveAsButton.Cursor = Cursors.Hand; saveButtons.AddChild(saveAsButton); saveAsButton.Click += (sender, e) => { if (saveAsWindow == null) { saveAsWindow = new SaveAsWindow(MergeAndSavePartsToNewMeshFile); saveAsWindow.Closed += (sender2, e2) => { saveAsWindow = null; }; } else { saveAsWindow.BringToFront(); } }; saveButtons.Visible = false; return saveButtons; }
private void OpenSaveAsWindow(object state) { if (saveAsWindow == null) { saveAsWindow = new SaveAsWindow(MergeAndSavePartsToNewMeshFile); saveAsWindow.Closed += new EventHandler(SaveAsWindow_Closed); } else { saveAsWindow.BringToFront(); } }
private FlowLayoutWidget CreateSaveButtons() { TextImageButtonFactory saveButtonFactory = new TextImageButtonFactory(); saveButtonFactory.FixedWidth = 56; saveButtonFactory.FixedHeight = 40; saveButtonFactory.normalFillColor = RGBA_Bytes.White; saveButtonFactory.normalTextColor = RGBA_Bytes.Black; saveButtonFactory.hoverTextColor = RGBA_Bytes.Black; saveButtonFactory.hoverFillColor = new RGBA_Bytes(255, 255, 255, 200); FlowLayoutWidget saveButtons = new FlowLayoutWidget(); //Create Save Button Button saveButton = saveButtonFactory.Generate(LocalizedString.Get("Save"), centerText: true); saveButton.Cursor = Cursors.Hand; saveButtons.AddChild(saveButton); saveButton.Click += (sender, e) => { MergeAndSavePartsToStl(); }; //Create Save As Button saveButtonFactory.FixedWidth = SideBarButtonWidth - saveButtonFactory.FixedWidth - 2; Button saveAsButton = saveButtonFactory.Generate("Save As".Localize(), centerText: true); saveAsButton.Cursor = Cursors.Hand; saveButtons.AddChild(saveAsButton); saveAsButton.Click += (sender, e) => { if(saveAsWindowIsOpen == false) { saveAsWindow = new SaveAsWindow(MergeAndSavePartsToStl); this.saveAsWindowIsOpen = true; saveAsWindow.Closed += new EventHandler(SaveAsWindow_Closed); } else { if(saveAsWindowIsOpen != null) { saveAsWindow.BringToFront(); } } }; saveButtons.Visible = false; return saveButtons; }
private void OpenSaveAsWindow() { if (saveAsWindow == null) { saveAsWindow = new SaveAsWindow(MergeAndSavePartsToNewMeshFile, printItemWrapper.SourceLibraryProvider); saveAsWindow.Closed += new EventHandler(SaveAsWindow_Closed); } else { saveAsWindow.BringToFront(); } }