Integration of OCCT 6.5.0 from SVN
[occt.git] / src / IGESToBRep / IGESToBRep_Actor.cxx
1 #include <Standard_ErrorHandler.hxx>
2 #include <IGESToBRep_Actor.ixx>
3 #include <Standard_Failure.hxx>
4
5 #include <IGESToBRep.hxx>
6 #include <IGESData_IGESEntity.hxx>
7 #include <IGESData_IGESModel.hxx>
8 #include <IGESData_GlobalSection.hxx>
9
10 #include <IGESToBRep_CurveAndSurface.hxx>
11
12 #include <Interface_Macros.hxx>
13 #include <Interface_Static.hxx>
14
15 #include <TopoDS_Shape.hxx>
16
17 #include <TransferBRep.hxx>
18 #include <TransferBRep_ShapeBinder.hxx>
19
20 #include <XSAlgo.hxx>
21 #include <XSAlgo_AlgoContainer.hxx>
22 #include <ShapeFix_ShapeTolerance.hxx>
23 #include <BRepLib.hxx>
24 #include <ShapeExtend_Explorer.hxx>
25
26 //=======================================================================
27 //function : IGESToBRep_Actor
28 //purpose  : 
29 //=======================================================================
30 IGESToBRep_Actor::IGESToBRep_Actor ()
31 {  thecontinuity = 0;  theeps = 0.0001;  }
32
33
34 //=======================================================================
35 //function : SetModel
36 //purpose  : 
37 //=======================================================================
38 void IGESToBRep_Actor::SetModel (const Handle(Interface_InterfaceModel)& model)
39 {
40   themodel = model;
41   theeps = Handle(IGESData_IGESModel)::DownCast(themodel)->GlobalSection().Resolution();
42 }
43
44
45 //=======================================================================
46 //function : SetContinuity
47 //purpose  : 
48 //=======================================================================
49 void  IGESToBRep_Actor::SetContinuity (const Standard_Integer continuity)
50 {
51   thecontinuity = continuity;
52 }
53
54
55 //=======================================================================
56 //function : GetContinuity
57 //purpose  : 
58 //=======================================================================
59 Standard_Integer  IGESToBRep_Actor::GetContinuity () const
60 {
61   return thecontinuity;
62 }
63
64 //=======================================================================
65 //function : Recognize
66 //purpose  : 
67 //=======================================================================
68 Standard_Boolean  IGESToBRep_Actor::Recognize
69 (const Handle(Standard_Transient)& start)
70 {
71   DeclareAndCast(IGESData_IGESModel,mymodel,themodel);
72   DeclareAndCast(IGESData_IGESEntity,ent,start);
73   if (ent.IsNull()) return Standard_False;
74
75 //   Cas reconnus
76   Standard_Integer typnum = ent->TypeNumber();
77   Standard_Integer fornum = ent->FormNumber();
78   if (IGESToBRep::IsCurveAndSurface(ent) ||
79       (typnum == 402 && (fornum == 1 || fornum == 7 || 
80                          fornum == 14 || fornum == 15)  ||
81       (typnum == 408 ) || (typnum == 308)))
82     return Standard_True;
83
84 //  Cas restants : non reconnus
85   return Standard_False;
86 }
87 //=======================================================================
88 //function : EncodeRegul
89 //purpose  : INTERNAL to encode regularity on edges
90 //=======================================================================
91
92 static Standard_Boolean  EncodeRegul (const TopoDS_Shape& sh)
93 {
94   Standard_Real tolang = Interface_Static::RVal("read.encoderegularity.angle");
95   if (sh.IsNull()) return Standard_True;
96   if (tolang <= 0) return Standard_True;
97   try {
98     OCC_CATCH_SIGNALS
99     BRepLib::EncodeRegularity (sh,tolang);
100   }
101   catch(Standard_Failure) {
102     return Standard_False;
103   }
104   return Standard_True;
105 }
106 //=======================================================================
107 //function : TrimTolerances
108 //purpose  : Trims tolerances of the shape according to static parameters
109 //          
110 //=======================================================================
111
112 static void TrimTolerances (const TopoDS_Shape& shape,
113                             const Standard_Real tol)
114 {
115   if( Interface_Static::IVal("read.maxprecision.mode")==1) {
116     ShapeFix_ShapeTolerance SFST;
117     SFST.LimitTolerance (shape, 0, Max(tol,Interface_Static::RVal ("read.maxprecision.val")));
118   }
119 }
120
121
122
123 //=======================================================================
124 //function : Transfer
125 //purpose  : 
126 //=======================================================================
127 Handle(Transfer_Binder) IGESToBRep_Actor::Transfer
128 (const Handle(Standard_Transient)& start, const Handle(Transfer_TransientProcess)& TP)
129 {
130   DeclareAndCast(IGESData_IGESModel,mymodel,themodel);
131   DeclareAndCast(IGESData_IGESEntity,ent,start);
132   if (mymodel.IsNull() || ent.IsNull()) return NullResult();
133   Standard_Integer anum = mymodel->Number(start);
134   
135   if(!Interface_Static::IVal("read.iges.faulty.entities") && mymodel->IsErrorEntity(anum)) 
136     return NullResult();
137   TopoDS_Shape shape;
138
139 //   appeler le transfert seulement si type OK
140   Standard_Integer typnum = ent->TypeNumber();
141   Standard_Integer fornum = ent->FormNumber();
142   Standard_Real eps;
143   if (IGESToBRep::IsCurveAndSurface(ent) ||
144       (typnum == 402 && (fornum == 1 || fornum == 7|| 
145                          fornum == 14 || fornum == 15)) || 
146       (typnum == 408) || (typnum == 308)) {
147     XSAlgo::AlgoContainer()->PrepareForTransfer();
148     IGESToBRep_CurveAndSurface CAS;
149     CAS.SetModel(mymodel);
150     CAS.SetContinuity(thecontinuity);
151     CAS.SetTransferProcess(TP);
152     Standard_Integer Ival = Interface_Static::IVal("read.precision.mode");
153     if ( Ival == 0)
154       eps = mymodel->GlobalSection().Resolution();
155     else
156       eps = Interface_Static::RVal("read.precision.val"); //:10 ABV 11 Nov 97
157 //:10      eps = BRepAPI::Precision(); 
158     Ival = Interface_Static::IVal("read.iges.bspline.approxd1.mode");
159     CAS.SetModeApprox ( (Ival > 0) );
160     Ival = Interface_Static::IVal("read.surfacecurve.mode");
161     CAS.SetSurfaceCurve (Ival);
162
163     if (eps > 1.E-08) {
164       CAS.SetEpsGeom(eps);
165       theeps = eps*CAS.GetUnitFactor();
166 //      Interface_Static::SetRVal("lastpreci",theeps);
167     }
168     Standard_Integer nbTPitems = TP->NbMapped();
169     {
170       try {
171         OCC_CATCH_SIGNALS
172         shape = CAS.TransferGeometry(ent);
173       }
174       catch(Standard_Failure) {
175         shape.Nullify();
176       }
177     }
178     
179     // fixing shape
180 //    shape =  XSAlgo::AlgoContainer()->PerformFixShape( shape, TP, theeps, CAS.GetMaxTol() );
181     Handle(Standard_Transient) info;
182     shape = XSAlgo::AlgoContainer()->ProcessShape( shape, theeps, CAS.GetMaxTol(), 
183                                                    "read.iges.resource.name", 
184                                                    "read.iges.sequence", info );
185     XSAlgo::AlgoContainer()->MergeTransferInfo(TP, info, nbTPitems);
186   }
187 // if (!shape.IsNull()) TransferBRep::SameParameter (shape,Standard_False,eps);
188   ShapeExtend_Explorer SBE;
189   if (SBE.ShapeType(shape,Standard_True) != TopAbs_SHAPE) {
190     if (!shape.IsNull()) {
191       EncodeRegul (shape);
192       //#74 rln 03.03.99 S4135
193       TrimTolerances (shape, UsedTolerance());
194    //   Shapes().Append(shape);
195     }
196   }
197   Handle(TransferBRep_ShapeBinder) binder;
198   if (!shape.IsNull()) binder = new TransferBRep_ShapeBinder(shape);
199   return binder;
200 }
201
202
203     Standard_Real  IGESToBRep_Actor::UsedTolerance () const
204       {  return theeps;  }