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 const bool theIsInOperation )
36 : HYDROGUI_DataObject( theParent, theData, theParentEntry, theIsInOperation ), CAM_DataObject( theParent )
40 QString HYDROGUI_Zone::text( const int theColumnId ) const
43 if( !modelObject().IsNull() )
45 switch ( theColumnId )
48 // Get Ref.Object name
49 aRes = getRefObjectNames();
52 // Get bathymetry name
53 aRes = getBathimetryName();
56 aRes = LightApp_DataObject::text( theColumnId );
62 QString HYDROGUI_Zone::getRefObjectNames() const
65 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
66 if ( !aZone.IsNull() )
68 HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects();
69 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
70 for ( ; anIter.More(); anIter.Next() )
72 Handle(HYDROData_Object) aRefGeomObj =
73 Handle(HYDROData_Object)::DownCast( anIter.Value() );
74 if ( !aRefGeomObj.IsNull() )
76 // Get Ref.Object name
77 aRes += aRefGeomObj->GetName() + ", ";
81 if ( aRes.length() > 1 )
83 aRes.remove( aRes.length() - 2, 2 );
88 QString HYDROGUI_Zone::getBathimetryName() const
91 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
92 if ( !aZone.IsNull() )
94 HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects();
95 bool isMergingNeed = aZone->IsMergingNeed();
96 if ( ( isMergingNeed && aZone->GetMergeType() == HYDROData_Zone::Merge_UNKNOWN )
97 || ( aSeq.Length() == 1 ) || ( !isMergingNeed ) )
99 // Collect all used bathymetries names when merging is necessary
100 // or just get the name of bathymetry of a single geometry object
101 // or just get the name of a single bathymetry
102 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
103 QSet<QString> aNamesSet;
105 for ( ; anIter.More(); anIter.Next() )
107 Handle(HYDROData_Object) aRefGeomObj =
108 Handle(HYDROData_Object)::DownCast( anIter.Value() );
109 if ( !aRefGeomObj.IsNull() )
111 // Get bathymetry name
112 Handle(HYDROData_Bathymetry) aBathymetry = aRefGeomObj->GetBathymetry();
113 if ( !aBathymetry.IsNull() )
115 aName = aBathymetry->GetName();
116 if ( !isMergingNeed )
118 // Get the first geometry object's bathymetry name and go out
123 if ( !aNamesSet.contains( aName ) )
125 aRes += aName + ", ";
126 aNamesSet.insert( aName );
131 // Remove the last comma if necessary
132 if ( isMergingNeed && ( aRes.length() > 1 ) )
134 aRes.remove( aRes.length() - 2, 2 );
139 switch( aZone->GetMergeType() )
141 case HYDROData_Zone::Merge_ZMIN: // The minimum values
142 aRes = QObject::tr( "MERGE_ZMIN" );
144 case HYDROData_Zone::Merge_ZMAX: // The maximum values
145 aRes = QObject::tr( "MERGE_ZMAX" );
147 case HYDROData_Zone::Merge_Object: // Only one bathymetry will be taken into account
149 Handle(HYDROData_Bathymetry) aBathymetry = aZone->GetMergeBathymetry();
150 if ( !aBathymetry.IsNull() )
152 aRes = aBathymetry->GetName();
157 aRes = QObject::tr( "MERGE_UNKNOWN" );
164 bool HYDROGUI_Zone::isMergingNeed() const
167 if( !modelObject().IsNull() )
169 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
170 if ( !aZone.IsNull() )
172 aRes = aZone->IsMergingNeed();
178 QColor HYDROGUI_Zone::color( const ColorRole theColorRole, const int theColumnId ) const
180 // Implement red color for bathymetry conflicts in case creation dialog
182 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
183 if ( !aZone.IsNull() )
185 if ( ( aZone->IsMergingNeed() && aZone->GetMergeType() == HYDROData_Zone::Merge_UNKNOWN ) )
187 switch( theColorRole )
189 case Text: // editor foreground (text) color
190 case Foreground: // foreground (text) color
193 case HighlightedText: // highlighted foreground (text) color
196 case Base: // editor background color
197 case Background: // background color
198 case Highlight: // highlight background color
204 if ( !aRes.isValid() )
206 aRes = HYDROGUI_DataObject::color( theColorRole, theColumnId );
211 QStringList HYDROGUI_Zone::getBathymetries() const
214 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
215 if ( !aZone.IsNull() )
217 HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects();
218 // Collect all used bathymetries names when merging is necessary
219 // or just get the name of bathymetry of a single geometry object
220 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
221 for ( ; anIter.More(); anIter.Next() )
223 Handle(HYDROData_Object) aRefGeomObj =
224 Handle(HYDROData_Object)::DownCast( anIter.Value() );
225 if ( !aRefGeomObj.IsNull() )
227 // Get bathymetry name
228 Handle(HYDROData_Bathymetry) aBathymetry = aRefGeomObj->GetBathymetry();
229 if ( !aBathymetry.IsNull() && !aRes.contains( aBathymetry->GetName() ))
231 aRes.append( aBathymetry->GetName() );
239 HYDROData_Zone::MergeBathymetriesType HYDROGUI_Zone::getMergeType() const
241 HYDROData_Zone::MergeBathymetriesType aRes = HYDROData_Zone::Merge_UNKNOWN;
242 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
243 if ( !aZone.IsNull() )
245 aRes = aZone->GetMergeType();
250 void HYDROGUI_Zone::setMergeType( int theMergeType, QString theBathymetryName )
252 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
253 if ( !aZone.IsNull() )
255 HYDROData_Zone::MergeBathymetriesType aMergeType =
256 ( HYDROData_Zone::MergeBathymetriesType )theMergeType;
257 aZone->SetMergeType( aMergeType );
258 if ( aMergeType == HYDROData_Zone::Merge_Object )
260 // Find a bathymetry by the given name and set it as the zone's merge bathymetry
261 HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects();
262 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
263 for ( ; anIter.More(); anIter.Next() )
265 Handle(HYDROData_Object) aRefGeomObj =
266 Handle(HYDROData_Object)::DownCast( anIter.Value() );
267 if ( !aRefGeomObj.IsNull() )
269 // Get bathymetry name
270 Handle(HYDROData_Bathymetry) aBathymetry = aRefGeomObj->GetBathymetry();
271 if ( !aBathymetry.IsNull() && theBathymetryName == aBathymetry->GetName() )
273 aZone->SetMergeBathymetry( aBathymetry );
283 \brief Check if this object is can't be renamed in place
286 \return \c true if the item can be renamed by the user in place (e.g. in the Object browser)
288 bool HYDROGUI_Zone::renameAllowed( const int id ) const
290 if ( id == NameId && isInOperation() )
294 return HYDROGUI_DataObject::renameAllowed( id );
298 // \brief Set name of this object.
300 // \return \c true if rename operation finished successfully, \c false otherwise.
302 //bool HYDROGUI_Zone::setName(const QString& theName)
304 // if ( isInOperation() )
306 // bool aRes = false;
307 // if ( !theName.isEmpty() )
309 // Handle(HYDROData_Entity) anEntity = modelObject();
310 // CAM_Module* aModule = module();
311 // if( anEntity->GetName() != theName && aModule )
313 // // check that there are no other objects with the same name in the document
314 // Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( aModule, theName );
315 // if ( anObject.IsNull() )
317 // anEntity->SetName( theName );
322 // // Inform the user that the name is already used
323 // QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" );
324 // QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName );
325 // SUIT_MessageBox::critical( getApp()->desktop(), aTitle, aMessage );
332 // aRes = HYDROGUI_DataObject::setName( theName );