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
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.
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.
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.
25 #include <BRepTest.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>
33 #include <BRepAlgo_Fuse.hxx>
34 #include <BRepAlgo_Common.hxx>
35 #include <BRepAlgo_Cut.hxx>
36 #include <BRepAlgo_Section.hxx>
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>
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>
54 #include <TopTools_IndexedMapOfShape.hxx>
61 //=======================================================================
63 //=======================================================================
65 static Standard_Integer topop(Draw_Interpretor& , Standard_Integer n, const char** a)
69 TopoDS_Shape s1 = DBRep::Get(a[2]);
70 TopoDS_Shape s2 = DBRep::Get(a[3]);
72 if (s1.IsNull() || s2.IsNull()) return 1;
77 res = BRepAlgo_Fuse(s1,s2);
78 else if (*(a[0]+1) == 'o')
79 res = BRepAlgo_Common(s1,s2);
81 res = BRepAlgo_Cut(s1,s2);
89 //=======================================================================
91 //=======================================================================
93 static Standard_Integer section(Draw_Interpretor& , Standard_Integer n, const char** a)
98 TopoDS_Shape s1 = DBRep::Get(a[2]);
99 TopoDS_Shape s2 = DBRep::Get(a[3]);
101 if (s1.IsNull() || s2.IsNull())
104 BRepAlgo_Section Sec(s1, s2, Standard_False);
107 for (int i=4; i < n; i++) {
108 if (!strcasecmp(a[i], "-2d"))
110 Sec.ComputePCurveOn1(Standard_True);
111 Sec.ComputePCurveOn2(Standard_True);
113 else if (!strcasecmp(a[i], "-2d1"))
115 Sec.ComputePCurveOn1(Standard_True);
116 Sec.ComputePCurveOn2(Standard_False);
118 else if (!strcasecmp(a[i], "-2d2"))
120 Sec.ComputePCurveOn1(Standard_False);
121 Sec.ComputePCurveOn2(Standard_True);
123 else if (!strcasecmp(a[i], "-no2d"))
125 Sec.ComputePCurveOn1(Standard_False);
126 Sec.ComputePCurveOn2(Standard_False);
128 else if (!strcasecmp(a[i], "-a"))
129 Sec.Approximation(Standard_True);
130 else if (strcasecmp(a[i], "-p"))
132 cout << "Unknown option: " << a[i] << endl;
139 DBRep::Set(a[1],res);
144 //=======================================================================
146 //=======================================================================
148 static Standard_Integer psection(Draw_Interpretor& , Standard_Integer n, const char** a)
152 TopoDS_Shape s = DBRep::Get(a[2]);
153 if (s.IsNull()) return 1;
155 Handle(Geom_Surface) ps = DrawTrSurf::GetSurface(a[3]);
156 if (ps.IsNull()) return 1;
158 Handle(Geom_Plane) pg = Handle(Geom_Plane)::DownCast(ps);
159 if (pg.IsNull()) return 1;
161 const gp_Pln& p = pg->Pln();
163 TopoDS_Shape res = BRepAlgo_Section(s,p);
165 DBRep::Set(a[1],res);
170 static Standard_Integer halfspace(Draw_Interpretor& di,
171 Standard_Integer n, const char** a)
175 // Le point indiquant le cote "matiere".
176 gp_Pnt RefPnt = gp_Pnt(Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
178 TopoDS_Shape Face = DBRep::Get(a[2],TopAbs_FACE);
179 if ( Face.IsNull()) {
180 TopoDS_Shape Shell = DBRep::Get(a[2],TopAbs_SHELL);
181 if (Shell.IsNull()) {
182 //cout << a[2] << " must be a face or a shell" << endl;
183 di << a[2] << " must be a face or a shell" << "\n";
187 BRepPrimAPI_MakeHalfSpace Half(TopoDS::Shell(Shell),RefPnt);
188 if ( Half.IsDone()) {
189 DBRep::Set(a[1],Half.Solid());
192 //cout << " HalfSpace NotDone" << endl;
193 di << " HalfSpace NotDone" << "\n";
199 BRepPrimAPI_MakeHalfSpace Half(TopoDS::Face(Face),RefPnt);
200 if ( Half.IsDone()) {
201 DBRep::Set(a[1],Half.Solid());
204 //cout << " HalfSpace NotDone" << endl;
205 di << " HalfSpace NotDone" << "\n";
212 //=======================================================================
213 //function : buildfaces
215 //=======================================================================
217 static Standard_Integer buildfaces(Draw_Interpretor& , Standard_Integer narg, const char** a)
219 if (narg < 4) return 1;
221 TopoDS_Shape InputShape(DBRep::Get( a[2] ,TopAbs_FACE));
222 TopoDS_Face F = TopoDS::Face(InputShape);
223 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[2],TopAbs_FACE));
224 BRepAlgo_FaceRestrictor FR;
227 for (Standard_Integer i = 3 ; i < narg ; i++) {
228 TopoDS_Shape InputWire(DBRep::Get(a[i],TopAbs_WIRE));
229 TopoDS_Wire W = TopoDS::Wire(InputWire);
230 // TopoDS_Wire W = TopoDS::Wire(DBRep::Get(a[i],TopAbs_WIRE));
234 if (!FR.IsDone()) return 1;
238 BB.MakeCompound(Res);
240 for (; FR.More(); FR.Next()) {
241 TopoDS_Face FF = FR.Current();
243 DBRep::Set(a[1],Res);
248 //=======================================================================
249 //function : TopologyCommands
251 //=======================================================================
253 void BRepTest::TopologyCommands(Draw_Interpretor& theCommands)
255 static Standard_Boolean done = Standard_False;
257 done = Standard_True;
259 DBRep::BasicCommands(theCommands);
261 const char* g = "TOPOLOGY Topological operation commands";
263 theCommands.Add("fuse","fuse result s1 s2",__FILE__,topop,g);
264 theCommands.Add("common","common result s1 s2",__FILE__,topop,g);
265 theCommands.Add("cut","cut result part tool",__FILE__,topop,g);
266 theCommands.Add("section","section result s1 s2 [-no2d/-2d/-2d1/-2d2] [-p/-a]",__FILE__,section,g);
267 theCommands.Add("psection","psection result s plane",__FILE__,psection,g);
268 theCommands.Add("halfspace","halfspace result face/shell x y z",__FILE__,halfspace,g);
269 theCommands.Add("buildfaces","buildfaces result faceReference wire1 wire2 ...",__FILE__,buildfaces,g);