]> Creatis software - creaImageIO.git/commitdiff
Ordering complete with int or string distinction
authorcaballero <caballero>
Tue, 3 Mar 2009 10:46:54 +0000 (10:46 +0000)
committercaballero <caballero>
Tue, 3 Mar 2009 10:46:54 +0000 (10:46 +0000)
src2/creaImageIOTreeAttributeDescriptor.cpp
src2/creaImageIOTreeAttributeDescriptor.h
src2/creaImageIOTreeNode.cpp
src2/creaImageIOWxTreeView.cpp

index 799cb12cc2210b357912d40d78e805234f53f1d9..34647974489a1cb26156579808d0dd5435256f29 100644 (file)
@@ -43,7 +43,6 @@ namespace creaImageIO
       GimmickDebugMessage(3,"AttributeDescriptor : '"<<key
                          <<"' ["<<flags<<"]"<<std::endl);
       GimmickDebugMessage(3,"='"<<mName<<"'"<<std::endl);
-         DecodeType();
     }
 
     //=====================================================================
@@ -75,7 +74,6 @@ namespace creaImageIO
        {
          mName = entry->GetName();
          CleanName(mName);
-         DecodeType();
          GimmickDebugMessage(3,"='"<<mName<<"'"<<std::endl);
        }
       else
@@ -85,8 +83,7 @@ namespace creaImageIO
                         <<"Considering it as a user attribute"
                         << std::endl);
          mName = "UNKNOWN";
-         mGroup = mElement = mType = 0;
-         DecodeType();
+         mGroup = mElement = 0;
        }
       
     }
@@ -117,17 +114,19 @@ namespace creaImageIO
        }
       return;
     }
+
     //=====================================================================
-       ///Decodes the type of attribute into the valid groups
-       void AttributeDescriptor::DecodeType()
-       {
-               // Retrieve the name from gdcm dict
+       /// Decodes the type of the attribute
+     void AttributeDescriptor::DecodeType(unsigned int& typ) const
+         {
+                 
+               
+                 // Retrieve the name from gdcm dict
                GDCM_NAME_SPACE::DictEntry* entry =
                GDCM_NAME_SPACE::Global::GetDicts()
-               ->GetDefaultPubDict()->GetEntry(mGroup,mElement);
+               ->GetDefaultPubDict()->GetEntry(GetGroup(),GetElement());
 
                std::string type = entry->GetVR().str();
-               CleanName(type);
                GimmickDebugMessage(3,"VR Value is "<<type<<"!"<<std::endl);
                if(type=="AS" ||
                type=="DA" ||
@@ -140,14 +139,17 @@ namespace creaImageIO
                type=="US" ||
                type=="SH")
                {
-                       mType=1;
+                       type="1";
+                        sscanf(type.c_str(),"%u",&typ);
                }
                else
                {
-                       mType=2;
+                       type="2";
+                        sscanf(type.c_str(),"%u",&typ);
                }
-
-       }
+               
+         }
+         //=====================================================================
 
   } // EO namespace tree
 
index 49c975b4bea28ebcf50bba6ba93b37c8b88d466e..d2afc8515bacfca18f75fe37e2cb5b65c0cb72e6 100644 (file)
@@ -27,11 +27,11 @@ namespace creaImageIO
 
          /// Types
       /// The attribute is of numeric type
-      static const unsigned int NUMBER=1;
+      static const int NUMBER=1;
       /// The attribute is of string type
-      static const unsigned int STRING=2;
+      static const int STRING=2;
          /// The attribute's type is unknown
-      static const unsigned int UNKNOWN=0;
+      static const int UNKNOWN=0;
 
       /// Default ctor
       AttributeDescriptor()
@@ -69,9 +69,7 @@ namespace creaImageIO
       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,
                                              unsigned short& group,
@@ -80,15 +78,15 @@ namespace creaImageIO
       /// 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();
