creaImageIO_lib
creaImageIO::TreeHandlerImageAdder Class Reference

Object which can add images files to a TreeHandler. Is able to parse (recursively) a part of a filesystem to look for known images and load their attributes in order to add the images to a Tree (submission via a TreeHandler::AddBranch) More...

#include <creaImageIOTreeHandlerImageAdder.h>

Collaboration diagram for creaImageIO::TreeHandlerImageAdder:

Classes

class  Progress
 

Public Types

typedef boost::signal< void(Progress &)> ProgressSignalType
 
typedef
ProgressSignalType::slot_function_type 
ProgressCallbackType
 

Public Member Functions

 TreeHandlerImageAdder (TreeHandler *tree)
 Ctor. More...
 
 ~TreeHandlerImageAdder ()
 Dtor. More...
 
void SetTreeHandler (TreeHandler *tree)
 Sets the TreeHandler. More...
 
void SetSynchronizer (Synchronizer *s)
 Sets the synchronizer. More...
 
void SetCurrentDatabase (std::string cur)
 Sets the synchronizer. More...
 
const ProgressGetProgress () const
 
void ConnectProgressObserver (ProgressCallbackType callback)
 
bool IsHandledFile (const std::string &filename)
 Returns if the file can be read or not. More...
 
void AddFiles (const std::vector< std::string > &filename)
 Adds a list of files to the TreeHandler. More...
 
void AddDirectory (const std::string &directory, bool recurse)
 (Recursively) adds the files of a directory to the TreeHandler More...
 
void RemoveFile (tree::Node *node)
 Removes a file from the databases. More...
 
void RemoveFiles (const std::vector< tree::Node * > &nodes)
 Removes files from the databases. More...
 
void remove (tree::Node *i_node)
 
std::string Synchronize (bool repair, bool checkAttributes)
 Synchronizes the DB and disk by repeating the operations the user has done and returns a report. More...
 
void CheckSyncDirectory (const std::string &dirpath, bool recursive, bool repair, bool checkAttributes, std::vector< std::string > &i_ignorefiles, std::vector< std::string > &attsModified, std::vector< std::string > &newfiles)
 Recursively checks if the directory is synchronized and optionally the state of the attributes. More...
 
void CopyFiles (const std::vector< std::string > &filenames, const std::string directory)
 Copies the files indicated in the vector and updates all databases. More...
 
void SaveAs (const std::vector< std::string > &filenames, std::vector< vtkImageData * > i_images)
 Saves as the files indicated in the vector in a specific directory. More...
 
void FindNode (tree::Node *parent, int level, const std::string &searchParam, const std::string &searchVal, tree::Node *&node)
 Finds the node that matches the specified parameters. More...
 
void FindNodePartial (tree::Node *parent, int level, const std::string &searchParam, const std::string &searchVal, tree::Node *&node)
 Finds the nodes that partially match the searchVal. More...
 
void CheckAttributes (bool repair, std::string &file, std::vector< std::string > &attsModified)
 Checks the attributes of the database against the ones in disk. More...
 
void DeleteDriveFromMainDB (const std::string &drive)
 Deletes the drive with the given name (use for all databases except maintenance and timestamp) More...
 
void DeleteDriveFromOtherDB (const std::string &drive)
 Deletes the drive with the given name (use for maintenance and timestamp databases) More...
 
void EditField (tree::Node *node, const std::string &name, const std::string &key, const std::string &val)
 Edits the given field and sets the new parameters. More...
 
void GetAttributes (const std::vector< std::string > &params, const std::string &filename, std::vector< std::string > &results)
 Returns the demanded attributes for the given file. More...
 
const std::string isAttributeExist (const std::string i_attr)
 Test if an attribute is referenced for a given treeHandler. More...
 

Private Member Functions

void AddFile (const std::string &filename)
 
void AddDirectoryRecursor (const std::string &directory, bool recurse, const std::string &addKey)
 Recursive method which does the main job for AddDirectory. More...
 

Private Attributes

TreeHandlermTreeHandler
 
SynchronizermSynchronizer
 
ImageReader mReader
 
std::string mCurrentDB
 
Progress mProgress
 
ProgressSignalType mProgressSignal
 

Detailed Description

Object which can add images files to a TreeHandler. Is able to parse (recursively) a part of a filesystem to look for known images and load their attributes in order to add the images to a Tree (submission via a TreeHandler::AddBranch)

Definition at line 52 of file creaImageIOTreeHandlerImageAdder.h.

Member Typedef Documentation

typedef ProgressSignalType::slot_function_type creaImageIO::TreeHandlerImageAdder::ProgressCallbackType

