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 "IGESPlugin_GUI.h"
22 #include "IGESPlugin_ExportDlg.h"
25 #include <SUIT_Desktop.h>
26 #include <SUIT_FileDlg.h>
27 #include <SUIT_MessageBox.h>
28 #include <SUIT_OverrideCursor.h>
29 #include <SUIT_Tools.h>
30 #include <LightApp_SelectionMgr.h>
31 #include <SalomeApp_Application.h>
32 #include <SalomeApp_Study.h>
33 #include <SALOME_ListIO.hxx>
36 #include "GeometryGUI.h"
37 #include "GEOM_Operation.h"
39 #include "GEOM_Displayer.h"
41 #include <SALOMEconfig.h>
42 #include CORBA_SERVER_HEADER(IGESPlugin)
44 //=======================================================================
45 // function : IGESPlugin_GUI()
46 // purpose : Constructor
47 //=======================================================================
48 IGESPlugin_GUI::IGESPlugin_GUI( GeometryGUI* parent ) : GEOMPluginGUI( parent )
52 //=======================================================================
53 // function : ~IGESPlugin_GUI
54 // purpose : Destructor
55 //=======================================================================
56 IGESPlugin_GUI::~IGESPlugin_GUI()
60 //=======================================================================
61 // function : OnGUIEvent()
63 //=======================================================================
64 bool IGESPlugin_GUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
67 switch ( theCommandID ) {
69 cmd = "Export_IGES"; break;
71 cmd = "Import_IGES"; break;
75 return OnGUIEvent( cmd, parent );
78 //=======================================================================
79 // function : OnGUIEvent()
81 //=======================================================================
82 bool IGESPlugin_GUI::OnGUIEvent( const QString& theCommandID, SUIT_Desktop* parent )
86 if( theCommandID == "Export_IGES" ) {
87 result = exportIGES( parent );
89 else if (theCommandID == "Import_IGES") {
90 result = importIGES( parent );
93 getGeometryGUI()->getApp()->putInfo( tr("GEOM_PRP_COMMAND").arg( theCommandID ) );
99 //=======================================================================
100 // function : importIGES
102 //=======================================================================
103 bool IGESPlugin_GUI::importIGES( SUIT_Desktop* parent )
105 SalomeApp_Application* app = getGeometryGUI()->getApp();
106 if ( !app ) return false;
107 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() );
108 if ( !study ) return false;
110 SALOMEDS::Study_var dsStudy = GeometryGUI::ClientStudyToStudy( study->studyDS() );
111 GEOM::GEOM_IOperations_var op = GeometryGUI::GetGeomGen()->GetPluginOperations( dsStudy->StudyId(), "IGESPluginEngine" );
112 GEOM::IIGESOperations_var igesOp = GEOM::IIGESOperations::_narrow( op );
113 if ( CORBA::is_nil( igesOp ) ) return false;
115 QStringList fileNames = app->getOpenFileNames( SUIT_FileDlg::getLastVisitedPath().isEmpty() ? QDir::currentPath() : QString(""),
117 tr( "IMPORT_TITLE" ),
119 if ( fileNames.count() > 0 )
121 QStringList entryList;
123 SUIT_MessageBox::StandardButton igesAnswer = SUIT_MessageBox::NoButton;
125 for ( int i = 0; i < fileNames.count(); i++ )
127 QString fileName = fileNames.at( i );
128 SUIT_OverrideCursor wc;
129 GEOM_Operation transaction( app, igesOp.in() );
130 bool ignoreUnits = false;
134 app->putInfo( tr( "GEOM_PRP_LOADING" ).arg( SUIT_Tools::file( fileName, true ) ) );
137 CORBA::String_var units = igesOp->ReadValue( fileName.toUtf8().constData(), "LEN_UNITS" );
138 QString unitsStr( units.in() );
139 bool unitsOK = unitsStr.isEmpty() || unitsStr == "M" || unitsStr.toLower() == "metre";
143 if( igesAnswer == SUIT_MessageBox::NoToAll )
147 else if( igesAnswer != SUIT_MessageBox::YesToAll )
149 SUIT_MessageBox::StandardButtons btns = SUIT_MessageBox::Yes | SUIT_MessageBox::No | SUIT_MessageBox::Cancel;
150 if ( i < fileNames.count()-1 ) btns = btns | SUIT_MessageBox::YesToAll | SUIT_MessageBox::NoToAll;
151 igesAnswer = SUIT_MessageBox::question( parent,
153 tr( "SCALE_DIMENSIONS" ).arg( unitsStr ),
155 SUIT_MessageBox::No );
156 switch ( igesAnswer )
158 case SUIT_MessageBox::Cancel:
159 return true; // cancel (break) import operation
160 case SUIT_MessageBox::Yes:
161 case SUIT_MessageBox::YesToAll:
162 break; // scaling is confirmed
163 case SUIT_MessageBox::No:
164 case SUIT_MessageBox::NoAll:
165 ignoreUnits = true; // scaling is rejected
172 GEOM::ListOfGO_var result = igesOp->ImportIGES( fileName.toUtf8().constData(), ignoreUnits );
173 if ( result->length() > 0 && igesOp->IsDone() )
175 GEOM::GEOM_Object_var main = result[0];
176 QString publishName = GEOMBase::GetDefaultName( SUIT_Tools::file( fileName, true ) );
177 SALOMEDS::SObject_var so = GeometryGUI::GetGeomGen()->PublishInStudy( dsStudy,
178 SALOMEDS::SObject::_nil(),
180 publishName.toUtf8().constData() );
182 entryList.append( so->GetID() );
183 transaction.commit();
184 GEOM_Displayer( study ).Display( main.in() );
189 errors.append( QString( "%1 : %2" ).arg( fileName ).arg( igesOp->GetErrorCode() ) );
192 catch( const SALOME::SALOME_Exception& e )
198 getGeometryGUI()->updateObjBrowser( true );
199 app->browseObjects( entryList );
201 if ( errors.count() > 0 )
203 SUIT_MessageBox::critical( parent,
205 tr( "GEOM_IMPORT_ERRORS" ) + "\n" + errors.join( "\n" ) );
208 return fileNames.count() > 0;
211 //=======================================================================
212 // function : exportIGES
214 //=======================================================================
215 bool IGESPlugin_GUI::exportIGES( SUIT_Desktop* parent )
217 SalomeApp_Application* app = getGeometryGUI()->getApp();
218 if ( !app ) return false;
219 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() );
220 if ( !study ) return false;
222 SALOMEDS::Study_var dsStudy = GeometryGUI::ClientStudyToStudy( study->studyDS() );
223 GEOM::GEOM_IOperations_var op = GeometryGUI::GetGeomGen()->GetPluginOperations( dsStudy->StudyId(), "IGESPluginEngine" );
224 GEOM::IIGESOperations_var igesOp = GEOM::IIGESOperations::_narrow( op );
225 if ( CORBA::is_nil( igesOp ) ) return false;
227 LightApp_SelectionMgr* sm = app->selectionMgr();
228 if ( !sm ) return false;
230 SALOME_ListIO selectedObjects;
231 sm->selectedObjects( selectedObjects );
234 SALOME_ListIteratorOfListIO it( selectedObjects );
235 for ( ; it.More(); it.Next() )
237 Handle(SALOME_InteractiveObject) io = it.Value();
238 GEOM::GEOM_Object_var obj = GEOMBase::ConvertIOinGEOMObject( io );
240 if ( CORBA::is_nil( obj ) ) continue;
243 QString fileName = IGESPlugin_ExportDlg::getFileName( QString( io->getName() ),
245 tr( "EXPORT_TITLE" ),
249 if ( fileName.isEmpty() )
252 SUIT_OverrideCursor wc;
254 GEOM_Operation transaction( app, igesOp.in() );
258 app->putInfo( tr( "GEOM_PRP_EXPORT" ).arg( fileName ) );
261 igesOp->ExportIGES( obj, fileName.toUtf8().constData(), version.toUtf8().constData() );
263 if ( igesOp->IsDone() )
265 transaction.commit();
270 SUIT_MessageBox::critical( parent,
272 tr( "GEOM_PRP_ABORT" ) + "\n" + tr( igesOp->GetErrorCode() ) );
276 catch ( const SALOME::SALOME_Exception& e )
286 SUIT_MessageBox::warning( parent,
288 tr( "GEOM_WRN_NO_APPROPRIATE_SELECTION" ) );
293 //=====================================================================================
295 //=====================================================================================
299 __declspec( dllexport )
301 GEOMGUI* GetLibGUI( GeometryGUI* parent )
303 return new IGESPlugin_GUI( parent );