0024002: Overall code and build procedure refactoring -- automatic
[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>
49b0c452 17#include <BOPCol_ListOfShape.hxx>
42cf5bc1 18#include <BOPTest.hxx>
49b0c452 19#include <BOPTest_Objects.hxx>
49b0c452 20#include <BRepAlgoAPI_BooleanOperation.hxx>
21#include <BRepAlgoAPI_BuilderAlgo.hxx>
22#include <BRepAlgoAPI_Common.hxx>
49b0c452 23#include <BRepAlgoAPI_Cut.hxx>
42cf5bc1 24#include <BRepAlgoAPI_Fuse.hxx>
49b0c452 25#include <BRepAlgoAPI_Section.hxx>
42cf5bc1 26#include <DBRep.hxx>
27#include <Draw.hxx>
28#include <TopoDS_Shape.hxx>
29#include <TopTools_ListOfShape.hxx>
49b0c452 30
42cf5bc1 31#include <stdio.h>
32#include <string.h>
49b0c452 33static
34 void ConvertList(const BOPCol_ListOfShape& aLSB,
35 TopTools_ListOfShape& aLS);
36
37static Standard_Integer bapibuild(Draw_Interpretor&, Standard_Integer, const char**);
38static Standard_Integer bapibop (Draw_Interpretor&, Standard_Integer, const char**);
39
40//=======================================================================
41//function : APICommands
42//purpose :
43//=======================================================================
44void BOPTest::APICommands(Draw_Interpretor& theCommands)
45{
46 static Standard_Boolean done = Standard_False;
47 if (done) return;
48 done = Standard_True;
49 // Chapter's name
43cb0011 50 const char* g = "BOPTest commands";
49b0c452 51 // Commands
52 theCommands.Add("bapibuild", "use bapibuild r" , __FILE__, bapibuild, g);
53 theCommands.Add("bapibop", "use bapibop r type" , __FILE__, bapibop, g);
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 //
68 char buf[128];
69 Standard_Boolean bRunParallel;
70 Standard_Integer iErr, iOp;
71 Standard_Real aFuzzyValue;
72 BRepAlgoAPI_Common aCommon;
73 BRepAlgoAPI_Fuse aFuse;
74 BRepAlgoAPI_Cut aCut;
75 BRepAlgoAPI_Section aSection;
76 BRepAlgoAPI_BooleanOperation *pBuilder;
77 BOPAlgo_Operation aOp;
78 //
79 pBuilder=NULL;
80 iOp=atoi(a[2]);
81 if (iOp<0 || iOp>4) {
82 printf(" invalid operation type\n");
83 return 0;
84 }
85 aOp=(BOPAlgo_Operation)iOp;
86 //
87 switch (aOp) {
88 case BOPAlgo_COMMON:
89 pBuilder=&aCommon;
90 break;
91 //
92 case BOPAlgo_FUSE:
93 pBuilder=&aFuse;
94 break;
95 //
96 case BOPAlgo_CUT:
97 case BOPAlgo_CUT21:
98 pBuilder=&aCut;
99 break;
100 //
101 case BOPAlgo_SECTION:
102 pBuilder=&aSection;
103 break;
104 //
105 default:
106 break;
107 }
108 //
109 BOPCol_ListOfShape& aLSB=BOPTest_Objects::Shapes();
110 BOPCol_ListOfShape& aLTB=BOPTest_Objects::Tools();
111 //
112 TopTools_ListOfShape aLS, aLT;
113 ConvertList(aLSB, aLS);
114 ConvertList(aLTB, aLT);
115 //
116 bRunParallel=BOPTest_Objects::RunParallel();
117 aFuzzyValue=BOPTest_Objects::FuzzyValue();
118 //
119 if (aOp!=BOPAlgo_CUT21) {
120 pBuilder->SetArguments(aLS);
121 pBuilder->SetTools(aLT);
122 }
123 else {
124 pBuilder->SetArguments(aLT);
125 pBuilder->SetTools(aLS);
126 }
127 //
128 pBuilder->SetRunParallel(bRunParallel);
129 pBuilder->SetFuzzyValue(aFuzzyValue);
130 //
131 pBuilder->Build();
132 iErr=pBuilder->ErrorStatus();
133 if (iErr) {
134 Sprintf(buf, " error: %d\n", iErr);
135 di << buf;
136 return 0;
137 }
138 //
139 const TopoDS_Shape& aR=pBuilder->Shape();
140 if (aR.IsNull()) {
141 di << " null shape\n";
142 return 0;
143 }
144 //
145 DBRep::Set(a[1], aR);
146 return 0;
147}
148//=======================================================================
149//function : bapibuild
150//purpose :
151//=======================================================================
152Standard_Integer bapibuild(Draw_Interpretor& di,
153 Standard_Integer n,
154 const char** a)
155{
156 if (n<2) {
157 di << " use bapibuild r\n";
158 return 0;
159 }
160 //
161 char buf[128];
162 Standard_Boolean bRunParallel;
163 Standard_Integer iErr;
164 Standard_Real aFuzzyValue;
165 BRepAlgoAPI_BuilderAlgo aBuilder;
166 //
167 BOPCol_ListOfShape& aLSB=BOPTest_Objects::Shapes();
43cb0011 168 BOPCol_ListOfShape& aLTB=BOPTest_Objects::Tools();
49b0c452 169 //
43cb0011 170 TopTools_ListOfShape aLS;
49b0c452 171 ConvertList(aLSB, aLS);
43cb0011 172 ConvertList(aLTB, aLS);
49b0c452 173 //
174 bRunParallel=BOPTest_Objects::RunParallel();
175 aFuzzyValue=BOPTest_Objects::FuzzyValue();
176 //
177 aBuilder.SetArguments(aLS);
178 aBuilder.SetRunParallel(bRunParallel);
179 aBuilder.SetFuzzyValue(aFuzzyValue);
180 //
181 aBuilder.Build();
182 iErr=aBuilder.ErrorStatus();
183 if (iErr) {
184 Sprintf(buf, " error: %d\n", iErr);
185 di << buf;
186 return 0;
187 }
188 //
189 const TopoDS_Shape& aR=aBuilder.Shape();
190 if (aR.IsNull()) {
191 di << " null shape\n";
192 return 0;
193 }
194 //
195 DBRep::Set(a[1], aR);
196 return 0;
197}
198//=======================================================================
199//function : ConvertLists
200//purpose :
201//=======================================================================
202void ConvertList(const BOPCol_ListOfShape& aLSB,
203 TopTools_ListOfShape& aLS)
204{
205 BOPCol_ListIteratorOfListOfShape aItB;
206 //
49b0c452 207 aItB.Initialize(aLSB);
208 for (; aItB.More(); aItB.Next()) {
209 const TopoDS_Shape& aS=aItB.Value();
210 aLS.Append(aS);
211 }
212}
213