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_ZoneTool.h>
20 #include <HYDROData_Zone.h>
23 int randHue( int theHue )
25 if( theHue>=0 && theHue<360 )
31 int randValue( int theMin, int theMax )
33 return theMin + rand()%(theMax-theMin);
36 void AssignDefaultColor( const Handle(HYDROData_Zone)& theZone,
37 int theHue, int theSMargin, int theBMargin )
39 int aHue = randHue( theHue );
40 int aSat = randValue( theSMargin, 255 );
41 int aBri = randValue( theBMargin, 255-theBMargin );
43 QColor aColor = QColor::fromHsl( aHue, aSat, aBri );
44 theZone->SetColor( aColor );
47 namespace HYDROGUI_ZoneTool {
49 void AssignDefaultColors( const QList<Handle(HYDROData_Region)>& theRegions, int theSMargin, int theBMargin )
51 foreach( Handle(HYDROData_Region) region, theRegions )
52 AssignDefaultColors( region, theSMargin, theBMargin );
55 void AssignDefaultColors( const Handle(HYDROData_Region)& theRegion, int theSMargin, int theBMargin )
57 int aHue = randHue( -1 );
58 HYDROData_SequenceOfObjects zones = theRegion->GetZones();
59 HYDROData_SequenceOfObjects::Iterator zonesIt( zones );
60 for( ; zonesIt.More(); zonesIt.Next() )
62 Handle(HYDROData_Zone) aZone =
63 Handle(HYDROData_Zone)::DownCast( zonesIt.Value() );
64 AssignDefaultColor( aZone, aHue, theSMargin, theBMargin );
68 void AssignDefaultColors( const HYDROData_SequenceOfObjects& theRegions, int theSMargin, int theBMargin )
70 for ( int i = 1; i <= theRegions.Length(); i++ )
71 AssignDefaultColors( Handle(HYDROData_Region)::DownCast(theRegions(i)), theSMargin, theBMargin );