Salome HOME
Remove OCCViewer_ViewWidget
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_DataObject.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HYDROGUI_DataObject.h"
24
25 #include <SUIT_DataObject.h>
26 #include <TDF_Tool.hxx>
27 #include <SUIT_ResourceMgr.h>
28 #include <SUIT_Session.h>
29 #include <QPixmap>
30
31 HYDROGUI_DataObject::HYDROGUI_DataObject( SUIT_DataObject* theParent, 
32                                           Handle(HYDROData_Entity) theData,
33                                           const QString& theParentEntry )
34 : CAM_DataObject( theParent ),
35   LightApp_DataObject( theParent ),
36   myData( theData ),
37   myParentEntry( theParentEntry ),
38   myIsValid( true )
39 {
40 }
41
42 QString HYDROGUI_DataObject::entry() const
43 {
44   QString anEntry = HYDROGUI_DataObject::dataObjectEntry( modelObject() );
45   if( isReference() )
46     anEntry.prepend( myParentEntry + "_" );
47   return anEntry;
48 }
49
50 QString HYDROGUI_DataObject::refEntry() const
51 {
52   if( !myParentEntry.isEmpty() )
53     return HYDROGUI_DataObject::dataObjectEntry( modelObject() );
54   return QString();
55 }
56
57 QString HYDROGUI_DataObject::name() const
58 {
59   if( !myData.IsNull() )
60     return myData->GetName();
61   return QString();
62 }
63
64 QFont HYDROGUI_DataObject::font( const int theId ) const
65 {
66   QFont aFont = LightApp_DataObject::font( theId );
67   if( theId == NameId )
68   {
69     Handle(HYDROData_Entity) aDataObject = modelObject();
70     if( !aDataObject.IsNull() && aDataObject->IsMustBeUpdated() )
71       aFont.setItalic( true );
72   }
73   return aFont;
74 }
75
76 QColor HYDROGUI_DataObject::color( const ColorRole theRole, const int theId ) const
77 {
78   QColor aColor;
79
80   if ( !isValid() ) {
81     switch ( theRole )
82     {
83       case Text:
84       case Foreground:
85       case Highlight:
86         aColor = QColor( 255, 0, 0 ); // red
87       break;
88       case HighlightedText:
89         // text color for the highlighted item
90         aColor = QColor( 255, 255, 255 );   // white
91       break;
92
93       default:
94         break;
95     }
96   }
97
98   if ( !aColor.isValid() ) {
99     aColor = LightApp_DataObject::color( theRole, theId );
100   }
101
102   return aColor;
103 }
104
105 QPixmap HYDROGUI_DataObject::icon( const int theId ) const
106 {
107   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
108   if ( theId == NameId )
109   {
110     QString anIcon;
111     Handle(HYDROData_Entity) aDataObject = modelObject();
112     if( aDataObject.IsNull() )
113     {
114       anIcon = QObject::tr( "HYDRO_TYPE0_ICO" ); // KIND_UNKNOWN
115     }
116     else
117     {
118       anIcon = QObject::tr( QString("HYDRO_TYPE%1_ICO").arg( (int)aDataObject->GetKind() ).toAscii() );
119     }
120
121     return aResMgr->loadPixmap( "HYDRO", anIcon );
122   }
123   return LightApp_DataObject::icon( theId );
124 }
125
126 QString HYDROGUI_DataObject::dataObjectEntry( const Handle(HYDROData_Entity)& theObject,
127                                               const bool theWithPrefix )
128 {
129   QString aEntryStr = QString::null;
130   if( !theObject.IsNull() )
131   {
132     TCollection_AsciiString aLabEntr;
133     TDF_Tool::Entry( theObject->Label(), aLabEntr );
134     aEntryStr = aLabEntr.ToCString();
135     if( theWithPrefix )
136       aEntryStr.prepend( HYDROGUI_DataObject::entryPrefix() );
137   }
138   return aEntryStr;
139 }
140
141 void HYDROGUI_DataObject::setIsValid( const bool theIsValid )
142 {
143   myIsValid = theIsValid;
144 }
145
146 bool HYDROGUI_DataObject::isValid() const
147 {
148   return myIsValid;
149 }
150
151 HYDROGUI_NamedObject::HYDROGUI_NamedObject( SUIT_DataObject* theParent,
152                                             const QString&   theName,
153                                             const QString&   theParentEntry  )
154 : CAM_DataObject( theParent ),
155   LightApp_DataObject( theParent ),
156   myName( theName ),
157   myParentEntry( theParentEntry )
158 {
159 }
160
161 QString HYDROGUI_NamedObject::entry() const
162 {
163   QString anEntry = HYDROGUI_DataObject::entryPrefix() + name();
164   if( !myParentEntry.isEmpty() )
165     anEntry.prepend( myParentEntry + "_" );
166   return anEntry;
167 }
168
169 QString HYDROGUI_NamedObject::name() const
170 {
171   return myName;
172 }
173
174 QPixmap HYDROGUI_NamedObject::icon( const int theId ) const
175 {
176   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
177   if ( theId == NameId )
178   {
179     return aResMgr->loadPixmap( "HYDRO", QObject::tr( "PARTITION_ICO" ) );
180   }
181   return LightApp_DataObject::icon( theId );
182 }
183
184 HYDROGUI_DropTargetObject::HYDROGUI_DropTargetObject( SUIT_DataObject* theParent,
185                                             const QString&   theName,
186                                             const QString&   theParentEntry  )
187 : HYDROGUI_NamedObject( theParent, theName, theParentEntry ), CAM_DataObject( theParent )
188 {
189 }