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_ExportDlg.h"
22 #include "DXFPlugin_Operations_i.hh"
25 #include <SUIT_Session.h>
26 #include <SUIT_Desktop.h>
27 #include <SUIT_Tools.h>
28 #include <SUIT_MessageBox.h>
29 #include <SUIT_OverrideCursor.h>
31 #include <SalomeApp_Application.h>
35 #include <GEOM_Operation.h>
36 #include <GEOM_Constants.h>
38 //=================================================================================
40 //=================================================================================
41 DXFPlugin_ExportDlg::DXFPlugin_ExportDlg( Handle(SALOME_InteractiveObject)& object, QWidget* parent )
42 : SUIT_FileDlg( parent, false, true, true ),
43 GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) )
45 setWindowTitle( tr( "DXFPLUGIN_EXPORT_TITLE" ) );
46 setNameFilter( tr( "DXFPLUGIN_DXF_FILES" ) );
49 const char* objectName = myObject->getName();
50 selectFile( QString( objectName ) );
53 //=================================================================================
55 //=================================================================================
56 DXFPlugin_ExportDlg::~DXFPlugin_ExportDlg()
58 // no need to delete child widgets, Qt does it all for us
61 //=================================================================================
62 // function : createOperation
64 //=================================================================================
65 GEOM::GEOM_IOperations_ptr DXFPlugin_ExportDlg::createOperation()
67 return getGeomEngine()->GetPluginOperations( getStudyId(), "DXFPluginEngine" );
70 //=================================================================================
73 //=================================================================================
74 bool DXFPlugin_ExportDlg::isValid( QString& msg )
77 //@@ add custom validation actions here @@//
81 //=================================================================================
84 //=================================================================================
85 bool DXFPlugin_ExportDlg::execute( ObjectList& objects )
87 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
88 if (!app) return false;
90 DXFPlugin::GEOM_IDXFPluginOperations_var aDXFOp = DXFPlugin::GEOM_IDXFPluginOperations::_narrow( getOperation() );
91 if ( aDXFOp->_is_nil() ) return false;
93 GEOM::GEOM_Object_var anObj = GEOMBase::ConvertIOinGEOMObject( myObject );
94 if ( anObj->_is_nil() ) return false;
96 QString aFile = selectedFile();
98 // User has pressed "Cancel" --> stop the operation
99 if ( aFile.isEmpty() )
102 GEOM_Operation* anOp = new GEOM_Operation( app, aDXFOp.in() );
104 SUIT_OverrideCursor wc;
105 app->putInfo( tr("GEOM_PRP_EXPORT").arg(SUIT_Tools::file( aFile, /*withExten=*/true )) );
107 aDXFOp->ExportDXF( anObj, aFile.toUtf8().constData() );
108 if( aDXFOp->IsDone() )
113 SUIT_MessageBox::critical( app->desktop(),
114 QObject::tr("GEOM_ERROR"),
115 QObject::tr("GEOM_PRP_ABORT") + "\n" + QObject::tr( aDXFOp->GetErrorCode() ) );
119 catch( const SALOME::SALOME_Exception& S_ex ) {
124 objects.push_back( anObj._retn() );
128 void DXFPlugin_ExportDlg::accept()
130 SUIT_FileDlg::accept();