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>
Classes | |
class | Progress |
Public Types | |
typedef boost::signal< void(Progress &)> | ProgressSignalType |
typedef ProgressSignalType::slot_function_type | ProgressCallbackType |
Public Member Functions | |
TreeHandlerImageAdder (TreeHandler *tree) | |
Ctor. | |
~TreeHandlerImageAdder () | |
Dtor. | |
void | SetTreeHandler (TreeHandler *tree) |
Sets the TreeHandler. | |
void | SetSynchronizer (Synchronizer *s) |
Sets the synchronizer. | |
void | SetCurrentDatabase (std::string cur) |
Sets the synchronizer. | |
const Progress & | GetProgress () const |
void | ConnectProgressObserver (ProgressCallbackType callback) |
bool | IsHandledFile (const std::string &filename) |
Returns if the file can be read or not. | |
void | AddFiles (const std::vector< std::string > &filename) |
Adds a list of files to the TreeHandler. | |
void | AddDirectory (const std::string &directory, bool recurse) |
(Recursively) adds the files of a directory to the TreeHandler | |
void | RemoveFile (tree::Node *node) |
Removes a file from the databases. | |
void | RemoveFiles (const std::vector< tree::Node * > &nodes) |
Removes files from the databases. | |
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. | |
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. | |
void | CopyFiles (const std::vector< std::string > &filenames, const std::string directory) |
Copies the files indicated in the vector and updates all databases. | |
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. | |
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. | |
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. | |
void | CheckAttributes (bool repair, std::string &file, std::vector< std::string > &attsModified) |
Checks the attributes of the database against the ones in disk. | |
void | DeleteDriveFromMainDB (const std::string &drive) |
Deletes the drive with the given name (use for all databases except maintenance and timestamp). | |
void | DeleteDriveFromOtherDB (const std::string &drive) |
Deletes the drive with the given name (use for maintenance and timestamp databases). | |
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. | |
void | GetAttributes (const std::vector< std::string > ¶ms, const std::string &filename, std::vector< std::string > &results) |
Returns the demanded attributes for the given file. | |
const std::string | isAttributeExist (const std::string i_attr) |
Test if an attribute is referenced for a given treeHandler. | |
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. | |
Private Attributes | |
TreeHandler * | mTreeHandler |
Synchronizer * | mSynchronizer |
ImageReader | mReader |
std::string | mCurrentDB |
Progress | mProgress |
ProgressSignalType | mProgressSignal |
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 25 of file creaImageIOTreeHandlerImageAdder.h.
typedef ProgressSignalType::slot_function_type creaImageIO::TreeHandlerImageAdder::ProgressCallbackType |
Definition at line 89 of file creaImageIOTreeHandlerImageAdder.h.
typedef boost::signal<void (Progress&)> creaImageIO::TreeHandlerImageAdder::ProgressSignalType |
Definition at line 88 of file creaImageIOTreeHandlerImageAdder.h.
creaImageIO::TreeHandlerImageAdder::TreeHandlerImageAdder | ( | TreeHandler * | tree | ) |
creaImageIO::TreeHandlerImageAdder::~TreeHandlerImageAdder | ( | ) |
void creaImageIO::TreeHandlerImageAdder::AddDirectory | ( | const std::string & | directory, | |
bool | recurse | |||
) |
(Recursively) adds the files of a directory to the TreeHandler
Definition at line 77 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().
{ mProgress.Reset(); std::stringstream files; std::stringstream rec; rec<<recurse; mSynchronizer->InsertAddOp(directory,rec.str(),"0",mCurrentDB); std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","ADD_OPS","PATH",directory,mCurrentDB); mTreeHandler->BeginTransaction(); mSynchronizer->GetList(mCurrentDB); AddDirectoryRecursor( directory, recurse, addKey ); //DicomImageScanner sc; //AddDirectoryRecursorScanner(directory, recurse, addKey, sc, false ); int nFiles=GetProgress().GetNumberAddedFiles(); files<<nFiles; mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",files.str(),"ADD_KEY",addKey,mCurrentDB); mTreeHandler->EndTransaction(); GimmickDebugMessage(3,mProgress<<std::endl); }
void creaImageIO::TreeHandlerImageAdder::AddDirectoryRecursor | ( | const std::string & | directory, | |
bool | recurse, | |||
const std::string & | addKey | |||
) | [private] |
Recursive method which does the main job for AddDirectory.
Definition at line 250 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().
{ GimmickDebugMessage(4,"Scanning '"<<dirpath<<"'"<<std::endl); mProgress.IncNumberScannedDirs(); if ( !fs::exists( dirpath ) ) return; time_t lastModif=fs::last_write_time(dirpath); fs::directory_iterator end_itr; // default construction yields past-the-end for ( fs::directory_iterator itr( dirpath ); itr != end_itr; ++itr ) { // If is directory & recurse : do recurse if ( fs::is_directory(itr->status()) ) { if (recursive) { AddDirectoryRecursor( itr->string(), recursive, addKey); } } else { std::string parent_id; // tTest if directory (and only it) exists or not. bool valid = mSynchronizer->isIndexed(itr->string());//true;//=mTimestampHandler->AddDirectory(dirpath, itr->string(), lastModif, time(0),mCurrentDB); if(valid) { mProgress.IncNumberScannedFiles(); if (IsHandledFile(itr->string())) { mProgress.IncNumberHandledFiles(); AddFile( itr->string() ); //mTreeHandler->GetTopLevelNodeId("FullFileName",itr->string(),parent_id); std::stringstream removedOn; removedOn<<time(0); mSynchronizer->InsertIgnoreFile(addKey, itr->string(),"0",removedOn.str(),mCurrentDB); } mProgressSignal(mProgress); if (mProgress.GetStop()) { //itr = end_itr; break; } } } } }
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 101 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().
{ GimmickDebugMessage(4,"Adding '"<<filename<<"'"<<std::endl); std::map< std::string, std::string> attr; mTreeHandler->GetTree().GetDescriptor().BuildAttributeMap(attr); mReader.ReadAttributes(filename,attr); //bool bSOPIID = false; //std::map<std::string, std::string>::iterator it_att = attr.begin(); //for(; it_att != attr.end(); it_att++) //{ // if (it_att->first == "D0008_0018") // { // bSOPIID = mTreeHandler->TestSOPIID(it_attr->second); // break; // } //} //if(bSOPIID) // return; int lev = mTreeHandler->AddBranch(attr); // update the progress according to lev if (lev<mTreeHandler->GetTree().GetNumberOfLevels()) mProgress.IncNumberAddedFiles(); }
void creaImageIO::TreeHandlerImageAdder::AddFiles | ( | const std::vector< std::string > & | filename | ) |
Adds a list of files to the TreeHandler.
Definition at line 46 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().
{ mProgress.Reset(); unsigned int nbf = filenames.size(); std::vector<std::string>::const_iterator i; mSynchronizer->GetList(mCurrentDB); for (i=filenames.begin();i!=filenames.end();++i) { mProgress.IncNumberScannedFiles(); if (IsHandledFile(*i)) { mProgress.IncNumberHandledFiles(); if(mSynchronizer->isIndexed(*i)) { mSynchronizer->InsertAddOp((*i),"0","1",mCurrentDB); std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","ADD_OPS","PATH",(*i),mCurrentDB); std::stringstream removedOn; removedOn<<time(0); mSynchronizer->InsertIgnoreFile(addKey,(*i),"0",removedOn.str(),mCurrentDB); AddFile(*i); } } mProgressSignal(mProgress); if (mProgress.GetStop()) break; } }
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 488 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().
{ std::map< std::string, std::string> attr; mTreeHandler->GetTree().GetDescriptor().BuildAttributeMap(attr); mReader.ReadAttributes(file,attr); tree::LevelDescriptor::AttributeDescriptorListType adl= mTreeHandler->GetTree().GetAttributeDescriptorList(mTreeHandler->GetTree().GetNumberOfLevels()-1); tree::LevelDescriptor::AttributeDescriptorListType::const_iterator a; for (a = adl.begin();a!=adl.end();++a) { std::string databaseVal; mTreeHandler->GetAttribute("Image","FullFileName",file,a->GetKey(),databaseVal); std::string fileVal=attr.find(a->GetKey())->second; if ( a->GetFlags()==0 && databaseVal == fileVal) { if(repair) { mTreeHandler->SetAttribute("Image",a->GetKey(),fileVal,"FullFileName", file); } attsModified.push_back(file); } } }
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 309 of file creaImageIOTreeHandlerImageAdder.cpp.
References CheckAttributes(), and IsHandledFile().
Referenced by Synchronize().
{ if ( !fs::exists( dirpath ) ) return; fs::directory_iterator end_itr; // default construction yields past-the-end for ( fs::directory_iterator itr( dirpath ); itr != end_itr; ++itr ) { // If is directory & recurse : do recurse if ( fs::is_directory(itr->status()) ) { if (recursive) { CheckSyncDirectory( itr->string(), recursive, repair, checkAttributes, i_ignorefiles, attsModified, newfiles); } } else { if (IsHandledFile(itr->string())) { bool bfound = false; for(std::vector<std::string>::iterator it_new = i_ignorefiles.begin(); it_new < i_ignorefiles.end(); ++it_new) { if((*it_new) == itr->string()) { bfound = true; //Additional checking of attributes if(checkAttributes) { CheckAttributes(repair,(*it_new),attsModified); } i_ignorefiles.erase(it_new); break; } } if(!bfound && i_ignorefiles.size()>0 ) { newfiles.push_back( itr->string() ); } } } } }
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 32 of file creaImageIOTreeHandlerImageAdder.cpp.
References mProgressSignal.
{ mProgressSignal.connect(callback); }
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 569 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().
{ std::vector<std::string>::const_iterator i; if(!boost::filesystem::exists(directory)) { boost::filesystem::create_directory(boost::filesystem::path(directory)); mSynchronizer->InsertAddOp(directory,"0","0",mCurrentDB); } std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","ADD_OPS","PATH",directory,mCurrentDB); size_t last; std::vector<std::string> newNames; for(i=filenames.begin();i!=filenames.end();++i) { std::string dir=directory.c_str(); if(boost::filesystem::exists(*i) && (*i).find(dir)==std::string::npos) { std::string path=*i; last=(*i).find_last_of('/'); std::string f="\\"+(*i).substr(last+1); int p=1; std::stringstream out; out<<directory<<f; while(boost::filesystem::exists(out.str())) { out.str(""); out<<directory<<f.substr(0,f.size()-4)<<"("<<p<<")"<<f.substr(f.size()-4); p++; } std::string result=out.str(); boost::filesystem::copy_file((*i),result); //To update image database mTreeHandler->SetAttribute("Image","FullFileName",result,"FullFileName", (*i)); //To update maintenance database //1.Add the new path and increase number of children on new operation. std::stringstream removedOn; removedOn<<time(0); //Inserts the file mSynchronizer->InsertIgnoreFile(addKey, result,"0",removedOn.str(),mCurrentDB); //Gets the number of files added int files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",addKey,mCurrentDB)).c_str()); files=files+1; std::stringstream fil; fil<<files; //Sets the new number of files mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",fil.str(),"ADD_KEY",addKey,mCurrentDB); fil.str(""); //2.Set the old path as removed and decrease number of children on old operation. //Gets the old add key std::string oldAddKey=mSynchronizer->GetAttribute("ADD_KEY","IGNORED_FILES","PATH",path,mCurrentDB); //Sets the file as removed mSynchronizer->SetAttribute("REMOVE","IGNORED_FILES","1","PATH = '"+path+"' AND ADD_KEY",oldAddKey,mCurrentDB); //Gets the number of files added files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",oldAddKey,mCurrentDB)).c_str()); files=files-1; fil<<files; //Sets the new number of files mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",fil.str(),"ADD_KEY",oldAddKey,mCurrentDB); } } }
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 638 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().
{ //Delete from local database and others tree::Node* node=0; mTreeHandler->LoadChildren(NULL,4); FindNodePartial(mTreeHandler->GetTree().GetChildrenList()[0],3,"FullFileName",drive,node); while(node!=0) { mTreeHandler->Remove(node); node=0; mTreeHandler->LoadChildren(NULL,4); FindNodePartial(mTreeHandler->GetTree().GetChildrenList()[0],3,"FullFileName",drive,node); } }
void creaImageIO::TreeHandlerImageAdder::DeleteDriveFromOtherDB | ( | const std::string & | drive | ) |
Deletes the drive with the given name (use for maintenance and timestamp databases).
Definition at line 655 of file creaImageIOTreeHandlerImageAdder.cpp.
References mSynchronizer, and creaImageIO::Synchronizer::RemoveEntries().
Referenced by creaImageIO::Gimmick::DeleteDrive().
{ //Delete from maintenance mSynchronizer->RemoveEntries("ADD_OPS", "PATH", "LIKE", drive+"%"); mSynchronizer->RemoveEntries("IGNORED_FILES", "PATH", "LIKE", drive+"%"); }
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 663 of file creaImageIOTreeHandlerImageAdder.cpp.
References mTreeHandler, creaImageIO::TreeHandler::SetAttribute(), and creaImageIO::tree::Node::SetAttribute().
Referenced by creaImageIO::Gimmick::EditField().
{ node->SetAttribute(key,val); mTreeHandler->SetAttribute(node,key,val); }
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 516 of file creaImageIOTreeHandlerImageAdder.cpp.
References creaImageIO::tree::Node::GetAttribute(), and creaImageIO::tree::Node::GetChildrenList().
Referenced by Synchronize().
{ if(level>1) { std::vector<tree::Node*>::iterator iter; for(iter=parent->GetChildrenList().begin();iter!=parent->GetChildrenList().end();++iter) { FindNode(*iter,level-1,searchParam,searchVal,node); } } else { if(parent->GetAttribute(searchParam).compare(searchVal)==0) { node=parent; } } }
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 546 of file creaImageIOTreeHandlerImageAdder.cpp.
References creaImageIO::tree::Node::GetAttribute(), and creaImageIO::tree::Node::GetChildrenList().
Referenced by DeleteDriveFromMainDB().
{ if(level>1) { std::vector<tree::Node*>::iterator iter; for(iter=parent->GetChildrenList().begin();iter!=parent->GetChildrenList().end() && node==0 ;++iter) { FindNodePartial(*iter,level-1,searchParam,searchVal,node); } } else { if(parent->GetAttribute(searchParam).find(searchVal)<9000) { node=parent; return; } } }
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 670 of file creaImageIOTreeHandlerImageAdder.cpp.
References creaImageIO::TreeHandler::GetAttribute(), and mTreeHandler.
Referenced by creaImageIO::Gimmick::GetAttributes().
{ std::vector<std::string>::const_iterator i; std::string result; for(i=params.begin();i!=params.end();i++) { mTreeHandler->GetAttribute("Image","FullFileName",filename,*i,result); results.push_back(result); } }
const Progress& creaImageIO::TreeHandlerImageAdder::GetProgress | ( | ) | const [inline] |
Definition at line 84 of file creaImageIOTreeHandlerImageAdder.h.
References mProgress.
Referenced by AddDirectory().
{ return mProgress; }
const std::string creaImageIO::TreeHandlerImageAdder::isAttributeExist | ( | const std::string | i_attr | ) |
Test if an attribute is referenced for a given treeHandler.
Definition at line 684 of file creaImageIOTreeHandlerImageAdder.cpp.
References creaImageIO::TreeHandler::GetTree(), creaImageIO::tree::Tree::isAttributeExist(), and mTreeHandler.
Referenced by creaImageIO::Gimmick::fillVectInfos().
{ return mTreeHandler->GetTree().isAttributeExist(i_attr); }
bool creaImageIO::TreeHandlerImageAdder::IsHandledFile | ( | const std::string & | filename | ) |
Returns if the file can be read or not.
Definition at line 39 of file creaImageIOTreeHandlerImageAdder.cpp.
References creaImageIO::ImageReader::CanRead(), and mReader.
Referenced by AddDirectoryRecursor(), AddFiles(), CheckSyncDirectory(), and Synchronize().
{ return (mReader.CanRead(filename)); }
void creaImageIO::TreeHandlerImageAdder::remove | ( | tree::Node * | i_node | ) |
Definition at line 166 of file creaImageIOTreeHandlerImageAdder.cpp.
References creaImageIO::Synchronizer::GetAttribute(), creaImageIO::tree::Node::GetAttribute(), mCurrentDB, mSynchronizer, and creaImageIO::Synchronizer::SetAttribute().
{ std::string path=i_node->GetAttribute("FullFileName"); //Gets the add key std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","IGNORED_FILES","PATH",path,mCurrentDB); //Gets the number of files added int files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",addKey,mCurrentDB)).c_str()); files=files-1; std::stringstream out; out<<files; //Sets the new number of files mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",out.str(),"ADD_KEY",addKey,mCurrentDB); //Sets the file as removed mSynchronizer->SetAttribute("REMOVE","IGNORED_FILES","1","PATH = '"+path+"' AND ADD_KEY",addKey,mCurrentDB); }
void creaImageIO::TreeHandlerImageAdder::RemoveFile | ( | tree::Node * | node | ) |
Removes a file from the databases.
Definition at line 132 of file creaImageIOTreeHandlerImageAdder.cpp.
References creaImageIO::tree::Node::GetChildrenList(), creaImageIO::tree::Node::GetNumberOfChildren(), and RemoveFiles().
Referenced by creaImageIO::Gimmick::RemoveFile(), and Synchronize().
{ int n=node->GetNumberOfChildren(); if(n>0) { RemoveFiles(node->GetChildrenList()); } else { remove(node); } }
void creaImageIO::TreeHandlerImageAdder::RemoveFiles | ( | const std::vector< tree::Node * > & | nodes | ) |
Removes files from the databases.
Definition at line 147 of file creaImageIOTreeHandlerImageAdder.cpp.
Referenced by RemoveFile().
{ std::vector<tree::Node*>::const_iterator it; for(it=nodes.begin();it!=nodes.end();++it) { int n=(*it)->GetNumberOfChildren(); if(n>0) { RemoveFiles((*it)->GetChildrenList()); } else { remove(*it); } } }
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 536 of file creaImageIOTreeHandlerImageAdder.cpp.
{ std::vector<std::string>::const_iterator it_file = filenames.begin(); std::vector<vtkImageData *>::iterator it_image = i_images.begin(); /* mWriter.CanWrite(".jpeg"); for(; it_file != filenames.end(); ++it_file, ++it_image) mWriter.WriteImage(it_file->c_str(), (vtkImageData &)it_image);*/ }
void creaImageIO::TreeHandlerImageAdder::SetCurrentDatabase | ( | std::string | cur | ) | [inline] |
Sets the synchronizer.
Definition at line 40 of file creaImageIOTreeHandlerImageAdder.h.
References mCurrentDB.
Referenced by creaImageIO::Gimmick::AddDir(), creaImageIO::Gimmick::AddFiles(), creaImageIO::Gimmick::CopyFiles(), creaImageIO::Gimmick::EditField(), creaImageIO::Gimmick::GetAttributes(), creaImageIO::Gimmick::RemoveFile(), and creaImageIO::Gimmick::Synchronize().
{mCurrentDB=cur;}
void creaImageIO::TreeHandlerImageAdder::SetSynchronizer | ( | Synchronizer * | s | ) | [inline] |
Sets the synchronizer.
Definition at line 38 of file creaImageIOTreeHandlerImageAdder.h.
References mSynchronizer.
Referenced by creaImageIO::Gimmick::AddDir(), creaImageIO::Gimmick::AddFiles(), creaImageIO::Gimmick::CopyFiles(), creaImageIO::Gimmick::DeleteDrive(), creaImageIO::Gimmick::GetAttributes(), creaImageIO::Gimmick::RemoveFile(), and creaImageIO::Gimmick::Synchronize().
{mSynchronizer=s;}
void creaImageIO::TreeHandlerImageAdder::SetTreeHandler | ( | TreeHandler * | tree | ) | [inline] |
Sets the TreeHandler.
Definition at line 35 of file creaImageIOTreeHandlerImageAdder.h.
References mTreeHandler.
Referenced by creaImageIO::Gimmick::AddDir(), creaImageIO::Gimmick::AddFiles(), creaImageIO::Gimmick::CopyFiles(), creaImageIO::Gimmick::DeleteDrive(), creaImageIO::Gimmick::EditField(), creaImageIO::Gimmick::fillVectInfos(), creaImageIO::Gimmick::GetAttributes(), and creaImageIO::Gimmick::Synchronize().
{ mTreeHandler = tree;}
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 362 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().
{ std::vector<AddList> fileList; std::vector<std::string> ignoreList; std::vector<std::string> newFiles; std::vector<std::string> attsModified; std::stringstream mess; std::vector<AddList>::iterator iter; //Gets the list of added files mSynchronizer->GetFileList(fileList,mCurrentDB); std::vector<std::string>::iterator i; //Actions to take if the user doesn't want to repair if(!repair) { //Iterates to see if they are in sync for(iter=fileList.begin();iter!=fileList.end();++iter) { mSynchronizer->GetIgnoredFiles((*iter).key,ignoreList); bool rec=true; if((*iter).recursive=="0"){rec=false;} CheckSyncDirectory((*iter).path,rec,repair,checkAttributes,ignoreList,attsModified,newFiles); } //Add to message the result of new found files mess<<"New Files Found: "<<newFiles.size()<<std::endl; if(newFiles.size()>0) { mess<<"Filenames: "<<std::endl; for(i=newFiles.begin();i!=newFiles.end();++i) { mess<<*i<<std::endl; } } //Add to message the result of missing files mess<<"Missing Files: "<<ignoreList.size()<<std::endl; if(ignoreList.size()>0) { mess<<"Filenames: "<<std::endl; for(i=ignoreList.begin();i!=ignoreList.end();++i) { mess<<*i<<std::endl; } } //In the case that the user wants to check the attributes... if(checkAttributes) { //... add to message the result of files that have been changed. mess<<"Files with different attributes: "<<attsModified.size()<<std::endl; if(attsModified.size()>0) { mess<<"Filenames: "<<std::endl; for(i=attsModified.begin();i!=attsModified.end();++i) { mess<<*i<<std::endl; } } } } //Actions to take if the user wants to repair else { int nf=0; //Iterates to see if they are in sync for(iter=fileList.begin();iter!=fileList.end();++iter) { mSynchronizer->GetIgnoredFiles((*iter).key,ignoreList); bool rec=true; if((*iter).recursive=="0"){rec=false;} CheckSyncDirectory((*iter).path,rec,repair,checkAttributes,ignoreList,attsModified,newFiles); //For the new files, add them for (i=newFiles.begin();i!=newFiles.end();++i) { if (IsHandledFile(*i)) { std::stringstream removedOn; removedOn<<time(0); mSynchronizer->InsertIgnoreFile((*iter).key,(*i),"0",removedOn.str(),mCurrentDB); //Gets the number of files added int files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",(*iter).key,mCurrentDB)).c_str()); files=files+1; std::stringstream out; out<<files; //Sets the new number of files mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",out.str(),"ADD_KEY",(*iter).key,mCurrentDB); AddFile(*i); } } nf+=newFiles.size(); newFiles.clear(); } //Reports number of added files mess<<"Files Added: "<<nf<<std::endl; //Removes the necessary files and reports the results if(ignoreList.size()>0) { tree::Node* node; mTreeHandler->LoadChildren(NULL,4); for(i=ignoreList.begin();i!=ignoreList.end();++i) { FindNode(mTreeHandler->GetTree().GetChildrenList()[0],3,"FullFileName",*i,node); RemoveFile(node); mTreeHandler->Remove(node); } } mess<<"Files Removed: "<<ignoreList.size()<<std::endl; //In the case that the user wants to check the attributes... if(checkAttributes) { //... add to message the result of files that were modified. mess<<"Files Modified: "<<attsModified.size()<<std::endl; } } return mess.str(); }
std::string creaImageIO::TreeHandlerImageAdder::mCurrentDB [private] |
Definition at line 185 of file creaImageIOTreeHandlerImageAdder.h.
Referenced by AddDirectory(), AddDirectoryRecursor(), AddFiles(), CopyFiles(), remove(), SetCurrentDatabase(), and Synchronize().
Definition at line 187 of file creaImageIOTreeHandlerImageAdder.h.
Referenced by AddDirectory(), AddDirectoryRecursor(), AddFile(), AddFiles(), and GetProgress().
Definition at line 188 of file creaImageIOTreeHandlerImageAdder.h.
Referenced by AddDirectoryRecursor(), AddFiles(), and ConnectProgressObserver().
Definition at line 183 of file creaImageIOTreeHandlerImageAdder.h.
Referenced by AddFile(), CheckAttributes(), and IsHandledFile().
Definition at line 182 of file creaImageIOTreeHandlerImageAdder.h.
Referenced by AddDirectory(), AddDirectoryRecursor(), AddFiles(), CopyFiles(), DeleteDriveFromOtherDB(), remove(), SetSynchronizer(), and Synchronize().
Definition at line 181 of file creaImageIOTreeHandlerImageAdder.h.
Referenced by AddDirectory(), AddFile(), CheckAttributes(), CopyFiles(), DeleteDriveFromMainDB(), EditField(), GetAttributes(), isAttributeExist(), SetTreeHandler(), and Synchronize().