From: mkr Date: Wed, 13 May 2015 14:03:31 +0000 (+0300) Subject: refs #525: autocolor of zones in a calculation case. X-Git-Tag: v1.4.1~21^2~7 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a67db4d469efef157ce7d7f3abc33a1942f3fd51;p=modules%2Fhydro.git refs #525: autocolor of zones in a calculation case. --- diff --git a/src/HYDROData/HYDROData_Entity.h b/src/HYDROData/HYDROData_Entity.h index 9ed01046..b4fd34b9 100644 --- a/src/HYDROData/HYDROData_Entity.h +++ b/src/HYDROData/HYDROData_Entity.h @@ -241,6 +241,20 @@ public: */ void findPythonReferenceObject( MapOfTreatedObjects& theTreatedObjects, QStringList& theScript ) const; + + /** + * Internal method that used to store the color attribute + * \param theTag tag of a label that keeps the attribute (for 0 this is myLab) + * \param theColor color to save + */ + HYDRODATA_EXPORT void SetColor( const QColor& theColor, const int theTag = 0 ); + + /** + * Internal method that used to retreive the color attribute + * \param theTag tag of a label that keeps the attribute (for 0 this is myLab) + * \param theDefColor default color to return if attribute has not been set before + */ + HYDRODATA_EXPORT QColor GetColor( const QColor& theDefColor, const int theTag = 0 ) const; protected: @@ -369,21 +383,7 @@ protected: * \param theTag tag of a label that keeps the attribute (for 0 this is myLab) */ void ClearReferenceObjects( const int theTag = 0 ); - - /** - * Internal method that used to store the color attribute - * \param theTag tag of a label that keeps the attribute (for 0 this is myLab) - * \param theColor color to save - */ - void SetColor( const QColor& theColor, const int theTag = 0 ); - - /** - * Internal method that used to retreive the color attribute - * \param theTag tag of a label that keeps the attribute (for 0 this is myLab) - * \param theDefColor default color to return if attribute has not been set before - */ - QColor GetColor( const QColor& theDefColor, const int theTag = 0 ) const; - + protected: /** diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx index 0e996779..015a6a87 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -716,6 +717,8 @@ void HYDROGUI_CalculationOp::onNext( const int theIndex ) myShowZones = true; myEditedObject->Update(); + AssignDefaultZonesColors(); + //aPanel->setEditedObject( myEditedObject ); aPanel->refreshZonesBrowser(); @@ -783,6 +786,77 @@ void HYDROGUI_CalculationOp::setZonesVisible( bool theIsVisible ) } } +void HYDROGUI_CalculationOp::AssignDefaultZonesColors() +{ + HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions(); + HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions ); + HYDROData_SequenceOfObjects aZones; + Handle(HYDROData_Region) aRegion; + if ( myPreviewViewManager ) + { + if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() ) + { + Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext(); + if ( !aCtx.IsNull() ) + { + int aCounter = 0; + for ( ; aRegionsIter.More(); aRegionsIter.Next() ) + { + aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() ); + if ( !aRegion.IsNull() ) + { + aZones = aRegion->GetZones(); + HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones ); + for ( ; aZonesIter.More(); aZonesIter.Next() ) + { + // Zone + Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() ); + if ( !aZone.IsNull() ) + { + QColor aFillingColor = GenerateDefaultZonesColor(++aCounter); + while (aFillingColor == Qt::red) + aFillingColor = GenerateDefaultZonesColor(++aCounter); + + aZone->SetColor(aFillingColor); + } + } + } + } + } + } + } +} + +QColor HYDROGUI_CalculationOp::GenerateDefaultZonesColor( int theIndex, + float theSaturation/* = 0.5*/, + float theValue/* = 0.95*/ ) const +{ + float aGoldenRatioConjugate = (float)(360./582.); + float aHue = (float)rand(); + aHue += aGoldenRatioConjugate*theIndex; + aHue -= floor(aHue); + + float aR = 0., aG = 0., aB = 0.; + int aHueInt = (int)(aHue*6.); + float aF = aHue*6. - aHueInt; + float aP = theValue * (1. - theSaturation); + float aQ = theValue * (1. - aF*theSaturation); + float aT = theValue * (1. - (1. - aF) * theSaturation); + switch (aHueInt) + { + case 0: { aR = theValue; aG = aT; aB = aP; break; } + case 1: { aR = aQ; aG = theValue; aB = aP; break; } + case 2: { aR = aP; aG = theValue; aB = aT; break; } + case 3: { aR = aP; aG = aQ; aB = theValue; break; } + case 4: { aR = aT; aG = aP; aB = theValue; break; } + case 5: { aR = theValue; aG = aP; aB = aQ; break; } + default: break; + } + + QColor aColor = QColor( (int)(aR*256.), (int)(aG*256.), (int)(aB*256.) ); + return ( aColor.isValid() ? aColor : HYDROData_ImmersibleZone::DefaultFillingColor() ); +} + void HYDROGUI_CalculationOp::createPreview() { LightApp_Application* anApp = module()->getApp(); diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.h b/src/HYDROGUI/HYDROGUI_CalculationOp.h index 993f2c17..3658ae5b 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.h +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.h @@ -127,6 +127,26 @@ private: void getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq, QStringList& theNames, QStringList& theEntries ) const; + /** + * Internal method that used to assign unique default colors for zones + */ + void AssignDefaultZonesColors(); + /** + * Internal method that used to generate default color for zone + * @param theIndex the index of color to be generated + * @param theSaturation the saturation of the color in the range 0 to 1, + * and the bigger it is, the stronger the color is. Grayish colors have + * saturation near 0, very strong colors have saturation near 1. + * The defalt value is 0.5. + * @param theValue the value in the range 0 to 1, represents lightness or + * brightness of the color. 0 is black, 1 is as far from black as possible. + * The defalt value is 0.95. + * \return the generated color + */ + QColor GenerateDefaultZonesColor( int theIndex, + float theSaturation = 0.5, + float theValue = 0.95 ) const; + /** * Ask user to confirm splitting zones recalculation after regions list modification. * \return true if confirmed diff --git a/src/HYDROGUI/HYDROGUI_Shape.cxx b/src/HYDROGUI/HYDROGUI_Shape.cxx index c54bb9e0..08900fbe 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.cxx +++ b/src/HYDROGUI/HYDROGUI_Shape.cxx @@ -225,26 +225,8 @@ void HYDROGUI_Shape::update( bool isUpdateViewer, } else { - // Generate the filling color for zone - QStringList aGeomObjectsNames; - - HYDROData_SequenceOfObjects aRefObjects = aZone->GetGeometryObjects(); - HYDROData_SequenceOfObjects::Iterator anIter( aRefObjects ); - for ( ; anIter.More(); anIter.Next() ) - { - Handle(HYDROData_Object) aRefbject = - Handle(HYDROData_Object)::DownCast( anIter.Value() ); - if ( aRefbject.IsNull() ) - continue; - - QString aRefObjectName = aRefbject->GetName(); - if ( aRefObjectName.isEmpty() ) - continue; - - aGeomObjectsNames.append( aRefObjectName ); - } - - setFillingColor( HYDROGUI_Tool::GenerateFillingColor( aDocument, aGeomObjectsNames ) ); + // Set the filling color for zone + setFillingColor( aZone->GetColor(HYDROData_ImmersibleZone::DefaultFillingColor()) ); } } else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Profile) ) )