1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 #include <StepData_UndefinedEntity.ixx>
19 #include <Interface_ParamType.hxx>
20 #include <TCollection_AsciiString.hxx>
21 #include <Interface_Macros.hxx>
25 StepData_UndefinedEntity::StepData_UndefinedEntity ()
26 { thecont = new Interface_UndefinedContent; thesub = Standard_False; }
28 StepData_UndefinedEntity::StepData_UndefinedEntity
29 (const Standard_Boolean issub)
30 { thesub = issub; thecont = new Interface_UndefinedContent; }
32 Handle(Interface_UndefinedContent)
33 StepData_UndefinedEntity::UndefinedContent () const
36 Standard_Boolean StepData_UndefinedEntity::IsSub () const
39 Standard_Boolean StepData_UndefinedEntity::IsComplex () const
40 { return (!thenext.IsNull()); }
42 Handle(StepData_UndefinedEntity) StepData_UndefinedEntity::Next () const
45 Standard_CString StepData_UndefinedEntity::StepType () const
46 { if (thetype.IsNull()) return ""; return thetype->ToCString(); }
49 void StepData_UndefinedEntity::ReadRecord(const Handle(StepData_StepReaderData)& SR,
50 const Standard_Integer num,
51 Handle(Interface_Check)& ach)
53 thetype = new TCollection_HAsciiString(SR->RecordType(num));
54 Standard_Integer nb = SR->NbParams(num);
56 thecont->Reservate (nb,4);
57 for (Standard_Integer i = 1; i <= nb; i ++) {
58 Handle(Standard_Transient) anent;
59 Handle(TCollection_HAsciiString) hval;
60 Standard_CString val = SR->ParamCValue(num,i);
61 Interface_ParamType partyp = SR->ParamType(num,i);
62 Standard_Integer nume = 0;
63 if (partyp == Interface_ParamIdent) {
64 nume = SR->ParamNumber(num,i);
66 ach->AddFail("A reference to another entity is unresolved");
67 partyp = Interface_ParamVoid;
70 anent = SR->BoundEntity(nume);
73 else if (partyp == Interface_ParamSub) {
74 nume = SR->ParamNumber(num,i);
75 Handle(StepData_UndefinedEntity) und = new StepData_UndefinedEntity (Standard_True);
77 und->ReadRecord(SR,nume,ach);
79 else if (partyp == Interface_ParamText) {
80 // Return integre a supprimer silya
81 Standard_Integer lval = strlen(val); Standard_Integer mval = -1;
82 for (Standard_Integer j = 0; j < lval; j ++) {
83 if (val[j] == '\n') { mval = i; break; }
87 hval = new TCollection_HAsciiString (val);
88 hval->RemoveAll('\n');
91 if (nume == 0) hval = new TCollection_HAsciiString (val);
92 if (nume > 0) thecont->AddEntity(partyp,anent);
93 else thecont->AddLiteral (partyp,hval);
95 Standard_Integer nextyp = SR->NextForComplex(num);
96 if (nextyp == 0) return;
97 thenext = new StepData_UndefinedEntity;
98 thenext->ReadRecord(SR,nextyp,ach);
102 void StepData_UndefinedEntity::WriteParams (StepData_StepWriter& SW) const
104 if (!IsSub()) SW.StartEntity(TCollection_AsciiString(StepType()));
105 Standard_Integer nb = thecont->NbParams();
106 Handle(Standard_Transient) anent;
107 for (Standard_Integer i = 1; i <= nb; i ++) {
108 Interface_ParamType partyp = thecont->ParamType(i);
109 if (partyp == Interface_ParamSub) {
110 DeclareAndCast(StepData_UndefinedEntity,und,thecont->ParamEntity(i));
111 und->StepType(); //svv #2
112 if (und->IsSub()) SW.OpenTypedSub (und->StepType());
113 und->WriteParams(SW);
114 if (und->IsSub()) SW.CloseSub();
116 else if (partyp == Interface_ParamIdent) {
117 anent = thecont->ParamEntity(i);
120 else SW.SendString (thecont->ParamValue(i)->ToCString());
122 // if (IsSub()) return;
123 // SW.NewLine(Standard_True);
124 if (thenext.IsNull()) return;
125 thenext->WriteParams(SW);
128 void StepData_UndefinedEntity::GetFromAnother
129 (const Handle(StepData_UndefinedEntity)& another,
130 Interface_CopyTool& TC)
132 // DeclareAndCast(StepData_UndefinedEntity,another,other);
133 thetype = new TCollection_HAsciiString (another->StepType());
134 thecont = new Interface_UndefinedContent;
135 thecont->GetFromAnother(another->UndefinedContent(),TC);
137 thesub = another->IsSub();
138 if (another->IsComplex()) thenext =
139 GetCasted(StepData_UndefinedEntity,TC.Transferred(another->Next()));
140 else thenext.Nullify();
144 void StepData_UndefinedEntity::FillShared
145 (Interface_EntityIterator& list) const
147 Standard_Integer i, nb = thecont->NbParams();
148 for (i = 1; i <= nb; i ++) {
149 Interface_ParamType ptype = thecont->ParamType(i);
150 if (ptype == Interface_ParamSub) {
151 DeclareAndCast(StepData_UndefinedEntity,subent,thecont->ParamEntity(i));
152 subent->FillShared (list);
153 } else if (ptype == Interface_ParamIdent) {
154 list.AddItem(thecont->ParamEntity(i));
157 if (!thenext.IsNull()) thenext->FillShared (list);