1 // Created by: Joelle CHAUVET
2 // Copyright (c) 1996-1999 Matra Datavision
3 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
20 // Modified: Tue Oct 15 10:12:02 1996
21 // Add ChFi2d_TangencyError (PRO3529)
22 // Modified: Fri Sep 25 09:38:04 1998
23 // status = ChFi2d_NotAuthorized if edges are not
24 // lines or circles (BUC60288) + partial_result
27 #include <TColgp_Array1OfPnt2d.hxx>
28 #include <BRepTest.hxx>
30 #include <Draw_Interpretor.hxx>
31 #include <Draw_Appli.hxx>
32 #include <BRepFilletAPI_MakeFillet2d.hxx>
33 #include <TopAbs_ShapeEnum.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS_Edge.hxx>
36 #include <TopoDS_Vertex.hxx>
40 //=======================================================================
42 //purpose : 2d fillets and chamfers
43 //=======================================================================
45 static Standard_Integer chfi2d(Draw_Interpretor& di, Standard_Integer n, const char** a)
48 di << "chfi2d : not enough args";
52 // set up the algorithm
53 TopoDS_Shape F = DBRep::Get(a[2],TopAbs_FACE);
55 di << "chfi2d : "<< a[2] << " not a face";
59 BRepFilletAPI_MakeFillet2d MF(TopoDS::Face(F));
60 if (MF.Status() == ChFi2d_NotPlanar) {
61 di << "chfi2d : not a planar face";
66 Standard_Boolean partial_result = Standard_False;
67 Standard_Integer i = 3;
70 TopoDS_Shape aLocalEdge(DBRep::Get(a[i],TopAbs_EDGE));
71 TopoDS_Edge E1 = TopoDS::Edge(aLocalEdge);
72 aLocalEdge = DBRep::Get(a[i+1],TopAbs_EDGE);
73 TopoDS_Edge E2 = TopoDS::Edge(aLocalEdge);
74 // TopoDS_Edge E1 = TopoDS::Edge(DBRep::Get(a[i],TopAbs_EDGE));
75 // TopoDS_Edge E2 = TopoDS::Edge(DBRep::Get(a[i+1],TopAbs_EDGE));
77 if (E1.IsNull() || E2.IsNull()) {
78 di << "chfi2d : " << a[i] << " or " << a[i+1] << " not an edge";
80 di <<" WARNING : this is a partial result ";
87 if (!TopExp::CommonVertex(E1,E2,V)) {
88 di << "chfi2d " << a[i] << " and " << a[i+1] << " does not share a vertex";
90 di <<" WARNING : this is a partial result ";
98 di << "chfi2d : not enough args";
100 di <<" WARNING : this is a partial result ";
101 DBRep::Set(a[1],res);
106 Standard_Real p1 = Draw::Atof(a[i+1]);
112 di << "chfi2d : not enough args";
113 if (partial_result) {
114 di <<" WARNING : this is a partial result ";
115 DBRep::Set(a[1],res);
119 Standard_Real p2 = Draw::Atof(a[i+2]);
120 if (a[i][2] == 'D') {
121 MF.AddChamfer(E1,E2,p1,p2);
124 MF.AddChamfer(E1,V,p1,p2 * (M_PI / 180.0));
128 if (MF.Status() == ChFi2d_TangencyError) {
129 di << "chfi2d : " << a[i-2] << " and " << a[i-1] << " are tangent ";
130 if (partial_result) {
131 di <<" WARNING : this is a partial result ";
132 DBRep::Set(a[1],res);
137 if (MF.Status() == ChFi2d_NotAuthorized) {
138 di << "chfi2d : " << a[i-2] << " or " << a[i-1] << " is not a line or a circle ";
139 if (partial_result) {
140 di <<" WARNING : this is a partial result ";
141 DBRep::Set(a[1],res);
146 if (MF.Status() != ChFi2d_IsDone) {
147 di << "chfi2d : operation failed on " << a[i-2];
148 if (partial_result) {
149 di <<" WARNING : this is a partial result ";
150 DBRep::Set(a[1],res);
155 partial_result = Standard_True;
174 //=======================================================================
175 //function : Fillet2DCommands
177 //=======================================================================
179 void BRepTest::Fillet2DCommands(Draw_Interpretor& theCommands)
181 static Standard_Boolean done = Standard_False;
183 done = Standard_True;
185 DBRep::BasicCommands(theCommands);
187 const char* g = "TOPOLOGY Fillet2D construction commands";
189 theCommands.Add("chfi2d","chfi2d result face [edge1 edge2 (F radius/CDD d1 d2/CDA d ang) ....]",__FILE__,chfi2d,g);