/// <summary> /// Adds a single attribute with the tag sequence, VR and values specified. /// </summary> /// <remarks> /// Depending on the group number of the last tag in the tag sequence, the attribute /// is set in the FileMetaInformation or DataSet of this instance. /// <br></br><br></br> /// If an attribute already exists with this tag sequence, it is removed first before it is /// again set. /// <br></br><br></br> /// If sequence items (each with a sequence item index) are specified in the tag sequence, /// empty sequence items will be added automatically to avoid gaps in the sequence items of sequence /// attributes. /// </remarks> /// <param name="tagSequence">The tag sequence that uniquely identifies the attribute.</param> /// <param name="vR">The VR of the attribute.</param> /// <param name="parameters"> /// The values of the attribute. Do not use the DICOM delimeter '\' directly. Instead use /// multiple parameter arguments for this method when adding a single attribute with multiple values. /// </param> internal void Set(TagSequence tagSequence, VR vR, params Object[] parameters) { // Check if the TagSequence supplied uniquely identifies one attribute. if (!tagSequence.IsSingleAttributeMatching) { throw new HliException(tagSequence.ToString() + " not valid for setting an attribute."); } if (tagSequence.IsValidForFileMetaInformation) { FileMetaInformation.Set(tagSequence, vR, parameters); } else if (tagSequence.IsValidForDataSet) { DataSet.Set(tagSequence, vR, parameters); } else { throw new HliException(tagSequence.ToString() + " not valid for setting a DicomFile attribute."); } }
void LoadDCMFile(string dicomFile) { DCMFile = dicomFile; string definitionDir = Environment.GetEnvironmentVariable("COMMONPROGRAMFILES") + @"\DVTk\Definition Files\DICOM\"; try { // Load the Definition Files DirectoryInfo theDefDirectoryInfo = new DirectoryInfo(definitionDir); if(theDefDirectoryInfo.Exists) { FileInfo[] theDefFilesInfo = theDefDirectoryInfo.GetFiles(); foreach (FileInfo defFile in theDefFilesInfo) { bool ok = _MainThread.Options.LoadDefinitionFile(defFile.FullName); if(!ok) { string theWarningText = string.Format("The Definition file {0} could not be loaded.\n", defFile.FullName); richTextBoxLog.AppendText(theWarningText); } } } //Subscribe the Dvtk activity report event handler for getting all activity logging. _MainThread.Options.DvtkScriptSession.ActivityReportEvent += activityReportEventHandler; _MainThread.Options.DvtkScriptSession.AddGroupLength = true; // Set the Results & Data directory _MainThread.Options.ResultsDirectory = Application.StartupPath + "\\" + "Results"; _MainThread.Options.DataDirectory = Application.StartupPath + "\\" + "Results"; // Read the Media file DicomFile dcmFile = new DicomFile(); dcmFile.Read(dicomFile, _MainThread); // dcmFile.Read(dicomFile); // Get the FMI from the selected Media file if(_FileMetaInfo == null) _FileMetaInfo = new FileMetaInformation(); _FileMetaInfo = dcmFile.FileMetaInformation; string tsStr = "Undefined"; if(_FileMetaInfo.Exists("0x00020010")) { // Get the Transfer syntax HLI.Attribute tranferSyntaxAttr = _FileMetaInfo["0x00020010"]; _TransferSyntax = tranferSyntaxAttr.Values[0]; tsStr = _TransferSyntax; } menuItemSaveAsELE.Visible = true; menuItemSaveAsILE.Visible = true; menuItemSaveAsEBE.Visible = true; if (_TransferSyntax == "1.2.840.10008.1.2.1") menuItemSaveAsELE.Visible = false; else if (_TransferSyntax == "1.2.840.10008.1.2") menuItemSaveAsILE.Visible = false; else if (_TransferSyntax == "1.2.840.10008.1.2.2") menuItemSaveAsEBE.Visible = false; else { menuItemSaveAsELE.Visible = false; menuItemSaveAsILE.Visible = false; menuItemSaveAsEBE.Visible = false; } // Get the Data set from the selected DICOM file/DICOMDIR string sopClassUID = ""; if(_FileMetaInfo.Exists("0x00020002")) { // Get the Transfer syntax HLI.Attribute sopClassUIDAttr = _FileMetaInfo["0x00020002"]; sopClassUID = sopClassUIDAttr.Values[0]; } if(_DCMdataset == null) _DCMdataset = new HLI.DataSet(); if(sopClassUID == "1.2.840.10008.1.3.10") { // Read the DICOMDIR dataset _DCMdataset.DvtkDataDataSet = Dvtk.DvtkDataHelper.ReadDataSetFromFile(dicomFile); _IsDICOMDIR = true; IsRefFilesReadCompleted = false; backgroundWorkerEditor.RunWorkerAsync(); string msg = "DICOMDIR read successfully.\n"; richTextBoxLog.AppendText(msg); } else { // Read the Media file dataset _DCMdataset = dcmFile.DataSet; _IsDICOMDIR = false; } string theInfoText; if(_DCMdataset != null) { _IsDCMFileLoaded = true; UpdateAttributeDataGrid(); UpdateFMIDataGrid(); theInfoText = string.Format("Media file {0} read successfully with Transfer Syntax: {1}.\n\n", dicomFile, tsStr); richTextBoxLog.AppendText(theInfoText); } else { theInfoText = string.Format("Error in reading Media file {0}\n\n", DCMFile); richTextBoxLog.AppendText(theInfoText); } } catch(Exception exception) { //Ask user to get more detailed logging string theErrorText = string.Format("Media file {0} could not be read:\n{1}\nDo you want to see detail logging?\n", dicomFile, exception.Message); DialogResult theDialogResult = MessageBox.Show(theErrorText, "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error); if (theDialogResult == DialogResult.Yes) { GetDetailedLogging(); } else { richTextBoxLog.AppendText("Select another Media file."); } _IsDCMFileLoaded = false; _DCMdataset = null; _FileMetaInfo = null; UpdateTitleBarText(); if (datasetBinding != null) datasetBinding.Clear(); } //Reset the variable _IsNewDCMFileLoaded = false; }
void SaveFileAsDefinedTS(string transferSyntax) { if (DCMFile == "") { richTextBoxLog.AppendText("There is no Media file to save, please select Media file.\n"); return; } try { SaveFileDialog saveAsDlg = new SaveFileDialog(); saveAsDlg.Filter = "DCM files (*.dcm) |*.dcm | All files (*.*)|*.*"; FileInfo dcmFileInfo = new FileInfo(DCMFile); saveAsDlg.InitialDirectory = dcmFileInfo.DirectoryName; saveAsDlg.FileName = dcmFileInfo.Name; saveAsDlg.Title = "Save DICOM file..."; if (saveAsDlg.ShowDialog() == DialogResult.OK) { richTextBoxLog.AppendText("Saving the modified Media file.\n"); _NewDCMFileName = saveAsDlg.FileName.Trim(); if (DCMFile != _NewDCMFileName) _IsSavedInNewDCMFile = true; DvtkData.Media.DicomFile dicomMediaFile = new DvtkData.Media.DicomFile(); // set up the file head DvtkData.Media.FileHead fileHead = new DvtkData.Media.FileHead(); // add the Transfer Syntax UID DvtkData.Dul.TransferSyntax tSyntax = new DvtkData.Dul.TransferSyntax(transferSyntax); fileHead.TransferSyntax = tSyntax; // set up the file meta information DvtkData.Media.FileMetaInformation fileMetaInformation = new DvtkData.Media.FileMetaInformation(); // add the FMI version fileMetaInformation.AddAttribute(DvtkData.Dimse.Tag.FILE_META_INFORMATION_VERSION.GroupNumber, DvtkData.Dimse.Tag.FILE_META_INFORMATION_VERSION.ElementNumber, VR.OB, 1, 2); // add the SOP Class UID fileMetaInformation.AddAttribute(DvtkData.Dimse.Tag.MEDIA_STORAGE_SOP_CLASS_UID.GroupNumber, DvtkData.Dimse.Tag.MEDIA_STORAGE_SOP_CLASS_UID.ElementNumber, VR.UI, _FileMetaInfo.MediaStorageSOPClassUID); // add the SOP Instance UID fileMetaInformation.AddAttribute(DvtkData.Dimse.Tag.MEDIA_STORAGE_SOP_INSTANCE_UID.GroupNumber, DvtkData.Dimse.Tag.MEDIA_STORAGE_SOP_INSTANCE_UID.ElementNumber, VR.UI, _FileMetaInfo.MediaStorageSOPInstanceUID); // add the Transfer Syntax UID fileMetaInformation.AddAttribute(DvtkData.Dimse.Tag.TRANSFER_SYNTAX_UID.GroupNumber, DvtkData.Dimse.Tag.TRANSFER_SYNTAX_UID.ElementNumber, VR.UI, transferSyntax); // add the Implemenation Class UID string implClassUID = ""; if(_FileMetaInfo.Exists("0x00020012")) { // Get the Transfer syntax HLI.Attribute implClassUIDAttr = _FileMetaInfo["0x00020012"]; implClassUID = implClassUIDAttr.Values[0]; } fileMetaInformation.AddAttribute(DvtkData.Dimse.Tag.IMPLEMENTATION_CLASS_UID.GroupNumber, DvtkData.Dimse.Tag.IMPLEMENTATION_CLASS_UID.ElementNumber, VR.UI, implClassUID); // add the Implementation Version Name string implClassVersion = ""; if(_FileMetaInfo.Exists("0x00020013")) { // Get the Transfer syntax HLI.Attribute implClassVersionAttr = _FileMetaInfo["0x00020013"]; implClassVersion = implClassVersionAttr.Values[0]; } fileMetaInformation.AddAttribute(DvtkData.Dimse.Tag.IMPLEMENTATION_VERSION_NAME.GroupNumber, DvtkData.Dimse.Tag.IMPLEMENTATION_VERSION_NAME.ElementNumber, VR.SH, implClassVersion); // set up the dicomMediaFile contents dicomMediaFile.FileHead = fileHead; dicomMediaFile.FileMetaInformation = fileMetaInformation; dicomMediaFile.DataSet = _DCMdataset.DvtkDataDataSet; // write the dicomMediaFile to file Dvtk.DvtkDataHelper.WriteDataSetToFile(dicomMediaFile, _NewDCMFileName); string theLogText = string.Format("Dataset {0} saved successfully with transfer syntax: {1}.\n\n", _NewDCMFileName, transferSyntax); richTextBoxLog.AppendText(theLogText); richTextBoxLog.ScrollToCaret(); richTextBoxLog.Focus(); //Cleanup the FMI & Dataset IsDCMFileModified = false; _IsAttributeGroupLengthDefined = false; _DCMdataset = null; _FileMetaInfo = null; if (_IsSavedInNewDCMFile) { FileInfo newDcmFileInfo = new FileInfo(_NewDCMFileName); _IsNewDCMFileLoaded = true; this.dirListBox.Path = newDcmFileInfo.DirectoryName; this.fileListBox.Path = this.dirListBox.Path; this.fileListBox.SelectedItem = newDcmFileInfo.Name; this.dirListBox.Refresh(); this.fileListBox.Refresh(); //Load the new Media file LoadDCMFile(_NewDCMFileName); } else { _IsNewDCMFileLoaded = false; this.dirListBox.Path = dcmFileInfo.DirectoryName; this.fileListBox.Path = this.dirListBox.Path; this.fileListBox.SelectedItem = dcmFileInfo.Name; //Load the new Media file LoadDCMFile(DCMFile); } UpdateTitleBarText(); } } catch (Exception exception) { string theErrorText; theErrorText = string.Format("Media file {0} could not be saved:\n{1}\n\n", _NewDCMFileName, exception.Message); richTextBoxLog.AppendText(theErrorText); richTextBoxLog.ScrollToCaret(); richTextBoxLog.Focus(); IsDCMFileModified = false; UpdateTitleBarText(); } }
private void buttonSave_Click(object sender, System.EventArgs e) { if(DCMFile == "") { richTextBoxLog.AppendText("There is no Media file to save, please select Media file.\n"); return; } try { SaveFileDialog saveAsDlg = new SaveFileDialog(); saveAsDlg.Filter = "DCM files (*.dcm)|*.dcm|All files (*.*)|*.*"; FileInfo dcmFileInfo = new FileInfo(DCMFile); saveAsDlg.InitialDirectory = dcmFileInfo.DirectoryName; saveAsDlg.FileName = dcmFileInfo.Name; saveAsDlg.Title = "Save Media file..."; if (saveAsDlg.ShowDialog () == DialogResult.OK) { richTextBoxLog.AppendText("Saving the modified Media file.\n"); _NewDCMFileName = saveAsDlg.FileName.Trim(); if(DCMFile != _NewDCMFileName) _IsSavedInNewDCMFile = true; string theLogText; if (!_IsDICOMDIR) { DicomFile dcmFile = new DicomFile(); // Add FMI as it is to Media file dcmFile.FileMetaInformation = _FileMetaInfo; dcmFile.FileMetaInformation.TransferSyntax = _TransferSyntax; // Add modified dataset to Media file dcmFile.DataSet = _DCMdataset; //Set attribute group length if (_IsAttributeGroupLengthDefined) dcmFile.AddGroupLength = true; dcmFile.Write(_NewDCMFileName); } else { //DicomDir dicomdir = new DicomDir(); //// Add FMI as it is to Media file //dicomdir.FileMetaInformation = _FileMetaInfo; //dicomdir.FileMetaInformation.TransferSyntax = _TransferSyntax; //// Add modified dataset to Media file //dicomdir.DataSet = _DCMdataset; //dicomdir.Write(_NewDCMFileName); } theLogText = string.Format("Media file {0} saved successfully.\n\n", _NewDCMFileName); richTextBoxLog.AppendText(theLogText); richTextBoxLog.ScrollToCaret(); richTextBoxLog.Focus(); //Cleanup the FMI & Dataset IsDCMFileModified = false; _IsAttributeGroupLengthDefined = false; _DCMdataset = null; _FileMetaInfo = null; if(_IsSavedInNewDCMFile) { FileInfo newDcmFileInfo = new FileInfo(_NewDCMFileName); _IsNewDCMFileLoaded = true; this.dirListBox.Path = newDcmFileInfo.DirectoryName; this.fileListBox.Path = this.dirListBox.Path; this.fileListBox.SelectedItem = newDcmFileInfo.Name; this.dirListBox.Refresh(); this.fileListBox.Refresh(); //Load the new Media file LoadDCMFile(_NewDCMFileName); } else { _IsNewDCMFileLoaded = false; this.dirListBox.Path = dcmFileInfo.DirectoryName; this.fileListBox.Path = this.dirListBox.Path; this.fileListBox.SelectedItem = dcmFileInfo.Name; //Load the new Media file LoadDCMFile(DCMFile); } UpdateTitleBarText(); } } catch(Exception exception) { string theErrorText; theErrorText = string.Format("Media file {0} could not be saved:\n{1}\n\n", _NewDCMFileName, exception.Message); richTextBoxLog.AppendText(theErrorText); richTextBoxLog.ScrollToCaret(); richTextBoxLog.Focus(); IsDCMFileModified = false; UpdateTitleBarText(); } }
public DICOMEditor() { // // Required for Windows Form Designer support // InitializeComponent(); // Initialize the Dvtk library Dvtk.Setup.Initialize(); _DCMdataset = new HLI.DataSet(); _FileMetaInfo = new FileMetaInformation(); _AttributesInfoForDataGrid = new ArrayList(); _FMIForDataGrid = new ArrayList(); InitializeDatasetGrid(); InitializeFMIGrid(); // Get the session context ThreadManager threadMgr = new ThreadManager(); _MainThread = new MainThread(); _MainThread.Initialize(threadMgr); // Subscribe to Dvtk Activity report handler activityReportEventHandler = new Dvtk.Events.ActivityReportEventHandler(OnActivityReportEvent); // Subscribe to Sniffer Activity report handler activityLoggingDelegate = new appendTextToActivityLogging_ThreadSafe_Delegate(this.AppendTextToActivityLogging_ThreadSafe); // Provide functionality to open application with Media file or Directory // which contains Media files if(dcmFileOrDirToBeOpened != "") { DirectoryInfo userDirInfo = new DirectoryInfo(dcmFileOrDirToBeOpened.Trim()); if(userDirInfo.Exists) { //It's a directory contains Media files this.dirListBox.Path = userDirInfo.FullName; this.fileListBox.Path = this.dirListBox.Path; } else { //It's a Media file FileInfo dcmFileInfo = new FileInfo(dcmFileOrDirToBeOpened.Trim()); this.dirListBox.Path = dcmFileInfo.DirectoryName; this.fileListBox.Path = this.dirListBox.Path; this.fileListBox.SelectedItem = dcmFileInfo.Name; } } }
/// <summary> /// Constructor /// </summary> public DCMEditor() { // // Required for Windows Form Designer support // InitializeComponent(); fileTypeCombo.DropDownStyle = ComboBoxStyle.DropDownList; fileTypeCombo.SelectedIndex = 0; _DCMdataset = new HLI.DataSet(); _FileMetaInfo = new FileMetaInformation(); _AttributesInfoForDataGrid = new ArrayList(); _FMIForDataGrid = new ArrayList(); InitializeDatasetGrid(); InitializeFMIGrid(); // Get the session context & load definition file ThreadManager threadMgr = new ThreadManager(); _MainThread = new MainThread(); _MainThread.Initialize(threadMgr); }
void LoadDCMFile(string dicomFile) { DCMFile = dicomFile; try { // Load the Definition Files foreach (string defFile in _DefFiles) { if(!_MainThread.Options.LoadDefinitionFile(defFile)) { string theWarningText = string.Format("The Definition file {0} could not be loaded.\n", defFile); richTextBoxLog.AppendText(theWarningText); } } _DefFiles.Clear(); // Set the Data directory _MainThread.Options.DataDirectory = _DataDirectory; // Read the DCM File DicomFile dcmFile = new DicomFile(); dcmFile.DataSet.UnVrDefinitionLookUpWhenReading = false; dcmFile.Read(_DCMFileName, _MainThread); // Get the FMI from the selected DCM file // Get the FMI from the selected DCM file if(_FileMetaInfo == null) _FileMetaInfo = new FileMetaInformation(); _FileMetaInfo = dcmFile.FileMetaInformation; string tsStr; if(_FileMetaInfo.Exists("0x00020010")) { // Get the Transfer syntax HLI.Attribute tranferSyntaxAttr = _FileMetaInfo["0x00020010"]; _TransferSyntax = tranferSyntaxAttr.Values[0]; tsStr = _TransferSyntax; } else { _TransferSyntax = "1.2.840.10008.1.2.1"; tsStr = "Undefined, the default transfer syntax will Explicit VR Little Endian"; _FileMetaInfo.Set("0x00020010",VR.UI,"1.2.840.10008.1.2.1"); } // Get the Data set from the selected DCM file if(_DCMdataset == null) _DCMdataset = new HLI.DataSet(); _DCMdataset = dcmFile.DataSet; string theInfoText; if(_DCMdataset != null) { UpdateAttributeDataGrid(); UpdateFMIDataGrid(); theInfoText = string.Format("DCM file {0} read successfully with Transfer Syntax {1}.\n\n", _DCMFileName,tsStr); richTextBoxLog.AppendText(theInfoText); } else { theInfoText = string.Format("Error in reading DCM file {0}\n\n", _DCMFileName); richTextBoxLog.AppendText(theInfoText); } } catch(Exception exception) { string theErrorText; theErrorText = string.Format("DCM file {0} could not be read:\n{1}\n\n", _DCMFileName, exception.Message); richTextBoxLog.AppendText(theErrorText); _DCMdataset = null; _FileMetaInfo = null; //dataGridAttributes.SetDataBinding(null, ""); } //Reset the variable _IsNewDCMFileLoaded = false; }
private void buttonSave_Click(object sender, System.EventArgs e) { if(_DCMFileName == "") { richTextBoxLog.AppendText("There is no DCM File to save, please select DCM file.\n"); return; } richTextBoxLog.AppendText("Saving the modified DCM file.\n"); try { SaveFileDialog saveAsDlg = new SaveFileDialog(); saveAsDlg.Filter = "DCM files (*.dcm)|*.dcm|All files (*.*)|*.*"; FileInfo dcmFileInfo = new FileInfo(_DCMFileName); saveAsDlg.InitialDirectory = dcmFileInfo.DirectoryName; saveAsDlg.FileName = dcmFileInfo.Name; saveAsDlg.Title = "Save DCM File..."; if (saveAsDlg.ShowDialog () == DialogResult.OK) { _NewDCMFileName = saveAsDlg.FileName.Trim(); if(_DCMFileName != _NewDCMFileName) _IsSavedInNewDCMFile = true; _DCMFileName = saveAsDlg.FileName; DicomFile dcmFile = new DicomFile(); // Add FMI as it is to DCM file dcmFile.FileMetaInformation = _FileMetaInfo; // Add modified dataset to DCM file dcmFile.DataSet = _DCMdataset; string theLogText; dcmFile.Write(_NewDCMFileName); theLogText = string.Format("DCM file {0} saved successfully.\n\n", _NewDCMFileName); richTextBoxLog.AppendText(theLogText); richTextBoxLog.ScrollToCaret(); _IsDCMFileChanged = false; _DCMdataset = null; _FileMetaInfo = null; if(_IsSavedInNewDCMFile) { FileInfo newDcmFileInfo = new FileInfo(_NewDCMFileName); _IsNewDCMFileLoaded = true; this.dirListBox.Path = newDcmFileInfo.DirectoryName; this.fileListBox.Path = this.dirListBox.Path; this.fileListBox.SelectedItem = newDcmFileInfo.Name; this.dirListBox.Refresh(); this.fileListBox.Refresh(); //Load the new DCM file LoadDCMFile(_NewDCMFileName); } else { _IsNewDCMFileLoaded = false; this.dirListBox.Path = dcmFileInfo.DirectoryName; this.fileListBox.Path = this.dirListBox.Path; this.fileListBox.SelectedItem = dcmFileInfo.Name; //Load the new DCM file LoadDCMFile(_DCMFileName); } } } catch(Exception exception) { string theErrorText; theErrorText = string.Format("DCM file {0} could not be saved:\n{1}\n\n", _NewDCMFileName, exception.Message); richTextBoxLog.AppendText(theErrorText); richTextBoxLog.ScrollToCaret(); _IsDCMFileChanged = false; } }
public void TearDown() { this.fileMetaInformation = null; }
public void SetUp() { this.fileMetaInformation = new FileMetaInformation(); }
public void TearDown() { this.fileMetaInformation = null; }
public void SetUp() { this.fileMetaInformation = new FileMetaInformation(); }