0024002: Overall code and build procedure refactoring -- automatic
[occt.git] / src / BRepAlgo / BRepAlgo_1.cxx
CommitLineData
b311480e 1// Created on: 1999-10-21
2// Created by: Atelier CAS2000
3// Copyright (c) 1999-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
7fd59977 17
42cf5bc1 18#include <BRep_Builder.hxx>
19#include <BRep_Tool.hxx>
20#include <BRepAlgo.hxx>
7fd59977 21#include <BRepCheck.hxx>
22#include <BRepCheck_Analyzer.hxx>
23#include <BRepCheck_ListIteratorOfListOfStatus.hxx>
24#include <BRepCheck_ListOfStatus.hxx>
25#include <BRepCheck_Result.hxx>
26#include <BRepCheck_Shell.hxx>
27#include <BRepLib.hxx>
7fd59977 28#include <BRepTools.hxx>
42cf5bc1 29#include <gp.hxx>
7fd59977 30#include <Precision.hxx>
31#include <TopExp_Explorer.hxx>
7fd59977 32#include <TopoDS.hxx>
7fd59977 33#include <TopoDS_Compound.hxx>
42cf5bc1 34#include <TopoDS_Edge.hxx>
35#include <TopoDS_Face.hxx>
36#include <TopoDS_Shape.hxx>
37#include <TopoDS_Wire.hxx>
38#include <TopTools_ListIteratorOfListOfShape.hxx>
39#include <TopTools_MapOfShape.hxx>
7fd59977 40
41//=======================================================================
42//function : IsValid
43//purpose :
44//=======================================================================
b311480e 45Standard_Boolean BRepAlgo::IsValid(const TopoDS_Shape& S)
7fd59977 46{
47 BRepCheck_Analyzer ana(S);
48 return ana.IsValid();
49}
50
51//=======================================================================
52//function : IsValid
53//purpose :
54//=======================================================================
55 Standard_Boolean BRepAlgo::IsValid(const TopTools_ListOfShape& theArgs,
56 const TopoDS_Shape& theResult,
57 const Standard_Boolean closedSolid,
58 const Standard_Boolean GeomCtrl)
59{
60 if (theResult.IsNull()) return Standard_True;
61 Standard_Boolean validate= Standard_False;
62
63 TopTools_MapOfShape allFaces;
64 TopExp_Explorer tEx;
65 TopTools_ListIteratorOfListOfShape itLOS;
66 for (itLOS.Initialize(theArgs);
67 itLOS.More(); itLOS.Next()) {
68 if (itLOS.Value().IsSame(theResult)) {
69 validate = Standard_True;
70 break;
71 }
72 for (tEx.Init(itLOS.Value(), TopAbs_FACE); tEx.More(); tEx.Next()) {
73 allFaces.Add(tEx.Current());
74 }
75 }
76
77 TopoDS_Compound toCheck;
78
79 if (allFaces.IsEmpty()) {
80 if (validate) return Standard_True;
81 BRepCheck_Analyzer ana(theResult, GeomCtrl);
82 if (!ana.IsValid()) return Standard_False;
83 }
84 else if (!validate) {
85 BRep_Builder bB;
86 TopoDS_Face curf;
87 for (tEx.Init(theResult, TopAbs_FACE); tEx.More(); tEx.Next()) {
88 curf=TopoDS::Face(tEx.Current());
89 if (!allFaces.Contains(curf)) {
90 if (toCheck.IsNull()) bB.MakeCompound(toCheck);
91 BRepTools::Update(curf);
92 bB.Add(toCheck, curf);
93 }
94 }
95 if (toCheck.IsNull()) {
96 validate = Standard_True;
97 }
98 else {
99 BRepCheck_Analyzer ana(toCheck, Standard_True);
100 if (!ana.IsValid()) {
101
0d969553 102// Check if the problem is not just BRepCheck_InvalidSameParameterFlag
7fd59977 103 BRepCheck_ListIteratorOfListOfStatus itl;
104 BRepCheck_Status sta;
105 for (tEx.Init(toCheck, TopAbs_FACE); tEx.More(); tEx.Next()) {
106 if (!ana.Result(tEx.Current()).IsNull()) {
107 for (itl.Initialize(ana.Result(tEx.Current())->Status()); itl.More(); itl.Next()) {
108 sta=itl.Value();
0d969553 109// If a face is incorrect
7fd59977 110 if (sta != BRepCheck_NoError) {
111 BRepCheck_ListIteratorOfListOfStatus ilt;
112 TopExp_Explorer exp;
113 for (exp.Init(tEx.Current(), TopAbs_EDGE); exp.More(); exp.Next()) {
114 const Handle(BRepCheck_Result)& res = ana.Result(exp.Current());
115 for (res->InitContextIterator(); res->MoreShapeInContext(); res->NextShapeInContext()) {
116 if (res->ContextualShape().IsSame(tEx.Current())) {
117 for (ilt.Initialize(res->StatusOnShape()); ilt.More(); ilt.Next()) {
118 sta=ilt.Value();
0d969553 119// If an edge is BRepCheck_InvalidSameParameterFlag or BRepCheck_InvalidSameRangeFlag, it is forced
7fd59977 120 if (sta == BRepCheck_InvalidSameParameterFlag ||
121 sta == BRepCheck_InvalidSameRangeFlag) {
122 bB.SameRange(TopoDS::Edge(exp.Current()), Standard_False);
123 bB.SameParameter(TopoDS::Edge(exp.Current()), Standard_False);
124 BRepLib::SameParameter(TopoDS::Edge(exp.Current()),
125 BRep_Tool::Tolerance(TopoDS::Edge(exp.Current())));
126 break;
127 }
128 }
129 }
130 }
131 }
132 break;
133 }
134 }
135 }
136 }
0d969553 137// Remake control (there can be a problem of another type orb the one that cannot be corrected
7fd59977 138 ana.Init(toCheck, Standard_True);
139 if (!ana.IsValid()) return Standard_False;
140 }
141 }
142 }
143
144 Handle(BRepCheck_Shell) HR;
145 for (tEx.Init(theResult, TopAbs_SHELL); tEx.More(); tEx.Next()) {
146 if (HR.IsNull()) HR = new BRepCheck_Shell(TopoDS::Shell(tEx.Current()));
147 else HR->Init(tEx.Current());
148 if (HR->Status().First() != BRepCheck_NoError) return Standard_False;
149 if (HR->Orientation(Standard_False) != BRepCheck_NoError) return Standard_False;
150 if (closedSolid) {
151 if (HR->Closed() != BRepCheck_NoError) return Standard_False;
152 }
153 }
154
155 return Standard_True;
156}
157
158
159//=======================================================================
160//function : IsTopologicallyValid
161//purpose :
162//=======================================================================
163 Standard_Boolean BRepAlgo::IsTopologicallyValid(const TopoDS_Shape& S)
164{
165//
166
7fd59977 167// if (getenv("DONT_SWITCH_IS_VALID") != NULL) {
168// return Standard_True ;
169// }
170// else {
171 BRepCheck_Analyzer ana(S,Standard_False);
172 return ana.IsValid();
173
174// }
175}
176
177
178