Definition at line 116 of file creaImageIOTreeHandlerImageAdder.h.

Constructor & Destructor Documentation

creaImageIO::TreeHandlerImageAdder::TreeHandlerImageAdder ( TreeHandler tree)

Ctor.

Definition at line 48 of file creaImageIOTreeHandlerImageAdder.cpp.

49  : mTreeHandler(tree)
50  {
51  }
creaImageIO::TreeHandlerImageAdder::~TreeHandlerImageAdder ( )

Dtor.

Definition at line 53 of file creaImageIOTreeHandlerImageAdder.cpp.

54  {
55  }

Member Function Documentation

void creaImageIO::TreeHandlerImageAdder::AddDirectory ( const std::string &  directory,
bool  recurse 
)

(Recursively) adds the files of a directory to the TreeHandler

Definition at line 104 of file creaImageIOTreeHandlerImageAdder.cpp.

References AddDirectoryRecursor(), creaImageIO::TreeHandler::BeginTransaction(), creaImageIO::TreeHandler::EndTransaction(), creaImageIO::Synchronizer::GetAttribute(), creaImageIO::Synchronizer::GetList(), creaImageIO::TreeHandlerImageAdder::Progress::GetNumberAddedFiles(), GetProgress(), GimmickDebugMessage, creaImageIO::Synchronizer::InsertAddOp(), mCurrentDB, mProgress, mSynchronizer, mTreeHandler, creaImageIO::TreeHandlerImageAdder::Progress::Reset(), and creaImageIO::Synchronizer::SetAttribute().

Referenced by creaImageIO::Gimmick::AddDir().

106  {
107  mProgress.Reset();
108  std::stringstream files;
109 
110  std::stringstream rec;
111  rec<<recurse;
112  mSynchronizer->InsertAddOp(directory,rec.str(),"0",mCurrentDB);
113  std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","ADD_OPS","PATH",directory,mCurrentDB);
116  AddDirectoryRecursor( directory, recurse, addKey );
117  //DicomImageScanner sc;
118  //AddDirectoryRecursorScanner(directory, recurse, addKey, sc, false );
119 
120  int nFiles=GetProgress().GetNumberAddedFiles();
121  files<<nFiles;
122  mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",files.str(),"ADD_KEY",addKey,mCurrentDB);
124  GimmickDebugMessage(3,mProgress<<std::endl);
125  }

Here is the call graph for this function:

Here is the caller graph for this function:

void creaImageIO::TreeHandlerImageAdder::AddDirectoryRecursor ( const std::string &  directory,
bool  recurse,
const std::string &  addKey 
)
private

Recursive method which does the main job for AddDirectory.

fix warning: unused variable lastModif

Definition at line 277 of file creaImageIOTreeHandlerImageAdder.cpp.

References AddFile(), creaImageIO::TreeHandlerImageAdder::Progress::GetStop(), GimmickDebugMessage, creaImageIO::TreeHandlerImageAdder::Progress::IncNumberHandledFiles(), creaImageIO::TreeHandlerImageAdder::Progress::IncNumberScannedDirs(), creaImageIO::TreeHandlerImageAdder::Progress::IncNumberScannedFiles(), creaImageIO::Synchronizer::InsertIgnoreFile(), IsHandledFile(), creaImageIO::Synchronizer::isIndexed(), mCurrentDB, mProgress, mProgressSignal, and mSynchronizer.

Referenced by AddDirectory().

280  {
281  GimmickDebugMessage(4,"Scanning '"<<dirpath<<"'"<<std::endl);
283 
284  if ( !fs::exists( dirpath ) ) return;
285 
287  time_t lastModif=fs::last_write_time(dirpath);
288 
289  fs::directory_iterator end_itr; // default construction yields past-the-end
290  for ( fs::directory_iterator itr( dirpath );
291  itr != end_itr;
292  ++itr )
293  {
294  // If is directory & recurse : do recurse
295  if ( fs::is_directory(itr->status()) )
296  {
297  if (recursive)
298  {
299  AddDirectoryRecursor( itr->path().string(), recursive, addKey);
300  }
301  }
302  else
303  {
304  std::string parent_id;
305  // tTest if directory (and only it) exists or not.
306  bool valid = mSynchronizer->isIndexed(itr->path().string());//true;//=mTimestampHandler->AddDirectory(dirpath, itr->string(), lastModif, time(0),mCurrentDB);
307  if(valid)
308  {
310  if (IsHandledFile(itr->path().string()))
311  {
313  AddFile( itr->path().string() );
314  //mTreeHandler->GetTopLevelNodeId("FullFileName",itr->string(),parent_id);
315  std::stringstream removedOn;
316  removedOn<<time(0);
317  mSynchronizer->InsertIgnoreFile(addKey, itr->path().string(),"0",removedOn.str(),mCurrentDB);
318  }
319 
321  if (mProgress.GetStop())
322  {
323  //itr = end_itr;
324  break;
325  }
326 
327  }
328  }
329  }
330 
331  }

