0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / BOPTest / BOPTest_APICommands.cxx
CommitLineData
49b0c452 1// Created by: Peter KURNEV
2// Copyright (c) 2014 OPEN CASCADE SAS
3//
4// This file is part of Open CASCADE Technology software library.
5//
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.
11//
12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
14
49b0c452 15
42cf5bc1 16#include <BOPAlgo_PaveFiller.hxx>
42cf5bc1 17#include <BOPTest.hxx>
49b0c452 18#include <BOPTest_Objects.hxx>
49b0c452 19#include <BRepAlgoAPI_BooleanOperation.hxx>
20#include <BRepAlgoAPI_BuilderAlgo.hxx>
21#include <BRepAlgoAPI_Common.hxx>
49b0c452 22#include <BRepAlgoAPI_Cut.hxx>
42cf5bc1 23#include <BRepAlgoAPI_Fuse.hxx>
49b0c452 24#include <BRepAlgoAPI_Section.hxx>
c58055ad 25#include <BRepAlgoAPI_Splitter.hxx>
4f7d41ea 26#include <BRepTest_Objects.hxx>
42cf5bc1 27#include <DBRep.hxx>
28#include <Draw.hxx>
29#include <TopoDS_Shape.hxx>
30#include <TopTools_ListOfShape.hxx>
49b0c452 31
42cf5bc1 32#include <stdio.h>
33#include <string.h>
49b0c452 34
c58055ad 35static Standard_Integer bapibuild(Draw_Interpretor&, Standard_Integer, const char**);
36static Standard_Integer bapibop (Draw_Interpretor&, Standard_Integer, const char**);
37static Standard_Integer bapisplit(Draw_Interpretor&, Standard_Integer, const char**);
49b0c452 38
39//=======================================================================
40//function : APICommands
41//purpose :
42//=======================================================================
43void BOPTest::APICommands(Draw_Interpretor& theCommands)
44{
45 static Standard_Boolean done = Standard_False;
46 if (done) return;
47 done = Standard_True;
48 // Chapter's name
43cb0011 49 const char* g = "BOPTest commands";
49b0c452 50 // Commands
51 theCommands.Add("bapibuild", "use bapibuild r" , __FILE__, bapibuild, g);
52 theCommands.Add("bapibop", "use bapibop r type" , __FILE__, bapibop, g);
c58055ad 53 theCommands.Add("bapisplit", "use bapisplit r" , __FILE__, bapisplit, g);
49b0c452 54}
55//=======================================================================
56//function : bapibop
57//purpose :
58//=======================================================================
59Standard_Integer bapibop(Draw_Interpretor& di,
60 Standard_Integer n,
61 const char** a)
62{
63 if (n<3) {
64 di << " use bapibop r type\n";
65 return 0;
66 }
67 //
3510db62 68 Standard_Boolean bRunParallel, bNonDestructive;
33ba8565 69 Standard_Integer iOp;
49b0c452 70 Standard_Real aFuzzyValue;
71 BRepAlgoAPI_Common aCommon;
72 BRepAlgoAPI_Fuse aFuse;
73 BRepAlgoAPI_Cut aCut;
74 BRepAlgoAPI_Section aSection;
75 BRepAlgoAPI_BooleanOperation *pBuilder;
76 BOPAlgo_Operation aOp;
77 //
78 pBuilder=NULL;
79 iOp=atoi(a[2]);
80 if (iOp<0 || iOp>4) {
33ba8565 81 di << "invalid operation type\n";
49b0c452 82 return 0;
83 }
84 aOp=(BOPAlgo_Operation)iOp;
85 //
86 switch (aOp) {
87 case BOPAlgo_COMMON:
88 pBuilder=&aCommon;
89 break;
90 //
91 case BOPAlgo_FUSE:
92 pBuilder=&aFuse;
93 break;
94 //
95 case BOPAlgo_CUT:
96 case BOPAlgo_CUT21:
97 pBuilder=&aCut;
98 break;
99 //
100 case BOPAlgo_SECTION:
101 pBuilder=&aSection;
102 break;
103 //
104 default:
105 break;
106 }
107 //
1155d05a 108 TopTools_ListOfShape& aLS=BOPTest_Objects::Shapes();
109 TopTools_ListOfShape& aLT=BOPTest_Objects::Tools();
49b0c452 110 //
111 bRunParallel=BOPTest_Objects::RunParallel();
112 aFuzzyValue=BOPTest_Objects::FuzzyValue();
3510db62 113 bNonDestructive = BOPTest_Objects::NonDestructive();
483ce1bd 114 BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue();
49b0c452 115 //
116 if (aOp!=BOPAlgo_CUT21) {
117 pBuilder->SetArguments(aLS);
118 pBuilder->SetTools(aLT);
119 }
120 else {
121 pBuilder->SetArguments(aLT);
122 pBuilder->SetTools(aLS);
123 }
124 //
125 pBuilder->SetRunParallel(bRunParallel);
126 pBuilder->SetFuzzyValue(aFuzzyValue);
3510db62 127 pBuilder->SetNonDestructive(bNonDestructive);
483ce1bd 128 pBuilder->SetGlue(aGlue);
98b37659 129 pBuilder->SetCheckInverted(BOPTest_Objects::CheckInverted());
944768d2 130 pBuilder->SetUseOBB(BOPTest_Objects::UseOBB());
948fe6ca 131 pBuilder->SetToFillHistory(BRepTest_Objects::IsHistoryNeeded());
49b0c452 132 //
948fe6ca 133 pBuilder->Build();
134 pBuilder->SimplifyResult(BOPTest_Objects::UnifyEdges(),
135 BOPTest_Objects::UnifyFaces(),
136 BOPTest_Objects::Angular());
4f7d41ea 137
948fe6ca 138 // Store the history of operation into the session
139 if (BRepTest_Objects::IsHistoryNeeded())
140 BRepTest_Objects::SetHistory(pBuilder->History());
4f7d41ea 141
33ba8565 142 if (pBuilder->HasWarnings()) {
143 Standard_SStream aSStream;
144 pBuilder->DumpWarnings(aSStream);
145 di << aSStream;
146 }
147 //
148 if (pBuilder->HasErrors()) {
149 Standard_SStream aSStream;
150 pBuilder->DumpErrors(aSStream);
151 di << aSStream;
49b0c452 152 return 0;
153 }
154 //
155 const TopoDS_Shape& aR=pBuilder->Shape();
156 if (aR.IsNull()) {
157 di << " null shape\n";
158 return 0;
159 }
160 //
161 DBRep::Set(a[1], aR);
162 return 0;
163}
164//=======================================================================
165//function : bapibuild
166//purpose :
167//=======================================================================
168Standard_Integer bapibuild(Draw_Interpretor& di,
169 Standard_Integer n,
170 const char** a)
171{
172 if (n<2) {
173 di << " use bapibuild r\n";
174 return 0;
175 }
176 //
3510db62 177 Standard_Boolean bRunParallel, bNonDestructive;
49b0c452 178 Standard_Integer iErr;
179 Standard_Real aFuzzyValue;
180 BRepAlgoAPI_BuilderAlgo aBuilder;
181 //
1155d05a 182 TopTools_ListOfShape aLS = BOPTest_Objects::Shapes();
183 TopTools_ListOfShape aLT = BOPTest_Objects::Tools();
49b0c452 184 //
1155d05a 185 aLS.Append(aLT);
49b0c452 186 bRunParallel=BOPTest_Objects::RunParallel();
187 aFuzzyValue=BOPTest_Objects::FuzzyValue();
3510db62 188 bNonDestructive = BOPTest_Objects::NonDestructive();
483ce1bd 189 BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue();
49b0c452 190 //
191 aBuilder.SetArguments(aLS);
192 aBuilder.SetRunParallel(bRunParallel);
193 aBuilder.SetFuzzyValue(aFuzzyValue);
3510db62 194 aBuilder.SetNonDestructive(bNonDestructive);
483ce1bd 195 aBuilder.SetGlue(aGlue);
98b37659 196 aBuilder.SetCheckInverted(BOPTest_Objects::CheckInverted());
944768d2 197 aBuilder.SetUseOBB(BOPTest_Objects::UseOBB());
948fe6ca 198 aBuilder.SetToFillHistory(BRepTest_Objects::IsHistoryNeeded());
49b0c452 199 //
948fe6ca 200 aBuilder.Build();
201 aBuilder.SimplifyResult(BOPTest_Objects::UnifyEdges(),
202 BOPTest_Objects::UnifyFaces(),
203 BOPTest_Objects::Angular());
4f7d41ea 204
948fe6ca 205 // Store the history of operation into the session
206 if (BRepTest_Objects::IsHistoryNeeded())
207 BRepTest_Objects::SetHistory(aBuilder.History());
4f7d41ea 208
33ba8565 209 if (aBuilder.HasWarnings()) {
210 Standard_SStream aSStream;
211 aBuilder.DumpWarnings(aSStream);
212 di << aSStream;
213 }
214 //
215 iErr=aBuilder.HasErrors();
49b0c452 216 if (iErr) {
33ba8565 217 Standard_SStream aSStream;
218 aBuilder.DumpErrors(aSStream);
219 di << aSStream;
49b0c452 220 return 0;
221 }
222 //
223 const TopoDS_Shape& aR=aBuilder.Shape();
224 if (aR.IsNull()) {
225 di << " null shape\n";
226 return 0;
227 }
228 //
229 DBRep::Set(a[1], aR);
230 return 0;
231}
c58055ad 232
233//=======================================================================
234//function : bapisplit
235//purpose :
236//=======================================================================
237Standard_Integer bapisplit(Draw_Interpretor& di,
238 Standard_Integer n,
239 const char** a)
240{
241 if (n < 2) {
242 di << " use bapisplit r\n";
243 return 1;
244 }
245 //
246 BRepAlgoAPI_Splitter aSplitter;
247 // setting arguments
248 aSplitter.SetArguments(BOPTest_Objects::Shapes());
249 aSplitter.SetTools(BOPTest_Objects::Tools());
250 // setting options
251 aSplitter.SetRunParallel(BOPTest_Objects::RunParallel());
252 aSplitter.SetFuzzyValue(BOPTest_Objects::FuzzyValue());
253 aSplitter.SetNonDestructive(BOPTest_Objects::NonDestructive());
254 aSplitter.SetGlue(BOPTest_Objects::Glue());
98b37659 255 aSplitter.SetCheckInverted(BOPTest_Objects::CheckInverted());
944768d2 256 aSplitter.SetUseOBB(BOPTest_Objects::UseOBB());
948fe6ca 257 aSplitter.SetToFillHistory(BRepTest_Objects::IsHistoryNeeded());
c58055ad 258 //
259 // performing operation
260 aSplitter.Build();
948fe6ca 261 aSplitter.SimplifyResult(BOPTest_Objects::UnifyEdges(),
262 BOPTest_Objects::UnifyFaces(),
263 BOPTest_Objects::Angular());
4f7d41ea 264
948fe6ca 265 // Store the history of operation into the session
266 if (BRepTest_Objects::IsHistoryNeeded())
267 BRepTest_Objects::SetHistory(aSplitter.History());
4f7d41ea 268
33ba8565 269 // check warning status
270 if (aSplitter.HasWarnings()) {
271 Standard_SStream aSStream;
272 aSplitter.DumpWarnings(aSStream);
273 di << aSStream;
274 }
c58055ad 275 // checking error status
33ba8565 276 Standard_Integer iErr = aSplitter.HasErrors();
c58055ad 277 if (iErr) {
33ba8565 278 Standard_SStream aSStream;
279 aSplitter.DumpErrors(aSStream);
280 di << aSStream;
c58055ad 281 return 0;
282 }
283 //
284 // getting the result of the operation
285 const TopoDS_Shape& aR = aSplitter.Shape();
286 if (aR.IsNull()) {
287 di << " null shape\n";
288 return 0;
289 }
290 //
291 DBRep::Set(a[1], aR);
292 return 0;
293}