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 <BRepLProp_SLProps.hxx>
36 #include <TopTools_ListIteratorOfListOfShape.hxx>
38 #include <TopoDS_Edge.hxx>
39 #include <TopoDS_Compound.hxx>
40 #include <TopoDS_Wire.hxx>
41 #include <TopExp_Explorer.hxx>
42 #include <TopOpeBRepBuild_HBuilder.hxx>
43 #include <TopOpeBRepDS_HDataStructure.hxx>
46 #include <TopTools_IndexedMapOfShape.hxx>
49 //=======================================================================
51 //=======================================================================
53 static Standard_Integer topop(Draw_Interpretor& , Standard_Integer n, const char** a)
57 TopoDS_Shape s1 = DBRep::Get(a[2]);
58 TopoDS_Shape s2 = DBRep::Get(a[3]);
60 if (s1.IsNull() || s2.IsNull()) return 1;
65 res = BRepAlgo_Fuse(s1,s2);
66 else if (*(a[0]+1) == 'o')
67 res = BRepAlgo_Common(s1,s2);
69 res = BRepAlgo_Cut(s1,s2);
77 //=======================================================================
79 //=======================================================================
81 static Standard_Integer section(Draw_Interpretor& , Standard_Integer n, const char** a)
86 TopoDS_Shape s1 = DBRep::Get(a[2]);
87 TopoDS_Shape s2 = DBRep::Get(a[3]);
89 if (s1.IsNull() || s2.IsNull())
92 BRepAlgo_Section Sec(s1, s2, Standard_False);
95 for (int i=4; i < n; i++) {
96 if (!strcasecmp(a[i], "-2d"))
98 Sec.ComputePCurveOn1(Standard_True);
99 Sec.ComputePCurveOn2(Standard_True);
101 else if (!strcasecmp(a[i], "-2d1"))
103 Sec.ComputePCurveOn1(Standard_True);
104 Sec.ComputePCurveOn2(Standard_False);
106 else if (!strcasecmp(a[i], "-2d2"))
108 Sec.ComputePCurveOn1(Standard_False);
109 Sec.ComputePCurveOn2(Standard_True);
111 else if (!strcasecmp(a[i], "-no2d"))
113 Sec.ComputePCurveOn1(Standard_False);
114 Sec.ComputePCurveOn2(Standard_False);
116 else if (!strcasecmp(a[i], "-a"))
117 Sec.Approximation(Standard_True);
118 else if (strcasecmp(a[i], "-p"))
120 cout << "Unknown option: " << a[i] << endl;
127 DBRep::Set(a[1],res);
132 //=======================================================================
134 //=======================================================================
136 static Standard_Integer psection(Draw_Interpretor& , Standard_Integer n, const char** a)
140 TopoDS_Shape s = DBRep::Get(a[2]);
141 if (s.IsNull()) return 1;
143 Handle(Geom_Surface) ps = DrawTrSurf::GetSurface(a[3]);
144 if (ps.IsNull()) return 1;
146 Handle(Geom_Plane) pg = Handle(Geom_Plane)::DownCast(ps);
147 if (pg.IsNull()) return 1;
149 const gp_Pln& p = pg->Pln();
151 TopoDS_Shape res = BRepAlgo_Section(s,p);
153 DBRep::Set(a[1],res);
158 static Standard_Integer halfspace(Draw_Interpretor& di,
159 Standard_Integer n, const char** a)
163 // Le point indiquant le cote "matiere".
164 gp_Pnt RefPnt = gp_Pnt(Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
166 TopoDS_Shape Face = DBRep::Get(a[2],TopAbs_FACE);
167 if ( Face.IsNull()) {
168 TopoDS_Shape Shell = DBRep::Get(a[2],TopAbs_SHELL);
169 if (Shell.IsNull()) {
170 //cout << a[2] << " must be a face or a shell" << endl;
171 di << a[2] << " must be a face or a shell\n";
175 BRepPrimAPI_MakeHalfSpace Half(TopoDS::Shell(Shell),RefPnt);
176 if ( Half.IsDone()) {
177 DBRep::Set(a[1],Half.Solid());
180 //cout << " HalfSpace NotDone" << endl;
181 di << " HalfSpace NotDone\n";
187 BRepPrimAPI_MakeHalfSpace Half(TopoDS::Face(Face),RefPnt);
188 if ( Half.IsDone()) {
189 DBRep::Set(a[1],Half.Solid());
192 //cout << " HalfSpace NotDone" << endl;
193 di << " HalfSpace NotDone\n";
200 //=======================================================================
201 //function : buildfaces
203 //=======================================================================
205 static Standard_Integer buildfaces(Draw_Interpretor& , Standard_Integer narg, const char** a)
207 if (narg < 4) return 1;
209 TopoDS_Shape InputShape(DBRep::Get( a[2] ,TopAbs_FACE));
210 TopoDS_Face F = TopoDS::Face(InputShape);
211 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[2],TopAbs_FACE));
212 BRepAlgo_FaceRestrictor FR;
215 for (Standard_Integer i = 3 ; i < narg ; i++) {
216 TopoDS_Shape InputWire(DBRep::Get(a[i],TopAbs_WIRE));
217 TopoDS_Wire W = TopoDS::Wire(InputWire);
218 // TopoDS_Wire W = TopoDS::Wire(DBRep::Get(a[i],TopAbs_WIRE));
222 if (!FR.IsDone()) return 1;
226 BB.MakeCompound(Res);
228 for (; FR.More(); FR.Next()) {
229 TopoDS_Face FF = FR.Current();
231 DBRep::Set(a[1],Res);
236 //=======================================================================
237 //function : TopologyCommands
239 //=======================================================================
241 void BRepTest::TopologyCommands(Draw_Interpretor& theCommands)
243 static Standard_Boolean done = Standard_False;
245 done = Standard_True;
247 DBRep::BasicCommands(theCommands);
249 const char* g = "TOPOLOGY Topological operation commands";
251 theCommands.Add("fuse","fuse result s1 s2",__FILE__,topop,g);
252 theCommands.Add("common","common result s1 s2",__FILE__,topop,g);
253 theCommands.Add("cut","cut result part tool",__FILE__,topop,g);
254 theCommands.Add("section","section result s1 s2 [-no2d/-2d/-2d1/-2d2] [-p/-a]",__FILE__,section,g);
255 theCommands.Add("psection","psection result s plane",__FILE__,psection,g);
256 theCommands.Add("halfspace","halfspace result face/shell x y z",__FILE__,halfspace,g);
257 theCommands.Add("buildfaces","buildfaces result faceReference wire1 wire2 ...",__FILE__,buildfaces,g);