From 6c7bd0dee212d000a93095947916b6aef5ca54d3 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Fri, 28 Sep 2018 09:33:26 +0200 Subject: [PATCH] GroupsFlagsInfo property of ExtractGroup can be set at any time independantly from updateinformation invokation. ExtractGroup is now compatible with Save State and Custom Filters --- src/Plugins/MEDReader/IO/vtkExtractGroup.cxx | 30 ++++++++++++++----- src/Plugins/MEDReader/Test/testMEDReader0.py | 2 +- src/Plugins/MEDReader/Test/testMEDReader16.py | 2 +- src/Plugins/MEDReader/Test/testMEDReader17.py | 6 ++-- src/Plugins/MEDReader/Test/testMEDReader18.py | 2 +- src/Plugins/MEDReader/Test/testMEDReader8.py | 2 +- src/Plugins/MEDReader/Test/testMEDReader9.py | 8 ++--- 7 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/Plugins/MEDReader/IO/vtkExtractGroup.cxx b/src/Plugins/MEDReader/IO/vtkExtractGroup.cxx index 255ccc5b..4197a987 100644 --- a/src/Plugins/MEDReader/IO/vtkExtractGroup.cxx +++ b/src/Plugins/MEDReader/IO/vtkExtractGroup.cxx @@ -71,14 +71,15 @@ public: ExtractGroupStatus():_status(false) { } ExtractGroupStatus(const char *name); bool getStatus() const { return _status; } - void setStatus(bool status) { _status=status; } + void setStatus(bool status) const { _status=status; } void cpyStatusFrom(const ExtractGroupStatus& other) { _status=other._status; } std::string getName() const { return _name; } + void resetStatus() const { _status=false; } const char *getKeyOfEntry() const { return _ze_key_name.c_str(); } virtual void printMySelf(std::ostream& os) const; virtual bool isSameAs(const ExtractGroupStatus& other) const; protected: -bool _status; +mutable bool _status; std::string _name; std::string _ze_key_name; }; @@ -120,6 +121,7 @@ public: void setStatusOfEntryStr(const char *entry, bool status); void printMySelf(std::ostream& os) const; std::set getIdsToKeep() const; + void clearSelection() const; int getIdOfFamily(const std::string& famName) const; static bool IsInformationOK(vtkInformation *info); private: @@ -129,6 +131,7 @@ private: private: std::vector _groups; std::vector _fams; + mutable std::vector< std::pair > _selection; std::string _mesh_name; }; @@ -308,8 +311,7 @@ bool vtkExtractGroup::vtkExtractGroupInternal::getStatusOfEntryStr(const char *e void vtkExtractGroup::vtkExtractGroupInternal::setStatusOfEntryStr(const char *entry, bool status) { - ExtractGroupStatus& elt(getEntry(entry)); - elt.setStatus(status); + _selection.emplace_back(entry,status); } const ExtractGroupStatus& vtkExtractGroup::vtkExtractGroupInternal::getEntry(const char *entry) const @@ -392,6 +394,11 @@ void ExtractGroupFam::fillIdsToKeep(std::set& s) const std::set vtkExtractGroup::vtkExtractGroupInternal::getIdsToKeep() const { + for(auto it: _selection) + { + const ExtractGroupStatus& elt(getEntry(it.first.c_str())); + elt.setStatus(it.second); + } std::map m(this->computeFamStrIdMap()); std::set s; for(std::vector::const_iterator it0=_groups.begin();it0!=_groups.end();it0++) @@ -413,6 +420,15 @@ std::set vtkExtractGroup::vtkExtractGroupInternal::getIdsToKeep() const return s; } +void vtkExtractGroup::vtkExtractGroupInternal::clearSelection() const +{ + _selection.clear(); + for(auto it : _groups) + it.resetStatus(); + for(auto it : _fams) + it.resetStatus(); +} + std::map vtkExtractGroup::vtkExtractGroupInternal::computeFamStrIdMap() const { std::map ret; @@ -585,6 +601,7 @@ int vtkExtractGroup::RequestData(vtkInformation *request, vtkInformationVector * vtkInformation *outInfo(outputVector->GetInformationObject(0)); vtkMultiBlockDataSet *output(vtkMultiBlockDataSet::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()))); std::set idsToKeep(this->Internal->getIdsToKeep()); + this->Internal->clearSelection(); // first shrink the input bool catchAll,catchSmth; vtkSmartPointer thres1(vtkSmartPointer::New()),thres2(vtkSmartPointer::New()); @@ -705,11 +722,8 @@ int vtkExtractGroup::GetGroupsFlagsArrayStatus(const char *name) void vtkExtractGroup::SetGroupsFlagsStatus(const char *name, int status) { //std::cerr << "vtkExtractGroup::SetFieldsStatus(" << name << "," << status << ")" << std::endl; - if (GetNumberOfGroupsFlagsArrays()<1) - return; this->Internal->setStatusOfEntryStr(name,(bool)status); - if(std::string(name)==GetGroupsFlagsArrayName(GetNumberOfGroupsFlagsArrays()-1)) - this->Modified(); + this->Modified(); //this->Internal->printMySelf(std::cerr); } diff --git a/src/Plugins/MEDReader/Test/testMEDReader0.py b/src/Plugins/MEDReader/Test/testMEDReader0.py index 214ab198..55a0e422 100644 --- a/src/Plugins/MEDReader/Test/testMEDReader0.py +++ b/src/Plugins/MEDReader/Test/testMEDReader0.py @@ -88,7 +88,7 @@ myMedReader.AllArrays=keys RenderView1 = GetRenderView() ELNOfieldToSurface1=ELNOfieldToSurface(Input=myMedReader) ExtractGroup1=ExtractGroup(Input=ELNOfieldToSurface1) -ExtractGroup1.UpdatePipelineInformation() +#ExtractGroup1.UpdatePipelineInformation() ExtractGroup1.AllGroups=['GRP_ba2','GRP_to1','GRP_web'] assert(isinstance(ExtractGroup1.GetProperty("MeshName")[0],str)) assert(ExtractGroup1.GetProperty("MeshName")[0]=="mesh") diff --git a/src/Plugins/MEDReader/Test/testMEDReader16.py b/src/Plugins/MEDReader/Test/testMEDReader16.py index fb9219c4..20109228 100644 --- a/src/Plugins/MEDReader/Test/testMEDReader16.py +++ b/src/Plugins/MEDReader/Test/testMEDReader16.py @@ -48,7 +48,7 @@ ExpectedEntries=['TS0/Mesh/ComSup0/MyField@@][@@GSSNE','TS1/Mesh/ComSup0/Mesh@@] assert(reader.GetProperty("FieldsTreeInfo")[::2]==ExpectedEntries) reader.AllArrays=['TS0/Mesh/ComSup0/MyField@@][@@GSSNE'] ExtractGroup1 = ExtractGroup(Input=reader) -ExtractGroup1.UpdatePipelineInformation() +#ExtractGroup1.UpdatePipelineInformation() ExtractGroup1.AllGroups=["GRP_grp1"] ELNOfieldToSurface1=ELNOfieldToSurface(Input=ExtractGroup1) ELNOfieldToPointGaussian1=ELNOfieldToPointGaussian(Input=ExtractGroup1) diff --git a/src/Plugins/MEDReader/Test/testMEDReader17.py b/src/Plugins/MEDReader/Test/testMEDReader17.py index 7668e4d7..f6edd58f 100644 --- a/src/Plugins/MEDReader/Test/testMEDReader17.py +++ b/src/Plugins/MEDReader/Test/testMEDReader17.py @@ -48,7 +48,7 @@ ExpectedEntries=['TS0/Mesh/ComSup0/MyField@@][@@GSSNE','TS1/Mesh/ComSup0/Mesh@@] assert(reader.GetProperty("FieldsTreeInfo")[::2]==ExpectedEntries) reader.AllArrays=['TS0/Mesh/ComSup0/MyField@@][@@GSSNE'] ExtractGroup1 = ExtractGroup(Input=reader) -ExtractGroup1.UpdatePipelineInformation() +#ExtractGroup1.UpdatePipelineInformation() ExtractGroup1.AllGroups=["GRP_grp1"] ELNOfieldToPointGaussian1=ELNOfieldToPointGaussian(Input=ExtractGroup1) ELNOfieldToPointGaussian1.SelectSourceArray=['ELNO@MyField'] @@ -56,9 +56,9 @@ ELNOfieldToPointGaussian1.SelectSourceArray=['ELNO@MyField'] ELNOfieldToPointGaussian1=ELNOfieldToPointGaussian(Input=reader) ELNOfieldToPointGaussian1.SelectSourceArray=['ELNO@MyField'] ExtractGroup1 = ExtractGroup(Input=ELNOfieldToPointGaussian1) -ExtractGroup1.UpdatePipelineInformation() +#ExtractGroup1.UpdatePipelineInformation() ExtractGroup1.AllGroups=["GRP_grp1"] -ExtractGroup1.UpdatePipeline() +#ExtractGroup1.UpdatePipeline() res=servermanager.Fetch(ExtractGroup1,0) assert(res.GetBlock(0).GetNumberOfCells()==8) vtkArrToTest=res.GetBlock(0).GetPointData().GetArray("MyField") diff --git a/src/Plugins/MEDReader/Test/testMEDReader18.py b/src/Plugins/MEDReader/Test/testMEDReader18.py index 957c4586..2cd3f14a 100644 --- a/src/Plugins/MEDReader/Test/testMEDReader18.py +++ b/src/Plugins/MEDReader/Test/testMEDReader18.py @@ -47,7 +47,7 @@ reader=MEDReader(FileName=fname) reader.AllArrays=['TS0/mesh/ComSup0/mesh@@][@@P0'] ExtractGroup1 = ExtractGroup(Input=reader) ExtractGroup1.AllGroups=["GRP_grp0","GRP_grp1"] -ExtractGroup1.UpdatePipelineInformation() +#ExtractGroup1.UpdatePipelineInformation() res=servermanager.Fetch(ExtractGroup1,0) assert(res.GetNumberOfBlocks()==2) assert(res.GetBlock(1).GetNumberOfCells()==1) diff --git a/src/Plugins/MEDReader/Test/testMEDReader8.py b/src/Plugins/MEDReader/Test/testMEDReader8.py index e4dfb78f..5d527516 100644 --- a/src/Plugins/MEDReader/Test/testMEDReader8.py +++ b/src/Plugins/MEDReader/Test/testMEDReader8.py @@ -76,7 +76,7 @@ assert(list(extractCT.GetProperty("GeoTypesInfo"))==['TRI3','0','QUAD4','0']) extractCT.AllGeoTypes=['TRI3'] extGrp=ExtractGroup(Input=extractCT) -extGrp.UpdatePipelineInformation() +#extGrp.UpdatePipelineInformation() assert([x for x in list(extGrp.GetProperty("GroupsFlagsInfo")[::2]) if x[:4]=="GRP_"]==['GRP_grp0']) extGrp.AllGroups="GRP_grp0" diff --git a/src/Plugins/MEDReader/Test/testMEDReader9.py b/src/Plugins/MEDReader/Test/testMEDReader9.py index 61c5cc60..f94723a4 100644 --- a/src/Plugins/MEDReader/Test/testMEDReader9.py +++ b/src/Plugins/MEDReader/Test/testMEDReader9.py @@ -44,12 +44,12 @@ from paraview.simple import * myMedReader=MEDReader(FileName=fname) myMedReader.AllArrays=['TS0/m1/ComSup0/f1@@][@@P0'] -myMedReader.UpdatePipelineInformation() +#myMedReader.UpdatePipelineInformation() ExtractGroup1=ExtractGroup(Input=myMedReader) -ExtractGroup1.UpdatePipelineInformation() +#ExtractGroup1.UpdatePipelineInformation() assert(ExtractGroup1.GetProperty("MeshName")[0]=="m1") myMedReader.AllArrays=['TS0/m2/ComSup0/f2@@][@@P0'] -myMedReader.UpdatePipeline() +#myMedReader.UpdatePipeline() ExtractGroup2=ExtractGroup(Input=myMedReader) -ExtractGroup2.UpdatePipelineInformation() +#ExtractGroup2.UpdatePipelineInformation() assert(ExtractGroup2.GetProperty("MeshName")[0]=="m2") -- 2.39.2