0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / IGESToBRep / IGESToBRep_Actor.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 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
973c2be1 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.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
42cf5bc1 14
15#include <BRepLib.hxx>
7fd59977 16#include <IGESData_IGESModel.hxx>
42cf5bc1 17#include <IGESToBRep.hxx>
18#include <IGESToBRep_Actor.hxx>
7fd59977 19#include <IGESToBRep_CurveAndSurface.hxx>
42cf5bc1 20#include <Interface_InterfaceModel.hxx>
7fd59977 21#include <Interface_Macros.hxx>
22#include <Interface_Static.hxx>
7e785937 23#include <Message_ProgressScope.hxx>
42cf5bc1 24#include <ShapeExtend_Explorer.hxx>
25#include <ShapeFix_ShapeTolerance.hxx>
26#include <Standard_ErrorHandler.hxx>
27#include <Standard_Failure.hxx>
28#include <Standard_Transient.hxx>
29#include <Standard_Type.hxx>
b485ee79 30#include <TopoDS_Shape.hxx>
42cf5bc1 31#include <Transfer_Binder.hxx>
32#include <Transfer_TransientProcess.hxx>
7fd59977 33#include <TransferBRep_ShapeBinder.hxx>
7fd59977 34#include <XSAlgo.hxx>
35#include <XSAlgo_AlgoContainer.hxx>
7fd59977 36
92efcf78 37IMPLEMENT_STANDARD_RTTIEXT(IGESToBRep_Actor,Transfer_ActorOfTransientProcess)
38
7fd59977 39//=======================================================================
40//function : IGESToBRep_Actor
41//purpose :
42//=======================================================================
43IGESToBRep_Actor::IGESToBRep_Actor ()
44{ thecontinuity = 0; theeps = 0.0001; }
45
46
47//=======================================================================
48//function : SetModel
49//purpose :
50//=======================================================================
51void IGESToBRep_Actor::SetModel (const Handle(Interface_InterfaceModel)& model)
52{
53 themodel = model;
54 theeps = Handle(IGESData_IGESModel)::DownCast(themodel)->GlobalSection().Resolution();
55}
56
57
58//=======================================================================
59//function : SetContinuity
60//purpose :
61//=======================================================================
62void IGESToBRep_Actor::SetContinuity (const Standard_Integer continuity)
63{
64 thecontinuity = continuity;
65}
66
67
68//=======================================================================
69//function : GetContinuity
70//purpose :
71//=======================================================================
72Standard_Integer IGESToBRep_Actor::GetContinuity () const
73{
74 return thecontinuity;
75}
76
77//=======================================================================
78//function : Recognize
79//purpose :
80//=======================================================================
81Standard_Boolean IGESToBRep_Actor::Recognize
82(const Handle(Standard_Transient)& start)
83{
84 DeclareAndCast(IGESData_IGESModel,mymodel,themodel);
85 DeclareAndCast(IGESData_IGESEntity,ent,start);
86 if (ent.IsNull()) return Standard_False;
87
88// Cas reconnus
89 Standard_Integer typnum = ent->TypeNumber();
90 Standard_Integer fornum = ent->FormNumber();
91 if (IGESToBRep::IsCurveAndSurface(ent) ||
0ebaa4db 92 ((typnum == 402 && (fornum == 1 || fornum == 7 ||
93 fornum == 14 || fornum == 15)) ||
94 (typnum == 408 ) || (typnum == 308)))
7fd59977 95 return Standard_True;
96
97// Cas restants : non reconnus
98 return Standard_False;
99}
100//=======================================================================
101//function : EncodeRegul
102//purpose : INTERNAL to encode regularity on edges
103//=======================================================================
104
105static Standard_Boolean EncodeRegul (const TopoDS_Shape& sh)
106{
107 Standard_Real tolang = Interface_Static::RVal("read.encoderegularity.angle");
108 if (sh.IsNull()) return Standard_True;
109 if (tolang <= 0) return Standard_True;
110 try {
111 OCC_CATCH_SIGNALS
112 BRepLib::EncodeRegularity (sh,tolang);
113 }
a738b534 114 catch(Standard_Failure const&) {
7fd59977 115 return Standard_False;
116 }
117 return Standard_True;
118}
119//=======================================================================
120//function : TrimTolerances
121//purpose : Trims tolerances of the shape according to static parameters
122//
123//=======================================================================
124
125static void TrimTolerances (const TopoDS_Shape& shape,
126 const Standard_Real tol)
127{
128 if( Interface_Static::IVal("read.maxprecision.mode")==1) {
129 ShapeFix_ShapeTolerance SFST;
130 SFST.LimitTolerance (shape, 0, Max(tol,Interface_Static::RVal ("read.maxprecision.val")));
131 }
132}
133
7fd59977 134//=======================================================================
135//function : Transfer
136//purpose :
137//=======================================================================
138Handle(Transfer_Binder) IGESToBRep_Actor::Transfer
7e785937 139(const Handle(Standard_Transient)& start, const Handle(Transfer_TransientProcess)& TP,
140 const Message_ProgressRange& theProgress)
7fd59977 141{
142 DeclareAndCast(IGESData_IGESModel,mymodel,themodel);
143 DeclareAndCast(IGESData_IGESEntity,ent,start);
144 if (mymodel.IsNull() || ent.IsNull()) return NullResult();
145 Standard_Integer anum = mymodel->Number(start);
146
dde68833 147 if (Interface_Static::IVal("read.iges.faulty.entities") == 0 && mymodel->IsErrorEntity(anum))
7fd59977 148 return NullResult();
149 TopoDS_Shape shape;
150
151// appeler le transfert seulement si type OK
152 Standard_Integer typnum = ent->TypeNumber();
153 Standard_Integer fornum = ent->FormNumber();
154 Standard_Real eps;
155 if (IGESToBRep::IsCurveAndSurface(ent) ||
156 (typnum == 402 && (fornum == 1 || fornum == 7||
157 fornum == 14 || fornum == 15)) ||
158 (typnum == 408) || (typnum == 308)) {
b485ee79
KD
159
160 // Start progress scope (no need to check if progress exists -- it is safe)
7e785937 161 Message_ProgressScope aPS(theProgress, "Transfer stage", 2);
b485ee79 162
7fd59977 163 XSAlgo::AlgoContainer()->PrepareForTransfer();
164 IGESToBRep_CurveAndSurface CAS;
165 CAS.SetModel(mymodel);
166 CAS.SetContinuity(thecontinuity);
167 CAS.SetTransferProcess(TP);
168 Standard_Integer Ival = Interface_Static::IVal("read.precision.mode");
169 if ( Ival == 0)
170 eps = mymodel->GlobalSection().Resolution();
171 else
172 eps = Interface_Static::RVal("read.precision.val"); //:10 ABV 11 Nov 97
173//:10 eps = BRepAPI::Precision();
174 Ival = Interface_Static::IVal("read.iges.bspline.approxd1.mode");
175 CAS.SetModeApprox ( (Ival > 0) );
176 Ival = Interface_Static::IVal("read.surfacecurve.mode");
177 CAS.SetSurfaceCurve (Ival);
178
179 if (eps > 1.E-08) {
180 CAS.SetEpsGeom(eps);
181 theeps = eps*CAS.GetUnitFactor();
182// Interface_Static::SetRVal("lastpreci",theeps);
183 }
184 Standard_Integer nbTPitems = TP->NbMapped();
185 {
186 try {
187 OCC_CATCH_SIGNALS
7e785937 188 shape = CAS.TransferGeometry(ent, aPS.Next());
7fd59977 189 }
a738b534 190 catch(Standard_Failure const&) {
7fd59977 191 shape.Nullify();
192 }
193 }
194
195 // fixing shape
7fd59977 196 Handle(Standard_Transient) info;
c479c4f6 197 shape = XSAlgo::AlgoContainer()->ProcessShape(shape, theeps, CAS.GetMaxTol(),
198 "read.iges.resource.name",
199 "read.iges.sequence",
200 info, mymodel->ReShape(),
2a0420be 201 aPS.Next(), false, TopAbs_EDGE);
7fd59977 202 XSAlgo::AlgoContainer()->MergeTransferInfo(TP, info, nbTPitems);
203 }
b485ee79 204
7fd59977 205 ShapeExtend_Explorer SBE;
206 if (SBE.ShapeType(shape,Standard_True) != TopAbs_SHAPE) {
207 if (!shape.IsNull()) {
208 EncodeRegul (shape);
209 //#74 rln 03.03.99 S4135
210 TrimTolerances (shape, UsedTolerance());
211 // Shapes().Append(shape);
212 }
213 }
214 Handle(TransferBRep_ShapeBinder) binder;
215 if (!shape.IsNull()) binder = new TransferBRep_ShapeBinder(shape);
216 return binder;
217}
218
219
220 Standard_Real IGESToBRep_Actor::UsedTolerance () const
221 { return theeps; }