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