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.
14 #include <StepData_UndefinedEntity.ixx>
15 #include <Interface_ParamType.hxx>
16 #include <TCollection_AsciiString.hxx>
17 #include <Interface_Macros.hxx>
21 StepData_UndefinedEntity::StepData_UndefinedEntity ()
22 { thecont = new Interface_UndefinedContent; thesub = Standard_False; }
24 StepData_UndefinedEntity::StepData_UndefinedEntity
25 (const Standard_Boolean issub)
26 { thesub = issub; thecont = new Interface_UndefinedContent; }
28 Handle(Interface_UndefinedContent)
29 StepData_UndefinedEntity::UndefinedContent () const
32 Standard_Boolean StepData_UndefinedEntity::IsSub () const
35 Standard_Boolean StepData_UndefinedEntity::IsComplex () const
36 { return (!thenext.IsNull()); }
38 Handle(StepData_UndefinedEntity) StepData_UndefinedEntity::Next () const
41 Standard_CString StepData_UndefinedEntity::StepType () const
42 { if (thetype.IsNull()) return ""; return thetype->ToCString(); }
45 void StepData_UndefinedEntity::ReadRecord(const Handle(StepData_StepReaderData)& SR,
46 const Standard_Integer num,
47 Handle(Interface_Check)& ach)
49 thetype = new TCollection_HAsciiString(SR->RecordType(num));
50 Standard_Integer nb = SR->NbParams(num);
52 thecont->Reservate (nb,4);
53 for (Standard_Integer i = 1; i <= nb; i ++) {
54 Handle(Standard_Transient) anent;
55 Handle(TCollection_HAsciiString) hval;
56 Standard_CString val = SR->ParamCValue(num,i);
57 Interface_ParamType partyp = SR->ParamType(num,i);
58 Standard_Integer nume = 0;
59 if (partyp == Interface_ParamIdent) {
60 nume = SR->ParamNumber(num,i);
62 ach->AddFail("A reference to another entity is unresolved");
63 partyp = Interface_ParamVoid;
66 anent = SR->BoundEntity(nume);
69 else if (partyp == Interface_ParamSub) {
70 nume = SR->ParamNumber(num,i);
71 Handle(StepData_UndefinedEntity) und = new StepData_UndefinedEntity (Standard_True);
73 und->ReadRecord(SR,nume,ach);
75 else if (partyp == Interface_ParamText) {
76 // Return integre a supprimer silya
77 Standard_Integer lval = (Standard_Integer)strlen(val); Standard_Integer mval = -1;
78 for (Standard_Integer j = 0; j < lval; j ++) {
79 if (val[j] == '\n') { mval = i; break; }
83 hval = new TCollection_HAsciiString (val);
84 hval->RemoveAll('\n');
87 if (nume == 0) hval = new TCollection_HAsciiString (val);
88 if (nume > 0) thecont->AddEntity(partyp,anent);
89 else thecont->AddLiteral (partyp,hval);
91 Standard_Integer nextyp = SR->NextForComplex(num);
92 if (nextyp == 0) return;
93 thenext = new StepData_UndefinedEntity;
94 thenext->ReadRecord(SR,nextyp,ach);
98 void StepData_UndefinedEntity::WriteParams (StepData_StepWriter& SW) const
100 if (!IsSub()) SW.StartEntity(TCollection_AsciiString(StepType()));
101 Standard_Integer nb = thecont->NbParams();
102 Handle(Standard_Transient) anent;
103 for (Standard_Integer i = 1; i <= nb; i ++) {
104 Interface_ParamType partyp = thecont->ParamType(i);
105 if (partyp == Interface_ParamSub) {
106 DeclareAndCast(StepData_UndefinedEntity,und,thecont->ParamEntity(i));
107 und->StepType(); //svv #2
108 if (und->IsSub()) SW.OpenTypedSub (und->StepType());
109 und->WriteParams(SW);
110 if (und->IsSub()) SW.CloseSub();
112 else if (partyp == Interface_ParamIdent) {
113 anent = thecont->ParamEntity(i);
116 else SW.SendString (thecont->ParamValue(i)->ToCString());
118 // if (IsSub()) return;
119 // SW.NewLine(Standard_True);
120 if (thenext.IsNull()) return;
121 thenext->WriteParams(SW);
124 void StepData_UndefinedEntity::GetFromAnother
125 (const Handle(StepData_UndefinedEntity)& another,
126 Interface_CopyTool& TC)
128 // DeclareAndCast(StepData_UndefinedEntity,another,other);
129 thetype = new TCollection_HAsciiString (another->StepType());
130 thecont = new Interface_UndefinedContent;
131 thecont->GetFromAnother(another->UndefinedContent(),TC);
133 thesub = another->IsSub();
134 if (another->IsComplex()) thenext =
135 GetCasted(StepData_UndefinedEntity,TC.Transferred(another->Next()));
136 else thenext.Nullify();
140 void StepData_UndefinedEntity::FillShared
141 (Interface_EntityIterator& list) const
143 Standard_Integer i, nb = thecont->NbParams();
144 for (i = 1; i <= nb; i ++) {
145 Interface_ParamType ptype = thecont->ParamType(i);
146 if (ptype == Interface_ParamSub) {
147 DeclareAndCast(StepData_UndefinedEntity,subent,thecont->ParamEntity(i));
148 subent->FillShared (list);
149 } else if (ptype == Interface_ParamIdent) {
150 list.AddItem(thecont->ParamEntity(i));
153 if (!thenext.IsNull()) thenext->FillShared (list);