From 71710e0798ae4aa4f07eb1a1fcb48b75d9df8cc7 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 12 May 2017 15:37:04 +0200 Subject: [PATCH] ENH: use prefix when displaying group,patch names for paraview selection - easier to detect the implicit grouping --- .../PVFoamReader/vtkPVFoam/vtkPVFoam.C | 4 +-- .../vtkPVFoam/vtkPVFoamUpdateInfo.C | 26 ++++++++-------- .../graphics/PVReaders/foamPv/foamPvCore.C | 30 +++++++++++++------ .../graphics/PVReaders/foamPv/foamPvCore.H | 13 ++++---- .../PVReaders/foamPv/foamPvCoreTemplates.C | 6 ++-- 5 files changed, 47 insertions(+), 32 deletions(-) diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.C b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.C index 2ba76a4c31..9fd2f2cdc4 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.C @@ -240,7 +240,7 @@ void Foam::vtkPVFoam::updateMeshPartsStatus() Foam::word Foam::vtkPVFoam::getPartName(const int partId) { - return getFirstWord(reader_->GetPartArrayName(partId)); + return getFoamName(reader_->GetPartArrayName(partId)); } @@ -649,7 +649,7 @@ void Foam::vtkPVFoam::renderPatchNames if (show && meshPtr_) { - // get the display patches, strip off any suffix + // get the display patches, strip off any prefix/suffix hashedWordList selectedPatches = getSelected ( reader_->GetPartSelection(), diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamUpdateInfo.C b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamUpdateInfo.C index 213694e6e5..7bdfd32586 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamUpdateInfo.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamUpdateInfo.C @@ -192,7 +192,7 @@ void Foam::vtkPVFoam::updateInfoLagrangian // Add cloud to GUI list arraySelection->AddArray ( - (cloudDirs[cloudi] + " - lagrangian").c_str() + ("lagrangian/" + cloudDirs[cloudi]).c_str() ); ++rangeLagrangian_; } @@ -246,7 +246,7 @@ void Foam::vtkPVFoam::updateInfoPatches } // Valid patch if nFace > 0 - add patch to GUI list - const string dpyName = groupName + " - group"; + const string dpyName = "group/" + groupName; arraySelection->AddArray(dpyName.c_str()); ++rangePatches_; @@ -262,7 +262,7 @@ void Foam::vtkPVFoam::updateInfoPatches { enabledEntriesSet.insert ( - pp.name() + " - patch" + "patch/" + pp.name() ); } } @@ -285,7 +285,7 @@ void Foam::vtkPVFoam::updateInfoPatches // Add patch to GUI list arraySelection->AddArray ( - (pp.name() + " - patch").c_str() + ("patch/" + pp.name()).c_str() ); ++rangePatches_; } @@ -360,7 +360,7 @@ void Foam::vtkPVFoam::updateInfoPatches const auto& groupName = iter.key(); const auto& patchIDs = iter.object(); - const string dpyName = groupName + " - group"; + const string dpyName = "group/" + groupName; arraySelection->AddArray(dpyName.c_str()); ++rangePatches_; @@ -376,7 +376,7 @@ void Foam::vtkPVFoam::updateInfoPatches { enabledEntriesSet.insert ( - names[patchId] + " - patch"; + "patch/" + names[patchId] ); } } @@ -395,7 +395,7 @@ void Foam::vtkPVFoam::updateInfoPatches { arraySelection->AddArray ( - (names[patchi] + " - patch").c_str() + ("patch/" + names[patchi]).c_str() ); ++rangePatches_; } @@ -449,7 +449,7 @@ void Foam::vtkPVFoam::updateInfoZones { arraySelection->AddArray ( - (namesLst[elemI] + " - cellZone").c_str() + ("cellZone/" + namesLst[elemI]).c_str() ); ++rangeCellZones_; } @@ -472,7 +472,7 @@ void Foam::vtkPVFoam::updateInfoZones { arraySelection->AddArray ( - (namesLst[elemI] + " - faceZone").c_str() + ("faceZone/" + namesLst[elemI]).c_str() ); ++rangeFaceZones_; } @@ -495,7 +495,7 @@ void Foam::vtkPVFoam::updateInfoZones { arraySelection->AddArray ( - (namesLst[elemI] + " - pointZone").c_str() + ("pointZone/" + namesLst[elemI]).c_str() ); ++rangePointZones_; } @@ -554,7 +554,7 @@ void Foam::vtkPVFoam::updateInfoSets ( arraySelection, objects, - " - cellSet" + "cellSet/" ); rangeFaceSets_.reset(arraySelection->GetNumberOfArrays()); @@ -562,7 +562,7 @@ void Foam::vtkPVFoam::updateInfoSets ( arraySelection, objects, - " - faceSet" + "faceSet/" ); rangePointSets_.reset(arraySelection->GetNumberOfArrays()); @@ -570,7 +570,7 @@ void Foam::vtkPVFoam::updateInfoSets ( arraySelection, objects, - " - pointSet" + "pointSet/" ); if (debug) diff --git a/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvCore.C b/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvCore.C index 4a9468d8e2..b2c5c822e2 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvCore.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvCore.C @@ -164,7 +164,7 @@ Foam::hashedWordList Foam::foamPvCore::getSelected { if (select->GetArraySetting(i)) { - selected.append(getFirstWord(select->GetArrayName(i))); + selected.append(getFoamName(select->GetArrayName(i))); } } @@ -185,7 +185,7 @@ Foam::hashedWordList Foam::foamPvCore::getSelected { if (select->GetArraySetting(i)) { - selected.append(getFirstWord(select->GetArrayName(i))); + selected.append(getFoamName(select->GetArrayName(i))); } } @@ -295,17 +295,29 @@ void Foam::foamPvCore::setSelectedArrayEntries } -Foam::word Foam::foamPvCore::getFirstWord(const char* str) +Foam::word Foam::foamPvCore::getFoamName(const std::string& str) { - if (str) + if (str.size()) { - label n = 0; - while (str[n] && word::valid(str[n])) + std::string::size_type beg = str.rfind('/'); + if (beg == std::string::npos) { - ++n; + beg = 0; } - // don't need to re-check for invalid chars - return word(str, n, false); + else + { + ++beg; + } + + std::string::size_type end = beg; + + while (str[end] && word::valid(str[end])) + { + ++end; + } + + // Already checked for valid/invalid chars + return word(str.substr(beg, beg+end), false); } else { diff --git a/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvCore.H b/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvCore.H index 5a2d0d44e7..8a81633408 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvCore.H +++ b/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvCore.H @@ -180,7 +180,7 @@ public: ( vtkDataArraySelection* select, const IOobjectList& objects, - const std::string& suffix = string::null + const std::string& prefix = string::null ); @@ -191,14 +191,16 @@ public: vtkDataArraySelection* select ); - //- Retrieve the current selections as a wordHashSet + //- Retrieve the current selections as a hashedWordList, + // while stripping off any prefix or suffix static hashedWordList getSelected ( vtkDataArraySelection* select ); - //- Retrieve a sub-list of the current selections + //- Retrieve a sub-list of the current selections as a hashedWordList, + // while stripping off any prefix or suffix static hashedWordList getSelected ( vtkDataArraySelection* select, @@ -228,8 +230,9 @@ public: ); - //- Extract up to the first non-word characters - static word getFirstWord(const char* str); + //- Extract the first word characters after a slash + static word getFoamName(const std::string& str); + //- Simple memory used debugging information static void printMemory(); diff --git a/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvCoreTemplates.C b/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvCoreTemplates.C index 7cedd047a2..7908a7752d 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvCoreTemplates.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvCoreTemplates.C @@ -60,20 +60,20 @@ Foam::label Foam::foamPvCore::addToSelection ( vtkDataArraySelection *select, const IOobjectList& objects, - const std::string& suffix + const std::string& prefix ) { const wordList names = objects.sortedNames(Type::typeName); forAll(names, i) { - if (suffix.empty()) + if (prefix.empty()) { select->AddArray(names[i].c_str()); } else { - select->AddArray((names[i] + suffix).c_str()); + select->AddArray((prefix + names[i]).c_str()); } }