vtkSMDoubleVectorProperty.cxx 9.96 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*=========================================================================

  Program:   ParaView
  Module:    vtkSMDoubleVectorProperty.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 "vtkSMDoubleVectorProperty.h"

#include "vtkClientServerStream.h"
#include "vtkObjectFactory.h"
19
#include "vtkProcessModule.h"
20 21 22
#include "vtkPVConfig.h" // needed for DEFAULT_DOUBLE_PRECISION_VALUE
#include "vtkPVXMLElement.h"
#include "vtkSMMessage.h"
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
23
#include "vtkSMVectorPropertyTemplate.h"
24
#include "vtkSMStateLocator.h"
25 26 27

vtkStandardNewMacro(vtkSMDoubleVectorProperty);

Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
28 29
class vtkSMDoubleVectorProperty::vtkInternals :
  public vtkSMVectorPropertyTemplate<double>
30
{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
31 32 33 34 35
public:
  vtkInternals(vtkSMDoubleVectorProperty* ivp):
    vtkSMVectorPropertyTemplate<double>(ivp)
  {
  }
36 37 38 39 40
};

//---------------------------------------------------------------------------
vtkSMDoubleVectorProperty::vtkSMDoubleVectorProperty()
{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
41
  this->Internals = new vtkInternals(this);
42
  this->ArgumentIsArray = 0;
43
  this->Precision = DEFAULT_DOUBLE_PRECISION_VALUE;
44 45 46 47 48 49 50 51
}

//---------------------------------------------------------------------------
vtkSMDoubleVectorProperty::~vtkSMDoubleVectorProperty()
{
  delete this->Internals;
}

52
//---------------------------------------------------------------------------
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
53
void vtkSMDoubleVectorProperty::WriteTo(vtkSMMessage* msg)
54
{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
55 56
  ProxyState_Property *prop = msg->AddExtension(ProxyState::property);
  prop->set_name(this->GetXMLName());
57
  Variant *variant = prop->mutable_value();
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
58
  variant->set_type(Variant::FLOAT64);
59
  std::vector<double>::iterator iter;
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
60 61 62 63 64
  for (iter = this->Internals->Values.begin(); iter!=
    this->Internals->Values.end(); ++iter)
    {
    variant->add_float64(*iter);
    }
65 66
}

67
//---------------------------------------------------------------------------
68 69
void vtkSMDoubleVectorProperty::ReadFrom(const vtkSMMessage* msg, int offset,
                                         vtkSMProxyLocator*)
70
{
71 72 73 74 75 76
  assert(msg->ExtensionSize(ProxyState::property) > offset);

  const ProxyState_Property *prop = &msg->GetExtension(ProxyState::property,
    offset);
  assert(strcmp(prop->name().c_str(), this->GetXMLName()) == 0);

77
  const Variant *variant = &prop->value();
78 79 80
  int num_elems = variant->float64_size();
  double *values = new double[num_elems];
  for (int cc=0; cc < num_elems; cc++)
81
    {
82
    values[cc] = variant->float64(cc);
83
    }
84 85
  this->SetElements(values, num_elems);
  delete[] values;
86 87
}

Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
88

Berk Geveci's avatar
Berk Geveci committed
89 90 91
//---------------------------------------------------------------------------
void vtkSMDoubleVectorProperty::SetNumberOfUncheckedElements(unsigned int num)
{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
92
  this->Internals->SetNumberOfUncheckedElements(num);
Berk Geveci's avatar
Berk Geveci committed
93 94
}

95
//---------------------------------------------------------------------------
Berk Geveci's avatar
Berk Geveci committed
96
void vtkSMDoubleVectorProperty::SetNumberOfElements(unsigned int num)
97
{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
98
  this->Internals->SetNumberOfElements(num);
99 100
}

Berk Geveci's avatar
Berk Geveci committed
101 102 103
//---------------------------------------------------------------------------
unsigned int vtkSMDoubleVectorProperty::GetNumberOfUncheckedElements()
{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
104
  return this->Internals->GetNumberOfUncheckedElements();
Berk Geveci's avatar
Berk Geveci committed
105 106
}

