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
9 // under the terms of the GNU Lesser General Public 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();
116 // modified by NIZHNY-MKK Wed May 19 16:56:16 2004.BEGIN
117 // There is no need to check anything.
118 // if (myShape.IsSame(S)) {
119 // myMap(S)->Blind();
121 // modified by NIZHNY-MKK Wed May 19 16:56:23 2004.END
125 // Modified by skv - Tue Apr 27 11:38:08 2004 Begin
126 // There is no need to check anything except vertices on single edge.
127 // if (myShape.IsSame(S)) {
128 // myMap(S)->Blind();
130 // Modified by skv - Tue Apr 27 11:38:09 2004 End
131 TopTools_MapOfShape MapS;
133 for (exp.Init(S,TopAbs_VERTEX);exp.More(); exp.Next()) {
134 const TopoDS_Shape& aVertex = exp.Current();
137 if (MapS.Add(aVertex)) {
138 myMap(aVertex)->InContext(S);
141 catch(Standard_Failure) {
143 cout<<"BRepCheck_Analyzer : ";
144 Standard_Failure::Caught()->Print(cout);
147 if ( ! myMap(S).IsNull() ) {
148 myMap(S)->SetFailStatus(S);
150 Handle(BRepCheck_Result) aRes = myMap(aVertex);
151 if ( ! aRes.IsNull() ) {
152 aRes->SetFailStatus(aVertex);
153 aRes->SetFailStatus(S);
160 // Modified by Sergey KHROMOV - Mon May 6 15:53:39 2002 Begin
161 // There is no need to check the orientation of a single wire
162 // (not in context of face).
164 // if (myShape.IsSame(S)) {
165 // Handle(BRepCheck_Wire)::DownCast(myMap(S))->Orientation(TopoDS_Face(),
169 // Modified by Sergey KHROMOV - Mon May 6 15:53:40 2002 End
173 TopTools_MapOfShape MapS;
174 for (exp.Init(S,TopAbs_VERTEX);exp.More(); exp.Next()) {
177 if (MapS.Add(exp.Current())) {
178 myMap(exp.Current())->InContext(S);
181 catch(Standard_Failure) {
183 cout<<"BRepCheck_Analyzer : ";
184 Standard_Failure::Caught()->Print(cout);
187 if ( ! myMap(S).IsNull() ) {
188 myMap(S)->SetFailStatus(S);
190 Handle(BRepCheck_Result) aRes = myMap(exp.Current());
192 if ( ! aRes.IsNull() ) {
193 aRes->SetFailStatus(exp.Current());
194 aRes->SetFailStatus(S);
198 Standard_Boolean performwire = Standard_True;
200 for (exp.Init(S,TopAbs_EDGE);exp.More(); exp.Next()) {
203 if (MapS.Add(exp.Current())) {
204 Handle(BRepCheck_Result)& res = myMap(exp.Current());
207 for (res->InitContextIterator();
208 res->MoreShapeInContext();
209 res->NextShapeInContext()) {
210 if(res->ContextualShape().IsSame(S)) {
214 BRepCheck_ListIteratorOfListOfStatus itl(res->StatusOnShape());
215 for (; itl.More(); itl.Next()) {
216 BRepCheck_Status ste = itl.Value();
217 if (ste == BRepCheck_NoCurveOnSurface ||
218 ste == BRepCheck_InvalidCurveOnSurface ||
219 ste == BRepCheck_InvalidRange ||
220 ste == BRepCheck_InvalidCurveOnClosedSurface) {
221 performwire = Standard_False;
228 catch(Standard_Failure) {
230 cout<<"BRepCheck_Analyzer : ";
231 Standard_Failure::Caught()->Print(cout);
235 if ( ! myMap(S).IsNull() ) {
236 myMap(S)->SetFailStatus(S);
238 Handle(BRepCheck_Result) aRes = myMap(exp.Current());
240 if ( ! aRes.IsNull() ) {
241 aRes->SetFailStatus(exp.Current());
242 aRes->SetFailStatus(S);
246 Standard_Boolean orientofwires = performwire;
247 for (exp.Init(S,TopAbs_WIRE);exp.More(); exp.Next()) {
250 Handle(BRepCheck_Result)& res = myMap(exp.Current());
253 for (res->InitContextIterator();
254 res->MoreShapeInContext();
255 res->NextShapeInContext()) {
256 if(res->ContextualShape().IsSame(S)) {
260 BRepCheck_ListIteratorOfListOfStatus itl(res->StatusOnShape());
261 for (; itl.More(); itl.Next()) {
262 BRepCheck_Status ste = itl.Value();
263 if (ste != BRepCheck_NoError) {
264 orientofwires = Standard_False;
270 catch(Standard_Failure) {
272 cout<<"BRepCheck_Analyzer : ";
273 Standard_Failure::Caught()->Print(cout);
276 if ( ! myMap(S).IsNull() ) {
277 myMap(S)->SetFailStatus(S);
279 Handle(BRepCheck_Result) aRes = myMap(exp.Current());
281 if ( ! aRes.IsNull() ) {
282 aRes->SetFailStatus(exp.Current());
283 aRes->SetFailStatus(S);
292 Handle(BRepCheck_Face)::DownCast(myMap(S))->
293 OrientationOfWires(Standard_True);// on enregistre
296 // Handle(BRepCheck_Face)::DownCast(myMap(S))->
297 // IntersectWires(Standard_True); // on enregistre
300 Handle(BRepCheck_Face)::DownCast(myMap(S))->SetUnorientable();
304 Handle(BRepCheck_Face)::DownCast(myMap(S))->SetUnorientable();
307 catch(Standard_Failure) {
309 cout<<"BRepCheck_Analyzer : ";
310 Standard_Failure::Caught()->Print(cout);
314 if ( ! myMap(S).IsNull() ) {
315 myMap(S)->SetFailStatus(S);
318 for (exp.Init(S,TopAbs_WIRE);exp.More(); exp.Next()) {
319 Handle(BRepCheck_Result) aRes = myMap(exp.Current());
321 if ( ! aRes.IsNull() ) {
322 aRes->SetFailStatus(exp.Current());
323 aRes->SetFailStatus(S);
324 myMap(S)->SetFailStatus(exp.Current());
332 //modified by NIZNHY-PKV Mon Oct 13 14:23:53 2008f
334 Standard_Boolean VerifyOrientation, bFlag;
336 VerifyOrientation = Standard_True;
338 exp.Init(S,TopAbs_FACE);
339 for (; exp.More(); exp.Next()) {
340 const TopoDS_Shape& aF=exp.Current();
343 bFlag= !(Handle(BRepCheck_Face)::DownCast(myMap(aF))->IsUnorientable());
344 VerifyOrientation = (VerifyOrientation && bFlag);
346 catch(Standard_Failure) {
348 cout<<"BRepCheck_Analyzer : ";
349 Standard_Failure::Caught()->Print(cout);
353 if ( ! myMap(S).IsNull() ) {
354 myMap(S)->SetFailStatus(S);
356 Handle(BRepCheck_Result) aRes = myMap(exp.Current());
358 if ( ! aRes.IsNull() ) {
359 aRes->SetFailStatus(exp.Current());
360 aRes->SetFailStatus(S);
366 if (VerifyOrientation) {
367 Handle(BRepCheck_Shell)::DownCast(myMap(S))->Orientation(Standard_True);
370 Handle(BRepCheck_Shell)::DownCast(myMap(S))->SetUnorientable();
373 catch(Standard_Failure) {
375 cout<<"BRepCheck_Analyzer : ";
376 Standard_Failure::Caught()->Print(cout);
380 if ( ! myMap(S).IsNull() ) {
381 myMap(S)->SetFailStatus(S);
383 exp.Init(S,TopAbs_FACE);
384 for (; exp.More(); exp.Next()) {
385 Handle(BRepCheck_Result) aRes = myMap(exp.Current());
386 if ( ! aRes.IsNull() ) {
387 aRes->SetFailStatus(exp.Current());
388 aRes->SetFailStatus(S);
389 myMap(S)->SetFailStatus(exp.Current());
395 //modified by NIZNHY-PKV Mon Oct 13 14:24:04 2008t
399 exp.Init(S,TopAbs_SHELL);
400 for (; exp.More(); exp.Next()) {
401 const TopoDS_Shape& aShell=exp.Current();
404 myMap(aShell)->InContext(S);
406 catch(Standard_Failure) {
408 cout<<"BRepCheck_Analyzer : ";
409 Standard_Failure::Caught()->Print(cout);
412 if ( ! myMap(S).IsNull() ) {
413 myMap(S)->SetFailStatus(S);
416 Handle(BRepCheck_Result) aRes = myMap(aShell);
417 if (!aRes.IsNull() ) {
418 aRes->SetFailStatus(exp.Current());
419 aRes->SetFailStatus(S);
424 break;//case TopAbs_SOLID
431 //=======================================================================
434 //=======================================================================
436 Standard_Boolean BRepCheck_Analyzer::IsValid(const TopoDS_Shape& S) const
438 if (!myMap(S).IsNull()) {
439 BRepCheck_ListIteratorOfListOfStatus itl;
440 itl.Initialize(myMap(S)->Status());
441 if (itl.Value() != BRepCheck_NoError) { // a voir
442 return Standard_False;
446 for(TopoDS_Iterator theIterator(S);theIterator.More();theIterator.Next()) {
447 if (!IsValid(theIterator.Value())) {
448 return Standard_False;
452 switch (S.ShapeType()) {
455 return ValidSub(S,TopAbs_VERTEX);
460 Standard_Boolean valid = ValidSub(S,TopAbs_WIRE);
461 valid = valid && ValidSub(S,TopAbs_EDGE);
462 valid = valid && ValidSub(S,TopAbs_VERTEX);
468 // return ValidSub(S,TopAbs_FACE);
471 // return ValidSub(S,TopAbs_EDGE);
473 return ValidSub(S,TopAbs_SHELL);
479 return Standard_True;
482 //=======================================================================
483 //function : ValidSub
485 //=======================================================================
487 Standard_Boolean BRepCheck_Analyzer::ValidSub
488 (const TopoDS_Shape& S,
489 const TopAbs_ShapeEnum SubType) const
491 BRepCheck_ListIteratorOfListOfStatus itl;
493 for (exp.Init(S,SubType);exp.More(); exp.Next()) {
494 // for (TopExp_Explorer exp(S,SubType);exp.More(); exp.Next()) {
495 const Handle(BRepCheck_Result)& RV = myMap(exp.Current());
496 for (RV->InitContextIterator();
497 RV->MoreShapeInContext();
498 RV->NextShapeInContext()) {
499 if (RV->ContextualShape().IsSame(S)) {
504 if(!RV->MoreShapeInContext()) break;
506 for (itl.Initialize(RV->StatusOnShape()); itl.More(); itl.Next()) {
507 if (itl.Value() != BRepCheck_NoError) {
508 return Standard_False;
512 return Standard_True ;