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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
|
/*=========================================================================
Program: ParaView
Module: vtkSMCompositeTreeDomain.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 "vtkSMCompositeTreeDomain.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkPVCompositeDataInformation.h"
#include "vtkPVCompositeDataInformationIterator.h"
#include "vtkPVDataInformation.h"
#include "vtkPVXMLElement.h"
#include "vtkSMInputProperty.h"
#include "vtkSMIntVectorProperty.h"
#include "vtkSMPropertyHelper.h"
#include "vtkSMSourceProxy.h"
vtkStandardNewMacro(vtkSMCompositeTreeDomain);
vtkCxxSetObjectMacro(vtkSMCompositeTreeDomain, Information, vtkPVDataInformation);
//----------------------------------------------------------------------------
vtkSMCompositeTreeDomain::vtkSMCompositeTreeDomain()
{
this->Information = 0;
this->LastInformation = 0;
this->Mode = ALL;
this->DefaultMode = DEFAULT;
this->Source = 0;
this->SourcePort = 0;
}
//----------------------------------------------------------------------------
vtkSMCompositeTreeDomain::~vtkSMCompositeTreeDomain()
{
this->Source = 0;
this->SourcePort = 0;
this->SetInformation(0);
}
//---------------------------------------------------------------------------
void vtkSMCompositeTreeDomain::Update(vtkSMProperty*)
{
this->Source = 0;
this->SourcePort = 0;
this->SetInformation(0);
vtkSMInputProperty* pp = vtkSMInputProperty::SafeDownCast(this->GetRequiredProperty("Input"));
if (pp)
{
this->Update(pp);
}
}
//---------------------------------------------------------------------------
void vtkSMCompositeTreeDomain::InvokeModifiedIfChanged()
{
if (this->Information != this->LastInformation ||
(this->Information && this->UpdateTime < this->Information->GetMTime()))
{
this->LastInformation = this->Information;
this->UpdateTime.Modified();
this->DomainModified();
}
}
//---------------------------------------------------------------------------
vtkSMSourceProxy* vtkSMCompositeTreeDomain::GetSource()
{
return this->Source.GetPointer();
}
//---------------------------------------------------------------------------
void vtkSMCompositeTreeDomain::Update(vtkSMInputProperty* ip)
{
unsigned int i;
unsigned int numProxs = ip->GetNumberOfUncheckedProxies();
for (i = 0; i < numProxs; i++)
{
vtkSMSourceProxy* sp = vtkSMSourceProxy::SafeDownCast(ip->GetUncheckedProxy(i));
if (sp)
{
vtkPVDataInformation* info =
sp->GetDataInformation(ip->GetUncheckedOutputPortForConnection(i));
if (!info)
{
continue;
}
this->Source = sp;
this->SourcePort = ip->GetUncheckedOutputPortForConnection(i);
this->SetInformation(info);
this->InvokeModifiedIfChanged();
return;
}
}
// In case there is no valid unchecked proxy, use the actual
// proxy values
numProxs = ip->GetNumberOfProxies();
for (i = 0; i < numProxs; i++)
{
vtkSMSourceProxy* sp = vtkSMSourceProxy::SafeDownCast(ip->GetProxy(i));
if (sp)
{
vtkPVDataInformation* info = sp->GetDataInformation(ip->GetOutputPortForConnection(i));
if (!info)
{
continue;
}
this->Source = sp;
this->SourcePort = ip->GetOutputPortForConnection(i);
this->SetInformation(info);
this->InvokeModifiedIfChanged();
return;
}
}
}
//---------------------------------------------------------------------------
int vtkSMCompositeTreeDomain::ReadXMLAttributes(vtkSMProperty* prop, vtkPVXMLElement* element)
{
this->Superclass::ReadXMLAttributes(prop, element);
this->Mode = ALL;
const char* mode = element->GetAttribute("mode");
if (mode)
{
if (strcmp(mode, "all") == 0)
{
this->Mode = ALL;
}
else if (strcmp(mode, "leaves") == 0)
{
this->Mode = LEAVES;
}
else if (strcmp(mode, "amr") == 0)
{
this->Mode = AMR;
}
else if (strcmp(mode, "non-leaves") == 0)
{
vtkWarningMacro("Obsolete 'non-leaves' mode detected. Using 'all' instead.");
this->Mode = ALL;
}
else if (strcmp(mode, "none") == 0)
{
// not sure why this mode was ever added or what it stood for <|:0).
vtkWarningMacro("Obsolete 'none' mode detected. Using 'all' instead.");
this->Mode = ALL;
}
else
{
vtkErrorMacro("Unrecognized mode: " << mode);
return 0;
}
}
if (const char* default_mode = element->GetAttribute("default_mode"))
{
if (strcmp(default_mode, "nonempty-leaf") == 0)
{
this->DefaultMode = NONEMPTY_LEAF;
}
else
{
vtkErrorMacro("Unrecognized 'default_mode': " << mode);
return 0;
}
}
if (vtkPVXMLElement* hints = prop->GetHints())
{
vtkPVXMLElement* useFlatIndex = hints->FindNestedElementByName("UseFlatIndex");
if (useFlatIndex && useFlatIndex->GetAttribute("value") &&
strcmp(useFlatIndex->GetAttribute("value"), "0") == 0)
{
this->Mode = AMR;
vtkWarningMacro("'UseFlatIndex' index hint is deprecated. You may simply want "
"to set the 'mode' for the domain to 'amr' in the XML configuration.");
}
}
return 1;
}
//----------------------------------------------------------------------------
int vtkSMCompositeTreeDomain::SetDefaultValues(vtkSMProperty* property, bool use_unchecked_values)
{
vtkSMIntVectorProperty* ivp = vtkSMIntVectorProperty::SafeDownCast(property);
vtkSMPropertyHelper helper(property);
helper.SetUseUnchecked(use_unchecked_values);
if (ivp && this->Information)
{
if (this->Mode == LEAVES || this->DefaultMode == NONEMPTY_LEAF)
{
vtkNew<vtkPVCompositeDataInformationIterator> iter;
iter->SetDataInformation(this->Information);
int index = -1;
for (iter->InitTraversal(); !iter->IsDoneWithTraversal(); iter->GoToNextItem())
{
index++;
if (vtkPVDataInformation* info = iter->GetCurrentDataInformation())
{
vtkPVCompositeDataInformation* cinfo = info->GetCompositeDataInformation();
if (!cinfo->GetDataIsComposite() || cinfo->GetDataIsMultiPiece())
{
break;
}
}
}
if (index != -1)
{
const bool repeatable = (ivp->GetRepeatCommand() == 1);
const int num_elements_per_command = ivp->GetNumberOfElementsPerCommand();
const int num_elements = ivp->GetNumberOfElements();
// Ensure that we don't set incorrect number of elements as the default
// for any property.
if ((repeatable && num_elements_per_command == 1) || (!repeatable && num_elements == 1))
{
helper.Set(0, index);
return 1;
}
}
}
}
return this->Superclass::SetDefaultValues(property, use_unchecked_values);
}
//----------------------------------------------------------------------------
void vtkSMCompositeTreeDomain::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "Information: " << this->Information << endl;
os << indent << "Mode: ";
switch (this->Mode)
{
case ALL:
os << "ALL";
break;
case LEAVES:
os << "LEAVES";
break;
case NON_LEAVES:
os << "NON_LEAVES";
break;
case AMR:
os << "AMR";
default:
os << "UNKNOWN";
}
os << endl;
os << indent << "DefaultMode: ";
switch (this->DefaultMode)
{
case DEFAULT:
os << "DEFAULT";
break;
case NONEMPTY_LEAF:
os << "NONEMPTY_LEAF";
break;
default:
os << "UNKNOWN";
}
os << endl;
os << indent << "SourcePort: " << this->SourcePort << endl;
}
|