summaryrefslogtreecommitdiff
path: root/src/TObj/TObj_Partition.cxx
blob: 58f32b4552da9ec6175d1ccca4c0d73f864ead19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// 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 <TObj_Partition.hxx>

#include <TObj_Model.hxx>
#include <TObj_TNameContainer.hxx>

#include <TDataStd_Name.hxx>

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()
{
}