Salome HOME
Updated copyright comment
[modules/gui.git] / src / SALOME_PYQT / SALOME_PYQT_GUILight / SALOME_PYQT_DataObjectLight.cxx
1 // Copyright (C) 2007-2024  CEA, EDF, 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 //  Author : Roman NIKOLAEV, Open CASCADE S.A.S. (roman.nikolaev@opencascade.com)
21 //  Date   : 22/06/2007
22 //
23 #include "SALOME_PYQT_DataObjectLight.h"
24 #include <LightApp_Application.h>
25 #include <SUIT_Session.h>
26 #include <utilities.h>
27 #include <SUIT_ResourceMgr.h>
28
29
30 #include <CAM_DataModel.h>
31 #include <CAM_Module.h>
32
33
34 /*!
35  *  Class:       SALOME_PYQT_DataObjectLight
36  *  Description: LIGHT PYTHON module's data object
37  */
38
39 static int _ID = 0;
40
41 //=================================================================================
42 // function : SALOME_PYQT_DataObjectLight()
43 // purpose  : constructor
44 //=================================================================================
45 SALOME_PYQT_DataObjectLight::SALOME_PYQT_DataObjectLight ( SUIT_DataObject* parent )
46   : CAM_DataObject(parent),
47     LightApp_DataObject( parent )
48
49 {
50   _ID++;
51   myEntry = QString("PYLIGHT_OBJ_%1").arg(_ID);
52 }
53
54 //=================================================================================
55 // function : SALOME_PYQT_DataObjectLight()
56 // purpose  : destructor
57 //=================================================================================
58 SALOME_PYQT_DataObjectLight::~SALOME_PYQT_DataObjectLight()
59 {
60   
61 }
62
63 //=================================================================================
64 // function : SALOME_PYQT_DataObjectLight::entry()
65 // purpose  : return entry of object
66 //=================================================================================
67 QString SALOME_PYQT_DataObjectLight::entry() const
68 {
69   return myEntry;
70 }
71
72 //=================================================================================
73 // function : SALOME_PYQT_DataObjectLight::refEntry()
74 // purpose  : return entry of the data object referenced by this one (if any)
75 //=================================================================================
76 QString SALOME_PYQT_DataObjectLight::refEntry() const
77 {
78   return myRefEntry;
79 }
80
81 //=================================================================================
82 // function : SALOME_PYQT_DataObjectLight::setRefEntry()
83 // purpose  : sets entry of the data object referenced by this one
84 //=================================================================================
85 void SALOME_PYQT_DataObjectLight::setRefEntry( const QString& refEntry )
86 {
87   myRefEntry = refEntry;
88 }
89
90 //=================================================================================
91 // function : SALOME_PYQT_DataObjectLight::name()
92 // purpose  : return name of object
93 //=================================================================================
94 QString SALOME_PYQT_DataObjectLight::name() const
95 {
96   return myName;
97 }
98
99 //=================================================================================
100 // function : SALOME_PYQT_DataObjectLight::icon()
101 // purpose  : return icon of object
102 //=================================================================================
103 QPixmap SALOME_PYQT_DataObjectLight::icon(const int index) const
104 {
105   if(index == NameId)
106     return myIcon;
107   else
108     return LightApp_DataObject::icon( index );
109 }
110
111
112 //=================================================================================
113 // function : SALOME_PYQT_DataObjectLight::toolTip()
114 // purpose  : return toolTip of object
115 //=================================================================================
116 QString SALOME_PYQT_DataObjectLight::toolTip(const int /*index*/) const
117 {
118   return myToolTip;
119 }
120
121 //=================================================================================
122 // function : SALOME_PYQT_DataObjectLight::toolTip()
123 // purpose  : return toolTip of object
124 //=================================================================================
125 QColor SALOME_PYQT_DataObjectLight::color( const ColorRole role, const int id ) const
126 {
127   QColor c;
128
129   switch ( role )
130   {
131   case Text:
132   case Foreground:
133     if ( !isReference() )
134       c = myColor;
135     break;
136
137   default:
138     break;
139   }
140
141   // Issue 21379: LightApp_DataObject::color() defines colors for valid references
142   if ( !c.isValid() )
143     c = LightApp_DataObject::color( role, id );
144
145   return c;
146 }
147
148 bool SALOME_PYQT_DataObjectLight::setName(const QString& name)
149 {
150   myName = name;
151   return true;
152 }
153
154 void SALOME_PYQT_DataObjectLight::setIcon(const QString& iconname)
155 {
156   if(!iconname.isEmpty()) {
157     LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
158     if(anApp) {
159       QString modulename = anApp->activeModule()->name();
160       if(!modulename.isEmpty())
161         {
162           myIcon = SUIT_Session::session()->resourceMgr()->loadPixmap(modulename,
163                                                                       QObject::tr(iconname.toLatin1()));
164         }
165     }
166   }
167 }
168
169 void SALOME_PYQT_DataObjectLight::setToolTip(const QString& tooltip)
170 {
171   myToolTip = tooltip;
172 }
173
174 void SALOME_PYQT_DataObjectLight::setColor(const QColor& color)
175 {
176   myColor = color;
177 }