From: asl Date: Fri, 22 Sep 2017 11:55:39 +0000 (+0300) Subject: refs #1340: first implementation of new zone colors algo X-Git-Tag: v2.1~58^2~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c15120b32e5441fb56054664ccd94d9e8ae80094;p=modules%2Fhydro.git refs #1340: first implementation of new zone colors algo Conflicts: src/HYDROGUI/CMakeLists.txt src/HYDRO_tests/ExternalFiles.cmake src/HYDRO_tests/reference_data/CMakeLists.txt --- diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index cdf4d761..a35f02cf 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -147,6 +147,7 @@ set(PROJECT_HEADERS HYDROGUI_SetTransparencyOp.h HYDROGUI_TransparencyDlg.h HYDROGUI_Overview.h + HYDROGUI_ZoneTool.h ) QT_WRAP_MOC(PROJECT_HEADERS_MOC ${PROJECT_HEADERS}) @@ -296,6 +297,7 @@ set(PROJECT_SOURCES HYDROGUI_SetTransparencyOp.cxx HYDROGUI_TransparencyDlg.cxx HYDROGUI_Overview.cxx + HYDROGUI_ZoneTool.cxx ) add_definitions( diff --git a/src/HYDROGUI/HYDROGUI_ZoneTool.cxx b/src/HYDROGUI/HYDROGUI_ZoneTool.cxx new file mode 100644 index 00000000..b5b75c4f --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_ZoneTool.cxx @@ -0,0 +1,69 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include +#include +#include + +int randHue( int theHue ) +{ + if( theHue>=0 && theHue<360 ) + return theHue; + else + return rand()%360; +} + +int randValue( int theMin, int theMax ) +{ + return theMin + rand()%(theMax-theMin); +} + +void AssignDefaultColor( const Handle(HYDROData_Zone)& theZone, + int theHue, int theSMargin, int theBMargin ) +{ + int aHue = randHue( theHue ); + int aSat = randValue( theSMargin, 255 ); + int aBri = randValue( theBMargin, 255-theBMargin ); + + QColor aColor = QColor::fromHsl( aHue, aSat, aBri ); + theZone->SetColor( aColor ); +} + +namespace HYDROGUI_ZoneTool { + +void AssignDefaultColors( const QList& theRegions, int theSMargin, int theBMargin ) +{ + foreach( Handle(HYDROData_Region) region, theRegions ) + AssignDefaultColors( region, theSMargin, theBMargin ); +} + +void AssignDefaultColors( const Handle(HYDROData_Region)& theRegion, int theSMargin, int theBMargin ) +{ + int aHue = randHue( -1 ); + HYDROData_SequenceOfObjects zones = theRegion->GetZones(); + HYDROData_SequenceOfObjects::Iterator zonesIt( zones ); + for( ; zonesIt.More(); zonesIt.Next() ) + { + Handle(HYDROData_Zone) aZone = + Handle(HYDROData_Zone)::DownCast( zonesIt.Value() ); + AssignDefaultColor( aZone, aHue, theSMargin, theBMargin ); + } +} + + +}; diff --git a/src/HYDROGUI/HYDROGUI_ZoneTool.h b/src/HYDROGUI/HYDROGUI_ZoneTool.h new file mode 100644 index 00000000..b419544b --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_ZoneTool.h @@ -0,0 +1,31 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef HYDROGUI_ZoneTool_H +#define HYDROGUI_ZoneTool_H + +#include + +namespace HYDROGUI_ZoneTool +{ + void AssignDefaultColors( const QList&, int theSMargin = 128, int theBMargin = 90 ); + void AssignDefaultColors( const Handle(HYDROData_Region)&, int theSMargin = 128, int theBMargin = 90 ); +}; + + +#endif diff --git a/src/HYDRO_tests/ExternalFiles.cmake b/src/HYDRO_tests/ExternalFiles.cmake index f93423ba..0071a1d3 100644 --- a/src/HYDRO_tests/ExternalFiles.cmake +++ b/src/HYDRO_tests/ExternalFiles.cmake @@ -78,6 +78,7 @@ set( EXTERNAL_FILES ../HYDROGUI/HYDROGUI_ListSelector.cxx ../HYDROGUI/HYDROGUI_OrderedListWidget.cxx ../HYDROGUI/HYDROGUI_Overview.cxx + ../HYDROGUI/HYDROGUI_ZoneTool.cxx ../HYDROGUI/HYDROGUI_ProfileDlg.cxx ../HYDROGUI/HYDROGUI_ViewerDlg.cxx ../HYDROGUI/HYDROGUI_AISTrihedron.cxx @@ -91,6 +92,7 @@ set( MOC_HEADERS ../HYDROGUI/HYDROGUI_ListSelector.h ../HYDROGUI/HYDROGUI_OrderedListWidget.h ../HYDROGUI/HYDROGUI_Overview.h + ../HYDROGUI/HYDROGUI_ZoneTool.h ../HYDROGUI/HYDROGUI_ProfileDlg.h ../HYDROGUI/HYDROGUI_ViewerDlg.h ) diff --git a/src/HYDRO_tests/reference_data/CMakeLists.txt b/src/HYDRO_tests/reference_data/CMakeLists.txt index 8957b095..c3651f27 100644 --- a/src/HYDRO_tests/reference_data/CMakeLists.txt +++ b/src/HYDRO_tests/reference_data/CMakeLists.txt @@ -143,6 +143,7 @@ SET(REFERENCE_DATA bathy_rescaled_visible.png bathy_text_labels.png bathy_prs_fit_selected.png + zone_random_colors.png ) # Application tests diff --git a/src/HYDRO_tests/reference_data/zone_random_colors.png b/src/HYDRO_tests/reference_data/zone_random_colors.png new file mode 100644 index 00000000..1bf0ab4c Binary files /dev/null and b/src/HYDRO_tests/reference_data/zone_random_colors.png differ