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
17 #include <BRepAlgoAPI_Check.hxx>
18
19 #include <BOPAlgo_ArgumentAnalyzer.hxx>
20 #include <BRepCheck_Analyzer.hxx>
21
22 //=======================================================================
23 //function : BRepAlgoAPI_Check
24 //purpose :
25 //=======================================================================
BRepAlgoAPI_Check()26 BRepAlgoAPI_Check::BRepAlgoAPI_Check()
27 :
28 BOPAlgo_Options(),
29 myTestSE(Standard_True),
30 myTestSI(Standard_True),
31 myOperation(BOPAlgo_UNKNOWN)
32 {
33 }
34
35 //=======================================================================
36 //function : BRepAlgoAPI_Check
37 //purpose :
38 //=======================================================================
BRepAlgoAPI_Check(const TopoDS_Shape & theS,const Standard_Boolean bTestSE,const Standard_Boolean bTestSI,const Message_ProgressRange & theRange)39 BRepAlgoAPI_Check::BRepAlgoAPI_Check(const TopoDS_Shape& theS,
40 const Standard_Boolean bTestSE,
41 const Standard_Boolean bTestSI,
42 const Message_ProgressRange& theRange)
43 :
44 BOPAlgo_Options(),
45 myS1(theS),
46 myTestSE(bTestSE),
47 myTestSI(bTestSI),
48 myOperation(BOPAlgo_UNKNOWN)
49 {
50 Perform(theRange);
51 }
52
53 //=======================================================================
54 //function : BRepAlgoAPI_Check
55 //purpose :
56 //=======================================================================
BRepAlgoAPI_Check(const TopoDS_Shape & theS1,const TopoDS_Shape & theS2,const BOPAlgo_Operation theOp,const Standard_Boolean bTestSE,const Standard_Boolean bTestSI,const Message_ProgressRange & theRange)57 BRepAlgoAPI_Check::BRepAlgoAPI_Check(const TopoDS_Shape& theS1,
58 const TopoDS_Shape& theS2,
59 const BOPAlgo_Operation theOp,
60 const Standard_Boolean bTestSE,
61 const Standard_Boolean bTestSI,
62 const Message_ProgressRange& theRange)
63 :
64 BOPAlgo_Options(),
65 myS1(theS1),
66 myS2(theS2),
67 myTestSE(bTestSE),
68 myTestSI(bTestSI),
69 myOperation(theOp)
70 {
71 Perform(theRange);
72 }
73
74 //=======================================================================
75 //function : ~BRepAlgoAPI_Check
76 //purpose :
77 //=======================================================================
~BRepAlgoAPI_Check()78 BRepAlgoAPI_Check::~BRepAlgoAPI_Check()
79 {
80 }
81
82 //=======================================================================
83 //function : Perform
84 //purpose :
85 //=======================================================================
Perform(const Message_ProgressRange & theRange)86 void BRepAlgoAPI_Check::Perform(const Message_ProgressRange& theRange)
87 {
88 // Check the incompatibility of shapes types, small edges and self-interference
89 BOPAlgo_ArgumentAnalyzer anAnalyzer;
90 // Set the shapes and options for the check
91 anAnalyzer.SetShape1(myS1);
92 anAnalyzer.SetShape2(myS2);
93 anAnalyzer.OperationType() = myOperation;
94 anAnalyzer.ArgumentTypeMode() = Standard_True;
95 anAnalyzer.SmallEdgeMode() = myTestSE;
96 anAnalyzer.SelfInterMode() = myTestSI;
97 // Set options from BOPAlgo_Options
98 anAnalyzer.SetRunParallel(myRunParallel);
99 anAnalyzer.SetFuzzyValue(myFuzzyValue);
100 // Perform the check
101 Message_ProgressScope aPS(theRange, "Checking shapes", 1);
102 anAnalyzer.Perform(aPS.Next());
103 if (UserBreak(aPS))
104 {
105 return;
106 }
107 // Get the results
108 myFaultyShapes = anAnalyzer.GetCheckResult();
109
110 // Check the topological validity of the shapes
111 Standard_Boolean isValidS1 = !myS1.IsNull() ?
112 BRepCheck_Analyzer(myS1).IsValid() : Standard_True;
113
114 Standard_Boolean isValidS2 = !myS2.IsNull() ?
115 BRepCheck_Analyzer(myS2).IsValid() : Standard_True;
116
117 if (!isValidS1 || !isValidS2) {
118 BOPAlgo_CheckResult aRes;
119 aRes.SetCheckStatus(BOPAlgo_NotValid);
120 if (!isValidS1) {
121 aRes.SetShape1(myS1);
122 }
123 if (!isValidS2) {
124 aRes.SetShape2(myS2);
125 }
126 myFaultyShapes.Append(aRes);
127 }
128 }
129