]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #1340: first implementation of new zone colors algo
authorasl <asl@opencascade.com>
Fri, 22 Sep 2017 11:55:39 +0000 (14:55 +0300)
committerisn <isn@opencascade.com>
Fri, 27 Oct 2017 18:12:49 +0000 (21:12 +0300)
Conflicts:
src/HYDROGUI/CMakeLists.txt
src/HYDRO_tests/ExternalFiles.cmake
src/HYDRO_tests/reference_data/CMakeLists.txt

src/HYDROGUI/CMakeLists.txt
src/HYDROGUI/HYDROGUI_ZoneTool.cxx [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_ZoneTool.h [new file with mode: 0644]
src/HYDRO_tests/ExternalFiles.cmake
src/HYDRO_tests/reference_data/CMakeLists.txt
src/HYDRO_tests/reference_data/zone_random_colors.png [new file with mode: 0644]

index cdf4d76143dc3005df993f1cb0d19a92a17eae8b..a35f02cfc4d5397ec3868ac425b482c5e7913a86 100644 (file)
@@ -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 (file)
index 0000000..b5b75c4
--- /dev/null
@@ -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 <HYDROGUI_ZoneTool.h>
+#include <HYDROData_Zone.h>
+#include <QColor>
+
+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<Handle(HYDROData_Region)>& 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 (file)
index 0000000..b419544
--- /dev/null
@@ -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 <HYDROData_Region.h>
+
+namespace HYDROGUI_ZoneTool
+{
+  void AssignDefaultColors( const QList<Handle(HYDROData_Region)>&, int theSMargin = 128, int theBMargin = 90 );
+  void AssignDefaultColors( const Handle(HYDROData_Region)&, int theSMargin = 128, int theBMargin = 90 );
+};
+
+
+#endif
index f93423ba664db911f9f4196af8ea2d1eab96b576..0071a1d3770f7f7cff3bc53ca7d8806830a41bbd 100644 (file)
@@ -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
 )
index 8957b0957432814d767b926c28d4f0a2371910ba..c3651f279ff8ed9409689eb482e84693c623a6a7 100644 (file)
@@ -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 (file)
index 0000000..1bf0ab4
Binary files /dev/null and b/src/HYDRO_tests/reference_data/zone_random_colors.png differ