Here is the call graph for this function:

Here is the caller graph for this function:

void creaImageIO::TreeHandlerImageAdder::AddFile ( const std::string &  filename)
private

Adds a single file to the TreeHandler WITHOUT testing wether it is handled or not hence you have to call IsHandledFile before using AddFile!

Definition at line 128 of file creaImageIOTreeHandlerImageAdder.cpp.

References creaImageIO::TreeHandler::AddBranch(), creaImageIO::tree::Descriptor::BuildAttributeMap(), creaImageIO::tree::Tree::GetDescriptor(), creaImageIO::TreeHandler::GetTree(), GimmickDebugMessage, creaImageIO::TreeHandlerImageAdder::Progress::IncNumberAddedFiles(), mProgress, mReader, mTreeHandler, and creaImageIO::ImageReader::ReadAttributes().

Referenced by AddDirectoryRecursor(), AddFiles(), and Synchronize().

129  {
130  GimmickDebugMessage(4,"Adding '"<<filename<<"'"<<std::endl);
131  std::map< std::string, std::string> attr;
133 
134 
135  mReader.ReadAttributes(filename,attr);
138  //bool bSOPIID = false;
139  //std::map<std::string, std::string>::iterator it_att = attr.begin();
140  //for(; it_att != attr.end(); it_att++)
141  //{
142  // if (it_att->first == "D0008_0018")
143  // {
144  // bSOPIID = mTreeHandler->TestSOPIID(it_attr->second);
145  // break;
146  // }
147  //}
148  //if(bSOPIID)
149  // return;
150 
151  int lev = mTreeHandler->AddBranch(attr);
152 
153  // update the progress according to lev
154  if (lev<mTreeHandler->GetTree().GetNumberOfLevels())
156  }

Here is the call graph for this function:

Here is the caller graph for this function:

void creaImageIO::TreeHandlerImageAdder::AddFiles ( const std::vector< std::string > &  filename)

Adds a list of files to the TreeHandler.

Definition at line 73 of file creaImageIOTreeHandlerImageAdder.cpp.

References AddFile(), creaImageIO::Synchronizer::GetAttribute(), creaImageIO::Synchronizer::GetList(), creaImageIO::TreeHandlerImageAdder::Progress::GetStop(), creaImageIO::TreeHandlerImageAdder::Progress::IncNumberHandledFiles(), creaImageIO::TreeHandlerImageAdder::Progress::IncNumberScannedFiles(), creaImageIO::Synchronizer::InsertAddOp(), creaImageIO::Synchronizer::InsertIgnoreFile(), IsHandledFile(), creaImageIO::Synchronizer::isIndexed(), mCurrentDB, mProgress, mProgressSignal, mSynchronizer, and creaImageIO::TreeHandlerImageAdder::Progress::Reset().

Referenced by creaImageIO::Gimmick::AddFiles().

74  {
75  mProgress.Reset();
76 
77  //unsigned int nbf = filenames.size();
78  std::vector<std::string>::const_iterator i;
80  for (i=filenames.begin();i!=filenames.end();++i)
81  {
82 
84  if (IsHandledFile(*i))
85  {
87  if(mSynchronizer->isIndexed(*i))
88  {
89  mSynchronizer->InsertAddOp((*i),"0","1",mCurrentDB);
90  std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","ADD_OPS","PATH",(*i),mCurrentDB);
91  std::stringstream removedOn;
92  removedOn<<time(0);
93  mSynchronizer->InsertIgnoreFile(addKey,(*i),"0",removedOn.str(),mCurrentDB);
94  AddFile(*i);
95  }
96  }
98  if (mProgress.GetStop()) break;
99  }
100  }

Here is the call graph for this function:

Here is the caller graph for this function:

void creaImageIO::TreeHandlerImageAdder::CheckAttributes ( bool  repair,
std::string &  file,
std::vector< std::string > &  attsModified 
)

Checks the attributes of the database against the ones in disk.

Definition at line 516 of file creaImageIOTreeHandlerImageAdder.cpp.

References creaImageIO::tree::Descriptor::BuildAttributeMap(), creaImageIO::TreeHandler::GetAttribute(), creaImageIO::tree::Tree::GetAttributeDescriptorList(), creaImageIO::tree::Tree::GetDescriptor(), creaImageIO::tree::Tree::GetNumberOfLevels(), creaImageIO::TreeHandler::GetTree(), mReader, mTreeHandler, creaImageIO::ImageReader::ReadAttributes(), and creaImageIO::TreeHandler::SetAttribute().

