//--------------------------------------------------------------------------- #include #pragma hdrstop #include "IOD_Form.h" #include "MainForm.h" #define TREE_ROOT_LEVEL 0 //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TIOD_Frm *IOD_Frm; //--------------------------------------------------------------------------- __fastcall TIOD_Frm::TIOD_Frm(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TIOD_Frm::DisplayNode(void) { if(!LEADDicom1->CurrentIOD) return; /* display the Nodes information */ Edit_Code->Text = IntToStr(LEADDicom1->CurrentIOD->Code); Edit_Name->Text = LEADDicom1->CurrentIOD->Name; Edit_Type->Text = IntToStr(LEADDicom1->CurrentIOD->nType); Edit_Usage->Text = IntToStr(LEADDicom1->CurrentIOD->Usage); Memo_Description->Text = LEADDicom1->CurrentIOD->Description; } void __fastcall TIOD_Frm::FillTree(void) { TreeView1->ShowLines = true; TreeView1->ShowRoot = true; TreeView1->Enabled = false; /* move to root of tree */ LEADDicom1->MoveFirstIOD(false); /* move to first IOD in tree */ LEADDicom1->MoveRootIOD(); /* get the root of this IOD */ /* now, add the IOD items */ FillSubTree(0); TreeView1->Selected = TreeView1->Items->GetFirstNode(); TreeView1->Enabled = true; } void __fastcall TIOD_Frm::FillSubTree(TTreeNode *ParentNode) { int nRet; TTreeNode *NodeX; /* add the node to the tree */ NodeX = TreeView1->Items->AddChild(ParentNode, LEADDicom1->CurrentIOD->Name); NodeX->Data = Pointer(LEADDicom1->CurrentIOD->hIOD); nRet = LEADDicom1->MoveChildIOD(); /* does this node have a child? */ if(nRet == SUCCESS) FillSubTree(NodeX); /* move to next node in same level(if(one) */ nRet = LEADDicom1->MoveNextIOD(true); if(nRet == SUCCESS) FillSubTree(ParentNode); else /* move back to parent */ LEADDicom1->MoveParentIOD(); } void __fastcall TIOD_Frm::Button_DefaultIODClick(TObject *Sender) { Screen->Cursor = crHourGlass; TreeView1->Items->Clear(); TreeView1->Refresh(); LEADDicom1->DefaultIOD(); FillTree(); UpdateButtons(); Screen->Cursor = crDefault; DisplayNode(); } void __fastcall TIOD_Frm::Button_ResetIODClick(TObject *Sender) { LEADDicom1->ResetIOD(); TreeView1->Items->Clear(); TreeView1->Refresh(); /* clear all IOD items */ LEADDicom1->ResetIOD(); UpdateButtons(); } void __fastcall TIOD_Frm::Button_InsertClick(TObject *Sender) { int nRet; TTreeNode *NodeX; bool bInsert = false; Cardinal uCode; Byte nType; THandle hIOD; uCode = StrToInt(Edit_Code->Text); nType = Byte(StrToInt(Edit_Type->Text)); hIOD = LEADDicom1->CurrentIOD->hIOD; if(nType == DICOM_IOD_TYPE_CLASS) { while(TreeView1->Selected->Level > TREE_ROOT_LEVEL) TreeView1->Selected = TreeView1->Selected->Parent; CheckBox_InsertAsChild->Checked = false; } /* does an IOD already exist on that level? */ if(CheckBox_InsertAsChild->Checked) { /* if(the selected item has a child, move to that level */ nRet = LEADDicom1->MoveChildIOD(); if(nRet != SUCCESS) bInsert = true; else /* check this level to see if(IOD already exists */ { LEADDicom1->MoveFirstIOD(true); nRet = LEADDicom1->FindIOD(uCode, nType, true); if(nRet != SUCCESS) bInsert = true; /* move back to parent level */ LEADDicom1->MoveParentIOD(); } } else { LEADDicom1->MoveFirstIOD(true); nRet = LEADDicom1->FindIOD(uCode, nType, true); if(nRet != SUCCESS) bInsert = true; LEADDicom1->SetCurrentIOD(hIOD); } /* allow user to insert item at the same level as the current or as child */ if(bInsert) { LEADDicom1->InsertIOD(CheckBox_InsertAsChild->Checked, nType, uCode, Edit_Name->Text, Word(StrToInt(Edit_Usage->Text)), Memo_Description->Text); /* add the node to the tree */ if(CheckBox_InsertAsChild->Checked) NodeX = TreeView1->Items->AddChild(TreeView1->Selected, LEADDicom1->CurrentIOD->Name); else NodeX = TreeView1->Items->AddChildFirst(TreeView1->Selected, LEADDicom1->CurrentIOD->Name); NodeX->Data = Pointer(LEADDicom1->CurrentIOD->hIOD); } else ShowMessage("Already exists"); DisplayNode(); UpdateButtons(); } void __fastcall TIOD_Frm::Button_DeleteClick(TObject *Sender) { if(TreeView1->Selected == 0) return; LEADDicom1->DeleteIOD(); DisplayNode(); /* remove it from the list view control */ TreeView1->Items->Delete(TreeView1->Selected); TreeView1->Refresh(); TreeView1->SetFocus(); UpdateButtons(); } void __fastcall TIOD_Frm::Button_SetNameClick(TObject *Sender) { /* change the name */ LEADDicom1->SetIODName(Edit_NewIODName->Text); /* update it in the tree view control */ TreeView1->Selected->Text = LEADDicom1->CurrentIOD->Name; TreeView1->Refresh(); DisplayNode(); } void __fastcall TIOD_Frm::Button_FirstClick(TObject *Sender) { TTreeNode *PrevNode; LEADDicom1->MoveFirstIOD(true); PrevNode = TreeView1->Selected->getPrevSibling(); Screen->Cursor = crHourGlass; TreeView1->Items->BeginUpdate(); while(PrevNode) { TreeView1->Selected = PrevNode; PrevNode = TreeView1->Selected->getPrevSibling(); } TreeView1->Items->EndUpdate(); Screen->Cursor = crDefault; TreeView1->SetFocus(); DisplayNode(); } void __fastcall TIOD_Frm::Button_LastClick(TObject *Sender) { TTreeNode *NextNode; LEADDicom1->MoveLastIOD(true); NextNode = TreeView1->Selected->getNextSibling(); Screen->Cursor = crHourGlass; TreeView1->Items->BeginUpdate(); while(NextNode) { TreeView1->Selected = NextNode; NextNode = TreeView1->Selected->getNextSibling(); } TreeView1->Items->EndUpdate(); Screen->Cursor = crDefault; TreeView1->SetFocus(); DisplayNode(); } void __fastcall TIOD_Frm::Button_NextClick(TObject *Sender) { if(TreeView1->Selected->getNextSibling() != 0) { LEADDicom1->MoveNextIOD(true); TreeView1->Selected = TreeView1->Selected->getNextSibling(); TreeView1->SetFocus(); DisplayNode(); } } void __fastcall TIOD_Frm::Button_PrevClick(TObject *Sender) { if(TreeView1->Selected->getPrevSibling() != 0) { LEADDicom1->MovePrevIOD(true); TreeView1->Selected = TreeView1->Selected->getPrevSibling(); TreeView1->SetFocus(); DisplayNode(); } } void __fastcall TIOD_Frm::Button_SetDescriptionClick(TObject *Sender) { if(TreeView1->Selected->Level == TREE_ROOT_LEVEL) return; /* change the name */ LEADDicom1->SetIODDescription(Memo_NewDescription->Text); /* update the display */ DisplayNode(); } void __fastcall TIOD_Frm::Button_ParentClick(TObject *Sender) { if(TreeView1->Selected->Parent != 0) { LEADDicom1->MoveParentIOD(); TreeView1->Selected = TreeView1->Selected->Parent; TreeView1->SetFocus(); DisplayNode(); } } void __fastcall TIOD_Frm::Button_RootClick(TObject *Sender) { LEADDicom1->MoveRootIOD(); /* TreeView1->Selected = */ while(TreeView1->Selected->Level > TREE_ROOT_LEVEL) TreeView1->Selected = TreeView1->Selected->Parent; TreeView1->SetFocus(); DisplayNode(); } void __fastcall TIOD_Frm::Button_ChildClick(TObject *Sender) { if(TreeView1->Selected->getFirstChild() != 0) { LEADDicom1->MoveChildIOD(); TreeView1->Selected = TreeView1->Selected->getFirstChild(); TreeView1->SetFocus(); DisplayNode(); } } void __fastcall TIOD_Frm::TreeView1Change(TObject *Sender, TTreeNode *Node) { if(Node == 0) return; LEADDicom1->SetCurrentIOD(THandle(Node->Data)); Node->MakeVisible(); DisplayNode(); } void __fastcall TIOD_Frm::FormCreate(TObject *Sender) { LEADDicom1 = MainFrm->LEADDicom1; LEADDicom1->EnableMethodErrors = false; FillTree(); LEADDicom1->EnableMethodErrors = true; DisplayNode(); } //--------------------------------------------------------------------------- void __fastcall TIOD_Frm::UpdateButtons(void) { Boolean bTreeViewEmpty; if(TreeView1->Items->Count == 0 ) { bTreeViewEmpty = true; Edit_Code->Text = ""; Edit_Name->Text = ""; Edit_Type->Text = ""; Edit_Usage->Text = ""; Memo_Description->Text = ""; } else bTreeViewEmpty = false; Button_First->Enabled = ! bTreeViewEmpty; Button_Next->Enabled = ! bTreeViewEmpty; Button_Last->Enabled = ! bTreeViewEmpty; Button_Prev->Enabled = ! bTreeViewEmpty; Button_SetName->Enabled = ! bTreeViewEmpty; Button_Root->Enabled = ! bTreeViewEmpty; Button_Parent->Enabled = ! bTreeViewEmpty; Button_Child->Enabled = ! bTreeViewEmpty; Edit_NewIODName->Enabled = ! bTreeViewEmpty; Label1->Enabled = ! bTreeViewEmpty; Button_SetDescription->Enabled = ! bTreeViewEmpty; Memo_NewDescription->Enabled = ! bTreeViewEmpty; Label_NewDescription->Enabled = ! bTreeViewEmpty; }