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