0023024: Update headers of OCCT files
[occt.git] / src / BOP / BOP_WireSolid.cxx
CommitLineData
b311480e 1// Created on: 2002-02-04
2// Created by: Peter KURNEV
3// Copyright (c) 2002-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
7fd59977 20
21
22#include <BOP_WireSolid.ixx>
23
24#include <Standard_Failure.hxx>
25#include <Standard_ErrorHandler.hxx>
26
27#include <TopoDS.hxx>
28#include <TopoDS_Edge.hxx>
29
30#include <BooleanOperations_ShapesDataStructure.hxx>
31#include <BooleanOperations_StateOfShape.hxx>
32
33#include <BOPTColStd_Dump.hxx>
34
35#include <BOPTools_SplitShapesPool.hxx>
36#include <BOPTools_ListOfPaveBlock.hxx>
37#include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
38#include <BOPTools_PaveBlock.hxx>
39#include <BOPTools_DSFiller.hxx>
40#include <BOPTools_PaveFiller.hxx>
41#include <BOPTools_WireStateFiller.hxx>
42
43
44#include <BOP_CorrectTolerances.hxx>
45#include <BOP_BuilderTools.hxx>
46#include <BOP_WireSolidHistoryCollector.hxx>
47
48//=======================================================================
49// function: BOP_WireSolid::BOP_WireSolid
50// purpose:
51//=======================================================================
b311480e 52BOP_WireSolid::BOP_WireSolid()
7fd59977 53{
54}
55//=======================================================================
56// function: Destroy
57// purpose:
58//=======================================================================
59 void BOP_WireSolid::Destroy()
60{
61}
62//=======================================================================
63// function: Do
64// purpose:
65//=======================================================================
66 void BOP_WireSolid::Do()
67{
68 myErrorStatus=0;
69 myIsDone=Standard_False;
70 //
71 // Filling the DS
72 BOPTools_DSFiller aDSFiller;
73 aDSFiller.SetShapes (myShape1, myShape2);
74 //
75 aDSFiller.Perform ();
76 //
77 DoWithFiller(aDSFiller);
78}
79
80//=======================================================================
81// function: DoWithFiller
82// purpose:
83//=======================================================================
84 void BOP_WireSolid::DoWithFiller(const BOPTools_DSFiller& aDSFiller)
85{
86 myErrorStatus=0;
87 myIsDone=Standard_False;
88 myResultMap.Clear();
89 myModifiedMap.Clear();
90 myDSFiller=(BOPTools_DSFiller*) &aDSFiller;
91 //
92 try {
93 OCC_CATCH_SIGNALS
94
95 if(!myDSFiller->IsDone()) {
96 myErrorStatus = 1;
97 BOPTColStd_Dump::PrintMessage("DSFiller is invalid: Can not build result\n");
98 return;
99 }
100
101 Standard_Boolean bCheckTypes;
102 //
103 bCheckTypes=CheckArgTypes();
104 if (!bCheckTypes) {
105 myErrorStatus=10;
106 return;
107 }
108 //
109 Standard_Boolean bIsNewFiller;
110 bIsNewFiller=aDSFiller.IsNewFiller();
111
112 if (bIsNewFiller) {
113 //
114 // Preparing the States
115 const BOPTools_PaveFiller& aPaveFiller=myDSFiller->PaveFiller();
116 BOPTools_WireStateFiller aStateFiller(aPaveFiller);
117 aStateFiller.Do();
118
119 aDSFiller.SetNewFiller(!bIsNewFiller);
120 }
121 //
122 BuildResult();
123 //
124 BOP_CorrectTolerances::CorrectTolerances(myResult, 0.01);
125 //
126 FillModified();
127
128 if(!myHistory.IsNull()) {
129 Handle(BOP_WireSolidHistoryCollector) aHistory =
130 Handle(BOP_WireSolidHistoryCollector)::DownCast(myHistory);
131 aHistory->SetResult(myResult, myDSFiller);
132 }
133 myIsDone=Standard_True;
134 }
135 catch ( Standard_Failure ) {
136 myErrorStatus = 1;
137 BOPTColStd_Dump::PrintMessage("Can not build result\n");
138 }
139}
140
141//=======================================================================
142// function: BuildResult
143// purpose:
144//=======================================================================
145 void BOP_WireSolid::BuildResult()
146{
147
148 AddSplitParts();
149 //
150 MakeResult();
151}
152
153//=======================================================================
154// function: CheckArgTypes
155// purpose:
156//=======================================================================
157Standard_Boolean BOP_WireSolid::CheckArgTypes(const TopAbs_ShapeEnum theType1,
158 const TopAbs_ShapeEnum theType2,
159 const BOP_Operation theOperation)
160{
161 Standard_Boolean bFlag=Standard_False;
162
163 if (theType1==TopAbs_WIRE && theType2==TopAbs_SOLID) {
164 if (theOperation==BOP_FUSE || theOperation==BOP_CUT21) {
165 return bFlag;
166 }
167 }
168 //
169 if (theType1==TopAbs_SOLID && theType2==TopAbs_WIRE) {
170 if (theOperation==BOP_FUSE || theOperation==BOP_CUT) {
171 return bFlag;
172 }
173 }
174 //
175 return !bFlag;
176}
177
178//=======================================================================
179// function: CheckArgTypes
180// purpose:
181//=======================================================================
182 Standard_Boolean BOP_WireSolid::CheckArgTypes() const
183{
184// Standard_Boolean bFlag=Standard_False;
185
186 TopAbs_ShapeEnum aT1, aT2;
187 const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
188
189 aT1=aDS.Object().ShapeType();
190 aT2=aDS.Tool().ShapeType();
191 //
192// if (aT1==TopAbs_WIRE && aT2==TopAbs_SOLID) {
193// if (myOperation==BOP_FUSE || myOperation==BOP_CUT21) {
194// return bFlag;
195// }
196// }
197// //
198// if (aT1==TopAbs_SOLID && aT2==TopAbs_WIRE) {
199// if (myOperation==BOP_FUSE || myOperation==BOP_CUT) {
200// return bFlag;
201// }
202// }
203// //
204// return !bFlag;
205 return CheckArgTypes(aT1, aT2, myOperation);
206}
207
208//=======================================================================
209// function: AddSplitParts
210// purpose:
211//=======================================================================
212 void BOP_WireSolid::AddSplitParts()
213{
214
215 const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
216 const BOPTools_PaveFiller& aPaveFiller=myDSFiller->PaveFiller();
217 const BOPTools_SplitShapesPool& aSplitShapesPool=aPaveFiller.SplitShapesPool();
218 //
219 Standard_Integer i, aNbPB, iRank, nSp, iBeg, iEnd;
220 TopAbs_ShapeEnum aType;
221 BooleanOperations_StateOfShape aState, aStateCmp;
222
223 iBeg=1;
224 iEnd=aDS.NumberOfShapesOfTheObject();
225 if (aDS.Tool().ShapeType()==TopAbs_WIRE) {
226 iBeg=iEnd+1;
227 iEnd=aDS.NumberOfSourceShapes();
228 }
229
230 for (i=iBeg; i<=iEnd; ++i) {
231 aType=aDS.GetShapeType(i);
232 if (aType!=TopAbs_EDGE) {
233 continue;
234 }
235 const TopoDS_Edge& aE=TopoDS::Edge(aDS.Shape(i));
236 iRank=aDS.Rank(i);
237
238 aStateCmp=BOP_BuilderTools::StateToCompare(iRank, myOperation);
239
240 const BOPTools_ListOfPaveBlock& aLPB=aSplitShapesPool(aDS.RefEdge(i));
241 aNbPB=aLPB.Extent();
242 //
243 if (!aNbPB) {
244 aState=aDS.GetState(i);
245 if (aState==aStateCmp) {
246 myLS.Append(aE);
247 }
248 if (myOperation==BOP_COMMON && aState==BooleanOperations_ON) {
249 myLS.Append(aE);
250 }
251 }
252 //
253 else {
254 BOPTools_ListIteratorOfListOfPaveBlock aPBIt(aLPB);
255 for (; aPBIt.More(); aPBIt.Next()) {
256 const BOPTools_PaveBlock& aPB=aPBIt.Value();
257 nSp=aPB.Edge();
258 const TopoDS_Edge& aSS=TopoDS::Edge(aDS.Shape(nSp));
259 aState=aDS.GetState(nSp);
260 if (aState==aStateCmp) {
261 myLS.Append(aSS);
262 }
263 if (myOperation==BOP_COMMON && aState==BooleanOperations_ON) {
264 myLS.Append(aSS);
265 }
266 }
267 }
268 }
269}
270
271//=======================================================================
272// function: SetHistoryCollector
273// purpose:
274//=======================================================================
275void BOP_WireSolid::SetHistoryCollector(const Handle(BOP_HistoryCollector)& theHistory)
276{
277 if(theHistory.IsNull() ||
278 !theHistory->IsKind(STANDARD_TYPE(BOP_WireSolidHistoryCollector)))
279 myHistory.Nullify();
280 else
281 myHistory = theHistory;
282}