0024624: Lost word in license statement in source files
[occt.git] / src / IGESControl / IGESControl_Reader.cxx
CommitLineData
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//gka 06.01.99 S3767
15//abv 10.04.99 S4136: eliminate using BRepAPI::Precision()
16#include <IGESControl_Reader.ixx>
17#include <IGESControl_Controller.hxx>
18#include <XSControl_Controller.hxx>
19#include <XSControl_TransferReader.hxx>
20#include <Interface_ShareFlags.hxx>
21
22#include <IFSelect_Functions.hxx>
23#include <Interface_InterfaceModel.hxx>
24#include <IGESData_IGESModel.hxx>
25
26#include <Interface_Static.hxx>
27#include <Interface_Check.hxx>
28
29// S3767 dce 18/01/1999
30#include <Message_Msg.hxx>
31#include <Transfer_TransientProcess.hxx>
32#include <Transfer_IteratorOfProcessForTransient.hxx>
33#include <Transfer_Binder.hxx>
34#include <TopoDS_Shape.hxx>
35#include <Interface_CheckIterator.hxx>
36#include <Transfer_IteratorOfProcessForTransient.hxx>
37#include <IFSelect_CheckCounter.hxx>//Transfer_Iterator.hxx>
38#include <Dico_DictionaryOfTransient.hxx>
39#include <Dico_DictionaryOfInteger.hxx>
40#include <Dico_IteratorOfDictionaryOfInteger.hxx>
41#include <Dico_IteratorOfDictionaryOfTransient.hxx>
42#include <Interface_Macros.hxx>
43#include <IGESData_IGESEntity.hxx>
44#include <TColStd_HSequenceOfInteger.hxx>
45#include <OSD_Timer.hxx>
46#include <Transfer_TransferOutput.hxx>
47#include <ShapeExtend_Explorer.hxx>
7fd59977 48#include <Message_Messenger.hxx>
49#include <Transfer_ActorOfTransientProcess.hxx>
50#include <IGESToBRep_Actor.hxx>
51#include <IGESData_FileProtocol.hxx>
52#include <TransferBRep.hxx>
53#include <ShapeFix_ShapeTolerance.hxx>
54#include <BRepLib.hxx>
55// add of stdio.h for NT compilation
56#include <stdio.h>
57
58
59//=======================================================================
60//function : IGESControl_Reader
61//purpose :
62//=======================================================================
63
64IGESControl_Reader::IGESControl_Reader ()
65{
66 IGESControl_Controller::Init();
67 SetWS (new XSControl_WorkSession);
68 SetNorm("IGES");
69 theReadOnlyVisible = Standard_False;
70}
71
72
73//=======================================================================
74//function : IGESControl_Reader
75//purpose :
76//=======================================================================
77
78IGESControl_Reader::IGESControl_Reader
79 (const Handle(XSControl_WorkSession)& WS, const Standard_Boolean scratch)
80{
81 IGESControl_Controller::Init();
82 SetWS (WS,scratch);
83 SetNorm ("IGES");
84 theReadOnlyVisible = Standard_False;
85}
86
87
88//=======================================================================
89//function : IGESModel
90//purpose :
91//=======================================================================
92
93Handle(IGESData_IGESModel) IGESControl_Reader::IGESModel () const
94{
95 return Handle(IGESData_IGESModel)::DownCast(Model());
96}
97
98
99
100//=======================================================================
101//function : NbRootsForTransfer
102//purpose :
103//=======================================================================
104
105Standard_Integer IGESControl_Reader::NbRootsForTransfer()
106{
107 if (therootsta) return theroots.Length();
108 therootsta = Standard_True;
109
110 Handle(IGESData_IGESModel) model = IGESModel();
111 if (model.IsNull()) return 0;
112
113 Handle(XSControl_WorkSession) session = WS();
114 Handle(Interface_Protocol) protocol = session->Protocol();
115 Handle(XSControl_Controller) controller = session->NormAdaptor();
116 Handle(Transfer_ActorOfTransientProcess) actor = controller->ActorRead(model);
117
118 Interface_ShareFlags SH (model,protocol);
119
120 // sln 11.06.2002 OCC448
121 Interface_Static::SetIVal("read.iges.onlyvisible",theReadOnlyVisible);
122
123 Standard_Integer nb = model->NbEntities();
124 for (Standard_Integer i = 1; i <= nb; i ++) {
125 Handle(IGESData_IGESEntity) ent = model->Entity(i);
126 if ( SH.IsShared(ent) || ! actor->Recognize (ent) ) continue;
127 // on ajoute un traitement pour ne prendre que les entites visibles
128 if ( ! theReadOnlyVisible || ent->BlankStatus() == 0 ) {
129 theroots.Append(ent);
130 }
131 }
132
133 return theroots.Length();
134}
135
136// #### Reliquat de methodes a reprendre ####
137
138//=======================================================================
139// Function : PrintTransferInfo
140// Purpose : Print statistics information on transfer using MoniTool message management
141// Created : 18/01/98 DCE for S3767
142// Modified :
143//=======================================================================
144
145void IGESControl_Reader::PrintTransferInfo
146 (const IFSelect_PrintFail failsonly, const IFSelect_PrintCount mode) const
147{
148 Standard_Integer nbWarn = 0, nbFail= 0, nbEntities =0, nbRoots = 0, nbResults = 0;
149 Handle(Transfer_TransientProcess) TP = WS()->MapReader();
150 Handle(Message_Messenger) TF = TP->Messenger();
151 Handle(Interface_InterfaceModel) model = TP->Model();
152 if (! model.IsNull()) {
153 nbEntities = model->NbEntities();
154 nbRoots = TP->NbRoots();
155 //nbResults = TP->NbMapped();
156 Transfer_IteratorOfProcessForTransient iterTrans = TP->RootResult(Standard_True);
157 Handle(Dico_DictionaryOfInteger) dicoCountResult = new Dico_DictionaryOfInteger;
158 Handle(Dico_DictionaryOfInteger) dicoCountMapping = new Dico_DictionaryOfInteger;
159 for (iterTrans.Start(); iterTrans.More() ; iterTrans.Next() ) {
160 nbResults++;
161 // Init for dicoCountResult for IFSelect_ResultCount
162 if ( mode == IFSelect_ResultCount ) {
163 char mess[300];
164 const Handle(Transfer_Binder) aBinder = iterTrans.Value();
165 sprintf(mess,"\t%s",aBinder->ResultTypeName());
166 Standard_Boolean deja;
167 Standard_Integer& nb = dicoCountResult->NewItem(mess,deja);
168 if (!deja) nb = 0;
169 nb ++;
170 }
171 // Init for dicoCountMapping for IFSelect_Mapping
172 else if ( mode == IFSelect_Mapping ) {
173 char mess[300];
174 const Handle(Transfer_Binder) aBinder = iterTrans.Value();
175 DeclareAndCast(IGESData_IGESEntity,igesEnt,iterTrans.Starting());
176
177 sprintf(mess,"%d\t%d\t%s\t%s", igesEnt->TypeNumber(), igesEnt->FormNumber(),
178 "%d", aBinder->ResultTypeName());
179 //cout << mess << endl;
180 Standard_Boolean deja;
181 Standard_Integer& nb = dicoCountMapping->NewItem(mess,deja);
182 if (!deja) nb = 0;
183 nb ++;
184 }
185 }
186
187 Interface_CheckIterator checkIterator = TP->CheckList(Standard_False);
188 Handle(Dico_DictionaryOfInteger) dicoCount = new Dico_DictionaryOfInteger;
189 Handle(Dico_DictionaryOfTransient) dicoList = new Dico_DictionaryOfTransient;
190 // Init the dicoCount dicoList and nbWarn ,nb Fail.
191 for(checkIterator.Start(); checkIterator.More(); checkIterator.Next() ) {
192 char mess[300];
193 const Handle(Interface_Check) aCheck = checkIterator.Value();
194 Handle(Standard_Transient) ent = model->Value(checkIterator.Number());
195 DeclareAndCast(IGESData_IGESEntity,igesEnt,ent);
196 Standard_Integer type = igesEnt->TypeNumber(), form = igesEnt->FormNumber();
197 Standard_Integer nw = aCheck->NbWarnings(), nf = aCheck->NbFails(), i;
198 for(i = 1; (failsonly==IFSelect_FailAndWarn) && (i<= nw); i++) {
199 sprintf(mess,"\t W\t%d\t%d\t%s",type,form,aCheck->CWarning(i));
200 Standard_Boolean deja;
201 Standard_Integer& nb = dicoCount->NewItem(mess,deja);
202 if (!deja) nb = 0;
203 nb ++;
204 Handle(Standard_Transient)& anitem = dicoList->NewItem(mess,deja);
205 DeclareAndCast(TColStd_HSequenceOfInteger,alist,anitem);
206 if (!deja) { alist = new TColStd_HSequenceOfInteger(); anitem = alist; }
207 alist->Append(model->Number(igesEnt)*2-1);
208 }
209 for(i = 1; i<= nf; i++) {
210 sprintf(mess,"\t F\t%d\t%d\t%s",type,form,aCheck->CFail(i));
211 // TF << mess << endl;
212 Standard_Boolean deja;
213 Standard_Integer& nb = dicoCount->NewItem(mess,deja);
214 if (!deja) nb = 0;
215 nb ++;
216 Handle(Standard_Transient)& anitem = dicoList->NewItem(mess,deja);
217 DeclareAndCast(TColStd_HSequenceOfInteger,alist,anitem);
218 if (!deja) { alist = new TColStd_HSequenceOfInteger(); anitem = alist; }
219 alist->Append(model->Number(igesEnt)*2-1);
220 }
221 nbWarn += nw;
222 nbFail += nf;
223 }
224 Message_Msg msg3000("IGES_3000"); // *************************
225 TF->Send (msg3000, Message_Info); //smh#14
226
227 switch (mode) {
228 case IFSelect_GeneralInfo : {
229 Message_Msg msg3005("IGES_3005");TF->Send(msg3005, Message_Info);
230 Message_Msg msg3010("IGES_3010");msg3010.Arg(nbEntities);TF->Send(msg3010, Message_Info);
231 Message_Msg msg3011("IGES_3011");msg3011.Arg(nbRoots);TF->Send(msg3011, Message_Info);
232 Message_Msg msg3015("IGES_3015");msg3015.Arg(nbResults);TF->Send(msg3015, Message_Info);
233 Message_Msg msg3020("IGES_3020");msg3020.Arg(nbWarn);TF->Send(msg3020, Message_Info);
234 Message_Msg msg3025("IGES_3025");msg3025.Arg(nbFail);TF->Send(msg3025, Message_Info);
235 break;
236 }
237 case IFSelect_CountByItem :
238 case IFSelect_ListByItem : {
239 Message_Msg msg3030("IGES_3030");
240 TF->Send(msg3030, Message_Info);
241 Dico_IteratorOfDictionaryOfInteger dicoCountIter(dicoCount);
242 Dico_IteratorOfDictionaryOfTransient dicoListIter(dicoList);
243 for(dicoCountIter.Start(),dicoListIter.Start();
244 dicoCountIter.More() && dicoListIter.More();
245 dicoCountIter.Next(),dicoListIter.Next()) {
246 TF << dicoCountIter.Value() << dicoCountIter.Name() << endl;
247 if (mode == IFSelect_ListByItem) {
248 DeclareAndCast(TColStd_HSequenceOfInteger, entityList, dicoListIter.Value());
249 Standard_Integer length = entityList->Length();
250 Message_Msg msg3035("IGES_3035");
251 TF->Send(msg3035, Message_Info);
252 char line[80];
253 sprintf(line,"\t\t\t");
254 TF << line ;
255 Standard_Integer nbInLine =0;
256 for(Standard_Integer i = 1; i <= length ; i++ ) {
257 // IDT_Out << (entityList->Value(i)) << " ";
258 sprintf(line,"\t %d", entityList->Value(i));
259 TF << line ;
260 if (++nbInLine == 6) {
261 nbInLine = 0;
262 sprintf(line,"\n\t\t\t");
263 TF << line ;
264 }
265 }
266 TF << endl ;
267 }
268 }
269 break;
270 }
271 case IFSelect_ResultCount : {
272 Message_Msg msg3040("IGES_3040");TF->Send(msg3040, Message_Info);
273 Message_Msg msg3011("IGES_3011");msg3011.Arg(nbRoots);TF->Send(msg3011, Message_Info);
274 Message_Msg msg3015("IGES_3015");msg3015.Arg(nbResults);TF->Send(msg3015, Message_Info);
275 Message_Msg msg3045("IGES_3045");TF->Send(msg3045, Message_Info);
276 Dico_IteratorOfDictionaryOfInteger dicoCountIter(dicoCountResult);
277 for(dicoCountIter.Start(); dicoCountIter.More(); dicoCountIter.Next()) {
278 TF << dicoCountIter.Value() << dicoCountIter.Name() << endl;
279 }
280 break;
281 }
282 case IFSelect_Mapping : {
283 Message_Msg msg3040("IGES_3050");TF->Send(msg3040, Message_Info);
284 Message_Msg msg3011("IGES_3011");msg3011.Arg(nbRoots);TF->Send(msg3011, Message_Info);
285 Message_Msg msg3015("IGES_3015");msg3015.Arg(nbResults);TF->Send(msg3015, Message_Info);
286 Message_Msg msg3045("IGES_3055");TF->Send(msg3045, Message_Info);
287 // Add failed entities in dicoCountMapping
288 if (nbRoots!=nbResults) {
289 for( Standard_Integer i = 1; i <= nbRoots ; i++) {
290 DeclareAndCast(IGESData_IGESEntity, root, TP->Root(i));
291 if (!TP->IsBound(root)) {
292 char mess[300];
293
294 sprintf(mess,"%d\t%d \t%s\t%s", root->TypeNumber(), root->FormNumber(),
295 "%d", "Failed");
296 //cout << mess << endl;
297 Standard_Boolean deja;
298 Standard_Integer& nb = dicoCountMapping->NewItem(mess,deja);
299 if (!deja) nb = 0;
300 nb ++;
301 }
302 }
303 }
304 Dico_IteratorOfDictionaryOfInteger dicoCountIter(dicoCountMapping);
305 for(dicoCountIter.Start(); dicoCountIter.More(); dicoCountIter.Next()) {
306 char mess[80];
307 sprintf(mess, dicoCountIter.Name().ToCString() , dicoCountIter.Value());
308 TF << mess << endl; //dicoCountIter.Value() << dicoCountIter.Name() << endl;
309 }
310 break;
311 }
312 default: break;
313 }
314 }
315}