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 | |
15 | #include <Interface_Check.hxx> |
16 | #include <Interface_CopyTool.hxx> |
17 | #include <Interface_EntityIterator.hxx> |
18 | #include <Interface_Macros.hxx> |
7fd59977 |
19 | #include <Interface_ParamType.hxx> |
42cf5bc1 |
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> |
7fd59977 |
25 | #include <TCollection_AsciiString.hxx> |
42cf5bc1 |
26 | #include <TCollection_HAsciiString.hxx> |
7fd59977 |
27 | |
b311480e |
28 | StepData_UndefinedEntity::StepData_UndefinedEntity () |
7fd59977 |
29 | { thecont = new Interface_UndefinedContent; thesub = Standard_False; } |
30 | |
31 | StepData_UndefinedEntity::StepData_UndefinedEntity |
32 | (const Standard_Boolean issub) |
33 | { thesub = issub; thecont = new Interface_UndefinedContent; } |
34 | |
35 | Handle(Interface_UndefinedContent) |
36 | StepData_UndefinedEntity::UndefinedContent () const |
37 | { return thecont; } |
38 | |
39 | Standard_Boolean StepData_UndefinedEntity::IsSub () const |
40 | { return thesub; } |
41 | |
42 | Standard_Boolean StepData_UndefinedEntity::IsComplex () const |
43 | { return (!thenext.IsNull()); } |
44 | |
45 | Handle(StepData_UndefinedEntity) StepData_UndefinedEntity::Next () const |
46 | { return thenext; } |
47 | |
48 | Standard_CString StepData_UndefinedEntity::StepType () const |
49 | { if (thetype.IsNull()) return ""; return thetype->ToCString(); } |
50 | |
51 | |
52 | void StepData_UndefinedEntity::ReadRecord(const Handle(StepData_StepReaderData)& SR, |
53 | const Standard_Integer num, |
54 | Handle(Interface_Check)& ach) |
55 | { |
56 | thetype = new TCollection_HAsciiString(SR->RecordType(num)); |
57 | Standard_Integer nb = SR->NbParams(num); |
58 | |
59 | thecont->Reservate (nb,4); |
60 | for (Standard_Integer i = 1; i <= nb; i ++) { |
61 | Handle(Standard_Transient) anent; |
62 | Handle(TCollection_HAsciiString) hval; |
63 | Standard_CString val = SR->ParamCValue(num,i); |
64 | Interface_ParamType partyp = SR->ParamType(num,i); |
65 | Standard_Integer nume = 0; |
66 | if (partyp == Interface_ParamIdent) { |
67 | nume = SR->ParamNumber(num,i); |
68 | if (nume <= 0) { |
69 | ach->AddFail("A reference to another entity is unresolved"); |
70 | partyp = Interface_ParamVoid; |
71 | } |
72 | else { |
73 | anent = SR->BoundEntity(nume); |
74 | } |
75 | } |
76 | else if (partyp == Interface_ParamSub) { |
77 | nume = SR->ParamNumber(num,i); |
78 | Handle(StepData_UndefinedEntity) und = new StepData_UndefinedEntity (Standard_True); |
79 | anent = und; |
80 | und->ReadRecord(SR,nume,ach); |
81 | } |
82 | else if (partyp == Interface_ParamText) { |
83 | // Return integre a supprimer silya |
7dc9e047 |
84 | Standard_Integer lval = (Standard_Integer)strlen(val); Standard_Integer mval = -1; |
7fd59977 |
85 | for (Standard_Integer j = 0; j < lval; j ++) { |
86 | if (val[j] == '\n') { mval = i; break; } |
87 | } |
88 | if (mval > 0) { |
89 | nume = -1; |
90 | hval = new TCollection_HAsciiString (val); |
91 | hval->RemoveAll('\n'); |
92 | } |
93 | } |
94 | if (nume == 0) hval = new TCollection_HAsciiString (val); |
95 | if (nume > 0) thecont->AddEntity(partyp,anent); |
96 | else thecont->AddLiteral (partyp,hval); |
97 | } |
98 | Standard_Integer nextyp = SR->NextForComplex(num); |
99 | if (nextyp == 0) return; |
100 | thenext = new StepData_UndefinedEntity; |
101 | thenext->ReadRecord(SR,nextyp,ach); |
102 | } |
103 | |
104 | |
105 | void StepData_UndefinedEntity::WriteParams (StepData_StepWriter& SW) const |
106 | { |
107 | if (!IsSub()) SW.StartEntity(TCollection_AsciiString(StepType())); |
108 | Standard_Integer nb = thecont->NbParams(); |
109 | Handle(Standard_Transient) anent; |
110 | for (Standard_Integer i = 1; i <= nb; i ++) { |
111 | Interface_ParamType partyp = thecont->ParamType(i); |
112 | if (partyp == Interface_ParamSub) { |
113 | DeclareAndCast(StepData_UndefinedEntity,und,thecont->ParamEntity(i)); |
114 | und->StepType(); //svv #2 |
115 | if (und->IsSub()) SW.OpenTypedSub (und->StepType()); |
116 | und->WriteParams(SW); |
117 | if (und->IsSub()) SW.CloseSub(); |
118 | } |
119 | else if (partyp == Interface_ParamIdent) { |
120 | anent = thecont->ParamEntity(i); |
121 | SW.Send(anent); |
122 | } |
123 | else SW.SendString (thecont->ParamValue(i)->ToCString()); |
124 | } |
125 | // if (IsSub()) return; |
126 | // SW.NewLine(Standard_True); |
127 | if (thenext.IsNull()) return; |
128 | thenext->WriteParams(SW); |
129 | } |
130 | |
131 | void StepData_UndefinedEntity::GetFromAnother |
132 | (const Handle(StepData_UndefinedEntity)& another, |
133 | Interface_CopyTool& TC) |
134 | { |
135 | // DeclareAndCast(StepData_UndefinedEntity,another,other); |
136 | thetype = new TCollection_HAsciiString (another->StepType()); |
137 | thecont = new Interface_UndefinedContent; |
138 | thecont->GetFromAnother(another->UndefinedContent(),TC); |
139 | |
140 | thesub = another->IsSub(); |
141 | if (another->IsComplex()) thenext = |
142 | GetCasted(StepData_UndefinedEntity,TC.Transferred(another->Next())); |
143 | else thenext.Nullify(); |
144 | } |
145 | |
146 | |
147 | void StepData_UndefinedEntity::FillShared |
148 | (Interface_EntityIterator& list) const |
149 | { |
150 | Standard_Integer i, nb = thecont->NbParams(); |
151 | for (i = 1; i <= nb; i ++) { |
152 | Interface_ParamType ptype = thecont->ParamType(i); |
153 | if (ptype == Interface_ParamSub) { |
154 | DeclareAndCast(StepData_UndefinedEntity,subent,thecont->ParamEntity(i)); |
155 | subent->FillShared (list); |
156 | } else if (ptype == Interface_ParamIdent) { |
157 | list.AddItem(thecont->ParamEntity(i)); |
158 | } |
159 | } |
160 | if (!thenext.IsNull()) thenext->FillShared (list); |
161 | } |