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>
36 #include <TFunction_DriverTable.hxx>
37 #include <TFunction_Driver.hxx>
38 #include <TFunction_Logbook.hxx>
39 #include <TDF_Tool.hxx>
41 #include <BRep_Tool.hxx>
42 #include <BRepCheck.hxx>
43 #include <BRepCheck_Result.hxx>
44 #include <BRepCheck_ListIteratorOfListOfStatus.hxx>
45 #include <BRepGProp.hxx>
46 #include <BRepBndLib.hxx>
47 #include <BRepExtrema_DistShapeShape.hxx>
49 #include <Bnd_Box.hxx>
51 #include <GProp_GProps.hxx>
52 #include <GProp_PrincipalProps.hxx>
56 #include <TopoDS_Edge.hxx>
57 #include <TopoDS_Face.hxx>
58 #include <TopoDS_Shape.hxx>
59 #include <TopoDS_Vertex.hxx>
60 #include <TopoDS_Iterator.hxx>
61 #include <TopExp_Explorer.hxx>
62 #include <TopTools_MapOfShape.hxx>
63 #include <TopTools_ListOfShape.hxx>
64 #include <TopTools_ListIteratorOfListOfShape.hxx>
66 #include <Geom_Surface.hxx>
67 #include <Geom_Plane.hxx>
70 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
72 //=============================================================================
76 //=============================================================================
77 GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations (GEOM_Engine* theEngine, int theDocID)
78 : GEOM_IOperations(theEngine, theDocID)
80 MESSAGE("GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations");
83 //=============================================================================
87 //=============================================================================
88 GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations()
90 MESSAGE("GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations");
94 //=============================================================================
95 /*! Get LCS, corresponding to the given shape.
96 * Origin of the LCS is situated at the shape's center of mass.
97 * Axes of the LCS are obtained from shape's location or,
98 * if the shape is a planar face, from position of its plane.
100 //=============================================================================
101 gp_Ax3 GEOMImpl_IMeasureOperations::GetPosition (const TopoDS_Shape& theShape)
105 if (theShape.IsNull())
109 aResult.Transform(theShape.Location().Transformation());
110 if (theShape.ShapeType() == TopAbs_FACE) {
111 Handle(Geom_Surface) aGS = BRep_Tool::Surface(TopoDS::Face(theShape));
112 if (!aGS.IsNull() && aGS->IsKind(STANDARD_TYPE(Geom_Plane))) {
113 Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast(aGS);
114 gp_Pln aPln = aGPlane->Pln();
115 aResult = aPln.Position();
121 if (theShape.ShapeType() == TopAbs_VERTEX) {
122 aPnt = BRep_Tool::Pnt(TopoDS::Vertex(theShape));
125 GProp_GProps aSystem;
126 if (theShape.ShapeType() == TopAbs_EDGE || theShape.ShapeType() == TopAbs_WIRE)
127 BRepGProp::LinearProperties(theShape, aSystem);
128 else if (theShape.ShapeType() == TopAbs_FACE || theShape.ShapeType() == TopAbs_SHELL)
129 BRepGProp::SurfaceProperties(theShape, aSystem);
131 BRepGProp::VolumeProperties(theShape, aSystem);
133 aPnt = aSystem.CentreOfMass();
136 aResult.SetLocation(aPnt);
141 //=============================================================================
145 //=============================================================================
146 void GEOMImpl_IMeasureOperations::GetPosition
147 (Handle(GEOM_Object) theShape,
148 Standard_Real& Ox, Standard_Real& Oy, Standard_Real& Oz,
149 Standard_Real& Zx, Standard_Real& Zy, Standard_Real& Zz,
150 Standard_Real& Xx, Standard_Real& Xy, Standard_Real& Xz)
154 //Set default values: global CS
155 Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
158 if (theShape.IsNull()) return;
160 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
161 if (aRefShape.IsNull()) return;
163 TopoDS_Shape aShape = aRefShape->GetValue();
164 if (aShape.IsNull()) {
165 SetErrorCode("The Objects has NULL Shape");
170 gp_Ax3 anAx3 = GetPosition(aShape);
172 gp_Pnt anOri = anAx3.Location();
173 gp_Dir aDirZ = anAx3.Direction();
174 gp_Dir aDirX = anAx3.XDirection();
177 anOri.Coord(Ox, Oy, Oz);
178 aDirZ.Coord(Zx, Zy, Zz);
179 aDirX.Coord(Xx, Xy, Xz);
181 catch (Standard_Failure) {
182 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
183 SetErrorCode(aFail->GetMessageString());
190 //=============================================================================
194 //=============================================================================
195 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetCentreOfMass
196 (Handle(GEOM_Object) theShape)
200 if (theShape.IsNull()) return NULL;
202 //Add a new CentreOfMass object
203 Handle(GEOM_Object) aCDG = GetEngine()->AddObject(GetDocID(), GEOM_CDG);
205 //Add a new CentreOfMass function
206 Handle(GEOM_Function) aFunction =
207 aCDG->AddFunction(GEOMImpl_MeasureDriver::GetID(), CDG_MEASURE);
208 if (aFunction.IsNull()) return NULL;
210 //Check if the function is set correctly
211 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
213 GEOMImpl_IMeasure aCI (aFunction);
215 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
216 if (aRefShape.IsNull()) return NULL;
218 aCI.SetBase(aRefShape);
220 //Compute the CentreOfMass value
222 if (!GetSolver()->ComputeFunction(aFunction)) {
223 SetErrorCode("Measure driver failed to compute centre of mass");
227 catch (Standard_Failure) {
228 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
229 SetErrorCode(aFail->GetMessageString());
233 //Make a Python command
234 GEOM::TPythonDump(aFunction) << aCDG << " = geompy.MakeCDG(" << theShape << ")";
240 //=============================================================================
244 //=============================================================================
245 void GEOMImpl_IMeasureOperations::GetBasicProperties (Handle(GEOM_Object) theShape,
246 Standard_Real& theLength,
247 Standard_Real& theSurfArea,
248 Standard_Real& theVolume)
252 if (theShape.IsNull()) return;
254 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
255 if (aRefShape.IsNull()) return;
257 TopoDS_Shape aShape = aRefShape->GetValue();
258 if (aShape.IsNull()) {
259 SetErrorCode("The Objects has NULL Shape");
263 //Compute the parameters
264 GProp_GProps LProps, SProps;
266 BRepGProp::LinearProperties(aShape, LProps);
267 theLength = LProps.Mass();
269 BRepGProp::SurfaceProperties(aShape, SProps);
270 theSurfArea = SProps.Mass();
273 if (aShape.ShapeType() < TopAbs_SHELL) {
274 for (TopExp_Explorer Exp (aShape, TopAbs_SOLID); Exp.More(); Exp.Next()) {
276 BRepGProp::VolumeProperties(Exp.Current(), VProps);
277 theVolume += VProps.Mass();
281 catch (Standard_Failure) {
282 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
283 SetErrorCode(aFail->GetMessageString());
290 //=============================================================================
294 //=============================================================================
295 void GEOMImpl_IMeasureOperations::GetInertia
296 (Handle(GEOM_Object) theShape,
297 Standard_Real& I11, Standard_Real& I12, Standard_Real& I13,
298 Standard_Real& I21, Standard_Real& I22, Standard_Real& I23,
299 Standard_Real& I31, Standard_Real& I32, Standard_Real& I33,
300 Standard_Real& Ix , Standard_Real& Iy , Standard_Real& Iz)
304 if (theShape.IsNull()) return;
306 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
307 if (aRefShape.IsNull()) return;
309 TopoDS_Shape aShape = aRefShape->GetValue();
310 if (aShape.IsNull()) {
311 SetErrorCode("The Objects has NULL Shape");
315 //Compute the parameters
319 if (aShape.ShapeType() == TopAbs_VERTEX ||
320 aShape.ShapeType() == TopAbs_EDGE ||
321 aShape.ShapeType() == TopAbs_WIRE) {
322 BRepGProp::LinearProperties(aShape, System);
323 } else if (aShape.ShapeType() == TopAbs_FACE ||
324 aShape.ShapeType() == TopAbs_SHELL) {
325 BRepGProp::SurfaceProperties(aShape, System);
327 BRepGProp::VolumeProperties(aShape, System);
329 gp_Mat I = System.MatrixOfInertia();
343 GProp_PrincipalProps Pr = System.PrincipalProperties();
344 Pr.Moments(Ix,Iy,Iz);
346 catch (Standard_Failure) {
347 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
348 SetErrorCode(aFail->GetMessageString());
355 //=============================================================================
359 //=============================================================================
360 void GEOMImpl_IMeasureOperations::GetBoundingBox
361 (Handle(GEOM_Object) theShape,
362 Standard_Real& Xmin, Standard_Real& Xmax,
363 Standard_Real& Ymin, Standard_Real& Ymax,
364 Standard_Real& Zmin, Standard_Real& Zmax)
368 if (theShape.IsNull()) return;
370 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
371 if (aRefShape.IsNull()) return;
373 TopoDS_Shape aShape = aRefShape->GetValue();
374 if (aShape.IsNull()) {
375 SetErrorCode("The Objects has NULL Shape");
379 //Compute the parameters
383 BRepBndLib::Add(aShape, B);
384 B.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
386 catch (Standard_Failure) {
387 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
388 SetErrorCode(aFail->GetMessageString());
395 //=============================================================================
399 //=============================================================================
400 void GEOMImpl_IMeasureOperations::GetTolerance
401 (Handle(GEOM_Object) theShape,
402 Standard_Real& FaceMin, Standard_Real& FaceMax,
403 Standard_Real& EdgeMin, Standard_Real& EdgeMax,
404 Standard_Real& VertMin, Standard_Real& VertMax)
408 if (theShape.IsNull()) return;
410 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
411 if (aRefShape.IsNull()) return;
413 TopoDS_Shape aShape = aRefShape->GetValue();
414 if (aShape.IsNull()) {
415 SetErrorCode("The Objects has NULL Shape");
419 //Compute the parameters
421 FaceMin = EdgeMin = VertMin = RealLast();
422 FaceMax = EdgeMax = VertMax = -RealLast();
425 for (TopExp_Explorer ExF (aShape, TopAbs_FACE); ExF.More(); ExF.Next()) {
426 TopoDS_Face Face = TopoDS::Face(ExF.Current());
427 T = BRep_Tool::Tolerance(Face);
433 for (TopExp_Explorer ExE (aShape, TopAbs_EDGE); ExE.More(); ExE.Next()) {
434 TopoDS_Edge Edge = TopoDS::Edge(ExE.Current());
435 T = BRep_Tool::Tolerance(Edge);
441 for (TopExp_Explorer ExV (aShape, TopAbs_VERTEX); ExV.More(); ExV.Next()) {
442 TopoDS_Vertex Vertex = TopoDS::Vertex(ExV.Current());
443 T = BRep_Tool::Tolerance(Vertex);
450 catch (Standard_Failure) {
451 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
452 SetErrorCode(aFail->GetMessageString());
459 //=============================================================================
463 //=============================================================================
464 bool GEOMImpl_IMeasureOperations::CheckShape (Handle(GEOM_Object) theShape,
465 const Standard_Boolean theIsCheckGeom,
466 TCollection_AsciiString& theDump)
470 if (theShape.IsNull()) return false;
472 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
473 if (aRefShape.IsNull()) return false;
475 TopoDS_Shape aShape = aRefShape->GetValue();
476 if (aShape.IsNull()) {
477 SetErrorCode("The Objects has NULL Shape");
481 //Compute the parameters
482 bool isValid = false;
484 BRepCheck_Analyzer ana (aShape, theIsCheckGeom);
489 StructuralDump(ana, aShape, theDump);
492 catch (Standard_Failure) {
493 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
494 SetErrorCode(aFail->GetMessageString());
502 //=============================================================================
506 //=============================================================================
507 TCollection_AsciiString GEOMImpl_IMeasureOperations::WhatIs (Handle(GEOM_Object) theShape)
511 TCollection_AsciiString Astr;
513 if (theShape.IsNull()) return Astr;
515 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
516 if (aRefShape.IsNull()) return Astr;
518 TopoDS_Shape aShape = aRefShape->GetValue();
519 if (aShape.IsNull()) {
520 SetErrorCode("The Objects has NULL Shape");
524 //Compute the parameters
525 if (aShape.ShapeType() == TopAbs_EDGE) {
526 if (BRep_Tool::Degenerated(TopoDS::Edge(aShape))) {
527 Astr = Astr + " It is a degenerated edge \n";
531 Astr = Astr + " Number of sub-shapes : \n";
534 int iType, nbTypes [TopAbs_SHAPE];
535 for (iType = 0; iType < TopAbs_SHAPE; ++iType)
537 nbTypes[aShape.ShapeType()]++;
539 TopTools_MapOfShape aMapOfShape;
540 aMapOfShape.Add(aShape);
541 TopTools_ListOfShape aListOfShape;
542 aListOfShape.Append(aShape);
544 TopTools_ListIteratorOfListOfShape itL (aListOfShape);
545 for (; itL.More(); itL.Next()) {
546 TopoDS_Iterator it (itL.Value());
547 for (; it.More(); it.Next()) {
548 TopoDS_Shape s = it.Value();
549 if (aMapOfShape.Add(s)) {
550 aListOfShape.Append(s);
551 nbTypes[s.ShapeType()]++;
556 Astr = Astr + " VERTEX : " + TCollection_AsciiString(nbTypes[TopAbs_VERTEX]) + "\n";
557 Astr = Astr + " EDGE : " + TCollection_AsciiString(nbTypes[TopAbs_EDGE]) + "\n";
558 Astr = Astr + " WIRE : " + TCollection_AsciiString(nbTypes[TopAbs_WIRE]) + "\n";
559 Astr = Astr + " FACE : " + TCollection_AsciiString(nbTypes[TopAbs_FACE]) + "\n";
560 Astr = Astr + " SHELL : " + TCollection_AsciiString(nbTypes[TopAbs_SHELL]) + "\n";
561 Astr = Astr + " SOLID : " + TCollection_AsciiString(nbTypes[TopAbs_SOLID]) + "\n";
562 Astr = Astr + " COMPSOLID : " + TCollection_AsciiString(nbTypes[TopAbs_COMPSOLID]) + "\n";
563 Astr = Astr + " COMPOUND : " + TCollection_AsciiString(nbTypes[TopAbs_COMPOUND]) + "\n";
564 Astr = Astr + " SHAPE : " + TCollection_AsciiString(aMapOfShape.Extent());
566 catch (Standard_Failure) {
567 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
568 SetErrorCode(aFail->GetMessageString());
576 //=============================================================================
580 //=============================================================================
581 Standard_Real GEOMImpl_IMeasureOperations::GetMinDistance
582 (Handle(GEOM_Object) theShape1, Handle(GEOM_Object) theShape2,
583 Standard_Real& X1, Standard_Real& Y1, Standard_Real& Z1,
584 Standard_Real& X2, Standard_Real& Y2, Standard_Real& Z2)
587 Standard_Real MinDist = 1.e9;
589 if (theShape1.IsNull() || theShape2.IsNull()) return MinDist;
591 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
592 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
593 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return MinDist;
595 TopoDS_Shape aShape1 = aRefShape1->GetValue();
596 TopoDS_Shape aShape2 = aRefShape2->GetValue();
597 if (aShape1.IsNull() || aShape2.IsNull()) {
598 SetErrorCode("One of Objects has NULL Shape");
602 //Compute the parameters
604 BRepExtrema_DistShapeShape dst (aShape1, aShape2);
606 gp_Pnt PMin1, PMin2, P1, P2;
608 for (int i = 1; i <= dst.NbSolution(); i++) {
609 P1 = dst.PointOnShape1(i);
610 P2 = dst.PointOnShape2(i);
612 Standard_Real Dist = P1.Distance(P2);
613 if (MinDist > Dist) {
620 PMin1.Coord(X1, Y1, Z1);
621 PMin2.Coord(X2, Y2, Z2);
624 catch (Standard_Failure) {
625 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
626 SetErrorCode(aFail->GetMessageString());
634 //=======================================================================
635 //function : PointCoordinates
636 //purpose : Get coordinates of point
637 //=======================================================================
638 void GEOMImpl_IMeasureOperations::PointCoordinates( Handle(GEOM_Object) theShape,
639 Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ )
643 if ( theShape.IsNull() )
646 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
647 if ( aRefShape.IsNull() )
650 TopoDS_Shape aShape = aRefShape->GetValue();
651 if ( aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX )
653 SetErrorCode( "Shape must be a vertex" );
659 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
665 catch ( Standard_Failure )
667 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
668 SetErrorCode( aFail->GetMessageString() );
672 //=======================================================================
673 //function : StructuralDump
674 //purpose : Structural (data exchange) style of output.
675 //=======================================================================
676 void GEOMImpl_IMeasureOperations::StructuralDump (const BRepCheck_Analyzer& theAna,
677 const TopoDS_Shape& theShape,
678 TCollection_AsciiString& theDump)
682 theDump += " -- The Shape has problems :\n";
683 theDump += " Check Count\n";
684 theDump += " ------------------------------------------------\n";
686 Standard_Integer last_stat = (Standard_Integer)BRepCheck_CheckFail;
687 Handle(TColStd_HArray1OfInteger) NbProblems =
688 new TColStd_HArray1OfInteger(1, last_stat);
689 for (i = 1; i <= last_stat; i++)
690 NbProblems->SetValue(i,0);
692 Handle(TopTools_HSequenceOfShape) sl;
693 sl = new TopTools_HSequenceOfShape();
694 TopTools_DataMapOfShapeListOfShape theMap;
696 GetProblemShapes(theAna, theShape, sl, NbProblems, theMap);
699 Standard_Integer count = 0;
700 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnCurve);
702 theDump += " Invalid Point on Curve ................... ";
703 theDump += TCollection_AsciiString(count) + "\n";
705 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnCurveOnSurface);
707 theDump += " Invalid Point on CurveOnSurface .......... ";
708 theDump += TCollection_AsciiString(count) + "\n";
710 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnSurface);
712 theDump += " Invalid Point on Surface ................. ";
713 theDump += TCollection_AsciiString(count) + "\n";
715 count = NbProblems->Value((Standard_Integer)BRepCheck_No3DCurve);
717 theDump += " No 3D Curve .............................. ";
718 theDump += TCollection_AsciiString(count) + "\n";
720 count = NbProblems->Value((Standard_Integer)BRepCheck_Multiple3DCurve);
722 theDump += " Multiple 3D Curve ........................ ";
723 theDump += TCollection_AsciiString(count) + "\n";
725 count = NbProblems->Value((Standard_Integer)BRepCheck_Invalid3DCurve);
727 theDump += " Invalid 3D Curve ......................... ";
728 theDump += TCollection_AsciiString(count) + "\n";
730 count = NbProblems->Value((Standard_Integer)BRepCheck_NoCurveOnSurface);
732 theDump += " No Curve on Surface ...................... ";
733 theDump += TCollection_AsciiString(count) + "\n";
735 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidCurveOnSurface);
737 theDump += " Invalid Curve on Surface ................. ";
738 theDump += TCollection_AsciiString(count) + "\n";
740 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidCurveOnClosedSurface);
742 theDump += " Invalid Curve on closed Surface .......... ";
743 theDump += TCollection_AsciiString(count) + "\n";
745 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidSameRangeFlag);
747 theDump += " Invalid SameRange Flag ................... ";
748 theDump += TCollection_AsciiString(count) + "\n";
750 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidSameParameterFlag);
752 theDump += " Invalid SameParameter Flag ............... ";
753 theDump += TCollection_AsciiString(count) + "\n";
755 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidDegeneratedFlag);
757 theDump += " Invalid Degenerated Flag ................. ";
758 theDump += TCollection_AsciiString(count) + "\n";
760 count = NbProblems->Value((Standard_Integer)BRepCheck_FreeEdge);
762 theDump += " Free Edge ................................ ";
763 theDump += TCollection_AsciiString(count) + "\n";
765 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidMultiConnexity);
767 theDump += " Invalid MultiConnexity ................... ";
768 theDump += TCollection_AsciiString(count) + "\n";
770 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidRange);
772 theDump += " Invalid Range ............................ ";
773 theDump += TCollection_AsciiString(count) + "\n";
775 count = NbProblems->Value((Standard_Integer)BRepCheck_EmptyWire);
777 theDump += " Empty Wire ............................... ";
778 theDump += TCollection_AsciiString(count) + "\n";
780 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantEdge);
782 theDump += " Redundant Edge ........................... ";
783 theDump += TCollection_AsciiString(count) + "\n";
785 count = NbProblems->Value((Standard_Integer)BRepCheck_SelfIntersectingWire);
787 theDump += " Self Intersecting Wire ................... ";
788 theDump += TCollection_AsciiString(count) + "\n";
790 count = NbProblems->Value((Standard_Integer)BRepCheck_NoSurface);
792 theDump += " No Surface ............................... ";
793 theDump += TCollection_AsciiString(count) + "\n";
795 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidWire);
797 theDump += " Invalid Wire ............................. ";
798 theDump += TCollection_AsciiString(count) + "\n";
800 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantWire);
802 theDump += " Redundant Wire ........................... ";
803 theDump += TCollection_AsciiString(count) + "\n";
805 count = NbProblems->Value((Standard_Integer)BRepCheck_IntersectingWires);
807 theDump += " Intersecting Wires ....................... ";
808 theDump += TCollection_AsciiString(count) + "\n";
810 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidImbricationOfWires);
812 theDump += " Invalid Imbrication of Wires ............. ";
813 theDump += TCollection_AsciiString(count) + "\n";
815 count = NbProblems->Value((Standard_Integer)BRepCheck_EmptyShell);
817 theDump += " Empty Shell .............................. ";
818 theDump += TCollection_AsciiString(count) + "\n";
820 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantFace);
822 theDump += " Redundant Face ........................... ";
823 theDump += TCollection_AsciiString(count) + "\n";
825 count = NbProblems->Value((Standard_Integer)BRepCheck_UnorientableShape);
827 theDump += " Unorientable Shape ....................... ";
828 theDump += TCollection_AsciiString(count) + "\n";
830 count = NbProblems->Value((Standard_Integer)BRepCheck_NotClosed);
832 theDump += " Not Closed ............................... ";
833 theDump += TCollection_AsciiString(count) + "\n";
835 count = NbProblems->Value((Standard_Integer)BRepCheck_NotConnected);
837 theDump += " Not Connected ............................ ";
838 theDump += TCollection_AsciiString(count) + "\n";
840 count = NbProblems->Value((Standard_Integer)BRepCheck_SubshapeNotInShape);
842 theDump += " Subshape not in Shape .................... ";
843 theDump += TCollection_AsciiString(count) + "\n";
845 count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientation);
847 theDump += " Bad Orientation .......................... ";
848 theDump += TCollection_AsciiString(count) + "\n";
850 count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientationOfSubshape);
852 theDump += " Bad Orientation of Subshape .............. ";
853 theDump += TCollection_AsciiString(count) + "\n";
855 count = NbProblems->Value((Standard_Integer)BRepCheck_CheckFail);
857 theDump += " checkshape failure ....................... ";
858 theDump += TCollection_AsciiString(count) + "\n";
861 theDump += " ------------------------------------------------\n";
862 theDump += "*** Shapes with problems : ";
863 theDump += TCollection_AsciiString(sl->Length()) + "\n";
865 Standard_Integer nbv, nbe, nbw, nbf, nbs, nbo;
866 nbv = nbe = nbw = nbf = nbs = nbo = 0;
868 for (i = 1; i <= sl->Length(); i++) {
869 TopoDS_Shape shi = sl->Value(i);
870 TopAbs_ShapeEnum sti = shi.ShapeType();
872 case TopAbs_VERTEX : nbv++; break;
873 case TopAbs_EDGE : nbe++; break;
874 case TopAbs_WIRE : nbw++; break;
875 case TopAbs_FACE : nbf++; break;
876 case TopAbs_SHELL : nbs++; break;
877 case TopAbs_SOLID : nbo++; break;
883 theDump += "VERTEX : ";
884 if (nbv < 10) theDump += " ";
885 theDump += TCollection_AsciiString(nbv) + "\n";
888 theDump += "EDGE : ";
889 if (nbe < 10) theDump += " ";
890 theDump += TCollection_AsciiString(nbe) + "\n";
893 theDump += "WIRE : ";
894 if (nbw < 10) theDump += " ";
895 theDump += TCollection_AsciiString(nbw) + "\n";
898 theDump += "FACE : ";
899 if (nbf < 10) theDump += " ";
900 theDump += TCollection_AsciiString(nbf) + "\n";
903 theDump += "SHELL : ";
904 if (nbs < 10) theDump += " ";
905 theDump += TCollection_AsciiString(nbs) + "\n";
908 theDump += "SOLID : ";
909 if (nbo < 10) theDump += " ";
910 theDump += TCollection_AsciiString(nbo) + "\n";
914 //=======================================================================
915 //function : GetProblemShapes
916 // purpose : for StructuralDump
917 //=======================================================================
918 void GEOMImpl_IMeasureOperations::GetProblemShapes (const BRepCheck_Analyzer& theAna,
919 const TopoDS_Shape& theShape,
920 Handle(TopTools_HSequenceOfShape)& sl,
921 Handle(TColStd_HArray1OfInteger)& NbProblems,
922 TopTools_DataMapOfShapeListOfShape& theMap)
924 for (TopoDS_Iterator iter(theShape); iter.More(); iter.Next()) {
925 GetProblemShapes(theAna, iter.Value(), sl, NbProblems, theMap);
927 TopAbs_ShapeEnum styp = theShape.ShapeType();
928 BRepCheck_ListIteratorOfListOfStatus itl;
929 TopTools_ListOfShape empty;
930 if (!theMap.IsBound(theShape)) {
931 theMap.Bind(theShape,empty);
933 if (!theAna.Result(theShape).IsNull()) {
934 itl.Initialize(theAna.Result(theShape)->Status());
935 // !!! May be, we have to print all the problems, not only the first one ?
936 if (itl.Value() != BRepCheck_NoError) {
937 sl->Append(theShape);
938 BRepCheck_Status stat = itl.Value();
939 NbProblems->SetValue((Standard_Integer)stat,
940 NbProblems->Value((Standard_Integer)stat) + 1);
947 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_VERTEX, theMap);
950 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_WIRE, theMap);
951 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_EDGE, theMap);
952 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_VERTEX, theMap);
957 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_SHELL, theMap);
964 //=======================================================================
965 //function : Contains
966 //=======================================================================
967 static Standard_Boolean Contains (const TopTools_ListOfShape& L,
968 const TopoDS_Shape& S)
970 TopTools_ListIteratorOfListOfShape it;
971 for (it.Initialize(L); it.More(); it.Next()) {
972 if (it.Value().IsSame(S)) {
973 return Standard_True;
976 return Standard_False;
979 //=======================================================================
980 //function : GetProblemSub
981 // purpose : for StructuralDump
982 //=======================================================================
983 void GEOMImpl_IMeasureOperations::GetProblemSub (const BRepCheck_Analyzer& theAna,
984 const TopoDS_Shape& theShape,
985 Handle(TopTools_HSequenceOfShape)& sl,
986 Handle(TColStd_HArray1OfInteger)& NbProblems,
987 const TopAbs_ShapeEnum Subtype,
988 TopTools_DataMapOfShapeListOfShape& theMap)
990 BRepCheck_ListIteratorOfListOfStatus itl;
992 for (exp.Init(theShape, Subtype); exp.More(); exp.Next()) {
993 const TopoDS_Shape& sub = exp.Current();
995 const Handle(BRepCheck_Result)& res = theAna.Result(sub);
996 for (res->InitContextIterator();
997 res->MoreShapeInContext();
998 res->NextShapeInContext()) {
999 if (res->ContextualShape().IsSame(theShape) && !Contains(theMap(sub), theShape)) {
1000 theMap(sub).Append(theShape);
1001 itl.Initialize(res->StatusOnShape());
1003 if (itl.Value() != BRepCheck_NoError) {
1004 Standard_Integer ii = 0;
1006 for (ii = 1; ii <= sl->Length(); ii++)
1007 if (sl->Value(ii).IsSame(sub)) break;
1009 if (ii > sl->Length()) {
1011 BRepCheck_Status stat = itl.Value();
1012 NbProblems->SetValue((Standard_Integer)stat,
1013 NbProblems->Value((Standard_Integer)stat) + 1);
1015 for (ii = 1; ii <= sl->Length(); ii++)
1016 if (sl->Value(ii).IsSame(theShape)) break;
1017 if (ii > sl->Length()) {
1018 sl->Append(theShape);
1019 BRepCheck_Status stat = itl.Value();
1020 NbProblems->SetValue((Standard_Integer)stat,
1021 NbProblems->Value((Standard_Integer)stat) + 1);