From 801076f8d0c7d0930c6a158c3c75e74187d89761 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 17 Jan 2017 10:14:15 +0100 Subject: [PATCH 01/35] ENH: adjust header management for foamVtk output - provide headerType typedef in foamVtkFormatter, foamVtkOutput - remove byteOrder and headerType constants from foamVtkFormatter since the same strings can also be obtained from foamVtkPTraits - additional convenience methods in foamVtkFormatter --- src/conversion/vtk/output/foamVtkOutput.C | 13 +-- src/conversion/vtk/output/foamVtkOutput.H | 6 ++ src/fileFormats/vtk/format/foamVtkFormatter.C | 97 ++++++++++--------- src/fileFormats/vtk/format/foamVtkFormatter.H | 39 ++++++-- 4 files changed, 93 insertions(+), 62 deletions(-) diff --git a/src/conversion/vtk/output/foamVtkOutput.C b/src/conversion/vtk/output/foamVtkOutput.C index 4ece681a85..fc2d298841 100644 --- a/src/conversion/vtk/output/foamVtkOutput.C +++ b/src/conversion/vtk/output/foamVtkOutput.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -62,14 +62,7 @@ Foam::label Foam::foamVtkOutput::writeVtmFile vtmFile .xmlHeader() - .openTag("VTKFile") - ( "type", content ) - ( "version", "1.0" ) - ( "byte_order", foamVtkFormatter::byteOrder ) - ( "header_type", foamVtkFormatter::headerType ) - .closeTag(); - - vtmFile.tag(content); + .beginVTKFile(content, "1.0"); forAll(files, i) { @@ -80,7 +73,7 @@ Foam::label Foam::foamVtkOutput::writeVtmFile .closeTag(true); } - vtmFile.endTag(content).endTag("VTKFile"); + vtmFile.endTag(content).endVTKFile(); return files.size(); } diff --git a/src/conversion/vtk/output/foamVtkOutput.H b/src/conversion/vtk/output/foamVtkOutput.H index ad7964bfff..f0897d6675 100644 --- a/src/conversion/vtk/output/foamVtkOutput.H +++ b/src/conversion/vtk/output/foamVtkOutput.H @@ -58,6 +58,12 @@ class foamVtkOutput public: + // Public typedefs + + //- Use UInt64 for header data + typedef foamVtkFormatter::headerType headerType; + + // Forward declarations class legacy; diff --git a/src/fileFormats/vtk/format/foamVtkFormatter.C b/src/fileFormats/vtk/format/foamVtkFormatter.C index 2bc607a78a..5b9fded769 100644 --- a/src/fileFormats/vtk/format/foamVtkFormatter.C +++ b/src/fileFormats/vtk/format/foamVtkFormatter.C @@ -23,16 +23,6 @@ License \*---------------------------------------------------------------------------*/ #include "foamVtkFormatter.H" -#include "foamVtkPTraits.H" - -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -const char* const Foam::foamVtkFormatter::byteOrder - = Foam::foamVtkPTraits::typeName; - -const char* const Foam::foamVtkFormatter::headerType = - Foam::foamVtkPTraits::typeName; - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -145,16 +135,6 @@ Foam::foamVtkFormatter::closeTag(const bool isEmpty) } -Foam::foamVtkFormatter& -Foam::foamVtkFormatter::tag(const word& tag) -{ - openTag(tag); - closeTag(); - - return *this; -} - - Foam::foamVtkFormatter& Foam::foamVtkFormatter::endTag(const word& tag) { @@ -186,6 +166,53 @@ Foam::foamVtkFormatter::endTag(const word& tag) } +Foam::foamVtkFormatter& +Foam::foamVtkFormatter::tag(const word& tag) +{ + openTag(tag); + closeTag(); + + return *this; +} + + +Foam::foamVtkFormatter& +Foam::foamVtkFormatter::beginVTKFile +( + const word& contentType, + const word& contentVersion, + const bool leaveOpen +) +{ + openTag("VTKFile"); + xmlAttr("type", contentType); + xmlAttr("version", contentVersion); + xmlAttr("byte_order", foamVtkPTraits::typeName); + xmlAttr("header_type", foamVtkPTraits::typeName); + closeTag(); + + openTag(contentType); + if (!leaveOpen) + { + closeTag(); + } + + return *this; +} + + +Foam::foamVtkFormatter& +Foam::foamVtkFormatter::beginAppendedData() +{ + openTag("AppendedData"); + xmlAttr("encoding", encoding()); + closeTag(); + os_ << '_'; + + return *this; +} + + Foam::foamVtkFormatter& Foam::foamVtkFormatter::xmlAttr ( @@ -258,55 +285,35 @@ Foam::foamVtkFormatter::xmlAttr // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * // Foam::foamVtkFormatter& -Foam::foamVtkFormatter::operator() -( - const word& k, - const std::string& v -) +Foam::foamVtkFormatter::operator()(const word& k, const std::string& v) { return xmlAttr(k, v); } Foam::foamVtkFormatter& -Foam::foamVtkFormatter::operator() -( - const word& k, - const int32_t v -) +Foam::foamVtkFormatter::operator()(const word& k, const int32_t v) { return xmlAttr(k, v); } Foam::foamVtkFormatter& -Foam::foamVtkFormatter::operator() -( - const word& k, - const int64_t v -) +Foam::foamVtkFormatter::operator()(const word& k, const int64_t v) { return xmlAttr(k, v); } Foam::foamVtkFormatter& -Foam::foamVtkFormatter::operator() -( - const word& k, - const uint64_t v -) +Foam::foamVtkFormatter::operator()(const word& k, const uint64_t v) { return xmlAttr(k, v); } Foam::foamVtkFormatter& -Foam::foamVtkFormatter::operator() -( - const word& k, - const scalar v -) +Foam::foamVtkFormatter::operator()(const word& k, const scalar v) { return xmlAttr(k, v); } diff --git a/src/fileFormats/vtk/format/foamVtkFormatter.H b/src/fileFormats/vtk/format/foamVtkFormatter.H index 5ab0776d60..9e37f2c625 100644 --- a/src/fileFormats/vtk/format/foamVtkFormatter.H +++ b/src/fileFormats/vtk/format/foamVtkFormatter.H @@ -89,13 +89,10 @@ protected: public: - // Static Data + // Public typedefs - //- VTK name for the 'byte_order' attribute - static const char* const byteOrder; - - //- VTK name for the 'header_type' attribute (UInt64) - static const char* const headerType; + //- Use UInt64 for header data + typedef uint64_t headerType; //- Destructor @@ -161,6 +158,20 @@ public: //- Write XML tag without any attributes. Combines openTag/closeTag. foamVtkFormatter& tag(const word& tag); + //- Add a "VTKFile" XML tag for contentType, followed by a tag for + // the contentType itself. Optionally leave the contentType tag + // open for adding additional attributes. + foamVtkFormatter& beginVTKFile + ( + const word& contentType, + const word& contentVersion, + const bool leaveOpen = false + ); + + //- Add a "AppendedData" XML tag with the current encoding and output + // the requisite '_' prefix. + foamVtkFormatter& beginAppendedData(); + //- Open "DataArray" XML tag template @@ -174,11 +185,25 @@ public: //- End "DataArray" XML tag - foamVtkFormatter& endDataArray() + inline foamVtkFormatter& endDataArray() { return endTag("DataArray"); } + //- End "AppendedData" XML tag + inline foamVtkFormatter& endAppendedData() + { + flush(); // flush any pending encoded content + os_ << '\n'; // clear separation from content. + return endTag("AppendedData"); + } + + //- End "VTKFile" XML tag + inline foamVtkFormatter& endVTKFile() + { + return endTag("VTKFile"); + } + //- Write XML attribute foamVtkFormatter& xmlAttr From 71ea6bec621df5545ff9f84c4b72743e4b13c79f Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 4 Jan 2017 10:48:13 +0100 Subject: [PATCH 02/35] ENH: update blockMesh reader for paraview 5.2 (issue #337) - although this is not the final desired form, since it uses individual pqPropertyWidget customizations (ie, ugly layout, too many bits of code), but is an interesting intermediate solution that may be useful in other contexts. --- .../PVblockMeshReader/CMakeLists.txt | 79 +++++----- .../PVblockMeshReader/PVblockMeshReader.qrc | 5 - .../PVblockMeshReader/PVblockMeshReader.xml | 7 - .../PVblockMeshReader_SM.xml | 87 +++++------ .../pqPVblockMeshReaderPanel.cxx | 143 ------------------ .../PVblockMeshReader/pqRefreshProperty.cxx | 120 +++++++++++++++ ...kMeshReaderPanel.h => pqRefreshProperty.h} | 63 ++++---- .../pqShowPointNumbersProperty.cxx | 122 +++++++++++++++ .../pqShowPointNumbersProperty.h | 89 +++++++++++ .../vtkPVblockMeshReader.cxx | 14 +- .../PVblockMeshReader/vtkPVblockMeshReader.h | 16 +- .../vtkPVblockMesh/vtkPVblockMesh.C | 40 +++-- .../vtkPVblockMesh/vtkPVblockMesh.H | 31 +--- .../vtkPVblockMesh/vtkPVblockMeshConvert.C | 13 +- .../vtkPVblockMesh/vtkPVblockMeshUtils.C | 43 +----- 15 files changed, 484 insertions(+), 388 deletions(-) delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/PVblockMeshReader.qrc delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/PVblockMeshReader.xml delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqPVblockMeshReaderPanel.cxx create mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqRefreshProperty.cxx rename applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/{pqPVblockMeshReaderPanel.h => pqRefreshProperty.h} (61%) create mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqShowPointNumbersProperty.cxx create mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqShowPointNumbersProperty.h diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/CMakeLists.txt b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/CMakeLists.txt index 34c9353fe9..3ef1d0c672 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/CMakeLists.txt +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/CMakeLists.txt @@ -1,11 +1,4 @@ -# create a plugin that adds a reader to the ParaView GUI -# it is added in the file dialog when doing opens/saves. - -# The qrc file is processed by Qt's resource compiler (rcc) -# the qrc file must have a resource prefix of "/ParaViewResources" -# and ParaView will read anything contained under that prefix -# the pqReader.xml file contains xml defining readers with their -# file extensions and descriptions. +# Create a plugin to add a reader to the ParaView GUI CMAKE_MINIMUM_REQUIRED(VERSION 2.6) @@ -25,7 +18,7 @@ INCLUDE_DIRECTORIES( ) ADD_DEFINITIONS( - -std=c++0x + -std=c++11 -DWM_$ENV{WM_PRECISION_OPTION} -DWM_LABEL_SIZE=$ENV{WM_LABEL_SIZE} ) @@ -37,44 +30,44 @@ SET( "Single output directory for building all libraries." ) -# -# Define combined plugin -# -# Extend the auto-generated panel -QT4_WRAP_CPP(MOC_SRCS pqPVblockMeshReaderPanel.h) - -ADD_PARAVIEW_OBJECT_PANEL(IFACES IFACE_SRCS - CLASS_NAME pqPVblockMeshReaderPanel - XML_NAME PVblockMeshReader # name of SourceProxy in *SM.xml - XML_GROUP sources -) - -# Separate GUI_RESOURCE_FILES deprecated with paraview 4.3 -# so check if version < 4.4 - -IF(("${PARAVIEW_VERSION_MAJOR}" LESS 5) AND ("${PARAVIEW_VERSION_MINOR}" LESS 4)) - ADD_PARAVIEW_PLUGIN( - PVblockMeshReader_SM "1.0" - SERVER_MANAGER_XML PVblockMeshReader_SM.xml - SERVER_MANAGER_SOURCES vtkPVblockMeshReader.cxx - GUI_INTERFACES ${IFACES} - GUI_SOURCES pqPVblockMeshReaderPanel.cxx - ${MOC_SRCS} ${UI_SRCS} ${IFACE_SRCS} - GUI_RESOURCE_FILES PVblockMeshReader.xml - ) +IF (PARAVIEW_QT_VERSION VERSION_GREATER "4") + QT5_WRAP_CPP(MOC_SRCS + pqRefreshProperty.h + pqShowPointNumbersProperty.h + ) ELSE() - ADD_PARAVIEW_PLUGIN( - PVblockMeshReader_SM "1.0" - SERVER_MANAGER_XML PVblockMeshReader_SM.xml - SERVER_MANAGER_SOURCES vtkPVblockMeshReader.cxx - GUI_INTERFACES ${IFACES} - GUI_SOURCES pqPVblockMeshReaderPanel.cxx - ${MOC_SRCS} ${UI_SRCS} ${IFACE_SRCS} - ) + QT4_WRAP_CPP(MOC_SRCS + pqRefreshProperty.h + pqShowPointNumbersProperty.h + ) ENDIF() -# Build the client-side plugin +ADD_PARAVIEW_PROPERTY_WIDGET(IFACES0 IFACES0_SRCS + TYPE "openfoam_refresh_button" + CLASS_NAME pqRefreshProperty +) + +ADD_PARAVIEW_PROPERTY_WIDGET(IFACES1 IFACES1_SRCS + TYPE "openfoam_show_point_numbers" + CLASS_NAME pqShowPointNumbersProperty +) + +ADD_PARAVIEW_PLUGIN( + PVblockMeshReader_SM "1.0" + SERVER_MANAGER_XML PVblockMeshReader_SM.xml + SERVER_MANAGER_SOURCES vtkPVblockMeshReader.cxx + GUI_INTERFACES + ${IFACES0} + ${IFACES1} + SOURCES + ${IFACES0_SRCS} + ${IFACES1_SRCS} + ${MOC_SRCS} + pqRefreshProperty.cxx + pqShowPointNumbersProperty.cxx +) + TARGET_LINK_LIBRARIES( PVblockMeshReader_SM diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/PVblockMeshReader.qrc b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/PVblockMeshReader.qrc deleted file mode 100644 index 228226bd56..0000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/PVblockMeshReader.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - PVblockMeshReader.xml - - diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/PVblockMeshReader.xml b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/PVblockMeshReader.xml deleted file mode 100644 index 9354a13525..0000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/PVblockMeshReader.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/PVblockMeshReader_SM.xml b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/PVblockMeshReader_SM.xml index 28df8ae78b..61b251bbd1 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/PVblockMeshReader_SM.xml +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/PVblockMeshReader_SM.xml @@ -5,45 +5,38 @@ class="vtkPVblockMeshReader"> - + panel_visibility="never"> - - Specifies the filename for the OpenFOAM blockMesh Reader. - + The filename for the OpenFOAM blockMesh reader. - - - - - Show point numbers in render window. - - - - - + + panel_widget="openfoam_refresh_button" + number_of_elements="1" + panel_visibility="default"> - - Rescan for updated blockMeshDict. - + Rescan for updated blockMeshDict. + + + + Show point numbers in render window. + @@ -81,7 +71,7 @@ information_only="1"> - + information_property="CurvedEdgesArrayStatus"> - - This property contains a list of the curved edges - + The list of curved edges - - - - + + + + + + + + + + + + + diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqPVblockMeshReaderPanel.cxx b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqPVblockMeshReaderPanel.cxx deleted file mode 100644 index 06f0db328d..0000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqPVblockMeshReaderPanel.cxx +++ /dev/null @@ -1,143 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -\*---------------------------------------------------------------------------*/ - -#include "pqPVblockMeshReaderPanel.h" - -// QT -#include -#include -#include -#include -#include -#include -#include - -// Paraview <-> QT UI -#include "pqAnimationScene.h" -#include "pqApplicationCore.h" -#include "pqPipelineRepresentation.h" -#include "pqServerManagerModel.h" -#include "pqView.h" - -// Paraview Server Manager -#include "vtkSMDoubleVectorProperty.h" -#include "vtkSMIntVectorProperty.h" -#include "vtkSMProperty.h" -#include "vtkSMSourceProxy.h" - - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -pqPVblockMeshReaderPanel::pqPVblockMeshReaderPanel -( - pqProxy *proxy, - QWidget *p -) -: - pqAutoGeneratedObjectPanel(proxy, p) -{ - // Create first sublayout (at top of the panel) - QGridLayout *form = new QGridLayout(); - this->PanelLayout->addLayout(form, 0, 0, 1, -1); - - vtkSMProperty* prop = 0; - - // Refresh button for updating blocks - if ((prop = this->proxy()->GetProperty("UiRefresh")) != 0) - { - prop->SetImmediateUpdate(1); - QPushButton* refresh = new QPushButton("Refresh"); - refresh->setToolTip("Rescan for updated blockMeshDict."); - - form->addWidget(refresh, 0, 0, Qt::AlignLeft); - QObject::connect - ( - refresh, - SIGNAL(clicked()), - this, - SLOT(RefreshPressed()) - ); - } - - // Checkbox for showing point numbers - if ((prop = this->proxy()->GetProperty("UiShowPointNumbers")) != 0) - { - prop->SetImmediateUpdate(true); - - ShowPointNumbers_ = new QCheckBox("Show Point Numbers"); - ShowPointNumbers_->setToolTip("Show point numbers in render window."); - ShowPointNumbers_->setChecked - ( - vtkSMIntVectorProperty::SafeDownCast(prop)->GetElement(0) - ); - - form->addWidget(ShowPointNumbers_); - - connect - ( - ShowPointNumbers_, - SIGNAL(stateChanged(int)), - this, - SLOT(ShowPointNumbersToggled()) - ); - } - -} - -// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // - -void pqPVblockMeshReaderPanel::ShowPointNumbersToggled() -{ - vtkSMIntVectorProperty::SafeDownCast - ( - this->proxy()->GetProperty("UiShowPointNumbers") - )->SetElement(0, ShowPointNumbers_->isChecked()); - - // Update the active view - if (this->view()) - { - this->view()->render(); - } - // OR: update all views - // pqApplicationCore::instance()->render(); -} - - -void pqPVblockMeshReaderPanel::RefreshPressed() -{ - // Update everything - vtkSMIntVectorProperty::SafeDownCast - ( - this->proxy()->GetProperty("UiRefresh") - )->Modified(); - - vtkSMSourceProxy::SafeDownCast(this->proxy())->UpdatePipeline(); - - // Render all views - pqApplicationCore::instance()->render(); -} - - -// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqRefreshProperty.cxx b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqRefreshProperty.cxx new file mode 100644 index 0000000000..c925dfe8cc --- /dev/null +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqRefreshProperty.cxx @@ -0,0 +1,120 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "pqRefreshProperty.h" + +#include +#include + +#include "pqApplicationCore.h" +#include "pqView.h" +#include "vtkSMDocumentation.h" +#include "vtkSMIntVectorProperty.h" +#include "vtkSMSourceProxy.h" + +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +// file-scope +static void setButtonProperties +( + QAbstractButton* b, + vtkSMIntVectorProperty* prop, + bool initChecked = true +) +{ + QString tip; + + vtkSMDocumentation* doc = prop->GetDocumentation(); + if (doc) + { + const char* txt = doc->GetDescription(); + if (txt) + { + tip = QString(txt).simplified(); + } + } + + b->setText(prop->GetXMLLabel()); + if (tip.size()) + { + b->setToolTip(tip); + } + b->setFocusPolicy(Qt::NoFocus); // avoid dotted border + + // initial checked state + if (initChecked) + { + b->setChecked(prop->GetElement(0)); + } +} + + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +void pqRefreshProperty::refreshPressed() +{ + // Update everything + refresh_->Modified(); + + vtkSMSourceProxy::SafeDownCast(this->proxy())->UpdatePipeline(); + + // Render all views + pqApplicationCore::instance()->render(); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +pqRefreshProperty::pqRefreshProperty +( + vtkSMProxy* proxy, + vtkSMProperty* prop, + QWidget* parent +) +: + Superclass(proxy, parent), + refresh_(vtkSMIntVectorProperty::SafeDownCast(prop)) +{ + // Replace with our UI content + this->setShowLabel(false); + + QGridLayout* form = new QGridLayout(this); + + QPushButton* b = new QPushButton(this); + setButtonProperties(b, refresh_, false); + form->addWidget(b, 0, 0, Qt::AlignLeft); + + connect(b, SIGNAL(clicked()), this, SLOT(refreshPressed())); + refresh_->SetImmediateUpdate(true); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +pqRefreshProperty::~pqRefreshProperty() +{} + + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqPVblockMeshReaderPanel.h b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqRefreshProperty.h similarity index 61% rename from applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqPVblockMeshReaderPanel.h rename to applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqRefreshProperty.h index 4c15bc374e..cf2879ebfb 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqPVblockMeshReaderPanel.h +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqRefreshProperty.h @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -22,60 +22,63 @@ License along with OpenFOAM. If not, see . Class - pqPVblockMeshReaderPanel + pqRefreshProperty Description - GUI modifications for the ParaView reader panel - - A custom panel for the PVblockMeshReader. + Custom refresh button (ParaView blockMesh reader) SourceFiles - pqPVblockMeshReaderPanel.cxx + pqRefreshProperty.cxx \*---------------------------------------------------------------------------*/ -#ifndef pqPVblockMeshReaderPanel_h -#define pqPVblockMeshReaderPanel_h +#ifndef pqRefreshProperty_h +#define pqRefreshProperty_h -#include "pqAutoGeneratedObjectPanel.h" +#include "pqPropertyWidget.h" -// Forward declaration of QT classes - -class QCheckBox; -class QLineEdit; -class QTimer; -class QToolButton; - -// Forward declaration of ParaView classes -class vtkSMSourceProxy; +// Forward declarations (ParaView) +class vtkSMIntVectorProperty; /*---------------------------------------------------------------------------*\ - Class pqPVblockMeshReaderPanel Declaration + Class pqRefreshProperty Declaration \*---------------------------------------------------------------------------*/ -class pqPVblockMeshReaderPanel +class pqRefreshProperty : - public pqAutoGeneratedObjectPanel + public pqPropertyWidget { - // Private data Q_OBJECT; - typedef pqAutoGeneratedObjectPanel Superclass; + typedef pqPropertyWidget Superclass; + + // Private data + + //- Refresh (bool property - as push button) + vtkSMIntVectorProperty* refresh_; - //- Show Point Numbers checkbox - QCheckBox* ShowPointNumbers_; protected slots: - void ShowPointNumbersToggled(); - void RefreshPressed(); + // Protected Member Functions + + //- Trigger refresh + void refreshPressed(); public: - // Constructors + //- Construct from components + pqRefreshProperty + ( + vtkSMProxy* proxy, + vtkSMProperty* prop, + QWidget* parent = nullptr + ); + + + //- Destructor + virtual ~pqRefreshProperty(); - //- Construct from components - pqPVblockMeshReaderPanel(pqProxy*, QWidget*); }; diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqShowPointNumbersProperty.cxx b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqShowPointNumbersProperty.cxx new file mode 100644 index 0000000000..8e3c40e1aa --- /dev/null +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqShowPointNumbersProperty.cxx @@ -0,0 +1,122 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "pqShowPointNumbersProperty.h" + +#include +#include + +#include "pqApplicationCore.h" +#include "pqView.h" +#include "vtkSMDocumentation.h" +#include "vtkSMIntVectorProperty.h" + +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +// file-scope +static void setButtonProperties +( + QAbstractButton* b, + vtkSMIntVectorProperty* prop, + bool initChecked = true +) +{ + QString tip; + + vtkSMDocumentation* doc = prop->GetDocumentation(); + if (doc) + { + const char* txt = doc->GetDescription(); + if (txt) + { + tip = QString(txt).simplified(); + } + } + + b->setText(prop->GetXMLLabel()); + if (tip.size()) + { + b->setToolTip(tip); + } + b->setFocusPolicy(Qt::NoFocus); // avoid dotted border + + // initial checked state + if (initChecked) + { + b->setChecked(prop->GetElement(0)); + } +} + + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +void pqShowPointNumbersProperty::showPointNumbers(bool checked) +{ + showPointNumbers_->SetElement(0, checked); + + // Update the active view + if (this->view()) + { + this->view()->render(); + } + + // OR: update all views + // pqApplicationCore::instance()->render(); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +pqShowPointNumbersProperty::pqShowPointNumbersProperty +( + vtkSMProxy* proxy, + vtkSMProperty* prop, + QWidget* parent +) +: + Superclass(proxy, parent), + showPointNumbers_(vtkSMIntVectorProperty::SafeDownCast(prop)) +{ + // Replace with our UI content + this->setShowLabel(false); + + QGridLayout* form = new QGridLayout(this); + + QCheckBox* b = new QCheckBox(this); + setButtonProperties(b, showPointNumbers_); + form->addWidget(b, 0, 0, Qt::AlignLeft); + + connect(b, SIGNAL(toggled(bool)), this, SLOT(showPointNumbers(bool))); + showPointNumbers_->SetImmediateUpdate(true); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +pqShowPointNumbersProperty::~pqShowPointNumbersProperty() +{} + + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqShowPointNumbersProperty.h b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqShowPointNumbersProperty.h new file mode 100644 index 0000000000..30021a309d --- /dev/null +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqShowPointNumbersProperty.h @@ -0,0 +1,89 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + pqShowPointNumbersProperty + +Description + Custom UI handling of show-points (ParaView blockMesh reader) + +SourceFiles + pqShowPointNumbersProperty.cxx + +\*---------------------------------------------------------------------------*/ +#ifndef pqShowPointNumbersProperty_h +#define pqShowPointNumbersProperty_h + +#include "pqPropertyWidget.h" + +// Forward declarations (ParaView) +class vtkSMIntVectorProperty; + + +/*---------------------------------------------------------------------------*\ + Class pqShowPointNumbersProperty Declaration +\*---------------------------------------------------------------------------*/ + +class pqShowPointNumbersProperty +: + public pqPropertyWidget +{ + Q_OBJECT; + typedef pqPropertyWidget Superclass; + + // Private data + + //- Show Point Numbers (bool property) + vtkSMIntVectorProperty* showPointNumbers_; + + +protected slots: + + // Protected Member Functions + + //- Sync property with changed checkbox state, update rendered view(s) + void showPointNumbers(bool checked); + + +public: + + //- Construct from components + pqShowPointNumbersProperty + ( + vtkSMProxy* proxy, + vtkSMProperty* prop, + QWidget* parent = nullptr + ); + + + //- Destructor + virtual ~pqShowPointNumbersProperty(); + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/vtkPVblockMeshReader.cxx b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/vtkPVblockMeshReader.cxx index 6d559e7a33..2ff68b27b7 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/vtkPVblockMeshReader.cxx +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/vtkPVblockMeshReader.cxx @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -59,7 +59,7 @@ vtkPVblockMeshReader::vtkPVblockMeshReader() FileName = nullptr; foamData_ = nullptr; - ShowPointNumbers = 1; + ShowPointNumbers = true; BlockSelection = vtkDataArraySelection::New(); CurvedEdgesSelection = vtkDataArraySelection::New(); @@ -92,7 +92,7 @@ vtkPVblockMeshReader::vtkPVblockMeshReader() vtkPVblockMeshReader::~vtkPVblockMeshReader() { - vtkDebugMacro(<<"Deconstructor"); + vtkDebugMacro(<<"Destructor"); if (foamData_) { @@ -106,8 +106,8 @@ vtkPVblockMeshReader::~vtkPVblockMeshReader() delete [] FileName; } - BlockSelection->RemoveObserver(this->SelectionObserver); - CurvedEdgesSelection->RemoveObserver(this->SelectionObserver); + BlockSelection->RemoveAllObservers(); + CurvedEdgesSelection->RemoveAllObservers(); SelectionObserver->Delete(); BlockSelection->Delete(); @@ -218,7 +218,7 @@ int vtkPVblockMeshReader::RequestData } -void vtkPVblockMeshReader::SetRefresh(int val) +void vtkPVblockMeshReader::SetRefresh(bool val) { // Delete the current blockMesh to force re-read and update if (foamData_) @@ -232,7 +232,7 @@ void vtkPVblockMeshReader::SetRefresh(int val) } -void vtkPVblockMeshReader::SetShowPointNumbers(const int val) +void vtkPVblockMeshReader::SetShowPointNumbers(bool val) { if (ShowPointNumbers != val) { diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/vtkPVblockMeshReader.h b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/vtkPVblockMeshReader.h index b160b7c035..92a02e7ebd 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/vtkPVblockMeshReader.h +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/vtkPVblockMeshReader.h @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -73,12 +73,12 @@ public: // Description: // Display corner point labels - virtual void SetShowPointNumbers(int); - vtkGetMacro(ShowPointNumbers, int); + virtual void SetShowPointNumbers(bool); + vtkGetMacro(ShowPointNumbers, bool); // Description: // Refresh blockMesh from changes to blockMeshDict - virtual void SetRefresh(int); + virtual void SetRefresh(bool); // Description: // Blocks selection list control @@ -144,25 +144,23 @@ protected: private: //- Disallow default bitwise copy construct - vtkPVblockMeshReader(const vtkPVblockMeshReader&); + vtkPVblockMeshReader(const vtkPVblockMeshReader&) = delete; //- Disallow default bitwise assignment - void operator=(const vtkPVblockMeshReader&); + void operator=(const vtkPVblockMeshReader&) = delete; //- Add/remove point numbers to/from the view void updatePointNumbersView(const bool show); //- Show Point Numbers - int ShowPointNumbers; + bool ShowPointNumbers; vtkDataArraySelection* BlockSelection; vtkDataArraySelection* CurvedEdgesSelection; - //BTX Foam::vtkPVblockMesh* foamData_; - //ETX }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMesh.C b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMesh.C index dd40c8e359..c4b5e9c6e5 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMesh.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMesh.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -63,13 +63,15 @@ void Foam::vtkPVblockMesh::updateInfoBlocks vtkDataArraySelection* arraySelection ) { + arrayRange& range = arrayRangeBlocks_; + if (debug) { Info<< " Foam::vtkPVblockMesh::updateInfoBlocks" << " [meshPtr=" << (meshPtr_ ? "set" : "nullptr") << "]" << endl; } - arrayRangeBlocks_.reset( arraySelection->GetNumberOfArrays() ); + range.reset(arraySelection->GetNumberOfArrays()); const blockMesh& blkMesh = *meshPtr_; @@ -80,21 +82,20 @@ void Foam::vtkPVblockMesh::updateInfoBlocks // Display either blockI as a number or with its name // (looked up from blockMeshDict) - OStringStream os; - blockDescriptor::write(os, blockI, blkMesh.meshDict()); - word partName(os.str()); + OStringStream ostr; + blockDescriptor::write(ostr, blockI, blkMesh.meshDict()); // append the (optional) zone name if (!blockDef.zoneName().empty()) { - partName += " - " + blockDef.zoneName(); + ostr << " - " << blockDef.zoneName(); } - // Add blockId and zoneName to GUI list - arraySelection->AddArray(partName.c_str()); + // Add "blockId" or "blockId - zoneName" to GUI list + arraySelection->AddArray(ostr.str().c_str()); } - arrayRangeBlocks_ += nBlocks; + range += nBlocks; if (debug) { @@ -111,18 +112,19 @@ void Foam::vtkPVblockMesh::updateInfoEdges vtkDataArraySelection* arraySelection ) { + arrayRange& range = arrayRangeEdges_; + if (debug) { Info<< " Foam::vtkPVblockMesh::updateInfoEdges" << " [meshPtr=" << (meshPtr_ ? "set" : "nullptr") << "]" << endl; } - arrayRangeEdges_.reset( arraySelection->GetNumberOfArrays() ); + range.reset(arraySelection->GetNumberOfArrays()); const blockMesh& blkMesh = *meshPtr_; const blockEdgeList& edges = blkMesh.edges(); - const int nEdges = edges.size(); forAll(edges, edgeI) { OStringStream ostr; @@ -135,7 +137,7 @@ void Foam::vtkPVblockMesh::updateInfoEdges arraySelection->AddArray(ostr.str().c_str()); } - arrayRangeEdges_ += nEdges; + range += edges.size(); if (debug) { @@ -281,18 +283,14 @@ void Foam::vtkPVblockMesh::updateInfo() resetCounters(); vtkDataArraySelection* blockSelection = reader_->GetBlockSelection(); - vtkDataArraySelection* edgeSelection = reader_->GetCurvedEdgesSelection(); + vtkDataArraySelection* edgeSelection = reader_->GetCurvedEdgesSelection(); // enable 'internalMesh' on the first call // or preserve the enabled selections stringList enabledParts; stringList enabledEdges; - bool firstTime = false; - if (!blockSelection->GetNumberOfArrays() && !meshPtr_) - { - firstTime = true; - } - else + const bool firstTime = (!blockSelection->GetNumberOfArrays() && !meshPtr_); + if (!firstTime) { enabledParts = getSelectedArrayEntries(blockSelection); enabledEdges = getSelectedArrayEntries(edgeSelection); @@ -306,10 +304,10 @@ void Foam::vtkPVblockMesh::updateInfo() updateFoamMesh(); // Update mesh parts list - updateInfoBlocks( blockSelection ); + updateInfoBlocks(blockSelection); // Update curved edges list - updateInfoEdges( edgeSelection ); + updateInfoEdges(edgeSelection); // restore the enabled selections if (!firstTime) diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMesh.H b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMesh.H index dc502926f4..abaa705f13 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMesh.H +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMesh.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -41,18 +41,11 @@ SourceFiles #ifndef vtkPVblockMesh_H #define vtkPVblockMesh_H -// do not include legacy strstream headers -#ifndef VTK_EXCLUDE_STRSTREAM_HEADERS -# define VTK_EXCLUDE_STRSTREAM_HEADERS -#endif - #include "className.H" #include "fileName.H" #include "stringList.H" #include "wordList.H" -#include "primitivePatch.H" - // * * * * * * * * * * * * * Forward Declarations * * * * * * * * * * * * * // class vtkDataArraySelection; @@ -198,6 +191,7 @@ class vtkPVblockMesh //- List of point numbers for rendering to window List pointNumberTextActorsPtrs_; + // Private Member Functions // Convenience method use to convert the readers from VTK 5 @@ -211,23 +205,6 @@ class vtkPVblockMesh const std::string& datasetName ); - // Convenience method use to convert the readers from VTK 5 - // multiblock API to the current composite data infrastructure - static vtkDataSet* GetDataSetFromBlock - ( - vtkMultiBlockDataSet* output, - const arrayRange&, - const label datasetNo - ); - - // Convenience method use to convert the readers from VTK 5 - // multiblock API to the current composite data infrastructure - static label GetNumberOfDataSets - ( - vtkMultiBlockDataSet* output, - const arrayRange& - ); - //- Update boolList from GUI selection static void updateBoolListStatus ( @@ -294,10 +271,10 @@ class vtkPVblockMesh //- Disallow default bitwise copy construct - vtkPVblockMesh(const vtkPVblockMesh&); + vtkPVblockMesh(const vtkPVblockMesh&) = delete; //- Disallow default bitwise assignment - void operator=(const vtkPVblockMesh&); + void operator=(const vtkPVblockMesh&) = delete; public: diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMeshConvert.C b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMeshConvert.C index 9c7f8a06ba..09df113f0e 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMeshConvert.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMeshConvert.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -52,7 +52,7 @@ void Foam::vtkPVblockMesh::convertMeshBlocks vtkDataArraySelection* selection = reader_->GetBlockSelection(); arrayRange& range = arrayRangeBlocks_; range.block(blockNo); // set output block - label datasetNo = 0; // restart at dataset 0 + label datasetNo = 0; // restart at dataset 0 const blockMesh& blkMesh = *meshPtr_; const Foam::pointField& blockPoints = blkMesh.vertices(); @@ -234,7 +234,6 @@ void Foam::vtkPVblockMesh::convertMeshEdges } } - // anything added? if (datasetNo) { @@ -286,7 +285,7 @@ void Foam::vtkPVblockMesh::convertMeshCorners scaleFactor ); - vtkcells->InsertNextCell(1, &pointId); + vtkcells->InsertNextCell(1, &pointId); // VTK_VERTEX pointId++; } @@ -296,11 +295,7 @@ void Foam::vtkPVblockMesh::convertMeshCorners vtkmesh->SetVerts(vtkcells); vtkcells->Delete(); - AddToBlock - ( - output, vtkmesh, range, datasetNo, - arrayRangeCorners_.name() - ); + AddToBlock(output, vtkmesh, range, datasetNo, range.name()); vtkmesh->Delete(); datasetNo++; diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMeshUtils.C b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMeshUtils.C index a838c5b602..92602737b9 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMeshUtils.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMeshUtils.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -126,47 +126,6 @@ void Foam::vtkPVblockMesh::AddToBlock } -vtkDataSet* Foam::vtkPVblockMesh::GetDataSetFromBlock -( - vtkMultiBlockDataSet* output, - const arrayRange& range, - const label datasetNo -) -{ - const int blockNo = range.block(); - - vtkDataObject* blockDO = output->GetBlock(blockNo); - vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO); - - if (block) - { - return vtkDataSet::SafeDownCast(block->GetBlock(datasetNo)); - } - - return 0; -} - - -// ununsed at the moment -Foam::label Foam::vtkPVblockMesh::GetNumberOfDataSets -( - vtkMultiBlockDataSet* output, - const arrayRange& range -) -{ - const int blockNo = range.block(); - - vtkDataObject* blockDO = output->GetBlock(blockNo); - vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO); - if (block) - { - return block->GetNumberOfBlocks(); - } - - return 0; -} - - Foam::wordHashSet Foam::vtkPVblockMesh::getSelected ( vtkDataArraySelection* select From 4eb679614cd04478355c72d9fa651cbb4e0d8289 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 4 Jan 2017 12:27:36 +0100 Subject: [PATCH 03/35] ENH: update blockMesh reader (issue #337) - use property group customization instead of individual pqPropertyWidget --- .../PVblockMeshReader/CMakeLists.txt | 50 +++---- .../PVblockMeshReader_SM.xml | 6 +- ...operty.cxx => pqFoamBlockMeshControls.cxx} | 80 +++++++++--- ...rsProperty.h => pqFoamBlockMeshControls.h} | 37 ++++-- .../PVblockMeshReader/pqRefreshProperty.h | 89 ------------- .../pqShowPointNumbersProperty.cxx | 122 ------------------ 6 files changed, 114 insertions(+), 270 deletions(-) rename applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/{pqRefreshProperty.cxx => pqFoamBlockMeshControls.cxx} (62%) rename applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/{pqShowPointNumbersProperty.h => pqFoamBlockMeshControls.h} (71%) delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqRefreshProperty.h delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqShowPointNumbersProperty.cxx diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/CMakeLists.txt b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/CMakeLists.txt index 3ef1d0c672..0ee611b0ed 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/CMakeLists.txt +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/CMakeLists.txt @@ -1,75 +1,65 @@ # Create a plugin to add a reader to the ParaView GUI -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +cmake_minimum_required(VERSION 2.6) -FIND_PACKAGE(ParaView REQUIRED) -INCLUDE(${PARAVIEW_USE_FILE}) +find_package(ParaView REQUIRED) +include(${PARAVIEW_USE_FILE}) -LINK_DIRECTORIES( +link_directories( $ENV{FOAM_LIBBIN} $ENV{FOAM_EXT_LIBBIN} ) -INCLUDE_DIRECTORIES( +include_directories( $ENV{WM_PROJECT_DIR}/src/OpenFOAM/lnInclude $ENV{WM_PROJECT_DIR}/src/OSspecific/$ENV{WM_OSTYPE}/lnInclude $ENV{WM_PROJECT_DIR}/src/meshing/blockMesh/lnInclude ${PROJECT_SOURCE_DIR}/../vtkPVblockMesh ) -ADD_DEFINITIONS( +add_definitions( -std=c++11 -DWM_$ENV{WM_PRECISION_OPTION} -DWM_LABEL_SIZE=$ENV{WM_LABEL_SIZE} ) # Set output library destination to plugin directory -SET( +set( LIBRARY_OUTPUT_PATH $ENV{PV_PLUGIN_PATH} CACHE INTERNAL "Single output directory for building all libraries." ) -IF (PARAVIEW_QT_VERSION VERSION_GREATER "4") - QT5_WRAP_CPP(MOC_SRCS - pqRefreshProperty.h - pqShowPointNumbersProperty.h +if (PARAVIEW_QT_VERSION VERSION_GREATER "4") + qt5_wrap_cpp(MOC_SRCS + pqFoamBlockMeshControls.h ) -ELSE() - QT4_WRAP_CPP(MOC_SRCS - pqRefreshProperty.h - pqShowPointNumbersProperty.h +else() + qt4_wrap_cpp(MOC_SRCS + pqFoamBlockMeshControls.h ) -ENDIF() +endif() -ADD_PARAVIEW_PROPERTY_WIDGET(IFACES0 IFACES0_SRCS - TYPE "openfoam_refresh_button" - CLASS_NAME pqRefreshProperty +add_paraview_property_group_widget(IFACES0 IFACES0_SRCS + TYPE "openfoam_blockMesh_general_controls" + CLASS_NAME pqFoamBlockMeshControls ) -ADD_PARAVIEW_PROPERTY_WIDGET(IFACES1 IFACES1_SRCS - TYPE "openfoam_show_point_numbers" - CLASS_NAME pqShowPointNumbersProperty -) - -ADD_PARAVIEW_PLUGIN( +add_paraview_plugin( PVblockMeshReader_SM "1.0" SERVER_MANAGER_XML PVblockMeshReader_SM.xml SERVER_MANAGER_SOURCES vtkPVblockMeshReader.cxx GUI_INTERFACES ${IFACES0} - ${IFACES1} SOURCES ${IFACES0_SRCS} - ${IFACES1_SRCS} ${MOC_SRCS} - pqRefreshProperty.cxx - pqShowPointNumbersProperty.cxx + pqFoamBlockMeshControls.cxx ) -TARGET_LINK_LIBRARIES( +target_link_libraries( PVblockMeshReader_SM LINK_PUBLIC vtkPVblockMesh diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/PVblockMeshReader_SM.xml b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/PVblockMeshReader_SM.xml index 61b251bbd1..e782c4371f 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/PVblockMeshReader_SM.xml +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/PVblockMeshReader_SM.xml @@ -19,7 +19,6 @@ name="Refresh" command="SetRefresh" default_values="0" - panel_widget="openfoam_refresh_button" number_of_elements="1" panel_visibility="default"> @@ -31,7 +30,6 @@ name="ShowPointNumbers" command="SetShowPointNumbers" default_values="1" - panel_widget="openfoam_show_point_numbers" number_of_elements="1" panel_visibility="default"> @@ -94,7 +92,9 @@ file_description="OpenFOAM blockMesh"/> - + diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqRefreshProperty.cxx b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqFoamBlockMeshControls.cxx similarity index 62% rename from applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqRefreshProperty.cxx rename to applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqFoamBlockMeshControls.cxx index c925dfe8cc..911ad83988 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqRefreshProperty.cxx +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqFoamBlockMeshControls.cxx @@ -23,21 +23,24 @@ License \*---------------------------------------------------------------------------*/ -#include "pqRefreshProperty.h" +#include "pqFoamBlockMeshControls.h" -#include +#include #include +#include #include "pqApplicationCore.h" #include "pqView.h" #include "vtkSMDocumentation.h" #include "vtkSMIntVectorProperty.h" +#include "vtkSMPropertyGroup.h" #include "vtkSMSourceProxy.h" + // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // // file-scope -static void setButtonProperties +static QAbstractButton* setButtonProperties ( QAbstractButton* b, vtkSMIntVectorProperty* prop, @@ -68,12 +71,31 @@ static void setButtonProperties { b->setChecked(prop->GetElement(0)); } + + return b; +} + + +static vtkSMIntVectorProperty* lookupIntProp +( + vtkSMPropertyGroup* group, + const char* name +) +{ + vtkSMProperty* prop = group->GetProperty(name); + + if (prop) + { + return vtkSMIntVectorProperty::SafeDownCast(prop); + } + + return nullptr; } // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // -void pqRefreshProperty::refreshPressed() +void pqFoamBlockMeshControls::refreshPressed() { // Update everything refresh_->Modified(); @@ -85,35 +107,61 @@ void pqRefreshProperty::refreshPressed() } +void pqFoamBlockMeshControls::showPointNumbers(bool checked) +{ + showPointNumbers_->SetElement(0, checked); + + // Update the active view + if (this->view()) + { + this->view()->render(); + } + + // OR: update all views + // pqApplicationCore::instance()->render(); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -pqRefreshProperty::pqRefreshProperty +pqFoamBlockMeshControls::pqFoamBlockMeshControls ( vtkSMProxy* proxy, - vtkSMProperty* prop, + vtkSMPropertyGroup* group, QWidget* parent ) : Superclass(proxy, parent), - refresh_(vtkSMIntVectorProperty::SafeDownCast(prop)) + refresh_(lookupIntProp(group, "Refresh")), + showPointNumbers_(lookupIntProp(group, "ShowPointNumbers")) { - // Replace with our UI content - this->setShowLabel(false); - QGridLayout* form = new QGridLayout(this); - QPushButton* b = new QPushButton(this); - setButtonProperties(b, refresh_, false); - form->addWidget(b, 0, 0, Qt::AlignLeft); + if (refresh_) + { + QPushButton* b = new QPushButton(this); + setButtonProperties(b, refresh_, false); + form->addWidget(b, 0, 0, Qt::AlignLeft); - connect(b, SIGNAL(clicked()), this, SLOT(refreshPressed())); - refresh_->SetImmediateUpdate(true); + connect(b, SIGNAL(clicked()), this, SLOT(refreshPressed())); + refresh_->SetImmediateUpdate(true); + } + + if (showPointNumbers_) + { + QCheckBox* b = new QCheckBox(this); + setButtonProperties(b, showPointNumbers_); + form->addWidget(b, 0, 1, Qt::AlignLeft); + + connect(b, SIGNAL(toggled(bool)), this, SLOT(showPointNumbers(bool))); + showPointNumbers_->SetImmediateUpdate(true); + } } // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // -pqRefreshProperty::~pqRefreshProperty() +pqFoamBlockMeshControls::~pqFoamBlockMeshControls() {} diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqShowPointNumbersProperty.h b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqFoamBlockMeshControls.h similarity index 71% rename from applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqShowPointNumbersProperty.h rename to applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqFoamBlockMeshControls.h index 30021a309d..0ec7150d5c 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqShowPointNumbersProperty.h +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqFoamBlockMeshControls.h @@ -22,17 +22,19 @@ License along with OpenFOAM. If not, see . Class - pqShowPointNumbersProperty + pqFoamBlockMeshControls Description - Custom UI handling of show-points (ParaView blockMesh reader) + Customized property controls for the ParaView blockMesh reader. + + Refresh and ShowPointNumbers. SourceFiles - pqShowPointNumbersProperty.cxx + pqFoamBlockMeshControls.cxx \*---------------------------------------------------------------------------*/ -#ifndef pqShowPointNumbersProperty_h -#define pqShowPointNumbersProperty_h +#ifndef pqFoamBlockMeshControls_h +#define pqFoamBlockMeshControls_h #include "pqPropertyWidget.h" @@ -41,10 +43,10 @@ class vtkSMIntVectorProperty; /*---------------------------------------------------------------------------*\ - Class pqShowPointNumbersProperty Declaration + Class pqFoamBlockMeshControls Declaration \*---------------------------------------------------------------------------*/ -class pqShowPointNumbersProperty +class pqFoamBlockMeshControls : public pqPropertyWidget { @@ -53,14 +55,29 @@ class pqShowPointNumbersProperty // Private data + //- Refresh (bool property - as push button) + vtkSMIntVectorProperty* refresh_; + //- Show Point Numbers (bool property) vtkSMIntVectorProperty* showPointNumbers_; + // Private Member Functions + + //- Disallow default bitwise copy construct + pqFoamBlockMeshControls(const pqFoamBlockMeshControls&) = delete; + + //- Disallow default bitwise assignment + void operator=(const pqFoamBlockMeshControls&) = delete; + + protected slots: // Protected Member Functions + //- Trigger refresh + void refreshPressed(); + //- Sync property with changed checkbox state, update rendered view(s) void showPointNumbers(bool checked); @@ -68,16 +85,16 @@ protected slots: public: //- Construct from components - pqShowPointNumbersProperty + pqFoamBlockMeshControls ( vtkSMProxy* proxy, - vtkSMProperty* prop, + vtkSMPropertyGroup* group, QWidget* parent = nullptr ); //- Destructor - virtual ~pqShowPointNumbersProperty(); + virtual ~pqFoamBlockMeshControls(); }; diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqRefreshProperty.h b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqRefreshProperty.h deleted file mode 100644 index cf2879ebfb..0000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqRefreshProperty.h +++ /dev/null @@ -1,89 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -Class - pqRefreshProperty - -Description - Custom refresh button (ParaView blockMesh reader) - -SourceFiles - pqRefreshProperty.cxx - -\*---------------------------------------------------------------------------*/ -#ifndef pqRefreshProperty_h -#define pqRefreshProperty_h - -#include "pqPropertyWidget.h" - -// Forward declarations (ParaView) -class vtkSMIntVectorProperty; - - -/*---------------------------------------------------------------------------*\ - Class pqRefreshProperty Declaration -\*---------------------------------------------------------------------------*/ - -class pqRefreshProperty -: - public pqPropertyWidget -{ - Q_OBJECT; - typedef pqPropertyWidget Superclass; - - // Private data - - //- Refresh (bool property - as push button) - vtkSMIntVectorProperty* refresh_; - - -protected slots: - - // Protected Member Functions - - //- Trigger refresh - void refreshPressed(); - - -public: - - //- Construct from components - pqRefreshProperty - ( - vtkSMProxy* proxy, - vtkSMProperty* prop, - QWidget* parent = nullptr - ); - - - //- Destructor - virtual ~pqRefreshProperty(); - -}; - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqShowPointNumbersProperty.cxx b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqShowPointNumbersProperty.cxx deleted file mode 100644 index 8e3c40e1aa..0000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqShowPointNumbersProperty.cxx +++ /dev/null @@ -1,122 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -\*---------------------------------------------------------------------------*/ - -#include "pqShowPointNumbersProperty.h" - -#include -#include - -#include "pqApplicationCore.h" -#include "pqView.h" -#include "vtkSMDocumentation.h" -#include "vtkSMIntVectorProperty.h" - -// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // - -// file-scope -static void setButtonProperties -( - QAbstractButton* b, - vtkSMIntVectorProperty* prop, - bool initChecked = true -) -{ - QString tip; - - vtkSMDocumentation* doc = prop->GetDocumentation(); - if (doc) - { - const char* txt = doc->GetDescription(); - if (txt) - { - tip = QString(txt).simplified(); - } - } - - b->setText(prop->GetXMLLabel()); - if (tip.size()) - { - b->setToolTip(tip); - } - b->setFocusPolicy(Qt::NoFocus); // avoid dotted border - - // initial checked state - if (initChecked) - { - b->setChecked(prop->GetElement(0)); - } -} - - -// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // - -void pqShowPointNumbersProperty::showPointNumbers(bool checked) -{ - showPointNumbers_->SetElement(0, checked); - - // Update the active view - if (this->view()) - { - this->view()->render(); - } - - // OR: update all views - // pqApplicationCore::instance()->render(); -} - - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -pqShowPointNumbersProperty::pqShowPointNumbersProperty -( - vtkSMProxy* proxy, - vtkSMProperty* prop, - QWidget* parent -) -: - Superclass(proxy, parent), - showPointNumbers_(vtkSMIntVectorProperty::SafeDownCast(prop)) -{ - // Replace with our UI content - this->setShowLabel(false); - - QGridLayout* form = new QGridLayout(this); - - QCheckBox* b = new QCheckBox(this); - setButtonProperties(b, showPointNumbers_); - form->addWidget(b, 0, 0, Qt::AlignLeft); - - connect(b, SIGNAL(toggled(bool)), this, SLOT(showPointNumbers(bool))); - showPointNumbers_->SetImmediateUpdate(true); -} - - -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -pqShowPointNumbersProperty::~pqShowPointNumbersProperty() -{} - - -// ************************************************************************* // From 2c96ec7550775cc594dd78b815e5266d0403924c Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 5 Jan 2017 11:31:11 +0100 Subject: [PATCH 04/35] ENH: update QT interface code for ParaView reader (issue #337) - remove old (ParaView-3) files - Works in 4.4.0, 5.0.1, 5.2.0 etc STYLE: - slots now use SM properties directly without a second lookup. This reduces exposure of the QT elements and simplifies the coding. - avoid focus borders on the Qt elements - place the "use Polyhedron" checkbox into a column - move "Cache Mesh" down in the GUI (an advanced feature and thus should be less prominent) - obtain button labels/tooltip directly from the XML content --- .../PVFoamReader/PVFoamReader/CMakeLists.txt | 82 ++- .../PVFoamReader/PVFoamReader.qrc | 5 - .../PVFoamReader/PVFoamReader.xml | 7 - .../PVFoamReader/PVFoamReader_SM.xml | 289 ++++++----- .../PVFoamReader/pqFoamReaderControls.cxx | 364 +++++++++++++ .../PVFoamReader/pqFoamReaderControls.h | 118 +++++ .../PVFoamReader/pqPVFoamReaderPanel.cxx | 485 ------------------ .../PVFoamReader/pqPVFoamReaderPanel.h | 116 ----- .../PVFoamReader/vtkPVFoamReader.cxx | 44 +- .../PVFoamReader/vtkPVFoamReader.h | 72 ++- .../PVFoamReader/vtkPVFoam/vtkPVFoam.H | 5 - .../PVReaders/vtkPVReaders/vtkPVReaders.H | 5 - 12 files changed, 719 insertions(+), 873 deletions(-) delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/PVFoamReader.qrc delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/PVFoamReader.xml create mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqFoamReaderControls.cxx create mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqFoamReaderControls.h delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqPVFoamReaderPanel.cxx delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqPVFoamReaderPanel.h diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/CMakeLists.txt b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/CMakeLists.txt index 49e64bf76c..6671a5d179 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/CMakeLists.txt +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/CMakeLists.txt @@ -1,81 +1,65 @@ -# Create a plugin that adds a reader to the ParaView GUI -# it is added in the file dialog when doing opens/saves. +# Create a plugin to add a reader to the ParaView GUI -# The qrc file is processed by Qt's resource compiler (rcc) -# the qrc file must have a resource prefix of "/ParaViewResources" -# and ParaView will read anything contained under that prefix -# the pqReader.xml file contains xml defining readers with their -# file extensions and descriptions. +cmake_minimum_required(VERSION 2.8) -CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +find_package(ParaView REQUIRED) +include(${PARAVIEW_USE_FILE}) -FIND_PACKAGE(ParaView REQUIRED) -INCLUDE(${PARAVIEW_USE_FILE}) - -LINK_DIRECTORIES( +link_directories( $ENV{FOAM_LIBBIN} $ENV{FOAM_EXT_LIBBIN} ) -INCLUDE_DIRECTORIES( +include_directories( $ENV{WM_PROJECT_DIR}/src/OpenFOAM/lnInclude $ENV{WM_PROJECT_DIR}/src/OSspecific/$ENV{WM_OSTYPE}/lnInclude $ENV{WM_PROJECT_DIR}/src/finiteVolume/lnInclude ${PROJECT_SOURCE_DIR}/../vtkPVFoam ) -ADD_DEFINITIONS( - -std=c++0x +add_definitions( + -std=c++11 -DWM_$ENV{WM_PRECISION_OPTION} -DWM_LABEL_SIZE=$ENV{WM_LABEL_SIZE} ) # Set output library destination to plugin directory -SET( +set( LIBRARY_OUTPUT_PATH $ENV{PV_PLUGIN_PATH} CACHE INTERNAL "Single output directory for building all libraries." ) -# -# Defined combined plugin -# +if (PARAVIEW_QT_VERSION VERSION_GREATER "4") + qt5_wrap_cpp(MOC_SRCS + pqFoamReaderControls.h + ) +else() + qt4_wrap_cpp(MOC_SRCS + pqFoamReaderControls.h + ) +endif() -# Extend the auto-generated panel -QT4_WRAP_CPP(MOC_SRCS pqPVFoamReaderPanel.h) - -ADD_PARAVIEW_OBJECT_PANEL(IFACES IFACE_SRCS - CLASS_NAME pqPVFoamReaderPanel - XML_NAME PVFoamReader # name of SourceProxy in *SM.xml - XML_GROUP sources +add_paraview_property_group_widget(IFACES0 IFACES0_SRCS + TYPE "openfoam_reader_general_controls" + CLASS_NAME pqFoamReaderControls ) -# Separate GUI_RESOURCE_FILES deprecated with paraview 4.3 -# so check if version < 4.4 +add_paraview_plugin( + PVFoamReader_SM "1.0" + SERVER_MANAGER_XML PVFoamReader_SM.xml + SERVER_MANAGER_SOURCES vtkPVFoamReader.cxx + GUI_INTERFACES + ${IFACES0} + SOURCES + ${IFACES0_SRCS} + ${MOC_SRCS} + pqFoamReaderControls.cxx +) -IF(("${PARAVIEW_VERSION_MAJOR}" LESS 5) AND ("${PARAVIEW_VERSION_MINOR}" LESS 4)) - ADD_PARAVIEW_PLUGIN( - PVFoamReader_SM "1.0" - SERVER_MANAGER_XML PVFoamReader_SM.xml - SERVER_MANAGER_SOURCES vtkPVFoamReader.cxx - GUI_INTERFACES ${IFACES} - GUI_SOURCES pqPVFoamReaderPanel.cxx - ${MOC_SRCS} ${UI_SRCS} ${IFACE_SRCS} - GUI_RESOURCE_FILES PVFoamReader.xml - ) -ELSE() - ADD_PARAVIEW_PLUGIN( - PVFoamReader_SM "1.0" - SERVER_MANAGER_XML PVFoamReader_SM.xml - SERVER_MANAGER_SOURCES vtkPVFoamReader.cxx - GUI_INTERFACES ${IFACES} - GUI_SOURCES pqPVFoamReaderPanel.cxx - ${MOC_SRCS} ${UI_SRCS} ${IFACE_SRCS} - ) -ENDIF() -TARGET_LINK_LIBRARIES( +target_link_libraries( PVFoamReader_SM LINK_PUBLIC vtkPVFoam diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/PVFoamReader.qrc b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/PVFoamReader.qrc deleted file mode 100644 index 9bb30ea5c0..0000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/PVFoamReader.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - PVFoamReader.xml - - diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/PVFoamReader.xml b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/PVFoamReader.xml deleted file mode 100644 index 5507293c67..0000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/PVFoamReader.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/PVFoamReader_SM.xml b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/PVFoamReader_SM.xml index 69bcfc0962..ebb0c3be93 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/PVFoamReader_SM.xml +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/PVFoamReader_SM.xml @@ -5,14 +5,14 @@ class="vtkPVFoamReader"> - + panel_visibility="never"> - Specifies the filename for the OpenFOAM Reader. + The filename for the OpenFOAM reader module. @@ -27,157 +27,151 @@ - - - - - Cache the fvMesh in memory. - - - - + number_of_elements="1" + panel_visibility="default"> - Rescan for updated timesteps/fields. + Rescan for updated times/fields. - + panel_visibility="default"> - Skip including the 0/ time directory + Ignore the 0/ time directory. + + + + + + + + Search the polyMesh/sets/ directory + + + + + + + + ZoneMesh information is used to find {cell,face,point}Zones. + The polyMesh/ directory is only checked on startup. + + + + + + + + Show patchGroups only. + + + + + + + + Show patch names in render window. - + number_of_elements="1" + panel_visibility="default"> - Interpolate volume fields into point fields + Interpolate volFields into pointFields. - + number_of_elements="1" + panel_visibility="default"> - Extrapolate internalField to non-constraint patches + Extrapolate internalField to non-constraint patches. + + + + + + + + Force reader GUI update. - + number_of_elements="1" + panel_visibility="default"> Use vtkPolyhedron instead of decomposing polyhedra. - - + - - Search the polyMesh/sets/ directory - - - - - - - - ZoneMesh information is used to find {cell,face,point}Zones. - The polyMesh/ directory is only checked on startup. - - - - - - + panel_visibility="default"> - Show patch names in render window - - - - - - - - Show groups only - - - - - - - - A simple way to cause a reader GUI modification. + Cache the fvMesh in memory. @@ -191,7 +185,7 @@ information_only="1"> - + information_property="PartArrayStatus"> - This property contains a list of the mesh parts - (patches, groups, sets, zones). + The list of mesh parts (patches, groups, sets, zones). @@ -218,7 +210,7 @@ information_only="1"> - + information_property="VolFieldArrayStatus"> - - This property contains a list of the volume fields - + The list of volume fields. @@ -244,7 +233,7 @@ information_only="1"> - + information_property="LagrangianFieldArrayStatus"> - - This property contains a list of the lagrangian fields - + The list of Lagrangian fields. @@ -270,7 +256,7 @@ information_only="1"> - + information_property="PointFieldArrayStatus"> - - This property contains a list of the point fields - + The list of point fields. - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqFoamReaderControls.cxx b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqFoamReaderControls.cxx new file mode 100644 index 0000000000..95c3002d74 --- /dev/null +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqFoamReaderControls.cxx @@ -0,0 +1,364 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "pqFoamReaderControls.h" + +#include +#include +#include +#include + +#include "pqApplicationCore.h" +#include "pqPipelineRepresentation.h" +#include "pqView.h" +#include "vtkSMDocumentation.h" +#include "vtkSMIntVectorProperty.h" +#include "vtkSMPropertyGroup.h" +#include "vtkSMSourceProxy.h" + + +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +// file-scope +static QAbstractButton* setButtonProperties +( + QAbstractButton* b, + vtkSMIntVectorProperty* prop, + bool initChecked = true +) +{ + QString tip; + + vtkSMDocumentation* doc = prop->GetDocumentation(); + if (doc) + { + const char* txt = doc->GetDescription(); + if (txt) + { + tip = QString(txt).simplified(); + } + } + + b->setText(prop->GetXMLLabel()); + if (tip.size()) + { + b->setToolTip(tip); + } + b->setFocusPolicy(Qt::NoFocus); // avoid dotted border + + // initial checked state + if (initChecked) + { + b->setChecked(prop->GetElement(0)); + } + + return b; +} + + +static vtkSMIntVectorProperty* lookupIntProp +( + vtkSMPropertyGroup* group, + const char* name +) +{ + vtkSMProperty* prop = group->GetProperty(name); + + if (prop) + { + return vtkSMIntVectorProperty::SafeDownCast(prop); + } + + return nullptr; +} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void pqFoamReaderControls::updatePartsStatus() +{ + vtkSMProperty* prop = this->proxy()->GetProperty("PartArrayStatus"); + if (prop) + { + this->proxy()->UpdatePropertyInformation(prop); + } +} + + +void pqFoamReaderControls::updatePartsStatus(bool) +{ + updatePartsStatus(); +} + + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +void pqFoamReaderControls::refreshPressed() +{ + // Update everything + refresh_->Modified(); + + vtkSMSourceProxy::SafeDownCast(this->proxy())->UpdatePipeline(); + + // Update all views + pqApplicationCore::instance()->render(); +} + + +void pqFoamReaderControls::cacheMesh(bool checked) +{ + cacheMesh_->SetElement(0, checked); +} + + +void pqFoamReaderControls::showPatchNames(bool checked) +{ + showPatchNames_->SetElement(0, checked); + + // update the active view + if (this->view()) + { + this->view()->render(); + } + // OR: update all views + // pqApplicationCore::instance()->render(); +} + + +void pqFoamReaderControls::showGroupsOnly(bool checked) +{ + showGroupsOnly_->SetElement(0, checked); + updatePartsStatus(); +} + + +void pqFoamReaderControls::includeSets(bool checked) +{ + includeSets_->SetElement(0, checked); + updatePartsStatus(); +} + + +void pqFoamReaderControls::includeZones(bool checked) +{ + includeZones_->SetElement(0, checked); + updatePartsStatus(); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +pqFoamReaderControls::pqFoamReaderControls +( + vtkSMProxy* proxy, + vtkSMPropertyGroup* group, + QWidget* parent +) +: + Superclass(proxy, parent), + refresh_(lookupIntProp(group, "Refresh")), + showPatchNames_(lookupIntProp(group, "ShowPatchNames")), + showGroupsOnly_(lookupIntProp(group, "ShowGroupsOnly")), + includeSets_(lookupIntProp(group, "IncludeSets")), + includeZones_(lookupIntProp(group, "IncludeZones")), + cacheMesh_(lookupIntProp(group, "CacheMesh")) +{ + typedef vtkSMIntVectorProperty intProp; + + QGridLayout* form = new QGridLayout(this); + + // ROW + // ~~~ + int row = 0; + + if (refresh_) + { + QPushButton* b = new QPushButton(this); + setButtonProperties(b, refresh_, false); + form->addWidget(b, row, 0, Qt::AlignLeft); + + connect(b, SIGNAL(clicked()), this, SLOT(refreshPressed())); + refresh_->SetImmediateUpdate(true); + } + + intProp* zeroTime = lookupIntProp(group, "ZeroTime"); + if (zeroTime) + { + QCheckBox* b = new QCheckBox(this); + setButtonProperties(b, zeroTime); + form->addWidget(b, row, 1, Qt::AlignLeft); + + addPropertyLink(b, "checked", SIGNAL(toggled(bool)), zeroTime); + } + + // LINE + // ~~~~ + ++row; + { + QFrame* hline = new QFrame(this); + hline->setFrameStyle(QFrame::HLine | QFrame::Sunken); + form->addWidget(hline, row, 0, 1, 4); + } + + // ROW + // ~~~ + ++row; + + if (includeSets_) + { + QCheckBox* b = new QCheckBox(this); + setButtonProperties(b, includeSets_); + form->addWidget(b, row, 0, Qt::AlignLeft); + + addPropertyLink(b, "checked", SIGNAL(toggled(bool)), includeSets_); + + connect(b, SIGNAL(toggled(bool)), this, SLOT(includeSets(bool))); + includeSets_->SetImmediateUpdate(true); + } + + if (showGroupsOnly_) + { + QCheckBox* b = new QCheckBox(this); + setButtonProperties(b, showGroupsOnly_); + form->addWidget(b, row, 1, Qt::AlignLeft); + + addPropertyLink(b, "checked", SIGNAL(toggled(bool)), showGroupsOnly_); + + connect(b, SIGNAL(toggled(bool)), this, SLOT(showGroupsOnly(bool))); + showGroupsOnly_->SetImmediateUpdate(true); + } + + + // ROW + // ~~~ + ++row; + + if (includeZones_) + { + QCheckBox* b = new QCheckBox(this); + setButtonProperties(b, includeZones_); + form->addWidget(b, row, 0, Qt::AlignLeft); + + addPropertyLink(b, "checked", SIGNAL(toggled(bool)), includeZones_); + + connect(b, SIGNAL(toggled(bool)), this, SLOT(includeZones(bool))); + includeZones_->SetImmediateUpdate(true); + } + + if (showPatchNames_) + { + QCheckBox* b = new QCheckBox(this); + setButtonProperties(b, showPatchNames_); + form->addWidget(b, row, 1, Qt::AlignLeft); + + connect(b, SIGNAL(toggled(bool)), this, SLOT(showPatchNames(bool))); + showPatchNames_->SetImmediateUpdate(true); + } + + // LINE + // ~~~~ + ++row; + { + QFrame* hline = new QFrame(this); + hline->setFrameStyle(QFrame::HLine | QFrame::Sunken); + form->addWidget(hline, row, 0, 1, 4); + } + + // ROW + // ~~~ + ++row; + + intProp* interpolate = lookupIntProp(group, "InterpolateFields"); + if (interpolate) + { + QCheckBox* b = new QCheckBox(this); + setButtonProperties(b, interpolate); + form->addWidget(b, row, 0, Qt::AlignLeft); + + addPropertyLink(b, "checked", SIGNAL(toggled(bool)), interpolate); + } + + intProp* extrapolate = lookupIntProp(group, "ExtrapolatePatches"); + if (extrapolate) + { + QCheckBox* b = new QCheckBox(this); + setButtonProperties(b, extrapolate); + form->addWidget(b, row, 1, Qt::AlignLeft); + + addPropertyLink(b, "checked", SIGNAL(toggled(bool)), extrapolate); + } + + // LINE + // ~~~~ + ++row; + { + QFrame* hline = new QFrame(this); + hline->setFrameStyle(QFrame::HLine | QFrame::Sunken); + form->addWidget(hline, row, 0, 1, 4); + } + + // ROW + // ~~~ + ++row; + + intProp* updateGui = lookupIntProp(group, "UpdateGUI"); + if (updateGui) + { + QPushButton* b = new QPushButton(this); + setButtonProperties(b, updateGui, false); + form->addWidget(b, row, 0, Qt::AlignLeft); + + addPropertyLink(b, "checked", SIGNAL(clicked()), updateGui); + } + + intProp* usePolyhedron = lookupIntProp(group, "UseVTKPolyhedron"); + if (usePolyhedron) + { + QCheckBox* b = new QCheckBox(this); + setButtonProperties(b, usePolyhedron); + form->addWidget(b, row, 1, Qt::AlignLeft); + + addPropertyLink(b, "checked", SIGNAL(toggled(bool)), usePolyhedron); + } + + if (cacheMesh_) + { + QCheckBox* b = new QCheckBox(this); + setButtonProperties(b, cacheMesh_); + form->addWidget(b, row, 2, Qt::AlignLeft); + + connect(b, SIGNAL(toggled(bool)), this, SLOT(cacheMesh(bool))); + cacheMesh_->SetImmediateUpdate(true); + } +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +pqFoamReaderControls::~pqFoamReaderControls() +{} + + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqFoamReaderControls.h b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqFoamReaderControls.h new file mode 100644 index 0000000000..dd958f5e8c --- /dev/null +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqFoamReaderControls.h @@ -0,0 +1,118 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + pqFoamReaderControls + +Description + A custom property group widget for the PVFoamReader. + +SourceFiles + pqFoamReaderControls.cxx + +\*---------------------------------------------------------------------------*/ +#ifndef pqFoamReaderControls_h +#define pqFoamReaderControls_h + +#include "pqPropertyWidget.h" + +// Forward declarations +class vtkSMIntVectorProperty; + + +/*---------------------------------------------------------------------------*\ + Class pqFoamReaderControls Declaration +\*---------------------------------------------------------------------------*/ + +class pqFoamReaderControls +: + public pqPropertyWidget +{ + Q_OBJECT; + typedef pqPropertyWidget Superclass; + + // Private data + + //- Refresh (bool property - as push button) + vtkSMIntVectorProperty* refresh_; + + //- Show Patch Names (bool property) + vtkSMIntVectorProperty* showPatchNames_; + + //- Show Groups Only (bool property) + vtkSMIntVectorProperty* showGroupsOnly_; + + //- IncludeSets (bool property) + vtkSMIntVectorProperty* includeSets_; + + //- IncludeZones (bool property) + vtkSMIntVectorProperty* includeZones_; + + //- CacheMesh (bool property) + vtkSMIntVectorProperty* cacheMesh_; + + +private slots: + + // Private Member Functions + + //- Update "PartArrayStatus" property information + void updatePartsStatus(); + + //- Update "PartArrayStatus" property information + void updatePartsStatus(bool unused); + + +protected slots: + + // Protected Member Functions + + void refreshPressed(); + void cacheMesh(bool checked); + void showPatchNames(bool checked); + void showGroupsOnly(bool checked); + void includeSets(bool checked); + void includeZones(bool checked); + + +public: + + //- Construct from components + pqFoamReaderControls + ( + vtkSMProxy* proxy, + vtkSMPropertyGroup* group, + QWidget* parent = nullptr + ); + + //- Destructor + virtual ~pqFoamReaderControls(); + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqPVFoamReaderPanel.cxx b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqPVFoamReaderPanel.cxx deleted file mode 100644 index 521068d409..0000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqPVFoamReaderPanel.cxx +++ /dev/null @@ -1,485 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -\*---------------------------------------------------------------------------*/ - -#include "pqPVFoamReaderPanel.h" - -// QT -#include -#include -#include -#include -#include -#include -#include - -// Paraview <-> QT UI -#include "pqAnimationScene.h" -#include "pqApplicationCore.h" -#include "pqPipelineRepresentation.h" -#include "pqServerManagerModel.h" -#include "pqView.h" - -// Paraview Server Manager -#include "vtkSMDoubleVectorProperty.h" -#include "vtkSMIntVectorProperty.h" -#include "vtkSMProperty.h" -#include "vtkSMSourceProxy.h" - - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -pqPVFoamReaderPanel::pqPVFoamReaderPanel -( - pqProxy *proxy, - QWidget *p -) -: - pqAutoGeneratedObjectPanel(proxy, p) -{ - // create first sublayout (at top of the panel) - QGridLayout* form = new QGridLayout(); - this->PanelLayout->addLayout(form, 0, 0, 1, -1); - - // ROW 0 - // ~~~~~ - - vtkSMProperty* prop = 0; - - // refresh button for updating times/fields - if ((prop = this->proxy()->GetProperty("UiRefresh")) != 0) - { - prop->SetImmediateUpdate(1); - QPushButton* refresh = new QPushButton("Refresh Times"); - refresh->setToolTip("Rescan for updated times/fields."); - - form->addWidget(refresh, 0, 0, Qt::AlignLeft); - QObject::connect - ( - refresh, - SIGNAL(clicked()), - this, - SLOT(RefreshPressed()) - ); - } - - // checkbox for skip zeroTime - if ((prop = this->proxy()->GetProperty("UiZeroTime")) != 0) - { - // immediate update on the Server Manager side - prop->SetImmediateUpdate(true); - - ZeroTime_ = new QCheckBox("Skip Zero Time"); - ZeroTime_->setChecked - ( - vtkSMIntVectorProperty::SafeDownCast(prop)->GetElement(0) - ); - ZeroTime_->setToolTip - ( - "Skip including the 0/ time directory." - ); - - form->addWidget(ZeroTime_, 0, 1, Qt::AlignLeft); - connect - ( - ZeroTime_, - SIGNAL(stateChanged(int)), - this, - SLOT(ZeroTimeToggled()) - ); - } - - // ROW 1 - // ~~~~~ - - QFrame* hline1 = new QFrame(this); - hline1->setFrameStyle(QFrame::HLine | QFrame::Sunken); - form->addWidget(hline1, 1, 0, 1, 3); - - // ROW 2 - // ~~~~~ - - // checkbox for caching mesh - if ((prop = this->proxy()->GetProperty("UiCacheMesh")) != 0) - { - // immediate update on the Server Manager side - prop->SetImmediateUpdate(true); - - CacheMesh_ = new QCheckBox("Cache Mesh"); - CacheMesh_->setChecked - ( - vtkSMIntVectorProperty::SafeDownCast(prop)->GetElement(0) - ); - CacheMesh_->setToolTip - ( - "Cache the fvMesh in memory." - ); - - form->addWidget(CacheMesh_, 2, 0, Qt::AlignLeft); - connect - ( - CacheMesh_, - SIGNAL(stateChanged(int)), - this, - SLOT(CacheMeshToggled()) - ); - } - - // cell 2,1 empty - - // ROW 3 - // ~~~~~ - - // checkbox for include sets - if ((prop = this->proxy()->GetProperty("UiIncludeSets")) != 0) - { - // immediate update on the Server Manager side - prop->SetImmediateUpdate(true); - - IncludeSets_ = new QCheckBox("Include Sets"); - IncludeSets_->setChecked - ( - vtkSMIntVectorProperty::SafeDownCast(prop)->GetElement(0) - ); - IncludeSets_->setToolTip - ( - "Search the polyMesh/sets/ directory." - ); - - // row/col 1,0 - form->addWidget(IncludeSets_, 3, 0, Qt::AlignLeft); - connect - ( - IncludeSets_, - SIGNAL(stateChanged(int)), - this, - SLOT(IncludeSetsToggled()) - ); - } - - // checkbox for Groups Only - if ((prop = this->proxy()->GetProperty("UiShowGroupsOnly")) != 0) - { - // immediate update on the Server Manager side - prop->SetImmediateUpdate(true); - - ShowGroupsOnly_ = new QCheckBox("Groups Only"); - ShowGroupsOnly_->setChecked - ( - vtkSMIntVectorProperty::SafeDownCast(prop)->GetElement(0) - ); - ShowGroupsOnly_->setToolTip - ( - "Show patchGroups only." - ); - - // row/col 2, 2 - form->addWidget(ShowGroupsOnly_, 3, 1, Qt::AlignLeft); - connect - ( - ShowGroupsOnly_, - SIGNAL(stateChanged(int)), - this, - SLOT(ShowGroupsOnlyToggled()) - ); - } - - - // ROW 4 - // ~~~~~ - - // checkbox for include zones - if ((prop = this->proxy()->GetProperty("UiIncludeZones")) != 0) - { - // immediate update on the Server Manager side - prop->SetImmediateUpdate(true); - - IncludeZones_ = new QCheckBox("Include Zones"); - IncludeZones_->setChecked - ( - vtkSMIntVectorProperty::SafeDownCast(prop)->GetElement(0) - ); - IncludeZones_->setToolTip - ( - "ZoneMesh information is used to find {cell,face,point}Zones. " - "The polyMesh/ directory is only checked on startup." - ); - - // row/col 1,1 - form->addWidget(IncludeZones_, 4, 0, Qt::AlignLeft); - connect - ( - IncludeZones_, - SIGNAL(stateChanged(int)), - this, - SLOT(IncludeZonesToggled()) - ); - } - - // checkbox for patch names - if ((prop = this->proxy()->GetProperty("UiShowPatchNames")) != 0) - { - // immediate update on the Server Manager side - prop->SetImmediateUpdate(true); - - ShowPatchNames_ = new QCheckBox("Patch Names"); - ShowPatchNames_->setChecked - ( - vtkSMIntVectorProperty::SafeDownCast(prop)->GetElement(0) - ); - ShowPatchNames_->setToolTip - ( - "Show patch names in render window." - ); - - // row/col 0,1 - form->addWidget(ShowPatchNames_, 4, 1, Qt::AlignLeft); - connect - ( - ShowPatchNames_, - SIGNAL(stateChanged(int)), - this, - SLOT(ShowPatchNamesToggled()) - ); - } - - // ROW 5 - // ~~~~~ - - QFrame* hline2 = new QFrame(this); - hline2->setFrameStyle(QFrame::HLine | QFrame::Sunken); - form->addWidget(hline2, 5, 0, 1, 3); - - // ROW 6 - // ~~~~~ - - // checkbox for vol field interpolation - if ((prop = this->proxy()->GetProperty("UiInterpolateVolFields")) != 0) - { - // immediate update on the Server Manager side - prop->SetImmediateUpdate(true); - - InterpolateVolFields_ = new QCheckBox("Interpolate volFields"); - InterpolateVolFields_->setChecked - ( - vtkSMIntVectorProperty::SafeDownCast(prop)->GetElement(0) - ); - InterpolateVolFields_->setToolTip - ( - "Interpolate volFields into pointFields" - ); - - // row/col 1,1 - form->addWidget(InterpolateVolFields_, 6, 0, Qt::AlignLeft); - connect - ( - InterpolateVolFields_, - SIGNAL(stateChanged(int)), - this, - SLOT(InterpolateVolFieldsToggled()) - ); - } - - // checkbox for extrapolate patches - if ((prop = this->proxy()->GetProperty("UiExtrapolatePatches")) != 0) - { - // immediate update on the Server Manager side - prop->SetImmediateUpdate(true); - - ExtrapolatePatches_ = new QCheckBox("Extrapolate Patches"); - ExtrapolatePatches_->setChecked - ( - vtkSMIntVectorProperty::SafeDownCast(prop)->GetElement(0) - ); - ExtrapolatePatches_->setToolTip - ( - "Extrapolate internalField to non-constraint patches" - ); - - // row/col 1,1 - form->addWidget(ExtrapolatePatches_, 6, 1, Qt::AlignLeft); - connect - ( - ExtrapolatePatches_, - SIGNAL(stateChanged(int)), - this, - SLOT(ExtrapolatePatchesToggled()) - ); - } - - // ROW 7 - // ~~~~~ - - QFrame* hline3 = new QFrame(this); - hline3->setFrameStyle(QFrame::HLine | QFrame::Sunken); - form->addWidget(hline3, 7, 0, 1, 3); - - // update GUI button - if ((prop = this->proxy()->GetProperty("UpdateGUI")) != 0) - { - prop->SetImmediateUpdate(1); - QPushButton* updateGUI = new QPushButton("Update GUI"); - updateGUI->setToolTip("Update GUI"); - - form->addWidget(updateGUI, 8, 0, Qt::AlignLeft); - QObject::connect - ( - updateGUI, - SIGNAL(clicked()), - this, - SLOT(setModified()) - ); - } -} - - -// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // - -void pqPVFoamReaderPanel::CacheMeshToggled() -{ - vtkSMIntVectorProperty::SafeDownCast - ( - this->proxy()->GetProperty("UiCacheMesh") - )->SetElement(0, CacheMesh_->isChecked()); -} - - -void pqPVFoamReaderPanel::RefreshPressed() -{ - // update everything - vtkSMIntVectorProperty::SafeDownCast - ( - this->proxy()->GetProperty("UiRefresh") - )->Modified(); - - vtkSMSourceProxy::SafeDownCast(this->proxy())->UpdatePipeline(); - - // render all views - pqApplicationCore::instance()->render(); -} - - -void pqPVFoamReaderPanel::ZeroTimeToggled() -{ - vtkSMIntVectorProperty::SafeDownCast - ( - this->proxy()->GetProperty("UiZeroTime") - )->SetElement(0, ZeroTime_->isChecked()); - - this->setModified(); -} - - -void pqPVFoamReaderPanel::ShowPatchNamesToggled() -{ - vtkSMIntVectorProperty::SafeDownCast - ( - this->proxy()->GetProperty("UiShowPatchNames") - )->SetElement(0, ShowPatchNames_->isChecked()); - - // update the active view - if (this->view()) - { - this->view()->render(); - } - // OR: update all views - // pqApplicationCore::instance()->render(); -} - - -void pqPVFoamReaderPanel::ShowGroupsOnlyToggled() -{ - vtkSMProperty* prop; - - vtkSMIntVectorProperty::SafeDownCast - ( - this->proxy()->GetProperty("UiShowGroupsOnly") - )->SetElement(0, ShowGroupsOnly_->isChecked()); - - if ((prop = this->proxy()->GetProperty("PartArrayStatus")) != 0) - { - this->proxy()->UpdatePropertyInformation(prop); - } -} - - -void pqPVFoamReaderPanel::IncludeSetsToggled() -{ - vtkSMProperty* prop; - - vtkSMIntVectorProperty::SafeDownCast - ( - this->proxy()->GetProperty("UiIncludeSets") - )->SetElement(0, IncludeSets_->isChecked()); - - if ((prop = this->proxy()->GetProperty("PartArrayStatus")) != 0) - { - this->proxy()->UpdatePropertyInformation(prop); - } -} - - -void pqPVFoamReaderPanel::IncludeZonesToggled() -{ - vtkSMProperty* prop; - - vtkSMIntVectorProperty::SafeDownCast - ( - this->proxy()->GetProperty("UiIncludeZones") - )->SetElement(0, IncludeZones_->isChecked()); - - if ((prop = this->proxy()->GetProperty("PartArrayStatus")) != 0) - { - this->proxy()->UpdatePropertyInformation(prop); - } -} - - -void pqPVFoamReaderPanel::ExtrapolatePatchesToggled() -{ - vtkSMProperty* prop; - - vtkSMIntVectorProperty::SafeDownCast - ( - this->proxy()->GetProperty("UiExtrapolatePatches") - )->SetElement(0, ExtrapolatePatches_->isChecked()); - - this->setModified(); -} - - -void pqPVFoamReaderPanel::InterpolateVolFieldsToggled() -{ - vtkSMProperty* prop; - - vtkSMIntVectorProperty::SafeDownCast - ( - this->proxy()->GetProperty("UiInterpolateVolFields") - )->SetElement(0, InterpolateVolFields_->isChecked()); - - this->setModified(); -} - - -// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqPVFoamReaderPanel.h b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqPVFoamReaderPanel.h deleted file mode 100644 index 6ca0f3f7a5..0000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqPVFoamReaderPanel.h +++ /dev/null @@ -1,116 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -Class - pqPVFoamReaderPanel - -Description - GUI modifications for the ParaView reader panel - - A custom panel for the PVFoamReader. - -SourceFiles - pqPVFoamReaderPanel.cxx - -\*---------------------------------------------------------------------------*/ -#ifndef pqPVFoamReaderPanel_h -#define pqPVFoamReaderPanel_h - - -#include "pqAutoGeneratedObjectPanel.h" - -// Forward declaration of QT classes - -class QCheckBox; -class QLineEdit; -class QTimer; -class QToolButton; - -// Forward declaration of ParaView classes -class vtkSMSourceProxy; - - -/*---------------------------------------------------------------------------*\ - Class pqPVFoamReaderPanel Declaration -\*---------------------------------------------------------------------------*/ - -class pqPVFoamReaderPanel -: - public pqAutoGeneratedObjectPanel -{ - // Private data - Q_OBJECT; - typedef pqAutoGeneratedObjectPanel Superclass; - - //- ZeroTime checkbox - QCheckBox* ZeroTime_; - - //- CacheMesh checkbox - QCheckBox* CacheMesh_; - - //- Show Patch Names checkbox - QCheckBox* ShowPatchNames_; - - //- Show Groups Only checkbox - QCheckBox* ShowGroupsOnly_; - - //- IncludeSets checkbox - QCheckBox* IncludeSets_; - - //- IncludeZones checkbox - QCheckBox* IncludeZones_; - - //- InterpolateVolFields checkbox - QCheckBox* InterpolateVolFields_; - - //- ExtrapolatePatches checkbox - QCheckBox* ExtrapolatePatches_; - - -protected slots: - - void CacheMeshToggled(); - void ZeroTimeToggled(); - void RefreshPressed(); - void ShowPatchNamesToggled(); - void ShowGroupsOnlyToggled(); - void IncludeSetsToggled(); - void IncludeZonesToggled(); - void InterpolateVolFieldsToggled(); - void ExtrapolatePatchesToggled(); - - -public: - - // Constructors - - //- Construct from components - pqPVFoamReaderPanel(pqProxy*, QWidget*); -}; - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.cxx b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.cxx index 6b539c5a68..d8af0bfea7 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.cxx +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.cxx @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -76,19 +76,19 @@ vtkPVFoamReader::vtkPVFoamReader() TimeStepRange[0] = 0; TimeStepRange[1] = 0; - CacheMesh = 1; - Refresh = 0; + CacheMesh = true; + Refresh = false; - SkipZeroTime = 0; - ExtrapolatePatches = 0; - UseVTKPolyhedron = 0; - IncludeSets = 0; - IncludeZones = 0; - ShowPatchNames = 0; - ShowGroupsOnly = 0; - InterpolateVolFields = 1; + SkipZeroTime = false; + ExtrapolatePatches = false; + UseVTKPolyhedron = false; + IncludeSets = false; + IncludeZones = false; + ShowPatchNames = false; + ShowGroupsOnly = false; + InterpolateVolFields = true; - UpdateGUI = 0; + UpdateGUI = false; PartSelection = vtkDataArraySelection::New(); VolFieldSelection = vtkDataArraySelection::New(); @@ -151,10 +151,10 @@ vtkPVFoamReader::~vtkPVFoamReader() } - PartSelection->RemoveObserver(this->SelectionObserver); - VolFieldSelection->RemoveObserver(this->SelectionObserver); - PointFieldSelection->RemoveObserver(this->SelectionObserver); - LagrangianFieldSelection->RemoveObserver(this->SelectionObserver); + PartSelection->RemoveAllObservers(); + VolFieldSelection->RemoveAllObservers(); + PointFieldSelection->RemoveAllObservers(); + LagrangianFieldSelection->RemoveAllObservers(); SelectionObserver->Delete(); @@ -417,13 +417,13 @@ int vtkPVFoamReader::RequestData } -void vtkPVFoamReader::SetRefresh(int val) +void vtkPVFoamReader::SetRefresh(bool val) { Modified(); } -void vtkPVFoamReader::SetIncludeSets(int val) +void vtkPVFoamReader::SetIncludeSets(bool val) { if (IncludeSets != val) { @@ -436,7 +436,7 @@ void vtkPVFoamReader::SetIncludeSets(int val) } -void vtkPVFoamReader::SetIncludeZones(int val) +void vtkPVFoamReader::SetIncludeZones(bool val) { if (IncludeZones != val) { @@ -449,7 +449,7 @@ void vtkPVFoamReader::SetIncludeZones(int val) } -void vtkPVFoamReader::SetShowPatchNames(int val) +void vtkPVFoamReader::SetShowPatchNames(bool val) { if (ShowPatchNames != val) { @@ -459,7 +459,7 @@ void vtkPVFoamReader::SetShowPatchNames(int val) } -void vtkPVFoamReader::SetShowGroupsOnly(int val) +void vtkPVFoamReader::SetShowGroupsOnly(bool val) { if (ShowGroupsOnly != val) { @@ -502,7 +502,7 @@ void vtkPVFoamReader::updatePatchNamesView(const bool show) ); } - // use refresh here? + // Use refresh here? } diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.h b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.h index d29b80e1ff..74aeedda34 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.h +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.h @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -79,57 +79,57 @@ public: // Description: // OpenFOAM mesh caching control - vtkSetMacro(CacheMesh, int); - vtkGetMacro(CacheMesh, int); + vtkSetMacro(CacheMesh, bool); + vtkGetMacro(CacheMesh, bool); // Description: // OpenFOAM refresh times/fields - virtual void SetRefresh(int); + virtual void SetRefresh(bool); // Description: // OpenFOAM skip/include the 0/ time directory - vtkSetMacro(SkipZeroTime, int); - vtkGetMacro(SkipZeroTime, int); + vtkSetMacro(SkipZeroTime, bool); + vtkGetMacro(SkipZeroTime, bool); // Description: // GUI update control - vtkSetMacro(UpdateGUI, int); - vtkGetMacro(UpdateGUI, int); + vtkSetMacro(UpdateGUI, bool); + vtkGetMacro(UpdateGUI, bool); // Description: // OpenFOAM extrapolate internal values onto the patches - vtkSetMacro(ExtrapolatePatches, int); - vtkGetMacro(ExtrapolatePatches, int); + vtkSetMacro(ExtrapolatePatches, bool); + vtkGetMacro(ExtrapolatePatches, bool); // Description: // OpenFOAM use vtkPolyhedron instead of decomposing polyhedra - vtkSetMacro(UseVTKPolyhedron, int); - vtkGetMacro(UseVTKPolyhedron, int); + vtkSetMacro(UseVTKPolyhedron, bool); + vtkGetMacro(UseVTKPolyhedron, bool); // Description: // OpenFOAM read sets control - virtual void SetIncludeSets(int); - vtkGetMacro(IncludeSets, int); + virtual void SetIncludeSets(bool); + vtkGetMacro(IncludeSets, bool); // Description: // OpenFOAM read zones control - virtual void SetIncludeZones(int); - vtkGetMacro(IncludeZones, int); + virtual void SetIncludeZones(bool); + vtkGetMacro(IncludeZones, bool); // Description: // OpenFOAM display patch names control - virtual void SetShowPatchNames(int); - vtkGetMacro(ShowPatchNames, int); + virtual void SetShowPatchNames(bool); + vtkGetMacro(ShowPatchNames, bool); // Description: // OpenFOAM display patchGroups - virtual void SetShowGroupsOnly(int); - vtkGetMacro(ShowGroupsOnly, int); + virtual void SetShowGroupsOnly(bool); + vtkGetMacro(ShowGroupsOnly, bool); // Description: // OpenFOAM volField interpolation - vtkSetMacro(InterpolateVolFields, int); - vtkGetMacro(InterpolateVolFields, int); + vtkSetMacro(InterpolateVolFields, bool); + vtkGetMacro(InterpolateVolFields, bool); // Description: // Get the current timestep @@ -218,29 +218,29 @@ protected: private: //- Disallow default bitwise copy construct - vtkPVFoamReader(const vtkPVFoamReader&); + vtkPVFoamReader(const vtkPVFoamReader&) = delete; //- Disallow default bitwise assignment - void operator=(const vtkPVFoamReader&); + void operator=(const vtkPVFoamReader&) = delete; //- Add/remove patch names to/from the view void updatePatchNamesView(const bool show); int TimeStepRange[2]; - int Refresh; - int CacheMesh; - int SkipZeroTime; + bool Refresh; + bool CacheMesh; + bool SkipZeroTime; - int ExtrapolatePatches; - int UseVTKPolyhedron; - int IncludeSets; - int IncludeZones; - int ShowPatchNames; - int ShowGroupsOnly; - int InterpolateVolFields; + bool ExtrapolatePatches; + bool UseVTKPolyhedron; + bool IncludeSets; + bool IncludeZones; + bool ShowPatchNames; + bool ShowGroupsOnly; + bool InterpolateVolFields; //- Dummy variable/switch to invoke a reader update - int UpdateGUI; + bool UpdateGUI; vtkDataArraySelection* PartSelection; vtkDataArraySelection* VolFieldSelection; @@ -250,9 +250,7 @@ private: //- Cached data for output port0 (experimental!) vtkMultiBlockDataSet* output0_; - //BTX Foam::vtkPVFoam* foamData_; - //ETX }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.H b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.H index 5fb4b0b0d8..fb3a988b86 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.H +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.H @@ -56,11 +56,6 @@ SourceFiles #ifndef vtkPVFoam_H #define vtkPVFoam_H -// do not include legacy strstream headers -#ifndef VTK_EXCLUDE_STRSTREAM_HEADERS -# define VTK_EXCLUDE_STRSTREAM_HEADERS -#endif - #include "className.H" #include "fileName.H" #include "stringList.H" diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVReaders/vtkPVReaders.H b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVReaders/vtkPVReaders.H index 958668105f..200939c315 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVReaders/vtkPVReaders.H +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVReaders/vtkPVReaders.H @@ -36,11 +36,6 @@ SourceFiles #ifndef vtkPVReaders_H #define vtkPVReaders_H -// do not include legacy strstream headers -#ifndef VTK_EXCLUDE_STRSTREAM_HEADERS -# define VTK_EXCLUDE_STRSTREAM_HEADERS -#endif - #include "className.H" #include "fileName.H" #include "stringList.H" From 7a90f5e6fbc31009ad47402cdef576324d6193c9 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 5 Jan 2017 16:22:07 +0100 Subject: [PATCH 05/35] ENH: add versioning to paraview plugin support libraries (issue #370) - use "-pvMAJ.MIN" suffix for similarity with the paraview convention - use sentinel file to ensure clean change of intermediate targets - ensure all library files are being properly removed --- .../graphics/PVReaders/Allwmake | 56 ++++++++++++++++- .../graphics/PVReaders/PVFoamReader/Allwclean | 8 +-- .../graphics/PVReaders/PVFoamReader/Allwmake | 63 +++++++++++++++++-- .../PVFoamReader/PVFoamReader/CMakeLists.txt | 2 +- .../PVFoamReader/vtkPVFoam/Make/files | 2 +- .../PVFoamReader/vtkPVFoam/Make/options | 4 +- .../PVReaders/PVblockMeshReader/Allwclean | 8 +-- .../PVReaders/PVblockMeshReader/Allwmake | 63 +++++++++++++++++-- .../PVblockMeshReader/CMakeLists.txt | 2 +- .../vtkPVblockMesh/Make/files | 2 +- .../vtkPVblockMesh/Make/options | 4 +- .../PVReaders/vtkPVReaders/Make/files | 2 +- .../PVReaders/vtkPVReaders/Make/options | 2 + .../graphics/runTimePostProcessing/Allwclean | 9 ++- .../graphics/runTimePostProcessing/Allwmake | 61 ++++++++++++++++-- wmake/rules/General/paraview | 8 +++ 16 files changed, 260 insertions(+), 36 deletions(-) create mode 100644 wmake/rules/General/paraview diff --git a/applications/utilities/postProcessing/graphics/PVReaders/Allwmake b/applications/utilities/postProcessing/graphics/PVReaders/Allwmake index df34613a03..c6ca055da0 100755 --- a/applications/utilities/postProcessing/graphics/PVReaders/Allwmake +++ b/applications/utilities/postProcessing/graphics/PVReaders/Allwmake @@ -7,6 +7,11 @@ export WM_CONTINUE_ON_ERROR=true # Parse arguments for library compilation . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments +# Source the wmake functions +. $WM_PROJECT_DIR/wmake/scripts/wmakeFunctions + +# ----------------------------------------------------------------------------- + # # There are several prerequisites for building plugins # @@ -34,6 +39,53 @@ canBuildPlugin() } +# +# Check sentinel file(s) to handle paraview version changes +# +versionOk() +{ + findObjectDir "$1" # Where generated files are stored + local sentinel="$objectsDir/ThirdParty" + + echo $sentinel + + local prev + if read -r prev 2>/dev/null < $sentinel + then + case "$prev" in + ("ParaView_DIR=$ParaView_DIR") + return 0 + ;; + (*) + echo "ParaView_DIR changed between builds" 1>&2 + return 1 + ;; + esac + elif [ -f "$objectsDir/CMakeCache.txt" ] + then + echo "previous build was incomplete" 1>&2 + return 1 + else + return 0 + fi +} + + +# +# Build library - use sentinel file(s) to handle paraview version changes +# +wmakeLibPv() +{ + for libName + do + sentinel=$(versionOk $libName) || wclean $libName # version changed + wmake $targetType $libName && { + echo "ParaView_DIR=$ParaView_DIR" > $sentinel + } + done +} + + # ----------------------------------------------------------------------------- # major version as per paraview include directory: @@ -45,9 +97,9 @@ case "$major" in if canBuildPlugin then ( - wmake $targetType vtkPVReaders + wmakeLibPv vtkPVReaders PVblockMeshReader/Allwmake $targetType $* - PVFoamReader/Allwmake $targetType $* + PVFoamReader/Allwmake $targetType $* # Dummy directory to trigger proper 'wclean all' behaviour # - the Allwclean will otherwise not be used diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/Allwclean b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/Allwclean index f0cd56dee2..4df5195cb1 100755 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/Allwclean +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/Allwclean @@ -2,17 +2,15 @@ cd ${0%/*} || exit 1 # Run from this directory # Source the wmake functions -. $WM_DIR/scripts/wmakeFunctions +. $WM_PROJECT_DIR/wmake/scripts/wmakeFunctions -#set -x - -# deal with client/server vs combined plugins +# Cleanup client-server and/or combined plugins rm -f $FOAM_LIBBIN/libPVFoamReader* 2>/dev/null rm -rf PVFoamReader/Make # safety: old build location wclean libso vtkPVFoam -# Where are the generated files stored? +# Cleanup generated files findObjectDir $PWD # remove entire top-level rm -rf "$objectsDir" > /dev/null 2>&1 diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/Allwmake b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/Allwmake index 7788998933..afba137322 100755 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/Allwmake +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/Allwmake @@ -5,20 +5,56 @@ cd ${0%/*} || exit 1 # Run from this directory . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments # Source the wmake functions -. $WM_DIR/scripts/wmakeFunctions +. $WM_PROJECT_DIR/wmake/scripts/wmakeFunctions # Ensure CMake gets the correct C/C++ compilers [ -n "$WM_CC" ] && export CC="$WM_CC" [ -n "$WM_CXX" ] && export CXX="$WM_CXX" +# ----------------------------------------------------------------------------- + +# +# Check sentinel file(s) to handle paraview version changes +# +versionOk() +{ + findObjectDir "$1" # Where generated files are stored + local sentinel="$objectsDir/ThirdParty" + + echo $sentinel + + local prev + if read -r prev 2>/dev/null < $sentinel + then + case "$prev" in + ("ParaView_DIR=$ParaView_DIR") + return 0 + ;; + (*) + echo "ParaView_DIR changed between builds" 1>&2 + return 1 + ;; + esac + elif [ -f "$objectsDir/CMakeCache.txt" ] + then + echo "previous build was incomplete" 1>&2 + return 1 + else + return 0 + fi +} + # CMake into objectsDir, # with an additional attempt if (possibly incorrect) CMakeCache.txt existed doCmake() { local sourceDir="$1" - findObjectDir $sourceDir # Where are generated files stored? + + # version changed + sentinel=$(versionOk $sourceDir) || rm -rf "$objectsDir" > /dev/null 2>&1 + test -f "$objectsDir/CMakeCache.txt" retry=$? # CMakeCache.txt exists, but sources may have moved @@ -35,14 +71,33 @@ doCmake() else exit 1 fi - } && make + } && make && { + echo "ParaView_DIR=$ParaView_DIR" > $sentinel + } ) } +# +# Build library - use sentinel file(s) to handle paraview version changes +# +wmakeLibPv() +{ + for libName + do + sentinel=$(versionOk $libName) || wclean $libName # version changed + wmake $targetType $libName && { + echo "ParaView_DIR=$ParaView_DIR" > $sentinel + } + done +} + + +# ----------------------------------------------------------------------------- + if [ -d "$ParaView_DIR" ] then - wmake $targetType vtkPVFoam + wmakeLibPv vtkPVFoam if [ "$targetType" != objects ] then diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/CMakeLists.txt b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/CMakeLists.txt index 6671a5d179..40745ba928 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/CMakeLists.txt +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/CMakeLists.txt @@ -62,7 +62,7 @@ add_paraview_plugin( target_link_libraries( PVFoamReader_SM LINK_PUBLIC - vtkPVFoam + vtkPVFoam-pv${PARAVIEW_VERSION_MAJOR}.${PARAVIEW_VERSION_MINOR} finiteVolume OpenFOAM ) diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/files b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/files index b26829761d..6f9412f0af 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/files +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/files @@ -8,4 +8,4 @@ vtkPVFoamMeshZone.C vtkPVFoamUpdateInfo.C vtkPVFoamUtils.C -LIB = $(FOAM_LIBBIN)/libvtkPVFoam +LIB = $(FOAM_LIBBIN)/libvtkPVFoam-pv${ParaView_MAJOR} diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/options b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/options index 0154a3bcba..aa2b9039da 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/options +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/options @@ -1,3 +1,5 @@ +sinclude $(GENERAL_RULES)/paraview + EXE_INC = \ ${c++LESSWARN} \ -I$(LIB_SRC)/meshTools/lnInclude \ @@ -16,5 +18,5 @@ LIB_LIBS = \ -lconversion \ -lgenericPatchFields \ -llagrangian \ - -L$(FOAM_LIBBIN) -lvtkPVReaders \ + -L$(FOAM_LIBBIN) -lvtkPVReaders-pv${ParaView_MAJOR} \ $(GLIBS) diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/Allwclean b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/Allwclean index 3a81901a0b..8e0fd1a41a 100755 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/Allwclean +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/Allwclean @@ -2,17 +2,15 @@ cd ${0%/*} || exit 1 # Run from this directory # Source the wmake functions -. $WM_DIR/scripts/wmakeFunctions +. $WM_PROJECT_DIR/wmake/scripts/wmakeFunctions -#set -x - -# deal with client/server vs combined plugins +# Cleanup client-server and/or combined plugins rm -f $FOAM_LIBBIN/libPVblockMeshReader* 2>/dev/null rm -rf PVblockMeshReader/Make # safety: old build location wclean libso vtkPVblockMesh -# Where are the generated files stored? +# Cleanup generated files findObjectDir $PWD # remove entire top-level rm -rf "$objectsDir" > /dev/null 2>&1 diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/Allwmake b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/Allwmake index 607a6cb8e3..844b129306 100755 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/Allwmake +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/Allwmake @@ -5,20 +5,56 @@ cd ${0%/*} || exit 1 # Run from this directory . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments # Source the wmake functions -. $WM_DIR/scripts/wmakeFunctions +. $WM_PROJECT_DIR/wmake/scripts/wmakeFunctions # Ensure CMake gets the correct C/C++ compilers [ -n "$WM_CC" ] && export CC="$WM_CC" [ -n "$WM_CXX" ] && export CXX="$WM_CXX" +# ----------------------------------------------------------------------------- + +# +# Check sentinel file(s) to handle paraview version changes +# +versionOk() +{ + findObjectDir "$1" # Where generated files are stored + local sentinel="$objectsDir/ThirdParty" + + echo $sentinel + + local prev + if read -r prev 2>/dev/null < $sentinel + then + case "$prev" in + ("ParaView_DIR=$ParaView_DIR") + return 0 + ;; + (*) + echo "ParaView_DIR changed between builds" 1>&2 + return 1 + ;; + esac + elif [ -f "$objectsDir/CMakeCache.txt" ] + then + echo "previous build was incomplete" 1>&2 + return 1 + else + return 0 + fi +} + # CMake into objectsDir, # with an additional attempt if (possibly incorrect) CMakeCache.txt existed doCmake() { local sourceDir="$1" - findObjectDir $sourceDir # Where are generated files stored? + + # version changed + sentinel=$(versionOk $sourceDir) || rm -rf "$objectsDir" > /dev/null 2>&1 + test -f "$objectsDir/CMakeCache.txt" retry=$? # CMakeCache.txt exists, but sources may have moved @@ -35,14 +71,33 @@ doCmake() else exit 1 fi - } && make + } && make && { + echo "ParaView_DIR=$ParaView_DIR" > $sentinel + } ) } +# +# Build library - use sentinel file(s) to handle paraview version changes +# +wmakeLibPv() +{ + for libName + do + sentinel=$(versionOk $libName) || wclean $libName # version changed + wmake $targetType $libName && { + echo "ParaView_DIR=$ParaView_DIR" > $sentinel + } + done +} + + +# ----------------------------------------------------------------------------- + if [ -d "$ParaView_DIR" ] then - wmake $targetType vtkPVblockMesh + wmakeLibPv vtkPVblockMesh if [ "$targetType" != objects ] then diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/CMakeLists.txt b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/CMakeLists.txt index 0ee611b0ed..6e75664790 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/CMakeLists.txt +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/CMakeLists.txt @@ -62,7 +62,7 @@ add_paraview_plugin( target_link_libraries( PVblockMeshReader_SM LINK_PUBLIC - vtkPVblockMesh + vtkPVblockMesh-pv${PARAVIEW_VERSION_MAJOR}.${PARAVIEW_VERSION_MINOR} blockMesh OpenFOAM ) diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/Make/files b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/Make/files index e6e4fb230e..b3a5e2fdf8 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/Make/files +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/Make/files @@ -2,4 +2,4 @@ vtkPVblockMesh.C vtkPVblockMeshConvert.C vtkPVblockMeshUtils.C -LIB = $(FOAM_LIBBIN)/libvtkPVblockMesh +LIB = $(FOAM_LIBBIN)/libvtkPVblockMesh-pv${ParaView_MAJOR} diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/Make/options b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/Make/options index 79abf2d7fc..f8fc1e5877 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/Make/options +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/Make/options @@ -1,3 +1,5 @@ +sinclude $(GENERAL_RULES)/paraview + EXE_INC = \ ${c++LESSWARN} \ -I$(LIB_SRC)/meshTools/lnInclude \ @@ -12,5 +14,5 @@ LIB_LIBS = \ -lmeshTools \ -lfileFormats \ -lblockMesh \ - -L$(FOAM_LIBBIN) -lvtkPVReaders \ + -L$(FOAM_LIBBIN) -lvtkPVReaders-pv${ParaView_MAJOR} \ $(GLIBS) diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVReaders/Make/files b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVReaders/Make/files index e26a8c4979..bce3910d9d 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVReaders/Make/files +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVReaders/Make/files @@ -1,3 +1,3 @@ vtkPVReaders.C -LIB = $(FOAM_LIBBIN)/libvtkPVReaders +LIB = $(FOAM_LIBBIN)/libvtkPVReaders-pv${ParaView_MAJOR} diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVReaders/Make/options b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVReaders/Make/options index d84fae1560..39510d9f57 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVReaders/Make/options +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVReaders/Make/options @@ -1,3 +1,5 @@ +sinclude $(GENERAL_RULES)/paraview + EXE_INC = \ ${c++LESSWARN} \ -I$(ParaView_INCLUDE_DIR) \ diff --git a/src/functionObjects/graphics/runTimePostProcessing/Allwclean b/src/functionObjects/graphics/runTimePostProcessing/Allwclean index 1d94a698c5..00ff12fadb 100755 --- a/src/functionObjects/graphics/runTimePostProcessing/Allwclean +++ b/src/functionObjects/graphics/runTimePostProcessing/Allwclean @@ -2,10 +2,13 @@ cd ${0%/*} || exit 1 # Run from this directory # Source the wmake functions -. $WM_DIR/scripts/wmakeFunctions +. $WM_PROJECT_DIR/wmake/scripts/wmakeFunctions -# Where are the generated files stored? -findObjectDir $PWD +# Cleanup library +rm -f $FOAM_LIBBIN/librunTimePostProcessing* 2>/dev/null + +# Cleanup generated files +findObjectDir $PWD # remove entire top-level rm -rf "$objectsDir" > /dev/null 2>&1 #------------------------------------------------------------------------------ diff --git a/src/functionObjects/graphics/runTimePostProcessing/Allwmake b/src/functionObjects/graphics/runTimePostProcessing/Allwmake index 4b2ad8b107..66ba0b7cc1 100755 --- a/src/functionObjects/graphics/runTimePostProcessing/Allwmake +++ b/src/functionObjects/graphics/runTimePostProcessing/Allwmake @@ -2,23 +2,56 @@ cd ${0%/*} || exit 1 # Run from this directory # Source the wmake functions -. $WM_DIR/scripts/wmakeFunctions +. $WM_PROJECT_DIR/wmake/scripts/wmakeFunctions # Ensure CMake gets the correct C/C++ compilers [ -n "$WM_CC" ] && export CC="$WM_CC" [ -n "$WM_CXX" ] && export CXX="$WM_CXX" -echo "======================================================================" -echo "${PWD##*/} : $PWD" -echo +# ----------------------------------------------------------------------------- + +# +# Check sentinel file(s) to handle vtk/paraview version changes +# +versionOk() +{ + findObjectDir "$1" # Where generated files are stored + local sentinel="$objectsDir/ThirdParty" + + echo $sentinel + + local prev + if read -r prev 2>/dev/null < $sentinel + then + case "$prev" in + ("ParaView_DIR=$ParaView_DIR" | "VTK_DIR=$VTK_DIR") + return 0 + ;; + (*) + echo "ParaView_DIR or VTK_DIR changed between builds" 1>&2 + return 1 + ;; + esac + elif [ -f "$objectsDir/CMakeCache.txt" ] + then + echo "previous build was incomplete" 1>&2 + return 1 + else + return 0 + fi +} + # CMake into objectsDir, # with an additional attempt if (possibly incorrect) CMakeCache.txt existed doCmake() { local sourceDir="$1" - findObjectDir $sourceDir # Where are generated files stored? + + # version changed + sentinel=$(versionOk $sourceDir) || rm -rf "$objectsDir" > /dev/null 2>&1 + test -f "$objectsDir/CMakeCache.txt" retry=$? # CMakeCache.txt exists, but sources may have moved @@ -35,11 +68,27 @@ doCmake() else exit 1 fi - } && make + } && make && { + if [ -d "$VTK_DIR" ] + then + echo "VTK_DIR=$VTK_DIR" + elif [ -d "$ParaView_DIR" ] + then + echo "ParaView_DIR=$ParaView_DIR" + else + echo unknown + fi > $sentinel + } ) } +# ----------------------------------------------------------------------------- + +echo "======================================================================" +echo "${PWD##*/} : $PWD" +echo + if [ -d "$VTK_DIR" -o -d "$ParaView_DIR" ] then if [ "$targetType" != objects ] diff --git a/wmake/rules/General/paraview b/wmake/rules/General/paraview new file mode 100644 index 0000000000..1df6ded1bc --- /dev/null +++ b/wmake/rules/General/paraview @@ -0,0 +1,8 @@ +#-------------------------------*- makefile -*--------------------------------- +# paraview values + +# major.minor: eg, /path/paraview-5.0 -> 5.0 +# +ParaView_MAJOR := $(shell echo $(ParaView_INCLUDE_DIR) | sed -e 's/^.*-//') + +#------------------------------------------------------------------------------ From ecb80a2ee84439ec594a234bfc234140a6623d1e Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 12 Jan 2017 06:40:58 +0100 Subject: [PATCH 06/35] ENH: refactor paraview readers code to avoid duplication - as originally intended years ago, but never actually done. - use 'foamPvCore' instead of 'vtkPVReaders' to avoid potential name collisions with any 'vtk*' files and since we may reuse these functions in other foam-paraview modules (not just readers). STYLE: use same font size/colour for patch-names as for point-numbers BUG: repair issue with single time-step - paraview time-selector returns '0' as the requested time if there is only one time step. However, if we have skipped the 0/ directory, this single time step is likely a non-zero value. --- .../graphics/PVReaders/Allwclean | 2 +- .../graphics/PVReaders/Allwmake | 2 +- .../PVFoamReader/PVFoamReader/CMakeLists.txt | 2 + .../PVFoamReader/PVFoamReader_SM.xml | 11 + .../PVFoamReader/vtkPVFoamReader.cxx | 178 ++-- .../PVFoamReader/vtkPVFoamReader.h | 7 +- .../PVFoamReader/vtkPVFoam/Make/files | 3 - .../PVFoamReader/vtkPVFoam/Make/options | 4 +- .../vtkPVFoam/vtkOpenFOAMPoints.H | 79 -- .../PVFoamReader/vtkPVFoam/vtkPVFoam.C | 143 ++- .../PVFoamReader/vtkPVFoam/vtkPVFoam.H | 663 +++++-------- .../vtkPVFoam/vtkPVFoamFaceField.H | 117 --- .../vtkPVFoam/vtkPVFoamFieldTemplates.C | 909 ++++++++++++++++++ .../PVFoamReader/vtkPVFoam/vtkPVFoamFields.C | 183 ++-- .../vtkPVFoam/vtkPVFoamLagrangianFields.H | 113 --- .../PVFoamReader/vtkPVFoam/vtkPVFoamMesh.C | 121 ++- .../vtkPVFoam/vtkPVFoamMeshLagrangian.C | 11 +- .../PVFoamReader/vtkPVFoam/vtkPVFoamMeshSet.C | 148 --- .../vtkPVFoam/vtkPVFoamMeshVolume.C | 39 +- .../vtkPVFoam/vtkPVFoamMeshZone.C | 75 -- .../vtkPVFoam/vtkPVFoamPatchField.H | 129 --- .../vtkPVFoam/vtkPVFoamPointFields.H | 331 ------- .../vtkPVFoam/vtkPVFoamTemplates.C | 10 +- .../vtkPVFoam/vtkPVFoamUpdateInfo.C | 151 ++- ...nfoFields.H => vtkPVFoamUpdateTemplates.C} | 25 +- .../PVFoamReader/vtkPVFoam/vtkPVFoamUtils.C | 340 ------- .../vtkPVFoam/vtkPVFoamVolFields.H | 456 --------- .../PVblockMeshReader/CMakeLists.txt | 2 + .../vtkPVblockMeshReader.cxx | 34 +- .../PVblockMeshReader/vtkPVblockMeshReader.h | 5 +- .../vtkPVblockMesh/Make/files | 1 - .../vtkPVblockMesh/Make/options | 4 +- .../vtkPVblockMesh/vtkOpenFOAMPoints.H | 65 -- .../vtkPVblockMesh/vtkPVblockMesh.C | 42 +- .../vtkPVblockMesh/vtkPVblockMesh.H | 133 +-- .../vtkPVblockMesh/vtkPVblockMeshConvert.C | 51 +- .../vtkPVblockMesh/vtkPVblockMeshUtils.C | 316 ------ .../graphics/PVReaders/foamPv/Make/files | 3 + .../{vtkPVReaders => foamPv}/Make/options | 1 + .../vtkPVReaders.C => foamPv/foamPvCore.C} | 212 ++-- .../vtkPVReaders.H => foamPv/foamPvCore.H} | 168 ++-- .../foamPvCoreTemplates.C} | 60 +- .../foamPvFields.H} | 49 +- .../PVReaders/vtkPVReaders/Make/files | 3 - 44 files changed, 1933 insertions(+), 3468 deletions(-) delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkOpenFOAMPoints.H delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFaceField.H create mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFieldTemplates.C delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamLagrangianFields.H delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamMeshSet.C delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamMeshZone.C delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamPatchField.H delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamPointFields.H rename applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/{vtkPVFoamUpdateInfoFields.H => vtkPVFoamUpdateTemplates.C} (84%) delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamUtils.C delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamVolFields.H delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkOpenFOAMPoints.H delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMeshUtils.C create mode 100644 applications/utilities/postProcessing/graphics/PVReaders/foamPv/Make/files rename applications/utilities/postProcessing/graphics/PVReaders/{vtkPVReaders => foamPv}/Make/options (79%) rename applications/utilities/postProcessing/graphics/PVReaders/{vtkPVReaders/vtkPVReaders.C => foamPv/foamPvCore.C} (58%) rename applications/utilities/postProcessing/graphics/PVReaders/{vtkPVReaders/vtkPVReaders.H => foamPv/foamPvCore.H} (52%) rename applications/utilities/postProcessing/graphics/PVReaders/{PVFoamReader/vtkPVFoam/vtkPVFoamAddToSelection.H => foamPv/foamPvCoreTemplates.C} (63%) rename applications/utilities/postProcessing/graphics/PVReaders/{PVFoamReader/vtkPVFoam/vtkOpenFOAMTupleRemap.H => foamPv/foamPvFields.H} (59%) delete mode 100644 applications/utilities/postProcessing/graphics/PVReaders/vtkPVReaders/Make/files diff --git a/applications/utilities/postProcessing/graphics/PVReaders/Allwclean b/applications/utilities/postProcessing/graphics/PVReaders/Allwclean index 23ec661742..6614154374 100755 --- a/applications/utilities/postProcessing/graphics/PVReaders/Allwclean +++ b/applications/utilities/postProcessing/graphics/PVReaders/Allwclean @@ -1,7 +1,7 @@ #!/bin/sh cd ${0%/*} || exit 1 # Run from this directory -wclean libso vtkPVReaders +wclean libso foamPv PVblockMeshReader/Allwclean PVFoamReader/Allwclean diff --git a/applications/utilities/postProcessing/graphics/PVReaders/Allwmake b/applications/utilities/postProcessing/graphics/PVReaders/Allwmake index c6ca055da0..2f89bc4c8a 100755 --- a/applications/utilities/postProcessing/graphics/PVReaders/Allwmake +++ b/applications/utilities/postProcessing/graphics/PVReaders/Allwmake @@ -97,7 +97,7 @@ case "$major" in if canBuildPlugin then ( - wmakeLibPv vtkPVReaders + wmakeLibPv foamPv PVblockMeshReader/Allwmake $targetType $* PVFoamReader/Allwmake $targetType $* diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/CMakeLists.txt b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/CMakeLists.txt index 40745ba928..819a476c3a 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/CMakeLists.txt +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/CMakeLists.txt @@ -15,6 +15,7 @@ include_directories( $ENV{WM_PROJECT_DIR}/src/OSspecific/$ENV{WM_OSTYPE}/lnInclude $ENV{WM_PROJECT_DIR}/src/finiteVolume/lnInclude ${PROJECT_SOURCE_DIR}/../vtkPVFoam + ${PROJECT_SOURCE_DIR}/../../foamPv/lnInclude ) add_definitions( @@ -63,6 +64,7 @@ target_link_libraries( PVFoamReader_SM LINK_PUBLIC vtkPVFoam-pv${PARAVIEW_VERSION_MAJOR}.${PARAVIEW_VERSION_MINOR} + foamPv-pv${PARAVIEW_VERSION_MAJOR}.${PARAVIEW_VERSION_MINOR} finiteVolume OpenFOAM ) diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/PVFoamReader_SM.xml b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/PVFoamReader_SM.xml index ebb0c3be93..82b3384a28 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/PVFoamReader_SM.xml +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/PVFoamReader_SM.xml @@ -273,6 +273,17 @@ The list of point fields. + + + + Print basic information to stdout + + + + #undef EXPERIMENTAL_TIME_CACHING // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -58,10 +62,9 @@ vtkPVFoamReader::vtkPVFoamReader() SetNumberOfInputPorts(0); - FileName = nullptr; - foamData_ = nullptr; - - output0_ = nullptr; + FileName = nullptr; + backend_ = nullptr; + output0_ = nullptr; #ifdef VTKPVFOAM_DUALPORT // Add second output for the Lagrangian @@ -133,11 +136,11 @@ vtkPVFoamReader::~vtkPVFoamReader() { vtkDebugMacro(<<"Deconstructor"); - if (foamData_) + if (backend_) { // remove patch names updatePatchNamesView(false); - delete foamData_; + delete backend_; } if (FileName) @@ -188,7 +191,7 @@ int vtkPVFoamReader::RequestInformation return 0; } - int nInfo = outputVector->GetNumberOfInformationObjects(); + const int nInfo = outputVector->GetNumberOfInformationObjects(); if (Foam::vtkPVFoam::debug) { @@ -199,60 +202,70 @@ int vtkPVFoamReader::RequestInformation } } - if (!foamData_) + if (!backend_) { - foamData_ = new Foam::vtkPVFoam(FileName, this); + backend_ = new Foam::vtkPVFoam(FileName, this); } else { - foamData_->updateInfo(); + backend_->updateInfo(); } - int nTimeSteps = 0; - double* timeSteps = foamData_->findTimes(nTimeSteps); + std::vector times = backend_->findTimes(this->SkipZeroTime); - if (!nTimeSteps) + if (times.empty()) { vtkErrorMacro("could not find valid OpenFOAM mesh"); // delete foamData and flag it as fatal error - delete foamData_; - foamData_ = nullptr; + delete backend_; + backend_ = nullptr; return 0; } // set identical time steps for all ports for (int infoI = 0; infoI < nInfo; ++infoI) { - outputVector->GetInformationObject(infoI)->Set + vtkInformation *outInfo = outputVector->GetInformationObject(infoI); + + outInfo->Set ( vtkStreamingDemandDrivenPipeline::TIME_STEPS(), - timeSteps, - nTimeSteps + times.data(), + static_cast(times.size()) ); + + // Something like this may be useful: + // outInfo->Set + // ( + // vtkStreamingDemandDrivenPipeline::TIME_DEPENDENT_INFORMATION(), + // 1 + // ); } - if (nTimeSteps) + if (times.size()) { - double timeRange[2]; - timeRange[0] = timeSteps[0]; - timeRange[1] = timeSteps[nTimeSteps-1]; + double timeRange[2]{ times.front(), times.back() }; if (Foam::vtkPVFoam::debug > 1) { - cout<<"nTimeSteps " << nTimeSteps << "\n" - <<"timeRange " << timeRange[0] << " to " << timeRange[1] - << "\n"; + cout + <<"nInfo " << nInfo << "\n" + <<"time-range " << times.front() << ':' << times.back() << "\n" + <<"times " << times.size() << "("; - for (int timeI = 0; timeI < nTimeSteps; ++timeI) + for (const double& val : times) { - cout<< "step[" << timeI << "] = " << timeSteps[timeI] << "\n"; + cout<< ' ' << val; } + cout << " )" << std::endl; } for (int infoI = 0; infoI < nInfo; ++infoI) { - outputVector->GetInformationObject(infoI)->Set + vtkInformation *outInfo = outputVector->GetInformationObject(infoI); + + outInfo->Set ( vtkStreamingDemandDrivenPipeline::TIME_RANGE(), timeRange, @@ -261,8 +274,6 @@ int vtkPVFoamReader::RequestInformation } } - delete timeSteps; - return 1; } @@ -282,15 +293,14 @@ int vtkPVFoamReader::RequestData vtkErrorMacro("FileName has to be specified!"); return 0; } - - // catch previous error - if (!foamData_) + if (!backend_) { + // catch some previous error vtkErrorMacro("Reader failed - perhaps no mesh?"); return 0; } - int nInfo = outputVector->GetNumberOfInformationObjects(); + const int nInfo = outputVector->GetNumberOfInformationObjects(); if (Foam::vtkPVFoam::debug) { @@ -315,23 +325,31 @@ int vtkPVFoamReader::RequestData { vtkInformation *outInfo = outputVector->GetInformationObject(infoI); + int nsteps = outInfo->Length(vtkStreamingDemandDrivenPipeline::TIME_STEPS()); + if ( outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP()) - && outInfo->Length(vtkStreamingDemandDrivenPipeline::TIME_STEPS()) > 0 + && nsteps > 0 ) { - requestTime[nRequestTime++] = - outInfo->Get - ( - vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP() - ); + requestTime[nRequestTime] = + ( + 1 == nsteps + // Only one time-step available, UPDATE_TIME_STEP is unreliable + ? outInfo->Get(vtkStreamingDemandDrivenPipeline::TIME_STEPS(), 0) + : outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP()) + ); + + // outInfo->Set(vtkDataObject::DATA_TIME_STEP(), requestTime[nRequestTime]); + // this->SetTimeValue(requestedTimeValue); + ++nRequestTime; } } if (nRequestTime) { - foamData_->setTime(nRequestTime, requestTime); + backend_->setTime(nRequestTime, requestTime); } vtkMultiBlockDataSet* output = vtkMultiBlockDataSet::SafeDownCast @@ -362,7 +380,7 @@ int vtkPVFoamReader::RequestData // but trashes the fields and still triggers the GeometryFilter if (needsUpdate) { - foamData_->Update(output); + backend_->Update(output); output0_->ShallowCopy(output); } else @@ -391,7 +409,7 @@ int vtkPVFoamReader::RequestData #else #ifdef VTKPVFOAM_DUALPORT - foamData_->Update + backend_->Update ( output, vtkMultiBlockDataSet::SafeDownCast @@ -403,7 +421,7 @@ int vtkPVFoamReader::RequestData ); ); #else - foamData_->Update(output, output); + backend_->Update(output, output); #endif updatePatchNamesView(ShowPatchNames); @@ -411,12 +429,27 @@ int vtkPVFoamReader::RequestData #endif // Do any cleanup on the OpenFOAM side - foamData_->CleanUp(); + backend_->CleanUp(); return 1; } +void vtkPVFoamReader::PrintInfo() +{ + if (backend_) + { + backend_->printInfo(); + } + else + { + cout + <<"OpenFOAM reader not initialized\n" + << std::flush; + } +} + + void vtkPVFoamReader::SetRefresh(bool val) { Modified(); @@ -428,9 +461,9 @@ void vtkPVFoamReader::SetIncludeSets(bool val) if (IncludeSets != val) { IncludeSets = val; - if (foamData_) + if (backend_) { - foamData_->updateInfo(); + backend_->updateInfo(); } } } @@ -441,9 +474,9 @@ void vtkPVFoamReader::SetIncludeZones(bool val) if (IncludeZones != val) { IncludeZones = val; - if (foamData_) + if (backend_) { - foamData_->updateInfo(); + backend_->updateInfo(); } } } @@ -464,9 +497,9 @@ void vtkPVFoamReader::SetShowGroupsOnly(bool val) if (ShowGroupsOnly != val) { ShowGroupsOnly = val; - if (foamData_) + if (backend_) { - foamData_->updateInfo(); + backend_->updateInfo(); } } } @@ -485,7 +518,7 @@ void vtkPVFoamReader::updatePatchNamesView(const bool show) // Server manager model for querying items in the server manager pqServerManagerModel* smModel = appCore->getServerManagerModel(); - if (!smModel || !foamData_) + if (!smModel || !backend_) { return; } @@ -495,7 +528,7 @@ void vtkPVFoamReader::updatePatchNamesView(const bool show) for (int viewI=0; viewI < renderViews.size(); ++viewI) { - foamData_->renderPatchNames + backend_->renderPatchNames ( renderViews[viewI]->getRenderViewProxy()->GetRenderer(), show @@ -514,7 +547,7 @@ void vtkPVFoamReader::PrintSelf(ostream& os, vtkIndent indent) os << indent << "File name: " << (this->FileName ? this->FileName : "(none)") << "\n"; - foamData_->PrintSelf(os, indent); + backend_->PrintSelf(os, indent); os << indent << "Time step range: " << this->TimeStepRange[0] << " - " << this->TimeStepRange[1] << "\n" @@ -524,7 +557,7 @@ void vtkPVFoamReader::PrintSelf(ostream& os, vtkIndent indent) int vtkPVFoamReader::GetTimeStep() { - return foamData_ ? foamData_->timeIndex() : -1; + return backend_ ? backend_->timeIndex() : -1; } @@ -533,32 +566,24 @@ int vtkPVFoamReader::GetTimeStep() vtkDataArraySelection* vtkPVFoamReader::GetPartSelection() { - vtkDebugMacro(<<"GetPartSelection"); return PartSelection; } - int vtkPVFoamReader::GetNumberOfPartArrays() { - vtkDebugMacro(<<"GetNumberOfPartArrays"); return PartSelection->GetNumberOfArrays(); } - const char* vtkPVFoamReader::GetPartArrayName(int index) { - vtkDebugMacro(<<"GetPartArrayName"); return PartSelection->GetArrayName(index); } - int vtkPVFoamReader::GetPartArrayStatus(const char* name) { - vtkDebugMacro(<<"GetPartArrayStatus"); return PartSelection->ArrayIsEnabled(name); } - void vtkPVFoamReader::SetPartArrayStatus(const char* name, int status) { vtkDebugMacro("Set mesh part \"" << name << "\" status to: " << status); @@ -579,35 +604,26 @@ void vtkPVFoamReader::SetPartArrayStatus(const char* name, int status) vtkDataArraySelection* vtkPVFoamReader::GetVolFieldSelection() { - vtkDebugMacro(<<"GetVolFieldSelection"); return VolFieldSelection; } - int vtkPVFoamReader::GetNumberOfVolFieldArrays() { - vtkDebugMacro(<<"GetNumberOfVolFieldArrays"); return VolFieldSelection->GetNumberOfArrays(); } - const char* vtkPVFoamReader::GetVolFieldArrayName(int index) { - vtkDebugMacro(<<"GetVolFieldArrayName"); return VolFieldSelection->GetArrayName(index); } - int vtkPVFoamReader::GetVolFieldArrayStatus(const char* name) { - vtkDebugMacro(<<"GetVolFieldArrayStatus"); return VolFieldSelection->ArrayIsEnabled(name); } - void vtkPVFoamReader::SetVolFieldArrayStatus(const char* name, int status) { - vtkDebugMacro(<<"SetVolFieldArrayStatus"); if (status) { VolFieldSelection->EnableArray(name); @@ -624,35 +640,26 @@ void vtkPVFoamReader::SetVolFieldArrayStatus(const char* name, int status) vtkDataArraySelection* vtkPVFoamReader::GetPointFieldSelection() { - vtkDebugMacro(<<"GetPointFieldSelection"); return PointFieldSelection; } - int vtkPVFoamReader::GetNumberOfPointFieldArrays() { - vtkDebugMacro(<<"GetNumberOfPointFieldArrays"); return PointFieldSelection->GetNumberOfArrays(); } - const char* vtkPVFoamReader::GetPointFieldArrayName(int index) { - vtkDebugMacro(<<"GetPointFieldArrayName"); return PointFieldSelection->GetArrayName(index); } - int vtkPVFoamReader::GetPointFieldArrayStatus(const char* name) { - vtkDebugMacro(<<"GetPointFieldArrayStatus"); return PointFieldSelection->ArrayIsEnabled(name); } - void vtkPVFoamReader::SetPointFieldArrayStatus(const char* name, int status) { - vtkDebugMacro(<<"SetPointFieldArrayStatus"); if (status) { PointFieldSelection->EnableArray(name); @@ -669,39 +676,30 @@ void vtkPVFoamReader::SetPointFieldArrayStatus(const char* name, int status) vtkDataArraySelection* vtkPVFoamReader::GetLagrangianFieldSelection() { - vtkDebugMacro(<<"GetLagrangianFieldSelection"); return LagrangianFieldSelection; } - int vtkPVFoamReader::GetNumberOfLagrangianFieldArrays() { - vtkDebugMacro(<<"GetNumberOfLagrangianFieldArrays"); return LagrangianFieldSelection->GetNumberOfArrays(); } - const char* vtkPVFoamReader::GetLagrangianFieldArrayName(int index) { - vtkDebugMacro(<<"GetLagrangianFieldArrayName"); return LagrangianFieldSelection->GetArrayName(index); } - int vtkPVFoamReader::GetLagrangianFieldArrayStatus(const char* name) { - vtkDebugMacro(<<"GetLagrangianFieldArrayStatus"); return LagrangianFieldSelection->ArrayIsEnabled(name); } - void vtkPVFoamReader::SetLagrangianFieldArrayStatus ( const char* name, int status ) { - vtkDebugMacro(<<"SetLagrangianFieldArrayStatus"); if (status) { LagrangianFieldSelection->EnableArray(name); diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.h b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.h index 74aeedda34..28a68445cd 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.h +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.h @@ -77,6 +77,10 @@ public: vtkSetStringMacro(FileName); vtkGetStringMacro(FileName); + // Description: + // Print some case information + virtual void PrintInfo(); + // Description: // OpenFOAM mesh caching control vtkSetMacro(CacheMesh, bool); @@ -250,7 +254,8 @@ private: //- Cached data for output port0 (experimental!) vtkMultiBlockDataSet* output0_; - Foam::vtkPVFoam* foamData_; + //- Backend portion of the reader + Foam::vtkPVFoam* backend_; }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/files b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/files index 6f9412f0af..c159826919 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/files +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/files @@ -2,10 +2,7 @@ vtkPVFoam.C vtkPVFoamFields.C vtkPVFoamMesh.C vtkPVFoamMeshLagrangian.C -vtkPVFoamMeshSet.C vtkPVFoamMeshVolume.C -vtkPVFoamMeshZone.C vtkPVFoamUpdateInfo.C -vtkPVFoamUtils.C LIB = $(FOAM_LIBBIN)/libvtkPVFoam-pv${ParaView_MAJOR} diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/options b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/options index aa2b9039da..4a73939711 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/options +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/options @@ -10,7 +10,7 @@ EXE_INC = \ -I$(LIB_SRC)/conversion/lnInclude \ -I$(ParaView_INCLUDE_DIR) \ -I$(ParaView_INCLUDE_DIR)/vtkkwiml \ - -I../../vtkPVReaders/lnInclude \ + -I../../foamPv/lnInclude \ -I../PVFoamReader LIB_LIBS = \ @@ -18,5 +18,5 @@ LIB_LIBS = \ -lconversion \ -lgenericPatchFields \ -llagrangian \ - -L$(FOAM_LIBBIN) -lvtkPVReaders-pv${ParaView_MAJOR} \ + -L$(FOAM_LIBBIN) -lfoamPv-pv${ParaView_MAJOR} \ $(GLIBS) diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkOpenFOAMPoints.H b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkOpenFOAMPoints.H deleted file mode 100644 index 2a45d73b2a..0000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkOpenFOAMPoints.H +++ /dev/null @@ -1,79 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -InClass - vtkPVFoam - -\*---------------------------------------------------------------------------*/ - -#ifndef vtkOpenFOAMPoints_H -#define vtkOpenFOAMPoints_H - -// VTK includes -#include "vtkPoints.h" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -inline void vtkInsertNextOpenFOAMPoint -( - vtkPoints *points, - const Foam::point& p -) -{ - points->InsertNextPoint(p.x(), p.y(), p.z()); -} - -#if 0 -// this should be faster, but didn't get it working ... -inline void vtkSetOpenFOAMPoint -( - vtkPoints *points, - const Foam::label id, - const Foam::point& p -) -{ - points->SetPoint(id, p.x(), p.y(), p.z()); -} - - -// Convert OpenFOAM mesh vertices to VTK -inline vtkPoints* vtkSetOpenFOAMPoints(const Foam::pointField& points) -{ - vtkPoints *vtkpoints = vtkPoints::New(); - vtkpoints->SetNumberOfPoints(points.size()); - forAll(points, i) - { - const Foam::point& p = points[i]; - vtkpoints->SetPoint(i, p.x(), p.y(), p.z()); - } - - return vtkpoints; -} - -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.C b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.C index 0f8e09252c..9ec5d92e71 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -42,15 +42,11 @@ License namespace Foam { -defineTypeNameAndDebug(vtkPVFoam, 0); + defineTypeNameAndDebug(vtkPVFoam, 0); } - // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -#include "vtkPVFoamAddToSelection.H" -#include "vtkPVFoamUpdateInfoFields.H" - void Foam::vtkPVFoam::resetCounters() { // Reset array range information (ids and sizes) @@ -116,14 +112,10 @@ int Foam::vtkPVFoam::setTime(int nRequest, const double requestTimes[]) if (debug) { - Info<< " Foam::vtkPVFoam::setTime("; + Info<< " setTime("; for (int requestI = 0; requestI < nRequest; ++requestI) { - if (requestI) - { - Info<< ", "; - } - + if (requestI) Info<< ", "; Info<< requestTimes[requestI]; } Info<< ") - previousIndex = " << timeIndex_ @@ -160,7 +152,7 @@ int Foam::vtkPVFoam::setTime(int nRequest, const double requestTimes[]) if (debug) { - Info<< " Foam::vtkPVFoam::setTime() - selectedTime=" + Info<< " setTime() - selectedTime=" << Times[nearestIndex].name() << " index=" << timeIndex_ << "/" << Times.size() << " meshChanged=" << Switch(meshChanged_) @@ -175,7 +167,7 @@ void Foam::vtkPVFoam::updateMeshPartsStatus() { if (debug) { - Info<< " Foam::vtkPVFoam::updateMeshPartsStatus" << endl; + Info<< " updateMeshPartsStatus" << endl; } vtkDataArraySelection* selection = reader_->GetPartSelection(); @@ -203,7 +195,7 @@ void Foam::vtkPVFoam::updateMeshPartsStatus() meshChanged_ = true; } - if (debug) + if (debug > 1) { Info<< " part[" << partId << "] = " << partStatus_[partId] @@ -212,11 +204,17 @@ void Foam::vtkPVFoam::updateMeshPartsStatus() } if (debug) { - Info<< " Foam::vtkPVFoam::updateMeshPartsStatus" << endl; + Info<< " updateMeshPartsStatus" << endl; } } +Foam::word Foam::vtkPVFoam::getPartName(const int partId) +{ + return getFirstWord(reader_->GetPartArrayName(partId)); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::vtkPVFoam::vtkPVFoam @@ -245,7 +243,7 @@ Foam::vtkPVFoam::vtkPVFoam { if (debug) { - Info<< "Foam::vtkPVFoam::vtkPVFoam - " << FileName << endl; + Info<< "vtkPVFoam - " << FileName << endl; printMemory(); } @@ -333,7 +331,7 @@ Foam::vtkPVFoam::~vtkPVFoam() { if (debug) { - Info<< " Foam::vtkPVFoam::~vtkPVFoam" << endl; + Info<< "~vtkPVFoam" << endl; } delete meshPtr_; @@ -346,7 +344,7 @@ void Foam::vtkPVFoam::updateInfo() { if (debug) { - Info<< " Foam::vtkPVFoam::updateInfo" + Info<< " updateInfo" << " [meshPtr=" << (meshPtr_ ? "set" : "nullptr") << "] timeIndex=" << timeIndex_ << endl; } @@ -363,16 +361,15 @@ void Foam::vtkPVFoam::updateInfo() // time of the vtkDataArraySelection, but the qt/paraview proxy // layer doesn't care about that anyhow. - // enable 'internalMesh' on the first call - // or preserve the enabled selections stringList enabledEntries; if (!partSelection->GetNumberOfArrays() && !meshPtr_) { - enabledEntries.setSize(1); - enabledEntries[0] = "internalMesh"; + // enable 'internalMesh' on the first call + enabledEntries = { "internalMesh" }; } else { + // preserve the enabled selections enabledEntries = getSelectedArrayEntries(partSelection); } @@ -395,23 +392,12 @@ void Foam::vtkPVFoam::updateInfo() } // Update volume, point and lagrangian fields - updateInfoFields - ( - reader_->GetVolFieldSelection() - ); - updateInfoFields - ( - reader_->GetPointFieldSelection() - ); - updateInfoLagrangianFields(); + updateInfoFields(); if (debug) { - // just for debug info - getSelectedArrayEntries(partSelection); - Info<< " Foam::vtkPVFoam::updateInfo" << endl; + Info<< " updateInfo" << endl; } - } @@ -419,7 +405,7 @@ void Foam::vtkPVFoam::updateFoamMesh() { if (debug) { - Info<< " Foam::vtkPVFoam::updateFoamMesh" << endl; + Info<< " updateFoamMesh" << endl; printMemory(); } @@ -463,7 +449,7 @@ void Foam::vtkPVFoam::updateFoamMesh() if (debug) { - Info<< " Foam::vtkPVFoam::updateFoamMesh" << endl; + Info<< " updateFoamMesh" << endl; printMemory(); } } @@ -532,7 +518,7 @@ void Foam::vtkPVFoam::Update convertLagrangianFields(lagrangianOutput); if (debug) { - Info<< "done reader part" << endl; + Info<< "done reader part" << nl << endl; } reader_->UpdateProgress(0.95); @@ -548,68 +534,58 @@ void Foam::vtkPVFoam::CleanUp() } -double* Foam::vtkPVFoam::findTimes(int& nTimeSteps) +std::vector Foam::vtkPVFoam::findTimes(const bool skipZero) const { - int nTimes = 0; - double* tsteps = nullptr; + std::vector times; if (dbPtr_.valid()) { - Time& runTime = dbPtr_(); + const Time& runTime = dbPtr_(); instantList timeLst = runTime.times(); // find the first time for which this mesh appears to exist - label timeI = 0; - for (; timeI < timeLst.size(); ++timeI) + label begIndex = timeLst.size(); + forAll(timeLst, timeI) { - const word& timeName = timeLst[timeI].name(); - if ( - isFile(runTime.path()/timeName/meshDir_/"points") - && IOobject + IOobject ( "points", - timeName, + timeLst[timeI].name(), meshDir_, runTime - ).typeHeaderOk(true) + ).typeHeaderOk(false, false) ) { + begIndex = timeI; break; } } - nTimes = timeLst.size() - timeI; + label nTimes = timeLst.size() - begIndex; // skip "constant" time whenever possible - if (timeI == 0 && nTimes > 1) + if (begIndex == 0 && nTimes > 1) { - if (timeLst[timeI].name() == runTime.constant()) + if (timeLst[begIndex].name() == runTime.constant()) { - ++timeI; + ++begIndex; --nTimes; } } - // skip "0/" time if requested and possible - if (nTimes > 1 && reader_->GetSkipZeroTime()) + if (skipZero && nTimes > 1 && timeLst[begIndex].name() == "0") { - if (mag(timeLst[timeI].value()) < SMALL) - { - ++timeI; - --nTimes; - } + ++begIndex; + --nTimes; } - if (nTimes) + times.reserve(nTimes); + while (nTimes-- > 0) { - tsteps = new double[nTimes]; - for (label stepI = 0; stepI < nTimes; ++stepI, ++timeI) - { - tsteps[stepI] = timeLst[timeI].value(); - } + times.push_back(timeLst[begIndex++].value()); } } else @@ -620,10 +596,7 @@ double* Foam::vtkPVFoam::findTimes(int& nTimeSteps) } } - // vector length returned via the parameter - nTimeSteps = nTimes; - - return tsteps; + return times; } @@ -650,7 +623,7 @@ void Foam::vtkPVFoam::renderPatchNames if (show) { // get the display patches, strip off any suffix - wordHashSet selectedPatches = getSelected + hashedWordList selectedPatches = getSelected ( reader_->GetPartSelection(), arrayRangePatches_ @@ -793,8 +766,8 @@ void Foam::vtkPVFoam::renderPatchNames tprop->BoldOff(); tprop->ShadowOff(); tprop->SetLineSpacing(1.0); - tprop->SetFontSize(12); - tprop->SetColor(1.0, 0.0, 0.0); + tprop->SetFontSize(14); + tprop->SetColor(1.0, 0.0, 1.0); tprop->SetJustificationToCentered(); // Set text to use 3-D world co-ordinates @@ -840,4 +813,24 @@ void Foam::vtkPVFoam::PrintSelf(ostream& os, vtkIndent indent) const } +void Foam::vtkPVFoam::printInfo() const +{ + std::cout + << "Region: " << meshRegion_ << "\n" + << "nPoints: " << (meshPtr_ ? meshPtr_->nPoints() : 0) << "\n" + << "nCells: " << (meshPtr_ ? meshPtr_->nCells() : 0) << "\n" + << "nTimes: " + << (dbPtr_.valid() ? dbPtr_().times().size() : 0) << "\n"; + + std::vector times = this->findTimes(reader_->GetSkipZeroTime()); + + std::cout<<" " << times.size() << "("; + for (const double& val : times) + { + std::cout<< ' ' << val; + } + std::cout << " )" << std::endl; +} + + // ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.H b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.H index fb3a988b86..17322e44c7 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.H +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -29,24 +29,15 @@ Description SourceFiles vtkPVFoam.C - vtkPVFoam.H vtkPVFoamFields.C vtkPVFoamMesh.C vtkPVFoamMeshLagrangian.C - vtkPVFoamTemplates.C - vtkPVFoamMeshSet.C vtkPVFoamMeshVolume.C - vtkPVFoamMeshZone.C - vtkPVFoamFaceField.H - vtkPVFoamLagrangianFields.H - vtkPVFoamPatchField.H - vtkPVFoamPointFields.H - vtkPVFoamPoints.H + vtkPVFoamTemplates.C vtkPVFoamUpdateInfo.C - vtkPVFoamUpdateInfoFields.H vtkPVFoamUtils.C - vtkPVFoamVolFields.H - vtkPVFoamAddToSelection.H + vtkPVFoamFieldTemplates.C + vtkPVFoamUpdateTemplates.C // Needed by VTK: vtkDataArrayTemplateImplicit.txx @@ -63,6 +54,7 @@ SourceFiles #include "primitivePatch.H" #include "PrimitivePatchInterpolation.H" #include "volPointInterpolation.H" +#include "foamPvCore.H" #undef VTKPVFOAM_DUALPORT @@ -70,6 +62,7 @@ SourceFiles class vtkDataArraySelection; class vtkDataSet; +class vtkFloatArray; class vtkPoints; class vtkPVFoamReader; class vtkRenderer; @@ -90,10 +83,9 @@ class Time; class fvMesh; class IOobjectList; class polyPatch; -class faceSet; -class pointSet; template class IOField; +template class Field; template class List; /*---------------------------------------------------------------------------*\ @@ -101,84 +93,15 @@ template class List; \*---------------------------------------------------------------------------*/ class vtkPVFoam +: + private foamPvCore { + // Convenience typedefs + typedef PrimitivePatchInterpolation patchInterpolator; + + // Private classes - //- Bookkeeping for GUI checklists and the multi-block organization - class arrayRange - { - const char *name_; - int block_; - int start_; - int size_; - - public: - - arrayRange(const char *name, const int blockNo=0) - : - name_(name), - block_(blockNo), - start_(0), - size_(0) - {} - - //- Return the block holding these datasets - int block() const - { - return block_; - } - - //- Assign block number, return previous value - int block(int blockNo) - { - int prev = block_; - block_ = blockNo; - return prev; - } - - //- Return block name - const char* name() const - { - return name_; - } - - //- Return array start index - int start() const - { - return start_; - } - - //- Return array end index - int end() const - { - return start_ + size_; - } - - //- Return sublist size - int size() const - { - return size_; - } - - bool empty() const - { - return !size_; - } - - //- Reset the size to zero and optionally assign a new start - void reset(const int startAt = 0) - { - start_ = startAt; - size_ = 0; - } - - //- Increment the size - void operator+=(const int n) - { - size_ += n; - } - }; - //- Bookkeeping for polyhedral cell decomposition // hide in extra pointMap (cellSet/cellZone) for now class polyDecomp @@ -297,372 +220,258 @@ class vtkPVFoam //- List of patch names for rendering to window List patchTextActorsPtrs_; + // Private Member Functions - // Convenience method use to convert the readers from VTK 5 - // multiblock API to the current composite data infrastructure - static void AddToBlock - ( - vtkMultiBlockDataSet* output, - vtkDataSet* dataset, - const arrayRange&, - const label datasetNo, - const std::string& datasetName - ); - - // Convenience method use to convert the readers from VTK 5 - // multiblock API to the current composite data infrastructure - static vtkDataSet* GetDataSetFromBlock - ( - vtkMultiBlockDataSet* output, - const arrayRange&, - const label datasetNo - ); - - // Convenience method use to convert the readers from VTK 5 - // multiblock API to the current composite data infrastructure - static label GetNumberOfDataSets - ( - vtkMultiBlockDataSet* output, - const arrayRange& - ); - //- Reset data counters void resetCounters(); - // Update information helper functions + // Update information helper functions - //- Update the mesh parts selected in the GUI - void updateMeshPartsStatus(); + //- Update the mesh parts selected in the GUI + void updateMeshPartsStatus(); - //- Internal mesh info - void updateInfoInternalMesh(vtkDataArraySelection*); + //- Internal mesh info + void updateInfoInternalMesh(vtkDataArraySelection*); - //- Lagrangian info - void updateInfoLagrangian(vtkDataArraySelection*); + //- Lagrangian info + void updateInfoLagrangian(vtkDataArraySelection*); - //- Patch info - void updateInfoPatches(vtkDataArraySelection*, stringList&); + //- Patch info + void updateInfoPatches(vtkDataArraySelection*, stringList&); - //- Set info - void updateInfoSets(vtkDataArraySelection*); + //- Set info + void updateInfoSets(vtkDataArraySelection*); - //- Zone info - void updateInfoZones(vtkDataArraySelection*); + //- Zone info + void updateInfoZones(vtkDataArraySelection*); - //- Get non-empty zone names for zoneType from file - wordList getZoneNames(const word& zoneType) const; + //- Get non-empty zone names for zoneType from file + wordList getZoneNames(const word& zoneType) const; - //- Get non-empty zone names from mesh info - template - wordList getZoneNames - ( - const ZoneMesh& - ) const; - - //- Add objects of Type to paraview array selection - template - label addToSelection - ( - vtkDataArraySelection*, - const IOobjectList&, - const string& suffix=string::null - ); - - //- Field info - template class patchType, class meshType> - void updateInfoFields(vtkDataArraySelection*); - - //- Lagrangian field info - void updateInfoLagrangianFields(); - - - // Update helper functions - - //- OpenFOAM mesh - void updateFoamMesh(); - - //- Reduce memory footprint after conversion - void reduceMemory(); - - - // Mesh conversion functions - - //- Volume mesh - void convertMeshVolume(vtkMultiBlockDataSet*, int& blockNo); - - //- Lagrangian mesh - void convertMeshLagrangian(vtkMultiBlockDataSet*, int& blockNo); - - //- Patch meshes - void convertMeshPatches(vtkMultiBlockDataSet*, int& blockNo); - - //- Cell zone meshes - void convertMeshCellZones(vtkMultiBlockDataSet*, int& blockNo); - - //- Face zone meshes - void convertMeshFaceZones(vtkMultiBlockDataSet*, int& blockNo); - - //- Point zone meshes - void convertMeshPointZones(vtkMultiBlockDataSet*, int& blockNo); - - //- Cell set meshes - void convertMeshCellSets(vtkMultiBlockDataSet*, int& blockNo); - - //- Face set meshes - void convertMeshFaceSets(vtkMultiBlockDataSet*, int& blockNo); - - //- Point set meshes - void convertMeshPointSets(vtkMultiBlockDataSet*, int& blockNo); - - - // Add mesh functions - - //- Add internal mesh/cell set meshes - vtkUnstructuredGrid* volumeVTKMesh(const fvMesh&, polyDecomp&); - - //- Add Lagrangian mesh - vtkPolyData* lagrangianVTKMesh - ( - const fvMesh&, - const word& cloudName - ); - - //- Add patch mesh - template - vtkPolyData* patchVTKMesh(const word& name, const PatchType&); - - //- Add point zone - vtkPolyData* pointZoneVTKMesh - ( - const fvMesh&, - const labelList& pointLabels - ); - - //- Add face set mesh - vtkPolyData* faceSetVTKMesh - ( - const fvMesh&, - const faceSet& - ); - - //- Add point mesh - vtkPolyData* pointSetVTKMesh - ( - const fvMesh&, - const pointSet& - ); - - // Field conversion functions - - //- Convert volume fields - void convertVolFields(vtkMultiBlockDataSet*); - - //- Convert point fields - void convertPointFields(vtkMultiBlockDataSet*); - - //- Convert Lagrangian fields - void convertLagrangianFields(vtkMultiBlockDataSet*); - - - //- Add the fields in the selected time directory to the selection - // lists - template - label addObjectsToSelection + //- Get names of on non-empty zones from the mesh info + template + static wordList getZoneNames ( - vtkDataArraySelection*, - const IOobjectList&, - const string& suffix=string::null + const ZoneMesh& zmesh + ); + + //- Field (volume, point, lagrangian) info + void updateInfoFields(); + + //- Field info + template class patchType, class meshType> + void updateInfoFields + ( + vtkDataArraySelection* select + ); + + //- Lagrangian field info + void updateInfoLagrangianFields(vtkDataArraySelection* select); + + + // Update helper functions + + //- OpenFOAM mesh + void updateFoamMesh(); + + //- Reduce memory footprint after conversion + void reduceMemory(); + + + // Mesh conversion functions + + //- Convert volume mesh + void convertMeshVolume(vtkMultiBlockDataSet* output, int& blockNo); + + //- Convert Lagrangian points + void convertMeshLagrangian(vtkMultiBlockDataSet* output, int& blockNo); + + //- Convert mesh patches + void convertMeshPatches(vtkMultiBlockDataSet* output, int& blockNo); + + //- Convert cell zones + void convertMeshCellZones(vtkMultiBlockDataSet* output, int& blockNo); + + //- Convert face zones + void convertMeshFaceZones(vtkMultiBlockDataSet* output, int& blockNo); + + //- Convert point zones + void convertMeshPointZones(vtkMultiBlockDataSet* output, int& blockNo); + + //- Convert cell sets + void convertMeshCellSets(vtkMultiBlockDataSet* output, int& blockNo); + + //- Convert face sets + void convertMeshFaceSets(vtkMultiBlockDataSet* output, int& blockNo); + + //- Convert point sets + void convertMeshPointSets(vtkMultiBlockDataSet* output, int& blockNo); + + + // Add mesh functions + + //- Volume meshes as vtkUnstructuredGrid + vtkUnstructuredGrid* volumeVTKMesh + ( + const fvMesh& mesh, + polyDecomp& decompInfo + ); + + //- Lagrangian positions as vtkPolyData + vtkPolyData* lagrangianVTKMesh + ( + const polyMesh& mesh, + const word& cloudName + ); + + //- Patches (mesh or primitive) as vtkPolyData + template + vtkPolyData* patchVTKMesh + ( + const word& name, + const PatchType& p ); - // Convert OpenFOAM fields + // Field conversion functions - //- Volume field - all types - template - void convertVolField - ( - const PtrList>&, - const GeometricField&, - const bool interpFields, - vtkMultiBlockDataSet* output - ); + //- Convert Field to VTK field + template + vtkFloatArray* convertFieldToVTK + ( + const word& name, + const Field& fld + ); - //- Volume fields - all types - template - void convertVolFields - ( - const fvMesh&, - const PtrList>&, - const IOobjectList&, - const bool interpFields, - vtkMultiBlockDataSet* output - ); + //- Face set/zone field + template + vtkFloatArray* convertFaceFieldToVTK + ( + const GeometricField& fld, + const labelUList& faceLabels + ); - //- Volume internal fields (DimensionedField)- all types - template - void convertDimFields - ( - const fvMesh&, - const PtrList>&, - const IOobjectList&, - const bool interpFields, - vtkMultiBlockDataSet* output - ); - - //- Volume field - all selected parts - template - void convertVolFieldBlock - ( - const GeometricField&, - autoPtr>&, - vtkMultiBlockDataSet* output, - const arrayRange&, - const List& decompLst - ); - - //- Volume field - template - void convertVolField - ( - const GeometricField&, - vtkMultiBlockDataSet* output, - const arrayRange&, - const label datasetNo, - const polyDecomp& - ); - - //- Patch field - template - void convertPatchField - ( - const word& name, - const Field&, - vtkMultiBlockDataSet* output, - const arrayRange&, - const label datasetNo - ); - - //- Face set/zone field - template - void convertFaceField - ( - const GeometricField&, - vtkMultiBlockDataSet* output, - const arrayRange&, - const label datasetNo, - const fvMesh&, - const labelList& faceLabels - ); - - //- Lagrangian fields - all types - template - void convertLagrangianFields - ( - const IOobjectList&, - vtkMultiBlockDataSet* output, - const label datasetNo - ); - - //- Lagrangian field - template - void convertLagrangianField - ( - const IOField&, - vtkMultiBlockDataSet* output, - const arrayRange&, - const label datasetNo - ); - - //- Point fields - all types - template - void convertPointFields - ( - const fvMesh&, - const pointMesh&, - const IOobjectList&, - vtkMultiBlockDataSet* output - ); - - //- Point field - all selected parts - template - void convertPointFieldBlock - ( - const GeometricField&, - vtkMultiBlockDataSet* output, - const arrayRange&, - const List& - ); - - //- Point fields - template - void convertPointField - ( - const GeometricField&, - const GeometricField&, - vtkMultiBlockDataSet* output, - const arrayRange&, - const label datasetNo, - const polyDecomp& - ); - - //- Patch point field - template - void convertPatchPointField - ( - const word& name, - const Field&, - vtkMultiBlockDataSet* output, - const arrayRange&, - const label datasetNo - ); + //- Volume field + template + vtkFloatArray* convertVolFieldToVTK + ( + const GeometricField& fld, + const polyDecomp& decompInfo + ); - // GUI selection helper functions + //- Convert volume fields + void convertVolFields(vtkMultiBlockDataSet* output); - //- Only keep what is listed in hashSet - static void pruneObjectList - ( - IOobjectList&, - const wordHashSet& - ); + //- Convert point fields + void convertPointFields(vtkMultiBlockDataSet* output); - //- Retrieve the current selections - static wordHashSet getSelected(vtkDataArraySelection*); + //- Convert Lagrangian fields + void convertLagrangianFields(vtkMultiBlockDataSet* output); - //- Retrieve a sub-list of the current selections - static wordHashSet getSelected - ( - vtkDataArraySelection*, - const arrayRange& - ); - //- Retrieve the current selections - static stringList getSelectedArrayEntries(vtkDataArraySelection*); + // Convert OpenFOAM fields - //- Retrieve a sub-list of the current selections - static stringList getSelectedArrayEntries - ( - vtkDataArraySelection*, - const arrayRange& - ); + //- Volume field - all types + template + void convertVolField + ( + const PtrList& patchInterpList, + const GeometricField& fld, + vtkMultiBlockDataSet* output + ); - //- Set selection(s) - static void setSelectedArrayEntries - ( - vtkDataArraySelection*, - const stringList& - ); + //- Volume fields - all types + template + void convertVolFields + ( + const fvMesh& mesh, + const PtrList& patchInterpList, + const IOobjectList& objects, + vtkMultiBlockDataSet* output + ); - //- Get the first word from the mesh parts selection - word getPartName(const int); + //- Volume internal fields (DimensionedField)- all types + template + void convertDimFields + ( + const fvMesh& mesh, + const PtrList& patchInterpList, + const IOobjectList& objects, + vtkMultiBlockDataSet* output + ); + //- Volume field - all selected parts + template + void convertVolFieldBlock + ( + const GeometricField& fld, + autoPtr>& ptfPtr, + vtkMultiBlockDataSet* output, + const arrayRange& range, + const List& decompLst + ); + + //- Lagrangian fields - all types + template + void convertLagrangianFields + ( + const IOobjectList& objects, + vtkMultiBlockDataSet* output, + const label datasetNo + ); + + //- Point fields - all types + template + void convertPointFields + ( + const pointMesh& pMesh, + const IOobjectList& objects, + vtkMultiBlockDataSet* output + ); + + //- Point field - all selected parts + template + void convertPointFieldBlock + ( + const GeometricField& pfld, + vtkMultiBlockDataSet* output, + const arrayRange& range, + const List& decompLst + ); + + //- Point field + template + void convertPointField + ( + vtkUnstructuredGrid* vtkmesh, + const GeometricField& pfld, + const GeometricField& vfld, + const polyDecomp& decomp + ); + + + // GUI selection helper functions + + //- Only retain specified fields + static void pruneObjectList + ( + IOobjectList& objects, + const hashedWordList& retain + ); + + //- Get the first word from the reader 'parts' selection + word getPartName(const int partId); + + + // Constructors //- Disallow default bitwise copy construct - vtkPVFoam(const vtkPVFoam&); + vtkPVFoam(const vtkPVFoam&) = delete; //- Disallow default bitwise assignment - void operator=(const vtkPVFoam&); + void operator=(const vtkPVFoam&) = delete; public: @@ -700,9 +509,9 @@ public: //- Clean any storage void CleanUp(); - //- Allocate and return a list of selected times - // returns the count via the parameter - double* findTimes(int& nTimeSteps); + //- Return a list of selected times. + // Use STL container since these values are used by the plugin + std::vector findTimes(const bool skipZero = false) const; //- Add/remove patch names to/from the view void renderPatchNames(vtkRenderer*, const bool show); @@ -725,9 +534,7 @@ public: //- Debug information void PrintSelf(ostream&, vtkIndent) const; - //- Simple memory used debugging information - static void printMemory(); - + void printInfo() const; }; diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFaceField.H b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFaceField.H deleted file mode 100644 index 69395405d5..0000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFaceField.H +++ /dev/null @@ -1,117 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -InClass - vtkPVFoam - -\*---------------------------------------------------------------------------*/ - -#ifndef vtkPVFoamFaceField_H -#define vtkPVFoamFaceField_H - -// VTK includes -#include "vtkCellData.h" -#include "vtkFloatArray.h" -#include "vtkMultiBlockDataSet.h" -#include "vtkPolyData.h" - -#include "vtkOpenFOAMTupleRemap.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -template -void Foam::vtkPVFoam::convertFaceField -( - const GeometricField& tf, - vtkMultiBlockDataSet* output, - const arrayRange& range, - const label datasetNo, - const fvMesh& mesh, - const labelList& faceLabels -) -{ - const label nComp = pTraits::nComponents; - const label nInternalFaces = mesh.nInternalFaces(); - const labelList& faceOwner = mesh.faceOwner(); - const labelList& faceNeigh = mesh.faceNeighbour(); - - vtkFloatArray* cellData = vtkFloatArray::New(); - cellData->SetNumberOfTuples(faceLabels.size()); - cellData->SetNumberOfComponents(nComp); - cellData->Allocate(nComp*faceLabels.size()); - cellData->SetName(tf.name().c_str()); - - if (debug) - { - Info<< "convert convertFaceField: " - << tf.name() - << " size = " << tf.size() - << " nComp=" << nComp - << " nTuples = " << faceLabels.size() << endl; - } - - float vec[nComp]; - - // for interior faces: average owner/neighbour - // for boundary faces: owner - forAll(faceLabels, facei) - { - const label faceNo = faceLabels[facei]; - if (faceNo < nInternalFaces) - { - Type t = 0.5*(tf[faceOwner[faceNo]] + tf[faceNeigh[faceNo]]); - - for (direction d=0; d(vec); - - cellData->InsertTuple(facei, vec); - } - - - vtkPolyData::SafeDownCast - ( - GetDataSetFromBlock(output, range, datasetNo) - ) ->GetCellData() - ->AddArray(cellData); - - cellData->Delete(); -} - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFieldTemplates.C b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFieldTemplates.C new file mode 100644 index 0000000000..c6b9e3b86c --- /dev/null +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFieldTemplates.C @@ -0,0 +1,909 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +InClass + vtkPVFoam + +\*---------------------------------------------------------------------------*/ + +#ifndef vtkPVFoamFieldTemplates_C +#define vtkPVFoamFieldTemplates_C + +// OpenFOAM includes +#include "emptyFvPatchField.H" +#include "wallPolyPatch.H" +#include "faceSet.H" +#include "volPointInterpolation.H" +#include "zeroGradientFvPatchField.H" +#include "interpolatePointToCell.H" +#include "foamPvFields.H" + +// vtk includes +#include "vtkFloatArray.h" +#include "vtkCellData.h" +#include "vtkPointData.h" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// +// volume-fields +// + +template +void Foam::vtkPVFoam::convertVolField +( + const PtrList& patchInterpList, + const GeometricField& fld, + vtkMultiBlockDataSet* output +) +{ + const fvMesh& mesh = fld.mesh(); + const polyBoundaryMesh& patches = mesh.boundaryMesh(); + + const bool interpField = !patchInterpList.empty(); + const bool extrapPatch = reader_->GetExtrapolatePatches(); + + // Interpolated field (demand driven) + autoPtr> ptfPtr; + if (interpField) + { + if (debug) + { + Info<< "convertVolField interpolating:" << fld.name() << endl; + } + + ptfPtr.reset + ( + volPointInterpolation::New(mesh).interpolate(fld).ptr() + ); + } + + // Convert activated internalMesh regions + convertVolFieldBlock + ( + fld, + ptfPtr, + output, + arrayRangeVolume_, + regionPolyDecomp_ + ); + + // Convert activated cellZones + convertVolFieldBlock + ( + fld, + ptfPtr, + output, + arrayRangeCellZones_, + zonePolyDecomp_ + ); + + // Convert activated cellSets + convertVolFieldBlock + ( + fld, + ptfPtr, + output, + arrayRangeCellSets_, + csetPolyDecomp_ + ); + + + // + // Convert patches - if activated + // + for + ( + int partId = arrayRangePatches_.start(); + partId < arrayRangePatches_.end(); + ++partId + ) + { + const word patchName = getPartName(partId); + const label datasetNo = partDataset_[partId]; + const label patchId = patches.findPatchID(patchName); + + if (!partStatus_[partId] || patchId < 0) + { + continue; + } + + vtkPolyData* vtkmesh = getDataFromBlock + ( + output, arrayRangePatches_, datasetNo + ); + + if (!vtkmesh) + { + continue; + } + + const fvPatchField& ptf = fld.boundaryField()[patchId]; + + if + ( + isType>(ptf) + || + ( + extrapPatch + && !polyPatch::constraintType(patches[patchId].type()) + ) + ) + { + fvPatch p(ptf.patch().patch(), mesh.boundary()); + + tmp> tpptf + ( + fvPatchField(p, fld).patchInternalField() + ); + + vtkFloatArray* cdata = convertFieldToVTK(fld.name(), tpptf()); + vtkmesh->GetCellData()->AddArray(cdata); + cdata->Delete(); + + if (patchId < patchInterpList.size()) + { + vtkFloatArray* pdata = convertFieldToVTK + ( + fld.name(), + patchInterpList[patchId].faceToPointInterpolate(tpptf)() + ); + + vtkmesh->GetPointData()->AddArray(pdata); + pdata->Delete(); + } + } + else + { + vtkFloatArray* cdata = convertFieldToVTK(fld.name(), ptf); + vtkmesh->GetCellData()->AddArray(cdata); + cdata->Delete(); + + if (patchId < patchInterpList.size()) + { + vtkFloatArray* pdata = convertFieldToVTK + ( + fld.name(), + patchInterpList[patchId].faceToPointInterpolate(ptf)() + ); + + vtkmesh->GetPointData()->AddArray(pdata); + pdata->Delete(); + } + } + } + + // + // Convert face zones - if activated + // + for + ( + int partId = arrayRangeFaceZones_.start(); + partId < arrayRangeFaceZones_.end(); + ++partId + ) + { + const word zoneName = getPartName(partId); + const label datasetNo = partDataset_[partId]; + + if (!partStatus_[partId] || datasetNo < 0) + { + continue; + } + + const faceZoneMesh& zMesh = mesh.faceZones(); + const label zoneId = zMesh.findZoneID(zoneName); + + if (zoneId < 0) + { + continue; + } + + vtkPolyData* vtkmesh = getDataFromBlock + ( + output, arrayRangeFaceZones_, datasetNo + ); + + if (vtkmesh) + { + vtkFloatArray* cdata = convertFaceFieldToVTK + ( + fld, + zMesh[zoneId] + ); + + vtkmesh->GetCellData()->AddArray(cdata); + cdata->Delete(); + } + + // TODO: points + } + + // + // Convert face sets - if activated + // + for + ( + int partId = arrayRangeFaceSets_.start(); + partId < arrayRangeFaceSets_.end(); + ++partId + ) + { + const word selectName = getPartName(partId); + const label datasetNo = partDataset_[partId]; + + if (!partStatus_[partId]) + { + continue; + } + + vtkPolyData* vtkmesh = getDataFromBlock + ( + output, arrayRangeFaceSets_, datasetNo + ); + + if (!vtkmesh) + { + continue; + } + + const faceSet fSet(mesh, selectName); + + vtkFloatArray* cdata = convertFaceFieldToVTK + ( + fld, + fSet.sortedToc() + ); + + vtkmesh->GetCellData()->AddArray(cdata); + cdata->Delete(); + + // TODO: points + } +} + + +template +void Foam::vtkPVFoam::convertVolFields +( + const fvMesh& mesh, + const PtrList& patchInterpList, + const IOobjectList& objects, + vtkMultiBlockDataSet* output +) +{ + forAllConstIter(IOobjectList, objects, iter) + { + // restrict to GeometricField + if + ( + iter()->headerClassName() + != GeometricField::typeName + ) + { + continue; + } + + // Load field + GeometricField fld + ( + *iter(), + mesh + ); + + // Convert + convertVolField(patchInterpList, fld, output); + } +} + + +template +void Foam::vtkPVFoam::convertDimFields +( + const fvMesh& mesh, + const PtrList& patchInterpList, + const IOobjectList& objects, + vtkMultiBlockDataSet* output +) +{ + typedef GeometricField VolFieldType; + + forAllConstIter(IOobjectList, objects, iter) + { + // restrict to DimensionedField + if + ( + iter()->headerClassName() + != DimensionedField::typeName + ) + { + continue; + } + + // Load field + DimensionedField dimFld(*iter(), mesh); + + // Construct volField with zero-gradient patch fields + + IOobject io(dimFld); + io.readOpt() = IOobject::NO_READ; + + PtrList> patchFields(mesh.boundary().size()); + forAll(patchFields, patchI) + { + patchFields.set + ( + patchI, + fvPatchField::New + ( + zeroGradientFvPatchField::typeName, + mesh.boundary()[patchI], + dimFld + ) + ); + } + + VolFieldType volFld + ( + io, + dimFld.mesh(), + dimFld.dimensions(), + dimFld, + patchFields + ); + volFld.correctBoundaryConditions(); + + convertVolField(patchInterpList, volFld, output); + } +} + + +template +void Foam::vtkPVFoam::convertVolFieldBlock +( + const GeometricField& fld, + autoPtr>& ptfPtr, + vtkMultiBlockDataSet* output, + const arrayRange& range, + const List& decompLst +) +{ + for (int partId = range.start(); partId < range.end(); ++partId) + { + const label datasetNo = partDataset_[partId]; + + if (!partStatus_[partId]) + { + continue; + } + + vtkUnstructuredGrid* vtkmesh = + getDataFromBlock(output, range, datasetNo); + + if (!vtkmesh) + { + continue; + } + + vtkFloatArray* cdata = convertVolFieldToVTK + ( + fld, + decompLst[datasetNo] + ); + + vtkmesh->GetCellData()->AddArray(cdata); + cdata->Delete(); + + if (ptfPtr.valid()) + { + convertPointField(vtkmesh, ptfPtr(), fld, decompLst[datasetNo]); + } + } +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// +// point-fields +// + +template +void Foam::vtkPVFoam::convertPointFields +( + const pointMesh& pMesh, + const IOobjectList& objects, + vtkMultiBlockDataSet* output +) +{ + const polyMesh& mesh = pMesh.mesh(); + const polyBoundaryMesh& patches = mesh.boundaryMesh(); + + forAllConstIter(IOobjectList, objects, iter) + { + const word& fieldName = iter()->name(); + // restrict to this GeometricField + if + ( + iter()->headerClassName() + != GeometricField::typeName + ) + { + continue; + } + + if (debug) + { + Info<< "convertPointFields : " << fieldName << endl; + } + + GeometricField pfld(*iter(), pMesh); + + + // Convert activated internalMesh regions + convertPointFieldBlock + ( + pfld, + output, + arrayRangeVolume_, + regionPolyDecomp_ + ); + + // Convert activated cellZones + convertPointFieldBlock + ( + pfld, + output, + arrayRangeCellZones_, + zonePolyDecomp_ + ); + + // Convert activated cellSets + convertPointFieldBlock + ( + pfld, + output, + arrayRangeCellSets_, + csetPolyDecomp_ + ); + + + // + // Convert patches - if activated + // + for + ( + int partId = arrayRangePatches_.start(); + partId < arrayRangePatches_.end(); + ++partId + ) + { + const word patchName = getPartName(partId); + const label datasetNo = partDataset_[partId]; + const label patchId = patches.findPatchID(patchName); + + if (!partStatus_[partId] || patchId < 0) + { + continue; + } + + vtkPolyData* vtkmesh = getDataFromBlock + ( + output, arrayRangePatches_, datasetNo + ); + + if (vtkmesh) + { + vtkFloatArray* pdata = convertFieldToVTK + ( + fieldName, + pfld.boundaryField()[patchId].patchInternalField()() + ); + + vtkmesh->GetPointData()->AddArray(pdata); + pdata->Delete(); + } + } + + // + // Convert faceZones - if activated + // + for + ( + int partId = arrayRangeFaceZones_.start(); + partId < arrayRangeFaceZones_.end(); + ++partId + ) + { + const word zoneName = getPartName(partId); + const label datasetNo = partDataset_[partId]; + const label zoneId = mesh.faceZones().findZoneID(zoneName); + + if (!partStatus_[partId] || zoneId < 0) + { + continue; + } + + vtkPolyData* vtkmesh = getDataFromBlock + ( + output, arrayRangeFaceZones_, datasetNo + ); + + if (vtkmesh) + { + // Extract the field on the zone + Field znfld + ( + pfld.primitiveField(), + mesh.faceZones()[zoneId]().meshPoints() + ); + + vtkFloatArray* pdata = convertFieldToVTK(fieldName, znfld); + + vtkmesh->GetPointData()->AddArray(pdata); + pdata->Delete(); + } + } + } +} + + +template +void Foam::vtkPVFoam::convertPointFieldBlock +( + const GeometricField& pfld, + vtkMultiBlockDataSet* output, + const arrayRange& range, + const List& decompLst +) +{ + for (int partId = range.start(); partId < range.end(); ++partId) + { + const label datasetNo = partDataset_[partId]; + + if (!partStatus_[partId]) + { + continue; + } + + vtkUnstructuredGrid* vtkmesh = getDataFromBlock + ( + output, range, datasetNo + ); + + if (vtkmesh) + { + convertPointField + ( + vtkmesh, + pfld, + GeometricField::null(), + decompLst[datasetNo] + ); + } + } +} + + +template +void Foam::vtkPVFoam::convertPointField +( + vtkUnstructuredGrid* vtkmesh, + const GeometricField& pfld, + const GeometricField& vfld, + const polyDecomp& decomp +) +{ + if (!vtkmesh) + { + return; + } + + const label nComp = pTraits::nComponents; + const labelUList& addPointCellLabels = decomp.addPointCellLabels(); + const labelUList& pointMap = decomp.pointMap(); + + // use a pointMap or address directly into mesh + const label nPoints = (pointMap.size() ? pointMap.size() : pfld.size()); + + vtkFloatArray* fldData = vtkFloatArray::New(); + fldData->SetNumberOfTuples(nPoints + addPointCellLabels.size()); + fldData->SetNumberOfComponents(nComp); + fldData->Allocate(nComp*(nPoints + addPointCellLabels.size())); + + // Note: using the name of the original volField + // not the name generated by the interpolation "volPointInterpolate()" + + if (&vfld != &GeometricField::null()) + { + fldData->SetName(vfld.name().c_str()); + } + else + { + fldData->SetName(pfld.name().c_str()); + } + + if (debug) + { + Info<< "convert Point field: " + << pfld.name() + << " size=" << (nPoints + addPointCellLabels.size()) + << " (" << nPoints << " + " << addPointCellLabels.size() + << ") nComp=" << nComp << endl; + } + + float vec[nComp]; + + if (pointMap.size()) + { + forAll(pointMap, i) + { + const Type& t = pfld[pointMap[i]]; + for (direction d=0; d(vec); + + fldData->InsertTuple(i, vec); + } + } + else + { + forAll(pfld, i) + { + const Type& t = pfld[i]; + for (direction d=0; d(vec); + + fldData->InsertTuple(i, vec); + } + } + + // continue insertion from here + label i = nPoints; + + if (&vfld != &GeometricField::null()) + { + forAll(addPointCellLabels, apI) + { + const Type& t = vfld[addPointCellLabels[apI]]; + for (direction d=0; d(vec); + + fldData->InsertTuple(i++, vec); + } + } + else + { + forAll(addPointCellLabels, apI) + { + Type t = interpolatePointToCell(pfld, addPointCellLabels[apI]); + for (direction d=0; d(vec); + + fldData->InsertTuple(i++, vec); + } + } + + vtkmesh->GetPointData()->AddArray(fldData); + fldData->Delete(); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// +// lagrangian-fields +// + +template +void Foam::vtkPVFoam::convertLagrangianFields +( + const IOobjectList& objects, + vtkMultiBlockDataSet* output, + const label datasetNo +) +{ + const arrayRange& range = arrayRangeLagrangian_; + + forAllConstIter(IOobjectList, objects, iter) + { + // restrict to this IOField + if (iter()->headerClassName() == IOField::typeName) + { + vtkPolyData* vtkmesh = + getDataFromBlock(output, range, datasetNo); + + if (vtkmesh) + { + IOField fld(*iter()); + + vtkFloatArray* fldData = convertFieldToVTK(fld.name(), fld); + vtkmesh->GetPointData()->AddArray(fldData); + fldData->Delete(); + } + } + } +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// +// low-level conversions +// + +template +vtkFloatArray* Foam::vtkPVFoam::convertFieldToVTK +( + const word& name, + const Field& fld +) +{ + if (debug) + { + Info<< "convert Field<" << pTraits::typeName << "> " + << name + << " size=" << fld.size() + << " nComp=" << label(pTraits::nComponents) << endl; + } + + const label nComp = pTraits::nComponents; + + vtkFloatArray* fldData = vtkFloatArray::New(); + fldData->SetNumberOfTuples(fld.size()); + fldData->SetNumberOfComponents(nComp); + fldData->Allocate(nComp*fld.size()); + fldData->SetName(name.c_str()); + + float vec[nComp]; + forAll(fld, i) + { + const Type& t = fld[i]; + for (direction d=0; d(vec); + + fldData->InsertTuple(i, vec); + } + + return fldData; +} + + +template +vtkFloatArray* Foam::vtkPVFoam::convertFaceFieldToVTK +( + const GeometricField& fld, + const labelUList& faceLabels +) +{ + if (debug) + { + Info<< "convert face field: " + << fld.name() + << " size=" << faceLabels.size() + << " nComp=" << label(pTraits::nComponents) << endl; + } + + const fvMesh& mesh = fld.mesh(); + + const label nComp = pTraits::nComponents; + const label nInternalFaces = mesh.nInternalFaces(); + const labelList& faceOwner = mesh.faceOwner(); + const labelList& faceNeigh = mesh.faceNeighbour(); + + vtkFloatArray* fldData = vtkFloatArray::New(); + fldData->SetNumberOfTuples(faceLabels.size()); + fldData->SetNumberOfComponents(nComp); + fldData->Allocate(nComp*faceLabels.size()); + fldData->SetName(fld.name().c_str()); + + float vec[nComp]; + + // for interior faces: average owner/neighbour + // for boundary faces: owner + forAll(faceLabels, facei) + { + const label faceNo = faceLabels[facei]; + if (faceNo < nInternalFaces) + { + Type t = 0.5*(fld[faceOwner[faceNo]] + fld[faceNeigh[faceNo]]); + + for (direction d=0; d(vec); + + fldData->InsertTuple(facei, vec); + } + + return fldData; +} + + +template +vtkFloatArray* Foam::vtkPVFoam::convertVolFieldToVTK +( + const GeometricField& fld, + const polyDecomp& decompInfo +) +{ + const label nComp = pTraits::nComponents; + const labelList& superCells = decompInfo.superCells(); + + vtkFloatArray* fldData = vtkFloatArray::New(); + fldData->SetNumberOfTuples(superCells.size()); + fldData->SetNumberOfComponents(nComp); + fldData->Allocate(nComp*superCells.size()); + fldData->SetName(fld.name().c_str()); + + if (debug) + { + Info<< "convert volField: " + << fld.name() + << " size=" << superCells.size() + << " (" << fld.size() << " + " + << (superCells.size() - fld.size()) + << ") nComp=" << nComp << endl; + } + + float vec[nComp]; + forAll(superCells, i) + { + const Type& t = fld[superCells[i]]; + for (direction d=0; d(vec); + + fldData->InsertTuple(i, vec); + } + + return fldData; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFields.C b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFields.C index 47d2c3aa07..880ca89a4f 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFields.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFields.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -26,6 +26,7 @@ License #include "vtkPVFoam.H" // OpenFOAM includes +#include "Cloud.H" #include "IOobjectList.H" #include "vtkPVFoamReader.h" @@ -34,29 +35,26 @@ License #include "vtkPolyData.h" #include "vtkUnstructuredGrid.h" +// Templates (only needed here) +#include "vtkPVFoamFieldTemplates.C" + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -#include "vtkPVFoamVolFields.H" -#include "vtkPVFoamPointFields.H" -#include "vtkPVFoamLagrangianFields.H" - - void Foam::vtkPVFoam::pruneObjectList ( IOobjectList& objects, - const wordHashSet& selected + const hashedWordList& retain ) { - // hash all the selected field names - if (selected.empty()) + if (retain.empty()) { objects.clear(); } - // only keep selected fields + // only retain specified fields forAllIter(IOobjectList, objects, iter) { - if (!selected.found(iter()->name())) + if (!retain.found(iter()->name())) { objects.erase(iter); } @@ -71,7 +69,8 @@ void Foam::vtkPVFoam::convertVolFields { const fvMesh& mesh = *meshPtr_; - wordHashSet selectedFields = getSelected + const bool interpFields = reader_->GetInterpolateVolFields(); + hashedWordList selectedFields = getSelected ( reader_->GetVolFieldSelection() ); @@ -93,80 +92,50 @@ void Foam::vtkPVFoam::convertVolFields if (debug) { - Info<< " Foam::vtkPVFoam::convertVolFields" << nl - << "converting OpenFOAM volume fields" << endl; + Info<< " convert volume fields" << endl; forAllConstIter(IOobjectList, objects, iter) { Info<< " " << iter()->name() - << " == " << iter()->objectPath() << nl; + << " == " << iter()->objectPath() << endl; } printMemory(); } - PtrList> - ppInterpList(mesh.boundaryMesh().size()); + PtrList interpLst; - forAll(ppInterpList, i) + if (interpFields) { - ppInterpList.set - ( - i, - new PrimitivePatchInterpolation + interpLst.setSize(mesh.boundaryMesh().size()); + + forAll(interpLst, i) + { + interpLst.set ( - mesh.boundaryMesh()[i] - ) - ); + i, + new PrimitivePatchInterpolation + ( + mesh.boundaryMesh()[i] + ) + ); + } } + convertVolFields(mesh, interpLst, objects, output); + convertVolFields(mesh, interpLst, objects, output); + convertVolFields(mesh, interpLst, objects, output); + convertVolFields(mesh, interpLst, objects, output); + convertVolFields(mesh, interpLst, objects, output); - bool interpFields = reader_->GetInterpolateVolFields(); - - convertVolFields - ( - mesh, ppInterpList, objects, interpFields, output - ); - convertVolFields - ( - mesh, ppInterpList, objects, interpFields, output - ); - convertVolFields - ( - mesh, ppInterpList, objects, interpFields, output - ); - convertVolFields - ( - mesh, ppInterpList, objects, interpFields, output - ); - convertVolFields - ( - mesh, ppInterpList, objects, interpFields, output - ); - - convertDimFields - ( - mesh, ppInterpList, objects, interpFields, output - ); - convertDimFields - ( - mesh, ppInterpList, objects, interpFields, output - ); - convertDimFields - ( - mesh, ppInterpList, objects, interpFields, output - ); - convertDimFields - ( - mesh, ppInterpList, objects, interpFields, output - ); - convertDimFields - ( - mesh, ppInterpList, objects, interpFields, output - ); + convertDimFields(mesh, interpLst, objects, output); + convertDimFields(mesh, interpLst, objects, output); + convertDimFields(mesh, interpLst, objects, output); + convertDimFields(mesh, interpLst, objects, output); + convertDimFields(mesh, interpLst, objects, output); if (debug) { - Info<< " Foam::vtkPVFoam::convertVolFields" << endl; + Info<< " convert volume fields" << endl; printMemory(); } } @@ -179,7 +148,7 @@ void Foam::vtkPVFoam::convertPointFields { const fvMesh& mesh = *meshPtr_; - wordHashSet selectedFields = getSelected + hashedWordList selectedFields = getSelected ( reader_->GetPointFieldSelection() ); @@ -205,12 +174,11 @@ void Foam::vtkPVFoam::convertPointFields if (debug) { - Info<< " Foam::vtkPVFoam::convertPointFields" << nl - << "converting OpenFOAM volume fields -> point fields" << endl; + Info<< " convert volume -> point fields" << endl; forAllConstIter(IOobjectList, objects, iter) { Info<< " " << iter()->name() - << " == " << iter()->objectPath() << nl; + << " == " << iter()->objectPath() << endl; } printMemory(); } @@ -218,31 +186,15 @@ void Foam::vtkPVFoam::convertPointFields // Construct interpolation on the raw mesh const pointMesh& pMesh = pointMesh::New(mesh); - - convertPointFields - ( - mesh, pMesh, objects, output - ); - convertPointFields - ( - mesh, pMesh, objects, output - ); - convertPointFields - ( - mesh, pMesh, objects, output - ); - convertPointFields - ( - mesh, pMesh, objects, output - ); - convertPointFields - ( - mesh, pMesh, objects, output - ); + convertPointFields(pMesh, objects, output); + convertPointFields(pMesh, objects, output); + convertPointFields(pMesh, objects, output); + convertPointFields(pMesh, objects, output); + convertPointFields(pMesh, objects, output); if (debug) { - Info<< " Foam::vtkPVFoam::convertPointFields" << endl; + Info<< " convert volume -> point fields" << endl; printMemory(); } } @@ -256,7 +208,7 @@ void Foam::vtkPVFoam::convertLagrangianFields arrayRange& range = arrayRangeLagrangian_; const fvMesh& mesh = *meshPtr_; - wordHashSet selectedFields = getSelected + hashedWordList selectedFields = getSelected ( reader_->GetLagrangianFieldSelection() ); @@ -268,7 +220,7 @@ void Foam::vtkPVFoam::convertLagrangianFields if (debug) { - Info<< " Foam::vtkPVFoam::convertLagrangianFields" << endl; + Info<< " convert Lagrangian fields" << endl; printMemory(); } @@ -282,7 +234,6 @@ void Foam::vtkPVFoam::convertLagrangianFields continue; } - // Get the Lagrangian fields for this time and this cloud // but only keep selected fields // the region name is already in the mesh db @@ -301,43 +252,25 @@ void Foam::vtkPVFoam::convertLagrangianFields if (debug) { - Info<< "converting OpenFOAM lagrangian fields" << nl; + Info<< "converting OpenFOAM lagrangian fields" << endl; forAllConstIter(IOobjectList, objects, iter) { Info<< " " << iter()->name() - << " == " << iter()->objectPath() << nl; + << " == " << iter()->objectPath() << endl; } } - convertLagrangianFields - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqFoamReaderControls.cxx b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqFoamReaderControls.cxx index 95c3002d74..3b6fe3da97 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqFoamReaderControls.cxx +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqFoamReaderControls.cxx @@ -30,7 +30,7 @@ License #include #include -#include "pqApplicationCore.h" +#include "pqPVApplicationCore.h" #include "pqPipelineRepresentation.h" #include "pqView.h" #include "vtkSMDocumentation.h" @@ -45,8 +45,7 @@ License static QAbstractButton* setButtonProperties ( QAbstractButton* b, - vtkSMIntVectorProperty* prop, - bool initChecked = true + vtkSMProperty* prop ) { QString tip; @@ -68,10 +67,13 @@ static QAbstractButton* setButtonProperties } b->setFocusPolicy(Qt::NoFocus); // avoid dotted border - // initial checked state - if (initChecked) + vtkSMIntVectorProperty* intProp = + vtkSMIntVectorProperty::SafeDownCast(prop); + + // initial checked state for integer (bool) properties + if (intProp) { - b->setChecked(prop->GetElement(0)); + b->setChecked(intProp->GetElement(0)); } return b; @@ -97,19 +99,27 @@ static vtkSMIntVectorProperty* lookupIntProp // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void pqFoamReaderControls::updatePartsStatus() +void pqFoamReaderControls::fireCommand +( + vtkSMIntVectorProperty* prop, + bool checked +) { - vtkSMProperty* prop = this->proxy()->GetProperty("PartArrayStatus"); - if (prop) - { - this->proxy()->UpdatePropertyInformation(prop); - } + vtkSMProxy* pxy = this->proxy(); + + prop->SetElement(0, checked); // Toogle bool + + // Fire off command + prop->Modified(); + pxy->UpdateProperty(pxy->GetPropertyName(prop)); } -void pqFoamReaderControls::updatePartsStatus(bool) +void pqFoamReaderControls::updateParts() { - updatePartsStatus(); + vtkSMProxy* pxy = this->proxy(); + + pxy->UpdatePropertyInformation(pxy->GetProperty("PartArrayStatus")); } @@ -117,25 +127,28 @@ void pqFoamReaderControls::updatePartsStatus(bool) void pqFoamReaderControls::refreshPressed() { - // Update everything + vtkSMProxy* pxy = this->proxy(); + + // Fire off command refresh_->Modified(); + pxy->UpdateProperty(pxy->GetPropertyName(refresh_)); - vtkSMSourceProxy::SafeDownCast(this->proxy())->UpdatePipeline(); + vtkSMSourceProxy::SafeDownCast(pxy)->UpdatePipeline(); - // Update all views - pqApplicationCore::instance()->render(); + // Trigger a rendering (all views) + pqPVApplicationCore::instance()->render(); } void pqFoamReaderControls::cacheMesh(bool checked) { - cacheMesh_->SetElement(0, checked); + fireCommand(cacheMesh_, checked); } void pqFoamReaderControls::showPatchNames(bool checked) { - showPatchNames_->SetElement(0, checked); + fireCommand(showPatchNames_, checked); // update the active view if (this->view()) @@ -143,28 +156,28 @@ void pqFoamReaderControls::showPatchNames(bool checked) this->view()->render(); } // OR: update all views - // pqApplicationCore::instance()->render(); + // pqPVApplicationCore::instance()->render(); } void pqFoamReaderControls::showGroupsOnly(bool checked) { - showGroupsOnly_->SetElement(0, checked); - updatePartsStatus(); + fireCommand(showGroupsOnly_, checked); + updateParts(); } void pqFoamReaderControls::includeSets(bool checked) { - includeSets_->SetElement(0, checked); - updatePartsStatus(); + fireCommand(includeSets_, checked); + updateParts(); } void pqFoamReaderControls::includeZones(bool checked) { - includeZones_->SetElement(0, checked); - updatePartsStatus(); + fireCommand(includeZones_, checked); + updateParts(); } @@ -178,7 +191,7 @@ pqFoamReaderControls::pqFoamReaderControls ) : Superclass(proxy, parent), - refresh_(lookupIntProp(group, "Refresh")), + refresh_(group->GetProperty("Refresh")), showPatchNames_(lookupIntProp(group, "ShowPatchNames")), showGroupsOnly_(lookupIntProp(group, "ShowGroupsOnly")), includeSets_(lookupIntProp(group, "IncludeSets")), @@ -196,11 +209,10 @@ pqFoamReaderControls::pqFoamReaderControls if (refresh_) { QPushButton* b = new QPushButton(this); - setButtonProperties(b, refresh_, false); + setButtonProperties(b, refresh_); form->addWidget(b, row, 0, Qt::AlignLeft); connect(b, SIGNAL(clicked()), this, SLOT(refreshPressed())); - refresh_->SetImmediateUpdate(true); } intProp* zeroTime = lookupIntProp(group, "ZeroTime"); @@ -233,9 +245,7 @@ pqFoamReaderControls::pqFoamReaderControls form->addWidget(b, row, 0, Qt::AlignLeft); addPropertyLink(b, "checked", SIGNAL(toggled(bool)), includeSets_); - connect(b, SIGNAL(toggled(bool)), this, SLOT(includeSets(bool))); - includeSets_->SetImmediateUpdate(true); } if (showGroupsOnly_) @@ -245,9 +255,7 @@ pqFoamReaderControls::pqFoamReaderControls form->addWidget(b, row, 1, Qt::AlignLeft); addPropertyLink(b, "checked", SIGNAL(toggled(bool)), showGroupsOnly_); - connect(b, SIGNAL(toggled(bool)), this, SLOT(showGroupsOnly(bool))); - showGroupsOnly_->SetImmediateUpdate(true); } @@ -262,9 +270,7 @@ pqFoamReaderControls::pqFoamReaderControls form->addWidget(b, row, 0, Qt::AlignLeft); addPropertyLink(b, "checked", SIGNAL(toggled(bool)), includeZones_); - connect(b, SIGNAL(toggled(bool)), this, SLOT(includeZones(bool))); - includeZones_->SetImmediateUpdate(true); } if (showPatchNames_) @@ -274,7 +280,6 @@ pqFoamReaderControls::pqFoamReaderControls form->addWidget(b, row, 1, Qt::AlignLeft); connect(b, SIGNAL(toggled(bool)), this, SLOT(showPatchNames(bool))); - showPatchNames_->SetImmediateUpdate(true); } // LINE @@ -327,7 +332,7 @@ pqFoamReaderControls::pqFoamReaderControls if (updateGui) { QPushButton* b = new QPushButton(this); - setButtonProperties(b, updateGui, false); + setButtonProperties(b, updateGui); form->addWidget(b, row, 0, Qt::AlignLeft); addPropertyLink(b, "checked", SIGNAL(clicked()), updateGui); @@ -350,7 +355,6 @@ pqFoamReaderControls::pqFoamReaderControls form->addWidget(b, row, 2, Qt::AlignLeft); connect(b, SIGNAL(toggled(bool)), this, SLOT(cacheMesh(bool))); - cacheMesh_->SetImmediateUpdate(true); } } diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqFoamReaderControls.h b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqFoamReaderControls.h index dd958f5e8c..fc3c8d4044 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqFoamReaderControls.h +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqFoamReaderControls.h @@ -37,6 +37,7 @@ SourceFiles #include "pqPropertyWidget.h" // Forward declarations +class vtkSMProperty; class vtkSMIntVectorProperty; @@ -53,8 +54,8 @@ class pqFoamReaderControls // Private data - //- Refresh (bool property - as push button) - vtkSMIntVectorProperty* refresh_; + //- Refresh (push button) + vtkSMProperty* refresh_; //- Show Patch Names (bool property) vtkSMIntVectorProperty* showPatchNames_; @@ -72,15 +73,28 @@ class pqFoamReaderControls vtkSMIntVectorProperty* cacheMesh_; + // Private Member Functions + + //- Update property + void fireCommand(vtkSMProperty* prop); + + //- Toggle and update bool property + void fireCommand(vtkSMIntVectorProperty* prop, bool checked); + + + //- Disallow default bitwise copy construct + pqFoamReaderControls(const pqFoamReaderControls&) = delete; + + //- Disallow default bitwise assignment + void operator=(const pqFoamReaderControls&) = delete; + + private slots: // Private Member Functions //- Update "PartArrayStatus" property information - void updatePartsStatus(); - - //- Update "PartArrayStatus" property information - void updatePartsStatus(bool unused); + void updateParts(); protected slots: diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.cxx b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.cxx index ecfffe09e2..46c01d92f7 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.cxx +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.cxx @@ -80,7 +80,6 @@ vtkPVFoamReader::vtkPVFoamReader() TimeStepRange[1] = 0; CacheMesh = true; - Refresh = false; SkipZeroTime = false; ExtrapolatePatches = false; @@ -138,9 +137,11 @@ vtkPVFoamReader::~vtkPVFoamReader() if (backend_) { - // remove patch names + // Remove text actors updatePatchNamesView(false); + delete backend_; + backend_ = nullptr; } if (FileName) @@ -202,13 +203,13 @@ int vtkPVFoamReader::RequestInformation } } - if (!backend_) + if (backend_) { - backend_ = new Foam::vtkPVFoam(FileName, this); + backend_->updateInfo(); } else { - backend_->updateInfo(); + backend_ = new Foam::vtkPVFoam(FileName, this); } std::vector times = backend_->findTimes(this->SkipZeroTime); @@ -450,7 +451,7 @@ void vtkPVFoamReader::PrintInfo() } -void vtkPVFoamReader::SetRefresh(bool val) +void vtkPVFoamReader::Refresh() { Modified(); } diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.h b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.h index 28a68445cd..c634f667fb 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.h +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.h @@ -88,7 +88,7 @@ public: // Description: // OpenFOAM refresh times/fields - virtual void SetRefresh(bool); + virtual void Refresh(); // Description: // OpenFOAM skip/include the 0/ time directory @@ -231,7 +231,6 @@ private: void updatePatchNamesView(const bool show); int TimeStepRange[2]; - bool Refresh; bool CacheMesh; bool SkipZeroTime; diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.C b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.C index 9ec5d92e71..2b7ab51888 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.C @@ -45,6 +45,35 @@ namespace Foam defineTypeNameAndDebug(vtkPVFoam, 0); } + +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +vtkTextActor* Foam::vtkPVFoam::createTextActor +( + const string& s, + const point& pt +) +{ + vtkTextActor* txt = vtkTextActor::New(); + txt->SetInput(s.c_str()); + + // Set text properties + vtkTextProperty* tprop = txt->GetTextProperty(); + tprop->SetFontFamilyToArial(); + tprop->BoldOn(); + tprop->ShadowOff(); + tprop->SetLineSpacing(1.0); + tprop->SetFontSize(14); + tprop->SetColor(1.0, 0.0, 1.0); + tprop->SetJustificationToCentered(); + + txt->GetPositionCoordinate()->SetCoordinateSystemToWorld(); + txt->GetPositionCoordinate()->SetValue(pt.x(), pt.y(), pt.z()); + + return txt; +} + + // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // void Foam::vtkPVFoam::resetCounters() @@ -606,11 +635,6 @@ void Foam::vtkPVFoam::renderPatchNames const bool show ) { - if (!meshPtr_) - { - return; - } - // always remove old actors first forAll(patchTextActorsPtrs_, patchi) @@ -620,7 +644,7 @@ void Foam::vtkPVFoam::renderPatchNames } patchTextActorsPtrs_.clear(); - if (show) + if (show && meshPtr_) { // get the display patches, strip off any suffix hashedWordList selectedPatches = getSelected @@ -737,17 +761,16 @@ void Foam::vtkPVFoam::renderPatchNames { const polyPatch& pp = pbMesh[patchi]; - label globalZoneI = 0; - // Only selected patches will have a non-zero number of zones - label nDisplayZones = min(MAXPATCHZONES, nZones[patchi]); + const label nDisplayZones = min(MAXPATCHZONES, nZones[patchi]); label increment = 1; if (nZones[patchi] >= MAXPATCHZONES) { increment = nZones[patchi]/MAXPATCHZONES; } - for (label i = 0; i < nDisplayZones; i++) + label globalZoneI = 0; + for (label i = 0; i < nDisplayZones; ++i, globalZoneI += increment) { if (debug) { @@ -756,45 +779,24 @@ void Foam::vtkPVFoam::renderPatchNames << "globalZoneI = " << globalZoneI << endl; } - vtkTextActor* txt = vtkTextActor::New(); - - txt->SetInput(pp.name().c_str()); - - // Set text properties - vtkTextProperty* tprop = txt->GetTextProperty(); - tprop->SetFontFamilyToArial(); - tprop->BoldOff(); - tprop->ShadowOff(); - tprop->SetLineSpacing(1.0); - tprop->SetFontSize(14); - tprop->SetColor(1.0, 0.0, 1.0); - tprop->SetJustificationToCentered(); - - // Set text to use 3-D world co-ordinates - txt->GetPositionCoordinate()->SetCoordinateSystemToWorld(); - - txt->GetPositionCoordinate()->SetValue + // Into a list for later removal + patchTextActorsPtrs_[displayZoneI++] = createTextActor ( - zoneCentre[patchi][globalZoneI].x(), - zoneCentre[patchi][globalZoneI].y(), - zoneCentre[patchi][globalZoneI].z() + pp.name(), + zoneCentre[patchi][globalZoneI] ); - - // Add text to each renderer - renderer->AddViewProp(txt); - - // Maintain a list of text labels added so that they can be - // removed later - patchTextActorsPtrs_[displayZoneI] = txt; - - globalZoneI += increment; - displayZoneI++; } } // Resize the patch names list to the actual number of patch names added patchTextActorsPtrs_.setSize(displayZoneI); } + + // Add text to each renderer + forAll(patchTextActorsPtrs_, actori) + { + renderer->AddViewProp(patchTextActorsPtrs_[actori]); + } } diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.H b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.H index 17322e44c7..3f0a1ad55d 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.H +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.H @@ -223,6 +223,9 @@ class vtkPVFoam // Private Member Functions + //- Create a text actor + static vtkTextActor* createTextActor(const string& s, const point& pt); + //- Reset data counters void resetCounters(); diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/PVblockMeshReader_SM.xml b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/PVblockMeshReader_SM.xml index e782c4371f..e0110552ee 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/PVblockMeshReader_SM.xml +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/PVblockMeshReader_SM.xml @@ -14,20 +14,32 @@ The filename for the OpenFOAM blockMesh reader. - - + + Rescan for updated blockMeshDict. + + + + + + - Rescan for updated blockMeshDict. + Show patch names in render window. Show point numbers in render window. - + + + + + + + The list of curved edges - - - - - - - - - @@ -106,6 +111,12 @@ + + + + diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqFoamBlockMeshControls.cxx b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqFoamBlockMeshControls.cxx index 911ad83988..ab4a651706 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqFoamBlockMeshControls.cxx +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqFoamBlockMeshControls.cxx @@ -29,7 +29,7 @@ License #include #include -#include "pqApplicationCore.h" +#include "pqPVApplicationCore.h" #include "pqView.h" #include "vtkSMDocumentation.h" #include "vtkSMIntVectorProperty.h" @@ -43,8 +43,7 @@ License static QAbstractButton* setButtonProperties ( QAbstractButton* b, - vtkSMIntVectorProperty* prop, - bool initChecked = true + vtkSMProperty* prop ) { QString tip; @@ -66,10 +65,14 @@ static QAbstractButton* setButtonProperties } b->setFocusPolicy(Qt::NoFocus); // avoid dotted border - // initial checked state - if (initChecked) + + vtkSMIntVectorProperty* intProp = + vtkSMIntVectorProperty::SafeDownCast(prop); + + // initial checked state for integer (bool) properties + if (intProp) { - b->setChecked(prop->GetElement(0)); + b->setChecked(intProp->GetElement(0)); } return b; @@ -93,23 +96,61 @@ static vtkSMIntVectorProperty* lookupIntProp } +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void pqFoamBlockMeshControls::fireCommand(vtkSMProperty* prop) +{ + vtkSMProxy* pxy = this->proxy(); + + // Fire off command + prop->Modified(); + pxy->UpdateProperty(pxy->GetPropertyName(prop)); +} + + +void pqFoamBlockMeshControls::fireCommand +( + vtkSMIntVectorProperty* prop, + bool checked +) +{ + vtkSMProxy* pxy = this->proxy(); + + prop->SetElement(0, checked); // Toogle bool + + // Fire off command + prop->Modified(); + pxy->UpdateProperty(pxy->GetPropertyName(prop)); +} + + +void pqFoamBlockMeshControls::updateParts() +{ + vtkSMProxy* pxy = this->proxy(); + + pxy->UpdatePropertyInformation(pxy->GetProperty("BlockArrayStatus")); + pxy->UpdatePropertyInformation(pxy->GetProperty("CurvedEdgesArrayStatus")); +} + + // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // void pqFoamBlockMeshControls::refreshPressed() { - // Update everything - refresh_->Modified(); + fireCommand(refresh_); vtkSMSourceProxy::SafeDownCast(this->proxy())->UpdatePipeline(); - // Render all views - pqApplicationCore::instance()->render(); + // Trigger a rendering (all views) + pqPVApplicationCore::instance()->render(); + + updateParts(); } -void pqFoamBlockMeshControls::showPointNumbers(bool checked) +void pqFoamBlockMeshControls::showPatchNames(bool checked) { - showPointNumbers_->SetElement(0, checked); + fireCommand(showPatchNames_, checked); // Update the active view if (this->view()) @@ -118,7 +159,22 @@ void pqFoamBlockMeshControls::showPointNumbers(bool checked) } // OR: update all views - // pqApplicationCore::instance()->render(); + // pqPVApplicationCore::instance()->render(); +} + + +void pqFoamBlockMeshControls::showPointNumbers(bool checked) +{ + fireCommand(showPointNumbers_, checked); + + // Update the active view + if (this->view()) + { + this->view()->render(); + } + + // OR: update all views + // pqPVApplicationCore::instance()->render(); } @@ -132,7 +188,8 @@ pqFoamBlockMeshControls::pqFoamBlockMeshControls ) : Superclass(proxy, parent), - refresh_(lookupIntProp(group, "Refresh")), + refresh_(group->GetProperty("Refresh")), + showPatchNames_(lookupIntProp(group, "ShowPatchNames")), showPointNumbers_(lookupIntProp(group, "ShowPointNumbers")) { QGridLayout* form = new QGridLayout(this); @@ -140,21 +197,28 @@ pqFoamBlockMeshControls::pqFoamBlockMeshControls if (refresh_) { QPushButton* b = new QPushButton(this); - setButtonProperties(b, refresh_, false); + setButtonProperties(b, refresh_); form->addWidget(b, 0, 0, Qt::AlignLeft); connect(b, SIGNAL(clicked()), this, SLOT(refreshPressed())); - refresh_->SetImmediateUpdate(true); + } + + if (showPatchNames_) + { + QCheckBox* b = new QCheckBox(this); + setButtonProperties(b, showPatchNames_); + form->addWidget(b, 0, 1, Qt::AlignLeft); + + connect(b, SIGNAL(toggled(bool)), this, SLOT(showPatchNames(bool))); } if (showPointNumbers_) { QCheckBox* b = new QCheckBox(this); setButtonProperties(b, showPointNumbers_); - form->addWidget(b, 0, 1, Qt::AlignLeft); + form->addWidget(b, 0, 2, Qt::AlignLeft); connect(b, SIGNAL(toggled(bool)), this, SLOT(showPointNumbers(bool))); - showPointNumbers_->SetImmediateUpdate(true); } } diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqFoamBlockMeshControls.h b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqFoamBlockMeshControls.h index 0ec7150d5c..a46cdc3052 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqFoamBlockMeshControls.h +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqFoamBlockMeshControls.h @@ -27,7 +27,7 @@ Class Description Customized property controls for the ParaView blockMesh reader. - Refresh and ShowPointNumbers. + Refresh, ShowPatchNames, ShowPointNumbers. SourceFiles pqFoamBlockMeshControls.cxx @@ -39,6 +39,7 @@ SourceFiles #include "pqPropertyWidget.h" // Forward declarations (ParaView) +class vtkSMProperty; class vtkSMIntVectorProperty; @@ -55,8 +56,11 @@ class pqFoamBlockMeshControls // Private data - //- Refresh (bool property - as push button) - vtkSMIntVectorProperty* refresh_; + //- Refresh (push button) + vtkSMProperty* refresh_; + + //- Show Patch Names (bool property) + vtkSMIntVectorProperty* showPatchNames_; //- Show Point Numbers (bool property) vtkSMIntVectorProperty* showPointNumbers_; @@ -64,6 +68,16 @@ class pqFoamBlockMeshControls // Private Member Functions + //- Update property + void fireCommand(vtkSMProperty* prop); + + //- Toggle and update bool property + void fireCommand(vtkSMIntVectorProperty* prop, bool checked); + + //- Update "BlockArrayStatus", "CurvedEdgesArrayStatus" information + void updateParts(); + + //- Disallow default bitwise copy construct pqFoamBlockMeshControls(const pqFoamBlockMeshControls&) = delete; @@ -78,6 +92,9 @@ protected slots: //- Trigger refresh void refreshPressed(); + //- Sync property with changed checkbox state, update rendered view(s) + void showPatchNames(bool checked); + //- Sync property with changed checkbox state, update rendered view(s) void showPointNumbers(bool checked); diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/vtkPVblockMeshReader.cxx b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/vtkPVblockMeshReader.cxx index 51f2fd8061..2c8c1ce453 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/vtkPVblockMeshReader.cxx +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/vtkPVblockMeshReader.cxx @@ -59,6 +59,7 @@ vtkPVblockMeshReader::vtkPVblockMeshReader() FileName = nullptr; backend_ = nullptr; + ShowPatchNames = false; ShowPointNumbers = true; BlockSelection = vtkDataArraySelection::New(); @@ -95,9 +96,12 @@ vtkPVblockMeshReader::~vtkPVblockMeshReader() if (backend_) { - // Remove point numbers + // Remove text actors + updatePatchNamesView(false); updatePointNumbersView(false); + delete backend_; + backend_ = nullptr; } if (FileName) @@ -110,6 +114,7 @@ vtkPVblockMeshReader::~vtkPVblockMeshReader() SelectionObserver->Delete(); BlockSelection->Delete(); + CurvedEdgesSelection->Delete(); } @@ -124,35 +129,25 @@ int vtkPVblockMeshReader::RequestInformation { vtkDebugMacro(<<"RequestInformation"); - if (Foam::vtkPVblockMesh::debug) - { - cout<<"REQUEST_INFORMATION\n"; - } - if (!FileName) { vtkErrorMacro("FileName has to be specified!"); return 0; } - int nInfo = outputVector->GetNumberOfInformationObjects(); - if (Foam::vtkPVblockMesh::debug) { - cout<<"RequestInformation with " << nInfo << " item(s)\n"; - for (int infoI = 0; infoI < nInfo; ++infoI) - { - outputVector->GetInformationObject(infoI)->Print(cout); - } + cout<<"REQUEST_INFORMATION\n"; + outputVector->GetInformationObject(0)->Print(cout); } - if (!backend_) + if (backend_) { - backend_ = new Foam::vtkPVblockMesh(FileName, this); + backend_->updateInfo(); } else { - backend_->updateInfo(); + backend_ = new Foam::vtkPVblockMesh(FileName, this); } return 1; @@ -181,15 +176,10 @@ int vtkPVblockMeshReader::RequestData return 0; } - int nInfo = outputVector->GetNumberOfInformationObjects(); - if (Foam::vtkPVblockMesh::debug) { - cout<<"RequestData with " << nInfo << " item(s)\n"; - for (int infoI = 0; infoI < nInfo; ++infoI) - { - outputVector->GetInformationObject(infoI)->Print(cout); - } + cout<<"REQUEST_DATA:\n"; + outputVector->GetInformationObject(0)->Print(cout); } vtkMultiBlockDataSet* output = vtkMultiBlockDataSet::SafeDownCast @@ -207,6 +197,8 @@ int vtkPVblockMeshReader::RequestData } backend_->Update(output); + + updatePatchNamesView(ShowPatchNames); updatePointNumbersView(ShowPointNumbers); // Do any cleanup on the OpenFOAM side @@ -216,17 +208,30 @@ int vtkPVblockMeshReader::RequestData } -void vtkPVblockMeshReader::SetRefresh(bool val) +void vtkPVblockMeshReader::Refresh() { // Delete the current blockMesh to force re-read and update if (backend_) { + // Remove text actors + updatePatchNamesView(false); updatePointNumbersView(false); + delete backend_; backend_ = nullptr; } - Modified(); + this->Modified(); +} + + +void vtkPVblockMeshReader::SetShowPatchNames(bool val) +{ + if (ShowPatchNames != val) + { + ShowPatchNames = val; + updatePatchNamesView(ShowPatchNames); + } } @@ -240,6 +245,38 @@ void vtkPVblockMeshReader::SetShowPointNumbers(bool val) } +void vtkPVblockMeshReader::updatePatchNamesView(const bool show) +{ + pqApplicationCore* appCore = pqApplicationCore::instance(); + + // Need to check this, since our destructor calls this + if (!appCore) + { + return; + } + + // Server manager model for querying items in the server manager + pqServerManagerModel* smModel = appCore->getServerManagerModel(); + if (!smModel || !backend_) + { + return; + } + + // Get all the pqRenderView instances + QList renderViews = smModel->findItems(); + for (int viewI=0; viewIrenderPatchNames + ( + renderViews[viewI]->getRenderViewProxy()->GetRenderer(), + show + ); + } + + // Use refresh here? +} + + void vtkPVblockMeshReader::updatePointNumbersView(const bool show) { pqApplicationCore* appCore = pqApplicationCore::instance(); @@ -257,7 +294,6 @@ void vtkPVblockMeshReader::updatePointNumbersView(const bool show) return; } - // Get all the pqRenderView instances QList renderViews = smModel->findItems(); for (int viewI=0; viewIGetNumberOfArrays(); } - const char* vtkPVblockMeshReader::GetBlockArrayName(int index) { - vtkDebugMacro(<<"GetBlockArrayName"); return BlockSelection->GetArrayName(index); } - int vtkPVblockMeshReader::GetBlockArrayStatus(const char* name) { - vtkDebugMacro(<<"GetBlockArrayStatus"); return BlockSelection->ArrayIsEnabled(name); } - void vtkPVblockMeshReader::SetBlockArrayStatus ( const char* name, int status ) { - vtkDebugMacro(<<"SetBlockArrayStatus"); if (status) { BlockSelection->EnableArray(name); @@ -339,39 +366,30 @@ void vtkPVblockMeshReader::SetBlockArrayStatus vtkDataArraySelection* vtkPVblockMeshReader::GetCurvedEdgesSelection() { - vtkDebugMacro(<<"GetCurvedEdgesSelection"); return CurvedEdgesSelection; } - int vtkPVblockMeshReader::GetNumberOfCurvedEdgesArrays() { - vtkDebugMacro(<<"GetNumberOfCurvedEdgesArrays"); return CurvedEdgesSelection->GetNumberOfArrays(); } - const char* vtkPVblockMeshReader::GetCurvedEdgesArrayName(int index) { - vtkDebugMacro(<<"GetCurvedEdgesArrayName"); return CurvedEdgesSelection->GetArrayName(index); } - int vtkPVblockMeshReader::GetCurvedEdgesArrayStatus(const char* name) { - vtkDebugMacro(<<"GetCurvedEdgesArrayStatus"); return CurvedEdgesSelection->ArrayIsEnabled(name); } - void vtkPVblockMeshReader::SetCurvedEdgesArrayStatus ( const char* name, int status ) { - vtkDebugMacro(<<"SetCurvedEdgesArrayStatus"); if (status) { CurvedEdgesSelection->EnableArray(name); diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/vtkPVblockMeshReader.h b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/vtkPVblockMeshReader.h index 1cb24d7baf..66805716ee 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/vtkPVblockMeshReader.h +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/vtkPVblockMeshReader.h @@ -71,6 +71,11 @@ public: vtkSetStringMacro(FileName); vtkGetStringMacro(FileName); + // Description: + // Display patch names + virtual void SetShowPatchNames(bool); + vtkGetMacro(ShowPatchNames, bool); + // Description: // Display corner point labels virtual void SetShowPointNumbers(bool); @@ -78,22 +83,22 @@ public: // Description: // Refresh blockMesh from changes to blockMeshDict - virtual void SetRefresh(bool); + virtual void Refresh(); // Description: // Blocks selection list control vtkDataArraySelection* GetBlockSelection(); int GetNumberOfBlockArrays(); - int GetBlockArrayStatus(const char*); - void SetBlockArrayStatus(const char*, int status); + int GetBlockArrayStatus(const char* name); + void SetBlockArrayStatus(const char* name, int status); const char* GetBlockArrayName(int index); // Description: // CurvedEdges selection list control vtkDataArraySelection* GetCurvedEdgesSelection(); int GetNumberOfCurvedEdgesArrays(); - int GetCurvedEdgesArrayStatus(const char*); - void SetCurvedEdgesArrayStatus(const char*, int status); + int GetCurvedEdgesArrayStatus(const char* name); + void SetCurvedEdgesArrayStatus(const char* name, int status); const char* GetCurvedEdgesArrayName(int index); // Description: @@ -119,17 +124,17 @@ protected: //- Return information about mesh, times, etc without loading anything virtual int RequestInformation ( - vtkInformation*, - vtkInformationVector**, - vtkInformationVector* + vtkInformation* unusedRequest, + vtkInformationVector** unusedInputVector, + vtkInformationVector* outputVector ); - //- Get the mesh/fields for a particular time + //- Get the mesh for a particular time virtual int RequestData ( - vtkInformation*, - vtkInformationVector**, - vtkInformationVector* + vtkInformation* unusedRequest, + vtkInformationVector** unusedInputVector, + vtkInformationVector* outputVector ); //- Fill in additional port information @@ -149,15 +154,20 @@ private: //- Disallow default bitwise assignment void operator=(const vtkPVblockMeshReader&) = delete; + //- Add/remove patch names to/from the view + void updatePatchNamesView(const bool show); + //- Add/remove point numbers to/from the view void updatePointNumbersView(const bool show); + //- Show Patch Names + bool ShowPatchNames; + //- Show Point Numbers bool ShowPointNumbers; vtkDataArraySelection* BlockSelection; - vtkDataArraySelection* CurvedEdgesSelection; //- Backend portion of the reader diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMesh.C b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMesh.C index 4dee4f8953..e64f031dec 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMesh.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMesh.C @@ -28,6 +28,7 @@ License // OpenFOAM includes #include "blockMesh.H" +#include "blockMeshTools.H" #include "Time.H" #include "patchZones.H" #include "OStringStream.H" @@ -47,6 +48,34 @@ namespace Foam } +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +vtkTextActor* Foam::vtkPVblockMesh::createTextActor +( + const string& s, + const point& pt +) +{ + vtkTextActor* txt = vtkTextActor::New(); + txt->SetInput(s.c_str()); + + // Set text properties + vtkTextProperty* tprop = txt->GetTextProperty(); + tprop->SetFontFamilyToArial(); + tprop->BoldOn(); + tprop->ShadowOff(); + tprop->SetLineSpacing(1.0); + tprop->SetFontSize(14); + tprop->SetColor(1.0, 0.0, 1.0); + tprop->SetJustificationToCentered(); + + txt->GetPositionCoordinate()->SetCoordinateSystemToWorld(); + txt->GetPositionCoordinate()->SetValue(pt.x(), pt.y(), pt.z()); + + return txt; +} + + // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // void Foam::vtkPVblockMesh::resetCounters() @@ -60,7 +89,7 @@ void Foam::vtkPVblockMesh::resetCounters() void Foam::vtkPVblockMesh::updateInfoBlocks ( - vtkDataArraySelection* arraySelection + vtkDataArraySelection* select ) { arrayRange& range = arrayRangeBlocks_; @@ -71,7 +100,7 @@ void Foam::vtkPVblockMesh::updateInfoBlocks << " [meshPtr=" << (meshPtr_ ? "set" : "null") << "]" << endl; } - range.reset(arraySelection->GetNumberOfArrays()); + range.reset(select->GetNumberOfArrays()); const blockMesh& blkMesh = *meshPtr_; @@ -92,7 +121,7 @@ void Foam::vtkPVblockMesh::updateInfoBlocks } // Add "blockId" or "blockId - zoneName" to GUI list - arraySelection->AddArray(ostr.str().c_str()); + select->AddArray(ostr.str().c_str()); } range += nBlocks; @@ -106,7 +135,7 @@ void Foam::vtkPVblockMesh::updateInfoBlocks void Foam::vtkPVblockMesh::updateInfoEdges ( - vtkDataArraySelection* arraySelection + vtkDataArraySelection* select ) { arrayRange& range = arrayRangeEdges_; @@ -117,7 +146,7 @@ void Foam::vtkPVblockMesh::updateInfoEdges << " [meshPtr=" << (meshPtr_ ? "set" : "null") << "]" << endl; } - range.reset(arraySelection->GetNumberOfArrays()); + range.reset(select->GetNumberOfArrays()); const blockMesh& blkMesh = *meshPtr_; const blockEdgeList& edges = blkMesh.edges(); @@ -131,7 +160,7 @@ void Foam::vtkPVblockMesh::updateInfoEdges ostr << " - " << edges[edgeI].type(); // Add "beg:end - type" to GUI list - arraySelection->AddArray(ostr.str().c_str()); + select->AddArray(ostr.str().c_str()); } range += edges.size(); @@ -251,14 +280,6 @@ Foam::vtkPVblockMesh::~vtkPVblockMesh() Info<< "~vtkPVblockMesh" << endl; } - // Hmm. pointNumberTextActors are not getting removed - // - forAll(pointNumberTextActorsPtrs_, pointi) - { - pointNumberTextActorsPtrs_[pointi]->Delete(); - } - pointNumberTextActorsPtrs_.clear(); - delete meshPtr_; } @@ -411,6 +432,103 @@ void Foam::vtkPVblockMesh::CleanUp() } +void Foam::vtkPVblockMesh::renderPatchNames +( + vtkRenderer* renderer, + const bool show +) +{ + // always remove old actors first + forAll(patchTextActorsPtrs_, actori) + { + renderer->RemoveViewProp(patchTextActorsPtrs_[actori]); + patchTextActorsPtrs_[actori]->Delete(); + } + patchTextActorsPtrs_.clear(); + + // the number of text actors + label nActors = 0; + + if (show && meshPtr_) + { + const blockMesh& blkMesh = *meshPtr_; + const dictionary& meshDescription = blkMesh.meshDict(); + const pointField& cornerPts = blkMesh.vertices(); + const scalar scaleFactor = blkMesh.scaleFactor(); + + if (!meshDescription.found("boundary")) + { + return; + } + + // 8 sides per block is plenty + patchTextActorsPtrs_.setSize(8*blkMesh.size()); + + // Collect all variables + dictionary varDict(meshDescription.subOrEmptyDict("namedVertices")); + varDict.merge(meshDescription.subOrEmptyDict("namedBlocks")); + + // Read like boundary file + const PtrList patchesInfo(meshDescription.lookup("boundary")); + + forAll(patchesInfo, patchi) + { + const entry& patchInfo = patchesInfo[patchi]; + + if (!patchInfo.isDict()) + { + IOWarningInFunction(meshDescription) + << "Entry " << patchInfo << " in boundary section is not a" + << " valid dictionary." + << endl; + break; + } + + const word& patchName = patchInfo.keyword(); + + // Read block faces + faceList patchFaces = blockMeshTools::read + ( + patchInfo.dict().lookup("faces"), + varDict + ); + + forAll(patchFaces, facei) + { + const face& f = patchFaces[facei]; + + // Into a list for later removal + patchTextActorsPtrs_[nActors++] = createTextActor + ( + patchName, + f.centre(cornerPts) * scaleFactor + ); + + if (nActors == patchTextActorsPtrs_.size()) + { + // hit max allocated space - bail out + break; + } + } + + if (nActors == patchTextActorsPtrs_.size()) + { + // hit max allocated space - bail out + break; + } + } + + patchTextActorsPtrs_.setSize(nActors); + } + + // Add text to each renderer + forAll(patchTextActorsPtrs_, actori) + { + renderer->AddViewProp(patchTextActorsPtrs_[actori]); + } +} + + void Foam::vtkPVblockMesh::renderPointNumbers ( vtkRenderer* renderer, @@ -419,12 +537,12 @@ void Foam::vtkPVblockMesh::renderPointNumbers { // always remove old actors first - forAll(pointNumberTextActorsPtrs_, pointi) + forAll(pointTextActorsPtrs_, actori) { - renderer->RemoveViewProp(pointNumberTextActorsPtrs_[pointi]); - pointNumberTextActorsPtrs_[pointi]->Delete(); + renderer->RemoveViewProp(pointTextActorsPtrs_[actori]); + pointTextActorsPtrs_[actori]->Delete(); } - pointNumberTextActorsPtrs_.clear(); + pointTextActorsPtrs_.clear(); if (show && meshPtr_) { @@ -432,49 +550,29 @@ void Foam::vtkPVblockMesh::renderPointNumbers const pointField& cornerPts = blkMesh.vertices(); const scalar scaleFactor = blkMesh.scaleFactor(); - pointNumberTextActorsPtrs_.setSize(cornerPts.size()); + pointTextActorsPtrs_.setSize(cornerPts.size()); forAll(cornerPts, pointi) { - vtkTextActor* txt = vtkTextActor::New(); - // Display either pointi as a number or with its name // (looked up from blockMeshDict) - { - OStringStream os; - blockVertex::write(os, pointi, blkMesh.meshDict()); - txt->SetInput(os.str().c_str()); - } + OStringStream os; + blockVertex::write(os, pointi, blkMesh.meshDict()); - // Set text properties - vtkTextProperty* tprop = txt->GetTextProperty(); - tprop->SetFontFamilyToArial(); - tprop->BoldOn(); - tprop->ShadowOff(); - tprop->SetLineSpacing(1.0); - tprop->SetFontSize(14); - tprop->SetColor(1.0, 0.0, 1.0); - tprop->SetJustificationToCentered(); - - // Set text to use 3-D world co-ordinates - txt->GetPositionCoordinate()->SetCoordinateSystemToWorld(); - - txt->GetPositionCoordinate()->SetValue + // Into a list for later removal + pointTextActorsPtrs_[pointi] = createTextActor ( - cornerPts[pointi].x()*scaleFactor, - cornerPts[pointi].y()*scaleFactor, - cornerPts[pointi].z()*scaleFactor + os.str(), + cornerPts[pointi]*scaleFactor ); - - // Add text to each renderer - renderer->AddViewProp(txt); - - // Maintain a list of text labels added so that they can be - // removed later - pointNumberTextActorsPtrs_[pointi] = txt; } } -} + // Add text to each renderer + forAll(pointTextActorsPtrs_, actori) + { + renderer->AddViewProp(pointTextActorsPtrs_[actori]); + } +} void Foam::vtkPVblockMesh::PrintSelf(ostream& os, vtkIndent indent) const diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMesh.H b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMesh.H index e4e8c56c2c..a22316c84a 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMesh.H +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMesh.H @@ -109,38 +109,38 @@ class vtkPVblockMesh //- First instance and size of block corners (only partially used) arrayRange arrayRangeCorners_; + //- List of patch names for rendering to window + List patchTextActorsPtrs_; + //- List of point numbers for rendering to window - List pointNumberTextActorsPtrs_; + List pointTextActorsPtrs_; // Private Member Functions + //- Create a text actor + static vtkTextActor* createTextActor(const string& s, const point& pt); + //- Reset data counters void resetCounters(); - // Update information helper functions + //- OpenFOAM mesh + void updateFoamMesh(); - //- Internal block info - void updateInfoBlocks(vtkDataArraySelection*); + //- Internal block info + void updateInfoBlocks(vtkDataArraySelection* select); - //- Block curved edges info - void updateInfoEdges(vtkDataArraySelection*); + //- Block curved edges info + void updateInfoEdges(vtkDataArraySelection* select); - // Update helper functions + //- Mesh blocks + void convertMeshBlocks(vtkMultiBlockDataSet*, int& blockNo); - //- OpenFOAM mesh - void updateFoamMesh(); + //- Mesh curved edges + void convertMeshEdges(vtkMultiBlockDataSet*, int& blockNo); - // Mesh conversion functions - - //- Mesh blocks - void convertMeshBlocks(vtkMultiBlockDataSet*, int& blockNo); - - //- Mesh curved edges - void convertMeshEdges(vtkMultiBlockDataSet*, int& blockNo); - - //- Mesh corners - void convertMeshCorners(vtkMultiBlockDataSet*, int& blockNo); + //- Mesh corners + void convertMeshCorners(vtkMultiBlockDataSet*, int& blockNo); //- Disallow default bitwise copy construct @@ -181,6 +181,9 @@ public: //- Clean any storage void CleanUp(); + //- Add/remove patch names to/from the view + void renderPatchNames(vtkRenderer*, const bool show); + //- Add/remove point numbers to/from the view void renderPointNumbers(vtkRenderer*, const bool show); From fe0bb227aeee8f6f2c7dc9dc7ce6d137efcb12bf Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 18 Jan 2017 11:31:15 +0100 Subject: [PATCH 08/35] STYLE: adjust documentation for scalarTransport FO --- .../solvers/scalarTransport/scalarTransport.C | 15 +++++---------- .../solvers/scalarTransport/scalarTransport.H | 19 ++++++++++--------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/functionObjects/solvers/scalarTransport/scalarTransport.C b/src/functionObjects/solvers/scalarTransport/scalarTransport.C index 84b68341d8..641241b91e 100644 --- a/src/functionObjects/solvers/scalarTransport/scalarTransport.C +++ b/src/functionObjects/solvers/scalarTransport/scalarTransport.C @@ -201,7 +201,7 @@ Foam::functionObjects::scalarTransport::scalarTransport resetOnStartUp_(false), schemesField_("unknown-schemesField"), fvOptions_(mesh_), - bounded01_(dict.lookupOrDefault("bounded01", true)) + bounded01_(dict.lookupOrDefault("bounded01", true)) { read(dict); @@ -235,12 +235,7 @@ bool Foam::functionObjects::scalarTransport::read(const dictionary& dict) dict.readIfPresent("bounded01", bounded01_); schemesField_ = dict.lookupOrDefault("schemesField", fieldName_); - - constantD_ = false; - if (dict.readIfPresent("D", D_)) - { - constantD_ = true; - } + constantD_ = dict.readIfPresent("D", D_); dict.readIfPresent("nCorr", nCorr_); dict.readIfPresent("resetOnStartUp", resetOnStartUp_); @@ -256,11 +251,11 @@ bool Foam::functionObjects::scalarTransport::read(const dictionary& dict) bool Foam::functionObjects::scalarTransport::execute() { - Log << type() << " write:" << endl; - volScalarField& s = transportedField(); - const surfaceScalarField& phi = + Log << type() << " execute: " << s.name() << endl; + + const surfaceScalarField& phi = mesh_.lookupObject(phiName_); // Calculate the diffusivity diff --git a/src/functionObjects/solvers/scalarTransport/scalarTransport.H b/src/functionObjects/solvers/scalarTransport/scalarTransport.H index e2570fc7f9..bc743e7eea 100644 --- a/src/functionObjects/solvers/scalarTransport/scalarTransport.H +++ b/src/functionObjects/solvers/scalarTransport/scalarTransport.H @@ -111,17 +111,18 @@ Usage \table Property | Description | Required | Default value type | Type name: scalarTransport | yes | - phi | Name of flux field | yes | + field | Name of the scalar field | no | s + phi | Name of flux field | no | phi rho | Name of density field | no | rho - phase | Name of the phase name | no | none + phase | Name of the phase | no | none nut | Name of the turbulence viscosity | no | none D | Diffusion coefficient | no | auto generated nCorr | Number of correctors | no | 0 resetOnStartUp | Reset scalar to zero on start-up | no | no - schemesField | Name of field to specify schemes | no | fieldName + schemesField | Name of field to specify schemes | no | field name fvOptions | List of scalar sources | no | - bounded01 | Bounds scalar between 0-1 for multiphase | no |true - phasePhiCompressed |Compressed flux for VOF | no | alphaPhiUn + bounded01 | Bounds scalar between 0-1 for multiphase | no | true + phasePhiCompressed | Compressed flux for VOF | no | alphaPhiUn \endtable See also @@ -156,10 +157,10 @@ class scalarTransport { // Private data - //- Name of field to process + //- Name of the transport field. word fieldName_; - //- Name of flux field + //- Name of flux field (optional) word phiName_; //- Name of density field (optional) @@ -168,10 +169,10 @@ class scalarTransport //- Name of turbulent viscosity field (optional) word nutName_; - //- Name of phase field + //- Name of phase field (optional) word phaseName_; - //- Name of phase field compressed flux + //- Name of phase field compressed flux (optional) word phasePhiCompressedName_; //- Diffusion coefficient (optional) From 2fa6ae6f6219150fabc219e3bf7f1f3487e19930 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 20 Jan 2017 21:13:38 +0100 Subject: [PATCH 09/35] STYLE: use pre-increment and cbegin/cend form for forAll* macros - no reason to use post-increment in forAll() macro. - use C++11 cbegin()/cend() method names for forAll*Iter() macros. These method names have been in OpenFOAM since 2009 and are also used by C++11 containers. STYLE: nullptr instead of 0 in UList --- src/OpenFOAM/containers/Lists/UList/UList.H | 8 ++++---- src/OpenFOAM/containers/Lists/UList/UListI.H | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/OpenFOAM/containers/Lists/UList/UList.H b/src/OpenFOAM/containers/Lists/UList/UList.H index 719df10a0f..a31416cc73 100644 --- a/src/OpenFOAM/containers/Lists/UList/UList.H +++ b/src/OpenFOAM/containers/Lists/UList/UList.H @@ -427,7 +427,7 @@ inline void reverse(UList&); // \endcode // \sa forAllReverse #define forAll(list, i) \ - for (Foam::label i=0; i<(list).size(); i++) + for (Foam::label i=0; i<(list).size(); ++i) //- Reverse loop across all elements in \a list // \par Usage @@ -439,7 +439,7 @@ inline void reverse(UList&); // \endcode // \sa forAll #define forAllReverse(list, i) \ - for (Foam::label i=(list).size()-1; i>=0; i--) + for (Foam::label i=(list).size()-1; i>=0; --i) //- Iterate across all elements in the \a container object of type // \a Container. @@ -472,8 +472,8 @@ inline void reverse(UList&); #define forAllConstIter(Container,container,iter) \ for \ ( \ - Container::const_iterator iter = (container).begin(); \ - iter != (container).end(); \ + Container::const_iterator iter = (container).cbegin(); \ + iter != (container).cend(); \ ++iter \ ) diff --git a/src/OpenFOAM/containers/Lists/UList/UListI.H b/src/OpenFOAM/containers/Lists/UList/UListI.H index 0e4825c79c..bd9fe339eb 100644 --- a/src/OpenFOAM/containers/Lists/UList/UListI.H +++ b/src/OpenFOAM/containers/Lists/UList/UListI.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -33,7 +33,7 @@ template inline Foam::UList::UList() : size_(0), - v_(0) + v_(nullptr) {} @@ -321,7 +321,7 @@ inline bool Foam::UList::empty() const template inline void Foam::reverse(UList& ul, const label n) { - for (int i=0; i Date: Mon, 23 Jan 2017 17:09:26 +0100 Subject: [PATCH 10/35] ENH: freshen code in labelRange classes - misc improvements in functionality. --- .../test/labelRanges/Test-labelRanges.C | 24 ++-- .../primitives/ranges/labelRange/labelRange.C | 43 +++--- .../primitives/ranges/labelRange/labelRange.H | 125 +++++++++++------- .../ranges/labelRange/labelRangeI.H | 112 ++++++++++++---- .../ranges/labelRange/labelRanges.C | 11 +- .../ranges/labelRange/labelRanges.H | 64 +++++---- .../ranges/labelRange/labelRangesI.H | 46 +++---- 7 files changed, 245 insertions(+), 180 deletions(-) diff --git a/applications/test/labelRanges/Test-labelRanges.C b/applications/test/labelRanges/Test-labelRanges.C index 9f2be334d1..dec03a06f0 100644 --- a/applications/test/labelRanges/Test-labelRanges.C +++ b/applications/test/labelRanges/Test-labelRanges.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -58,6 +58,7 @@ int main(int argc, char *argv[]) } + labelRange range; labelRanges ranges; bool removeMode = false; @@ -74,14 +75,16 @@ int main(int argc, char *argv[]) continue; } - label start = 0; - label size = 0; + { + label start = 0; + label size = 0; - IStringStream(args[argI])() >> start; - ++argI; - IStringStream(args[argI])() >> size; + IStringStream(args[argI])() >> start; + ++argI; + IStringStream(args[argI])() >> size; - labelRange range(start, size); + range.reset(start, size); + } Info<< "---------------" << nl; if (removeMode) @@ -107,10 +110,11 @@ int main(int argc, char *argv[]) ranges.add(range); } - Info<< "" << ranges << "" << nl; - forAllConstIter(labelRanges, ranges, iter) + Info<< "" << ranges << "" << nl + << "content:"; + for (auto i : ranges) { - Info<< " " << iter(); + Info<< " " << i; } Info<< nl; } diff --git a/src/OpenFOAM/primitives/ranges/labelRange/labelRange.C b/src/OpenFOAM/primitives/ranges/labelRange/labelRange.C index 11aacf25cb..2bf9810f6c 100644 --- a/src/OpenFOAM/primitives/ranges/labelRange/labelRange.C +++ b/src/OpenFOAM/primitives/ranges/labelRange/labelRange.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -29,8 +29,6 @@ License // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -const Foam::labelRange::const_iterator Foam::labelRange::endIter_; - int Foam::labelRange::debug(::Foam::debug::debugSwitch("labelRange", 0)); @@ -47,13 +45,24 @@ Foam::labelRange::labelRange(Istream& is) // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -bool Foam::labelRange::intersects -( - const labelRange& range, - const bool touches -) const +void Foam::labelRange::adjust() { - label final = touches ? 1 : 0; + if (start_ < 0) + { + size_ += start_; + start_ = 0; + } + + if (size_ < 0) + { + size_ = 0; + } +} + + +bool Foam::labelRange::overlaps(const labelRange& range, bool touches) const +{ + const label final = touches ? 1 : 0; return ( @@ -97,7 +106,7 @@ Foam::labelRange Foam::labelRange::join(const labelRange& range) const // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // -Foam::labelRange& Foam::labelRange::operator+=(const labelRange& rhs) +void Foam::labelRange::operator+=(const labelRange& rhs) { if (!size_) { @@ -112,8 +121,6 @@ Foam::labelRange& Foam::labelRange::operator+=(const labelRange& rhs) start_ = lower; size_ = upper - lower + 1; } - - return *this; } @@ -127,10 +134,10 @@ Foam::Istream& Foam::operator>>(Istream& is, labelRange& range) is.check("operator>>(Istream&, labelRange&)"); - // disallow invalid sizes - if (range.size_ <= 0) + // Disallow invalid sizes + if (range.size_ < 0) { - range.clear(); + range.size_ = 0; } return is; @@ -139,15 +146,11 @@ Foam::Istream& Foam::operator>>(Istream& is, labelRange& range) Foam::Ostream& Foam::operator<<(Ostream& os, const labelRange& range) { - // write ASCII only for now + // Write ASCII only for now os << token::BEGIN_LIST << range.start_ << token::SPACE << range.size_ << token::END_LIST; -// os << token::BEGIN_BLOCK -// << range.start_ << "-" << range.last() -// << token::END_BLOCK; - os.check("operator<<(Ostream&, const labelRange&)"); return os; } diff --git a/src/OpenFOAM/primitives/ranges/labelRange/labelRange.H b/src/OpenFOAM/primitives/ranges/labelRange/labelRange.H index 24dd33729c..3fa69c4ff3 100644 --- a/src/OpenFOAM/primitives/ranges/labelRange/labelRange.H +++ b/src/OpenFOAM/primitives/ranges/labelRange/labelRange.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -25,7 +25,7 @@ Class Foam::labelRange Description - A label range specifier. + A range of labels. SourceFiles labelRange.C @@ -47,8 +47,8 @@ class Ostream; // Forward declaration of friend functions and operators class labelRange; -Istream& operator>>(Istream&, labelRange&); -Ostream& operator<<(Ostream&, const labelRange&); +Istream& operator>>(Istream& is, labelRange& range); +Ostream& operator<<(Ostream& os, const labelRange& range); /*---------------------------------------------------------------------------*\ Class labelRange Declaration @@ -63,7 +63,7 @@ class labelRange public: - static int debug; + static int debug; // Public classes @@ -75,31 +75,50 @@ public: bool operator()(const labelRange& a, const labelRange& b) { - return a.first() < b.first(); + return a.operator<(b); } }; + // Constructors - //- Construct an empty range + //- Construct an empty range with zero as start and size. inline labelRange(); - //- Construct a range - // A negative size is autmatically changed to zero. - inline labelRange(const label start, const label size); + //- Construct a range from start and size. + // Optionally adjust the start to avoid any negative indices. + // Always reduce a negative size to zero. + inline labelRange + ( + const label start, + const label size, + const bool adjustStart = false + ); //- Construct from Istream. - labelRange(Istream&); + labelRange(Istream& is); // Member Functions - //- Reset to zero size + //- Alias for setSize(const label) + inline void resize(const label n); + + //- Adjust size + inline void setSize(const label n); + + //- Reset to zero start and zero size inline void clear(); //- Is the range empty? inline bool empty() const; + //- Adjust the start to avoid any negative indices + void adjust(); + + //- Is the range valid (non-empty)? + inline bool valid() const; + //- Return the effective size of the range inline label size() const; @@ -109,32 +128,44 @@ public: //- The (inclusive) upper value of the range inline label last() const; - //- Return true if the value is within the range - inline bool contains(const label) const; + //- Reset start and size. + // Optionally adjust the start to avoid any negative indices. + // Always reduce a negative size to zero. + // Return true if the updated range valid (non-empty). + inline bool reset + ( + const label start, + const label size, + const bool adjustStart = false + ); - //- Return true if the ranges intersect + //- Return true if the value is within the range + inline bool contains(const label value) const; + + //- Return true if the ranges overlap. // Optional test for ranges that also just touch each other - bool intersects(const labelRange&, const bool touches = false) const; + bool overlaps(const labelRange& range, bool touches=false) const; //- Return a joined range, squashing any gaps in between - // A prior intersects() check can be used to avoid squashing gaps. - labelRange join(const labelRange&) const; + // A prior overlaps() check can be used to avoid squashing gaps. + labelRange join(const labelRange& range) const; // Member Operators //- Return element in range, no bounds checking - inline label operator[](const label) const; + inline label operator[](const label i) const; - //- Comparison function for sorting, compares the start + //- Comparison function for sorting, compares the start. + // If the start values are equal, also compares the size. inline bool operator<(const labelRange& rhs) const; //- Join ranges, squashing any gaps in between - // A prior intersects() check can be used to avoid squashing gaps. - labelRange& operator+=(const labelRange&); + // A prior overlaps() check can be used to avoid squashing gaps. + void operator+=(const labelRange& rhs); - inline bool operator==(const labelRange&) const; - inline bool operator!=(const labelRange&) const; + inline bool operator==(const labelRange& rhs) const; + inline bool operator!=(const labelRange& rhs) const; // STL iterator @@ -142,6 +173,8 @@ public: //- An STL const_iterator class const_iterator { + friend class labelRange; + // Private data //- Reference to the range for which this is an iterator @@ -150,54 +183,48 @@ public: //- Current index label index_; - public: // Constructors - //- Construct null - equivalent to an 'end' position - inline const_iterator(); - - //- Construct from range, moving to its 'begin' position - inline explicit const_iterator(const labelRange&); + //- Construct from range at 'begin' or 'end' position + inline const_iterator + ( + const labelRange& range, + const bool endIter = false + ); + public: // Member operators - inline bool operator==(const const_iterator&) const; + inline bool operator==(const const_iterator& iter) const; + inline bool operator!=(const const_iterator& iter) const; - inline bool operator!=(const const_iterator&) const; - - inline label operator*(); - inline label operator()(); + inline label operator*() const; + inline label operator()() const; inline const_iterator& operator++(); inline const_iterator operator++(int); }; - //- const_iterator set to the beginning of the range + //- A const_iterator set to the beginning of the range inline const_iterator cbegin() const; - //- const_iterator set to beyond the end of the range - inline const const_iterator& cend() const; + //- A const_iterator set to beyond the end of the range + inline const const_iterator cend() const; - //- const_iterator set to the beginning of the range + //- A const_iterator set to the beginning of the range inline const_iterator begin() const; - //- const_iterator set to beyond the end of the range - inline const const_iterator& end() const; + //- A const_iterator set to beyond the end of the range + inline const const_iterator end() const; // IOstream Operators - friend Istream& operator>>(Istream&, labelRange&); - friend Ostream& operator<<(Ostream&, const labelRange&); - - -private: - - //- const_iterator returned by end(), cend() - static const const_iterator endIter_; + friend Istream& operator>>(Istream& is, labelRange& range); + friend Ostream& operator<<(Ostream& os, const labelRange& range); }; diff --git a/src/OpenFOAM/primitives/ranges/labelRange/labelRangeI.H b/src/OpenFOAM/primitives/ranges/labelRange/labelRangeI.H index 21e839cf3c..927a6f57a0 100644 --- a/src/OpenFOAM/primitives/ranges/labelRange/labelRangeI.H +++ b/src/OpenFOAM/primitives/ranges/labelRange/labelRangeI.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -33,32 +33,39 @@ inline Foam::labelRange::labelRange() {} -inline Foam::labelRange::labelRange(const label start, const label size) +inline Foam::labelRange::labelRange +( + const label start, + const label size, + const bool adjustStart +) : start_(start), size_(size) { - // disallow invalid sizes - if (size_ <= 0) + if (adjustStart) { - this->clear(); + // Disallow invalid indices and sizes + adjust(); + } + else if (size_ < 0) + { + // Disallow invalid sizes + size_ = 0; } } // * * * * * * * * * * * * * * * * Iterators * * * * * * * * * * * * * * * * // -inline Foam::labelRange::const_iterator::const_iterator() -: - range_(*reinterpret_cast(0)), - index_(-1) -{} - - -inline Foam::labelRange::const_iterator::const_iterator(const labelRange& range) +inline Foam::labelRange::const_iterator::const_iterator +( + const labelRange& range, + const bool endIter +) : range_(range), - index_(range_.empty() ? -1 : 0) + index_(endIter ? range_.size() : 0) {} @@ -76,17 +83,17 @@ inline bool Foam::labelRange::const_iterator::operator!= const const_iterator& iter ) const { - return !(this->operator==(iter)); + return (this->index_ != iter.index_); } -inline Foam::label Foam::labelRange::const_iterator::operator*() +inline Foam::label Foam::labelRange::const_iterator::operator*() const { return range_[index_]; } -inline Foam::label Foam::labelRange::const_iterator::operator()() +inline Foam::label Foam::labelRange::const_iterator::operator()() const { return range_[index_]; } @@ -95,12 +102,7 @@ inline Foam::label Foam::labelRange::const_iterator::operator()() inline Foam::labelRange::const_iterator& Foam::labelRange::const_iterator::operator++() { - if (++index_ >= range_.size()) - { - // equivalent to end iterator - index_ = -1; - } - + ++index_; return *this; } @@ -109,7 +111,7 @@ inline Foam::labelRange::const_iterator Foam::labelRange::const_iterator::operator++(int) { const_iterator old = *this; - this->operator++(); + ++index_; return old; } @@ -120,9 +122,9 @@ inline Foam::labelRange::const_iterator Foam::labelRange::cbegin() const } -inline const Foam::labelRange::const_iterator& Foam::labelRange::cend() const +inline const Foam::labelRange::const_iterator Foam::labelRange::cend() const { - return endIter_; + return const_iterator(*this, true); } @@ -132,14 +134,31 @@ inline Foam::labelRange::const_iterator Foam::labelRange::begin() const } -inline const Foam::labelRange::const_iterator& Foam::labelRange::end() const +inline const Foam::labelRange::const_iterator Foam::labelRange::end() const { - return endIter_; + return const_iterator(*this, true); } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +inline void Foam::labelRange::resize(const label n) +{ + setSize(n); +} + + +inline void Foam::labelRange::setSize(const label n) +{ + size_ = n; + + if (size_ < 0) + { + size_ = 0; + } +} + + inline void Foam::labelRange::clear() { start_ = size_ = 0; @@ -152,6 +171,12 @@ inline bool Foam::labelRange::empty() const } +inline bool Foam::labelRange::valid() const +{ + return size_; +} + + inline Foam::label Foam::labelRange::size() const { return size_; @@ -170,6 +195,31 @@ inline Foam::label Foam::labelRange::last() const } +inline bool Foam::labelRange::reset +( + const label start, + const label size, + const bool adjustStart +) +{ + start_ = start; + size_ = size; + + if (adjustStart) + { + // Disallow invalid indices and sizes + adjust(); + } + else if (size_ < 0) + { + // Disallow invalid sizes + size_ = 0; + } + + return size_; +} + + inline bool Foam::labelRange::contains(const label value) const { return value >= this->first() && value <= this->last(); @@ -186,7 +236,11 @@ inline Foam::label Foam::labelRange::operator[](const label i) const inline bool Foam::labelRange::operator<(const labelRange& rhs) const { - return this->first() < rhs.first(); + return + ( + this->first() < rhs.first() + || (this->first() == rhs.first() && this->size() < rhs.size()) + ); } diff --git a/src/OpenFOAM/primitives/ranges/labelRange/labelRanges.C b/src/OpenFOAM/primitives/ranges/labelRange/labelRanges.C index 101c2bce98..d9edff0e47 100644 --- a/src/OpenFOAM/primitives/ranges/labelRange/labelRanges.C +++ b/src/OpenFOAM/primitives/ranges/labelRange/labelRanges.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -26,11 +26,6 @@ License #include "labelRanges.H" #include "ListOps.H" -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -const Foam::labelRanges::const_iterator Foam::labelRanges::endIter_; - - // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // void Foam::labelRanges::insertBefore @@ -141,7 +136,7 @@ bool Foam::labelRanges::add(const labelRange& range) { labelRange& currRange = ParentType::operator[](elemI); - if (currRange.intersects(range, true)) + if (currRange.overlaps(range, true)) { // absorb into the existing (adjacent/overlapping) range currRange += range; @@ -150,7 +145,7 @@ bool Foam::labelRanges::add(const labelRange& range) for (; elemI < this->size()-1; ++elemI) { labelRange& nextRange = ParentType::operator[](elemI+1); - if (currRange.intersects(nextRange, true)) + if (currRange.overlaps(nextRange, true)) { currRange += nextRange; nextRange.clear(); diff --git a/src/OpenFOAM/primitives/ranges/labelRange/labelRanges.H b/src/OpenFOAM/primitives/ranges/labelRange/labelRanges.H index 6fa10b0aac..134acb0482 100644 --- a/src/OpenFOAM/primitives/ranges/labelRange/labelRanges.H +++ b/src/OpenFOAM/primitives/ranges/labelRange/labelRanges.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -49,8 +49,8 @@ class Ostream; // Forward declaration of friend functions and operators class labelRanges; -Istream& operator>>(Istream&, labelRanges&); -Ostream& operator<<(Ostream&, const labelRanges&); +Istream& operator>>(Istream& is, labelRanges& ranges); +Ostream& operator<<(Ostream& is, const labelRanges& ranges); /*---------------------------------------------------------------------------*\ Class labelRanges Declaration @@ -68,13 +68,13 @@ class labelRanges // Private Member Functions //- Insert range before specified insertion index, by copying up - void insertBefore(const label, const labelRange&); + void insertBefore(const label insert, const labelRange& range); //- Purge empty ranges, by copying down void purgeEmpty(); //- Print the range for debugging purposes - Ostream& printRange(Ostream&, const labelRange&) const; + Ostream& printRange(Ostream& os, const labelRange& range) const; public: @@ -85,10 +85,10 @@ public: inline labelRanges(); //- Construct given size - inline explicit labelRanges(const label); + inline explicit labelRanges(const label nElem); //- Construct from Istream. - labelRanges(Istream&); + labelRanges(Istream& is); // Member Functions @@ -100,19 +100,22 @@ public: using DynamicList::empty; //- Return true if the value is within any of the ranges - inline bool contains(const label) const; + inline bool contains(const label value) const; //- Add the range to the list - bool add(const labelRange&); + bool add(const labelRange& range); //- Remove the range from the list - bool remove(const labelRange&); + bool remove(const labelRange& range); + // STL iterator //- An STL const_iterator class const_iterator { + friend class labelRanges; + // Private data //- Reference to the list for which this is an iterator @@ -124,22 +127,21 @@ public: //- Index of current element at listIndex label subIndex_; - public: - // Constructors - //- Construct null - equivalent to an 'end' position - inline const_iterator(); - - //- Construct from list, moving to its 'begin' position - inline explicit const_iterator(const labelRanges&); + //- Construct from ranges at 'begin' or 'end' position + inline const_iterator + ( + const labelRanges& lst, + const bool endIter = false + ); + public: // Member operators - inline bool operator==(const const_iterator&) const; - - inline bool operator!=(const const_iterator&) const; + inline bool operator==(const const_iterator& iter) const; + inline bool operator!=(const const_iterator& iter) const; inline label operator*(); inline label operator()(); @@ -149,29 +151,23 @@ public: }; - //- const_iterator set to the beginning of the list + //- A const_iterator set to the beginning of the list inline const_iterator cbegin() const; - //- const_iterator set to beyond the end of the list - inline const const_iterator& cend() const; + //- A const_iterator set to beyond the end of the list + inline const const_iterator cend() const; - //- const_iterator set to the beginning of the list + //- A const_iterator set to the beginning of the list inline const_iterator begin() const; - //- const_iterator set to beyond the end of the list - inline const const_iterator& end() const; + //- A const_iterator set to beyond the end of the list + inline const const_iterator end() const; // IOstream Operators - friend Istream& operator>>(Istream&, labelRanges&); - friend Ostream& operator<<(Ostream&, const labelRanges&); - - -private: - - //- const_iterator returned by end(), cend() - static const const_iterator endIter_; + friend Istream& operator>>(Istream& is, labelRanges& ranges); + friend Ostream& operator<<(Ostream& os, const labelRanges& ranges); }; diff --git a/src/OpenFOAM/primitives/ranges/labelRange/labelRangesI.H b/src/OpenFOAM/primitives/ranges/labelRange/labelRangesI.H index 739d582e9f..9ccad0e300 100644 --- a/src/OpenFOAM/primitives/ranges/labelRange/labelRangesI.H +++ b/src/OpenFOAM/primitives/ranges/labelRange/labelRangesI.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -40,28 +40,18 @@ inline Foam::labelRanges::labelRanges(const label nElem) // * * * * * * * * * * * * * * * * Iterators * * * * * * * * * * * * * * * * // -inline Foam::labelRanges::const_iterator::const_iterator() +inline Foam::labelRanges::const_iterator::const_iterator +( + const labelRanges& lst, + const bool endIter +) : - list_(*reinterpret_cast(0)), - index_(-1), - subIndex_(-1) + list_(lst), + index_(endIter ? lst.size() : 0), + subIndex_(0) {} -inline Foam::labelRanges::const_iterator::const_iterator(const labelRanges& lst) -: - list_(lst), - index_(0), - subIndex_(0) -{ - if (list_.empty()) - { - // equivalent to end iterator - index_ = subIndex_ = -1; - } -} - - inline bool Foam::labelRanges::const_iterator::operator== ( const const_iterator& iter @@ -69,7 +59,7 @@ inline bool Foam::labelRanges::const_iterator::operator== { return ( - this->index_ == iter.index_ + this->index_ == iter.index_ && this->subIndex_ == iter.subIndex_ ); } @@ -101,13 +91,9 @@ Foam::labelRanges::const_iterator::operator++() { if (++subIndex_ >= list_[index_].size()) { - // go to next list entry + // Next sub-list + ++index_; subIndex_ = 0; - if (++index_ >= list_.size()) - { - // equivalent to end iterator - index_ = subIndex_ = -1; - } } return *this; @@ -129,9 +115,9 @@ inline Foam::labelRanges::const_iterator Foam::labelRanges::cbegin() const } -inline const Foam::labelRanges::const_iterator& Foam::labelRanges::cend() const +inline const Foam::labelRanges::const_iterator Foam::labelRanges::cend() const { - return endIter_; + return const_iterator(*this, true); } @@ -141,9 +127,9 @@ inline Foam::labelRanges::const_iterator Foam::labelRanges::begin() const } -inline const Foam::labelRanges::const_iterator& Foam::labelRanges::end() const +inline const Foam::labelRanges::const_iterator Foam::labelRanges::end() const { - return endIter_; + return const_iterator(*this, true); } From a99143506dedc4432b33f11418a5f57817cae268 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 24 Jan 2017 12:59:13 +0100 Subject: [PATCH 11/35] BUG: not incrementing when reading via singly-linked list --- applications/test/List/Test-List.C | 21 +++++++++++++++++-- src/OpenFOAM/containers/Lists/List/ListIO.C | 2 +- src/OpenFOAM/containers/Lists/UList/UList.C | 2 +- src/OpenFOAM/containers/Lists/UList/UListIO.C | 14 ++++++------- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/applications/test/List/Test-List.C b/applications/test/List/Test-List.C index 65073700ab..fc8fab5178 100644 --- a/applications/test/List/Test-List.C +++ b/applications/test/List/Test-List.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -42,7 +42,11 @@ See also #include "vector.H" #include "ListOps.H" -#include +#include "labelRange.H" +#include "ListOps.H" +#include "SubList.H" + +#include using namespace Foam; @@ -61,6 +65,19 @@ int main(int argc, char *argv[]) #include "setRootCase.H" + if (false) + { + labelList intlist(IStringStream("(0 1 2)")()); + Info<<"construct from Istream: " << intlist << endl; + + IStringStream("(3 4 5)")() >> static_cast(intlist); + Info<<"is >>: " << intlist << endl; + + IStringStream("(6 7 8)")() >> intlist; + Info<<"is >>: " << intlist << endl; + } + + List list1(IStringStream("1 ((0 1 2))")()); Info<< "list1: " << list1 << endl; diff --git a/src/OpenFOAM/containers/Lists/List/ListIO.C b/src/OpenFOAM/containers/Lists/List/ListIO.C index bbc55ec10d..6229cb9490 100644 --- a/src/OpenFOAM/containers/Lists/List/ListIO.C +++ b/src/OpenFOAM/containers/Lists/List/ListIO.C @@ -64,7 +64,7 @@ Foam::Istream& Foam::operator>>(Istream& is, List& L) } else if (firstToken.isLabel()) { - label s = firstToken.labelToken(); + const label s = firstToken.labelToken(); // Set list length to that read L.setSize(s); diff --git a/src/OpenFOAM/containers/Lists/UList/UList.C b/src/OpenFOAM/containers/Lists/UList/UList.C index 52177d79bc..320b22f68f 100644 --- a/src/OpenFOAM/containers/Lists/UList/UList.C +++ b/src/OpenFOAM/containers/Lists/UList/UList.C @@ -183,7 +183,7 @@ bool Foam::UList::operator<(const UList& a) const ( const_iterator vi = begin(), ai = a.begin(); vi < end() && ai < a.end(); - vi++, ai++ + ++vi, ++ai ) { if (*vi < *ai) diff --git a/src/OpenFOAM/containers/Lists/UList/UListIO.C b/src/OpenFOAM/containers/Lists/UList/UListIO.C index a4648137cf..0559a63adc 100644 --- a/src/OpenFOAM/containers/Lists/UList/UListIO.C +++ b/src/OpenFOAM/containers/Lists/UList/UListIO.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -165,7 +165,7 @@ Foam::Istream& Foam::operator>>(Istream& is, UList& L) ) ); // Check list length - label s = elems.size(); + const label s = elems.size(); if (s != L.size()) { @@ -174,14 +174,14 @@ Foam::Istream& Foam::operator>>(Istream& is, UList& L) << " expected " << L.size() << exit(FatalIOError); } - for (label i=0; i>(Istream& is, UList& L) { if (delimiter == token::BEGIN_LIST) { - for (label i=0; i> L[i]; @@ -226,7 +226,7 @@ Foam::Istream& Foam::operator>>(Istream& is, UList& L) "reading the single entry" ); - for (label i=0; i>(Istream& is, UList& L) ( typename SLList::const_iterator iter = sll.begin(); iter != sll.end(); - ++iter + ++iter, ++i ) { L[i] = iter(); From d404ef954b09432ad006aa6a0b5f5b0f0d743058 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 16 Jan 2017 18:25:03 +0100 Subject: [PATCH 12/35] BUG: incorrect super-cells for foamVtkCells decomposition (fixes #385) --- src/conversion/vtk/part/foamVtkCells.C | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/conversion/vtk/part/foamVtkCells.C b/src/conversion/vtk/part/foamVtkCells.C index b4c7beacde..5846c8442d 100644 --- a/src/conversion/vtk/part/foamVtkCells.C +++ b/src/conversion/vtk/part/foamVtkCells.C @@ -326,7 +326,7 @@ void Foam::foamVtkCells::correct() nAddVerts += 5; vertOffset_[celLoc] = nAddVerts; - decompose_.superCells_[nAddCells++] = celLoc; + decompose_.superCells_[nAddCells++] = cellI; } cellTypes_[celLoc] = foamVtkCore::VTK_PYRAMID; @@ -373,7 +373,7 @@ void Foam::foamVtkCells::correct() nAddVerts += 4; vertOffset_[celLoc] = nAddVerts; - decompose_.superCells_[nAddCells++] = celLoc; + decompose_.superCells_[nAddCells++] = cellI; } cellTypes_[celLoc] = foamVtkCore::VTK_TETRA; From f265b0484cc2217b21b76f37c4a2dc9fb0159b2c Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 17 Jan 2017 08:42:05 +0100 Subject: [PATCH 13/35] BUG: extra newline in foamVtkAppendBase64Formatter flush() Enhancements - introduce intermediate layer for base64 foamVtk formatting - add encodedLength() method, which is useful for xml appended output --- .../db/IOstreams/hashes/base64Layer.C | 18 ++- .../db/IOstreams/hashes/base64Layer.H | 20 +-- src/fileFormats/Make/files | 1 + .../vtk/format/foamVtkAppendBase64Formatter.C | 17 +-- .../vtk/format/foamVtkAppendBase64Formatter.H | 12 +- .../vtk/format/foamVtkAppendRawFormatter.C | 14 +-- .../vtk/format/foamVtkAppendRawFormatter.H | 14 ++- .../vtk/format/foamVtkAsciiFormatter.C | 29 +++-- .../vtk/format/foamVtkAsciiFormatter.H | 29 +++-- .../vtk/format/foamVtkBase64Formatter.C | 65 ++-------- .../vtk/format/foamVtkBase64Formatter.H | 30 +---- .../vtk/format/foamVtkBase64Layer.C | 116 ++++++++++++++++++ .../vtk/format/foamVtkBase64Layer.H | 114 +++++++++++++++++ src/fileFormats/vtk/format/foamVtkFormatter.C | 10 +- src/fileFormats/vtk/format/foamVtkFormatter.H | 54 ++++---- .../vtk/format/foamVtkLegacyFormatter.C | 6 +- .../vtk/format/foamVtkLegacyFormatter.H | 28 +++-- .../vtk/format/foamVtkOutputOptions.C | 24 ++-- .../vtk/format/foamVtkOutputOptions.H | 12 +- 19 files changed, 406 insertions(+), 207 deletions(-) create mode 100644 src/fileFormats/vtk/format/foamVtkBase64Layer.C create mode 100644 src/fileFormats/vtk/format/foamVtkBase64Layer.H diff --git a/src/OpenFOAM/db/IOstreams/hashes/base64Layer.C b/src/OpenFOAM/db/IOstreams/hashes/base64Layer.C index f1123f7519..5e055c1ca1 100644 --- a/src/OpenFOAM/db/IOstreams/hashes/base64Layer.C +++ b/src/OpenFOAM/db/IOstreams/hashes/base64Layer.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -43,27 +43,35 @@ static const unsigned char base64Chars[64] = //! \endcond +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +std::size_t Foam::base64Layer::encodedLength(std::size_t n) +{ + return 4 * ((n / 3) + (n % 3 ? 1 : 0)); +} + + // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // -inline unsigned char Foam::base64Layer::encode0() +inline unsigned char Foam::base64Layer::encode0() const { // Top 6 bits of char0 return base64Chars[((group_[0] & 0xFC) >> 2)]; } -inline unsigned char Foam::base64Layer::encode1() +inline unsigned char Foam::base64Layer::encode1() const { // Bottom 2 bits of char0, Top 4 bits of char1 return base64Chars[((group_[0] & 0x03) << 4) | ((group_[1] & 0xF0) >> 4)]; } -inline unsigned char Foam::base64Layer::encode2() +inline unsigned char Foam::base64Layer::encode2() const { // Bottom 4 bits of char1, Top 2 bits of char2 return base64Chars[((group_[1] & 0x0F) << 2) | ((group_[2] & 0xC0) >> 6)]; } -inline unsigned char Foam::base64Layer::encode3() +inline unsigned char Foam::base64Layer::encode3() const { // Bottom 6 bits of char2 return base64Chars[(group_[2] & 0x3F)]; diff --git a/src/OpenFOAM/db/IOstreams/hashes/base64Layer.H b/src/OpenFOAM/db/IOstreams/hashes/base64Layer.H index 9aa4bc8d79..4eaaf87e83 100644 --- a/src/OpenFOAM/db/IOstreams/hashes/base64Layer.H +++ b/src/OpenFOAM/db/IOstreams/hashes/base64Layer.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -30,7 +30,7 @@ Description Base64 encoding accoding to RFC 4648 specification (https://tools.ietf.org/html/rfc4648#page-5). It is the obligation of the caller to avoid using normal output - while the base-64 encoding layer is actively being used. + while the base-64 encoding layer is actively used. SourceFiles base64Layer.C @@ -70,10 +70,10 @@ class base64Layer // Private Member Functions - inline unsigned char encode0(); - inline unsigned char encode1(); - inline unsigned char encode2(); - inline unsigned char encode3(); + inline unsigned char encode0() const; + inline unsigned char encode1() const; + inline unsigned char encode2() const; + inline unsigned char encode3() const; //- Disallow default bitwise copy construct base64Layer(const base64Layer&) = delete; @@ -95,7 +95,7 @@ public: // Constructors //- Construct and attach to an output stream - base64Layer(std::ostream&); + base64Layer(std::ostream& os); //- Destructor @@ -104,6 +104,10 @@ public: // Member Functions + //- The encoded length has 4 bytes out for every 3 bytes in. + static std::size_t encodedLength(std::size_t n); + + //- Encode the character sequence, writing when possible. void write(const char* s, std::streamsize n); @@ -111,7 +115,7 @@ public: void reset(); //- End the encoding sequence, padding the final characters with '='. - // Return false if no encoding layer was actually used. + // Return false if no encoding was actually performed. bool close(); }; diff --git a/src/fileFormats/Make/files b/src/fileFormats/Make/files index 87fd35ee22..ab7fe26dc2 100644 --- a/src/fileFormats/Make/files +++ b/src/fileFormats/Make/files @@ -19,6 +19,7 @@ vtk/format/foamVtkAppendBase64Formatter.C vtk/format/foamVtkAppendRawFormatter.C vtk/format/foamVtkAsciiFormatter.C vtk/format/foamVtkBase64Formatter.C +vtk/format/foamVtkBase64Layer.C vtk/format/foamVtkLegacyFormatter.C vtk/format/foamVtkFormatter.C vtk/format/foamVtkOutputOptions.C diff --git a/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.C b/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.C index ee8b84200f..3805b61812 100644 --- a/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.C +++ b/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -27,8 +27,7 @@ License // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -const char* Foam::foamVtkAppendBase64Formatter::name_ = "append"; -const char* Foam::foamVtkAppendBase64Formatter::encoding_ = "base64"; +const char* Foam::foamVtkAppendBase64Formatter::name_ = "append"; // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -38,14 +37,16 @@ Foam::foamVtkAppendBase64Formatter::foamVtkAppendBase64Formatter std::ostream& os ) : - foamVtkBase64Formatter(os) + foamVtkBase64Layer(os) {} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // Foam::foamVtkAppendBase64Formatter::~foamVtkAppendBase64Formatter() -{} +{ + base64Layer::close(); +} // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // @@ -56,10 +57,4 @@ const char* Foam::foamVtkAppendBase64Formatter::name() const } -const char* Foam::foamVtkAppendBase64Formatter::encoding() const -{ - return encoding_; -} - - // ************************************************************************* // diff --git a/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.H b/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.H index b7239ee7c6..db3e1d6694 100644 --- a/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.H +++ b/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -36,7 +36,7 @@ SourceFiles #ifndef foamVtkAppendBase64Formatter_H #define foamVtkAppendBase64Formatter_H -#include "foamVtkBase64Formatter.H" +#include "foamVtkBase64Layer.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -49,12 +49,11 @@ namespace Foam class foamVtkAppendBase64Formatter : - public foamVtkBase64Formatter + public foamVtkBase64Layer { // Private Data Members static const char* name_; - static const char* encoding_; // Private Member Functions @@ -71,7 +70,7 @@ public: // Constructors //- Construct and attach to an output stream - foamVtkAppendBase64Formatter(std::ostream&); + foamVtkAppendBase64Formatter(std::ostream& os); //- Destructor @@ -83,9 +82,6 @@ public: //- Output name for XML type ("append") virtual const char* name() const; - //- Name for the XML append encoding ("base64"). - virtual const char* encoding() const; - }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.C b/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.C index 9933970495..ae565323b8 100644 --- a/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.C +++ b/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -71,9 +71,9 @@ const char* Foam::foamVtkAppendRawFormatter::encoding() const } -void Foam::foamVtkAppendRawFormatter::writeSize(const uint64_t val) +void Foam::foamVtkAppendRawFormatter::writeSize(const uint64_t nBytes) { - write(reinterpret_cast(&val), sizeof(uint64_t)); + write(reinterpret_cast(&nBytes), sizeof(uint64_t)); } @@ -85,28 +85,28 @@ void Foam::foamVtkAppendRawFormatter::write(const uint8_t val) void Foam::foamVtkAppendRawFormatter::write(const label val) { - // std::cerr<<"label is:" << sizeof(val) << '\n'; + // std::cerr<<"label:" << sizeof(val) << "=" << val << '\n'; write(reinterpret_cast(&val), sizeof(label)); } void Foam::foamVtkAppendRawFormatter::write(const float val) { - // std::cerr<<"float is:" << sizeof(val) << '\n'; + // std::cerr<<"float:" << sizeof(val) << "=" << val << '\n'; write(reinterpret_cast(&val), sizeof(float)); } void Foam::foamVtkAppendRawFormatter::write(const double val) { - // std::cerr<<"write double as float:" << val << '\n'; + // std::cerr<<"double as float=" << val << '\n'; float copy(val); write(copy); } void Foam::foamVtkAppendRawFormatter::flush() -{} +{/*nop*/} // ************************************************************************* // diff --git a/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.H b/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.H index abc3db0929..1dcb9b8d55 100644 --- a/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.H +++ b/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.H @@ -77,7 +77,7 @@ public: // Constructors //- Construct and attach to an output stream - foamVtkAppendRawFormatter(std::ostream&); + foamVtkAppendRawFormatter(std::ostream& os); //- Destructor @@ -94,12 +94,14 @@ public: //- Write leading size for binary output - virtual void writeSize(const uint64_t); + virtual void writeSize(const uint64_t nBytes); - virtual void write(const uint8_t); - virtual void write(const label); - virtual void write(const float); - virtual void write(const double); + virtual void write(const uint8_t val); + virtual void write(const label val); + virtual void write(const float val); + virtual void write(const double val); + + //- A no-op for this format virtual void flush(); }; diff --git a/src/fileFormats/vtk/format/foamVtkAsciiFormatter.C b/src/fileFormats/vtk/format/foamVtkAsciiFormatter.C index 6a78f73f53..9ed22db233 100644 --- a/src/fileFormats/vtk/format/foamVtkAsciiFormatter.C +++ b/src/fileFormats/vtk/format/foamVtkAsciiFormatter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -47,6 +47,16 @@ inline void Foam::foamVtkAsciiFormatter::next() } +inline void Foam::foamVtkAsciiFormatter::done() +{ + if (pos_) + { + os()<< '\n'; + } + pos_ = 0; +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::foamVtkAsciiFormatter::foamVtkAsciiFormatter(std::ostream& os) @@ -73,7 +83,7 @@ Foam::foamVtkAsciiFormatter::foamVtkAsciiFormatter Foam::foamVtkAsciiFormatter::~foamVtkAsciiFormatter() { - flush(); + done(); } @@ -91,7 +101,7 @@ const char* Foam::foamVtkAsciiFormatter::encoding() const } -void Foam::foamVtkAsciiFormatter::writeSize(const uint64_t) +void Foam::foamVtkAsciiFormatter::writeSize(const uint64_t ignored) {/*nop*/} @@ -125,11 +135,14 @@ void Foam::foamVtkAsciiFormatter::write(const double val) void Foam::foamVtkAsciiFormatter::flush() { - if (pos_) - { - os()<< '\n'; - } - pos_ = 0; + done(); +} + + +std::size_t +Foam::foamVtkAsciiFormatter::encodedLength(std::size_t ignored) const +{ + return 0; } diff --git a/src/fileFormats/vtk/format/foamVtkAsciiFormatter.H b/src/fileFormats/vtk/format/foamVtkAsciiFormatter.H index 009d776f89..8b8e06b2a2 100644 --- a/src/fileFormats/vtk/format/foamVtkAsciiFormatter.H +++ b/src/fileFormats/vtk/format/foamVtkAsciiFormatter.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -62,9 +62,12 @@ class foamVtkAsciiFormatter // Private Member Functions - //- Advance to next position, adding space or newline as required + //- Advance to next position, adding space or newline as needed inline void next(); + //- Finish an output line, adding newline as needed + inline void done(); + //- Disallow default bitwise copy construct foamVtkAsciiFormatter(const foamVtkAsciiFormatter&) = delete; @@ -78,10 +81,10 @@ public: // Constructors //- Construct and attach to an output stream, use default precision - foamVtkAsciiFormatter(std::ostream&); + foamVtkAsciiFormatter(std::ostream& os); //- Construct and attach to an output stream, use specified precision - foamVtkAsciiFormatter(std::ostream&, unsigned precision); + foamVtkAsciiFormatter(std::ostream& os, unsigned precision); //- Destructor @@ -95,18 +98,24 @@ public: virtual const char* name() const; //- Name for the XML append encoding - unused. - // Currently simply "ASCII", but this should not be relied upon. + // Currently identical to name(), but do not rely on this. virtual const char* encoding() const; //- Write leading size - this is a no-op for ascii output - virtual void writeSize(const uint64_t); + virtual void writeSize(const uint64_t ignored); - virtual void write(const uint8_t); - virtual void write(const label); - virtual void write(const float); - virtual void write(const double); + virtual void write(const uint8_t val); + virtual void write(const label val); + virtual void write(const float val); + virtual void write(const double val); + + //- Write a newline if needed to finish a line of output. virtual void flush(); + + //- The encoded length for ascii output is not applicable. + virtual std::size_t encodedLength(std::size_t ignored) const; + }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/fileFormats/vtk/format/foamVtkBase64Formatter.C b/src/fileFormats/vtk/format/foamVtkBase64Formatter.C index a11d97bd49..f87efbb19f 100644 --- a/src/fileFormats/vtk/format/foamVtkBase64Formatter.C +++ b/src/fileFormats/vtk/format/foamVtkBase64Formatter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -27,28 +27,14 @@ License // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -const char* Foam::foamVtkBase64Formatter::name_ = "binary"; -const char* Foam::foamVtkBase64Formatter::encoding_ = "base64"; - - -// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // - -void Foam::foamVtkBase64Formatter::write -( - const char* s, - std::streamsize n -) -{ - base64Layer::write(s, n); -} +const char* Foam::foamVtkBase64Formatter::name_ = "binary"; // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::foamVtkBase64Formatter::foamVtkBase64Formatter(std::ostream& os) : - foamVtkFormatter(os), - base64Layer(os) + foamVtkBase64Layer(os) {} @@ -56,7 +42,10 @@ Foam::foamVtkBase64Formatter::foamVtkBase64Formatter(std::ostream& os) Foam::foamVtkBase64Formatter::~foamVtkBase64Formatter() { - flush(); + if (base64Layer::close()) + { + os().put('\n'); + } } @@ -68,46 +57,6 @@ const char* Foam::foamVtkBase64Formatter::name() const } -const char* Foam::foamVtkBase64Formatter::encoding() const -{ - return encoding_; -} - - -void Foam::foamVtkBase64Formatter::writeSize(const uint64_t val) -{ - write(reinterpret_cast(&val), sizeof(uint64_t)); -} - - -void Foam::foamVtkBase64Formatter::write(const uint8_t val) -{ - base64Layer::add(val); -} - - -void Foam::foamVtkBase64Formatter::write(const label val) -{ - // std::cerr<<"label is:" << sizeof(val) << '\n'; - write(reinterpret_cast(&val), sizeof(label)); -} - - -void Foam::foamVtkBase64Formatter::write(const float val) -{ - // std::cerr<<"float is:" << sizeof(val) << '\n'; - write(reinterpret_cast(&val), sizeof(float)); -} - - -void Foam::foamVtkBase64Formatter::write(const double val) -{ - // std::cerr<<"write double as float:" << val << '\n'; - float copy(val); - write(copy); -} - - void Foam::foamVtkBase64Formatter::flush() { if (base64Layer::close()) diff --git a/src/fileFormats/vtk/format/foamVtkBase64Formatter.H b/src/fileFormats/vtk/format/foamVtkBase64Formatter.H index f01bec3d9a..e92fa4f9e3 100644 --- a/src/fileFormats/vtk/format/foamVtkBase64Formatter.H +++ b/src/fileFormats/vtk/format/foamVtkBase64Formatter.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -33,8 +33,7 @@ Description #ifndef foamVtkBase64Formatter_H #define foamVtkBase64Formatter_H -#include "foamVtkFormatter.H" -#include "base64Layer.H" +#include "foamVtkBase64Layer.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -47,8 +46,7 @@ namespace Foam class foamVtkBase64Formatter : - public foamVtkFormatter, - private base64Layer + public foamVtkBase64Layer { // Private Data Members @@ -64,20 +62,12 @@ class foamVtkBase64Formatter //- Disallow default bitwise assignment void operator=(const foamVtkBase64Formatter&) = delete; -protected: - - // Protected Member Functions - - //- Write - void write(const char* s, std::streamsize n); - - public: // Constructors //- Construct and attach to an output stream - foamVtkBase64Formatter(std::ostream&); + foamVtkBase64Formatter(std::ostream& os); //- Destructor @@ -90,17 +80,9 @@ public: // The lowercase version of the Legacy output type. virtual const char* name() const; - //- Name for the XML append encoding. - virtual const char* encoding() const; - - //- Write leading size for binary output - virtual void writeSize(const uint64_t); - - virtual void write(const uint8_t); - virtual void write(const label); - virtual void write(const float); - virtual void write(const double); + //- End the encoding sequence (padding the final characters with '=') + // and write a newline to the output if any encoding was done. virtual void flush(); }; diff --git a/src/fileFormats/vtk/format/foamVtkBase64Layer.C b/src/fileFormats/vtk/format/foamVtkBase64Layer.C new file mode 100644 index 0000000000..d66970d522 --- /dev/null +++ b/src/fileFormats/vtk/format/foamVtkBase64Layer.C @@ -0,0 +1,116 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "foamVtkBase64Layer.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +const char* Foam::foamVtkBase64Layer::encoding_ = "base64"; + + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +void Foam::foamVtkBase64Layer::write +( + const char* s, + std::streamsize n +) +{ + base64Layer::write(s, n); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::foamVtkBase64Layer::foamVtkBase64Layer(std::ostream& os) +: + foamVtkFormatter(os), + base64Layer(os) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::foamVtkBase64Layer::~foamVtkBase64Layer() +{ + base64Layer::close(); +} + + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +const char* Foam::foamVtkBase64Layer::encoding() const +{ + return encoding_; +} + + +void Foam::foamVtkBase64Layer::writeSize(const uint64_t nBytes) +{ + write(reinterpret_cast(&nBytes), sizeof(uint64_t)); +} + + +void Foam::foamVtkBase64Layer::write(const uint8_t val) +{ + base64Layer::add(val); +} + + +void Foam::foamVtkBase64Layer::write(const label val) +{ + // std::cerr<<"label:" << sizeof(val) << "=" << val << '\n'; + write(reinterpret_cast(&val), sizeof(label)); +} + + +void Foam::foamVtkBase64Layer::write(const float val) +{ + // std::cerr<<"float:" << sizeof(val) << "=" << val << '\n'; + write(reinterpret_cast(&val), sizeof(float)); +} + + +void Foam::foamVtkBase64Layer::write(const double val) +{ + // std::cerr<<"double as float=" << val << '\n'; + float copy(val); + write(copy); +} + + +void Foam::foamVtkBase64Layer::flush() +{ + base64Layer::close(); +} + + +std::size_t Foam::foamVtkBase64Layer::encodedLength(std::size_t n) const +{ + return base64Layer::encodedLength(n); +} + + +// ************************************************************************* // diff --git a/src/fileFormats/vtk/format/foamVtkBase64Layer.H b/src/fileFormats/vtk/format/foamVtkBase64Layer.H new file mode 100644 index 0000000000..61527a11bc --- /dev/null +++ b/src/fileFormats/vtk/format/foamVtkBase64Layer.H @@ -0,0 +1,114 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + foamVtkBase64Layer + +Description + Base-64 encoded output. + +\*---------------------------------------------------------------------------*/ + +#ifndef foamVtkBase64Layer_H +#define foamVtkBase64Layer_H + +#include "foamVtkFormatter.H" +#include "base64Layer.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class foamVtkBase64Layer Declaration +\*---------------------------------------------------------------------------*/ + +class foamVtkBase64Layer +: + public foamVtkFormatter, + protected base64Layer +{ + // Private Data Members + + static const char* encoding_; + + + // Private Member Functions + + //- Disallow default bitwise copy construct + foamVtkBase64Layer(const foamVtkBase64Layer&) = delete; + + //- Disallow default bitwise assignment + void operator=(const foamVtkBase64Layer&) = delete; + +protected: + + // Protected Member Functions + + //- Write + void write(const char* s, std::streamsize n); + + + // Constructors + + //- Construct and attach to an output stream + foamVtkBase64Layer(std::ostream& os); + +public: + + //- Destructor + virtual ~foamVtkBase64Layer(); + + + // Member Functions + + //- Name for the XML append encoding ("base64"). + virtual const char* encoding() const; + + + //- Write leading size for binary output + virtual void writeSize(const uint64_t nBytes); + + virtual void write(const uint8_t val); + virtual void write(const label val); + virtual void write(const float val); + virtual void write(const double val); + + //- End the encoding sequence (padding the final characters with '=') + virtual void flush(); + + //- The encoded length for base64 encoded output. + virtual std::size_t encodedLength(std::size_t n) const; + +}; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/fileFormats/vtk/format/foamVtkFormatter.C b/src/fileFormats/vtk/format/foamVtkFormatter.C index 7271dd22f5..2bc607a78a 100644 --- a/src/fileFormats/vtk/format/foamVtkFormatter.C +++ b/src/fileFormats/vtk/format/foamVtkFormatter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -52,6 +52,12 @@ Foam::foamVtkFormatter::~foamVtkFormatter() // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // +std::size_t Foam::foamVtkFormatter::encodedLength(std::size_t n) const +{ + return n; +} + + void Foam::foamVtkFormatter::indent() { label n = xmlTags_.size() * 2; @@ -149,7 +155,6 @@ Foam::foamVtkFormatter::tag(const word& tag) } - Foam::foamVtkFormatter& Foam::foamVtkFormatter::endTag(const word& tag) { @@ -181,7 +186,6 @@ Foam::foamVtkFormatter::endTag(const word& tag) } - Foam::foamVtkFormatter& Foam::foamVtkFormatter::xmlAttr ( diff --git a/src/fileFormats/vtk/format/foamVtkFormatter.H b/src/fileFormats/vtk/format/foamVtkFormatter.H index 65519b1955..5ab0776d60 100644 --- a/src/fileFormats/vtk/format/foamVtkFormatter.H +++ b/src/fileFormats/vtk/format/foamVtkFormatter.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -74,8 +74,8 @@ class foamVtkFormatter template foamVtkFormatter& xmlAttribute ( - const word&, - const Type&, + const word& k, + const Type& v, const char quote ); @@ -120,14 +120,20 @@ public: //- Write leading size for binary output - virtual void writeSize(const uint64_t) = 0; + virtual void writeSize(const uint64_t nBytes) = 0; - virtual void write(const uint8_t) = 0; - virtual void write(const label) = 0; - virtual void write(const float) = 0; - virtual void write(const double) = 0; + virtual void write(const uint8_t val) = 0; + virtual void write(const label val) = 0; + virtual void write(const float val) = 0; + virtual void write(const double val) = 0; + + //- Flush encoding, write newline etc. virtual void flush() = 0; + //- The encoded length for binary output. + // The default is pass-through. + virtual std::size_t encodedLength(std::size_t n) const; + // Member Functions @@ -138,7 +144,7 @@ public: foamVtkFormatter& xmlHeader(); //- Write XML comment (at the current indentation level) - foamVtkFormatter& comment(const std::string&); + foamVtkFormatter& comment(const std::string& text); //- Open XML tag @@ -177,40 +183,40 @@ public: //- Write XML attribute foamVtkFormatter& xmlAttr ( - const word&, - const std::string&, + const word& k, + const std::string& v, const char quote = '\'' ); //- Write XML attribute foamVtkFormatter& xmlAttr ( - const word&, - const int32_t, + const word& k, + const int32_t v, const char quote = '\'' ); //- Write XML attribute foamVtkFormatter& xmlAttr ( - const word&, - const int64_t, + const word& k, + const int64_t v, const char quote = '\'' ); //- Write XML attribute foamVtkFormatter& xmlAttr ( - const word&, - const uint64_t, + const word& k, + const uint64_t v, const char quote = '\'' ); //- Write XML attribute foamVtkFormatter& xmlAttr ( - const word&, - const scalar, + const word& k, + const scalar v, const char quote = '\'' ); @@ -219,19 +225,19 @@ public: // Member Operators //- Write XML attribute - foamVtkFormatter& operator()(const word&, const std::string&); + foamVtkFormatter& operator()(const word& k, const std::string& v); //- Write XML attribute - foamVtkFormatter& operator()(const word&, const int32_t); + foamVtkFormatter& operator()(const word& k, const int32_t v); //- Write XML attribute - foamVtkFormatter& operator()(const word&, const int64_t); + foamVtkFormatter& operator()(const word& k, const int64_t v); //- Write XML attribute - foamVtkFormatter& operator()(const word&, const uint64_t); + foamVtkFormatter& operator()(const word& k, const uint64_t v); //- Write XML attribute - foamVtkFormatter& operator()(const word&, const scalar); + foamVtkFormatter& operator()(const word& k, const scalar v); }; diff --git a/src/fileFormats/vtk/format/foamVtkLegacyFormatter.C b/src/fileFormats/vtk/format/foamVtkLegacyFormatter.C index 89525ab0ba..a3e87264f8 100644 --- a/src/fileFormats/vtk/format/foamVtkLegacyFormatter.C +++ b/src/fileFormats/vtk/format/foamVtkLegacyFormatter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -71,8 +71,8 @@ const char* Foam::foamVtkLegacyFormatter::encoding() const } -void Foam::foamVtkLegacyFormatter::writeSize(const uint64_t) -{} +void Foam::foamVtkLegacyFormatter::writeSize(const uint64_t ignored) +{/*nop*/} void Foam::foamVtkLegacyFormatter::write(const uint8_t val) diff --git a/src/fileFormats/vtk/format/foamVtkLegacyFormatter.H b/src/fileFormats/vtk/format/foamVtkLegacyFormatter.H index fe2395add4..6ec5ba7e8d 100644 --- a/src/fileFormats/vtk/format/foamVtkLegacyFormatter.H +++ b/src/fileFormats/vtk/format/foamVtkLegacyFormatter.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,11 +25,10 @@ Class foamVtkLegacyFormatter Description - Binary output for the VTK legacy format, always written as big-endian. + Binary output for the VTK legacy format, always written as big-endian + and with 32-bit integers. - The legacy files are always written as big endian. - Since integers in the legacy format are limited to 32-bit, - this format should not be used for OpenFOAM with 64-bit label sizes. + This format should never be used for OpenFOAM with 64-bit label sizes. SourceFiles foamVtkLegacyFormatter.C @@ -81,7 +80,7 @@ public: // Constructors //- Construct and attach to an output stream - foamVtkLegacyFormatter(std::ostream&); + foamVtkLegacyFormatter(std::ostream& os); //- Destructor @@ -90,22 +89,25 @@ public: // Member Functions - //- Name for the Legacy output type ("BINARY") + //- Name for the legacy binary output type ("BINARY") virtual const char* name() const; //- Name for the XML append encoding (unused) - // Currently simply "BINARY", but this should not be relied upon. + // Currently identical to name(), but do not rely on this. virtual const char* encoding() const; //- Write leading size - a no-op for legacy binary output - virtual void writeSize(const uint64_t); + virtual void writeSize(const uint64_t ignored); - virtual void write(const uint8_t); - virtual void write(const label); - virtual void write(const float); - virtual void write(const double); + virtual void write(const uint8_t val); + virtual void write(const label val); + virtual void write(const float val); + virtual void write(const double val); + + //- Write a newline to the output virtual void flush(); + }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/fileFormats/vtk/format/foamVtkOutputOptions.C b/src/fileFormats/vtk/format/foamVtkOutputOptions.C index 39f11a432e..c88d334594 100644 --- a/src/fileFormats/vtk/format/foamVtkOutputOptions.C +++ b/src/fileFormats/vtk/format/foamVtkOutputOptions.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -45,10 +45,8 @@ Foam::foamVtkOutputOptions::foamVtkOutputOptions() // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * // -Foam::autoPtr Foam::foamVtkOutputOptions::newFormatter -( - std::ostream& os -) const +Foam::autoPtr +Foam::foamVtkOutputOptions::newFormatter(std::ostream& os) const { switch (type_) { @@ -87,9 +85,9 @@ Foam::autoPtr Foam::foamVtkOutputOptions::newFormatter // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // -void Foam::foamVtkOutputOptions::ascii(bool b) +void Foam::foamVtkOutputOptions::ascii(bool on) { - if (b) + if (on) { // Force ASCII: @@ -132,9 +130,9 @@ void Foam::foamVtkOutputOptions::ascii(bool b) } -void Foam::foamVtkOutputOptions::append(bool b) +void Foam::foamVtkOutputOptions::append(bool on) { - if (b) + if (on) { if (!(type_ & APPEND)) { @@ -153,9 +151,9 @@ void Foam::foamVtkOutputOptions::append(bool b) } -void Foam::foamVtkOutputOptions::legacy(bool b) +void Foam::foamVtkOutputOptions::legacy(bool on) { - if (b) + if (on) { if (type_ & APPEND) { @@ -180,9 +178,9 @@ void Foam::foamVtkOutputOptions::legacy(bool b) } -void Foam::foamVtkOutputOptions::precision(unsigned val) const +void Foam::foamVtkOutputOptions::precision(unsigned prec) const { - precision_ = val; + precision_ = prec; } diff --git a/src/fileFormats/vtk/format/foamVtkOutputOptions.H b/src/fileFormats/vtk/format/foamVtkOutputOptions.H index a5f59de514..7e0e89b24b 100644 --- a/src/fileFormats/vtk/format/foamVtkOutputOptions.H +++ b/src/fileFormats/vtk/format/foamVtkOutputOptions.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -88,7 +88,7 @@ public: // Selectors //- Return new data formatter based on the writer options - autoPtr newFormatter(std::ostream&) const; + autoPtr newFormatter(std::ostream& os) const; // Member Functions @@ -117,16 +117,16 @@ public: // In append mode, this switches between base64 and raw binary. // In XML mode, this switches between ASCII and base64. // In legacy mode, this switches between ASCII and binary. - void ascii(bool); + void ascii(bool on); //- Toggle append mode on/off. - void append(bool); + void append(bool on); //- Toggle legacy mode on/off. - void legacy(bool); + void legacy(bool on); //- Set the write precision to be used for new ASCII formatters - void precision(unsigned val) const; + void precision(unsigned prec) const; // Other From 2cc23a23e7e698eb40d8ba031813e030bbb1be63 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 17 Jan 2017 08:54:07 +0100 Subject: [PATCH 14/35] BUG: missing specializations in foamVtkPTraits header --- src/fileFormats/vtk/type/foamVtkPTraits.C | 4 ++-- src/fileFormats/vtk/type/foamVtkPTraits.H | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/fileFormats/vtk/type/foamVtkPTraits.C b/src/fileFormats/vtk/type/foamVtkPTraits.C index 91bf1f3a33..feb5e909c2 100644 --- a/src/fileFormats/vtk/type/foamVtkPTraits.C +++ b/src/fileFormats/vtk/type/foamVtkPTraits.C @@ -59,11 +59,11 @@ Foam::foamVtkPTraits::typeName = "Float64"; #ifdef WM_LITTLE_ENDIAN template<> const char* const -Foam::foamVtkPTraits<::Foam::endian>::typeName = "LittleEndian"; +Foam::foamVtkPTraits::typeName = "LittleEndian"; #else template<> const char* const -Foam::foamVtkPTraits<::Foam::endian>::typeName = "BigEndian"; +Foam::foamVtkPTraits::typeName = "BigEndian"; #endif diff --git a/src/fileFormats/vtk/type/foamVtkPTraits.H b/src/fileFormats/vtk/type/foamVtkPTraits.H index ea95c0820d..ff77c03b8d 100644 --- a/src/fileFormats/vtk/type/foamVtkPTraits.H +++ b/src/fileFormats/vtk/type/foamVtkPTraits.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -58,28 +58,28 @@ public: template<> -const char* const foamVtkPTraits::typeName; // = UInt8 +const char* const foamVtkPTraits::typeName; // UInt8 template<> -const char* const foamVtkPTraits::typeName; // = Int32 +const char* const foamVtkPTraits::typeName; // Int32 template<> -const char* const foamVtkPTraits::typeName; // = UInt32 +const char* const foamVtkPTraits::typeName; // UInt32 template<> -const char* const foamVtkPTraits::typeName; // = Int64 +const char* const foamVtkPTraits::typeName; // Int64 template<> -const char* const foamVtkPTraits::typeName; // = UInt64 +const char* const foamVtkPTraits::typeName; // UInt64 template<> -const char* const foamVtkPTraits::typeName; // = Float32 +const char* const foamVtkPTraits::typeName; // Float32 template<> -const char* const foamVtkPTraits::typeName; // = Float64 +const char* const foamVtkPTraits::typeName; // Float64 template<> -const char* const foamVtkPTraits<::Foam::endian>::typeName; +const char* const foamVtkPTraits::typeName; // (Big|Little)Endian // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // From 9d63cc5ca8ce20fffb0b34a16402edb9c0a2ce4f Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 23 Jan 2017 13:37:42 +0100 Subject: [PATCH 15/35] ENH: add versioning for VTK library to runTimePostProcessing (issue #370) Eg, librunTimePostProcessing.so librunTimePostProcessing.so.7 -> librunTimePostProcessing.so.7.1.0 librunTimePostProcessing.so.7.1.0 - centralize handling of paraview/vtk versioning into wmake/cmakeFunctions --- .../graphics/PVReaders/Allwmake | 80 +-------- .../graphics/PVReaders/PVFoamReader/Allwmake | 92 +--------- .../PVReaders/PVblockMeshReader/Allwmake | 92 +--------- .../graphics/runTimePostProcessing/Allwmake | 96 ++--------- .../CMakeLists-Common.txt | 22 ++- wmake/scripts/cmakeFunctions | 163 ++++++++++++++++++ wmake/scripts/wmakeFunctions | 5 +- 7 files changed, 203 insertions(+), 347 deletions(-) create mode 100644 wmake/scripts/cmakeFunctions mode change 100755 => 100644 wmake/scripts/wmakeFunctions diff --git a/applications/utilities/postProcessing/graphics/PVReaders/Allwmake b/applications/utilities/postProcessing/graphics/PVReaders/Allwmake index 2f89bc4c8a..13eb3a9470 100755 --- a/applications/utilities/postProcessing/graphics/PVReaders/Allwmake +++ b/applications/utilities/postProcessing/graphics/PVReaders/Allwmake @@ -7,84 +7,8 @@ export WM_CONTINUE_ON_ERROR=true # Parse arguments for library compilation . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments -# Source the wmake functions -. $WM_PROJECT_DIR/wmake/scripts/wmakeFunctions - -# ----------------------------------------------------------------------------- - -# -# There are several prerequisites for building plugins -# -#set -x -canBuildPlugin() -{ - [ -d "$ParaView_DIR" -a -r "$ParaView_DIR" ] || { - echo "==> cannot build ParaView plugins without paraview directory" - echo " ParaView_DIR=$ParaView_DIR" - return 1 - } - - [ -n "$PV_PLUGIN_PATH" ] || { - echo "==> ${PWD##*/} : invalid PV_PLUGIN_PATH for building ParaView plugins" - echo " PV_PLUGIN_PATH=${PV_PLUGIN_PATH:-unset}" - return 1 - } - - type cmake > /dev/null 2>&1 || { - echo "==> cannot build ParaView plugins without cmake" - return 1 - } - - return 0 # success -} - - -# -# Check sentinel file(s) to handle paraview version changes -# -versionOk() -{ - findObjectDir "$1" # Where generated files are stored - local sentinel="$objectsDir/ThirdParty" - - echo $sentinel - - local prev - if read -r prev 2>/dev/null < $sentinel - then - case "$prev" in - ("ParaView_DIR=$ParaView_DIR") - return 0 - ;; - (*) - echo "ParaView_DIR changed between builds" 1>&2 - return 1 - ;; - esac - elif [ -f "$objectsDir/CMakeCache.txt" ] - then - echo "previous build was incomplete" 1>&2 - return 1 - else - return 0 - fi -} - - -# -# Build library - use sentinel file(s) to handle paraview version changes -# -wmakeLibPv() -{ - for libName - do - sentinel=$(versionOk $libName) || wclean $libName # version changed - wmake $targetType $libName && { - echo "ParaView_DIR=$ParaView_DIR" > $sentinel - } - done -} - +# Source CMake functions +. $WM_PROJECT_DIR/wmake/scripts/cmakeFunctions # ----------------------------------------------------------------------------- diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/Allwmake b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/Allwmake index afba137322..b9f216f54e 100755 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/Allwmake +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/Allwmake @@ -4,94 +4,8 @@ cd ${0%/*} || exit 1 # Run from this directory # Parse arguments for library compilation . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments -# Source the wmake functions -. $WM_PROJECT_DIR/wmake/scripts/wmakeFunctions - -# Ensure CMake gets the correct C/C++ compilers -[ -n "$WM_CC" ] && export CC="$WM_CC" -[ -n "$WM_CXX" ] && export CXX="$WM_CXX" - -# ----------------------------------------------------------------------------- - -# -# Check sentinel file(s) to handle paraview version changes -# -versionOk() -{ - findObjectDir "$1" # Where generated files are stored - local sentinel="$objectsDir/ThirdParty" - - echo $sentinel - - local prev - if read -r prev 2>/dev/null < $sentinel - then - case "$prev" in - ("ParaView_DIR=$ParaView_DIR") - return 0 - ;; - (*) - echo "ParaView_DIR changed between builds" 1>&2 - return 1 - ;; - esac - elif [ -f "$objectsDir/CMakeCache.txt" ] - then - echo "previous build was incomplete" 1>&2 - return 1 - else - return 0 - fi -} - - -# CMake into objectsDir, -# with an additional attempt if (possibly incorrect) CMakeCache.txt existed -doCmake() -{ - local sourceDir="$1" - findObjectDir $sourceDir # Where are generated files stored? - - # version changed - sentinel=$(versionOk $sourceDir) || rm -rf "$objectsDir" > /dev/null 2>&1 - - test -f "$objectsDir/CMakeCache.txt" - retry=$? # CMakeCache.txt exists, but sources may have moved - - mkdir -p $objectsDir && \ - ( - cd $objectsDir || exit 1 - - cmake $sourceDir || { - if [ $retry -eq 0 ] - then - echo "Removing CMakeCache.txt and attempt again" - rm -f CMakeCache.txt - cmake $sourceDir - else - exit 1 - fi - } && make && { - echo "ParaView_DIR=$ParaView_DIR" > $sentinel - } - ) -} - - -# -# Build library - use sentinel file(s) to handle paraview version changes -# -wmakeLibPv() -{ - for libName - do - sentinel=$(versionOk $libName) || wclean $libName # version changed - wmake $targetType $libName && { - echo "ParaView_DIR=$ParaView_DIR" > $sentinel - } - done -} - +# Source CMake functions +. $WM_PROJECT_DIR/wmake/scripts/cmakeFunctions # ----------------------------------------------------------------------------- @@ -101,7 +15,7 @@ then if [ "$targetType" != objects ] then - doCmake $PWD/PVFoamReader || { + cmakePv $PWD/PVFoamReader || { echo echo " WARNING: incomplete build of ParaView OpenFOAM plugin" echo diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/Allwmake b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/Allwmake index 844b129306..24d577b2ae 100755 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/Allwmake +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/Allwmake @@ -4,94 +4,8 @@ cd ${0%/*} || exit 1 # Run from this directory # Parse arguments for library compilation . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments -# Source the wmake functions -. $WM_PROJECT_DIR/wmake/scripts/wmakeFunctions - -# Ensure CMake gets the correct C/C++ compilers -[ -n "$WM_CC" ] && export CC="$WM_CC" -[ -n "$WM_CXX" ] && export CXX="$WM_CXX" - -# ----------------------------------------------------------------------------- - -# -# Check sentinel file(s) to handle paraview version changes -# -versionOk() -{ - findObjectDir "$1" # Where generated files are stored - local sentinel="$objectsDir/ThirdParty" - - echo $sentinel - - local prev - if read -r prev 2>/dev/null < $sentinel - then - case "$prev" in - ("ParaView_DIR=$ParaView_DIR") - return 0 - ;; - (*) - echo "ParaView_DIR changed between builds" 1>&2 - return 1 - ;; - esac - elif [ -f "$objectsDir/CMakeCache.txt" ] - then - echo "previous build was incomplete" 1>&2 - return 1 - else - return 0 - fi -} - - -# CMake into objectsDir, -# with an additional attempt if (possibly incorrect) CMakeCache.txt existed -doCmake() -{ - local sourceDir="$1" - findObjectDir $sourceDir # Where are generated files stored? - - # version changed - sentinel=$(versionOk $sourceDir) || rm -rf "$objectsDir" > /dev/null 2>&1 - - test -f "$objectsDir/CMakeCache.txt" - retry=$? # CMakeCache.txt exists, but sources may have moved - - mkdir -p $objectsDir && \ - ( - cd $objectsDir || exit 1 - - cmake $sourceDir || { - if [ $retry -eq 0 ] - then - echo "Removing CMakeCache.txt and attempt again" - rm -f CMakeCache.txt - cmake $sourceDir - else - exit 1 - fi - } && make && { - echo "ParaView_DIR=$ParaView_DIR" > $sentinel - } - ) -} - - -# -# Build library - use sentinel file(s) to handle paraview version changes -# -wmakeLibPv() -{ - for libName - do - sentinel=$(versionOk $libName) || wclean $libName # version changed - wmake $targetType $libName && { - echo "ParaView_DIR=$ParaView_DIR" > $sentinel - } - done -} - +# Source CMake functions +. $WM_PROJECT_DIR/wmake/scripts/cmakeFunctions # ----------------------------------------------------------------------------- @@ -101,7 +15,7 @@ then if [ "$targetType" != objects ] then - doCmake $PWD/PVblockMeshReader || { + cmakePv $PWD/PVblockMeshReader || { echo echo " WARNING: incomplete build of ParaView BlockMesh plugin" echo diff --git a/src/functionObjects/graphics/runTimePostProcessing/Allwmake b/src/functionObjects/graphics/runTimePostProcessing/Allwmake index 66ba0b7cc1..d7d73741dc 100755 --- a/src/functionObjects/graphics/runTimePostProcessing/Allwmake +++ b/src/functionObjects/graphics/runTimePostProcessing/Allwmake @@ -1,87 +1,8 @@ #!/bin/sh cd ${0%/*} || exit 1 # Run from this directory -# Source the wmake functions -. $WM_PROJECT_DIR/wmake/scripts/wmakeFunctions - -# Ensure CMake gets the correct C/C++ compilers -[ -n "$WM_CC" ] && export CC="$WM_CC" -[ -n "$WM_CXX" ] && export CXX="$WM_CXX" - -# ----------------------------------------------------------------------------- - -# -# Check sentinel file(s) to handle vtk/paraview version changes -# -versionOk() -{ - findObjectDir "$1" # Where generated files are stored - local sentinel="$objectsDir/ThirdParty" - - echo $sentinel - - local prev - if read -r prev 2>/dev/null < $sentinel - then - case "$prev" in - ("ParaView_DIR=$ParaView_DIR" | "VTK_DIR=$VTK_DIR") - return 0 - ;; - (*) - echo "ParaView_DIR or VTK_DIR changed between builds" 1>&2 - return 1 - ;; - esac - elif [ -f "$objectsDir/CMakeCache.txt" ] - then - echo "previous build was incomplete" 1>&2 - return 1 - else - return 0 - fi -} - - -# CMake into objectsDir, -# with an additional attempt if (possibly incorrect) CMakeCache.txt existed -doCmake() -{ - local sourceDir="$1" - findObjectDir $sourceDir # Where are generated files stored? - - # version changed - sentinel=$(versionOk $sourceDir) || rm -rf "$objectsDir" > /dev/null 2>&1 - - test -f "$objectsDir/CMakeCache.txt" - retry=$? # CMakeCache.txt exists, but sources may have moved - - mkdir -p $objectsDir && \ - ( - cd $objectsDir || exit 1 - - cmake $sourceDir || { - if [ $retry -eq 0 ] - then - echo "Removing CMakeCache.txt and attempt again" - rm -f CMakeCache.txt - cmake $sourceDir - else - exit 1 - fi - } && make && { - if [ -d "$VTK_DIR" ] - then - echo "VTK_DIR=$VTK_DIR" - elif [ -d "$ParaView_DIR" ] - then - echo "ParaView_DIR=$ParaView_DIR" - else - echo unknown - fi > $sentinel - } - ) -} - +# Source CMake functions +. $WM_PROJECT_DIR/wmake/scripts/cmakeFunctions # ----------------------------------------------------------------------------- @@ -89,13 +10,22 @@ echo "======================================================================" echo "${PWD##*/} : $PWD" echo -if [ -d "$VTK_DIR" -o -d "$ParaView_DIR" ] +unset depend +if [ -d "$VTK_DIR" ] +then + depend="VTK_DIR=$VTK_DIR" +elif [ -d "$ParaView_DIR" ] +then + depend="ParaView_DIR=$ParaView_DIR" +fi + +if [ -n "$depend" ] then if [ "$targetType" != objects ] then if type cmake > /dev/null 2>&1 then - doCmake $PWD || { + cmakeVersioned "$depend" $PWD || { echo echo " WARNING: incomplete build of VTK-based post-processing" echo diff --git a/src/functionObjects/graphics/runTimePostProcessing/CMakeLists-Common.txt b/src/functionObjects/graphics/runTimePostProcessing/CMakeLists-Common.txt index 3e7a61e625..3f23c20c3e 100644 --- a/src/functionObjects/graphics/runTimePostProcessing/CMakeLists-Common.txt +++ b/src/functionObjects/graphics/runTimePostProcessing/CMakeLists-Common.txt @@ -32,13 +32,13 @@ add_definitions( set(CMAKE_BUILD_TYPE Release) set(CMAKE_CXX_FLAGS_DEBUG - "-g -O0 -std=c++0x -Wall -Wextra -Wno-unused-parameter -Wnon-virtual-dtor -Wno-overloaded-virtual" + "-g -O0 -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wnon-virtual-dtor -Wno-overloaded-virtual" ) -set(CMAKE_C_FLAGS_DEBUG "-g -O0 -std=c++0x") +set(CMAKE_C_FLAGS_DEBUG "-g -O0 -std=c++11") set(CMAKE_CXX_FLAGS_RELEASE - "-O3 -std=c++0x -Wall -Wextra -Wno-unused-parameter -Wnon-virtual-dtor -Wno-overloaded-virtual") -set(CMAKE_C_FLAGS_RELEASE "-O3 -std=c++0x") + "-O3 -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wnon-virtual-dtor -Wno-overloaded-virtual") +set(CMAKE_C_FLAGS_RELEASE "-O3 -std=c++11") # Set output library destination to plugin directory set(LIBRARY_OUTPUT_PATH $ENV{FOAM_LIBBIN} @@ -46,6 +46,12 @@ set(LIBRARY_OUTPUT_PATH $ENV{FOAM_LIBBIN} "" ) +## Record VTK version for general bookkeeping +# file(WRITE +# ${CMAKE_BINARY_DIR}/version +# "VTK_VERSION=${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}.${VTK_BUILD_VERSION}\n" +# ) + file(GLOB SOURCE_FILES fieldVisualisationBase.C functionObjectBase.C @@ -75,11 +81,17 @@ add_library( ${SOURCE_FILES} ) +set_target_properties( + runTimePostProcessing + PROPERTIES + VERSION ${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}.${VTK_BUILD_VERSION} + SOVERSION ${VTK_MAJOR_VERSION} +) + target_link_libraries( runTimePostProcessing ${VTK_LIBRARIES} ${OPENFOAM_LIBRARIES} ) - #----------------------------------------------------------------------------- diff --git a/wmake/scripts/cmakeFunctions b/wmake/scripts/cmakeFunctions new file mode 100644 index 0000000000..a95e686aea --- /dev/null +++ b/wmake/scripts/cmakeFunctions @@ -0,0 +1,163 @@ +#----------------------------------*-sh-*-------------------------------------- +# ========= | +# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox +# \\ / O peration | +# \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. +# \\/ M anipulation | +#------------------------------------------------------------------------------ +# License +# This file is part of OpenFOAM. +# +# OpenFOAM is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# OpenFOAM is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License +# along with OpenFOAM. If not, see . +# +# Script +# cmakeFunctions +# +# Description +# Helper functions for CMake +#------------------------------------------------------------------------------ + +# Source the wmake functions +. $WM_PROJECT_DIR/wmake/scripts/wmakeFunctions + +# Ensure CMake gets the correct C/C++ compilers +[ -n "$WM_CC" ] && export CC="$WM_CC" +[ -n "$WM_CXX" ] && export CXX="$WM_CXX" + + +#------------------------------------------------------------------------------ + +# +# Check sentinel file(s) to handle paraview / vtk version changes +# +sameDependency() +{ + local depend="$1" + findObjectDir "$2" # Where generated files are stored + local sentinel="$objectsDir/ThirdParty" + + echo $sentinel + + local prev + if read -r prev 2>/dev/null < $sentinel + then + if [ "$prev" = "$depend" ] + then + return 0 + else + echo "${depend%=*} changed between builds" 1>&2 + return 1 + fi + elif [ -f "$objectsDir/CMakeCache.txt" ] + then + echo "previous build was incomplete" 1>&2 + return 1 + else + return 0 + fi +} + + +# CMake into objectsDir with external dependency +cmakeVersioned() +{ + local depend="$1" + local sourceDir="$2" + findObjectDir $sourceDir # Where are generated files stored? + + local sentinel + + # version changed + sentinel=$(sameDependency "$depend" "$sourceDir") \ + || rm -rf "$objectsDir" > /dev/null 2>&1 + + test -f "$objectsDir/CMakeCache.txt" + retry=$? # Additional attempt if sources moved + + mkdir -p $objectsDir && \ + ( + cd $objectsDir || exit 1 + + cmake $sourceDir || { + if [ $retry -eq 0 ] + then + echo "Removing CMakeCache.txt and attempt again" 1>&2 + rm -f CMakeCache.txt + cmake $sourceDir + else + exit 1 + fi + } && make && { echo "$depend" > $sentinel; } + ) +} + + +# CMake into objectsDir with VTK_DIR dependency +cmakeVtk() +{ + cmakeVersioned "VTK_DIR=$VTK_DIR" "$1" +} + + +# CMake into objectsDir with ParaView_DIR dependency +cmakePv() +{ + cmakeVersioned "ParaView_DIR=$ParaView_DIR" "$1" +} + + +# +# Build library - use sentinel file(s) to handle paraview version changes +# +wmakeLibPv() +{ + local depend="ParaView_DIR=$ParaView_DIR" + local sentinel + + for libName + do + # version changed + sentinel=$(sameDependency "$depend" $libName) || wclean $libName + wmake $targetType $libName && { echo "$depend" > $sentinel; } + done +} + + +# +# There are several prerequisites for building plugins +# +canBuildPlugin() +{ + [ -d "$ParaView_DIR" -a -r "$ParaView_DIR" ] || { + echo "==> cannot build ParaView plugins without paraview directory" + echo " ParaView_DIR=$ParaView_DIR" + return 1 + } + + [ -n "$PV_PLUGIN_PATH" ] || { + echo "==> ${PWD##*/} : invalid PV_PLUGIN_PATH for building ParaView plugins" + echo " PV_PLUGIN_PATH=${PV_PLUGIN_PATH:-unset}" + return 1 + } + + type cmake > /dev/null 2>&1 || { + echo "==> cannot build ParaView plugins without cmake" + return 1 + } + + return 0 # success +} + + +#------------------------------------------------------------------------------ diff --git a/wmake/scripts/wmakeFunctions b/wmake/scripts/wmakeFunctions old mode 100755 new mode 100644 index 0262350c20..7a12ad0545 --- a/wmake/scripts/wmakeFunctions +++ b/wmake/scripts/wmakeFunctions @@ -1,11 +1,10 @@ -#!/bin/sh -#------------------------------------------------------------------------------ +#----------------------------------*-sh-*-------------------------------------- # ========= | # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / O peration | # \\ / A nd | Copyright (C) 2015-2016 OpenFOAM Foundation # \\/ M anipulation | -#------------------------------------------------------------------------------- +#------------------------------------------------------------------------------ # License # This file is part of OpenFOAM. # From 14d8f6cb1770714c0e32d0e65e74b8de508c0474 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 25 Jan 2017 11:51:14 +0100 Subject: [PATCH 16/35] DEFEATURE: remove writers for OpenDX format (issue #294) - last OpenDX release/news was from 2007. Cannot maintain or verify if the writers are correct. --- src/sampling/Make/files | 1 - .../writers/dx/dxSurfaceWriter.C | 234 ---------------- .../writers/dx/dxSurfaceWriter.H | 175 ------------ .../writers/dx/dxSurfaceWriterTemplates.C | 80 ------ src/triSurface/Make/files | 1 - .../triSurface/interfaces/DX/writeDX.C | 257 ------------------ src/triSurface/triSurface/triSurface.C | 6 +- src/triSurface/triSurface/triSurface.H | 5 - 8 files changed, 1 insertion(+), 758 deletions(-) delete mode 100644 src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.C delete mode 100644 src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.H delete mode 100644 src/sampling/sampledSurface/writers/dx/dxSurfaceWriterTemplates.C delete mode 100644 src/triSurface/triSurface/interfaces/DX/writeDX.C diff --git a/src/sampling/Make/files b/src/sampling/Make/files index 8dbf6e9394..01cce60496 100644 --- a/src/sampling/Make/files +++ b/src/sampling/Make/files @@ -48,7 +48,6 @@ sampledSurface/thresholdCellFaces/sampledThresholdCellFaces.C surfWriters = sampledSurface/writers $(surfWriters)/surfaceWriter.C -$(surfWriters)/dx/dxSurfaceWriter.C $(surfWriters)/ensight/ensightSurfaceWriter.C $(surfWriters)/foam/foamSurfaceWriter.C $(surfWriters)/nastran/nastranSurfaceWriter.C diff --git a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.C b/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.C deleted file mode 100644 index 6f06073257..0000000000 --- a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.C +++ /dev/null @@ -1,234 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -\*---------------------------------------------------------------------------*/ - -#include "dxSurfaceWriter.H" -#include "makeSurfaceWriterMethods.H" - -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -namespace Foam -{ - makeSurfaceWriterType(dxSurfaceWriter); -} - - -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -void Foam::dxSurfaceWriter::writeGeometry -( - Ostream& os, - const meshedSurf& surf -) -{ - const pointField& points = surf.points(); - const faceList& faces = surf.faces(); - - // Write vertex coordinates - - os << "# The irregular positions" << nl - << "object 1 class array type float rank 1 shape 3 items " - << points.size() << " data follows" << nl; - - forAll(points, pointi) - { - const point& pt = points[pointi]; - - os << float(pt.x()) << ' ' << float(pt.y()) << ' ' << float(pt.z()) - << nl; - } - os << nl; - - // Write triangles - os << "# The irregular connections (triangles)" << nl - << "object 2 class array type int rank 1 shape 3 items " - << faces.size() << " data follows" << nl; - - forAll(faces, facei) - { - const face& f = faces[facei]; - - if (f.size() != 3) - { - FatalErrorInFunction - << "Face " << facei << " vertices " << f - << " is not a triangle." - << exit(FatalError); - } - - os << f[0] << ' ' << f[1] << ' ' << f[2] << nl; - } - os << "attribute \"element type\" string \"triangles\"" << nl - << "attribute \"ref\" string \"positions\"" << nl << nl; -} - - -void Foam::dxSurfaceWriter::writeTrailer(Ostream& os, const bool isNodeValues) -{ - if (isNodeValues) - { - os << nl << "attribute \"dep\" string \"positions\"" - << nl << nl; - } - else - { - os << nl << "attribute \"dep\" string \"connections\"" - << nl << nl; - } - - os << "# the field, with three components: \"positions\"," - << " \"connections\", and \"data\"" << nl - << "object \"irregular positions irregular " - << "connections\" class field" - << nl - << "component \"positions\" value 1" << nl - << "component \"connections\" value 2" << nl - << "component \"data\" value 3" << nl; - - os << "end" << endl; -} - - -namespace Foam -{ - template<> - void Foam::dxSurfaceWriter::writeData - ( - Ostream& os, - const Field& values - ) - { - os << "object 3 class array type float rank 0 items " - << values.size() << " data follows" << nl; - - forAll(values, elemI) - { - os << float(values[elemI]) << nl; - } - } - - - template<> - void Foam::dxSurfaceWriter::writeData - ( - Ostream& os, - const Field& values - ) - { - os << "object 3 class array type float rank 1 shape 3 items " - << values.size() << " data follows" << nl; - - forAll(values, elemI) - { - os << float(values[elemI].x()) << ' ' - << float(values[elemI].y()) << ' ' - << float(values[elemI].z()) << nl; - } - } - - - template<> - void Foam::dxSurfaceWriter::writeData - ( - Ostream& os, - const Field& values - ) - { - os << "object 3 class array type float rank 0 items " - << values.size() << " data follows" << nl; - - forAll(values, elemI) - { - os << float(values[elemI][0]) << nl; - } - } - - - template<> - void Foam::dxSurfaceWriter::writeData - ( - Ostream& os, - const Field& values - ) - { - os << "object 3 class array type float rank 2 shape 3 items " - << values.size() << " data follows" << nl; - - forAll(values, elemI) - { - const symmTensor& t = values[elemI]; - - os << float(t.xx()) << ' ' << float(t.xy()) << ' ' << float(t.xz()) - << float(t.xy()) << ' ' << float(t.yy()) << ' ' << float(t.yz()) - << float(t.xz()) << ' ' << float(t.yz()) << ' ' << float(t.zz()) - << nl; - } - } - - - // Write Field in DX format - template<> - inline void Foam::dxSurfaceWriter::writeData - ( - Ostream& os, - const Field& values - ) - { - os << "object 3 class array type float rank 2 shape 3 items " - << values.size() << " data follows" << nl; - - forAll(values, elemI) - { - const tensor& t = values[elemI]; - - os << float(t.xx()) << ' ' << float(t.xy()) << ' ' << float(t.xz()) - << float(t.yx()) << ' ' << float(t.yy()) << ' ' << float(t.yz()) - << float(t.zx()) << ' ' << float(t.zy()) << ' ' << float(t.zz()) - << nl; - } - } -} - - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -Foam::dxSurfaceWriter::dxSurfaceWriter() -: - surfaceWriter() -{} - - -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -Foam::dxSurfaceWriter::~dxSurfaceWriter() -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -// create write methods -defineSurfaceWriterWriteFields(Foam::dxSurfaceWriter); - - -// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.H b/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.H deleted file mode 100644 index 8a169d3beb..0000000000 --- a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.H +++ /dev/null @@ -1,175 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -Class - Foam::dxSurfaceWriter - -Description - A surfaceWriter for OpenDX format. - -SourceFiles - dxSurfaceWriter.C - -\*---------------------------------------------------------------------------*/ - -#ifndef dxSurfaceWriter_H -#define dxSurfaceWriter_H - -#include "surfaceWriter.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -/*---------------------------------------------------------------------------*\ - Class dxSurfaceWriter Declaration -\*---------------------------------------------------------------------------*/ - -class dxSurfaceWriter -: - public surfaceWriter -{ - - // Private Member Functions - - static void writeGeometry(Ostream&, const meshedSurf&); - static void writeTrailer(Ostream&, const bool isNodeValues); - - template - static void writeData(Ostream&, const Field&); - - //- Templated write operation - template - fileName writeTemplate - ( - const fileName& outputDir, - const fileName& surfaceName, - const meshedSurf& surf, - const word& fieldName, - const Field& values, - const bool isNodeValues, - const bool verbose - ) const; - - -public: - - //- Runtime type information - TypeName("dx"); - - - // Constructors - - //- Construct null - dxSurfaceWriter(); - - - //- Destructor - virtual ~dxSurfaceWriter(); - - - // Member Functions - - //- Write scalarField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual fileName write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const meshedSurf& surf, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues, - const bool verbose = false - ) const; // override - - //- Write vectorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual fileName write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const meshedSurf& surf, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues, - const bool verbose = false - ) const; // override - - //- Write sphericalTensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual fileName write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const meshedSurf& surf, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues, - const bool verbose = false - ) const; // override - - //- Write symmTensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual fileName write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const meshedSurf& surf, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues, - const bool verbose = false - ) const; // override - - //- Write tensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual fileName write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const meshedSurf& surf, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues, - const bool verbose = false - ) const; // override -}; - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#ifdef NoRepository - #include "dxSurfaceWriterTemplates.C" -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriterTemplates.C b/src/sampling/sampledSurface/writers/dx/dxSurfaceWriterTemplates.C deleted file mode 100644 index f9bb67c99a..0000000000 --- a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriterTemplates.C +++ /dev/null @@ -1,80 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -\*---------------------------------------------------------------------------*/ - -#include "OFstream.H" -#include "OSspecific.H" - -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -template -inline void Foam::dxSurfaceWriter::writeData -( - Ostream& os, - const Field& values -) -{ - os << "object 3 class array type float rank 0 items " - << values.size() << " data follows" << nl; - - forAll(values, elemI) - { - os << float(0.0) << nl; - } -} - - -template -Foam::fileName Foam::dxSurfaceWriter::writeTemplate -( - const fileName& outputDir, - const fileName& surfaceName, - const meshedSurf& surf, - const word& fieldName, - const Field& values, - const bool isNodeValues, - const bool verbose -) const -{ - if (!isDir(outputDir)) - { - mkDir(outputDir); - } - - OFstream os(outputDir/fieldName + '_' + surfaceName + ".dx"); - - if (verbose) - { - Info<< "Writing field " << fieldName << " to " << os.name() << endl; - } - - writeGeometry(os, surf); - writeData(os, values); - writeTrailer(os, isNodeValues); - - return os.name(); -} - - -// ************************************************************************* // diff --git a/src/triSurface/Make/files b/src/triSurface/Make/files index fab067d63e..337ccbac83 100644 --- a/src/triSurface/Make/files +++ b/src/triSurface/Make/files @@ -16,7 +16,6 @@ $(interfaces)/OFF/readOFF.C $(interfaces)/OFF/writeOFF.C $(interfaces)/TRI/writeTRI.C $(interfaces)/TRI/readTRI.C -$(interfaces)/DX/writeDX.C $(interfaces)/AC3D/readAC.C $(interfaces)/AC3D/writeAC.C $(interfaces)/VTK/readVTK.C diff --git a/src/triSurface/triSurface/interfaces/DX/writeDX.C b/src/triSurface/triSurface/interfaces/DX/writeDX.C deleted file mode 100644 index 9e28c0f5cb..0000000000 --- a/src/triSurface/triSurface/interfaces/DX/writeDX.C +++ /dev/null @@ -1,257 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -Description - OpenDX format. Both data-only and scalar/vector data. - -\*---------------------------------------------------------------------------*/ - -#include "triSurface.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -// Geometry (positions + connections) -// writeSorted: sort acc. to patch -void triSurface::writeDXGeometry -( - const bool writeSorted, - Ostream& os -) const -{ - labelList faceMap; - surfacePatchList patches(calcPatches(faceMap)); - - // Print patch names as comment - os << "# Patches:" << endl; - forAll(patches, patchi) - { - os << "# " << patchi << " " - << patches[patchi].name() << endl; - } - os << nl << endl; - - // Write vertex coordinates - - os << "# The irregular positions" << endl - << "object 1 class array type float rank 1 shape 3 items " - << nPoints() << " data follows" << endl; - forAll(localPoints(), pointi) - { - const point& pt = localPoints()[pointi]; - os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl; - } - os << endl; - - os << "# The irregular connections (triangles)" << endl - << "object 2 class array type int rank 1 shape 3 items " - << size() << " data follows" << endl; - - if (writeSorted) - { - label faceIndex = 0; - - forAll(patches, patchi) - { - // Print all faces belonging to this patch - - for - ( - label patchFacei = 0; - patchFacei < patches[patchi].size(); - patchFacei++ - ) - { - const label facei = faceMap[faceIndex++]; - const labelledTri& f = localFaces()[facei]; - - os << f[0] << ' ' << f[1] << ' ' << f[2] << endl; - } - } - } - else - { - forAll(*this, facei) - { - const labelledTri& f = localFaces()[facei]; - - os << f[0] << ' ' << f[1] << ' ' << f[2] << endl; - } - } - os << "attribute \"element type\" string \"triangles\"" << endl - << "attribute \"ref\" string \"positions\"" << endl << endl; -} - - -// Standard trailer -void triSurface::writeDXTrailer(Ostream& os) const -{ - os << "# the field, with three components: \"positions\", \"connections\"" - << ", and \"data\"" << endl - << "object \"irregular positions irregular connections\" class field" - << endl - << "component \"positions\" value 1" << endl - << "component \"connections\" value 2" << endl - << "component \"data\" value 3" << endl; -} - - -// Geometry only (data field is either faceIndex or patchIndex) -void triSurface::writeDX(const bool writeSorted, Ostream& os) const -{ - writeDXGeometry(writeSorted, os); - - os << "object 3 class array type float rank 0 items " << size() - << " data follows" << endl; - if (writeSorted) - { - // Write patch number as data - - labelList faceMap; - surfacePatchList patches(calcPatches(faceMap)); - - forAll(patches, patchi) - { - forAll(patches[patchi], patchFacei) - { - os << patchi << endl; - } - } - } - else - { - // Write face number as data - - forAll(*this, facei) - { - os << facei << endl; - } - } - - os << endl << "attribute \"dep\" string \"connections\"" << endl << endl; - - writeDXTrailer(os); - - os << "end" << endl; -} - - -// Geometry + scalar data -void triSurface::writeDX(const scalarField& field, Ostream& os) const -{ - writeDXGeometry(false, os); - - if (field.size() == size()) - { - // Connections dependent data - os << "object 3 class array type float rank 0 items " << field.size() - << " data follows" << endl; - forAll(field, facei) - { - os << field[facei] << endl; - } - os << endl - << "attribute \"dep\" string \"connections\"" << endl << endl; - } - else if (field.size() == nPoints()) - { - // Positions dependent data - os << "object 3 class array type float rank 0 items " << field.size() - << " data follows" << endl; - forAll(field, pointi) - { - os << field[pointi] << endl; - } - os << endl - << "attribute \"dep\" string \"positions\"" << endl << endl; - } - else - { - FatalErrorInFunction - << "Illegal field size " << field.size() << " is not equal " - << " to number of faces " << size() << " or to number " - << " of points " << nPoints() << exit(FatalError); - } - - writeDXTrailer(os); - - os << "end" << endl; -} - - -// Geometry + vector data -void triSurface::writeDX(const vectorField& field, Ostream& os) const -{ - writeDXGeometry(false, os); - - if (field.size() == size()) - { - // Connections dependent data - os << "object 3 class array type float rank 1 shape 3 items " - << field.size() << " data follows" << endl; - forAll(field, facei) - { - os << field[facei].x() << ' ' - << field[facei].y() << ' ' - << field[facei].z() << endl; - } - os << endl - << "attribute \"dep\" string \"connections\"" << endl << endl; - } - else if (field.size() == nPoints()) - { - // Positions dependent data - os << "object 3 class array type float rank 1 shape 3 items " - << field.size() << " data follows" << endl; - forAll(field, pointi) - { - os << field[pointi].x() << ' ' - << field[pointi].y() << ' ' - << field[pointi].z() << endl; - } - os << endl - << "attribute \"dep\" string \"positions\"" << endl << endl; - } - else - { - FatalErrorInFunction - << "Illegal field size " << field.size() << " is not equal " - << " to number of faces " << size() << " or to number " - << " of points " << nPoints() << exit(FatalError); - } - - writeDXTrailer(os); - - os << "end" << endl; -} - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// ************************************************************************* // diff --git a/src/triSurface/triSurface/triSurface.C b/src/triSurface/triSurface/triSurface.C index 6bc2e9d64b..a5478fcf3e 100644 --- a/src/triSurface/triSurface/triSurface.C +++ b/src/triSurface/triSurface/triSurface.C @@ -464,10 +464,6 @@ void Foam::triSurface::write { writeTRI(sort, OFstream(name)()); } - else if (ext == "dx") - { - writeDX(sort, OFstream(name)()); - } else if (ext == "ac") { writeAC(OFstream(name)()); @@ -483,7 +479,7 @@ void Foam::triSurface::write << " for file " << name << ". Supported extensions are '.ftr', '.stl', '.stlb', " << "'.gts', '.obj', '.vtk'" - << ", '.off', '.dx', '.smesh', '.ac' and '.tri'" + << ", '.off', '.smesh', '.ac' and '.tri'" << exit(FatalError); } } diff --git a/src/triSurface/triSurface/triSurface.H b/src/triSurface/triSurface/triSurface.H index ccf47c713e..4c05e8d1a8 100644 --- a/src/triSurface/triSurface/triSurface.H +++ b/src/triSurface/triSurface/triSurface.H @@ -178,11 +178,6 @@ class triSurface //- Write to Ostream in AC3D format. Always sorted by patch. void writeAC(Ostream&) const; - //- For DX writing. - void writeDX(const bool, Ostream&) const; - void writeDXGeometry(const bool, Ostream&) const; - void writeDXTrailer(Ostream&) const; - // Static private functions From a7195288321096a736fa2a7e770377957d70eb70 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 25 Jan 2017 11:58:55 +0100 Subject: [PATCH 17/35] ENH: use STL reader from surfMesh library for triSurface as well (issue #294) - initial step in reducing duplicate IO for triSurface. - write STL triangle using common core routines from fileFormats --- src/fileFormats/stl/STLCore.C | 4 +- src/fileFormats/stl/STLCore.H | 4 +- src/fileFormats/stl/STLReader.C | 27 +- src/fileFormats/stl/STLReader.H | 53 +- src/fileFormats/stl/STLReaderASCII.L | 13 +- src/fileFormats/stl/STLpoint.H | 10 +- src/fileFormats/stl/STLtriangle.H | 33 +- src/fileFormats/stl/STLtriangleI.H | 22 +- .../surfaceFormats/stl/STLsurfaceFormat.C | 6 +- src/triSurface/Make/files | 2 - .../triSurface/interfaces/STL/readSTL.C | 84 +-- .../triSurface/interfaces/STL/readSTLASCII.L | 490 ------------------ .../triSurface/interfaces/STL/readSTLBINARY.C | 152 ------ .../triSurface/interfaces/STL/writeSTL.C | 105 ++-- src/triSurface/triSurface/triSurface.C | 4 +- src/triSurface/triSurface/triSurface.H | 6 +- 16 files changed, 203 insertions(+), 812 deletions(-) delete mode 100644 src/triSurface/triSurface/interfaces/STL/readSTLASCII.L delete mode 100644 src/triSurface/triSurface/interfaces/STL/readSTLBINARY.C diff --git a/src/fileFormats/stl/STLCore.C b/src/fileFormats/stl/STLCore.C index a38d3a3cdf..9b7c0c2e1c 100644 --- a/src/fileFormats/stl/STLCore.C +++ b/src/fileFormats/stl/STLCore.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -52,7 +52,7 @@ bool Foam::fileFormats::STLCore::isBinaryName const STLFormat& format ) { - return (format == DETECT ? (filename.ext() == "stlb") : format == BINARY); + return (format == UNKNOWN ? (filename.ext() == "stlb") : format == BINARY); } diff --git a/src/fileFormats/stl/STLCore.H b/src/fileFormats/stl/STLCore.H index 548cfabde2..fede83b850 100644 --- a/src/fileFormats/stl/STLCore.H +++ b/src/fileFormats/stl/STLCore.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -61,7 +61,7 @@ public: { ASCII, //!< ASCII BINARY, //!< BINARY - DETECT //!< Detect based on (input) content or (output) extension + UNKNOWN //!< Detect based on (input) content or (output) extension }; diff --git a/src/fileFormats/stl/STLReader.C b/src/fileFormats/stl/STLReader.C index c507b02673..b7b91a0bb7 100644 --- a/src/fileFormats/stl/STLReader.C +++ b/src/fileFormats/stl/STLReader.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -37,6 +37,7 @@ bool Foam::fileFormats::STLReader::readBINARY ) { sorted_ = true; + format_ = UNKNOWN; label nTris = 0; autoPtr streamPtr = readBinaryHeader(filename, nTris); @@ -123,6 +124,7 @@ bool Foam::fileFormats::STLReader::readBINARY names_.clear(); sizes_.transfer(dynSizes); + format_ = BINARY; return true; } @@ -133,7 +135,7 @@ bool Foam::fileFormats::STLReader::readFile const STLFormat& format ) { - if (format == DETECT ? detectBinaryHeader(filename) : format == BINARY) + if (format == UNKNOWN ? detectBinaryHeader(filename) : format == BINARY) { return readBINARY(filename); } @@ -155,10 +157,11 @@ Foam::fileFormats::STLReader::STLReader points_(), zoneIds_(), names_(), - sizes_() + sizes_(), + format_(STLCore::UNKNOWN) { // Auto-detect ASCII/BINARY format - readFile(filename, STLCore::DETECT); + readFile(filename, STLCore::UNKNOWN); } @@ -172,7 +175,8 @@ Foam::fileFormats::STLReader::STLReader points_(), zoneIds_(), names_(), - sizes_() + sizes_(), + format_(STLCore::UNKNOWN) { // Manually specified ASCII/BINARY format readFile(filename, format); @@ -185,4 +189,17 @@ Foam::fileFormats::STLReader::~STLReader() {} +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +void Foam::fileFormats::STLReader::clear() +{ + sorted_ = true; + points_.clear(); + zoneIds_.clear(); + names_.clear(); + sizes_.clear(); + format_ = UNKNOWN; +} + + // ************************************************************************* // diff --git a/src/fileFormats/stl/STLReader.H b/src/fileFormats/stl/STLReader.H index db985181d0..9ed6838bc1 100644 --- a/src/fileFormats/stl/STLReader.H +++ b/src/fileFormats/stl/STLReader.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -25,7 +25,7 @@ Class Foam::fileFormats::STLReader Description - Internal class used by the STLsurfaceFormat + Internal class used by the STLsurfaceFormat and triSurface. SourceFiles STLReader.C @@ -72,17 +72,20 @@ class STLReader //- The solid count, in the order of their first appearance List