Salome HOME
Merge remote-tracking branch 'origin/BR_1323_0' into BR_2017
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ZoneTool.cxx
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.
6 //
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.
11 //
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
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include <HYDROGUI_ZoneTool.h>
20 #include <HYDROData_Zone.h>
21 #include <QColor>
22
23 int randHue( int theHue )
24 {
25   if( theHue>=0 && theHue<360 )
26     return theHue;
27   else
28     return rand()%360;
29 }
30
31 int randValue( int theMin, int theMax )
32 {
33   return theMin + rand()%(theMax-theMin);
34 }
35
36 void AssignDefaultColor( const Handle(HYDROData_Zone)& theZone,
37                          int theHue, int theSMargin, int theBMargin )
38 {
39   int aHue = randHue( theHue );
40   int aSat = randValue( theSMargin, 255 );
41   int aBri = randValue( theBMargin, 255-theBMargin );
42
43   QColor aColor = QColor::fromHsl( aHue, aSat, aBri );
44   theZone->SetColor( aColor );
45 }
46
47 namespace HYDROGUI_ZoneTool { 
48
49 void AssignDefaultColors( const QList<Handle(HYDROData_Region)>& theRegions, int theSMargin, int theBMargin )
50 {
51   foreach( Handle(HYDROData_Region) region, theRegions )
52     AssignDefaultColors( region, theSMargin, theBMargin );
53 }
54
55 void AssignDefaultColors( const Handle(HYDROData_Region)& theRegion, int theSMargin, int theBMargin )
56 {
57   int aHue = randHue( -1 );
58   HYDROData_SequenceOfObjects zones = theRegion->GetZones();
59   HYDROData_SequenceOfObjects::Iterator zonesIt( zones );
60   for( ; zonesIt.More(); zonesIt.Next() )
61   {
62     Handle(HYDROData_Zone) aZone =
63       Handle(HYDROData_Zone)::DownCast( zonesIt.Value() );
64     AssignDefaultColor( aZone, aHue, theSMargin, theBMargin );
65   }
66 }
67
68 void AssignDefaultColors( const HYDROData_SequenceOfObjects& theRegions, int theSMargin, int theBMargin )
69 {
70   for ( int i = 1; i <= theRegions.Length(); i++ )
71     AssignDefaultColors( Handle(HYDROData_Region)::DownCast(theRegions(i)), theSMargin, theBMargin );
72 }
73
74 };