Referenced by CheckSyncDirectory().

517  {
518  std::map< std::string, std::string> attr;
520  mReader.ReadAttributes(file,attr);
522  tree::LevelDescriptor::AttributeDescriptorListType::const_iterator a;
523  for (a = adl.begin();a!=adl.end();++a)
524  {
525  std::string databaseVal;
526  mTreeHandler->GetAttribute("Image","FullFileName",file,a->GetKey(),databaseVal);
527  std::string fileVal=attr.find(a->GetKey())->second;
528  if ( a->GetFlags()==0 && databaseVal == fileVal)
529  {
530  if(repair)
531  {
532  mTreeHandler->SetAttribute("Image",a->GetKey(),fileVal,"FullFileName", file);
533  }
534  attsModified.push_back(file);
535  }
536 
537  }
538 
539  }

Here is the call graph for this function:

Here is the caller graph for this function:

void creaImageIO::TreeHandlerImageAdder::CheckSyncDirectory ( const std::string &  dirpath,
bool  recursive,
bool  repair,
bool  checkAttributes,
std::vector< std::string > &  i_ignorefiles,
std::vector< std::string > &  attsModified,
std::vector< std::string > &  newfiles 
)

Recursively checks if the directory is synchronized and optionally the state of the attributes.

Definition at line 337 of file creaImageIOTreeHandlerImageAdder.cpp.

References CheckAttributes(), and IsHandledFile().

Referenced by Synchronize().

344  {
345  if ( !fs::exists( dirpath ) ) return;
346  fs::directory_iterator end_itr; // default construction yields past-the-end
347 
348  for ( fs::directory_iterator itr( dirpath ); itr != end_itr; ++itr )
349  {
350  // If is directory & recurse : do recurse
351  if ( fs::is_directory(itr->status()) )
352  {
353  if (recursive)
354  {
355  CheckSyncDirectory( itr->path().string(), recursive, repair, checkAttributes, i_ignorefiles, attsModified, newfiles);
356  }
357  }
358  else
359  {
360  if (IsHandledFile(itr->path().string()))
361  {
362  bool bfound = false;
363  for(std::vector<std::string>::iterator it_new = i_ignorefiles.begin(); it_new < i_ignorefiles.end(); ++it_new)
364  {
365  if((*it_new) == itr->path().string())
366  {
367  bfound = true;
368  //Additional checking of attributes
369  if(checkAttributes)
370  {
371  CheckAttributes(repair,(*it_new),attsModified);
372  }
373  i_ignorefiles.erase(it_new);
374  break;
375  }
376  }
377  if(!bfound && i_ignorefiles.size()>0 )
378  {
379  newfiles.push_back( itr->path().string() );
380  }
381  }
382  }
383  }
384  }

Here is the call graph for this function:

Here is the caller graph for this function:

void creaImageIO::TreeHandlerImageAdder::ConnectProgressObserver ( ProgressCallbackType  callback)

Adds the function f to the list of functions to call when the addition progresses. f is of type ProgressCallbackType which is: void (*ProgressCallbackType)(Progress&) To pass a member function 'f' of an instance 'c' of a class 'C' as callback you have to 'bind' it, i.e. call: ConnectProgressObserver ( boost::bind( &C::f , c, _1 ) );

Definition at line 59 of file creaImageIOTreeHandlerImageAdder.cpp.

References mProgressSignal.

60  {
61  mProgressSignal.connect(callback);
62  }
void creaImageIO::TreeHandlerImageAdder::CopyFiles ( const std::vector< std::string > &  filenames,
const std::string  directory 
)

Copies the files indicated in the vector and updates all databases.

Definition at line 597 of file creaImageIOTreeHandlerImageAdder.cpp.

References creaImageIO::Synchronizer::GetAttribute(), creaImageIO::Synchronizer::InsertAddOp(), creaImageIO::Synchronizer::InsertIgnoreFile(), mCurrentDB, mSynchronizer, mTreeHandler, creaImageIO::Synchronizer::SetAttribute(), and creaImageIO::TreeHandler::SetAttribute().

Referenced by creaImageIO::Gimmick::CopyFiles().

