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 <Interface_Protocol.hxx>
16 #include <Interface_ReaderLib.hxx>
17 #include <StepData_FileProtocol.hxx>
18 #include <StepData_HeaderTool.hxx>
19 #include <StepData_Protocol.hxx>
20 #include <StepData_StepReaderData.hxx>
21 #include <TCollection_AsciiString.hxx>
23 // HeaderTool prend en charge le Schema de Donnees utilise pour un Fichier
24 // Ce Schema peut etre compose de un ou plusieurs Protocoles, chacun etant
25 // designe par une String. Les Strings correspondent au type "SCHEMA_NAME"
26 // (typedef) et le Schema est une entite de Header de type "FILE_SCHEMA",
27 // il a cette forme dans le fichier :
28 static Interface_ReaderLib lib;
31 StepData_HeaderTool::StepData_HeaderTool
32 (const Handle(StepData_StepReaderData)& data)
35 thedone = Standard_False;
36 Standard_Integer num = 0;
37 while ( (num = data->FindNextRecord(num)) != 0) {
38 const TCollection_AsciiString& headertype = data->RecordType(num);
39 if (headertype == "FILE_SCHEMA") {
40 Standard_Integer numsub = data->SubListNumber(num,1,Standard_True);
41 Standard_Integer nb = data->NbParams(numsub);
42 for (Standard_Integer i = 1; i <= nb; i ++) {
43 TCollection_AsciiString unom = data->ParamCValue(numsub,i);
44 unom.Remove(unom.Length());
45 unom.Remove(1); // quotes debut et fin
46 thenames.Append(unom);
53 StepData_HeaderTool::StepData_HeaderTool
54 (const TColStd_SequenceOfAsciiString& names)
57 thedone = Standard_False;
58 Standard_Integer nb = names.Length();
59 for (Standard_Integer i = 1; i <= nb; i ++) thenames.Append(names.Value(i));
62 Standard_Integer StepData_HeaderTool::NbSchemaNames () const
63 { return thenames.Length(); }
65 const TCollection_AsciiString& StepData_HeaderTool::SchemaName
66 (const Standard_Integer num) const
67 { return thenames.Value(num); }
69 Handle(StepData_Protocol) StepData_HeaderTool::NamedProtocol
70 (const TCollection_AsciiString& name) const
72 Handle(StepData_Protocol) proto;
73 for (lib.Start(); lib.More(); lib.Next()) {
74 proto = Handle(StepData_Protocol)::DownCast(lib.Protocol());
75 if ( name.IsEqual(proto->SchemaName()) ) return proto;
81 void StepData_HeaderTool::Build
82 (const Handle(StepData_FileProtocol)& proto)
84 thedone = Standard_True;
86 Standard_Integer nb = thenames.Length();
87 for (Standard_Integer i = 1; i <= nb; i ++) {
88 Handle(StepData_Protocol) unproto = NamedProtocol(thenames.Value(i));
89 if (unproto.IsNull()) theignored.Append(thenames.Value(i));
90 else proto->Add(unproto);
94 Handle(StepData_Protocol) StepData_HeaderTool::Protocol ()
96 thedone = Standard_True;
98 Handle(StepData_Protocol) unproto;
99 if (thenames.IsEmpty()) return unproto;
100 if (thenames.Length() == 1) {
101 unproto = NamedProtocol (thenames.Value(1));
102 if (unproto.IsNull()) theignored.Append (thenames.Value(1));
105 Handle(StepData_FileProtocol) proto = new StepData_FileProtocol;
111 Standard_Boolean StepData_HeaderTool::IsDone () const
115 Standard_Integer StepData_HeaderTool::NbIgnoreds () const
116 { return theignored.Length(); }
118 const TCollection_AsciiString& StepData_HeaderTool::Ignored
119 (const Standard_Integer num) const
120 { return theignored.Value(num); }
123 void StepData_HeaderTool::Print (Standard_OStream& S) const
125 Standard_Integer nb = thenames.Length();
126 Standard_Integer lng = 0; Standard_Integer ln1;
127 S << " --- StepData_HeaderTool : List of Protocol Names --- Count : "
129 Standard_Integer i; // svv Jan11 2000 : porting on DEC
130 for (i = 1; i <= nb; i ++) {
131 ln1 = thenames.Value(i).Length() + 8; lng += ln1;
132 if (lng > 80) { S << std::endl; lng = ln1; }
133 S << " " << i << " : " << thenames.Value(i);
135 if (lng == 0) S << std::endl;
137 nb = theignored.Length();
139 S << " --- Evaluation of Protocol not Done ---" << std::endl;
140 } else if (nb == 0) {
141 S << " --- All Names correspond to a known Protocol ---" << std::endl;
144 S << " --- Among them, " << nb << " remain unrecognized ---" << std::endl;
145 for (i = 1; i <= nb; i ++) {
146 ln1 = theignored.Value(i).Length() + 3; lng += ln1;
147 if (lng > 80) { S << std::endl; lng = ln1; }
148 S << " : " << theignored.Value(i);
150 if (lng == 0) S << std::endl;