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 //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>
22 #include <IFSelect_Functions.hxx>
23 #include <Interface_InterfaceModel.hxx>
24 #include <IGESData_IGESModel.hxx>
26 #include <Interface_Static.hxx>
27 #include <Interface_Check.hxx>
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>
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
59 //=======================================================================
60 //function : IGESControl_Reader
62 //=======================================================================
64 IGESControl_Reader::IGESControl_Reader ()
66 IGESControl_Controller::Init();
67 SetWS (new XSControl_WorkSession);
69 theReadOnlyVisible = Standard_False;
73 //=======================================================================
74 //function : IGESControl_Reader
76 //=======================================================================
78 IGESControl_Reader::IGESControl_Reader
79 (const Handle(XSControl_WorkSession)& WS, const Standard_Boolean scratch)
81 IGESControl_Controller::Init();
84 theReadOnlyVisible = Standard_False;
88 //=======================================================================
89 //function : IGESModel
91 //=======================================================================
93 Handle(IGESData_IGESModel) IGESControl_Reader::IGESModel () const
95 return Handle(IGESData_IGESModel)::DownCast(Model());
100 //=======================================================================
101 //function : NbRootsForTransfer
103 //=======================================================================
105 Standard_Integer IGESControl_Reader::NbRootsForTransfer()
107 if (therootsta) return theroots.Length();
108 therootsta = Standard_True;
110 Handle(IGESData_IGESModel) model = IGESModel();
111 if (model.IsNull()) return 0;
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);
118 Interface_ShareFlags SH (model,protocol);
120 // sln 11.06.2002 OCC448
121 Interface_Static::SetIVal("read.iges.onlyvisible",theReadOnlyVisible);
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);
133 return theroots.Length();
136 // #### Reliquat de methodes a reprendre ####
138 //=======================================================================
139 // Function : PrintTransferInfo
140 // Purpose : Print statistics information on transfer using MoniTool message management
141 // Created : 18/01/98 DCE for S3767
143 //=======================================================================
145 void IGESControl_Reader::PrintTransferInfo
146 (const IFSelect_PrintFail failsonly, const IFSelect_PrintCount mode) const
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() ) {
161 // Init for dicoCountResult for IFSelect_ResultCount
162 if ( mode == IFSelect_ResultCount ) {
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);
171 // Init for dicoCountMapping for IFSelect_Mapping
172 else if ( mode == IFSelect_Mapping ) {
174 const Handle(Transfer_Binder) aBinder = iterTrans.Value();
175 DeclareAndCast(IGESData_IGESEntity,igesEnt,iterTrans.Starting());
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);
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() ) {
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);
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);
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);
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);
224 Message_Msg msg3000("IGES_3000"); // *************************
225 TF->Send (msg3000, Message_Info); //smh#14
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);
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);
253 sprintf(line,"\t\t\t");
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));
260 if (++nbInLine == 6) {
262 sprintf(line,"\n\t\t\t");
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;
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)) {
294 sprintf(mess,"%d\t%d \t%s\t%s", root->TypeNumber(), root->FormNumber(),
296 //cout << mess << endl;
297 Standard_Boolean deja;
298 Standard_Integer& nb = dicoCountMapping->NewItem(mess,deja);
304 Dico_IteratorOfDictionaryOfInteger dicoCountIter(dicoCountMapping);
305 for(dicoCountIter.Start(); dicoCountIter.More(); dicoCountIter.Next()) {
307 sprintf(mess, dicoCountIter.Name().ToCString() , dicoCountIter.Value());
308 TF << mess << endl; //dicoCountIter.Value() << dicoCountIter.Name() << endl;