1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 #include "ATOMICGUI.h"
26 #include "ATOMICGUI_DataModel.h"
27 #include "ATOMICGUI_DataObject.h"
28 #include "ATOMICGUI_Selection.h"
29 #include "ATOMICGUI_CreateMolOp.h"
30 #include "ATOMICGUI_AddAtomOp.h"
31 #include "ATOMICGUI_ImportExportOp.h"
32 #include "ATOMICGUI_RenameOp.h"
33 #include "ATOMICGUI_DeleteOp.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 );
135 /*! Returns list of entities of selected objects. */
136 void ATOMICGUI::selected( QStringList& entries, const bool multiple )
138 LightApp_SelectionMgr* mgr = getApp()->selectionMgr();
142 SUIT_DataOwnerPtrList anOwnersList;
143 mgr->selected( anOwnersList );
145 for ( int i = 0; i < anOwnersList.size(); i++ )
147 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( anOwnersList[ i ].get() );
148 QStringList es = owner->entry().split( "_" );
149 if ( es.count() > 1 && es[ 0 ] == "ATOMICGUI" && es[ 1 ] != "root" )
151 entries.append( owner->entry() );
158 /*! Instantiation of a custom Data Model. */
159 CAM_DataModel* ATOMICGUI::createDataModel()
161 return new ATOMICGUI_DataModel( this );
164 /*! Instantiation of a custom Selection object - manager of parameters for popup construction. */
165 LightApp_Selection* ATOMICGUI::createSelection() const
167 return new ATOMICGUI_Selection();
170 /*! Activation function. Called on every activation of a GUI module. */
171 bool ATOMICGUI::activateModule ( SUIT_Study* study )
173 bool isDone = LightApp_Module::activateModule( study );
174 if ( !isDone ) return false;
176 setMenuShown( true );
177 setToolShown( true );
182 /*! Deactivation function. Called on every deactivation of a GUI module. */
183 bool ATOMICGUI::deactivateModule ( SUIT_Study* study )
185 setMenuShown( false );
186 setToolShown( false );
188 return LightApp_Module::deactivateModule( study );
191 /*! slot connected to all functions of the component (create molecule, add atom, etc.) */
192 void ATOMICGUI::onOperation()
194 if( sender() && sender()->inherits( "QAction" ) )
196 int id = actionId( ( QAction* )sender() );
197 startOperation( id );
201 /*! Instantiation of a custom Operation object - component's action manager. */
202 LightApp_Operation* ATOMICGUI::createOperation( const int id ) const
207 return new ATOMICGUI_ImportExportOp( true );
210 return new ATOMICGUI_ImportExportOp( false );
213 return new ATOMICGUI_CreateMolOp();
216 return new ATOMICGUI_AddAtomOp();
219 return new ATOMICGUI_RenameOp();
222 return new ATOMICGUI_DeleteOp();
230 #define ATOMICGUI_EXPORT __declspec(dllexport)
232 #define ATOMICGUI_EXPORT
235 /*! GUI module instantiation function */
237 ATOMICGUI_EXPORT CAM_Module* createModule() {
238 return new ATOMICGUI();