vtkSMEnumerationDomain.h 3.82 KB
Newer Older
Berk Geveci's avatar
Berk Geveci committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*=========================================================================

  Program:   ParaView
  Module:    vtkSMEnumerationDomain.h

  Copyright (c) Kitware, Inc.
  All rights reserved.
  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
Berk Geveci's avatar
Berk Geveci committed
15
// .NAME vtkSMEnumerationDomain - list of integers with associated strings
Berk Geveci's avatar
Berk Geveci committed
16
// .SECTION Description
Berk Geveci's avatar
Berk Geveci committed
17 18
// vtkSMEnumerationDomain represents an enumeration of integer values
// with associated descriptive strings.
Berk Geveci's avatar
Berk Geveci committed
19 20 21 22 23
// Valid XML elements are:
// @verbatim
// * <Entry text="" value=""/> where text is the descriptive
// string and value is the integer value.
// @endverbatim
Berk Geveci's avatar
Berk Geveci committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
// .SECTION See Also
// vtkSMDomain 

#ifndef __vtkSMEnumerationDomain_h
#define __vtkSMEnumerationDomain_h

#include "vtkSMDomain.h"

//BTX
struct vtkSMEnumerationDomainInternals;
//ETX

class VTK_EXPORT vtkSMEnumerationDomain : public vtkSMDomain
{
public:
  static vtkSMEnumerationDomain* New();
40
  vtkTypeMacro(vtkSMEnumerationDomain, vtkSMDomain);
Berk Geveci's avatar
Berk Geveci committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
  void PrintSelf(ostream& os, vtkIndent indent);

  // Description:
  // Returns true if the value of the propery is in the domain.
  // The propery has to be a vtkSMIntVectorProperty. If all 
  // vector values are in the domain, it returns 1. It returns
  // 0 otherwise.
  virtual int IsInDomain(vtkSMProperty* property);

  // Description:
  // Returns true if the int is in the domain. If value is
  // in domain, it's index is return in idx.
  int IsInDomain(int val, unsigned int& idx);

  // Description:
Berk Geveci's avatar
Berk Geveci committed
56
  // Returns the number of entries in the enumeration.
Berk Geveci's avatar
Berk Geveci committed
57 58 59
  unsigned int GetNumberOfEntries();

  // Description:
Berk Geveci's avatar
Berk Geveci committed
60
  // Returns the integer value of an enumeration entry.
Berk Geveci's avatar
Berk Geveci committed
61 62 63
  int GetEntryValue(unsigned int idx);

  // Description:
Berk Geveci's avatar
Berk Geveci committed
64
  // Returns the descriptive string of an enumeration entry.
Berk Geveci's avatar
Berk Geveci committed
65 66
  const char* GetEntryText(unsigned int idx);

67 68 69 70
  // Description:
  // Returns the text for an enumeration value.
  const char* GetEntryTextForValue(int value);

71 72 73 74 75 76 77 78
  // Description:
  // Return 1 is the text is present in the enumeration, otherwise 0.
  int HasEntryText(const char* text);

  // Description:
  // Get the value for an enumeration text. The return value is valid only is
  // HasEntryText() returns 1.
  int GetEntryValueForText(const char* text);
79 80 81 82 83 84 85 86
//BTX
  // Description:
  // Given an entry text, return the integer value.
  // Valid is set to 1 if text is defined, otherwise 0.
  // If valid=0, return value is undefined.
  int GetEntryValue(const char* text, int& valid);
//ETX

Berk Geveci's avatar
Berk Geveci committed
87
  // Description:
Berk Geveci's avatar
Berk Geveci committed
88
  // Add a new enumeration entry. text cannot be null.
Berk Geveci's avatar
Berk Geveci committed
89 90 91
  void AddEntry(const char* text, int value);

  // Description:
Berk Geveci's avatar
Berk Geveci committed
92
  // Clear all entries.
Berk Geveci's avatar
Berk Geveci committed
93 94
  void RemoveAllEntries();

95 96 97 98
  // Description:
  // Update self based on the "unchecked" values of all required
  // properties. Overwritten by sub-classes.
  virtual void Update(vtkSMProperty* property);
99 100 101 102 103

  // Description:
  // Overridden to ensure that the property's default value is valid for the
  // enumeration, if not it will be set to the first enumeration value. 
  virtual int SetDefaultValues(vtkSMProperty*);
Berk Geveci's avatar
Berk Geveci committed
104 105 106 107 108 109 110
protected:
  vtkSMEnumerationDomain();
  ~vtkSMEnumerationDomain();

  // Description:
  // Set the appropriate ivars from the xml element. Should
  // be overwritten by subclass if adding ivars.
Berk Geveci's avatar
Berk Geveci committed
111
  virtual int ReadXMLAttributes(vtkSMProperty* prop, vtkPVXMLElement* element);
Berk Geveci's avatar
Berk Geveci committed
112

113
  virtual void ChildSaveState(vtkPVXMLElement* domainElement);
Berk Geveci's avatar
Berk Geveci committed
114

Berk Geveci's avatar
Berk Geveci committed
115 116 117 118 119 120 121 122
  vtkSMEnumerationDomainInternals* EInternals;

private:
  vtkSMEnumerationDomain(const vtkSMEnumerationDomain&); // Not implemented
  void operator=(const vtkSMEnumerationDomain&); // Not implemented
};

#endif