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