Salome HOME
Update of CheckDone
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Displayer.cxx
1 // Copyright (C) 2007-2024  CEA, EDF, 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 #include <SPV3D_Prs.h>
40 #include <SPV3D_ViewModel.h>
41 #include <PV3DViewer_ViewWindow.h>
42
43 //For PV3D
44 #include "SMESH_Actor.h"
45
46 // IDL includes
47 #include <SALOMEconfig.h>
48 #include CORBA_SERVER_HEADER(SMESH_Group)
49 #include CORBA_SERVER_HEADER(SMESH_Mesh)
50
51 std::string SMESHGUI_Displayer::getName( const QString& entry )
52 {
53   Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
54   theIO->setEntry( entry.toUtf8().constData() );
55   if ( !theIO.IsNull() )
56   {
57     //  Find SOBject (because shape should be published previously)
58     if ( study() )
59     {
60       _PTR(SObject) aSObj ( study()->studyDS()->FindObjectID( theIO->getEntry() ) );
61       _PTR(GenericAttribute) anAttr;
62
63       if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
64       {
65         _PTR(AttributeName) aNameAttr( anAttr );
66         return aNameAttr->Value();
67       }
68     }
69   }
70   return "";
71 }
72
73 SMESHGUI_Displayer::SMESHGUI_Displayer( SalomeApp_Application* app )
74 : LightApp_Displayer(),
75   myApp( app ),
76   isNeedFitAll(false)
77 {
78 }
79
80 SMESHGUI_Displayer::~SMESHGUI_Displayer()
81 {
82 }
83
84 SALOME_Prs* SMESHGUI_Displayer::buildPresentation( const QString& entry, SALOME_View* theViewFrame )
85 {
86   SALOME_Prs *prs = nullptr;
87
88   SALOME_View* aViewFrame = theViewFrame ? theViewFrame : GetActiveView();
89
90   if ( aViewFrame )
91   {
92     SVTK_Viewer* vtk_viewer = dynamic_cast<SVTK_Viewer*>( aViewFrame );
93     if( vtk_viewer )
94     {
95       SUIT_ViewWindow* wnd = vtk_viewer->getViewManager()->getActiveView();
96       SMESH_Actor* anActor = SMESH::FindActorByEntry( wnd, entry.toUtf8().data() );
97       if( !anActor )
98         anActor = SMESH::CreateActor( entry.toUtf8().data(), true );
99       if( anActor )
100       {
101         isNeedFitAll = SMESH::NoSmeshActors();
102         SMESH::DisplayActor( wnd, anActor );
103         prs = LightApp_Displayer::buildPresentation( entry.toUtf8().data(), aViewFrame );
104       }
105       if( prs )
106         UpdatePrs( prs );
107       else if( anActor )
108         SMESH::RemoveActor( vtk_viewer->getViewManager()->getActiveView(), anActor );
109     }
110     
111     SPV3D_ViewModel *pv3d_viewer = dynamic_cast<SPV3D_ViewModel *>( aViewFrame );
112     if(pv3d_viewer)
113     {
114       SUIT_ViewWindow* wnd = pv3d_viewer->getViewManager()->getActiveView();
115       SMESH_Actor* anActor = SMESH::FindActorByEntry( wnd, entry.toUtf8().data() );
116       if( !anActor )
117         anActor = SMESH::CreateActor( entry.toUtf8().data(), true );
118       if( anActor )
119       {
120         prs = LightApp_Displayer::buildPresentation( entry.toUtf8().data(), aViewFrame );
121         if( prs )
122         {
123           SPV3D_Prs *pv3dPrs = dynamic_cast<SPV3D_Prs*>( prs );
124           if( pv3dPrs )
125           {
126             pv3dPrs->SetName( getName( entry ) );
127             pv3dPrs->FillUsingActor( anActor );
128           }
129         }
130       }
131     }
132   }
133
134   return prs;
135 }
136
137 SalomeApp_Study* SMESHGUI_Displayer::study() const
138 {
139   return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
140 }
141
142 bool SMESHGUI_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
143 {
144   bool res = false;
145   if(viewer_type != SVTK_Viewer::Type() && viewer_type != SPV3D_ViewModel::Type())
146     return res;
147   
148   _PTR(SObject) obj = SMESH::getStudy()->FindObjectID( (const char*)entry.toUtf8() );
149   CORBA::Object_var anObj = SMESH::SObjectToObject( obj );
150   
151   if ( !CORBA::is_nil( anObj ) )
152   {
153     SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( anObj );
154     if ( ! ( res = !mesh->_is_nil() ))
155     {
156       SMESH::SMESH_subMesh_var aSubMeshObj = SMESH::SMESH_subMesh::_narrow( anObj );
157       if ( ! ( res = !aSubMeshObj->_is_nil() ))
158       {
159         SMESH::SMESH_GroupBase_var aGroupObj = SMESH::SMESH_GroupBase::_narrow( anObj );
160         res = !aGroupObj->_is_nil();
161       }
162     }
163   }
164   return res;
165 }
166
167 void SMESHGUI_Displayer::Display( const QStringList& theList, const bool anUpdateViewer, SALOME_View* theView ) 
168 {
169   LightApp_Displayer::Display( theList, anUpdateViewer, theView );
170   
171   if (isNeedFitAll) {
172     SMESH::FitAll();
173     isNeedFitAll = false;
174   }
175 }