598  {
599  std::vector<std::string>::const_iterator i;
600  if(!boost::filesystem::exists(directory))
601  {
602  boost::filesystem::create_directory(boost::filesystem::path(directory));
603  mSynchronizer->InsertAddOp(directory,"0","0",mCurrentDB);
604  }
605  std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","ADD_OPS","PATH",directory,mCurrentDB);
606  size_t last;
607  std::vector<std::string> newNames;
608  for(i=filenames.begin();i!=filenames.end();++i)
609  {
610  std::string dir=directory.c_str();
611  if(boost::filesystem::exists(*i) && (*i).find(dir)==std::string::npos)
612  {
613  std::string path=*i;
614  last=(*i).find_last_of('/');
615  std::string f="\\"+(*i).substr(last+1);
616 
617  int p=1;
618  std::stringstream out;
619  out<<directory<<f;
620  while(boost::filesystem::exists(out.str()))
621  {
622  out.str("");
623  out<<directory<<f.substr(0,f.size()-4)<<"("<<p<<")"<<f.substr(f.size()-4);
624  p++;
625  }
626  std::string result=out.str();
627  boost::filesystem::copy_file((*i),result);
628 
629  //To update image database
630  mTreeHandler->SetAttribute("Image","FullFileName",result,"FullFileName", (*i));
631 
632  //To update maintenance database
633  //1.Add the new path and increase number of children on new operation.
634  std::stringstream removedOn;
635  removedOn<<time(0);
636  //Inserts the file
637  mSynchronizer->InsertIgnoreFile(addKey, result,"0",removedOn.str(),mCurrentDB);
638  //Gets the number of files added
639  int files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",addKey,mCurrentDB)).c_str());
640  files=files+1;
641  std::stringstream fil;
642  fil<<files;
643  //Sets the new number of files
644  mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",fil.str(),"ADD_KEY",addKey,mCurrentDB);
645  fil.str("");
646 
647  //2.Set the old path as removed and decrease number of children on old operation.
648  //Gets the old add key
649  std::string oldAddKey=mSynchronizer->GetAttribute("ADD_KEY","IGNORED_FILES","PATH",path,mCurrentDB);
650  //Sets the file as removed
651  mSynchronizer->SetAttribute("REMOVE","IGNORED_FILES","1","PATH = '"+path+"' AND ADD_KEY",oldAddKey,mCurrentDB);
652  //Gets the number of files added
653  files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",oldAddKey,mCurrentDB)).c_str());
654  files=files-1;
655  fil<<files;
656  //Sets the new number of files
657  mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",fil.str(),"ADD_KEY",oldAddKey,mCurrentDB);
658 
659  }
660 
661  }
662  }

Here is the call graph for this function:

Here is the caller graph for this function:

void creaImageIO::TreeHandlerImageAdder::DeleteDriveFromMainDB ( const std::string &  drive)

Deletes the drive with the given name (use for all databases except maintenance and timestamp)

Definition at line 666 of file creaImageIOTreeHandlerImageAdder.cpp.

References FindNodePartial(), creaImageIO::tree::Node::GetChildrenList(), creaImageIO::TreeHandler::GetTree(), creaImageIO::TreeHandler::LoadChildren(), mTreeHandler, and creaImageIO::TreeHandler::Remove().

Referenced by creaImageIO::Gimmick::DeleteDrive().

667  {
668  //Delete from local database and others
669  tree::Node* node=0;
670  mTreeHandler->LoadChildren(NULL,4);
671  FindNodePartial(mTreeHandler->GetTree().GetChildrenList()[0],3,"FullFileName",drive,node);
672  while(node!=0)
673  {
674  mTreeHandler->Remove(node);
675  node=0;
676  mTreeHandler->LoadChildren(NULL,4);
677  FindNodePartial(mTreeHandler->GetTree().GetChildrenList()[0],3,"FullFileName",drive,node);
678  }
679  }

Here is the call graph for this function:

Here is the caller graph for this function:

void creaImageIO::TreeHandlerImageAdder::DeleteDriveFromOtherDB ( const std::string &  drive)

Deletes the drive with the given name (use for maintenance and timestamp databases)

Definition at line 683 of file creaImageIOTreeHandlerImageAdder.cpp.

References mSynchronizer, and creaImageIO::Synchronizer::RemoveEntries().

Referenced by creaImageIO::Gimmick::DeleteDrive().

684  {
685  //Delete from maintenance
686  mSynchronizer->RemoveEntries("ADD_OPS", "PATH", "LIKE", drive+"%");
687  mSynchronizer->RemoveEntries("IGNORED_FILES", "PATH", "LIKE", drive+"%");
688  }

Here is the call graph for this function:

Here is the caller graph for this function:

void creaImageIO::TreeHandlerImageAdder::EditField ( tree::Node node,
const std::string &  name,
const std::string &  key,
const std::string &  val 
)

Edits the given field and sets the new parameters.

Definition at line 691 of file creaImageIOTreeHandlerImageAdder.cpp.

