Salome HOME
Copyright update 2022
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Displayer.cxx
1 // Copyright (C) 2007-2022  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 : Displayer for SMESH module
24 // File   : SMESHGUI_Displayer.cxx
25 // Author : Alexander SOLOVYOV, Open CASCADE S.A.S.
26 // SMESH includes
27 //
28
29 #include "SMESHGUI_Displayer.h"
30 #include "SMESHGUI_VTKUtils.h"
31 #include "SMESHGUI_Utils.h"
32
33 // SALOME GUI includes
34 #include <SalomeApp_Study.h>
35 #include <SalomeApp_Application.h>
36 #include <SUIT_ViewManager.h>
37 #include <SVTK_ViewModel.h>
38 #include <SVTK_ViewWindow.h>
39
40
41 // IDL includes
42 #include <SALOMEconfig.h>
43 #include CORBA_SERVER_HEADER(SMESH_Group)
44 #include CORBA_SERVER_HEADER(SMESH_Mesh)
45
46
47 SMESHGUI_Displayer::SMESHGUI_Displayer( SalomeApp_Application* app )
48 : LightApp_Displayer(),
49   myApp( app ),
50   isNeedFitAll(false)
51 {
52 }
53
54 SMESHGUI_Displayer::~SMESHGUI_Displayer()
55 {
56 }
57
58 SALOME_Prs* SMESHGUI_Displayer::buildPresentation( const QString& entry, SALOME_View* theViewFrame )
59 {
60   SALOME_Prs* prs = 0;
61
62   SALOME_View* aViewFrame = theViewFrame ? theViewFrame : GetActiveView();
63
64   if ( aViewFrame )
65   {
66     SVTK_Viewer* vtk_viewer = dynamic_cast<SVTK_Viewer*>( aViewFrame );
67     if( vtk_viewer )
68     {
69       SUIT_ViewWindow* wnd = vtk_viewer->getViewManager()->getActiveView();
70       SMESH_Actor* anActor = SMESH::FindActorByEntry( wnd, entry.toUtf8().data() );
71       if( !anActor )
72         anActor = SMESH::CreateActor( entry.toUtf8().data(), true );
73       if( anActor )
74       {
75         isNeedFitAll = SMESH::NoSmeshActors();
76         SMESH::DisplayActor( wnd, anActor );
77         prs = LightApp_Displayer::buildPresentation( entry.toUtf8().data(), aViewFrame );
78       }
79       if( prs )
80         UpdatePrs( prs );
81       else if( anActor )
82         SMESH::RemoveActor( vtk_viewer->getViewManager()->getActiveView(), anActor );
83     }
84   }
85
86   return prs;
87 }
88
89 SalomeApp_Study* SMESHGUI_Displayer::study() const
90 {
91   return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
92 }
93
94 bool SMESHGUI_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
95 {
96   bool res = false;
97   if(viewer_type != SVTK_Viewer::Type())
98     return res;
99   
100   _PTR(SObject) obj = SMESH::getStudy()->FindObjectID( (const char*)entry.toUtf8() );
101   CORBA::Object_var anObj = SMESH::SObjectToObject( obj );
102   
103   if ( !CORBA::is_nil( anObj ) )
104   {
105     SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( anObj );
106     if ( ! ( res = !mesh->_is_nil() ))
107     {
108       SMESH::SMESH_subMesh_var aSubMeshObj = SMESH::SMESH_subMesh::_narrow( anObj );
109       if ( ! ( res = !aSubMeshObj->_is_nil() ))
110       {
111         SMESH::SMESH_GroupBase_var aGroupObj = SMESH::SMESH_GroupBase::_narrow( anObj );
112         res = !aGroupObj->_is_nil();
113       }
114     }
115   }
116   return res;
117 }
118
119 void SMESHGUI_Displayer::Display( const QStringList& theList, const bool anUpdateViewer, SALOME_View* theView ) 
120 {
121   LightApp_Displayer::Display( theList, anUpdateViewer, theView );
122   
123   if (isNeedFitAll) {
124     SMESH::FitAll();
125     isNeedFitAll = false;
126   }
127 }