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