1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkDataArraySelection.h
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 /**
16  * @class   vtkDataArraySelection
17  * @brief   Store on/off settings for data arrays for a vtkSource.
18  *
19  * vtkDataArraySelection can be used by vtkSource subclasses to store
20  * on/off settings for whether each vtkDataArray in its input should
21  * be passed in the source's output.  This is primarily intended to
22  * allow file readers to configure what data arrays are read from the
23  * file.
24 */
25 
26 #ifndef vtkDataArraySelection_h
27 #define vtkDataArraySelection_h
28 
29 #include "vtkCommonCoreModule.h" // For export macro
30 #include "vtkObject.h"
31 
32 class vtkDataArraySelectionInternals;
33 
34 class VTKCOMMONCORE_EXPORT vtkDataArraySelection : public vtkObject
35 {
36 public:
37   vtkTypeMacro(vtkDataArraySelection,vtkObject);
38   void PrintSelf(ostream& os, vtkIndent indent) override;
39   static vtkDataArraySelection* New();
40 
41   /**
42    * Enable the array with the given name.  Creates a new entry if
43    * none exists.
44    */
45   void EnableArray(const char* name);
46 
47   /**
48    * Disable the array with the given name.  Creates a new entry if
49    * none exists.
50    */
51   void DisableArray(const char* name);
52 
53   /**
54    * Return whether the array with the given name is enabled.  If
55    * there is no entry, the array is assumed to be disabled.
56    */
57   int ArrayIsEnabled(const char* name);
58 
59   /**
60    * Return whether the array with the given name exists.
61    */
62   int ArrayExists(const char* name);
63 
64   /**
65    * Enable all arrays that currently have an entry.
66    */
67   void EnableAllArrays();
68 
69   /**
70    * Disable all arrays that currently have an entry.
71    */
72   void DisableAllArrays();
73 
74   /**
75    * Get the number of arrays that currently have an entry.
76    */
77   int GetNumberOfArrays();
78 
79   /**
80    * Get the number of arrays that are enabled.
81    */
82   int GetNumberOfArraysEnabled();
83 
84   /**
85    * Get the name of the array entry at the given index.
86    */
87   const char* GetArrayName(int index);
88 
89   /**
90    * Get an index of the array with the given name.
91    */
92   int GetArrayIndex(const char *name);
93 
94   /**
95    * Get the index of an array with the given name among those
96    * that are enabled.  Returns -1 if the array is not enabled.
97    */
98   int GetEnabledArrayIndex(const char* name);
99 
100   /**
101    * Get whether the array at the given index is enabled.
102    */
103   int GetArraySetting(int index);
104 
105   /**
106    * Get whether the array is enabled/disable using its name.
107    */
GetArraySetting(const char * name)108   int GetArraySetting(const char* name)
109   {
110     return this->GetArraySetting(this->GetArrayIndex(name));
111   }
112 
113   /**
114    * Set array setting given the name. If the array doesn't exist, it will be
115    * added.
116    */
117   void SetArraySetting(const char* name, int status);
118 
119   /**
120    * Remove all array entries.
121    */
122   void RemoveAllArrays();
123 
124   /**
125    * Add to the list of arrays that have entries.  For arrays that
126    * already have entries, the settings are untouched.  For arrays
127    * that don't already have an entry, they are assumed to be enabled
128    * by default. The state can also be passed as the second argument.
129    * This method should be called only by the filter owning this
130    * object.
131    */
132   int AddArray(const char* name, bool state=true);
133 
134   /**
135    * Remove an array setting given its index.
136    */
137   void RemoveArrayByIndex(int index);
138 
139   /**
140    * Remove an array setting given its name.
141    */
142   void RemoveArrayByName(const char* name);
143 
144   //@{
145   /**
146    * Set the list of arrays that have entries.  For arrays that
147    * already have entries, the settings are copied.  For arrays that
148    * don't already have an entry, they are assigned the given default
149    * status.  If no default status is given, it is assumed to be on.
150    * There will be no more entries than the names given.  This method
151    * should be called only by the filter owning this object.  The
152    * signature with the default must have a different name due to a
153    * bug in the Borland C++ 5.5 compiler.
154    */
155   void SetArrays(const char* const* names, int numArrays);
156   void SetArraysWithDefault(const char* const* names, int numArrays,
157                             int defaultStatus);
158   //@}
159 
160   /**
161    * Copy the selections from the given vtkDataArraySelection instance.
162    */
163   void CopySelections(vtkDataArraySelection* selections);
164 
165   /**
166    * Update `this` to include values from `other`. For arrays that don't
167    * exist in `this` but exist in `other`, they will get added to `this` with
168    * the same array setting as in `other`. Array settings for arrays already in
169    * `this` are left unchanged.
170    */
171   void Union(vtkDataArraySelection* other);
172 
173 protected:
174   vtkDataArraySelection();
175   ~vtkDataArraySelection() override;
176 
177   // Internal implementation details.
178   vtkDataArraySelectionInternals* Internal;
179 
180 private:
181   vtkDataArraySelection(const vtkDataArraySelection&) = delete;
182   void operator=(const vtkDataArraySelection&) = delete;
183 };
184 
185 #endif
186