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.
15 #include <BRepLib.hxx>
16 #include <IGESData_GlobalSection.hxx>
17 #include <IGESData_IGESEntity.hxx>
18 #include <IGESData_IGESModel.hxx>
19 #include <IGESToBRep.hxx>
20 #include <IGESToBRep_Actor.hxx>
21 #include <IGESToBRep_CurveAndSurface.hxx>
22 #include <Interface_InterfaceModel.hxx>
23 #include <Interface_Macros.hxx>
24 #include <Interface_Static.hxx>
25 #include <Message_ProgressSentry.hxx>
26 #include <ShapeExtend_Explorer.hxx>
27 #include <ShapeFix_ShapeTolerance.hxx>
28 #include <Standard_ErrorHandler.hxx>
29 #include <Standard_Failure.hxx>
30 #include <Standard_Transient.hxx>
31 #include <Standard_Type.hxx>
32 #include <TopoDS_Shape.hxx>
33 #include <Transfer_Binder.hxx>
34 #include <Transfer_TransientProcess.hxx>
35 #include <TransferBRep.hxx>
36 #include <TransferBRep_ShapeBinder.hxx>
38 #include <XSAlgo_AlgoContainer.hxx>
40 IMPLEMENT_STANDARD_RTTIEXT(IGESToBRep_Actor,Transfer_ActorOfTransientProcess)
42 //=======================================================================
43 //function : IGESToBRep_Actor
45 //=======================================================================
46 IGESToBRep_Actor::IGESToBRep_Actor ()
47 { thecontinuity = 0; theeps = 0.0001; }
50 //=======================================================================
53 //=======================================================================
54 void IGESToBRep_Actor::SetModel (const Handle(Interface_InterfaceModel)& model)
57 theeps = Handle(IGESData_IGESModel)::DownCast(themodel)->GlobalSection().Resolution();
61 //=======================================================================
62 //function : SetContinuity
64 //=======================================================================
65 void IGESToBRep_Actor::SetContinuity (const Standard_Integer continuity)
67 thecontinuity = continuity;
71 //=======================================================================
72 //function : GetContinuity
74 //=======================================================================
75 Standard_Integer IGESToBRep_Actor::GetContinuity () const
80 //=======================================================================
81 //function : Recognize
83 //=======================================================================
84 Standard_Boolean IGESToBRep_Actor::Recognize
85 (const Handle(Standard_Transient)& start)
87 DeclareAndCast(IGESData_IGESModel,mymodel,themodel);
88 DeclareAndCast(IGESData_IGESEntity,ent,start);
89 if (ent.IsNull()) return Standard_False;
92 Standard_Integer typnum = ent->TypeNumber();
93 Standard_Integer fornum = ent->FormNumber();
94 if (IGESToBRep::IsCurveAndSurface(ent) ||
95 ((typnum == 402 && (fornum == 1 || fornum == 7 ||
96 fornum == 14 || fornum == 15)) ||
97 (typnum == 408 ) || (typnum == 308)))
100 // Cas restants : non reconnus
101 return Standard_False;
103 //=======================================================================
104 //function : EncodeRegul
105 //purpose : INTERNAL to encode regularity on edges
106 //=======================================================================
108 static Standard_Boolean EncodeRegul (const TopoDS_Shape& sh)
110 Standard_Real tolang = Interface_Static::RVal("read.encoderegularity.angle");
111 if (sh.IsNull()) return Standard_True;
112 if (tolang <= 0) return Standard_True;
115 BRepLib::EncodeRegularity (sh,tolang);
117 catch(Standard_Failure const&) {
118 return Standard_False;
120 return Standard_True;
122 //=======================================================================
123 //function : TrimTolerances
124 //purpose : Trims tolerances of the shape according to static parameters
126 //=======================================================================
128 static void TrimTolerances (const TopoDS_Shape& shape,
129 const Standard_Real tol)
131 if( Interface_Static::IVal("read.maxprecision.mode")==1) {
132 ShapeFix_ShapeTolerance SFST;
133 SFST.LimitTolerance (shape, 0, Max(tol,Interface_Static::RVal ("read.maxprecision.val")));
139 //=======================================================================
140 //function : Transfer
142 //=======================================================================
143 Handle(Transfer_Binder) IGESToBRep_Actor::Transfer
144 (const Handle(Standard_Transient)& start, const Handle(Transfer_TransientProcess)& TP)
146 DeclareAndCast(IGESData_IGESModel,mymodel,themodel);
147 DeclareAndCast(IGESData_IGESEntity,ent,start);
148 if (mymodel.IsNull() || ent.IsNull()) return NullResult();
149 Standard_Integer anum = mymodel->Number(start);
151 if (Interface_Static::IVal("read.iges.faulty.entities") == 0 && mymodel->IsErrorEntity(anum))
155 // appeler le transfert seulement si type OK
156 Standard_Integer typnum = ent->TypeNumber();
157 Standard_Integer fornum = ent->FormNumber();
159 if (IGESToBRep::IsCurveAndSurface(ent) ||
160 (typnum == 402 && (fornum == 1 || fornum == 7||
161 fornum == 14 || fornum == 15)) ||
162 (typnum == 408) || (typnum == 308)) {
164 // Start progress scope (no need to check if progress exists -- it is safe)
165 Message_ProgressSentry aPSentry(TP->GetProgress(), "Transfer stage", 0, 2, 1);
167 XSAlgo::AlgoContainer()->PrepareForTransfer();
168 IGESToBRep_CurveAndSurface CAS;
169 CAS.SetModel(mymodel);
170 CAS.SetContinuity(thecontinuity);
171 CAS.SetTransferProcess(TP);
172 Standard_Integer Ival = Interface_Static::IVal("read.precision.mode");
174 eps = mymodel->GlobalSection().Resolution();
176 eps = Interface_Static::RVal("read.precision.val"); //:10 ABV 11 Nov 97
177 //:10 eps = BRepAPI::Precision();
178 Ival = Interface_Static::IVal("read.iges.bspline.approxd1.mode");
179 CAS.SetModeApprox ( (Ival > 0) );
180 Ival = Interface_Static::IVal("read.surfacecurve.mode");
181 CAS.SetSurfaceCurve (Ival);
185 theeps = eps*CAS.GetUnitFactor();
186 // Interface_Static::SetRVal("lastpreci",theeps);
188 Standard_Integer nbTPitems = TP->NbMapped();
192 shape = CAS.TransferGeometry(ent);
194 catch(Standard_Failure const&) {
199 // Switch to fix stage.
203 Handle(Standard_Transient) info;
204 shape = XSAlgo::AlgoContainer()->ProcessShape( shape, theeps, CAS.GetMaxTol(),
205 "read.iges.resource.name",
206 "read.iges.sequence", info,
208 XSAlgo::AlgoContainer()->MergeTransferInfo(TP, info, nbTPitems);
211 ShapeExtend_Explorer SBE;
212 if (SBE.ShapeType(shape,Standard_True) != TopAbs_SHAPE) {
213 if (!shape.IsNull()) {
215 //#74 rln 03.03.99 S4135
216 TrimTolerances (shape, UsedTolerance());
217 // Shapes().Append(shape);
220 Handle(TransferBRep_ShapeBinder) binder;
221 if (!shape.IsNull()) binder = new TransferBRep_ShapeBinder(shape);
226 Standard_Real IGESToBRep_Actor::UsedTolerance () const