1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_Zone.h"
21 #include <HYDROData_Zone.h>
22 #include <HYDROData_Object.h>
23 #include <HYDROData_IAltitudeObject.h>
25 #include <SUIT_DataObject.h>
28 HYDROGUI_Zone::HYDROGUI_Zone( SUIT_DataObject* theParent,
29 Handle(HYDROData_Zone) theData,
30 const QString& theParentEntry,
31 const bool theIsInOperation )
32 : HYDROGUI_DataObject( theParent, theData, theParentEntry, theIsInOperation ), CAM_DataObject( theParent )
36 QString HYDROGUI_Zone::text( const int theColumnId ) const
39 if( !modelObject().IsNull() )
41 switch ( theColumnId )
44 // Get Ref.Object name
45 aRes = getRefObjectNames();
48 // Get altitude/land cover object name
49 aRes = getObjectName();
52 aRes = LightApp_DataObject::text( theColumnId );
58 QString HYDROGUI_Zone::getRefObjectNames() const
61 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
62 if ( !aZone.IsNull() )
64 HYDROData_SequenceOfObjects aSeq = aZone->GetObjects();
65 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
66 for ( ; anIter.More(); anIter.Next() )
68 Handle(HYDROData_Entity) aRefGeomObj = anIter.Value();
69 if ( !aRefGeomObj.IsNull() )
71 // Get Ref.Object name
72 aRes += aRefGeomObj->GetName() + ", ";
76 if ( aRes.length() > 1 )
78 aRes.remove( aRes.length() - 2, 2 );
83 QString HYDROGUI_Zone::getObjectName() const
86 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
87 if ( !aZone.IsNull() )
89 HYDROData_SequenceOfObjects aSeq = aZone->GetObjects();
90 bool isMergingNeed = aZone->IsMergingNeed();
91 if ( ( isMergingNeed && aZone->GetMergeType() == HYDROData_Zone::Merge_UNKNOWN )
92 || ( aSeq.Length() == 1 ) || ( !isMergingNeed ) )
94 // Collect all used altitudes names when merging is necessary
95 // or just get the name of altitude of a single geometry object
96 // or just get the name of a single altitude
97 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
98 QSet<QString> aNamesSet;
100 for ( ; anIter.More(); anIter.Next() )
103 Handle(HYDROData_Object) aRefGeomObj =
104 Handle(HYDROData_Object)::DownCast( anIter.Value() );
105 if ( !aRefGeomObj.IsNull() )
107 // Get altitude object name
108 Handle(HYDROData_IAltitudeObject) anAltitudeObj = aRefGeomObj->GetAltitudeObject();
109 if ( !anAltitudeObj.IsNull() )
111 aName = anAltitudeObj->GetName();
112 if ( !isMergingNeed )
114 // Get the first geometry object's altitude name and go out
121 if ( !aName.isEmpty() && !aNamesSet.contains( aName ) )
123 aRes += aName + ", ";
124 aNamesSet.insert( aName );
127 // Remove the last comma if necessary
128 if ( isMergingNeed && ( aRes.length() > 1 ) )
130 aRes.remove( aRes.length() - 2, 2 );
135 switch( aZone->GetMergeType() )
137 case HYDROData_Zone::Merge_ZMIN: // The minimum values
138 aRes = QObject::tr( "MERGE_ZMIN" );
140 case HYDROData_Zone::Merge_ZMAX: // The maximum values
141 aRes = QObject::tr( "MERGE_ZMAX" );
143 case HYDROData_Zone::Merge_Object: // Only one altitude/land cover will be taken into account
145 Handle(HYDROData_Entity) aMergeObj = aZone->GetMergeObject();
146 if ( !aMergeObj.IsNull() )
147 aRes = aMergeObj->GetName();
151 aRes = QObject::tr( "MERGE_UNKNOWN" );
158 bool HYDROGUI_Zone::isMergingNeed() const
161 if( !modelObject().IsNull() )
163 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
164 if ( !aZone.IsNull() )
166 aRes = aZone->IsMergingNeed();
172 QColor HYDROGUI_Zone::color( const ColorRole theColorRole, const int theColumnId ) const
174 // Implement red color for altitude conflicts in case creation dialog
176 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
177 if ( !aZone.IsNull() )
179 if ( ( aZone->IsMergingNeed() && aZone->GetMergeType() == HYDROData_Zone::Merge_UNKNOWN ) )
181 switch( theColorRole )
183 case Text: // editor foreground (text) color
184 case Foreground: // foreground (text) color
187 case HighlightedText: // highlighted foreground (text) color
190 case Base: // editor background color
191 case Background: // background color
192 case Highlight: // highlight background color
198 if ( !aRes.isValid() )
200 aRes = HYDROGUI_DataObject::color( theColorRole, theColumnId );
205 QStringList HYDROGUI_Zone::getObjects() const
208 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
209 if ( !aZone.IsNull() )
211 HYDROData_SequenceOfObjects aSeq = aZone->GetObjects();
212 // Collect all used altitudes/land cover names when merging is necessary
213 // or just get the name of altitude/land cover of a single object
214 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
215 for ( ; anIter.More(); anIter.Next() )
217 Handle(HYDROData_Object) aRefGeomObj =
218 Handle(HYDROData_Object)::DownCast( anIter.Value() );
219 if ( !aRefGeomObj.IsNull() )
221 Handle(HYDROData_IAltitudeObject) anAltitudeObj = aRefGeomObj->GetAltitudeObject();
222 if ( !anAltitudeObj.IsNull() && !aRes.contains( anAltitudeObj->GetName() ) )
223 aRes.append( anAltitudeObj->GetName() );
225 aRes.append( anIter.Value()->GetName() );
232 HYDROData_Zone::MergeType HYDROGUI_Zone::getMergeType() const
234 HYDROData_Zone::MergeType aRes = HYDROData_Zone::Merge_UNKNOWN;
235 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
236 if ( !aZone.IsNull() )
238 aRes = aZone->GetMergeType();
243 void HYDROGUI_Zone::setMergeType( int theMergeType, QString theMergeObjectName )
245 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
246 if ( !aZone.IsNull() )
248 HYDROData_Zone::MergeType aMergeType =
249 ( HYDROData_Zone::MergeType )theMergeType;
250 aZone->SetMergeType( aMergeType );
251 if ( aMergeType == HYDROData_Zone::Merge_Object )
253 // Find an altitude/land cover object by the given name and set it as the zone's merge altitude/land cover
254 HYDROData_SequenceOfObjects aSeq = aZone->GetObjects();
255 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
256 for ( ; anIter.More(); anIter.Next() )
258 Handle(HYDROData_Entity) aMergeObject;
260 Handle(HYDROData_Object) aRefGeomObj =
261 Handle(HYDROData_Object)::DownCast( anIter.Value() );
262 if ( !aRefGeomObj.IsNull() )
264 // Get altitude object
265 aMergeObject = aRefGeomObj->GetAltitudeObject();
268 if ( !aMergeObject.IsNull() && theMergeObjectName == aMergeObject->GetName() )
270 aZone->SetMergeObject( aMergeObject );
279 \brief Check if this object is can't be renamed in place
282 \return \c true if the item can be renamed by the user in place (e.g. in the Object browser)
284 bool HYDROGUI_Zone::renameAllowed( const int id ) const
286 if ( id == NameId && isInOperation() )
290 return HYDROGUI_DataObject::renameAllowed( id );
294 // \brief Set name of this object.
296 // \return \c true if rename operation finished successfully, \c false otherwise.
298 //bool HYDROGUI_Zone::setName(const QString& theName)
300 // if ( isInOperation() )
302 // bool aRes = false;
303 // if ( !theName.isEmpty() )
305 // Handle(HYDROData_Entity) anEntity = modelObject();
306 // CAM_Module* aModule = module();
307 // if( anEntity->GetName() != theName && aModule )
309 // // check that there are no other objects with the same name in the document
310 // Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( aModule, theName );
311 // if ( anObject.IsNull() )
313 // anEntity->SetName( theName );
318 // // Inform the user that the name is already used
319 // QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" );
320 // QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName );
321 // SUIT_MessageBox::critical( getApp()->desktop(), aTitle, aMessage );
328 // aRes = HYDROGUI_DataObject::setName( theName );