// DicomVidDoc.cpp : implementation of the CDicomVidDoc class // #include "stdafx.h" #include "DICOMVid.h" #include "NewDlg.h" #include "Document.h" #include "MainFrm.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #define LEAD_IMPLEMENTATION_CLASS_UID "1.2.840.114257.0.1" #define LEAD_IMPLEMENTATION_VERSION_NAME "LEADTOOLS Demo" #define LEAD_FILE_SET_ID "Example" ///////////////////////////////////////////////////////////////////////////// // CDicomVidDoc IMPLEMENT_DYNCREATE(CDicomVidDoc, CDocument) BEGIN_MESSAGE_MAP(CDicomVidDoc, CDocument) //{{AFX_MSG_MAP(CDicomVidDoc) ON_COMMAND(ID_FILE_OPEN, OnFileOpen) ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs) ON_COMMAND(ID_FILE_PRINT, OnFilePrint) ON_COMMAND(ID_FILE_NEWDICOMFILE, OnFileNewdicomfile) ON_COMMAND(ID_FILE_CLOSEDICOMFILE, OnFileClosedicomfile) ON_UPDATE_COMMAND_UI(ID_FILE_CLOSEDICOMFILE, OnUpdateFileClosedicomfile) ON_UPDATE_COMMAND_UI(ID_FILE_SAVE_AS, OnUpdateFileSaveAs) ON_UPDATE_COMMAND_UI(ID_FILE_NEWDICOMFILE, OnUpdateFileNewdicomfile) ON_UPDATE_COMMAND_UI(ID_FILE_OPEN, OnUpdateFileOpen) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CDicomVidDoc construction/destruction CDicomVidDoc::CDicomVidDoc() { // TODO: add one-time construction code here m_bDataSetInitialized = FALSE; m_pDICOMIOD = NULL; m_nInstanceNumber = 1; } CDicomVidDoc::~CDicomVidDoc() { } BOOL CDicomVidDoc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; // TODO: add reinitialization code here // (SDI documents will reuse this document) return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CDicomVidDoc serialization void CDicomVidDoc::Serialize(CArchive& ar) { if (ar.IsStoring()) { // TODO: add storing code here } else { // TODO: add loading code here } } ///////////////////////////////////////////////////////////////////////////// // CDicomVidDoc diagnostics #ifdef _DEBUG void CDicomVidDoc::AssertValid() const { CDocument::AssertValid(); } void CDicomVidDoc::Dump(CDumpContext& dc) const { CDocument::Dump(dc); } #endif //_DEBUG L_BOOL CDicomVidDoc::CanInsertCompressedImage() { pDICOMELEMENT pElement =NULL; pElement = m_DS.FindFirstElement(NULL, TAG_TRANSFER_SYNTAX_UID, FALSE); if(pElement) { L_CHAR *pszText = NULL; L_UINT32 nLength; nLength = m_DS.GetConvertValue(pElement, NULL); pszText = (L_CHAR *)malloc(nLength); if(NULL != pszText) { m_DS.GetConvertValue(pElement, pszText); if((strcmp(pszText,UID_IMPLICIT_VR_LITTLE_ENDIAN) == 0)|| (strcmp(pszText,UID_EXPLICIT_VR_BIG_ENDIAN) == 0)) { free(pszText); return FALSE; } else { free(pszText); return TRUE; } free(pszText); } } return TRUE; } L_UINT16 CDicomVidDoc::ChangeDSToAcceptCompressed() { TCHAR szPath[MAX_PATH]; TCHAR szFileName[MAX_PATH]; L_UINT16 nRet; pDICOMELEMENT pPixelDataElement= NULL; //If the dataset can already accept compressed images then don't do anything if(TRUE == CanInsertCompressedImage()) { return DICOM_SUCCESS; } // Get a temp file name GetTempPath (sizeof (szPath) / sizeof (TCHAR), szPath); UINT uRet = GetTempFileName (szPath, _T ("tmp"), 0, szFileName); if(0==uRet) { return DICOM_ERROR_MEMORY; } // Delete the pixel data element pPixelDataElement = m_DS.FindFirstElement(NULL, TAG_PIXEL_DATA, FALSE); if(pPixelDataElement) { m_DS.DeleteElement(pPixelDataElement); pPixelDataElement= NULL; } // Save the dataset into a temp file and pass // proper flags to make it Explicit Little Endian nRet = m_DS.SaveDS( szFileName, DS_EXPLICIT_VR | DS_LITTLE_ENDIAN | DS_METAHEADER_PRESENT | DS_GROUP_LENGTHS ); if(DICOM_SUCCESS != nRet) { return nRet; } // Reset the data set and then load the temp file we saved m_DS.ResetDS(); nRet = m_DS.LoadDS(szFileName,DS_LOAD_CLOSE); if(DICOM_SUCCESS != nRet) { DeleteFile(szFileName); return nRet; } // Clean Up! DeleteFile(szFileName); return DICOM_SUCCESS; } ///////////////////////////////////////////////////////////////////////////// // CDicomVidDoc commands // Open an existing DICOM file void CDicomVidDoc::OnFileOpen() { TCHAR szFilters[] =_T ("DICOM Files (*.dic)|*.dic|DCM Files (*.dcm)|*.dcm|All files (*.*)|*.*||"); L_UINT16 nRet; L_INT nLoadFlags = 0; switch(CheckDirtyFlag()) { case IDYES : OnFileSaveAs(); break; case IDNO : break; case IDCANCEL : return ; break; } CFileDialog dlg ( TRUE, _T ("dic"), _T ("*.dic"), OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilters); if (dlg.DoModal () == IDOK) { CWaitCursor Wait; Reset(); // Load Data Set from this file. nRet = m_DS.LoadDS((L_CHAR *)(LPCSTR)dlg.GetPathName(), nLoadFlags); if (nRet != DICOM_SUCCESS) { DisplayError(nRet); return; } // Is this IOD in our list ? if((m_pDICOMIOD =GetDSIOD(&m_DS)) == NULL) { m_DS.ResetDS(); AfxMessageBox("This DICOM file does not support multi-frame images", MB_ICONSTOP); UpdateAllViews (NULL); return; } nRet = ChangeDSToAcceptCompressed(); if (nRet != DICOM_SUCCESS) { Reset(); UpdateAllViews (NULL); DisplayError(nRet); return; } m_bDataSetInitialized = TRUE; CMainFrame * pMainFrame = (CMainFrame * )AfxGetMainWnd( ); if(pMainFrame) { pMainFrame->SetDicomDS(&(GetActiveDS())); } // Update the elements tree UpdateAllViews (NULL); } } // Save DICOM file void CDicomVidDoc::OnFileSaveAs() { L_UINT16 nRet; TCHAR szFilters[] =_T ("DICOM Files (*.dic)|*.dic|All files (*.*)|*.*||"); CFileDialog dlg ( FALSE, _T ("dic"), _T ("*.dic"), OFN_OVERWRITEPROMPT, szFilters); // Get file name if (dlg.DoModal () == IDOK) { CWaitCursor Wait; //Save dataset into file nRet = m_DS.SaveDS((L_CHAR *)(LPCTSTR)dlg.GetPathName(), DS_GROUP_LENGTHS|DS_METAHEADER_PRESENT); if (nRet != DICOM_SUCCESS) { DisplayError(nRet); return; } SetModifiedFlag(FALSE); } } L_VOID CDicomVidDoc::Reset(L_VOID) { m_DS.ResetDS(); m_pDICOMIOD = NULL; m_bDataSetInitialized = FALSE; CMainFrame * pMainFrame = (CMainFrame * )AfxGetMainWnd( ); if(pMainFrame) { pMainFrame->SetDicomDS(NULL); } SetModifiedFlag(FALSE); } void CDicomVidDoc::OnFilePrint() { // TODO: Add your command handler code here } // Convert error code into a string L_VOID CDicomVidDoc ::ConvertError(L_INT nError, CString &strError) { L_INT i; L_CHAR *p; strError = ""; for (i = 0, p = NULL; i < sizeof(m_Error) / sizeof(m_Error[0]); i++) { if (nError == m_Error[i].nCode) { p = m_Error[i].pszText; break; } } if (p == NULL) { strError.Format("%d", nError); } else { strError = p; } } L_VOID CDicomVidDoc ::DisplayError(L_INT nError) { CString strError; ConvertError(nError, strError); AfxMessageBox(strError, MB_ICONSTOP); } // Create a new DICOM file void CDicomVidDoc::OnFileNewdicomfile() { CDicomNewDlg NewDicomDlg; switch(CheckDirtyFlag()) { case IDYES : OnFileSaveAs(); break; case IDNO : break; case IDCANCEL : return ; break; } //Get class (IOD) for the new DICOM file if (NewDicomDlg.DoModal() == IDOK) { CWaitCursor Wait; // Prepare a new data set Reset(); if(!CreateDICOMFileFromTemplate(NewDicomDlg.m_nClass)) { m_DS.InitDS(NewDicomDlg.m_nClass, NewDicomDlg.m_nFlags); } // Remove any optional elements from // the dataset and set some default values CleanDSAndSetDefaultValues(NewDicomDlg.m_nClass,&m_DS,FALSE); // Is this IOD in our list ? if((m_pDICOMIOD =GetDSIOD(&m_DS)) == NULL) { AfxMessageBox("Could not create a new DICOM file", MB_ICONSTOP); return ; } //Yes we have a valid dataset m_bDataSetInitialized = TRUE; CMainFrame * pMainFrame = (CMainFrame * )AfxGetMainWnd( ); if(pMainFrame) { pMainFrame->SetDicomDS(&(GetActiveDS())); } // Update the elements tree UpdateAllViews (NULL); SetModifiedFlag(TRUE); } } // Create a template Presentation state DS and load it into m_CurPSDataSet L_BOOL CDicomVidDoc::CreateDICOMFileFromTemplate(L_UINT32 uClass) { DWORD dwID; switch(uClass) { case CLASS_VIDEO_ENDOSCOPIC_IMAGE_STORAGE: dwID = IDR_VIDEO_ENDOSCOPY; break; case CLASS_VIDEO_MICROSCOPIC_IMAGE_STORAGE: dwID = IDR_VIDEO_MICROSCOPY; break; case CLASS_VIDEO_PHOTOGRAPHIC_IMAGE_STORAGE: dwID = IDR_VIDEO_PHOTOGRAPHY; break; case CLASS_SC_MULTI_FRAME_TRUE_COLOR_IMAGE_STORAGE: dwID = IDR_MULTI_FRAME_SC; break; default: return FALSE; } HRSRC hRsrc = FindResource(AfxGetInstanceHandle(), MAKEINTRESOURCE(dwID), "DICOM"); if (!hRsrc) { return FALSE; } DWORD dwResLen = SizeofResource(AfxGetInstanceHandle(), hRsrc) ; if (dwResLen == 0) { return FALSE; } HGLOBAL hGlobal = LoadResource(AfxGetInstanceHandle(), hRsrc); if (!hGlobal) { return FALSE; } L_CHAR* pszTemplatePS = (L_CHAR*)LockResource(hGlobal); if (!pszTemplatePS) { return FALSE; } L_CHAR szTempPath[MAX_PATH] = "\0"; DWORD dWord = GetTempPath(sizeof(szTempPath), szTempPath); if(dWord == 0) { return FALSE; } L_CHAR* pszFullName = lstrcat(szTempPath, "TemplatePS.PRE"); if (!pszFullName) { return FALSE; } HANDLE hFile = CreateFile(pszFullName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if(hFile == INVALID_HANDLE_VALUE) { return FALSE; } DWORD dwWritten; if (!WriteFile(hFile, pszTemplatePS, dwResLen, &dwWritten, NULL)) { DeleteFile(pszFullName); return FALSE; } CloseHandle(hFile); // Loading the DS if (m_DS.LoadDS(pszFullName, DS_LOAD_CLOSE) != DICOM_SUCCESS) { return FALSE; } DeleteFile(pszFullName); return TRUE; } L_INT CDicomVidDoc::IsEmptySequence ( pDICOMELEMENT pElementSequence, LDicomDS *pDicomDataSet ) { pDICOMELEMENT pElementItem; pDICOMELEMENT pElement; int bEmpty; bEmpty = TRUE; pElementItem = pDicomDataSet->GetChildElement(pElementSequence, TRUE); while (pElementItem) { pElement = pDicomDataSet->GetChildElement(pElementItem, TRUE); while (pElement) { // If a sequence, make a recursive call if (pElement->nLength == ELEMENT_LENGTH_MAX) bEmpty = bEmpty && IsEmptySequence(pElement,pDicomDataSet); else if (pElement->nLength != 0) { bEmpty = FALSE; } pElement = pDicomDataSet->GetNextElement(pElement, TRUE, TRUE); } pElementItem = pDicomDataSet->GetNextElement(pElementItem, TRUE, TRUE); } return bEmpty; } // Delete any optional element which has no value void CDicomVidDoc::DeleteEmptyElementsType3(L_UINT32 uClass,LDicomDS *pDicomDataSet) { pDICOMELEMENT pElementPrev = NULL; pDICOMELEMENT pElement; pDICOMIOD pIODClass = LDicomIOD::FindClass(uClass); if (pIODClass) { pDICOMIOD pIOD; pElement = pDicomDataSet->GetFirstElement(NULL, FALSE, TRUE); pElementPrev = NULL; while (pElement) { pIOD = LDicomIOD::Find(pIODClass, pElement->nTag, IOD_TYPE_ELEMENT, FALSE); if ((pIOD) && (pIOD->nUsage == IOD_USAGE_3)) { // nLength==0 means (1) Sequence or (2)Empty Element // Case 1: Sequence if (pElement->nLength == ELEMENT_LENGTH_MAX) { int bEmptySequence = IsEmptySequence(pElement,pDicomDataSet); if (bEmptySequence) { //if deleting the first element, pElementPrev is NULL //Therefore we must call GetFirstElement pDicomDataSet->DeleteElement(pElement); pElement = pElementPrev; if (!pElement) pElement = pDicomDataSet->GetFirstElement(NULL, FALSE, TRUE); } } // Case 2: Empty Element else if (pElement->nLength == 0) { //if deleting the first element, pElementPrev is NULL //Therefore we must call GetFirstElement pDicomDataSet->DeleteElement(pElement); pElement = pElementPrev; if (!pElement) pElement = pDicomDataSet->GetFirstElement(NULL, FALSE, TRUE); } } pElementPrev = pElement; pElement = pDicomDataSet->GetNextElement(pElement, FALSE, TRUE); } } } L_INT CDicomVidDoc::IsEmptyModule(L_UINT32 uModule,LDicomDS *pDicomDataSet) { int bEmpty = TRUE; pDICOMMODULE pModule; pModule = pDicomDataSet->FindModule(uModule); if (pModule) bEmpty = IsEmptyModule(pModule,pDicomDataSet); return bEmpty; } L_INT CDicomVidDoc::IsEmptyModule(pDICOMMODULE pModule,LDicomDS *pDicomDataSet) { if (pModule == NULL) return TRUE; int bEmpty = TRUE; for (L_UINT32 i=0; i< pModule->nCount; i++) { if (pModule->pElement[i]->nLength == ELEMENT_LENGTH_MAX) bEmpty = bEmpty && IsEmptySequence(pModule->pElement[i],pDicomDataSet); else if (pModule->pElement[i]->nLength != 0) { bEmpty = FALSE; } } return bEmpty; } void CDicomVidDoc:: DeleteEmptyModulesOptional(L_UINT32 uClass,LDicomDS *pDicomDataSet) { int nCountModule = LDicomIOD::GetCountModule(uClass); pDICOMIOD pIOD; for (int i=0; inUsage == IOD_USAGE_U)) { pDICOMMODULE pModule = pDicomDataSet->FindModule(pIOD->nCode); if ((pModule) && IsEmptyModule(pModule,pDicomDataSet)) pDicomDataSet->DeleteModule(pIOD->nCode); } } } // Remove all empty optional elements void CDicomVidDoc::CleanDataSet(L_UINT32 uClass,LDicomDS *pDicomDataSet) { DeleteEmptyElementsType3(uClass,pDicomDataSet); DeleteEmptyModulesOptional(uClass,pDicomDataSet); } void CDicomVidDoc::CleanDSAndSetDefaultValues ( L_UINT32 uClass, LDicomDS *pDicomDataSet, L_BOOL bInsertMissingElements ) { CleanDataSet(uClass,pDicomDataSet); // Set some default values SetDSDefaultValues(pDicomDataSet,bInsertMissingElements); } L_BOOL CDicomVidDoc:: CanUpdateElementValue(LDicomDS *pDicomDataSet,pDICOMELEMENT pElement) { if(pElement && pDicomDataSet->GetConvertValue(pElement, NULL)) { switch (pElement->nTag) { case TAG_MEDIA_STORAGE_SOP_CLASS_UID: case TAG_SOP_CLASS_UID: case TAG_MODALITY: return FALSE; } } return TRUE; } // Set some default values from a predefined table(m_DefaultElementValues) void CDicomVidDoc::SetDSDefaultValues(LDicomDS *pDicomDataSet,L_BOOL bInsertMissingElements) { int i; pDICOMTAG pTag; L_UINT16 nVR; pDICOMELEMENT pElement; SYSTEMTIME Time; char szValue[80]; GetSystemTime( &Time ); // Loop through all the elements in the default value table for (i = 0; i < sizeof(m_DefaultElementValues) / sizeof(m_DefaultElementValues[0]); i++) { pTag = L_DicomFindTag(m_DefaultElementValues[i].nTag); nVR = (pTag != NULL) ? pTag->nVR : VR_UN; pElement = NULL; pElement = pDicomDataSet->FindFirstElement(NULL, m_DefaultElementValues[i].nTag, FALSE); if (pElement == NULL) { // If the element is missing and the user of // this functions wants to add it , then add it if(bInsertMissingElements) { pElement = pDicomDataSet->InsertElement( NULL, FALSE, m_DefaultElementValues[i].nTag, nVR, FALSE, ELEMENT_INDEX_MAX); } } if (m_DefaultElementValues[i].nTag == TAG_DATE_OF_SECONDARY_CAPTURE) { sprintf(szValue, "%02d/%02d/%04d", Time.wMonth, Time.wDay, Time.wYear); if(pElement) { pDicomDataSet->FreeValue(pElement); pDicomDataSet->SetConvertValue(pElement, szValue, 1); } } else if (m_DefaultElementValues[i].nTag == TAG_TIME_OF_SECONDARY_CAPTURE) { sprintf(szValue, "%02d:%02d:%04d.0", Time.wHour, Time.wMinute, Time.wSecond); if(pElement) { pDicomDataSet->FreeValue(pElement); pDicomDataSet->SetConvertValue(pElement, szValue, 1); } } else { if(pElement&& CanUpdateElementValue(pDicomDataSet,pElement)) { // Set the value for this element pDicomDataSet->FreeValue(pElement); pDicomDataSet->SetConvertValue(pElement, m_DefaultElementValues[i].pszValue, 1); } } } // Set different UIDs for this dataset SetInstanceUIDs(pDicomDataSet); //Set instance numbers SetInstanceNumbers(pDicomDataSet,m_nInstanceNumber++); // Update study date and time SetStudyDateAndTime(pDicomDataSet); // Set meta header info InsertMetaHeader(pDicomDataSet); } //Generate a UID const TCHAR * const CDicomVidDoc::CreateGUID() { SYSTEMTIME SystemTime; FILETIME FileTime; GetSystemTime(&SystemTime); SystemTimeToFileTime(&SystemTime,&FileTime); DWORD Tick=GetTickCount(); DWORD HighWord=FileTime.dwHighDateTime+0x146BF4; wsprintf( m_InstanceGUID, TEXT("1.2.840.114257.0.1%010u%05u%05u%05u%05u%05u%05u"), FileTime.dwLowDateTime, LOWORD(HighWord), HIWORD(HighWord |0x10000000), LOWORD(rand()), HIWORD(Tick), LOWORD(Tick), LOWORD(rand())); return m_InstanceGUID ; } void CDicomVidDoc:: SetInstanceUIDs(LDicomDS *pDicomDataSet) { pDICOMELEMENT pElement; // Set STUDY INSTANCE UID pElement = pDicomDataSet->FindFirstElement(NULL, TAG_STUDY_INSTANCE_UID, FALSE); if (pElement == NULL) { pElement = pDicomDataSet->InsertElement(NULL, FALSE, TAG_STUDY_INSTANCE_UID, VR_UI, FALSE, 0); } pDicomDataSet->FreeValue(pElement); pDicomDataSet->SetConvertValue(pElement, (char*) CreateGUID(), 1); // Set SERIES INSTANCE UID pElement = pDicomDataSet->FindFirstElement(NULL, TAG_SERIES_INSTANCE_UID, FALSE); if (pElement == NULL) { pElement = pDicomDataSet->InsertElement(NULL, FALSE, TAG_SERIES_INSTANCE_UID, VR_UI, FALSE, 0); } pDicomDataSet->FreeValue(pElement); pDicomDataSet->SetConvertValue(pElement, (char*) CreateGUID(), 1); // Set SOP INSTANCE UID const char * pGUID = CreateGUID(); pElement = pDicomDataSet->FindFirstElement(NULL, TAG_SOP_INSTANCE_UID, FALSE); if (pElement == NULL) { pElement = pDicomDataSet->InsertElement(NULL, FALSE, TAG_SOP_INSTANCE_UID, VR_UI, FALSE, 0); } pDicomDataSet->FreeValue(pElement); pDicomDataSet->SetConvertValue(pElement, (char * )pGUID, 1); // Media Storage SOP Instance UID pElement = pDicomDataSet->FindFirstElement(NULL, TAG_MEDIA_STORAGE_SOP_INSTANCE_UID, FALSE); if (pElement == NULL) { pElement = pDicomDataSet->InsertElement(NULL, FALSE, TAG_MEDIA_STORAGE_SOP_INSTANCE_UID, VR_UI, FALSE, 0); } pDicomDataSet->FreeValue(pElement); pDicomDataSet->SetConvertValue(pElement, (char * )pGUID, 1); } L_VOID CDicomVidDoc :: SetInstanceNumbers(LDicomDS *pDicomDataSet, L_INT nInstanceNumber) { pDICOMELEMENT pElement; char szValue[32]; sprintf(szValue, "%d", nInstanceNumber); // Series number pElement = pDicomDataSet->FindFirstElement(NULL, TAG_SERIES_NUMBER, FALSE); if(pElement) { pDicomDataSet->FreeValue(pElement); pDicomDataSet->SetConvertValue(pElement, szValue, 1); } // Instance number pElement = pDicomDataSet->FindFirstElement(NULL, TAG_INSTANCE_NUMBER, FALSE); if(pElement) { pDicomDataSet->FreeValue(pElement); pDicomDataSet->SetConvertValue(pElement, szValue, 1); } // Study ID pElement = pDicomDataSet->FindFirstElement(NULL, TAG_STUDY_ID, FALSE); if(pElement) { pDicomDataSet->FreeValue(pElement); pDicomDataSet->SetConvertValue(pElement, szValue, 1); } sprintf(szValue, "854125%d", nInstanceNumber); // Accession number pElement = pDicomDataSet->FindFirstElement(NULL, TAG_ACCESSION_NUMBER, FALSE); if(pElement) { pDicomDataSet->FreeValue(pElement); pDicomDataSet->SetConvertValue(pElement, szValue, 1); } } void CDicomVidDoc:: SetStudyDateAndTime(LDicomDS *pDicomDataSet) { SYSTEMTIME Time; char szValue[64]; pDICOMELEMENT pElement; GetLocalTime(&Time); // Set study date pElement = pDicomDataSet->FindFirstElement(NULL, TAG_STUDY_DATE, FALSE); if (pElement) { sprintf(szValue, "%02d/%02d/%04d", Time.wMonth, Time.wDay, Time.wYear); pDicomDataSet->FreeValue(pElement); pDicomDataSet->SetConvertValue(pElement, szValue, 1); } // Set content date pElement = pDicomDataSet->FindFirstElement(NULL, TAG_CONTENT_DATE, FALSE); if (pElement) { pDicomDataSet->FreeValue(pElement); pDicomDataSet->SetConvertValue(pElement, szValue, 1); } // Set study time pElement = pDicomDataSet->FindFirstElement(NULL, TAG_STUDY_TIME, FALSE); if (pElement) { sprintf(szValue, "%02d:%02d:%04d.0", Time.wHour, Time.wMinute, Time.wSecond); pDicomDataSet->FreeValue(pElement); pDicomDataSet->SetConvertValue(pElement, szValue, 1); } // Set content time pElement = pDicomDataSet->FindFirstElement(NULL, TAG_CONTENT_TIME, FALSE); if (pElement) { pDicomDataSet->FreeValue(pElement); pDicomDataSet->SetConvertValue(pElement, szValue, 1); } } L_VOID CDicomVidDoc::InsertMetaHeader(LDicomDS *pDS) { pDICOMELEMENT pElement; // Add File Meta Information Version pElement = pDS->FindFirstElement(NULL, TAG_FILE_META_INFORMATION_VERSION, FALSE); if (pElement == NULL) { pElement = pDS->InsertElement(NULL, FALSE, TAG_FILE_META_INFORMATION_VERSION, VR_OB, FALSE, 0); } if(pElement) { L_CHAR cValue[2] = {0x00, 0x01}; pDS->SetCharValue(pElement, cValue, 2); } // Implementation Class UID pElement = pDS->FindFirstElement(NULL, TAG_IMPLEMENTATION_CLASS_UID, FALSE); if (pElement == NULL) { pElement = pDS->InsertElement(NULL, FALSE, TAG_IMPLEMENTATION_CLASS_UID, VR_UI, FALSE, 0); } if(pElement) { pDS->SetConvertValue(pElement, LEAD_IMPLEMENTATION_CLASS_UID, 1); } // Implementation Version Name pElement = pDS->FindFirstElement(NULL, TAG_IMPLEMENTATION_VERSION_NAME, FALSE); if (pElement == NULL) { pElement = pDS->InsertElement(NULL, FALSE, TAG_IMPLEMENTATION_VERSION_NAME, VR_SH, FALSE, 0); } if(pElement) { pDS->SetConvertValue(pElement, LEAD_IMPLEMENTATION_VERSION_NAME , 1); } } int CDicomVidDoc::CheckDirtyFlag() { if(IsModified()) { return AfxMessageBox("Do you want to save the changes you made to this Data Set?",MB_YESNOCANCEL); } return IDNO; } BOOL CDicomVidDoc::CanCloseFrame(CFrameWnd* pFrame) { switch(CheckDirtyFlag()) { case IDYES : OnFileSaveAs(); return TRUE; break; case IDNO : return TRUE; break; case IDCANCEL : return FALSE; break; } return TRUE; } void CDicomVidDoc::OnFileClosedicomfile() { switch(CheckDirtyFlag()) { case IDYES : OnFileSaveAs(); break; case IDNO : break; case IDCANCEL : return ; break; } Reset(); UpdateAllViews (NULL); } void CDicomVidDoc::OnUpdateFileClosedicomfile(CCmdUI* pCmdUI) { pCmdUI->Enable(m_bDataSetInitialized && !IsCapturing()); } void CDicomVidDoc::OnUpdateFileSaveAs(CCmdUI* pCmdUI) { pCmdUI->Enable(m_bDataSetInitialized && !IsCapturing()); } L_BOOL CDicomVidDoc::IsCapturing() { CMainFrame * pMainFrame = (CMainFrame * )AfxGetMainWnd( ); if(pMainFrame) { return pMainFrame->IsCapturing(); } return FALSE; } void CDicomVidDoc::OnUpdateFileNewdicomfile(CCmdUI* pCmdUI) { pCmdUI->Enable(!IsCapturing()); } void CDicomVidDoc::OnUpdateFileOpen(CCmdUI* pCmdUI) { pCmdUI->Enable(!IsCapturing()); }