]> Creatis software - gdcm.git/commitdiff
Now, gdcmObject::SetEntryByNumber *adds* a new gdcmHeaderEntry to the cuurent
authorjpr <jpr>
Fri, 12 Mar 2004 14:10:46 +0000 (14:10 +0000)
committerjpr <jpr>
Fri, 12 Mar 2004 14:10:46 +0000 (14:10 +0000)
object if the given (group,elem) is not found

src/gdcmFile.h
src/gdcmHeaderEntry.h
src/gdcmObject.cxx
src/gdcmParser.cxx
src/gdcmParser.h

index 29287b24a9bc6842472a8dfe6aef9e43943af071..d5c602c8778a17225e693901631d612981b4b495 100644 (file)
@@ -106,7 +106,7 @@ private:
   /// ==0  if GetImageData    was used
   /// ==-1 if ImageData never read                       
    int PixelRead;     
-                       .
+
    /// weather already parsed 
    int Parsed;
    
index dd228c60f0a66daa526c5e9105482de10871bfe7..cff9a758d1b2cf5beabd071c3a231f14f2f44748 100644 (file)
@@ -195,6 +195,7 @@ public:
 private:
    // FIXME: In fact we should be more specific and use :
    // friend gdcmHeaderEntry * gdcmHeader::ReadNextElement(void);
+   
    friend class gdcmHeader;
 
 // Variables
@@ -213,18 +214,18 @@ private:
    /// *for internal* use only
    guint32 ReadLength;
 
- /// Even when reading explicit vr files, some
- /// elements happen to be implicit. Flag them here
- /// since we can't use the entry->vr without breaking
- /// the underlying dictionary.        
  /// Even when reading explicit vr files, some
  /// elements happen to be implicit. Flag them here
  /// since we can't use the entry->vr without breaking
+   /// the underlying dictionary.      
    bool ImplicitVR;
                          
    std::string  value;
 
-  /// unsecure memory area to hold 'non string' values 
-  /// (ie : Lookup Tables, overlays)   
+   /// unsecure memory area to hold 'non string' values 
+   /// (ie : Lookup Tables, overlays)   
    void *voidArea;
-  /// Offset from the begining of file for direct user access               
+   /// Offset from the begining of file for direct user access              
    size_t Offset; 
       
    int printLevel;
