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>
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 )
38 QString HYDROGUI_Zone::text( const int theColumnId ) const
41 if( !modelObject().IsNull() )
43 switch ( theColumnId )
46 // Get Ref.Object name
47 aRes = getRefObjectNames();
50 // Get bathymetry name
51 aRes = getBathimetryName();
54 aRes = LightApp_DataObject::text( theColumnId );
60 QString HYDROGUI_Zone::getRefObjectNames() const
63 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
64 if ( !aZone.IsNull() )
66 HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects();
67 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
68 for ( ; anIter.More(); anIter.Next() )
70 Handle(HYDROData_Object) aRefGeomObj =
71 Handle(HYDROData_Object)::DownCast( anIter.Value() );
72 if ( !aRefGeomObj.IsNull() )
74 // Get Ref.Object name
75 aRes += aRefGeomObj->GetName() + ", ";
79 if ( aRes.length() > 1 )
81 aRes.remove( aRes.length() - 2, 2 );
86 QString HYDROGUI_Zone::getBathimetryName() const
89 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
90 if ( !aZone.IsNull() )
92 HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects();
93 if ( aZone->IsMergingNeed() || aSeq.Length() == 1 )
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() )
100 Handle(HYDROData_Object) aRefGeomObj =
101 Handle(HYDROData_Object)::DownCast( anIter.Value() );
102 if ( !aRefGeomObj.IsNull() )
104 // Get bathymetry name
105 Handle(HYDROData_Bathymetry) aBathymetry = aRefGeomObj->GetBathymetry();
106 if ( !aBathymetry.IsNull() )
108 aRes += aBathymetry->GetName() + ", ";
112 if ( aRes.length() > 1 )
114 aRes.remove( aRes.length() - 2, 2 );
119 switch( aZone->GetMergeType() )
121 case HYDROData_Zone::Merge_ZMIN: // The minimum values
122 aRes = QObject::tr( "MERGE_ZMIN" );
124 case HYDROData_Zone::Merge_ZMAX: // The maximum values
125 aRes = QObject::tr( "MERGE_ZMAX" );
127 case HYDROData_Zone::Merge_Object: // Only one bathymetry will be taken into account
129 Handle(HYDROData_Bathymetry) aBathymetry = aZone->GetMergeBathymetry();
130 if ( !aBathymetry.IsNull() )
132 aRes = aBathymetry->GetName();
137 aRes = QObject::tr( "MERGE_UNKNOWN" );
144 bool HYDROGUI_Zone::isMergingNeed() const
147 if( !modelObject().IsNull() )
149 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
150 if ( !aZone.IsNull() )
152 aRes = aZone->IsMergingNeed();
158 QColor HYDROGUI_Zone::color( const ColorRole theColorRole, const int theColumnId ) const
160 // Implement red color for bathymetry conflicts in case creation dialog
162 if( isMergingNeed() )
164 switch( theColorRole )
166 case Text: // editor foreground (text) color
167 case Foreground: // foreground (text) color
170 case HighlightedText: // highlighted foreground (text) color
173 case Base: // editor background color
174 case Background: // background color
175 case Highlight: // highlight background color
182 aRes = LightApp_DataObject::color( theColorRole, theColumnId );
187 QStringList HYDROGUI_Zone::getBathymetries() const
190 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
191 if ( !aZone.IsNull() )
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() )
199 Handle(HYDROData_Object) aRefGeomObj =
200 Handle(HYDROData_Object)::DownCast( anIter.Value() );
201 if ( !aRefGeomObj.IsNull() )
203 // Get bathymetry name
204 Handle(HYDROData_Bathymetry) aBathymetry = aRefGeomObj->GetBathymetry();
205 if ( !aBathymetry.IsNull() && !aRes.contains( aBathymetry->GetName() ))
207 aRes.append( aBathymetry->GetName() );
215 HYDROData_Zone::MergeBathymetriesType HYDROGUI_Zone::getMergeType() const
217 HYDROData_Zone::MergeBathymetriesType aRes = HYDROData_Zone::Merge_UNKNOWN;
218 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
219 if ( !aZone.IsNull() )
221 aRes = aZone->GetMergeType();
226 void HYDROGUI_Zone::setMergeType( int theMergeType, QString theBathymetryName )
228 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
229 if ( !aZone.IsNull() )
231 HYDROData_Zone::MergeBathymetriesType aMergeType =
232 ( HYDROData_Zone::MergeBathymetriesType )theMergeType;
233 aZone->SetMergeType( aMergeType );
234 if ( aMergeType == HYDROData_Zone::Merge_Object )
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() )
241 Handle(HYDROData_Object) aRefGeomObj =
242 Handle(HYDROData_Object)::DownCast( anIter.Value() );
243 if ( !aRefGeomObj.IsNull() )
245 // Get bathymetry name
246 Handle(HYDROData_Bathymetry) aBathymetry = aRefGeomObj->GetBathymetry();
247 if ( !aBathymetry.IsNull() && theBathymetryName == aBathymetry->GetName() )
249 aZone->SetMergeBathymetry( aBathymetry );