1 // Copyright (C) 2014 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"
40 #include <SALOMEconfig.h>
41 #include CORBA_SERVER_HEADER(BREPPlugin)
43 //=======================================================================
44 // function : BREPPlugin_GUI()
45 // purpose : Constructor
46 //=======================================================================
47 BREPPlugin_GUI::BREPPlugin_GUI( GeometryGUI* parent ) : GEOMPluginGUI( parent )
51 //=======================================================================
52 // function : ~BREPPlugin_GUI
53 // purpose : Destructor
54 //=======================================================================
55 BREPPlugin_GUI::~BREPPlugin_GUI()
59 //=======================================================================
60 // function : OnGUIEvent()
62 //=======================================================================
63 bool BREPPlugin_GUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
66 switch ( theCommandID ) {
68 cmd = "Export_BREP"; break;
70 cmd = "Import_BREP"; break;
74 return OnGUIEvent( cmd, parent );
77 //=======================================================================
78 // function : OnGUIEvent()
80 //=======================================================================
81 bool BREPPlugin_GUI::OnGUIEvent( const QString& theCommandID, SUIT_Desktop* parent )
85 if ( theCommandID == "Export_BREP" )
87 result = exportBREP( parent );
89 else if ( theCommandID == "Import_BREP" )
91 result = importBREP( parent );
95 getGeometryGUI()->getApp()->putInfo( tr("GEOM_PRP_COMMAND").arg( theCommandID ) );
101 //=======================================================================
102 // function : importBREP
104 //=======================================================================
105 bool BREPPlugin_GUI::importBREP( SUIT_Desktop* parent )
107 SalomeApp_Application* app = getGeometryGUI()->getApp();
108 if ( !app ) return false;
109 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() );
110 if ( !study ) return false;
112 SALOMEDS::Study_var dsStudy = GeometryGUI::ClientStudyToStudy( study->studyDS() );
113 GEOM::GEOM_IOperations_var op = GeometryGUI::GetGeomGen()->GetPluginOperations( dsStudy->StudyId(), "BREPPluginEngine" );
114 GEOM::IBREPOperations_var brepOp = GEOM::IBREPOperations::_narrow( op );
115 if ( CORBA::is_nil( brepOp ) ) 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.in() );
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( dsStudy,
141 SALOMEDS::SObject::_nil(),
143 publishName.toUtf8().constData() );
145 entryList.append( so->GetID() );
146 transaction.commit();
147 GEOM_Displayer( study ).Display( main.in() );
152 errors.append( QString( "%1 : %2" ).arg( fileName ).arg( brepOp->GetErrorCode() ) );
155 catch( const SALOME::SALOME_Exception& e )
160 getGeometryGUI()->updateObjBrowser( true );
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;
181 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() );
182 if ( !study ) return false;
184 SALOMEDS::Study_var dsStudy = GeometryGUI::ClientStudyToStudy( study->studyDS() );
185 GEOM::GEOM_IOperations_var op = GeometryGUI::GetGeomGen()->GetPluginOperations( dsStudy->StudyId(), "BREPPluginEngine" );
186 GEOM::IBREPOperations_var brepOp = GEOM::IBREPOperations::_narrow( op );
187 if ( CORBA::is_nil( brepOp ) ) return false;
189 LightApp_SelectionMgr* sm = app->selectionMgr();
190 if ( !sm ) return false;
192 SALOME_ListIO selectedObjects;
193 sm->selectedObjects( selectedObjects );
196 SALOME_ListIteratorOfListIO it( selectedObjects );
197 for ( ; it.More(); it.Next() )
199 Handle(SALOME_InteractiveObject) io = it.Value();
200 GEOM::GEOM_Object_var obj = GEOMBase::ConvertIOinGEOMObject( io );
202 if ( CORBA::is_nil( obj ) ) continue;
204 QString fileName = app->getFileName( false,
205 QString( io->getName() ),
207 tr( "EXPORT_TITLE" ),
210 if ( fileName.isEmpty() )
213 SUIT_OverrideCursor wc;
215 GEOM_Operation transaction( app, brepOp.in() );
219 app->putInfo( tr( "GEOM_PRP_EXPORT" ).arg( fileName ) );
222 brepOp->ExportBREP( obj, fileName.toUtf8().constData() );
224 if ( brepOp->IsDone() )
226 transaction.commit();
231 SUIT_MessageBox::critical( parent,
233 tr( "GEOM_PRP_ABORT" ) + "\n" + tr( brepOp->GetErrorCode() ) );
237 catch ( const SALOME::SALOME_Exception& e )
247 SUIT_MessageBox::warning( parent,
249 tr( "GEOM_WRN_NO_APPROPRIATE_SELECTION" ) );
254 //=====================================================================================
256 //=====================================================================================
260 __declspec( dllexport )
262 GEOMGUI* GetLibGUI( GeometryGUI* parent )
264 return new BREPPlugin_GUI( parent );