+//============================================================================
+/*! Function : GetIndexInFather
+ * Purpose :
+ */
+//============================================================================
+int SALOMEDSImpl_UseCaseBuilder::GetIndexInFather(const SALOMEDSImpl_SObject& theFather,
+ const SALOMEDSImpl_SObject& theObject)
+{
+ int index = -1;
+ if(!_root || !theFather || !theObject) return index;
+
+ DF_Label aFatherLabel = theFather.GetLabel(), aLabel = theObject.GetLabel();
+ if(aFatherLabel == aLabel) return index;
+
+ SALOMEDSImpl_AttributeTreeNode *aFather = NULL, *aNode = NULL;
+
+ if(aFatherLabel.IsNull()) return index;
+ if(!(aFather=(SALOMEDSImpl_AttributeTreeNode*)aFatherLabel.FindAttribute(_root->ID()))) return index;
+
+ if(aLabel.IsNull()) return index;
+ if(!(aNode=(SALOMEDSImpl_AttributeTreeNode*)aLabel.FindAttribute(_root->ID()))) {
+ aNode = SALOMEDSImpl_AttributeTreeNode::Set(aLabel, _root->ID());
+ }
+
+ if ( _lastChild && _lastChild->GetFather() == aFather )
+ {
+ if ( aNode == _lastChild )
+ index = _childIndex;
+ else if ( aNode == _lastChild->GetPrevious())
+ index = _childIndex - 1;
+ else if ( aNode == _lastChild->GetNext())
+ {
+ index = ++_childIndex;
+ _lastChild = aNode;
+ }
+ }
+
+ if ( index < 0 )
+ {
+ SALOMEDSImpl_AttributeTreeNode* Last = aFather->GetFirst();
+ for ( index = 0; Last && aNode != Last && Last->HasNext(); ++index )
+ {
+ Last = Last->GetNext();
+ }
+ if ( Last != aNode )
+ index = -1;
+ else if ( !Last->HasNext() )
+ {
+ _lastChild = Last;
+ _childIndex = index;
+ }
+ }
+
+ return index;
+}
+