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() && aZone->GetMergeType() == HYDROData_Zone::Merge_UNKNOWN )
94 || aSeq.Length() == 1 )
96 // Collect all used bathymetries names when merging is necessary
97 // or just get the name of bathymetry of a single geometry object
98 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
99 for ( ; anIter.More(); anIter.Next() )
101 Handle(HYDROData_Object) aRefGeomObj =
102 Handle(HYDROData_Object)::DownCast( anIter.Value() );
103 if ( !aRefGeomObj.IsNull() )
105 // Get bathymetry name
106 Handle(HYDROData_Bathymetry) aBathymetry = aRefGeomObj->GetBathymetry();
107 if ( !aBathymetry.IsNull() )
109 aRes += aBathymetry->GetName() + ", ";
113 if ( aRes.length() > 1 )
115 aRes.remove( aRes.length() - 2, 2 );
120 switch( aZone->GetMergeType() )
122 case HYDROData_Zone::Merge_ZMIN: // The minimum values
123 aRes = QObject::tr( "MERGE_ZMIN" );
125 case HYDROData_Zone::Merge_ZMAX: // The maximum values
126 aRes = QObject::tr( "MERGE_ZMAX" );
128 case HYDROData_Zone::Merge_Object: // Only one bathymetry will be taken into account
130 Handle(HYDROData_Bathymetry) aBathymetry = aZone->GetMergeBathymetry();
131 if ( !aBathymetry.IsNull() )
133 aRes = aBathymetry->GetName();
138 aRes = QObject::tr( "MERGE_UNKNOWN" );
145 bool HYDROGUI_Zone::isMergingNeed() const
148 if( !modelObject().IsNull() )
150 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
151 if ( !aZone.IsNull() )
153 aRes = aZone->IsMergingNeed();
159 QColor HYDROGUI_Zone::color( const ColorRole theColorRole, const int theColumnId ) const
161 // Implement red color for bathymetry conflicts in case creation dialog
163 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
164 if ( !aZone.IsNull() )
166 if ( ( aZone->IsMergingNeed() && aZone->GetMergeType() == HYDROData_Zone::Merge_UNKNOWN ) )
168 switch( theColorRole )
170 case Text: // editor foreground (text) color
171 case Foreground: // foreground (text) color
174 case HighlightedText: // highlighted foreground (text) color
177 case Base: // editor background color
178 case Background: // background color
179 case Highlight: // highlight background color
185 if ( !aRes.isValid() )
187 aRes = LightApp_DataObject::color( theColorRole, theColumnId );
192 QStringList HYDROGUI_Zone::getBathymetries() const
195 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
196 if ( !aZone.IsNull() )
198 HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects();
199 // Collect all used bathymetries names when merging is necessary
200 // or just get the name of bathymetry of a single geometry object
201 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
202 for ( ; anIter.More(); anIter.Next() )
204 Handle(HYDROData_Object) aRefGeomObj =
205 Handle(HYDROData_Object)::DownCast( anIter.Value() );
206 if ( !aRefGeomObj.IsNull() )
208 // Get bathymetry name
209 Handle(HYDROData_Bathymetry) aBathymetry = aRefGeomObj->GetBathymetry();
210 if ( !aBathymetry.IsNull() && !aRes.contains( aBathymetry->GetName() ))
212 aRes.append( aBathymetry->GetName() );
220 HYDROData_Zone::MergeBathymetriesType HYDROGUI_Zone::getMergeType() const
222 HYDROData_Zone::MergeBathymetriesType aRes = HYDROData_Zone::Merge_UNKNOWN;
223 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
224 if ( !aZone.IsNull() )
226 aRes = aZone->GetMergeType();
231 void HYDROGUI_Zone::setMergeType( int theMergeType, QString theBathymetryName )
233 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
234 if ( !aZone.IsNull() )
236 HYDROData_Zone::MergeBathymetriesType aMergeType =
237 ( HYDROData_Zone::MergeBathymetriesType )theMergeType;
238 aZone->SetMergeType( aMergeType );
239 if ( aMergeType == HYDROData_Zone::Merge_Object )
241 // Find a bathymetry by the given name and set it as the zone's merge bathymetry
242 HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects();
243 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
244 for ( ; anIter.More(); anIter.Next() )
246 Handle(HYDROData_Object) aRefGeomObj =
247 Handle(HYDROData_Object)::DownCast( anIter.Value() );
248 if ( !aRefGeomObj.IsNull() )
250 // Get bathymetry name
251 Handle(HYDROData_Bathymetry) aBathymetry = aRefGeomObj->GetBathymetry();
252 if ( !aBathymetry.IsNull() && theBathymetryName == aBathymetry->GetName() )
254 aZone->SetMergeBathymetry( aBathymetry );