+ if ( !canCreateNewRule() ) {
+ return false;
+ }
+
+ // Existing pairs of object indexes
+ QStringList aNames = getAvailableObjectNames();
+ QList< QPair<int, int> > aRules;
+ foreach( const HYDROData_CustomRule& aRule, getRules() ) {
+ int anIndex1 = aNames.indexOf( aRule.Object1->GetName() );
+ int anIndex2 = aNames.indexOf( aRule.Object2->GetName() );
+ if ( anIndex1 >= 0 && anIndex2 >= 0 ) {
+ aRules << QPair<int, int>( anIndex1, anIndex2 );
+ aRules << QPair<int, int>( anIndex2, anIndex1 );
+ }
+ }
+
+ // Try to find:
+ // 1. the new pair of objects
+ // 2. the priority type corresponding to the objects order
+ Handle(HYDROData_Entity) anObject1, anObject2;
+ HYDROData_PriorityType aPriorityType = GREATER;
+
+ int aNbObjects = myObjects.count();
+ for ( int anIndex1 = 0; anIndex1 < aNbObjects; anIndex1++ ) {
+ bool isFound = false;
+
+ for ( int anIndex2 = 0; anIndex2 < aNbObjects; anIndex2++ ) {
+ if ( anIndex1 == anIndex2 ) {
+ continue;
+ }
+
+ if ( !aRules.contains( QPair<int, int>( anIndex1, anIndex2 ) ) ) {
+ anObject1 = myObjects.at( anIndex1 );
+ anObject2 = myObjects.at( anIndex2 );
+ if ( anIndex1 > anIndex2 ) {
+ aPriorityType = LESS;
+ }
+ isFound = true;
+ break;
+ }
+ }
+
+ if ( isFound ) {
+ break;
+ }
+ }
+
+ // Create a new rule
+ bool isCreated = false;
+
+ if ( !anObject1.IsNull() && !anObject2.IsNull() ) {
+ HYDROData_CustomRule aNewRule;
+ aNewRule.Object1 = anObject1;
+ aNewRule.Object2 = anObject2;
+ aNewRule.Priority = aPriorityType;
+ aNewRule.MergeType = HYDROData_Zone::Merge_ZMIN;
+
+ beginResetModel();
+ myRules << aNewRule;
+ endResetModel();
+
+ isCreated = true;