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_GenericObjPtr.h"
39 #include <SALOMEconfig.h>
40 #include CORBA_SERVER_HEADER(VTKPlugin)
42 typedef GEOM::GenericObjPtr<GEOM::IVTKOperations> VTKOpPtr;
44 //=======================================================================
45 // function : VTKPlugin_GUI()
46 // purpose : Constructor
47 //=======================================================================
48 VTKPlugin_GUI::VTKPlugin_GUI( GeometryGUI* parent ) : GEOMPluginGUI( parent )
52 //=======================================================================
53 // function : ~VTKPlugin_GUI
54 // purpose : Destructor
55 //=======================================================================
56 VTKPlugin_GUI::~VTKPlugin_GUI()
60 //=======================================================================
61 // function : OnGUIEvent()
63 //=======================================================================
64 bool VTKPlugin_GUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
67 switch ( theCommandID ) {
69 cmd = "Export_VTK"; break;
73 return OnGUIEvent( cmd, parent );
76 //=======================================================================
77 // function : OnGUIEvent()
79 //=======================================================================
80 bool VTKPlugin_GUI::OnGUIEvent( const QString& theCommandID, SUIT_Desktop* parent )
84 if( theCommandID == "Export_VTK" ) {
85 result = exportVTK( parent );
88 getGeometryGUI()->getApp()->putInfo( tr("GEOM_PRP_COMMAND").arg( theCommandID ) );
91 return true; // ???????????
94 //=======================================================================
95 // function : exportVTK
97 //=======================================================================
98 bool VTKPlugin_GUI::exportVTK( SUIT_Desktop* parent )
100 SalomeApp_Application* app = getGeometryGUI()->getApp();
101 if ( !app ) return false;
103 GEOM::GEOM_IOperations_var op = GeometryGUI::GetGeomGen()->GetPluginOperations( "VTKPluginEngine" );
104 VTKOpPtr vtkOp = GEOM::IVTKOperations::_narrow( op );
105 if ( vtkOp.isNull() ) return false;
107 LightApp_SelectionMgr* sm = app->selectionMgr();
108 if ( !sm ) return false;
110 SALOME_ListIO selectedObjects;
111 sm->selectedObjects( selectedObjects );
114 SALOME_ListIteratorOfListIO it( selectedObjects );
115 for ( ; it.More(); it.Next() )
117 Handle(SALOME_InteractiveObject) io = it.Value();
118 GEOM::GEOM_Object_var obj = GEOMBase::ConvertIOinGEOMObject( io );
120 if ( CORBA::is_nil( obj ) ) continue;
122 double deflection = 0.;
123 QString fileName = VTKPlugin_ExportDlg::getFileName( io,
125 tr( "EXPORT_TITLE" ),
129 if ( fileName.isEmpty() )
132 SUIT_OverrideCursor wc;
134 GEOM_Operation transaction( app, vtkOp.get() );
138 app->putInfo( tr( "GEOM_PRP_EXPORT" ).arg( fileName ) );
141 vtkOp->ExportVTK( obj, fileName.toUtf8().constData(), deflection );
143 if ( vtkOp->IsDone() )
145 transaction.commit();
150 SUIT_MessageBox::critical( parent,
152 tr( "GEOM_PRP_ABORT" ) + "\n" + tr( vtkOp->GetErrorCode() ) );
156 catch ( const SALOME::SALOME_Exception& e )
166 SUIT_MessageBox::warning( parent,
168 tr( "GEOM_WRN_NO_APPROPRIATE_SELECTION" ) );
173 //=====================================================================================
175 //=====================================================================================
179 __declspec( dllexport )
181 GEOMGUI* GetLibGUI( GeometryGUI* parent )
183 return new VTKPlugin_GUI( parent );