0027232: Configuration - fix mblen missing building issue on Android
[occt.git] / src / IGESDefs / IGESDefs_ToolAttributeDef.cxx
1 // Created by: CKY / Contract Toubro-Larsen
2 // Copyright (c) 1993-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 //--------------------------------------------------------------------
17 //--------------------------------------------------------------------
18
19 #include <IGESData_DirChecker.hxx>
20 #include <IGESData_Dump.hxx>
21 #include <IGESData_HArray1OfIGESEntity.hxx>
22 #include <IGESData_IGESDumper.hxx>
23 #include <IGESData_IGESEntity.hxx>
24 #include <IGESData_IGESReaderData.hxx>
25 #include <IGESData_IGESWriter.hxx>
26 #include <IGESData_ParamCursor.hxx>
27 #include <IGESData_ParamReader.hxx>
28 #include <IGESDefs_AttributeDef.hxx>
29 #include <IGESDefs_HArray1OfHArray1OfTextDisplayTemplate.hxx>
30 #include <IGESDefs_ToolAttributeDef.hxx>
31 #include <IGESGraph_HArray1OfTextDisplayTemplate.hxx>
32 #include <IGESGraph_TextDisplayTemplate.hxx>
33 #include <Interface_Check.hxx>
34 #include <Interface_CopyTool.hxx>
35 #include <Interface_EntityIterator.hxx>
36 #include <Interface_HArray1OfHAsciiString.hxx>
37 #include <Interface_Macros.hxx>
38 #include <Interface_ShareTool.hxx>
39 #include <Message_Messenger.hxx>
40 #include <Standard_DomainError.hxx>
41 #include <TCollection_HAsciiString.hxx>
42 #include <TColStd_HArray1OfInteger.hxx>
43 #include <TColStd_HArray1OfReal.hxx>
44 #include <TColStd_HArray1OfTransient.hxx>
45
46 #include <stdio.h>
47 IGESDefs_ToolAttributeDef::IGESDefs_ToolAttributeDef ()    {  }
48
49
50 void IGESDefs_ToolAttributeDef::ReadOwnParams
51   (const Handle(IGESDefs_AttributeDef)& ent,
52   const Handle(IGESData_IGESReaderData)& IR, IGESData_ParamReader& PR) const
53 {
54   //Standard_Boolean st; //szv#4:S4163:12Mar99 moved down
55   Handle(TCollection_HAsciiString) aName;
56   Standard_Integer aListType;
57   Handle(TColStd_HArray1OfInteger)    attrTypes;
58   Handle(TColStd_HArray1OfInteger)    attrValueDataTypes;
59   Handle(TColStd_HArray1OfInteger)    attrValueCounts;
60   Handle(TColStd_HArray1OfTransient) attrValues;
61   Handle(IGESDefs_HArray1OfHArray1OfTextDisplayTemplate) attrValuePointers;
62   Standard_Integer nbval;
63   Standard_Integer fn = ent->FormNumber();
64
65   if (PR.DefinedElseSkip())
66     PR.ReadText(PR.Current(), "Attribute Table Name", aName); //szv#4:S4163:12Mar99 `st=` not needed
67
68   PR.ReadInteger(PR.Current(), "Attribute List Type", aListType); //szv#4:S4163:12Mar99 `st=` not needed
69
70   Standard_Boolean st = PR.ReadInteger(PR.Current(), "Number of Attributes", nbval);
71   if (st && nbval > 0)
72     {
73       attrTypes          = new TColStd_HArray1OfInteger(1, nbval);
74       attrValueDataTypes = new TColStd_HArray1OfInteger(1, nbval);
75       attrValueCounts    = new TColStd_HArray1OfInteger(1, nbval);
76       if (fn > 0)  attrValues =
77         new TColStd_HArray1OfTransient(1, nbval);
78       if (fn > 1)  attrValuePointers =
79         new IGESDefs_HArray1OfHArray1OfTextDisplayTemplate(1, nbval);
80     }
81   else  PR.AddFail("Number of Attributes: Not Positive");
82
83   if ( ! attrTypes.IsNull())
84     for (Standard_Integer i = 1; i <= nbval; i++)
85       {
86         Standard_Integer attrType;
87         Standard_Integer attrValueDataType;
88         Standard_Integer avc;
89 //  Value according type
90         Handle(IGESGraph_HArray1OfTextDisplayTemplate) attrValuePointer;
91
92         //st = PR.ReadInteger(PR.Current(), "Attribute Type", attrType); //szv#4:S4163:12Mar99 moved in if
93         if (PR.ReadInteger(PR.Current(), "Attribute Type", attrType))
94           attrTypes->SetValue(i, attrType);
95
96         st = PR.ReadInteger(PR.Current(),"Attribute Data Type",attrValueDataType);
97         if (st) attrValueDataTypes->SetValue(i, attrValueDataType);
98
99         if (PR.DefinedElseSkip())
100           st = PR.ReadInteger (PR.Current(),"Attribute Value Count",avc);
101         else  avc = 1;
102
103         if (st) {
104           attrValueCounts->SetValue(i, avc);
105           if (fn > 1)  attrValuePointer =
106             new IGESGraph_HArray1OfTextDisplayTemplate(1, avc);
107         }
108
109         if (! attrValues.IsNull())
110           if (fn > 0)
111             {
112               Handle(TColStd_HArray1OfInteger)        attrInt;
113               Handle(TColStd_HArray1OfReal)           attrReal;
114               Handle(Interface_HArray1OfHAsciiString) attrStr;
115               Handle(IGESData_HArray1OfIGESEntity)    attrEnt;
116               switch (attrValueDataType) {
117                 case 1 : attrInt  = new TColStd_HArray1OfInteger       (1,avc);
118                   attrValues->SetValue(i,attrInt);  break;
119                 case 2 : attrReal = new TColStd_HArray1OfReal          (1,avc);
120                   attrValues->SetValue(i,attrReal); break;
121                 case 3 : attrStr  = new Interface_HArray1OfHAsciiString(1,avc);
122                   attrValues->SetValue(i,attrStr);  break;
123                 case 4 : attrEnt  = new IGESData_HArray1OfIGESEntity   (1,avc);
124                   attrValues->SetValue(i,attrEnt);  break;
125                 case 6 : attrInt  = new TColStd_HArray1OfInteger       (1,avc);
126                   attrValues->SetValue(i,attrInt);  break;
127                 default : break;
128               }
129               for (Standard_Integer j = 1; j <= avc; j++)
130                 {
131                   switch(attrValueDataType)
132                     {
133                     case 0:
134                       {
135                         PR.SetCurrentNumber(PR.CurrentNumber() + 1); // passer
136 ////                    attrValue->SetValue(j, NULL);    par defaut
137                         break;
138                       }
139                     case 1:
140                       {
141                         Standard_Integer temp;
142                         //st = PR.ReadInteger(PR.Current(), "Attribute Value", temp); //szv#4:S4163:12Mar99 moved in if
143                         if (PR.ReadInteger(PR.Current(), "Attribute Value", temp))
144                           attrInt->SetValue(j, temp);
145                       }
146                       break;
147                     case 2:
148                       {
149                         Standard_Real temp;
150                         //st = PR.ReadReal(PR.Current(), "Attribute Value", temp); //szv#4:S4163:12Mar99 moved in if
151                         if (PR.ReadReal(PR.Current(), "Attribute Value", temp))
152                           attrReal->SetValue(j, temp);
153                       }
154                       break;
155                     case 3:
156                       {
157                         Handle(TCollection_HAsciiString) temp;
158                         //st = PR.ReadText(PR.Current(), "Attribute Value", temp); //szv#4:S4163:12Mar99 moved in if
159                         if (PR.ReadText(PR.Current(), "Attribute Value", temp))
160                           attrStr->SetValue(j, temp);
161                       }
162                       break;
163                     case 4:
164                       {
165                         Handle(IGESData_IGESEntity) temp;
166                         //st = PR.ReadEntity(IR, PR.Current(), "Attribute Value", temp); //szv#4:S4163:12Mar99 moved in if
167                         if (PR.ReadEntity(IR, PR.Current(), "Attribute Value", temp))
168                           attrEnt->SetValue(j, temp);
169                       }
170                       break;
171                     case 5:
172                         PR.SetCurrentNumber(PR.CurrentNumber() + 1);  // skip
173                       break;
174                     case 6:
175                       {
176                         Standard_Boolean temp;
177                         //st = PR.ReadBoolean(PR.Current(), "Attribute Value", temp); //szv#4:S4163:12Mar99 moved in if
178                         if (PR.ReadBoolean(PR.Current(), "Attribute Value", temp))
179                           attrInt->SetValue(j, (temp ? 1 : 0));
180                       }
181                       break;
182                     }
183                   if (fn == 2)
184                     {
185                       Handle(IGESGraph_TextDisplayTemplate) tempText;
186                       //st = PR.ReadEntity(IR,PR.Current(),"Attribute Val. Pointer",
187                                          //STANDARD_TYPE(IGESGraph_TextDisplayTemplate), tempText); //szv#4:S4163:12Mar99 moved in if
188                       if (PR.ReadEntity(IR,PR.Current(),"Attribute Val. Pointer",
189                                         STANDARD_TYPE(IGESGraph_TextDisplayTemplate), tempText))
190                         attrValuePointer->SetValue(j, tempText);
191                     }
192                 }
193               if (fn == 2)
194                 attrValuePointers->SetValue(i, attrValuePointer);
195             }
196       }
197
198   DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
199   ent->Init
200     (aName, aListType, attrTypes, attrValueDataTypes, attrValueCounts,
201      attrValues, attrValuePointers);
202 }
203
204 void IGESDefs_ToolAttributeDef::WriteOwnParams
205   (const Handle(IGESDefs_AttributeDef)& ent, IGESData_IGESWriter& IW) const
206 {
207   if (ent->HasTableName()) IW.Send(ent->TableName());
208   else                     IW.SendVoid();
209   IW.Send(ent->ListType());
210   Standard_Integer upper = ent->NbAttributes();
211   IW.Send(upper);
212
213   for (Standard_Integer i = 1; i <= upper; i++)
214     {
215       Standard_Integer check = ent->AttributeValueDataType(i);
216       Standard_Integer count = ent->AttributeValueCount(i);
217       IW.Send(ent->AttributeType(i));
218       IW.Send(check);
219       IW.Send(count);
220       if (ent->FormNumber() > 0)
221         {
222           for (Standard_Integer j = 1; j <= count; j++)
223             {
224               switch (check) {
225                 case 0 : IW.SendVoid();  break;
226                 case 1 : IW.Send(ent->AttributeAsInteger(i,j));  break;
227                 case 2 : IW.Send(ent->AttributeAsReal(i,j));     break;
228                 case 3 : IW.Send(ent->AttributeAsString(i,j));   break;
229                 case 4 : IW.Send(ent->AttributeAsEntity(i,j));   break;
230                 case 5 : IW.SendVoid();  break;
231                 case 6 : IW.SendBoolean(ent->AttributeAsLogical(i,j)); break;
232                 default : break;
233               }
234               if ( ent->FormNumber() == 2)
235                 IW.Send(ent->AttributeTextDisplay(i,j));
236             }
237         }
238     }
239 }
240
241 void  IGESDefs_ToolAttributeDef::OwnShared
242   (const Handle(IGESDefs_AttributeDef)& ent, Interface_EntityIterator& iter) const
243 {
244   Standard_Integer upper = ent->NbAttributes();
245   for (Standard_Integer i = 1; i <= upper; i++)
246     {
247       Standard_Integer check = ent->AttributeValueDataType(i);
248       Standard_Integer count = ent->AttributeValueCount(i);
249       if (ent->FormNumber() > 0)
250         {
251           for (Standard_Integer j = 1; j <= count; j++)
252             {
253               if ( check == 4 ) iter.GetOneItem(ent->AttributeAsEntity(i,j));
254               if ( ent->FormNumber() == 2)
255                 iter.GetOneItem(ent->AttributeTextDisplay(i,j));
256             }
257         }
258     }
259 }
260
261
262 void IGESDefs_ToolAttributeDef::OwnCopy
263   (const Handle(IGESDefs_AttributeDef)& another,
264    const Handle(IGESDefs_AttributeDef)& ent, Interface_CopyTool& TC) const
265 {
266   Handle(TCollection_HAsciiString) aName;
267   if (!another->TableName().IsNull()) aName =
268     new TCollection_HAsciiString(another->TableName());
269   Standard_Integer aListType = another->ListType();
270
271   Handle(TColStd_HArray1OfInteger) attrTypes;
272   Handle(TColStd_HArray1OfInteger) attrValueDataTypes;
273   Handle(TColStd_HArray1OfInteger) attrValueCounts;
274   Handle(TColStd_HArray1OfTransient) attrValues;
275   Handle(IGESDefs_HArray1OfHArray1OfTextDisplayTemplate)  attrValuePointers;
276   Standard_Integer nbval = another->NbAttributes();
277
278   attrTypes = new TColStd_HArray1OfInteger(1, nbval);
279   attrValueDataTypes = new TColStd_HArray1OfInteger(1, nbval);
280   attrValueCounts = new TColStd_HArray1OfInteger(1, nbval);
281   if (another->HasValues()) attrValues =
282     new TColStd_HArray1OfTransient(1, nbval);
283   if (another->HasTextDisplay()) attrValuePointers =
284     new IGESDefs_HArray1OfHArray1OfTextDisplayTemplate(1, nbval);
285
286   for (Standard_Integer i = 1; i <= nbval; i++)
287     {
288       Standard_Integer attrType = another->AttributeType(i);
289       attrTypes->SetValue(i, attrType);
290       Standard_Integer attrValueDataType = another->AttributeValueDataType(i);
291       attrValueDataTypes->SetValue(i, attrValueDataType);
292       Standard_Integer avc               = another->AttributeValueCount(i);
293       attrValueCounts->SetValue(i, avc);
294       Handle(IGESGraph_HArray1OfTextDisplayTemplate) attrValuePointer;
295
296       if (another->HasTextDisplay()) attrValuePointer =
297         new IGESGraph_HArray1OfTextDisplayTemplate(1, avc);
298
299       if (another->HasValues())
300         {
301           Handle(TColStd_HArray1OfInteger)        attrInt;
302           Handle(TColStd_HArray1OfReal)           attrReal;
303           Handle(Interface_HArray1OfHAsciiString) attrStr;
304           Handle(IGESData_HArray1OfIGESEntity)    attrEnt;
305           switch (attrValueDataType) {
306             case 1 : attrInt  = new TColStd_HArray1OfInteger       (1,avc);
307               attrValues->SetValue(i,attrInt);  break;
308             case 2 : attrReal = new TColStd_HArray1OfReal          (1,avc);
309               attrValues->SetValue(i,attrReal); break;
310             case 3 : attrStr  = new Interface_HArray1OfHAsciiString(1,avc);
311               attrValues->SetValue(i,attrStr);  break;
312             case 4 : attrEnt  = new IGESData_HArray1OfIGESEntity   (1,avc);
313               attrValues->SetValue(i,attrEnt);  break;
314             case 6 : attrInt  = new TColStd_HArray1OfInteger       (1,avc);
315               attrValues->SetValue(i,attrInt);  break;
316             default : break;
317           }
318           for (Standard_Integer j = 1; j <= avc; j ++)
319             {
320               switch(attrValueDataType)
321                 {
322                 case 0:
323                   break;
324                 case 1: attrInt->SetValue(j,another->AttributeAsInteger(i,j));
325                   break;
326                 case 2: attrReal->SetValue(j,another->AttributeAsReal(i,j));
327                   break;
328                 case 3: attrStr->SetValue(j,new TCollection_HAsciiString
329                                            (another->AttributeAsString(i,j)));
330                   break;
331                 case 4: {
332                   DeclareAndCast(IGESData_IGESEntity,Ent,TC.Transferred
333                                  (another->AttributeAsEntity(i,j)));
334                   attrEnt->SetValue(j,Ent);
335                 }
336                   break;
337                 case 5:
338                   break;
339                 case 6: attrInt->SetValue
340                   (j,(another->AttributeAsLogical(i,j) ? 1 : 0));
341                   break;
342                 default : break;
343                 }
344               if (another->HasTextDisplay())
345                 {
346                   DeclareAndCast(IGESGraph_TextDisplayTemplate, temptext,
347                                  TC.Transferred(another->AttributeTextDisplay(i,j)));
348                   attrValuePointer->SetValue (j, temptext);
349                 }
350             }
351           if (another->HasTextDisplay())
352             attrValuePointers->SetValue(i, attrValuePointer);
353         }
354     }
355   ent->Init
356     (aName, aListType, attrTypes, attrValueDataTypes, attrValueCounts,
357      attrValues, attrValuePointers);
358 }
359
360 IGESData_DirChecker  IGESDefs_ToolAttributeDef::DirChecker
361   (const Handle(IGESDefs_AttributeDef)& /* ent */ ) const
362 {
363   IGESData_DirChecker DC (322, 0, 2);
364   DC.Structure(IGESData_DefVoid);
365   DC.LineFont(IGESData_DefAny);
366   DC.LineWeight(IGESData_DefValue);
367   DC.Color(IGESData_DefAny);
368   DC.BlankStatusIgnored();
369   DC.SubordinateStatusRequired(0);
370   DC.UseFlagRequired(2);
371   DC.GraphicsIgnored(1);
372   return DC;
373 }
374
375 void IGESDefs_ToolAttributeDef::OwnCheck
376   (const Handle(IGESDefs_AttributeDef)& ent,
377    const Interface_ShareTool& , Handle(Interface_Check)& ach) const
378 {
379   Standard_Integer nb = ent->NbAttributes();
380   Standard_Integer fn = ent->FormNumber();
381   for (Standard_Integer i = 1; i <= nb; i ++) {
382     char mess[80];
383     if (ent->AttributeType(i) < 0 || ent->AttributeType(i) > 9999) {
384       sprintf(mess,"Attribute Type n0.%d not in <0 - 9999>", ent->AttributeType(i));
385       ach->AddFail(mess);
386     }
387     Standard_Integer aty = ent->AttributeValueDataType(i);
388     if (aty < 0 || aty > 6) {
389       sprintf(mess,"Attribute Value Data Type n0.%d not in <0 - 6>", aty);
390       ach->AddFail(mess);
391     }
392     if (ent->AttributeValueCount(i) <= 0) continue;
393     Handle(Standard_Transient) list = ent->AttributeList(i);
394     if (fn > 0 && ent.IsNull()) {
395       if (aty == 0 || aty == 5) continue;
396       sprintf(mess,"Form Number > 0 and Attribute Value List n0.%d undefined", aty);
397       ach->AddFail(mess);
398       continue;
399     }
400     else if (fn == 0) continue;
401     mess[0] = '\0';
402     switch (aty) {
403       case 1 : if (!list->IsKind(STANDARD_TYPE(TColStd_HArray1OfInteger)))
404         sprintf(mess,"Attribute List n0.%d (Integers) badly defined", aty);
405         break;
406       case 2 : if (!list->IsKind(STANDARD_TYPE(TColStd_HArray1OfReal)))
407         sprintf(mess,"Attribute List n0.%d (Reals) badly defined", aty);
408         break;
409       case 3 : if (!list->IsKind(STANDARD_TYPE(Interface_HArray1OfHAsciiString)))
410         sprintf(mess,"Attribute List n0.%d (Strings) badly defined", aty);
411         break;
412       case 4 : if (!list->IsKind(STANDARD_TYPE(IGESData_HArray1OfIGESEntity)))
413         sprintf(mess,"Attribute List n0.%d (IGES Pointers) badly defined", aty);
414         break;
415       case 6 : if (!list->IsKind(STANDARD_TYPE(TColStd_HArray1OfInteger)))
416         sprintf(mess,"Attribute List n0.%d (Logicals i.e. Integers) badly defined", aty);
417         break;
418       default : break;
419     }
420     if (mess[0] != '\0') ach->AddFail(mess);
421   }
422 }
423
424
425 void IGESDefs_ToolAttributeDef::OwnDump
426   (const Handle(IGESDefs_AttributeDef)& ent, const IGESData_IGESDumper& dumper,
427    const Handle(Message_Messenger)& S, const Standard_Integer level) const
428 {
429   Standard_Integer sublevel = (level > 4) ? 1 : 0;
430
431   S << "IGESDefs_AttributeDef" << endl;
432   S << "Attribute Table Name: ";
433   IGESData_DumpString(S,ent->TableName());
434   S << endl;
435   S << "Attribute List Type  : " << ent->ListType() << endl;
436   S << "Number of Attributes : " << ent->NbAttributes() << endl;
437   S << "Attribute Types : " << endl;
438   S << "Attribute Value Data Types : " << endl;
439   S << "Attribute Value Counts : " << endl;
440   if (ent->HasValues())       S << "Attribute Values : " << endl;
441   if (ent->HasTextDisplay())  S << "Attribute Value Entities : " << endl;
442   IGESData_DumpVals(S,-level,1, ent->NbAttributes(),ent->AttributeType);
443   S << endl;
444   if (level > 4)
445     {
446       Standard_Integer upper = ent->NbAttributes();
447       for (Standard_Integer i = 1; i <= upper ; i ++)
448         {
449           Standard_Integer avc = ent->AttributeValueCount(i);
450           Standard_Integer typ = ent->AttributeValueDataType(i);
451           S << "[" << i << "]:  ";
452           S << "Attribute Type : " << ent->AttributeType(i) << "  ";
453           S << "Value Data Type : " << typ;
454           switch (typ) {
455             case 0 : S << "  (Void)";     break;
456             case 1 : S << " : Integer ";  break;
457             case 2 : S << " : Real    ";  break;
458             case 3 : S << " : String  ";  break;
459             case 4 : S << " : Entity  ";  break;
460             case 5 : S << " (Not Used)";  break;
461             case 6 : S << " : Logical ";  break;
462             default :   break;
463           }
464           S << "   Count : " << avc << endl;
465           if (ent->HasValues())
466             {
467               if (level <= 5) {
468                 S << " [ content (Values) : ask level > 5 ]" << endl;
469                 continue;
470               }
471               for (Standard_Integer j = 1; j <= avc; j ++)
472                 {
473                   S << "[" << j << "]: ";
474                   switch(ent->AttributeValueDataType(i))
475                     {
476                     case 0:  S << "(Void) ";
477                       break;
478                     case 1:  S << ent->AttributeAsInteger(i,j);
479                       break;
480                     case 2:  S << ent->AttributeAsReal(i,j);
481                       break;
482                     case 3:  IGESData_DumpString(S,ent->AttributeAsString(i,j));
483                       break;
484                     case 4: dumper.Dump(ent->AttributeAsEntity(i,j),S,level-5);
485                       break;
486                     case 5:  S << "(Not Used)";
487                       break;
488                     case 6:
489                       S << ( ent->AttributeAsLogical(i,j) ? "True" : "False");
490                       break;
491                     default : break;
492                     }
493                   if (ent->HasTextDisplay())
494                     {
495                       S << "  Attribute Value Pointer : ";
496                       dumper.Dump (ent->AttributeTextDisplay(i,j),S, sublevel);
497                     }
498                   S << endl;
499                 }
500             }
501         }
502     }
503   S << endl;
504 }