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