Salome HOME
2cc75e4d270ac1c358269a73057fec8b3ab4595d
[samples/atomic.git] / src / ATOMICGUI / ATOMICGUI_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 "ATOMICGUI_DataObject.h"
21 #include "ATOMICGUI_Data.h"
22
23 #include <SUIT_Session.h>
24 #include <SUIT_ResourceMgr.h>
25 #include <CAM_DataModel.h>
26 #include <CAM_Module.h>
27
28 /*! Constructor */
29 ATOMICGUI_DataObject::ATOMICGUI_DataObject( SUIT_DataObject* parent,
30                                             ATOMICGUI_AtomicMolecule* mol, 
31                                             int idx )
32   : LightApp_DataObject( parent ),
33     CAM_DataObject( parent),
34     myMolecule( mol ),
35     myIndex( idx )
36 {
37 }
38
39 /*! Destructor */
40 ATOMICGUI_DataObject::~ATOMICGUI_DataObject()
41 {
42 }
43
44 /*! Returns unique object ID */
45 QString ATOMICGUI_DataObject::entry() const
46 {
47   QString id = "root";
48   if ( myMolecule )
49     id = QString::number( myMolecule->id() ); 
50   if ( myIndex >= 0 )
51     id += QString( "_%1" ).arg( QString::number( myMolecule->atomId( myIndex ) ) ); 
52   return QString( "ATOMICGUI_%1" ).arg( id );
53 }
54
55 /*! Returns a name of the Data Object. */
56 QString ATOMICGUI_DataObject::name() const
57 {
58   QString n;
59   if ( myMolecule )
60     n = myIndex < 0 ? myMolecule->name() 
61                     : myMolecule->atomName( myIndex );
62   return n;
63 }
64
65 /*! Returns an icon of the Data Object. */
66 QPixmap ATOMICGUI_DataObject::icon(const int column) const
67 {
68   static QPixmap pxmole = SUIT_Session::session()->resourceMgr()->loadPixmap( "ATOMIC", QObject::tr( "ICON_MOLECULE" ), false );
69   static QPixmap pxatom = SUIT_Session::session()->resourceMgr()->loadPixmap( "ATOMIC", QObject::tr( "ICON_ATOM" ), false );
70   static QPixmap nullpx;
71   return column == NameId ? ( myIndex < 0 ? pxmole : pxatom ) : nullpx;
72 }
73
74 /*! Returns a tooltip for the object (to be displayed in the Object Browser). */
75 QString ATOMICGUI_DataObject::toolTip(const int) const
76 {
77   QString tt;
78   if ( myMolecule )
79     tt = myIndex < 0 ? QString( QObject::tr( "ATOMIC_MOLECULE" ) + ": %1" ).arg( myMolecule->name() )
80       : QString( QObject::tr( "ATOMIC_ATOM" ) + ": %1: %2,%3,%4" ).
81       arg( myMolecule->atomName( myIndex ) ).
82       arg( myMolecule->atomX( myIndex ) ).
83       arg( myMolecule->atomY( myIndex ) ).
84       arg( myMolecule->atomZ( myIndex ) );
85   return tt;
86 }
87
88 /*! Returns true if the Data Object corresponds to a Molecule. */
89 bool ATOMICGUI_DataObject::isMolecule() const
90 {
91   return myMolecule && myIndex < 0;
92 }
93
94 /*! Returns true if the Data Object corresponds to an Atom. */
95 bool ATOMICGUI_DataObject::isAtom() const
96 {
97   return myMolecule && myIndex >= 0;
98 }
99
100 /*! Constructor */
101 ATOMICGUI_ModuleObject::ATOMICGUI_ModuleObject( CAM_DataModel* dm, SUIT_DataObject* parent )
102 : ATOMICGUI_DataObject( parent ),
103   LightApp_ModuleObject( dm, parent ),
104   CAM_DataObject( parent )
105 {
106 }
107
108 /*! Returns a name of the root object. */
109 QString ATOMICGUI_ModuleObject::name() const
110 {
111   return CAM_ModuleObject::name();
112 }
113
114 /*! Returns an icon of the root object. */
115 QPixmap ATOMICGUI_ModuleObject::icon(const int column) const
116 {
117   QPixmap px;
118   if ( column == NameId && dataModel() ) {
119     QString anIconName = dataModel()->module()->iconName();
120     if ( !anIconName.isEmpty() )
121       px = SUIT_Session::session()->resourceMgr()->loadPixmap( "ATOMIC", anIconName, false );
122   }
123   return px;
124 }
125
126 /*! Returns a tooltip of the root object. */
127 QString ATOMICGUI_ModuleObject::toolTip(const int) const
128 {
129   return QObject::tr( "ATOMIC_ROOT_TOOLTIP" );
130 }