1 // File: TObj_Partition.cxx
2 // Created: Tue Nov 23 11:27:33 2004
3 // Author: Pavel TELKOV
4 // Copyright: Open CASCADE 2007
5 // The original implementation Copyright: (C) RINA S.p.A
7 #include <TObj_Partition.hxx>
9 #include <TObj_Model.hxx>
10 #include <TObj_TNameContainer.hxx>
12 #include <TDataStd_Name.hxx>
14 IMPLEMENT_STANDARD_HANDLE(TObj_Partition,TObj_Object)
15 IMPLEMENT_STANDARD_RTTIEXT(TObj_Partition,TObj_Object)
16 IMPLEMENT_TOBJOCAF_PERSISTENCE(TObj_Partition)
18 //=======================================================================
19 //function : TObj_Partition
21 //=======================================================================
23 TObj_Partition::TObj_Partition (const TDF_Label& theLabel)
24 : TObj_Object( theLabel )
28 //=======================================================================
31 //=======================================================================
33 Handle(TObj_Partition) TObj_Partition::Create
34 (const TDF_Label& theLabel)
36 Handle(TObj_Partition) aPartition =
37 new TObj_Partition(theLabel);
38 aPartition->SetLastIndex(0);
42 //=======================================================================
45 //=======================================================================
47 TDF_Label TObj_Partition::NewLabel() const
51 aLabel = aTag.NewChild(GetChildLabel());
55 //=======================================================================
56 //function : SetNamePrefix
58 //=======================================================================
60 void TObj_Partition::SetNamePrefix
61 (const Handle(TCollection_HExtendedString)& thePrefix)
62 { myPrefix = thePrefix; }
64 //=======================================================================
67 //=======================================================================
69 Handle(TCollection_HExtendedString) TObj_Partition::GetNewName
70 ( const Standard_Boolean theIsToChangeCount )
72 if ( myPrefix.IsNull() ) return 0;
74 Standard_Integer aRank = GetLastIndex()+1;
75 Standard_Integer saveRank = aRank;
76 Handle(TCollection_HExtendedString) aName;
79 aName = new TCollection_HExtendedString(myPrefix->String()+aRank++);
80 } while( GetModel()->IsRegisteredName( aName, GetDictionary() ) );
82 // the last index is increased taking into account only names that are
83 // actually set; the name requested by the current operation can be
84 // dropped later and this will not cause index to be increased
85 if ( theIsToChangeCount && --aRank > saveRank )
86 SetLastIndex ( aRank );
90 //=======================================================================
91 //function : GetPartition
93 //=======================================================================
95 Handle(TObj_Partition) TObj_Partition::GetPartition
96 (const Handle(TObj_Object)& theObject)
98 Handle(TObj_Partition) aPartition;
99 if(!theObject.IsNull())
101 TDF_Label aLabel = theObject->GetLabel().Father();
103 // find partition which contains the object
104 while(aPartition.IsNull() && !aLabel.IsNull())
106 Handle(TObj_Object) anObject;
107 if(TObj_Object::GetObj(aLabel,anObject,Standard_True))
108 aPartition = Handle(TObj_Partition)::DownCast(anObject);
110 if(aPartition.IsNull())
111 aLabel = aLabel.Father();
117 //=======================================================================
118 //function : GetLastIndex
120 //=======================================================================
122 Standard_Integer TObj_Partition::GetLastIndex() const
124 return getInteger(DataTag_LastIndex);
127 //=======================================================================
128 //function : SetLastIndex
130 //=======================================================================
132 void TObj_Partition::SetLastIndex(const Standard_Integer theIndex)
134 setInteger(theIndex,DataTag_LastIndex);
137 //=======================================================================
138 //function : copyData
139 //purpose : protected
140 //=======================================================================
142 Standard_Boolean TObj_Partition::copyData
143 (const Handle(TObj_Object)& theTargetObject)
145 Standard_Boolean IsDone;
146 Handle(TObj_Partition) aTargetPartition =
147 Handle(TObj_Partition)::DownCast(theTargetObject);
148 IsDone = aTargetPartition.IsNull() ? Standard_False : Standard_True;
151 IsDone = TObj_Object::copyData(theTargetObject);
154 aTargetPartition->myPrefix = myPrefix;
160 //=======================================================================
162 //purpose : do not register a name in the dictionary
163 //=======================================================================
165 Standard_Boolean TObj_Partition::SetName(const Handle(TCollection_HExtendedString)& theName) const
167 Handle(TCollection_HExtendedString) anOldName = GetName();
168 if( !anOldName.IsNull() && theName->String().IsEqual(anOldName->String()) )
169 return Standard_True;
171 TDataStd_Name::Set(GetLabel(),theName->String());
172 return Standard_True;
175 //=======================================================================
176 //function : AfterRetrieval
177 //purpose : do not register a name in the dictionary
178 //=======================================================================
180 void TObj_Partition::AfterRetrieval()