References mTreeHandler, creaImageIO::tree::Node::SetAttribute(), and creaImageIO::TreeHandler::SetAttribute().

Referenced by creaImageIO::Gimmick::EditField().

692  {
693  node->SetAttribute(key,val);
694  mTreeHandler->SetAttribute(node,key,val);
695  }

Here is the call graph for this function:

Here is the caller graph for this function:

void creaImageIO::TreeHandlerImageAdder::FindNode ( tree::Node parent,
int  level,
const std::string &  searchParam,
const std::string &  searchVal,
tree::Node *&  node 
)

Finds the node that matches the specified parameters.

Definition at line 544 of file creaImageIOTreeHandlerImageAdder.cpp.

References creaImageIO::tree::Node::GetAttribute(), and creaImageIO::tree::Node::GetChildrenList().

Referenced by Synchronize().

545  {
546  if(level>1)
547  {
548  std::vector<tree::Node*>::iterator iter;
549  for(iter=parent->GetChildrenList().begin();iter!=parent->GetChildrenList().end();++iter)
550  {
551  FindNode(*iter,level-1,searchParam,searchVal,node);
552  }
553  }
554  else
555  {
556  if(parent->GetAttribute(searchParam).compare(searchVal)==0)
557  {
558  node=parent;
559  }
560 
561  }
562  }

Here is the call graph for this function:

Here is the caller graph for this function:

void creaImageIO::TreeHandlerImageAdder::FindNodePartial ( tree::Node parent,
int  level,
const std::string &  searchParam,
const std::string &  searchVal,
tree::Node *&  node 
)

Finds the nodes that partially match the searchVal.

Definition at line 574 of file creaImageIOTreeHandlerImageAdder.cpp.

References creaImageIO::tree::Node::GetAttribute(), and creaImageIO::tree::Node::GetChildrenList().

Referenced by DeleteDriveFromMainDB().

575  {
576  if(level>1)
577  {
578  std::vector<tree::Node*>::iterator iter;
579  for(iter=parent->GetChildrenList().begin();iter!=parent->GetChildrenList().end() && node==0 ;++iter)
580  {
581  FindNodePartial(*iter,level-1,searchParam,searchVal,node);
582  }
583  }
584  else
585  {
586  if(parent->GetAttribute(searchParam).find(searchVal)<9000)
587  {
588  node=parent;
589  return;
590  }
591 
592  }
593  }

Here is the call graph for this function:

Here is the caller graph for this function:

void creaImageIO::TreeHandlerImageAdder::GetAttributes ( const std::vector< std::string > &  params,
const std::string &  filename,
std::vector< std::string > &  results 
)

Returns the demanded attributes for the given file.

Definition at line 698 of file creaImageIOTreeHandlerImageAdder.cpp.

References creaImageIO::TreeHandler::GetAttribute(), and mTreeHandler.

Referenced by creaImageIO::Gimmick::GetAttributes().

701  {
702  std::vector<std::string>::const_iterator i;
703  std::string result;
704  for(i=params.begin();i!=params.end();i++)
705  {
706  mTreeHandler->GetAttribute("Image","FullFileName",filename,*i,result);
707  results.push_back(result);
708  }
709  }

Here is the call graph for this function:

Here is the caller graph for this function:

const Progress& creaImageIO::TreeHandlerImageAdder::GetProgress ( ) const
inline

Definition at line 111 of file creaImageIOTreeHandlerImageAdder.h.

References mProgress.

Referenced by AddDirectory().

111 { return mProgress; }

Here is the caller graph for this function:

const std::string creaImageIO::TreeHandlerImageAdder::isAttributeExist ( const std::string  i_attr)

Test if an attribute is referenced for a given treeHandler.

Definition at line 712 of file creaImageIOTreeHandlerImageAdder.cpp.

References creaImageIO::TreeHandler::GetTree(), creaImageIO::tree::Tree::isAttributeExist(), and mTreeHandler.

Referenced by creaImageIO::Gimmick::fillVectInfos().

713  {
714  return mTreeHandler->GetTree().isAttributeExist(i_attr);
715  }

Here is the call graph for this function:

Here is the caller graph for this function:

bool creaImageIO::TreeHandlerImageAdder::IsHandledFile ( const std::string &  filename)

Returns if the file can be read or not.

Definition at line 66 of file creaImageIOTreeHandlerImageAdder.cpp.

References creaImageIO::ImageReader::CanRead(), and mReader.

Referenced by AddDirectoryRecursor(), AddFiles(), CheckSyncDirectory(), and Synchronize().

67  {
68  return (mReader.CanRead(filename));
69  }

Here is the call graph for this function:

Here is the caller graph for this function:

