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"
40 #include "GEOM_GenericObjPtr.h"
42 #include <SALOMEconfig.h>
43 #include CORBA_SERVER_HEADER(IGESPlugin)
45 typedef GEOM::GenericObjPtr<GEOM::IIGESOperations> IGESOpPtr;
47 //=======================================================================
48 // function : IGESPlugin_GUI()
49 // purpose : Constructor
50 //=======================================================================
51 IGESPlugin_GUI::IGESPlugin_GUI( GeometryGUI* parent ) : GEOMPluginGUI( parent )
55 //=======================================================================
56 // function : ~IGESPlugin_GUI
57 // purpose : Destructor
58 //=======================================================================
59 IGESPlugin_GUI::~IGESPlugin_GUI()
63 //=======================================================================
64 // function : OnGUIEvent()
66 //=======================================================================
67 bool IGESPlugin_GUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
70 switch ( theCommandID ) {
72 cmd = "Export_IGES"; break;
74 cmd = "Import_IGES"; break;
78 return OnGUIEvent( cmd, parent );
81 //=======================================================================
82 // function : OnGUIEvent()
84 //=======================================================================
85 bool IGESPlugin_GUI::OnGUIEvent( const QString& theCommandID, SUIT_Desktop* parent )
89 if( theCommandID == "Export_IGES" ) {
90 result = exportIGES( parent );
92 else if (theCommandID == "Import_IGES") {
93 result = importIGES( parent );
96 getGeometryGUI()->getApp()->putInfo( tr("GEOM_PRP_COMMAND").arg( theCommandID ) );
102 //=======================================================================
103 // function : importIGES
105 //=======================================================================
106 bool IGESPlugin_GUI::importIGES( SUIT_Desktop* parent )
108 SalomeApp_Application* app = getGeometryGUI()->getApp();
109 if ( !app ) return false;
110 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() );
111 if ( !study ) return false;
113 SALOMEDS::Study_var dsStudy = GeometryGUI::ClientStudyToStudy( study->studyDS() );
114 GEOM::GEOM_IOperations_var op = GeometryGUI::GetGeomGen()->GetPluginOperations( dsStudy->StudyId(), "IGESPluginEngine" );
115 IGESOpPtr igesOp = GEOM::IIGESOperations::_narrow( op );
116 if ( igesOp.isNull() ) return false;
118 QStringList fileNames = app->getOpenFileNames( SUIT_FileDlg::getLastVisitedPath().isEmpty() ? QDir::currentPath() : QString(""),
120 tr( "IMPORT_TITLE" ),
122 if ( fileNames.count() > 0 )
124 QStringList entryList;
126 SUIT_MessageBox::StandardButton igesAnswer = SUIT_MessageBox::NoButton;
128 for ( int i = 0; i < fileNames.count(); i++ )
130 QString fileName = fileNames.at( i );
131 SUIT_OverrideCursor wc;
132 GEOM_Operation transaction( app, igesOp.get() );
133 bool ignoreUnits = false;
137 app->putInfo( tr( "GEOM_PRP_LOADING" ).arg( SUIT_Tools::file( fileName, true ) ) );
140 CORBA::String_var units = igesOp->ReadValue( fileName.toUtf8().constData(), "LEN_UNITS" );
141 QString unitsStr( units.in() );
142 bool unitsOK = unitsStr.isEmpty() || unitsStr == "M" || unitsStr.toLower() == "metre";
146 if( igesAnswer == SUIT_MessageBox::NoToAll )
150 else if( igesAnswer != SUIT_MessageBox::YesToAll )
152 SUIT_MessageBox::StandardButtons btns = SUIT_MessageBox::Yes | SUIT_MessageBox::No | SUIT_MessageBox::Cancel;
153 if ( i < fileNames.count()-1 ) btns = btns | SUIT_MessageBox::YesToAll | SUIT_MessageBox::NoToAll;
154 igesAnswer = SUIT_MessageBox::question( parent,
156 tr( "SCALE_DIMENSIONS" ).arg( unitsStr ),
158 SUIT_MessageBox::No );
159 switch ( igesAnswer )
161 case SUIT_MessageBox::Cancel:
162 return true; // cancel (break) import operation
163 case SUIT_MessageBox::Yes:
164 case SUIT_MessageBox::YesToAll:
165 break; // scaling is confirmed
166 case SUIT_MessageBox::No:
167 case SUIT_MessageBox::NoAll:
168 ignoreUnits = true; // scaling is rejected
175 GEOM::ListOfGO_var result = igesOp->ImportIGES( fileName.toUtf8().constData(), ignoreUnits );
176 if ( result->length() > 0 && igesOp->IsDone() )
178 GEOM::GEOM_Object_var main = result[0];
179 QString publishName = GEOMBase::GetDefaultName( SUIT_Tools::file( fileName, true ) );
180 SALOMEDS::SObject_var so = GeometryGUI::GetGeomGen()->PublishInStudy( dsStudy,
181 SALOMEDS::SObject::_nil(),
183 publishName.toUtf8().constData() );
185 entryList.append( so->GetID() );
186 transaction.commit();
187 GEOM_Displayer( study ).Display( main.in() );
193 errors.append( QString( "%1 : %2" ).arg( fileName ).arg( igesOp->GetErrorCode() ) );
196 catch( const SALOME::SALOME_Exception& e )
202 getGeometryGUI()->updateObjBrowser( true );
203 app->browseObjects( entryList );
205 if ( errors.count() > 0 )
207 SUIT_MessageBox::critical( parent,
209 tr( "GEOM_IMPORT_ERRORS" ) + "\n" + errors.join( "\n" ) );
212 return fileNames.count() > 0;
215 //=======================================================================
216 // function : exportIGES
218 //=======================================================================
219 bool IGESPlugin_GUI::exportIGES( SUIT_Desktop* parent )
221 SalomeApp_Application* app = getGeometryGUI()->getApp();
222 if ( !app ) return false;
223 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() );
224 if ( !study ) return false;
226 SALOMEDS::Study_var dsStudy = GeometryGUI::ClientStudyToStudy( study->studyDS() );
227 GEOM::GEOM_IOperations_var op = GeometryGUI::GetGeomGen()->GetPluginOperations( dsStudy->StudyId(), "IGESPluginEngine" );
228 IGESOpPtr igesOp = GEOM::IIGESOperations::_narrow( op );
229 if ( igesOp.isNull() ) return false;
231 LightApp_SelectionMgr* sm = app->selectionMgr();
232 if ( !sm ) return false;
234 SALOME_ListIO selectedObjects;
235 sm->selectedObjects( selectedObjects );
238 SALOME_ListIteratorOfListIO it( selectedObjects );
239 for ( ; it.More(); it.Next() )
241 Handle(SALOME_InteractiveObject) io = it.Value();
242 GEOM::GEOM_Object_var obj = GEOMBase::ConvertIOinGEOMObject( io );
244 if ( CORBA::is_nil( obj ) ) continue;
247 QString fileName = IGESPlugin_ExportDlg::getFileName( QString( io->getName() ),
249 tr( "EXPORT_TITLE" ),
253 if ( fileName.isEmpty() )
256 SUIT_OverrideCursor wc;
258 GEOM_Operation transaction( app, igesOp.get() );
262 app->putInfo( tr( "GEOM_PRP_EXPORT" ).arg( fileName ) );
265 igesOp->ExportIGES( obj, fileName.toUtf8().constData(), version.toUtf8().constData() );
267 if ( igesOp->IsDone() )
269 transaction.commit();
274 SUIT_MessageBox::critical( parent,
276 tr( "GEOM_PRP_ABORT" ) + "\n" + tr( igesOp->GetErrorCode() ) );
280 catch ( const SALOME::SALOME_Exception& e )
290 SUIT_MessageBox::warning( parent,
292 tr( "GEOM_WRN_NO_APPROPRIATE_SELECTION" ) );
297 //=====================================================================================
299 //=====================================================================================
303 __declspec( dllexport )
305 GEOMGUI* GetLibGUI( GeometryGUI* parent )
307 return new IGESPlugin_GUI( parent );