//--------------------------------------------------------------------------- #include #pragma hdrstop #include "VR_Form.h" #include "MainForm.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TVR_Frm *VR_Frm; //--------------------------------------------------------------------------- __fastcall TVR_Frm::TVR_Frm(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TVR_Frm::DisplayItem(void) { int nRestrict; if(LEADDicom1->CurrentVR == 0) return; /* display the items information */ Edit_Code->Text = MainFrm->VRCodeDesc(LEADDicom1->CurrentVR->Code); Edit_Name->Text = LEADDicom1->CurrentVR->Name; Edit_Length->Text = FloatToStr(LEADDicom1->CurrentVR->Length); nRestrict = LEADDicom1->CurrentVR->Restrict; nRestrict = nRestrict & ~VR_BINARY; nRestrict = nRestrict & ~VR_STRING; nRestrict = nRestrict & ~VR_TEXT; switch(nRestrict) { case VR_FIXED: Edit_Restrict->Text = "Fixed"; break; case VR_MAXIMUM: Edit_Restrict->Text = "Maximum"; break; case VR_MAXIMUM_GROUP: Edit_Restrict->Text = "Maximum Group"; break; case VR_ANY: Edit_Restrict->Text = "Any Length"; break; case VR_NOT_APPLICABLE: Edit_Restrict->Text = "Not Applicable"; break; case VR_MAX: Edit_Restrict->Text = "Max"; default: Edit_Restrict->Text = IntToStr(LEADDicom1->CurrentVR->Restrict); break; } Edit_UnitSize->Text = IntToStr(LEADDicom1->CurrentVR->UnitSize); } void __fastcall TVR_Frm::FillList(void) { TListItem *ItemX; Cardinal nCount, x; /* get the VR Item count */ nCount = LEADDicom1->GetVRCount(); if(nCount > 0) { /* get the first VR Item */ LEADDicom1->MoveFirstVR(); ListView1->Items->BeginUpdate(); for(x=1; x<=nCount; ++x) { /* add item to the ListView control */ ItemX = ListView1->Items->Add(); ItemX->Caption = IntToStr(LEADDicom1->CurrentVR->Code); ItemX->SubItems->Add(LEADDicom1->CurrentVR->Name); ItemX->SubItems->Add(FloatToStr(LEADDicom1->CurrentVR->Length)); ItemX->SubItems->Add(IntToStr(LEADDicom1->CurrentVR->Restrict)); ItemX->SubItems->Add(IntToStr(LEADDicom1->CurrentVR->UnitSize)); if(x < nCount) /* get next item */ LEADDicom1->MoveNextVR(); } ListView1->Items->EndUpdate(); LEADDicom1->MoveFirstVR(); ListView1->Selected = ListView1->Items->Item[0]; ListView1->Selected->Focused = true; } } void __fastcall TVR_Frm::Button_DefaultVRClick(TObject *Sender) { Screen->Cursor = crHourGlass; ListView1->Items->Clear(); ListView1->Refresh(); LEADDicom1->DefaultVR(); FillList(); DisplayItem(); UpdateButtons(); Screen->Cursor = crDefault; } void __fastcall TVR_Frm::Button_ResetVRClick(TObject *Sender) { ListView1->Items->Clear(); ListView1->Refresh(); /* Clear all items from the VR Table */ LEADDicom1->ResetVR(); UpdateButtons(); } Word __fastcall TVR_Frm::GetVRCode(AnsiString sCode) { if(sCode == "AE") return VR_AE; if(sCode == "AS") return VR_AS; if(sCode == "AT") return VR_AT; if(sCode == "CS") return VR_CS; if(sCode == "DA") return VR_DA; if(sCode == "DS") return VR_DS; if(sCode == "DT") return VR_DT; if(sCode == "FD") return VR_FD; if(sCode == "FL") return VR_FL; if(sCode == "IS") return VR_IS; if(sCode == "LO") return VR_LO; if(sCode == "LT") return VR_LT; if(sCode == "OB") return VR_OB; if(sCode == "OW") return VR_OW; if(sCode == "PN") return VR_PN; if(sCode == "SH") return VR_SH; if(sCode == "SL") return VR_SL; if(sCode == "SQ") return VR_SQ; if(sCode == "SS") return VR_SS; if(sCode == "ST") return VR_ST; if(sCode == "TM") return VR_TM; if(sCode == "UI") return VR_UI; if(sCode == "UL") return VR_UL; if(sCode == "UN") return VR_UN; if(sCode == "US") return VR_US; if(sCode == "UT") return VR_UT; return Word(StrToInt(sCode)); } Word __fastcall GetRestrict(AnsiString sRestrict) { if(sRestrict == "Fixed") return VR_FIXED; if(sRestrict == "Maximum") return VR_MAXIMUM; if(sRestrict == "Maximum Group") return VR_MAXIMUM_GROUP; if(sRestrict == "Any Length") return VR_ANY; if(sRestrict == "Not Applicable") return VR_NOT_APPLICABLE; if(sRestrict == "Max") return VR_MAX; return Word(StrToInt(sRestrict)); } void __fastcall TVR_Frm::Button_InsertClick(TObject *Sender) { int nRet; Word nCode, nRestrict; TListItem *ItemX; nCode = GetVRCode(Edit_Code->Text); nRet = LEADDicom1->FindVR(nCode); if(nRet == SUCCESS) { ShowMessage("Already Exists!"); return; } nRestrict = GetRestrict(Edit_Restrict->Text); nRet = LEADDicom1->InsertVR(nCode, Edit_Name->Text, StrToFloat(Edit_Length->Text), nRestrict, Word(StrToInt(Edit_UnitSize->Text))); if(nRet != SUCCESS) { ShowMessage("Error"); return; } /* add item to the ListView control */ ItemX = ListView1->Items->Add(); ItemX->Caption = IntToStr(LEADDicom1->CurrentVR->Code); ItemX->SubItems->Add(LEADDicom1->CurrentVR->Name); ItemX->SubItems->Add(FloatToStr(LEADDicom1->CurrentVR->Length)); ItemX->SubItems->Add(IntToStr(LEADDicom1->CurrentVR->Restrict)); ItemX->SubItems->Add(IntToStr(LEADDicom1->CurrentVR->UnitSize)); DisplayItem(); ListView1->Selected = ItemX; ListView1->Selected->Focused = true; ListView1->Refresh (); ListView1->SetFocus(); UpdateButtons(); } void __fastcall TVR_Frm::Button_DeleteClick(TObject *Sender) { int nIndex; Word nCode; if(ListView1->Selected == 0) return; nCode = Word(StrToInt(ListView1->Selected->Caption)); /* move to the selected VR */ if(LEADDicom1->FindVR(nCode) != SUCCESS) return; /* delete it */ LEADDicom1->DeleteVR(); /* remove it from the list view control */ nIndex = ListView1->Selected->Index; ListView1->Items->Delete(nIndex); --nIndex; UpdateButtons(); if(nIndex < 0) nIndex = 0; if(ListView1->Items->Count == 0) return; ListView1->Selected = ListView1->Items->Item[nIndex]; ListView1->Selected->Focused = true; DisplayItem(); ListView1->Refresh(); ListView1->SetFocus(); } void __fastcall TVR_Frm::Button_SetNameClick(TObject *Sender) { /* move to the selected VR */ if(LEADDicom1->FindVR(Word(StrToInt(ListView1->Selected->Caption))) == SUCCESS) LEADDicom1->SetVRName(Edit_NewVRName->Text); /* change the name */ /* update it in the list view control */ DisplayItem(); ListView1->Selected->SubItems->Strings[0] = LEADDicom1->CurrentVR->Name; ListView1->Refresh(); } void __fastcall TVR_Frm::UpdateList(void) { ListView1->Selected = ListView1->FindCaption(0, IntToStr(LEADDicom1->CurrentVR->Code), false, true, false); ListView1->Selected->Focused = true; ListView1->Selected->MakeVisible(false); ListView1->SetFocus(); } void __fastcall TVR_Frm::Button_FirstClick(TObject *Sender) { LEADDicom1->MoveFirstVR(); UpdateList(); DisplayItem(); } void __fastcall TVR_Frm::Button_LastClick(TObject *Sender) { LEADDicom1->MoveLastVR(); UpdateList(); DisplayItem(); } void __fastcall TVR_Frm::Button_NextClick(TObject *Sender) { LEADDicom1->MoveNextVR(); UpdateList(); DisplayItem(); } void __fastcall TVR_Frm::Button_PrevClick(TObject *Sender) { LEADDicom1->MovePrevVR(); UpdateList(); DisplayItem(); } void __fastcall TVR_Frm::ListView1Change(TObject *Sender, TListItem *Item, TItemChange Change) { if((Change == ctState) && Item->Selected) { LEADDicom1->FindVR(Word(StrToInt(Item->Caption))); DisplayItem(); } } void __fastcall TVR_Frm::FormCreate(TObject *Sender) { LEADDicom1 = MainFrm->LEADDicom1; LEADDicom1->EnableMethodErrors = false; FillList(); LEADDicom1->EnableMethodErrors = true; DisplayItem(); } //--------------------------------------------------------------------------- void __fastcall TVR_Frm::UpdateButtons() { Boolean bListViewEmpty; if(ListView1->Items->Count == 0 ) { bListViewEmpty = true; Edit_Code->Text = ""; Edit_Name->Text = ""; Edit_Length->Text = ""; Edit_Restrict->Text = ""; Edit_UnitSize->Text = ""; } else bListViewEmpty = false; Button_First->Enabled = !bListViewEmpty; Button_Next->Enabled = !bListViewEmpty; Button_Last->Enabled = !bListViewEmpty; Button_Prev->Enabled = !bListViewEmpty; Button_SetName->Enabled = !bListViewEmpty; Edit_NewVRName->Enabled = !bListViewEmpty; Label1->Enabled = !bListViewEmpty; } //---------------------------------------------------------------------------