0025748: Parallel version of progress indicator
[occt.git] / src / IGESControl / IGESControl_ActorWrite.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14
15 #include <BRepToIGES_BREntity.hxx>
16 #include <BRepToIGESBRep_Entity.hxx>
17 #include <Geom_Curve.hxx>
18 #include <Geom_Surface.hxx>
19 #include <GeomToIGES_GeomCurve.hxx>
20 #include <GeomToIGES_GeomSurface.hxx>
21 #include <IGESControl_ActorWrite.hxx>
22 #include <IGESData_IGESEntity.hxx>
23 #include <IGESData_IGESModel.hxx>
24 #include <Interface_Macros.hxx>
25 #include <Interface_Static.hxx>
26 #include <Standard_Type.hxx>
27 #include <Transfer_Binder.hxx>
28 #include <Transfer_Finder.hxx>
29 #include <Transfer_FinderProcess.hxx>
30 #include <Transfer_SimpleBinderOfTransient.hxx>
31 #include <Transfer_TransientMapper.hxx>
32 #include <TransferBRep_ShapeMapper.hxx>
33 #include <XSAlgo.hxx>
34 #include <XSAlgo_AlgoContainer.hxx>
35
36 IMPLEMENT_STANDARD_RTTIEXT(IGESControl_ActorWrite,Transfer_ActorOfFinderProcess)
37
38 IGESControl_ActorWrite::IGESControl_ActorWrite ()  {  ModeTrans() = 0;  }
39
40 Standard_Boolean  IGESControl_ActorWrite::Recognize
41   (const Handle(Transfer_Finder)& start)
42 {
43   DeclareAndCast(TransferBRep_ShapeMapper,shmap,start);
44   if (!shmap.IsNull()) return Standard_True;
45   DeclareAndCast(Transfer_TransientMapper,gemap,start);
46   if (!gemap.IsNull()) {
47     Handle(Standard_Transient) geom = gemap->Value();
48     DeclareAndCast(Geom_Curve,Curve,geom);
49     DeclareAndCast(Geom_Surface,Surf,geom);
50     if (!Curve.IsNull() || !Surf.IsNull()) return Standard_True;
51   }
52   return Standard_False;
53 }
54
55 Handle(Transfer_Binder)  IGESControl_ActorWrite::Transfer
56   (const Handle(Transfer_Finder)& start,
57    const Handle(Transfer_FinderProcess)& FP,
58    const Message_ProgressRange& theProgress)
59 {
60   XSAlgo::AlgoContainer()->PrepareForTransfer();
61     
62   DeclareAndCast(IGESData_IGESModel,modl,FP->Model());
63   if (modl.IsNull()) return NullResult();
64   if (themodetrans < 0 || themodetrans > 1) return NullResult();
65   Handle(Standard_Transient) ent;
66
67   DeclareAndCast(TransferBRep_ShapeMapper,shmap,start);
68   if (!shmap.IsNull()) {
69     TopoDS_Shape shape = shmap->Value();
70     if (shape.IsNull()) return NullResult();
71 //  modified by NIZHNY-EAP Tue Aug 29 11:16:54 2000 ___BEGIN___
72     Handle(Standard_Transient) info;
73     Standard_Real Tol = Interface_Static::RVal("write.precision.val");
74     Standard_Real maxTol = Interface_Static::RVal("read.maxprecision.val");
75     shape = XSAlgo::AlgoContainer()->ProcessShape( shape, Tol, maxTol, 
76                                                    "write.iges.resource.name", 
77                                                    "write.iges.sequence", info,
78                                                    theProgress );
79 //  modified by NIZHNY-EAP Tue Aug 29 11:17:01 2000 ___END___
80
81     BRepToIGES_BREntity   BR0; BR0.SetModel(modl);  BR0.SetTransferProcess(FP);
82     BRepToIGESBRep_Entity BR1; BR1.SetModel(modl);  BR1.SetTransferProcess(FP);
83
84     if (themodetrans == 0) ent = BR0.TransferShape(shape, theProgress);
85     if (themodetrans == 1) ent = BR1.TransferShape(shape, theProgress);
86 //  modified by NIZHNY-EAP Tue Aug 29 11:37:18 2000 ___BEGIN___
87     XSAlgo::AlgoContainer()->MergeTransferInfo(FP, info);
88 //  modified by NIZHNY-EAP Tue Aug 29 11:37:25 2000 ___END___
89     if (!ent.IsNull()) return TransientResult(ent);
90   }
91   DeclareAndCast(Transfer_TransientMapper,gemap,start);
92   if (!gemap.IsNull()) {
93     Handle(Standard_Transient) geom = gemap->Value();
94     DeclareAndCast(Geom_Curve,Curve,geom);
95     DeclareAndCast(Geom_Surface,Surf,geom);
96  
97 //  On reconnait : Curve et Surface de Geom
98 //   quid de Point; Geom2d ?
99  
100 //  GeomToIGES_GeomPoint GP;
101     GeomToIGES_GeomCurve GC;    GC.SetModel(modl);
102     GeomToIGES_GeomSurface GS;  GS.SetModel(modl);
103     if (!Curve.IsNull())
104       ent = GC.TransferCurve(Curve,Curve->FirstParameter(),Curve->LastParameter())
105 ;
106     else if (!Surf.IsNull()) {
107       Standard_Real U1,U2,V1,V2;
108       Surf->Bounds(U1,U2,V1,V2);
109       ent = GS.TransferSurface(Surf,U1,U2,V1,V2);
110     }
111     if (!ent.IsNull()) return TransientResult(ent);
112   }
113
114   return NullResult();
115 }