X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPlugins%2FMEDReader%2FIO%2FvtkMEDReader.cxx;h=769e87a4b802a452a251d4acdc0daf0a1e05cd73;hb=60ce6156a78d9390b0ff18260b7edf234ff8ac4b;hp=6524e075a943099e8b6ddf45aacc41b3f608e63d;hpb=d170abf6cb7fa44827057ce004760d1ef45d9f2d;p=modules%2Fparavis.git diff --git a/src/Plugins/MEDReader/IO/vtkMEDReader.cxx b/src/Plugins/MEDReader/IO/vtkMEDReader.cxx index 6524e075..769e87a4 100644 --- a/src/Plugins/MEDReader/IO/vtkMEDReader.cxx +++ b/src/Plugins/MEDReader/IO/vtkMEDReader.cxx @@ -3,7 +3,7 @@ // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -52,11 +52,102 @@ #include #include +/*! + * This class stores properties in loading state mode (pvsm) when the MED file has not been read yet. + * The file is not read beacause FileName has not been informed yet ! So this class stores properties of vtkMEDReader instance that + * owns it and wait the vtkMEDReader::SetFileName to apply properties afterwards. + */ +class PropertyKeeper +{ +public: + PropertyKeeper(vtkMEDReader *master):_master(master),IsGVActivated(false),GVValue(0),IsCMActivated(false),CMValue(0) { } + void assignPropertiesIfNeeded(); + bool arePropertiesOnTreeToSetAfter() const; + // + void pushFieldStatusEntry(const char* name, int status); + void pushGenerateVectorsValue(int value); + void pushChangeModeValue(int value); + void pushTimesFlagsStatusEntry(const char* name, int status); +protected: + // pool of pairs to assign in SetFieldsStatus if needed. The use case is the load using pvsm. + std::vector< std::pair > SetFieldsStatusPairs; + // generate vector + bool IsGVActivated; + int GVValue; + // change mode + bool IsCMActivated; + int CMValue; + // + std::vector< std::pair > TimesFlagsStatusPairs; + vtkMEDReader *_master; +}; + +void PropertyKeeper::assignPropertiesIfNeeded() +{ + if(!this->SetFieldsStatusPairs.empty()) + { + for(std::vector< std::pair >::const_iterator it=this->SetFieldsStatusPairs.begin();it!=this->SetFieldsStatusPairs.end();it++) + _master->SetFieldsStatus((*it).first.c_str(),(*it).second); + this->SetFieldsStatusPairs.clear(); + } + if(!this->TimesFlagsStatusPairs.empty()) + { + for(std::vector< std::pair >::const_iterator it=this->TimesFlagsStatusPairs.begin();it!=this->TimesFlagsStatusPairs.end();it++) + _master->SetTimesFlagsStatus((*it).first.c_str(),(*it).second); + this->TimesFlagsStatusPairs.clear(); + } + if(this->IsGVActivated) + { + _master->GenerateVectors(this->GVValue); + this->IsGVActivated=false; + } + if(this->IsCMActivated) + { + _master->ChangeMode(this->CMValue); + this->IsCMActivated=false; + } +} + +void PropertyKeeper::pushFieldStatusEntry(const char* name, int status) +{ + bool found(false); + for(std::vector< std::pair >::const_iterator it=this->SetFieldsStatusPairs.begin();it!=this->SetFieldsStatusPairs.end() && !found;it++) + found=(*it).first==name; + if(!found) + this->SetFieldsStatusPairs.push_back(std::pair(name,status)); +} + +void PropertyKeeper::pushTimesFlagsStatusEntry(const char* name, int status) +{ + bool found(false); + for(std::vector< std::pair >::const_iterator it=this->TimesFlagsStatusPairs.begin();it!=this->TimesFlagsStatusPairs.end() && !found;it++) + found=(*it).first==name; + if(!found) + this->TimesFlagsStatusPairs.push_back(std::pair(name,status)); +} + +void PropertyKeeper::pushGenerateVectorsValue(int value) +{ + this->IsGVActivated=true; + this->GVValue=value; +} + +void PropertyKeeper::pushChangeModeValue(int value) +{ + this->IsCMActivated=true; + this->CMValue=value; +} + +bool PropertyKeeper::arePropertiesOnTreeToSetAfter() const +{ + return !SetFieldsStatusPairs.empty(); +} + class vtkMEDReader::vtkMEDReaderInternal { public: - vtkMEDReaderInternal():TK(0),IsMEDOrSauv(true),IsStdOrMode(false),GenerateVect(false),SIL(0),LastLev0(-1),FirstCall0(2) + vtkMEDReaderInternal(vtkMEDReader *master):TK(0),IsMEDOrSauv(true),IsStdOrMode(false),GenerateVect(false),SIL(0),LastLev0(-1),FirstCall0(2),PK(master) { } @@ -88,13 +179,15 @@ public: vtkMutableDirectedGraph* SIL; // store the lev0 id in Tree corresponding to the TIME_STEPS in the pipeline. int LastLev0; + // The property keeper is usable only in pvsm mode. + PropertyKeeper PK; private: unsigned char FirstCall0; }; vtkStandardNewMacro(vtkMEDReader); -vtkMEDReader::vtkMEDReader():Internal(new vtkMEDReaderInternal) +vtkMEDReader::vtkMEDReader():Internal(new vtkMEDReaderInternal(this)) { this->SetNumberOfInputPorts(0); this->SetNumberOfOutputPorts(1); @@ -112,12 +205,18 @@ void vtkMEDReader::Reload(int a) std::cerr << "vtkMEDReader::Reload" << a << std::endl; std::string fName((const char *)this->GetFileName()); delete this->Internal; - this->Internal=new vtkMEDReaderInternal; + this->Internal=new vtkMEDReaderInternal(this); this->SetFileName(fName.c_str()); } void vtkMEDReader::GenerateVectors(int val) { + if(this->Internal->FileName.empty()) + {//pvsm mode + this->Internal->PK.pushGenerateVectorsValue(val); + return ; + } + //not pvsm mode (general case) bool val2((bool)val); if(val2!=this->Internal->GenerateVect) { @@ -128,6 +227,12 @@ void vtkMEDReader::GenerateVectors(int val) void vtkMEDReader::ChangeMode(int newMode) { + if(this->Internal->FileName.empty()) + {//pvsm mode + this->Internal->PK.pushChangeModeValue(newMode); + return ; + } + //not pvsm mode (general case) this->Internal->IsStdOrMode=newMode!=0; //std::cerr << "vtkMEDReader::ChangeMode : " << this->Internal->IsStdOrMode << std::endl; this->Modified(); @@ -140,21 +245,38 @@ const char *vtkMEDReader::GetSeparator() void vtkMEDReader::SetFileName(const char *fname) { - this->Internal->FileName=fname; - std::size_t pos(this->Internal->FileName.find_last_of('.')); - if(pos!=std::string::npos) + try { - std::string ext(this->Internal->FileName.substr(pos)); - if(ext.find("sauv")!=std::string::npos) - this->Internal->IsMEDOrSauv=false; + this->Internal->FileName=fname; + std::size_t pos(this->Internal->FileName.find_last_of('.')); + if(pos!=std::string::npos) + { + std::string ext(this->Internal->FileName.substr(pos)); + if(ext.find("sauv")!=std::string::npos) + this->Internal->IsMEDOrSauv=false; + } + if(this->Internal->Tree.getNumberOfLeavesArrays()==0) + { + this->Internal->Tree.loadMainStructureOfFile(this->Internal->FileName.c_str(),this->Internal->IsMEDOrSauv); + if(!this->Internal->PK.arePropertiesOnTreeToSetAfter()) + this->Internal->Tree.activateTheFirst();//This line manually initialize the status of server (this) with the remote client. + this->Internal->TK.setMaxNumberOfTimeSteps(this->Internal->Tree.getMaxNumberOfTimeSteps()); + } + this->Modified(); + this->Internal->PK.assignPropertiesIfNeeded(); } - if(this->Internal->Tree.getNumberOfLeavesArrays()==0) + catch(INTERP_KERNEL::Exception& e) { - this->Internal->Tree.loadMainStructureOfFile(this->Internal->FileName.c_str(),this->Internal->IsMEDOrSauv); - this->Internal->Tree.activateTheFirst();//This line manually initialize the status of server (this) with the remote client. - this->Internal->TK.setMaxNumberOfTimeSteps(this->Internal->Tree.getMaxNumberOfTimeSteps()); + delete this->Internal; + this->Internal=0; + std::ostringstream oss; + oss << "Exception has been thrown in vtkMEDReader::SetFileName : " << e.what() << std::endl; + if(this->HasObserver("ErrorEvent") ) + this->InvokeEvent("ErrorEvent",const_cast(oss.str().c_str())); + else + vtkOutputWindowDisplayErrorText(const_cast(oss.str().c_str())); + vtkObject::BreakOnError(); } - this->Modified(); } char *vtkMEDReader::GetFileName() @@ -165,6 +287,8 @@ char *vtkMEDReader::GetFileName() int vtkMEDReader::RequestInformation(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) { //std::cerr << "########################################## RequestInformation ##########################################" << std::endl; + if(!this->Internal) + return 0; try { vtkInformation *outInfo(outputVector->GetInformationObject(0)); @@ -186,6 +310,8 @@ int vtkMEDReader::RequestInformation(vtkInformation *request, vtkInformationVect int vtkMEDReader::RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) { //std::cerr << "########################################## RequestData ##########################################"; + if(!this->Internal) + return 0; try { vtkInformation *outInfo(outputVector->GetInformationObject(0)); @@ -211,14 +337,33 @@ int vtkMEDReader::RequestData(vtkInformation *request, vtkInformationVector **in void vtkMEDReader::SetFieldsStatus(const char* name, int status) { //std::cerr << "vtkMEDReader::SetFieldsStatus(" << name << "," << status << ") called !" << std::endl; - this->Internal->Tree.changeStatusOfAndUpdateToHaveCoherentVTKDataSet(this->Internal->Tree.getIdHavingZeName(name),status); - if(std::string(name)==GetFieldsTreeArrayName(GetNumberOfFieldsTreeArrays()-1)) - if(!this->Internal->PluginStart0()) - this->Modified(); + if(this->Internal->FileName.empty()) + {//pvsm mode + this->Internal->PK.pushFieldStatusEntry(name,status); + return ; + } + //not pvsm mode (general case) + try + { + this->Internal->Tree.changeStatusOfAndUpdateToHaveCoherentVTKDataSet(this->Internal->Tree.getIdHavingZeName(name),status); + if(std::string(name)==GetFieldsTreeArrayName(GetNumberOfFieldsTreeArrays()-1)) + if(!this->Internal->PluginStart0()) + this->Modified(); + } + catch(INTERP_KERNEL::Exception& e) + { + if(!this->Internal->FileName.empty()) + { + std::cerr << "vtkMEDReader::SetFieldsStatus error : " << e.what() << " *** WITH STATUS=" << status << endl; + return ; + } + } } int vtkMEDReader::GetNumberOfFieldsTreeArrays() { + if(!this->Internal) + return 0; int ret(this->Internal->Tree.getNumberOfLeavesArrays()); //std::cerr << "vtkMEDReader::GetNumberOfFieldsTreeArrays called ! " << ret << std::endl; return ret; @@ -226,9 +371,8 @@ int vtkMEDReader::GetNumberOfFieldsTreeArrays() const char *vtkMEDReader::GetFieldsTreeArrayName(int index) { - std::string ret(this->Internal->Tree.getNameOf(index)); + return this->Internal->Tree.getNameOfC(index); //std::cerr << "vtkMEDReader::GetFieldsTreeArrayName(" << index << ") called ! " << ret << std::endl; - return ret.c_str(); } int vtkMEDReader::GetFieldsTreeArrayStatus(const char *name) @@ -240,6 +384,12 @@ int vtkMEDReader::GetFieldsTreeArrayStatus(const char *name) void vtkMEDReader::SetTimesFlagsStatus(const char *name, int status) { + if(this->Internal->FileName.empty()) + {//pvsm mode + this->Internal->PK.pushTimesFlagsStatusEntry(name,status); + return ; + } + //not pvsm mode (general case) int pos(0); std::istringstream iss(name); iss >> pos; this->Internal->TK.getTimesFlagArray()[pos].first=(bool)status; @@ -253,6 +403,8 @@ void vtkMEDReader::SetTimesFlagsStatus(const char *name, int status) int vtkMEDReader::GetNumberOfTimesFlagsArrays() { + if(!this->Internal) + return 0; return (int)this->Internal->TK.getTimesFlagArray().size(); } @@ -270,6 +422,8 @@ int vtkMEDReader::GetTimesFlagsArrayStatus(const char *name) void vtkMEDReader::UpdateSIL(vtkInformation *info) { + if(!this->Internal) + return ; vtkMutableDirectedGraph *sil(vtkMutableDirectedGraph::New()); std::string meshName(this->BuildSIL(sil)); if(meshName!=this->Internal->DftMeshName)