1 // Created on: 2004-11-23
2 // Created by: Pavel TELKOV
3 // Copyright (c) 2004-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 // The original implementation Copyright: (C) RINA S.p.A
18 #include <TObj_Partition.hxx>
20 #include <TObj_Model.hxx>
21 #include <TObj_TNameContainer.hxx>
23 #include <TDataStd_Name.hxx>
26 IMPLEMENT_TOBJOCAF_PERSISTENCE(TObj_Partition)
28 //=======================================================================
29 //function : TObj_Partition
31 //=======================================================================
33 TObj_Partition::TObj_Partition (const TDF_Label& theLabel)
34 : TObj_Object( theLabel )
38 //=======================================================================
41 //=======================================================================
43 Handle(TObj_Partition) TObj_Partition::Create
44 (const TDF_Label& theLabel)
46 Handle(TObj_Partition) aPartition =
47 new TObj_Partition(theLabel);
48 aPartition->SetLastIndex(0);
52 //=======================================================================
55 //=======================================================================
57 TDF_Label TObj_Partition::NewLabel() const
61 aLabel = aTag.NewChild(GetChildLabel());
65 //=======================================================================
66 //function : SetNamePrefix
68 //=======================================================================
70 void TObj_Partition::SetNamePrefix
71 (const Handle(TCollection_HExtendedString)& thePrefix)
72 { myPrefix = thePrefix; }
74 //=======================================================================
77 //=======================================================================
79 Handle(TCollection_HExtendedString) TObj_Partition::GetNewName
80 ( const Standard_Boolean theIsToChangeCount )
82 if ( myPrefix.IsNull() ) return 0;
84 Standard_Integer aRank = GetLastIndex()+1;
85 Standard_Integer saveRank = aRank;
86 Handle(TCollection_HExtendedString) aName;
89 aName = new TCollection_HExtendedString(myPrefix->String()+aRank++);
90 } while( GetModel()->IsRegisteredName( aName, GetDictionary() ) );
92 // the last index is increased taking into account only names that are
93 // actually set; the name requested by the current operation can be
94 // dropped later and this will not cause index to be increased
95 if ( theIsToChangeCount && --aRank > saveRank )
96 SetLastIndex ( aRank );
100 //=======================================================================
101 //function : GetPartition
103 //=======================================================================
105 Handle(TObj_Partition) TObj_Partition::GetPartition
106 (const Handle(TObj_Object)& theObject)
108 Handle(TObj_Partition) aPartition;
109 if(!theObject.IsNull())
111 TDF_Label aLabel = theObject->GetLabel().Father();
113 // find partition which contains the object
114 while(aPartition.IsNull() && !aLabel.IsNull())
116 Handle(TObj_Object) anObject;
117 if(TObj_Object::GetObj(aLabel,anObject,Standard_True))
118 aPartition = Handle(TObj_Partition)::DownCast(anObject);
120 if(aPartition.IsNull())
121 aLabel = aLabel.Father();
127 //=======================================================================
128 //function : GetLastIndex
130 //=======================================================================
132 Standard_Integer TObj_Partition::GetLastIndex() const
134 return getInteger(DataTag_LastIndex);
137 //=======================================================================
138 //function : SetLastIndex
140 //=======================================================================
142 void TObj_Partition::SetLastIndex(const Standard_Integer theIndex)
144 setInteger(theIndex,DataTag_LastIndex);
147 //=======================================================================
148 //function : copyData
149 //purpose : protected
150 //=======================================================================
152 Standard_Boolean TObj_Partition::copyData
153 (const Handle(TObj_Object)& theTargetObject)
155 Standard_Boolean IsDone;
156 Handle(TObj_Partition) aTargetPartition =
157 Handle(TObj_Partition)::DownCast(theTargetObject);
158 IsDone = aTargetPartition.IsNull() ? Standard_False : Standard_True;
161 IsDone = TObj_Object::copyData(theTargetObject);
164 aTargetPartition->myPrefix = myPrefix;
170 //=======================================================================
172 //purpose : do not register a name in the dictionary
173 //=======================================================================
175 Standard_Boolean TObj_Partition::SetName(const Handle(TCollection_HExtendedString)& theName) const
177 Handle(TCollection_HExtendedString) anOldName = GetName();
178 if( !anOldName.IsNull() && theName->String().IsEqual(anOldName->String()) )
179 return Standard_True;
181 TDataStd_Name::Set(GetLabel(),theName->String());
182 return Standard_True;
185 //=======================================================================
186 //function : AfterRetrieval
187 //purpose : do not register a name in the dictionary
188 //=======================================================================
190 void TObj_Partition::AfterRetrieval()