public void AddItemsByFolder() { SelectFolderDialogCreationArgs args = new SelectFolderDialogCreationArgs(); args.AllowCreateNewFolder = false; args.Path = _lastFolder; args.Prompt = SR.MessageSelectAddFilesFolder; FileDialogResult result = base.Context.DesktopWindow.ShowSelectFolderDialogBox(args); if (result.Action == DialogBoxAction.Ok) { _lastFolder = result.FileName; base.Context.BulkOperationsMode = true; try { base.Load(false, result.FileName); base.RefreshTable(); } finally { base.Context.BulkOperationsMode = false; } } }
public void Open() { SelectFolderDialogCreationArgs args = new SelectFolderDialogCreationArgs(); args.AllowCreateNewFolder = false; args.Path = _lastFolder; args.Prompt = SR.MessageSelectFolderToFilter; FileDialogResult result = base.Context.DesktopWindow.ShowSelectFolderDialogBox(args); if (result.Action == DialogBoxAction.Ok) { _lastFolder = result.FileName; StudyFilterComponent component = new StudyFilterComponent(); component.BulkOperationsMode = true; if (component.Load(base.Context.DesktopWindow, true, result.FileName)) { component.Refresh(true); base.Context.DesktopWindow.Workspaces.AddNew(component, SR.StudyFilters); } component.BulkOperationsMode = false; } }
public void Open() { var args = new SelectFolderDialogCreationArgs { AllowCreateNewFolder = false, Prompt = @"Open Dicom Files" }; var result = base.Context.DesktopWindow.ShowSelectFolderDialogBox(args); if (result.Action == DialogBoxAction.Ok) { base.Context.Component.LoadFolder(result.FileName); } //FileDialogCreationArgs args = new FileDialogCreationArgs(string.Empty) //{ // Title = @"Open File Set", // FileExtension = string.Empty //}; //args.Filters.Add(new FileExtensionFilter("DICOMDIR; *.dcm", @"All Support File")); //args.Filters.Add(new FileExtensionFilter("*.*", @"All Files")); //FileDialogResult result = base.Context.DesktopWindow.ShowOpenFileDialogBox(args); //if (result.Action == DialogBoxAction.Ok) //{ // FileName = result.FileName; //} //base.Context.Component.Load(FileName); }
private void ChangeToSyntax(TransferSyntax syntax) { string[] files = BuildFileList(); var args = new SelectFolderDialogCreationArgs { Path = GetDirectoryOfFirstPath(), AllowCreateNewFolder = true, Prompt = "Select output folder" }; var result = base.Context.DesktopWindow.ShowSelectFolderDialogBox(args); if (result.Action != DialogBoxAction.Ok) { return; } foreach (string file in files) { try { DicomFile dicomFile = new DicomFile(file); dicomFile.Load(); dicomFile.ChangeTransferSyntax(syntax); string sourceFileName = System.IO.Path.GetFileNameWithoutExtension(file); string fileName = System.IO.Path.Combine(result.FileName, sourceFileName); fileName += ".compressed.dcm"; dicomFile.Save(fileName); } catch (Exception e) { ExceptionHandler.Report(e, Context.DesktopWindow); } } }
private bool Initialize() { _synchronizationContext = SynchronizationContext.Current; _exportedInstances = new AuditedInstances(); _canceled = false; _overwrite = false; if (Anonymize) { ExportComponent component = new ExportComponent(); component.OutputPath = OutputPath; if (DialogBoxAction.Ok != DesktopWindow.ShowDialogBox(component, SR.Export)) { return(false); } OutputPath = component.OutputPath; StudyData studyData = new StudyData { PatientId = component.PatientId, PatientsNameRaw = component.PatientsName, PatientsBirthDate = component.PatientsDateOfBirth, StudyId = component.StudyId, StudyDescription = component.StudyDescription, AccessionNumber = component.AccessionNumber, StudyDate = component.StudyDate }; _anonymizer = new DicomAnonymizer(); _anonymizer.KeepPrivateTags = component.KeepPrivateTags; _anonymizer.ValidationOptions = ValidationOptions.RelaxAllChecks; _anonymizer.StudyDataPrototype = studyData; } else { SelectFolderDialogCreationArgs args = new SelectFolderDialogCreationArgs(); args.Prompt = SR.MessageSelectOutputLocation; args.Path = OutputPath; FileDialogResult result = DesktopWindow.ShowSelectFolderDialogBox(args); if (result.Action != DialogBoxAction.Ok) { return(false); } OutputPath = result.FileName; } return(true); }
/// <summary> /// Shows a 'Select folder' dialog in front of this window. /// </summary> /// <param name="args"></param> /// <returns></returns> public FileDialogResult ShowSelectFolderDialogBox(SelectFolderDialogCreationArgs args) { var dialog = new FolderBrowserDialog(); dialog.SelectedPath = args.Path ?? ""; dialog.Description = args.Prompt ?? ""; dialog.ShowNewFolderButton = args.AllowCreateNewFolder; var dr = dialog.ShowDialog(_form); if (dr == DialogResult.OK) { return(new FileDialogResult(DialogBoxAction.Ok, dialog.SelectedPath)); } return(new FileDialogResult(DialogBoxAction.Cancel, (string)null)); }
public void Create() { SelectFolderDialogCreationArgs args = new SelectFolderDialogCreationArgs(); args.Path = _lastFolder ?? Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); FileDialogResult result = base.Context.DesktopWindow.ShowSelectFolderDialogBox(args); if (result.Action == DialogBoxAction.Ok) { _lastFolder = result.FileName; StudyLoaderExtensionPoint xp = new StudyLoaderExtensionPoint(); IStudyLoader loader = (IStudyLoader)CollectionUtils.SelectFirst(xp.CreateExtensions(), delegate(object extension) { return(((IStudyLoader)extension).Name == "DICOM_LOCAL"); }); var selected = base.Context.SelectedStudy; loader.Start(new StudyLoaderArgs(selected.StudyInstanceUid, selected.Server, StudyLoaderOptions.Default)); StudyXml xml = new StudyXml(); Sop sop; while (null != (sop = loader.LoadNextSop())) { xml.AddFile(((ILocalSopDataSource)sop.DataSource).File); } StudyXmlOutputSettings settings = new StudyXmlOutputSettings(); settings.IncludePrivateValues = StudyXmlTagInclusion.IgnoreTag; settings.IncludeUnknownTags = StudyXmlTagInclusion.IgnoreTag; settings.MaxTagLength = 100 * 1024; settings.IncludeSourceFileName = true; XmlDocument doc = xml.GetMemento(settings); string fileName = System.IO.Path.Combine(result.FileName, "studyxml.xml"); XmlTextWriter writer = new XmlTextWriter(fileName, Encoding.UTF8); writer.Formatting = Formatting.Indented; writer.Indentation = 5; doc.Save(writer); } }
public void ShowOutputPathDialog() { SelectFolderDialogCreationArgs dialogArgs = new SelectFolderDialogCreationArgs(_outputPath); dialogArgs.AllowCreateNewFolder = true; dialogArgs.Path = this.OutputPath; dialogArgs.Prompt = SR.MessageSelectOutputLocation; FileDialogResult result = base.Host.DesktopWindow.ShowSelectFolderDialogBox(dialogArgs); if (result.Action == DialogBoxAction.Ok) { OutputPath = result.FileName; } if (!this.HasValidationErrors) { base.ShowValidation(true); } }
public void Open() { SelectFolderDialogCreationArgs args = new SelectFolderDialogCreationArgs(); args.AllowCreateNewFolder = false; args.Path = _lastFolder; args.Prompt = SR.MessageSelectFolderToFilter; FileDialogResult result = base.Context.DesktopWindow.ShowSelectFolderDialogBox(args); if (result.Action == DialogBoxAction.Ok) { _lastFolder = result.FileName; string[] file = Directory.GetFiles(_lastFolder, "*.*", SearchOption.AllDirectories); fileName = file; ClearCanvas.ImageViewer.ImageViewerComponent viewer = null; DesktopWindow desktopWindow = null; List <string> _filenames = new List <string>(); foreach (DesktopWindow window in Application.DesktopWindows) { foreach (Workspace space in window.Workspaces) { if (space.Title == "imageview") { desktopWindow = window; viewer = space.Component as ClearCanvas.ImageViewer.ImageViewerComponent; } } } if (viewer != null) { viewer.PhysicalWorkspace.Clear(); viewer.LogicalWorkspace.Clear(); viewer.ReAllocateStudyTree(); viewer.Layout(); viewer.LoadImages(file, ""); viewer.Layout(); } } }
public void ChangeFileStore() { var args = new SelectFolderDialogCreationArgs(FileStoreDirectory) { Prompt = SR.TitleSelectFileStore, AllowCreateNewFolder = true }; var result = base.Host.DesktopWindow.ShowSelectFolderDialogBox(args); if (result.Action != DialogBoxAction.Ok) { return; } try { FileStoreDirectory = result.FileName; } catch (Exception e) { ExceptionHandler.Report(e, Host.DesktopWindow); } }
public void Go() { string[] files = BuildFileList(); var args = new SelectFolderDialogCreationArgs { Path = GetDirectoryOfFirstPath(), AllowCreateNewFolder = true, Prompt = "Select output folder" }; var result = base.Context.DesktopWindow.ShowSelectFolderDialogBox(args); if (result.Action != DialogBoxAction.Ok) { return; } try { foreach (string file in files) { DicomFile dicomFile = new DicomFile(file); dicomFile.Load(); if (!new OverlayPlaneModuleIod(dicomFile.DataSet).ExtractEmbeddedOverlays()) { continue; } string sourceFileName = System.IO.Path.GetFileNameWithoutExtension(file); string fileName = System.IO.Path.Combine(result.FileName, sourceFileName); fileName += ".overlays-extracted.dcm"; dicomFile.Save(fileName); } } catch (Exception e) { ExceptionHandler.Report(e, Context.DesktopWindow); } }
/// <summary> /// Shows a 'Select folder' dialog in front of this window. /// </summary> /// <param name="args"></param> /// <returns></returns> public FileDialogResult ShowSelectFolderDialogBox(SelectFolderDialogCreationArgs args) { throw new NotSupportedException(); }
/// <summary> /// Shows a 'Select folder' dialog in front of this window. /// </summary> /// <param name="args"></param> /// <returns></returns> public FileDialogResult ShowSelectFolderDialogBox(SelectFolderDialogCreationArgs args) { var dialog = new FolderBrowserDialog(); dialog.SelectedPath = args.Path ?? ""; dialog.Description = args.Prompt ?? ""; dialog.ShowNewFolderButton = args.AllowCreateNewFolder; var dr = dialog.ShowDialog(_form); if (dr == DialogResult.OK) { return new FileDialogResult(DialogBoxAction.Ok, dialog.SelectedPath); } return new FileDialogResult(DialogBoxAction.Cancel, (string)null); }
public void Go() { string[] files = BuildFileList(); var args = new SelectFolderDialogCreationArgs { Path = GetDirectoryOfFirstPath(), AllowCreateNewFolder = true, Prompt = "Select output folder" }; var result = base.Context.DesktopWindow.ShowSelectFolderDialogBox(args); if (result.Action != DialogBoxAction.Ok) { return; } try { foreach (string file in files) { DicomFile dicomFile = new DicomFile(file); dicomFile.Load(); if (dicomFile.TransferSyntax.Encapsulated) { continue; } DicomAttribute attribute; if (!dicomFile.DataSet.TryGetAttribute(DicomTags.PixelData, out attribute)) { continue; } new OverlayPlaneModuleIod(dicomFile.DataSet).ExtractEmbeddedOverlays(); var rawPixelData = (byte[])attribute.Values; DicomPixelData pd = new DicomUncompressedPixelData(dicomFile); if (DicomUncompressedPixelData.ZeroUnusedBits(rawPixelData, pd.BitsAllocated, pd.BitsStored, pd.HighBit)) { Platform.Log(LogLevel.Info, "Zeroed some unused bits."); } if (DicomUncompressedPixelData.RightAlign(rawPixelData, pd.BitsAllocated, pd.BitsStored, pd.HighBit)) { var newHighBit = (ushort)(pd.HighBit - pd.LowBit); Platform.Log(LogLevel.Info, "Right aligned pixel data (High Bit: {0}->{1}).", pd.HighBit, newHighBit); pd.HighBit = newHighBit; //correct high bit after right-aligning. dicomFile.DataSet[DicomTags.HighBit].SetUInt16(0, newHighBit); } string sourceFileName = System.IO.Path.GetFileNameWithoutExtension(file); string fileName = System.IO.Path.Combine(result.FileName, sourceFileName); fileName += ".fixed-pixeldata.dcm"; dicomFile.Save(fileName); } } catch (Exception e) { ExceptionHandler.Report(e, Context.DesktopWindow); } }
private bool PromptSaveDestination(out Dictionary <string, string> filenames) { var storeLocation = GetCanonicalPath(StudyStore.FileStoreDirectory) + Path.DirectorySeparatorChar; filenames = null; if (_loadedFiles.Count > 1) { string selectedPath; var args = new SelectFolderDialogCreationArgs { AllowCreateNewFolder = true, Prompt = SR.MessageSelectDestinationFolder }; do { // show select folder dialog var result = Host.DesktopWindow.ShowSelectFolderDialogBox(args); if (result.Action != DialogBoxAction.Ok || string.IsNullOrWhiteSpace(result.FileName)) { return(false); } args.Path = selectedPath = result.FileName; if ((GetCanonicalPath(selectedPath) + Path.DirectorySeparatorChar).StartsWith(storeLocation)) { // if selected path is under the filestore location, make user choose another one var message = SR.MessageFileStoreNotValidSaveLocation; Host.DesktopWindow.ShowMessageBox(message, MessageBoxActions.Ok); selectedPath = string.Empty; } else if (Directory.Exists(selectedPath) && Directory.EnumerateFiles(selectedPath).Any()) { // if selected path contains files, confirm that operation will overwrite files, or let user choose another one var message = SR.MessageOutputFolderNotEmptyConfirmOverwriteFiles; if (Host.DesktopWindow.ShowMessageBox(message, MessageBoxActions.YesNo) != DialogBoxAction.Yes) { selectedPath = string.Empty; } } } while (string.IsNullOrWhiteSpace(selectedPath)); // create the file map using new filenames in the selected path var n = 0; filenames = _loadedFiles.ToDictionary(f => f.Filename, f => Path.Combine(selectedPath, string.Format("{0:D8}.dcm", ++n))); return(true); } else { string targetFilename; var originalFilename = _loadedFiles[0].Filename; var args = new FileDialogCreationArgs(originalFilename) { PreventSaveToInstallPath = true, Title = SR.TitleSaveAs }; args.Filters.Add(new FileExtensionFilter("*.*", SR.LabelAllFiles)); do { // show save file dialog var result = Host.DesktopWindow.ShowSaveFileDialogBox(args); if (result.Action != DialogBoxAction.Ok || string.IsNullOrWhiteSpace(result.FileName)) { return(false); } targetFilename = result.FileName; if (GetCanonicalPath(targetFilename).StartsWith(storeLocation)) { // if destination file is in filestore, make user choose another one var message = SR.MessageFileStoreNotValidSaveLocation; Host.DesktopWindow.ShowMessageBox(message, MessageBoxActions.Ok); targetFilename = string.Empty; } // save dialog handles prompting if destination file already exists } while (string.IsNullOrWhiteSpace(targetFilename)); // create file map with the one single entry filenames = new Dictionary <string, string> { { originalFilename, targetFilename } }; return(true); } }