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