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 <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_ProgressScope.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>
37 #include <XSAlgo.hxx>
38 #include <XSAlgo_AlgoContainer.hxx>
39
IMPLEMENT_STANDARD_RTTIEXT(IGESToBRep_Actor,Transfer_ActorOfTransientProcess)40 IMPLEMENT_STANDARD_RTTIEXT(IGESToBRep_Actor,Transfer_ActorOfTransientProcess)
41
42 //=======================================================================
43 //function : IGESToBRep_Actor
44 //purpose :
45 //=======================================================================
46 IGESToBRep_Actor::IGESToBRep_Actor ()
47 { thecontinuity = 0; theeps = 0.0001; }
48
49
50 //=======================================================================
51 //function : SetModel
52 //purpose :
53 //=======================================================================
SetModel(const Handle (Interface_InterfaceModel)& model)54 void IGESToBRep_Actor::SetModel (const Handle(Interface_InterfaceModel)& model)
55 {
56 themodel = model;
57 theeps = Handle(IGESData_IGESModel)::DownCast(themodel)->GlobalSection().Resolution();
58 }
59
60
61 //=======================================================================
62 //function : SetContinuity
63 //purpose :
64 //=======================================================================
SetContinuity(const Standard_Integer continuity)65 void IGESToBRep_Actor::SetContinuity (const Standard_Integer continuity)
66 {
67 thecontinuity = continuity;
68 }
69
70
71 //=======================================================================
72 //function : GetContinuity
73 //purpose :
74 //=======================================================================
GetContinuity() const75 Standard_Integer IGESToBRep_Actor::GetContinuity () const
76 {
77 return thecontinuity;
78 }
79
80 //=======================================================================
81 //function : Recognize
82 //purpose :
83 //=======================================================================
Recognize(const Handle (Standard_Transient)& start)84 Standard_Boolean IGESToBRep_Actor::Recognize
85 (const Handle(Standard_Transient)& start)
86 {
87 DeclareAndCast(IGESData_IGESModel,mymodel,themodel);
88 DeclareAndCast(IGESData_IGESEntity,ent,start);
89 if (ent.IsNull()) return Standard_False;
90
91 // Cas reconnus
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)))
98 return Standard_True;
99
100 // Cas restants : non reconnus
101 return Standard_False;
102 }
103 //=======================================================================
104 //function : EncodeRegul
105 //purpose : INTERNAL to encode regularity on edges
106 //=======================================================================
107
EncodeRegul(const TopoDS_Shape & sh)108 static Standard_Boolean EncodeRegul (const TopoDS_Shape& sh)
109 {
110 Standard_Real tolang = Interface_Static::RVal("read.encoderegularity.angle");
111 if (sh.IsNull()) return Standard_True;
112 if (tolang <= 0) return Standard_True;
113 try {
114 OCC_CATCH_SIGNALS
115 BRepLib::EncodeRegularity (sh,tolang);
116 }
117 catch(Standard_Failure const&) {
118 return Standard_False;
119 }
120 return Standard_True;
121 }
122 //=======================================================================
123 //function : TrimTolerances
124 //purpose : Trims tolerances of the shape according to static parameters
125 //
126 //=======================================================================
127
TrimTolerances(const TopoDS_Shape & shape,const Standard_Real tol)128 static void TrimTolerances (const TopoDS_Shape& shape,
129 const Standard_Real tol)
130 {
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")));
134 }
135 }
136
137
138
139 //=======================================================================
140 //function : Transfer
141 //purpose :
142 //=======================================================================
Handle(Transfer_Binder)143 Handle(Transfer_Binder) IGESToBRep_Actor::Transfer
144 (const Handle(Standard_Transient)& start, const Handle(Transfer_TransientProcess)& TP,
145 const Message_ProgressRange& theProgress)
146 {
147 DeclareAndCast(IGESData_IGESModel,mymodel,themodel);
148 DeclareAndCast(IGESData_IGESEntity,ent,start);
149 if (mymodel.IsNull() || ent.IsNull()) return NullResult();
150 Standard_Integer anum = mymodel->Number(start);
151
152 if (Interface_Static::IVal("read.iges.faulty.entities") == 0 && mymodel->IsErrorEntity(anum))
153 return NullResult();
154 TopoDS_Shape shape;
155
156 // appeler le transfert seulement si type OK
157 Standard_Integer typnum = ent->TypeNumber();
158 Standard_Integer fornum = ent->FormNumber();
159 Standard_Real eps;
160 if (IGESToBRep::IsCurveAndSurface(ent) ||
161 (typnum == 402 && (fornum == 1 || fornum == 7||
162 fornum == 14 || fornum == 15)) ||
163 (typnum == 408) || (typnum == 308)) {
164
165 // Start progress scope (no need to check if progress exists -- it is safe)
166 Message_ProgressScope aPS(theProgress, "Transfer stage", 2);
167
168 XSAlgo::AlgoContainer()->PrepareForTransfer();
169 IGESToBRep_CurveAndSurface CAS;
170 CAS.SetModel(mymodel);
171 CAS.SetContinuity(thecontinuity);
172 CAS.SetTransferProcess(TP);
173 Standard_Integer Ival = Interface_Static::IVal("read.precision.mode");
174 if ( Ival == 0)
175 eps = mymodel->GlobalSection().Resolution();
176 else
177 eps = Interface_Static::RVal("read.precision.val"); //:10 ABV 11 Nov 97
178 //:10 eps = BRepAPI::Precision();
179 Ival = Interface_Static::IVal("read.iges.bspline.approxd1.mode");
180 CAS.SetModeApprox ( (Ival > 0) );
181 Ival = Interface_Static::IVal("read.surfacecurve.mode");
182 CAS.SetSurfaceCurve (Ival);
183
184 if (eps > 1.E-08) {
185 CAS.SetEpsGeom(eps);
186 theeps = eps*CAS.GetUnitFactor();
187 // Interface_Static::SetRVal("lastpreci",theeps);
188 }
189 Standard_Integer nbTPitems = TP->NbMapped();
190 {
191 try {
192 OCC_CATCH_SIGNALS
193 shape = CAS.TransferGeometry(ent, aPS.Next());
194 }
195 catch(Standard_Failure const&) {
196 shape.Nullify();
197 }
198 }
199
200 // fixing shape
201 Handle(Standard_Transient) info;
202 shape = XSAlgo::AlgoContainer()->ProcessShape( shape, theeps, CAS.GetMaxTol(),
203 "read.iges.resource.name",
204 "read.iges.sequence", info,
205 aPS.Next());
206 XSAlgo::AlgoContainer()->MergeTransferInfo(TP, info, nbTPitems);
207 }
208
209 ShapeExtend_Explorer SBE;
210 if (SBE.ShapeType(shape,Standard_True) != TopAbs_SHAPE) {
211 if (!shape.IsNull()) {
212 EncodeRegul (shape);
213 //#74 rln 03.03.99 S4135
214 TrimTolerances (shape, UsedTolerance());
215 // Shapes().Append(shape);
216 }
217 }
218 Handle(TransferBRep_ShapeBinder) binder;
219 if (!shape.IsNull()) binder = new TransferBRep_ShapeBinder(shape);
220 return binder;
221 }
222
223
UsedTolerance() const224 Standard_Real IGESToBRep_Actor::UsedTolerance () const
225 { return theeps; }
226