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