32 #include <gdcmGlobal.h>
33 #include <gdcmDictSet.h>
36 #if defined(USE_GDCM2)
37 #include <gdcmGlobal.h>
38 #include <gdcmDicts.h>
41 #include <boost/algorithm/string.hpp>
48 : wxDialog(parent, -1,_T(
"Descriptor Creation"), wxDefaultPosition, wxSize(550,550)) , m_path(path)
56 ownatt[
"FullFileName"] =
"Full_File_Name";
57 ownatt[
"FullFileDirectory"] =
"Full_File_Directory";
61 wxButton *NewDescriptor =
new wxButton(
this, -1,_T(
"Create a new descriptor"), wxPoint(10,7) );
64 wxButton *LoadDescriptor =
new wxButton(
this, -1,_T(
"Load a descriptor"), wxPoint(150,7) );
68 wxStaticLine *line1 =
new wxStaticLine(
this, -1, wxPoint(5,40), wxSize(540,2));
72 wxStaticText * LevelText=
new wxStaticText(
this,-1,_T(
" Level: "), wxPoint(5,50));
78 wxStaticLine *line2 =
new wxStaticLine(
this, -1, wxPoint(5,75), wxSize(540,2));
83 wxStaticText * GR=
new wxStaticText(
this,-1,_T(
" DICOM Group: "), wxPoint(5,110));
84 GRCtrl=
new wxTextCtrl(
this,
ID_GR_CTRL,_T(
"0x0010"), wxPoint(82,110), wxSize(50,25));
88 wxStaticText * EL=
new wxStaticText(
this,-1,_T(
" DICOM Element: "), wxPoint(140,110));
89 ELCtrl=
new wxTextCtrl(
this,
ID_EL_CTRL,_T(
"0x0010"), wxPoint(230,110), wxSize(50,25));
93 choices[0] = _T(
"Unknow Attribute");
94 std::map<std::string, std::string>::iterator it_att =
ownatt.begin();
95 for(
int i = 1; it_att !=
ownatt.end(); it_att++, i++)
97 choices[i] = crea::std2wx(it_att->second);
105 wxButton *addAttribute =
new wxButton(
this,
ID_ATTRIBUTE_ADD,_T(
"add an attribute"), wxPoint(440,110) );
108 wxStaticLine *line3 =
new wxStaticLine(
this, -1, wxPoint(5,140), wxSize(540,2));
112 ResultCtrl=
new wxTextCtrl(
this,
ID_EL_CTRL,_T(
""), wxPoint(5,150), wxSize(250,310), wxTE_READONLY| wxMac | wxTE_MULTILINE | wxTE_RICH );
113 wxButton *RemoveCtrl =
new wxButton(
this,
ID_REMOVE_ADD,_T(
"Remove an entry"), wxPoint(280,200) );
117 wxStaticLine *line4 =
new wxStaticLine(
this, -1, wxPoint(5,470), wxSize(540,2));
119 wxButton *Ok =
new wxButton(
this, -1,_T(
"OK"), wxPoint(10,480) );
122 wxButton *Apply =
new wxButton(
this, -1,_T(
"APPLY"), wxPoint(150,480) );
126 wxButton *Cancel =
new wxButton(
this, wxID_CANCEL,_T(
"CANCEL"), wxPoint(250,480) );
148 std::string name_att;
151 name_att =
"D" + crea::wx2std(
GRCtrl->GetValue()) +
"_" + crea::wx2std(
ELCtrl->GetValue());
156 std::string st = crea::wx2std(wd);
172 wxMessageBox(_T(
"Need a level first!"),crea::std2wx(
"WARNING"),wxOK,
this);
186 wxMessageBox(_T(
"Attribute already used in this level"),crea::std2wx(
"WARNING"),wxOK,
this);
191 for (
int i = 1; i<=
lv;i++)
197 wxTextAttr ResultAttr(
ResultCtrl->GetDefaultStyle());
198 ResultAttr.SetTextColour(*wxWHITE);
200 std::string text =
" ";
201 ResultCtrl->WriteText(crea::std2wx(
" " + name_att));
202 ResultAttr.SetTextColour(*wxBLACK);
233 wxMessageBox(_T(
"Level already used"),crea::std2wx((
"WARNING")),wxOK,
this);
239 for (
int i = 1; i<
lv;i++)
245 for (
int i = 1; i<
lv;i++)
252 wxTextAttr ResultAttr(
ResultCtrl->GetDefaultStyle());
253 ResultAttr.SetTextColour(*wxRED);
256 ResultAttr.SetTextColour(*wxBLACK);
271 if(!
GRCtrl->GetValue().IsEmpty() && !
ELCtrl->GetValue().IsEmpty()
275 std::string gr = crea::wx2std(
GRCtrl->GetValue());
276 std::string el = crea::wx2std(
ELCtrl->GetValue());
277 std::stringstream val;
279 unsigned short group;
280 unsigned short element;
281 val << std::dec << gr ;
282 val >> std::hex >> group;
284 val << std::dec << el ;
285 val >> std::hex >> element;
286 #if defined(USE_GDCM)
288 GDCM_NAME_SPACE::DictEntry* entry = GDCM_NAME_SPACE::Global::GetDicts()->GetDefaultPubDict()->GetEntry(group, element);
318 std::map<std::string, std::string>::iterator it_att =
ownatt.begin();
319 for(; it_att !=
ownatt.end(); it_att++)
321 if(it_att->second == name)
323 result = it_att->first.c_str();
341 std::string tx(crea::wx2std(
ResultCtrl->GetRange(0,
ResultCtrl->XYToPosition(0,line+1))).c_str());
342 std::string::size_type level_pos_start = tx.rfind(
"|_");
343 if(level_pos_start == -1)
349 level_pos_start += 2;
352 std::string::size_type level_pos_end = tx.find_first_of(
"\n",level_pos_start);
353 return tx.substr(level_pos_start,level_pos_end - level_pos_start);
369 ResultCtrl->PositionToXY( pos_start,&column, &line);
372 std::string name(
"root");
379 wxString text =
ResultCtrl->GetLineText(line);
380 if ( text.Find(_T(
"|_")) == -1)
384 std::string tx = crea::wx2std(text);
385 std::string::size_type EL_start_pos = tx.find_last_of(
" ");
386 RemoveAttribute(level, tx.substr(EL_start_pos+1,tx.size() - EL_start_pos));
392 lv = text.Find(_T(
"|"))/3;
393 pos_start=
ResultCtrl->XYToPosition(0,line-1);
422 outDscp +=
"O NumberOfChildren ";
439 outDscp += crea::wx2std(
ELCtrl->GetValue());
457 std::map<std::string, std::vector <std::string> >::iterator it_tree =
DscpTree.begin();
458 for (;it_tree !=
DscpTree.end(); it_tree++)
460 if(it_tree->first == name)
469 std::vector <std::string> branch;
482 bool bresult =
false;
483 std::map<int, std::string>::iterator it_list=
lvlist.begin();
484 for(; it_list !=
lvlist.end(); it_list++)
486 if(it_list->second == name)
491 std::map<int, std::string>::iterator it_list2 = it_list;
492 for(;it_list !=
lvlist.end(); it_list++)
494 std::map<std::string, std::vector <std::string> >::iterator it_tree =
DscpTree.begin();
495 for (;it_tree !=
DscpTree.end(); it_tree++)
497 if(it_tree->first == name)
518 std::map<std::string, std::vector <std::string> >::iterator it_tree =
DscpTree.begin();
519 for (;it_tree !=
DscpTree.end(); it_tree++)
521 if (it_tree->first.c_str() == level)
523 std::vector<std::string>::iterator it_branch = it_tree->second.begin();
524 for(;it_branch != it_tree->second.end(); it_branch++)
526 if(it_branch->c_str() == name)
533 it_tree->second.push_back(name);
549 bool bresult =
false;
550 std::map<std::string, std::vector <std::string> >::iterator it_tree =
DscpTree.begin();
551 for (;it_tree !=
DscpTree.end(); it_tree++)
553 if(it_tree->first == level)
555 std::vector<std::string>::iterator it_branch = it_tree->second.begin();
556 cout << it_tree->second.size();
557 for(;it_branch != it_tree->second.end(); it_branch++)
559 if(it_branch->c_str() == name)
562 it_tree->second.erase(it_branch);
591 long style = wxOPEN | wxFILE_MUST_EXIST;
597 std::string wc(
"*.dscp");
598 wxFileDialog* FD =
new wxFileDialog( 0,
605 if (FD->ShowModal()==wxID_OK)
637 std::string file =
"";
639 std::string wc(
"*.dscp");
640 wxFileDialog* FD =
new wxFileDialog( 0,
649 if (FD->ShowModal()==wxID_OK)
652 file = crea::wx2std(FD->GetPath()).c_str();
653 std::ofstream ofs(file.c_str());
686 std::map<std::string, std::vector <std::string> >::iterator it_tree =
DscpTree.begin();
687 std::map<int, std::string >::iterator it_lv_nb =
lvlist.begin();
688 std::map<int, std::string >::iterator it_lv =
lvlist.begin();
690 for (;it_lv !=
lvlist.end(); it_lv++)
694 outDscp += it_lv->second.c_str();
696 if(it_lv_nb !=
lvlist.end())
698 outDscp +=
"O NumberOfChildren ";
699 outDscp += it_lv_nb->second.c_str();
704 std::vector<std::string>::iterator it_branch =
DscpTree[it_lv->second.c_str()].begin();
705 for(;it_branch !=
DscpTree[it_lv->second.c_str()].end(); it_branch++)
707 std::string att = it_branch->c_str();
708 if(att[0] ==
'D' && att[7] ==
'_' && att.size() == 14)
711 outDscp += att.substr(1,6) +
" ";
712 outDscp += att.substr(8,6) +
" ";
739 std::ifstream i_file(i_name.c_str());
740 std::stringstream buffer;
741 buffer << i_file.rdbuf();
745 #if defined(USE_GDCM2)
746 const gdcm::Global& g = gdcm::Global::GetInstance();
747 const gdcm::Dicts &dicts = g.GetDicts();
748 const gdcm::Dict &dict = dicts.GetPublicDict();
756 while(std::getline(buffer, line))
776 std::vector<std::string> descriptors;
777 std::string separator =
" ";
778 std::string::size_type last_pos = line.find_first_not_of(separator);
780 std::string::size_type pos = line.find_first_of(separator, last_pos);
781 while(std::string::npos != pos || std::string::npos != last_pos)
783 descriptors.push_back(line.substr(last_pos, pos - last_pos));
784 last_pos = line.find_first_not_of(separator, pos);
785 pos = line.find_first_of(separator, last_pos);
789 unsigned int flag = 0;
790 if(descriptors.size() == 4)
792 std::stringstream val;
793 val << std::dec << descriptors[3];
798 if(descriptors[0] ==
"D")
799 { std::stringstream val, val2;
800 unsigned short group;
801 unsigned short element;
802 val << std::dec << descriptors[1] ;
803 val >> std::hex >> group;
804 val2 << std::dec << descriptors[2];
805 val2 >> std::hex >> element;
806 std::string compose =
"D";
807 compose += descriptors[1];
809 compose += descriptors[2];
810 #if defined(USE_GDCM)
811 GDCM_NAME_SPACE::DictEntry* entry = GDCM_NAME_SPACE::Global::GetDicts()->GetDefaultPubDict()->GetEntry(group, element);
818 #if defined(USE_GDCM2)
819 gdcm::DictEntry dictentry = dict.GetDictEntry(gdcm::Tag(group, element));
828 else if(descriptors[0].find(
"#") != -1)
834 boost::algorithm::replace_all(descriptors[2],
"_",
" ");
835 if(ilevel>0 && descriptors[1] !=
"NumberOfChildren" )
837 onAddAttribute( descriptors[2].c_str(),descriptors[1].c_str(), level);