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.
14 #include <StepData_HeaderTool.ixx>
15 #include <Interface_ReaderLib.hxx>
16 #include <Interface_Protocol.hxx>
19 // HeaderTool prend en charge le Schema de Donnees utilise pour un Fichier
20 // Ce Schema peut etre compose de un ou plusieurs Protocoles, chacun etant
21 // designe par une String. Les Strings correspondent au type "SCHEMA_NAME"
22 // (typedef) et le Schema est une entite de Header de type "FILE_SCHEMA",
23 // il a cette forme dans le fichier :
27 static Interface_ReaderLib lib;
30 StepData_HeaderTool::StepData_HeaderTool
31 (const Handle(StepData_StepReaderData)& data)
34 thedone = Standard_False;
35 Standard_Integer num = 0;
36 while ( (num = data->FindNextRecord(num)) != 0) {
37 const TCollection_AsciiString& headertype = data->RecordType(num);
38 if (headertype == "FILE_SCHEMA") {
39 Standard_Integer numsub = data->SubListNumber(num,1,Standard_True);
40 Standard_Integer nb = data->NbParams(numsub);
41 for (Standard_Integer i = 1; i <= nb; i ++) {
42 TCollection_AsciiString unom = data->ParamCValue(numsub,i);
43 unom.Remove(unom.Length());
44 unom.Remove(1); // quotes debut et fin
45 thenames.Append(unom);
52 StepData_HeaderTool::StepData_HeaderTool
53 (const TColStd_SequenceOfAsciiString& names)
56 thedone = Standard_False;
57 Standard_Integer nb = names.Length();
58 for (Standard_Integer i = 1; i <= nb; i ++) thenames.Append(names.Value(i));
61 Standard_Integer StepData_HeaderTool::NbSchemaNames () const
62 { return thenames.Length(); }
64 const TCollection_AsciiString& StepData_HeaderTool::SchemaName
65 (const Standard_Integer num) const
66 { return thenames.Value(num); }
68 Handle(StepData_Protocol) StepData_HeaderTool::NamedProtocol
69 (const TCollection_AsciiString& name) const
71 Handle(StepData_Protocol) proto;
72 for (lib.Start(); lib.More(); lib.Next()) {
73 proto = Handle(StepData_Protocol)::DownCast(lib.Protocol());
74 if ( name.IsEqual(proto->SchemaName()) ) return proto;
80 void StepData_HeaderTool::Build
81 (const Handle(StepData_FileProtocol)& proto)
83 thedone = Standard_True;
85 Standard_Integer nb = thenames.Length();
86 for (Standard_Integer i = 1; i <= nb; i ++) {
87 Handle(StepData_Protocol) unproto = NamedProtocol(thenames.Value(i));
88 if (unproto.IsNull()) theignored.Append(thenames.Value(i));
89 else proto->Add(unproto);
93 Handle(StepData_Protocol) StepData_HeaderTool::Protocol ()
95 thedone = Standard_True;
97 Handle(StepData_Protocol) unproto;
98 if (thenames.IsEmpty()) return unproto;
99 if (thenames.Length() == 1) {
100 unproto = NamedProtocol (thenames.Value(1));
101 if (unproto.IsNull()) theignored.Append (thenames.Value(1));
104 Handle(StepData_FileProtocol) proto = new StepData_FileProtocol;
110 Standard_Boolean StepData_HeaderTool::IsDone () const
114 Standard_Integer StepData_HeaderTool::NbIgnoreds () const
115 { return theignored.Length(); }
117 const TCollection_AsciiString& StepData_HeaderTool::Ignored
118 (const Standard_Integer num) const
119 { return theignored.Value(num); }
122 void StepData_HeaderTool::Print (Standard_OStream& S) const
124 Standard_Integer nb = thenames.Length();
125 Standard_Integer lng = 0; Standard_Integer ln1;
126 S << " --- StepData_HeaderTool : List of Protocol Names --- Count : "
128 Standard_Integer i; // svv Jan11 2000 : porting on DEC
129 for (i = 1; i <= nb; i ++) {
130 ln1 = thenames.Value(i).Length() + 8; lng += ln1;
131 if (lng > 80) { S << endl; lng = ln1; }
132 S << " " << i << " : " << thenames.Value(i);
134 if (lng == 0) S << endl;
136 nb = theignored.Length();
138 S << " --- Evaluation of Protocol not Done ---" << endl;
139 } else if (nb == 0) {
140 S << " --- All Names correspond to a known Protocol ---" << endl;
143 S << " --- Among them, " << nb << " remain unrecognized ---" << endl;
144 for (i = 1; i <= nb; i ++) {
145 ln1 = theignored.Value(i).Length() + 3; lng += ln1;
146 if (lng > 80) { S << endl; lng = ln1; }
147 S << " : " << theignored.Value(i);
149 if (lng == 0) S << endl;