vtkSMArraySelectionDomain.cxx 2.91 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
/*=========================================================================

  Program:   ParaView
  Module:    vtkSMArraySelectionDomain.cxx

  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.

=========================================================================*/
#include "vtkSMArraySelectionDomain.h"

#include "vtkObjectFactory.h"
#include "vtkSMStringVectorProperty.h"

vtkStandardNewMacro(vtkSMArraySelectionDomain);

//---------------------------------------------------------------------------
vtkSMArraySelectionDomain::vtkSMArraySelectionDomain()
{
}

//---------------------------------------------------------------------------
vtkSMArraySelectionDomain::~vtkSMArraySelectionDomain()
{
}

//---------------------------------------------------------------------------
void vtkSMArraySelectionDomain::Update(vtkSMProperty* prop)
{
  vtkSMStringVectorProperty* svp = vtkSMStringVectorProperty::SafeDownCast(prop);
  if (svp && svp->GetInformationOnly())
    {
    this->RemoveAllStrings();
    this->SetIntDomainMode(vtkSMStringListRangeDomain::BOOLEAN);

41 42
    if (svp->GetNumberOfElementsPerCommand() == 1 &&
      svp->GetElementType(0) == vtkSMStringVectorProperty::STRING)
43
      {
44 45 46 47 48 49 50
      // Information property does not provide selection information,
      // it simply provides the list of arrays.
      unsigned int numEls = svp->GetNumberOfElements();
      for (unsigned int i=0; i<numEls; i++)
        {
        this->AddString(svp->GetElement(i));
        }
51
      }
52
    else
53
      {
54 55 56 57 58 59 60 61 62 63 64
      unsigned int numEls = svp->GetNumberOfElements();
      if (numEls % 2 != 0)
        {
        vtkErrorMacro("The required property seems to have wrong number of "
          "elements. It should be a multiple of 2");
        return;
        }
      for (unsigned int i=0; i<numEls/2; i++)
        {
        this->AddString(svp->GetElement(i*2));
        }
65
      }
66
    this->InvokeModified();
67 68
    }
}
Clinton Stimpson's avatar
 
Clinton Stimpson committed
69
  
70
//---------------------------------------------------------------------------
Clinton Stimpson's avatar
 
Clinton Stimpson committed
71 72 73
int vtkSMArraySelectionDomain::SetDefaultValues(vtkSMProperty* prop)
{
  vtkSMStringVectorProperty* svp = vtkSMStringVectorProperty::SafeDownCast(prop);
Clinton Stimpson's avatar
 
Clinton Stimpson committed
74
  if(!svp || this->GetNumberOfRequiredProperties() == 0)
Clinton Stimpson's avatar
 
Clinton Stimpson committed
75 76 77 78 79
    {
    return this->Superclass::SetDefaultValues(prop);
    }

  // info property has default values
80 81 82
  vtkSMStringVectorProperty* isvp = vtkSMStringVectorProperty::SafeDownCast(
    prop->GetInformationProperty());
  if (isvp)
Clinton Stimpson's avatar
 
Clinton Stimpson committed
83
    {
84
    svp->Copy(isvp);
Clinton Stimpson's avatar
 
Clinton Stimpson committed
85
    }
Clinton Stimpson's avatar
 
Clinton Stimpson committed
86
  
Clinton Stimpson's avatar
 
Clinton Stimpson committed
87 88
  return 1;
}
89 90 91 92 93 94

//---------------------------------------------------------------------------
void vtkSMArraySelectionDomain::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
}