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.
17 #include <BRepCheck_Analyzer.ixx>
19 #include <BRepCheck_Vertex.hxx>
20 #include <BRepCheck_Edge.hxx>
21 #include <BRepCheck_Wire.hxx>
22 #include <BRepCheck_Face.hxx>
23 #include <BRepCheck_Shell.hxx>
24 #include <BRepCheck_ListIteratorOfListOfStatus.hxx>
26 #include <TopoDS_Iterator.hxx>
27 #include <TopExp_Explorer.hxx>
29 #include <TopTools_MapOfShape.hxx>
31 #include <TopoDS_Face.hxx>
33 #include <Standard_ErrorHandler.hxx>
34 #include <Standard_Failure.hxx>
36 //=======================================================================
39 //=======================================================================
41 void BRepCheck_Analyzer::Init(const TopoDS_Shape& S,
42 const Standard_Boolean B)
45 Standard_NullObject::Raise();
55 //=======================================================================
58 //=======================================================================
60 void BRepCheck_Analyzer::Put(const TopoDS_Shape& S,
61 const Standard_Boolean B)
63 if (!myMap.IsBound(S)) {
64 Handle(BRepCheck_Result) HR;
65 switch (S.ShapeType()) {
67 HR = new BRepCheck_Vertex(TopoDS::Vertex(S));
70 HR = new BRepCheck_Edge(TopoDS::Edge(S));
71 Handle(BRepCheck_Edge)::DownCast(HR)->GeometricControls(B);
74 HR = new BRepCheck_Wire(TopoDS::Wire(S));
75 Handle(BRepCheck_Wire)::DownCast(HR)->GeometricControls(B);
78 HR = new BRepCheck_Face(TopoDS::Face(S));
79 Handle(BRepCheck_Face)::DownCast(HR)->GeometricControls(B);
82 HR = new BRepCheck_Shell(TopoDS::Shell(S));
85 case TopAbs_COMPSOLID:
92 for(TopoDS_Iterator theIterator(S);theIterator.More();theIterator.Next()) {
93 Put(theIterator.Value(),B); // performs minimum on each shape
99 //=======================================================================
102 //=======================================================================
104 void BRepCheck_Analyzer::Perform(const TopoDS_Shape& S)
106 for(TopoDS_Iterator theIterator(S);theIterator.More();theIterator.Next())
107 Perform(theIterator.Value());
110 TopAbs_ShapeEnum styp;
113 styp = S.ShapeType();
118 // modified by NIZHNY-MKK Wed May 19 16:56:16 2004.BEGIN
119 // There is no need to check anything.
120 // if (myShape.IsSame(S)) {
121 // myMap(S)->Blind();
123 // modified by NIZHNY-MKK Wed May 19 16:56:23 2004.END
128 Handle(BRepCheck_Result)& aRes = myMap(S);
132 BRepCheck_Status ste = Handle(BRepCheck_Edge)::
133 DownCast(aRes)->CheckPolygonOnTriangulation(TopoDS::Edge(S));
135 if(ste != BRepCheck_NoError)
137 Handle(BRepCheck_Edge)::DownCast(aRes)->SetStatus(ste);
140 catch(Standard_Failure)
143 cout<<"BRepCheck_Analyzer : ";
144 Standard_Failure::Caught()->Print(cout);
147 if ( ! myMap(S).IsNull() )
149 myMap(S)->SetFailStatus(S);
152 if ( ! aRes.IsNull() )
154 aRes->SetFailStatus(exp.Current());
155 aRes->SetFailStatus(S);
159 TopTools_MapOfShape MapS;
161 for (exp.Init(S,TopAbs_VERTEX);exp.More(); exp.Next())
163 const TopoDS_Shape& aVertex = exp.Current();
167 if (MapS.Add(aVertex))
168 myMap(aVertex)->InContext(S);
170 catch(Standard_Failure)
173 cout<<"BRepCheck_Analyzer : ";
174 Standard_Failure::Caught()->Print(cout);
177 if ( ! myMap(S).IsNull() )
178 myMap(S)->SetFailStatus(S);
180 Handle(BRepCheck_Result) aRes = myMap(aVertex);
182 if ( ! aRes.IsNull() )
184 aRes->SetFailStatus(aVertex);
185 aRes->SetFailStatus(S);
187 }//catch(Standard_Failure)
188 }//for (exp.Init(S,TopAbs_VERTEX);exp.More(); exp.Next())
197 TopTools_MapOfShape MapS;
198 for (exp.Init(S,TopAbs_VERTEX);exp.More(); exp.Next())
203 if (MapS.Add(exp.Current()))
205 myMap(exp.Current())->InContext(S);
208 catch(Standard_Failure)
211 cout<<"BRepCheck_Analyzer : ";
212 Standard_Failure::Caught()->Print(cout);
215 if ( ! myMap(S).IsNull() )
217 myMap(S)->SetFailStatus(S);
220 Handle(BRepCheck_Result) aRes = myMap(exp.Current());
222 if ( ! aRes.IsNull() )
224 aRes->SetFailStatus(exp.Current());
225 aRes->SetFailStatus(S);
230 Standard_Boolean performwire = Standard_True;
231 Standard_Boolean isInvalidTolerance = Standard_False;
233 for (exp.Init(S,TopAbs_EDGE);exp.More(); exp.Next())
238 if (MapS.Add(exp.Current()))
240 Handle(BRepCheck_Result)& res = myMap(exp.Current());
244 for ( res->InitContextIterator();
245 res->MoreShapeInContext();
246 res->NextShapeInContext())
248 if(res->ContextualShape().IsSame(S))
252 BRepCheck_ListIteratorOfListOfStatus itl(res->StatusOnShape());
253 for (; itl.More(); itl.Next())
255 BRepCheck_Status ste = itl.Value();
256 if (ste == BRepCheck_NoCurveOnSurface ||
257 ste == BRepCheck_InvalidCurveOnSurface ||
258 ste == BRepCheck_InvalidRange ||
259 ste == BRepCheck_InvalidCurveOnClosedSurface)
261 performwire = Standard_False;
268 catch(Standard_Failure)
271 cout<<"BRepCheck_Analyzer : ";
272 Standard_Failure::Caught()->Print(cout);
275 if ( ! myMap(S).IsNull() )
277 myMap(S)->SetFailStatus(S);
280 Handle(BRepCheck_Result) aRes = myMap(exp.Current());
282 if ( ! aRes.IsNull() )
284 aRes->SetFailStatus(exp.Current());
285 aRes->SetFailStatus(S);
290 Standard_Boolean orientofwires = performwire;
291 for (exp.Init(S,TopAbs_WIRE);exp.More(); exp.Next())
296 Handle(BRepCheck_Result)& res = myMap(exp.Current());
300 for ( res->InitContextIterator();
301 res->MoreShapeInContext();
302 res->NextShapeInContext())
304 if(res->ContextualShape().IsSame(S))
309 BRepCheck_ListIteratorOfListOfStatus itl(res->StatusOnShape());
310 for (; itl.More(); itl.Next())
312 BRepCheck_Status ste = itl.Value();
313 if (ste != BRepCheck_NoError)
315 orientofwires = Standard_False;
321 catch(Standard_Failure)
324 cout<<"BRepCheck_Analyzer : ";
325 Standard_Failure::Caught()->Print(cout);
328 if ( ! myMap(S).IsNull() )
330 myMap(S)->SetFailStatus(S);
333 Handle(BRepCheck_Result) aRes = myMap(exp.Current());
335 if ( ! aRes.IsNull() )
337 aRes->SetFailStatus(exp.Current());
338 aRes->SetFailStatus(S);
346 if(isInvalidTolerance)
348 Handle(BRepCheck_Face)::
349 DownCast(myMap(S))->SetStatus(BRepCheck_InvalidToleranceValue);
351 else if (performwire)
355 Handle(BRepCheck_Face)::DownCast(myMap(S))->
356 OrientationOfWires(Standard_True);// on enregistre
360 Handle(BRepCheck_Face)::DownCast(myMap(S))->SetUnorientable();
365 Handle(BRepCheck_Face)::DownCast(myMap(S))->SetUnorientable();
368 catch(Standard_Failure)
371 cout<<"BRepCheck_Analyzer : ";
372 Standard_Failure::Caught()->Print(cout);
375 if ( ! myMap(S).IsNull() )
377 myMap(S)->SetFailStatus(S);
380 for (exp.Init(S,TopAbs_WIRE);exp.More(); exp.Next())
382 Handle(BRepCheck_Result) aRes = myMap(exp.Current());
384 if ( ! aRes.IsNull() )
386 aRes->SetFailStatus(exp.Current());
387 aRes->SetFailStatus(S);
388 myMap(S)->SetFailStatus(exp.Current());
396 //modified by NIZNHY-PKV Mon Oct 13 14:23:53 2008f
397 //modified by NIZNHY-PKV Mon Oct 13 14:24:04 2008t
402 exp.Init(S,TopAbs_SHELL);
403 for (; exp.More(); exp.Next())
405 const TopoDS_Shape& aShell=exp.Current();
409 myMap(aShell)->InContext(S);
411 catch(Standard_Failure)
414 cout<<"BRepCheck_Analyzer : ";
415 Standard_Failure::Caught()->Print(cout);
418 if ( ! myMap(S).IsNull() )
420 myMap(S)->SetFailStatus(S);
424 Handle(BRepCheck_Result) aRes = myMap(aShell);
427 aRes->SetFailStatus(exp.Current());
428 aRes->SetFailStatus(S);
430 }//catch(Standard_Failure)
431 }//for (; exp.More(); exp.Next())
433 break;//case TopAbs_SOLID
440 //=======================================================================
443 //=======================================================================
445 Standard_Boolean BRepCheck_Analyzer::IsValid(const TopoDS_Shape& S) const
447 if (!myMap(S).IsNull()) {
448 BRepCheck_ListIteratorOfListOfStatus itl;
449 itl.Initialize(myMap(S)->Status());
450 if (itl.Value() != BRepCheck_NoError) { // a voir
451 return Standard_False;
455 for(TopoDS_Iterator theIterator(S);theIterator.More();theIterator.Next()) {
456 if (!IsValid(theIterator.Value())) {
457 return Standard_False;
461 switch (S.ShapeType()) {
464 return ValidSub(S,TopAbs_VERTEX);
469 Standard_Boolean valid = ValidSub(S,TopAbs_WIRE);
470 valid = valid && ValidSub(S,TopAbs_EDGE);
471 valid = valid && ValidSub(S,TopAbs_VERTEX);
477 // return ValidSub(S,TopAbs_FACE);
480 // return ValidSub(S,TopAbs_EDGE);
482 return ValidSub(S,TopAbs_SHELL);
488 return Standard_True;
491 //=======================================================================
492 //function : ValidSub
494 //=======================================================================
496 Standard_Boolean BRepCheck_Analyzer::ValidSub
497 (const TopoDS_Shape& S,
498 const TopAbs_ShapeEnum SubType) const
500 BRepCheck_ListIteratorOfListOfStatus itl;
502 for (exp.Init(S,SubType);exp.More(); exp.Next()) {
503 // for (TopExp_Explorer exp(S,SubType);exp.More(); exp.Next()) {
504 const Handle(BRepCheck_Result)& RV = myMap(exp.Current());
505 for (RV->InitContextIterator();
506 RV->MoreShapeInContext();
507 RV->NextShapeInContext()) {
508 if (RV->ContextualShape().IsSame(S)) {
513 if(!RV->MoreShapeInContext()) break;
515 for (itl.Initialize(RV->StatusOnShape()); itl.More(); itl.Next()) {
516 if (itl.Value() != BRepCheck_NoError) {
517 return Standard_False;
521 return Standard_True ;