1 // Copyright (C) 2014-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include "VTKPlugin_GUI.h"
22 #include "VTKPlugin_ExportDlg.h"
25 #include <SUIT_Desktop.h>
26 #include <SUIT_MessageBox.h>
27 #include <SUIT_OverrideCursor.h>
28 #include <LightApp_SelectionMgr.h>
29 #include <SalomeApp_Application.h>
30 #include <SalomeApp_Study.h>
31 #include <SALOME_ListIO.hxx>
34 #include "GeometryGUI.h"
35 #include "GEOM_Operation.h"
37 #include "GEOM_Displayer.h"
38 #include "GEOM_GenericObjPtr.h"
40 #include <SALOMEconfig.h>
41 #include CORBA_SERVER_HEADER(VTKPlugin)
43 typedef GEOM::GenericObjPtr<GEOM::IVTKOperations> VTKOpPtr;
45 //=======================================================================
46 // function : VTKPlugin_GUI()
47 // purpose : Constructor
48 //=======================================================================
49 VTKPlugin_GUI::VTKPlugin_GUI( GeometryGUI* parent ) : GEOMPluginGUI( parent )
53 //=======================================================================
54 // function : ~VTKPlugin_GUI
55 // purpose : Destructor
56 //=======================================================================
57 VTKPlugin_GUI::~VTKPlugin_GUI()
61 //=======================================================================
62 // function : OnGUIEvent()
64 //=======================================================================
65 bool VTKPlugin_GUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
68 switch ( theCommandID ) {
70 cmd = "Export_VTK"; break;
74 return OnGUIEvent( cmd, parent );
77 //=======================================================================
78 // function : OnGUIEvent()
80 //=======================================================================
81 bool VTKPlugin_GUI::OnGUIEvent( const QString& theCommandID, SUIT_Desktop* parent )
85 if( theCommandID == "Export_VTK" ) {
86 result = exportVTK( parent );
89 getGeometryGUI()->getApp()->putInfo( tr("GEOM_PRP_COMMAND").arg( theCommandID ) );
95 //=======================================================================
96 // function : exportVTK
98 //=======================================================================
99 bool VTKPlugin_GUI::exportVTK( SUIT_Desktop* parent )
101 SalomeApp_Application* app = getGeometryGUI()->getApp();
102 if ( !app ) return false;
103 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() );
104 if ( !study ) return false;
106 SALOMEDS::Study_var dsStudy = GeometryGUI::ClientStudyToStudy( study->studyDS() );
107 GEOM::GEOM_IOperations_var op = GeometryGUI::GetGeomGen()->GetPluginOperations( dsStudy->StudyId(), "VTKPluginEngine" );
108 VTKOpPtr vtkOp = GEOM::IVTKOperations::_narrow( op );
109 if ( vtkOp.isNull() ) return false;
111 LightApp_SelectionMgr* sm = app->selectionMgr();
112 if ( !sm ) return false;
114 SALOME_ListIO selectedObjects;
115 sm->selectedObjects( selectedObjects );
118 SALOME_ListIteratorOfListIO it( selectedObjects );
119 for ( ; it.More(); it.Next() )
121 Handle(SALOME_InteractiveObject) io = it.Value();
122 GEOM::GEOM_Object_var obj = GEOMBase::ConvertIOinGEOMObject( io );
124 if ( CORBA::is_nil( obj ) ) continue;
126 double deflection = 0.;
127 QString fileName = VTKPlugin_ExportDlg::getFileName( io,
129 tr( "EXPORT_TITLE" ),
133 if ( fileName.isEmpty() )
136 SUIT_OverrideCursor wc;
138 GEOM_Operation transaction( app, vtkOp.get() );
142 app->putInfo( tr( "GEOM_PRP_EXPORT" ).arg( fileName ) );
145 vtkOp->ExportVTK( obj, fileName.toUtf8().constData(), deflection );
147 if ( vtkOp->IsDone() )
149 transaction.commit();
154 SUIT_MessageBox::critical( parent,
156 tr( "GEOM_PRP_ABORT" ) + "\n" + tr( vtkOp->GetErrorCode() ) );
160 catch ( const SALOME::SALOME_Exception& e )
170 SUIT_MessageBox::warning( parent,
172 tr( "GEOM_WRN_NO_APPROPRIATE_SELECTION" ) );
177 //=====================================================================================
179 //=====================================================================================
183 __declspec( dllexport )
185 GEOMGUI* GetLibGUI( GeometryGUI* parent )
187 return new VTKPlugin_GUI( parent );