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 "DXFPlugin_ImportDlg.h"
22 #include "DXFPlugin_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>
33 #include <GEOM_Operation.h>
35 //=================================================================================
37 //=================================================================================
38 DXFPlugin_ImportDlg::DXFPlugin_ImportDlg( QWidget* parent )
39 : SUIT_FileDlg( parent, true, true, true ),
40 GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) )
42 setWindowTitle( tr( "DXFPLUGIN_IMPORT_TITLE" ) );
43 setAcceptMode( AcceptOpen );
44 setNameFilter( tr( "DXFPLUGIN_DXF_FILES" ) );
45 setFileMode( QFileDialog::ExistingFiles );
48 //=================================================================================
50 //=================================================================================
51 DXFPlugin_ImportDlg::~DXFPlugin_ImportDlg()
53 // no need to delete child widgets, Qt does it all for us
56 //=================================================================================
57 // function : createOperation
59 //=================================================================================
60 GEOM::GEOM_IOperations_ptr DXFPlugin_ImportDlg::createOperation()
62 return getGeomEngine()->GetPluginOperations(getStudyId(), "DXFPluginEngine");
65 //=================================================================================
68 //=================================================================================
69 bool DXFPlugin_ImportDlg::isValid (QString& msg)
72 //@@ add custom validation actions here @@//
76 //=================================================================================
79 //=================================================================================
80 bool DXFPlugin_ImportDlg::execute( ObjectList& objects )
83 GEOM::GEOM_Object_var anObj;
84 DXFPlugin::GEOM_IDXFPluginOperations_var anOper = DXFPlugin::GEOM_IDXFPluginOperations::_narrow( getOperation() );
86 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
88 QStringList fileNames = selectedFiles();
89 if ( fileNames.count() == 0 )
90 return false; // nothing selected, return
92 for( int i = 0; i < fileNames.size(); i++ ) {
93 QString aFileName = fileNames.at( i );
94 if ( aFileName.isEmpty() )
96 GEOM_Operation* anOp = new GEOM_Operation( app, anOper.in() );
98 app->putInfo( tr( "GEOM_PRP_LOADING" ).arg( SUIT_Tools::file( aFileName.toUtf8().constData(), /*withExten=*/true ) ) );
100 GEOM::ListOfGO_var anObj = anOper->ImportDXF( aFileName.toUtf8().constData() );
101 if( anObj->length() > 0 && anOper->IsDone() ) {
102 GEOM::GEOM_Object_ptr anObjPtr = anObj[0]._retn();
103 objects.push_back( anObjPtr );
104 QString aPublishObjName = GEOMBase::GetDefaultName( SUIT_Tools::file( fileNames.at( i ),
105 /*withExten=*/true ) );
106 anObjPtr->SetName( aPublishObjName.toStdString().c_str() );
111 SUIT_MessageBox::critical( app->desktop(),
112 QObject::tr("GEOM_ERROR"),
113 QObject::tr("GEOM_PRP_ABORT") + "\n" + QObject::tr( anOper->GetErrorCode() ) );
116 catch( const SALOME::SALOME_Exception& S_ex ) {
123 //=================================================================================
126 //=================================================================================
127 void DXFPlugin_ImportDlg::accept()
129 SUIT_FileDlg::accept();
133 //=================================================================================
134 // function : getObjectName
136 //=================================================================================
137 QString DXFPlugin_ImportDlg::getObjectName( GEOM::GEOM_Object_ptr object ) const
139 if( object->_is_nil() )
140 return QString::null;
141 return object->GetName();