4e57c75e |
1 | // Created by: Peter KURNEV |
db8e4b9a |
2 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
4e57c75e |
3 | // |
4e57c75e |
4 | // |
d5f74e42 |
5 | // This file is part of Open CASCADE Technology software library. |
4e57c75e |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
4e57c75e |
15 | |
4e57c75e |
16 | |
42cf5bc1 |
17 | #include <BOPAlgo_WireEdgeSet.hxx> |
18 | #include <BOPAlgo_WireSplitter.hxx> |
33ba8565 |
19 | #include <BOPAlgo_Alerts.hxx> |
98b37659 |
20 | #include <BOPTools_AlgoTools.hxx> |
1155d05a |
21 | #include <BOPTools_Parallel.hxx> |
42cf5bc1 |
22 | #include <BRep_Builder.hxx> |
23 | #include <BRep_Tool.hxx> |
1155d05a |
24 | #include <NCollection_Vector.hxx> |
42cf5bc1 |
25 | #include <TopoDS.hxx> |
26 | #include <TopoDS_Edge.hxx> |
27 | #include <TopoDS_Face.hxx> |
42cf5bc1 |
28 | #include <TopoDS_Shape.hxx> |
29 | #include <TopoDS_Wire.hxx> |
1155d05a |
30 | #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx> |
31 | #include <TopTools_IndexedMapOfShape.hxx> |
32 | #include <TopTools_ListOfShape.hxx> |
33 | #include <TopTools_MapOfShape.hxx> |
4e57c75e |
34 | |
35 | //======================================================================= |
36 | //function : |
37 | //purpose : |
38 | //======================================================================= |
db8e4b9a |
39 | BOPAlgo_WireSplitter::BOPAlgo_WireSplitter() |
4e57c75e |
40 | : |
41 | BOPAlgo_Algo(), |
42 | myWES(NULL), |
43 | myLCB(myAllocator) |
44 | { |
45 | } |
46 | //======================================================================= |
47 | //function : |
48 | //purpose : |
49 | //======================================================================= |
db8e4b9a |
50 | BOPAlgo_WireSplitter::BOPAlgo_WireSplitter |
51 | (const Handle(NCollection_BaseAllocator)& theAllocator) |
4e57c75e |
52 | : |
53 | BOPAlgo_Algo(theAllocator), |
54 | myWES(NULL), |
55 | myLCB(myAllocator) |
56 | { |
57 | } |
58 | //======================================================================= |
59 | //function : ~ |
60 | //purpose : |
61 | //======================================================================= |
db8e4b9a |
62 | BOPAlgo_WireSplitter::~BOPAlgo_WireSplitter() |
4e57c75e |
63 | { |
64 | } |
65 | //======================================================================= |
66 | //function : SetWES |
67 | //purpose : |
68 | //======================================================================= |
db8e4b9a |
69 | void BOPAlgo_WireSplitter::SetWES(const BOPAlgo_WireEdgeSet& theWES) |
4e57c75e |
70 | { |
71 | myWES=(BOPAlgo_WireEdgeSet*)&theWES; |
72 | } |
73 | //======================================================================= |
74 | //function : WES |
75 | //purpose : |
76 | //======================================================================= |
db8e4b9a |
77 | BOPAlgo_WireEdgeSet& BOPAlgo_WireSplitter::WES() |
4e57c75e |
78 | { |
79 | return *myWES; |
80 | } |
81 | //======================================================================= |
51db0179 |
82 | //function : SetContext |
83 | //purpose : |
84 | //======================================================================= |
85 | void BOPAlgo_WireSplitter::SetContext(const Handle(IntTools_Context)& theContext) |
86 | { |
87 | myContext = theContext; |
88 | } |
89 | //======================================================================= |
90 | //function : Context |
91 | //purpose : |
92 | //======================================================================= |
93 | const Handle(IntTools_Context)& BOPAlgo_WireSplitter::Context() |
94 | { |
95 | return myContext; |
96 | } |
97 | //======================================================================= |
4e57c75e |
98 | // function: CheckData |
99 | // purpose: |
100 | //======================================================================= |
db8e4b9a |
101 | void BOPAlgo_WireSplitter::CheckData() |
4e57c75e |
102 | { |
4e57c75e |
103 | if (!myWES) { |
33ba8565 |
104 | AddError (new BOPAlgo_AlertNullInputShapes); |
4e57c75e |
105 | return; |
106 | } |
107 | } |
108 | //======================================================================= |
109 | //function : Perform |
110 | //purpose : |
111 | //======================================================================= |
db8e4b9a |
112 | void BOPAlgo_WireSplitter::Perform() |
4e57c75e |
113 | { |
33ba8565 |
114 | GetReport()->Clear(); |
4e57c75e |
115 | // |
116 | CheckData(); |
33ba8565 |
117 | if (HasErrors()) { |
4e57c75e |
118 | return; |
119 | } |
120 | // |
51db0179 |
121 | // create a context |
122 | if (myContext.IsNull()) { |
123 | myContext = new IntTools_Context; |
124 | } |
125 | // |
98b37659 |
126 | BOPTools_AlgoTools::MakeConnexityBlocks |
127 | (myWES->StartElements(), TopAbs_VERTEX, TopAbs_EDGE, myLCB); |
128 | |
4e57c75e |
129 | MakeWires(); |
130 | } |
db8e4b9a |
131 | |
db8e4b9a |
132 | ///////////////////////////////////////////////////////////////////////// |
51db0179 |
133 | class BOPAlgo_WS_ConnexityBlock { |
134 | public: |
135 | BOPAlgo_WS_ConnexityBlock() {}; |
136 | ~BOPAlgo_WS_ConnexityBlock() {}; |
db8e4b9a |
137 | |
51db0179 |
138 | void SetFace(const TopoDS_Face& theF) { |
139 | myFace = theF; |
140 | } |
db8e4b9a |
141 | |
51db0179 |
142 | const TopoDS_Face& Face() const { |
143 | return myFace; |
144 | } |
c7b59798 |
145 | |
51db0179 |
146 | void SetConnexityBlock(const BOPTools_ConnexityBlock& theCB) { |
147 | myCB = theCB; |
148 | } |
149 | |
150 | const BOPTools_ConnexityBlock& ConnexityBlock() const { |
151 | return myCB; |
152 | } |
153 | |
154 | void SetContext(const Handle(IntTools_Context)& aContext) { |
155 | myContext = aContext; |
db8e4b9a |
156 | } |
157 | // |
51db0179 |
158 | const Handle(IntTools_Context)& Context()const { |
159 | return myContext; |
db8e4b9a |
160 | } |
51db0179 |
161 | |
162 | void Perform() { |
163 | BOPAlgo_WireSplitter::SplitBlock(myFace, myCB, myContext); |
db8e4b9a |
164 | } |
51db0179 |
165 | |
166 | protected: |
167 | TopoDS_Face myFace; |
168 | BOPTools_ConnexityBlock myCB; |
169 | Handle(IntTools_Context) myContext; |
db8e4b9a |
170 | }; |
51db0179 |
171 | |
fc867b96 |
172 | typedef NCollection_Vector<BOPAlgo_WS_ConnexityBlock> BOPAlgo_VectorOfConnexityBlock; |
51db0179 |
173 | |
db8e4b9a |
174 | //======================================================================= |
175 | //function : MakeWires |
176 | //purpose : |
177 | //======================================================================= |
178 | void BOPAlgo_WireSplitter::MakeWires() |
179 | { |
180 | Standard_Boolean bIsRegular; |
181 | Standard_Integer aNbVCB, k; |
182 | TopoDS_Wire aW; |
183 | BOPTools_ListIteratorOfListOfConnexityBlock aItCB; |
1155d05a |
184 | TopTools_ListIteratorOfListOfShape aIt; |
51db0179 |
185 | BOPAlgo_VectorOfConnexityBlock aVCB; |
186 | // |
187 | const TopoDS_Face& aF=myWES->Face(); |
db8e4b9a |
188 | // |
189 | aItCB.Initialize(myLCB); |
190 | for (; aItCB.More(); aItCB.Next()) { |
191 | BOPTools_ConnexityBlock& aCB=aItCB.ChangeValue(); |
192 | bIsRegular=aCB.IsRegular(); |
193 | if (bIsRegular) { |
1155d05a |
194 | TopTools_ListOfShape& aLE=aCB.ChangeShapes(); |
db8e4b9a |
195 | BOPAlgo_WireSplitter::MakeWire(aLE, aW); |
196 | myWES->AddShape(aW); |
197 | } |
198 | else { |
1155d05a |
199 | BOPAlgo_WS_ConnexityBlock& aWSCB = aVCB.Appended(); |
51db0179 |
200 | aWSCB.SetFace(aF); |
201 | aWSCB.SetConnexityBlock(aCB); |
db8e4b9a |
202 | } |
203 | } |
db8e4b9a |
204 | //=================================================== |
fc867b96 |
205 | BOPTools_Parallel::Perform (myRunParallel, aVCB, myContext); |
db8e4b9a |
206 | //=================================================== |
1155d05a |
207 | aNbVCB=aVCB.Length(); |
db8e4b9a |
208 | for (k=0; k<aNbVCB; ++k) { |
51db0179 |
209 | const BOPAlgo_WS_ConnexityBlock& aCB=aVCB(k); |
1155d05a |
210 | const TopTools_ListOfShape& aLW=aCB.ConnexityBlock().Loops(); |
db8e4b9a |
211 | aIt.Initialize(aLW); |
212 | for (; aIt.More(); aIt.Next()) { |
213 | const TopoDS_Shape& aWx=aIt.Value(); |
214 | myWES->AddShape(aWx); |
215 | } |
216 | } |
217 | } |