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_AddAtomDlg.h"
30 #include <LightApp_Application.h>
31 #include <LightApp_DataOwner.h>
32 #include <LightApp_SelectionMgr.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_Desktop.h>
42 ATOMICGUI::ATOMICGUI()
43 : LightApp_Module( "ATOMICGUI" )
47 /*! Initialization funciton. Called only once on first activation of GUI module. */
48 void ATOMICGUI::initialize ( CAM_Application* app )
50 LightApp_Module::initialize( app );// call parent's implementation
52 SUIT_Desktop* parent = application()->desktop();
53 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
56 createAction( agCreateMol, tr("TOP_CREATE_MOL"), resMgr->loadPixmap("ATOMIC", tr("ICON_MOLECULE")),
57 tr("MEN_CREATE_MOL"), tr("STB_CREATE_MOL"), 0, parent, false, this, SLOT(onOperation()) );
58 createAction( agAddAtom, tr("TOP_ADD_ATOM"), resMgr->loadPixmap("ATOMIC", tr("ICON_ATOM")),
59 tr("MEN_ADD_ATOM"), tr("STB_ADD_ATOM"), 0, parent, false, this, SLOT(onOperation()) );
62 int aAtomicMnu = createMenu( tr( "MEN_ATOMIC" ), -1, -1, 50 );
63 createMenu( agCreateMol, aAtomicMnu, 10 );
64 createMenu( separator(), aAtomicMnu, -1, 10 );
65 createMenu( agAddAtom, aAtomicMnu, 10 );
68 int tbId = createTool( tr( "MEN_ATOMIC" ) );
69 createTool( agCreateMol, tbId );
70 createTool( agAddAtom, tbId );
73 /*! Returns default icon of a component. */
74 QString ATOMICGUI::iconName() const
76 return QObject::tr( "ICON_ATOMIC" );
79 /*! Returns list of windows required for this GUI module. */
80 void ATOMICGUI::windows ( QMap<int, int>& aMap ) const
82 aMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
85 /*! Returns list of entities of selected objects. */
86 void ATOMICGUI::selected( QStringList& entries, const bool multiple )
88 LightApp_SelectionMgr* mgr = getApp()->selectionMgr();
92 SUIT_DataOwnerPtrList anOwnersList;
93 mgr->selected( anOwnersList );
95 for ( int i = 0; i < anOwnersList.size(); i++ )
97 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( anOwnersList[ i ].get() );
98 QStringList es = owner->entry().split( "_" );
99 if ( es.count() > 1 && es[ 0 ] == "ATOMICGUI" && es[ 1 ] != "root" )
101 entries.append( owner->entry() );
108 /*! Instantiation of a custom Data Model. */
109 CAM_DataModel* ATOMICGUI::createDataModel()
111 return new ATOMICGUI_DataModel( this );
114 /*! Activation function. Called on every activation of a GUI module. */
115 bool ATOMICGUI::activateModule ( SUIT_Study* study )
117 bool isDone = LightApp_Module::activateModule( study );
118 if ( !isDone ) return false;
120 setMenuShown( true );
121 setToolShown( true );
126 /*! Deactivation function. Called on every deactivation of a GUI module. */
127 bool ATOMICGUI::deactivateModule ( SUIT_Study* study )
129 setMenuShown( false );
130 setToolShown( false );
132 return LightApp_Module::deactivateModule( study );
135 /*! slot connected to all functions of the component (create molecule, add atom, etc.) */
136 void ATOMICGUI::onOperation()
138 if( sender() && sender()->inherits( "QAction" ) )
140 int id = actionId( ( QAction* )sender() );
141 if ( id == agCreateMol ) {
142 ATOMICGUI_DataModel* dm = dynamic_cast<ATOMICGUI_DataModel*>( dataModel() );
144 dm->createMolecule();
145 getApp()->updateObjectBrowser();
148 else if ( id == agAddAtom ) {
150 selected( entries, false );
151 ATOMICGUI_AddAtomDlg dlg ( getApp()->desktop() );
152 int res = dlg.exec();
153 ATOMICGUI_DataModel* dm = dynamic_cast<ATOMICGUI_DataModel*>( dataModel() );
154 if( dm && res == QDialog::Accepted && dlg.acceptData( entries ) ) {
157 dlg.data( name, x, y, z );
158 dm->addAtom( entries.first(), name, x, y, z );
159 getApp()->updateObjectBrowser();
165 /*! Called on popup menu request by LightApp_Application. */
166 void ATOMICGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& /*title*/ )
168 if ( client == "ObjectBrowser" ) {
170 selected( entries, false );
171 if ( entries.size() ) {
172 QStringList es = entries.first().split( "_" );
173 if ( es.count() == 2 && es[ 0 ] == "ATOMICGUI" ) { // selected object belongs to ATOMICGUI
174 // and it is a molecule object
175 menu->addAction(action( agAddAtom ));
183 #define ATOMICGUI_EXPORT __declspec(dllexport)
185 #define ATOMICGUI_EXPORT
188 /*! GUI module instantiation function */
190 ATOMICGUI_EXPORT CAM_Module* createModule() {
191 return new ATOMICGUI();