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