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