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 | // pdn 26.02.99 added initializing of compound in function OneShape |
15 | //: gka 14.04.99: S4136: apply scaling |
7fd59977 |
16 | |
42cf5bc1 |
17 | #include <BRep_Builder.hxx> |
18 | #include <IFSelect_Functions.hxx> |
19 | #include <Interface_Check.hxx> |
20 | #include <Interface_InterfaceModel.hxx> |
21 | #include <Interface_ShareFlags.hxx> |
22 | #include <Interface_Static.hxx> |
0ebe5b0a |
23 | #include <Message.hxx> |
24 | #include <Message_Messenger.hxx> |
42cf5bc1 |
25 | #include <Message_ProgressSentry.hxx> |
7fd59977 |
26 | #include <ShapeExtend_Explorer.hxx> |
42cf5bc1 |
27 | #include <Standard_Transient.hxx> |
7fd59977 |
28 | #include <TopoDS_Compound.hxx> |
42cf5bc1 |
29 | #include <TopoDS_Shape.hxx> |
30 | #include <Transfer_Binder.hxx> |
7fd59977 |
31 | #include <Transfer_IteratorOfProcessForTransient.hxx> |
32 | #include <Transfer_TransientProcess.hxx> |
42cf5bc1 |
33 | #include <XSControl_Controller.hxx> |
34 | #include <XSControl_Reader.hxx> |
35 | #include <XSControl_TransferReader.hxx> |
36 | #include <XSControl_WorkSession.hxx> |
7fd59977 |
37 | |
42cf5bc1 |
38 | //#include <ShapeCustom.hxx> |
7fd59977 |
39 | //#include <ShapeAlgo.hxx> |
40 | //#include <ShapeAlgo_AlgoContainer.hxx> |
7fd59977 |
41 | //======================================================================= |
42 | //function : XSControl_Reader |
43 | //purpose : |
44 | //======================================================================= |
7fd59977 |
45 | XSControl_Reader::XSControl_Reader () |
46 | { |
47 | SetWS (new XSControl_WorkSession); |
48 | } |
49 | |
50 | |
51 | //======================================================================= |
52 | //function : XSControl_Reader |
53 | //purpose : |
54 | //======================================================================= |
55 | |
56 | XSControl_Reader::XSControl_Reader (const Standard_CString norm) |
57 | { |
58 | SetNorm (norm); |
59 | } |
60 | |
61 | |
62 | //======================================================================= |
63 | //function : XSControl_Reader |
64 | //purpose : |
65 | //======================================================================= |
66 | |
67 | XSControl_Reader::XSControl_Reader(const Handle(XSControl_WorkSession)& WS, |
68 | const Standard_Boolean scratch) |
69 | { |
70 | SetWS (WS,scratch); |
71 | } |
72 | |
73 | |
74 | //======================================================================= |
75 | //function : SetNorm |
76 | //purpose : |
77 | //======================================================================= |
78 | |
79 | Standard_Boolean XSControl_Reader::SetNorm (const Standard_CString norm) |
80 | { |
81 | if (thesession.IsNull()) SetWS (new XSControl_WorkSession); |
82 | Standard_Boolean stat = thesession->SelectNorm (norm); |
83 | if (stat) { |
84 | thesession->InitTransferReader(0); |
85 | thesession->InitTransferReader(4); |
86 | } |
87 | return stat; |
88 | } |
89 | |
90 | |
91 | //======================================================================= |
92 | //function : SetWS |
93 | //purpose : |
94 | //======================================================================= |
95 | |
96 | void XSControl_Reader::SetWS(const Handle(XSControl_WorkSession)& WS, |
97 | const Standard_Boolean scratch) |
98 | { |
99 | therootsta = Standard_False; |
100 | theroots.Clear(); |
101 | thesession = WS; |
102 | // Il doit y avoir un Controller ... Sinon onverra plus tard (apres SetNorm) |
103 | if (thesession->NormAdaptor().IsNull()) return; |
104 | Handle(Interface_InterfaceModel) model = thesession->Model (); |
105 | if (scratch || model.IsNull()) model = thesession->NewModel (); |
106 | thesession->InitTransferReader(0); |
107 | thesession->InitTransferReader(4); |
108 | } |
109 | |
110 | |
111 | //======================================================================= |
112 | //function : WS |
113 | //purpose : |
114 | //======================================================================= |
115 | |
116 | Handle(XSControl_WorkSession) XSControl_Reader::WS () const |
117 | { |
118 | return thesession; |
119 | } |
120 | |
121 | |
122 | //======================================================================= |
123 | //function : ReadFile |
124 | //purpose : |
125 | //======================================================================= |
126 | |
127 | IFSelect_ReturnStatus XSControl_Reader::ReadFile |
128 | (const Standard_CString filename) |
129 | { |
130 | IFSelect_ReturnStatus stat = thesession->ReadFile(filename); |
131 | thesession->InitTransferReader(4); |
132 | return stat; |
133 | } |
134 | |
135 | |
136 | Handle(Interface_InterfaceModel) XSControl_Reader::Model () const |
137 | { |
138 | return thesession->Model(); |
139 | } |
140 | |
141 | |
142 | //======================================================================= |
143 | //function : GiveList |
144 | //purpose : |
145 | //======================================================================= |
146 | |
147 | Handle(TColStd_HSequenceOfTransient) XSControl_Reader::GiveList |
148 | (const Standard_CString first, const Standard_CString second) |
149 | { |
150 | if (first && first[0] != '\0') { |
151 | return thesession->GiveList (first,second); |
152 | } |
153 | |
154 | Handle(TColStd_HSequenceOfTransient) list = new TColStd_HSequenceOfTransient(); |
155 | Standard_Integer i,nbr = NbRootsForTransfer(); |
156 | for (i = 1; i <= nbr; i ++) list->Append (RootForTransfer(i)); |
157 | return list; |
158 | } |
159 | |
160 | |
161 | //======================================================================= |
162 | //function : GiveList |
163 | //purpose : |
164 | //======================================================================= |
165 | |
166 | Handle(TColStd_HSequenceOfTransient) XSControl_Reader::GiveList |
167 | (const Standard_CString first, const Handle(Standard_Transient)& list) |
168 | { |
169 | return thesession->GiveListFromList (first,list); |
170 | } |
171 | |
172 | |
173 | //======================================================================= |
174 | //function : NbRootsForTransfer |
175 | //purpose : |
176 | //======================================================================= |
177 | |
178 | Standard_Integer XSControl_Reader::NbRootsForTransfer () |
179 | { |
180 | if (therootsta) return theroots.Length(); |
181 | therootsta = Standard_True; |
182 | Interface_ShareFlags sf (thesession->Graph()); |
183 | Standard_Integer i, nbr = sf.NbRoots(); |
184 | for (i = 1; i <= nbr; i ++) { |
185 | // on filtre les racines qu on sait transferer |
186 | Handle(Standard_Transient) start = sf.Root(i); |
187 | if (thesession->TransferReader()->Recognize(start)) theroots.Append(start); |
188 | } |
189 | return theroots.Length(); |
190 | } |
191 | |
192 | |
193 | //======================================================================= |
194 | //function : RootForTransfer |
195 | //purpose : |
196 | //======================================================================= |
197 | |
198 | Handle(Standard_Transient) XSControl_Reader::RootForTransfer |
199 | (const Standard_Integer num) |
200 | { |
201 | Handle(Standard_Transient) voidroot; |
202 | Standard_Integer nbr = NbRootsForTransfer(); |
203 | if (num < 1 || num > nbr) return voidroot; |
204 | return theroots.Value(num); |
205 | } |
206 | |
207 | |
208 | // #### TRANSFERT #### |
209 | |
210 | |
211 | //======================================================================= |
212 | //function : TransferOneRoot |
213 | //purpose : |
214 | //======================================================================= |
215 | |
216 | Standard_Boolean XSControl_Reader::TransferOneRoot(const Standard_Integer num) |
217 | { |
218 | return TransferEntity (RootForTransfer (num)); |
219 | } |
220 | |
221 | |
222 | //======================================================================= |
223 | //function : TransferOne |
224 | //purpose : |
225 | //======================================================================= |
226 | |
227 | Standard_Boolean XSControl_Reader::TransferOne(const Standard_Integer num) |
228 | { |
229 | return TransferEntity (thesession->StartingEntity (num)); |
230 | } |
231 | |
232 | |
233 | //======================================================================= |
234 | //function : TransferEntity |
235 | //purpose : |
236 | //======================================================================= |
237 | |
238 | Standard_Boolean XSControl_Reader::TransferEntity |
239 | (const Handle(Standard_Transient)& start) |
240 | { |
241 | if (start.IsNull()) return Standard_False; |
7f56eba8 |
242 | const Handle(XSControl_TransferReader) &TR = thesession->TransferReader(); |
7fd59977 |
243 | TR->BeginTransfer(); |
244 | if (TR->TransferOne (start) == 0) return Standard_False; |
245 | TopoDS_Shape sh = TR->ShapeResult(start); |
246 | //ShapeExtend_Explorer STU; |
247 | //SMH May 00: allow empty shapes (STEP CAX-IF, external references) |
248 | //if (STU.ShapeType(sh,Standard_True) == TopAbs_SHAPE) return Standard_False; // nulle-vide |
249 | theshapes.Append(sh); |
250 | return Standard_True; |
251 | } |
252 | |
253 | |
254 | //======================================================================= |
255 | //function : TransferList |
256 | //purpose : |
257 | //======================================================================= |
258 | |
259 | Standard_Integer XSControl_Reader::TransferList |
260 | (const Handle(TColStd_HSequenceOfTransient)& list) |
261 | { |
262 | if (list.IsNull()) return 0; |
263 | Standard_Integer nbt = 0; |
264 | Standard_Integer i, nb = list->Length(); |
7f56eba8 |
265 | const Handle(XSControl_TransferReader) &TR = thesession->TransferReader(); |
7fd59977 |
266 | TR->BeginTransfer(); |
267 | ClearShapes(); |
268 | ShapeExtend_Explorer STU; |
269 | for (i = 1; i <= nb; i ++) { |
270 | Handle(Standard_Transient) start = list->Value(i); |
271 | if (TR->TransferOne (start) == 0) continue; |
272 | TopoDS_Shape sh = TR->ShapeResult(start); |
273 | if (STU.ShapeType(sh,Standard_True) == TopAbs_SHAPE) continue; // nulle-vide |
274 | theshapes.Append(sh); |
275 | nbt ++; |
276 | } |
277 | return nbt; |
278 | } |
279 | |
280 | |
281 | //======================================================================= |
282 | //function : TransferRoots |
283 | //purpose : |
284 | //======================================================================= |
285 | |
286 | Standard_Integer XSControl_Reader::TransferRoots () |
287 | { |
288 | NbRootsForTransfer(); |
289 | Standard_Integer nbt = 0; |
290 | Standard_Integer i, nb = theroots.Length(); |
7f56eba8 |
291 | const Handle(XSControl_TransferReader) &TR = thesession->TransferReader(); |
7fd59977 |
292 | |
293 | TR->BeginTransfer(); |
294 | ClearShapes(); |
295 | ShapeExtend_Explorer STU; |
7f56eba8 |
296 | const Handle(Transfer_TransientProcess) &proc = thesession->TransferReader()->TransientProcess(); |
7fd59977 |
297 | Message_ProgressSentry PS ( proc->GetProgress(), "Root", 0, nb, 1 ); |
298 | for (i = 1; i <= nb && PS.More(); i ++,PS.Next()) { |
299 | Handle(Standard_Transient) start = theroots.Value(i); |
300 | if (TR->TransferOne (start) == 0) continue; |
301 | TopoDS_Shape sh = TR->ShapeResult(start); |
302 | if (STU.ShapeType(sh,Standard_True) == TopAbs_SHAPE) continue; // nulle-vide |
303 | theshapes.Append(sh); |
304 | nbt ++; |
305 | } |
306 | return nbt; |
307 | } |
308 | |
309 | |
310 | //======================================================================= |
311 | //function : ClearShapes |
312 | //purpose : |
313 | //======================================================================= |
314 | |
315 | void XSControl_Reader::ClearShapes () |
316 | { |
317 | theshapes.Clear(); |
318 | } |
319 | |
320 | |
321 | //======================================================================= |
322 | //function : NbShapes |
323 | //purpose : |
324 | //======================================================================= |
325 | |
326 | Standard_Integer XSControl_Reader::NbShapes () const |
327 | { |
328 | return theshapes.Length(); |
329 | } |
330 | |
331 | |
332 | //======================================================================= |
333 | //function : Shapes |
334 | //purpose : |
335 | //======================================================================= |
336 | |
337 | TopTools_SequenceOfShape& XSControl_Reader::Shapes() |
338 | { |
339 | return theshapes; |
340 | } |
341 | |
342 | |
343 | //======================================================================= |
344 | //function : Shape |
345 | //purpose : |
346 | //======================================================================= |
347 | |
348 | TopoDS_Shape XSControl_Reader::Shape (const Standard_Integer num) const |
349 | { |
350 | return theshapes.Value(num); |
351 | } |
352 | |
353 | |
354 | //======================================================================= |
355 | //function : OneShape |
356 | //purpose : |
357 | //======================================================================= |
358 | |
359 | TopoDS_Shape XSControl_Reader::OneShape () const |
360 | { |
361 | TopoDS_Shape sh; |
362 | Standard_Integer i,nb = theshapes.Length(); |
363 | if (nb == 0) return sh; |
364 | if (nb == 1) return theshapes.Value(1); |
365 | TopoDS_Compound C; |
366 | BRep_Builder B; |
367 | //pdn 26.02.99 testing S4133 |
368 | B.MakeCompound(C); |
369 | for (i = 1; i <= nb; i ++) B.Add (C,theshapes.Value(i)); |
370 | return C; |
371 | } |
372 | |
7fd59977 |
373 | //======================================================================= |
374 | //function : PrintCheckLoad |
0ebe5b0a |
375 | //purpose : |
7fd59977 |
376 | //======================================================================= |
0ebe5b0a |
377 | void XSControl_Reader::PrintCheckLoad (Standard_OStream& theStream, |
378 | const Standard_Boolean failsonly, |
379 | const IFSelect_PrintCount mode) const |
380 | { |
381 | thesession->PrintCheckList (theStream, thesession->ModelCheckList(),failsonly, mode); |
382 | } |
7fd59977 |
383 | |
0ebe5b0a |
384 | //======================================================================= |
385 | //function : PrintCheckLoad |
386 | //purpose : |
387 | //======================================================================= |
7fd59977 |
388 | void XSControl_Reader::PrintCheckLoad (const Standard_Boolean failsonly, |
389 | const IFSelect_PrintCount mode) const |
390 | { |
0ebe5b0a |
391 | Message_Messenger::StreamBuffer aBuffer = Message::SendInfo(); |
392 | PrintCheckLoad (aBuffer, failsonly, mode); |
7fd59977 |
393 | } |
394 | |
7fd59977 |
395 | //======================================================================= |
396 | //function : PrintCheckTransfer |
0ebe5b0a |
397 | //purpose : |
7fd59977 |
398 | //======================================================================= |
0ebe5b0a |
399 | void XSControl_Reader::PrintCheckTransfer(Standard_OStream& theStream, |
400 | const Standard_Boolean failsonly, |
401 | const IFSelect_PrintCount mode) const |
402 | { |
403 | thesession->PrintCheckList (theStream, thesession->TransferReader()->LastCheckList(), failsonly, mode); |
404 | } |
7fd59977 |
405 | |
0ebe5b0a |
406 | //======================================================================= |
407 | //function : PrintCheckTransfer |
408 | //purpose : |
409 | //======================================================================= |
7fd59977 |
410 | void XSControl_Reader::PrintCheckTransfer(const Standard_Boolean failsonly, |
411 | const IFSelect_PrintCount mode) const |
412 | { |
0ebe5b0a |
413 | Message_Messenger::StreamBuffer aBuffer = Message::SendInfo(); |
414 | PrintCheckTransfer(aBuffer, failsonly, mode); |
7fd59977 |
415 | } |
416 | |
7fd59977 |
417 | //======================================================================= |
418 | //function : PrintStatsTransfer |
0ebe5b0a |
419 | //purpose : |
7fd59977 |
420 | //======================================================================= |
0ebe5b0a |
421 | void XSControl_Reader::PrintStatsTransfer (Standard_OStream& theStream, |
422 | const Standard_Integer what, |
423 | const Standard_Integer mode) const |
424 | { |
425 | thesession->TransferReader()->PrintStats (theStream, what,mode); |
426 | } |
7fd59977 |
427 | |
0ebe5b0a |
428 | //======================================================================= |
429 | //function : PrintStatsTransfer |
430 | //purpose : |
431 | //======================================================================= |
7fd59977 |
432 | void XSControl_Reader::PrintStatsTransfer (const Standard_Integer what, |
433 | const Standard_Integer mode) const |
434 | { |
0ebe5b0a |
435 | Message_Messenger::StreamBuffer aBuffer = Message::SendInfo(); |
436 | PrintStatsTransfer (aBuffer, what, mode); |
7fd59977 |
437 | } |
438 | |
7fd59977 |
439 | //======================================================================= |
440 | //function : GetStatsTransfer |
441 | //purpose : |
442 | //======================================================================= |
443 | |
444 | void XSControl_Reader::GetStatsTransfer (const Handle(TColStd_HSequenceOfTransient)& list, |
445 | Standard_Integer& nbMapped, |
446 | Standard_Integer& nbWithResult, |
447 | Standard_Integer& nbWithFail) const |
448 | { |
7f56eba8 |
449 | const Handle(Transfer_TransientProcess) &TP = thesession->TransferReader()->TransientProcess(); |
7fd59977 |
450 | Transfer_IteratorOfProcessForTransient itrp(Standard_True); |
451 | itrp = TP->CompleteResult(Standard_True); |
452 | if(!list.IsNull()) itrp.Filter (list); |
453 | nbMapped = nbWithFail = nbWithResult = 0; |
454 | |
455 | for (itrp.Start(); itrp.More(); itrp.Next()) { |
456 | Handle(Transfer_Binder) binder = itrp.Value(); |
457 | Handle(Standard_Transient) ent = itrp.Starting(); |
458 | nbMapped++; |
459 | if (binder.IsNull()) nbWithFail++; |
460 | else |
461 | if(!binder->HasResult()) nbWithFail++; |
462 | else |
463 | { |
464 | Interface_CheckStatus cst = binder->Check()->Status(); |
465 | if ((cst == Interface_CheckOK)||(cst == Interface_CheckWarning)) |
466 | nbWithResult++; |
467 | else |
468 | nbWithFail++; |
469 | } |
470 | } |
471 | } |
472 | |