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 "BREPPlugin_GUI.h"
24 #include <SUIT_Desktop.h>
25 #include <SUIT_FileDlg.h>
26 #include <SUIT_MessageBox.h>
27 #include <SUIT_OverrideCursor.h>
28 #include <SUIT_Tools.h>
29 #include <LightApp_SelectionMgr.h>
30 #include <SalomeApp_Application.h>
31 #include <SalomeApp_Study.h>
32 #include <SALOME_ListIO.hxx>
35 #include "GeometryGUI.h"
36 #include "GEOM_Operation.h"
38 #include "GEOM_Displayer.h"
39 #include "GEOM_GenericObjPtr.h"
41 #include <SALOMEconfig.h>
42 #include CORBA_SERVER_HEADER(BREPPlugin)
44 typedef GEOM::GenericObjPtr<GEOM::IBREPOperations> BREPOpPtr;
46 //=======================================================================
47 // function : BREPPlugin_GUI()
48 // purpose : Constructor
49 //=======================================================================
50 BREPPlugin_GUI::BREPPlugin_GUI( GeometryGUI* parent ) : GEOMPluginGUI( parent )
54 //=======================================================================
55 // function : ~BREPPlugin_GUI
56 // purpose : Destructor
57 //=======================================================================
58 BREPPlugin_GUI::~BREPPlugin_GUI()
62 //=======================================================================
63 // function : OnGUIEvent()
65 //=======================================================================
66 bool BREPPlugin_GUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
69 switch ( theCommandID ) {
71 cmd = "Export_BREP"; break;
73 cmd = "Import_BREP"; break;
77 return OnGUIEvent( cmd, parent );
80 //=======================================================================
81 // function : OnGUIEvent()
83 //=======================================================================
84 bool BREPPlugin_GUI::OnGUIEvent( const QString& theCommandID, SUIT_Desktop* parent )
88 if ( theCommandID == "Export_BREP" )
90 result = exportBREP( parent );
92 else if ( theCommandID == "Import_BREP" )
94 result = importBREP( parent );
98 getGeometryGUI()->getApp()->putInfo( tr("GEOM_PRP_COMMAND").arg( theCommandID ) );
104 //=======================================================================
105 // function : importBREP
107 //=======================================================================
108 bool BREPPlugin_GUI::importBREP( SUIT_Desktop* parent )
110 SalomeApp_Application* app = getGeometryGUI()->getApp();
111 if ( !app ) return false;
112 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() );
113 if ( !study ) return false;
115 SALOMEDS::Study_var dsStudy = GeometryGUI::ClientStudyToStudy( study->studyDS() );
116 GEOM::GEOM_IOperations_var op = GeometryGUI::GetGeomGen()->GetPluginOperations( dsStudy->StudyId(), "BREPPluginEngine" );
117 BREPOpPtr brepOp = GEOM::IBREPOperations::_narrow( op );
118 if ( brepOp.isNull() ) return false;
120 QStringList fileNames = app->getOpenFileNames( SUIT_FileDlg::getLastVisitedPath().isEmpty() ? QDir::currentPath() : QString(""),
122 tr( "IMPORT_TITLE" ),
124 if ( fileNames.count() > 0 )
126 QStringList entryList;
129 foreach( QString fileName, fileNames )
131 SUIT_OverrideCursor wc;
132 GEOM_Operation transaction( app, brepOp.get() );
136 app->putInfo( tr( "GEOM_PRP_LOADING" ).arg( fileName ) );
138 GEOM::ListOfGO_var result = brepOp->ImportBREP( fileName.toUtf8().constData() );
139 if ( result->length() > 0 && brepOp->IsDone() )
141 GEOM::GEOM_Object_var main = result[0];
142 QString publishName = GEOMBase::GetDefaultName( SUIT_Tools::file( fileName, true ) );
143 SALOMEDS::SObject_var so = GeometryGUI::GetGeomGen()->PublishInStudy( dsStudy,
144 SALOMEDS::SObject::_nil(),
146 publishName.toUtf8().constData() );
148 entryList.append( so->GetID() );
149 transaction.commit();
150 GEOM_Displayer( study ).Display( main.in() );
156 errors.append( QString( "%1 : %2" ).arg( fileName ).arg( brepOp->GetErrorCode() ) );
159 catch( const SALOME::SALOME_Exception& e )
164 getGeometryGUI()->updateObjBrowser( true );
165 app->browseObjects( entryList );
167 if ( errors.count() > 0 )
169 SUIT_MessageBox::critical( parent,
171 tr( "GEOM_IMPORT_ERRORS" ) + "\n" + errors.join( "\n" ) );
174 return fileNames.count() > 0;
177 //=======================================================================
178 // function : exportBREP
180 //=======================================================================
181 bool BREPPlugin_GUI::exportBREP( SUIT_Desktop* parent )
183 SalomeApp_Application* app = getGeometryGUI()->getApp();
184 if ( !app ) return false;
185 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() );
186 if ( !study ) return false;
188 SALOMEDS::Study_var dsStudy = GeometryGUI::ClientStudyToStudy( study->studyDS() );
189 GEOM::GEOM_IOperations_var op = GeometryGUI::GetGeomGen()->GetPluginOperations( dsStudy->StudyId(), "BREPPluginEngine" );
190 BREPOpPtr brepOp = GEOM::IBREPOperations::_narrow( op );
191 if ( brepOp.isNull() ) return false;
193 LightApp_SelectionMgr* sm = app->selectionMgr();
194 if ( !sm ) return false;
196 SALOME_ListIO selectedObjects;
197 sm->selectedObjects( selectedObjects );
200 SALOME_ListIteratorOfListIO it( selectedObjects );
201 for ( ; it.More(); it.Next() )
203 Handle(SALOME_InteractiveObject) io = it.Value();
204 GEOM::GEOM_Object_var obj = GEOMBase::ConvertIOinGEOMObject( io );
206 if ( CORBA::is_nil( obj ) ) continue;
208 QString fileName = app->getFileName( false,
209 QString( io->getName() ),
211 tr( "EXPORT_TITLE" ),
214 if ( fileName.isEmpty() )
217 SUIT_OverrideCursor wc;
219 GEOM_Operation transaction( app, brepOp.get() );
223 app->putInfo( tr( "GEOM_PRP_EXPORT" ).arg( fileName ) );
226 brepOp->ExportBREP( obj, fileName.toUtf8().constData() );
228 if ( brepOp->IsDone() )
230 transaction.commit();
235 SUIT_MessageBox::critical( parent,
237 tr( "GEOM_PRP_ABORT" ) + "\n" + tr( brepOp->GetErrorCode() ) );
241 catch ( const SALOME::SALOME_Exception& e )
251 SUIT_MessageBox::warning( parent,
253 tr( "GEOM_WRN_NO_APPROPRIATE_SELECTION" ) );
258 //=====================================================================================
260 //=====================================================================================
264 __declspec( dllexport )
266 GEOMGUI* GetLibGUI( GeometryGUI* parent )
268 return new BREPPlugin_GUI( parent );