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 "ACISPlugin_ImportDlg.h"
22 #include "ACISPlugin_Operations_i.hh"
25 #include <SUIT_Session.h>
26 #include <SUIT_MessageBox.h>
27 #include <SUIT_Desktop.h>
28 #include <SUIT_Tools.h>
29 #include <SalomeApp_Application.h>
30 #include <SalomeApp_Study.h>
33 #include <GeometryGUI.h>
35 #include <GEOM_Operation.h>
37 //=================================================================================
39 //=================================================================================
40 ACISPlugin_ImportDlg::ACISPlugin_ImportDlg( QWidget* parent )
41 : SUIT_FileDlg( parent, true, true, true ),
42 GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) )
44 setWindowTitle( tr( "ACISPLUGIN_IMPORT_TITLE" ) );
45 setAcceptMode( AcceptOpen );
46 setNameFilter( tr( "ACISPLUGIN_ACIS_FILES" ) );
47 setFileMode( QFileDialog::ExistingFiles );
50 //=================================================================================
52 //=================================================================================
53 ACISPlugin_ImportDlg::~ACISPlugin_ImportDlg()
55 // no need to delete child widgets, Qt does it all for us
58 //=================================================================================
59 // function : createOperation
61 //=================================================================================
62 GEOM::GEOM_IOperations_ptr ACISPlugin_ImportDlg::createOperation()
64 return getGeomEngine()->GetPluginOperations(getStudyId(), "ACISPluginEngine");
67 //=================================================================================
70 //=================================================================================
71 bool ACISPlugin_ImportDlg::isValid (QString& msg)
74 //@@ add custom validation actions here @@//
78 //=================================================================================
81 //=================================================================================
82 bool ACISPlugin_ImportDlg::execute( ObjectList& objects )
85 GEOM::GEOM_Object_var anObj;
86 ACISPlugin::GEOM_IACISPluginOperations_var anOper = ACISPlugin::GEOM_IACISPluginOperations::_narrow( getOperation() );
88 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
89 _PTR(Study) aStudy = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() )->studyDS();
90 SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy );
92 QStringList fileNames = selectedFiles();
93 if ( fileNames.count() == 0 )
94 return false; // nothing selected, return
96 SUIT_MessageBox::StandardButton acisAnswer = SUIT_MessageBox::NoButton;
98 for( int i = 0; i < fileNames.size(); i++ ) {
99 QString aFileName = fileNames.at( i );
100 if ( aFileName.isEmpty() )
102 GEOM_Operation* anOp = new GEOM_Operation( app, anOper.in() );
104 app->putInfo( tr( "GEOM_PRP_LOADING" ).arg( SUIT_Tools::file( aFileName.toUtf8().constData(), /*withExten=*/true ) ) );
107 if ( acisAnswer != SUIT_MessageBox::YesToAll && acisAnswer != SUIT_MessageBox::NoToAll ) {
108 SUIT_MessageBox::StandardButtons btns = SUIT_MessageBox::Yes | SUIT_MessageBox::No;
109 if ( i < fileNames.count()-1 ) btns = btns | SUIT_MessageBox::YesToAll | SUIT_MessageBox::NoToAll;
110 acisAnswer = SUIT_MessageBox::question( app->desktop(),
111 "Question",//tr("WRN_WARNING"),
112 tr("GEOM_PUBLISH_NAMED_SHAPES"),
113 btns | SUIT_MessageBox::Cancel,
114 SUIT_MessageBox::No );
115 if ( acisAnswer == SUIT_MessageBox::Cancel ) {
116 anOper->SetErrorCode(OK);
117 return true; // cancel (break) import operation
121 GEOM::ListOfGO_var anObj = anOper->ImportACIS( aFileName.toUtf8().constData() );
123 if ( anObj->length() > 0 && anOper->IsDone() ) {
124 GEOM::GEOM_Object_ptr anObjPtr = anObj[0]._retn();
125 objects.push_back( anObjPtr );
126 QString aPublishObjName =
127 GEOMBase::GetDefaultName( SUIT_Tools::file( aFileName, /*withExten=*/true ) );
128 anObjPtr->SetName( aPublishObjName.toStdString().c_str() );
130 SALOMEDS::SObject_var aSO =
131 GeometryGUI::GetGeomGen()->PublishInStudy( aDSStudy,
132 SALOMEDS::SObject::_nil(),
134 aPublishObjName.toLatin1().constData() );
135 if ( acisAnswer == SUIT_MessageBox::Yes || acisAnswer == SUIT_MessageBox::YesToAll )
136 GeometryGUI::GetGeomGen()->PublishNamedShapesInStudy( aDSStudy, anObjPtr );
142 SUIT_MessageBox::critical( app->desktop(),
143 QObject::tr("GEOM_ERROR"),
144 QObject::tr("GEOM_PRP_ABORT") + "\n" + QObject::tr( anOper->GetErrorCode() ) );
147 catch( const SALOME::SALOME_Exception& S_ex ) {
154 //=================================================================================
157 //=================================================================================
158 void ACISPlugin_ImportDlg::accept()
160 SUIT_FileDlg::accept();
164 //=================================================================================
165 // function : getObjectName
167 //=================================================================================
168 QString ACISPlugin_ImportDlg::getObjectName( GEOM::GEOM_Object_ptr object ) const
170 if( object->_is_nil() )
171 return QString::null;
172 return object->GetName();