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