Salome HOME
b2b4d05e971784599368176c4f5a6ed448ce1dc7
[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 <HYDROData_Image.h>
26
27 #include <SUIT_DataObject.h>
28
29 #include <TDF_Tool.hxx>
30
31 HYDROGUI_DataObject::HYDROGUI_DataObject( SUIT_DataObject* theParent, 
32                                           Handle(HYDROData_Object) theData,
33                                           const QString& theParentEntry )
34 : CAM_DataObject( theParent ),
35   LightApp_DataObject( theParent ),
36   myData( theData ),
37   myParentEntry( theParentEntry )
38 {
39 }
40
41 QString HYDROGUI_DataObject::entry() const
42 {
43   QString anEntry = HYDROGUI_DataObject::dataObjectEntry( modelObject() );
44   if( isReference() )
45     anEntry.prepend( myParentEntry + "_" );
46   return anEntry;
47 }
48
49 QString HYDROGUI_DataObject::refEntry() const
50 {
51   if( !myParentEntry.isEmpty() )
52     return HYDROGUI_DataObject::dataObjectEntry( modelObject() );
53   return QString();
54 }
55
56 QString HYDROGUI_DataObject::name() const
57 {
58   if( !myData.IsNull() )
59     return myData->GetName();
60   return QString();
61 }
62
63 QFont HYDROGUI_DataObject::font( const int theId ) const
64 {
65   QFont aFont = LightApp_DataObject::font( theId );
66   if( theId == NameId )
67   {
68     Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( modelObject() );
69     if( !anImage.IsNull() && anImage->MustBeUpdated() )
70       aFont.setItalic( true );
71   }
72   return aFont;
73 }
74
75 QString HYDROGUI_DataObject::dataObjectEntry( const Handle(HYDROData_Object)& theObject,
76                                               const bool theWithPrefix )
77 {
78   QString aEntryStr = QString::null;
79   if( !theObject.IsNull() )
80   {
81     TCollection_AsciiString aLabEntr;
82     TDF_Tool::Entry( theObject->Label(), aLabEntr );
83     aEntryStr = aLabEntr.ToCString();
84     if( theWithPrefix )
85       aEntryStr.prepend( HYDROGUI_DataObject::entryPrefix() );
86   }
87   return aEntryStr;
88 }
89
90 HYDROGUI_NamedObject::HYDROGUI_NamedObject( SUIT_DataObject* theParent,
91                                             const QString&   theName,
92                                             const QString&   theParentEntry  )
93 : CAM_DataObject( theParent ),
94   LightApp_DataObject( theParent ),
95   myName( theName ),
96   myParentEntry( theParentEntry )
97 {
98 }
99
100 QString HYDROGUI_NamedObject::entry() const
101 {
102   QString anEntry = HYDROGUI_DataObject::entryPrefix() + name();
103   if( !myParentEntry.isEmpty() )
104     anEntry.prepend( myParentEntry + "_" );
105   return anEntry;
106 }
107
108 QString HYDROGUI_NamedObject::name() const
109 {
110   return myName;
111 }