1 // Created on: 2012-12-17
2 // Created by: Eugeny MALTCHIKOV
3 // Copyright (c) 2012-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <BRepAlgoAPI_Check.ixx>
17 #include <BOPAlgo_ArgumentAnalyzer.hxx>
18 #include <BRepBuilderAPI_Copy.hxx>
19 #include <BRepCheck_Analyzer.hxx>
21 //=======================================================================
22 //function : BRepAlgoAPI_Check
24 //=======================================================================
25 BRepAlgoAPI_Check::BRepAlgoAPI_Check()
30 //=======================================================================
31 //function : BRepAlgoAPI_Check
33 //=======================================================================
34 BRepAlgoAPI_Check::BRepAlgoAPI_Check(const TopoDS_Shape& theS,
35 const Standard_Boolean bTestSE,
36 const Standard_Boolean bTestSI)
38 Init(theS, TopoDS_Shape(), BOPAlgo_UNKNOWN, bTestSE, bTestSI);
43 //=======================================================================
44 //function : BRepAlgoAPI_Check
46 //=======================================================================
47 BRepAlgoAPI_Check::BRepAlgoAPI_Check(const TopoDS_Shape& theS1,
48 const TopoDS_Shape& theS2,
49 const BOPAlgo_Operation theOp,
50 const Standard_Boolean bTestSE,
51 const Standard_Boolean bTestSI)
53 Init(theS1, theS2, theOp, bTestSE, bTestSI);
58 //=======================================================================
59 //function : ~BRepAlgoAPI_Check
61 //=======================================================================
62 BRepAlgoAPI_Check::~BRepAlgoAPI_Check()
71 //=======================================================================
74 //=======================================================================
75 void BRepAlgoAPI_Check::SetData(const TopoDS_Shape& theS,
76 const Standard_Boolean bTestSE,
77 const Standard_Boolean bTestSI)
79 Init(theS, TopoDS_Shape(), BOPAlgo_UNKNOWN, bTestSE, bTestSI);
82 //=======================================================================
85 //=======================================================================
86 void BRepAlgoAPI_Check::SetData(const TopoDS_Shape& theS1,
87 const TopoDS_Shape& theS2,
88 const BOPAlgo_Operation theOp,
89 const Standard_Boolean bTestSE,
90 const Standard_Boolean bTestSI)
92 Init(theS1, theS2, theOp, bTestSE, bTestSI);
96 //=======================================================================
99 //=======================================================================
100 void BRepAlgoAPI_Check::Init(const TopoDS_Shape& theS1,
101 const TopoDS_Shape& theS2,
102 const BOPAlgo_Operation theOp,
103 const Standard_Boolean bTestSE,
104 const Standard_Boolean bTestSI)
107 myS1 = theS1.IsNull() ? theS1 : BRepBuilderAPI_Copy(theS1).Shape();
108 myS2 = theS2.IsNull() ? theS2 : BRepBuilderAPI_Copy(theS2).Shape();
110 myAnalyzer = new BOPAlgo_ArgumentAnalyzer();
112 myAnalyzer->SetShape1(myS1);
113 myAnalyzer->SetShape2(myS2);
114 myAnalyzer->OperationType()=theOp;
115 myAnalyzer->ArgumentTypeMode() = Standard_True;
116 myAnalyzer->SmallEdgeMode() = bTestSE;
117 myAnalyzer->SelfInterMode() = bTestSI;
120 //=======================================================================
123 //=======================================================================
124 const BOPAlgo_ListOfCheckResult& BRepAlgoAPI_Check::Result()
129 //=======================================================================
132 //=======================================================================
133 Standard_Boolean BRepAlgoAPI_Check::IsValid()
135 return myResult.IsEmpty();
138 //=======================================================================
141 //=======================================================================
142 void BRepAlgoAPI_Check::Perform()
144 Standard_Boolean isS1, isS2;
145 //incompatibility of shape types, small edges and self-interference
146 myAnalyzer->Perform();
147 if (myAnalyzer->HasFaulty()) {
148 myResult = myAnalyzer->GetCheckResult();
151 //topological validity
152 isS1 = !myS1.IsNull();
153 isS2 = !myS2.IsNull();
155 BRepCheck_Analyzer anS1(myS1);
156 isS1 = anS1.IsValid();
158 isS1 = Standard_True;
162 BRepCheck_Analyzer anS2(myS2);
163 isS2 = anS2.IsValid();
165 isS2 = Standard_True;
167 if (!isS1 || !isS2) {
168 BOPAlgo_CheckResult aRes;
169 aRes.SetCheckStatus(BOPAlgo_NotValid);
171 aRes.SetShape1(myS1);
174 aRes.SetShape2(myS2);
176 myResult.Append(aRes);