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_Shape.hxx>
28 #include <Precision.hxx>
30 //===============================================================================
31 // function : chamf_throat_with_penetration
32 // purpose : command to construct chamfers with constant throat with penetration
34 // Here the chamfer is propagated on tangential edges to the
36 //===============================================================================
38 static Standard_Integer chamf_throat_with_penetration(Draw_Interpretor& di,
39 Standard_Integer narg,
45 TopoDS_Shape S = DBRep::Get(a[2]);
46 if (S.IsNull()) return 1;
50 Standard_Real offset, throat;
51 Standard_Integer i = 3;
52 Standard_Integer NbArg = 4;
54 BRepFilletAPI_MakeChamfer aMCh(S);
55 aMCh.SetMode(ChFiDS_ConstThroatWithPenetrationChamfer);
57 while (i + NbArg <= narg) {
58 TopoDS_Shape aLocalEdge(DBRep::Get(a[i], TopAbs_EDGE));
59 E = TopoDS::Edge(aLocalEdge);
60 TopoDS_Shape aLocalFace(DBRep::Get(a[i + 1], TopAbs_FACE));
61 F = TopoDS::Face(aLocalFace);
62 // E = TopoDS::Edge(DBRep::Get(a[i], TopAbs_EDGE));
63 // F = TopoDS::Face(DBRep::Get(a[i + 1], TopAbs_FACE));
64 if (!E.IsNull() && !F.IsNull() && (aMCh.Contour(E) == 0) ) {
65 offset = Draw::Atof(a[i + 2]);
66 throat = Draw::Atof(a[i + 3]);
68 if (offset > Precision::Confusion() &&
70 aMCh.Add(offset,throat,E ,F);
75 // compute the chamfer and display the result
76 if (aMCh.NbContours() == 0 )
78 //std::cout<<"No suitable edges to chamfer"<<std::endl;
79 di<<"No suitable edges to chamfer\n";
85 DBRep::Set(a[1],aMCh);
89 //std::cout<<"compute of chamfer failed"<<std::endl;
90 di<<"compute of chamfer failed\n";
95 //===============================================================================
96 // function : chamf_throat
97 // purpose : command to construct chamfers with constant throat on several edges
98 // Here the chamfer is propagated on tangential edges to the
100 //===============================================================================
102 static Standard_Integer chamf_throat(Draw_Interpretor& di,
103 Standard_Integer narg,
109 TopoDS_Shape S = DBRep::Get(a[2]);
110 if (S.IsNull()) return 1;
113 Standard_Real throat;
114 Standard_Integer i = 3;
116 BRepFilletAPI_MakeChamfer aMCh(S);
117 aMCh.SetMode(ChFiDS_ConstThroatChamfer);
119 while (i + 1 < narg) {
120 TopoDS_Shape aLocalEdge(DBRep::Get(a[i], TopAbs_EDGE));
121 E = TopoDS::Edge(aLocalEdge);
122 if (!E.IsNull() && (aMCh.Contour(E) == 0) ) {
123 throat = Draw::Atof(a[i + 1]);
125 if (throat > Precision::Confusion())
131 // compute the chamfer and display the result
132 if (aMCh.NbContours() == 0 )
134 //std::cout<<"No suitable edges to chamfer"<<std::endl;
135 di<<"No suitable edges to chamfer\n";
141 DBRep::Set(a[1],aMCh);
145 //std::cout<<"compute of chamfer failed"<<std::endl;
146 di<<"compute of chamfer failed\n";
151 //=========================================================================
152 // function : chamfer
153 // purpose : command to construct chamfers on several edges
154 // Here the chamfer is propagated on tangential edges to the
156 //=========================================================================
158 static Standard_Integer chamfer(Draw_Interpretor& di,
159 Standard_Integer narg,
162 // check the argument number of the command
164 di <<" help for chamf : \n";
165 di <<" Construction by equal distances from edge : chamf newname shape edge dist\n";
166 di <<" Construction by two distances from edge : chamf newname shape edge face dist1 dist2\n";
167 di <<" Construction by distance from edge and given angle : chamf newname shape edge face A dist angle\n";
173 TopoDS_Shape S = DBRep::Get(a[2]);
179 Standard_Real d1,d2, angle;
180 Standard_Integer i = 3;
182 BRepFilletAPI_MakeChamfer aMCh(S);
184 while (i + 1 < narg) {
185 TopoDS_Shape aLocalEdge(DBRep::Get(a[i], TopAbs_EDGE));
186 if (aLocalEdge.IsNull())
188 E = TopoDS::Edge(aLocalEdge);
189 TopoDS_Shape aLocalFace(DBRep::Get(a[i + 1], TopAbs_FACE));
190 if (aLocalFace.IsNull())
192 //symmetric chamfer (one distance)
194 if (aMCh.Contour(E) == 0 &&
195 d1 > Precision::Confusion())
201 F = TopoDS::Face(aLocalFace);
205 if (!strcasecmp(a[i + 2], "A") &&
208 //chamfer with distance and angle
209 d1 = Draw::Atof(a[i + 3]);
210 angle = Draw::Atof(a[i + 4]);
211 angle *= M_PI / 180.;
212 if (aMCh.Contour(E) == 0 &&
213 d1 > Precision::Confusion() &&
214 angle > Precision::Confusion() &&
215 M_PI/2 - angle > Precision::Confusion())
216 aMCh.AddDA(d1, angle, E, F);
221 //chamfer with two distances
222 d1 = Draw::Atof(a[i + 2]);
223 d2 = Draw::Atof(a[i + 3]);
224 if (aMCh.Contour(E) == 0 &&
225 d1 > Precision::Confusion() &&
226 d2 > Precision::Confusion())
227 aMCh.Add(d1, d2, E, F);
234 // compute the chamfer and display the result
235 if (aMCh.NbContours() == 0 )
237 //std::cout<<"No suitable edges to chamfer"<<std::endl;
238 di<<"No suitable edges to chamfer\n";
244 DBRep::Set(a[1],aMCh);
248 //std::cout<<"compute of chamfer failed"<<std::endl;
249 di<<"compute of chamfer failed\n";
259 //=======================================================================
260 //function : ChamferCommands
262 //=======================================================================
264 void BRepTest::ChamferCommands(Draw_Interpretor& theCommands)
266 static Standard_Boolean done = Standard_False;
268 done = Standard_True;
270 DBRep::BasicCommands(theCommands);
272 const char* g = "TOPOLOGY Fillet construction commands";
274 // theCommands.Add("chamf",
275 // "chamf newname shape edge1 face1 dist1_1 dist1_2 edge2 face2 dist2_1 dist2_2 ... ",__FILE__,chamfer,g);
277 theCommands.Add("chamf",
278 "for help call chamf without arguments",__FILE__,chamfer,g);
280 theCommands.Add("chamf_throat",
281 "chamf_throat result shape edge throat"
282 ,__FILE__,chamf_throat,g);
284 theCommands.Add("chamf_throat_with_penetration",
285 "chamf_throat_with_penetration result shape edge face offset throat",
286 __FILE__,chamf_throat_with_penetration,g);