1 // Created on: 1995-12-08
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
23 #include <BRepCheck_Analyzer.ixx>
25 #include <BRepCheck_Vertex.hxx>
26 #include <BRepCheck_Edge.hxx>
27 #include <BRepCheck_Wire.hxx>
28 #include <BRepCheck_Face.hxx>
29 #include <BRepCheck_Shell.hxx>
30 #include <BRepCheck_ListIteratorOfListOfStatus.hxx>
32 #include <TopoDS_Iterator.hxx>
33 #include <TopExp_Explorer.hxx>
35 #include <TopTools_MapOfShape.hxx>
37 #include <TopoDS_Face.hxx>
39 #include <Standard_ErrorHandler.hxx>
40 #include <Standard_Failure.hxx>
42 //=======================================================================
45 //=======================================================================
47 void BRepCheck_Analyzer::Init(const TopoDS_Shape& S,
48 const Standard_Boolean B)
51 Standard_NullObject::Raise();
61 //=======================================================================
64 //=======================================================================
66 void BRepCheck_Analyzer::Put(const TopoDS_Shape& S,
67 const Standard_Boolean B)
69 if (!myMap.IsBound(S)) {
70 Handle(BRepCheck_Result) HR;
71 switch (S.ShapeType()) {
73 HR = new BRepCheck_Vertex(TopoDS::Vertex(S));
76 HR = new BRepCheck_Edge(TopoDS::Edge(S));
77 Handle(BRepCheck_Edge)::DownCast(HR)->GeometricControls(B);
80 HR = new BRepCheck_Wire(TopoDS::Wire(S));
81 Handle(BRepCheck_Wire)::DownCast(HR)->GeometricControls(B);
84 HR = new BRepCheck_Face(TopoDS::Face(S));
85 Handle(BRepCheck_Face)::DownCast(HR)->GeometricControls(B);
88 HR = new BRepCheck_Shell(TopoDS::Shell(S));
91 case TopAbs_COMPSOLID:
100 for(TopoDS_Iterator theIterator(S);theIterator.More();theIterator.Next()) {
101 Put(theIterator.Value(),B); // performs minimum on each shape
107 //=======================================================================
110 //=======================================================================
112 void BRepCheck_Analyzer::Perform(const TopoDS_Shape& S)
114 for(TopoDS_Iterator theIterator(S);theIterator.More();theIterator.Next()) {
115 Perform(theIterator.Value());
118 TopAbs_ShapeEnum styp;
121 styp = S.ShapeType();
124 // modified by NIZHNY-MKK Wed May 19 16:56:16 2004.BEGIN
125 // There is no need to check anything.
126 // if (myShape.IsSame(S)) {
127 // myMap(S)->Blind();
129 // modified by NIZHNY-MKK Wed May 19 16:56:23 2004.END
133 // Modified by skv - Tue Apr 27 11:38:08 2004 Begin
134 // There is no need to check anything except vertices on single edge.
135 // if (myShape.IsSame(S)) {
136 // myMap(S)->Blind();
138 // Modified by skv - Tue Apr 27 11:38:09 2004 End
139 TopTools_MapOfShape MapS;
141 for (exp.Init(S,TopAbs_VERTEX);exp.More(); exp.Next()) {
142 const TopoDS_Shape& aVertex = exp.Current();
145 if (MapS.Add(aVertex)) {
146 myMap(aVertex)->InContext(S);
149 catch(Standard_Failure) {
151 cout<<"BRepCheck_Analyzer : ";
152 Standard_Failure::Caught()->Print(cout);
155 if ( ! myMap(S).IsNull() ) {
156 myMap(S)->SetFailStatus(S);
158 Handle(BRepCheck_Result) aRes = myMap(aVertex);
159 if ( ! aRes.IsNull() ) {
160 aRes->SetFailStatus(aVertex);
161 aRes->SetFailStatus(S);
168 // Modified by Sergey KHROMOV - Mon May 6 15:53:39 2002 Begin
169 // There is no need to check the orientation of a single wire
170 // (not in context of face).
172 // if (myShape.IsSame(S)) {
173 // Handle(BRepCheck_Wire)::DownCast(myMap(S))->Orientation(TopoDS_Face(),
177 // Modified by Sergey KHROMOV - Mon May 6 15:53:40 2002 End
181 TopTools_MapOfShape MapS;
182 for (exp.Init(S,TopAbs_VERTEX);exp.More(); exp.Next()) {
185 if (MapS.Add(exp.Current())) {
186 myMap(exp.Current())->InContext(S);
189 catch(Standard_Failure) {
191 cout<<"BRepCheck_Analyzer : ";
192 Standard_Failure::Caught()->Print(cout);
195 if ( ! myMap(S).IsNull() ) {
196 myMap(S)->SetFailStatus(S);
198 Handle(BRepCheck_Result) aRes = myMap(exp.Current());
200 if ( ! aRes.IsNull() ) {
201 aRes->SetFailStatus(exp.Current());
202 aRes->SetFailStatus(S);
206 Standard_Boolean performwire = Standard_True;
208 for (exp.Init(S,TopAbs_EDGE);exp.More(); exp.Next()) {
211 if (MapS.Add(exp.Current())) {
212 Handle(BRepCheck_Result)& res = myMap(exp.Current());
215 for (res->InitContextIterator();
216 res->MoreShapeInContext();
217 res->NextShapeInContext()) {
218 if(res->ContextualShape().IsSame(S)) {
222 BRepCheck_ListIteratorOfListOfStatus itl(res->StatusOnShape());
223 for (; itl.More(); itl.Next()) {
224 BRepCheck_Status ste = itl.Value();
225 if (ste == BRepCheck_NoCurveOnSurface ||
226 ste == BRepCheck_InvalidCurveOnSurface ||
227 ste == BRepCheck_InvalidRange ||
228 ste == BRepCheck_InvalidCurveOnClosedSurface) {
229 performwire = Standard_False;
236 catch(Standard_Failure) {
238 cout<<"BRepCheck_Analyzer : ";
239 Standard_Failure::Caught()->Print(cout);
243 if ( ! myMap(S).IsNull() ) {
244 myMap(S)->SetFailStatus(S);
246 Handle(BRepCheck_Result) aRes = myMap(exp.Current());
248 if ( ! aRes.IsNull() ) {
249 aRes->SetFailStatus(exp.Current());
250 aRes->SetFailStatus(S);
254 Standard_Boolean orientofwires = performwire;
255 for (exp.Init(S,TopAbs_WIRE);exp.More(); exp.Next()) {
258 Handle(BRepCheck_Result)& res = myMap(exp.Current());
261 for (res->InitContextIterator();
262 res->MoreShapeInContext();
263 res->NextShapeInContext()) {
264 if(res->ContextualShape().IsSame(S)) {
268 BRepCheck_ListIteratorOfListOfStatus itl(res->StatusOnShape());
269 for (; itl.More(); itl.Next()) {
270 BRepCheck_Status ste = itl.Value();
271 if (ste != BRepCheck_NoError) {
272 orientofwires = Standard_False;
278 catch(Standard_Failure) {
280 cout<<"BRepCheck_Analyzer : ";
281 Standard_Failure::Caught()->Print(cout);
284 if ( ! myMap(S).IsNull() ) {
285 myMap(S)->SetFailStatus(S);
287 Handle(BRepCheck_Result) aRes = myMap(exp.Current());
289 if ( ! aRes.IsNull() ) {
290 aRes->SetFailStatus(exp.Current());
291 aRes->SetFailStatus(S);
300 Handle(BRepCheck_Face)::DownCast(myMap(S))->
301 OrientationOfWires(Standard_True);// on enregistre
304 // Handle(BRepCheck_Face)::DownCast(myMap(S))->
305 // IntersectWires(Standard_True); // on enregistre
308 Handle(BRepCheck_Face)::DownCast(myMap(S))->SetUnorientable();
312 Handle(BRepCheck_Face)::DownCast(myMap(S))->SetUnorientable();
315 catch(Standard_Failure) {
317 cout<<"BRepCheck_Analyzer : ";
318 Standard_Failure::Caught()->Print(cout);
322 if ( ! myMap(S).IsNull() ) {
323 myMap(S)->SetFailStatus(S);
326 for (exp.Init(S,TopAbs_WIRE);exp.More(); exp.Next()) {
327 Handle(BRepCheck_Result) aRes = myMap(exp.Current());
329 if ( ! aRes.IsNull() ) {
330 aRes->SetFailStatus(exp.Current());
331 aRes->SetFailStatus(S);
332 myMap(S)->SetFailStatus(exp.Current());
340 //modified by NIZNHY-PKV Mon Oct 13 14:23:53 2008f
342 Standard_Boolean VerifyOrientation, bFlag;
344 VerifyOrientation = Standard_True;
346 exp.Init(S,TopAbs_FACE);
347 for (; exp.More(); exp.Next()) {
348 const TopoDS_Shape& aF=exp.Current();
351 bFlag= !(Handle(BRepCheck_Face)::DownCast(myMap(aF))->IsUnorientable());
352 VerifyOrientation = (VerifyOrientation && bFlag);
354 catch(Standard_Failure) {
356 cout<<"BRepCheck_Analyzer : ";
357 Standard_Failure::Caught()->Print(cout);
361 if ( ! myMap(S).IsNull() ) {
362 myMap(S)->SetFailStatus(S);
364 Handle(BRepCheck_Result) aRes = myMap(exp.Current());
366 if ( ! aRes.IsNull() ) {
367 aRes->SetFailStatus(exp.Current());
368 aRes->SetFailStatus(S);
374 if (VerifyOrientation) {
375 Handle(BRepCheck_Shell)::DownCast(myMap(S))->Orientation(Standard_True);
378 Handle(BRepCheck_Shell)::DownCast(myMap(S))->SetUnorientable();
381 catch(Standard_Failure) {
383 cout<<"BRepCheck_Analyzer : ";
384 Standard_Failure::Caught()->Print(cout);
388 if ( ! myMap(S).IsNull() ) {
389 myMap(S)->SetFailStatus(S);
391 exp.Init(S,TopAbs_FACE);
392 for (; exp.More(); exp.Next()) {
393 Handle(BRepCheck_Result) aRes = myMap(exp.Current());
394 if ( ! aRes.IsNull() ) {
395 aRes->SetFailStatus(exp.Current());
396 aRes->SetFailStatus(S);
397 myMap(S)->SetFailStatus(exp.Current());
403 //modified by NIZNHY-PKV Mon Oct 13 14:24:04 2008t
407 exp.Init(S,TopAbs_SHELL);
408 for (; exp.More(); exp.Next()) {
409 const TopoDS_Shape& aShell=exp.Current();
412 myMap(aShell)->InContext(S);
414 catch(Standard_Failure) {
416 cout<<"BRepCheck_Analyzer : ";
417 Standard_Failure::Caught()->Print(cout);
420 if ( ! myMap(S).IsNull() ) {
421 myMap(S)->SetFailStatus(S);
424 Handle(BRepCheck_Result) aRes = myMap(aShell);
425 if (!aRes.IsNull() ) {
426 aRes->SetFailStatus(exp.Current());
427 aRes->SetFailStatus(S);
432 break;//case TopAbs_SOLID
439 //=======================================================================
442 //=======================================================================
444 Standard_Boolean BRepCheck_Analyzer::IsValid(const TopoDS_Shape& S) const
446 if (!myMap(S).IsNull()) {
447 BRepCheck_ListIteratorOfListOfStatus itl;
448 itl.Initialize(myMap(S)->Status());
449 if (itl.Value() != BRepCheck_NoError) { // a voir
450 return Standard_False;
454 for(TopoDS_Iterator theIterator(S);theIterator.More();theIterator.Next()) {
455 if (!IsValid(theIterator.Value())) {
456 return Standard_False;
460 switch (S.ShapeType()) {
463 return ValidSub(S,TopAbs_VERTEX);
468 Standard_Boolean valid = ValidSub(S,TopAbs_WIRE);
469 valid = valid && ValidSub(S,TopAbs_EDGE);
470 valid = valid && ValidSub(S,TopAbs_VERTEX);
476 // return ValidSub(S,TopAbs_FACE);
479 // return ValidSub(S,TopAbs_EDGE);
481 return ValidSub(S,TopAbs_SHELL);
487 return Standard_True;
490 //=======================================================================
491 //function : ValidSub
493 //=======================================================================
495 Standard_Boolean BRepCheck_Analyzer::ValidSub
496 (const TopoDS_Shape& S,
497 const TopAbs_ShapeEnum SubType) const
499 BRepCheck_ListIteratorOfListOfStatus itl;
501 for (exp.Init(S,SubType);exp.More(); exp.Next()) {
502 // for (TopExp_Explorer exp(S,SubType);exp.More(); exp.Next()) {
503 const Handle(BRepCheck_Result)& RV = myMap(exp.Current());
504 for (RV->InitContextIterator();
505 RV->MoreShapeInContext();
506 RV->NextShapeInContext()) {
507 if (RV->ContextualShape().IsSame(S)) {
512 if(!RV->MoreShapeInContext()) break;
514 for (itl.Initialize(RV->StatusOnShape()); itl.More(); itl.Next()) {
515 if (itl.Value() != BRepCheck_NoError) {
516 return Standard_False;
520 return Standard_True ;