*/
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:
* \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:
/**
#include <HYDROData_PolylineXY.h>
#include <HYDROData_ShapesGroup.h>
#include <HYDROData_Iterator.h>
+#include <HYDROData_ImmersibleZone.h>
#include <HYDROData_Object.h>
#include <HYDROData_Tool.h>
myShowZones = true;
myEditedObject->Update();
+ AssignDefaultZonesColors();
+
//aPanel->setEditedObject( myEditedObject );
aPanel->refreshZonesBrowser();
}
}
+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();
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
}
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) ) )