1 // Created on: 1999-10-21
2 // Created by: Atelier CAS2000
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <BRepAlgo.ixx>
19 #include <BRepCheck.hxx>
20 #include <BRepCheck_Analyzer.hxx>
21 #include <BRepCheck_ListIteratorOfListOfStatus.hxx>
22 #include <BRepCheck_ListOfStatus.hxx>
23 #include <BRepCheck_Result.hxx>
24 #include <BRepCheck_Shell.hxx>
25 #include <BRepLib.hxx>
26 #include <BRep_Builder.hxx>
27 #include <BRep_Tool.hxx>
28 #include <BRepTools.hxx>
29 #include <Precision.hxx>
30 #include <TopExp_Explorer.hxx>
31 #include <TopTools_ListIteratorOfListOfShape.hxx>
32 #include <TopTools_MapOfShape.hxx>
34 #include <TopoDS_Face.hxx>
35 #include <TopoDS_Compound.hxx>
38 //=======================================================================
41 //=======================================================================
42 Standard_Boolean BRepAlgo::IsValid(const TopoDS_Shape& S)
44 BRepCheck_Analyzer ana(S);
48 //=======================================================================
51 //=======================================================================
52 Standard_Boolean BRepAlgo::IsValid(const TopTools_ListOfShape& theArgs,
53 const TopoDS_Shape& theResult,
54 const Standard_Boolean closedSolid,
55 const Standard_Boolean GeomCtrl)
57 if (theResult.IsNull()) return Standard_True;
58 Standard_Boolean validate= Standard_False;
60 TopTools_MapOfShape allFaces;
62 TopTools_ListIteratorOfListOfShape itLOS;
63 for (itLOS.Initialize(theArgs);
64 itLOS.More(); itLOS.Next()) {
65 if (itLOS.Value().IsSame(theResult)) {
66 validate = Standard_True;
69 for (tEx.Init(itLOS.Value(), TopAbs_FACE); tEx.More(); tEx.Next()) {
70 allFaces.Add(tEx.Current());
74 TopoDS_Compound toCheck;
76 if (allFaces.IsEmpty()) {
77 if (validate) return Standard_True;
78 BRepCheck_Analyzer ana(theResult, GeomCtrl);
79 if (!ana.IsValid()) return Standard_False;
84 for (tEx.Init(theResult, TopAbs_FACE); tEx.More(); tEx.Next()) {
85 curf=TopoDS::Face(tEx.Current());
86 if (!allFaces.Contains(curf)) {
87 if (toCheck.IsNull()) bB.MakeCompound(toCheck);
88 BRepTools::Update(curf);
89 bB.Add(toCheck, curf);
92 if (toCheck.IsNull()) {
93 validate = Standard_True;
96 BRepCheck_Analyzer ana(toCheck, Standard_True);
99 // Check if the problem is not just BRepCheck_InvalidSameParameterFlag
100 BRepCheck_ListIteratorOfListOfStatus itl;
101 BRepCheck_Status sta;
102 for (tEx.Init(toCheck, TopAbs_FACE); tEx.More(); tEx.Next()) {
103 if (!ana.Result(tEx.Current()).IsNull()) {
104 for (itl.Initialize(ana.Result(tEx.Current())->Status()); itl.More(); itl.Next()) {
106 // If a face is incorrect
107 if (sta != BRepCheck_NoError) {
108 BRepCheck_ListIteratorOfListOfStatus ilt;
110 for (exp.Init(tEx.Current(), TopAbs_EDGE); exp.More(); exp.Next()) {
111 const Handle(BRepCheck_Result)& res = ana.Result(exp.Current());
112 for (res->InitContextIterator(); res->MoreShapeInContext(); res->NextShapeInContext()) {
113 if (res->ContextualShape().IsSame(tEx.Current())) {
114 for (ilt.Initialize(res->StatusOnShape()); ilt.More(); ilt.Next()) {
116 // If an edge is BRepCheck_InvalidSameParameterFlag or BRepCheck_InvalidSameRangeFlag, it is forced
117 if (sta == BRepCheck_InvalidSameParameterFlag ||
118 sta == BRepCheck_InvalidSameRangeFlag) {
119 bB.SameRange(TopoDS::Edge(exp.Current()), Standard_False);
120 bB.SameParameter(TopoDS::Edge(exp.Current()), Standard_False);
121 BRepLib::SameParameter(TopoDS::Edge(exp.Current()),
122 BRep_Tool::Tolerance(TopoDS::Edge(exp.Current())));
134 // Remake control (there can be a problem of another type orb the one that cannot be corrected
135 ana.Init(toCheck, Standard_True);
136 if (!ana.IsValid()) return Standard_False;
141 Handle(BRepCheck_Shell) HR;
142 for (tEx.Init(theResult, TopAbs_SHELL); tEx.More(); tEx.Next()) {
143 if (HR.IsNull()) HR = new BRepCheck_Shell(TopoDS::Shell(tEx.Current()));
144 else HR->Init(tEx.Current());
145 if (HR->Status().First() != BRepCheck_NoError) return Standard_False;
146 if (HR->Orientation(Standard_False) != BRepCheck_NoError) return Standard_False;
148 if (HR->Closed() != BRepCheck_NoError) return Standard_False;
152 return Standard_True;
156 //=======================================================================
157 //function : IsTopologicallyValid
159 //=======================================================================
160 Standard_Boolean BRepAlgo::IsTopologicallyValid(const TopoDS_Shape& S)
164 // if (getenv("DONT_SWITCH_IS_VALID") != NULL) {
165 // return Standard_True ;
168 BRepCheck_Analyzer ana(S,Standard_False);
169 return ana.IsValid();