index 66c40a80c6ef927779e32e6f504848945b28de26..3f4b5101f4dc8c0e1bfda7f83661756bfe8713ad 100644 (file)
@@ -89,25 +89,57 @@ std::string gdcmObject::GetEntryByName(TagName name)  {
  * \ingroup gdcmParser
  * \brief   Sets Entry (Dicom Element) value of an element,
  *          specified by it's tag (Group, Number) 
- *          and the length, too ...       
+ *          and the length, too ...
+ *          If the Element is not found, it's just created !
+ * \warning we suppose, right now, the element belongs to a Public Group
+ *          (NOT a shadow one)       
  * @param   val string value to set
  * @param   group Group of the searched tag.
  * @param   element Element of the searched tag.
- * @return  true if element was found, else false
+ * @return  true if element was found or created successfully
  */
  bool gdcmObject::SetEntryByNumber(std::string val,guint16 group, 
-                                                  guint16 element) {
-                                                  
-   //for(ListTag::iterator i=beginObj;i!=endObj;++i) // JPR
-   for(ListTag::iterator i=beginObj;;++i) {  
-      if ( (*i)->GetGroup()==group && (*i)->GetElement()==element) {
+                                                  guint16 element) {
+
+   gdcmHeaderEntry *a;
+   for(ListTag::iterator i=beginObj;;++i) { 
+      if ( (*i)->GetGroup() == 0xfffe && (*i)->GetElement() == 0xe000 ) 
+         continue;
+      if ( group   < (*i)->GetGroup() || 
+           (group == (*i)->GetGroup() && element < (*i)->GetElement()) ){
+        // instead of ReplaceOrCreateByNumber 
+        // that is a method of gdcmParser :-( 
+         gdcmHeaderEntry *Entry;
+         TagKey key = gdcmDictEntry::TranslateToKey(group, element);
+         if ( ! ptagHT->count(key)) {
+          // we assume the element is a belongs to a Public Group (not a shadow one)
+          // we assume a Public Dictionnary *is* loaded
+           gdcmDict *PubDict         = gdcmGlobal::GetDicts()->GetDefaultPubDict();
+           // we assume the invoqued (group,elem) exists
+          // inside the Public Dictionary
+           gdcmDictEntry *DictEntry  = PubDict->GetDictEntryByNumber(group, element); 
+           // we assume the constuctor didn't fail
+           Entry = new gdcmHeaderEntry(DictEntry);
+          // ----
+          // TODO
+          // ----
+          // better we don't assume too much !
+          // in the next release, gdcmObject will be used 
+          // to describe any Header Entry ...
+         } else {
+            Entry = ptagHT->find(key)->second;
+         }
+         Entry->SetValue(val); 
+         Entry->SetLength(val.length());
+         plistEntries->insert(i,Entry); 
+        return true;
+      }           
+      if (group == (*i)->GetGroup() && element == (*i)->GetElement() ) {
          (*i)->SetValue(val);
-        (*i)->SetLength(val.length()+1);
-         return true;
-      }
-      if (i == endObj) break;      
-   }
-   return false;                                                   
+         (*i)->SetLength(val.length()); 
+         return true;    
+      }   
+   }                                               
 }
 /**
  * \ingroup gdcmObject
index 60dd01bacafccf20d2483deb38aa32a07bd7c03e..cea36d4ec8f30adadf59d4497a59077c06882e85 100644 (file)
@@ -453,22 +453,28 @@ bool gdcmParser::Write(FILE *fp, FileType type) {
  * \ingroup gdcmParser
  * \brief   Modifies the value of a given Header Entry (Dicom Element)
  *          if it exists; Creates it with the given value if it doesn't
+ * \warning : adds the Header Entry to the HTable, NOT to the chained List
  * @param   Value passed as a std::string
- * @param   Group
- * @param   Elem
- * \return  false only if new element creation fails
+ * @param Group   group of the Entry 
+ * @param Elem element of the Entry
+ * \return  pointer to the created Header Entry
+ *          NULL if creation failed
  */
-bool gdcmParser::ReplaceOrCreateByNumber(std::string Value, 
+gdcmHeaderEntry * gdcmParser::ReplaceOrCreateByNumber(
+                                         std::string Value, 
                                          guint16 Group, 
-                                        guint16 Elem ){
-   if (CheckIfEntryExistByNumber(Group, Elem) == 0) {
+                                        guint16 Elem ){                                         
+   gdcmHeaderEntry* a;
+   a = GetHeaderEntryByNumber( Group, Elem);                                    
+   if (a == NULL) {
       gdcmHeaderEntry *a =NewHeaderEntryByNumber(Group, Elem);
       if (a == NULL) 
-         return false;
+         return NULL;
       AddHeaderEntry(a);
    }   
-   SetEntryByNumber(Value, Group, Elem);
-   return(true);
+   //SetEntryByNumber(Value, Group, Elem);
+   a->SetValue(Value);
+   return(a);
 }   
 
 /**
@@ -478,20 +484,24 @@ bool gdcmParser::ReplaceOrCreateByNumber(std::string Value,
  * @param   Value passed as a char*
  * @param Group   group of the Entry 
  * @param Elem element of the Entry
- * \return  boolean 
+ * \return  pointer to the created Header Entry
+ *          NULL if creation failed 
  * 
  */
-bool gdcmParser::ReplaceOrCreateByNumber(char* Value, guint16 Group, guint16 Elem ) {
+gdcmHeaderEntry *  gdcmParser::ReplaceOrCreateByNumber(
+                                     char* Value, 
+                                     guint16 Group, 
+                                     guint16 Elem ) {
    gdcmHeaderEntry* nvHeaderEntry=NewHeaderEntryByNumber(Group, Elem);
 
    if(!nvHeaderEntry)
-      return(false);
+      return(NULL);
 
    AddHeaderEntry(nvHeaderEntry);
 
    std::string v = Value;      
    SetEntryByNumber(v, Group, Elem);
-   return(true);
+   return(nvHeaderEntry);
 }  
 
 /**
index 8767a1d4b99e13fe0880b971bbbd796508af533f..10943f5ff1010ffde2f93099b22a175200e5f2f5 100644 (file)
@@ -105,8 +105,8 @@ public:
 // Write (used in gdcmFile, gdcmDicomDir)
    virtual bool Write(FILE *, FileType);
 
-   bool ReplaceOrCreateByNumber(std::string Value, guint16 Group, guint16 Elem);
-   bool ReplaceOrCreateByNumber(     char  *Value, guint16 Group, guint16 Elem);
+   gdcmHeaderEntry * ReplaceOrCreateByNumber(std::string Value, guint16 Group, guint16 Elem);
+   gdcmHeaderEntry * ReplaceOrCreateByNumber(     char  *Value, guint16 Group, guint16 Elem);
    bool ReplaceIfExistByNumber (     char  *Value, guint16 Group, guint16 Elem);
 
 // System access
@@ -257,8 +257,7 @@ private:
    gdcmHeaderEntry *NewHeaderEntryByNumber(guint16 group, 
                                            guint16 element);
    gdcmHeaderEntry *NewHeaderEntryByName  (std::string Name);
-
-
+   
    // Deprecated (Not used) --> commented out
    //gdcmHeaderEntry *NewManualHeaderEntryToPubDict(std::string NewTagName,
    //                                                  std::string VR);
@@ -296,15 +295,15 @@ private:
    */
    int sw;
    /**
-   * \brief Size treshold above which an element value will NOT be loaded in 
+   * \brief Size threshold above which an element value will NOT be loaded in 
    *       memory (to avoid loading the image/volume itself). By default,
    *       this upper bound is fixed to 1024 bytes (which might look reasonable
-   * when one considers the definition of the various VR contents).
+   *       when one considers the definition of the various VR contents).
    */
    guint32 MaxSizeLoadEntry;
    
    /**
-   * \brief Size treshold above which an element value will NOT be *printed* in
+   * \brief Size threshold above which an element value will NOT be *printed* in
    *        order no to polute the screen output. 
    *        By default, this upper bound is fixed to 64 bytes.
    */