0028599: Replacement of old Boolean operations with new ones in BRepProj_Projection...
[occt.git] / src / IVtkTools / IVtkTools_ShapeObject.cxx
CommitLineData
913a4c4a 1// Created on: 2011-10-27
2// Created by: Roman KOZLOV
3// Copyright (c) 2011-2014 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
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.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
16#include <IVtkTools_ShapeObject.hxx>
17#include <IVtkTools_ShapeDataSource.hxx>
a9660929 18
19// prevent disabling some MSVC warning messages by VTK headers
20#ifdef _MSC_VER
21#pragma warning(push)
22#endif
913a4c4a 23#include <vtkActor.h>
913a4c4a 24#include <vtkObjectFactory.h>
25#include <vtkDataSet.h>
26#include <vtkInformation.h>
27#include <vtkInformationObjectBaseKey.h>
913a4c4a 28#include <vtkPolyData.h>
a9660929 29#ifdef _MSC_VER
30#pragma warning(pop)
31#endif
913a4c4a 32
33IVtkTools_ShapeObject::KeyPtr IVtkTools_ShapeObject::myKey = 0;
34
35//============================================================================
36// Method: getKey
37// Purpose: Static method to get vtkInformationKey for retrieving OccShape
38// instance from the actor.
39//============================================================================
40IVtkTools_ShapeObject::KeyPtr IVtkTools_ShapeObject::getKey()
41{
42 if (!myKey)
43 {
44 myKey = new vtkInformationObjectBaseKey( "OccShapePtr", "IVtkTools_ShapeObject::Key" );
45 }
46
47 return myKey;
48}
49
50//============================================================================
51// Method: GetOccShape
52// Purpose: Static method to get OCC shape from VTK actor's data from
53// information object by key.
54//============================================================================
55IVtkOCC_Shape::Handle IVtkTools_ShapeObject::GetOccShape (vtkActor* theActor)
56{
57 IVtkOCC_Shape::Handle anOccShape;
a2f76b15 58 vtkSmartPointer<IVtkTools_ShapeDataSource> aSrc =
59 IVtkTools_ShapeObject::GetShapeSource (theActor);
60 if (aSrc.GetPointer() != NULL)
913a4c4a 61 {
62 anOccShape = aSrc->GetShape();
63 }
64 return anOccShape;
65}
66
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//============================================================================
a2f76b15 72vtkSmartPointer<IVtkTools_ShapeDataSource> IVtkTools_ShapeObject
73::GetShapeSource (vtkActor* theActor)
913a4c4a 74{
a2f76b15 75 vtkSmartPointer<IVtkTools_ShapeDataSource> anOccShapeSource;
76 vtkSmartPointer<vtkInformation> anInfo = theActor->GetPropertyKeys();
77 if (anInfo.GetPointer() != NULL)
913a4c4a 78 {
79 KeyPtr aKey = getKey();
80 if (aKey->Has(anInfo))
81 {
a2f76b15 82 vtkSmartPointer<IVtkTools_ShapeObject> aShapeObj =
83 IVtkTools_ShapeObject::SafeDownCast(aKey->Get (anInfo));
913a4c4a 84 anOccShapeSource = aShapeObj->GetShapeSource();
85 }
86 }
87 return anOccShapeSource;
88}
89
90//============================================================================
91// Method: SetShapeSource
92// Purpose: Static method to set OCC shape source to VTK dataset in information
93// object with key.
94//============================================================================
95void IVtkTools_ShapeObject::SetShapeSource (IVtkTools_ShapeDataSource* theDataSource,
96 vtkDataSet* theDataSet)
97{
98 if (!theDataSet->GetInformation() )
99 {
a2f76b15 100 theDataSet->SetInformation (vtkSmartPointer<vtkInformation>::New());
913a4c4a 101 }
a2f76b15 102 vtkSmartPointer<vtkInformation> aDatasetInfo = theDataSet->GetInformation();
913a4c4a 103 KeyPtr aKey = getKey();
a2f76b15 104 vtkSmartPointer<IVtkTools_ShapeObject> aShapeObj =
105 vtkSmartPointer<IVtkTools_ShapeObject>::New();
913a4c4a 106 aShapeObj->SetShapeSource (theDataSource);
107 aKey->Set(aDatasetInfo, aShapeObj);
913a4c4a 108}
109
110//============================================================================
111// Method: SetShapeSource
112// Purpose: Static method to set OCC shape source to VTK actor in information
113// object with key.
114//============================================================================
115void IVtkTools_ShapeObject::SetShapeSource (IVtkTools_ShapeDataSource* theDataSource,
116 vtkActor* theActor)
117{
118 if ( !theActor->GetPropertyKeys() )
119 {
a2f76b15 120 theActor->SetPropertyKeys (vtkSmartPointer<vtkInformation>::New());
913a4c4a 121 }
122
a2f76b15 123 vtkSmartPointer<vtkInformation> anInfo = theActor->GetPropertyKeys();
913a4c4a 124 KeyPtr aKey = getKey();
a2f76b15 125 vtkSmartPointer<IVtkTools_ShapeObject> aShapeObj =
126 vtkSmartPointer<IVtkTools_ShapeObject>::New();
127 aShapeObj->SetShapeSource(theDataSource);
913a4c4a 128 aKey->Set (anInfo, aShapeObj);
913a4c4a 129}
130
131//! @class IVtkTools_ShapeObject
132//! @brief VTK holder class for OCC shapes to pass them through pipelines.
68858c7d 133vtkStandardNewMacro(IVtkTools_ShapeObject)
913a4c4a 134
135//============================================================================
136// Method: Constructor
137// Purpose: Protected constructor.
138//============================================================================
139IVtkTools_ShapeObject::IVtkTools_ShapeObject()
140{ }
141
142//============================================================================
143// Method: Destructor
144// Purpose: Protected destructor.
145//============================================================================
146IVtkTools_ShapeObject::~IVtkTools_ShapeObject()
147{ }
148
149//============================================================================
150// Method: SetShapeSource
151// Purpose:
152//============================================================================
153void IVtkTools_ShapeObject::SetShapeSource (IVtkTools_ShapeDataSource* theDataSource)
154{
155 myShapeSource = theDataSource;
156}
157
158//============================================================================
159// Method: GetShapeSource
160// Purpose:
161//============================================================================
a2f76b15 162IVtkTools_ShapeDataSource* IVtkTools_ShapeObject::GetShapeSource() const
913a4c4a 163{
164 return myShapeSource;
165}
166