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_Failure.hxx>
71 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
73 //=============================================================================
77 //=============================================================================
78 GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations (GEOM_Engine* theEngine, int theDocID)
79 : GEOM_IOperations(theEngine, theDocID)
81 MESSAGE("GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations");
84 //=============================================================================
88 //=============================================================================
89 GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations()
91 MESSAGE("GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations");
95 //=============================================================================
96 /*! Get LCS, corresponding to the given shape.
97 * Origin of the LCS is situated at the shape's center of mass.
98 * Axes of the LCS are obtained from shape's location or,
99 * if the shape is a planar face, from position of its plane.
101 //=============================================================================
102 gp_Ax3 GEOMImpl_IMeasureOperations::GetPosition (const TopoDS_Shape& theShape)
106 if (theShape.IsNull())
110 aResult.Transform(theShape.Location().Transformation());
111 if (theShape.ShapeType() == TopAbs_FACE) {
112 Handle(Geom_Surface) aGS = BRep_Tool::Surface(TopoDS::Face(theShape));
113 if (!aGS.IsNull() && aGS->IsKind(STANDARD_TYPE(Geom_Plane))) {
114 Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast(aGS);
115 gp_Pln aPln = aGPlane->Pln();
116 aResult = aPln.Position();
122 if (theShape.ShapeType() == TopAbs_VERTEX) {
123 aPnt = BRep_Tool::Pnt(TopoDS::Vertex(theShape));
126 GProp_GProps aSystem;
127 if (theShape.ShapeType() == TopAbs_EDGE || theShape.ShapeType() == TopAbs_WIRE)
128 BRepGProp::LinearProperties(theShape, aSystem);
129 else if (theShape.ShapeType() == TopAbs_FACE || theShape.ShapeType() == TopAbs_SHELL)
130 BRepGProp::SurfaceProperties(theShape, aSystem);
132 BRepGProp::VolumeProperties(theShape, aSystem);
134 aPnt = aSystem.CentreOfMass();
137 aResult.SetLocation(aPnt);
142 //=============================================================================
146 //=============================================================================
147 void GEOMImpl_IMeasureOperations::GetPosition
148 (Handle(GEOM_Object) theShape,
149 Standard_Real& Ox, Standard_Real& Oy, Standard_Real& Oz,
150 Standard_Real& Zx, Standard_Real& Zy, Standard_Real& Zz,
151 Standard_Real& Xx, Standard_Real& Xy, Standard_Real& Xz)
155 //Set default values: global CS
156 Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
159 if (theShape.IsNull()) return;
161 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
162 if (aRefShape.IsNull()) return;
164 TopoDS_Shape aShape = aRefShape->GetValue();
165 if (aShape.IsNull()) {
166 SetErrorCode("The Objects has NULL Shape");
171 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
175 gp_Ax3 anAx3 = GetPosition(aShape);
177 gp_Pnt anOri = anAx3.Location();
178 gp_Dir aDirZ = anAx3.Direction();
179 gp_Dir aDirX = anAx3.XDirection();
182 anOri.Coord(Ox, Oy, Oz);
183 aDirZ.Coord(Zx, Zy, Zz);
184 aDirX.Coord(Xx, Xy, Xz);
186 catch (Standard_Failure) {
187 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
188 SetErrorCode(aFail->GetMessageString());
195 //=============================================================================
199 //=============================================================================
200 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetCentreOfMass
201 (Handle(GEOM_Object) theShape)
205 if (theShape.IsNull()) return NULL;
207 //Add a new CentreOfMass object
208 Handle(GEOM_Object) aCDG = GetEngine()->AddObject(GetDocID(), GEOM_CDG);
210 //Add a new CentreOfMass function
211 Handle(GEOM_Function) aFunction =
212 aCDG->AddFunction(GEOMImpl_MeasureDriver::GetID(), CDG_MEASURE);
213 if (aFunction.IsNull()) return NULL;
215 //Check if the function is set correctly
216 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
218 GEOMImpl_IMeasure aCI (aFunction);
220 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
221 if (aRefShape.IsNull()) return NULL;
223 aCI.SetBase(aRefShape);
225 //Compute the CentreOfMass value
227 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
230 if (!GetSolver()->ComputeFunction(aFunction)) {
231 SetErrorCode("Measure driver failed to compute centre of mass");
235 catch (Standard_Failure) {
236 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
237 SetErrorCode(aFail->GetMessageString());
241 //Make a Python command
242 GEOM::TPythonDump(aFunction) << aCDG << " = geompy.MakeCDG(" << theShape << ")";
248 //=============================================================================
252 //=============================================================================
253 void GEOMImpl_IMeasureOperations::GetBasicProperties (Handle(GEOM_Object) theShape,
254 Standard_Real& theLength,
255 Standard_Real& theSurfArea,
256 Standard_Real& theVolume)
260 if (theShape.IsNull()) return;
262 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
263 if (aRefShape.IsNull()) return;
265 TopoDS_Shape aShape = aRefShape->GetValue();
266 if (aShape.IsNull()) {
267 SetErrorCode("The Objects has NULL Shape");
271 //Compute the parameters
272 GProp_GProps LProps, SProps;
274 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
277 BRepGProp::LinearProperties(aShape, LProps);
278 theLength = LProps.Mass();
280 BRepGProp::SurfaceProperties(aShape, SProps);
281 theSurfArea = SProps.Mass();
284 if (aShape.ShapeType() < TopAbs_SHELL) {
285 for (TopExp_Explorer Exp (aShape, TopAbs_SOLID); Exp.More(); Exp.Next()) {
287 BRepGProp::VolumeProperties(Exp.Current(), VProps);
288 theVolume += VProps.Mass();
292 catch (Standard_Failure) {
293 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
294 SetErrorCode(aFail->GetMessageString());
301 //=============================================================================
305 //=============================================================================
306 void GEOMImpl_IMeasureOperations::GetInertia
307 (Handle(GEOM_Object) theShape,
308 Standard_Real& I11, Standard_Real& I12, Standard_Real& I13,
309 Standard_Real& I21, Standard_Real& I22, Standard_Real& I23,
310 Standard_Real& I31, Standard_Real& I32, Standard_Real& I33,
311 Standard_Real& Ix , Standard_Real& Iy , Standard_Real& Iz)
315 if (theShape.IsNull()) return;
317 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
318 if (aRefShape.IsNull()) return;
320 TopoDS_Shape aShape = aRefShape->GetValue();
321 if (aShape.IsNull()) {
322 SetErrorCode("The Objects has NULL Shape");
326 //Compute the parameters
330 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
333 if (aShape.ShapeType() == TopAbs_VERTEX ||
334 aShape.ShapeType() == TopAbs_EDGE ||
335 aShape.ShapeType() == TopAbs_WIRE) {
336 BRepGProp::LinearProperties(aShape, System);
337 } else if (aShape.ShapeType() == TopAbs_FACE ||
338 aShape.ShapeType() == TopAbs_SHELL) {
339 BRepGProp::SurfaceProperties(aShape, System);
341 BRepGProp::VolumeProperties(aShape, System);
343 gp_Mat I = System.MatrixOfInertia();
357 GProp_PrincipalProps Pr = System.PrincipalProperties();
358 Pr.Moments(Ix,Iy,Iz);
360 catch (Standard_Failure) {
361 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
362 SetErrorCode(aFail->GetMessageString());
369 //=============================================================================
373 //=============================================================================
374 void GEOMImpl_IMeasureOperations::GetBoundingBox
375 (Handle(GEOM_Object) theShape,
376 Standard_Real& Xmin, Standard_Real& Xmax,
377 Standard_Real& Ymin, Standard_Real& Ymax,
378 Standard_Real& Zmin, Standard_Real& Zmax)
382 if (theShape.IsNull()) return;
384 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
385 if (aRefShape.IsNull()) return;
387 TopoDS_Shape aShape = aRefShape->GetValue();
388 if (aShape.IsNull()) {
389 SetErrorCode("The Objects has NULL Shape");
393 //Compute the parameters
397 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
400 BRepBndLib::Add(aShape, B);
401 B.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
403 catch (Standard_Failure) {
404 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
405 SetErrorCode(aFail->GetMessageString());
412 //=============================================================================
416 //=============================================================================
417 void GEOMImpl_IMeasureOperations::GetTolerance
418 (Handle(GEOM_Object) theShape,
419 Standard_Real& FaceMin, Standard_Real& FaceMax,
420 Standard_Real& EdgeMin, Standard_Real& EdgeMax,
421 Standard_Real& VertMin, Standard_Real& VertMax)
425 if (theShape.IsNull()) return;
427 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
428 if (aRefShape.IsNull()) return;
430 TopoDS_Shape aShape = aRefShape->GetValue();
431 if (aShape.IsNull()) {
432 SetErrorCode("The Objects has NULL Shape");
436 //Compute the parameters
438 FaceMin = EdgeMin = VertMin = RealLast();
439 FaceMax = EdgeMax = VertMax = -RealLast();
442 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
445 for (TopExp_Explorer ExF (aShape, TopAbs_FACE); ExF.More(); ExF.Next()) {
446 TopoDS_Face Face = TopoDS::Face(ExF.Current());
447 T = BRep_Tool::Tolerance(Face);
453 for (TopExp_Explorer ExE (aShape, TopAbs_EDGE); ExE.More(); ExE.Next()) {
454 TopoDS_Edge Edge = TopoDS::Edge(ExE.Current());
455 T = BRep_Tool::Tolerance(Edge);
461 for (TopExp_Explorer ExV (aShape, TopAbs_VERTEX); ExV.More(); ExV.Next()) {
462 TopoDS_Vertex Vertex = TopoDS::Vertex(ExV.Current());
463 T = BRep_Tool::Tolerance(Vertex);
470 catch (Standard_Failure) {
471 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
472 SetErrorCode(aFail->GetMessageString());
479 //=============================================================================
483 //=============================================================================
484 bool GEOMImpl_IMeasureOperations::CheckShape (Handle(GEOM_Object) theShape,
485 const Standard_Boolean theIsCheckGeom,
486 TCollection_AsciiString& theDump)
490 if (theShape.IsNull()) return false;
492 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
493 if (aRefShape.IsNull()) return false;
495 TopoDS_Shape aShape = aRefShape->GetValue();
496 if (aShape.IsNull()) {
497 SetErrorCode("The Objects has NULL Shape");
501 //Compute the parameters
502 bool isValid = false;
504 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
507 BRepCheck_Analyzer ana (aShape, theIsCheckGeom);
512 StructuralDump(ana, aShape, theDump);
515 catch (Standard_Failure) {
516 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
517 SetErrorCode(aFail->GetMessageString());
525 //=============================================================================
529 //=============================================================================
530 TCollection_AsciiString GEOMImpl_IMeasureOperations::WhatIs (Handle(GEOM_Object) theShape)
534 TCollection_AsciiString Astr;
536 if (theShape.IsNull()) return Astr;
538 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
539 if (aRefShape.IsNull()) return Astr;
541 TopoDS_Shape aShape = aRefShape->GetValue();
542 if (aShape.IsNull()) {
543 SetErrorCode("The Objects has NULL Shape");
547 //Compute the parameters
548 if (aShape.ShapeType() == TopAbs_EDGE) {
549 if (BRep_Tool::Degenerated(TopoDS::Edge(aShape))) {
550 Astr = Astr + " It is a degenerated edge \n";
554 Astr = Astr + " Number of sub-shapes : \n";
557 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
560 int iType, nbTypes [TopAbs_SHAPE];
561 for (iType = 0; iType < TopAbs_SHAPE; ++iType)
563 nbTypes[aShape.ShapeType()]++;
565 TopTools_MapOfShape aMapOfShape;
566 aMapOfShape.Add(aShape);
567 TopTools_ListOfShape aListOfShape;
568 aListOfShape.Append(aShape);
570 TopTools_ListIteratorOfListOfShape itL (aListOfShape);
571 for (; itL.More(); itL.Next()) {
572 TopoDS_Iterator it (itL.Value());
573 for (; it.More(); it.Next()) {
574 TopoDS_Shape s = it.Value();
575 if (aMapOfShape.Add(s)) {
576 aListOfShape.Append(s);
577 nbTypes[s.ShapeType()]++;
582 Astr = Astr + " VERTEX : " + TCollection_AsciiString(nbTypes[TopAbs_VERTEX]) + "\n";
583 Astr = Astr + " EDGE : " + TCollection_AsciiString(nbTypes[TopAbs_EDGE]) + "\n";
584 Astr = Astr + " WIRE : " + TCollection_AsciiString(nbTypes[TopAbs_WIRE]) + "\n";
585 Astr = Astr + " FACE : " + TCollection_AsciiString(nbTypes[TopAbs_FACE]) + "\n";
586 Astr = Astr + " SHELL : " + TCollection_AsciiString(nbTypes[TopAbs_SHELL]) + "\n";
587 Astr = Astr + " SOLID : " + TCollection_AsciiString(nbTypes[TopAbs_SOLID]) + "\n";
588 Astr = Astr + " COMPSOLID : " + TCollection_AsciiString(nbTypes[TopAbs_COMPSOLID]) + "\n";
589 Astr = Astr + " COMPOUND : " + TCollection_AsciiString(nbTypes[TopAbs_COMPOUND]) + "\n";
590 Astr = Astr + " SHAPE : " + TCollection_AsciiString(aMapOfShape.Extent());
592 catch (Standard_Failure) {
593 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
594 SetErrorCode(aFail->GetMessageString());
602 //=============================================================================
606 //=============================================================================
607 Standard_Real GEOMImpl_IMeasureOperations::GetMinDistance
608 (Handle(GEOM_Object) theShape1, Handle(GEOM_Object) theShape2,
609 Standard_Real& X1, Standard_Real& Y1, Standard_Real& Z1,
610 Standard_Real& X2, Standard_Real& Y2, Standard_Real& Z2)
613 Standard_Real MinDist = 1.e9;
615 if (theShape1.IsNull() || theShape2.IsNull()) return MinDist;
617 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
618 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
619 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return MinDist;
621 TopoDS_Shape aShape1 = aRefShape1->GetValue();
622 TopoDS_Shape aShape2 = aRefShape2->GetValue();
623 if (aShape1.IsNull() || aShape2.IsNull()) {
624 SetErrorCode("One of Objects has NULL Shape");
628 //Compute the parameters
630 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
633 BRepExtrema_DistShapeShape dst (aShape1, aShape2);
635 gp_Pnt PMin1, PMin2, P1, P2;
637 for (int i = 1; i <= dst.NbSolution(); i++) {
638 P1 = dst.PointOnShape1(i);
639 P2 = dst.PointOnShape2(i);
641 Standard_Real Dist = P1.Distance(P2);
642 if (MinDist > Dist) {
649 PMin1.Coord(X1, Y1, Z1);
650 PMin2.Coord(X2, Y2, Z2);
653 catch (Standard_Failure) {
654 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
655 SetErrorCode(aFail->GetMessageString());
663 //=======================================================================
664 //function : PointCoordinates
665 //purpose : Get coordinates of point
666 //=======================================================================
667 void GEOMImpl_IMeasureOperations::PointCoordinates( Handle(GEOM_Object) theShape,
668 Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ )
672 if ( theShape.IsNull() )
675 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
676 if ( aRefShape.IsNull() )
679 TopoDS_Shape aShape = aRefShape->GetValue();
680 if ( aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX )
682 SetErrorCode( "Shape must be a vertex" );
687 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
690 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
696 catch ( Standard_Failure )
698 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
699 SetErrorCode( aFail->GetMessageString() );
703 //=======================================================================
704 //function : StructuralDump
705 //purpose : Structural (data exchange) style of output.
706 //=======================================================================
707 void GEOMImpl_IMeasureOperations::StructuralDump (const BRepCheck_Analyzer& theAna,
708 const TopoDS_Shape& theShape,
709 TCollection_AsciiString& theDump)
713 theDump += " -- The Shape has problems :\n";
714 theDump += " Check Count\n";
715 theDump += " ------------------------------------------------\n";
717 Standard_Integer last_stat = (Standard_Integer)BRepCheck_CheckFail;
718 Handle(TColStd_HArray1OfInteger) NbProblems =
719 new TColStd_HArray1OfInteger(1, last_stat);
720 for (i = 1; i <= last_stat; i++)
721 NbProblems->SetValue(i,0);
723 Handle(TopTools_HSequenceOfShape) sl;
724 sl = new TopTools_HSequenceOfShape();
725 TopTools_DataMapOfShapeListOfShape theMap;
727 GetProblemShapes(theAna, theShape, sl, NbProblems, theMap);
730 Standard_Integer count = 0;
731 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnCurve);
733 theDump += " Invalid Point on Curve ................... ";
734 theDump += TCollection_AsciiString(count) + "\n";
736 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnCurveOnSurface);
738 theDump += " Invalid Point on CurveOnSurface .......... ";
739 theDump += TCollection_AsciiString(count) + "\n";
741 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnSurface);
743 theDump += " Invalid Point on Surface ................. ";
744 theDump += TCollection_AsciiString(count) + "\n";
746 count = NbProblems->Value((Standard_Integer)BRepCheck_No3DCurve);
748 theDump += " No 3D Curve .............................. ";
749 theDump += TCollection_AsciiString(count) + "\n";
751 count = NbProblems->Value((Standard_Integer)BRepCheck_Multiple3DCurve);
753 theDump += " Multiple 3D Curve ........................ ";
754 theDump += TCollection_AsciiString(count) + "\n";
756 count = NbProblems->Value((Standard_Integer)BRepCheck_Invalid3DCurve);
758 theDump += " Invalid 3D Curve ......................... ";
759 theDump += TCollection_AsciiString(count) + "\n";
761 count = NbProblems->Value((Standard_Integer)BRepCheck_NoCurveOnSurface);
763 theDump += " No Curve on Surface ...................... ";
764 theDump += TCollection_AsciiString(count) + "\n";
766 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidCurveOnSurface);
768 theDump += " Invalid Curve on Surface ................. ";
769 theDump += TCollection_AsciiString(count) + "\n";
771 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidCurveOnClosedSurface);
773 theDump += " Invalid Curve on closed Surface .......... ";
774 theDump += TCollection_AsciiString(count) + "\n";
776 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidSameRangeFlag);
778 theDump += " Invalid SameRange Flag ................... ";
779 theDump += TCollection_AsciiString(count) + "\n";
781 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidSameParameterFlag);
783 theDump += " Invalid SameParameter Flag ............... ";
784 theDump += TCollection_AsciiString(count) + "\n";
786 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidDegeneratedFlag);
788 theDump += " Invalid Degenerated Flag ................. ";
789 theDump += TCollection_AsciiString(count) + "\n";
791 count = NbProblems->Value((Standard_Integer)BRepCheck_FreeEdge);
793 theDump += " Free Edge ................................ ";
794 theDump += TCollection_AsciiString(count) + "\n";
796 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidMultiConnexity);
798 theDump += " Invalid MultiConnexity ................... ";
799 theDump += TCollection_AsciiString(count) + "\n";
801 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidRange);
803 theDump += " Invalid Range ............................ ";
804 theDump += TCollection_AsciiString(count) + "\n";
806 count = NbProblems->Value((Standard_Integer)BRepCheck_EmptyWire);
808 theDump += " Empty Wire ............................... ";
809 theDump += TCollection_AsciiString(count) + "\n";
811 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantEdge);
813 theDump += " Redundant Edge ........................... ";
814 theDump += TCollection_AsciiString(count) + "\n";
816 count = NbProblems->Value((Standard_Integer)BRepCheck_SelfIntersectingWire);
818 theDump += " Self Intersecting Wire ................... ";
819 theDump += TCollection_AsciiString(count) + "\n";
821 count = NbProblems->Value((Standard_Integer)BRepCheck_NoSurface);
823 theDump += " No Surface ............................... ";
824 theDump += TCollection_AsciiString(count) + "\n";
826 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidWire);
828 theDump += " Invalid Wire ............................. ";
829 theDump += TCollection_AsciiString(count) + "\n";
831 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantWire);
833 theDump += " Redundant Wire ........................... ";
834 theDump += TCollection_AsciiString(count) + "\n";
836 count = NbProblems->Value((Standard_Integer)BRepCheck_IntersectingWires);
838 theDump += " Intersecting Wires ....................... ";
839 theDump += TCollection_AsciiString(count) + "\n";
841 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidImbricationOfWires);
843 theDump += " Invalid Imbrication of Wires ............. ";
844 theDump += TCollection_AsciiString(count) + "\n";
846 count = NbProblems->Value((Standard_Integer)BRepCheck_EmptyShell);
848 theDump += " Empty Shell .............................. ";
849 theDump += TCollection_AsciiString(count) + "\n";
851 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantFace);
853 theDump += " Redundant Face ........................... ";
854 theDump += TCollection_AsciiString(count) + "\n";
856 count = NbProblems->Value((Standard_Integer)BRepCheck_UnorientableShape);
858 theDump += " Unorientable Shape ....................... ";
859 theDump += TCollection_AsciiString(count) + "\n";
861 count = NbProblems->Value((Standard_Integer)BRepCheck_NotClosed);
863 theDump += " Not Closed ............................... ";
864 theDump += TCollection_AsciiString(count) + "\n";
866 count = NbProblems->Value((Standard_Integer)BRepCheck_NotConnected);
868 theDump += " Not Connected ............................ ";
869 theDump += TCollection_AsciiString(count) + "\n";
871 count = NbProblems->Value((Standard_Integer)BRepCheck_SubshapeNotInShape);
873 theDump += " Subshape not in Shape .................... ";
874 theDump += TCollection_AsciiString(count) + "\n";
876 count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientation);
878 theDump += " Bad Orientation .......................... ";
879 theDump += TCollection_AsciiString(count) + "\n";
881 count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientationOfSubshape);
883 theDump += " Bad Orientation of Subshape .............. ";
884 theDump += TCollection_AsciiString(count) + "\n";
886 count = NbProblems->Value((Standard_Integer)BRepCheck_CheckFail);
888 theDump += " checkshape failure ....................... ";
889 theDump += TCollection_AsciiString(count) + "\n";
892 theDump += " ------------------------------------------------\n";
893 theDump += "*** Shapes with problems : ";
894 theDump += TCollection_AsciiString(sl->Length()) + "\n";
896 Standard_Integer nbv, nbe, nbw, nbf, nbs, nbo;
897 nbv = nbe = nbw = nbf = nbs = nbo = 0;
899 for (i = 1; i <= sl->Length(); i++) {
900 TopoDS_Shape shi = sl->Value(i);
901 TopAbs_ShapeEnum sti = shi.ShapeType();
903 case TopAbs_VERTEX : nbv++; break;
904 case TopAbs_EDGE : nbe++; break;
905 case TopAbs_WIRE : nbw++; break;
906 case TopAbs_FACE : nbf++; break;
907 case TopAbs_SHELL : nbs++; break;
908 case TopAbs_SOLID : nbo++; break;
914 theDump += "VERTEX : ";
915 if (nbv < 10) theDump += " ";
916 theDump += TCollection_AsciiString(nbv) + "\n";
919 theDump += "EDGE : ";
920 if (nbe < 10) theDump += " ";
921 theDump += TCollection_AsciiString(nbe) + "\n";
924 theDump += "WIRE : ";
925 if (nbw < 10) theDump += " ";
926 theDump += TCollection_AsciiString(nbw) + "\n";
929 theDump += "FACE : ";
930 if (nbf < 10) theDump += " ";
931 theDump += TCollection_AsciiString(nbf) + "\n";
934 theDump += "SHELL : ";
935 if (nbs < 10) theDump += " ";
936 theDump += TCollection_AsciiString(nbs) + "\n";
939 theDump += "SOLID : ";
940 if (nbo < 10) theDump += " ";
941 theDump += TCollection_AsciiString(nbo) + "\n";
945 //=======================================================================
946 //function : GetProblemShapes
947 // purpose : for StructuralDump
948 //=======================================================================
949 void GEOMImpl_IMeasureOperations::GetProblemShapes (const BRepCheck_Analyzer& theAna,
950 const TopoDS_Shape& theShape,
951 Handle(TopTools_HSequenceOfShape)& sl,
952 Handle(TColStd_HArray1OfInteger)& NbProblems,
953 TopTools_DataMapOfShapeListOfShape& theMap)
955 for (TopoDS_Iterator iter(theShape); iter.More(); iter.Next()) {
956 GetProblemShapes(theAna, iter.Value(), sl, NbProblems, theMap);
958 TopAbs_ShapeEnum styp = theShape.ShapeType();
959 BRepCheck_ListIteratorOfListOfStatus itl;
960 TopTools_ListOfShape empty;
961 if (!theMap.IsBound(theShape)) {
962 theMap.Bind(theShape,empty);
964 if (!theAna.Result(theShape).IsNull()) {
965 itl.Initialize(theAna.Result(theShape)->Status());
966 // !!! May be, we have to print all the problems, not only the first one ?
967 if (itl.Value() != BRepCheck_NoError) {
968 sl->Append(theShape);
969 BRepCheck_Status stat = itl.Value();
970 NbProblems->SetValue((Standard_Integer)stat,
971 NbProblems->Value((Standard_Integer)stat) + 1);
978 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_VERTEX, theMap);
981 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_WIRE, theMap);
982 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_EDGE, theMap);
983 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_VERTEX, theMap);
988 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_SHELL, theMap);
995 //=======================================================================
996 //function : Contains
997 //=======================================================================
998 static Standard_Boolean Contains (const TopTools_ListOfShape& L,
999 const TopoDS_Shape& S)
1001 TopTools_ListIteratorOfListOfShape it;
1002 for (it.Initialize(L); it.More(); it.Next()) {
1003 if (it.Value().IsSame(S)) {
1004 return Standard_True;
1007 return Standard_False;
1010 //=======================================================================
1011 //function : GetProblemSub
1012 // purpose : for StructuralDump
1013 //=======================================================================
1014 void GEOMImpl_IMeasureOperations::GetProblemSub (const BRepCheck_Analyzer& theAna,
1015 const TopoDS_Shape& theShape,
1016 Handle(TopTools_HSequenceOfShape)& sl,
1017 Handle(TColStd_HArray1OfInteger)& NbProblems,
1018 const TopAbs_ShapeEnum Subtype,
1019 TopTools_DataMapOfShapeListOfShape& theMap)
1021 BRepCheck_ListIteratorOfListOfStatus itl;
1022 TopExp_Explorer exp;
1023 for (exp.Init(theShape, Subtype); exp.More(); exp.Next()) {
1024 const TopoDS_Shape& sub = exp.Current();
1026 const Handle(BRepCheck_Result)& res = theAna.Result(sub);
1027 for (res->InitContextIterator();
1028 res->MoreShapeInContext();
1029 res->NextShapeInContext()) {
1030 if (res->ContextualShape().IsSame(theShape) && !Contains(theMap(sub), theShape)) {
1031 theMap(sub).Append(theShape);
1032 itl.Initialize(res->StatusOnShape());
1034 if (itl.Value() != BRepCheck_NoError) {
1035 Standard_Integer ii = 0;
1037 for (ii = 1; ii <= sl->Length(); ii++)
1038 if (sl->Value(ii).IsSame(sub)) break;
1040 if (ii > sl->Length()) {
1042 BRepCheck_Status stat = itl.Value();
1043 NbProblems->SetValue((Standard_Integer)stat,
1044 NbProblems->Value((Standard_Integer)stat) + 1);
1046 for (ii = 1; ii <= sl->Length(); ii++)
1047 if (sl->Value(ii).IsSame(theShape)) break;
1048 if (ii > sl->Length()) {
1049 sl->Append(theShape);
1050 BRepCheck_Status stat = itl.Value();
1051 NbProblems->SetValue((Standard_Integer)stat,
1052 NbProblems->Value((Standard_Integer)stat) + 1);