colourTables.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2019 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "colourTable.H"
29 #include "etcFiles.H"
30 #include "IFstream.H"
31 #include "HashSet.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 Foam::HashPtrTable<Foam::colourTable> Foam::colourTable::tables_;
36 
37 
38 
39 const Foam::Enum
40 <
42 >
44 ({
45  { predefinedType::COOL_WARM, "coolToWarm" },
46  { predefinedType::COLD_HOT, "coldAndHot" },
47  { predefinedType::FIRE, "fire" },
48  { predefinedType::RAINBOW, "rainbow" },
49  { predefinedType::GREYSCALE, "greyscale" },
50  { predefinedType::XRAY, "xray" },
51 });
52 
53 
54 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
55 
56 void Foam::colourTable::constructTables()
57 {
58  if (tables_.size())
59  {
61  << "attempt to re-construct colourTables when they already exist"
62  << exit(FatalError);
63  }
64 
65  IFstream is(findEtcFile("colourTables", true)); // Mandatory file
66 
67  HashPtrTable<colourTable> newEntries(is);
68  tables_.swap(newEntries);
69 
70  Info<< "loaded " << tables_.sortedToc()
71  << " from etc/colourTable" << endl;
72 
73  Info<< "== " << tables_ << nl;
74 }
75 
76 
78 {
79  if (tables_.empty())
80  {
81  constructTables();
82  }
83 
84  return tables_;
85 }
86 
87 
89 {
90  if (tables_.empty())
91  {
92  constructTables();
93  }
94 
95  const auto iter = tables_.cfind(tableName);
96 
97  if (iter.good())
98  {
99  const colourTable* p = iter.val();
100  return p;
101  }
102 
103  return nullptr;
104 }
105 
106 
108 {
109  return ptr(predefinedNames[tbl]);
110 }
111 
112 
114 {
115  const colourTable* p = ptr(tableName);
116 
117  if (!p)
118  {
120  << "No such colourTable: " << tableName
121  << exit(FatalError);
122  }
123 
124  return *p;
125 }
126 
127 
129 {
130  return ref(predefinedNames[tbl]);
131 }
132 
133 
134 // ************************************************************************* //
Foam::colourTable::predefinedNames
static const Enum< predefinedType > predefinedNames
Enumeration names for predefinedType.
Definition: colourTable.H:108
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:57
Foam::colourTable::ptr
static const colourTable * ptr(const word &tableName)
Look up pointer to colourTable by name, or nullptr on failure.
Definition: colourTables.C:88
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::colourTable::predefinedType
predefinedType
Enumeration of commonly used colour tables.
Definition: colourTable.H:93
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
ref
rDeltaT ref()
Foam::findEtcFile
fileName findEtcFile(const fileName &name, const bool mandatory=false, unsigned short location=0777)
Search for a single FILE within the etc directories.
Definition: etcFiles.C:446
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
colourTable.H
IFstream.H
HashSet.H
Foam::FatalError
error FatalError
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
etcFiles.H
Functions to search 'etc' directories for configuration files etc.
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::HashPtrTable< Foam::colourTable >
Foam::colourTable::tables
static const HashPtrTable< colourTable > & tables()
Predefined tables.
Definition: colourTables.C:77
Foam::colourTable
Base class for generating a colour table from node points.
Definition: colourTable.H:79
Foam::colourTable::ref
static const colourTable & ref(const word &tableName)
Look up pointer to colourTable by name. Fatal on failure.
Definition: colourTables.C:113