GimmickDebugMessage(3,"AttributeDescriptor : '"<<key
<<"' ["<<flags<<"]"<<std::endl);
GimmickDebugMessage(3,"='"<<mName<<"'"<<std::endl);
+ DecodeType();
}
//=====================================================================
GDCM_NAME_SPACE::DictEntry* entry =
GDCM_NAME_SPACE::Global::GetDicts()
->GetDefaultPubDict()->GetEntry(mGroup,mElement);
-
+
if (entry)
{
mName = entry->GetName();
CleanName(mName);
+ DecodeType();
GimmickDebugMessage(3,"='"<<mName<<"'"<<std::endl);
}
else
<<"Considering it as a user attribute"
<< std::endl);
mName = "UNKNOWN";
- mGroup = mElement = 0;
+ mGroup = mElement = mType = 0;
+ DecodeType();
}
}
std::string g = key.substr(1,4);
sscanf(key.c_str(),"D %04x _ %04x ",&group,&elem);
sscanf(g.c_str(),"%04x",&group);
- GimmickMessage(5,"GetDicomGroupElementFromKey '"<<g<<"' : "
+ GimmickDebugMessage(3,"GetDicomGroupElementFromKey '"<<g<<"' : "
<<group<<"|"<<elem<<std::endl);
}
else
return;
}
//=====================================================================
+ ///Decodes the type of attribute into the valid groups
+ void AttributeDescriptor::DecodeType()
+ {
+ // Retrieve the name from gdcm dict
+ GDCM_NAME_SPACE::DictEntry* entry =
+ GDCM_NAME_SPACE::Global::GetDicts()
+ ->GetDefaultPubDict()->GetEntry(mGroup,mElement);
+
+ std::string type = entry->GetVR().str();
+ CleanName(type);
+ GimmickDebugMessage(3,"VR Value is "<<type<<"!"<<std::endl);
+ if(type=="AS" ||
+ type=="DA" ||
+ type=="FL" ||
+ type=="FD" ||
+ type=="IS" ||
+ type=="SL" ||
+ type=="SS" ||
+ type=="UI" ||
+ type=="US" ||
+ type=="SH")
+ {
+ mType=1;
+ }
+ else
+ {
+ mType=2;
+ }
+
+ }
} // EO namespace tree
/// The attribute enters in label constitution (for printing)
static const unsigned int LABEL;
+ /// Types
+ /// The attribute is of numeric type
+ static const unsigned int NUMBER=1;
+ /// The attribute is of string type
+ static const unsigned int STRING=2;
+ /// The attribute's type is unknown
+ static const unsigned int UNKNOWN=0;
+
/// Default ctor
AttributeDescriptor()
: mKey(""), mName(""), mGroup(0), mElement(0), mFlags(0)
unsigned short GetElement() const { return mElement; }
/// Returns the flags of the attribute
unsigned int GetFlags() const { return mFlags; }
+ /// Returns the type of the attribute
+ unsigned int GetType() const { return mType; }
/// Extracts group and element from a key of the form "Dgroup_elem"
static void GetDicomGroupElementFromKey(const std::string& key,
/// Replace simple quote by double quotes
/// Cut string at NULL chars
void CleanName(std::string& str) const;
+ ///Decodes the attribute into accepted types
+ void DecodeType();
private:
std::string mKey;
std::string mName;
unsigned short mGroup;
unsigned short mElement;
unsigned int mFlags;
+ unsigned int mType;
};
// EO class AttributeDescriptor
//=====================================================================
Add(AttributeDescriptor(0x0008,0x103E),2); // Description
Add(AttributeDescriptor(0x0008,0x0080),2); // Institution Name
Add(AttributeDescriptor(0x0008,0x0081),2); // Institution Adress
- Add(AttributeDescriptor(0x0008,0x1010),2); // Station Name
+ Add(AttributeDescriptor(0x0008,0x1010),2); // Station Name
Add(AttributeDescriptor(0x0008,0x1048),2); // Physician of Record
Add(AttributeDescriptor(0x0008,0x1050),2); // Performing Physician's Name
Add(AttributeDescriptor(0x0018,0x1030),2); // Protocol Name
}
}
}
- //==================================================================
}
}
/// Adds the AttributeDescriptor to the list
void Add(const AttributeDescriptor&);
- /// The type of attribute container
+ /// The type of attribute container
typedef std::vector<AttributeDescriptor> AttributeDescriptorListType;
/// Returns the list of AttributeDescriptor (const)
{
return GetTree()->GetLevelDescriptor(GetLevel());
}
+
+ //=============================================================
+
+ //=============================================================
+ /// Returns the attribute descriptor of the passed parameter
+ const AttributeDescriptor& Node::GetAttributeDescriptor(const std::string& k)const
+ {
+ LevelDescriptor::AttributeDescriptorListType::const_iterator a;
+ for (a = GetTree()->GetAttributeDescriptorList(GetLevel()).begin();
+ a!= GetTree()->GetAttributeDescriptorList(GetLevel()).end();
+ ++a)
+ {
+ GimmickMessage(1,"Hello my type is"<<a->GetType()<<std::endl);
+ GimmickMessage(1,"Hello my group is"<<a->GetGroup()<<std::endl);
+ GimmickMessage(1,"Hello my element is"<<a->GetElement()<<std::endl);
+
+ if(a->GetKey()==k)
+ {
+ return *a;
+ }
+
+ }
+ return *a;
+ }
//=============================================================
//=============================================================
for (int i = 0; i<GetLevel(); ++i) mess += " ";
mess += "|_ " + GetLabel();
GimmickMessage(1,mess<<std::endl);
- ChildrenListType::const_iterator i;
- for (i=GetChildrenList().begin(); i!=GetChildrenList().end(); i++)
+ ChildrenListType::const_iterator j;
+ for (j=GetChildrenList().begin(); j!=GetChildrenList().end(); j++)
{
- (*i)->Print();
+ (*j)->Print();
}
}
//=============================================================
void UnsafeSetAttribute(const std::string& k, const std::string& v)
{ mAttributeMap[k] = v; }
- const AttributeDescriptor& GetAttributeDescriptor(const std::string& k)
- const;
+ const AttributeDescriptor& GetAttributeDescriptor(const std::string& k)const;
// { return GetTypeDescription().GetFieldDescription(k); }
#include <creaImageIOWxTreeView.h>
#include <creaImageIOSystem.h>
#include <wx/splitter.h>
-int wxCALLBACK MyCompareFunction(long item1, long item2, long WXUNUSED(sortData))
-{
- // inverse the order
- if (item1 < item2)
- return -1;
- if (item1 > item2)
- return 1;
+int wxCALLBACK MyCompareFunction(long item1, long item2, long sortData)
+{
+ std::string s1((char*)((long*)item1)[1]);
+ std::string s2((char*)((long*)item2)[1]);
+ GimmickMessage(1,
+ " Check: STRING 1: "
+ <<s1
+ <<" STRING 2: "
+ <<s2
+ <<std::endl);
+ if(sortData==1)
+ {
+ // inverse the order
+ if (s1 < s2)
+ return 1;
+ if (s1 > s2)
+ return -1;
- return 0;
+ return 0;
+ }
+ else
+ {
+ if (s1 < s2)
+ return -1;
+ if (s1 > s2)
+ return 1;
+
+ return 0;
+
+ }
+
}
+
namespace creaImageIO
{
//=====================================================================
// Create the columns : one for each attribute of the level
int col = 0;
- //ctrl->InsertItem(0, "1");
tree::LevelDescriptor::AttributeDescriptorListType::const_iterator a;
for (a = handler->GetTree().GetAttributeDescriptorList(i).begin();
wxListItem it;
it.SetTextColour(*wxRED);
it.SetText(_T("#C"));
- it.SetColumn(col);
- // ctrl->InsertColumn(col, _("Children"), col_style);
+
ctrl->InsertColumn(col,it);
- //ctrl->InsertItem(0, "1");
- //level.key.push_back(_("Children"));
- //level.key.push_back(handler->GetTree().GetChildrenList().size());
col++;
}
/// Initialize the first level splitter
sizer->Add( mLevelList[0].wxSplitter ,1, wxGROW ,0);
-
+ mColumnSelected=1;
+ mDirection=true;
UpdateLevel(1);
SetSizer( sizer );
struct ItemData
{
tree::Node* node;
+ int id;
};
//=====================================================================
<<(*i)->GetLabel()
<<"'"<<level
<<std::endl);
-
+ int _id=0;
//Adds columns
GetTreeHandler()->LoadChildren(*i,1);
tree::Node::ChildrenListType::reverse_iterator j;
);
ItemData* data = new ItemData;
- data->node = *j;
+
+ data->node = *j;
+ item.SetId(_id);
+ /*
+ std::string a=(*j)->GetAttribute(mLevelList[l].key[mColumnSelected-1]);
+ GimmickMessage(1,
+ "State Check: Att VAL"
+ <<a
+ <<std::endl);
+ */
+ data->id = _id;
item.SetData(data);
+ _id++;
long id = GetCtrl(l)->InsertItem(item);
oss << n;
std::string s(oss.str());
+
item.SetText( crea::std2wx(s));
// item.SetTextColour(*wxRED);
// item.SetBackgroundColour(*wxBLACK);
//================================================================
void WxTreeView::OnColClick(wxListEvent& event)
- {
- /*
+ {
//Obtain the column name and the level that needs to be organized
- int colNum=event.m_col;
+ mColumnSelected=event.m_col;
GimmickMessage(1,
" Column " <<event.m_col
<<std::endl);
{
if ( GetCtrl(level) == ctrl ) break;
}
-
+ UpdateLevel(level+1);
wxBusyCursor busy;
- std::vector<tree::Node*> sel=GetSelected(level+1);
-
- tree::Node* nodes[20];
-
- int l = level - 1;
- // to speed up inserting we hide the control temporarily
- GetCtrl(level)->Hide();
- GetCtrl(level)->DeleteAllItems();
-
- std::vector<tree::Node*>::iterator i;
- int num=0;
- for (i=sel.begin(); i!=sel.end(); ++i)
- {
-
- //Adds columns
- GetTreeHandler()->LoadChildren(*i,1);
- tree::Node::ChildrenListType::reverse_iterator j;
-
- for (j = (*i)->GetChildrenList().rbegin();
- j!= (*i)->GetChildrenList().rend();
- ++j)
- {
- nodes[num]=*j;
- num++;
- }
- }
+ int l = level - 1;
+
+ //Sets the data for the items to be sorted
+ std::string att;
- //Sorting elements
- int k, m;
- tree::Node* index;
-
+ int n = GetCtrl(level)->GetItemCount();
+ for (int i = 0; i < n; i++)
+ {
+ //Gets current item data
+ long adr = GetCtrl(level)->GetItemData(i);
+ //Extracts the node
+ tree::Node* nod = ((ItemData*)adr)->node;
+ //Obtains the organizing attribute
+ att=(*nod).GetAttribute(mLevelList[level].key[mColumnSelected-1]);
+ int ty=(*nod).GetAttributeDescriptor(mLevelList[level].key[mColumnSelected-1]).GetType();
+ GimmickMessage(1,"Type:"<<ty<<std::endl);
+ char* d= new char [att.size()+1];
+ strcpy (d, att.c_str());
+
+ //Creates array
+ long* lp= new long[2];
+ lp[0]=adr;
+ lp[1]=(long)d;
+
+ //Sets it as the data
+ GetCtrl(level)->SetItemData(i,(long)lp);
+ }
- for (k=1; k<num; ++k)
- {
- index = nodes[k];
- m = k;
- GimmickMessage(1,
- "Comparison Key 1: "
- <<(nodes[m-1])->GetAttribute(mLevelList[level].key[colNum-1])
- <<"Comparison Key 2: "<<(index)->GetAttribute(mLevelList[level].key[colNum-1])
- <<std::endl);
- while ((m > 0) && ((nodes[m-1])->GetAttribute(mLevelList[level].key[colNum-1]) >
- (index)->GetAttribute(mLevelList[level].key[colNum-1])))
- {
- nodes[m] = nodes[m-1];
- m = m - 1;
- }
- nodes[m] = index;
- }
-
- for (m=0; m<num; ++m)
- {
- tree::Node* node=nodes[m];
- wxListItem item;
- item.SetMask(wxLIST_MASK_STATE |
- wxLIST_MASK_TEXT |
- // wxLIST_MASK_IMAGE |
- wxLIST_MASK_DATA |
- // wxLIST_MASK_WIDTH |
- wxLIST_MASK_FORMAT
- );
-
- long id = GetCtrl(level)->InsertItem(item);
- int n;
- if ((node)->GetChildrenLoaded())
- {
- n=(node)->GetChildrenList().size();
- }
- else
- {
- n= GetTreeHandler()->GetNumberOfChildren(node);
- }
- std::ostringstream oss;
-
- oss << n;
- std::string s(oss.str());
+ if(mDirection)
+ {
+ GetCtrl(level)->SortItems(MyCompareFunction, 0);
+ mDirection=false;
+ }
+ else
+ {
+ GetCtrl(level)->SortItems(MyCompareFunction, 1);
+ mDirection=true;
+ }
- GetCtrl(level)->SetItem(id,0, crea::std2wx(s));
- GetCtrl(level)->SetColumnWidth(0, wxLIST_AUTOSIZE );
+ //Resets original data
- for (int k=1; k<GetCtrl(level)->GetColumnCount(); k++)
- {
- std::string val = (node)->GetAttribute(mLevelList[level].key[k-1]);
- if (val.size()==0) val = "?";
- GetCtrl(level)->SetItem(id,k, crea::std2wx(val));
- GetCtrl(level)->SetColumnWidth(k, wxLIST_AUTOSIZE );
+ long it = -1;
+ for ( ;; )
+ {
+ it = GetCtrl(level)->GetNextItem(it,
+ wxLIST_NEXT_ALL);
+ if ( it == -1 )
+ break;
+ //Gets current item data, extracts the node and resets it
+ long item = GetCtrl(level)->GetItemData(it);
+ GetCtrl(level)->SetItemData(it,((long*)item)[0]);
- }
-
}
-
-
- GetCtrl(level)->Show();
-*/
- }
+
+ }
//================================================================
void WxTreeView::ValidateSelectedImages()
} // EO namespace creaImageIO
-
void ValidateSelectedImages();
///Gets selected filenames
void GetSelectedAsString(std::vector<std::string>&s);
- // Updates the view of a level given the selected items of upper level
- // Recursive method
+ /// Updates the view of a level given the selected items of upper level
+ /// Recursive method
virtual void RecursiveUpdateLevel( int );
+
+
+ /// Currently Selected Column
+ int mColumnSelected;
+ ///Boolean that defines the direction of the organization
+ ///True is ascending order and false is descending
+ bool mDirection;