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 <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>
34 IMPLEMENT_STANDARD_RTTIEXT(IGESData_UndefinedEntity,IGESData_IGESEntity)
37 //=======================================================================
38 //function : IGESData_UndefinedEntity
40 //=======================================================================
41 IGESData_UndefinedEntity::IGESData_UndefinedEntity ()
43 thecont = new Interface_UndefinedContent;
47 //=======================================================================
48 //function : UndefinedContent
50 //=======================================================================
52 Handle(Interface_UndefinedContent) IGESData_UndefinedEntity::UndefinedContent () const
58 //=======================================================================
59 //function : ChangeableContent
61 //=======================================================================
63 Handle(Interface_UndefinedContent) IGESData_UndefinedEntity::ChangeableContent ()
69 //=======================================================================
70 //function : SetNewContent
72 //=======================================================================
74 void IGESData_UndefinedEntity::SetNewContent
75 (const Handle(Interface_UndefinedContent)& cont)
81 // .... (Re)definitions specifiques a UndefinedEntity ....
84 //=======================================================================
85 //function : IsOKDirPart
87 //=======================================================================
89 Standard_Boolean IGESData_UndefinedEntity::IsOKDirPart () const
91 return (thedstat == 0);
95 //=======================================================================
96 //function : DirStatus
98 //=======================================================================
100 Standard_Integer IGESData_UndefinedEntity::DirStatus () const
106 //=======================================================================
107 //function : SetOKDirPart
109 //=======================================================================
111 void IGESData_UndefinedEntity::SetOKDirPart ()
117 //=======================================================================
118 //function : DefLineFont
120 //=======================================================================
122 IGESData_DefType IGESData_UndefinedEntity::DefLineFont () const
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;
131 //=======================================================================
132 //function : DefLevel
134 //=======================================================================
136 IGESData_DefList IGESData_UndefinedEntity::DefLevel () const
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;
145 //=======================================================================
148 //=======================================================================
150 IGESData_DefList IGESData_UndefinedEntity::DefView () const
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;
159 //=======================================================================
160 //function : DefColor
162 //=======================================================================
164 IGESData_DefType IGESData_UndefinedEntity::DefColor () const
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;
173 //=======================================================================
174 //function : HasSubScriptNumber
176 //=======================================================================
178 Standard_Boolean IGESData_UndefinedEntity::HasSubScriptNumber () const
180 Standard_Integer st = ((thedstat/1024) & 1);
181 if (st == 0) return IGESData_IGESEntity::HasSubScriptNumber();
182 else return Standard_False;
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
190 //=======================================================================
193 //=======================================================================
195 Standard_Boolean IGESData_UndefinedEntity::ReadDir
196 (const Handle(IGESData_IGESReaderData)& IR, IGESData_DirPart& DP,
197 Handle(Interface_Check)& ach)
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 // =====================================
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
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);
218 iapb = Standard_False;
219 if (v[3] < -max) iapb = Standard_True;
221 anent = GetCasted(IGESData_IGESEntity,IR->BoundEntity((-1-v[3])/2));
222 if (!anent->IsKind(STANDARD_TYPE(IGESData_LineFontEntity))) iapb = Standard_True;
224 // Sending of message : Line Font Pattern field is incorrect.
226 Message_Msg Msg60 ("XSTEP_60");
227 ach->SendFail(Msg60);
232 iapb = Standard_False;
233 if (v[4] < -max) iapb = Standard_True;
235 anent = GetCasted(IGESData_IGESEntity,IR->BoundEntity((-1-v[4])/2));
236 if (!anent->IsKind(STANDARD_TYPE(IGESData_LevelListEntity))) iapb = Standard_True;
239 // Sending of message : Level field is incorrect.
241 Message_Msg Msg61 ("XSTEP_61");
242 ach->SendFail(Msg61);
247 iapb = Standard_False;
248 if (v[5] < 0 || v[5] > max) iapb = Standard_True;
250 anent = GetCasted(IGESData_IGESEntity,IR->BoundEntity((1+v[5])/2));
251 if (!anent->IsKind(STANDARD_TYPE(IGESData_ViewKindEntity))) iapb = Standard_True;
254 // Sending of message : View field is incorrect.
256 Message_Msg Msg62 ("XSTEP_62");
257 ach->SendFail(Msg62);
262 iapb = Standard_False;
263 if (v[6] < 0 || v[6] > max) iapb = Standard_True;
265 anent = GetCasted(IGESData_IGESEntity,IR->BoundEntity((1+v[6])/2));
266 if (!anent->IsKind(STANDARD_TYPE(IGESData_TransfEntity))) iapb = Standard_True;
269 // Sending of message : Transformation Matrix field is incorrect
271 Message_Msg Msg63 ("XSTEP_63");
272 ach->SendFail(Msg63);
277 iapb = Standard_False;
278 if (v[7] < 0 || v[7] > max) iapb = Standard_True;
280 anent = GetCasted(IGESData_IGESEntity,IR->BoundEntity((1+v[7])/2));
281 if (!anent->IsKind(STANDARD_TYPE(IGESData_LabelDisplayEntity))) iapb = Standard_True;
284 // Sending of message : Label Display Entity field is incorrect.
286 Message_Msg Msg64 ("XSTEP_64");
287 ach->SendFail(Msg64);
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; }
300 // Sending of message : Color Number field is incorrect.
302 Message_Msg Msg70 ("XSTEP_70");
303 ach->SendFail(Msg70);
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;
315 // Sending of message : Entity Subscript Number field is incorrect.
317 Message_Msg Msg72 ("XSTEP_72");
318 ach->SendFail(Msg72);
320 for (i = 0; i < 8; i ++) subs[i] = ' ';
323 // ... Fin de cette analyse : si necessaire on reconstruit DP ...
324 if (thedstat == 0) return Standard_True;
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;
333 // Parametres indifferencies : assocs et props ignores
335 //=======================================================================
336 //function : ReadOwnParams
338 //=======================================================================
340 void IGESData_UndefinedEntity::ReadOwnParams
341 (const Handle(IGESData_IGESReaderData)& /*IR*/, IGESData_ParamReader& PR)
343 Standard_Integer nb = PR.NbParams();
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));
351 else thecont->AddLiteral (ptyp,new TCollection_HAsciiString(PR.ParamValue(i)));
353 // On est TOUJOURS en mode litteral, c est bien plus clair !
354 thecont->AddLiteral (ptyp,new TCollection_HAsciiString(PR.ParamValue(i)));
356 PR.SetCurrentNumber(nb+1);
360 //=======================================================================
361 //function : WriteOwnParams
363 //=======================================================================
365 void IGESData_UndefinedEntity::WriteOwnParams(IGESData_IGESWriter& IW) const
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));
375 else IW.SendString (thecont->ParamValue(i));