Salome HOME
Implementation of ACISPLUGIN as a GEOM plugin (added files)
[plugins/acisplugin.git] / src / ACISPluginGUI.cxx
1 // Copyright (C) 2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // internal includes
21 #include "ACISPluginGUI.h"
22 #include "ACISPlugin_ExportDlg.h"
23 #include "ACISPlugin_ImportDlg.h"
24
25 // GUI includes
26 #include <SUIT_Desktop.h>
27 #include <SUIT_MessageBox.h>
28 #include <SalomeApp_Application.h>
29 #include <SALOME_ListIteratorOfListIO.hxx>
30 #include <LightApp_SelectionMgr.h>
31
32 // GEOM includes
33 #include <GeometryGUI.h>
34
35 //=======================================================================
36 // function : ACISPluginGUI()
37 // purpose  : Constructor
38 //=======================================================================
39 ACISPluginGUI::ACISPluginGUI( GeometryGUI* parent ) : GEOMPluginGUI( parent )
40 {
41 }
42
43 //=======================================================================
44 // function : ~ACISPluginGUI
45 // purpose  : Destructor
46 //=======================================================================
47 ACISPluginGUI::~ACISPluginGUI()
48 {
49 }
50
51 //=======================================================================
52 // function : OnGUIEvent()
53 // purpose  : 
54 //=======================================================================
55 bool ACISPluginGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
56 {
57   switch ( theCommandID ) {
58   case 1:
59     return OnGUIEvent("Export_ACIS", parent);
60   case 2:
61     return OnGUIEvent("Import_ACIS", parent);
62   default:
63     return OnGUIEvent("", parent);
64   }
65   return false;
66 }
67
68 //=======================================================================
69 // function : OnGUIEvent()
70 // purpose  :
71 //=======================================================================
72 bool ACISPluginGUI::OnGUIEvent( const QString& theCommandID, SUIT_Desktop* parent )
73 {
74   SalomeApp_Application* app = getGeometryGUI()->getApp();
75   if (!app) return false;
76
77   getGeometryGUI()->EmitSignalDeactivateDialog();
78
79   SUIT_FileDlg* dialog = NULL;
80   if( theCommandID == "Export_ACIS" ) {
81     // Get selected objects
82     LightApp_SelectionMgr* sm = app->selectionMgr();
83     if( !sm ) return false;
84     SALOME_ListIO selectedObjects;
85     sm->selectedObjects( selectedObjects );
86     if( selectedObjects.Extent() == 0 ) {
87       SUIT_MessageBox::warning( app->desktop(),
88                                 QObject::tr("WRN_WARNING"),
89                                 QObject::tr("GEOM_WRN_NO_APPROPRIATE_SELECTION") );
90     }
91     else {
92       SALOME_ListIteratorOfListIO It( selectedObjects );
93       for( ; It.More(); It.Next() ) {
94         Handle(SALOME_InteractiveObject) IObject = It.Value();
95         dialog = new ACISPlugin_ExportDlg( IObject, parent );
96         if( dialog->exec() == QDialog::Accepted )
97           delete dialog;
98       }
99     }
100   }
101   else if (theCommandID == "Import_ACIS") {
102     dialog = new ACISPlugin_ImportDlg( parent );
103     if (dialog != NULL)
104       dialog->show();
105     if( dialog->exec() == QDialog::Accepted )
106       delete dialog;
107   }
108   else {
109     app->putInfo( tr("GEOM_PRP_COMMAND").arg( theCommandID ) );
110   }
111
112   return true;
113 }
114
115 //=====================================================================================
116 // EXPORTED METHODS
117 //=====================================================================================
118 extern "C"
119 {
120 #ifdef WIN32
121     __declspec( dllexport )
122 #endif
123   GEOMGUI* GetLibGUI( GeometryGUI* parent )
124   {
125     return new ACISPluginGUI( parent );
126   }
127 }