Salome HOME
7a6f4e6c529c02257315a85cce0f96eaa60ded56
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_VTKUtils.h
1 // Copyright (C) 2007-2014  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 // SMESH SMESHGUI : GUI for SMESH component
24 // File   : SMESHGUI_VTKUtils.h
25 // Author : Open CASCADE S.A.S.
26 //
27 #ifndef SMESHGUI_VTKUTILS_H
28 #define SMESHGUI_VTKUTILS_H
29
30 // SMESH includes
31 #include "SMESH_SMESHGUI.hxx"
32 #include "SMESH_TypeDefs.hxx"
33 #include "SMDS_MeshNode.hxx"
34
35 #include "SMESHGUI_Utils.h"
36
37 #include <SMESH_Object.h>
38
39 // SALOME KERNEL includes
40 #include <SALOMEDSClient_definitions.hxx>
41
42 // SALOME GUI includes
43 #include <SALOME_InteractiveObject.hxx>
44 #include <VTKViewer_Filter.h>
45
46 class TColStd_IndexedMapOfInteger;
47
48 class SALOMEDSClient_Study;
49
50 class SUIT_ViewWindow;
51 class SUIT_ViewManager;
52
53 class SVTK_ViewWindow;
54 class SVTK_Selector;
55
56 class LightApp_SelectionMgr;
57 class SalomeApp_Module;
58
59 class SMESHGUI;
60 class SMESH_Actor;
61 class SALOME_Actor;
62
63 class vtkActor;
64 class SMDS_Mesh;
65 class SMDS_MeshNode;
66 class gp_Pln;
67 class gp_Lin;
68 class gp_Dir;
69 class gp_Pnt2d;
70 class gp_Vec2d;
71 class Handle(Geom_Line);
72 class Handle(Geom_Plane);
73 namespace SMESH
74 {
75   //----------------------------------------------------------------------------
76   typedef std::pair<int,std::string> TKeyOfVisualObj;
77   
78 SMESHGUI_EXPORT
79   TVisualObjPtr GetVisualObj( int, const char*, bool nulData =false );
80 SMESHGUI_EXPORT
81   void OnVisuException(); // PAL16631
82
83   //----------------------------------------------------------------------------
84 SMESHGUI_EXPORT
85   SVTK_ViewWindow* GetViewWindow( const SalomeApp_Module* = 0,
86                                   bool = false );
87 SMESHGUI_EXPORT
88   SVTK_ViewWindow* FindVtkViewWindow( SUIT_ViewManager*, SUIT_ViewWindow* );
89 SMESHGUI_EXPORT
90   SVTK_ViewWindow* GetVtkViewWindow( SUIT_ViewWindow* );
91
92 SMESHGUI_EXPORT
93   SVTK_ViewWindow* GetCurrentVtkView();
94
95   //----------------------------------------------------------------------------
96 SMESHGUI_EXPORT
97   void RepaintCurrentView();
98 SMESHGUI_EXPORT
99   void RepaintViewWindow( SVTK_ViewWindow* );
100 SMESHGUI_EXPORT
101   void RenderViewWindow( SVTK_ViewWindow* );
102 SMESHGUI_EXPORT
103   void FitAll();
104
105   //----------------------------------------------------------------------------
106 SMESHGUI_EXPORT
107   SMESH_Actor* FindActorByEntry( SUIT_ViewWindow*, const char* );
108 SMESHGUI_EXPORT
109   SMESH_Actor* FindActorByEntry( const char* );
110
111 SMESHGUI_EXPORT
112   SMESH_Actor* FindActorByObject( CORBA::Object_ptr );
113
114   //----------------------------------------------------------------------------
115 SMESHGUI_EXPORT  
116   SMESH_Actor* CreateActor( _PTR(Study), const char*, int = false );
117 SMESHGUI_EXPORT
118   void DisplayActor( SUIT_ViewWindow*, SMESH_Actor* );
119 SMESHGUI_EXPORT
120   void RemoveActor( SUIT_ViewWindow*, SMESH_Actor* );
121 SMESHGUI_EXPORT
122   void RemoveVisuData( int );
123
124   //----------------------------------------------------------------------------
125   enum EDisplaing { eDisplayAll, eDisplay, eDisplayOnly, eErase, eEraseAll };
126
127 SMESHGUI_EXPORT
128   bool UpdateView( SUIT_ViewWindow*, EDisplaing, const char* = "" );
129 SMESHGUI_EXPORT            
130   bool UpdateView( EDisplaing, const char* = "" );
131
132 SMESHGUI_EXPORT
133   void UpdateView();
134
135 SMESHGUI_EXPORT
136   bool UpdateNulData( const Handle(SALOME_InteractiveObject)& theIO, bool theDisplay);
137
138 SMESHGUI_EXPORT
139   bool Update( const Handle(SALOME_InteractiveObject)& theIO, bool theDisplay);
140
141   //----------------------------------------------------------------------------
142 SMESHGUI_EXPORT  
143   void SetPointRepresentation( bool );
144
145 SMESHGUI_EXPORT
146   void SetPickable( SMESH_Actor* = 0 );
147
148 SMESHGUI_EXPORT
149   void UpdateSelectionProp( SMESHGUI* );
150
151 SMESHGUI_EXPORT
152   void UpdateFontProp( SMESHGUI* );
153
154   //----------------------------------------------------------------------------
155 SMESHGUI_EXPORT
156   SVTK_Selector* GetSelector( SUIT_ViewWindow* = GetActiveWindow() );
157
158 SMESHGUI_EXPORT
159   void SetFilter( const Handle(VTKViewer_Filter)&, SVTK_Selector* = GetSelector() );
160 SMESHGUI_EXPORT
161   Handle(VTKViewer_Filter) GetFilter( int, SVTK_Selector* = GetSelector() );
162 SMESHGUI_EXPORT
163   bool IsFilterPresent( int, SVTK_Selector* = GetSelector() );
164 SMESHGUI_EXPORT
165   void RemoveFilter( int, SVTK_Selector* = GetSelector() );
166
167 SMESHGUI_EXPORT
168   void RemoveFilters( SVTK_Selector* = GetSelector());
169
170 SMESHGUI_EXPORT
171   bool IsValid( SALOME_Actor*, int, SVTK_Selector* = GetSelector() );
172
173   //----------------------------------------------------------------------------
174 SMESHGUI_EXPORT  
175   int GetNameOfSelectedSortedNodes( SMDSAbs_EntityType,
176                                     SVTK_Selector*,
177                                     SMESH_Actor*,
178                                     int,
179                                     QString& );
180 SMESHGUI_EXPORT
181   int GetNameOfSelectedNodes( SVTK_Selector*,
182                               const Handle(SALOME_InteractiveObject)&,
183                               QString& );
184 SMESHGUI_EXPORT
185   int GetNameOfSelectedElements( SVTK_Selector*,
186                                  const Handle(SALOME_InteractiveObject)&,
187                                  QString& );
188 SMESHGUI_EXPORT
189   int GetEdgeNodes( SVTK_Selector*, const TVisualObjPtr&, int&, int& );
190
191   //----------------------------------------------------------------------------
192 SMESHGUI_EXPORT  
193   int GetNameOfSelectedNodes( LightApp_SelectionMgr*,
194                               const Handle(SALOME_InteractiveObject)&,
195                               QString& );
196 SMESHGUI_EXPORT
197   int GetNameOfSelectedNodes( LightApp_SelectionMgr*, QString& );
198 SMESHGUI_EXPORT
199   int GetNameOfSelectedElements( LightApp_SelectionMgr*,
200                                  const Handle(SALOME_InteractiveObject)&,
201                                  QString& );
202 SMESHGUI_EXPORT
203   int GetNameOfSelectedElements( LightApp_SelectionMgr*, QString& );
204 SMESHGUI_EXPORT
205   int GetSelected( LightApp_SelectionMgr*, TColStd_IndexedMapOfInteger&, 
206                    const bool = true );
207
208 SMESHGUI_EXPORT
209   int GetEdgeNodes( LightApp_SelectionMgr*, int&, int& );
210
211 SMESHGUI_EXPORT
212   void SetControlsPrecision( const long );
213
214 #ifndef DISABLE_PLOT2DVIEWER
215 SMESHGUI_EXPORT
216   void ClearPlot2Viewers( SUIT_ViewWindow* theWindow );
217 #endif
218
219   //----------------------------------------------------------------------------
220 SMESHGUI_EXPORT
221   bool ComputeClippingPlaneParameters( std::list<vtkActor*> theActorList,
222                                        double theNormal[3],
223                                        double theDist,
224                                        double theBounds[6],
225                                        double theOrigin[3] );
226
227   bool ComputeBounds( std::list<vtkActor*> theActorList,
228                       double theBounds[6]);
229
230   void PositionToDistance( double theBounds[6],
231                            double theDirection[3],
232                            double thePos[3],
233                            double& theDist );
234   typedef std::pair<SMESH_TNodeXYZ, double> TNodeOfDist;
235   typedef std::pair<SMESH_TNodeXYZ, std::pair<double, double> > TNodeOfAngleAndDist, TNodeOfDistToPlaneAndDist;
236   typedef std::pair<int, std::pair<double, double> > TIdOfDistToPlaneAndDist;
237   bool CreatePlaneOnThreePoints( const gp_Pnt& thePoint1,
238                                  const gp_Pnt& thePoint2,
239                                  const gp_Pnt& thePoint3,
240                                  gp_Pln& thePlane );
241
242   void FindNbLowestPoint( std::list<gp_Pnt2d> theList, gp_Pnt2d& theNode );
243   bool IsNotPlaneIntersection( std::vector<SMESH_TNodeXYZ>& theVector,
244                                const gp_Pln& thePlane );
245   bool GetCorrectSequenceOfId( std::vector<SMESH_TNodeXYZ>& theVector );
246   void GetCorrectSequenceTwoPlaneOfId( std::vector<SMESH_TNodeXYZ>& thePlane1,
247                                        std::vector<SMESH_TNodeXYZ>& thePlane2,
248                                        std::list<int>& theResultListId );
249   void GetSortedNodesOnPolygon( std::vector<SMESH_TNodeXYZ>& theVectorOfNode,
250                                 std::list<int>& theResultListId );
251   void GetSortedNodesOnPyramid( std::vector<SMESH_TNodeXYZ>& theVectorOfNode,
252                                 std::list<int>& theResultListId );
253   void GetSortedNodesOnPrism( std::vector<SMESH_TNodeXYZ>& theVectorOfNode,
254                               std::list<int>& theResultListId );
255   bool Get2BasePlane( std::vector<SMESH_TNodeXYZ>& theVector,
256                       std::vector<SMESH_TNodeXYZ>& thePlane1,
257                       std::vector<SMESH_TNodeXYZ>& thePlane2);
258   bool GetNextCombination ( std::vector<int> & theVector1,
259                             std::vector<int> & theVector2,
260                             int theNbPoint );
261   static bool CompareNodeOfAngleAndDist ( const TNodeOfAngleAndDist& first,
262                                           const TNodeOfAngleAndDist& second );
263   static bool CompareNodeOfDist ( const TNodeOfAngleAndDist& first,
264                                   const TNodeOfAngleAndDist& second );
265   static bool CompareDistOfPlane ( const TNodeOfDistToPlaneAndDist& first,
266                                    const TNodeOfDistToPlaneAndDist& second );
267   static bool CompareDistOfPlaneById ( const TIdOfDistToPlaneAndDist& first,
268                                        const TIdOfDistToPlaneAndDist& second );
269   static bool CompareDistForCorrectPlane ( const TNodeOfDist& first,
270                                            const TNodeOfDist& second );
271
272  SMESHGUI_EXPORT
273    void RemoveVisualObjectWithActors( const char* theEntry, bool fromAllViews = false );
274 };
275
276 #endif // SMESHGUI_VTKUTILS_H