Salome HOME
Reference Bathymetry objects moved to base for geometry objects class.
[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 #include <HYDROData_Zone.h>
27 #include <HYDROData_Object.h>
28
29 #include <SUIT_DataObject.h>
30
31 #include <TDF_Tool.hxx>
32
33 HYDROGUI_DataObject::HYDROGUI_DataObject( SUIT_DataObject* theParent, 
34                                           Handle(HYDROData_Entity) theData,
35                                           const QString& theParentEntry )
36 : CAM_DataObject( theParent ),
37   LightApp_DataObject( theParent ),
38   myData( theData ),
39   myParentEntry( theParentEntry )
40 {
41 }
42
43 QString HYDROGUI_DataObject::entry() const
44 {
45   QString anEntry = HYDROGUI_DataObject::dataObjectEntry( modelObject() );
46   if( isReference() )
47     anEntry.prepend( myParentEntry + "_" );
48   return anEntry;
49 }
50
51 QString HYDROGUI_DataObject::refEntry() const
52 {
53   if( !myParentEntry.isEmpty() )
54     return HYDROGUI_DataObject::dataObjectEntry( modelObject() );
55   return QString();
56 }
57
58 QString HYDROGUI_DataObject::name() const
59 {
60   if( !myData.IsNull() )
61     return myData->GetName();
62   return QString();
63 }
64
65 QFont HYDROGUI_DataObject::font( const int theId ) const
66 {
67   QFont aFont = LightApp_DataObject::font( theId );
68   if( theId == NameId )
69   {
70     Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( modelObject() );
71     if( !anImage.IsNull() && anImage->MustBeUpdated() )
72       aFont.setItalic( true );
73   }
74   return aFont;
75 }
76
77 QString HYDROGUI_DataObject::text( const int theColumnId ) const
78 {
79   QString aRes;
80   if( !myData.IsNull() )
81   {
82     if ( theColumnId == RefObjectId || theColumnId == BathymetryId )
83     {
84       Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( myData );
85       if ( !aZone.IsNull() )
86       {
87         HYDROData_SequenceOfObjects::Iterator anIter( aZone->GetGeometryObjects() );
88         for ( ; anIter.More(); anIter.Next() )
89         {
90           Handle(HYDROData_Object) aRefGeomObj =
91             Handle(HYDROData_Object)::DownCast( anIter.Value() );
92           if ( !aRefGeomObj.IsNull() )
93           {
94             switch ( theColumnId )
95             {
96               case RefObjectId:
97                 aRes += aRefGeomObj->GetName() + ", ";
98                 break;
99               case BathymetryId:
100                 //TODO: Get bathymetry name
101                 //aRes += aRefGeomObj->
102                 ;
103             }
104           }
105         }
106       }
107       if ( aRes.length() > 1 )
108       {
109         aRes.remove( aRes.length() - 2, 2 );
110       }
111     }
112     else
113     {
114       aRes = LightApp_DataObject::text( theColumnId );
115     }
116   }
117   return aRes;
118 }
119
120 QColor HYDROGUI_DataObject::color( const ColorRole theColorRole, const int theColumnId ) const
121 {
122   //TODO: Implement red color for bathymetry conflicts in case creation dialog
123   return LightApp_DataObject::color( theColorRole, theColumnId );
124 }
125
126
127 QString HYDROGUI_DataObject::dataObjectEntry( const Handle(HYDROData_Entity)& theObject,
128                                               const bool theWithPrefix )
129 {
130   QString aEntryStr = QString::null;
131   if( !theObject.IsNull() )
132   {
133     TCollection_AsciiString aLabEntr;
134     TDF_Tool::Entry( theObject->Label(), aLabEntr );
135     aEntryStr = aLabEntr.ToCString();
136     if( theWithPrefix )
137       aEntryStr.prepend( HYDROGUI_DataObject::entryPrefix() );
138   }
139   return aEntryStr;
140 }
141
142 HYDROGUI_NamedObject::HYDROGUI_NamedObject( SUIT_DataObject* theParent,
143                                             const QString&   theName,
144                                             const QString&   theParentEntry  )
145 : CAM_DataObject( theParent ),
146   LightApp_DataObject( theParent ),
147   myName( theName ),
148   myParentEntry( theParentEntry )
149 {
150 }
151
152 QString HYDROGUI_NamedObject::entry() const
153 {
154   QString anEntry = HYDROGUI_DataObject::entryPrefix() + name();
155   if( !myParentEntry.isEmpty() )
156     anEntry.prepend( myParentEntry + "_" );
157   return anEntry;
158 }
159
160 QString HYDROGUI_NamedObject::name() const
161 {
162   return myName;
163 }