c0bea0d80a210ead569e30ab587ac4d1ab79f5d8
[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 #include <TopoDS_Iterator.hxx>
21
22 //=======================================================================
23 //function : 
24 //purpose  : 
25 //=======================================================================
26 BOPAlgo_Splitter::BOPAlgo_Splitter()
27 : BOPAlgo_ToolsProvider()
28 {
29 }
30 //=======================================================================
31 //function : 
32 //purpose  : 
33 //=======================================================================
34 BOPAlgo_Splitter::BOPAlgo_Splitter(const Handle(NCollection_BaseAllocator)& theAllocator)
35 : BOPAlgo_ToolsProvider(theAllocator)
36 {
37 }
38 //=======================================================================
39 //function : ~
40 //purpose  : 
41 //=======================================================================
42 BOPAlgo_Splitter::~BOPAlgo_Splitter()
43 {
44 }
45 //=======================================================================
46 // function: CheckData
47 // purpose: 
48 //=======================================================================
49 void BOPAlgo_Splitter::CheckData()
50 {
51   if (myArguments.IsEmpty() ||
52       (myArguments.Extent() + myTools.Extent()) < 2) {
53     // too few arguments to process
54     AddError (new BOPAlgo_AlertTooFewArguments);
55     return;
56   }
57   //
58   CheckFiller();
59 }
60
61 //=======================================================================
62 //function : Perform
63 //purpose  : 
64 //=======================================================================
65 void BOPAlgo_Splitter::Perform()
66 {
67   GetReport()->Clear();
68   //
69   if (myEntryPoint == 1) {
70     if (myPaveFiller) {
71       delete myPaveFiller;
72       myPaveFiller = NULL;
73     }
74   }
75   //
76   // prepare shapes for intersection
77   TopTools_ListOfShape aLS;
78   //
79   TopTools_ListIteratorOfListOfShape aItLS(myArguments);
80   for (; aItLS.More(); aItLS.Next()) {
81     aLS.Append(aItLS.Value());
82   }
83   //
84   aItLS.Initialize(myTools);
85   for (; aItLS.More(); aItLS.Next()) {
86     aLS.Append(aItLS.Value());
87   }
88   //
89   BOPAlgo_PaveFiller *pPF = new BOPAlgo_PaveFiller();
90   pPF->SetArguments(aLS);
91   pPF->SetRunParallel(myRunParallel);
92   pPF->SetProgressIndicator(myProgressIndicator);
93   pPF->SetFuzzyValue(myFuzzyValue);
94   pPF->SetNonDestructive(myNonDestructive);
95   pPF->SetGlue(myGlue);
96   pPF->SetUseOBB(myUseOBB);
97   //
98   pPF->Perform();
99   //
100   myEntryPoint = 1;
101   PerformInternal(*pPF);
102 }
103
104 //=======================================================================
105 //function : BuildResult
106 //purpose  : 
107 //=======================================================================
108 void BOPAlgo_Splitter::BuildResult(const TopAbs_ShapeEnum theType)
109 {
110   BOPAlgo_Builder::BuildResult(theType);
111
112   if (theType == TopAbs_COMPOUND)
113   {
114     // The method is called for the last time for this operation.
115     // If there is only one argument shape and it has been modified into
116     // a single shape, or has not been modified at all, the result shape
117     // has to be overwritten to avoid the unnecessary enclosure into compound.
118     if (myArguments.Extent() == 1)
119     {
120       TopoDS_Iterator it(myShape);
121       if (it.More())
122       {
123         const TopoDS_Shape& aSFirst = it.Value();
124         it.Next();
125         if (!it.More())
126           myShape = aSFirst;
127       }
128     }
129   }
130 }