Salome HOME
Modify creation of curves: 1) using QDockWidget instead of QDialog; 2) selection...
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Tool.cxx
index 3e11ed93c7fb9c6e41857d074af667362137a3ca..4650f24e36a5c2bd2115d005c9576c8ea7762f70 100644 (file)
@@ -29,6 +29,7 @@
 
 #include <HYDROData_Document.h>
 #include <HYDROData_Iterator.h>
+#include <HYDROData_Zone.h>
 
 #include <GraphicsView_Viewer.h>
 
@@ -301,30 +302,62 @@ ObjectKind HYDROGUI_Tool::GetSelectedPartition( HYDROGUI_Module* theModule )
 }
 
 Handle(HYDROData_Object) HYDROGUI_Tool::FindObjectByName( HYDROGUI_Module* theModule,
-                                                          const QString& theName,
+                                                          const QString&   theName,
                                                           const ObjectKind theObjectKind )
 {
   Handle(HYDROData_Object) anObject;
+  if ( theName.isEmpty() )
+    return anObject;
+
+  QStringList aNamesList;
+  aNamesList << theName;
+
+  HYDROData_SequenceOfObjects aSeqOfObjs = FindObjectsByNames( theModule, aNamesList, theObjectKind );
+  if( aSeqOfObjs.IsEmpty() )
+    return anObject;
+  
+  anObject = aSeqOfObjs.First();
+  return anObject;
+}
+
+HYDROData_SequenceOfObjects HYDROGUI_Tool::FindObjectsByNames( HYDROGUI_Module*   theModule,
+                                                               const QStringList& theNames,
+                                                               const ObjectKind   theObjectKind )
+{
+  HYDROData_SequenceOfObjects aResSeq;
+  if ( theNames.isEmpty() )
+    return aResSeq;
 
   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
   if( aDocument.IsNull() )
-    return anObject;
+    return aResSeq;
+
+  QStringList aNamesList = theNames;
 
   HYDROData_Iterator anIter( aDocument, theObjectKind );
   for( ; anIter.More(); anIter.Next() )
   {
     Handle(HYDROData_Object) anObjectRef = anIter.Current();
-    if( !anObjectRef.IsNull() && anObjectRef->GetName() == theName )
-    {
-      anObject = anObjectRef;
+    if( anObjectRef.IsNull() )
+      continue;
+
+    QString anObjName = anObjectRef->GetName();
+    if ( anObjName.isEmpty() || !aNamesList.contains( anObjName ) )
+      continue;
+
+    aResSeq.Append( anObjectRef );
+
+    aNamesList.removeAll( anObjName );
+    if ( aNamesList.isEmpty() )
       break;
-    }
   }
-  return anObject;
+
+  return aResSeq;
 }
 
-QString HYDROGUI_Tool::GenerateObjectName( HYDROGUI_Module* theModule,
-                                           const QString& thePrefix )
+QString HYDROGUI_Tool::GenerateObjectName( HYDROGUI_Module*   theModule,
+                                           const QString&     thePrefix,
+                                           const QStringList& theUsedNames )
 {
   QString aName;
   int anId = 1;
@@ -332,6 +365,9 @@ QString HYDROGUI_Tool::GenerateObjectName( HYDROGUI_Module* theModule,
   {
     aName = QString( "%1_%2" ).arg( thePrefix ).arg( QString::number( anId++ ) );
 
+    if ( theUsedNames.contains( aName ) )
+      continue;
+
     // check that there are no other objects with the same name in the document
     Handle(HYDROData_Object) anObject = FindObjectByName( theModule, aName, KIND_UNKNOWN );
     if( anObject.IsNull() )
@@ -444,3 +480,35 @@ QDockWidget* HYDROGUI_Tool::WindowDock( QWidget* wid )
   }
   return dock;
 }
+
+QColor HYDROGUI_Tool::GenerateFillingColor( HYDROGUI_Module*   theModule,
+                                            const QStringList& theZoneNames )
+{
+  QColor aFillingColor( HYDROData_Zone::DefaultFillingColor() );
+
+  int aCounter = 0;
+  int aR = 0, aG = 0, aB = 0;
+  QStringListIterator aZoneNameIter( theZoneNames );
+  while( aZoneNameIter.hasNext() )
+  {
+    const QString& aZoneName = aZoneNameIter.next();
+    Handle(HYDROData_Zone) aRefZone = Handle(HYDROData_Zone)::DownCast(
+      FindObjectByName( theModule, aZoneName, KIND_ZONE ) );
+    if( !aRefZone.IsNull() )
+    {
+      QColor aRefColor = aRefZone->GetFillingColor();
+      aR += aRefColor.red();
+      aG += aRefColor.green();
+      aB += aRefColor.blue();
+      aCounter++;
+    }
+  }
+  
+  if( aCounter > 0 )
+  {
+    aFillingColor = QColor( aR / aCounter, aG / aCounter, aB / aCounter );
+  }
+
+  return aFillingColor;
+}
+