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 // prevent disabling some MSVC warning messages by VTK headers
24 #include <vtkObjectFactory.h>
25 #include <vtkDataSet.h>
26 #include <vtkInformation.h>
27 #include <vtkInformationObjectBaseKey.h>
28 #include <vtkPolyData.h>
33 IVtkTools_ShapeObject::KeyPtr IVtkTools_ShapeObject::myKey = 0;
35 //============================================================================
37 // Purpose: Static method to get vtkInformationKey for retrieving OccShape
38 // instance from the actor.
39 //============================================================================
40 IVtkTools_ShapeObject::KeyPtr IVtkTools_ShapeObject::getKey()
44 myKey = new vtkInformationObjectBaseKey( "OccShapePtr", "IVtkTools_ShapeObject::Key" );
50 //============================================================================
51 // Method: GetOccShape
52 // Purpose: Static method to get OCC shape from VTK actor's data from
53 // information object by key.
54 //============================================================================
55 IVtkOCC_Shape::Handle IVtkTools_ShapeObject::GetOccShape (vtkActor* theActor)
57 IVtkOCC_Shape::Handle anOccShape;
58 vtkSmartPointer<IVtkTools_ShapeDataSource> aSrc =
59 IVtkTools_ShapeObject::GetShapeSource (theActor);
60 if (aSrc.GetPointer() != NULL)
62 anOccShape = aSrc->GetShape();
67 //============================================================================
68 // Method: GetShapeSource
69 // Purpose: Static method to get OCC shape source from VTK actor's data from
70 // information object by key.
71 //============================================================================
72 vtkSmartPointer<IVtkTools_ShapeDataSource> IVtkTools_ShapeObject
73 ::GetShapeSource (vtkActor* theActor)
75 vtkSmartPointer<IVtkTools_ShapeDataSource> anOccShapeSource;
76 vtkSmartPointer<vtkInformation> anInfo = theActor->GetPropertyKeys();
77 if (anInfo.GetPointer() != NULL)
79 KeyPtr aKey = getKey();
80 if (aKey->Has(anInfo))
82 vtkSmartPointer<IVtkTools_ShapeObject> aShapeObj =
83 IVtkTools_ShapeObject::SafeDownCast(aKey->Get (anInfo));
84 anOccShapeSource = aShapeObj->GetShapeSource();
87 return anOccShapeSource;
90 //============================================================================
91 // Method: SetShapeSource
92 // Purpose: Static method to set OCC shape source to VTK dataset in information
94 //============================================================================
95 void IVtkTools_ShapeObject::SetShapeSource (IVtkTools_ShapeDataSource* theDataSource,
96 vtkDataSet* theDataSet)
98 if (!theDataSet->GetInformation() )
100 theDataSet->SetInformation (vtkSmartPointer<vtkInformation>::New());
102 vtkSmartPointer<vtkInformation> aDatasetInfo = theDataSet->GetInformation();
103 KeyPtr aKey = getKey();
104 vtkSmartPointer<IVtkTools_ShapeObject> aShapeObj =
105 vtkSmartPointer<IVtkTools_ShapeObject>::New();
106 aShapeObj->SetShapeSource (theDataSource);
107 aKey->Set(aDatasetInfo, aShapeObj);
110 //============================================================================
111 // Method: SetShapeSource
112 // Purpose: Static method to set OCC shape source to VTK actor in information
114 //============================================================================
115 void IVtkTools_ShapeObject::SetShapeSource (IVtkTools_ShapeDataSource* theDataSource,
118 if ( !theActor->GetPropertyKeys() )
120 theActor->SetPropertyKeys (vtkSmartPointer<vtkInformation>::New());
123 vtkSmartPointer<vtkInformation> anInfo = theActor->GetPropertyKeys();
124 KeyPtr aKey = getKey();
125 vtkSmartPointer<IVtkTools_ShapeObject> aShapeObj =
126 vtkSmartPointer<IVtkTools_ShapeObject>::New();
127 aShapeObj->SetShapeSource(theDataSource);
128 aKey->Set (anInfo, aShapeObj);
131 //! @class IVtkTools_ShapeObject
132 //! @brief VTK holder class for OCC shapes to pass them through pipelines.
133 vtkStandardNewMacro(IVtkTools_ShapeObject)
135 //============================================================================
136 // Method: Constructor
137 // Purpose: Protected constructor.
138 //============================================================================
139 IVtkTools_ShapeObject::IVtkTools_ShapeObject()
142 //============================================================================
143 // Method: Destructor
144 // Purpose: Protected destructor.
145 //============================================================================
146 IVtkTools_ShapeObject::~IVtkTools_ShapeObject()
149 //============================================================================
150 // Method: SetShapeSource
152 //============================================================================
153 void IVtkTools_ShapeObject::SetShapeSource (IVtkTools_ShapeDataSource* theDataSource)
155 myShapeSource = theDataSource;
158 //============================================================================
159 // Method: GetShapeSource
161 //============================================================================
162 IVtkTools_ShapeDataSource* IVtkTools_ShapeObject::GetShapeSource() const
164 return myShapeSource;