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