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_Check.hxx>
16 #include <Interface_CopyTool.hxx>
17 #include <Interface_EntityIterator.hxx>
18 #include <Interface_Macros.hxx>
19 #include <Interface_ParamType.hxx>
20 #include <Interface_UndefinedContent.hxx>
21 #include <Standard_Type.hxx>
22 #include <StepData_StepReaderData.hxx>
23 #include <StepData_StepWriter.hxx>
24 #include <StepData_UndefinedEntity.hxx>
25 #include <TCollection_AsciiString.hxx>
26 #include <TCollection_HAsciiString.hxx>
28 IMPLEMENT_STANDARD_RTTIEXT(StepData_UndefinedEntity,Standard_Transient)
30 StepData_UndefinedEntity::StepData_UndefinedEntity ()
31 { thecont = new Interface_UndefinedContent; thesub = Standard_False; }
33 StepData_UndefinedEntity::StepData_UndefinedEntity
34 (const Standard_Boolean issub)
35 { thesub = issub; thecont = new Interface_UndefinedContent; }
37 Handle(Interface_UndefinedContent)
38 StepData_UndefinedEntity::UndefinedContent () const
41 Standard_Boolean StepData_UndefinedEntity::IsSub () const
44 Standard_Boolean StepData_UndefinedEntity::IsComplex () const
45 { return (!thenext.IsNull()); }
47 Handle(StepData_UndefinedEntity) StepData_UndefinedEntity::Next () const
50 Standard_CString StepData_UndefinedEntity::StepType () const
51 { if (thetype.IsNull()) return ""; return thetype->ToCString(); }
54 void StepData_UndefinedEntity::ReadRecord(const Handle(StepData_StepReaderData)& SR,
55 const Standard_Integer num,
56 Handle(Interface_Check)& ach)
58 thetype = new TCollection_HAsciiString(SR->RecordType(num));
59 Standard_Integer nb = SR->NbParams(num);
61 thecont->Reservate (nb,4);
62 for (Standard_Integer i = 1; i <= nb; i ++) {
63 Handle(Standard_Transient) anent;
64 Handle(TCollection_HAsciiString) hval;
65 Standard_CString val = SR->ParamCValue(num,i);
66 Interface_ParamType partyp = SR->ParamType(num,i);
67 Standard_Integer nume = 0;
68 if (partyp == Interface_ParamIdent) {
69 nume = SR->ParamNumber(num,i);
71 ach->AddFail("A reference to another entity is unresolved");
72 partyp = Interface_ParamVoid;
75 anent = SR->BoundEntity(nume);
78 else if (partyp == Interface_ParamSub) {
79 nume = SR->ParamNumber(num,i);
80 Handle(StepData_UndefinedEntity) und = new StepData_UndefinedEntity (Standard_True);
82 und->ReadRecord(SR,nume,ach);
84 else if (partyp == Interface_ParamText) {
85 // Return integre a supprimer silya
86 Standard_Integer lval = (Standard_Integer)strlen(val); Standard_Integer mval = -1;
87 for (Standard_Integer j = 0; j < lval; j ++) {
88 if (val[j] == '\n') { mval = i; break; }
92 hval = new TCollection_HAsciiString (val);
93 hval->RemoveAll('\n');
96 if (nume == 0) hval = new TCollection_HAsciiString (val);
97 if (nume > 0) thecont->AddEntity(partyp,anent);
98 else thecont->AddLiteral (partyp,hval);
100 Standard_Integer nextyp = SR->NextForComplex(num);
101 if (nextyp == 0) return;
102 thenext = new StepData_UndefinedEntity;
103 thenext->ReadRecord(SR,nextyp,ach);
107 void StepData_UndefinedEntity::WriteParams (StepData_StepWriter& SW) const
109 if (!IsSub()) SW.StartEntity(TCollection_AsciiString(StepType()));
110 Standard_Integer nb = thecont->NbParams();
111 Handle(Standard_Transient) anent;
112 for (Standard_Integer i = 1; i <= nb; i ++) {
113 Interface_ParamType partyp = thecont->ParamType(i);
114 if (partyp == Interface_ParamSub) {
115 DeclareAndCast(StepData_UndefinedEntity,und,thecont->ParamEntity(i));
116 und->StepType(); //svv #2
117 if (und->IsSub()) SW.OpenTypedSub (und->StepType());
118 und->WriteParams(SW);
119 if (und->IsSub()) SW.CloseSub();
121 else if (partyp == Interface_ParamIdent) {
122 anent = thecont->ParamEntity(i);
125 else SW.SendString (thecont->ParamValue(i)->ToCString());
127 // if (IsSub()) return;
128 // SW.NewLine(Standard_True);
129 if (thenext.IsNull()) return;
130 thenext->WriteParams(SW);
133 void StepData_UndefinedEntity::GetFromAnother
134 (const Handle(StepData_UndefinedEntity)& another,
135 Interface_CopyTool& TC)
137 // DeclareAndCast(StepData_UndefinedEntity,another,other);
138 thetype = new TCollection_HAsciiString (another->StepType());
139 thecont = new Interface_UndefinedContent;
140 thecont->GetFromAnother(another->UndefinedContent(),TC);
142 thesub = another->IsSub();
143 if (another->IsComplex()) thenext =
144 GetCasted(StepData_UndefinedEntity,TC.Transferred(another->Next()));
145 else thenext.Nullify();
149 void StepData_UndefinedEntity::FillShared
150 (Interface_EntityIterator& list) const
152 Standard_Integer i, nb = thecont->NbParams();
153 for (i = 1; i <= nb; i ++) {
154 Interface_ParamType ptype = thecont->ParamType(i);
155 if (ptype == Interface_ParamSub) {
156 DeclareAndCast(StepData_UndefinedEntity,subent,thecont->ParamEntity(i));
157 subent->FillShared (list);
158 } else if (ptype == Interface_ParamIdent) {
159 list.AddItem(thecont->ParamEntity(i));
162 if (!thenext.IsNull()) thenext->FillShared (list);