+         ///Decodes the type of attribute into the existing ones
+         void DecodeType(unsigned int& type) const;
+
     private:
       std::string mKey;
       std::string mName;
       unsigned short mGroup;
       unsigned short mElement;
       unsigned int mFlags;
-         unsigned int mType;
     };
     // EO class AttributeDescriptor
     //=====================================================================
index 09c89dcadb223442b82b474976708c9b4569c1bd..dabf3b14957071d21bcaf1f46a03543414c9b087 100644 (file)
@@ -118,10 +118,7 @@ namespace creaImageIO
           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;
index cdf0c18dc35f450cb76e73e22b7f1bd92798527f..1f3ccfeb1ff109fa35ba57ee90497ccb41cabd92 100644 (file)
@@ -1,7 +1,7 @@
 #include <creaImageIOWxTreeView.h>
 #include <creaImageIOSystem.h>
 #include <wx/splitter.h>
-int wxCALLBACK MyCompareFunction(long item1, long item2, long sortData)
+int wxCALLBACK CompareFunctionStrings(long item1, long item2, long sortData)
 {      
        std::string s1((char*)((long*)item1)[1]);
        std::string s2((char*)((long*)item2)[1]);
@@ -34,6 +34,39 @@ int wxCALLBACK MyCompareFunction(long item1, long item2, long sortData)
        
 }
 
+int wxCALLBACK CompareFunctionInts(long item1, long item2, long sortData)
+{      
+       int val1=atoi((char*)((long*)item1)[1]);
+       int val2=atoi((char*)((long*)item2)[1]);
+        GimmickMessage(1,
+               " Check: STRING 1: " 
+                       <<val1
+                       <<" STRING 2: "
+                       <<val2
+                       <<std::endl);
+       if(sortData==1)
+       {
+               // inverse the order
+               if (val1 < val2)
+                       return 1;
+               if (val1 > val2)
+                       return -1;
+
+               return 0;
+       }
+       else
+       {
+               if (val1 < val2)
+                       return -1;
+               if (val1 > val2)
+                       return 1;
+
+               return 0;
+
+       }
+       
+}
+
 namespace creaImageIO
 {
   //=====================================================================
@@ -395,18 +428,22 @@ namespace creaImageIO
 
          //Sets the data for the items to be sorted
        std::string att;
-       
+       unsigned int ty=0;
        int n = GetCtrl(level)->GetItemCount();
        for (int i = 0; i < n; i++)
          {
-         //Gets current item data
+                 
+           //Gets current item data
                long adr = GetCtrl(level)->GetItemData(i);
-               //Extracts the node
+               //Extracts the node and the type of attribute
                tree::Node* nod = ((ItemData*)adr)->node;
+               if(i==0)
+                 {
+                       (*nod).GetAttributeDescriptor(mLevelList[level].key[mColumnSelected-1]).DecodeType(ty);
+                 }
                //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());
 
@@ -418,16 +455,32 @@ namespace creaImageIO
                //Sets it as the data
                GetCtrl(level)->SetItemData(i,(long)lp);
          }     
-       
+         
+         //int ty=GetAttributeDescriptor(mLevelList[level].key[mColumnSelected-1]).GetType();
          if(mDirection)
          {
-               GetCtrl(level)->SortItems(MyCompareFunction, 0);
+                 if(ty==1)
+                 {
+                         GetCtrl(level)->SortItems(CompareFunctionInts, 0);
+                 }
+                 else
+                 {
+                         GetCtrl(level)->SortItems(CompareFunctionStrings, 0);
+                 }
+               
                mDirection=false;
          }
          else
          {
-               GetCtrl(level)->SortItems(MyCompareFunction, 1);
-               mDirection=true;
+                if(ty==1)
+                 {
+                         GetCtrl(level)->SortItems(CompareFunctionInts, 1);
+                 }
+                 else
+                 {
+                         GetCtrl(level)->SortItems(CompareFunctionStrings, 1);
+                 }
+                 mDirection=true;
          }
 
        //Resets original data