1 // Copyright (C) 2014-2015 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 "ACISPlugin_GUI.h"
22 #include "ACISPlugin_IOperations_i.hh"
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(ACISPlugin)
44 //=======================================================================
45 // function : ACISPlugin_GUI()
46 // purpose : Constructor
47 //=======================================================================
48 ACISPlugin_GUI::ACISPlugin_GUI( GeometryGUI* parent ) : GEOMPluginGUI( parent )
52 //=======================================================================
53 // function : ~ACISPlugin_GUI
54 // purpose : Destructor
55 //=======================================================================
56 ACISPlugin_GUI::~ACISPlugin_GUI()
60 //=======================================================================
61 // function : OnGUIEvent()
63 //=======================================================================
64 bool ACISPlugin_GUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
67 switch ( theCommandID ) {
75 return OnGUIEvent( cmd, parent );
78 //=======================================================================
79 // function : OnGUIEvent()
81 //=======================================================================
82 bool ACISPlugin_GUI::OnGUIEvent( const QString& theCommandID, SUIT_Desktop* parent )
86 if ( theCommandID == "Export_ACIS" )
88 result = exportACIS( parent );
90 else if ( theCommandID == "Import_ACIS" )
92 result = importACIS( parent );
96 getGeometryGUI()->getApp()->putInfo( tr("GEOM_PRP_COMMAND").arg( theCommandID ) );
101 //=======================================================================
102 // function : importACIS
104 //=======================================================================
105 bool ACISPlugin_GUI::importACIS( 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(), "ACISPluginEngine" );
114 ACISPlugin::IACISOperations_var acisOp = ACISPlugin::IACISOperations::_narrow( op );
115 if ( CORBA::is_nil( acisOp ) ) 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 SUIT_MessageBox::StandardButton acisAnswer = SUIT_MessageBox::NoButton;
128 foreach( QString fileName, fileNames )
130 SUIT_OverrideCursor wc;
131 GEOM_Operation transaction( app, acisOp.in() );
135 app->putInfo( tr( "GEOM_PRP_LOADING" ).arg( fileName ) );
138 if ( acisAnswer != SUIT_MessageBox::YesToAll && acisAnswer != SUIT_MessageBox::NoToAll ) {
139 SUIT_MessageBox::StandardButtons btns = SUIT_MessageBox::Yes | SUIT_MessageBox::No;
140 btns = btns | SUIT_MessageBox::YesToAll | SUIT_MessageBox::NoToAll;
141 acisAnswer = SUIT_MessageBox::question( app->desktop(),
143 tr("GEOM_PUBLISH_NAMED_SHAPES"),
144 btns | SUIT_MessageBox::Cancel,
145 SUIT_MessageBox::No );
146 if ( acisAnswer == SUIT_MessageBox::Cancel ) {
147 acisOp->SetErrorCode(OK);
148 return true; // cancel (break) import operation
151 GEOM::ListOfGO_var result = acisOp->ImportACIS( fileName.toUtf8().constData() );
153 if ( result->length() > 0 && acisOp->IsDone() ) {
154 GEOM::GEOM_Object_var main = result[0];
155 QString publishName = GEOMBase::GetDefaultName( SUIT_Tools::file( fileName, true ) );
156 main.in()->SetName( publishName.toStdString().c_str() );
157 SALOMEDS::SObject_var so = GeometryGUI::GetGeomGen()->PublishInStudy( dsStudy,
158 SALOMEDS::SObject::_nil(),
160 publishName.toUtf8().constData() );
161 if ( acisAnswer == SUIT_MessageBox::Yes || acisAnswer == SUIT_MessageBox::YesToAll )
162 GeometryGUI::GetGeomGen()->PublishNamedShapesInStudy( dsStudy, main.in() );
164 entryList.append( so->GetID() );
165 transaction.commit();
170 errors.append( QString( "%1 : %2" ).arg( fileName ).arg( acisOp->GetErrorCode() ) );
173 catch( const SALOME::SALOME_Exception& e )
178 getGeometryGUI()->updateObjBrowser( true );
179 app->browseObjects( entryList );
181 if ( errors.count() > 0 )
183 SUIT_MessageBox::critical( parent,
185 tr( "GEOM_IMPORT_ERRORS" ) + "\n" + errors.join( "\n" ) );
188 return fileNames.count() > 0;
191 //=======================================================================
192 // function : exportACIS
194 //=======================================================================
195 bool ACISPlugin_GUI::exportACIS( SUIT_Desktop* parent )
197 SalomeApp_Application* app = getGeometryGUI()->getApp();
198 if ( !app ) return false;
199 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() );
200 if ( !study ) return false;
202 SALOMEDS::Study_var dsStudy = GeometryGUI::ClientStudyToStudy( study->studyDS() );
203 GEOM::GEOM_IOperations_var op = GeometryGUI::GetGeomGen()->GetPluginOperations( dsStudy->StudyId(), "ACISPluginEngine" );
204 ACISPlugin::IACISOperations_var acisOp = ACISPlugin::IACISOperations::_narrow( op );
205 if ( CORBA::is_nil( acisOp ) ) return false;
207 LightApp_SelectionMgr* sm = app->selectionMgr();
208 if ( !sm ) return false;
210 SALOME_ListIO selectedObjects;
211 sm->selectedObjects( selectedObjects );
214 SALOME_ListIteratorOfListIO it( selectedObjects );
215 for ( ; it.More(); it.Next() )
217 Handle(SALOME_InteractiveObject) io = it.Value();
218 GEOM::GEOM_Object_var obj = GEOMBase::ConvertIOinGEOMObject( io );
220 if ( CORBA::is_nil( obj ) ) continue;
222 QString fileName = app->getFileName( false,
223 QString( io->getName() ),
225 tr( "EXPORT_TITLE" ),
228 if ( fileName.isEmpty() )
231 SUIT_OverrideCursor wc;
233 GEOM_Operation transaction( app, acisOp.in() );
237 app->putInfo( tr( "GEOM_PRP_EXPORT" ).arg( fileName ) );
240 acisOp->ExportACIS( obj, fileName.toUtf8().constData() );
242 if ( acisOp->IsDone() )
244 transaction.commit();
249 SUIT_MessageBox::critical( parent,
251 tr( "GEOM_PRP_ABORT" ) + "\n" + tr( acisOp->GetErrorCode() ) );
255 catch ( const SALOME::SALOME_Exception& e )
265 SUIT_MessageBox::warning( parent,
267 tr( "GEOM_WRN_NO_APPROPRIATE_SELECTION" ) );
272 //=====================================================================================
274 //=====================================================================================
278 __declspec( dllexport )
280 GEOMGUI* GetLibGUI( GeometryGUI* parent )
282 return new ACISPlugin_GUI( parent );