#include <HYDROData_Document.h>
#include <HYDROData_Iterator.h>
+#include <HYDROData_Zone.h>
#include <GraphicsView_Viewer.h>
}
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;
{
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() )
}
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;
+}
+