1 // Created on: 1999-10-21
2 // Created by: Atelier CAS2000
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
23 #include <BRepAlgo.ixx>
25 #include <BRepCheck.hxx>
26 #include <BRepCheck_Analyzer.hxx>
27 #include <BRepCheck_ListIteratorOfListOfStatus.hxx>
28 #include <BRepCheck_ListOfStatus.hxx>
29 #include <BRepCheck_Result.hxx>
30 #include <BRepCheck_Shell.hxx>
31 #include <BRepLib.hxx>
32 #include <BRep_Builder.hxx>
33 #include <BRep_Tool.hxx>
34 #include <BRepTools.hxx>
35 #include <Precision.hxx>
36 #include <TopExp_Explorer.hxx>
37 #include <TopTools_ListIteratorOfListOfShape.hxx>
38 #include <TopTools_MapOfShape.hxx>
40 #include <TopoDS_Face.hxx>
41 #include <TopoDS_Compound.hxx>
44 //=======================================================================
47 //=======================================================================
48 Standard_Boolean BRepAlgo::IsValid(const TopoDS_Shape& S)
50 BRepCheck_Analyzer ana(S);
54 //=======================================================================
57 //=======================================================================
58 Standard_Boolean BRepAlgo::IsValid(const TopTools_ListOfShape& theArgs,
59 const TopoDS_Shape& theResult,
60 const Standard_Boolean closedSolid,
61 const Standard_Boolean GeomCtrl)
63 if (theResult.IsNull()) return Standard_True;
64 Standard_Boolean validate= Standard_False;
66 TopTools_MapOfShape allFaces;
68 TopTools_ListIteratorOfListOfShape itLOS;
69 for (itLOS.Initialize(theArgs);
70 itLOS.More(); itLOS.Next()) {
71 if (itLOS.Value().IsSame(theResult)) {
72 validate = Standard_True;
75 for (tEx.Init(itLOS.Value(), TopAbs_FACE); tEx.More(); tEx.Next()) {
76 allFaces.Add(tEx.Current());
80 TopoDS_Compound toCheck;
82 if (allFaces.IsEmpty()) {
83 if (validate) return Standard_True;
84 BRepCheck_Analyzer ana(theResult, GeomCtrl);
85 if (!ana.IsValid()) return Standard_False;
90 for (tEx.Init(theResult, TopAbs_FACE); tEx.More(); tEx.Next()) {
91 curf=TopoDS::Face(tEx.Current());
92 if (!allFaces.Contains(curf)) {
93 if (toCheck.IsNull()) bB.MakeCompound(toCheck);
94 BRepTools::Update(curf);
95 bB.Add(toCheck, curf);
98 if (toCheck.IsNull()) {
99 validate = Standard_True;
102 BRepCheck_Analyzer ana(toCheck, Standard_True);
103 if (!ana.IsValid()) {
105 // Check if the problem is not just BRepCheck_InvalidSameParameterFlag
106 BRepCheck_ListIteratorOfListOfStatus itl;
107 BRepCheck_Status sta;
108 for (tEx.Init(toCheck, TopAbs_FACE); tEx.More(); tEx.Next()) {
109 if (!ana.Result(tEx.Current()).IsNull()) {
110 for (itl.Initialize(ana.Result(tEx.Current())->Status()); itl.More(); itl.Next()) {
112 // If a face is incorrect
113 if (sta != BRepCheck_NoError) {
114 BRepCheck_ListIteratorOfListOfStatus ilt;
116 for (exp.Init(tEx.Current(), TopAbs_EDGE); exp.More(); exp.Next()) {
117 const Handle(BRepCheck_Result)& res = ana.Result(exp.Current());
118 for (res->InitContextIterator(); res->MoreShapeInContext(); res->NextShapeInContext()) {
119 if (res->ContextualShape().IsSame(tEx.Current())) {
120 for (ilt.Initialize(res->StatusOnShape()); ilt.More(); ilt.Next()) {
122 // If an edge is BRepCheck_InvalidSameParameterFlag or BRepCheck_InvalidSameRangeFlag, it is forced
123 if (sta == BRepCheck_InvalidSameParameterFlag ||
124 sta == BRepCheck_InvalidSameRangeFlag) {
125 bB.SameRange(TopoDS::Edge(exp.Current()), Standard_False);
126 bB.SameParameter(TopoDS::Edge(exp.Current()), Standard_False);
127 BRepLib::SameParameter(TopoDS::Edge(exp.Current()),
128 BRep_Tool::Tolerance(TopoDS::Edge(exp.Current())));
140 // Remake control (there can be a problem of another type orb the one that cannot be corrected
141 ana.Init(toCheck, Standard_True);
142 if (!ana.IsValid()) return Standard_False;
147 Handle(BRepCheck_Shell) HR;
148 for (tEx.Init(theResult, TopAbs_SHELL); tEx.More(); tEx.Next()) {
149 if (HR.IsNull()) HR = new BRepCheck_Shell(TopoDS::Shell(tEx.Current()));
150 else HR->Init(tEx.Current());
151 if (HR->Status().First() != BRepCheck_NoError) return Standard_False;
152 if (HR->Orientation(Standard_False) != BRepCheck_NoError) return Standard_False;
154 if (HR->Closed() != BRepCheck_NoError) return Standard_False;
158 return Standard_True;
162 //=======================================================================
163 //function : IsTopologicallyValid
165 //=======================================================================
166 Standard_Boolean BRepAlgo::IsTopologicallyValid(const TopoDS_Shape& S)
170 // if (getenv("DONT_SWITCH_IS_VALID") != NULL) {
171 // return Standard_True ;
174 BRepCheck_Analyzer ana(S,Standard_False);
175 return ana.IsValid();