Salome HOME
updated copyright message
[modules/gui.git] / src / SVTK / SVTK_Functor.h
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef SVTK_Functor_H
24 #define SVTK_Functor_H
25
26 #include <functional>
27
28 #include <string>
29
30 #include <VTKViewer_Functor.h>
31
32 #include <SALOME_InteractiveObject.hxx>
33 #include <SALOME_ListIO.hxx>
34 /*!
35   \file SVTK_Functor.h
36   This file contains numbers of functors that allows user to perform corresponding operations with existing presentations.
37   Combination with algorithms it gives powerful, flexible and simple to extend way to introduce new type of operation.
38 */
39
40 namespace SVTK
41 {
42   using namespace VTK;
43
44   //! This functor check, if the actor have pointed entry
45   template<class TActor> 
46   struct TIsSameEntry
47   {
48     std::string myEntry;
49     //! To construct the functor
50     TIsSameEntry(const char* theEntry): 
51       myEntry(theEntry) 
52     {}
53     //! To calculate the functor
54     bool operator()(TActor* theActor)
55     {
56       if ( theActor->hasIO() )
57       {
58         Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
59         if ( anIO->hasEntry() )
60           return myEntry == anIO->getEntry();
61       }
62       return false;
63     }
64   };
65
66
67   //----------------------------------------------------------------
68   //! This functor check, if the actor point to the same #SALOME_InteractiveObject
69   template<class TActor> 
70   struct TIsSameIObject
71   {
72     Handle(SALOME_InteractiveObject) myIObject;
73     //! To construct the functor
74     TIsSameIObject(const Handle(SALOME_InteractiveObject)& theIObject):
75       myIObject(theIObject)
76     {}
77     //! To calculate the functor
78     bool operator()(TActor* theActor)
79     {
80       if(theActor->hasIO())
81       {
82         Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
83         return myIObject->isSame(anIO);
84       }
85       return false;
86     }
87   };
88
89
90   //----------------------------------------------------------------
91   /*!
92     This highlight every input actor
93   */
94   template<class TActor> 
95   struct THighlight
96   {
97     bool myIsHighlight;
98     //! To construct the functor
99     THighlight(bool theIsHighlight):
100       myIsHighlight( theIsHighlight ) 
101     {}
102     //! To calculate the functor
103     void operator()(TActor* theActor) 
104     {
105       if(theActor->GetVisibility() && theActor->GetMapper())
106         theActor->highlight( myIsHighlight );
107     }
108   };
109
110
111   //----------------------------------------------------------------
112   /*!
113     This collect visible IO in list
114   */
115   template<class TActor> 
116     struct TCollectIfVisible
117     {
118       SALOME_ListIO& myList;
119       //! To construct the functor
120       TCollectIfVisible (SALOME_ListIO& theList) : myList(theList)
121       {}
122       //! To calculate the functor
123       void operator()(TActor* theActor) 
124       {
125         if(theActor->GetVisibility() && theActor->hasIO())
126           myList.Append( theActor->getIO() );
127       }
128     };
129 }
130
131
132 #endif