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 <GeomAPI_ProjectPointOnCurve.hxx>
91 #include <ShapeAnalysis.hxx>
92 #include <ShapeAnalysis_Surface.hxx>
93 #include <GeomLProp_CLProps.hxx>
94 #include <GeomLProp_SLProps.hxx>
96 #include <Standard_Failure.hxx>
97 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
99 #include <GeomAPI_IntSS.hxx>
100 #include <Geom_SphericalSurface.hxx>
101 #include <Geom_ToroidalSurface.hxx>
102 #include <Geom_Circle.hxx>
103 #include <BRep_Builder.hxx>
104 #include <TopoDS_Compound.hxx>
105 #include <ShapeFix_Shape.hxx>
108 //=============================================================================
112 //=============================================================================
113 GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations (GEOM_Engine* theEngine, int theDocID)
114 : GEOM_IOperations(theEngine, theDocID)
116 MESSAGE("GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations");
119 //=============================================================================
123 //=============================================================================
124 GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations()
126 MESSAGE("GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations");
129 //=============================================================================
130 /*! Get kind and parameters of the given shape.
132 //=============================================================================
133 GEOMImpl_IMeasureOperations::ShapeKind GEOMImpl_IMeasureOperations::KindOfShape
134 (Handle(GEOM_Object) theShape,
135 Handle(TColStd_HSequenceOfInteger)& theIntegers,
136 Handle(TColStd_HSequenceOfReal)& theDoubles)
139 ShapeKind aKind = SK_NO_SHAPE;
141 if (theIntegers.IsNull()) theIntegers = new TColStd_HSequenceOfInteger;
142 else theIntegers->Clear();
144 if (theDoubles.IsNull()) theDoubles = new TColStd_HSequenceOfReal;
145 else theDoubles->Clear();
147 if (theShape.IsNull())
150 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
151 if (aRefShape.IsNull()) return aKind;
153 TopoDS_Shape aShape = aRefShape->GetValue();
154 if (aShape.IsNull()) return aKind;
157 GEOMAlgo_ShapeInfoFiller aSF;
158 aSF.SetShape(aShape);
160 Standard_Integer iErr = aSF.ErrorStatus();
162 SetErrorCode("Error in GEOMAlgo_ShapeInfoFiller");
165 const GEOMAlgo_ShapeInfo& anInfo = aSF.Info();
167 // Interprete results
168 TopAbs_ShapeEnum aType = anInfo.Type();
171 case TopAbs_COMPOUND:
172 case TopAbs_COMPSOLID:
174 // (+) geompy.kind.COMPOUND nb_solids nb_faces nb_edges nb_vertices
175 // (+) geompy.kind.COMPSOLID nb_solids nb_faces nb_edges nb_vertices
176 // ??? "nb_faces" - all faces or only 'standalone' faces?
177 if (aType == TopAbs_COMPOUND)
180 aKind = SK_COMPSOLID;
182 //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPOUND));
183 //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPSOLID));
184 theIntegers->Append(anInfo.NbSubShapes(TopAbs_SOLID));
185 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
186 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
187 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
193 // (+) geompy.kind.SHELL geompy.info.closed nb_faces nb_edges nb_vertices
194 // (+) geompy.kind.SHELL geompy.info.unclosed nb_faces nb_edges nb_vertices
197 theIntegers->Append((int)anInfo.KindOfClosed());
199 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
200 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
201 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
207 // (+) geompy.kind.WIRE geompy.info.closed nb_edges nb_vertices
208 // (+) geompy.kind.WIRE geompy.info.unclosed nb_edges nb_vertices
211 theIntegers->Append((int)anInfo.KindOfClosed());
213 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
214 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
222 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
225 case GEOMAlgo_KN_SPHERE:
226 // (+) geompy.kind.SPHERE xc yc zc R
230 gp_Pnt aC = anInfo.Location();
231 theDoubles->Append(aC.X());
232 theDoubles->Append(aC.Y());
233 theDoubles->Append(aC.Z());
235 theDoubles->Append(anInfo.Radius1());
238 case GEOMAlgo_KN_CYLINDER:
239 // (+) geompy.kind.CYLINDER xb yb zb dx dy dz R H
243 gp_Pnt aC = anInfo.Location();
244 theDoubles->Append(aC.X());
245 theDoubles->Append(aC.Y());
246 theDoubles->Append(aC.Z());
248 gp_Ax3 anAx3 = anInfo.Position();
249 gp_Dir aD = anAx3.Direction();
250 theDoubles->Append(aD.X());
251 theDoubles->Append(aD.Y());
252 theDoubles->Append(aD.Z());
254 theDoubles->Append(anInfo.Radius1());
255 theDoubles->Append(anInfo.Height());
258 case GEOMAlgo_KN_BOX:
259 // (+) geompy.kind.BOX xc yc zc ax ay az
263 gp_Pnt aC = anInfo.Location();
264 theDoubles->Append(aC.X());
265 theDoubles->Append(aC.Y());
266 theDoubles->Append(aC.Z());
268 gp_Ax3 anAx3 = anInfo.Position();
269 gp_Dir aD = anAx3.Direction();
270 gp_Dir aX = anAx3.XDirection();
273 if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
274 aX.IsParallel(gp::DX(), Precision::Angular())) {
275 theDoubles->Append(anInfo.Length()); // ax'
276 theDoubles->Append(anInfo.Width()); // ay'
277 theDoubles->Append(anInfo.Height()); // az'
279 else if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
280 aX.IsParallel(gp::DY(), Precision::Angular())) {
281 theDoubles->Append(anInfo.Width()); // ay'
282 theDoubles->Append(anInfo.Length()); // ax'
283 theDoubles->Append(anInfo.Height()); // az'
285 else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
286 aX.IsParallel(gp::DZ(), Precision::Angular())) {
287 theDoubles->Append(anInfo.Height()); // az'
288 theDoubles->Append(anInfo.Width()); // ay'
289 theDoubles->Append(anInfo.Length()); // ax'
291 else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
292 aX.IsParallel(gp::DY(), Precision::Angular())) {
293 theDoubles->Append(anInfo.Height()); // az'
294 theDoubles->Append(anInfo.Length()); // ax'
295 theDoubles->Append(anInfo.Width()); // ay'
297 else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
298 aX.IsParallel(gp::DZ(), Precision::Angular())) {
299 theDoubles->Append(anInfo.Width()); // ay'
300 theDoubles->Append(anInfo.Height()); // az'
301 theDoubles->Append(anInfo.Length()); // ax'
303 else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
304 aX.IsParallel(gp::DX(), Precision::Angular())) {
305 theDoubles->Append(anInfo.Length()); // ax'
306 theDoubles->Append(anInfo.Height()); // az'
307 theDoubles->Append(anInfo.Width()); // ay'
310 // (+) geompy.kind.ROTATED_BOX xo yo zo zx zy zz xx xy xz ax ay az
311 aKind = SK_ROTATED_BOX;
313 // Direction and XDirection
314 theDoubles->Append(aD.X());
315 theDoubles->Append(aD.Y());
316 theDoubles->Append(aD.Z());
318 theDoubles->Append(aX.X());
319 theDoubles->Append(aX.Y());
320 theDoubles->Append(aX.Z());
323 theDoubles->Append(anInfo.Length());
324 theDoubles->Append(anInfo.Width());
325 theDoubles->Append(anInfo.Height());
329 case GEOMAlgo_KN_TORUS:
330 // (+) geompy.kind.TORUS xc yc zc dx dy dz R_1 R_2
334 gp_Pnt aO = anInfo.Location();
335 theDoubles->Append(aO.X());
336 theDoubles->Append(aO.Y());
337 theDoubles->Append(aO.Z());
339 gp_Ax3 anAx3 = anInfo.Position();
340 gp_Dir aD = anAx3.Direction();
341 theDoubles->Append(aD.X());
342 theDoubles->Append(aD.Y());
343 theDoubles->Append(aD.Z());
345 theDoubles->Append(anInfo.Radius1());
346 theDoubles->Append(anInfo.Radius2());
349 case GEOMAlgo_KN_CONE:
350 // (+) geompy.kind.CONE xb yb zb dx dy dz R_1 R_2 H
354 gp_Pnt aO = anInfo.Location();
355 theDoubles->Append(aO.X());
356 theDoubles->Append(aO.Y());
357 theDoubles->Append(aO.Z());
359 gp_Ax3 anAx3 = anInfo.Position();
360 gp_Dir aD = anAx3.Direction();
361 theDoubles->Append(aD.X());
362 theDoubles->Append(aD.Y());
363 theDoubles->Append(aD.Z());
365 theDoubles->Append(anInfo.Radius1());
366 theDoubles->Append(anInfo.Radius2());
367 theDoubles->Append(anInfo.Height());
370 case GEOMAlgo_KN_POLYHEDRON:
371 // (+) geompy.kind.POLYHEDRON nb_faces nb_edges nb_vertices
373 aKind = SK_POLYHEDRON;
375 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
376 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
377 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
381 // (+) geompy.kind.SOLID nb_faces nb_edges nb_vertices
383 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
384 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
385 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
395 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
397 case GEOMAlgo_KN_SPHERE:
398 // (+) geompy.kind.SPHERE2D xc yc zc R
402 gp_Pnt aC = anInfo.Location();
403 theDoubles->Append(aC.X());
404 theDoubles->Append(aC.Y());
405 theDoubles->Append(aC.Z());
407 theDoubles->Append(anInfo.Radius1());
410 case GEOMAlgo_KN_CYLINDER:
411 // (+) geompy.kind.CYLINDER2D xb yb zb dx dy dz R H
413 aKind = SK_CYLINDER2D;
415 gp_Pnt aO = anInfo.Location();
416 theDoubles->Append(aO.X());
417 theDoubles->Append(aO.Y());
418 theDoubles->Append(aO.Z());
420 gp_Ax3 anAx3 = anInfo.Position();
421 gp_Dir aD = anAx3.Direction();
422 theDoubles->Append(aD.X());
423 theDoubles->Append(aD.Y());
424 theDoubles->Append(aD.Z());
426 theDoubles->Append(anInfo.Radius1());
427 theDoubles->Append(anInfo.Height());
430 case GEOMAlgo_KN_TORUS:
431 // (+) geompy.kind.TORUS2D xc yc zc dx dy dz R_1 R_2
435 gp_Pnt aO = anInfo.Location();
436 theDoubles->Append(aO.X());
437 theDoubles->Append(aO.Y());
438 theDoubles->Append(aO.Z());
440 gp_Ax3 anAx3 = anInfo.Position();
441 gp_Dir aD = anAx3.Direction();
442 theDoubles->Append(aD.X());
443 theDoubles->Append(aD.Y());
444 theDoubles->Append(aD.Z());
446 theDoubles->Append(anInfo.Radius1());
447 theDoubles->Append(anInfo.Radius2());
450 case GEOMAlgo_KN_CONE:
451 // (+) geompy.kind.CONE2D xc yc zc dx dy dz R_1 R_2 H
455 gp_Pnt aO = anInfo.Location();
456 theDoubles->Append(aO.X());
457 theDoubles->Append(aO.Y());
458 theDoubles->Append(aO.Z());
460 gp_Ax3 anAx3 = anInfo.Position();
461 gp_Dir aD = anAx3.Direction();
462 theDoubles->Append(aD.X());
463 theDoubles->Append(aD.Y());
464 theDoubles->Append(aD.Z());
466 theDoubles->Append(anInfo.Radius1());
467 theDoubles->Append(anInfo.Radius2());
468 theDoubles->Append(anInfo.Height());
471 case GEOMAlgo_KN_DISKCIRCLE:
472 // (+) geompy.kind.DISK_CIRCLE xc yc zc dx dy dz R
474 aKind = SK_DISK_CIRCLE;
476 gp_Pnt aC = anInfo.Location();
477 theDoubles->Append(aC.X());
478 theDoubles->Append(aC.Y());
479 theDoubles->Append(aC.Z());
481 gp_Ax3 anAx3 = anInfo.Position();
482 gp_Dir aD = anAx3.Direction();
483 theDoubles->Append(aD.X());
484 theDoubles->Append(aD.Y());
485 theDoubles->Append(aD.Z());
487 theDoubles->Append(anInfo.Radius1());
490 case GEOMAlgo_KN_DISKELLIPSE:
491 // (+) geompy.kind.DISK_ELLIPSE xc yc zc dx dy dz R_1 R_2
493 aKind = SK_DISK_ELLIPSE;
495 gp_Pnt aC = anInfo.Location();
496 theDoubles->Append(aC.X());
497 theDoubles->Append(aC.Y());
498 theDoubles->Append(aC.Z());
500 gp_Ax3 anAx3 = anInfo.Position();
501 gp_Dir aD = anAx3.Direction();
502 theDoubles->Append(aD.X());
503 theDoubles->Append(aD.Y());
504 theDoubles->Append(aD.Z());
506 theDoubles->Append(anInfo.Radius1());
507 theDoubles->Append(anInfo.Radius2());
510 case GEOMAlgo_KN_RECTANGLE:
511 case GEOMAlgo_KN_TRIANGLE:
512 case GEOMAlgo_KN_QUADRANGLE:
513 case GEOMAlgo_KN_POLYGON:
514 // (+) geompy.kind.POLYGON xo yo zo dx dy dz nb_edges nb_vertices
518 gp_Pnt aO = anInfo.Location();
519 theDoubles->Append(aO.X());
520 theDoubles->Append(aO.Y());
521 theDoubles->Append(aO.Z());
523 gp_Ax3 anAx3 = anInfo.Position();
524 gp_Dir aD = anAx3.Direction();
525 theDoubles->Append(aD.X());
526 theDoubles->Append(aD.Y());
527 theDoubles->Append(aD.Z());
529 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
530 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
533 case GEOMAlgo_KN_PLANE: // infinite
534 // (+) geompy.kind.PLANE xo yo zo dx dy dz
538 gp_Pnt aC = anInfo.Location();
539 theDoubles->Append(aC.X());
540 theDoubles->Append(aC.Y());
541 theDoubles->Append(aC.Z());
543 gp_Ax3 anAx3 = anInfo.Position();
544 gp_Dir aD = anAx3.Direction();
545 theDoubles->Append(aD.X());
546 theDoubles->Append(aD.Y());
547 theDoubles->Append(aD.Z());
551 if (anInfo.KindOfShape() == GEOMAlgo_KS_PLANE) {
552 // (+) geompy.kind.PLANAR xo yo zo dx dy dz nb_edges nb_vertices
556 gp_Pnt aC = anInfo.Location();
557 theDoubles->Append(aC.X());
558 theDoubles->Append(aC.Y());
559 theDoubles->Append(aC.Z());
561 gp_Ax3 anAx3 = anInfo.Position();
562 gp_Dir aD = anAx3.Direction();
563 theDoubles->Append(aD.X());
564 theDoubles->Append(aD.Y());
565 theDoubles->Append(aD.Z());
567 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
568 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
571 // ??? geompy.kind.FACE nb_edges nb_vertices _surface_type_id_
572 // (+) geompy.kind.FACE nb_edges nb_vertices
574 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
575 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
585 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
587 case GEOMAlgo_KN_CIRCLE:
589 // (+) geompy.kind.CIRCLE xc yc zc dx dy dz R
592 gp_Pnt aC = anInfo.Location();
593 theDoubles->Append(aC.X());
594 theDoubles->Append(aC.Y());
595 theDoubles->Append(aC.Z());
597 gp_Ax3 anAx3 = anInfo.Position();
598 gp_Dir aD = anAx3.Direction();
599 theDoubles->Append(aD.X());
600 theDoubles->Append(aD.Y());
601 theDoubles->Append(aD.Z());
603 theDoubles->Append(anInfo.Radius1());
606 case GEOMAlgo_KN_ARCCIRCLE:
608 // (+) geompy.kind.ARC_CIRCLE xc yc zc dx dy dz R x1 y1 z1 x2 y2 z2
609 aKind = SK_ARC_CIRCLE;
611 gp_Pnt aC = anInfo.Location();
612 theDoubles->Append(aC.X());
613 theDoubles->Append(aC.Y());
614 theDoubles->Append(aC.Z());
616 gp_Ax3 anAx3 = anInfo.Position();
617 gp_Dir aD = anAx3.Direction();
618 theDoubles->Append(aD.X());
619 theDoubles->Append(aD.Y());
620 theDoubles->Append(aD.Z());
622 theDoubles->Append(anInfo.Radius1());
624 gp_Pnt aP1 = anInfo.Pnt1();
625 theDoubles->Append(aP1.X());
626 theDoubles->Append(aP1.Y());
627 theDoubles->Append(aP1.Z());
629 gp_Pnt aP2 = anInfo.Pnt2();
630 theDoubles->Append(aP2.X());
631 theDoubles->Append(aP2.Y());
632 theDoubles->Append(aP2.Z());
635 case GEOMAlgo_KN_ELLIPSE:
637 // (+) geompy.kind.ELLIPSE xc yc zc dx dy dz R_1 R_2
640 gp_Pnt aC = anInfo.Location();
641 theDoubles->Append(aC.X());
642 theDoubles->Append(aC.Y());
643 theDoubles->Append(aC.Z());
645 gp_Ax3 anAx3 = anInfo.Position();
646 gp_Dir aD = anAx3.Direction();
647 theDoubles->Append(aD.X());
648 theDoubles->Append(aD.Y());
649 theDoubles->Append(aD.Z());
651 theDoubles->Append(anInfo.Radius1());
652 theDoubles->Append(anInfo.Radius2());
655 case GEOMAlgo_KN_ARCELLIPSE:
657 // (+) geompy.kind.ARC_ELLIPSE xc yc zc dx dy dz R_1 R_2 x1 y1 z1 x2 y2 z2
658 aKind = SK_ARC_ELLIPSE;
660 gp_Pnt aC = anInfo.Location();
661 theDoubles->Append(aC.X());
662 theDoubles->Append(aC.Y());
663 theDoubles->Append(aC.Z());
665 gp_Ax3 anAx3 = anInfo.Position();
666 gp_Dir aD = anAx3.Direction();
667 theDoubles->Append(aD.X());
668 theDoubles->Append(aD.Y());
669 theDoubles->Append(aD.Z());
671 theDoubles->Append(anInfo.Radius1());
672 theDoubles->Append(anInfo.Radius2());
674 gp_Pnt aP1 = anInfo.Pnt1();
675 theDoubles->Append(aP1.X());
676 theDoubles->Append(aP1.Y());
677 theDoubles->Append(aP1.Z());
679 gp_Pnt aP2 = anInfo.Pnt2();
680 theDoubles->Append(aP2.X());
681 theDoubles->Append(aP2.Y());
682 theDoubles->Append(aP2.Z());
685 case GEOMAlgo_KN_LINE:
687 // ??? geompy.kind.LINE x1 y1 z1 x2 y2 z2
688 // (+) geompy.kind.LINE x1 y1 z1 dx dy dz
691 gp_Pnt aO = anInfo.Location();
692 theDoubles->Append(aO.X());
693 theDoubles->Append(aO.Y());
694 theDoubles->Append(aO.Z());
696 gp_Dir aD = anInfo.Direction();
697 theDoubles->Append(aD.X());
698 theDoubles->Append(aD.Y());
699 theDoubles->Append(aD.Z());
702 case GEOMAlgo_KN_SEGMENT:
704 // (+) geompy.kind.SEGMENT x1 y1 z1 x2 y2 z2
707 gp_Pnt aP1 = anInfo.Pnt1();
708 theDoubles->Append(aP1.X());
709 theDoubles->Append(aP1.Y());
710 theDoubles->Append(aP1.Z());
712 gp_Pnt aP2 = anInfo.Pnt2();
713 theDoubles->Append(aP2.X());
714 theDoubles->Append(aP2.Y());
715 theDoubles->Append(aP2.Z());
719 // ??? geompy.kind.EDGE nb_vertices _curve_type_id_
720 // (+) geompy.kind.EDGE nb_vertices
721 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
728 // (+) geompy.kind.VERTEX x y z
731 gp_Pnt aP = anInfo.Location();
732 theDoubles->Append(aP.X());
733 theDoubles->Append(aP.Y());
734 theDoubles->Append(aP.Z());
743 //=============================================================================
744 /*! Get LCS, corresponding to the given shape.
745 * Origin of the LCS is situated at the shape's center of mass.
746 * Axes of the LCS are obtained from shape's location or,
747 * if the shape is a planar face, from position of its plane.
749 //=============================================================================
750 gp_Ax3 GEOMImpl_IMeasureOperations::GetPosition (const TopoDS_Shape& theShape)
754 if (theShape.IsNull())
758 aResult.Transform(theShape.Location().Transformation());
759 if (theShape.ShapeType() == TopAbs_FACE) {
760 Handle(Geom_Surface) aGS = BRep_Tool::Surface(TopoDS::Face(theShape));
761 if (!aGS.IsNull() && aGS->IsKind(STANDARD_TYPE(Geom_Plane))) {
762 Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast(aGS);
763 gp_Pln aPln = aGPlane->Pln();
764 aResult = aPln.Position();
770 if (theShape.ShapeType() == TopAbs_VERTEX) {
771 aPnt = BRep_Tool::Pnt(TopoDS::Vertex(theShape));
774 GProp_GProps aSystem;
775 if (theShape.ShapeType() == TopAbs_EDGE || theShape.ShapeType() == TopAbs_WIRE)
776 BRepGProp::LinearProperties(theShape, aSystem);
777 else if (theShape.ShapeType() == TopAbs_FACE || theShape.ShapeType() == TopAbs_SHELL)
778 BRepGProp::SurfaceProperties(theShape, aSystem);
780 BRepGProp::VolumeProperties(theShape, aSystem);
782 aPnt = aSystem.CentreOfMass();
785 aResult.SetLocation(aPnt);
790 //=============================================================================
794 //=============================================================================
795 void GEOMImpl_IMeasureOperations::GetPosition
796 (Handle(GEOM_Object) theShape,
797 Standard_Real& Ox, Standard_Real& Oy, Standard_Real& Oz,
798 Standard_Real& Zx, Standard_Real& Zy, Standard_Real& Zz,
799 Standard_Real& Xx, Standard_Real& Xy, Standard_Real& Xz)
803 //Set default values: global CS
804 Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
807 if (theShape.IsNull()) return;
809 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
810 if (aRefShape.IsNull()) return;
812 TopoDS_Shape aShape = aRefShape->GetValue();
813 if (aShape.IsNull()) {
814 SetErrorCode("The Objects has NULL Shape");
819 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
823 gp_Ax3 anAx3 = GetPosition(aShape);
825 gp_Pnt anOri = anAx3.Location();
826 gp_Dir aDirZ = anAx3.Direction();
827 gp_Dir aDirX = anAx3.XDirection();
830 anOri.Coord(Ox, Oy, Oz);
831 aDirZ.Coord(Zx, Zy, Zz);
832 aDirX.Coord(Xx, Xy, Xz);
834 catch (Standard_Failure) {
835 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
836 SetErrorCode(aFail->GetMessageString());
843 //=============================================================================
847 //=============================================================================
848 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetCentreOfMass
849 (Handle(GEOM_Object) theShape)
853 if (theShape.IsNull()) return NULL;
855 //Add a new CentreOfMass object
856 Handle(GEOM_Object) aCDG = GetEngine()->AddObject(GetDocID(), GEOM_CDG);
858 //Add a new CentreOfMass function
859 Handle(GEOM_Function) aFunction =
860 aCDG->AddFunction(GEOMImpl_MeasureDriver::GetID(), CDG_MEASURE);
861 if (aFunction.IsNull()) return NULL;
863 //Check if the function is set correctly
864 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
866 GEOMImpl_IMeasure aCI (aFunction);
868 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
869 if (aRefShape.IsNull()) return NULL;
871 aCI.SetBase(aRefShape);
873 //Compute the CentreOfMass value
875 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
878 if (!GetSolver()->ComputeFunction(aFunction)) {
879 SetErrorCode("Measure driver failed to compute centre of mass");
883 catch (Standard_Failure) {
884 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
885 SetErrorCode(aFail->GetMessageString());
889 //Make a Python command
890 GEOM::TPythonDump(aFunction) << aCDG << " = geompy.MakeCDG(" << theShape << ")";
896 //=============================================================================
900 //=============================================================================
901 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetNormal
902 (Handle(GEOM_Object) theFace,
903 Handle(GEOM_Object) theOptionalPoint)
907 if (theFace.IsNull()) return NULL;
909 //Add a new Normale object
910 Handle(GEOM_Object) aNorm = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
912 //Add a new Normale function
913 Handle(GEOM_Function) aFunction =
914 aNorm->AddFunction(GEOMImpl_MeasureDriver::GetID(), VECTOR_FACE_NORMALE);
915 if (aFunction.IsNull()) return NULL;
917 //Check if the function is set correctly
918 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
920 GEOMImpl_IMeasure aCI (aFunction);
922 Handle(GEOM_Function) aFace = theFace->GetLastFunction();
923 if (aFace.IsNull()) return NULL;
927 if (!theOptionalPoint.IsNull()) {
928 Handle(GEOM_Function) anOptPnt = theOptionalPoint->GetLastFunction();
929 aCI.SetPoint(anOptPnt);
932 //Compute the Normale value
934 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
937 if (!GetSolver()->ComputeFunction(aFunction)) {
938 SetErrorCode("Measure driver failed to compute normake of face");
942 catch (Standard_Failure) {
943 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
944 SetErrorCode(aFail->GetMessageString());
948 //Make a Python command
949 GEOM::TPythonDump pd (aFunction);
950 pd << aNorm << " = geompy.GetNormal(" << theFace;
951 if (!theOptionalPoint.IsNull()) {
952 pd << ", " << theOptionalPoint;
960 //=============================================================================
964 //=============================================================================
965 void GEOMImpl_IMeasureOperations::GetBasicProperties (Handle(GEOM_Object) theShape,
966 Standard_Real& theLength,
967 Standard_Real& theSurfArea,
968 Standard_Real& theVolume)
972 if (theShape.IsNull()) return;
974 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
975 if (aRefShape.IsNull()) return;
977 TopoDS_Shape aShape = aRefShape->GetValue();
978 if (aShape.IsNull()) {
979 SetErrorCode("The Objects has NULL Shape");
983 //Compute the parameters
984 GProp_GProps LProps, SProps;
986 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
989 BRepGProp::LinearProperties(aShape, LProps);
990 theLength = LProps.Mass();
992 BRepGProp::SurfaceProperties(aShape, SProps);
993 theSurfArea = SProps.Mass();
996 if (aShape.ShapeType() < TopAbs_SHELL) {
997 for (TopExp_Explorer Exp (aShape, TopAbs_SOLID); Exp.More(); Exp.Next()) {
999 BRepGProp::VolumeProperties(Exp.Current(), VProps);
1000 theVolume += VProps.Mass();
1004 catch (Standard_Failure) {
1005 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1006 SetErrorCode(aFail->GetMessageString());
1013 //=============================================================================
1017 //=============================================================================
1018 void GEOMImpl_IMeasureOperations::GetInertia
1019 (Handle(GEOM_Object) theShape,
1020 Standard_Real& I11, Standard_Real& I12, Standard_Real& I13,
1021 Standard_Real& I21, Standard_Real& I22, Standard_Real& I23,
1022 Standard_Real& I31, Standard_Real& I32, Standard_Real& I33,
1023 Standard_Real& Ix , Standard_Real& Iy , Standard_Real& Iz)
1027 if (theShape.IsNull()) return;
1029 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1030 if (aRefShape.IsNull()) return;
1032 TopoDS_Shape aShape = aRefShape->GetValue();
1033 if (aShape.IsNull()) {
1034 SetErrorCode("The Objects has NULL Shape");
1038 //Compute the parameters
1039 GProp_GProps System;
1042 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1045 if (aShape.ShapeType() == TopAbs_VERTEX ||
1046 aShape.ShapeType() == TopAbs_EDGE ||
1047 aShape.ShapeType() == TopAbs_WIRE) {
1048 BRepGProp::LinearProperties(aShape, System);
1049 } else if (aShape.ShapeType() == TopAbs_FACE ||
1050 aShape.ShapeType() == TopAbs_SHELL) {
1051 BRepGProp::SurfaceProperties(aShape, System);
1053 BRepGProp::VolumeProperties(aShape, System);
1055 gp_Mat I = System.MatrixOfInertia();
1069 GProp_PrincipalProps Pr = System.PrincipalProperties();
1070 Pr.Moments(Ix,Iy,Iz);
1072 catch (Standard_Failure) {
1073 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1074 SetErrorCode(aFail->GetMessageString());
1081 //=============================================================================
1085 //=============================================================================
1086 void GEOMImpl_IMeasureOperations::GetBoundingBox
1087 (Handle(GEOM_Object) theShape,
1088 Standard_Real& Xmin, Standard_Real& Xmax,
1089 Standard_Real& Ymin, Standard_Real& Ymax,
1090 Standard_Real& Zmin, Standard_Real& Zmax)
1094 if (theShape.IsNull()) return;
1096 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1097 if (aRefShape.IsNull()) return;
1099 TopoDS_Shape aShape = aRefShape->GetValue();
1100 if (aShape.IsNull()) {
1101 SetErrorCode("The Objects has NULL Shape");
1105 //Compute the parameters
1109 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1112 BRepBndLib::Add(aShape, B);
1113 B.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
1115 catch (Standard_Failure) {
1116 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1117 SetErrorCode(aFail->GetMessageString());
1124 //=============================================================================
1128 //=============================================================================
1129 void GEOMImpl_IMeasureOperations::GetTolerance
1130 (Handle(GEOM_Object) theShape,
1131 Standard_Real& FaceMin, Standard_Real& FaceMax,
1132 Standard_Real& EdgeMin, Standard_Real& EdgeMax,
1133 Standard_Real& VertMin, Standard_Real& VertMax)
1137 if (theShape.IsNull()) return;
1139 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1140 if (aRefShape.IsNull()) return;
1142 TopoDS_Shape aShape = aRefShape->GetValue();
1143 if (aShape.IsNull()) {
1144 SetErrorCode("The Objects has NULL Shape");
1148 //Compute the parameters
1150 FaceMin = EdgeMin = VertMin = RealLast();
1151 FaceMax = EdgeMax = VertMax = -RealLast();
1154 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1157 for (TopExp_Explorer ExF (aShape, TopAbs_FACE); ExF.More(); ExF.Next()) {
1158 TopoDS_Face Face = TopoDS::Face(ExF.Current());
1159 T = BRep_Tool::Tolerance(Face);
1165 for (TopExp_Explorer ExE (aShape, TopAbs_EDGE); ExE.More(); ExE.Next()) {
1166 TopoDS_Edge Edge = TopoDS::Edge(ExE.Current());
1167 T = BRep_Tool::Tolerance(Edge);
1173 for (TopExp_Explorer ExV (aShape, TopAbs_VERTEX); ExV.More(); ExV.Next()) {
1174 TopoDS_Vertex Vertex = TopoDS::Vertex(ExV.Current());
1175 T = BRep_Tool::Tolerance(Vertex);
1182 catch (Standard_Failure) {
1183 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1184 SetErrorCode(aFail->GetMessageString());
1191 //=============================================================================
1195 //=============================================================================
1196 bool GEOMImpl_IMeasureOperations::CheckShape (Handle(GEOM_Object) theShape,
1197 const Standard_Boolean theIsCheckGeom,
1198 TCollection_AsciiString& theDump)
1202 if (theShape.IsNull()) return false;
1204 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1205 if (aRefShape.IsNull()) return false;
1207 TopoDS_Shape aShape = aRefShape->GetValue();
1208 if (aShape.IsNull()) {
1209 SetErrorCode("The Objects has NULL Shape");
1213 //Compute the parameters
1214 bool isValid = false;
1216 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1219 BRepCheck_Analyzer ana (aShape, theIsCheckGeom);
1220 if (ana.IsValid()) {
1224 StructuralDump(ana, aShape, theDump);
1227 catch (Standard_Failure) {
1228 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1229 SetErrorCode(aFail->GetMessageString());
1237 //=============================================================================
1241 //=============================================================================
1242 TCollection_AsciiString GEOMImpl_IMeasureOperations::WhatIs (Handle(GEOM_Object) theShape)
1246 TCollection_AsciiString Astr;
1248 if (theShape.IsNull()) return Astr;
1250 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1251 if (aRefShape.IsNull()) return Astr;
1253 TopoDS_Shape aShape = aRefShape->GetValue();
1254 if (aShape.IsNull()) {
1255 SetErrorCode("The Objects has NULL Shape");
1259 //Compute the parameters
1260 if (aShape.ShapeType() == TopAbs_EDGE) {
1261 if (BRep_Tool::Degenerated(TopoDS::Edge(aShape))) {
1262 Astr = Astr + " It is a degenerated edge \n";
1266 Astr = Astr + " Number of sub-shapes : \n";
1269 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1272 int iType, nbTypes [TopAbs_SHAPE];
1273 for (iType = 0; iType < TopAbs_SHAPE; ++iType)
1275 nbTypes[aShape.ShapeType()]++;
1277 TopTools_MapOfShape aMapOfShape;
1278 aMapOfShape.Add(aShape);
1279 TopTools_ListOfShape aListOfShape;
1280 aListOfShape.Append(aShape);
1282 TopTools_ListIteratorOfListOfShape itL (aListOfShape);
1283 for (; itL.More(); itL.Next()) {
1284 TopoDS_Iterator it (itL.Value());
1285 for (; it.More(); it.Next()) {
1286 TopoDS_Shape s = it.Value();
1287 if (aMapOfShape.Add(s)) {
1288 aListOfShape.Append(s);
1289 nbTypes[s.ShapeType()]++;
1294 Astr = Astr + " VERTEX : " + TCollection_AsciiString(nbTypes[TopAbs_VERTEX]) + "\n";
1295 Astr = Astr + " EDGE : " + TCollection_AsciiString(nbTypes[TopAbs_EDGE]) + "\n";
1296 Astr = Astr + " WIRE : " + TCollection_AsciiString(nbTypes[TopAbs_WIRE]) + "\n";
1297 Astr = Astr + " FACE : " + TCollection_AsciiString(nbTypes[TopAbs_FACE]) + "\n";
1298 Astr = Astr + " SHELL : " + TCollection_AsciiString(nbTypes[TopAbs_SHELL]) + "\n";
1299 Astr = Astr + " SOLID : " + TCollection_AsciiString(nbTypes[TopAbs_SOLID]) + "\n";
1300 Astr = Astr + " COMPSOLID : " + TCollection_AsciiString(nbTypes[TopAbs_COMPSOLID]) + "\n";
1301 Astr = Astr + " COMPOUND : " + TCollection_AsciiString(nbTypes[TopAbs_COMPOUND]) + "\n";
1302 Astr = Astr + " SHAPE : " + TCollection_AsciiString(aMapOfShape.Extent());
1304 catch (Standard_Failure) {
1305 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1306 SetErrorCode(aFail->GetMessageString());
1315 //=======================================================================
1316 //function : CheckSingularCase
1317 //purpose : auxilary for GetMinDistance()
1318 // workaround for bugs 19899, 19908 and 19910 from Mantis
1319 //=======================================================================
1320 static double CheckSingularCase(const TopoDS_Shape& aSh1,
1321 const TopoDS_Shape& aSh2,
1322 gp_Pnt& Ptmp1, gp_Pnt& Ptmp2)
1324 bool IsChange1 = false;
1325 double AddDist1 = 0.0;
1326 TopExp_Explorer anExp;
1327 TopoDS_Shape tmpSh1, tmpSh2;
1329 for ( anExp.Init( aSh1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1331 tmpSh1 = anExp.Current();
1334 TopoDS_Shape sh = aSh1;
1335 while(sh.ShapeType()==TopAbs_COMPOUND) {
1336 TopoDS_Iterator it(sh);
1339 Handle(Geom_Surface) S = BRep_Tool::Surface(TopoDS::Face(tmpSh1));
1340 if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1341 S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1342 if( sh.ShapeType()==TopAbs_SHELL || sh.ShapeType()==TopAbs_FACE ) {
1345 S->Bounds(U1,U2,V1,V2);
1346 Handle(Geom_RectangularTrimmedSurface) TrS1 =
1347 new Geom_RectangularTrimmedSurface(S,U1,(U1+U2)/2.,V1,V2);
1348 Handle(Geom_RectangularTrimmedSurface) TrS2 =
1349 new Geom_RectangularTrimmedSurface(S,(U1+U2)/2.,U2,V1,V2);
1352 TopoDS_Compound Comp;
1353 B.MakeCompound(Comp);
1354 B.MakeFace(F1,TrS1,1.e-7);
1356 B.MakeFace(F2,TrS2,1.e-7);
1358 Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
1360 sfs->SetPrecision(1.e-6);
1361 sfs->SetMaxTolerance(1.0);
1363 tmpSh1 = sfs->Shape();
1367 if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ) {
1368 Handle(Geom_SphericalSurface) SS = Handle(Geom_SphericalSurface)::DownCast(S);
1369 gp_Pnt PC = SS->Location();
1372 B.MakeVertex(V,PC,1.e-7);
1374 AddDist1 = SS->Radius();
1378 Handle(Geom_ToroidalSurface) TS = Handle(Geom_ToroidalSurface)::DownCast(S);
1379 gp_Ax3 ax3 = TS->Position();
1380 Handle(Geom_Circle) C = new Geom_Circle(ax3.Ax2(),TS->MajorRadius());
1383 B.MakeEdge(E,C,1.e-7);
1385 AddDist1 = TS->MinorRadius();
1395 bool IsChange2 = false;
1396 double AddDist2 = 0.0;
1398 for ( anExp.Init( aSh2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1400 tmpSh2 = anExp.Current();
1403 TopoDS_Shape sh = aSh2;
1404 while(sh.ShapeType()==TopAbs_COMPOUND) {
1405 TopoDS_Iterator it(sh);
1408 Handle(Geom_Surface) S = BRep_Tool::Surface(TopoDS::Face(tmpSh2));
1409 if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1410 S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1411 if( sh.ShapeType()==TopAbs_SHELL || sh.ShapeType()==TopAbs_FACE ) {
1414 S->Bounds(U1,U2,V1,V2);
1415 Handle(Geom_RectangularTrimmedSurface) TrS1 =
1416 new Geom_RectangularTrimmedSurface(S,U1,(U1+U2)/2.,V1,V2);
1417 Handle(Geom_RectangularTrimmedSurface) TrS2 =
1418 new Geom_RectangularTrimmedSurface(S,(U1+U2)/2.,U2,V1,V2);
1421 TopoDS_Compound Comp;
1422 B.MakeCompound(Comp);
1423 B.MakeFace(F1,TrS1,1.e-7);
1425 B.MakeFace(F2,TrS2,1.e-7);
1427 Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
1429 sfs->SetPrecision(1.e-6);
1430 sfs->SetMaxTolerance(1.0);
1432 tmpSh2 = sfs->Shape();
1436 if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ) {
1437 Handle(Geom_SphericalSurface) SS = Handle(Geom_SphericalSurface)::DownCast(S);
1438 gp_Pnt PC = SS->Location();
1441 B.MakeVertex(V,PC,1.e-7);
1443 AddDist2 = SS->Radius();
1446 else if( S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1447 Handle(Geom_ToroidalSurface) TS = Handle(Geom_ToroidalSurface)::DownCast(S);
1448 gp_Ax3 ax3 = TS->Position();
1449 Handle(Geom_Circle) C = new Geom_Circle(ax3.Ax2(),TS->MajorRadius());
1452 B.MakeEdge(E,C,1.e-7);
1454 AddDist2 = TS->MinorRadius();
1465 if( !IsChange1 && !IsChange2 )
1468 BRepExtrema_DistShapeShape dst(tmpSh1,tmpSh2);
1470 double MinDist = 1.e9;
1471 gp_Pnt PMin1, PMin2, P1, P2;
1472 for (int i = 1; i <= dst.NbSolution(); i++) {
1473 P1 = dst.PointOnShape1(i);
1474 P2 = dst.PointOnShape2(i);
1475 Standard_Real Dist = P1.Distance(P2);
1476 if (MinDist > Dist) {
1487 gp_Dir aDir(gp_Vec(PMin1,PMin2));
1488 if( MinDist > (AddDist1+AddDist2) ) {
1489 Ptmp1 = gp_Pnt( PMin1.X() + aDir.X()*AddDist1,
1490 PMin1.Y() + aDir.Y()*AddDist1,
1491 PMin1.Z() + aDir.Z()*AddDist1 );
1492 Ptmp2 = gp_Pnt( PMin2.X() - aDir.X()*AddDist2,
1493 PMin2.Y() - aDir.Y()*AddDist2,
1494 PMin2.Z() - aDir.Z()*AddDist2 );
1495 return (MinDist - AddDist1 - AddDist2);
1498 if( AddDist1 > 0 ) {
1499 Ptmp1 = gp_Pnt( PMin1.X() + aDir.X()*AddDist1,
1500 PMin1.Y() + aDir.Y()*AddDist1,
1501 PMin1.Z() + aDir.Z()*AddDist1 );
1505 Ptmp2 = gp_Pnt( PMin2.X() - aDir.X()*AddDist2,
1506 PMin2.Y() - aDir.Y()*AddDist2,
1507 PMin2.Z() - aDir.Z()*AddDist2 );
1512 double res = MinDist - AddDist1 - AddDist2;
1513 if(res<0.) res = 0.0;
1519 static bool CheckSingularCase(const TopoDS_Shape& aSh1,
1520 const TopoDS_Shape& aSh2,
1523 TopExp_Explorer anExp;
1524 TopoDS_Shape tmpSh1, tmpSh2;
1526 for ( anExp.Init( aSh1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1528 tmpSh1 = anExp.Current();
1531 Handle(Geom_Surface) S1 = BRep_Tool::Surface(TopoDS::Face(tmpSh1));
1532 if( S1->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1533 S1->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1535 for ( anExp.Init( aSh2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1537 tmpSh2 = anExp.Current();
1538 Handle(Geom_Surface) S2 = BRep_Tool::Surface(TopoDS::Face(tmpSh2));
1539 GeomAPI_IntSS ISS(S1,S2,1.e-7);
1541 for(int i=1; i<=ISS.NbLines(); i++) {
1542 Handle(Geom_Curve) C3d = ISS.Line(i);
1545 B.MakeEdge(E,C3d,1.e-7);
1546 BRepExtrema_DistShapeShape dst(tmpSh2,E);
1548 gp_Pnt PMin1, PMin2, P1, P2;
1549 double MinDist = 1.e9;
1550 for (int i = 1; i <= dst.NbSolution(); i++) {
1551 P1 = dst.PointOnShape1(i);
1552 P2 = dst.PointOnShape2(i);
1553 Standard_Real Dist = P1.Distance(P2);
1554 if (MinDist > Dist) {
1568 for ( anExp.Init( aSh2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1570 tmpSh1 = anExp.Current();
1573 Handle(Geom_Surface) S1 = BRep_Tool::Surface(TopoDS::Face(tmpSh1));
1574 if( S1->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1575 S1->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1577 for ( anExp.Init( aSh1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1579 tmpSh2 = anExp.Current();
1580 Handle(Geom_Surface) S2 = BRep_Tool::Surface(TopoDS::Face(tmpSh2));
1581 GeomAPI_IntSS ISS(S1,S2,1.e-7);
1583 for(int i=1; i<=ISS.NbLines(); i++) {
1584 Handle(Geom_Curve) C3d = ISS.Line(i);
1587 B.MakeEdge(E,C3d,1.e-7);
1588 BRepExtrema_DistShapeShape dst(tmpSh2,E);
1591 double MinDist = 1.e9;
1592 for (int i = 1; i <= dst.NbSolution(); i++) {
1593 P1 = dst.PointOnShape1(i);
1594 P2 = dst.PointOnShape2(i);
1595 Standard_Real Dist = P1.Distance(P2);
1596 if (MinDist > Dist) {
1614 //=============================================================================
1618 //=============================================================================
1619 Standard_Real GEOMImpl_IMeasureOperations::GetMinDistance
1620 (Handle(GEOM_Object) theShape1, Handle(GEOM_Object) theShape2,
1621 Standard_Real& X1, Standard_Real& Y1, Standard_Real& Z1,
1622 Standard_Real& X2, Standard_Real& Y2, Standard_Real& Z2)
1625 Standard_Real MinDist = 1.e9;
1627 if (theShape1.IsNull() || theShape2.IsNull()) return MinDist;
1629 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
1630 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
1631 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return MinDist;
1633 TopoDS_Shape aShape1 = aRefShape1->GetValue();
1634 TopoDS_Shape aShape2 = aRefShape2->GetValue();
1635 if (aShape1.IsNull() || aShape2.IsNull()) {
1636 SetErrorCode("One of Objects has NULL Shape");
1640 //Compute the parameters
1642 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1647 // additional workaround for bugs 19899, 19908 and 19910 from Mantis
1648 gp_Pnt Ptmp1, Ptmp2;
1649 double dist = CheckSingularCase(aShape1, aShape2, Ptmp1, Ptmp2);
1651 Ptmp1.Coord(X1, Y1, Z1);
1652 Ptmp2.Coord(X2, Y2, Z2);
1657 BRepExtrema_DistShapeShape dst (aShape1, aShape2);
1659 gp_Pnt PMin1, PMin2, P1, P2;
1661 for (int i = 1; i <= dst.NbSolution(); i++) {
1662 P1 = dst.PointOnShape1(i);
1663 P2 = dst.PointOnShape2(i);
1665 Standard_Real Dist = P1.Distance(P2);
1666 if (MinDist > Dist) {
1673 PMin1.Coord(X1, Y1, Z1);
1674 PMin2.Coord(X2, Y2, Z2);
1677 catch (Standard_Failure) {
1678 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1679 SetErrorCode(aFail->GetMessageString());
1687 //=======================================================================
1689 * Get coordinates of point
1691 //=======================================================================
1692 void GEOMImpl_IMeasureOperations::PointCoordinates (Handle(GEOM_Object) theShape,
1693 Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ)
1697 if (theShape.IsNull())
1700 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1701 if (aRefShape.IsNull())
1704 TopoDS_Shape aShape = aRefShape->GetValue();
1705 if (aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX)
1707 SetErrorCode( "Shape must be a vertex" );
1712 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1715 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
1722 catch (Standard_Failure)
1724 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1725 SetErrorCode( aFail->GetMessageString() );
1729 //=======================================================================
1731 * Compute angle (in degrees) between two lines
1733 //=======================================================================
1734 Standard_Real GEOMImpl_IMeasureOperations::GetAngle (Handle(GEOM_Object) theLine1,
1735 Handle(GEOM_Object) theLine2)
1739 Standard_Real anAngle = -1.0;
1741 if (theLine1.IsNull() || theLine2.IsNull())
1744 Handle(GEOM_Function) aRefLine1 = theLine1->GetLastFunction();
1745 Handle(GEOM_Function) aRefLine2 = theLine2->GetLastFunction();
1746 if (aRefLine1.IsNull() || aRefLine2.IsNull())
1749 TopoDS_Shape aLine1 = aRefLine1->GetValue();
1750 TopoDS_Shape aLine2 = aRefLine2->GetValue();
1751 if (aLine1.IsNull() || aLine2.IsNull() ||
1752 aLine1.ShapeType() != TopAbs_EDGE ||
1753 aLine2.ShapeType() != TopAbs_EDGE)
1755 SetErrorCode("Two edges must be given");
1760 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1763 TopoDS_Edge E1 = TopoDS::Edge(aLine1);
1764 TopoDS_Edge E2 = TopoDS::Edge(aLine2);
1767 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp,lp);
1768 Handle(Geom_Curve) C2 = BRep_Tool::Curve(E2,fp,lp);
1770 if (!C1->IsKind(STANDARD_TYPE(Geom_Line)) ||
1771 !C2->IsKind(STANDARD_TYPE(Geom_Line)))
1773 SetErrorCode("The edges must be linear");
1777 Handle(Geom_Line) L1 = Handle(Geom_Line)::DownCast(C1);
1778 Handle(Geom_Line) L2 = Handle(Geom_Line)::DownCast(C2);
1780 gp_Lin aLin1 = L1->Lin();
1781 gp_Lin aLin2 = L2->Lin();
1783 anAngle = aLin1.Angle(aLin2);
1784 anAngle /= PI180; // convert radians into degrees
1788 catch (Standard_Failure)
1790 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1791 SetErrorCode(aFail->GetMessageString());
1798 //=============================================================================
1800 * CurveCurvatureByParam
1802 //=============================================================================
1803 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByParam
1804 (Handle(GEOM_Object) theCurve, Standard_Real& theParam)
1807 Standard_Real aRes = -1.0;
1809 if(theCurve.IsNull()) return aRes;
1811 Handle(GEOM_Function) aRefShape = theCurve->GetLastFunction();
1812 if(aRefShape.IsNull()) return aRes;
1814 TopoDS_Shape aShape = aRefShape->GetValue();
1815 if(aShape.IsNull()) {
1816 SetErrorCode("One of Objects has NULL Shape");
1820 Standard_Real aFP, aLP, aP;
1821 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aFP, aLP);
1822 aP = aFP + (aLP - aFP) * theParam;
1824 if(aCurve.IsNull()) return aRes;
1828 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1831 GeomLProp_CLProps Prop = GeomLProp_CLProps
1832 (aCurve, aP, 2, Precision::Confusion());
1833 aRes = fabs(Prop.Curvature());
1836 catch (Standard_Failure) {
1837 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1838 SetErrorCode(aFail->GetMessageString());
1842 if( aRes > Precision::Confusion() )
1851 //=============================================================================
1853 * CurveCurvatureByPoint
1855 //=============================================================================
1856 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByPoint
1857 (Handle(GEOM_Object) theCurve, Handle(GEOM_Object) thePoint)
1860 Standard_Real aRes = -1.0;
1862 if( theCurve.IsNull() || thePoint.IsNull() ) return aRes;
1864 Handle(GEOM_Function) aRefCurve = theCurve->GetLastFunction();
1865 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
1866 if( aRefCurve.IsNull() || aRefPoint.IsNull() ) return aRes;
1868 TopoDS_Edge anEdge = TopoDS::Edge(aRefCurve->GetValue());
1869 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
1870 if( anEdge.IsNull() || aPnt.IsNull() ) {
1871 SetErrorCode("One of Objects has NULL Shape");
1875 Standard_Real aFP, aLP;
1876 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFP, aLP);
1877 if(aCurve.IsNull()) return aRes;
1878 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
1882 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1885 GeomAPI_ProjectPointOnCurve PPC(aPoint, aCurve, aFP, aLP);
1886 if(PPC.NbPoints()>0) {
1887 GeomLProp_CLProps Prop = GeomLProp_CLProps
1888 (aCurve, PPC.LowerDistanceParameter(), 2, Precision::Confusion());
1889 aRes = fabs(Prop.Curvature());
1893 catch (Standard_Failure) {
1894 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1895 SetErrorCode(aFail->GetMessageString());
1899 if( aRes > Precision::Confusion() )
1908 //=============================================================================
1910 * getSurfaceCurvatures
1912 //=============================================================================
1913 Standard_Real GEOMImpl_IMeasureOperations::getSurfaceCurvatures
1914 (const Handle(Geom_Surface)& aSurf,
1915 Standard_Real theUParam,
1916 Standard_Real theVParam,
1917 Standard_Boolean theNeedMaxCurv)
1920 Standard_Real aRes = 1.0;
1922 if (aSurf.IsNull()) return aRes;
1925 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1928 GeomLProp_SLProps Prop = GeomLProp_SLProps
1929 (aSurf, theUParam, theVParam, 2, Precision::Confusion());
1930 if(Prop.IsCurvatureDefined()) {
1931 if(Prop.IsUmbilic()) {
1932 //cout<<"is umbilic"<<endl;
1933 aRes = fabs(Prop.MeanCurvature());
1936 //cout<<"is not umbilic"<<endl;
1937 double c1 = fabs(Prop.MaxCurvature());
1938 double c2 = fabs(Prop.MinCurvature());
1947 catch (Standard_Failure) {
1948 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1949 SetErrorCode(aFail->GetMessageString());
1953 if( fabs(aRes) > Precision::Confusion() )
1962 //=============================================================================
1964 * MaxSurfaceCurvatureByParam
1966 //=============================================================================
1967 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByParam
1968 (Handle(GEOM_Object) theSurf,
1969 Standard_Real& theUParam,
1970 Standard_Real& theVParam)
1973 Standard_Real aRes = -1.0;
1975 if (theSurf.IsNull()) return aRes;
1977 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
1978 if(aRefShape.IsNull()) return aRes;
1980 TopoDS_Shape aShape = aRefShape->GetValue();
1981 if(aShape.IsNull()) {
1982 SetErrorCode("One of Objects has NULL Shape");
1986 TopoDS_Face F = TopoDS::Face(aShape);
1987 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
1989 //Compute the parameters
1990 Standard_Real U1,U2,V1,V2;
1991 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
1992 Standard_Real U = U1 + (U2-U1)*theUParam;
1993 Standard_Real V = V1 + (V2-V1)*theVParam;
1995 return getSurfaceCurvatures(aSurf, U, V, true);
1999 //=============================================================================
2001 * MaxSurfaceCurvatureByPoint
2003 //=============================================================================
2004 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByPoint
2005 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2008 Standard_Real aRes = -1.0;
2010 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2012 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2013 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2014 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2016 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2017 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2018 if( aFace.IsNull() || aPnt.IsNull() ) {
2019 SetErrorCode("One of Objects has NULL Shape");
2023 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2024 if(aSurf.IsNull()) return aRes;
2025 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2027 //Compute the parameters
2028 ShapeAnalysis_Surface sas(aSurf);
2029 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2031 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), true);
2035 //=============================================================================
2037 * MinSurfaceCurvatureByParam
2039 //=============================================================================
2040 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByParam
2041 (Handle(GEOM_Object) theSurf,
2042 Standard_Real& theUParam,
2043 Standard_Real& theVParam)
2046 Standard_Real aRes = -1.0;
2048 if (theSurf.IsNull()) return aRes;
2050 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2051 if(aRefShape.IsNull()) return aRes;
2053 TopoDS_Shape aShape = aRefShape->GetValue();
2054 if(aShape.IsNull()) {
2055 SetErrorCode("One of Objects has NULL Shape");
2059 TopoDS_Face F = TopoDS::Face(aShape);
2060 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2062 //Compute the parameters
2063 Standard_Real U1,U2,V1,V2;
2064 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2065 Standard_Real U = U1 + (U2-U1)*theUParam;
2066 Standard_Real V = V1 + (V2-V1)*theVParam;
2068 return getSurfaceCurvatures(aSurf, U, V, false);
2072 //=============================================================================
2074 * MinSurfaceCurvatureByPoint
2076 //=============================================================================
2077 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByPoint
2078 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2081 Standard_Real aRes = -1.0;
2083 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2085 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2086 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2087 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2089 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2090 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2091 if( aFace.IsNull() || aPnt.IsNull() ) {
2092 SetErrorCode("One of Objects has NULL Shape");
2096 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2097 if(aSurf.IsNull()) return aRes;
2098 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2100 //Compute the parameters
2101 ShapeAnalysis_Surface sas(aSurf);
2102 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2104 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), false);
2108 //=======================================================================
2109 //function : StructuralDump
2110 //purpose : Structural (data exchange) style of output.
2111 //=======================================================================
2112 void GEOMImpl_IMeasureOperations::StructuralDump (const BRepCheck_Analyzer& theAna,
2113 const TopoDS_Shape& theShape,
2114 TCollection_AsciiString& theDump)
2118 theDump += " -- The Shape has problems :\n";
2119 theDump += " Check Count\n";
2120 theDump += " ------------------------------------------------\n";
2122 Standard_Integer last_stat = (Standard_Integer)BRepCheck_CheckFail;
2123 Handle(TColStd_HArray1OfInteger) NbProblems =
2124 new TColStd_HArray1OfInteger(1, last_stat);
2125 for (i = 1; i <= last_stat; i++)
2126 NbProblems->SetValue(i,0);
2128 Handle(TopTools_HSequenceOfShape) sl;
2129 sl = new TopTools_HSequenceOfShape();
2130 TopTools_DataMapOfShapeListOfShape theMap;
2132 GetProblemShapes(theAna, theShape, sl, NbProblems, theMap);
2135 Standard_Integer count = 0;
2136 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnCurve);
2138 theDump += " Invalid Point on Curve ................... ";
2139 theDump += TCollection_AsciiString(count) + "\n";
2141 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnCurveOnSurface);
2143 theDump += " Invalid Point on CurveOnSurface .......... ";
2144 theDump += TCollection_AsciiString(count) + "\n";
2146 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnSurface);
2148 theDump += " Invalid Point on Surface ................. ";
2149 theDump += TCollection_AsciiString(count) + "\n";
2151 count = NbProblems->Value((Standard_Integer)BRepCheck_No3DCurve);
2153 theDump += " No 3D Curve .............................. ";
2154 theDump += TCollection_AsciiString(count) + "\n";
2156 count = NbProblems->Value((Standard_Integer)BRepCheck_Multiple3DCurve);
2158 theDump += " Multiple 3D Curve ........................ ";
2159 theDump += TCollection_AsciiString(count) + "\n";
2161 count = NbProblems->Value((Standard_Integer)BRepCheck_Invalid3DCurve);
2163 theDump += " Invalid 3D Curve ......................... ";
2164 theDump += TCollection_AsciiString(count) + "\n";
2166 count = NbProblems->Value((Standard_Integer)BRepCheck_NoCurveOnSurface);
2168 theDump += " No Curve on Surface ...................... ";
2169 theDump += TCollection_AsciiString(count) + "\n";
2171 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidCurveOnSurface);
2173 theDump += " Invalid Curve on Surface ................. ";
2174 theDump += TCollection_AsciiString(count) + "\n";
2176 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidCurveOnClosedSurface);
2178 theDump += " Invalid Curve on closed Surface .......... ";
2179 theDump += TCollection_AsciiString(count) + "\n";
2181 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidSameRangeFlag);
2183 theDump += " Invalid SameRange Flag ................... ";
2184 theDump += TCollection_AsciiString(count) + "\n";
2186 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidSameParameterFlag);
2188 theDump += " Invalid SameParameter Flag ............... ";
2189 theDump += TCollection_AsciiString(count) + "\n";
2191 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidDegeneratedFlag);
2193 theDump += " Invalid Degenerated Flag ................. ";
2194 theDump += TCollection_AsciiString(count) + "\n";
2196 count = NbProblems->Value((Standard_Integer)BRepCheck_FreeEdge);
2198 theDump += " Free Edge ................................ ";
2199 theDump += TCollection_AsciiString(count) + "\n";
2201 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidMultiConnexity);
2203 theDump += " Invalid MultiConnexity ................... ";
2204 theDump += TCollection_AsciiString(count) + "\n";
2206 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidRange);
2208 theDump += " Invalid Range ............................ ";
2209 theDump += TCollection_AsciiString(count) + "\n";
2211 count = NbProblems->Value((Standard_Integer)BRepCheck_EmptyWire);
2213 theDump += " Empty Wire ............................... ";
2214 theDump += TCollection_AsciiString(count) + "\n";
2216 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantEdge);
2218 theDump += " Redundant Edge ........................... ";
2219 theDump += TCollection_AsciiString(count) + "\n";
2221 count = NbProblems->Value((Standard_Integer)BRepCheck_SelfIntersectingWire);
2223 theDump += " Self Intersecting Wire ................... ";
2224 theDump += TCollection_AsciiString(count) + "\n";
2226 count = NbProblems->Value((Standard_Integer)BRepCheck_NoSurface);
2228 theDump += " No Surface ............................... ";
2229 theDump += TCollection_AsciiString(count) + "\n";
2231 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidWire);
2233 theDump += " Invalid Wire ............................. ";
2234 theDump += TCollection_AsciiString(count) + "\n";
2236 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantWire);
2238 theDump += " Redundant Wire ........................... ";
2239 theDump += TCollection_AsciiString(count) + "\n";
2241 count = NbProblems->Value((Standard_Integer)BRepCheck_IntersectingWires);
2243 theDump += " Intersecting Wires ....................... ";
2244 theDump += TCollection_AsciiString(count) + "\n";
2246 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidImbricationOfWires);
2248 theDump += " Invalid Imbrication of Wires ............. ";
2249 theDump += TCollection_AsciiString(count) + "\n";
2251 count = NbProblems->Value((Standard_Integer)BRepCheck_EmptyShell);
2253 theDump += " Empty Shell .............................. ";
2254 theDump += TCollection_AsciiString(count) + "\n";
2256 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantFace);
2258 theDump += " Redundant Face ........................... ";
2259 theDump += TCollection_AsciiString(count) + "\n";
2261 count = NbProblems->Value((Standard_Integer)BRepCheck_UnorientableShape);
2263 theDump += " Unorientable Shape ....................... ";
2264 theDump += TCollection_AsciiString(count) + "\n";
2266 count = NbProblems->Value((Standard_Integer)BRepCheck_NotClosed);
2268 theDump += " Not Closed ............................... ";
2269 theDump += TCollection_AsciiString(count) + "\n";
2271 count = NbProblems->Value((Standard_Integer)BRepCheck_NotConnected);
2273 theDump += " Not Connected ............................ ";
2274 theDump += TCollection_AsciiString(count) + "\n";
2276 count = NbProblems->Value((Standard_Integer)BRepCheck_SubshapeNotInShape);
2278 theDump += " Subshape not in Shape .................... ";
2279 theDump += TCollection_AsciiString(count) + "\n";
2281 count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientation);
2283 theDump += " Bad Orientation .......................... ";
2284 theDump += TCollection_AsciiString(count) + "\n";
2286 count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientationOfSubshape);
2288 theDump += " Bad Orientation of Subshape .............. ";
2289 theDump += TCollection_AsciiString(count) + "\n";
2291 count = NbProblems->Value((Standard_Integer)BRepCheck_CheckFail);
2293 theDump += " checkshape failure ....................... ";
2294 theDump += TCollection_AsciiString(count) + "\n";
2297 theDump += " ------------------------------------------------\n";
2298 theDump += "*** Shapes with problems : ";
2299 theDump += TCollection_AsciiString(sl->Length()) + "\n";
2301 Standard_Integer nbv, nbe, nbw, nbf, nbs, nbo;
2302 nbv = nbe = nbw = nbf = nbs = nbo = 0;
2304 for (i = 1; i <= sl->Length(); i++) {
2305 TopoDS_Shape shi = sl->Value(i);
2306 TopAbs_ShapeEnum sti = shi.ShapeType();
2308 case TopAbs_VERTEX : nbv++; break;
2309 case TopAbs_EDGE : nbe++; break;
2310 case TopAbs_WIRE : nbw++; break;
2311 case TopAbs_FACE : nbf++; break;
2312 case TopAbs_SHELL : nbs++; break;
2313 case TopAbs_SOLID : nbo++; break;
2319 theDump += "VERTEX : ";
2320 if (nbv < 10) theDump += " ";
2321 theDump += TCollection_AsciiString(nbv) + "\n";
2324 theDump += "EDGE : ";
2325 if (nbe < 10) theDump += " ";
2326 theDump += TCollection_AsciiString(nbe) + "\n";
2329 theDump += "WIRE : ";
2330 if (nbw < 10) theDump += " ";
2331 theDump += TCollection_AsciiString(nbw) + "\n";
2334 theDump += "FACE : ";
2335 if (nbf < 10) theDump += " ";
2336 theDump += TCollection_AsciiString(nbf) + "\n";
2339 theDump += "SHELL : ";
2340 if (nbs < 10) theDump += " ";
2341 theDump += TCollection_AsciiString(nbs) + "\n";
2344 theDump += "SOLID : ";
2345 if (nbo < 10) theDump += " ";
2346 theDump += TCollection_AsciiString(nbo) + "\n";
2351 //=======================================================================
2352 //function : GetProblemShapes
2353 // purpose : for StructuralDump
2354 //=======================================================================
2355 void GEOMImpl_IMeasureOperations::GetProblemShapes (const BRepCheck_Analyzer& theAna,
2356 const TopoDS_Shape& theShape,
2357 Handle(TopTools_HSequenceOfShape)& sl,
2358 Handle(TColStd_HArray1OfInteger)& NbProblems,
2359 TopTools_DataMapOfShapeListOfShape& theMap)
2361 for (TopoDS_Iterator iter(theShape); iter.More(); iter.Next()) {
2362 GetProblemShapes(theAna, iter.Value(), sl, NbProblems, theMap);
2364 TopAbs_ShapeEnum styp = theShape.ShapeType();
2365 BRepCheck_ListIteratorOfListOfStatus itl;
2366 TopTools_ListOfShape empty;
2367 if (!theMap.IsBound(theShape)) {
2368 theMap.Bind(theShape,empty);
2370 if (!theAna.Result(theShape).IsNull()) {
2371 itl.Initialize(theAna.Result(theShape)->Status());
2372 // !!! May be, we have to print all the problems, not only the first one ?
2373 if (itl.Value() != BRepCheck_NoError) {
2374 sl->Append(theShape);
2375 BRepCheck_Status stat = itl.Value();
2376 NbProblems->SetValue((Standard_Integer)stat,
2377 NbProblems->Value((Standard_Integer)stat) + 1);
2384 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_VERTEX, theMap);
2387 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_WIRE, theMap);
2388 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_EDGE, theMap);
2389 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_VERTEX, theMap);
2394 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_SHELL, theMap);
2401 //=======================================================================
2402 //function : Contains
2403 //=======================================================================
2404 static Standard_Boolean Contains (const TopTools_ListOfShape& L,
2405 const TopoDS_Shape& S)
2407 TopTools_ListIteratorOfListOfShape it;
2408 for (it.Initialize(L); it.More(); it.Next()) {
2409 if (it.Value().IsSame(S)) {
2410 return Standard_True;
2413 return Standard_False;
2416 //=======================================================================
2417 //function : GetProblemSub
2418 // purpose : for StructuralDump
2419 //=======================================================================
2420 void GEOMImpl_IMeasureOperations::GetProblemSub (const BRepCheck_Analyzer& theAna,
2421 const TopoDS_Shape& theShape,
2422 Handle(TopTools_HSequenceOfShape)& sl,
2423 Handle(TColStd_HArray1OfInteger)& NbProblems,
2424 const TopAbs_ShapeEnum Subtype,
2425 TopTools_DataMapOfShapeListOfShape& theMap)
2427 BRepCheck_ListIteratorOfListOfStatus itl;
2428 TopExp_Explorer exp;
2429 for (exp.Init(theShape, Subtype); exp.More(); exp.Next()) {
2430 const TopoDS_Shape& sub = exp.Current();
2432 const Handle(BRepCheck_Result)& res = theAna.Result(sub);
2433 for (res->InitContextIterator();
2434 res->MoreShapeInContext();
2435 res->NextShapeInContext()) {
2436 if (res->ContextualShape().IsSame(theShape) && !Contains(theMap(sub), theShape)) {
2437 theMap(sub).Append(theShape);
2438 itl.Initialize(res->StatusOnShape());
2440 if (itl.Value() != BRepCheck_NoError) {
2441 Standard_Integer ii = 0;
2443 for (ii = 1; ii <= sl->Length(); ii++)
2444 if (sl->Value(ii).IsSame(sub)) break;
2446 if (ii > sl->Length()) {
2448 BRepCheck_Status stat = itl.Value();
2449 NbProblems->SetValue((Standard_Integer)stat,
2450 NbProblems->Value((Standard_Integer)stat) + 1);
2452 for (ii = 1; ii <= sl->Length(); ii++)
2453 if (sl->Value(ii).IsSame(theShape)) break;
2454 if (ii > sl->Length()) {
2455 sl->Append(theShape);
2456 BRepCheck_Status stat = itl.Value();
2457 NbProblems->SetValue((Standard_Integer)stat,
2458 NbProblems->Value((Standard_Integer)stat) + 1);