107
//---------------------------------------------------------------------------
Berk Geveci's avatar
Berk Geveci committed
108
unsigned int vtkSMDoubleVectorProperty::GetNumberOfElements()
109
{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
110
  return this->Internals->GetNumberOfElements();
111 112
}

113 114 115
//---------------------------------------------------------------------------
double* vtkSMDoubleVectorProperty::GetElements()
{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
116
  return this->Internals->GetElements();
117 118
}

119
//---------------------------------------------------------------------------
Berk Geveci's avatar
Berk Geveci committed
120
double vtkSMDoubleVectorProperty::GetElement(unsigned int idx)
121
{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
122
  return this->Internals->GetElement(idx);
123 124 125
}

//---------------------------------------------------------------------------
Berk Geveci's avatar
Berk Geveci committed
126 127
double vtkSMDoubleVectorProperty::GetUncheckedElement(unsigned int idx)
{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
128
  return this->Internals->GetUncheckedElement(idx);
Berk Geveci's avatar
Berk Geveci committed
129 130 131 132 133 134
}

//---------------------------------------------------------------------------
void vtkSMDoubleVectorProperty::SetUncheckedElement(
  unsigned int idx, double value)
{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
135
  this->Internals->SetUncheckedElement(idx, value);
Berk Geveci's avatar
Berk Geveci committed
136 137 138 139
}

//---------------------------------------------------------------------------
int vtkSMDoubleVectorProperty::SetElement(unsigned int idx, double value)
140
{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
141
  return this->Internals->SetElement(idx, value);
142 143 144
}

//---------------------------------------------------------------------------
Berk Geveci's avatar
Berk Geveci committed
145
int vtkSMDoubleVectorProperty::SetElements1(double value0)
146
{
Berk Geveci's avatar
Berk Geveci committed
147
  return this->SetElement(0, value0);
148 149 150
}

//---------------------------------------------------------------------------
Berk Geveci's avatar
Berk Geveci committed
151
int vtkSMDoubleVectorProperty::SetElements2(double value0, double value1)
152
{
Berk Geveci's avatar
Berk Geveci committed
153 154 155
  int retVal1 = this->SetElement(0, value0);
  int retVal2 = this->SetElement(1, value1);
  return (retVal1 && retVal2);
156 157 158
}

//---------------------------------------------------------------------------
Berk Geveci's avatar
Berk Geveci committed
159
int vtkSMDoubleVectorProperty::SetElements3(
160 161
  double value0, double value1, double value2)
{
Berk Geveci's avatar
Berk Geveci committed
162 163 164 165
  int retVal1 = this->SetElement(0, value0);
  int retVal2 = this->SetElement(1, value1);
  int retVal3 = this->SetElement(2, value2);
  return (retVal1 && retVal2 && retVal3);
166 167
}

168 169 170 171 172 173 174 175 176 177 178
//---------------------------------------------------------------------------
int vtkSMDoubleVectorProperty::SetElements4(
  double value0, double value1, double value2, double value3)
{
  int retVal1 = this->SetElement(0, value0);
  int retVal2 = this->SetElement(1, value1);
  int retVal3 = this->SetElement(2, value2);
  int retVal4 = this->SetElement(3, value3);
  return (retVal1 && retVal2 && retVal3 && retVal4);
}

179 180 181 182
//---------------------------------------------------------------------------
int vtkSMDoubleVectorProperty::SetElements(const double* values,
  unsigned int numValues)
{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
183
  return this->Internals->SetElements(values, numValues);
184 185
}

186
//---------------------------------------------------------------------------
Berk Geveci's avatar
Berk Geveci committed
187
int vtkSMDoubleVectorProperty::SetElements(const double* values)
188
{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
189
  return this->Internals->SetElements(values);
190 191
}

192 193 194 195 196 197 198 199 200 201 202 203
//---------------------------------------------------------------------------
int vtkSMDoubleVectorProperty::SetUncheckedElements(const double* values)
{
  return this->Internals->SetUncheckedElements(values);
}

