------------------------------------------------------------------------------
| 42 | |
| 43 | //------------------------------------------------------------------------------ |
| 44 | vtkViewNode* vtkViewNodeFactory::CreateNode(vtkObject* who) |
| 45 | { |
| 46 | if (!who) |
| 47 | { |
| 48 | return nullptr; |
| 49 | } |
| 50 | |
| 51 | vtkViewNode* (*func)() = nullptr; |
| 52 | |
| 53 | // First, check if there is an exact match for override functions for this |
| 54 | // object type. |
| 55 | { |
| 56 | auto fnOverrideIt = this->Internals->Overrides.find(who->GetClassName()); |
| 57 | if (fnOverrideIt != this->Internals->Overrides.end()) |
| 58 | { |
| 59 | func = fnOverrideIt->second; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | // Next, check if there is an indirect match (one of the parents of this |
| 64 | // object type has an override). If there is more than one override for |
| 65 | // types in this object's hierarchy, choose the most derived one. |
| 66 | if (func == nullptr) |
| 67 | { |
| 68 | vtkIdType closest = VTK_ID_MAX; |
| 69 | for (auto it = this->Internals->Overrides.begin(); it != this->Internals->Overrides.end(); ++it) |
| 70 | { |
| 71 | vtkIdType numberOfGenerations = who->GetNumberOfGenerationsFromBase(it->first.c_str()); |
| 72 | if (numberOfGenerations >= 0 && numberOfGenerations < closest) |
| 73 | { |
| 74 | closest = numberOfGenerations; |
| 75 | func = it->second; |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | // If neither are available, do not create a node for this object. |
| 81 | if (func == nullptr) |
| 82 | { |
| 83 | return nullptr; |
| 84 | } |
| 85 | |
| 86 | // Otherwise, create a node and initialize it. |
| 87 | vtkViewNode* vn = func(); |
| 88 | vn->SetMyFactory(this); |
| 89 | if (vn) |
| 90 | { |
| 91 | vn->SetRenderable(who); |
| 92 | } |
| 93 | |
| 94 | return vn; |
| 95 | } |
| 96 | |
| 97 | //------------------------------------------------------------------------------ |
| 98 | void vtkViewNodeFactory::RegisterOverride(const char* name, vtkViewNode* (*func)()) |