0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / BRepTest / BRepTest_ChamferCommands.cxx
CommitLineData
b311480e 1// Created on: 1995-09-25
2// Created by: Stagiaire Flore Lautheanne
3// Copyright (c) 1995-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
7fd59977 17#include <Draw_Interpretor.hxx>
18#include <BRepTest.hxx>
91322f44 19#include <Draw.hxx>
7fd59977 20#include <DBRep.hxx>
21#include <BRepFilletAPI_MakeChamfer.hxx>
22#include <TopAbs_ShapeEnum.hxx>
23#include <TopoDS.hxx>
24#include <TopoDS_Face.hxx>
25#include <TopoDS_Edge.hxx>
7fd59977 26#include <TopoDS_Shape.hxx>
27
28#include <Precision.hxx>
7fd59977 29
1d54b807 30//===============================================================================
31// function : chamf_throat_with_penetration
32// purpose : command to construct chamfers with constant throat with penetration
33// on several edges
34// Here the chamfer is propagated on tangential edges to the
35// required edge
36//===============================================================================
37
38static Standard_Integer chamf_throat_with_penetration(Draw_Interpretor& di,
39 Standard_Integer narg,
40 const char** a)
41{
42 if (narg < 7)
43 return 1;
44
45 TopoDS_Shape S = DBRep::Get(a[2]);
46 if (S.IsNull()) return 1;
47
48 TopoDS_Edge E;
49 TopoDS_Face F;
50 Standard_Real offset, throat;
51 Standard_Integer i = 3;
52 Standard_Integer NbArg = 4;
53
54 BRepFilletAPI_MakeChamfer aMCh(S);
55 aMCh.SetMode(ChFiDS_ConstThroatWithPenetrationChamfer);
56
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]);
67
68 if (offset > Precision::Confusion() &&
69 throat > offset)
70 aMCh.Add(offset,throat,E ,F);
71 }
72 i += NbArg;
73 }
74
75 // compute the chamfer and display the result
76 if (aMCh.NbContours() == 0 )
77 {
04232180 78 //std::cout<<"No suitable edges to chamfer"<<std::endl;
1d54b807 79 di<<"No suitable edges to chamfer\n";
80 return 1;
81 }
82 else aMCh.Build();
83
84 if (aMCh.IsDone()){
85 DBRep::Set(a[1],aMCh);
86 return 0;
87 }
88 else {
04232180 89 //std::cout<<"compute of chamfer failed"<<std::endl;
1d54b807 90 di<<"compute of chamfer failed\n";
91 return 1;
92 }
93}
94
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
99// required edge
100//===============================================================================
101
102static Standard_Integer chamf_throat(Draw_Interpretor& di,
103 Standard_Integer narg,
104 const char** a)
105{
106 if (narg < 5)
107 return 1;
108
109 TopoDS_Shape S = DBRep::Get(a[2]);
110 if (S.IsNull()) return 1;
111
112 TopoDS_Edge E;
113 Standard_Real throat;
114 Standard_Integer i = 3;
115
116 BRepFilletAPI_MakeChamfer aMCh(S);
117 aMCh.SetMode(ChFiDS_ConstThroatChamfer);
118
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]);
124
125 if (throat > Precision::Confusion())
126 aMCh.Add(throat, E);
127 }
128 i += 2;
129 }
130
131 // compute the chamfer and display the result
132 if (aMCh.NbContours() == 0 )
133 {
04232180 134 //std::cout<<"No suitable edges to chamfer"<<std::endl;
1d54b807 135 di<<"No suitable edges to chamfer\n";
136 return 1;
137 }
138 else aMCh.Build();
139
140 if (aMCh.IsDone()){
141 DBRep::Set(a[1],aMCh);
142 return 0;
143 }
144 else {
04232180 145 //std::cout<<"compute of chamfer failed"<<std::endl;
1d54b807 146 di<<"compute of chamfer failed\n";
147 return 1;
148 }
149}
150
7fd59977 151//=========================================================================
152// function : chamfer
153// purpose : command to construct chamfers on several edges
154// Here the chamfer is propagated on tangential edges to the
155// required edge
156//=========================================================================
157
158static Standard_Integer chamfer(Draw_Interpretor& di,
1d54b807 159 Standard_Integer narg,
160 const char** a)
7fd59977 161{
162 // check the argument number of the command
163 if (narg == 1) {
586db386 164 di <<" help for chamf : \n";
1d54b807 165 di <<" Construction by equal distances from edge : chamf newname shape edge dist\n";
586db386 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";
7fd59977 168 }
169 else {
1d54b807 170 if (narg < 5)
171 return 1;
7fd59977 172
173 TopoDS_Shape S = DBRep::Get(a[2]);
1d54b807 174 if (S.IsNull())
175 return 1;
7fd59977 176
177 TopoDS_Edge E;
178 TopoDS_Face F;
179 Standard_Real d1,d2, angle;
180 Standard_Integer i = 3;
7fd59977 181
182 BRepFilletAPI_MakeChamfer aMCh(S);
183
1d54b807 184 while (i + 1 < narg) {
7fd59977 185 TopoDS_Shape aLocalEdge(DBRep::Get(a[i], TopAbs_EDGE));
1d54b807 186 if (aLocalEdge.IsNull())
187 return 1;
7fd59977 188 E = TopoDS::Edge(aLocalEdge);
189 TopoDS_Shape aLocalFace(DBRep::Get(a[i + 1], TopAbs_FACE));
1d54b807 190 if (aLocalFace.IsNull())
191 {
192 //symmetric chamfer (one distance)
193 d1 = atof(a[i + 1]);
194 if (aMCh.Contour(E) == 0 &&
195 d1 > Precision::Confusion())
196 aMCh.Add(d1, E);
197 i += 2;
7fd59977 198 }
1d54b807 199 else
200 {
201 F = TopoDS::Face(aLocalFace);
7fd59977 202
1d54b807 203 if (i + 3 < narg)
204 {
205 if (!strcasecmp(a[i + 2], "A") &&
206 i + 4 < narg)
207 {
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);
217 i += 5;
218 }
219 else
220 {
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);
228 i += 4;
7fd59977 229 }
230 }
7fd59977 231 }
232 }
233
234 // compute the chamfer and display the result
235 if (aMCh.NbContours() == 0 )
236 {
04232180 237 //std::cout<<"No suitable edges to chamfer"<<std::endl;
586db386 238 di<<"No suitable edges to chamfer\n";
7fd59977 239 return 1;
240 }
241 else aMCh.Build();
242
243 if (aMCh.IsDone()){
244 DBRep::Set(a[1],aMCh);
245 return 0;
246 }
247 else {
04232180 248 //std::cout<<"compute of chamfer failed"<<std::endl;
586db386 249 di<<"compute of chamfer failed\n";
7fd59977 250 return 1;
251 }
252 }
1d54b807 253
254 return 0;
7fd59977 255}
256
257
258
259//=======================================================================
260//function : ChamferCommands
261//purpose :
262//=======================================================================
263
264void BRepTest::ChamferCommands(Draw_Interpretor& theCommands)
265{
266 static Standard_Boolean done = Standard_False;
267 if (done) return;
268 done = Standard_True;
269
270 DBRep::BasicCommands(theCommands);
271
272 const char* g = "TOPOLOGY Fillet construction commands";
273
274// theCommands.Add("chamf",
275// "chamf newname shape edge1 face1 dist1_1 dist1_2 edge2 face2 dist2_1 dist2_2 ... ",__FILE__,chamfer,g);
276
277 theCommands.Add("chamf",
278 "for help call chamf without arguments",__FILE__,chamfer,g);
279
1d54b807 280 theCommands.Add("chamf_throat",
281 "chamf_throat result shape edge throat"
282 ,__FILE__,chamf_throat,g);
283
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);
7fd59977 287}