1 // Created on: 1995-09-25
2 // Created by: Stagiaire Flore Lautheanne
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <Draw_Interpretor.hxx>
18 #include <BRepTest.hxx>
21 #include <BRepFilletAPI_MakeChamfer.hxx>
22 #include <TopAbs_ShapeEnum.hxx>
24 #include <TopoDS_Face.hxx>
25 #include <TopoDS_Edge.hxx>
26 #include <TopoDS_Vertex.hxx>
27 #include <TopoDS_Shape.hxx>
29 #include <Precision.hxx>
31 //===============================================================================
32 // function : chamf_throat_with_penetration
33 // purpose : command to construct chamfers with constant throat with penetration
35 // Here the chamfer is propagated on tangential edges to the
37 //===============================================================================
39 static Standard_Integer chamf_throat_with_penetration(Draw_Interpretor& di,
40 Standard_Integer narg,
46 TopoDS_Shape S = DBRep::Get(a[2]);
47 if (S.IsNull()) return 1;
51 Standard_Real offset, throat;
52 Standard_Integer i = 3;
53 Standard_Integer NbArg = 4;
55 BRepFilletAPI_MakeChamfer aMCh(S);
56 aMCh.SetMode(ChFiDS_ConstThroatWithPenetrationChamfer);
58 while (i + NbArg <= narg) {
59 TopoDS_Shape aLocalEdge(DBRep::Get(a[i], TopAbs_EDGE));
60 E = TopoDS::Edge(aLocalEdge);
61 TopoDS_Shape aLocalFace(DBRep::Get(a[i + 1], TopAbs_FACE));
62 F = TopoDS::Face(aLocalFace);
63 // E = TopoDS::Edge(DBRep::Get(a[i], TopAbs_EDGE));
64 // F = TopoDS::Face(DBRep::Get(a[i + 1], TopAbs_FACE));
65 if (!E.IsNull() && !F.IsNull() && (aMCh.Contour(E) == 0) ) {
66 offset = Draw::Atof(a[i + 2]);
67 throat = Draw::Atof(a[i + 3]);
69 if (offset > Precision::Confusion() &&
71 aMCh.Add(offset,throat,E ,F);
76 // compute the chamfer and display the result
77 if (aMCh.NbContours() == 0 )
79 //cout<<"No suitable edges to chamfer"<<endl;
80 di<<"No suitable edges to chamfer\n";
86 DBRep::Set(a[1],aMCh);
90 //cout<<"compute of chamfer failed"<<endl;
91 di<<"compute of chamfer failed\n";
96 //===============================================================================
97 // function : chamf_throat
98 // purpose : command to construct chamfers with constant throat on several edges
99 // Here the chamfer is propagated on tangential edges to the
101 //===============================================================================
103 static Standard_Integer chamf_throat(Draw_Interpretor& di,
104 Standard_Integer narg,
110 TopoDS_Shape S = DBRep::Get(a[2]);
111 if (S.IsNull()) return 1;
114 Standard_Real throat;
115 Standard_Integer i = 3;
117 BRepFilletAPI_MakeChamfer aMCh(S);
118 aMCh.SetMode(ChFiDS_ConstThroatChamfer);
120 while (i + 1 < narg) {
121 TopoDS_Shape aLocalEdge(DBRep::Get(a[i], TopAbs_EDGE));
122 E = TopoDS::Edge(aLocalEdge);
123 if (!E.IsNull() && (aMCh.Contour(E) == 0) ) {
124 throat = Draw::Atof(a[i + 1]);
126 if (throat > Precision::Confusion())
132 // compute the chamfer and display the result
133 if (aMCh.NbContours() == 0 )
135 //cout<<"No suitable edges to chamfer"<<endl;
136 di<<"No suitable edges to chamfer\n";
142 DBRep::Set(a[1],aMCh);
146 //cout<<"compute of chamfer failed"<<endl;
147 di<<"compute of chamfer failed\n";
152 //=========================================================================
153 // function : chamfer
154 // purpose : command to construct chamfers on several edges
155 // Here the chamfer is propagated on tangential edges to the
157 //=========================================================================
159 static Standard_Integer chamfer(Draw_Interpretor& di,
160 Standard_Integer narg,
163 // check the argument number of the command
165 di <<" help for chamf : \n";
166 di <<" Construction by equal distances from edge : chamf newname shape edge dist\n";
167 di <<" Construction by two distances from edge : chamf newname shape edge face dist1 dist2\n";
168 di <<" Construction by distance from edge and given angle : chamf newname shape edge face A dist angle\n";
174 TopoDS_Shape S = DBRep::Get(a[2]);
180 Standard_Real d1,d2, angle;
181 Standard_Integer i = 3;
183 BRepFilletAPI_MakeChamfer aMCh(S);
185 while (i + 1 < narg) {
186 TopoDS_Shape aLocalEdge(DBRep::Get(a[i], TopAbs_EDGE));
187 if (aLocalEdge.IsNull())
189 E = TopoDS::Edge(aLocalEdge);
190 TopoDS_Shape aLocalFace(DBRep::Get(a[i + 1], TopAbs_FACE));
191 if (aLocalFace.IsNull())
193 //symmetric chamfer (one distance)
195 if (aMCh.Contour(E) == 0 &&
196 d1 > Precision::Confusion())
202 F = TopoDS::Face(aLocalFace);
206 if (!strcasecmp(a[i + 2], "A") &&
209 //chamfer with distance and angle
210 d1 = Draw::Atof(a[i + 3]);
211 angle = Draw::Atof(a[i + 4]);
212 angle *= M_PI / 180.;
213 if (aMCh.Contour(E) == 0 &&
214 d1 > Precision::Confusion() &&
215 angle > Precision::Confusion() &&
216 M_PI/2 - angle > Precision::Confusion())
217 aMCh.AddDA(d1, angle, E, F);
222 //chamfer with two distances
223 d1 = Draw::Atof(a[i + 2]);
224 d2 = Draw::Atof(a[i + 3]);
225 if (aMCh.Contour(E) == 0 &&
226 d1 > Precision::Confusion() &&
227 d2 > Precision::Confusion())
228 aMCh.Add(d1, d2, E, F);
235 // compute the chamfer and display the result
236 if (aMCh.NbContours() == 0 )
238 //cout<<"No suitable edges to chamfer"<<endl;
239 di<<"No suitable edges to chamfer\n";
245 DBRep::Set(a[1],aMCh);
249 //cout<<"compute of chamfer failed"<<endl;
250 di<<"compute of chamfer failed\n";
260 //=======================================================================
261 //function : ChamferCommands
263 //=======================================================================
265 void BRepTest::ChamferCommands(Draw_Interpretor& theCommands)
267 static Standard_Boolean done = Standard_False;
269 done = Standard_True;
271 DBRep::BasicCommands(theCommands);
273 const char* g = "TOPOLOGY Fillet construction commands";
275 // theCommands.Add("chamf",
276 // "chamf newname shape edge1 face1 dist1_1 dist1_2 edge2 face2 dist2_1 dist2_2 ... ",__FILE__,chamfer,g);
278 theCommands.Add("chamf",
279 "for help call chamf without arguments",__FILE__,chamfer,g);
281 theCommands.Add("chamf_throat",
282 "chamf_throat result shape edge throat"
283 ,__FILE__,chamf_throat,g);
285 theCommands.Add("chamf_throat_with_penetration",
286 "chamf_throat_with_penetration result shape edge face offset throat",
287 __FILE__,chamf_throat_with_penetration,g);