1 // Created on: 1995-12-08
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1995-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.
18 #include <BRepCheck_Analyzer.hxx>
19 #include <BRepCheck_Edge.hxx>
20 #include <BRepCheck_Face.hxx>
21 #include <BRepCheck_ListIteratorOfListOfStatus.hxx>
22 #include <BRepCheck_Result.hxx>
23 #include <BRepCheck_Shell.hxx>
24 #include <BRepCheck_Solid.hxx>
25 #include <BRepCheck_Vertex.hxx>
26 #include <BRepCheck_Wire.hxx>
27 #include <Standard_ErrorHandler.hxx>
28 #include <Standard_Failure.hxx>
29 #include <Standard_NoSuchObject.hxx>
30 #include <Standard_NullObject.hxx>
31 #include <TopExp_Explorer.hxx>
33 #include <TopoDS_Face.hxx>
34 #include <TopoDS_Iterator.hxx>
35 #include <TopoDS_Shape.hxx>
36 #include <TopTools_MapOfShape.hxx>
38 //=======================================================================
41 //=======================================================================
42 void BRepCheck_Analyzer::Init(const TopoDS_Shape& S,
43 const Standard_Boolean B)
46 throw Standard_NullObject();
53 //=======================================================================
56 //=======================================================================
57 void BRepCheck_Analyzer::Put(const TopoDS_Shape& S,
58 const Standard_Boolean B)
60 if (!myMap.IsBound(S)) {
61 Handle(BRepCheck_Result) HR;
62 switch (S.ShapeType()) {
64 HR = new BRepCheck_Vertex(TopoDS::Vertex(S));
67 HR = new BRepCheck_Edge(TopoDS::Edge(S));
68 Handle(BRepCheck_Edge)::DownCast(HR)->GeometricControls(B);
71 HR = new BRepCheck_Wire(TopoDS::Wire(S));
72 Handle(BRepCheck_Wire)::DownCast(HR)->GeometricControls(B);
75 HR = new BRepCheck_Face(TopoDS::Face(S));
76 Handle(BRepCheck_Face)::DownCast(HR)->GeometricControls(B);
79 HR = new BRepCheck_Shell(TopoDS::Shell(S));
82 HR = new BRepCheck_Solid(TopoDS::Solid(S));
84 case TopAbs_COMPSOLID:
91 for(TopoDS_Iterator theIterator(S);theIterator.More();theIterator.Next()) {
92 Put(theIterator.Value(),B); // performs minimum on each shape
96 //=======================================================================
99 //=======================================================================
100 void BRepCheck_Analyzer::Perform(const TopoDS_Shape& S)
102 for(TopoDS_Iterator theIterator(S);theIterator.More();theIterator.Next())
103 Perform(theIterator.Value());
106 TopAbs_ShapeEnum styp;
109 styp = S.ShapeType();
114 // modified by NIZHNY-MKK Wed May 19 16:56:16 2004.BEGIN
115 // There is no need to check anything.
116 // if (myShape.IsSame(S)) {
117 // myMap(S)->Blind();
119 // modified by NIZHNY-MKK Wed May 19 16:56:23 2004.END
124 Handle(BRepCheck_Result)& aRes = myMap(S);
128 BRepCheck_Status ste = Handle(BRepCheck_Edge)::
129 DownCast(aRes)->CheckPolygonOnTriangulation(TopoDS::Edge(S));
131 if(ste != BRepCheck_NoError)
133 Handle(BRepCheck_Edge)::DownCast(aRes)->SetStatus(ste);
136 catch(Standard_Failure const& anException) {
138 std::cout<<"BRepCheck_Analyzer : ";
139 anException.Print(std::cout);
140 std::cout<<std::endl;
143 if ( ! myMap(S).IsNull() )
145 myMap(S)->SetFailStatus(S);
148 if ( ! aRes.IsNull() )
150 aRes->SetFailStatus(S);
154 TopTools_MapOfShape MapS;
156 for (exp.Init(S,TopAbs_VERTEX);exp.More(); exp.Next())
158 const TopoDS_Shape& aVertex = exp.Current();
162 if (MapS.Add(aVertex))
163 myMap(aVertex)->InContext(S);
165 catch(Standard_Failure const& anException) {
167 std::cout<<"BRepCheck_Analyzer : ";
168 anException.Print(std::cout);
169 std::cout<<std::endl;
172 if ( ! myMap(S).IsNull() )
173 myMap(S)->SetFailStatus(S);
175 Handle(BRepCheck_Result) aResOfVertex = myMap(aVertex);
177 if ( !aResOfVertex.IsNull() )
179 aResOfVertex->SetFailStatus(aVertex);
180 aResOfVertex->SetFailStatus(S);
182 }//catch(Standard_Failure)
183 }//for (exp.Init(S,TopAbs_VERTEX);exp.More(); exp.Next())
192 TopTools_MapOfShape MapS;
193 for (exp.Init(S,TopAbs_VERTEX);exp.More(); exp.Next())
198 if (MapS.Add(exp.Current()))
200 myMap(exp.Current())->InContext(S);
203 catch(Standard_Failure const& anException) {
205 std::cout<<"BRepCheck_Analyzer : ";
206 anException.Print(std::cout);
207 std::cout<<std::endl;
210 if ( ! myMap(S).IsNull() )
212 myMap(S)->SetFailStatus(S);
215 Handle(BRepCheck_Result) aRes = myMap(exp.Current());
217 if ( ! aRes.IsNull() )
219 aRes->SetFailStatus(exp.Current());
220 aRes->SetFailStatus(S);
225 Standard_Boolean performwire = Standard_True;
226 Standard_Boolean isInvalidTolerance = Standard_False;
228 for (exp.Init(S,TopAbs_EDGE);exp.More(); exp.Next())
233 if (MapS.Add(exp.Current()))
235 Handle(BRepCheck_Result)& res = myMap(exp.Current());
239 for ( res->InitContextIterator();
240 res->MoreShapeInContext();
241 res->NextShapeInContext())
243 if(res->ContextualShape().IsSame(S))
247 BRepCheck_ListIteratorOfListOfStatus itl(res->StatusOnShape());
248 for (; itl.More(); itl.Next())
250 BRepCheck_Status ste = itl.Value();
251 if (ste == BRepCheck_NoCurveOnSurface ||
252 ste == BRepCheck_InvalidCurveOnSurface ||
253 ste == BRepCheck_InvalidRange ||
254 ste == BRepCheck_InvalidCurveOnClosedSurface)
256 performwire = Standard_False;
263 catch(Standard_Failure const& anException) {
265 std::cout<<"BRepCheck_Analyzer : ";
266 anException.Print(std::cout);
267 std::cout<<std::endl;
270 if ( ! myMap(S).IsNull() )
272 myMap(S)->SetFailStatus(S);
275 Handle(BRepCheck_Result) aRes = myMap(exp.Current());
277 if ( ! aRes.IsNull() )
279 aRes->SetFailStatus(exp.Current());
280 aRes->SetFailStatus(S);
285 Standard_Boolean orientofwires = performwire;
286 for (exp.Init(S,TopAbs_WIRE);exp.More(); exp.Next())
291 Handle(BRepCheck_Result)& res = myMap(exp.Current());
295 for ( res->InitContextIterator();
296 res->MoreShapeInContext();
297 res->NextShapeInContext())
299 if(res->ContextualShape().IsSame(S))
304 BRepCheck_ListIteratorOfListOfStatus itl(res->StatusOnShape());
305 for (; itl.More(); itl.Next())
307 BRepCheck_Status ste = itl.Value();
308 if (ste != BRepCheck_NoError)
310 orientofwires = Standard_False;
316 catch(Standard_Failure const& anException) {
318 std::cout<<"BRepCheck_Analyzer : ";
319 anException.Print(std::cout);
320 std::cout<<std::endl;
323 if ( ! myMap(S).IsNull() )
325 myMap(S)->SetFailStatus(S);
328 Handle(BRepCheck_Result) aRes = myMap(exp.Current());
330 if ( ! aRes.IsNull() )
332 aRes->SetFailStatus(exp.Current());
333 aRes->SetFailStatus(S);
341 if(isInvalidTolerance)
343 Handle(BRepCheck_Face)::
344 DownCast(myMap(S))->SetStatus(BRepCheck_InvalidToleranceValue);
346 else if (performwire)
350 Handle(BRepCheck_Face)::DownCast(myMap(S))->
351 OrientationOfWires(Standard_True);// on enregistre
355 Handle(BRepCheck_Face)::DownCast(myMap(S))->SetUnorientable();
360 Handle(BRepCheck_Face)::DownCast(myMap(S))->SetUnorientable();
363 catch(Standard_Failure const& anException) {
365 std::cout<<"BRepCheck_Analyzer : ";
366 anException.Print(std::cout);
367 std::cout<<std::endl;
370 if ( ! myMap(S).IsNull() )
372 myMap(S)->SetFailStatus(S);
375 for (exp.Init(S,TopAbs_WIRE);exp.More(); exp.Next())
377 Handle(BRepCheck_Result) aRes = myMap(exp.Current());
379 if ( ! aRes.IsNull() )
381 aRes->SetFailStatus(exp.Current());
382 aRes->SetFailStatus(S);
383 myMap(S)->SetFailStatus(exp.Current());
395 exp.Init(S,TopAbs_SHELL);
396 for (; exp.More(); exp.Next())
398 const TopoDS_Shape& aShell=exp.Current();
402 myMap(aShell)->InContext(S);
404 catch(Standard_Failure const& anException) {
406 std::cout<<"BRepCheck_Analyzer : ";
407 anException.Print(std::cout);
408 std::cout<<std::endl;
411 if ( ! myMap(S).IsNull() )
413 myMap(S)->SetFailStatus(S);
417 Handle(BRepCheck_Result) aRes = myMap(aShell);
420 aRes->SetFailStatus(exp.Current());
421 aRes->SetFailStatus(S);
423 }//catch(Standard_Failure)
424 }//for (; exp.More(); exp.Next())
426 break;//case TopAbs_SOLID
433 //=======================================================================
436 //=======================================================================
438 Standard_Boolean BRepCheck_Analyzer::IsValid(const TopoDS_Shape& S) const
440 if (!myMap(S).IsNull()) {
441 BRepCheck_ListIteratorOfListOfStatus itl;
442 itl.Initialize(myMap(S)->Status());
443 if (itl.Value() != BRepCheck_NoError) { // a voir
444 return Standard_False;
448 for(TopoDS_Iterator theIterator(S);theIterator.More();theIterator.Next()) {
449 if (!IsValid(theIterator.Value())) {
450 return Standard_False;
454 switch (S.ShapeType()) {
457 return ValidSub(S,TopAbs_VERTEX);
462 Standard_Boolean valid = ValidSub(S,TopAbs_WIRE);
463 valid = valid && ValidSub(S,TopAbs_EDGE);
464 valid = valid && ValidSub(S,TopAbs_VERTEX);
470 // return ValidSub(S,TopAbs_FACE);
473 // return ValidSub(S,TopAbs_EDGE);
475 return ValidSub(S,TopAbs_SHELL);
481 return Standard_True;
484 //=======================================================================
485 //function : ValidSub
487 //=======================================================================
489 Standard_Boolean BRepCheck_Analyzer::ValidSub
490 (const TopoDS_Shape& S,
491 const TopAbs_ShapeEnum SubType) const
493 BRepCheck_ListIteratorOfListOfStatus itl;
495 for (exp.Init(S,SubType);exp.More(); exp.Next()) {
496 // for (TopExp_Explorer exp(S,SubType);exp.More(); exp.Next()) {
497 const Handle(BRepCheck_Result)& RV = myMap(exp.Current());
498 for (RV->InitContextIterator();
499 RV->MoreShapeInContext();
500 RV->NextShapeInContext()) {
501 if (RV->ContextualShape().IsSame(S)) {
506 if(!RV->MoreShapeInContext()) break;
508 for (itl.Initialize(RV->StatusOnShape()); itl.More(); itl.Next()) {
509 if (itl.Value() != BRepCheck_NoError) {
510 return Standard_False;
514 return Standard_True ;