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