1 // Copyright (C) 2014-2024 CEA, EDF, 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;
113 GEOM::GEOM_IOperations_var op = GeometryGUI::GetGeomGen()->GetPluginOperations( "BREPPluginEngine" );
114 BREPOpPtr brepOp = GEOM::IBREPOperations::_narrow( op );
115 if ( brepOp.isNull() ) return false;
117 QStringList fileNames = app->getOpenFileNames( SUIT_FileDlg::getLastVisitedPath().isEmpty() ? QDir::currentPath() : QString(""),
119 tr( "IMPORT_TITLE" ),
121 if ( fileNames.count() > 0 )
123 QStringList entryList;
126 foreach( QString fileName, fileNames )
128 SUIT_OverrideCursor wc;
129 GEOM_Operation transaction( app, brepOp.get() );
133 app->putInfo( tr( "GEOM_PRP_LOADING" ).arg( fileName ) );
135 GEOM::ListOfGO_var result = brepOp->ImportBREP( fileName.toUtf8().constData() );
136 if ( result->length() > 0 && brepOp->IsDone() )
138 GEOM::GEOM_Object_var main = result[0];
139 QString publishName = GEOMBase::GetDefaultName( SUIT_Tools::file( fileName, true ) );
140 SALOMEDS::SObject_var so = GeometryGUI::GetGeomGen()->PublishInStudy( SALOMEDS::SObject::_nil(),
142 publishName.toUtf8().constData() );
144 entryList.append( so->GetID() );
145 transaction.commit();
146 GEOM_Displayer().Display( main.in() );
152 errors.append( QString( "%1 : %2" ).arg( fileName ).arg( brepOp->GetErrorCode() ) );
155 catch( const SALOME::SALOME_Exception& e )
160 getGeometryGUI()->updateObjBrowser();
161 app->browseObjects( entryList );
163 if ( errors.count() > 0 )
165 SUIT_MessageBox::critical( parent,
167 tr( "GEOM_IMPORT_ERRORS" ) + "\n" + errors.join( "\n" ) );
170 return fileNames.count() > 0;
173 //=======================================================================
174 // function : exportBREP
176 //=======================================================================
177 bool BREPPlugin_GUI::exportBREP( SUIT_Desktop* parent )
179 SalomeApp_Application* app = getGeometryGUI()->getApp();
180 if ( !app ) return false;
182 GEOM::GEOM_IOperations_var op = GeometryGUI::GetGeomGen()->GetPluginOperations( "BREPPluginEngine" );
183 BREPOpPtr brepOp = GEOM::IBREPOperations::_narrow( op );
184 if ( brepOp.isNull() ) return false;
186 LightApp_SelectionMgr* sm = app->selectionMgr();
187 if ( !sm ) return false;
189 SALOME_ListIO selectedObjects;
190 sm->selectedObjects( selectedObjects );
193 SALOME_ListIteratorOfListIO it( selectedObjects );
194 for ( ; it.More(); it.Next() )
196 Handle(SALOME_InteractiveObject) io = it.Value();
197 GEOM::GEOM_Object_var obj = GEOMBase::ConvertIOinGEOMObject( io );
199 if ( CORBA::is_nil( obj ) ) continue;
201 QString fileName = app->getFileName( false,
202 QString( io->getName() ),
204 tr( "EXPORT_TITLE" ),
207 if ( fileName.isEmpty() )
210 SUIT_OverrideCursor wc;
212 GEOM_Operation transaction( app, brepOp.get() );
216 app->putInfo( tr( "GEOM_PRP_EXPORT" ).arg( fileName ) );
219 brepOp->ExportBREP( obj, fileName.toUtf8().constData() );
221 if ( brepOp->IsDone() )
223 transaction.commit();
228 SUIT_MessageBox::critical( parent,
230 tr( "GEOM_PRP_ABORT" ) + "\n" + tr( brepOp->GetErrorCode() ) );
234 catch ( const SALOME::SALOME_Exception& e )
244 SUIT_MessageBox::warning( parent,
246 tr( "GEOM_WRN_NO_APPROPRIATE_SELECTION" ) );
251 //=====================================================================================
253 //=====================================================================================
257 __declspec( dllexport )
259 GEOMGUI* GetLibGUI( GeometryGUI* parent )
261 return new BREPPlugin_GUI( parent );