//---------------------------------------------------------------------------
int vtkSMDoubleVectorProperty::SetUncheckedElements(const double* values, unsigned int numValues)
{
  return this->Internals->SetUncheckedElements(values, numValues);
}

204
//---------------------------------------------------------------------------
Berk Geveci's avatar
Berk Geveci committed
205 206
int vtkSMDoubleVectorProperty::ReadXMLAttributes(vtkSMProxy* proxy,
                                                 vtkPVXMLElement* element)
207 208 209
{
  int retVal;

Berk Geveci's avatar
Berk Geveci committed
210
  retVal = this->Superclass::ReadXMLAttributes(proxy, element);
211 212 213 214 215 216 217 218 219 220 221 222
  if (!retVal)
    {
    return retVal;
    }

  int arg_is_array;
  retVal = element->GetScalarAttribute("argument_is_array", &arg_is_array);
  if(retVal) 
    { 
    this->SetArgumentIsArray(arg_is_array); 
    }

223 224 225 226 227 228
  int precision=0;
  if (element->GetScalarAttribute("precision", &precision))
    {
    this->SetPrecision(precision);
    }

229 230 231
  int numElems = this->GetNumberOfElements();
  if (numElems > 0)
    {
232 233
    if (element->GetAttribute("default_values") &&
        strcmp("none", element->GetAttribute("default_values")) == 0 )
234
      {
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
235
      this->Internals->Initialized = false;
236
      }
237 238
    else
      {
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
      double* initVal = new double[numElems];
      int numRead = element->GetVectorAttribute("default_values",
                                                numElems,
                                                initVal);
      
      if (numRead > 0)
        {
        if (numRead != numElems)
          {
          vtkErrorMacro("The number of default values does not match the number "
                        "of elements. Initialization failed.");
          delete[] initVal;
          return 0;
          }
        this->SetElements(initVal);
        this->Internals->UpdateDefaultValues();
        }
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
256
      else if (!this->Internals->Initialized)
257 258 259 260 261 262
        {
        vtkErrorMacro("No default value is specified for property: "
                      << this->GetXMLName()
                      << ". This might lead to stability problems");
        }
      delete[] initVal;
263
      }
264 265
    }
    
266 267 268
  return 1;
}

269
//---------------------------------------------------------------------------
270
void vtkSMDoubleVectorProperty::Copy(vtkSMProperty* src)
271
{
272
  this->Superclass::Copy(src);
273 274 275

  vtkSMDoubleVectorProperty* dsrc = vtkSMDoubleVectorProperty::SafeDownCast(
    src);
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
276
  if (dsrc)
277
    {
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
278
    this->Internals->Copy(dsrc->Internals);
279 280 281
    }
}

282
//---------------------------------------------------------------------------
283 284 285 286 287 288
void vtkSMDoubleVectorProperty::ClearUncheckedElements()
{
  this->Internals->ClearUncheckedElements();
}

//---------------------------------------------------------------------------
289 290
void vtkSMDoubleVectorProperty::ResetToDefaultInternal()
{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
291
  this->Internals->ResetToDefaultInternal();
292 293
}

294 295 296 297
//---------------------------------------------------------------------------
void vtkSMDoubleVectorProperty::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
Berk Geveci's avatar
Berk Geveci committed
298 299

  os << indent << "ArgumentIsArray: " << this->ArgumentIsArray << endl;
300
  os << indent << "Precision: " << this->Precision << endl;
Berk Geveci's avatar
Berk Geveci committed
301 302 303 304 305 306 307

  os << indent << "Values: ";
  for (unsigned int i=0; i<this->GetNumberOfElements(); i++)
    {
    os << this->GetElement(i) << " ";
    }
  os << endl;
308
}
309 310 311 312 313
//---------------------------------------------------------------------------
void vtkSMDoubleVectorProperty::SaveStateValues(vtkPVXMLElement* propElement)
{
  this->Internals->SaveStateValues(propElement);
}
314 315 316 317 318
//---------------------------------------------------------------------------
int vtkSMDoubleVectorProperty::SetElementAsString(int idx, const char* value)
{
  return this->Internals->SetElementAsString(idx, value);
}