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 anent = SR->BoundEntity(nume);
77 ach->AddFail("A reference to another entity is unresolved");
78 partyp = Interface_ParamVoid;
81 else if (partyp == Interface_ParamSub) {
82 nume = SR->ParamNumber(num,i);
83 Handle(StepData_UndefinedEntity) und = new StepData_UndefinedEntity (Standard_True);
85 und->ReadRecord(SR,nume,ach);
87 else if (partyp == Interface_ParamText) {
88 // Return integre a supprimer silya
89 Standard_Integer lval = (Standard_Integer)strlen(val); Standard_Integer mval = -1;
90 for (Standard_Integer j = 0; j < lval; j ++) {
91 if (val[j] == '\n') { mval = i; break; }
95 hval = new TCollection_HAsciiString (val);
96 hval->RemoveAll('\n');
99 if (nume == 0) hval = new TCollection_HAsciiString (val);
100 if (nume > 0) thecont->AddEntity(partyp,anent);
101 else thecont->AddLiteral (partyp,hval);
103 Standard_Integer nextyp = SR->NextForComplex(num);
104 if (nextyp == 0) return;
105 thenext = new StepData_UndefinedEntity;
106 thenext->ReadRecord(SR,nextyp,ach);
110 void StepData_UndefinedEntity::WriteParams (StepData_StepWriter& SW) const
112 if (!IsSub()) SW.StartEntity(TCollection_AsciiString(StepType()));
113 Standard_Integer nb = thecont->NbParams();
114 Handle(Standard_Transient) anent;
115 for (Standard_Integer i = 1; i <= nb; i ++) {
116 Interface_ParamType partyp = thecont->ParamType(i);
117 if (partyp == Interface_ParamSub) {
118 DeclareAndCast(StepData_UndefinedEntity,und,thecont->ParamEntity(i));
119 und->StepType(); //svv #2
120 if (und->IsSub()) SW.OpenTypedSub (und->StepType());
121 und->WriteParams(SW);
122 if (und->IsSub()) SW.CloseSub();
124 else if (partyp == Interface_ParamIdent) {
125 anent = thecont->ParamEntity(i);
128 else SW.SendString (thecont->ParamValue(i)->ToCString());
130 // if (IsSub()) return;
131 // SW.NewLine(Standard_True);
132 if (thenext.IsNull()) return;
133 thenext->WriteParams(SW);
136 void StepData_UndefinedEntity::GetFromAnother
137 (const Handle(StepData_UndefinedEntity)& another,
138 Interface_CopyTool& TC)
140 // DeclareAndCast(StepData_UndefinedEntity,another,other);
141 thetype = new TCollection_HAsciiString (another->StepType());
142 thecont = new Interface_UndefinedContent;
143 thecont->GetFromAnother(another->UndefinedContent(),TC);
145 thesub = another->IsSub();
146 if (another->IsComplex()) thenext =
147 GetCasted(StepData_UndefinedEntity,TC.Transferred(another->Next()));
148 else thenext.Nullify();
152 void StepData_UndefinedEntity::FillShared
153 (Interface_EntityIterator& list) const
155 Standard_Integer i, nb = thecont->NbParams();
156 for (i = 1; i <= nb; i ++) {
157 Interface_ParamType ptype = thecont->ParamType(i);
158 if (ptype == Interface_ParamSub) {
159 DeclareAndCast(StepData_UndefinedEntity,subent,thecont->ParamEntity(i));
160 subent->FillShared (list);
161 } else if (ptype == Interface_ParamIdent) {
162 list.AddItem(thecont->ParamEntity(i));
165 if (!thenext.IsNull()) thenext->FillShared (list);