973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
42cf5bc1 |
14 | |
7fd59977 |
15 | #include <Interface_Protocol.hxx> |
42cf5bc1 |
16 | #include <Interface_ReaderLib.hxx> |
17 | #include <StepData_FileProtocol.hxx> |
18 | #include <StepData_HeaderTool.hxx> |
ec357c5c |
19 | #include <StepData_Protocol.hxx> |
42cf5bc1 |
20 | #include <StepData_StepReaderData.hxx> |
21 | #include <TCollection_AsciiString.hxx> |
7fd59977 |
22 | |
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 : |
7fd59977 |
28 | static Interface_ReaderLib lib; |
29 | |
30 | |
31 | StepData_HeaderTool::StepData_HeaderTool |
32 | (const Handle(StepData_StepReaderData)& data) |
33 | { |
34 | lib.SetComplete(); |
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); |
47 | } |
48 | } |
49 | } |
50 | } |
51 | |
52 | |
53 | StepData_HeaderTool::StepData_HeaderTool |
54 | (const TColStd_SequenceOfAsciiString& names) |
55 | { |
56 | lib.SetComplete(); |
57 | thedone = Standard_False; |
58 | Standard_Integer nb = names.Length(); |
59 | for (Standard_Integer i = 1; i <= nb; i ++) thenames.Append(names.Value(i)); |
60 | } |
61 | |
62 | Standard_Integer StepData_HeaderTool::NbSchemaNames () const |
63 | { return thenames.Length(); } |
64 | |
65 | const TCollection_AsciiString& StepData_HeaderTool::SchemaName |
66 | (const Standard_Integer num) const |
67 | { return thenames.Value(num); } |
68 | |
69 | Handle(StepData_Protocol) StepData_HeaderTool::NamedProtocol |
70 | (const TCollection_AsciiString& name) const |
71 | { |
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; |
76 | } |
77 | return proto; |
78 | } |
79 | |
80 | |
81 | void StepData_HeaderTool::Build |
82 | (const Handle(StepData_FileProtocol)& proto) |
83 | { |
84 | thedone = Standard_True; |
85 | theignored.Clear(); |
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); |
91 | } |
92 | } |
93 | |
94 | Handle(StepData_Protocol) StepData_HeaderTool::Protocol () |
95 | { |
96 | thedone = Standard_True; |
97 | theignored.Clear(); |
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)); |
103 | return unproto; |
104 | } |
105 | Handle(StepData_FileProtocol) proto = new StepData_FileProtocol; |
106 | Build(proto); |
107 | return proto; |
108 | } |
109 | |
110 | |
111 | Standard_Boolean StepData_HeaderTool::IsDone () const |
112 | { return thedone; } |
113 | |
114 | |
115 | Standard_Integer StepData_HeaderTool::NbIgnoreds () const |
116 | { return theignored.Length(); } |
117 | |
118 | const TCollection_AsciiString& StepData_HeaderTool::Ignored |
119 | (const Standard_Integer num) const |
120 | { return theignored.Value(num); } |
121 | |
122 | |
123 | void StepData_HeaderTool::Print (Standard_OStream& S) const |
124 | { |
125 | Standard_Integer nb = thenames.Length(); |
126 | Standard_Integer lng = 0; Standard_Integer ln1; |
127 | S << " --- StepData_HeaderTool : List of Protocol Names --- Count : " |
128 | << nb << endl; |
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 << endl; lng = ln1; } |
133 | S << " " << i << " : " << thenames.Value(i); |
134 | } |
135 | if (lng == 0) S << endl; |
136 | |
137 | nb = theignored.Length(); |
138 | if (!thedone) { |
139 | S << " --- Evaluation of Protocol not Done ---" << endl; |
140 | } else if (nb == 0) { |
141 | S << " --- All Names correspond to a known Protocol ---" << endl; |
142 | } else { |
143 | lng = ln1 = 0; |
144 | S << " --- Among them, " << nb << " remain unrecognized ---" << endl; |
145 | for (i = 1; i <= nb; i ++) { |
146 | ln1 = theignored.Value(i).Length() + 3; lng += ln1; |
147 | if (lng > 80) { S << endl; lng = ln1; } |
148 | S << " : " << theignored.Value(i); |
149 | } |
150 | if (lng == 0) S << endl; |
151 | } |
152 | } |