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
21 #include <Standard_Stream.hxx>
23 #include <GEOMImpl_IMeasureOperations.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOMImpl_MeasureDriver.hxx>
27 #include <GEOMImpl_IMeasure.hxx>
29 #include <GEOMAlgo_ShapeInfo.hxx>
30 #include <GEOMAlgo_ShapeInfoFiller.hxx>
32 #include <GEOM_Function.hxx>
33 #include <GEOM_PythonDump.hxx>
35 #include <utilities.h>
37 #include <Utils_ExceptHandlers.hxx>
40 #include <TFunction_DriverTable.hxx>
41 #include <TFunction_Driver.hxx>
42 #include <TFunction_Logbook.hxx>
43 #include <TDF_Tool.hxx>
45 #include <BRep_Tool.hxx>
46 #include <BRepAdaptor_Surface.hxx>
47 #include <BRepBndLib.hxx>
48 #include <BRepCheck.hxx>
49 #include <BRepCheck_Result.hxx>
50 #include <BRepCheck_ListIteratorOfListOfStatus.hxx>
51 #include <BRepExtrema_DistShapeShape.hxx>
52 #include <BRepGProp.hxx>
53 #include <BRepTools.hxx>
55 #include <Bnd_Box.hxx>
57 #include <GProp_GProps.hxx>
58 #include <GProp_PrincipalProps.hxx>
62 #include <TopoDS_Edge.hxx>
63 #include <TopoDS_Face.hxx>
64 #include <TopoDS_Shape.hxx>
65 #include <TopoDS_Vertex.hxx>
66 #include <TopoDS_Iterator.hxx>
67 #include <TopExp_Explorer.hxx>
68 #include <TopTools_MapOfShape.hxx>
69 #include <TopTools_ListOfShape.hxx>
70 #include <TopTools_ListIteratorOfListOfShape.hxx>
72 #include <GeomAbs_SurfaceType.hxx>
73 #include <Geom_Surface.hxx>
74 #include <Geom_Plane.hxx>
75 #include <Geom_SphericalSurface.hxx>
76 #include <Geom_CylindricalSurface.hxx>
77 #include <Geom_ToroidalSurface.hxx>
78 #include <Geom_ConicalSurface.hxx>
79 #include <Geom_SurfaceOfLinearExtrusion.hxx>
80 #include <Geom_SurfaceOfRevolution.hxx>
81 #include <Geom_BezierSurface.hxx>
82 #include <Geom_BSplineSurface.hxx>
83 #include <Geom_RectangularTrimmedSurface.hxx>
84 #include <Geom_OffsetSurface.hxx>
85 #include <Geom_Line.hxx>
90 #include <Standard_Failure.hxx>
91 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
93 //=============================================================================
97 //=============================================================================
98 GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations (GEOM_Engine* theEngine, int theDocID)
99 : GEOM_IOperations(theEngine, theDocID)
101 MESSAGE("GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations");
104 //=============================================================================
108 //=============================================================================
109 GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations()
111 MESSAGE("GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations");
114 //=============================================================================
115 /*! Get kind and parameters of the given shape.
117 //=============================================================================
118 GEOMImpl_IMeasureOperations::ShapeKind GEOMImpl_IMeasureOperations::KindOfShape
119 (Handle(GEOM_Object) theShape,
120 Handle(TColStd_HSequenceOfInteger)& theIntegers,
121 Handle(TColStd_HSequenceOfReal)& theDoubles)
124 ShapeKind aKind = SK_NO_SHAPE;
126 if (theIntegers.IsNull()) theIntegers = new TColStd_HSequenceOfInteger;
127 else theIntegers->Clear();
129 if (theDoubles.IsNull()) theDoubles = new TColStd_HSequenceOfReal;
130 else theDoubles->Clear();
132 if (theShape.IsNull())
135 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
136 if (aRefShape.IsNull()) return aKind;
138 TopoDS_Shape aShape = aRefShape->GetValue();
139 if (aShape.IsNull()) return aKind;
142 GEOMAlgo_ShapeInfoFiller aSF;
143 aSF.SetShape(aShape);
145 Standard_Integer iErr = aSF.ErrorStatus();
147 SetErrorCode("Error in GEOMAlgo_ShapeInfoFiller");
150 const GEOMAlgo_ShapeInfo& anInfo = aSF.Info();
152 // Interprete results
153 TopAbs_ShapeEnum aType = anInfo.Type();
156 case TopAbs_COMPOUND:
157 case TopAbs_COMPSOLID:
159 // (+) geompy.kind.COMPOUND nb_solids nb_faces nb_edges nb_vertices
160 // (+) geompy.kind.COMPSOLID nb_solids nb_faces nb_edges nb_vertices
161 // ??? "nb_faces" - all faces or only 'standalone' faces?
162 if (aType == TopAbs_COMPOUND)
165 aKind = SK_COMPSOLID;
167 //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPOUND));
168 //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPSOLID));
169 theIntegers->Append(anInfo.NbSubShapes(TopAbs_SOLID));
170 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
171 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
172 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
178 // (+) geompy.kind.SHELL geompy.info.closed nb_faces nb_edges nb_vertices
179 // (+) geompy.kind.SHELL geompy.info.unclosed nb_faces nb_edges nb_vertices
182 theIntegers->Append((int)anInfo.KindOfClosed());
184 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
185 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
186 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
192 // (+) geompy.kind.WIRE geompy.info.closed nb_edges nb_vertices
193 // (+) geompy.kind.WIRE geompy.info.unclosed nb_edges nb_vertices
196 theIntegers->Append((int)anInfo.KindOfClosed());
198 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
199 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
207 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
210 case GEOMAlgo_KN_SPHERE:
211 // (+) geompy.kind.SPHERE xc yc zc R
215 gp_Pnt aC = anInfo.Location();
216 theDoubles->Append(aC.X());
217 theDoubles->Append(aC.Y());
218 theDoubles->Append(aC.Z());
220 theDoubles->Append(anInfo.Radius1());
223 case GEOMAlgo_KN_CYLINDER:
224 // (+) geompy.kind.CYLINDER xb yb zb dx dy dz R H
228 gp_Pnt aC = anInfo.Location();
229 theDoubles->Append(aC.X());
230 theDoubles->Append(aC.Y());
231 theDoubles->Append(aC.Z());
233 gp_Ax3 anAx3 = anInfo.Position();
234 gp_Dir aD = anAx3.Direction();
235 theDoubles->Append(aD.X());
236 theDoubles->Append(aD.Y());
237 theDoubles->Append(aD.Z());
239 theDoubles->Append(anInfo.Radius1());
240 theDoubles->Append(anInfo.Height());
243 case GEOMAlgo_KN_BOX:
244 // (+) geompy.kind.BOX xc yc zc ax ay az
248 gp_Pnt aC = anInfo.Location();
249 theDoubles->Append(aC.X());
250 theDoubles->Append(aC.Y());
251 theDoubles->Append(aC.Z());
253 gp_Ax3 anAx3 = anInfo.Position();
254 gp_Dir aD = anAx3.Direction();
255 gp_Dir aX = anAx3.XDirection();
258 if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
259 aX.IsParallel(gp::DX(), Precision::Angular())) {
260 theDoubles->Append(anInfo.Length()); // ax'
261 theDoubles->Append(anInfo.Width()); // ay'
262 theDoubles->Append(anInfo.Height()); // az'
264 else if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
265 aX.IsParallel(gp::DY(), Precision::Angular())) {
266 theDoubles->Append(anInfo.Width()); // ay'
267 theDoubles->Append(anInfo.Length()); // ax'
268 theDoubles->Append(anInfo.Height()); // az'
270 else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
271 aX.IsParallel(gp::DZ(), Precision::Angular())) {
272 theDoubles->Append(anInfo.Height()); // az'
273 theDoubles->Append(anInfo.Width()); // ay'
274 theDoubles->Append(anInfo.Length()); // ax'
276 else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
277 aX.IsParallel(gp::DY(), Precision::Angular())) {
278 theDoubles->Append(anInfo.Height()); // az'
279 theDoubles->Append(anInfo.Length()); // ax'
280 theDoubles->Append(anInfo.Width()); // ay'
282 else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
283 aX.IsParallel(gp::DZ(), Precision::Angular())) {
284 theDoubles->Append(anInfo.Width()); // ay'
285 theDoubles->Append(anInfo.Height()); // az'
286 theDoubles->Append(anInfo.Length()); // ax'
288 else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
289 aX.IsParallel(gp::DX(), Precision::Angular())) {
290 theDoubles->Append(anInfo.Length()); // ax'
291 theDoubles->Append(anInfo.Height()); // az'
292 theDoubles->Append(anInfo.Width()); // ay'
295 // (+) geompy.kind.ROTATED_BOX xo yo zo zx zy zz xx xy xz ax ay az
296 aKind = SK_ROTATED_BOX;
298 // Direction and XDirection
299 theDoubles->Append(aD.X());
300 theDoubles->Append(aD.Y());
301 theDoubles->Append(aD.Z());
303 theDoubles->Append(aX.X());
304 theDoubles->Append(aX.Y());
305 theDoubles->Append(aX.Z());
308 theDoubles->Append(anInfo.Length());
309 theDoubles->Append(anInfo.Width());
310 theDoubles->Append(anInfo.Height());
314 case GEOMAlgo_KN_TORUS:
315 // (+) geompy.kind.TORUS xc yc zc dx dy dz R_1 R_2
319 gp_Pnt aO = anInfo.Location();
320 theDoubles->Append(aO.X());
321 theDoubles->Append(aO.Y());
322 theDoubles->Append(aO.Z());
324 gp_Ax3 anAx3 = anInfo.Position();
325 gp_Dir aD = anAx3.Direction();
326 theDoubles->Append(aD.X());
327 theDoubles->Append(aD.Y());
328 theDoubles->Append(aD.Z());
330 theDoubles->Append(anInfo.Radius1());
331 theDoubles->Append(anInfo.Radius2());
334 case GEOMAlgo_KN_CONE:
335 // (+) geompy.kind.CONE xb yb zb dx dy dz R_1 R_2 H
339 gp_Pnt aO = anInfo.Location();
340 theDoubles->Append(aO.X());
341 theDoubles->Append(aO.Y());
342 theDoubles->Append(aO.Z());
344 gp_Ax3 anAx3 = anInfo.Position();
345 gp_Dir aD = anAx3.Direction();
346 theDoubles->Append(aD.X());
347 theDoubles->Append(aD.Y());
348 theDoubles->Append(aD.Z());
350 theDoubles->Append(anInfo.Radius1());
351 theDoubles->Append(anInfo.Radius2());
352 theDoubles->Append(anInfo.Height());
355 case GEOMAlgo_KN_POLYHEDRON:
356 // (+) geompy.kind.POLYHEDRON nb_faces nb_edges nb_vertices
358 aKind = SK_POLYHEDRON;
360 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
361 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
362 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
366 // (+) geompy.kind.SOLID nb_faces nb_edges nb_vertices
368 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
369 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
370 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
380 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
382 case GEOMAlgo_KN_SPHERE:
383 // (+) geompy.kind.SPHERE2D xc yc zc R
387 gp_Pnt aC = anInfo.Location();
388 theDoubles->Append(aC.X());
389 theDoubles->Append(aC.Y());
390 theDoubles->Append(aC.Z());
392 theDoubles->Append(anInfo.Radius1());
395 case GEOMAlgo_KN_CYLINDER:
396 // (+) geompy.kind.CYLINDER2D xb yb zb dx dy dz R H
398 aKind = SK_CYLINDER2D;
400 gp_Pnt aO = anInfo.Location();
401 theDoubles->Append(aO.X());
402 theDoubles->Append(aO.Y());
403 theDoubles->Append(aO.Z());
405 gp_Ax3 anAx3 = anInfo.Position();
406 gp_Dir aD = anAx3.Direction();
407 theDoubles->Append(aD.X());
408 theDoubles->Append(aD.Y());
409 theDoubles->Append(aD.Z());
411 theDoubles->Append(anInfo.Radius1());
412 theDoubles->Append(anInfo.Height());
415 case GEOMAlgo_KN_TORUS:
416 // (+) geompy.kind.TORUS2D xc yc zc dx dy dz R_1 R_2
420 gp_Pnt aO = anInfo.Location();
421 theDoubles->Append(aO.X());
422 theDoubles->Append(aO.Y());
423 theDoubles->Append(aO.Z());
425 gp_Ax3 anAx3 = anInfo.Position();
426 gp_Dir aD = anAx3.Direction();
427 theDoubles->Append(aD.X());
428 theDoubles->Append(aD.Y());
429 theDoubles->Append(aD.Z());
431 theDoubles->Append(anInfo.Radius1());
432 theDoubles->Append(anInfo.Radius2());
435 case GEOMAlgo_KN_CONE:
436 // (+) geompy.kind.CONE2D xc yc zc dx dy dz R_1 R_2 H
440 gp_Pnt aO = anInfo.Location();
441 theDoubles->Append(aO.X());
442 theDoubles->Append(aO.Y());
443 theDoubles->Append(aO.Z());
445 gp_Ax3 anAx3 = anInfo.Position();
446 gp_Dir aD = anAx3.Direction();
447 theDoubles->Append(aD.X());
448 theDoubles->Append(aD.Y());
449 theDoubles->Append(aD.Z());
451 theDoubles->Append(anInfo.Radius1());
452 theDoubles->Append(anInfo.Radius2());
453 theDoubles->Append(anInfo.Height());
456 case GEOMAlgo_KN_DISKCIRCLE:
457 // (+) geompy.kind.DISK_CIRCLE xc yc zc dx dy dz R
459 aKind = SK_DISK_CIRCLE;
461 gp_Pnt aC = anInfo.Location();
462 theDoubles->Append(aC.X());
463 theDoubles->Append(aC.Y());
464 theDoubles->Append(aC.Z());
466 gp_Ax3 anAx3 = anInfo.Position();
467 gp_Dir aD = anAx3.Direction();
468 theDoubles->Append(aD.X());
469 theDoubles->Append(aD.Y());
470 theDoubles->Append(aD.Z());
472 theDoubles->Append(anInfo.Radius1());
475 case GEOMAlgo_KN_DISKELLIPSE:
476 // (+) geompy.kind.DISK_ELLIPSE xc yc zc dx dy dz R_1 R_2
478 aKind = SK_DISK_ELLIPSE;
480 gp_Pnt aC = anInfo.Location();
481 theDoubles->Append(aC.X());
482 theDoubles->Append(aC.Y());
483 theDoubles->Append(aC.Z());
485 gp_Ax3 anAx3 = anInfo.Position();
486 gp_Dir aD = anAx3.Direction();
487 theDoubles->Append(aD.X());
488 theDoubles->Append(aD.Y());
489 theDoubles->Append(aD.Z());
491 theDoubles->Append(anInfo.Radius1());
492 theDoubles->Append(anInfo.Radius2());
495 case GEOMAlgo_KN_RECTANGLE:
496 case GEOMAlgo_KN_TRIANGLE:
497 case GEOMAlgo_KN_QUADRANGLE:
498 case GEOMAlgo_KN_POLYGON:
499 // (+) geompy.kind.POLYGON xo yo zo dx dy dz nb_edges nb_vertices
503 gp_Pnt aO = anInfo.Location();
504 theDoubles->Append(aO.X());
505 theDoubles->Append(aO.Y());
506 theDoubles->Append(aO.Z());
508 gp_Ax3 anAx3 = anInfo.Position();
509 gp_Dir aD = anAx3.Direction();
510 theDoubles->Append(aD.X());
511 theDoubles->Append(aD.Y());
512 theDoubles->Append(aD.Z());
514 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
515 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
518 case GEOMAlgo_KN_PLANE: // infinite
519 // (+) geompy.kind.PLANE xo yo zo dx dy dz
523 gp_Pnt aC = anInfo.Location();
524 theDoubles->Append(aC.X());
525 theDoubles->Append(aC.Y());
526 theDoubles->Append(aC.Z());
528 gp_Ax3 anAx3 = anInfo.Position();
529 gp_Dir aD = anAx3.Direction();
530 theDoubles->Append(aD.X());
531 theDoubles->Append(aD.Y());
532 theDoubles->Append(aD.Z());
536 if (anInfo.KindOfShape() == GEOMAlgo_KS_PLANE) {
537 // (+) geompy.kind.PLANAR xo yo zo dx dy dz nb_edges nb_vertices
541 gp_Pnt aC = anInfo.Location();
542 theDoubles->Append(aC.X());
543 theDoubles->Append(aC.Y());
544 theDoubles->Append(aC.Z());
546 gp_Ax3 anAx3 = anInfo.Position();
547 gp_Dir aD = anAx3.Direction();
548 theDoubles->Append(aD.X());
549 theDoubles->Append(aD.Y());
550 theDoubles->Append(aD.Z());
552 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
553 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
556 // ??? geompy.kind.FACE nb_edges nb_vertices _surface_type_id_
557 // (+) geompy.kind.FACE nb_edges nb_vertices
559 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
560 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
570 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
572 case GEOMAlgo_KN_CIRCLE:
574 // (+) geompy.kind.CIRCLE xc yc zc dx dy dz R
577 gp_Pnt aC = anInfo.Location();
578 theDoubles->Append(aC.X());
579 theDoubles->Append(aC.Y());
580 theDoubles->Append(aC.Z());
582 gp_Ax3 anAx3 = anInfo.Position();
583 gp_Dir aD = anAx3.Direction();
584 theDoubles->Append(aD.X());
585 theDoubles->Append(aD.Y());
586 theDoubles->Append(aD.Z());
588 theDoubles->Append(anInfo.Radius1());
591 case GEOMAlgo_KN_ARCCIRCLE:
593 // (+) geompy.kind.ARC_CIRCLE xc yc zc dx dy dz R x1 y1 z1 x2 y2 z2
594 aKind = SK_ARC_CIRCLE;
596 gp_Pnt aC = anInfo.Location();
597 theDoubles->Append(aC.X());
598 theDoubles->Append(aC.Y());
599 theDoubles->Append(aC.Z());
601 gp_Ax3 anAx3 = anInfo.Position();
602 gp_Dir aD = anAx3.Direction();
603 theDoubles->Append(aD.X());
604 theDoubles->Append(aD.Y());
605 theDoubles->Append(aD.Z());
607 theDoubles->Append(anInfo.Radius1());
609 gp_Pnt aP1 = anInfo.Pnt1();
610 theDoubles->Append(aP1.X());
611 theDoubles->Append(aP1.Y());
612 theDoubles->Append(aP1.Z());
614 gp_Pnt aP2 = anInfo.Pnt2();
615 theDoubles->Append(aP2.X());
616 theDoubles->Append(aP2.Y());
617 theDoubles->Append(aP2.Z());
620 case GEOMAlgo_KN_ELLIPSE:
622 // (+) geompy.kind.ELLIPSE xc yc zc dx dy dz R_1 R_2
625 gp_Pnt aC = anInfo.Location();
626 theDoubles->Append(aC.X());
627 theDoubles->Append(aC.Y());
628 theDoubles->Append(aC.Z());
630 gp_Ax3 anAx3 = anInfo.Position();
631 gp_Dir aD = anAx3.Direction();
632 theDoubles->Append(aD.X());
633 theDoubles->Append(aD.Y());
634 theDoubles->Append(aD.Z());
636 theDoubles->Append(anInfo.Radius1());
637 theDoubles->Append(anInfo.Radius2());
640 case GEOMAlgo_KN_ARCELLIPSE:
642 // (+) geompy.kind.ARC_ELLIPSE xc yc zc dx dy dz R_1 R_2 x1 y1 z1 x2 y2 z2
643 aKind = SK_ARC_ELLIPSE;
645 gp_Pnt aC = anInfo.Location();
646 theDoubles->Append(aC.X());
647 theDoubles->Append(aC.Y());
648 theDoubles->Append(aC.Z());
650 gp_Ax3 anAx3 = anInfo.Position();
651 gp_Dir aD = anAx3.Direction();
652 theDoubles->Append(aD.X());
653 theDoubles->Append(aD.Y());
654 theDoubles->Append(aD.Z());
656 theDoubles->Append(anInfo.Radius1());
657 theDoubles->Append(anInfo.Radius2());
659 gp_Pnt aP1 = anInfo.Pnt1();
660 theDoubles->Append(aP1.X());
661 theDoubles->Append(aP1.Y());
662 theDoubles->Append(aP1.Z());
664 gp_Pnt aP2 = anInfo.Pnt2();
665 theDoubles->Append(aP2.X());
666 theDoubles->Append(aP2.Y());
667 theDoubles->Append(aP2.Z());
670 case GEOMAlgo_KN_LINE:
672 // ??? geompy.kind.LINE x1 y1 z1 x2 y2 z2
673 // (+) geompy.kind.LINE x1 y1 z1 dx dy dz
676 gp_Pnt aO = anInfo.Location();
677 theDoubles->Append(aO.X());
678 theDoubles->Append(aO.Y());
679 theDoubles->Append(aO.Z());
681 gp_Dir aD = anInfo.Direction();
682 theDoubles->Append(aD.X());
683 theDoubles->Append(aD.Y());
684 theDoubles->Append(aD.Z());
687 case GEOMAlgo_KN_SEGMENT:
689 // (+) geompy.kind.SEGMENT x1 y1 z1 x2 y2 z2
692 gp_Pnt aP1 = anInfo.Pnt1();
693 theDoubles->Append(aP1.X());
694 theDoubles->Append(aP1.Y());
695 theDoubles->Append(aP1.Z());
697 gp_Pnt aP2 = anInfo.Pnt2();
698 theDoubles->Append(aP2.X());
699 theDoubles->Append(aP2.Y());
700 theDoubles->Append(aP2.Z());
704 // ??? geompy.kind.EDGE nb_vertices _curve_type_id_
705 // (+) geompy.kind.EDGE nb_vertices
706 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
713 // (+) geompy.kind.VERTEX x y z
716 gp_Pnt aP = anInfo.Location();
717 theDoubles->Append(aP.X());
718 theDoubles->Append(aP.Y());
719 theDoubles->Append(aP.Z());
728 //=============================================================================
729 /*! Get LCS, corresponding to the given shape.
730 * Origin of the LCS is situated at the shape's center of mass.
731 * Axes of the LCS are obtained from shape's location or,
732 * if the shape is a planar face, from position of its plane.
734 //=============================================================================
735 gp_Ax3 GEOMImpl_IMeasureOperations::GetPosition (const TopoDS_Shape& theShape)
739 if (theShape.IsNull())
743 aResult.Transform(theShape.Location().Transformation());
744 if (theShape.ShapeType() == TopAbs_FACE) {
745 Handle(Geom_Surface) aGS = BRep_Tool::Surface(TopoDS::Face(theShape));
746 if (!aGS.IsNull() && aGS->IsKind(STANDARD_TYPE(Geom_Plane))) {
747 Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast(aGS);
748 gp_Pln aPln = aGPlane->Pln();
749 aResult = aPln.Position();
755 if (theShape.ShapeType() == TopAbs_VERTEX) {
756 aPnt = BRep_Tool::Pnt(TopoDS::Vertex(theShape));
759 GProp_GProps aSystem;
760 if (theShape.ShapeType() == TopAbs_EDGE || theShape.ShapeType() == TopAbs_WIRE)
761 BRepGProp::LinearProperties(theShape, aSystem);
762 else if (theShape.ShapeType() == TopAbs_FACE || theShape.ShapeType() == TopAbs_SHELL)
763 BRepGProp::SurfaceProperties(theShape, aSystem);
765 BRepGProp::VolumeProperties(theShape, aSystem);
767 aPnt = aSystem.CentreOfMass();
770 aResult.SetLocation(aPnt);
775 //=============================================================================
779 //=============================================================================
780 void GEOMImpl_IMeasureOperations::GetPosition
781 (Handle(GEOM_Object) theShape,
782 Standard_Real& Ox, Standard_Real& Oy, Standard_Real& Oz,
783 Standard_Real& Zx, Standard_Real& Zy, Standard_Real& Zz,
784 Standard_Real& Xx, Standard_Real& Xy, Standard_Real& Xz)
788 //Set default values: global CS
789 Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
792 if (theShape.IsNull()) return;
794 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
795 if (aRefShape.IsNull()) return;
797 TopoDS_Shape aShape = aRefShape->GetValue();
798 if (aShape.IsNull()) {
799 SetErrorCode("The Objects has NULL Shape");
804 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
808 gp_Ax3 anAx3 = GetPosition(aShape);
810 gp_Pnt anOri = anAx3.Location();
811 gp_Dir aDirZ = anAx3.Direction();
812 gp_Dir aDirX = anAx3.XDirection();
815 anOri.Coord(Ox, Oy, Oz);
816 aDirZ.Coord(Zx, Zy, Zz);
817 aDirX.Coord(Xx, Xy, Xz);
819 catch (Standard_Failure) {
820 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
821 SetErrorCode(aFail->GetMessageString());
828 //=============================================================================
832 //=============================================================================
833 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetCentreOfMass
834 (Handle(GEOM_Object) theShape)
838 if (theShape.IsNull()) return NULL;
840 //Add a new CentreOfMass object
841 Handle(GEOM_Object) aCDG = GetEngine()->AddObject(GetDocID(), GEOM_CDG);
843 //Add a new CentreOfMass function
844 Handle(GEOM_Function) aFunction =
845 aCDG->AddFunction(GEOMImpl_MeasureDriver::GetID(), CDG_MEASURE);
846 if (aFunction.IsNull()) return NULL;
848 //Check if the function is set correctly
849 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
851 GEOMImpl_IMeasure aCI (aFunction);
853 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
854 if (aRefShape.IsNull()) return NULL;
856 aCI.SetBase(aRefShape);
858 //Compute the CentreOfMass value
860 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
863 if (!GetSolver()->ComputeFunction(aFunction)) {
864 SetErrorCode("Measure driver failed to compute centre of mass");
868 catch (Standard_Failure) {
869 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
870 SetErrorCode(aFail->GetMessageString());
874 //Make a Python command
875 GEOM::TPythonDump(aFunction) << aCDG << " = geompy.MakeCDG(" << theShape << ")";
881 //=============================================================================
885 //=============================================================================
886 void GEOMImpl_IMeasureOperations::GetBasicProperties (Handle(GEOM_Object) theShape,
887 Standard_Real& theLength,
888 Standard_Real& theSurfArea,
889 Standard_Real& theVolume)
893 if (theShape.IsNull()) return;
895 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
896 if (aRefShape.IsNull()) return;
898 TopoDS_Shape aShape = aRefShape->GetValue();
899 if (aShape.IsNull()) {
900 SetErrorCode("The Objects has NULL Shape");
904 //Compute the parameters
905 GProp_GProps LProps, SProps;
907 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
910 BRepGProp::LinearProperties(aShape, LProps);
911 theLength = LProps.Mass();
913 BRepGProp::SurfaceProperties(aShape, SProps);
914 theSurfArea = SProps.Mass();
917 if (aShape.ShapeType() < TopAbs_SHELL) {
918 for (TopExp_Explorer Exp (aShape, TopAbs_SOLID); Exp.More(); Exp.Next()) {
920 BRepGProp::VolumeProperties(Exp.Current(), VProps);
921 theVolume += VProps.Mass();
925 catch (Standard_Failure) {
926 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
927 SetErrorCode(aFail->GetMessageString());
934 //=============================================================================
938 //=============================================================================
939 void GEOMImpl_IMeasureOperations::GetInertia
940 (Handle(GEOM_Object) theShape,
941 Standard_Real& I11, Standard_Real& I12, Standard_Real& I13,
942 Standard_Real& I21, Standard_Real& I22, Standard_Real& I23,
943 Standard_Real& I31, Standard_Real& I32, Standard_Real& I33,
944 Standard_Real& Ix , Standard_Real& Iy , Standard_Real& Iz)
948 if (theShape.IsNull()) return;
950 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
951 if (aRefShape.IsNull()) return;
953 TopoDS_Shape aShape = aRefShape->GetValue();
954 if (aShape.IsNull()) {
955 SetErrorCode("The Objects has NULL Shape");
959 //Compute the parameters
963 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
966 if (aShape.ShapeType() == TopAbs_VERTEX ||
967 aShape.ShapeType() == TopAbs_EDGE ||
968 aShape.ShapeType() == TopAbs_WIRE) {
969 BRepGProp::LinearProperties(aShape, System);
970 } else if (aShape.ShapeType() == TopAbs_FACE ||
971 aShape.ShapeType() == TopAbs_SHELL) {
972 BRepGProp::SurfaceProperties(aShape, System);
974 BRepGProp::VolumeProperties(aShape, System);
976 gp_Mat I = System.MatrixOfInertia();
990 GProp_PrincipalProps Pr = System.PrincipalProperties();
991 Pr.Moments(Ix,Iy,Iz);
993 catch (Standard_Failure) {
994 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
995 SetErrorCode(aFail->GetMessageString());
1002 //=============================================================================
1006 //=============================================================================
1007 void GEOMImpl_IMeasureOperations::GetBoundingBox
1008 (Handle(GEOM_Object) theShape,
1009 Standard_Real& Xmin, Standard_Real& Xmax,
1010 Standard_Real& Ymin, Standard_Real& Ymax,
1011 Standard_Real& Zmin, Standard_Real& Zmax)
1015 if (theShape.IsNull()) return;
1017 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1018 if (aRefShape.IsNull()) return;
1020 TopoDS_Shape aShape = aRefShape->GetValue();
1021 if (aShape.IsNull()) {
1022 SetErrorCode("The Objects has NULL Shape");
1026 //Compute the parameters
1030 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1033 BRepBndLib::Add(aShape, B);
1034 B.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
1036 catch (Standard_Failure) {
1037 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1038 SetErrorCode(aFail->GetMessageString());
1045 //=============================================================================
1049 //=============================================================================
1050 void GEOMImpl_IMeasureOperations::GetTolerance
1051 (Handle(GEOM_Object) theShape,
1052 Standard_Real& FaceMin, Standard_Real& FaceMax,
1053 Standard_Real& EdgeMin, Standard_Real& EdgeMax,
1054 Standard_Real& VertMin, Standard_Real& VertMax)
1058 if (theShape.IsNull()) return;
1060 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1061 if (aRefShape.IsNull()) return;
1063 TopoDS_Shape aShape = aRefShape->GetValue();
1064 if (aShape.IsNull()) {
1065 SetErrorCode("The Objects has NULL Shape");
1069 //Compute the parameters
1071 FaceMin = EdgeMin = VertMin = RealLast();
1072 FaceMax = EdgeMax = VertMax = -RealLast();
1075 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1078 for (TopExp_Explorer ExF (aShape, TopAbs_FACE); ExF.More(); ExF.Next()) {
1079 TopoDS_Face Face = TopoDS::Face(ExF.Current());
1080 T = BRep_Tool::Tolerance(Face);
1086 for (TopExp_Explorer ExE (aShape, TopAbs_EDGE); ExE.More(); ExE.Next()) {
1087 TopoDS_Edge Edge = TopoDS::Edge(ExE.Current());
1088 T = BRep_Tool::Tolerance(Edge);
1094 for (TopExp_Explorer ExV (aShape, TopAbs_VERTEX); ExV.More(); ExV.Next()) {
1095 TopoDS_Vertex Vertex = TopoDS::Vertex(ExV.Current());
1096 T = BRep_Tool::Tolerance(Vertex);
1103 catch (Standard_Failure) {
1104 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1105 SetErrorCode(aFail->GetMessageString());
1112 //=============================================================================
1116 //=============================================================================
1117 bool GEOMImpl_IMeasureOperations::CheckShape (Handle(GEOM_Object) theShape,
1118 const Standard_Boolean theIsCheckGeom,
1119 TCollection_AsciiString& theDump)
1123 if (theShape.IsNull()) return false;
1125 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1126 if (aRefShape.IsNull()) return false;
1128 TopoDS_Shape aShape = aRefShape->GetValue();
1129 if (aShape.IsNull()) {
1130 SetErrorCode("The Objects has NULL Shape");
1134 //Compute the parameters
1135 bool isValid = false;
1137 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1140 BRepCheck_Analyzer ana (aShape, theIsCheckGeom);
1141 if (ana.IsValid()) {
1145 StructuralDump(ana, aShape, theDump);
1148 catch (Standard_Failure) {
1149 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1150 SetErrorCode(aFail->GetMessageString());
1158 //=============================================================================
1162 //=============================================================================
1163 TCollection_AsciiString GEOMImpl_IMeasureOperations::WhatIs (Handle(GEOM_Object) theShape)
1167 TCollection_AsciiString Astr;
1169 if (theShape.IsNull()) return Astr;
1171 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1172 if (aRefShape.IsNull()) return Astr;
1174 TopoDS_Shape aShape = aRefShape->GetValue();
1175 if (aShape.IsNull()) {
1176 SetErrorCode("The Objects has NULL Shape");
1180 //Compute the parameters
1181 if (aShape.ShapeType() == TopAbs_EDGE) {
1182 if (BRep_Tool::Degenerated(TopoDS::Edge(aShape))) {
1183 Astr = Astr + " It is a degenerated edge \n";
1187 Astr = Astr + " Number of sub-shapes : \n";
1190 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1193 int iType, nbTypes [TopAbs_SHAPE];
1194 for (iType = 0; iType < TopAbs_SHAPE; ++iType)
1196 nbTypes[aShape.ShapeType()]++;
1198 TopTools_MapOfShape aMapOfShape;
1199 aMapOfShape.Add(aShape);
1200 TopTools_ListOfShape aListOfShape;
1201 aListOfShape.Append(aShape);
1203 TopTools_ListIteratorOfListOfShape itL (aListOfShape);
1204 for (; itL.More(); itL.Next()) {
1205 TopoDS_Iterator it (itL.Value());
1206 for (; it.More(); it.Next()) {
1207 TopoDS_Shape s = it.Value();
1208 if (aMapOfShape.Add(s)) {
1209 aListOfShape.Append(s);
1210 nbTypes[s.ShapeType()]++;
1215 Astr = Astr + " VERTEX : " + TCollection_AsciiString(nbTypes[TopAbs_VERTEX]) + "\n";
1216 Astr = Astr + " EDGE : " + TCollection_AsciiString(nbTypes[TopAbs_EDGE]) + "\n";
1217 Astr = Astr + " WIRE : " + TCollection_AsciiString(nbTypes[TopAbs_WIRE]) + "\n";
1218 Astr = Astr + " FACE : " + TCollection_AsciiString(nbTypes[TopAbs_FACE]) + "\n";
1219 Astr = Astr + " SHELL : " + TCollection_AsciiString(nbTypes[TopAbs_SHELL]) + "\n";
1220 Astr = Astr + " SOLID : " + TCollection_AsciiString(nbTypes[TopAbs_SOLID]) + "\n";
1221 Astr = Astr + " COMPSOLID : " + TCollection_AsciiString(nbTypes[TopAbs_COMPSOLID]) + "\n";
1222 Astr = Astr + " COMPOUND : " + TCollection_AsciiString(nbTypes[TopAbs_COMPOUND]) + "\n";
1223 Astr = Astr + " SHAPE : " + TCollection_AsciiString(aMapOfShape.Extent());
1225 catch (Standard_Failure) {
1226 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1227 SetErrorCode(aFail->GetMessageString());
1235 //=============================================================================
1239 //=============================================================================
1240 Standard_Real GEOMImpl_IMeasureOperations::GetMinDistance
1241 (Handle(GEOM_Object) theShape1, Handle(GEOM_Object) theShape2,
1242 Standard_Real& X1, Standard_Real& Y1, Standard_Real& Z1,
1243 Standard_Real& X2, Standard_Real& Y2, Standard_Real& Z2)
1246 Standard_Real MinDist = 1.e9;
1248 if (theShape1.IsNull() || theShape2.IsNull()) return MinDist;
1250 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
1251 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
1252 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return MinDist;
1254 TopoDS_Shape aShape1 = aRefShape1->GetValue();
1255 TopoDS_Shape aShape2 = aRefShape2->GetValue();
1256 if (aShape1.IsNull() || aShape2.IsNull()) {
1257 SetErrorCode("One of Objects has NULL Shape");
1261 //Compute the parameters
1263 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1266 BRepExtrema_DistShapeShape dst (aShape1, aShape2);
1268 gp_Pnt PMin1, PMin2, P1, P2;
1270 for (int i = 1; i <= dst.NbSolution(); i++) {
1271 P1 = dst.PointOnShape1(i);
1272 P2 = dst.PointOnShape2(i);
1274 Standard_Real Dist = P1.Distance(P2);
1275 if (MinDist > Dist) {
1282 PMin1.Coord(X1, Y1, Z1);
1283 PMin2.Coord(X2, Y2, Z2);
1286 catch (Standard_Failure) {
1287 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1288 SetErrorCode(aFail->GetMessageString());
1296 //=======================================================================
1298 * Get coordinates of point
1300 //=======================================================================
1301 void GEOMImpl_IMeasureOperations::PointCoordinates (Handle(GEOM_Object) theShape,
1302 Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ)
1306 if (theShape.IsNull())
1309 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1310 if (aRefShape.IsNull())
1313 TopoDS_Shape aShape = aRefShape->GetValue();
1314 if (aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX)
1316 SetErrorCode( "Shape must be a vertex" );
1321 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1324 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
1331 catch (Standard_Failure)
1333 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1334 SetErrorCode( aFail->GetMessageString() );
1338 //=======================================================================
1340 * Compute angle (in degrees) between two lines
1342 //=======================================================================
1343 Standard_Real GEOMImpl_IMeasureOperations::GetAngle (Handle(GEOM_Object) theLine1,
1344 Handle(GEOM_Object) theLine2)
1348 Standard_Real anAngle = -1.0;
1350 if (theLine1.IsNull() || theLine2.IsNull())
1353 Handle(GEOM_Function) aRefLine1 = theLine1->GetLastFunction();
1354 Handle(GEOM_Function) aRefLine2 = theLine2->GetLastFunction();
1355 if (aRefLine1.IsNull() || aRefLine2.IsNull())
1358 TopoDS_Shape aLine1 = aRefLine1->GetValue();
1359 TopoDS_Shape aLine2 = aRefLine2->GetValue();
1360 if (aLine1.IsNull() || aLine2.IsNull() ||
1361 aLine1.ShapeType() != TopAbs_EDGE ||
1362 aLine2.ShapeType() != TopAbs_EDGE)
1364 SetErrorCode("Two edges must be given");
1369 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1372 TopoDS_Edge E1 = TopoDS::Edge(aLine1);
1373 TopoDS_Edge E2 = TopoDS::Edge(aLine2);
1376 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp,lp);
1377 Handle(Geom_Curve) C2 = BRep_Tool::Curve(E2,fp,lp);
1379 if (!C1->IsKind(STANDARD_TYPE(Geom_Line)) ||
1380 !C2->IsKind(STANDARD_TYPE(Geom_Line)))
1382 SetErrorCode("The edges must be linear");
1386 Handle(Geom_Line) L1 = Handle(Geom_Line)::DownCast(C1);
1387 Handle(Geom_Line) L2 = Handle(Geom_Line)::DownCast(C2);
1389 gp_Lin aLin1 = L1->Lin();
1390 gp_Lin aLin2 = L2->Lin();
1392 anAngle = aLin1.Angle(aLin2);
1393 anAngle /= PI180; // convert radians into degrees
1397 catch (Standard_Failure)
1399 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1400 SetErrorCode(aFail->GetMessageString());
1406 //=======================================================================
1407 //function : StructuralDump
1408 //purpose : Structural (data exchange) style of output.
1409 //=======================================================================
1410 void GEOMImpl_IMeasureOperations::StructuralDump (const BRepCheck_Analyzer& theAna,
1411 const TopoDS_Shape& theShape,
1412 TCollection_AsciiString& theDump)
1416 theDump += " -- The Shape has problems :\n";
1417 theDump += " Check Count\n";
1418 theDump += " ------------------------------------------------\n";
1420 Standard_Integer last_stat = (Standard_Integer)BRepCheck_CheckFail;
1421 Handle(TColStd_HArray1OfInteger) NbProblems =
1422 new TColStd_HArray1OfInteger(1, last_stat);
1423 for (i = 1; i <= last_stat; i++)
1424 NbProblems->SetValue(i,0);
1426 Handle(TopTools_HSequenceOfShape) sl;
1427 sl = new TopTools_HSequenceOfShape();
1428 TopTools_DataMapOfShapeListOfShape theMap;
1430 GetProblemShapes(theAna, theShape, sl, NbProblems, theMap);
1433 Standard_Integer count = 0;
1434 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnCurve);
1436 theDump += " Invalid Point on Curve ................... ";
1437 theDump += TCollection_AsciiString(count) + "\n";
1439 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnCurveOnSurface);
1441 theDump += " Invalid Point on CurveOnSurface .......... ";
1442 theDump += TCollection_AsciiString(count) + "\n";
1444 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnSurface);
1446 theDump += " Invalid Point on Surface ................. ";
1447 theDump += TCollection_AsciiString(count) + "\n";
1449 count = NbProblems->Value((Standard_Integer)BRepCheck_No3DCurve);
1451 theDump += " No 3D Curve .............................. ";
1452 theDump += TCollection_AsciiString(count) + "\n";
1454 count = NbProblems->Value((Standard_Integer)BRepCheck_Multiple3DCurve);
1456 theDump += " Multiple 3D Curve ........................ ";
1457 theDump += TCollection_AsciiString(count) + "\n";
1459 count = NbProblems->Value((Standard_Integer)BRepCheck_Invalid3DCurve);
1461 theDump += " Invalid 3D Curve ......................... ";
1462 theDump += TCollection_AsciiString(count) + "\n";
1464 count = NbProblems->Value((Standard_Integer)BRepCheck_NoCurveOnSurface);
1466 theDump += " No Curve on Surface ...................... ";
1467 theDump += TCollection_AsciiString(count) + "\n";
1469 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidCurveOnSurface);
1471 theDump += " Invalid Curve on Surface ................. ";
1472 theDump += TCollection_AsciiString(count) + "\n";
1474 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidCurveOnClosedSurface);
1476 theDump += " Invalid Curve on closed Surface .......... ";
1477 theDump += TCollection_AsciiString(count) + "\n";
1479 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidSameRangeFlag);
1481 theDump += " Invalid SameRange Flag ................... ";
1482 theDump += TCollection_AsciiString(count) + "\n";
1484 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidSameParameterFlag);
1486 theDump += " Invalid SameParameter Flag ............... ";
1487 theDump += TCollection_AsciiString(count) + "\n";
1489 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidDegeneratedFlag);
1491 theDump += " Invalid Degenerated Flag ................. ";
1492 theDump += TCollection_AsciiString(count) + "\n";
1494 count = NbProblems->Value((Standard_Integer)BRepCheck_FreeEdge);
1496 theDump += " Free Edge ................................ ";
1497 theDump += TCollection_AsciiString(count) + "\n";
1499 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidMultiConnexity);
1501 theDump += " Invalid MultiConnexity ................... ";
1502 theDump += TCollection_AsciiString(count) + "\n";
1504 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidRange);
1506 theDump += " Invalid Range ............................ ";
1507 theDump += TCollection_AsciiString(count) + "\n";
1509 count = NbProblems->Value((Standard_Integer)BRepCheck_EmptyWire);
1511 theDump += " Empty Wire ............................... ";
1512 theDump += TCollection_AsciiString(count) + "\n";
1514 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantEdge);
1516 theDump += " Redundant Edge ........................... ";
1517 theDump += TCollection_AsciiString(count) + "\n";
1519 count = NbProblems->Value((Standard_Integer)BRepCheck_SelfIntersectingWire);
1521 theDump += " Self Intersecting Wire ................... ";
1522 theDump += TCollection_AsciiString(count) + "\n";
1524 count = NbProblems->Value((Standard_Integer)BRepCheck_NoSurface);
1526 theDump += " No Surface ............................... ";
1527 theDump += TCollection_AsciiString(count) + "\n";
1529 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidWire);
1531 theDump += " Invalid Wire ............................. ";
1532 theDump += TCollection_AsciiString(count) + "\n";
1534 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantWire);
1536 theDump += " Redundant Wire ........................... ";
1537 theDump += TCollection_AsciiString(count) + "\n";
1539 count = NbProblems->Value((Standard_Integer)BRepCheck_IntersectingWires);
1541 theDump += " Intersecting Wires ....................... ";
1542 theDump += TCollection_AsciiString(count) + "\n";
1544 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidImbricationOfWires);
1546 theDump += " Invalid Imbrication of Wires ............. ";
1547 theDump += TCollection_AsciiString(count) + "\n";
1549 count = NbProblems->Value((Standard_Integer)BRepCheck_EmptyShell);
1551 theDump += " Empty Shell .............................. ";
1552 theDump += TCollection_AsciiString(count) + "\n";
1554 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantFace);
1556 theDump += " Redundant Face ........................... ";
1557 theDump += TCollection_AsciiString(count) + "\n";
1559 count = NbProblems->Value((Standard_Integer)BRepCheck_UnorientableShape);
1561 theDump += " Unorientable Shape ....................... ";
1562 theDump += TCollection_AsciiString(count) + "\n";
1564 count = NbProblems->Value((Standard_Integer)BRepCheck_NotClosed);
1566 theDump += " Not Closed ............................... ";
1567 theDump += TCollection_AsciiString(count) + "\n";
1569 count = NbProblems->Value((Standard_Integer)BRepCheck_NotConnected);
1571 theDump += " Not Connected ............................ ";
1572 theDump += TCollection_AsciiString(count) + "\n";
1574 count = NbProblems->Value((Standard_Integer)BRepCheck_SubshapeNotInShape);
1576 theDump += " Subshape not in Shape .................... ";
1577 theDump += TCollection_AsciiString(count) + "\n";
1579 count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientation);
1581 theDump += " Bad Orientation .......................... ";
1582 theDump += TCollection_AsciiString(count) + "\n";
1584 count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientationOfSubshape);
1586 theDump += " Bad Orientation of Subshape .............. ";
1587 theDump += TCollection_AsciiString(count) + "\n";
1589 count = NbProblems->Value((Standard_Integer)BRepCheck_CheckFail);
1591 theDump += " checkshape failure ....................... ";
1592 theDump += TCollection_AsciiString(count) + "\n";
1595 theDump += " ------------------------------------------------\n";
1596 theDump += "*** Shapes with problems : ";
1597 theDump += TCollection_AsciiString(sl->Length()) + "\n";
1599 Standard_Integer nbv, nbe, nbw, nbf, nbs, nbo;
1600 nbv = nbe = nbw = nbf = nbs = nbo = 0;
1602 for (i = 1; i <= sl->Length(); i++) {
1603 TopoDS_Shape shi = sl->Value(i);
1604 TopAbs_ShapeEnum sti = shi.ShapeType();
1606 case TopAbs_VERTEX : nbv++; break;
1607 case TopAbs_EDGE : nbe++; break;
1608 case TopAbs_WIRE : nbw++; break;
1609 case TopAbs_FACE : nbf++; break;
1610 case TopAbs_SHELL : nbs++; break;
1611 case TopAbs_SOLID : nbo++; break;
1617 theDump += "VERTEX : ";
1618 if (nbv < 10) theDump += " ";
1619 theDump += TCollection_AsciiString(nbv) + "\n";
1622 theDump += "EDGE : ";
1623 if (nbe < 10) theDump += " ";
1624 theDump += TCollection_AsciiString(nbe) + "\n";
1627 theDump += "WIRE : ";
1628 if (nbw < 10) theDump += " ";
1629 theDump += TCollection_AsciiString(nbw) + "\n";
1632 theDump += "FACE : ";
1633 if (nbf < 10) theDump += " ";
1634 theDump += TCollection_AsciiString(nbf) + "\n";
1637 theDump += "SHELL : ";
1638 if (nbs < 10) theDump += " ";
1639 theDump += TCollection_AsciiString(nbs) + "\n";
1642 theDump += "SOLID : ";
1643 if (nbo < 10) theDump += " ";
1644 theDump += TCollection_AsciiString(nbo) + "\n";
1648 //=======================================================================
1649 //function : GetProblemShapes
1650 // purpose : for StructuralDump
1651 //=======================================================================
1652 void GEOMImpl_IMeasureOperations::GetProblemShapes (const BRepCheck_Analyzer& theAna,
1653 const TopoDS_Shape& theShape,
1654 Handle(TopTools_HSequenceOfShape)& sl,
1655 Handle(TColStd_HArray1OfInteger)& NbProblems,
1656 TopTools_DataMapOfShapeListOfShape& theMap)
1658 for (TopoDS_Iterator iter(theShape); iter.More(); iter.Next()) {
1659 GetProblemShapes(theAna, iter.Value(), sl, NbProblems, theMap);
1661 TopAbs_ShapeEnum styp = theShape.ShapeType();
1662 BRepCheck_ListIteratorOfListOfStatus itl;
1663 TopTools_ListOfShape empty;
1664 if (!theMap.IsBound(theShape)) {
1665 theMap.Bind(theShape,empty);
1667 if (!theAna.Result(theShape).IsNull()) {
1668 itl.Initialize(theAna.Result(theShape)->Status());
1669 // !!! May be, we have to print all the problems, not only the first one ?
1670 if (itl.Value() != BRepCheck_NoError) {
1671 sl->Append(theShape);
1672 BRepCheck_Status stat = itl.Value();
1673 NbProblems->SetValue((Standard_Integer)stat,
1674 NbProblems->Value((Standard_Integer)stat) + 1);
1681 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_VERTEX, theMap);
1684 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_WIRE, theMap);
1685 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_EDGE, theMap);
1686 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_VERTEX, theMap);
1691 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_SHELL, theMap);
1698 //=======================================================================
1699 //function : Contains
1700 //=======================================================================
1701 static Standard_Boolean Contains (const TopTools_ListOfShape& L,
1702 const TopoDS_Shape& S)
1704 TopTools_ListIteratorOfListOfShape it;
1705 for (it.Initialize(L); it.More(); it.Next()) {
1706 if (it.Value().IsSame(S)) {
1707 return Standard_True;
1710 return Standard_False;
1713 //=======================================================================
1714 //function : GetProblemSub
1715 // purpose : for StructuralDump
1716 //=======================================================================
1717 void GEOMImpl_IMeasureOperations::GetProblemSub (const BRepCheck_Analyzer& theAna,
1718 const TopoDS_Shape& theShape,
1719 Handle(TopTools_HSequenceOfShape)& sl,
1720 Handle(TColStd_HArray1OfInteger)& NbProblems,
1721 const TopAbs_ShapeEnum Subtype,
1722 TopTools_DataMapOfShapeListOfShape& theMap)
1724 BRepCheck_ListIteratorOfListOfStatus itl;
1725 TopExp_Explorer exp;
1726 for (exp.Init(theShape, Subtype); exp.More(); exp.Next()) {
1727 const TopoDS_Shape& sub = exp.Current();
1729 const Handle(BRepCheck_Result)& res = theAna.Result(sub);
1730 for (res->InitContextIterator();
1731 res->MoreShapeInContext();
1732 res->NextShapeInContext()) {
1733 if (res->ContextualShape().IsSame(theShape) && !Contains(theMap(sub), theShape)) {
1734 theMap(sub).Append(theShape);
1735 itl.Initialize(res->StatusOnShape());
1737 if (itl.Value() != BRepCheck_NoError) {
1738 Standard_Integer ii = 0;
1740 for (ii = 1; ii <= sl->Length(); ii++)
1741 if (sl->Value(ii).IsSame(sub)) break;
1743 if (ii > sl->Length()) {
1745 BRepCheck_Status stat = itl.Value();
1746 NbProblems->SetValue((Standard_Integer)stat,
1747 NbProblems->Value((Standard_Integer)stat) + 1);
1749 for (ii = 1; ii <= sl->Length(); ii++)
1750 if (sl->Value(ii).IsSame(theShape)) break;
1751 if (ii > sl->Length()) {
1752 sl->Append(theShape);
1753 BRepCheck_Status stat = itl.Value();
1754 NbProblems->SetValue((Standard_Integer)stat,
1755 NbProblems->Value((Standard_Integer)stat) + 1);