0020716: Eliminate usage of "config.h" header file
[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>
26#include <TopoDS_Vertex.hxx>
27#include <TopoDS_Shape.hxx>
28
29#include <Precision.hxx>
7fd59977 30
31//=========================================================================
32// function : chamfer
33// purpose : command to construct chamfers on several edges
34// Here the chamfer is propagated on tangential edges to the
35// required edge
36//=========================================================================
37
38static Standard_Integer chamfer(Draw_Interpretor& di,
39 Standard_Integer narg,
40 const char** a)
41
42{
43 // check the argument number of the command
44 if (narg == 1) {
45 //cout <<" help for chamf : "<< endl;
46 //cout <<" Construction by equal distances from edge : chamf newname shape edge face S dist"<< endl;
47 //cout <<" Construction by two distances from edge : chamf newname shape edge face dist1 dist2"<< endl;
48 //cout <<" Construction by distance from edge and given angle : chamf newname shape edge face A dist angle"<< endl;
49 di <<" help for chamf : "<< "\n";
50 di <<" Construction by equal distances from edge : chamf newname shape edge face S dist"<< "\n";
51 di <<" Construction by two distances from edge : chamf newname shape edge face dist1 dist2"<< "\n";
52 di <<" Construction by distance from edge and given angle : chamf newname shape edge face A dist angle"<< "\n";
53 }
54 else {
55 if (narg < 7) return 1;
56
57 TopoDS_Shape S = DBRep::Get(a[2]);
58 if (S.IsNull()) return 1;
59
60 TopoDS_Edge E;
61 TopoDS_Face F;
62 Standard_Real d1,d2, angle;
63 Standard_Integer i = 3;
64 Standard_Integer Method = 1;
65 Standard_Integer NbArg = 3;
66
67 BRepFilletAPI_MakeChamfer aMCh(S);
68
69 if (!strcasecmp(a[i + 2], "S") ) Method = 0;
70
71 if (Method != 0) {
72 if (!strcasecmp(a[i + 2], "A")) {
73 Method = 2;
74 NbArg++;
75 }
76 }
77
78 while (i + NbArg < narg) {
79 TopoDS_Shape aLocalEdge(DBRep::Get(a[i], TopAbs_EDGE));
80 E = TopoDS::Edge(aLocalEdge);
81 TopoDS_Shape aLocalFace(DBRep::Get(a[i + 1], TopAbs_FACE));
82 F = TopoDS::Face(aLocalFace);
83// E = TopoDS::Edge(DBRep::Get(a[i], TopAbs_EDGE));
84// F = TopoDS::Face(DBRep::Get(a[i + 1], TopAbs_FACE));
85 if (Method == 0) {
86 if (!E.IsNull() && !F.IsNull() && (aMCh.Contour(E) == 0) ) {
91322f44 87 d1 = Draw::Atof(a[i + 3]);
7fd59977 88
89 if ( d1 > Precision::Confusion())
90 aMCh.Add(d1,E ,F);
91 }
92 i += 4;
93 }
94 else if (Method == 1) {
95 if (!E.IsNull() && !F.IsNull() && (aMCh.Contour(E) == 0) ) {
91322f44 96 d1 = Draw::Atof(a[i + 2]);
97 d2 = Draw::Atof(a[i + 3]);
7fd59977 98
99 if ( (d1 > Precision::Confusion())
100 && (d2 > Precision::Confusion()) )
101 aMCh.Add(d1,d2,E,F);
102 }
103 i += 4;
104 }
105 else {
106 if (!E.IsNull() && !F.IsNull() && (aMCh.Contour(E) == 0) ) {
91322f44 107 d1 = Draw::Atof(a[i + 3]);
108 angle = Draw::Atof(a[i + 4]);
c6541a0c 109 angle *= M_PI / 180.;
7fd59977 110
111 if ( (d1 > Precision::Confusion())
112 && (angle > Precision::Confusion())
c6541a0c 113 && (M_PI / 2.- angle > Precision::Confusion()) )
7fd59977 114 aMCh.AddDA(d1, angle, E, F);
115 }
116 i += 5;
117 }
118
119 if ( i < narg) {
120 Method = 1;
121 NbArg = 3;
122 if (!strcasecmp(a[i + 2], "S") ) Method = 0;
123
124 if (Method != 0) {
125 if (!strcasecmp(a[i + 2], "A")) {
126 Method = 2;
127 NbArg++;
128 }
129 }
130
131 }
132 }
133
134 // compute the chamfer and display the result
135 if (aMCh.NbContours() == 0 )
136 {
137 //cout<<"No suitable edges to chamfer"<<endl;
138 di<<"No suitable edges to chamfer"<<"\n";
139 return 1;
140 }
141 else aMCh.Build();
142
143 if (aMCh.IsDone()){
144 DBRep::Set(a[1],aMCh);
145 return 0;
146 }
147 else {
148 //cout<<"compute of chamfer failed"<<endl;
149 di<<"compute of chamfer failed"<<"\n";
150 return 1;
151 }
152 }
153 return 0;
154
155}
156
157
158
159//=======================================================================
160//function : ChamferCommands
161//purpose :
162//=======================================================================
163
164void BRepTest::ChamferCommands(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 Fillet construction commands";
173
174// theCommands.Add("chamf",
175// "chamf newname shape edge1 face1 dist1_1 dist1_2 edge2 face2 dist2_1 dist2_2 ... ",__FILE__,chamfer,g);
176
177 theCommands.Add("chamf",
178 "for help call chamf without arguments",__FILE__,chamfer,g);
179
180}