1 // Created by: Peter KURNEV
2 // Copyright (c) 2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
16 #include <BOPAlgo_PaveFiller.hxx>
17 #include <BOPTest.hxx>
18 #include <BOPTest_Objects.hxx>
19 #include <BRepAlgoAPI_BooleanOperation.hxx>
20 #include <BRepAlgoAPI_BuilderAlgo.hxx>
21 #include <BRepAlgoAPI_Common.hxx>
22 #include <BRepAlgoAPI_Cut.hxx>
23 #include <BRepAlgoAPI_Fuse.hxx>
24 #include <BRepAlgoAPI_Section.hxx>
25 #include <BRepAlgoAPI_Splitter.hxx>
26 #include <BRepTest_Objects.hxx>
29 #include <TopoDS_Shape.hxx>
30 #include <TopTools_ListOfShape.hxx>
35 static Standard_Integer bapibuild(Draw_Interpretor&, Standard_Integer, const char**);
36 static Standard_Integer bapibop (Draw_Interpretor&, Standard_Integer, const char**);
37 static Standard_Integer bapisplit(Draw_Interpretor&, Standard_Integer, const char**);
39 //=======================================================================
40 //function : APICommands
42 //=======================================================================
43 void BOPTest::APICommands(Draw_Interpretor& theCommands)
45 static Standard_Boolean done = Standard_False;
49 const char* g = "BOPTest commands";
51 theCommands.Add("bapibuild", "use bapibuild r" , __FILE__, bapibuild, g);
52 theCommands.Add("bapibop", "use bapibop r type" , __FILE__, bapibop, g);
53 theCommands.Add("bapisplit", "use bapisplit r" , __FILE__, bapisplit, g);
55 //=======================================================================
58 //=======================================================================
59 Standard_Integer bapibop(Draw_Interpretor& di,
64 di << " use bapibop r type\n";
68 Standard_Boolean bRunParallel, bNonDestructive;
70 Standard_Real aFuzzyValue;
71 BRepAlgoAPI_Common aCommon;
72 BRepAlgoAPI_Fuse aFuse;
74 BRepAlgoAPI_Section aSection;
75 BRepAlgoAPI_BooleanOperation *pBuilder;
76 BOPAlgo_Operation aOp;
81 di << "invalid operation type\n";
84 aOp=(BOPAlgo_Operation)iOp;
100 case BOPAlgo_SECTION:
108 TopTools_ListOfShape& aLS=BOPTest_Objects::Shapes();
109 TopTools_ListOfShape& aLT=BOPTest_Objects::Tools();
111 bRunParallel=BOPTest_Objects::RunParallel();
112 aFuzzyValue=BOPTest_Objects::FuzzyValue();
113 bNonDestructive = BOPTest_Objects::NonDestructive();
114 BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue();
116 if (aOp!=BOPAlgo_CUT21) {
117 pBuilder->SetArguments(aLS);
118 pBuilder->SetTools(aLT);
121 pBuilder->SetArguments(aLT);
122 pBuilder->SetTools(aLS);
125 pBuilder->SetRunParallel(bRunParallel);
126 pBuilder->SetFuzzyValue(aFuzzyValue);
127 pBuilder->SetNonDestructive(bNonDestructive);
128 pBuilder->SetGlue(aGlue);
129 pBuilder->SetCheckInverted(BOPTest_Objects::CheckInverted());
130 pBuilder->SetUseOBB(BOPTest_Objects::UseOBB());
131 pBuilder->SetToFillHistory(BRepTest_Objects::IsHistoryNeeded());
134 pBuilder->SimplifyResult(BOPTest_Objects::UnifyEdges(),
135 BOPTest_Objects::UnifyFaces(),
136 BOPTest_Objects::Angular());
138 // Store the history of operation into the session
139 if (BRepTest_Objects::IsHistoryNeeded())
140 BRepTest_Objects::SetHistory(pBuilder->History());
142 if (pBuilder->HasWarnings()) {
143 Standard_SStream aSStream;
144 pBuilder->DumpWarnings(aSStream);
148 if (pBuilder->HasErrors()) {
149 Standard_SStream aSStream;
150 pBuilder->DumpErrors(aSStream);
155 const TopoDS_Shape& aR=pBuilder->Shape();
157 di << " null shape\n";
161 DBRep::Set(a[1], aR);
164 //=======================================================================
165 //function : bapibuild
167 //=======================================================================
168 Standard_Integer bapibuild(Draw_Interpretor& di,
173 di << " use bapibuild r\n";
177 Standard_Boolean bRunParallel, bNonDestructive;
178 Standard_Integer iErr;
179 Standard_Real aFuzzyValue;
180 BRepAlgoAPI_BuilderAlgo aBuilder;
182 TopTools_ListOfShape aLS = BOPTest_Objects::Shapes();
183 TopTools_ListOfShape aLT = BOPTest_Objects::Tools();
186 bRunParallel=BOPTest_Objects::RunParallel();
187 aFuzzyValue=BOPTest_Objects::FuzzyValue();
188 bNonDestructive = BOPTest_Objects::NonDestructive();
189 BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue();
191 aBuilder.SetArguments(aLS);
192 aBuilder.SetRunParallel(bRunParallel);
193 aBuilder.SetFuzzyValue(aFuzzyValue);
194 aBuilder.SetNonDestructive(bNonDestructive);
195 aBuilder.SetGlue(aGlue);
196 aBuilder.SetCheckInverted(BOPTest_Objects::CheckInverted());
197 aBuilder.SetUseOBB(BOPTest_Objects::UseOBB());
198 aBuilder.SetToFillHistory(BRepTest_Objects::IsHistoryNeeded());
201 aBuilder.SimplifyResult(BOPTest_Objects::UnifyEdges(),
202 BOPTest_Objects::UnifyFaces(),
203 BOPTest_Objects::Angular());
205 // Store the history of operation into the session
206 if (BRepTest_Objects::IsHistoryNeeded())
207 BRepTest_Objects::SetHistory(aBuilder.History());
209 if (aBuilder.HasWarnings()) {
210 Standard_SStream aSStream;
211 aBuilder.DumpWarnings(aSStream);
215 iErr=aBuilder.HasErrors();
217 Standard_SStream aSStream;
218 aBuilder.DumpErrors(aSStream);
223 const TopoDS_Shape& aR=aBuilder.Shape();
225 di << " null shape\n";
229 DBRep::Set(a[1], aR);
233 //=======================================================================
234 //function : bapisplit
236 //=======================================================================
237 Standard_Integer bapisplit(Draw_Interpretor& di,
242 di << " use bapisplit r\n";
246 BRepAlgoAPI_Splitter aSplitter;
248 aSplitter.SetArguments(BOPTest_Objects::Shapes());
249 aSplitter.SetTools(BOPTest_Objects::Tools());
251 aSplitter.SetRunParallel(BOPTest_Objects::RunParallel());
252 aSplitter.SetFuzzyValue(BOPTest_Objects::FuzzyValue());
253 aSplitter.SetNonDestructive(BOPTest_Objects::NonDestructive());
254 aSplitter.SetGlue(BOPTest_Objects::Glue());
255 aSplitter.SetCheckInverted(BOPTest_Objects::CheckInverted());
256 aSplitter.SetUseOBB(BOPTest_Objects::UseOBB());
257 aSplitter.SetToFillHistory(BRepTest_Objects::IsHistoryNeeded());
259 // performing operation
261 aSplitter.SimplifyResult(BOPTest_Objects::UnifyEdges(),
262 BOPTest_Objects::UnifyFaces(),
263 BOPTest_Objects::Angular());
265 // Store the history of operation into the session
266 if (BRepTest_Objects::IsHistoryNeeded())
267 BRepTest_Objects::SetHistory(aSplitter.History());
269 // check warning status
270 if (aSplitter.HasWarnings()) {
271 Standard_SStream aSStream;
272 aSplitter.DumpWarnings(aSStream);
275 // checking error status
276 Standard_Integer iErr = aSplitter.HasErrors();
278 Standard_SStream aSStream;
279 aSplitter.DumpErrors(aSStream);
284 // getting the result of the operation
285 const TopoDS_Shape& aR = aSplitter.Shape();
287 di << " null shape\n";
291 DBRep::Set(a[1], aR);