1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <Standard_Stream.hxx>
22 #include <GEOMImpl_IMeasureOperations.hxx>
24 #include <GEOMImpl_Types.hxx>
25 #include <GEOMImpl_MeasureDriver.hxx>
26 #include <GEOMImpl_IMeasure.hxx>
28 #include <GEOM_Function.hxx>
29 #include <GEOM_PythonDump.hxx>
31 #include "utilities.h"
33 #include <Utils_ExceptHandlers.hxx>
35 #include <TFunction_DriverTable.hxx>
36 #include <TFunction_Driver.hxx>
37 #include <TFunction_Logbook.hxx>
38 #include <TDF_Tool.hxx>
40 #include <BRep_Tool.hxx>
41 #include <BRepCheck.hxx>
42 #include <BRepCheck_Result.hxx>
43 #include <BRepCheck_ListIteratorOfListOfStatus.hxx>
44 #include <BRepGProp.hxx>
45 #include <BRepBndLib.hxx>
46 #include <BRepExtrema_DistShapeShape.hxx>
48 #include <Bnd_Box.hxx>
50 #include <GProp_GProps.hxx>
51 #include <GProp_PrincipalProps.hxx>
55 #include <TopoDS_Edge.hxx>
56 #include <TopoDS_Face.hxx>
57 #include <TopoDS_Shape.hxx>
58 #include <TopoDS_Vertex.hxx>
59 #include <TopoDS_Iterator.hxx>
60 #include <TopExp_Explorer.hxx>
61 #include <TopTools_MapOfShape.hxx>
62 #include <TopTools_ListOfShape.hxx>
63 #include <TopTools_ListIteratorOfListOfShape.hxx>
65 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
67 //=============================================================================
71 //=============================================================================
72 GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations (GEOM_Engine* theEngine, int theDocID)
73 : GEOM_IOperations(theEngine, theDocID)
75 MESSAGE("GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations");
78 //=============================================================================
82 //=============================================================================
83 GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations()
85 MESSAGE("GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations");
89 //=============================================================================
93 //=============================================================================
94 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetCentreOfMass
95 (Handle(GEOM_Object) theShape)
99 if (theShape.IsNull()) return NULL;
101 //Add a new CentreOfMass object
102 Handle(GEOM_Object) aCDG = GetEngine()->AddObject(GetDocID(), GEOM_CDG);
104 //Add a new CentreOfMass function
105 Handle(GEOM_Function) aFunction =
106 aCDG->AddFunction(GEOMImpl_MeasureDriver::GetID(), CDG_MEASURE);
107 if (aFunction.IsNull()) return NULL;
109 //Check if the function is set correctly
110 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
112 GEOMImpl_IMeasure aCI (aFunction);
114 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
115 if (aRefShape.IsNull()) return NULL;
117 aCI.SetBase(aRefShape);
119 //Compute the CentreOfMass value
121 if (!GetSolver()->ComputeFunction(aFunction)) {
122 SetErrorCode("Measure driver failed to compute centre of mass");
126 catch (Standard_Failure) {
127 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
128 SetErrorCode(aFail->GetMessageString());
132 //Make a Python command
133 GEOM::TPythonDump(aFunction) << aCDG << " = geompy.MakeCDG(" << theShape << ")";
139 //=============================================================================
143 //=============================================================================
144 void GEOMImpl_IMeasureOperations::GetBasicProperties (Handle(GEOM_Object) theShape,
145 Standard_Real& theLength,
146 Standard_Real& theSurfArea,
147 Standard_Real& theVolume)
151 if (theShape.IsNull()) return;
153 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
154 if (aRefShape.IsNull()) return;
156 TopoDS_Shape aShape = aRefShape->GetValue();
157 if (aShape.IsNull()) {
158 SetErrorCode("The Objects has NULL Shape");
162 //Compute the parameters
163 GProp_GProps LProps, SProps;
165 BRepGProp::LinearProperties(aShape, LProps);
166 theLength = LProps.Mass();
168 BRepGProp::SurfaceProperties(aShape, SProps);
169 theSurfArea = SProps.Mass();
172 if (aShape.ShapeType() < TopAbs_SHELL) {
173 for (TopExp_Explorer Exp (aShape, TopAbs_SOLID); Exp.More(); Exp.Next()) {
175 BRepGProp::VolumeProperties(Exp.Current(), VProps);
176 theVolume += VProps.Mass();
180 catch (Standard_Failure) {
181 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
182 SetErrorCode(aFail->GetMessageString());
189 //=============================================================================
193 //=============================================================================
194 void GEOMImpl_IMeasureOperations::GetInertia
195 (Handle(GEOM_Object) theShape,
196 Standard_Real& I11, Standard_Real& I12, Standard_Real& I13,
197 Standard_Real& I21, Standard_Real& I22, Standard_Real& I23,
198 Standard_Real& I31, Standard_Real& I32, Standard_Real& I33,
199 Standard_Real& Ix , Standard_Real& Iy , Standard_Real& Iz)
203 if (theShape.IsNull()) return;
205 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
206 if (aRefShape.IsNull()) return;
208 TopoDS_Shape aShape = aRefShape->GetValue();
209 if (aShape.IsNull()) {
210 SetErrorCode("The Objects has NULL Shape");
214 //Compute the parameters
218 if (aShape.ShapeType() == TopAbs_VERTEX ||
219 aShape.ShapeType() == TopAbs_EDGE ||
220 aShape.ShapeType() == TopAbs_WIRE) {
221 BRepGProp::LinearProperties(aShape, System);
222 } else if (aShape.ShapeType() == TopAbs_FACE ||
223 aShape.ShapeType() == TopAbs_SHELL) {
224 BRepGProp::SurfaceProperties(aShape, System);
226 BRepGProp::VolumeProperties(aShape, System);
228 gp_Mat I = System.MatrixOfInertia();
242 GProp_PrincipalProps Pr = System.PrincipalProperties();
243 Pr.Moments(Ix,Iy,Iz);
245 catch (Standard_Failure) {
246 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
247 SetErrorCode(aFail->GetMessageString());
254 //=============================================================================
258 //=============================================================================
259 void GEOMImpl_IMeasureOperations::GetBoundingBox
260 (Handle(GEOM_Object) theShape,
261 Standard_Real& Xmin, Standard_Real& Xmax,
262 Standard_Real& Ymin, Standard_Real& Ymax,
263 Standard_Real& Zmin, Standard_Real& Zmax)
267 if (theShape.IsNull()) return;
269 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
270 if (aRefShape.IsNull()) return;
272 TopoDS_Shape aShape = aRefShape->GetValue();
273 if (aShape.IsNull()) {
274 SetErrorCode("The Objects has NULL Shape");
278 //Compute the parameters
282 BRepBndLib::Add(aShape, B);
283 B.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
285 catch (Standard_Failure) {
286 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
287 SetErrorCode(aFail->GetMessageString());
294 //=============================================================================
298 //=============================================================================
299 void GEOMImpl_IMeasureOperations::GetTolerance
300 (Handle(GEOM_Object) theShape,
301 Standard_Real& FaceMin, Standard_Real& FaceMax,
302 Standard_Real& EdgeMin, Standard_Real& EdgeMax,
303 Standard_Real& VertMin, Standard_Real& VertMax)
307 if (theShape.IsNull()) return;
309 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
310 if (aRefShape.IsNull()) return;
312 TopoDS_Shape aShape = aRefShape->GetValue();
313 if (aShape.IsNull()) {
314 SetErrorCode("The Objects has NULL Shape");
318 //Compute the parameters
320 FaceMin = EdgeMin = VertMin = RealLast();
321 FaceMax = EdgeMax = VertMax = -RealLast();
324 for (TopExp_Explorer ExF (aShape, TopAbs_FACE); ExF.More(); ExF.Next()) {
325 TopoDS_Face Face = TopoDS::Face(ExF.Current());
326 T = BRep_Tool::Tolerance(Face);
332 for (TopExp_Explorer ExE (aShape, TopAbs_EDGE); ExE.More(); ExE.Next()) {
333 TopoDS_Edge Edge = TopoDS::Edge(ExE.Current());
334 T = BRep_Tool::Tolerance(Edge);
340 for (TopExp_Explorer ExV (aShape, TopAbs_VERTEX); ExV.More(); ExV.Next()) {
341 TopoDS_Vertex Vertex = TopoDS::Vertex(ExV.Current());
342 T = BRep_Tool::Tolerance(Vertex);
349 catch (Standard_Failure) {
350 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
351 SetErrorCode(aFail->GetMessageString());
358 //=============================================================================
362 //=============================================================================
363 bool GEOMImpl_IMeasureOperations::CheckShape (Handle(GEOM_Object) theShape,
364 const Standard_Boolean theIsCheckGeom,
365 TCollection_AsciiString& theDump)
369 if (theShape.IsNull()) return false;
371 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
372 if (aRefShape.IsNull()) return false;
374 TopoDS_Shape aShape = aRefShape->GetValue();
375 if (aShape.IsNull()) {
376 SetErrorCode("The Objects has NULL Shape");
380 //Compute the parameters
381 bool isValid = false;
383 BRepCheck_Analyzer ana (aShape, theIsCheckGeom);
388 StructuralDump(ana, aShape, theDump);
391 catch (Standard_Failure) {
392 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
393 SetErrorCode(aFail->GetMessageString());
401 //=============================================================================
405 //=============================================================================
406 TCollection_AsciiString GEOMImpl_IMeasureOperations::WhatIs (Handle(GEOM_Object) theShape)
410 TCollection_AsciiString Astr;
412 if (theShape.IsNull()) return Astr;
414 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
415 if (aRefShape.IsNull()) return Astr;
417 TopoDS_Shape aShape = aRefShape->GetValue();
418 if (aShape.IsNull()) {
419 SetErrorCode("The Objects has NULL Shape");
423 //Compute the parameters
424 if (aShape.ShapeType() == TopAbs_EDGE) {
425 if (BRep_Tool::Degenerated(TopoDS::Edge(aShape))) {
426 Astr = Astr + " It is a degenerated edge \n";
430 Astr = Astr + " Number of sub-shapes : \n";
433 int iType, nbTypes [TopAbs_SHAPE];
434 for (iType = 0; iType < TopAbs_SHAPE; ++iType)
436 nbTypes[aShape.ShapeType()]++;
438 TopTools_MapOfShape aMapOfShape;
439 aMapOfShape.Add(aShape);
440 TopTools_ListOfShape aListOfShape;
441 aListOfShape.Append(aShape);
443 TopTools_ListIteratorOfListOfShape itL (aListOfShape);
444 for (; itL.More(); itL.Next()) {
445 TopoDS_Iterator it (itL.Value());
446 for (; it.More(); it.Next()) {
447 TopoDS_Shape s = it.Value();
448 if (aMapOfShape.Add(s)) {
449 aListOfShape.Append(s);
450 nbTypes[s.ShapeType()]++;
455 Astr = Astr + " VERTEX : " + TCollection_AsciiString(nbTypes[TopAbs_VERTEX]) + "\n";
456 Astr = Astr + " EDGE : " + TCollection_AsciiString(nbTypes[TopAbs_EDGE]) + "\n";
457 Astr = Astr + " WIRE : " + TCollection_AsciiString(nbTypes[TopAbs_WIRE]) + "\n";
458 Astr = Astr + " FACE : " + TCollection_AsciiString(nbTypes[TopAbs_FACE]) + "\n";
459 Astr = Astr + " SHELL : " + TCollection_AsciiString(nbTypes[TopAbs_SHELL]) + "\n";
460 Astr = Astr + " SOLID : " + TCollection_AsciiString(nbTypes[TopAbs_SOLID]) + "\n";
461 Astr = Astr + " COMPSOLID : " + TCollection_AsciiString(nbTypes[TopAbs_COMPSOLID]) + "\n";
462 Astr = Astr + " COMPOUND : " + TCollection_AsciiString(nbTypes[TopAbs_COMPOUND]) + "\n";
463 Astr = Astr + " SHAPE : " + TCollection_AsciiString(aMapOfShape.Extent());
465 catch (Standard_Failure) {
466 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
467 SetErrorCode(aFail->GetMessageString());
475 //=============================================================================
479 //=============================================================================
480 Standard_Real GEOMImpl_IMeasureOperations::GetMinDistance
481 (Handle(GEOM_Object) theShape1, Handle(GEOM_Object) theShape2,
482 Standard_Real& X1, Standard_Real& Y1, Standard_Real& Z1,
483 Standard_Real& X2, Standard_Real& Y2, Standard_Real& Z2)
486 Standard_Real MinDist = 1.e9;
488 if (theShape1.IsNull() || theShape2.IsNull()) return MinDist;
490 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
491 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
492 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return MinDist;
494 TopoDS_Shape aShape1 = aRefShape1->GetValue();
495 TopoDS_Shape aShape2 = aRefShape2->GetValue();
496 if (aShape1.IsNull() || aShape2.IsNull()) {
497 SetErrorCode("One of Objects has NULL Shape");
501 //Compute the parameters
503 BRepExtrema_DistShapeShape dst (aShape1, aShape2);
505 gp_Pnt PMin1, PMin2, P1, P2;
507 for (int i = 1; i <= dst.NbSolution(); i++) {
508 P1 = dst.PointOnShape1(i);
509 P2 = dst.PointOnShape2(i);
511 Standard_Real Dist = P1.Distance(P2);
512 if (MinDist > Dist) {
519 PMin1.Coord(X1, Y1, Z1);
520 PMin2.Coord(X2, Y2, Z2);
523 catch (Standard_Failure) {
524 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
525 SetErrorCode(aFail->GetMessageString());
533 //=======================================================================
534 //function : PointCoordinates
535 //purpose : Get coordinates of point
536 //=======================================================================
537 void GEOMImpl_IMeasureOperations::PointCoordinates( Handle(GEOM_Object) theShape,
538 Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ )
542 if ( theShape.IsNull() )
545 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
546 if ( aRefShape.IsNull() )
549 TopoDS_Shape aShape = aRefShape->GetValue();
550 if ( aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX )
552 SetErrorCode( "Shape must be a vertex" );
558 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
564 catch ( Standard_Failure )
566 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
567 SetErrorCode( aFail->GetMessageString() );
571 //=======================================================================
572 //function : StructuralDump
573 //purpose : Structural (data exchange) style of output.
574 //=======================================================================
575 void GEOMImpl_IMeasureOperations::StructuralDump (const BRepCheck_Analyzer& theAna,
576 const TopoDS_Shape& theShape,
577 TCollection_AsciiString& theDump)
581 theDump += " -- The Shape has problems :\n";
582 theDump += " Check Count\n";
583 theDump += " ------------------------------------------------\n";
585 Standard_Integer last_stat = (Standard_Integer)BRepCheck_CheckFail;
586 Handle(TColStd_HArray1OfInteger) NbProblems =
587 new TColStd_HArray1OfInteger(1, last_stat);
588 for (i = 1; i <= last_stat; i++)
589 NbProblems->SetValue(i,0);
591 Handle(TopTools_HSequenceOfShape) sl;
592 sl = new TopTools_HSequenceOfShape();
593 TopTools_DataMapOfShapeListOfShape theMap;
595 GetProblemShapes(theAna, theShape, sl, NbProblems, theMap);
598 Standard_Integer count = 0;
599 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnCurve);
601 theDump += " Invalid Point on Curve ................... ";
602 theDump += TCollection_AsciiString(count) + "\n";
604 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnCurveOnSurface);
606 theDump += " Invalid Point on CurveOnSurface .......... ";
607 theDump += TCollection_AsciiString(count) + "\n";
609 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnSurface);
611 theDump += " Invalid Point on Surface ................. ";
612 theDump += TCollection_AsciiString(count) + "\n";
614 count = NbProblems->Value((Standard_Integer)BRepCheck_No3DCurve);
616 theDump += " No 3D Curve .............................. ";
617 theDump += TCollection_AsciiString(count) + "\n";
619 count = NbProblems->Value((Standard_Integer)BRepCheck_Multiple3DCurve);
621 theDump += " Multiple 3D Curve ........................ ";
622 theDump += TCollection_AsciiString(count) + "\n";
624 count = NbProblems->Value((Standard_Integer)BRepCheck_Invalid3DCurve);
626 theDump += " Invalid 3D Curve ......................... ";
627 theDump += TCollection_AsciiString(count) + "\n";
629 count = NbProblems->Value((Standard_Integer)BRepCheck_NoCurveOnSurface);
631 theDump += " No Curve on Surface ...................... ";
632 theDump += TCollection_AsciiString(count) + "\n";
634 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidCurveOnSurface);
636 theDump += " Invalid Curve on Surface ................. ";
637 theDump += TCollection_AsciiString(count) + "\n";
639 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidCurveOnClosedSurface);
641 theDump += " Invalid Curve on closed Surface .......... ";
642 theDump += TCollection_AsciiString(count) + "\n";
644 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidSameRangeFlag);
646 theDump += " Invalid SameRange Flag ................... ";
647 theDump += TCollection_AsciiString(count) + "\n";
649 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidSameParameterFlag);
651 theDump += " Invalid SameParameter Flag ............... ";
652 theDump += TCollection_AsciiString(count) + "\n";
654 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidDegeneratedFlag);
656 theDump += " Invalid Degenerated Flag ................. ";
657 theDump += TCollection_AsciiString(count) + "\n";
659 count = NbProblems->Value((Standard_Integer)BRepCheck_FreeEdge);
661 theDump += " Free Edge ................................ ";
662 theDump += TCollection_AsciiString(count) + "\n";
664 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidMultiConnexity);
666 theDump += " Invalid MultiConnexity ................... ";
667 theDump += TCollection_AsciiString(count) + "\n";
669 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidRange);
671 theDump += " Invalid Range ............................ ";
672 theDump += TCollection_AsciiString(count) + "\n";
674 count = NbProblems->Value((Standard_Integer)BRepCheck_EmptyWire);
676 theDump += " Empty Wire ............................... ";
677 theDump += TCollection_AsciiString(count) + "\n";
679 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantEdge);
681 theDump += " Redundant Edge ........................... ";
682 theDump += TCollection_AsciiString(count) + "\n";
684 count = NbProblems->Value((Standard_Integer)BRepCheck_SelfIntersectingWire);
686 theDump += " Self Intersecting Wire ................... ";
687 theDump += TCollection_AsciiString(count) + "\n";
689 count = NbProblems->Value((Standard_Integer)BRepCheck_NoSurface);
691 theDump += " No Surface ............................... ";
692 theDump += TCollection_AsciiString(count) + "\n";
694 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidWire);
696 theDump += " Invalid Wire ............................. ";
697 theDump += TCollection_AsciiString(count) + "\n";
699 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantWire);
701 theDump += " Redundant Wire ........................... ";
702 theDump += TCollection_AsciiString(count) + "\n";
704 count = NbProblems->Value((Standard_Integer)BRepCheck_IntersectingWires);
706 theDump += " Intersecting Wires ....................... ";
707 theDump += TCollection_AsciiString(count) + "\n";
709 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidImbricationOfWires);
711 theDump += " Invalid Imbrication of Wires ............. ";
712 theDump += TCollection_AsciiString(count) + "\n";
714 count = NbProblems->Value((Standard_Integer)BRepCheck_EmptyShell);
716 theDump += " Empty Shell .............................. ";
717 theDump += TCollection_AsciiString(count) + "\n";
719 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantFace);
721 theDump += " Redundant Face ........................... ";
722 theDump += TCollection_AsciiString(count) + "\n";
724 count = NbProblems->Value((Standard_Integer)BRepCheck_UnorientableShape);
726 theDump += " Unorientable Shape ....................... ";
727 theDump += TCollection_AsciiString(count) + "\n";
729 count = NbProblems->Value((Standard_Integer)BRepCheck_NotClosed);
731 theDump += " Not Closed ............................... ";
732 theDump += TCollection_AsciiString(count) + "\n";
734 count = NbProblems->Value((Standard_Integer)BRepCheck_NotConnected);
736 theDump += " Not Connected ............................ ";
737 theDump += TCollection_AsciiString(count) + "\n";
739 count = NbProblems->Value((Standard_Integer)BRepCheck_SubshapeNotInShape);
741 theDump += " Subshape not in Shape .................... ";
742 theDump += TCollection_AsciiString(count) + "\n";
744 count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientation);
746 theDump += " Bad Orientation .......................... ";
747 theDump += TCollection_AsciiString(count) + "\n";
749 count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientationOfSubshape);
751 theDump += " Bad Orientation of Subshape .............. ";
752 theDump += TCollection_AsciiString(count) + "\n";
754 count = NbProblems->Value((Standard_Integer)BRepCheck_CheckFail);
756 theDump += " checkshape failure ....................... ";
757 theDump += TCollection_AsciiString(count) + "\n";
760 theDump += " ------------------------------------------------\n";
761 theDump += "*** Shapes with problems : ";
762 theDump += TCollection_AsciiString(sl->Length()) + "\n";
764 Standard_Integer nbv, nbe, nbw, nbf, nbs, nbo;
765 nbv = nbe = nbw = nbf = nbs = nbo = 0;
767 for (i = 1; i <= sl->Length(); i++) {
768 TopoDS_Shape shi = sl->Value(i);
769 TopAbs_ShapeEnum sti = shi.ShapeType();
771 case TopAbs_VERTEX : nbv++; break;
772 case TopAbs_EDGE : nbe++; break;
773 case TopAbs_WIRE : nbw++; break;
774 case TopAbs_FACE : nbf++; break;
775 case TopAbs_SHELL : nbs++; break;
776 case TopAbs_SOLID : nbo++; break;
782 theDump += "VERTEX : ";
783 if (nbv < 10) theDump += " ";
784 theDump += TCollection_AsciiString(nbv) + "\n";
787 theDump += "EDGE : ";
788 if (nbe < 10) theDump += " ";
789 theDump += TCollection_AsciiString(nbe) + "\n";
792 theDump += "WIRE : ";
793 if (nbw < 10) theDump += " ";
794 theDump += TCollection_AsciiString(nbw) + "\n";
797 theDump += "FACE : ";
798 if (nbf < 10) theDump += " ";
799 theDump += TCollection_AsciiString(nbf) + "\n";
802 theDump += "SHELL : ";
803 if (nbs < 10) theDump += " ";
804 theDump += TCollection_AsciiString(nbs) + "\n";
807 theDump += "SOLID : ";
808 if (nbo < 10) theDump += " ";
809 theDump += TCollection_AsciiString(nbo) + "\n";
813 //=======================================================================
814 //function : GetProblemShapes
815 // purpose : for StructuralDump
816 //=======================================================================
817 void GEOMImpl_IMeasureOperations::GetProblemShapes (const BRepCheck_Analyzer& theAna,
818 const TopoDS_Shape& theShape,
819 Handle(TopTools_HSequenceOfShape)& sl,
820 Handle(TColStd_HArray1OfInteger)& NbProblems,
821 TopTools_DataMapOfShapeListOfShape& theMap)
823 for (TopoDS_Iterator iter(theShape); iter.More(); iter.Next()) {
824 GetProblemShapes(theAna, iter.Value(), sl, NbProblems, theMap);
826 TopAbs_ShapeEnum styp = theShape.ShapeType();
827 BRepCheck_ListIteratorOfListOfStatus itl;
828 TopTools_ListOfShape empty;
829 if (!theMap.IsBound(theShape)) {
830 theMap.Bind(theShape,empty);
832 if (!theAna.Result(theShape).IsNull()) {
833 itl.Initialize(theAna.Result(theShape)->Status());
834 // !!! May be, we have to print all the problems, not only the first one ?
835 if (itl.Value() != BRepCheck_NoError) {
836 sl->Append(theShape);
837 BRepCheck_Status stat = itl.Value();
838 NbProblems->SetValue((Standard_Integer)stat,
839 NbProblems->Value((Standard_Integer)stat) + 1);
846 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_VERTEX, theMap);
849 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_WIRE, theMap);
850 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_EDGE, theMap);
851 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_VERTEX, theMap);
856 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_SHELL, theMap);
863 //=======================================================================
864 //function : Contains
865 //=======================================================================
866 static Standard_Boolean Contains (const TopTools_ListOfShape& L,
867 const TopoDS_Shape& S)
869 TopTools_ListIteratorOfListOfShape it;
870 for (it.Initialize(L); it.More(); it.Next()) {
871 if (it.Value().IsSame(S)) {
872 return Standard_True;
875 return Standard_False;
878 //=======================================================================
879 //function : GetProblemSub
880 // purpose : for StructuralDump
881 //=======================================================================
882 void GEOMImpl_IMeasureOperations::GetProblemSub (const BRepCheck_Analyzer& theAna,
883 const TopoDS_Shape& theShape,
884 Handle(TopTools_HSequenceOfShape)& sl,
885 Handle(TColStd_HArray1OfInteger)& NbProblems,
886 const TopAbs_ShapeEnum Subtype,
887 TopTools_DataMapOfShapeListOfShape& theMap)
889 BRepCheck_ListIteratorOfListOfStatus itl;
891 for (exp.Init(theShape, Subtype); exp.More(); exp.Next()) {
892 const TopoDS_Shape& sub = exp.Current();
894 const Handle(BRepCheck_Result)& res = theAna.Result(sub);
895 for (res->InitContextIterator();
896 res->MoreShapeInContext();
897 res->NextShapeInContext()) {
898 if (res->ContextualShape().IsSame(theShape) && !Contains(theMap(sub), theShape)) {
899 theMap(sub).Append(theShape);
900 itl.Initialize(res->StatusOnShape());
902 if (itl.Value() != BRepCheck_NoError) {
903 Standard_Integer ii = 0;
905 for (ii = 1; ii <= sl->Length(); ii++)
906 if (sl->Value(ii).IsSame(sub)) break;
908 if (ii > sl->Length()) {
910 BRepCheck_Status stat = itl.Value();
911 NbProblems->SetValue((Standard_Integer)stat,
912 NbProblems->Value((Standard_Integer)stat) + 1);
914 for (ii = 1; ii <= sl->Length(); ii++)
915 if (sl->Value(ii).IsSame(theShape)) break;
916 if (ii > sl->Length()) {
917 sl->Append(theShape);
918 BRepCheck_Status stat = itl.Value();
919 NbProblems->SetValue((Standard_Integer)stat,
920 NbProblems->Value((Standard_Integer)stat) + 1);