1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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
20 #include "ATOMSOLVGUI_DataObject.h"
21 #include "ATOMSOLVGUI.h"
23 #include <LightApp_Study.h>
24 #include <LightApp_DataModel.h>
26 #include <SUIT_Session.h>
27 #include <SUIT_ResourceMgr.h>
29 #include <CAM_DataModel.h>
30 #include <CAM_Module.h>
33 ATOMSOLVGUI_DataObject::ATOMSOLVGUI_DataObject( SUIT_DataObject* parent, int mi, int ai )
34 : LightApp_DataObject( parent ),
35 CAM_DataObject( parent),
36 myMoleculeIndex( mi ),
42 ATOMSOLVGUI_DataObject::~ATOMSOLVGUI_DataObject()
46 /*! Returns unique object ID */
47 QString ATOMSOLVGUI_DataObject::entry() const
50 if ( myMoleculeIndex > -1 ) {
51 id = QString::number( myMoleculeIndex );
52 if ( myAtomIndex >= 0 )
53 id += QString( "_%1" ).arg( myAtomIndex );
56 return QString( "ATOMSOLVGUI_%1" ).arg( id );
59 /*! Returns a name of the Data Object. */
60 QString ATOMSOLVGUI_DataObject::name() const
62 ATOMSOLV_ORB::TMolecule tmolecule = getTMolecule();
63 ATOMGEN_ORB::Molecule_var mol = tmolecule.molecule;
64 if ( !CORBA::is_nil( mol ) ) {
66 return QString( "%1 [%2]" ).arg( mol->getName() ).arg( tmolecule.temperature );
67 else if ( myAtomIndex < mol->getNbAtoms() )
68 return mol->getAtom( myAtomIndex )->getName();
70 return QString("-Error-");
73 /*! Returns an icon of the Data Object. */
74 QPixmap ATOMSOLVGUI_DataObject::icon(const int) const
76 static QPixmap pxmole = SUIT_Session::session()->resourceMgr()->loadPixmap( "ATOMSOLV", QObject::tr( "ICON_MOLECULE" ), false );
77 static QPixmap pxatom = SUIT_Session::session()->resourceMgr()->loadPixmap( "ATOMSOLV", QObject::tr( "ICON_ATOM" ), false );
78 return isAtom() ? pxatom : pxmole;
81 /*! Returns a tooltip for the object (to be displayed in the Object Browser). */
82 QString ATOMSOLVGUI_DataObject::toolTip(const int) const
84 ATOMSOLV_ORB::TMolecule tmolecule = getTMolecule();
85 ATOMGEN_ORB::Molecule_var mol = tmolecule.molecule;
86 if ( !CORBA::is_nil( mol ) ) {
88 return QString( QObject::tr( "MOLECULE" ) + ": %1, temperature: %2" ).
89 arg( mol->getName() ).arg( tmolecule.temperature );
91 ATOMGEN_ORB::Atom_var atom = mol->getAtom( myAtomIndex );
92 if ( !CORBA::is_nil( atom ) )
93 return QString( QObject::tr( "ATOM" ) + ": %1: %2,%3,%4" ).
94 arg( atom->getName() ).arg( atom->getX() ).arg( atom->getY() ).arg( atom->getZ() );
100 ATOMSOLV_ORB::TMolecule ATOMSOLVGUI_DataObject::getTMolecule() const
102 ATOMSOLV_ORB::ATOMSOLV_Gen_var engine = ATOMSOLVGUI::GetATOMSOLVGen();
103 LightApp_RootObject* rootObj = dynamic_cast<LightApp_RootObject*> ( root() );
104 if ( rootObj && !CORBA::is_nil( engine ) ) {
105 ATOMSOLV_ORB::TMoleculeList_var molecules;
106 if ( engine->getData( molecules ) &&
107 myMoleculeIndex > -1 &&
108 myMoleculeIndex < molecules->length() )
109 return molecules[ myMoleculeIndex ];
111 return ATOMSOLV_ORB::TMolecule();
116 ATOMSOLVGUI_ModuleObject::ATOMSOLVGUI_ModuleObject( CAM_DataModel* dm, SUIT_DataObject* parent )
117 : ATOMSOLVGUI_DataObject( parent, -1 ),
118 LightApp_ModuleObject( dm, parent ),
119 CAM_DataObject( parent )
123 /*! Returns a name of the root object. */
124 QString ATOMSOLVGUI_ModuleObject::name() const
126 return CAM_ModuleObject::name();
129 /*! Returns an icon of the root object. */
130 QPixmap ATOMSOLVGUI_ModuleObject::icon(const int) const
134 QString anIconName = dataModel()->module()->iconName();
135 if ( !anIconName.isEmpty() )
136 px = SUIT_Session::session()->resourceMgr()->loadPixmap( "ATOMIC", anIconName, false );
141 /*! Returns a tooltip of the root object. */
142 QString ATOMSOLVGUI_ModuleObject::toolTip(const int) const
144 return QObject::tr( "ATOMIC_ROOT_TOOLTIP" );