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 "XTPlugin_GUI.h"
22 #include "XTPlugin_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(XTPlugin)
44 //=======================================================================
45 // function : XTPlugin_GUI()
46 // purpose : Constructor
47 //=======================================================================
48 XTPlugin_GUI::XTPlugin_GUI( GeometryGUI* parent ) : GEOMPluginGUI( parent )
52 //=======================================================================
53 // function : ~XTPlugin_GUI
54 // purpose : Destructor
55 //=======================================================================
56 XTPlugin_GUI::~XTPlugin_GUI()
60 //=======================================================================
61 // function : OnGUIEvent()
63 //=======================================================================
64 bool XTPlugin_GUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
67 switch ( theCommandID ) {
73 return OnGUIEvent( cmd, parent );
76 //=======================================================================
77 // function : OnGUIEvent()
79 //=======================================================================
80 bool XTPlugin_GUI::OnGUIEvent( const QString& theCommandID, SUIT_Desktop* parent )
84 if ( theCommandID == "Import_XT" )
86 result = importXT( parent );
90 getGeometryGUI()->getApp()->putInfo( tr("GEOM_PRP_COMMAND").arg( theCommandID ) );
97 //=======================================================================
98 // function : importXT
100 //=======================================================================
101 bool XTPlugin_GUI::importXT( SUIT_Desktop* parent )
103 SalomeApp_Application* app = getGeometryGUI()->getApp();
104 if ( !app ) return false;
105 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() );
106 if ( !study ) return false;
108 SALOMEDS::Study_var dsStudy = GeometryGUI::ClientStudyToStudy( study->studyDS() );
109 GEOM::GEOM_IOperations_var op = GeometryGUI::GetGeomGen()->GetPluginOperations( dsStudy->StudyId(), "XTPluginEngine" );
110 XTPlugin::IXTOperations_var xtOp = XTPlugin::IXTOperations::_narrow( op );
111 if ( CORBA::is_nil( xtOp ) ) return false;
113 QStringList fileNames = app->getOpenFileNames( SUIT_FileDlg::getLastVisitedPath().isEmpty() ? QDir::currentPath() : QString(""),
115 tr( "IMPORT_TITLE" ),
117 if ( fileNames.count() > 0 )
119 QStringList entryList;
122 foreach( QString fileName, fileNames )
124 SUIT_OverrideCursor wc;
125 GEOM_Operation transaction( app, xtOp.in() );
129 app->putInfo( tr( "GEOM_PRP_LOADING" ).arg( fileName ) );
131 GEOM::ListOfGO_var result = xtOp->ImportXT( fileName.toUtf8().constData() );
132 if ( result->length() > 0 && xtOp->IsDone() )
134 GEOM::GEOM_Object_var main = result[0];
135 QString publishName = GEOMBase::GetDefaultName( SUIT_Tools::file( fileName, true ) );
136 SALOMEDS::SObject_var so = GeometryGUI::GetGeomGen()->PublishInStudy( dsStudy,
137 SALOMEDS::SObject::_nil(),
139 publishName.toUtf8().constData() );
141 entryList.append( so->GetID() );
142 transaction.commit();
143 GEOM_Displayer( study ).Display( main.in() );
148 errors.append( QString( "%1 : %2" ).arg( fileName ).arg( xtOp->GetErrorCode() ) );
151 catch( const SALOME::SALOME_Exception& e )
156 getGeometryGUI()->updateObjBrowser( true );
157 app->browseObjects( entryList );
159 if ( errors.count() > 0 )
161 SUIT_MessageBox::critical( parent,
163 tr( "GEOM_IMPORT_ERRORS" ) + "\n" + errors.join( "\n" ) );
166 return fileNames.count() > 0;
169 //=====================================================================================
171 //=====================================================================================
175 __declspec( dllexport )
177 GEOMGUI* GetLibGUI( GeometryGUI* parent )
179 return new XTPlugin_GUI( parent );