0022792: Globally defined symbol PI conflicts with VTK definition (Intel compiler)
[occt.git] / src / BRepTest / BRepTest_Fillet2DCommands.cxx
CommitLineData
7fd59977 1// Modified: Tue Oct 15 10:12:02 1996
2// Author: Joelle CHAUVET
3// <jct@sgi38>
4// Add ChFi2d_TangencyError (PRO3529)
5// Modified: Fri Sep 25 09:38:04 1998
6// Author: Joelle CHAUVET
7// <jct@sgi64>
8// status = ChFi2d_NotAuthorized if edges are not
9// lines or circles (BUC60288) + partial_result
10
11
12#include <TColgp_Array1OfPnt2d.hxx>
13#include <BRepTest.hxx>
14#include <DBRep.hxx>
15#include <Draw_Interpretor.hxx>
16#include <Draw_Appli.hxx>
17#include <BRepFilletAPI_MakeFillet2d.hxx>
18#include <TopAbs_ShapeEnum.hxx>
19#include <TopoDS_Shape.hxx>
20#include <TopoDS_Edge.hxx>
21#include <TopoDS_Vertex.hxx>
22#include <TopoDS.hxx>
23#include <TopExp.hxx>
24
25//=======================================================================
26//function : chfi2d
27//purpose : 2d fillets and chamfers
28//=======================================================================
29
30static Standard_Integer chfi2d(Draw_Interpretor& di, Standard_Integer n, const char** a)
31{
32 if (n < 3) {
33 di << "chfi2d : not enough args";
34 return 1;
35 }
36
37 // set up the algorithm
38 TopoDS_Shape F = DBRep::Get(a[2],TopAbs_FACE);
39 if (F.IsNull()) {
40 di << "chfi2d : "<< a[2] << " not a face";
41 return 1;
42 }
43
44 BRepFilletAPI_MakeFillet2d MF(TopoDS::Face(F));
45 if (MF.Status() == ChFi2d_NotPlanar) {
46 di << "chfi2d : not a planar face";
47 return 1;
48 }
49
50 TopoDS_Shape res;
51 Standard_Boolean partial_result = Standard_False;
52 Standard_Integer i = 3;
53 while (i+1 < n) {
54
55 TopoDS_Shape aLocalEdge(DBRep::Get(a[i],TopAbs_EDGE));
56 TopoDS_Edge E1 = TopoDS::Edge(aLocalEdge);
57 aLocalEdge = DBRep::Get(a[i+1],TopAbs_EDGE);
58 TopoDS_Edge E2 = TopoDS::Edge(aLocalEdge);
59// TopoDS_Edge E1 = TopoDS::Edge(DBRep::Get(a[i],TopAbs_EDGE));
60// TopoDS_Edge E2 = TopoDS::Edge(DBRep::Get(a[i+1],TopAbs_EDGE));
61
62 if (E1.IsNull() || E2.IsNull()) {
63 di << "chfi2d : " << a[i] << " or " << a[i+1] << " not an edge";
64 if (partial_result) {
65 di <<" WARNING : this is a partial result ";
66 DBRep::Set(a[1],res);
67 }
68 return 1;
69 }
70
71 TopoDS_Vertex V;
72 if (!TopExp::CommonVertex(E1,E2,V)) {
73 di << "chfi2d " << a[i] << " and " << a[i+1] << " does not share a vertex";
74 if (partial_result) {
75 di <<" WARNING : this is a partial result ";
76 DBRep::Set(a[1],res);
77 }
78 return 1;
79 }
80
81 i += 2;
82 if (i+1 >= n) {
83 di << "chfi2d : not enough args";
84 if (partial_result) {
85 di <<" WARNING : this is a partial result ";
86 DBRep::Set(a[1],res);
87 }
88 return 1;
89 }
90
91 Standard_Real p1 = atof(a[i+1]);
92 if (*a[i] == 'F') {
93 MF.AddFillet(V,p1);
94 }
95 else {
96 if (i+2 >= n) {
97 di << "chfi2d : not enough args";
98 if (partial_result) {
99 di <<" WARNING : this is a partial result ";
100 DBRep::Set(a[1],res);
101 }
102 return 1;
103 }
104 Standard_Real p2 = atof(a[i+2]);
105 if (a[i][2] == 'D') {
106 MF.AddChamfer(E1,E2,p1,p2);
107 }
108 else {
c6541a0c 109 MF.AddChamfer(E1,V,p1,p2 * (M_PI / 180.0));
7fd59977 110 }
111 }
112
113 if (MF.Status() == ChFi2d_TangencyError) {
114 di << "chfi2d : " << a[i-2] << " and " << a[i-1] << " are tangent ";
115 if (partial_result) {
116 di <<" WARNING : this is a partial result ";
117 DBRep::Set(a[1],res);
118 }
119 return 1;
120 }
121
122 if (MF.Status() == ChFi2d_NotAuthorized) {
123 di << "chfi2d : " << a[i-2] << " or " << a[i-1] << " is not a line or a circle ";
124 if (partial_result) {
125 di <<" WARNING : this is a partial result ";
126 DBRep::Set(a[1],res);
127 }
128 return 1;
129 }
130
131 if (MF.Status() != ChFi2d_IsDone) {
132 di << "chfi2d : operation failed on " << a[i-2];
133 if (partial_result) {
134 di <<" WARNING : this is a partial result ";
135 DBRep::Set(a[1],res);
136 }
137 return 1;
138 }
139 else {
140 partial_result = Standard_True;
141 MF.Build();
142 res = MF.Shape();
143 }
144
145 if (*a[i] == 'F') {
146 i +=2;
147 }
148 else {
149 i +=3;
150 }
151 }
152
153 MF.Build();
154 DBRep::Set(a[1],MF);
155
156 return 0;
157}
158
159//=======================================================================
160//function : Fillet2DCommands
161//purpose :
162//=======================================================================
163
164void BRepTest::Fillet2DCommands(Draw_Interpretor& theCommands)
165{
166 static Standard_Boolean done = Standard_False;
167 if (done) return;
168 done = Standard_True;
169
170 DBRep::BasicCommands(theCommands);
171
172 const char* g = "TOPOLOGY Fillet2D construction commands";
173
174 theCommands.Add("chfi2d","chfi2d result face [edge1 edge2 (F radius/CDD d1 d2/CDA d ang) ....]",__FILE__,chfi2d,g);
175}