Salome HOME
- Merge type combo box in Calculation case dialog is filled and connected to get...
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Zone.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_Zone.h"
24
25 #include <HYDROData_Zone.h>
26 #include <HYDROData_Object.h>
27 #include <HYDROData_Bathymetry.h>
28
29 #include <SUIT_DataObject.h>
30
31 HYDROGUI_Zone::HYDROGUI_Zone( SUIT_DataObject* theParent, 
32                                           Handle(HYDROData_Zone) theData,
33                                           const QString& theParentEntry )
34 : HYDROGUI_DataObject( theParent, theData, theParentEntry ), CAM_DataObject( theParent )
35 {
36 }
37
38 QString HYDROGUI_Zone::text( const int theColumnId ) const
39 {
40   QString aRes;
41   if( !modelObject().IsNull() )
42   {
43     switch ( theColumnId )
44     {
45       case RefObjectId:
46         // Get Ref.Object name
47         aRes = getRefObjectNames();
48         break;
49       case BathymetryId:
50         // Get bathymetry name
51         aRes = getBathimetryName();
52         break;
53       default:
54         aRes = LightApp_DataObject::text( theColumnId );
55     }
56   }
57   return aRes;
58 }
59
60 QString HYDROGUI_Zone::getRefObjectNames() const
61 {
62   QString aRes;
63   Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
64   if ( !aZone.IsNull() )
65   {
66     HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects();
67     HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
68     for ( ; anIter.More(); anIter.Next() )
69     {
70       Handle(HYDROData_Object) aRefGeomObj =
71         Handle(HYDROData_Object)::DownCast( anIter.Value() );
72       if ( !aRefGeomObj.IsNull() )
73       {
74         // Get Ref.Object name
75         aRes += aRefGeomObj->GetName() + ", ";
76       }
77     }
78   }
79   if ( aRes.length() > 1 )
80   {
81     aRes.remove( aRes.length() - 2, 2 );
82   }
83   return aRes;
84 }
85
86 QString HYDROGUI_Zone::getBathimetryName() const
87 {
88   QString aRes;
89   Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
90   if ( !aZone.IsNull() )
91   {
92     HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects();
93     if ( aZone->IsMergingNeed() || aSeq.Length() == 1 )
94     {
95       // Collect all used bathymetries names when merging is necessary
96       // or just get the name of bathymetry of a single geometry object
97       HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
98       for ( ; anIter.More(); anIter.Next() )
99       {
100         Handle(HYDROData_Object) aRefGeomObj =
101           Handle(HYDROData_Object)::DownCast( anIter.Value() );
102         if ( !aRefGeomObj.IsNull() )
103         {
104           // Get bathymetry name
105           Handle(HYDROData_Bathymetry) aBathymetry = aRefGeomObj->GetBathymetry();
106           if ( !aBathymetry.IsNull() )
107           {
108             aRes += aBathymetry->GetName() + ", ";
109           }
110         }
111       }
112       if ( aRes.length() > 1 )
113       {
114         aRes.remove( aRes.length() - 2, 2 );
115       }
116     }
117     else
118     {
119       switch( aZone->GetMergeType() )
120       {
121         case HYDROData_Zone::Merge_ZMIN:    // The minimum values
122           aRes = QObject::tr( "MERGE_ZMIN" );
123           break;
124         case HYDROData_Zone::Merge_ZMAX:    // The maximum values
125           aRes = QObject::tr( "MERGE_ZMAX" );
126           break;
127         case HYDROData_Zone::Merge_Object:   // Only one bathymetry will be taken into account
128         {
129           Handle(HYDROData_Bathymetry) aBathymetry = aZone->GetMergeBathymetry();
130           if ( !aBathymetry.IsNull() )
131           {
132             aRes = aBathymetry->GetName();
133           }
134           break;
135         }
136         default:
137           aRes = QObject::tr( "MERGE_UNKNOWN" );
138       }
139     }
140   }
141   return aRes;
142 }
143
144 bool HYDROGUI_Zone::isMergingNeed() const
145 {
146   bool aRes = false;
147   if( !modelObject().IsNull() )
148   {
149     Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
150     if ( !aZone.IsNull() ) 
151     {
152       aRes = aZone->IsMergingNeed();
153     }
154   }
155   return aRes;
156 }
157
158 QColor HYDROGUI_Zone::color( const ColorRole theColorRole, const int theColumnId ) const
159 {
160   // Implement red color for bathymetry conflicts in case creation dialog
161   QColor aRes;
162   if( isMergingNeed() )
163   {
164     switch( theColorRole )
165     {
166       case Text:            // editor foreground (text) color
167       case Foreground:      // foreground (text) color
168         aRes = Qt::red;
169         break;
170       case HighlightedText: // highlighted foreground (text) color
171         aRes = Qt::black;
172         break;
173       case Base:            // editor background color
174       case Background:      // background color
175       case Highlight:       // highlight background color
176       default:
177         aRes = Qt::red;
178     }
179   }
180   else
181   {
182     aRes = LightApp_DataObject::color( theColorRole, theColumnId );
183   }
184   return aRes;
185 }
186
187 QStringList HYDROGUI_Zone::getBathymetries() const
188 {
189   QStringList aRes;
190   Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
191   if ( !aZone.IsNull() )
192   {
193     HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects();
194     // Collect all used bathymetries names when merging is necessary
195     // or just get the name of bathymetry of a single geometry object
196     HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
197     for ( ; anIter.More(); anIter.Next() )
198     {
199       Handle(HYDROData_Object) aRefGeomObj =
200         Handle(HYDROData_Object)::DownCast( anIter.Value() );
201       if ( !aRefGeomObj.IsNull() )
202       {
203         // Get bathymetry name
204         Handle(HYDROData_Bathymetry) aBathymetry = aRefGeomObj->GetBathymetry();
205         if ( !aBathymetry.IsNull() && !aRes.contains( aBathymetry->GetName() ))
206         {
207           aRes.append( aBathymetry->GetName() );
208         }
209       }
210     }
211   }
212   return aRes;
213 }
214
215 HYDROData_Zone::MergeBathymetriesType HYDROGUI_Zone::getMergeType() const
216 {
217   HYDROData_Zone::MergeBathymetriesType aRes = HYDROData_Zone::Merge_UNKNOWN;
218   Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
219   if ( !aZone.IsNull() )
220   {
221     aRes = aZone->GetMergeType();
222   }
223   return aRes;
224 }
225
226 void HYDROGUI_Zone::setMergeType( int theMergeType, QString theBathymetryName )
227 {
228   Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
229   if ( !aZone.IsNull() )
230   {
231     HYDROData_Zone::MergeBathymetriesType aMergeType = 
232       ( HYDROData_Zone::MergeBathymetriesType )theMergeType;
233     aZone->SetMergeType( aMergeType );
234     if ( aMergeType == HYDROData_Zone::Merge_Object )
235     {
236       // Find a bathymetry by the given name and set it as the zone's merge bathymetry
237       HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects();
238       HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
239       for ( ; anIter.More(); anIter.Next() )
240       {
241         Handle(HYDROData_Object) aRefGeomObj =
242           Handle(HYDROData_Object)::DownCast( anIter.Value() );
243         if ( !aRefGeomObj.IsNull() )
244         {
245           // Get bathymetry name
246           Handle(HYDROData_Bathymetry) aBathymetry = aRefGeomObj->GetBathymetry();
247           if ( !aBathymetry.IsNull() && theBathymetryName == aBathymetry->GetName() )
248           {
249             aZone->SetMergeBathymetry( aBathymetry );
250             break;
251           }
252         }
253       }
254     }
255   }
256 }