1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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_IAltitudeObject.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 altitude object name
53 aRes = getAltitudeName();
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::getAltitudeName() 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 altitudes names when merging is necessary
100 // or just get the name of altitude of a single geometry object
101 // or just get the name of a single altitude
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 altitude object name
112 Handle(HYDROData_IAltitudeObject) anAltitudeObj = aRefGeomObj->GetAltitudeObject();
113 if ( !anAltitudeObj.IsNull() )
115 aName = anAltitudeObj->GetName();
116 if ( !isMergingNeed )
118 // Get the first geometry object's altitude 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 altitude will be taken into account
149 Handle(HYDROData_IAltitudeObject) anAltitude = aZone->GetMergeAltitude();
150 if ( !anAltitude.IsNull() )
151 aRes = anAltitude->GetName();
155 aRes = QObject::tr( "MERGE_UNKNOWN" );
162 bool HYDROGUI_Zone::isMergingNeed() const
165 if( !modelObject().IsNull() )
167 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
168 if ( !aZone.IsNull() )
170 aRes = aZone->IsMergingNeed();
176 QColor HYDROGUI_Zone::color( const ColorRole theColorRole, const int theColumnId ) const
178 // Implement red color for altitude conflicts in case creation dialog
180 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
181 if ( !aZone.IsNull() )
183 if ( ( aZone->IsMergingNeed() && aZone->GetMergeType() == HYDROData_Zone::Merge_UNKNOWN ) )
185 switch( theColorRole )
187 case Text: // editor foreground (text) color
188 case Foreground: // foreground (text) color
191 case HighlightedText: // highlighted foreground (text) color
194 case Base: // editor background color
195 case Background: // background color
196 case Highlight: // highlight background color
202 if ( !aRes.isValid() )
204 aRes = HYDROGUI_DataObject::color( theColorRole, theColumnId );
209 QStringList HYDROGUI_Zone::getAltitudes() const
212 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
213 if ( !aZone.IsNull() )
215 HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects();
216 // Collect all used altitudes names when merging is necessary
217 // or just get the name of altitude of a single geometry object
218 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
219 for ( ; anIter.More(); anIter.Next() )
221 Handle(HYDROData_Object) aRefGeomObj =
222 Handle(HYDROData_Object)::DownCast( anIter.Value() );
223 if ( !aRefGeomObj.IsNull() )
225 Handle(HYDROData_IAltitudeObject) anAltitudeObj = aRefGeomObj->GetAltitudeObject();
226 if ( !anAltitudeObj.IsNull() && !aRes.contains( anAltitudeObj->GetName() ) )
227 aRes.append( anAltitudeObj->GetName() );
234 HYDROData_Zone::MergeAltitudesType HYDROGUI_Zone::getMergeType() const
236 HYDROData_Zone::MergeAltitudesType aRes = HYDROData_Zone::Merge_UNKNOWN;
237 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
238 if ( !aZone.IsNull() )
240 aRes = aZone->GetMergeType();
245 void HYDROGUI_Zone::setMergeType( int theMergeType, QString theAltitudeName )
247 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
248 if ( !aZone.IsNull() )
250 HYDROData_Zone::MergeAltitudesType aMergeType =
251 ( HYDROData_Zone::MergeAltitudesType )theMergeType;
252 aZone->SetMergeType( aMergeType );
253 if ( aMergeType == HYDROData_Zone::Merge_Object )
255 // Find an altitude object by the given name and set it as the zone's merge altitude
256 HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects();
257 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
258 for ( ; anIter.More(); anIter.Next() )
260 Handle(HYDROData_Object) aRefGeomObj =
261 Handle(HYDROData_Object)::DownCast( anIter.Value() );
262 if ( !aRefGeomObj.IsNull() )
264 // Get altitude object name
265 Handle(HYDROData_IAltitudeObject) anAltitudeObj = aRefGeomObj->GetAltitudeObject();
266 if ( !anAltitudeObj.IsNull() && theAltitudeName == anAltitudeObj->GetName() )
268 aZone->SetMergeAltitude( anAltitudeObj );
278 \brief Check if this object is can't be renamed in place
281 \return \c true if the item can be renamed by the user in place (e.g. in the Object browser)
283 bool HYDROGUI_Zone::renameAllowed( const int id ) const
285 if ( id == NameId && isInOperation() )
289 return HYDROGUI_DataObject::renameAllowed( id );
293 // \brief Set name of this object.
295 // \return \c true if rename operation finished successfully, \c false otherwise.
297 //bool HYDROGUI_Zone::setName(const QString& theName)
299 // if ( isInOperation() )
301 // bool aRes = false;
302 // if ( !theName.isEmpty() )
304 // Handle(HYDROData_Entity) anEntity = modelObject();
305 // CAM_Module* aModule = module();
306 // if( anEntity->GetName() != theName && aModule )
308 // // check that there are no other objects with the same name in the document
309 // Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( aModule, theName );
310 // if ( anObject.IsNull() )
312 // anEntity->SetName( theName );
317 // // Inform the user that the name is already used
318 // QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" );
319 // QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName );
320 // SUIT_MessageBox::critical( getApp()->desktop(), aTitle, aMessage );
327 // aRes = HYDROGUI_DataObject::setName( theName );