0028832: MMgt_TShared can be replaced by Standard_Transient
[occt.git] / src / StepData / StepData_FreeFormEntity.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
42cf5bc1 14
7fd59977 15#include <Interface_Macros.hxx>
42cf5bc1 16#include <Standard_Type.hxx>
17#include <StepData_Field.hxx>
18#include <StepData_FreeFormEntity.hxx>
997e128f 19#include <NCollection_DataMap.hxx>
20#include <Standard_Transient.hxx>
7fd59977 21
25e59720 22IMPLEMENT_STANDARD_RTTIEXT(StepData_FreeFormEntity,Standard_Transient)
92efcf78 23
b311480e 24void StepData_FreeFormEntity::SetStepType (const Standard_CString typenam)
7fd59977 25 { thetype.Clear(); thetype.AssignCat (typenam); }
26
27 Standard_CString StepData_FreeFormEntity::StepType () const
28 { return thetype.ToCString(); }
29
30 void StepData_FreeFormEntity::SetNext
31 (const Handle(StepData_FreeFormEntity)& next, const Standard_Boolean last)
32{
33 if (next.IsNull()) thenext.Nullify();
34 else if (thenext.IsNull()) thenext = next;
35 else if (last) thenext->SetNext(next);
36 else {
37 next->SetNext(thenext,last);
38 thenext = next;
39 }
40}
41
42 Handle(StepData_FreeFormEntity) StepData_FreeFormEntity::Next () const
43 { return thenext; }
44
45 Standard_Boolean StepData_FreeFormEntity::IsComplex () const
46 { return (!thenext.IsNull()); }
47
48 Handle(StepData_FreeFormEntity) StepData_FreeFormEntity::Typed
49 (const Standard_CString typenam) const
50{
51 Handle(StepData_FreeFormEntity) res;
52 if (thetype.IsEqual (typenam)) return this;
53 if (thenext.IsNull()) return res;
54 return thenext->Typed (typenam);
55}
56
57 Handle(TColStd_HSequenceOfAsciiString) StepData_FreeFormEntity::TypeList
58 () const
59{
60 Handle(TColStd_HSequenceOfAsciiString) li = new TColStd_HSequenceOfAsciiString();
61 li->Append (thetype);
62 Handle(StepData_FreeFormEntity) next = thenext;
63 while (!next.IsNull()) {
64 li->Append (TCollection_AsciiString (next->StepType()) );
65 next = next->Next();
66 }
67 return li;
68}
69
70 Standard_Boolean StepData_FreeFormEntity::Reorder
71 (Handle(StepData_FreeFormEntity)& ent)
72{
73 if (ent.IsNull()) return Standard_False;
74 if (!ent->IsComplex()) return Standard_False;
75 Standard_Boolean afr = Standard_False;
76 Handle(StepData_FreeFormEntity) e1 = ent; Handle(StepData_FreeFormEntity) e2 = ent->Next();
77 while (!e2.IsNull()) {
78 if (strcmp (e1->StepType(), e2->StepType()) > 0) { afr = Standard_True; break; }
79 e1 = e2; e2 = e1->Next();
80 }
81 if (!afr) return afr;
82// remise en ordre avec un dictionnaire
83 e1 = ent; e2.Nullify();
997e128f 84 NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)> dic;
7fd59977 85 while (!e1.IsNull()) {
997e128f 86 dic.Bind(e1->StepType(), e1);
7fd59977 87 e1 = e1->Next();
88 }
89// d abord effacer les next en cours ...
997e128f 90 NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)>::Iterator iter(dic);
91 for (; iter.More(); iter.Next()) {
7fd59977 92 e1 = GetCasted(StepData_FreeFormEntity,iter.Value());
93 if (!e1.IsNull()) e1->SetNext(e2);
94 }
95// ... puis les remettre dans l ordre
96 e1.Nullify();
997e128f 97 for (iter.Reset(); iter.More(); iter.Next()) {
7fd59977 98 e2 = GetCasted(StepData_FreeFormEntity,iter.Value());
99 if (!e1.IsNull()) e1->SetNext(e2);
100 e1 = e2;
101 }
102
103 ent = e1;
104 return afr;
105}
106
107
108 void StepData_FreeFormEntity::SetNbFields (const Standard_Integer nb)
109{
110 if (nb <= 0) thefields.Nullify();
111 else thefields = new StepData_HArray1OfField (1,nb);
112}
113
114 Standard_Integer StepData_FreeFormEntity::NbFields () const
115 { return (thefields.IsNull() ? 0 : thefields->Length()); }
116
117 const StepData_Field& StepData_FreeFormEntity::Field
118 (const Standard_Integer num) const
119 { return thefields->Value(num); }
120
121 StepData_Field& StepData_FreeFormEntity::CField
122 (const Standard_Integer num)
123 { return thefields->ChangeValue(num); }