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