Salome HOME
a0c53e315823f9390be6fa2f90e03605b577ac20
[samples/atomsolv.git] / src / ATOMSOLVGUI / ATOMSOLVGUI_DataObject.cxx
1 // Copyright (C) 2007-2020  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "ATOMSOLVGUI_DataObject.h"
21 #include "ATOMSOLVGUI.h"
22
23 #include <LightApp_Study.h>
24 #include <LightApp_DataModel.h>
25
26 #include <SUIT_Session.h>
27 #include <SUIT_ResourceMgr.h>
28
29 #include <CAM_DataModel.h>
30 #include <CAM_Module.h>
31
32 /*! Constructor */
33 ATOMSOLVGUI_DataObject::ATOMSOLVGUI_DataObject( SUIT_DataObject* parent, int mi, int ai )
34   : LightApp_DataObject( parent ),
35     CAM_DataObject( parent),
36     myMoleculeIndex( mi ),
37     myAtomIndex( ai )
38 {
39 }
40
41 /*! Destructor */
42 ATOMSOLVGUI_DataObject::~ATOMSOLVGUI_DataObject()
43 {
44 }
45
46 /*! Returns unique object ID */
47 QString ATOMSOLVGUI_DataObject::entry() const
48 {
49   QString id = "root";
50   if ( myMoleculeIndex > -1 ) {
51     id = QString::number( myMoleculeIndex );
52     if ( myAtomIndex >= 0 )
53         id += QString( "_%1" ).arg( myAtomIndex );
54   }
55
56   return QString( "ATOMSOLVGUI_%1" ).arg( id );
57 }
58
59 /*! Returns a name of the Data Object. */
60 QString ATOMSOLVGUI_DataObject::name() const
61 {
62   ATOMSOLV_ORB::TMolecule tmolecule = getTMolecule();
63   ATOMGEN_ORB::Molecule_var mol = tmolecule.molecule;
64   if ( !CORBA::is_nil( mol ) ) {
65     if ( !isAtom() )
66       return QString( "%1 [%2]" ).arg( mol->getName() ).arg( tmolecule.temperature );
67     else if ( myAtomIndex < mol->getNbAtoms() )
68       return mol->getAtom( myAtomIndex )->getName();    
69   }
70   return QString("-Error-");
71 }
72
73 /*! Returns an icon of the Data Object. */
74 QPixmap ATOMSOLVGUI_DataObject::icon(const int) const
75 {
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;
79 }
80
81 /*! Returns a tooltip for the object (to be displayed in the Object Browser). */
82 QString ATOMSOLVGUI_DataObject::toolTip(const int) const
83 {
84   ATOMSOLV_ORB::TMolecule tmolecule = getTMolecule();
85   ATOMGEN_ORB::Molecule_var mol = tmolecule.molecule;
86   if ( !CORBA::is_nil( mol ) ) {
87     if ( !isAtom() )
88       return QString( QObject::tr( "MOLECULE" ) + ": %1, temperature: %2" ).
89         arg( mol->getName() ).arg( tmolecule.temperature );
90     else {
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() );
95     }
96   }
97   return QString();
98 }
99
100 ATOMSOLV_ORB::TMolecule ATOMSOLVGUI_DataObject::getTMolecule() const
101 {
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 ];
110   }
111   return ATOMSOLV_ORB::TMolecule();
112 }
113
114
115 /*! Constructor */
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 )
120 {
121 }
122
123 /*! Returns a name of the root object. */
124 QString ATOMSOLVGUI_ModuleObject::name() const
125 {
126   return CAM_ModuleObject::name();
127 }
128
129 /*! Returns an icon of the root object. */
130 QPixmap ATOMSOLVGUI_ModuleObject::icon(const int) const
131 {
132   QPixmap px;
133   if ( dataModel() ) {
134     QString anIconName = dataModel()->module()->iconName();
135     if ( !anIconName.isEmpty() )
136       px = SUIT_Session::session()->resourceMgr()->loadPixmap( "ATOMIC", anIconName, false );
137   }
138   return px;
139 }
140
141 /*! Returns a tooltip of the root object. */
142 QString ATOMSOLVGUI_ModuleObject::toolTip(const int) const
143 {
144   return QObject::tr( "ATOMIC_ROOT_TOOLTIP" );
145 }
146