]> Creatis software - gdcm.git/blobdiff - src/gdcmDicomDir.cxx
* FIX : src/gdcmDicomDir.cxx : make windows compilable
[gdcm.git] / src / gdcmDicomDir.cxx
index f1c7e679db359efd404e77cc92e81e3909874821..b109d1efc8fa3882097be3e7e190ed9b701861cc 100644 (file)
 
 #include <sys/types.h>
 #include <errno.h>
-#include <unistd.h>
+
+#ifdef _MSC_VER 
+   #include <direct.h>
+#else
+   #include <unistd.h>
+#endif
 
 //-----------------------------------------------------------------------------
 //  For full DICOMDIR description, see:
@@ -37,11 +42,7 @@ gdcmDicomDir::gdcmDicomDir(const char *Name, bool parseDir,
 {
  // que l'on ai passe un root directory ou un DICOMDIR
  // et quelle que soit la valeur de parseDir,
- // on a lance gdcmParser
- cout << "---------------------------------------------- " << Name <<endl;
-
+ // on a lance gdcmParser 
       
    startMethod=            NULL;
    progressMethod=         NULL;
@@ -59,17 +60,21 @@ gdcmDicomDir::gdcmDicomDir(const char *Name, bool parseDir,
    metaElems=NULL;
 
 // gdcmParser already  executed
-// Si on a passe un root directory, on est assurĂ© de n'avoir rien ramenĂ©
+// if user passed a root directory, sure we didn't get anything
 
    if( GetListEntry().begin()==GetListEntry().end() ) 
    {
-     // Si, en plus, parseDir == false, ca devrait etre une erreur
+     // if parseDir == false, it should be tagged as an error
       dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : entry list empty");
 
       if(strlen(Name)==1 && Name[0]=='.') { // user passed '.' as Name
                                             // we get current directory name
-         char*dummy=(char*) malloc(1000); // TODO : check with Windoze
+         char*dummy=(char*) malloc(1000);   // TODO : check with Windoze // JPR
+#ifdef _MSC_VER
+         _getcwd(dummy,(size_t)1000);
+#else
          getcwd(dummy,(size_t)1000);
+#endif
          SetFileName(dummy); // will be converted into a string
          free(dummy);        // no longer needed   
       }
@@ -80,8 +85,12 @@ gdcmDicomDir::gdcmDicomDir(const char *Name, bool parseDir,
         ParseDirectory();
       }
    }
-   else
+   else {
       CreateDicomDir();
+      CheckBoundaries(); // to maintain consistency between 
+                         // home-made gdcmDicomDir 
+                        // and the ones comming from a DICOMDIR file
+   } 
 }
 
 /*
@@ -298,7 +307,7 @@ bool gdcmDicomDir::Write(std::string fileName)
    fwrite(filePreamble,128,1,fp1);
    fwrite("DICM",4,1,fp1);
    free(filePreamble);        
-   //UpdateDirectoryRecordSequenceLength(); // a reecrire en utilisant 
+   //UpdateDirectoryRecordSequenceLength(); // a reecrire en utilisant   JPR
                                             // la structure arborescente JPR
    WriteDicomDirEntries(fp1);
 
@@ -401,12 +410,48 @@ void gdcmDicomDir::CreateDicomDirChainedList(std::string path)
    std::sort(list.begin(),list.end(),gdcmDicomDir::HeaderLessThan);
 
    std::string tmp=fileList.GetDirName();
+      
    //for each Header of the chained list, add/update the Patient/Study/Serie/Image info
    SetElements(tmp,list);
-
+      
    CallEndMethod();
 }
 
+
+
+void gdcmDicomDir::CheckBoundaries()
+{   
+   ListDicomDirPatient::iterator  itPatient;
+   ListDicomDirStudy::iterator    itStudy;
+   ListDicomDirSerie::iterator    itSerie;
+   ListDicomDirImage::iterator    itImage; 
+   ListTag::iterator i,j; 
+   
+   GetDicomDirMeta()->ResetBoundaries(0);   
+
+   itPatient = GetDicomDirPatients().begin(); 
+   while ( itPatient != GetDicomDirPatients().end() ) {
+      (*itPatient)->ResetBoundaries(1);            
+      itStudy = ((*itPatient)->GetDicomDirStudies()).begin();        
+      while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) {   
+         (*itStudy)->ResetBoundaries(1); 
+         itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
+         while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) {
+            (*itSerie)->ResetBoundaries(1);
+            itImage = ((*itSerie)->GetDicomDirImages()).begin();
+            while (itImage != (*itSerie)->GetDicomDirImages().end() ) {
+               (*itImage)->ResetBoundaries(1);
+               ++itImage;                  
+           }
+           ++itSerie;                                
+         }
+        ++itStudy;            
+      } 
+      ++itPatient;     
+   }
+} 
+
+
 /*
  * \ingroup gdcmDicomDir
  * \brief   adds a new Patient to a partially created DICOMDIR