Integration of OCCT 6.5.0 from SVN
[occt.git] / src / StepData / StepData_FreeFormEntity.cxx
1 #include <StepData_FreeFormEntity.ixx>
2 #include <Dico_DictionaryOfTransient.hxx>
3 #include <Dico_IteratorOfDictionaryOfTransient.hxx>
4 #include <Interface_Macros.hxx>
5
6
7
8     void StepData_FreeFormEntity::SetStepType (const Standard_CString typenam)
9       {  thetype.Clear();  thetype.AssignCat (typenam);  }
10
11     Standard_CString  StepData_FreeFormEntity::StepType () const
12       {  return thetype.ToCString();  }
13
14     void  StepData_FreeFormEntity::SetNext
15   (const Handle(StepData_FreeFormEntity)& next, const Standard_Boolean last)
16 {
17   if (next.IsNull()) thenext.Nullify();
18   else if (thenext.IsNull()) thenext = next;
19   else if (last) thenext->SetNext(next);
20   else {
21     next->SetNext(thenext,last);
22     thenext = next;
23   }
24 }
25
26     Handle(StepData_FreeFormEntity)  StepData_FreeFormEntity::Next () const
27       {  return thenext;  }
28
29     Standard_Boolean  StepData_FreeFormEntity::IsComplex () const
30       {  return (!thenext.IsNull());  }
31
32     Handle(StepData_FreeFormEntity)  StepData_FreeFormEntity::Typed
33   (const Standard_CString typenam) const
34 {
35   Handle(StepData_FreeFormEntity) res;
36   if (thetype.IsEqual (typenam)) return this;
37   if (thenext.IsNull()) return res;
38   return thenext->Typed (typenam);
39 }
40
41     Handle(TColStd_HSequenceOfAsciiString)  StepData_FreeFormEntity::TypeList
42   () const
43 {
44   Handle(TColStd_HSequenceOfAsciiString) li = new TColStd_HSequenceOfAsciiString();
45   li->Append (thetype);
46   Handle(StepData_FreeFormEntity) next = thenext;
47   while (!next.IsNull()) {
48     li->Append (TCollection_AsciiString (next->StepType()) );
49     next = next->Next();
50   }
51   return li;
52 }
53
54     Standard_Boolean  StepData_FreeFormEntity::Reorder
55   (Handle(StepData_FreeFormEntity)& ent)
56 {
57   if (ent.IsNull()) return Standard_False;
58   if (!ent->IsComplex()) return Standard_False;
59   Standard_Boolean afr = Standard_False;
60   Handle(StepData_FreeFormEntity) e1 = ent;  Handle(StepData_FreeFormEntity) e2 = ent->Next();
61   while (!e2.IsNull()) {
62     if (strcmp (e1->StepType(), e2->StepType()) > 0) { afr = Standard_True; break; }
63     e1 = e2;  e2 = e1->Next();
64   }
65   if (!afr) return afr;
66 //  remise en ordre avec un dictionnaire
67   e1 = ent;  e2.Nullify();
68   Handle(Dico_DictionaryOfTransient) dic = new Dico_DictionaryOfTransient;
69   while (!e1.IsNull()) {
70     dic->SetItem (e1->StepType(), e1);
71     e1 = e1->Next();
72   }
73 //  d abord effacer les next en cours ...
74   Dico_IteratorOfDictionaryOfTransient iter(dic);
75   for (iter.Start(); iter.More(); iter.Next()) {
76     e1 = GetCasted(StepData_FreeFormEntity,iter.Value());
77     if (!e1.IsNull()) e1->SetNext(e2);
78   }
79 //  ... puis les remettre dans l ordre
80   e1.Nullify();
81   for (iter.Start(); iter.More(); iter.Next()) {
82     e2 = GetCasted(StepData_FreeFormEntity,iter.Value());
83     if (!e1.IsNull()) e1->SetNext(e2);
84     e1 = e2;
85   }
86
87   ent = e1;
88   return afr;
89 }
90
91
92     void  StepData_FreeFormEntity::SetNbFields (const Standard_Integer nb)
93 {
94   if (nb <= 0) thefields.Nullify();
95   else thefields = new StepData_HArray1OfField (1,nb);
96 }
97
98     Standard_Integer  StepData_FreeFormEntity::NbFields () const
99       {  return  (thefields.IsNull() ? 0 : thefields->Length());  }
100
101     const StepData_Field&  StepData_FreeFormEntity::Field
102   (const Standard_Integer num) const
103       {  return thefields->Value(num);  }
104
105     StepData_Field&  StepData_FreeFormEntity::CField
106   (const Standard_Integer num)
107       {  return thefields->ChangeValue(num);  }