1 // Copyright (C) 2007-2013 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.
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
22 #include "ATOMICGUI.h"
24 #include "ATOMICGUI_DataModel.h"
25 #include "ATOMICGUI_DataObject.h"
26 #include "ATOMICGUI_Selection.h"
27 #include "ATOMICGUI_CreateMolOp.h"
28 #include "ATOMICGUI_AddAtomOp.h"
29 #include "ATOMICGUI_ImportExportOp.h"
30 #include "ATOMICGUI_RenameOp.h"
31 #include "ATOMICGUI_DeleteOp.h"
33 #include <ATOMIC_version.h>
35 #include <LightApp_Application.h>
36 #include <LightApp_DataOwner.h>
37 #include <LightApp_SelectionMgr.h>
39 #include <SUIT_ResourceMgr.h>
40 #include <SUIT_Session.h>
41 #include <SUIT_Desktop.h>
46 ATOMICGUI::ATOMICGUI()
47 : LightApp_Module( "ATOMICGUI" )
51 /*! Initialization funciton. Called only once on first activation of GUI module. */
52 void ATOMICGUI::initialize ( CAM_Application* app )
54 LightApp_Module::initialize( app );// call parent's implementation
56 SUIT_Desktop* parent = application()->desktop();
57 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
60 createAction( agCreateMol, tr( "TOP_CREATE_MOL" ), resMgr->loadPixmap( "ATOMIC", tr( "ICON_MOLECULE" ) ),
61 tr( "MEN_CREATE_MOL" ), tr( "STB_CREATE_MOL" ), 0, parent, false, this, SLOT( onOperation() ) );
62 createAction( agAddAtom, tr( "TOP_ADD_ATOM" ), resMgr->loadPixmap( "ATOMIC", tr( "ICON_ATOM" ) ),
63 tr( "MEN_ADD_ATOM" ), tr( "STB_ADD_ATOM" ), 0, parent, false, this, SLOT( onOperation() ) );
64 createAction( agRename, tr( "TOP_RENAME" ), resMgr->loadPixmap( "ATOMIC", tr( "ICON_RENAME" ) ),
65 tr( "MEN_RENAME" ), tr( "STB_RENAME" ), 0, parent, false, this, SLOT( onOperation() ) );
66 createAction( agDelete, tr( "TOP_DELETE_OBJ" ), resMgr->loadPixmap( "ATOMIC", tr( "ICON_REMOVE" ) ),
67 tr( "MEN_DELETE_OBJ" ), tr( "STB_DELETE_OBJ" ), 0, parent, false, this, SLOT( onOperation() ) );
68 createAction( agImportXML, tr( "TOP_IMPORT_XML" ), QIcon(), tr( "MEN_IMPORT_XML" ),
69 tr( "STB_IMPORT_XML" ), 0, parent, false, this, SLOT( onOperation() ) );
70 createAction( agExportXML, tr( "TOP_EXPORT_XML" ), QIcon(), tr( "MEN_EXPORT_XML" ),
71 tr( "STB_EXPORT_XML" ), 0, parent, false, this, SLOT( onOperation() ) );
74 int aFileMnu = createMenu( tr( "MEN_FILE" ), -1, -1 );
75 createMenu( separator(), aFileMnu, -1, 10 );
76 createMenu( agImportXML, aFileMnu, 10 );
77 createMenu( agExportXML, aFileMnu, 10 );
78 createMenu( separator(), aFileMnu, -1, 10 );
80 int aEditMnu = createMenu( tr( "MEN_EDIT" ), -1, -1 );
81 createMenu( separator(), aEditMnu, -1, 10 );
82 createMenu( agRename, aEditMnu, 10 );
83 createMenu( agDelete, aEditMnu, 10 );
84 createMenu( separator(), aEditMnu, -1, 10 );
86 int aAtomicMnu = createMenu( tr( "MEN_ATOMIC" ), -1, -1, 50 );
87 createMenu( agCreateMol, aAtomicMnu, 10 );
88 createMenu( separator(), aAtomicMnu, -1, 10 );
89 createMenu( agAddAtom, aAtomicMnu, 10 );
92 int tbId = createTool( tr( "MEN_ATOMIC" ) );
93 createTool( agCreateMol, tbId );
94 createTool( agAddAtom, tbId );
95 createTool( separator(), tbId );
96 createTool( agRename, tbId );
97 createTool( separator(), tbId );
98 createTool( agDelete, tbId );
100 // popup for object browser
102 popupMgr()->insert ( separator(), parentId, 0 );
103 popupMgr()->insert ( action( agCreateMol ), parentId, 0 );
104 popupMgr()->insert ( action( agAddAtom ), parentId, 0 );
105 popupMgr()->insert ( separator(), parentId, 0 );
106 popupMgr()->insert ( action( agRename ), parentId, 0 );
107 popupMgr()->insert ( action( agDelete ), parentId, 0 );
108 popupMgr()->insert ( separator(), parentId, 0 );
110 QString rule = "client='ObjectBrowser' and selcount=1 and type='Molecule'";
111 popupMgr()->setRule( action( agAddAtom ), rule );
113 rule = "client='ObjectBrowser' and selcount=1 and type='Root'";
114 popupMgr()->setRule( action( agCreateMol ),rule );
116 rule = "($type in {'Molecule' 'Atom'}) and client='ObjectBrowser' and selcount=1";
117 popupMgr()->setRule( action( agRename ), rule );
119 rule = "($type in {'Molecule' 'Atom'}) and client='ObjectBrowser' and selcount>0";
120 popupMgr()->setRule( action( agDelete ), rule );
123 /*! Returns default icon of a component. */
124 QString ATOMICGUI::iconName() const
126 return QObject::tr( "ICON_ATOMIC" );
129 /*! Returns list of windows required for this GUI module. */
130 void ATOMICGUI::windows ( QMap<int, int>& aMap ) const
132 aMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
133 aMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea);
136 /*! Returns list of entities of selected objects. */
137 void ATOMICGUI::selected( QStringList& entries, const bool multiple )
139 LightApp_SelectionMgr* mgr = getApp()->selectionMgr();
143 SUIT_DataOwnerPtrList anOwnersList;
144 mgr->selected( anOwnersList );
146 for ( int i = 0; i < anOwnersList.size(); i++ )
148 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( anOwnersList[ i ].get() );
149 QStringList es = owner->entry().split( "_" );
150 if ( es.count() > 1 && es[ 0 ] == "ATOMICGUI" && es[ 1 ] != "root" )
152 entries.append( owner->entry() );
159 /*! Instantiation of a custom Data Model. */
160 CAM_DataModel* ATOMICGUI::createDataModel()
162 return new ATOMICGUI_DataModel( this );
165 /*! Instantiation of a custom Selection object - manager of parameters for popup construction. */
166 LightApp_Selection* ATOMICGUI::createSelection() const
168 return new ATOMICGUI_Selection();
171 /*! Activation function. Called on every activation of a GUI module. */
172 bool ATOMICGUI::activateModule ( SUIT_Study* study )
174 bool isDone = LightApp_Module::activateModule( study );
175 if ( !isDone ) return false;
177 setMenuShown( true );
178 setToolShown( true );
183 /*! Deactivation function. Called on every deactivation of a GUI module. */
184 bool ATOMICGUI::deactivateModule ( SUIT_Study* study )
186 setMenuShown( false );
187 setToolShown( false );
189 return LightApp_Module::deactivateModule( study );
192 /*! slot connected to all functions of the component (create molecule, add atom, etc.) */
193 void ATOMICGUI::onOperation()
195 if( sender() && sender()->inherits( "QAction" ) )
197 int id = actionId( ( QAction* )sender() );
198 startOperation( id );
202 /*! Instantiation of a custom Operation object - component's action manager. */
203 LightApp_Operation* ATOMICGUI::createOperation( const int id ) const
208 return new ATOMICGUI_ImportExportOp( true );
211 return new ATOMICGUI_ImportExportOp( false );
214 return new ATOMICGUI_CreateMolOp();
217 return new ATOMICGUI_AddAtomOp();
220 return new ATOMICGUI_RenameOp();
223 return new ATOMICGUI_DeleteOp();
231 #define ATOMICGUI_EXPORT __declspec(dllexport)
233 #define ATOMICGUI_EXPORT
236 /*! GUI module instantiation function */
238 ATOMICGUI_EXPORT CAM_Module* createModule() {
239 return new ATOMICGUI();
242 ATOMICGUI_EXPORT char* getModuleVersion() {
243 return (char*)ATOMIC_VERSION_STR;