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 | |
7fd59977 |
14 | #include <StepData_HeaderTool.ixx> |
15 | #include <Interface_ReaderLib.hxx> |
16 | #include <Interface_Protocol.hxx> |
17 | |
18 | |
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 : |
24 | |
7fd59977 |
25 | |
26 | |
27 | static Interface_ReaderLib lib; |
28 | |
29 | |
30 | StepData_HeaderTool::StepData_HeaderTool |
31 | (const Handle(StepData_StepReaderData)& data) |
32 | { |
33 | lib.SetComplete(); |
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); |
46 | } |
47 | } |
48 | } |
49 | } |
50 | |
51 | |
52 | StepData_HeaderTool::StepData_HeaderTool |
53 | (const TColStd_SequenceOfAsciiString& names) |
54 | { |
55 | lib.SetComplete(); |
56 | thedone = Standard_False; |
57 | Standard_Integer nb = names.Length(); |
58 | for (Standard_Integer i = 1; i <= nb; i ++) thenames.Append(names.Value(i)); |
59 | } |
60 | |
61 | Standard_Integer StepData_HeaderTool::NbSchemaNames () const |
62 | { return thenames.Length(); } |
63 | |
64 | const TCollection_AsciiString& StepData_HeaderTool::SchemaName |
65 | (const Standard_Integer num) const |
66 | { return thenames.Value(num); } |
67 | |
68 | Handle(StepData_Protocol) StepData_HeaderTool::NamedProtocol |
69 | (const TCollection_AsciiString& name) const |
70 | { |
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; |
75 | } |
76 | return proto; |
77 | } |
78 | |
79 | |
80 | void StepData_HeaderTool::Build |
81 | (const Handle(StepData_FileProtocol)& proto) |
82 | { |
83 | thedone = Standard_True; |
84 | theignored.Clear(); |
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); |
90 | } |
91 | } |
92 | |
93 | Handle(StepData_Protocol) StepData_HeaderTool::Protocol () |
94 | { |
95 | thedone = Standard_True; |
96 | theignored.Clear(); |
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)); |
102 | return unproto; |
103 | } |
104 | Handle(StepData_FileProtocol) proto = new StepData_FileProtocol; |
105 | Build(proto); |
106 | return proto; |
107 | } |
108 | |
109 | |
110 | Standard_Boolean StepData_HeaderTool::IsDone () const |
111 | { return thedone; } |
112 | |
113 | |
114 | Standard_Integer StepData_HeaderTool::NbIgnoreds () const |
115 | { return theignored.Length(); } |
116 | |
117 | const TCollection_AsciiString& StepData_HeaderTool::Ignored |
118 | (const Standard_Integer num) const |
119 | { return theignored.Value(num); } |
120 | |
121 | |
122 | void StepData_HeaderTool::Print (Standard_OStream& S) const |
123 | { |
124 | Standard_Integer nb = thenames.Length(); |
125 | Standard_Integer lng = 0; Standard_Integer ln1; |
126 | S << " --- StepData_HeaderTool : List of Protocol Names --- Count : " |
127 | << nb << endl; |
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); |
133 | } |
134 | if (lng == 0) S << endl; |
135 | |
136 | nb = theignored.Length(); |
137 | if (!thedone) { |
138 | S << " --- Evaluation of Protocol not Done ---" << endl; |
139 | } else if (nb == 0) { |
140 | S << " --- All Names correspond to a known Protocol ---" << endl; |
141 | } else { |
142 | lng = ln1 = 0; |
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); |
148 | } |
149 | if (lng == 0) S << endl; |
150 | } |
151 | } |