Back to index

salome-smesh  6.5.0
SMESHGUI_Displayer.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // SMESH SMESHGUI : Displayer for SMESH module
00024 // File   : SMESHGUI_Displayer.cxx
00025 // Author : Alexander SOLOVYOV, Open CASCADE S.A.S.
00026 // SMESH includes
00027 //
00028 
00029 #include "SMESHGUI_Displayer.h"
00030 #include "SMESHGUI_VTKUtils.h"
00031 #include "SMESHGUI_Utils.h"
00032 
00033 // SALOME GUI includes
00034 #include <SalomeApp_Study.h>
00035 #include <SalomeApp_Application.h>
00036 #include <SUIT_ViewManager.h>
00037 #include <SVTK_ViewModel.h>
00038 #include <SVTK_ViewWindow.h>
00039 
00040 
00041 // IDL includes
00042 #include <SALOMEconfig.h>
00043 #include CORBA_SERVER_HEADER(SMESH_Group)
00044 #include CORBA_SERVER_HEADER(SMESH_Mesh)
00045 
00046 
00047 SMESHGUI_Displayer::SMESHGUI_Displayer( SalomeApp_Application* app )
00048 : LightApp_Displayer(),
00049   myApp( app )
00050 {
00051 }
00052 
00053 SMESHGUI_Displayer::~SMESHGUI_Displayer()
00054 {
00055 }
00056 
00057 SALOME_Prs* SMESHGUI_Displayer::buildPresentation( const QString& entry, SALOME_View* theViewFrame )
00058 {
00059   SALOME_Prs* prs = 0;
00060 
00061   SALOME_View* aViewFrame = theViewFrame ? theViewFrame : GetActiveView();
00062 
00063   if ( aViewFrame )
00064   {
00065     SVTK_Viewer* vtk_viewer = dynamic_cast<SVTK_Viewer*>( aViewFrame );
00066     if( vtk_viewer )
00067     {
00068       SUIT_ViewWindow* wnd = vtk_viewer->getViewManager()->getActiveView();
00069       SMESH_Actor* anActor = SMESH::FindActorByEntry( wnd, entry.toLatin1().data() );
00070       if( !anActor )
00071         anActor = SMESH::CreateActor( study()->studyDS(), entry.toLatin1().data(), true );
00072       if( anActor )
00073       {
00074         SMESH::DisplayActor( wnd, anActor );
00075         prs = LightApp_Displayer::buildPresentation( entry.toLatin1().data(), aViewFrame );
00076       }
00077       if( prs )
00078         UpdatePrs( prs );
00079       else if( anActor )
00080         SMESH::RemoveActor( vtk_viewer->getViewManager()->getActiveView(), anActor );
00081     }
00082   }
00083 
00084   return prs;
00085 }
00086 
00087 SalomeApp_Study* SMESHGUI_Displayer::study() const
00088 {
00089   return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
00090 }
00091 
00092 bool SMESHGUI_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const {
00093   bool res = false;
00094   if(viewer_type != SVTK_Viewer::Type())
00095     return res;
00096   
00097   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
00098   if( !study )
00099     return res;
00100   
00101   
00102   _PTR(SObject) obj = study->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
00103   CORBA::Object_var anObj = SMESH::SObjectToObject( obj );
00104   
00105     /*
00106     if( !CORBA::is_nil( anObj ) ) {
00107     SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( anObj );
00108     if ( ! mesh->_is_nil() )
00109     res = (mesh->NbNodes() > 0);
00110     
00111     SMESH::SMESH_subMesh_var aSubMeshObj = SMESH::SMESH_subMesh::_narrow( anObj );
00112     if ( !aSubMeshObj->_is_nil() )
00113     res = (aSubMeshObj->GetNumberOfNodes(true) > 0);
00114     
00115     SMESH::SMESH_GroupBase_var aGroupObj = SMESH::SMESH_GroupBase::_narrow( anObj );
00116     if ( !aGroupObj->_is_nil() )
00117     res = !aGroupObj->IsEmpty();
00118     }*/
00119   if( !CORBA::is_nil( anObj ) ) {
00120     if(!SMESH::SMESH_Mesh::_narrow( anObj )->_is_nil() ||
00121        !SMESH::SMESH_subMesh::_narrow( anObj )->_is_nil() ||
00122        !SMESH::SMESH_GroupBase::_narrow( anObj )->_is_nil())
00123     res = true;
00124   }
00125   return res;
00126 }