b15a4a4e6107ffa2b6fc0c1cc455a11a40e52b47
[occt.git] / src / BOPTest / BOPTest_PartitionCommands.cxx
1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 //
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
8 //
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 //
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
18
19
20 #include <BOPTest.ixx>
21
22 #include <stdio.h>
23
24 #include <NCollection_IncAllocator.hxx>
25
26 #include <DBRep.hxx>
27 #include <Draw.hxx>
28 #include <Draw_Color.hxx>
29 #include <DrawTrSurf.hxx>
30
31 #include <TopoDS_Shape.hxx>
32 //
33 #include <BOPAlgo_Builder.hxx>
34 #include <BOPAlgo_PaveFiller.hxx>
35 #include <BOPAlgo_Operation.hxx>
36 #include <BOPAlgo_BOP.hxx>
37 //
38 #include <BOPTest_DrawableShape.hxx>
39 #include <BOPTest_Objects.hxx>
40
41 //
42 static Standard_Integer bfillds  (Draw_Interpretor&, Standard_Integer, const char**); 
43 static Standard_Integer bbuild   (Draw_Interpretor&, Standard_Integer, const char**);
44 static Standard_Integer bbop     (Draw_Interpretor&, Standard_Integer, const char**);
45 static Standard_Integer bclear   (Draw_Interpretor&, Standard_Integer, const char**);
46 //=======================================================================
47 //function : PartitionCommands
48 //purpose  : 
49 //=======================================================================
50   void BOPTest::PartitionCommands(Draw_Interpretor& theCommands)
51 {
52   static Standard_Boolean done = Standard_False;
53   if (done) return;
54   done = Standard_True;
55   // Chapter's name
56   const char* g = "Partition commands";
57   // Commands  
58   theCommands.Add("bfillds"  , "use bfillds"           , __FILE__, bfillds  , g);
59   theCommands.Add("bbuild"   , "use bbuild r"          , __FILE__, bbuild, g);
60   theCommands.Add("bbop"     , "use bbop r op"         , __FILE__, bbop, g);
61   theCommands.Add("bclear"   , "use bclear"            , __FILE__, bclear, g);
62 }
63
64 //=======================================================================
65 //function : bclear
66 //purpose  : 
67 //=======================================================================
68 Standard_Integer bclear(Draw_Interpretor& di, Standard_Integer n, const char** ) 
69 {
70   if (n!=1) {
71     di << " use bclear\n";
72     return 0;
73   }
74   //
75   BOPTest_Objects::Clear(); 
76   return 0;
77 }
78 //=======================================================================
79 //function : bfillds
80 //purpose  : 
81 //=======================================================================
82 Standard_Integer bfillds(Draw_Interpretor& di, Standard_Integer n, const char** ) 
83
84   if (n!=1) {
85     di << " Use bfillds\n";
86     return 0;
87   }
88   //
89   char buf[32];
90   Standard_Integer aNbS, aNbT, iErr;
91   BOPCol_ListIteratorOfListOfShape aIt;
92   BOPCol_ListOfShape aLC;
93   
94   BOPCol_ListOfShape& aLS=BOPTest_Objects::Shapes();
95   aNbS=aLS.Extent();
96   if (!aNbS) {
97     di << " no objects to process\n";
98     return 0;
99   }
100   //
101   BOPCol_ListOfShape& aLT=BOPTest_Objects::Tools();
102   aNbT=aLT.Extent();
103   //
104   aIt.Initialize(aLS);
105   for (; aIt.More(); aIt.Next()) {
106     const TopoDS_Shape& aS=aIt.Value();
107     aLC.Append(aS);
108   }
109   //
110   aIt.Initialize(aLT);
111   for (; aIt.More(); aIt.Next()) {
112     const TopoDS_Shape& aS=aIt.Value();
113      aLC.Append(aS);
114   }
115   //
116   BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
117   //
118   aPF.SetArguments(aLC);
119   //
120   aPF.Perform();
121   iErr=aPF.ErrorStatus();
122   if (iErr) {
123     Sprintf(buf, " error: %d\n",  iErr);
124     di << buf;
125     return 0;
126   }
127   //
128   return 0;
129 }
130
131 //=======================================================================
132 //function : bbuild
133 //purpose  : 
134 //=======================================================================
135 Standard_Integer bbuild(Draw_Interpretor& di, Standard_Integer n, const char** a) 
136
137   if (n!=2) {
138     di << " Use bbuild r\n";
139     return 0;
140   }
141   //
142   BOPDS_PDS pDS=BOPTest_Objects::PDS();
143   if (!pDS) {
144     di << " prepare PaveFiller first\n";
145     return 0;
146   }
147   //
148   char buf[32];
149   Standard_Integer iErr;
150   BOPCol_ListIteratorOfListOfShape aIt;
151   //
152   BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
153   //
154   BOPAlgo_Builder& aBuilder=BOPTest_Objects::Builder();
155   aBuilder.Clear();
156   //
157   BOPCol_ListOfShape& aLSObj=BOPTest_Objects::Shapes();
158   aIt.Initialize(aLSObj);
159   for (; aIt.More(); aIt.Next()) {
160     const TopoDS_Shape& aS=aIt.Value();
161     aBuilder.AddArgument(aS);
162   }
163   //
164   BOPCol_ListOfShape& aLSTool=BOPTest_Objects::Tools();
165   aIt.Initialize(aLSTool);
166   for (; aIt.More(); aIt.Next()) {
167     const TopoDS_Shape& aS=aIt.Value();
168     aBuilder.AddArgument(aS);
169   }
170   //
171   aBuilder.PerformWithFiller(aPF);
172   iErr=aBuilder.ErrorStatus();
173   if (iErr) {
174     Sprintf(buf, " error: %d\n",  iErr);
175     di << buf;
176     return 0;
177   }
178   //
179   const TopoDS_Shape& aR=aBuilder.Shape();
180   if (aR.IsNull()) {
181     di << " null shape\n";
182     return 0;
183   }
184   //
185   DBRep::Set(a[1], aR);
186   return 0;
187 }
188
189 //=======================================================================
190 //function : bbop
191 //purpose  : 
192 //=======================================================================
193 Standard_Integer bbop(Draw_Interpretor& di, Standard_Integer n, const char** a) 
194
195   if (n!=3) {
196     di << " use bbop r op\n";
197     return 0;
198   }
199   //
200   BOPDS_PDS pDS=BOPTest_Objects::PDS();
201   if (!pDS) {
202     di << " prepare PaveFiller first\n";
203     return 0;
204   }
205   //
206   char buf[32];
207   Standard_Integer iErr, iOp;
208   BOPAlgo_Operation aOp;
209   BOPCol_ListIteratorOfListOfShape aIt;
210   //
211   iOp=Draw::Atoi(a[2]);
212   if (iOp<0 || iOp>4) {
213     di << " invalid operation type\n";
214   }
215   aOp=(BOPAlgo_Operation)iOp;
216   //
217   BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
218   //
219   BOPAlgo_BOP& aBOP=BOPTest_Objects::BOP();
220   aBOP.Clear();
221   //
222   BOPCol_ListOfShape& aLSObj=BOPTest_Objects::Shapes();
223   aIt.Initialize(aLSObj);
224   for (; aIt.More(); aIt.Next()) {
225     const TopoDS_Shape& aS=aIt.Value();
226     aBOP.AddArgument(aS);
227   }
228   //
229   BOPCol_ListOfShape& aLSTools=BOPTest_Objects::Tools();
230   aIt.Initialize(aLSTools);
231   for (; aIt.More(); aIt.Next()) {
232     const TopoDS_Shape& aS=aIt.Value();
233     aBOP.AddTool(aS);
234   }
235   //
236   aBOP.SetOperation(aOp);
237   //
238   aBOP.PerformWithFiller(aPF);
239   iErr=aBOP.ErrorStatus();
240   if (iErr) {
241     Sprintf(buf, " error: %d\n",  iErr);
242     di << buf;
243     return 0;
244   }
245   //
246   const TopoDS_Shape& aR=aBOP.Shape();
247   if (aR.IsNull()) {
248     di << " null shape\n";
249     return 0;
250   }
251   //
252   DBRep::Set(a[1], aR);
253   return 0;
254 }
255