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 cout<<"BRepCheck_Analyzer : ";
139 anException.Print(cout);
143 if ( ! myMap(S).IsNull() )
145 myMap(S)->SetFailStatus(S);
148 if ( ! aRes.IsNull() )
150 aRes->SetFailStatus(exp.Current());
151 aRes->SetFailStatus(S);
155 TopTools_MapOfShape MapS;
157 for (exp.Init(S,TopAbs_VERTEX);exp.More(); exp.Next())
159 const TopoDS_Shape& aVertex = exp.Current();
163 if (MapS.Add(aVertex))
164 myMap(aVertex)->InContext(S);
166 catch(Standard_Failure const& anException) {
168 cout<<"BRepCheck_Analyzer : ";
169 anException.Print(cout);
173 if ( ! myMap(S).IsNull() )
174 myMap(S)->SetFailStatus(S);
176 Handle(BRepCheck_Result) aResOfVertex = myMap(aVertex);
178 if ( !aResOfVertex.IsNull() )
180 aResOfVertex->SetFailStatus(aVertex);
181 aResOfVertex->SetFailStatus(S);
183 }//catch(Standard_Failure)
184 }//for (exp.Init(S,TopAbs_VERTEX);exp.More(); exp.Next())
193 TopTools_MapOfShape MapS;
194 for (exp.Init(S,TopAbs_VERTEX);exp.More(); exp.Next())
199 if (MapS.Add(exp.Current()))
201 myMap(exp.Current())->InContext(S);
204 catch(Standard_Failure const& anException) {
206 cout<<"BRepCheck_Analyzer : ";
207 anException.Print(cout);
211 if ( ! myMap(S).IsNull() )
213 myMap(S)->SetFailStatus(S);
216 Handle(BRepCheck_Result) aRes = myMap(exp.Current());
218 if ( ! aRes.IsNull() )
220 aRes->SetFailStatus(exp.Current());
221 aRes->SetFailStatus(S);
226 Standard_Boolean performwire = Standard_True;
227 Standard_Boolean isInvalidTolerance = Standard_False;
229 for (exp.Init(S,TopAbs_EDGE);exp.More(); exp.Next())
234 if (MapS.Add(exp.Current()))
236 Handle(BRepCheck_Result)& res = myMap(exp.Current());
240 for ( res->InitContextIterator();
241 res->MoreShapeInContext();
242 res->NextShapeInContext())
244 if(res->ContextualShape().IsSame(S))
248 BRepCheck_ListIteratorOfListOfStatus itl(res->StatusOnShape());
249 for (; itl.More(); itl.Next())
251 BRepCheck_Status ste = itl.Value();
252 if (ste == BRepCheck_NoCurveOnSurface ||
253 ste == BRepCheck_InvalidCurveOnSurface ||
254 ste == BRepCheck_InvalidRange ||
255 ste == BRepCheck_InvalidCurveOnClosedSurface)
257 performwire = Standard_False;
264 catch(Standard_Failure const& anException) {
266 cout<<"BRepCheck_Analyzer : ";
267 anException.Print(cout);
271 if ( ! myMap(S).IsNull() )
273 myMap(S)->SetFailStatus(S);
276 Handle(BRepCheck_Result) aRes = myMap(exp.Current());
278 if ( ! aRes.IsNull() )
280 aRes->SetFailStatus(exp.Current());
281 aRes->SetFailStatus(S);
286 Standard_Boolean orientofwires = performwire;
287 for (exp.Init(S,TopAbs_WIRE);exp.More(); exp.Next())
292 Handle(BRepCheck_Result)& res = myMap(exp.Current());
296 for ( res->InitContextIterator();
297 res->MoreShapeInContext();
298 res->NextShapeInContext())
300 if(res->ContextualShape().IsSame(S))
305 BRepCheck_ListIteratorOfListOfStatus itl(res->StatusOnShape());
306 for (; itl.More(); itl.Next())
308 BRepCheck_Status ste = itl.Value();
309 if (ste != BRepCheck_NoError)
311 orientofwires = Standard_False;
317 catch(Standard_Failure const& anException) {
319 cout<<"BRepCheck_Analyzer : ";
320 anException.Print(cout);
324 if ( ! myMap(S).IsNull() )
326 myMap(S)->SetFailStatus(S);
329 Handle(BRepCheck_Result) aRes = myMap(exp.Current());
331 if ( ! aRes.IsNull() )
333 aRes->SetFailStatus(exp.Current());
334 aRes->SetFailStatus(S);
342 if(isInvalidTolerance)
344 Handle(BRepCheck_Face)::
345 DownCast(myMap(S))->SetStatus(BRepCheck_InvalidToleranceValue);
347 else if (performwire)
351 Handle(BRepCheck_Face)::DownCast(myMap(S))->
352 OrientationOfWires(Standard_True);// on enregistre
356 Handle(BRepCheck_Face)::DownCast(myMap(S))->SetUnorientable();
361 Handle(BRepCheck_Face)::DownCast(myMap(S))->SetUnorientable();
364 catch(Standard_Failure const& anException) {
366 cout<<"BRepCheck_Analyzer : ";
367 anException.Print(cout);
371 if ( ! myMap(S).IsNull() )
373 myMap(S)->SetFailStatus(S);
376 for (exp.Init(S,TopAbs_WIRE);exp.More(); exp.Next())
378 Handle(BRepCheck_Result) aRes = myMap(exp.Current());
380 if ( ! aRes.IsNull() )
382 aRes->SetFailStatus(exp.Current());
383 aRes->SetFailStatus(S);
384 myMap(S)->SetFailStatus(exp.Current());
396 exp.Init(S,TopAbs_SHELL);
397 for (; exp.More(); exp.Next())
399 const TopoDS_Shape& aShell=exp.Current();
403 myMap(aShell)->InContext(S);
405 catch(Standard_Failure const& anException) {
407 cout<<"BRepCheck_Analyzer : ";
408 anException.Print(cout);
412 if ( ! myMap(S).IsNull() )
414 myMap(S)->SetFailStatus(S);
418 Handle(BRepCheck_Result) aRes = myMap(aShell);
421 aRes->SetFailStatus(exp.Current());
422 aRes->SetFailStatus(S);
424 }//catch(Standard_Failure)
425 }//for (; exp.More(); exp.Next())
427 break;//case TopAbs_SOLID
434 //=======================================================================
437 //=======================================================================
439 Standard_Boolean BRepCheck_Analyzer::IsValid(const TopoDS_Shape& S) const
441 if (!myMap(S).IsNull()) {
442 BRepCheck_ListIteratorOfListOfStatus itl;
443 itl.Initialize(myMap(S)->Status());
444 if (itl.Value() != BRepCheck_NoError) { // a voir
445 return Standard_False;
449 for(TopoDS_Iterator theIterator(S);theIterator.More();theIterator.Next()) {
450 if (!IsValid(theIterator.Value())) {
451 return Standard_False;
455 switch (S.ShapeType()) {
458 return ValidSub(S,TopAbs_VERTEX);
463 Standard_Boolean valid = ValidSub(S,TopAbs_WIRE);
464 valid = valid && ValidSub(S,TopAbs_EDGE);
465 valid = valid && ValidSub(S,TopAbs_VERTEX);
471 // return ValidSub(S,TopAbs_FACE);
474 // return ValidSub(S,TopAbs_EDGE);
476 return ValidSub(S,TopAbs_SHELL);
482 return Standard_True;
485 //=======================================================================
486 //function : ValidSub
488 //=======================================================================
490 Standard_Boolean BRepCheck_Analyzer::ValidSub
491 (const TopoDS_Shape& S,
492 const TopAbs_ShapeEnum SubType) const
494 BRepCheck_ListIteratorOfListOfStatus itl;
496 for (exp.Init(S,SubType);exp.More(); exp.Next()) {
497 // for (TopExp_Explorer exp(S,SubType);exp.More(); exp.Next()) {
498 const Handle(BRepCheck_Result)& RV = myMap(exp.Current());
499 for (RV->InitContextIterator();
500 RV->MoreShapeInContext();
501 RV->NextShapeInContext()) {
502 if (RV->ContextualShape().IsSame(S)) {
507 if(!RV->MoreShapeInContext()) break;
509 for (itl.Initialize(RV->StatusOnShape()); itl.More(); itl.Next()) {
510 if (itl.Value() != BRepCheck_NoError) {
511 return Standard_False;
515 return Standard_True ;