b311480e |
1 | // Created on: 1993-07-22 |
2 | // Created by: Remi LEQUETTE |
3 | // Copyright (c) 1993-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 | #include <BRepTest.hxx> |
26 | #include <DBRep.hxx> |
27 | #include <Draw_Interpretor.hxx> |
28 | #include <DrawTrSurf.hxx> |
29 | #include <Geom_Plane.hxx> |
30 | #include <Draw_Appli.hxx> |
31 | #include <BRep_Builder.hxx> |
32 | |
33 | #include <BRepAlgo_Fuse.hxx> |
34 | #include <BRepAlgo_Common.hxx> |
35 | #include <BRepAlgo_Cut.hxx> |
36 | #include <BRepAlgo_Section.hxx> |
37 | |
38 | #include <BRepFilletAPI_MakeFillet.hxx> |
39 | #include <BRepBuilderAPI_MakeVertex.hxx> |
40 | #include <BRepPrimAPI_MakeHalfSpace.hxx> |
41 | #include <BRepAlgo_FaceRestrictor.hxx> |
42 | #include <BRepExtrema_ExtPF.hxx> |
43 | #include <BRepLProp_SLProps.hxx> |
44 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
45 | #include <TopoDS.hxx> |
46 | #include <TopoDS_Edge.hxx> |
47 | #include <TopoDS_Compound.hxx> |
48 | #include <TopoDS_Wire.hxx> |
49 | #include <TopExp_Explorer.hxx> |
50 | #include <TopOpeBRepBuild_HBuilder.hxx> |
51 | #include <TopOpeBRepDS_HDataStructure.hxx> |
52 | #include <gp.hxx> |
53 | #include <gp_Pln.hxx> |
54 | #include <TopTools_IndexedMapOfShape.hxx> |
55 | #include <TopExp.hxx> |
56 | |
57 | #ifdef HAVE_STRINGS_H |
58 | # include <strings.h> |
59 | #endif |
60 | |
61 | //======================================================================= |
62 | // topop |
63 | //======================================================================= |
64 | |
65 | static Standard_Integer topop(Draw_Interpretor& , Standard_Integer n, const char** a) |
66 | { |
67 | if (n < 4) return 1; |
68 | |
69 | TopoDS_Shape s1 = DBRep::Get(a[2]); |
70 | TopoDS_Shape s2 = DBRep::Get(a[3]); |
71 | |
72 | if (s1.IsNull() || s2.IsNull()) return 1; |
73 | |
74 | TopoDS_Shape res; |
75 | |
76 | if (*a[0] == 'f') |
77 | res = BRepAlgo_Fuse(s1,s2); |
78 | else if (*(a[0]+1) == 'o') |
79 | res = BRepAlgo_Common(s1,s2); |
80 | else |
81 | res = BRepAlgo_Cut(s1,s2); |
82 | |
83 | DBRep::Set(a[1],res); |
84 | |
85 | return 0; |
86 | } |
87 | |
88 | |
89 | //======================================================================= |
90 | // section |
91 | //======================================================================= |
92 | |
93 | static Standard_Integer section(Draw_Interpretor& , Standard_Integer n, const char** a) |
94 | { |
95 | |
96 | if (n < 4) return 1; |
97 | |
98 | TopoDS_Shape s1 = DBRep::Get(a[2]); |
99 | TopoDS_Shape s2 = DBRep::Get(a[3]); |
100 | |
101 | if (s1.IsNull() || s2.IsNull()) |
102 | return 1; |
103 | |
104 | BRepAlgo_Section Sec(s1, s2, Standard_False); |
105 | TopoDS_Shape res; |
106 | |
107 | if (n > 4) { |
108 | #ifdef WNT |
109 | if (!strcasecmp(a[4],"-2d") || !strcasecmp(a[4], "-no2d")) { |
110 | #else |
111 | if (!strncasecmp(a[4],"-2d", 3) || !strcasecmp(a[4], "-no2d")) { |
112 | #endif |
113 | if (!strcasecmp(a[4], "-2d")) { |
114 | Sec.ComputePCurveOn1(Standard_True); |
115 | Sec.ComputePCurveOn2(Standard_True); |
116 | } else |
117 | if (!strcasecmp(a[4], "-2d1")) |
118 | Sec.ComputePCurveOn1(Standard_True); |
119 | else |
120 | if (!strcasecmp(a[4], "-2d2")) |
121 | Sec.ComputePCurveOn2(Standard_True); |
122 | else |
123 | if (strcasecmp(a[4], "-no2d")) |
124 | return 1; |
125 | if(n > 5) |
126 | if (!strcasecmp(a[5], "-a")) |
127 | Sec.Approximation(TopOpeBRepTool_APPROX); |
128 | else |
129 | if (strcasecmp(a[5], "-p")) |
130 | return 1; |
131 | } else {// fin a[4],"-2d" |
132 | if (!strcasecmp(a[4], "-a") || !strcasecmp(a[4], "-p")) { |
133 | if (!strcasecmp(a[4], "-a")) |
134 | Sec.Approximation(TopOpeBRepTool_APPROX); |
135 | if(n > 5) { |
136 | #ifdef WNT |
137 | if (!strcasecmp(a[5],"-2d") || !strcasecmp(a[5], "-no2d")) { |
138 | #else |
139 | if (!strncasecmp(a[5],"-2d", 3) || !strcasecmp(a[5], "-no2d")) { |
140 | #endif |
141 | if (!strcasecmp(a[5], "-2d")) { |
142 | Sec.ComputePCurveOn1(Standard_True); |
143 | Sec.ComputePCurveOn2(Standard_True); |
144 | } else |
145 | if (!strcasecmp(a[5], "-2d1")) |
146 | Sec.ComputePCurveOn1(Standard_True); |
147 | else |
148 | if (!strcasecmp(a[5], "-2d2")) |
149 | Sec.ComputePCurveOn2(Standard_True); |
150 | else |
151 | if (strcasecmp(a[5], "-no2d")) |
152 | return 1; |
153 | } |
154 | } |
155 | } else // fin a[4],"-a" |
156 | return 1; |
157 | } |
158 | }// fin n > 4 |
159 | |
160 | res = Sec.Shape(); |
161 | |
162 | DBRep::Set(a[1],res); |
163 | |
164 | return 0; |
165 | } |
166 | |
167 | //======================================================================= |
168 | // psection |
169 | //======================================================================= |
170 | |
171 | static Standard_Integer psection(Draw_Interpretor& , Standard_Integer n, const char** a) |
172 | { |
173 | if (n < 4) return 1; |
174 | |
175 | TopoDS_Shape s = DBRep::Get(a[2]); |
176 | if (s.IsNull()) return 1; |
177 | |
178 | Handle(Geom_Surface) ps = DrawTrSurf::GetSurface(a[3]); |
179 | if (ps.IsNull()) return 1; |
180 | |
181 | Handle(Geom_Plane) pg = Handle(Geom_Plane)::DownCast(ps); |
182 | if (pg.IsNull()) return 1; |
183 | |
184 | const gp_Pln& p = pg->Pln(); |
185 | |
186 | TopoDS_Shape res = BRepAlgo_Section(s,p); |
187 | |
188 | DBRep::Set(a[1],res); |
189 | |
190 | return 0; |
191 | } |
192 | |
193 | static Standard_Integer halfspace(Draw_Interpretor& di, |
194 | Standard_Integer n, const char** a) |
195 | { |
196 | if (n < 6) return 1; |
197 | |
198 | // Le point indiquant le cote "matiere". |
91322f44 |
199 | gp_Pnt RefPnt = gp_Pnt(Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5])); |
7fd59977 |
200 | |
201 | TopoDS_Shape Face = DBRep::Get(a[2],TopAbs_FACE); |
202 | if ( Face.IsNull()) { |
203 | TopoDS_Shape Shell = DBRep::Get(a[2],TopAbs_SHELL); |
204 | if (Shell.IsNull()) { |
205 | //cout << a[2] << " must be a face or a shell" << endl; |
206 | di << a[2] << " must be a face or a shell" << "\n"; |
207 | return 1; |
208 | } |
209 | else { |
210 | BRepPrimAPI_MakeHalfSpace Half(TopoDS::Shell(Shell),RefPnt); |
211 | if ( Half.IsDone()) { |
212 | DBRep::Set(a[1],Half.Solid()); |
213 | } |
214 | else { |
215 | //cout << " HalfSpace NotDone" << endl; |
216 | di << " HalfSpace NotDone" << "\n"; |
217 | return 1; |
218 | } |
219 | } |
220 | } |
221 | else { |
222 | BRepPrimAPI_MakeHalfSpace Half(TopoDS::Face(Face),RefPnt); |
223 | if ( Half.IsDone()) { |
224 | DBRep::Set(a[1],Half.Solid()); |
225 | } |
226 | else { |
227 | //cout << " HalfSpace NotDone" << endl; |
228 | di << " HalfSpace NotDone" << "\n"; |
229 | return 1; |
230 | } |
231 | } |
232 | return 0; |
233 | } |
234 | |
235 | //======================================================================= |
236 | //function : buildfaces |
237 | //purpose : |
238 | //======================================================================= |
239 | |
240 | static Standard_Integer buildfaces(Draw_Interpretor& , Standard_Integer narg, const char** a) |
241 | { |
242 | if (narg < 4) return 1; |
243 | |
244 | TopoDS_Shape InputShape(DBRep::Get( a[2] ,TopAbs_FACE)); |
245 | TopoDS_Face F = TopoDS::Face(InputShape); |
246 | // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[2],TopAbs_FACE)); |
247 | BRepAlgo_FaceRestrictor FR; |
248 | FR.Init(F); |
249 | |
250 | for (Standard_Integer i = 3 ; i < narg ; i++) { |
251 | TopoDS_Shape InputWire(DBRep::Get(a[i],TopAbs_WIRE)); |
252 | TopoDS_Wire W = TopoDS::Wire(InputWire); |
253 | // TopoDS_Wire W = TopoDS::Wire(DBRep::Get(a[i],TopAbs_WIRE)); |
254 | FR.Add(W); |
255 | } |
256 | FR.Perform(); |
257 | if (!FR.IsDone()) return 1; |
258 | |
259 | TopoDS_Compound Res; |
260 | BRep_Builder BB; |
261 | BB.MakeCompound(Res); |
262 | |
263 | for (; FR.More(); FR.Next()) { |
264 | TopoDS_Face FF = FR.Current(); |
265 | BB.Add(Res,FF); |
266 | DBRep::Set(a[1],Res); |
267 | } |
268 | return 0; |
269 | } |
270 | |
271 | //======================================================================= |
272 | //function : TopologyCommands |
273 | //purpose : |
274 | //======================================================================= |
275 | |
276 | void BRepTest::TopologyCommands(Draw_Interpretor& theCommands) |
277 | { |
278 | static Standard_Boolean done = Standard_False; |
279 | if (done) return; |
280 | done = Standard_True; |
281 | |
282 | DBRep::BasicCommands(theCommands); |
283 | |
284 | const char* g = "TOPOLOGY Topological operation commands"; |
285 | |
286 | theCommands.Add("fuse","fuse result s1 s2",__FILE__,topop,g); |
287 | theCommands.Add("common","common result s1 s2",__FILE__,topop,g); |
288 | theCommands.Add("cut","cut result part tool",__FILE__,topop,g); |
289 | theCommands.Add("section","section result s1 s2 [-no2d/-2d/-2d1/-2d2] [-p/-a]",__FILE__,section,g); |
290 | theCommands.Add("psection","psection result s plane",__FILE__,psection,g); |
291 | theCommands.Add("halfspace","halfspace result face/shell x y z",__FILE__,halfspace,g); |
292 | theCommands.Add("buildfaces","buildfaces result faceReference wire1 wire2 ...",__FILE__,buildfaces,g); |
293 | } |