void creaImageIO::TreeHandlerImageAdder::remove ( tree::Node i_node)

Definition at line 193 of file creaImageIOTreeHandlerImageAdder.cpp.

References creaImageIO::tree::Node::GetAttribute(), creaImageIO::Synchronizer::GetAttribute(), mCurrentDB, mSynchronizer, and creaImageIO::Synchronizer::SetAttribute().

194  {
195  std::string path=i_node->GetAttribute("FullFileName");
196  //Gets the add key
197  std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","IGNORED_FILES","PATH",path,mCurrentDB);
198  //Gets the number of files added
199  int files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",addKey,mCurrentDB)).c_str());
200  files=files-1;
201  std::stringstream out;
202  out<<files;
203  //Sets the new number of files
204  mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",out.str(),"ADD_KEY",addKey,mCurrentDB);
205  //Sets the file as removed
206  mSynchronizer->SetAttribute("REMOVE","IGNORED_FILES","1","PATH = '"+path+"' AND ADD_KEY",addKey,mCurrentDB);
207  }

Here is the call graph for this function:

void creaImageIO::TreeHandlerImageAdder::RemoveFile ( tree::Node node)

Removes a file from the databases.

Definition at line 159 of file creaImageIOTreeHandlerImageAdder.cpp.

References creaImageIO::tree::Node::GetChildrenList(), creaImageIO::tree::Node::GetNumberOfChildren(), and RemoveFiles().

Referenced by creaImageIO::Gimmick::RemoveFile(), and Synchronize().

160  {
161  int n=node->GetNumberOfChildren();
162  if(n>0)
163  {
164  RemoveFiles(node->GetChildrenList());
165  }
166  else
167  {
168  remove(node);
169  }
170  }

Here is the call graph for this function:

Here is the caller graph for this function:

void creaImageIO::TreeHandlerImageAdder::RemoveFiles ( const std::vector< tree::Node * > &  nodes)

Removes files from the databases.

Definition at line 174 of file creaImageIOTreeHandlerImageAdder.cpp.

Referenced by RemoveFile().

175  {
176  std::vector<tree::Node*>::const_iterator it;
177  for(it=nodes.begin();it!=nodes.end();++it)
178  {
179  int n=(*it)->GetNumberOfChildren();
180  if(n>0)
181  {
182  RemoveFiles((*it)->GetChildrenList());
183  }
184  else
185  {
186  remove(*it);
187  }
188 
189  }
190  }

Here is the caller graph for this function:

void creaImageIO::TreeHandlerImageAdder::SaveAs ( const std::vector< std::string > &  filenames,
std::vector< vtkImageData * >  i_images 
)

Saves as the files indicated in the vector in a specific directory.

Definition at line 564 of file creaImageIOTreeHandlerImageAdder.cpp.

565  {
566  std::vector<std::string>::const_iterator it_file = filenames.begin();
567  std::vector<vtkImageData *>::iterator it_image = i_images.begin();
568  /* mWriter.CanWrite(".jpeg");
569  for(; it_file != filenames.end(); ++it_file, ++it_image)
570  mWriter.WriteImage(it_file->c_str(), (vtkImageData &)it_image);*/
571  }
void creaImageIO::TreeHandlerImageAdder::SetCurrentDatabase ( std::string  cur)
inline
void creaImageIO::TreeHandlerImageAdder::SetSynchronizer ( Synchronizer s)
inline
std::string creaImageIO::TreeHandlerImageAdder::Synchronize ( bool  repair,
bool  checkAttributes 
)

Synchronizes the DB and disk by repeating the operations the user has done and returns a report.

Definition at line 390 of file creaImageIOTreeHandlerImageAdder.cpp.

References AddFile(), CheckSyncDirectory(), FindNode(), creaImageIO::Synchronizer::GetAttribute(), creaImageIO::tree::Node::GetChildrenList(), creaImageIO::Synchronizer::GetFileList(), creaImageIO::Synchronizer::GetIgnoredFiles(), creaImageIO::TreeHandler::GetTree(), creaImageIO::Synchronizer::InsertIgnoreFile(), IsHandledFile(), creaImageIO::TreeHandler::LoadChildren(), mCurrentDB, mSynchronizer, mTreeHandler, creaImageIO::TreeHandler::Remove(), RemoveFile(), and creaImageIO::Synchronizer::SetAttribute().

Referenced by creaImageIO::Gimmick::Synchronize().

