1 // Copyright (C) 2007-2012 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_AddAtomDlg.h"
28 #include <LightApp_Application.h>
29 #include <LightApp_DataOwner.h>
30 #include <LightApp_SelectionMgr.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_Desktop.h>
40 ATOMICGUI::ATOMICGUI()
41 : LightApp_Module( "ATOMICGUI" )
45 /*! Initialization funciton. Called only once on first activation of GUI module. */
46 void ATOMICGUI::initialize ( CAM_Application* app )
48 LightApp_Module::initialize( app );// call parent's implementation
50 SUIT_Desktop* parent = application()->desktop();
51 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
54 createAction( agCreateMol, tr("TOP_CREATE_MOL"), resMgr->loadPixmap("ATOMIC", tr("ICON_MOLECULE")),
55 tr("MEN_CREATE_MOL"), tr("STB_CREATE_MOL"), 0, parent, false, this, SLOT(onOperation()) );
56 createAction( agAddAtom, tr("TOP_ADD_ATOM"), resMgr->loadPixmap("ATOMIC", tr("ICON_ATOM")),
57 tr("MEN_ADD_ATOM"), tr("STB_ADD_ATOM"), 0, parent, false, this, SLOT(onOperation()) );
60 int aAtomicMnu = createMenu( tr( "MEN_ATOMIC" ), -1, -1, 50 );
61 createMenu( agCreateMol, aAtomicMnu, 10 );
62 createMenu( separator(), aAtomicMnu, -1, 10 );
63 createMenu( agAddAtom, aAtomicMnu, 10 );
66 int tbId = createTool( tr( "MEN_ATOMIC" ) );
67 createTool( agCreateMol, tbId );
68 createTool( agAddAtom, tbId );
71 /*! Returns default icon of a component. */
72 QString ATOMICGUI::iconName() const
74 return QObject::tr( "ICON_ATOMIC" );
77 /*! Returns list of windows required for this GUI module. */
78 void ATOMICGUI::windows ( QMap<int, int>& aMap ) const
80 aMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
83 /*! Returns list of entities of selected objects. */
84 void ATOMICGUI::selected( QStringList& entries, const bool multiple )
86 LightApp_SelectionMgr* mgr = getApp()->selectionMgr();
90 SUIT_DataOwnerPtrList anOwnersList;
91 mgr->selected( anOwnersList );
93 for ( int i = 0; i < anOwnersList.size(); i++ )
95 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( anOwnersList[ i ].get() );
96 QStringList es = owner->entry().split( "_" );
97 if ( es.count() > 1 && es[ 0 ] == "ATOMICGUI" && es[ 1 ] != "root" )
99 entries.append( owner->entry() );
106 /*! Instantiation of a custom Data Model. */
107 CAM_DataModel* ATOMICGUI::createDataModel()
109 return new ATOMICGUI_DataModel( this );
112 /*! Activation function. Called on every activation of a GUI module. */
113 bool ATOMICGUI::activateModule ( SUIT_Study* study )
115 bool isDone = LightApp_Module::activateModule( study );
116 if ( !isDone ) return false;
118 setMenuShown( true );
119 setToolShown( true );
124 /*! Deactivation function. Called on every deactivation of a GUI module. */
125 bool ATOMICGUI::deactivateModule ( SUIT_Study* study )
127 setMenuShown( false );
128 setToolShown( false );
130 return LightApp_Module::deactivateModule( study );
133 /*! slot connected to all functions of the component (create molecule, add atom, etc.) */
134 void ATOMICGUI::onOperation()
136 if( sender() && sender()->inherits( "QAction" ) )
138 int id = actionId( ( QAction* )sender() );
139 if ( id == agCreateMol ) {
140 ATOMICGUI_DataModel* dm = dynamic_cast<ATOMICGUI_DataModel*>( dataModel() );
142 dm->createMolecule();
143 getApp()->updateObjectBrowser();
146 else if ( id == agAddAtom ) {
148 selected( entries, false );
149 ATOMICGUI_AddAtomDlg dlg ( getApp()->desktop() );
150 int res = dlg.exec();
151 ATOMICGUI_DataModel* dm = dynamic_cast<ATOMICGUI_DataModel*>( dataModel() );
152 if( dm && res == QDialog::Accepted && dlg.acceptData( entries ) ) {
155 dlg.data( name, x, y, z );
156 dm->addAtom( entries.first(), name, x, y, z );
157 getApp()->updateObjectBrowser();
163 /*! Called on popup menu request by LightApp_Application. */
164 void ATOMICGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& /*title*/ )
166 if ( client == "ObjectBrowser" ) {
168 selected( entries, false );
169 if ( entries.size() ) {
170 QStringList es = entries.first().split( "_" );
171 if ( es.count() == 2 && es[ 0 ] == "ATOMICGUI" ) { // selected object belongs to ATOMICGUI
172 // and it is a molecule object
173 menu->addAction(action( agAddAtom ));
181 #define ATOMICGUI_EXPORT __declspec(dllexport)
183 #define ATOMICGUI_EXPORT
186 /*! GUI module instantiation function */
188 ATOMICGUI_EXPORT CAM_Module* createModule() {
189 return new ATOMICGUI();