1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_Zone.h"
25 #include <HYDROData_Zone.h>
26 #include <HYDROData_Object.h>
27 #include <HYDROData_Bathymetry.h>
29 #include <SUIT_DataObject.h>
32 HYDROGUI_Zone::HYDROGUI_Zone( SUIT_DataObject* theParent,
33 Handle(HYDROData_Zone) theData,
34 const QString& theParentEntry )
35 : HYDROGUI_DataObject( theParent, theData, theParentEntry ), CAM_DataObject( theParent )
39 QString HYDROGUI_Zone::text( const int theColumnId ) const
42 if( !modelObject().IsNull() )
44 switch ( theColumnId )
47 // Get Ref.Object name
48 aRes = getRefObjectNames();
51 // Get bathymetry name
52 aRes = getBathimetryName();
55 aRes = LightApp_DataObject::text( theColumnId );
61 QString HYDROGUI_Zone::getRefObjectNames() const
64 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
65 if ( !aZone.IsNull() )
67 HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects();
68 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
69 for ( ; anIter.More(); anIter.Next() )
71 Handle(HYDROData_Object) aRefGeomObj =
72 Handle(HYDROData_Object)::DownCast( anIter.Value() );
73 if ( !aRefGeomObj.IsNull() )
75 // Get Ref.Object name
76 aRes += aRefGeomObj->GetName() + ", ";
80 if ( aRes.length() > 1 )
82 aRes.remove( aRes.length() - 2, 2 );
87 QString HYDROGUI_Zone::getBathimetryName() const
90 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
91 if ( !aZone.IsNull() )
93 HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects();
94 bool isMergingNeed = aZone->IsMergingNeed();
95 if ( ( isMergingNeed && aZone->GetMergeType() == HYDROData_Zone::Merge_UNKNOWN )
96 || ( aSeq.Length() == 1 ) || ( !isMergingNeed ) )
98 // Collect all used bathymetries names when merging is necessary
99 // or just get the name of bathymetry of a single geometry object
100 // or just get the name of a single bathymetry
101 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
102 QSet<QString> aNamesSet;
104 for ( ; anIter.More(); anIter.Next() )
106 Handle(HYDROData_Object) aRefGeomObj =
107 Handle(HYDROData_Object)::DownCast( anIter.Value() );
108 if ( !aRefGeomObj.IsNull() )
110 // Get bathymetry name
111 Handle(HYDROData_Bathymetry) aBathymetry = aRefGeomObj->GetBathymetry();
112 if ( !aBathymetry.IsNull() )
114 aName = aBathymetry->GetName();
115 if ( !isMergingNeed )
117 // Get the first geometry object's bathymetry name and go out
122 if ( !aNamesSet.contains( aName ) )
124 aRes += aName + ", ";
125 aNamesSet.insert( aName );
130 // Remove the last comma if necessary
131 if ( isMergingNeed && ( aRes.length() > 1 ) )
133 aRes.remove( aRes.length() - 2, 2 );
138 switch( aZone->GetMergeType() )
140 case HYDROData_Zone::Merge_ZMIN: // The minimum values
141 aRes = QObject::tr( "MERGE_ZMIN" );
143 case HYDROData_Zone::Merge_ZMAX: // The maximum values
144 aRes = QObject::tr( "MERGE_ZMAX" );
146 case HYDROData_Zone::Merge_Object: // Only one bathymetry will be taken into account
148 Handle(HYDROData_Bathymetry) aBathymetry = aZone->GetMergeBathymetry();
149 if ( !aBathymetry.IsNull() )
151 aRes = aBathymetry->GetName();
156 aRes = QObject::tr( "MERGE_UNKNOWN" );
163 bool HYDROGUI_Zone::isMergingNeed() const
166 if( !modelObject().IsNull() )
168 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
169 if ( !aZone.IsNull() )
171 aRes = aZone->IsMergingNeed();
177 QColor HYDROGUI_Zone::color( const ColorRole theColorRole, const int theColumnId ) const
179 // Implement red color for bathymetry conflicts in case creation dialog
181 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
182 if ( !aZone.IsNull() )
184 if ( ( aZone->IsMergingNeed() && aZone->GetMergeType() == HYDROData_Zone::Merge_UNKNOWN ) )
186 switch( theColorRole )
188 case Text: // editor foreground (text) color
189 case Foreground: // foreground (text) color
192 case HighlightedText: // highlighted foreground (text) color
195 case Base: // editor background color
196 case Background: // background color
197 case Highlight: // highlight background color
203 if ( !aRes.isValid() )
205 aRes = LightApp_DataObject::color( theColorRole, theColumnId );
210 QStringList HYDROGUI_Zone::getBathymetries() const
213 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
214 if ( !aZone.IsNull() )
216 HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects();
217 // Collect all used bathymetries names when merging is necessary
218 // or just get the name of bathymetry of a single geometry object
219 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
220 for ( ; anIter.More(); anIter.Next() )
222 Handle(HYDROData_Object) aRefGeomObj =
223 Handle(HYDROData_Object)::DownCast( anIter.Value() );
224 if ( !aRefGeomObj.IsNull() )
226 // Get bathymetry name
227 Handle(HYDROData_Bathymetry) aBathymetry = aRefGeomObj->GetBathymetry();
228 if ( !aBathymetry.IsNull() && !aRes.contains( aBathymetry->GetName() ))
230 aRes.append( aBathymetry->GetName() );
238 HYDROData_Zone::MergeBathymetriesType HYDROGUI_Zone::getMergeType() const
240 HYDROData_Zone::MergeBathymetriesType aRes = HYDROData_Zone::Merge_UNKNOWN;
241 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
242 if ( !aZone.IsNull() )
244 aRes = aZone->GetMergeType();
249 void HYDROGUI_Zone::setMergeType( int theMergeType, QString theBathymetryName )
251 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
252 if ( !aZone.IsNull() )
254 HYDROData_Zone::MergeBathymetriesType aMergeType =
255 ( HYDROData_Zone::MergeBathymetriesType )theMergeType;
256 aZone->SetMergeType( aMergeType );
257 if ( aMergeType == HYDROData_Zone::Merge_Object )
259 // Find a bathymetry by the given name and set it as the zone's merge bathymetry
260 HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects();
261 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
262 for ( ; anIter.More(); anIter.Next() )
264 Handle(HYDROData_Object) aRefGeomObj =
265 Handle(HYDROData_Object)::DownCast( anIter.Value() );
266 if ( !aRefGeomObj.IsNull() )
268 // Get bathymetry name
269 Handle(HYDROData_Bathymetry) aBathymetry = aRefGeomObj->GetBathymetry();
270 if ( !aBathymetry.IsNull() && theBathymetryName == aBathymetry->GetName() )
272 aZone->SetMergeBathymetry( aBathymetry );