1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 // pdn 26.02.99 added initializing of compound in function OneShape
15 //: gka 14.04.99: S4136: apply scaling
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>
24 #include <ShapeExtend_Explorer.hxx>
25 #include <Standard_Transient.hxx>
26 #include <TopoDS_Compound.hxx>
27 #include <TopoDS_Shape.hxx>
28 #include <Transfer_Binder.hxx>
29 #include <Transfer_IteratorOfProcessForTransient.hxx>
30 #include <Transfer_TransientProcess.hxx>
31 #include <XSControl_Controller.hxx>
32 #include <XSControl_Reader.hxx>
33 #include <XSControl_TransferReader.hxx>
34 #include <XSControl_WorkSession.hxx>
36 //#include <ShapeCustom.hxx>
37 //#include <ShapeAlgo.hxx>
38 //#include <ShapeAlgo_AlgoContainer.hxx>
39 //=======================================================================
40 //function : XSControl_Reader
42 //=======================================================================
43 XSControl_Reader::XSControl_Reader ()
45 SetWS (new XSControl_WorkSession);
49 //=======================================================================
50 //function : XSControl_Reader
52 //=======================================================================
54 XSControl_Reader::XSControl_Reader (const Standard_CString norm)
60 //=======================================================================
61 //function : XSControl_Reader
63 //=======================================================================
65 XSControl_Reader::XSControl_Reader(const Handle(XSControl_WorkSession)& WS,
66 const Standard_Boolean scratch)
72 //=======================================================================
75 //=======================================================================
77 Standard_Boolean XSControl_Reader::SetNorm (const Standard_CString norm)
79 if (thesession.IsNull()) SetWS (new XSControl_WorkSession);
80 Standard_Boolean stat = thesession->SelectNorm (norm);
82 thesession->InitTransferReader(0);
83 thesession->InitTransferReader(4);
89 //=======================================================================
92 //=======================================================================
94 void XSControl_Reader::SetWS(const Handle(XSControl_WorkSession)& WS,
95 const Standard_Boolean scratch)
97 therootsta = Standard_False;
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);
109 //=======================================================================
112 //=======================================================================
114 Handle(XSControl_WorkSession) XSControl_Reader::WS () const
120 //=======================================================================
121 //function : ReadFile
123 //=======================================================================
125 IFSelect_ReturnStatus XSControl_Reader::ReadFile
126 (const Standard_CString filename)
128 IFSelect_ReturnStatus stat = thesession->ReadFile(filename);
129 thesession->InitTransferReader(4);
134 Handle(Interface_InterfaceModel) XSControl_Reader::Model () const
136 return thesession->Model();
140 //=======================================================================
141 //function : GiveList
143 //=======================================================================
145 Handle(TColStd_HSequenceOfTransient) XSControl_Reader::GiveList
146 (const Standard_CString first, const Standard_CString second)
148 if (first && first[0] != '\0') {
149 return thesession->GiveList (first,second);
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));
159 //=======================================================================
160 //function : GiveList
162 //=======================================================================
164 Handle(TColStd_HSequenceOfTransient) XSControl_Reader::GiveList
165 (const Standard_CString first, const Handle(Standard_Transient)& list)
167 return thesession->GiveListFromList (first,list);
171 //=======================================================================
172 //function : NbRootsForTransfer
174 //=======================================================================
176 Standard_Integer XSControl_Reader::NbRootsForTransfer ()
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);
187 return theroots.Length();
191 //=======================================================================
192 //function : RootForTransfer
194 //=======================================================================
196 Handle(Standard_Transient) XSControl_Reader::RootForTransfer
197 (const Standard_Integer num)
199 Handle(Standard_Transient) voidroot;
200 Standard_Integer nbr = NbRootsForTransfer();
201 if (num < 1 || num > nbr) return voidroot;
202 return theroots.Value(num);
206 // #### TRANSFERT ####
209 //=======================================================================
210 //function : TransferOneRoot
212 //=======================================================================
214 Standard_Boolean XSControl_Reader::TransferOneRoot(const Standard_Integer num)
216 return TransferEntity (RootForTransfer (num));
220 //=======================================================================
221 //function : TransferOne
223 //=======================================================================
225 Standard_Boolean XSControl_Reader::TransferOne(const Standard_Integer num)
227 return TransferEntity (thesession->StartingEntity (num));
231 //=======================================================================
232 //function : TransferEntity
234 //=======================================================================
236 Standard_Boolean XSControl_Reader::TransferEntity
237 (const Handle(Standard_Transient)& start)
239 if (start.IsNull()) return Standard_False;
240 const Handle(XSControl_TransferReader) &TR = thesession->TransferReader();
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;
252 //=======================================================================
253 //function : TransferList
255 //=======================================================================
257 Standard_Integer XSControl_Reader::TransferList
258 (const Handle(TColStd_HSequenceOfTransient)& list)
260 if (list.IsNull()) return 0;
261 Standard_Integer nbt = 0;
262 Standard_Integer i, nb = list->Length();
263 const Handle(XSControl_TransferReader) &TR = thesession->TransferReader();
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);
279 //=======================================================================
280 //function : TransferRoots
282 //=======================================================================
284 Standard_Integer XSControl_Reader::TransferRoots ()
286 NbRootsForTransfer();
287 Standard_Integer nbt = 0;
288 Standard_Integer i, nb = theroots.Length();
289 const Handle(XSControl_TransferReader) &TR = thesession->TransferReader();
293 ShapeExtend_Explorer STU;
294 const Handle(Transfer_TransientProcess) &proc = thesession->TransferReader()->TransientProcess();
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);
308 //=======================================================================
309 //function : ClearShapes
311 //=======================================================================
313 void XSControl_Reader::ClearShapes ()
319 //=======================================================================
320 //function : NbShapes
322 //=======================================================================
324 Standard_Integer XSControl_Reader::NbShapes () const
326 return theshapes.Length();
330 //=======================================================================
333 //=======================================================================
335 TopTools_SequenceOfShape& XSControl_Reader::Shapes()
341 //=======================================================================
344 //=======================================================================
346 TopoDS_Shape XSControl_Reader::Shape (const Standard_Integer num) const
348 return theshapes.Value(num);
352 //=======================================================================
353 //function : OneShape
355 //=======================================================================
357 TopoDS_Shape XSControl_Reader::OneShape () const
360 Standard_Integer i,nb = theshapes.Length();
361 if (nb == 0) return sh;
362 if (nb == 1) return theshapes.Value(1);
365 //pdn 26.02.99 testing S4133
367 for (i = 1; i <= nb; i ++) B.Add (C,theshapes.Value(i));
372 //=======================================================================
373 //function : PrintCheckLoad
375 //=======================================================================
377 void XSControl_Reader::PrintCheckLoad (const Standard_Boolean failsonly,
378 const IFSelect_PrintCount mode) const
380 thesession->PrintCheckList (thesession->ModelCheckList(),failsonly, mode);
384 //=======================================================================
385 //function : PrintCheckTransfer
387 //=======================================================================
389 void XSControl_Reader::PrintCheckTransfer(const Standard_Boolean failsonly,
390 const IFSelect_PrintCount mode) const
392 thesession->PrintCheckList (thesession->TransferReader()->LastCheckList(),failsonly, mode);
396 //=======================================================================
397 //function : PrintStatsTransfer
399 //=======================================================================
401 void XSControl_Reader::PrintStatsTransfer (const Standard_Integer what,
402 const Standard_Integer mode) const
404 thesession->TransferReader()->PrintStats (what,mode);
408 //=======================================================================
409 //function : GetStatsTransfer
411 //=======================================================================
413 void XSControl_Reader::GetStatsTransfer (const Handle(TColStd_HSequenceOfTransient)& list,
414 Standard_Integer& nbMapped,
415 Standard_Integer& nbWithResult,
416 Standard_Integer& nbWithFail) const
418 const Handle(Transfer_TransientProcess) &TP = thesession->TransferReader()->TransientProcess();
419 Transfer_IteratorOfProcessForTransient itrp(Standard_True);
420 itrp = TP->CompleteResult(Standard_True);
421 if(!list.IsNull()) itrp.Filter (list);
422 nbMapped = nbWithFail = nbWithResult = 0;
424 for (itrp.Start(); itrp.More(); itrp.Next()) {
425 Handle(Transfer_Binder) binder = itrp.Value();
426 Handle(Standard_Transient) ent = itrp.Starting();
428 if (binder.IsNull()) nbWithFail++;
430 if(!binder->HasResult()) nbWithFail++;
433 Interface_CheckStatus cst = binder->Check()->Status();
434 if ((cst == Interface_CheckOK)||(cst == Interface_CheckWarning))