${KERNEL_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/src/SKETCHER
${CMAKE_CURRENT_SOURCE_DIR}
+ ${PROJECT_BINARY_DIR}/idl
)
# additional preprocessor / compiler flags
ADD_DEFINITIONS(
${OpenCASCADE_DEFINITIONS}
+ ${OMNIORB_DEFINITIONS}
)
# libraries to link to
${KERNEL_SALOMELocalTrace}
${KERNEL_OpUtil}
GEOMSketcher
+ ${QT_LIBRARIES}
)
# --- headers ---
GEOM_PythonDump.hxx
GEOM_DataMapOfAsciiStringTransient.hxx
GEOM_BaseObject.hxx
+ GEOM_ColorUtils.hxx
)
# --- sources ---
GEOM_BaseDriver.cxx
GEOM_SubShapeDriver.cxx
GEOM_PythonDump.cxx
+ GEOM_ColorUtils.cxx
)
# --- rules ---
--- /dev/null
+// Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// 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 "GEOM_ColorUtils.hxx"
+
+#include <QRandomGenerator>
+#include <QColor>
+
+
+SALOMEDS::Color GEOM_ColorUtils::getPredefinedUniqueColor()
+{
+ static QList<QColor> colors = []() {
+ QList<QColor> tempColors;
+ for (int s = 0; s < 2; s++)
+ {
+ for (int v = 100; v >= 40; v = v - 20)
+ {
+ for (int h = 0; h < 359; h = h + 60)
+ {
+ tempColors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
+ }
+ }
+ }
+ return tempColors;
+ }();
+
+ static int currentColor = randomize(colors.size());
+
+ SALOMEDS::Color color;
+ color.R = (double)colors[currentColor].red() / 255.0;
+ color.G = (double)colors[currentColor].green() / 255.0;
+ color.B = (double)colors[currentColor].blue() / 255.0;
+
+ currentColor = (currentColor+1) % colors.count();
+
+ return color;
+}
+
+int GEOM_ColorUtils::randomize(int size)
+{
+ return QRandomGenerator::global()->bounded(size);
+}
\ No newline at end of file
--- /dev/null
+// Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// 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 GEOMUTILS_COLOR_HXX
+#define GEOMUTILS_COLOR_HXX
+
+#include "SALOMEDS_Attributes.hh"
+
+#include <Standard_Macro.hxx>
+
+
+class GEOM_ColorUtils
+{
+public:
+ Standard_EXPORT static SALOMEDS::Color getPredefinedUniqueColor();
+
+private:
+ Standard_EXPORT static int randomize(int size);
+};
+
+#endif // GEOMUTILS_COLOR_HXX
\ No newline at end of file
#include "GEOM_Object.hxx"
+#include "GEOM_Engine.hxx"
+#include "GEOM_ColorUtils.hxx"
+
#include <TDataStd_Integer.hxx>
#include <TDataStd_Real.hxx>
#include <TDataStd_RealArray.hxx>
void GEOM_Object::SetAutoColor(bool theAutoColor)
{
TDataStd_Integer::Set(_label.FindChild(AUTO_COLOR_LABEL), (int)theAutoColor);
+
+ // Set color for the object here, othrewise it will stay default forever, despite
+ // the color displayed in viewver being defined on GEOM_Displayer::getColor() call.
+ // It's not clear if we need to reset color when auto color is disabled.
+ if (theAutoColor)
+ {
+ const SALOMEDS::Color color = GEOM_ColorUtils::getPredefinedUniqueColor();
+ SetColor({ color.R, color.G, color.B });
+ }
+
+ // Set color for all sub-shapes objects
+ SetAutoColorSubShapes(theAutoColor);
}
//=============================================================================
return funs;
}
+//=============================================================================
+/*!
+ * Toggles an auto color mode for sub-shapes of GEOM_Object
+ */
+//=============================================================================
+void GEOM_Object::SetAutoColorSubShapes(bool theAutoColor)
+{
+ const int nbFunctions = GetNbFunctions();
+ for (int i = 1; i <= nbFunctions; i++)
+ {
+ Handle(GEOM_Function) aFunction = GetFunction(i);
+ if (aFunction.IsNull())
+ continue;
+
+ const TDataStd_ListOfExtendedString& aListEntries = aFunction->GetSubShapeReferences();
+ for (TDataStd_ListIteratorOfListOfExtendedString anIt(aListEntries); anIt.More(); anIt.Next())
+ {
+ const TCollection_AsciiString anEntry = anIt.Value();
+ Handle(GEOM_Object) aSubObj =
+ Handle(GEOM_Object)::DownCast(GEOM_Engine::GetEngine()->GetObject(anEntry.ToCString(), false));
+ if (aSubObj.IsNull())
+ continue;
+
+ aSubObj->SetAutoColor(theAutoColor);
+ }
+ }
+}
+
+
IMPLEMENT_STANDARD_RTTIEXT(GEOM_Object, GEOM_BaseObject )
Standard_EXPORT static Handle(TColStd_HSequenceOfTransient)
GetLastFunctions( const std::list< Handle(GEOM_Object) >& theObjects );
+protected:
+ // Toggles an auto color mode for sub-shapes of GEOM_Object
+ Standard_EXPORT void SetAutoColorSubShapes(bool theAutoColor);
+
public:
DEFINE_STANDARD_RTTIEXT(GEOM_Object,GEOM_BaseObject)
};
${PROJECT_SOURCE_DIR}/src/GEOMImpl
${PROJECT_SOURCE_DIR}/src/GEOMUtils
${PROJECT_SOURCE_DIR}/src/GEOM_I
+ ${PROJECT_SOURCE_DIR}/src/GEOM
${CMAKE_CURRENT_SOURCE_DIR}
)
#include <GEOMGUI_AnnotationMgr.h>
#include <GEOMUtils.hxx>
+#include "GEOM_ColorUtils.hxx"
#include <Material_Model.h>
}
}
}
-
- uint randomize( uint size )
- {
- static bool initialized = false;
- if ( !initialized ) {
- qsrand( QDateTime::currentDateTime().toTime_t() );
- initialized = true;
- }
- uint v = qrand();
- v = uint( (double)( v ) / RAND_MAX * size );
- v = qMax( uint(0), qMin ( v, size-1 ) );
- return v;
- }
} // namespace
//================================================================
return myHasDisplayMode;
}
-SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
-{
- static QList<QColor> colors;
-
- if ( colors.isEmpty() ) {
-
- for (int s = 0; s < 2 ; s++)
- {
- for (int v = 100; v >= 40; v = v - 20)
- {
- for (int h = 0; h < 359 ; h = h + 60)
- {
- colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
- }
- }
- }
- }
-
- static int currentColor = randomize( colors.size() );
-
- SALOMEDS::Color color;
- color.R = (double)colors[currentColor].red() / 255.0;
- color.G = (double)colors[currentColor].green() / 255.0;
- color.B = (double)colors[currentColor].blue() / 255.0;
-
- currentColor = (currentColor+1) % colors.count();
-
- return color;
-}
-
SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
{
int aHue = -1;
GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
#ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
- aSColor = getPredefinedUniqueColor();
+ aSColor = GEOM_ColorUtils::getPredefinedUniqueColor();
hasColor = true;
#else // old algorithm for auto-colors
QList<SALOMEDS::Color> aReservedColors;
SalomeApp_Study* getStudy() const;
static SALOMEDS::Color getUniqueColor( const QList<SALOMEDS::Color>& );
- static SALOMEDS::Color getPredefinedUniqueColor();
/*Get color of the geom object*/
static SALOMEDS::Color getColor(GEOM::GEOM_Object_var aGeomObject, bool& hasColor);
${PROJECT_SOURCE_DIR}/src/Material
${PROJECT_SOURCE_DIR}/src/DependencyTree
${PROJECT_SOURCE_DIR}/src/GEOMUtils
+ ${PROJECT_SOURCE_DIR}/src/GEOM
${CMAKE_CURRENT_SOURCE_DIR}
)
#include "GEOMToolsGUI_MaterialPropertiesDlg.h"
#include "GEOMToolsGUI_LineWidthDlg.h"
#include "GEOMToolsGUI_ReduceStudyDlg.h"
+#include "GEOM_ColorUtils.hxx"
#include <Material_Model.h>
#include <GEOM_VTKPropertyMaterial.hxx>
#endif // GENERAL_AUTOCOLOR
#ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
- SALOMEDS::Color aColor = GEOM_Displayer::getPredefinedUniqueColor();
+ SALOMEDS::Color aColor = GEOM_ColorUtils::getPredefinedUniqueColor();
#else // old algorithm for auto-colors
SALOMEDS::Color aColor = GEOM_Displayer::getUniqueColor( aReservedColors );
aReservedColors.append( aColor );
--- /dev/null
+#!/usr/bin/env python3
+# Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
+#
+# 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
+#
+
+# Testing of setting and getting an automatically set color
+
+import salome
+salome.salome_init()
+
+from salome.geom import geomBuilder
+geompy = geomBuilder.New()
+
+# Create a box and extract its faces
+Box_1 = geompy.MakeBoxDXDYDZ(200, 200, 200)
+faces = geompy.ExtractShapes(Box_1, geompy.ShapeType["FACE"], True)
+Box_1.SetAutoColor(1)
+geompy.addToStudy(Box_1, 'Box_1')
+
+# Add each face to the study with a numeric name
+for i, face in enumerate(faces, start=1):
+ geompy.addToStudyInFather(Box_1, face, f'Face_{i}')
+
+# Check color of each face
+for face in faces:
+ color = face.GetColor()
+ print(f'{face.GetName()}: {color}')
+ assert color.R != -1 and color.G != -1 and color.B != -1, 'Auto color must be different than (-1, -1, -1)'
\ No newline at end of file
SET(ALL_TESTS
test_perf_01.py
test_patch_face_01.py
+ test_set_autocolor.py
)
IF(${OpenCASCADE_VERSION}.${OpenCASCADE_SP_VERSION} VERSION_GREATER "7.5.3.3")