1 // Created on: 1997-04-01
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 #include <TopOpeBRepTool_tol.hxx>
25 #include <TopExp_Explorer.hxx>
26 #include <Precision.hxx>
27 #include <BRep_Tool.hxx>
28 #include <TopOpeBRepTool_HBoxTool.hxx>
29 #include <Bnd_Box.hxx>
30 #include <TopOpeBRepTool_box.hxx>
31 #include <TopOpeBRepTool_define.hxx>
33 Standard_EXPORT void FTOL_FaceTolerances
34 (const Bnd_Box& B1, const Bnd_Box& B2,
35 const TopoDS_Face& myFace1, const TopoDS_Face& myFace2,
36 const BRepAdaptor_Surface& mySurface1, const BRepAdaptor_Surface& mySurface2,
37 Standard_Real& myTol1, Standard_Real& myTol2,
38 Standard_Real& Deflection, Standard_Real& MaxUV)
40 Standard_Real aTolF1 = BRep_Tool::Tolerance(myFace1);
41 Standard_Real aTolF2 = BRep_Tool::Tolerance(myFace2);
43 myTol1 = aTolF1 + aTolF2;
46 Standard_Real x0,y0,z0,x1,y1,z1,dx,dy,dz;
47 Standard_Boolean Box1OK,Box2OK;
49 if( !B1.IsOpenXmin() && !B1.IsOpenXmax()
50 && !B1.IsOpenYmin() && !B1.IsOpenYmax()
51 && !B1.IsOpenZmin() && !B1.IsOpenZmax()
56 Box1OK=Standard_False;
59 if( !B2.IsOpenXmin() && !B2.IsOpenXmax()
60 && !B2.IsOpenYmin() && !B2.IsOpenYmax()
61 && !B2.IsOpenZmin() && !B2.IsOpenZmax()
66 Box2OK=Standard_False;
70 B1.Get(x0,y0,z0,x1,y1,z1);
76 B2.Get(x0,y0,z0,x1,y1,z1);
77 Standard_Real _dx=x1-x0;
78 Standard_Real _dy=y1-y0;
79 Standard_Real _dz=z1-z0;
87 B2.Get(x0,y0,z0,x1,y1,z1);
98 if(dx>1000000.0) dx=1000000.0; //-- if(dx>10000.0) dx=10000.0;
101 Standard_Real tolef1 = Precision::Confusion();
102 for (ex.Init(myFace1,TopAbs_EDGE);ex.More();ex.Next()) {
103 Standard_Real tole=BRep_Tool::Tolerance(TopoDS::Edge(ex.Current()));
104 if (tole>tolef1) tolef1=tole;
106 Standard_Real tolef2 = Precision::Confusion();
107 for (ex.Init(myFace2,TopAbs_EDGE);ex.More();ex.Next()) {
108 Standard_Real tole=BRep_Tool::Tolerance(TopoDS::Edge(ex.Current()));
109 if (tole>tolef2) tolef2=tole;
111 Standard_Real tolef= tolef1;
112 if (tolef2>tolef) tolef=tolef2;
113 //jmb le 30 juillet 99. on ne multiplie pas la tolerance par la dimension de la piece
114 // Standard_Real tolbox = tolef*dx;
115 Standard_Real tolbox = tolef;
117 Standard_Real tolmin = Precision::Confusion();
123 Standard_Real MDEFLECTION = Deflection;
124 Standard_Real MMAXUV=0.01;
126 Standard_Real MU0,MU1,MV0,MV1,DP1,DP2,DP;
127 MU0=mySurface1.FirstUParameter();
128 MU1=mySurface1.LastUParameter();
129 MV0=mySurface1.FirstVParameter();
130 MV1=mySurface1.LastVParameter();
133 if(DP2<DP1) DP=DP2; else DP=DP1; //-- DP + petit
135 MU0=mySurface2.FirstUParameter();
136 MU1=mySurface2.LastUParameter();
137 MV0=mySurface2.FirstVParameter();
138 MV1=mySurface2.LastVParameter();
141 if(DP2>DP1) DP1=DP2; //-- DP1 + petit
142 if(DP1<DP) DP=DP1; //-- DP + petit
145 //jmb le 30 juillet 99
146 // non ! laisser MMAXUV a 0.01
150 // printf("\n FaceTolerances3d : TOL1 = %5.5eg TOL2=%5.5eg DEFL=%5.5eg MAXUV=%5.5eg\n",MTOL1,MTOL2,MDEFLECTION,0.01);
153 if(MMAXUV<1e-3) MMAXUV=1e-3;
154 if(MDEFLECTION<1e-3) MDEFLECTION = 1e-3;
156 if(MMAXUV>0.01) MMAXUV=0.01;
157 if(MDEFLECTION>0.1) MDEFLECTION = 0.1;
160 // printf("TOL1 = %5.5eg TOL2=%5.5eg DEFL=%5.5eg MAXUV=%5.5eg\n",MTOL1,MTOL2,MDEFLECTION,MMAXUV);
163 Deflection = MDEFLECTION;
165 } // FTOL_FaceTolerances
167 Standard_EXPORT void FTOL_FaceTolerances3d
168 (const TopoDS_Face& myFace1,
169 const TopoDS_Face& myFace2,
172 const Handle(TopOpeBRepTool_HBoxTool)& hbt = FBOX_GetHBoxTool();
174 if(hbt->HasBox(myFace1)) {
175 B1 = hbt->Box(myFace1);
178 B1.Update(0., 0., 0., 1., 1., 1.);
180 if(hbt->HasBox(myFace2)) {
181 B2 = hbt->Box(myFace2);
184 B2.Update(0., 0., 0., 1., 1., 1.);
186 BRepAdaptor_Surface mySurface1;
187 BRepAdaptor_Surface mySurface2;
188 mySurface1.Initialize(myFace1);
189 mySurface2.Initialize(myFace2);
190 Standard_Real Deflection=0.01,MaxUV=0.01;
191 Standard_Real myTol1,myTol2;
192 FTOL_FaceTolerances(B1,B2,
194 mySurface1,mySurface2,
195 myTol1,myTol2,Deflection,MaxUV);
196 myTol1 = (myTol1 > 1.e-4)? 1.e-4: myTol1;
197 myTol2 = (myTol2 > 1.e-4)? 1.e-4: myTol2;
198 Tol = Max(myTol1,myTol2);
201 Standard_EXPORT void FTOL_FaceTolerances3d
202 (const Bnd_Box& B1, const Bnd_Box& B2,
203 const TopoDS_Face& myFace1, const TopoDS_Face& myFace2,
204 const BRepAdaptor_Surface& mySurface1, const BRepAdaptor_Surface& mySurface2,
205 Standard_Real& myTol1, Standard_Real& myTol2,
206 Standard_Real& Deflection, Standard_Real& MaxUV)
208 FTOL_FaceTolerances(B1,B2,
210 mySurface1,mySurface2,
215 Standard_EXPORT void FTOL_FaceTolerances2d
218 const TopoDS_Face& myFace1,
219 const TopoDS_Face& myFace2,
220 const BRepAdaptor_Surface& mySurface1,
221 const BRepAdaptor_Surface& mySurface2,
222 Standard_Real& myTol1, Standard_Real& myTol2)
224 Standard_Real BIDDeflection,BIDMaxUV;
225 FTOL_FaceTolerances(B1,B2,
227 mySurface1,mySurface2,
229 BIDDeflection,BIDMaxUV);