b311480e |
1 | // Created on: 1995-09-25 |
2 | // Created by: Stagiaire Flore Lautheanne |
3 | // Copyright (c) 1995-1999 Matra Datavision |
4 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
5 | // |
6 | // The content of this file is subject to the Open CASCADE Technology Public |
7 | // License Version 6.5 (the "License"). You may not use the content of this file |
8 | // except in compliance with the License. Please obtain a copy of the License |
9 | // at http://www.opencascade.org and read it completely before using this file. |
10 | // |
11 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
12 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
13 | // |
14 | // The Original Code and all software distributed under the License is |
15 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
16 | // Initial Developer hereby disclaims all such warranties, including without |
17 | // limitation, any warranties of merchantability, fitness for a particular |
18 | // purpose or non-infringement. Please see the License for the specific terms |
19 | // and conditions governing the rights and limitations under the License. |
20 | |
7fd59977 |
21 | |
22 | #ifdef HAVE_CONFIG_H |
23 | # include <config.h> |
24 | #endif |
25 | |
26 | #include <Draw_Interpretor.hxx> |
27 | #include <BRepTest.hxx> |
28 | #include <DBRep.hxx> |
29 | #include <BRepFilletAPI_MakeChamfer.hxx> |
30 | #include <TopAbs_ShapeEnum.hxx> |
31 | #include <TopoDS.hxx> |
32 | #include <TopoDS_Face.hxx> |
33 | #include <TopoDS_Edge.hxx> |
34 | #include <TopoDS_Vertex.hxx> |
35 | #include <TopoDS_Shape.hxx> |
36 | |
37 | #include <Precision.hxx> |
38 | #ifdef HAVE_STRINGS_H |
39 | # include <strings.h> |
40 | #endif |
41 | |
42 | |
43 | |
44 | //========================================================================= |
45 | // function : chamfer |
46 | // purpose : command to construct chamfers on several edges |
47 | // Here the chamfer is propagated on tangential edges to the |
48 | // required edge |
49 | //========================================================================= |
50 | |
51 | static Standard_Integer chamfer(Draw_Interpretor& di, |
52 | Standard_Integer narg, |
53 | const char** a) |
54 | |
55 | { |
56 | // check the argument number of the command |
57 | if (narg == 1) { |
58 | //cout <<" help for chamf : "<< endl; |
59 | //cout <<" Construction by equal distances from edge : chamf newname shape edge face S dist"<< endl; |
60 | //cout <<" Construction by two distances from edge : chamf newname shape edge face dist1 dist2"<< endl; |
61 | //cout <<" Construction by distance from edge and given angle : chamf newname shape edge face A dist angle"<< endl; |
62 | di <<" help for chamf : "<< "\n"; |
63 | di <<" Construction by equal distances from edge : chamf newname shape edge face S dist"<< "\n"; |
64 | di <<" Construction by two distances from edge : chamf newname shape edge face dist1 dist2"<< "\n"; |
65 | di <<" Construction by distance from edge and given angle : chamf newname shape edge face A dist angle"<< "\n"; |
66 | } |
67 | else { |
68 | if (narg < 7) return 1; |
69 | |
70 | TopoDS_Shape S = DBRep::Get(a[2]); |
71 | if (S.IsNull()) return 1; |
72 | |
73 | TopoDS_Edge E; |
74 | TopoDS_Face F; |
75 | Standard_Real d1,d2, angle; |
76 | Standard_Integer i = 3; |
77 | Standard_Integer Method = 1; |
78 | Standard_Integer NbArg = 3; |
79 | |
80 | BRepFilletAPI_MakeChamfer aMCh(S); |
81 | |
82 | if (!strcasecmp(a[i + 2], "S") ) Method = 0; |
83 | |
84 | if (Method != 0) { |
85 | if (!strcasecmp(a[i + 2], "A")) { |
86 | Method = 2; |
87 | NbArg++; |
88 | } |
89 | } |
90 | |
91 | while (i + NbArg < narg) { |
92 | TopoDS_Shape aLocalEdge(DBRep::Get(a[i], TopAbs_EDGE)); |
93 | E = TopoDS::Edge(aLocalEdge); |
94 | TopoDS_Shape aLocalFace(DBRep::Get(a[i + 1], TopAbs_FACE)); |
95 | F = TopoDS::Face(aLocalFace); |
96 | // E = TopoDS::Edge(DBRep::Get(a[i], TopAbs_EDGE)); |
97 | // F = TopoDS::Face(DBRep::Get(a[i + 1], TopAbs_FACE)); |
98 | if (Method == 0) { |
99 | if (!E.IsNull() && !F.IsNull() && (aMCh.Contour(E) == 0) ) { |
100 | d1 = atof(a[i + 3]); |
101 | |
102 | if ( d1 > Precision::Confusion()) |
103 | aMCh.Add(d1,E ,F); |
104 | } |
105 | i += 4; |
106 | } |
107 | else if (Method == 1) { |
108 | if (!E.IsNull() && !F.IsNull() && (aMCh.Contour(E) == 0) ) { |
109 | d1 = atof(a[i + 2]); |
110 | d2 = atof(a[i + 3]); |
111 | |
112 | if ( (d1 > Precision::Confusion()) |
113 | && (d2 > Precision::Confusion()) ) |
114 | aMCh.Add(d1,d2,E,F); |
115 | } |
116 | i += 4; |
117 | } |
118 | else { |
119 | if (!E.IsNull() && !F.IsNull() && (aMCh.Contour(E) == 0) ) { |
120 | d1 = atof(a[i + 3]); |
121 | angle = atof(a[i + 4]); |
c6541a0c |
122 | angle *= M_PI / 180.; |
7fd59977 |
123 | |
124 | if ( (d1 > Precision::Confusion()) |
125 | && (angle > Precision::Confusion()) |
c6541a0c |
126 | && (M_PI / 2.- angle > Precision::Confusion()) ) |
7fd59977 |
127 | aMCh.AddDA(d1, angle, E, F); |
128 | } |
129 | i += 5; |
130 | } |
131 | |
132 | if ( i < narg) { |
133 | Method = 1; |
134 | NbArg = 3; |
135 | if (!strcasecmp(a[i + 2], "S") ) Method = 0; |
136 | |
137 | if (Method != 0) { |
138 | if (!strcasecmp(a[i + 2], "A")) { |
139 | Method = 2; |
140 | NbArg++; |
141 | } |
142 | } |
143 | |
144 | } |
145 | } |
146 | |
147 | // compute the chamfer and display the result |
148 | if (aMCh.NbContours() == 0 ) |
149 | { |
150 | //cout<<"No suitable edges to chamfer"<<endl; |
151 | di<<"No suitable edges to chamfer"<<"\n"; |
152 | return 1; |
153 | } |
154 | else aMCh.Build(); |
155 | |
156 | if (aMCh.IsDone()){ |
157 | DBRep::Set(a[1],aMCh); |
158 | return 0; |
159 | } |
160 | else { |
161 | //cout<<"compute of chamfer failed"<<endl; |
162 | di<<"compute of chamfer failed"<<"\n"; |
163 | return 1; |
164 | } |
165 | } |
166 | return 0; |
167 | |
168 | } |
169 | |
170 | |
171 | |
172 | //======================================================================= |
173 | //function : ChamferCommands |
174 | //purpose : |
175 | //======================================================================= |
176 | |
177 | void BRepTest::ChamferCommands(Draw_Interpretor& theCommands) |
178 | { |
179 | static Standard_Boolean done = Standard_False; |
180 | if (done) return; |
181 | done = Standard_True; |
182 | |
183 | DBRep::BasicCommands(theCommands); |
184 | |
185 | const char* g = "TOPOLOGY Fillet construction commands"; |
186 | |
187 | // theCommands.Add("chamf", |
188 | // "chamf newname shape edge1 face1 dist1_1 dist1_2 edge2 face2 dist2_1 dist2_2 ... ",__FILE__,chamfer,g); |
189 | |
190 | theCommands.Add("chamf", |
191 | "for help call chamf without arguments",__FILE__,chamfer,g); |
192 | |
193 | } |