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 | |
25e59720 |
28 | IMPLEMENT_STANDARD_RTTIEXT(StepData_UndefinedEntity,Standard_Transient) |
92efcf78 |
29 | |
b311480e |
30 | StepData_UndefinedEntity::StepData_UndefinedEntity () |
7fd59977 |
31 | { thecont = new Interface_UndefinedContent; thesub = Standard_False; } |
32 | |
33 | StepData_UndefinedEntity::StepData_UndefinedEntity |
34 | (const Standard_Boolean issub) |
35 | { thesub = issub; thecont = new Interface_UndefinedContent; } |
36 | |
37 | Handle(Interface_UndefinedContent) |
38 | StepData_UndefinedEntity::UndefinedContent () const |
39 | { return thecont; } |
40 | |
41 | Standard_Boolean StepData_UndefinedEntity::IsSub () const |
42 | { return thesub; } |
43 | |
44 | Standard_Boolean StepData_UndefinedEntity::IsComplex () const |
45 | { return (!thenext.IsNull()); } |
46 | |
47 | Handle(StepData_UndefinedEntity) StepData_UndefinedEntity::Next () const |
48 | { return thenext; } |
49 | |
50 | Standard_CString StepData_UndefinedEntity::StepType () const |
51 | { if (thetype.IsNull()) return ""; return thetype->ToCString(); } |
52 | |
53 | |
54 | void StepData_UndefinedEntity::ReadRecord(const Handle(StepData_StepReaderData)& SR, |
55 | const Standard_Integer num, |
56 | Handle(Interface_Check)& ach) |
57 | { |
58 | thetype = new TCollection_HAsciiString(SR->RecordType(num)); |
59 | Standard_Integer nb = SR->NbParams(num); |
60 | |
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); |
70 | if (nume <= 0) { |
71 | ach->AddFail("A reference to another entity is unresolved"); |
72 | partyp = Interface_ParamVoid; |
73 | } |
74 | else { |
75 | anent = SR->BoundEntity(nume); |
76 | } |
77 | } |
78 | else if (partyp == Interface_ParamSub) { |
79 | nume = SR->ParamNumber(num,i); |
80 | Handle(StepData_UndefinedEntity) und = new StepData_UndefinedEntity (Standard_True); |
81 | anent = und; |
82 | und->ReadRecord(SR,nume,ach); |
83 | } |
84 | else if (partyp == Interface_ParamText) { |
85 | // Return integre a supprimer silya |
7dc9e047 |
86 | Standard_Integer lval = (Standard_Integer)strlen(val); Standard_Integer mval = -1; |
7fd59977 |
87 | for (Standard_Integer j = 0; j < lval; j ++) { |
88 | if (val[j] == '\n') { mval = i; break; } |
89 | } |
90 | if (mval > 0) { |
91 | nume = -1; |
92 | hval = new TCollection_HAsciiString (val); |
93 | hval->RemoveAll('\n'); |
94 | } |
95 | } |
96 | if (nume == 0) hval = new TCollection_HAsciiString (val); |
97 | if (nume > 0) thecont->AddEntity(partyp,anent); |
98 | else thecont->AddLiteral (partyp,hval); |
99 | } |
100 | Standard_Integer nextyp = SR->NextForComplex(num); |
101 | if (nextyp == 0) return; |
102 | thenext = new StepData_UndefinedEntity; |
103 | thenext->ReadRecord(SR,nextyp,ach); |
104 | } |
105 | |
106 | |
107 | void StepData_UndefinedEntity::WriteParams (StepData_StepWriter& SW) const |
108 | { |
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(); |
120 | } |
121 | else if (partyp == Interface_ParamIdent) { |
122 | anent = thecont->ParamEntity(i); |
123 | SW.Send(anent); |
124 | } |
125 | else SW.SendString (thecont->ParamValue(i)->ToCString()); |
126 | } |
127 | // if (IsSub()) return; |
128 | // SW.NewLine(Standard_True); |
129 | if (thenext.IsNull()) return; |
130 | thenext->WriteParams(SW); |
131 | } |
132 | |
133 | void StepData_UndefinedEntity::GetFromAnother |
134 | (const Handle(StepData_UndefinedEntity)& another, |
135 | Interface_CopyTool& TC) |
136 | { |
137 | // DeclareAndCast(StepData_UndefinedEntity,another,other); |
138 | thetype = new TCollection_HAsciiString (another->StepType()); |
139 | thecont = new Interface_UndefinedContent; |
140 | thecont->GetFromAnother(another->UndefinedContent(),TC); |
141 | |
142 | thesub = another->IsSub(); |
143 | if (another->IsComplex()) thenext = |
144 | GetCasted(StepData_UndefinedEntity,TC.Transferred(another->Next())); |
145 | else thenext.Nullify(); |
146 | } |
147 | |
148 | |
149 | void StepData_UndefinedEntity::FillShared |
150 | (Interface_EntityIterator& list) const |
151 | { |
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)); |
160 | } |
161 | } |
162 | if (!thenext.IsNull()) thenext->FillShared (list); |
163 | } |