1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
18 #include <IGESToBRep_Actor.ixx>
19 #include <IGESToBRep.hxx>
20 #include <IGESData_IGESEntity.hxx>
21 #include <IGESData_IGESModel.hxx>
22 #include <IGESData_GlobalSection.hxx>
23 #include <IGESToBRep_CurveAndSurface.hxx>
25 #include <BRepLib.hxx>
27 #include <Standard_Failure.hxx>
28 #include <Standard_ErrorHandler.hxx>
29 #include <ShapeExtend_Explorer.hxx>
30 #include <ShapeFix_ShapeTolerance.hxx>
32 #include <Interface_Macros.hxx>
33 #include <Interface_Static.hxx>
35 #include <Message_ProgressSentry.hxx>
37 #include <TopoDS_Shape.hxx>
38 #include <TransferBRep.hxx>
39 #include <TransferBRep_ShapeBinder.hxx>
42 #include <XSAlgo_AlgoContainer.hxx>
44 //=======================================================================
45 //function : IGESToBRep_Actor
47 //=======================================================================
48 IGESToBRep_Actor::IGESToBRep_Actor ()
49 { thecontinuity = 0; theeps = 0.0001; }
52 //=======================================================================
55 //=======================================================================
56 void IGESToBRep_Actor::SetModel (const Handle(Interface_InterfaceModel)& model)
59 theeps = Handle(IGESData_IGESModel)::DownCast(themodel)->GlobalSection().Resolution();
63 //=======================================================================
64 //function : SetContinuity
66 //=======================================================================
67 void IGESToBRep_Actor::SetContinuity (const Standard_Integer continuity)
69 thecontinuity = continuity;
73 //=======================================================================
74 //function : GetContinuity
76 //=======================================================================
77 Standard_Integer IGESToBRep_Actor::GetContinuity () const
82 //=======================================================================
83 //function : Recognize
85 //=======================================================================
86 Standard_Boolean IGESToBRep_Actor::Recognize
87 (const Handle(Standard_Transient)& start)
89 DeclareAndCast(IGESData_IGESModel,mymodel,themodel);
90 DeclareAndCast(IGESData_IGESEntity,ent,start);
91 if (ent.IsNull()) return Standard_False;
94 Standard_Integer typnum = ent->TypeNumber();
95 Standard_Integer fornum = ent->FormNumber();
96 if (IGESToBRep::IsCurveAndSurface(ent) ||
97 (typnum == 402 && (fornum == 1 || fornum == 7 ||
98 fornum == 14 || fornum == 15) ||
99 (typnum == 408 ) || (typnum == 308)))
100 return Standard_True;
102 // Cas restants : non reconnus
103 return Standard_False;
105 //=======================================================================
106 //function : EncodeRegul
107 //purpose : INTERNAL to encode regularity on edges
108 //=======================================================================
110 static Standard_Boolean EncodeRegul (const TopoDS_Shape& sh)
112 Standard_Real tolang = Interface_Static::RVal("read.encoderegularity.angle");
113 if (sh.IsNull()) return Standard_True;
114 if (tolang <= 0) return Standard_True;
117 BRepLib::EncodeRegularity (sh,tolang);
119 catch(Standard_Failure) {
120 return Standard_False;
122 return Standard_True;
124 //=======================================================================
125 //function : TrimTolerances
126 //purpose : Trims tolerances of the shape according to static parameters
128 //=======================================================================
130 static void TrimTolerances (const TopoDS_Shape& shape,
131 const Standard_Real tol)
133 if( Interface_Static::IVal("read.maxprecision.mode")==1) {
134 ShapeFix_ShapeTolerance SFST;
135 SFST.LimitTolerance (shape, 0, Max(tol,Interface_Static::RVal ("read.maxprecision.val")));
141 //=======================================================================
142 //function : Transfer
144 //=======================================================================
145 Handle(Transfer_Binder) IGESToBRep_Actor::Transfer
146 (const Handle(Standard_Transient)& start, const Handle(Transfer_TransientProcess)& TP)
148 DeclareAndCast(IGESData_IGESModel,mymodel,themodel);
149 DeclareAndCast(IGESData_IGESEntity,ent,start);
150 if (mymodel.IsNull() || ent.IsNull()) return NullResult();
151 Standard_Integer anum = mymodel->Number(start);
153 if(!Interface_Static::IVal("read.iges.faulty.entities") && mymodel->IsErrorEntity(anum))
157 // appeler le transfert seulement si type OK
158 Standard_Integer typnum = ent->TypeNumber();
159 Standard_Integer fornum = ent->FormNumber();
161 if (IGESToBRep::IsCurveAndSurface(ent) ||
162 (typnum == 402 && (fornum == 1 || fornum == 7||
163 fornum == 14 || fornum == 15)) ||
164 (typnum == 408) || (typnum == 308)) {
166 // Start progress scope (no need to check if progress exists -- it is safe)
167 Message_ProgressSentry aPSentry(TP->GetProgress(), "Transfer stage", 0, 2, 1);
169 XSAlgo::AlgoContainer()->PrepareForTransfer();
170 IGESToBRep_CurveAndSurface CAS;
171 CAS.SetModel(mymodel);
172 CAS.SetContinuity(thecontinuity);
173 CAS.SetTransferProcess(TP);
174 Standard_Integer Ival = Interface_Static::IVal("read.precision.mode");
176 eps = mymodel->GlobalSection().Resolution();
178 eps = Interface_Static::RVal("read.precision.val"); //:10 ABV 11 Nov 97
179 //:10 eps = BRepAPI::Precision();
180 Ival = Interface_Static::IVal("read.iges.bspline.approxd1.mode");
181 CAS.SetModeApprox ( (Ival > 0) );
182 Ival = Interface_Static::IVal("read.surfacecurve.mode");
183 CAS.SetSurfaceCurve (Ival);
187 theeps = eps*CAS.GetUnitFactor();
188 // Interface_Static::SetRVal("lastpreci",theeps);
190 Standard_Integer nbTPitems = TP->NbMapped();
194 shape = CAS.TransferGeometry(ent);
196 catch(Standard_Failure) {
201 // Switch to fix stage.
205 Handle(Standard_Transient) info;
206 shape = XSAlgo::AlgoContainer()->ProcessShape( shape, theeps, CAS.GetMaxTol(),
207 "read.iges.resource.name",
208 "read.iges.sequence", info,
210 XSAlgo::AlgoContainer()->MergeTransferInfo(TP, info, nbTPitems);
213 ShapeExtend_Explorer SBE;
214 if (SBE.ShapeType(shape,Standard_True) != TopAbs_SHAPE) {
215 if (!shape.IsNull()) {
217 //#74 rln 03.03.99 S4135
218 TrimTolerances (shape, UsedTolerance());
219 // Shapes().Append(shape);
222 Handle(TransferBRep_ShapeBinder) binder;
223 if (!shape.IsNull()) binder = new TransferBRep_ShapeBinder(shape);
228 Standard_Real IGESToBRep_Actor::UsedTolerance () const