0028786: Refactoring of the Warning/Error reporting system of Boolean Operations...
[occt.git] / src / BOPAlgo / BOPAlgo_Splitter.cxx
1 // Created by: Eugeny MALTCHIKOV
2 // Copyright (c) 2017 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
15
16 #include <BOPAlgo_Splitter.hxx>
17 #include <BOPAlgo_PaveFiller.hxx>
18 #include <BOPAlgo_Alerts.hxx>
19
20 //=======================================================================
21 //function : 
22 //purpose  : 
23 //=======================================================================
24 BOPAlgo_Splitter::BOPAlgo_Splitter()
25 :
26   BOPAlgo_Builder(),
27   myTools(myAllocator),
28   myMapTools(100, myAllocator)
29 {
30 }
31 //=======================================================================
32 //function : 
33 //purpose  : 
34 //=======================================================================
35 BOPAlgo_Splitter::BOPAlgo_Splitter
36   (const Handle(NCollection_BaseAllocator)& theAllocator)
37 :
38   BOPAlgo_Builder(theAllocator),
39   myTools(myAllocator),
40   myMapTools(100, myAllocator)
41 {
42 }
43 //=======================================================================
44 //function : ~
45 //purpose  : 
46 //=======================================================================
47 BOPAlgo_Splitter::~BOPAlgo_Splitter()
48 {
49 }
50 //=======================================================================
51 //function : Clear
52 //purpose  : 
53 //=======================================================================
54 void BOPAlgo_Splitter::Clear()
55 {
56   BOPAlgo_Builder::Clear();
57   myTools.Clear();
58   myMapTools.Clear();
59 }
60 //=======================================================================
61 //function : AddTool
62 //purpose  : 
63 //=======================================================================
64 void BOPAlgo_Splitter::AddTool(const TopoDS_Shape& theShape)
65 {
66   if (myMapTools.Add(theShape)) {
67     myTools.Append(theShape);
68   }
69 }
70 //=======================================================================
71 //function : SetTools
72 //purpose  : 
73 //=======================================================================
74 void BOPAlgo_Splitter::SetTools(const BOPCol_ListOfShape& theShapes)
75 {
76   myTools.Clear();
77   BOPCol_ListIteratorOfListOfShape aIt(theShapes);
78   for (; aIt.More(); aIt.Next()) {
79     AddTool(aIt.Value());
80   }
81 }
82
83 //=======================================================================
84 // function: CheckData
85 // purpose: 
86 //=======================================================================
87 void BOPAlgo_Splitter::CheckData()
88 {
89   if (myArguments.IsEmpty() ||
90       (myArguments.Extent() + myTools.Extent()) < 2) {
91     // too few arguments to process
92     AddError (new BOPAlgo_AlertTooFewArguments);
93     return;
94   }
95   //
96   CheckFiller();
97 }
98
99 //=======================================================================
100 //function : Perform
101 //purpose  : 
102 //=======================================================================
103 void BOPAlgo_Splitter::Perform()
104 {
105   GetReport()->Clear();
106   //
107   if (myEntryPoint == 1) {
108     if (myPaveFiller) {
109       delete myPaveFiller;
110       myPaveFiller = NULL;
111     }
112   }
113   //
114   // prepare shapes for intersection
115   BOPCol_ListOfShape aLS;
116   //
117   BOPCol_ListIteratorOfListOfShape aItLS(myArguments);
118   for (; aItLS.More(); aItLS.Next()) {
119     aLS.Append(aItLS.Value());
120   }
121   //
122   aItLS.Initialize(myTools);
123   for (; aItLS.More(); aItLS.Next()) {
124     aLS.Append(aItLS.Value());
125   }
126   //
127   BOPAlgo_PaveFiller *pPF = new BOPAlgo_PaveFiller();
128   pPF->SetArguments(aLS);
129   pPF->SetRunParallel(myRunParallel);
130   pPF->SetProgressIndicator(myProgressIndicator);
131   pPF->SetFuzzyValue(myFuzzyValue);
132   pPF->SetNonDestructive(myNonDestructive);
133   pPF->SetGlue(myGlue);
134   //
135   pPF->Perform();
136   //
137   myEntryPoint = 1;
138   PerformInternal(*pPF);
139 }