1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
15 #include <Interface_Macros.hxx>
16 #include <Standard_Type.hxx>
17 #include <StepData_Field.hxx>
18 #include <StepData_FreeFormEntity.hxx>
19 #include <NCollection_DataMap.hxx>
20 #include <Standard_Transient.hxx>
22 IMPLEMENT_STANDARD_RTTIEXT(StepData_FreeFormEntity,Standard_Transient)
24 void StepData_FreeFormEntity::SetStepType (const Standard_CString typenam)
25 { thetype.Clear(); thetype.AssignCat (typenam); }
27 Standard_CString StepData_FreeFormEntity::StepType () const
28 { return thetype.ToCString(); }
30 void StepData_FreeFormEntity::SetNext
31 (const Handle(StepData_FreeFormEntity)& next, const Standard_Boolean last)
33 if (next.IsNull()) thenext.Nullify();
34 else if (thenext.IsNull()) thenext = next;
35 else if (last) thenext->SetNext(next);
37 next->SetNext(thenext,last);
42 Handle(StepData_FreeFormEntity) StepData_FreeFormEntity::Next () const
45 Standard_Boolean StepData_FreeFormEntity::IsComplex () const
46 { return (!thenext.IsNull()); }
48 Handle(StepData_FreeFormEntity) StepData_FreeFormEntity::Typed
49 (const Standard_CString typenam) const
51 Handle(StepData_FreeFormEntity) res;
52 if (thetype.IsEqual (typenam)) return this;
53 if (thenext.IsNull()) return res;
54 return thenext->Typed (typenam);
57 Handle(TColStd_HSequenceOfAsciiString) StepData_FreeFormEntity::TypeList
60 Handle(TColStd_HSequenceOfAsciiString) li = new TColStd_HSequenceOfAsciiString();
62 Handle(StepData_FreeFormEntity) next = thenext;
63 while (!next.IsNull()) {
64 li->Append (TCollection_AsciiString (next->StepType()) );
70 Standard_Boolean StepData_FreeFormEntity::Reorder
71 (Handle(StepData_FreeFormEntity)& ent)
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();
82 // remise en ordre avec un dictionnaire
83 e1 = ent; e2.Nullify();
84 NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)> dic;
85 while (!e1.IsNull()) {
86 dic.Bind(e1->StepType(), e1);
89 // d abord effacer les next en cours ...
90 NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)>::Iterator iter(dic);
91 for (; iter.More(); iter.Next()) {
92 e1 = GetCasted(StepData_FreeFormEntity,iter.Value());
93 if (!e1.IsNull()) e1->SetNext(e2);
95 // ... puis les remettre dans l ordre
97 for (iter.Reset(); iter.More(); iter.Next()) {
98 e2 = GetCasted(StepData_FreeFormEntity,iter.Value());
99 if (!e1.IsNull()) e1->SetNext(e2);
108 void StepData_FreeFormEntity::SetNbFields (const Standard_Integer nb)
110 if (nb <= 0) thefields.Nullify();
111 else thefields = new StepData_HArray1OfField (1,nb);
114 Standard_Integer StepData_FreeFormEntity::NbFields () const
115 { return (thefields.IsNull() ? 0 : thefields->Length()); }
117 const StepData_Field& StepData_FreeFormEntity::Field
118 (const Standard_Integer num) const
119 { return thefields->Value(num); }
121 StepData_Field& StepData_FreeFormEntity::CField
122 (const Standard_Integer num)
123 { return thefields->ChangeValue(num); }