--- /dev/null
+// Copyright (C) 2014 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+// internal includes
+#include "ACISPlugin_ImportDlg.h"
+#include "ACISPlugin_Operations_i.hh"
+
+// GUI includes
+#include <SUIT_Session.h>
+#include <SUIT_MessageBox.h>
+#include <SUIT_Desktop.h>
+#include <SUIT_Tools.h>
+#include <SalomeApp_Application.h>
+#include <SalomeApp_Study.h>
+
+// GEOM includes
+#include <GeometryGUI.h>
+#include <GEOMBase.h>
+#include <GEOM_Operation.h>
+
+//=================================================================================
+// Constructor
+//=================================================================================
+ACISPlugin_ImportDlg::ACISPlugin_ImportDlg( QWidget* parent )
+: SUIT_FileDlg( parent, true, true, true ),
+ GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) )
+{
+ setWindowTitle( tr( "ACISPLUGIN_IMPORT_TITLE" ) );
+ setAcceptMode( AcceptOpen );
+ setNameFilter( tr( "ACISPLUGIN_ACIS_FILES" ) );
+ setFileMode( QFileDialog::ExistingFiles );
+}
+
+//=================================================================================
+// Destructor
+//=================================================================================
+ACISPlugin_ImportDlg::~ACISPlugin_ImportDlg()
+{
+ // no need to delete child widgets, Qt does it all for us
+}
+
+//=================================================================================
+// function : createOperation
+// purpose :
+//=================================================================================
+GEOM::GEOM_IOperations_ptr ACISPlugin_ImportDlg::createOperation()
+{
+ return getGeomEngine()->GetPluginOperations(getStudyId(), "ACISPluginEngine");
+}
+
+//=================================================================================
+// function : isValid
+// purpose :
+//=================================================================================
+bool ACISPlugin_ImportDlg::isValid (QString& msg)
+{
+ bool ok = true;
+ //@@ add custom validation actions here @@//
+ return ok;
+}
+
+//=================================================================================
+// function : execute
+// purpose :
+//=================================================================================
+bool ACISPlugin_ImportDlg::execute( ObjectList& objects )
+{
+ bool res = false;
+ GEOM::GEOM_Object_var anObj;
+ ACISPlugin::GEOM_IACISPluginOperations_var anOper = ACISPlugin::GEOM_IACISPluginOperations::_narrow( getOperation() );
+
+ SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
+ _PTR(Study) aStudy = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() )->studyDS();
+ SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy );
+
+ QStringList fileNames = selectedFiles();
+ if ( fileNames.count() == 0 )
+ return false; // nothing selected, return
+
+ SUIT_MessageBox::StandardButton acisAnswer = SUIT_MessageBox::NoButton;
+
+ for( int i = 0; i < fileNames.size(); i++ ) {
+ QString aFileName = fileNames.at( i );
+ if ( aFileName.isEmpty() )
+ continue;
+ GEOM_Operation* anOp = new GEOM_Operation( app, anOper.in() );
+ try {
+ app->putInfo( tr( "GEOM_PRP_LOADING" ).arg( SUIT_Tools::file( aFileName.toUtf8().constData(), /*withExten=*/true ) ) );
+ anOp->start();
+
+ if ( acisAnswer != SUIT_MessageBox::YesToAll && acisAnswer != SUIT_MessageBox::NoToAll ) {
+ SUIT_MessageBox::StandardButtons btns = SUIT_MessageBox::Yes | SUIT_MessageBox::No;
+ if ( i < fileNames.count()-1 ) btns = btns | SUIT_MessageBox::YesToAll | SUIT_MessageBox::NoToAll;
+ acisAnswer = SUIT_MessageBox::question( app->desktop(),
+ "Question",//tr("WRN_WARNING"),
+ tr("GEOM_PUBLISH_NAMED_SHAPES"),
+ btns | SUIT_MessageBox::Cancel,
+ SUIT_MessageBox::No );
+ if ( acisAnswer == SUIT_MessageBox::Cancel ) {
+ anOper->SetErrorCode(OK);
+ return true; // cancel (break) import operation
+ }
+ }
+
+ GEOM::ListOfGO_var anObj = anOper->ImportACIS( aFileName.toUtf8().constData() );
+
+ if ( anObj->length() > 0 && anOper->IsDone() ) {
+ GEOM::GEOM_Object_ptr anObjPtr = anObj[0]._retn();
+ objects.push_back( anObjPtr );
+ QString aPublishObjName =
+ GEOMBase::GetDefaultName( SUIT_Tools::file( aFileName, /*withExten=*/true ) );
+ anObjPtr->SetName( aPublishObjName.toStdString().c_str() );
+
+ SALOMEDS::SObject_var aSO =
+ GeometryGUI::GetGeomGen()->PublishInStudy( aDSStudy,
+ SALOMEDS::SObject::_nil(),
+ anObjPtr,
+ aPublishObjName.toLatin1().constData() );
+ if ( acisAnswer == SUIT_MessageBox::Yes || acisAnswer == SUIT_MessageBox::YesToAll )
+ GeometryGUI::GetGeomGen()->PublishNamedShapesInStudy( aDSStudy, anObjPtr );
+
+ anOp->commit();
+ }
+ else {
+ anOp->abort();
+ SUIT_MessageBox::critical( app->desktop(),
+ QObject::tr("GEOM_ERROR"),
+ QObject::tr("GEOM_PRP_ABORT") + "\n" + QObject::tr( anOper->GetErrorCode() ) );
+ }
+ }
+ catch( const SALOME::SALOME_Exception& S_ex ) {
+ anOp->abort();
+ }
+ }
+ return true;
+}
+
+//=================================================================================
+// function : accept
+// purpose :
+//=================================================================================
+void ACISPlugin_ImportDlg::accept()
+{
+ SUIT_FileDlg::accept();
+ onAccept( false );
+}
+
+//=================================================================================
+// function : getObjectName
+// purpose :
+//=================================================================================
+QString ACISPlugin_ImportDlg::getObjectName( GEOM::GEOM_Object_ptr object ) const
+{
+ if( object->_is_nil() )
+ return QString::null;
+ return object->GetName();
+}