1 // Created on: 1993-07-22
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <BRepTest.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>
25 #include <BRepAlgo_Fuse.hxx>
26 #include <BRepAlgo_Common.hxx>
27 #include <BRepAlgo_Cut.hxx>
28 #include <BRepAlgo_Section.hxx>
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>
35 #include <TopTools_ListIteratorOfListOfShape.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>
45 #include <TopTools_IndexedMapOfShape.hxx>
48 //=======================================================================
50 //=======================================================================
52 static Standard_Integer topop(Draw_Interpretor& , Standard_Integer n, const char** a)
56 TopoDS_Shape s1 = DBRep::Get(a[2]);
57 TopoDS_Shape s2 = DBRep::Get(a[3]);
59 if (s1.IsNull() || s2.IsNull()) return 1;
64 res = BRepAlgo_Fuse(s1,s2);
65 else if (*(a[0]+1) == 'o')
66 res = BRepAlgo_Common(s1,s2);
68 res = BRepAlgo_Cut(s1,s2);
76 //=======================================================================
78 //=======================================================================
80 static Standard_Integer section(Draw_Interpretor& , Standard_Integer n, const char** a)
85 TopoDS_Shape s1 = DBRep::Get(a[2]);
86 TopoDS_Shape s2 = DBRep::Get(a[3]);
88 if (s1.IsNull() || s2.IsNull())
91 BRepAlgo_Section Sec(s1, s2, Standard_False);
94 for (int i=4; i < n; i++) {
95 if (!strcasecmp(a[i], "-2d"))
97 Sec.ComputePCurveOn1(Standard_True);
98 Sec.ComputePCurveOn2(Standard_True);
100 else if (!strcasecmp(a[i], "-2d1"))
102 Sec.ComputePCurveOn1(Standard_True);
103 Sec.ComputePCurveOn2(Standard_False);
105 else if (!strcasecmp(a[i], "-2d2"))
107 Sec.ComputePCurveOn1(Standard_False);
108 Sec.ComputePCurveOn2(Standard_True);
110 else if (!strcasecmp(a[i], "-no2d"))
112 Sec.ComputePCurveOn1(Standard_False);
113 Sec.ComputePCurveOn2(Standard_False);
115 else if (!strcasecmp(a[i], "-a"))
116 Sec.Approximation(Standard_True);
117 else if (strcasecmp(a[i], "-p"))
119 cout << "Unknown option: " << a[i] << endl;
126 DBRep::Set(a[1],res);
131 //=======================================================================
133 //=======================================================================
135 static Standard_Integer psection(Draw_Interpretor& , Standard_Integer n, const char** a)
139 TopoDS_Shape s = DBRep::Get(a[2]);
140 if (s.IsNull()) return 1;
142 Handle(Geom_Surface) ps = DrawTrSurf::GetSurface(a[3]);
143 if (ps.IsNull()) return 1;
145 Handle(Geom_Plane) pg = Handle(Geom_Plane)::DownCast(ps);
146 if (pg.IsNull()) return 1;
148 const gp_Pln& p = pg->Pln();
150 TopoDS_Shape res = BRepAlgo_Section(s,p);
152 DBRep::Set(a[1],res);
157 static Standard_Integer halfspace(Draw_Interpretor& di,
158 Standard_Integer n, const char** a)
162 // Le point indiquant le cote "matiere".
163 gp_Pnt RefPnt = gp_Pnt(Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
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;
170 di << a[2] << " must be a face or a shell\n";
174 BRepPrimAPI_MakeHalfSpace Half(TopoDS::Shell(Shell),RefPnt);
175 if ( Half.IsDone()) {
176 DBRep::Set(a[1],Half.Solid());
179 //cout << " HalfSpace NotDone" << endl;
180 di << " HalfSpace NotDone\n";
186 BRepPrimAPI_MakeHalfSpace Half(TopoDS::Face(Face),RefPnt);
187 if ( Half.IsDone()) {
188 DBRep::Set(a[1],Half.Solid());
191 //cout << " HalfSpace NotDone" << endl;
192 di << " HalfSpace NotDone\n";
199 //=======================================================================
200 //function : buildfaces
202 //=======================================================================
204 static Standard_Integer buildfaces(Draw_Interpretor& , Standard_Integer narg, const char** a)
206 if (narg < 4) return 1;
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;
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));
221 if (!FR.IsDone()) return 1;
225 BB.MakeCompound(Res);
227 for (; FR.More(); FR.Next()) {
228 TopoDS_Face FF = FR.Current();
230 DBRep::Set(a[1],Res);
235 //=======================================================================
236 //function : TopologyCommands
238 //=======================================================================
240 void BRepTest::TopologyCommands(Draw_Interpretor& theCommands)
242 static Standard_Boolean done = Standard_False;
244 done = Standard_True;
246 DBRep::BasicCommands(theCommands);
248 const char* g = "TOPOLOGY Topological operation commands";
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);