0021762: Integration of new Boolean Operation algorithm to OCCT.
[occt.git] / src / BRepAlgoAPI / BRepAlgoAPI_Check.cxx
1 // Created on: 2012-12-17
2 // Created by: Eugeny MALTCHIKOV
3 // Copyright (c) 2012-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
20 #include <BRepAlgoAPI_Check.ixx>
21 #include <BOPAlgo_ArgumentAnalyzer.hxx>
22 #include <BRepBuilderAPI_Copy.hxx>
23 #include <BRepCheck_Analyzer.hxx>
24
25 //=======================================================================
26 //function : BRepAlgoAPI_Check
27 //purpose  : 
28 //=======================================================================
29   BRepAlgoAPI_Check::BRepAlgoAPI_Check()
30 : myAnalyzer(NULL)
31 {
32 }
33
34 //=======================================================================
35 //function : BRepAlgoAPI_Check
36 //purpose  : 
37 //=======================================================================
38   BRepAlgoAPI_Check::BRepAlgoAPI_Check(const TopoDS_Shape& theS,
39                                        const Standard_Boolean bTestSE,
40                                        const Standard_Boolean bTestSI)
41 {
42   Init(theS, TopoDS_Shape(), BOPAlgo_UNKNOWN, bTestSE, bTestSI);
43   //
44   Perform();
45 }
46
47 //=======================================================================
48 //function : BRepAlgoAPI_Check
49 //purpose  : 
50 //=======================================================================
51   BRepAlgoAPI_Check::BRepAlgoAPI_Check(const TopoDS_Shape& theS1,
52                                        const TopoDS_Shape& theS2,
53                                        const BOPAlgo_Operation theOp,
54                                        const Standard_Boolean bTestSE,
55                                        const Standard_Boolean bTestSI)
56 {
57   Init(theS1, theS2, theOp, bTestSE, bTestSI);
58   //
59   Perform();
60 }
61
62 //=======================================================================
63 //function : ~BRepAlgoAPI_Check
64 //purpose  : 
65 //=======================================================================
66   BRepAlgoAPI_Check::~BRepAlgoAPI_Check()
67 {
68   if(myAnalyzer){
69     delete myAnalyzer;
70     myAnalyzer=NULL;
71   }
72   myResult.Clear();
73 }
74
75 //=======================================================================
76 //function : SetData
77 //purpose  : 
78 //=======================================================================
79   void BRepAlgoAPI_Check::SetData(const TopoDS_Shape& theS,
80                                   const Standard_Boolean bTestSE,
81                                   const Standard_Boolean bTestSI)
82 {
83   Init(theS, TopoDS_Shape(), BOPAlgo_UNKNOWN, bTestSE, bTestSI);
84 }
85
86 //=======================================================================
87 //function : SetData
88 //purpose  : 
89 //=======================================================================
90   void BRepAlgoAPI_Check::SetData(const TopoDS_Shape& theS1,
91                                   const TopoDS_Shape& theS2,
92                                   const BOPAlgo_Operation theOp,
93                                   const Standard_Boolean bTestSE,
94                                   const Standard_Boolean bTestSI)
95 {
96   Init(theS1, theS2, theOp, bTestSE, bTestSI);
97 }
98
99
100 //=======================================================================
101 //function : Init
102 //purpose  : 
103 //=======================================================================
104   void BRepAlgoAPI_Check::Init(const TopoDS_Shape& theS1,
105                                const TopoDS_Shape& theS2,
106                                const BOPAlgo_Operation theOp,
107                                const Standard_Boolean bTestSE,
108                                const Standard_Boolean bTestSI)
109 {
110   myResult.Clear();
111   myS1 = theS1.IsNull() ? theS1 : BRepBuilderAPI_Copy(theS1).Shape();
112   myS2 = theS2.IsNull() ? theS2 : BRepBuilderAPI_Copy(theS2).Shape();
113   //
114   myAnalyzer = new BOPAlgo_ArgumentAnalyzer();
115   //
116   myAnalyzer->SetShape1(myS1);
117   myAnalyzer->SetShape2(myS2);
118   myAnalyzer->OperationType()=theOp;
119   myAnalyzer->ArgumentTypeMode() = Standard_True;
120   myAnalyzer->SmallEdgeMode() = bTestSE;
121   myAnalyzer->SelfInterMode() = bTestSI;
122 }
123
124 //=======================================================================
125 //function : Result
126 //purpose  : 
127 //=======================================================================
128   const BOPAlgo_ListOfCheckResult& BRepAlgoAPI_Check::Result()
129 {
130   return myResult;
131 }
132
133 //=======================================================================
134 //function : IsValid
135 //purpose  : 
136 //=======================================================================
137   Standard_Boolean BRepAlgoAPI_Check::IsValid()
138 {
139   return myResult.IsEmpty();
140 }
141
142 //=======================================================================
143 //function : Perform
144 //purpose  : 
145 //=======================================================================
146   void BRepAlgoAPI_Check::Perform()
147 {
148   Standard_Boolean isS1, isS2;
149   //incompatibility of shape types, small edges and self-interference
150   myAnalyzer->Perform();
151   if (myAnalyzer->HasFaulty()) {
152     myResult = myAnalyzer->GetCheckResult();
153   }
154
155   //topological validity
156   isS1 = !myS1.IsNull();
157   isS2 = !myS2.IsNull();
158   if (isS1) {
159     BRepCheck_Analyzer anS1(myS1);
160     isS1 = anS1.IsValid();
161   } else {
162     isS1 = Standard_True;
163   }
164   //
165   if (isS2) {
166     BRepCheck_Analyzer anS2(myS2);
167     isS2 = anS2.IsValid();
168   } else {
169     isS2 = Standard_True;
170   }
171   if (!isS1 || !isS2) {
172     BOPAlgo_CheckResult aRes;
173     aRes.SetCheckStatus(BOPAlgo_NotValid);
174     if (!isS1) {
175       aRes.SetShape1(myS1);
176     }
177     if (!isS1) {
178       aRes.SetShape2(myS2);
179     }
180     myResult.Append(aRes);
181   }
182 }
183
184