0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / IGESData / IGESData_UndefinedEntity.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14
15 #include <IGESData_ColorEntity.hxx>
16 #include <IGESData_DirPart.hxx>
17 #include <IGESData_IGESReaderData.hxx>
18 #include <IGESData_IGESWriter.hxx>
19 #include <IGESData_LabelDisplayEntity.hxx>
20 #include <IGESData_LevelListEntity.hxx>
21 #include <IGESData_LineFontEntity.hxx>
22 #include <IGESData_ParamReader.hxx>
23 #include <IGESData_TransfEntity.hxx>
24 #include <IGESData_UndefinedEntity.hxx>
25 #include <IGESData_ViewKindEntity.hxx>
26 #include <Interface_Check.hxx>
27 #include <Interface_Macros.hxx>
28 #include <Interface_UndefinedContent.hxx>
29 #include <Message_Msg.hxx>
30 #include <Standard_Type.hxx>
31 #include <TCollection_AsciiString.hxx>
32 #include <TCollection_HAsciiString.hxx>
33
34 IMPLEMENT_STANDARD_RTTIEXT(IGESData_UndefinedEntity,IGESData_IGESEntity)
35
36 // MGE 23/07/98
37 //=======================================================================
38 //function : IGESData_UndefinedEntity
39 //purpose  : 
40 //=======================================================================
41 IGESData_UndefinedEntity::IGESData_UndefinedEntity ()
42 {
43   thecont = new Interface_UndefinedContent;
44 }
45
46
47 //=======================================================================
48 //function : UndefinedContent
49 //purpose  : 
50 //=======================================================================
51
52 Handle(Interface_UndefinedContent) IGESData_UndefinedEntity::UndefinedContent () const
53 {
54   return thecont;
55 }
56
57
58 //=======================================================================
59 //function : ChangeableContent
60 //purpose  : 
61 //=======================================================================
62
63 Handle(Interface_UndefinedContent) IGESData_UndefinedEntity::ChangeableContent ()
64 {
65   return thecont;
66 }
67
68
69 //=======================================================================
70 //function : SetNewContent
71 //purpose  : 
72 //=======================================================================
73
74 void IGESData_UndefinedEntity::SetNewContent
75   (const Handle(Interface_UndefinedContent)& cont)
76 {
77   thecont = cont;
78 }
79
80
81 //  ....           (Re)definitions specifiques a UndefinedEntity           ....
82
83
84 //=======================================================================
85 //function : IsOKDirPart
86 //purpose  : 
87 //=======================================================================
88
89 Standard_Boolean IGESData_UndefinedEntity::IsOKDirPart () const
90 {
91   return (thedstat == 0);
92 }
93
94
95 //=======================================================================
96 //function : DirStatus
97 //purpose  : 
98 //=======================================================================
99
100 Standard_Integer IGESData_UndefinedEntity::DirStatus () const
101 {
102   return thedstat;
103 }
104
105
106 //=======================================================================
107 //function : SetOKDirPart
108 //purpose  : 
109 //=======================================================================
110
111 void IGESData_UndefinedEntity::SetOKDirPart ()
112 {
113   thedstat = 0;
114 }
115
116
117 //=======================================================================
118 //function : DefLineFont
119 //purpose  : 
120 //=======================================================================
121
122 IGESData_DefType IGESData_UndefinedEntity::DefLineFont () const
123 {
124   Standard_Integer st = ((thedstat/4) & 3);
125   if (st == 0) return IGESData_IGESEntity::DefLineFont();
126   else if (st == 1) return IGESData_ErrorVal;
127   else return IGESData_ErrorRef;
128 }
129
130
131 //=======================================================================
132 //function : DefLevel
133 //purpose  : 
134 //=======================================================================
135
136 IGESData_DefList IGESData_UndefinedEntity::DefLevel () const
137 {
138   Standard_Integer st = ((thedstat/16) & 3);
139   if (st == 0) return IGESData_IGESEntity::DefLevel();
140   else if (st == 1) return IGESData_ErrorOne;
141   else return IGESData_ErrorSeveral;
142 }
143
144
145 //=======================================================================
146 //function : DefView
147 //purpose  : 
148 //=======================================================================
149
150 IGESData_DefList IGESData_UndefinedEntity::DefView () const
151 {
152   Standard_Integer st = ((thedstat/64) & 3);
153   if (st == 0) return IGESData_IGESEntity::DefView();
154   else if (st == 1) return IGESData_ErrorOne;
155   else return IGESData_ErrorSeveral;
156 }
157
158
159 //=======================================================================
160 //function : DefColor
161 //purpose  : 
162 //=======================================================================
163
164 IGESData_DefType IGESData_UndefinedEntity::DefColor () const
165 {
166   Standard_Integer st = ((thedstat/256) & 3);
167   if (st == 0) return IGESData_IGESEntity::DefColor();
168   else if (st == 1) return IGESData_ErrorVal;
169   else return IGESData_ErrorRef;
170 }
171
172
173 //=======================================================================
174 //function : HasSubScriptNumber
175 //purpose  : 
176 //=======================================================================
177
178 Standard_Boolean IGESData_UndefinedEntity::HasSubScriptNumber () const
179 {
180   Standard_Integer st = ((thedstat/1024) & 1);
181   if (st == 0) return IGESData_IGESEntity::HasSubScriptNumber();
182   else return Standard_False;
183 }
184
185
186 //   ReadDir verifie les donnees, s il y a des erreurs les note (status),
187 //   genere un nouveau DirPart sans ces erreurs, et appelle ReadDir de base
188
189
190 //=======================================================================
191 //function : ReadDir
192 //purpose  : 
193 //=======================================================================
194
195 Standard_Boolean IGESData_UndefinedEntity::ReadDir
196   (const Handle(IGESData_IGESReaderData)& IR, IGESData_DirPart& DP,
197    Handle(Interface_Check)& ach)
198 {
199   // MGE 23/07/98
200   // =====================================
201   //Message_Msg Msg60 ("XSTEP_60");
202   //Message_Msg Msg61 ("XSTEP_61");
203   //Message_Msg Msg62 ("XSTEP_62");
204   //Message_Msg Msg63 ("XSTEP_63");
205   //Message_Msg Msg64 ("XSTEP_64");
206   //Message_Msg Msg70 ("XSTEP_70");
207   //Message_Msg Msg72 ("XSTEP_72");
208   // =====================================
209
210   Standard_Integer v[17]; Standard_Character res1[9],res2[9],lab[9],subs[9];
211   Standard_Integer max = 2 * IR->NbRecords();    // valeur maxi pour DSectNum
212   thedstat = 0;
213
214   Handle(IGESData_IGESEntity) anent; Standard_Boolean iapb;
215   DP.Values(v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9],v[10],
216             v[11],v[12],v[13],v[14],v[15],v[16],res1,res2,lab,subs);
217
218   iapb = Standard_False;
219   if (v[3] < -max) iapb = Standard_True;
220   else if (v[3] < 0) {
221     anent = GetCasted(IGESData_IGESEntity,IR->BoundEntity((-1-v[3])/2));
222     if (!anent->IsKind(STANDARD_TYPE(IGESData_LineFontEntity))) iapb = Standard_True;
223   }
224   // Sending of message : Line Font Pattern field is incorrect.
225   if (iapb) { 
226     Message_Msg Msg60 ("XSTEP_60");
227     ach->SendFail(Msg60);
228     thedstat += 8;
229     v[3] = 0;
230   }
231
232   iapb = Standard_False;
233   if (v[4] < -max) iapb = Standard_True;
234   else if (v[4] < 0) {
235     anent = GetCasted(IGESData_IGESEntity,IR->BoundEntity((-1-v[4])/2));
236     if (!anent->IsKind(STANDARD_TYPE(IGESData_LevelListEntity))) iapb = Standard_True;
237   }
238
239   // Sending of message : Level field is incorrect.
240   if (iapb) { 
241     Message_Msg Msg61 ("XSTEP_61");
242     ach->SendFail(Msg61);
243     thedstat += 32;
244     v[3] = 0;
245   }
246
247   iapb = Standard_False;
248   if (v[5] < 0 || v[5] > max) iapb = Standard_True;
249   else if (v[5] > 0) {
250     anent = GetCasted(IGESData_IGESEntity,IR->BoundEntity((1+v[5])/2));
251     if (!anent->IsKind(STANDARD_TYPE(IGESData_ViewKindEntity))) iapb = Standard_True;
252   }
253
254   // Sending of message : View field is incorrect.
255   if (iapb) { 
256     Message_Msg Msg62 ("XSTEP_62");
257     ach->SendFail(Msg62);
258     thedstat += 128;
259     v[5] = 0;
260   }
261
262   iapb = Standard_False;
263   if (v[6] < 0 || v[6] > max) iapb = Standard_True;
264   else if (v[6] > 0) {
265     anent = GetCasted(IGESData_IGESEntity,IR->BoundEntity((1+v[6])/2));
266     if (!anent->IsKind(STANDARD_TYPE(IGESData_TransfEntity))) iapb = Standard_True;
267   }
268  
269   // Sending of message : Transformation Matrix field is incorrect
270   if (iapb) { 
271     Message_Msg Msg63 ("XSTEP_63");
272     ach->SendFail(Msg63);
273     thedstat |= 1;
274     v[6] = 0;
275   }
276
277   iapb = Standard_False;
278   if (v[7] < 0 || v[7] > max) iapb = Standard_True;
279   else if (v[7] < 0) {
280     anent = GetCasted(IGESData_IGESEntity,IR->BoundEntity((1+v[7])/2));
281     if (!anent->IsKind(STANDARD_TYPE(IGESData_LabelDisplayEntity))) iapb = Standard_True;
282   }
283
284   // Sending of message : Label Display Entity  field is incorrect.
285   if (iapb) { 
286     Message_Msg Msg64 ("XSTEP_64");
287     ach->SendFail(Msg64);
288     thedstat |= 1;
289     v[7] = 0;
290   }
291
292   iapb = Standard_False;
293   if (v[14] < 0 || v[14] > max) iapb = Standard_True;
294   else if (v[14] < 0) {
295     anent = GetCasted(IGESData_IGESEntity,IR->BoundEntity((1+v[14])/2));
296     if (!anent->IsKind(STANDARD_TYPE(IGESData_ColorEntity)))
297       {  thedstat += 512; v[14] = 0;  }
298   }
299   
300   // Sending of message : Color Number field is incorrect.
301   if (iapb) { 
302     Message_Msg Msg70 ("XSTEP_70");
303     ach->SendFail(Msg70);
304     thedstat += 512;
305     v[14] = 0;
306   }
307
308   iapb = Standard_False;
309   Standard_Integer i; // svv Jan11 2000 : porting on DEC
310   for (i = 0; i < 8; i ++) {
311     if (subs[i] == '\0') break;  // fin de ligne
312     if (subs[i] != ' ' && (subs[i] < 48 || subs[i] > 57)) iapb = Standard_True;
313   }
314
315   // Sending of message : Entity Subscript Number field is incorrect.
316   if (iapb) { 
317     Message_Msg Msg72 ("XSTEP_72");
318     ach->SendFail(Msg72);
319     thedstat += 1024;
320     for (i = 0; i < 8; i ++) subs[i] = ' ';
321   }
322
323 //  ...  Fin de cette analyse : si necessaire on reconstruit DP  ...
324   if (thedstat == 0) return Standard_True;
325   else {
326     DP.Init(v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9],v[10],
327              v[11],v[12],v[13],v[14],v[15],v[16],res1,res2,lab,subs);
328     return Standard_False;
329   }
330 }
331
332
333 //   Parametres indifferencies : assocs et props ignores
334
335 //=======================================================================
336 //function : ReadOwnParams
337 //purpose  : 
338 //=======================================================================
339
340 void IGESData_UndefinedEntity::ReadOwnParams
341   (const Handle(IGESData_IGESReaderData)& /*IR*/, IGESData_ParamReader& PR)
342 {
343   Standard_Integer nb = PR.NbParams();
344
345   thecont->Reservate(nb,nb);
346   for (Standard_Integer i = 1; i <= nb; i ++) {
347     Interface_ParamType ptyp = PR.ParamType(i);
348 /*    if (PR.IsParamEntity(i)) {
349       thecont->AddEntity (ptyp,PR.ParamEntity(IR,i));
350     }
351     else thecont->AddLiteral (ptyp,new TCollection_HAsciiString(PR.ParamValue(i)));
352 */
353 //  On est TOUJOURS en mode litteral, c est bien plus clair !
354     thecont->AddLiteral (ptyp,new TCollection_HAsciiString(PR.ParamValue(i)));
355   }
356   PR.SetCurrentNumber(nb+1);
357 }
358
359
360 //=======================================================================
361 //function : WriteOwnParams
362 //purpose  : 
363 //=======================================================================
364
365 void IGESData_UndefinedEntity::WriteOwnParams(IGESData_IGESWriter& IW) const
366 {
367   Standard_Integer nb = thecont->NbParams();
368   for (Standard_Integer i = 1; i <= nb; i ++) {
369     Interface_ParamType ptyp = thecont->ParamType(i);
370     if (ptyp == Interface_ParamVoid) IW.SendVoid();
371     else if (thecont->IsParamEntity(i)) {
372       DeclareAndCast(IGESData_IGESEntity,anent,thecont->ParamEntity(i));
373       IW.Send(anent);
374     }
375     else IW.SendString (thecont->ParamValue(i));
376   }
377 }