// File: TObj_Partition.cxx // Created: Tue Nov 23 11:27:33 2004 // Author: Pavel TELKOV // Copyright: Open CASCADE 2007 // The original implementation Copyright: (C) RINA S.p.A #include #include #include #include IMPLEMENT_STANDARD_HANDLE(TObj_Partition,TObj_Object) IMPLEMENT_STANDARD_RTTIEXT(TObj_Partition,TObj_Object) IMPLEMENT_TOBJOCAF_PERSISTENCE(TObj_Partition) //======================================================================= //function : TObj_Partition //purpose : //======================================================================= TObj_Partition::TObj_Partition (const TDF_Label& theLabel) : TObj_Object( theLabel ) { } //======================================================================= //function : Create //purpose : //======================================================================= Handle(TObj_Partition) TObj_Partition::Create (const TDF_Label& theLabel) { Handle(TObj_Partition) aPartition = new TObj_Partition(theLabel); aPartition->SetLastIndex(0); return aPartition; } //======================================================================= //function : NewLabel //purpose : //======================================================================= TDF_Label TObj_Partition::NewLabel() const { TDF_Label aLabel; TDF_TagSource aTag; aLabel = aTag.NewChild(GetChildLabel()); return aLabel; } //======================================================================= //function : SetNamePrefix //purpose : //======================================================================= void TObj_Partition::SetNamePrefix (const Handle(TCollection_HExtendedString)& thePrefix) { myPrefix = thePrefix; } //======================================================================= //function : NewName //purpose : //======================================================================= Handle(TCollection_HExtendedString) TObj_Partition::GetNewName ( const Standard_Boolean theIsToChangeCount ) { if ( myPrefix.IsNull() ) return 0; Standard_Integer aRank = GetLastIndex()+1; Standard_Integer saveRank = aRank; Handle(TCollection_HExtendedString) aName; do { aName = new TCollection_HExtendedString(myPrefix->String()+aRank++); } while( GetModel()->IsRegisteredName( aName, GetDictionary() ) ); // the last index is increased taking into account only names that are // actually set; the name requested by the current operation can be // dropped later and this will not cause index to be increased if ( theIsToChangeCount && --aRank > saveRank ) SetLastIndex ( aRank ); return aName; } //======================================================================= //function : GetPartition //purpose : //======================================================================= Handle(TObj_Partition) TObj_Partition::GetPartition (const Handle(TObj_Object)& theObject) { Handle(TObj_Partition) aPartition; if(!theObject.IsNull()) { TDF_Label aLabel = theObject->GetLabel().Father(); // find partition which contains the object while(aPartition.IsNull() && !aLabel.IsNull()) { Handle(TObj_Object) anObject; if(TObj_Object::GetObj(aLabel,anObject,Standard_True)) aPartition = Handle(TObj_Partition)::DownCast(anObject); if(aPartition.IsNull()) aLabel = aLabel.Father(); } } return aPartition; } //======================================================================= //function : GetLastIndex //purpose : //======================================================================= Standard_Integer TObj_Partition::GetLastIndex() const { return getInteger(DataTag_LastIndex); } //======================================================================= //function : SetLastIndex //purpose : //======================================================================= void TObj_Partition::SetLastIndex(const Standard_Integer theIndex) { setInteger(theIndex,DataTag_LastIndex); } //======================================================================= //function : copyData //purpose : protected //======================================================================= Standard_Boolean TObj_Partition::copyData (const Handle(TObj_Object)& theTargetObject) { Standard_Boolean IsDone; Handle(TObj_Partition) aTargetPartition = Handle(TObj_Partition)::DownCast(theTargetObject); IsDone = aTargetPartition.IsNull() ? Standard_False : Standard_True; if(IsDone) { IsDone = TObj_Object::copyData(theTargetObject); if ( IsDone ) { aTargetPartition->myPrefix = myPrefix; } } return IsDone; } //======================================================================= //function : SetName //purpose : do not register a name in the dictionary //======================================================================= Standard_Boolean TObj_Partition::SetName(const Handle(TCollection_HExtendedString)& theName) const { Handle(TCollection_HExtendedString) anOldName = GetName(); if( !anOldName.IsNull() && theName->String().IsEqual(anOldName->String()) ) return Standard_True; TDataStd_Name::Set(GetLabel(),theName->String()); return Standard_True; } //======================================================================= //function : AfterRetrieval //purpose : do not register a name in the dictionary //======================================================================= void TObj_Partition::AfterRetrieval() { }