1 // Created on: 2011-10-27
2 // Created by: Roman KOZLOV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <IVtkTools_ShapeObject.hxx>
17 #include <IVtkTools_ShapeDataSource.hxx>
19 #include <vtkObjectBase.h>
20 #include <vtkObjectFactory.h>
21 #include <vtkDataSet.h>
22 #include <vtkInformation.h>
23 #include <vtkInformationObjectBaseKey.h>
24 #include <vtkDebugLeaks.h>
25 #include <vtkPolyData.h>
27 IVtkTools_ShapeObject::KeyPtr IVtkTools_ShapeObject::myKey = 0;
29 //============================================================================
31 // Purpose: Static method to get vtkInformationKey for retrieving OccShape
32 // instance from the actor.
33 //============================================================================
34 IVtkTools_ShapeObject::KeyPtr IVtkTools_ShapeObject::getKey()
38 myKey = new vtkInformationObjectBaseKey( "OccShapePtr", "IVtkTools_ShapeObject::Key" );
44 //============================================================================
45 // Method: GetOccShape
46 // Purpose: Static method to get OCC shape from VTK actor's data from
47 // information object by key.
48 //============================================================================
49 IVtkOCC_Shape::Handle IVtkTools_ShapeObject::GetOccShape (vtkActor* theActor)
51 IVtkOCC_Shape::Handle anOccShape;
52 IVtkTools_ShapeDataSource* aSrc = IVtkTools_ShapeObject::GetShapeSource (theActor);
55 anOccShape = aSrc->GetShape();
60 //============================================================================
61 // Method: GetShapeSource
62 // Purpose: Static method to get OCC shape source from VTK actor's data from
63 // information object by key.
64 //============================================================================
65 IVtkTools_ShapeDataSource* IVtkTools_ShapeObject::GetShapeSource (vtkActor* theActor)
67 IVtkTools_ShapeDataSource* anOccShapeSource = 0;
68 vtkInformation* anInfo = theActor->GetPropertyKeys();
71 KeyPtr aKey = getKey();
72 if (aKey->Has(anInfo))
74 IVtkTools_ShapeObject* aShapeObj = (IVtkTools_ShapeObject*)(aKey->Get (anInfo));
75 anOccShapeSource = aShapeObj->GetShapeSource();
78 return anOccShapeSource;
81 //============================================================================
82 // Method: SetShapeSource
83 // Purpose: Static method to set OCC shape source to VTK dataset in information
85 //============================================================================
86 void IVtkTools_ShapeObject::SetShapeSource (IVtkTools_ShapeDataSource* theDataSource,
87 vtkDataSet* theDataSet)
89 if (!theDataSet->GetInformation() )
91 theDataSet->SetInformation (vtkInformation::New());
93 vtkInformation* aDatasetInfo = theDataSet->GetInformation();
94 KeyPtr aKey = getKey();
95 IVtkTools_ShapeObject* aShapeObj = IVtkTools_ShapeObject::New();
96 aShapeObj->SetShapeSource (theDataSource);
97 aKey->Set(aDatasetInfo, aShapeObj);
101 //============================================================================
102 // Method: SetShapeSource
103 // Purpose: Static method to set OCC shape source to VTK actor in information
105 //============================================================================
106 void IVtkTools_ShapeObject::SetShapeSource (IVtkTools_ShapeDataSource* theDataSource,
109 if ( !theActor->GetPropertyKeys() )
111 theActor->SetPropertyKeys (vtkInformation::New());
114 vtkInformation* anInfo = theActor->GetPropertyKeys();
115 KeyPtr aKey = getKey();
116 IVtkTools_ShapeObject* aShapeObj = IVtkTools_ShapeObject::New();
117 aShapeObj->SetShapeSource (theDataSource);
118 aKey->Set (anInfo, aShapeObj);
122 //! @class IVtkTools_ShapeObject
123 //! @brief VTK holder class for OCC shapes to pass them through pipelines.
124 vtkStandardNewMacro(IVtkTools_ShapeObject);
126 //============================================================================
127 // Method: Constructor
128 // Purpose: Protected constructor.
129 //============================================================================
130 IVtkTools_ShapeObject::IVtkTools_ShapeObject()
133 //============================================================================
134 // Method: Destructor
135 // Purpose: Protected destructor.
136 //============================================================================
137 IVtkTools_ShapeObject::~IVtkTools_ShapeObject()
140 //============================================================================
141 // Method: SetShapeSource
143 //============================================================================
144 void IVtkTools_ShapeObject::SetShapeSource (IVtkTools_ShapeDataSource* theDataSource)
146 myShapeSource = theDataSource;
149 //============================================================================
150 // Method: GetShapeSource
152 //============================================================================
153 IVtkTools_ShapeDataSource* IVtkTools_ShapeObject::GetShapeSource () const
155 return myShapeSource;