1 // Copyright (C) 2014-2015 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"
39 #include <SALOMEconfig.h>
40 #include CORBA_SERVER_HEADER(VTKPlugin)
42 //=======================================================================
43 // function : VTKPlugin_GUI()
44 // purpose : Constructor
45 //=======================================================================
46 VTKPlugin_GUI::VTKPlugin_GUI( GeometryGUI* parent ) : GEOMPluginGUI( parent )
50 //=======================================================================
51 // function : ~VTKPlugin_GUI
52 // purpose : Destructor
53 //=======================================================================
54 VTKPlugin_GUI::~VTKPlugin_GUI()
58 //=======================================================================
59 // function : OnGUIEvent()
61 //=======================================================================
62 bool VTKPlugin_GUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
65 switch ( theCommandID ) {
67 cmd = "Export_VTK"; break;
71 return OnGUIEvent( cmd, parent );
74 //=======================================================================
75 // function : OnGUIEvent()
77 //=======================================================================
78 bool VTKPlugin_GUI::OnGUIEvent( const QString& theCommandID, SUIT_Desktop* parent )
82 if( theCommandID == "Export_VTK" ) {
83 result = exportVTK( parent );
86 getGeometryGUI()->getApp()->putInfo( tr("GEOM_PRP_COMMAND").arg( theCommandID ) );
92 //=======================================================================
93 // function : exportVTK
95 //=======================================================================
96 bool VTKPlugin_GUI::exportVTK( SUIT_Desktop* parent )
98 SalomeApp_Application* app = getGeometryGUI()->getApp();
99 if ( !app ) return false;
100 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() );
101 if ( !study ) return false;
103 SALOMEDS::Study_var dsStudy = GeometryGUI::ClientStudyToStudy( study->studyDS() );
104 GEOM::GEOM_IOperations_var op = GeometryGUI::GetGeomGen()->GetPluginOperations( dsStudy->StudyId(), "VTKPluginEngine" );
105 GEOM::IVTKOperations_var stlOp = GEOM::IVTKOperations::_narrow( op );
106 if ( CORBA::is_nil( stlOp ) ) return false;
108 LightApp_SelectionMgr* sm = app->selectionMgr();
109 if ( !sm ) return false;
111 SALOME_ListIO selectedObjects;
112 sm->selectedObjects( selectedObjects );
115 SALOME_ListIteratorOfListIO it( selectedObjects );
116 for ( ; it.More(); it.Next() )
118 Handle(SALOME_InteractiveObject) io = it.Value();
119 GEOM::GEOM_Object_var obj = GEOMBase::ConvertIOinGEOMObject( io );
121 if ( CORBA::is_nil( obj ) ) continue;
123 double deflection = 0.;
124 QString fileName = VTKPlugin_ExportDlg::getFileName( io,
126 tr( "EXPORT_TITLE" ),
130 if ( fileName.isEmpty() )
133 SUIT_OverrideCursor wc;
135 GEOM_Operation transaction( app, stlOp.in() );
139 app->putInfo( tr( "GEOM_PRP_EXPORT" ).arg( fileName ) );
142 stlOp->ExportVTK( obj, fileName.toUtf8().constData(), deflection );
144 if ( stlOp->IsDone() )
146 transaction.commit();
151 SUIT_MessageBox::critical( parent,
153 tr( "GEOM_PRP_ABORT" ) + "\n" + tr( stlOp->GetErrorCode() ) );
157 catch ( const SALOME::SALOME_Exception& e )
167 SUIT_MessageBox::warning( parent,
169 tr( "GEOM_WRN_NO_APPROPRIATE_SELECTION" ) );
174 //=====================================================================================
176 //=====================================================================================
180 __declspec( dllexport )
182 GEOMGUI* GetLibGUI( GeometryGUI* parent )
184 return new VTKPlugin_GUI( parent );