391  {
392  std::vector<AddList> fileList;
393  std::vector<std::string> ignoreList;
394  std::vector<std::string> newFiles;
395  std::vector<std::string> attsModified;
396  std::stringstream mess;
397  std::vector<AddList>::iterator iter;
398 
399  //Gets the list of added files
401 
402  std::vector<std::string>::iterator i;
403  //Actions to take if the user doesn't want to repair
404  if(!repair)
405  {
406  //Iterates to see if they are in sync
407  for(iter=fileList.begin();iter!=fileList.end();++iter)
408  {
409  mSynchronizer->GetIgnoredFiles((*iter).key,ignoreList);
410  bool rec=true;
411  if((*iter).recursive=="0"){rec=false;}
412  CheckSyncDirectory((*iter).path,rec,repair,checkAttributes,ignoreList,attsModified,newFiles);
413  }
414 
415  //Add to message the result of new found files
416  mess<<"New Files Found: "<<newFiles.size()<<std::endl;
417  if(newFiles.size()>0)
418  {
419  mess<<"Filenames: "<<std::endl;
420  for(i=newFiles.begin();i!=newFiles.end();++i)
421  {
422  mess<<*i<<std::endl;
423  }
424  }
425 
426  //Add to message the result of missing files
427  mess<<"Missing Files: "<<ignoreList.size()<<std::endl;
428  if(ignoreList.size()>0)
429  {
430  mess<<"Filenames: "<<std::endl;
431  for(i=ignoreList.begin();i!=ignoreList.end();++i)
432  {
433  mess<<*i<<std::endl;
434  }
435  }
436 
437  //In the case that the user wants to check the attributes...
438  if(checkAttributes)
439  {
440  //... add to message the result of files that have been changed.
441  mess<<"Files with different attributes: "<<attsModified.size()<<std::endl;
442  if(attsModified.size()>0)
443  {
444  mess<<"Filenames: "<<std::endl;
445  for(i=attsModified.begin();i!=attsModified.end();++i)
446  {
447  mess<<*i<<std::endl;
448  }
449  }
450  }
451 
452  }
453 
454  //Actions to take if the user wants to repair
455  else
456  {
457  int nf=0;
458  //Iterates to see if they are in sync
459  for(iter=fileList.begin();iter!=fileList.end();++iter)
460  {
461  mSynchronizer->GetIgnoredFiles((*iter).key,ignoreList);
462  bool rec=true;
463  if((*iter).recursive=="0"){rec=false;}
464  CheckSyncDirectory((*iter).path,rec,repair,checkAttributes,ignoreList,attsModified,newFiles);
465 
466  //For the new files, add them
467  for (i=newFiles.begin();i!=newFiles.end();++i)
468  {
469  if (IsHandledFile(*i))
470  {
471  std::stringstream removedOn;
472  removedOn<<time(0);
473  mSynchronizer->InsertIgnoreFile((*iter).key,(*i),"0",removedOn.str(),mCurrentDB);
474  //Gets the number of files added
475  int files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",(*iter).key,mCurrentDB)).c_str());
476  files=files+1;
477  std::stringstream out;
478  out<<files;
479  //Sets the new number of files
480  mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",out.str(),"ADD_KEY",(*iter).key,mCurrentDB);
481  AddFile(*i);
482  }
483  }
484  nf+=(int)newFiles.size();
485  newFiles.clear();
486 
487  }
488  //Reports number of added files
489  mess<<"Files Added: "<<nf<<std::endl;
490 
491  //Removes the necessary files and reports the results
492  if(ignoreList.size()>0)
493  {
494  tree::Node* node;
495  mTreeHandler->LoadChildren(NULL,4);
496  for(i=ignoreList.begin();i!=ignoreList.end();++i)
497  {
498  FindNode(mTreeHandler->GetTree().GetChildrenList()[0],3,"FullFileName",*i,node);
499  RemoveFile(node);
500  mTreeHandler->Remove(node);
501  }
502  }
503  mess<<"Files Removed: "<<ignoreList.size()<<std::endl;
504  //In the case that the user wants to check the attributes...
505  if(checkAttributes)
506  {
507  //... add to message the result of files that were modified.
508  mess<<"Files Modified: "<<attsModified.size()<<std::endl;
509  }
510  }
511  return mess.str();
512 
513  }

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

std::string creaImageIO::TreeHandlerImageAdder::mCurrentDB
private
Progress creaImageIO::TreeHandlerImageAdder::mProgress
private
ProgressSignalType creaImageIO::TreeHandlerImageAdder::mProgressSignal
private
ImageReader creaImageIO::TreeHandlerImageAdder::mReader
private

Definition at line 210 of file creaImageIOTreeHandlerImageAdder.h.

Referenced by AddFile(), CheckAttributes(), and IsHandledFile().

Synchronizer* creaImageIO::TreeHandlerImageAdder::mSynchronizer
private

The documentation for this class was generated from the following files: