1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <Standard_Stream.hxx>
25 #include <GEOMImpl_IMeasureOperations.hxx>
27 #include <GEOMImpl_Types.hxx>
28 #include <GEOMImpl_MeasureDriver.hxx>
29 #include <GEOMImpl_IMeasure.hxx>
31 #include <GEOMAlgo_ShapeInfo.hxx>
32 #include <GEOMAlgo_ShapeInfoFiller.hxx>
34 #include <GEOM_Function.hxx>
35 #include <GEOM_PythonDump.hxx>
37 #include <utilities.h>
39 #include <Utils_ExceptHandlers.hxx>
42 #include <TFunction_DriverTable.hxx>
43 #include <TFunction_Driver.hxx>
44 #include <TFunction_Logbook.hxx>
45 #include <TDF_Tool.hxx>
47 #include <BRep_Tool.hxx>
48 #include <BRepAdaptor_Surface.hxx>
49 #include <BRepBndLib.hxx>
50 #include <BRepCheck.hxx>
51 #include <BRepCheck_Result.hxx>
52 #include <BRepCheck_ListIteratorOfListOfStatus.hxx>
53 #include <BRepExtrema_DistShapeShape.hxx>
54 #include <BRepGProp.hxx>
55 #include <BRepTools.hxx>
57 #include <Bnd_Box.hxx>
59 #include <GProp_GProps.hxx>
60 #include <GProp_PrincipalProps.hxx>
64 #include <TopoDS_Edge.hxx>
65 #include <TopoDS_Face.hxx>
66 #include <TopoDS_Shape.hxx>
67 #include <TopoDS_Vertex.hxx>
68 #include <TopoDS_Iterator.hxx>
69 #include <TopExp_Explorer.hxx>
70 #include <TopTools_MapOfShape.hxx>
71 #include <TopTools_ListOfShape.hxx>
72 #include <TopTools_ListIteratorOfListOfShape.hxx>
74 #include <GeomAbs_SurfaceType.hxx>
75 #include <Geom_Surface.hxx>
76 #include <Geom_Plane.hxx>
77 #include <Geom_SphericalSurface.hxx>
78 #include <Geom_CylindricalSurface.hxx>
79 #include <Geom_ToroidalSurface.hxx>
80 #include <Geom_ConicalSurface.hxx>
81 #include <Geom_SurfaceOfLinearExtrusion.hxx>
82 #include <Geom_SurfaceOfRevolution.hxx>
83 #include <Geom_BezierSurface.hxx>
84 #include <Geom_BSplineSurface.hxx>
85 #include <Geom_RectangularTrimmedSurface.hxx>
86 #include <Geom_OffsetSurface.hxx>
87 #include <Geom_Line.hxx>
92 #include <GeomAPI_ProjectPointOnCurve.hxx>
93 #include <GeomLProp_CLProps.hxx>
94 #include <GeomLProp_SLProps.hxx>
95 #include <ShapeAnalysis.hxx>
96 #include <ShapeAnalysis_Surface.hxx>
98 #include <Standard_Failure.hxx>
99 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
101 #include <BRepClass3d_SolidClassifier.hxx>
102 #include <BRep_Builder.hxx>
103 #include <GeomAPI_IntSS.hxx>
104 #include <Geom_Circle.hxx>
105 #include <Geom_SphericalSurface.hxx>
106 #include <Geom_ToroidalSurface.hxx>
107 #include <ShapeFix_Shape.hxx>
108 #include <TopoDS_Compound.hxx>
111 //=============================================================================
115 //=============================================================================
116 GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations (GEOM_Engine* theEngine, int theDocID)
117 : GEOM_IOperations(theEngine, theDocID)
119 MESSAGE("GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations");
122 //=============================================================================
126 //=============================================================================
127 GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations()
129 MESSAGE("GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations");
132 //=============================================================================
133 /*! Get kind and parameters of the given shape.
135 //=============================================================================
136 GEOMImpl_IMeasureOperations::ShapeKind GEOMImpl_IMeasureOperations::KindOfShape
137 (Handle(GEOM_Object) theShape,
138 Handle(TColStd_HSequenceOfInteger)& theIntegers,
139 Handle(TColStd_HSequenceOfReal)& theDoubles)
142 ShapeKind aKind = SK_NO_SHAPE;
144 if (theIntegers.IsNull()) theIntegers = new TColStd_HSequenceOfInteger;
145 else theIntegers->Clear();
147 if (theDoubles.IsNull()) theDoubles = new TColStd_HSequenceOfReal;
148 else theDoubles->Clear();
150 if (theShape.IsNull())
153 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
154 if (aRefShape.IsNull()) return aKind;
156 TopoDS_Shape aShape = aRefShape->GetValue();
157 if (aShape.IsNull()) return aKind;
159 int geom_type = theShape->GetType();
161 // check if it's advanced shape
162 if ( geom_type > ADVANCED_BASE ) {
168 GEOMAlgo_ShapeInfoFiller aSF;
169 aSF.SetShape(aShape);
171 Standard_Integer iErr = aSF.ErrorStatus();
173 SetErrorCode("Error in GEOMAlgo_ShapeInfoFiller");
176 const GEOMAlgo_ShapeInfo& anInfo = aSF.Info();
178 // Interprete results
179 TopAbs_ShapeEnum aType = anInfo.Type();
182 case TopAbs_COMPOUND:
183 case TopAbs_COMPSOLID:
185 // (+) geompy.kind.COMPOUND nb_solids nb_faces nb_edges nb_vertices
186 // (+) geompy.kind.COMPSOLID nb_solids nb_faces nb_edges nb_vertices
187 // ??? "nb_faces" - all faces or only 'standalone' faces?
188 if (aType == TopAbs_COMPOUND)
191 aKind = SK_COMPSOLID;
193 //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPOUND));
194 //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPSOLID));
195 theIntegers->Append(anInfo.NbSubShapes(TopAbs_SOLID));
196 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
197 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
198 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
204 // (+) geompy.kind.SHELL geompy.info.closed nb_faces nb_edges nb_vertices
205 // (+) geompy.kind.SHELL geompy.info.unclosed nb_faces nb_edges nb_vertices
208 theIntegers->Append((int)anInfo.KindOfClosed());
210 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
211 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
212 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
218 // (+) geompy.kind.WIRE geompy.info.closed nb_edges nb_vertices
219 // (+) geompy.kind.WIRE geompy.info.unclosed nb_edges nb_vertices
222 theIntegers->Append((int)anInfo.KindOfClosed());
224 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
225 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
233 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
236 case GEOMAlgo_KN_SPHERE:
237 // (+) geompy.kind.SPHERE xc yc zc R
241 gp_Pnt aC = anInfo.Location();
242 theDoubles->Append(aC.X());
243 theDoubles->Append(aC.Y());
244 theDoubles->Append(aC.Z());
246 theDoubles->Append(anInfo.Radius1());
249 case GEOMAlgo_KN_CYLINDER:
250 // (+) geompy.kind.CYLINDER xb yb zb dx dy dz R H
254 gp_Pnt aC = anInfo.Location();
255 theDoubles->Append(aC.X());
256 theDoubles->Append(aC.Y());
257 theDoubles->Append(aC.Z());
259 gp_Ax3 anAx3 = anInfo.Position();
260 gp_Dir aD = anAx3.Direction();
261 theDoubles->Append(aD.X());
262 theDoubles->Append(aD.Y());
263 theDoubles->Append(aD.Z());
265 theDoubles->Append(anInfo.Radius1());
266 theDoubles->Append(anInfo.Height());
269 case GEOMAlgo_KN_BOX:
270 // (+) geompy.kind.BOX xc yc zc ax ay az
274 gp_Pnt aC = anInfo.Location();
275 theDoubles->Append(aC.X());
276 theDoubles->Append(aC.Y());
277 theDoubles->Append(aC.Z());
279 gp_Ax3 anAx3 = anInfo.Position();
280 gp_Dir aD = anAx3.Direction();
281 gp_Dir aX = anAx3.XDirection();
284 if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
285 aX.IsParallel(gp::DX(), Precision::Angular())) {
286 theDoubles->Append(anInfo.Length()); // ax'
287 theDoubles->Append(anInfo.Width()); // ay'
288 theDoubles->Append(anInfo.Height()); // az'
290 else if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
291 aX.IsParallel(gp::DY(), Precision::Angular())) {
292 theDoubles->Append(anInfo.Width()); // ay'
293 theDoubles->Append(anInfo.Length()); // ax'
294 theDoubles->Append(anInfo.Height()); // az'
296 else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
297 aX.IsParallel(gp::DZ(), Precision::Angular())) {
298 theDoubles->Append(anInfo.Height()); // az'
299 theDoubles->Append(anInfo.Width()); // ay'
300 theDoubles->Append(anInfo.Length()); // ax'
302 else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
303 aX.IsParallel(gp::DY(), Precision::Angular())) {
304 theDoubles->Append(anInfo.Height()); // az'
305 theDoubles->Append(anInfo.Length()); // ax'
306 theDoubles->Append(anInfo.Width()); // ay'
308 else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
309 aX.IsParallel(gp::DZ(), Precision::Angular())) {
310 theDoubles->Append(anInfo.Width()); // ay'
311 theDoubles->Append(anInfo.Height()); // az'
312 theDoubles->Append(anInfo.Length()); // ax'
314 else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
315 aX.IsParallel(gp::DX(), Precision::Angular())) {
316 theDoubles->Append(anInfo.Length()); // ax'
317 theDoubles->Append(anInfo.Height()); // az'
318 theDoubles->Append(anInfo.Width()); // ay'
321 // (+) geompy.kind.ROTATED_BOX xo yo zo zx zy zz xx xy xz ax ay az
322 aKind = SK_ROTATED_BOX;
324 // Direction and XDirection
325 theDoubles->Append(aD.X());
326 theDoubles->Append(aD.Y());
327 theDoubles->Append(aD.Z());
329 theDoubles->Append(aX.X());
330 theDoubles->Append(aX.Y());
331 theDoubles->Append(aX.Z());
334 theDoubles->Append(anInfo.Length());
335 theDoubles->Append(anInfo.Width());
336 theDoubles->Append(anInfo.Height());
340 case GEOMAlgo_KN_TORUS:
341 // (+) geompy.kind.TORUS xc yc zc dx dy dz R_1 R_2
345 gp_Pnt aO = anInfo.Location();
346 theDoubles->Append(aO.X());
347 theDoubles->Append(aO.Y());
348 theDoubles->Append(aO.Z());
350 gp_Ax3 anAx3 = anInfo.Position();
351 gp_Dir aD = anAx3.Direction();
352 theDoubles->Append(aD.X());
353 theDoubles->Append(aD.Y());
354 theDoubles->Append(aD.Z());
356 theDoubles->Append(anInfo.Radius1());
357 theDoubles->Append(anInfo.Radius2());
360 case GEOMAlgo_KN_CONE:
361 // (+) geompy.kind.CONE xb yb zb dx dy dz R_1 R_2 H
365 gp_Pnt aO = anInfo.Location();
366 theDoubles->Append(aO.X());
367 theDoubles->Append(aO.Y());
368 theDoubles->Append(aO.Z());
370 gp_Ax3 anAx3 = anInfo.Position();
371 gp_Dir aD = anAx3.Direction();
372 theDoubles->Append(aD.X());
373 theDoubles->Append(aD.Y());
374 theDoubles->Append(aD.Z());
376 theDoubles->Append(anInfo.Radius1());
377 theDoubles->Append(anInfo.Radius2());
378 theDoubles->Append(anInfo.Height());
381 case GEOMAlgo_KN_POLYHEDRON:
382 // (+) geompy.kind.POLYHEDRON nb_faces nb_edges nb_vertices
384 aKind = SK_POLYHEDRON;
386 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
387 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
388 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
392 // (+) geompy.kind.SOLID nb_faces nb_edges nb_vertices
394 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
395 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
396 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
406 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
408 case GEOMAlgo_KN_SPHERE:
409 // (+) geompy.kind.SPHERE2D xc yc zc R
413 gp_Pnt aC = anInfo.Location();
414 theDoubles->Append(aC.X());
415 theDoubles->Append(aC.Y());
416 theDoubles->Append(aC.Z());
418 theDoubles->Append(anInfo.Radius1());
421 case GEOMAlgo_KN_CYLINDER:
422 // (+) geompy.kind.CYLINDER2D xb yb zb dx dy dz R H
424 aKind = SK_CYLINDER2D;
426 gp_Pnt aO = anInfo.Location();
427 theDoubles->Append(aO.X());
428 theDoubles->Append(aO.Y());
429 theDoubles->Append(aO.Z());
431 gp_Ax3 anAx3 = anInfo.Position();
432 gp_Dir aD = anAx3.Direction();
433 theDoubles->Append(aD.X());
434 theDoubles->Append(aD.Y());
435 theDoubles->Append(aD.Z());
437 theDoubles->Append(anInfo.Radius1());
438 theDoubles->Append(anInfo.Height());
441 case GEOMAlgo_KN_TORUS:
442 // (+) geompy.kind.TORUS2D xc yc zc dx dy dz R_1 R_2
446 gp_Pnt aO = anInfo.Location();
447 theDoubles->Append(aO.X());
448 theDoubles->Append(aO.Y());
449 theDoubles->Append(aO.Z());
451 gp_Ax3 anAx3 = anInfo.Position();
452 gp_Dir aD = anAx3.Direction();
453 theDoubles->Append(aD.X());
454 theDoubles->Append(aD.Y());
455 theDoubles->Append(aD.Z());
457 theDoubles->Append(anInfo.Radius1());
458 theDoubles->Append(anInfo.Radius2());
461 case GEOMAlgo_KN_CONE:
462 // (+) geompy.kind.CONE2D xc yc zc dx dy dz R_1 R_2 H
466 gp_Pnt aO = anInfo.Location();
467 theDoubles->Append(aO.X());
468 theDoubles->Append(aO.Y());
469 theDoubles->Append(aO.Z());
471 gp_Ax3 anAx3 = anInfo.Position();
472 gp_Dir aD = anAx3.Direction();
473 theDoubles->Append(aD.X());
474 theDoubles->Append(aD.Y());
475 theDoubles->Append(aD.Z());
477 theDoubles->Append(anInfo.Radius1());
478 theDoubles->Append(anInfo.Radius2());
479 theDoubles->Append(anInfo.Height());
482 case GEOMAlgo_KN_DISKCIRCLE:
483 // (+) geompy.kind.DISK_CIRCLE xc yc zc dx dy dz R
485 aKind = SK_DISK_CIRCLE;
487 gp_Pnt aC = anInfo.Location();
488 theDoubles->Append(aC.X());
489 theDoubles->Append(aC.Y());
490 theDoubles->Append(aC.Z());
492 gp_Ax3 anAx3 = anInfo.Position();
493 gp_Dir aD = anAx3.Direction();
494 theDoubles->Append(aD.X());
495 theDoubles->Append(aD.Y());
496 theDoubles->Append(aD.Z());
498 theDoubles->Append(anInfo.Radius1());
501 case GEOMAlgo_KN_DISKELLIPSE:
502 // (+) geompy.kind.DISK_ELLIPSE xc yc zc dx dy dz R_1 R_2
504 aKind = SK_DISK_ELLIPSE;
506 gp_Pnt aC = anInfo.Location();
507 theDoubles->Append(aC.X());
508 theDoubles->Append(aC.Y());
509 theDoubles->Append(aC.Z());
511 gp_Ax3 anAx3 = anInfo.Position();
512 gp_Dir aD = anAx3.Direction();
513 theDoubles->Append(aD.X());
514 theDoubles->Append(aD.Y());
515 theDoubles->Append(aD.Z());
517 theDoubles->Append(anInfo.Radius1());
518 theDoubles->Append(anInfo.Radius2());
521 case GEOMAlgo_KN_RECTANGLE:
522 case GEOMAlgo_KN_TRIANGLE:
523 case GEOMAlgo_KN_QUADRANGLE:
524 case GEOMAlgo_KN_POLYGON:
525 // (+) geompy.kind.POLYGON xo yo zo dx dy dz nb_edges nb_vertices
529 gp_Pnt aO = anInfo.Location();
530 theDoubles->Append(aO.X());
531 theDoubles->Append(aO.Y());
532 theDoubles->Append(aO.Z());
534 gp_Ax3 anAx3 = anInfo.Position();
535 gp_Dir aD = anAx3.Direction();
536 theDoubles->Append(aD.X());
537 theDoubles->Append(aD.Y());
538 theDoubles->Append(aD.Z());
540 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
541 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
544 case GEOMAlgo_KN_PLANE: // infinite
545 // (+) geompy.kind.PLANE xo yo zo dx dy dz
549 gp_Pnt aC = anInfo.Location();
550 theDoubles->Append(aC.X());
551 theDoubles->Append(aC.Y());
552 theDoubles->Append(aC.Z());
554 gp_Ax3 anAx3 = anInfo.Position();
555 gp_Dir aD = anAx3.Direction();
556 theDoubles->Append(aD.X());
557 theDoubles->Append(aD.Y());
558 theDoubles->Append(aD.Z());
562 if (anInfo.KindOfShape() == GEOMAlgo_KS_PLANE) {
563 // (+) geompy.kind.PLANAR xo yo zo dx dy dz nb_edges nb_vertices
567 gp_Pnt aC = anInfo.Location();
568 theDoubles->Append(aC.X());
569 theDoubles->Append(aC.Y());
570 theDoubles->Append(aC.Z());
572 gp_Ax3 anAx3 = anInfo.Position();
573 gp_Dir aD = anAx3.Direction();
574 theDoubles->Append(aD.X());
575 theDoubles->Append(aD.Y());
576 theDoubles->Append(aD.Z());
578 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
579 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
582 // ??? geompy.kind.FACE nb_edges nb_vertices _surface_type_id_
583 // (+) geompy.kind.FACE nb_edges nb_vertices
585 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
586 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
596 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
598 case GEOMAlgo_KN_CIRCLE:
600 // (+) geompy.kind.CIRCLE xc yc zc dx dy dz R
603 gp_Pnt aC = anInfo.Location();
604 theDoubles->Append(aC.X());
605 theDoubles->Append(aC.Y());
606 theDoubles->Append(aC.Z());
608 gp_Ax3 anAx3 = anInfo.Position();
609 gp_Dir aD = anAx3.Direction();
610 theDoubles->Append(aD.X());
611 theDoubles->Append(aD.Y());
612 theDoubles->Append(aD.Z());
614 theDoubles->Append(anInfo.Radius1());
617 case GEOMAlgo_KN_ARCCIRCLE:
619 // (+) geompy.kind.ARC_CIRCLE xc yc zc dx dy dz R x1 y1 z1 x2 y2 z2
620 aKind = SK_ARC_CIRCLE;
622 gp_Pnt aC = anInfo.Location();
623 theDoubles->Append(aC.X());
624 theDoubles->Append(aC.Y());
625 theDoubles->Append(aC.Z());
627 gp_Ax3 anAx3 = anInfo.Position();
628 gp_Dir aD = anAx3.Direction();
629 theDoubles->Append(aD.X());
630 theDoubles->Append(aD.Y());
631 theDoubles->Append(aD.Z());
633 theDoubles->Append(anInfo.Radius1());
635 gp_Pnt aP1 = anInfo.Pnt1();
636 theDoubles->Append(aP1.X());
637 theDoubles->Append(aP1.Y());
638 theDoubles->Append(aP1.Z());
640 gp_Pnt aP2 = anInfo.Pnt2();
641 theDoubles->Append(aP2.X());
642 theDoubles->Append(aP2.Y());
643 theDoubles->Append(aP2.Z());
646 case GEOMAlgo_KN_ELLIPSE:
648 // (+) geompy.kind.ELLIPSE xc yc zc dx dy dz R_1 R_2
651 gp_Pnt aC = anInfo.Location();
652 theDoubles->Append(aC.X());
653 theDoubles->Append(aC.Y());
654 theDoubles->Append(aC.Z());
656 gp_Ax3 anAx3 = anInfo.Position();
657 gp_Dir aD = anAx3.Direction();
658 theDoubles->Append(aD.X());
659 theDoubles->Append(aD.Y());
660 theDoubles->Append(aD.Z());
662 theDoubles->Append(anInfo.Radius1());
663 theDoubles->Append(anInfo.Radius2());
666 case GEOMAlgo_KN_ARCELLIPSE:
668 // (+) geompy.kind.ARC_ELLIPSE xc yc zc dx dy dz R_1 R_2 x1 y1 z1 x2 y2 z2
669 aKind = SK_ARC_ELLIPSE;
671 gp_Pnt aC = anInfo.Location();
672 theDoubles->Append(aC.X());
673 theDoubles->Append(aC.Y());
674 theDoubles->Append(aC.Z());
676 gp_Ax3 anAx3 = anInfo.Position();
677 gp_Dir aD = anAx3.Direction();
678 theDoubles->Append(aD.X());
679 theDoubles->Append(aD.Y());
680 theDoubles->Append(aD.Z());
682 theDoubles->Append(anInfo.Radius1());
683 theDoubles->Append(anInfo.Radius2());
685 gp_Pnt aP1 = anInfo.Pnt1();
686 theDoubles->Append(aP1.X());
687 theDoubles->Append(aP1.Y());
688 theDoubles->Append(aP1.Z());
690 gp_Pnt aP2 = anInfo.Pnt2();
691 theDoubles->Append(aP2.X());
692 theDoubles->Append(aP2.Y());
693 theDoubles->Append(aP2.Z());
696 case GEOMAlgo_KN_LINE:
698 // ??? geompy.kind.LINE x1 y1 z1 x2 y2 z2
699 // (+) geompy.kind.LINE x1 y1 z1 dx dy dz
702 gp_Pnt aO = anInfo.Location();
703 theDoubles->Append(aO.X());
704 theDoubles->Append(aO.Y());
705 theDoubles->Append(aO.Z());
707 gp_Dir aD = anInfo.Direction();
708 theDoubles->Append(aD.X());
709 theDoubles->Append(aD.Y());
710 theDoubles->Append(aD.Z());
713 case GEOMAlgo_KN_SEGMENT:
715 // (+) geompy.kind.SEGMENT x1 y1 z1 x2 y2 z2
718 gp_Pnt aP1 = anInfo.Pnt1();
719 theDoubles->Append(aP1.X());
720 theDoubles->Append(aP1.Y());
721 theDoubles->Append(aP1.Z());
723 gp_Pnt aP2 = anInfo.Pnt2();
724 theDoubles->Append(aP2.X());
725 theDoubles->Append(aP2.Y());
726 theDoubles->Append(aP2.Z());
730 // ??? geompy.kind.EDGE nb_vertices _curve_type_id_
731 // (+) geompy.kind.EDGE nb_vertices
732 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
739 // (+) geompy.kind.VERTEX x y z
742 gp_Pnt aP = anInfo.Location();
743 theDoubles->Append(aP.X());
744 theDoubles->Append(aP.Y());
745 theDoubles->Append(aP.Z());
754 //=============================================================================
755 /*! Get LCS, corresponding to the given shape.
756 * Origin of the LCS is situated at the shape's center of mass.
757 * Axes of the LCS are obtained from shape's location or,
758 * if the shape is a planar face, from position of its plane.
760 //=============================================================================
761 gp_Ax3 GEOMImpl_IMeasureOperations::GetPosition (const TopoDS_Shape& theShape)
765 if (theShape.IsNull())
769 aResult.Transform(theShape.Location().Transformation());
770 if (theShape.ShapeType() == TopAbs_FACE) {
771 Handle(Geom_Surface) aGS = BRep_Tool::Surface(TopoDS::Face(theShape));
772 if (!aGS.IsNull() && aGS->IsKind(STANDARD_TYPE(Geom_Plane))) {
773 Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast(aGS);
774 gp_Pln aPln = aGPlane->Pln();
775 aResult = aPln.Position();
781 if (theShape.ShapeType() == TopAbs_VERTEX) {
782 aPnt = BRep_Tool::Pnt(TopoDS::Vertex(theShape));
785 GProp_GProps aSystem;
786 if (theShape.ShapeType() == TopAbs_EDGE || theShape.ShapeType() == TopAbs_WIRE)
787 BRepGProp::LinearProperties(theShape, aSystem);
788 else if (theShape.ShapeType() == TopAbs_FACE || theShape.ShapeType() == TopAbs_SHELL)
789 BRepGProp::SurfaceProperties(theShape, aSystem);
791 BRepGProp::VolumeProperties(theShape, aSystem);
793 aPnt = aSystem.CentreOfMass();
796 aResult.SetLocation(aPnt);
801 //=============================================================================
805 //=============================================================================
806 void GEOMImpl_IMeasureOperations::GetPosition
807 (Handle(GEOM_Object) theShape,
808 Standard_Real& Ox, Standard_Real& Oy, Standard_Real& Oz,
809 Standard_Real& Zx, Standard_Real& Zy, Standard_Real& Zz,
810 Standard_Real& Xx, Standard_Real& Xy, Standard_Real& Xz)
814 //Set default values: global CS
815 Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
818 if (theShape.IsNull()) return;
820 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
821 if (aRefShape.IsNull()) return;
823 TopoDS_Shape aShape = aRefShape->GetValue();
824 if (aShape.IsNull()) {
825 SetErrorCode("The Objects has NULL Shape");
830 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
834 gp_Ax3 anAx3 = GetPosition(aShape);
836 gp_Pnt anOri = anAx3.Location();
837 gp_Dir aDirZ = anAx3.Direction();
838 gp_Dir aDirX = anAx3.XDirection();
841 anOri.Coord(Ox, Oy, Oz);
842 aDirZ.Coord(Zx, Zy, Zz);
843 aDirX.Coord(Xx, Xy, Xz);
845 catch (Standard_Failure) {
846 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
847 SetErrorCode(aFail->GetMessageString());
854 //=============================================================================
858 //=============================================================================
859 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetCentreOfMass
860 (Handle(GEOM_Object) theShape)
864 if (theShape.IsNull()) return NULL;
866 //Add a new CentreOfMass object
867 Handle(GEOM_Object) aCDG = GetEngine()->AddObject(GetDocID(), GEOM_CDG);
869 //Add a new CentreOfMass function
870 Handle(GEOM_Function) aFunction =
871 aCDG->AddFunction(GEOMImpl_MeasureDriver::GetID(), CDG_MEASURE);
872 if (aFunction.IsNull()) return NULL;
874 //Check if the function is set correctly
875 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
877 GEOMImpl_IMeasure aCI (aFunction);
879 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
880 if (aRefShape.IsNull()) return NULL;
882 aCI.SetBase(aRefShape);
884 //Compute the CentreOfMass value
886 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
889 if (!GetSolver()->ComputeFunction(aFunction)) {
890 SetErrorCode("Measure driver failed to compute centre of mass");
894 catch (Standard_Failure) {
895 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
896 SetErrorCode(aFail->GetMessageString());
900 //Make a Python command
901 GEOM::TPythonDump(aFunction) << aCDG << " = geompy.MakeCDG(" << theShape << ")";
907 //=============================================================================
911 //=============================================================================
912 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetVertexByIndex
913 (Handle(GEOM_Object) theShape,
914 Standard_Integer theIndex)
918 if (theShape.IsNull()) return NULL;
920 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
921 if (aRefShape.IsNull()) return NULL;
923 //Add a new Vertex object
924 Handle(GEOM_Object) aVertex = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
927 Handle(GEOM_Function) aFunction =
928 aVertex->AddFunction(GEOMImpl_MeasureDriver::GetID(), VERTEX_BY_INDEX);
929 if (aFunction.IsNull()) return NULL;
931 //Check if the function is set correctly
932 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
934 GEOMImpl_IMeasure aCI (aFunction);
935 aCI.SetBase(aRefShape);
936 aCI.SetIndex(theIndex);
940 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
943 if (!GetSolver()->ComputeFunction(aFunction)) {
944 SetErrorCode("Vertex by index driver failed.");
948 catch (Standard_Failure) {
949 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
950 SetErrorCode(aFail->GetMessageString());
954 //Make a Python command
955 GEOM::TPythonDump(aFunction) << aVertex << " = geompy.GetVertexByIndex(" << theShape << ", " << theIndex << ")";
961 //=============================================================================
965 //=============================================================================
966 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetNormal
967 (Handle(GEOM_Object) theFace,
968 Handle(GEOM_Object) theOptionalPoint)
972 if (theFace.IsNull()) return NULL;
974 //Add a new Normale object
975 Handle(GEOM_Object) aNorm = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
977 //Add a new Normale function
978 Handle(GEOM_Function) aFunction =
979 aNorm->AddFunction(GEOMImpl_MeasureDriver::GetID(), VECTOR_FACE_NORMALE);
980 if (aFunction.IsNull()) return NULL;
982 //Check if the function is set correctly
983 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
985 GEOMImpl_IMeasure aCI (aFunction);
987 Handle(GEOM_Function) aFace = theFace->GetLastFunction();
988 if (aFace.IsNull()) return NULL;
992 if (!theOptionalPoint.IsNull()) {
993 Handle(GEOM_Function) anOptPnt = theOptionalPoint->GetLastFunction();
994 aCI.SetPoint(anOptPnt);
997 //Compute the Normale value
999 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1002 if (!GetSolver()->ComputeFunction(aFunction)) {
1003 SetErrorCode("Measure driver failed to compute normake of face");
1007 catch (Standard_Failure) {
1008 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1009 SetErrorCode(aFail->GetMessageString());
1013 //Make a Python command
1014 GEOM::TPythonDump pd (aFunction);
1015 pd << aNorm << " = geompy.GetNormal(" << theFace;
1016 if (!theOptionalPoint.IsNull()) {
1017 pd << ", " << theOptionalPoint;
1025 //=============================================================================
1027 * GetBasicProperties
1029 //=============================================================================
1030 void GEOMImpl_IMeasureOperations::GetBasicProperties (Handle(GEOM_Object) theShape,
1031 Standard_Real& theLength,
1032 Standard_Real& theSurfArea,
1033 Standard_Real& theVolume)
1037 if (theShape.IsNull()) return;
1039 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1040 if (aRefShape.IsNull()) return;
1042 TopoDS_Shape aShape = aRefShape->GetValue();
1043 if (aShape.IsNull()) {
1044 SetErrorCode("The Objects has NULL Shape");
1048 //Compute the parameters
1049 GProp_GProps LProps, SProps;
1051 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1054 BRepGProp::LinearProperties(aShape, LProps);
1055 theLength = LProps.Mass();
1057 BRepGProp::SurfaceProperties(aShape, SProps);
1058 theSurfArea = SProps.Mass();
1061 if (aShape.ShapeType() < TopAbs_SHELL) {
1062 for (TopExp_Explorer Exp (aShape, TopAbs_SOLID); Exp.More(); Exp.Next()) {
1063 GProp_GProps VProps;
1064 BRepGProp::VolumeProperties(Exp.Current(), VProps);
1065 theVolume += VProps.Mass();
1069 catch (Standard_Failure) {
1070 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1071 SetErrorCode(aFail->GetMessageString());
1078 //=============================================================================
1082 //=============================================================================
1083 void GEOMImpl_IMeasureOperations::GetInertia
1084 (Handle(GEOM_Object) theShape,
1085 Standard_Real& I11, Standard_Real& I12, Standard_Real& I13,
1086 Standard_Real& I21, Standard_Real& I22, Standard_Real& I23,
1087 Standard_Real& I31, Standard_Real& I32, Standard_Real& I33,
1088 Standard_Real& Ix , Standard_Real& Iy , Standard_Real& Iz)
1092 if (theShape.IsNull()) return;
1094 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1095 if (aRefShape.IsNull()) return;
1097 TopoDS_Shape aShape = aRefShape->GetValue();
1098 if (aShape.IsNull()) {
1099 SetErrorCode("The Objects has NULL Shape");
1103 //Compute the parameters
1104 GProp_GProps System;
1107 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1110 if (aShape.ShapeType() == TopAbs_VERTEX ||
1111 aShape.ShapeType() == TopAbs_EDGE ||
1112 aShape.ShapeType() == TopAbs_WIRE) {
1113 BRepGProp::LinearProperties(aShape, System);
1114 } else if (aShape.ShapeType() == TopAbs_FACE ||
1115 aShape.ShapeType() == TopAbs_SHELL) {
1116 BRepGProp::SurfaceProperties(aShape, System);
1118 BRepGProp::VolumeProperties(aShape, System);
1120 gp_Mat I = System.MatrixOfInertia();
1134 GProp_PrincipalProps Pr = System.PrincipalProperties();
1135 Pr.Moments(Ix,Iy,Iz);
1137 catch (Standard_Failure) {
1138 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1139 SetErrorCode(aFail->GetMessageString());
1146 //=============================================================================
1150 //=============================================================================
1151 void GEOMImpl_IMeasureOperations::GetBoundingBox
1152 (Handle(GEOM_Object) theShape,
1153 Standard_Real& Xmin, Standard_Real& Xmax,
1154 Standard_Real& Ymin, Standard_Real& Ymax,
1155 Standard_Real& Zmin, Standard_Real& Zmax)
1159 if (theShape.IsNull()) return;
1161 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1162 if (aRefShape.IsNull()) return;
1164 TopoDS_Shape aShape = aRefShape->GetValue();
1165 if (aShape.IsNull()) {
1166 SetErrorCode("The Objects has NULL Shape");
1170 //Compute the parameters
1174 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1177 BRepBndLib::Add(aShape, B);
1178 B.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
1180 catch (Standard_Failure) {
1181 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1182 SetErrorCode(aFail->GetMessageString());
1189 //=============================================================================
1193 //=============================================================================
1194 void GEOMImpl_IMeasureOperations::GetTolerance
1195 (Handle(GEOM_Object) theShape,
1196 Standard_Real& FaceMin, Standard_Real& FaceMax,
1197 Standard_Real& EdgeMin, Standard_Real& EdgeMax,
1198 Standard_Real& VertMin, Standard_Real& VertMax)
1202 if (theShape.IsNull()) return;
1204 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1205 if (aRefShape.IsNull()) return;
1207 TopoDS_Shape aShape = aRefShape->GetValue();
1208 if (aShape.IsNull()) {
1209 SetErrorCode("The Objects has NULL Shape");
1213 //Compute the parameters
1215 FaceMin = EdgeMin = VertMin = RealLast();
1216 FaceMax = EdgeMax = VertMax = -RealLast();
1219 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1222 for (TopExp_Explorer ExF (aShape, TopAbs_FACE); ExF.More(); ExF.Next()) {
1223 TopoDS_Face Face = TopoDS::Face(ExF.Current());
1224 T = BRep_Tool::Tolerance(Face);
1230 for (TopExp_Explorer ExE (aShape, TopAbs_EDGE); ExE.More(); ExE.Next()) {
1231 TopoDS_Edge Edge = TopoDS::Edge(ExE.Current());
1232 T = BRep_Tool::Tolerance(Edge);
1238 for (TopExp_Explorer ExV (aShape, TopAbs_VERTEX); ExV.More(); ExV.Next()) {
1239 TopoDS_Vertex Vertex = TopoDS::Vertex(ExV.Current());
1240 T = BRep_Tool::Tolerance(Vertex);
1247 catch (Standard_Failure) {
1248 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1249 SetErrorCode(aFail->GetMessageString());
1256 //=============================================================================
1260 //=============================================================================
1261 bool GEOMImpl_IMeasureOperations::CheckShape (Handle(GEOM_Object) theShape,
1262 const Standard_Boolean theIsCheckGeom,
1263 TCollection_AsciiString& theDump)
1267 if (theShape.IsNull()) return false;
1269 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1270 if (aRefShape.IsNull()) return false;
1272 TopoDS_Shape aShape = aRefShape->GetValue();
1273 if (aShape.IsNull()) {
1274 SetErrorCode("The Objects has NULL Shape");
1278 //Compute the parameters
1279 bool isValid = false;
1281 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1284 BRepCheck_Analyzer ana (aShape, theIsCheckGeom);
1285 if (ana.IsValid()) {
1289 StructuralDump(ana, aShape, theDump);
1292 catch (Standard_Failure) {
1293 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1294 SetErrorCode(aFail->GetMessageString());
1302 //=============================================================================
1306 //=============================================================================
1307 TCollection_AsciiString GEOMImpl_IMeasureOperations::WhatIs (Handle(GEOM_Object) theShape)
1311 TCollection_AsciiString Astr;
1313 if (theShape.IsNull()) return Astr;
1315 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1316 if (aRefShape.IsNull()) return Astr;
1318 TopoDS_Shape aShape = aRefShape->GetValue();
1319 if (aShape.IsNull()) {
1320 SetErrorCode("The Objects has NULL Shape");
1324 //Compute the parameters
1325 if (aShape.ShapeType() == TopAbs_EDGE) {
1326 if (BRep_Tool::Degenerated(TopoDS::Edge(aShape))) {
1327 Astr = Astr + " It is a degenerated edge \n";
1331 Astr = Astr + " Number of sub-shapes : \n";
1334 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1337 int iType, nbTypes [TopAbs_SHAPE];
1338 for (iType = 0; iType < TopAbs_SHAPE; ++iType)
1340 nbTypes[aShape.ShapeType()]++;
1342 TopTools_MapOfShape aMapOfShape;
1343 aMapOfShape.Add(aShape);
1344 TopTools_ListOfShape aListOfShape;
1345 aListOfShape.Append(aShape);
1347 TopTools_ListIteratorOfListOfShape itL (aListOfShape);
1348 for (; itL.More(); itL.Next()) {
1349 TopoDS_Iterator it (itL.Value());
1350 for (; it.More(); it.Next()) {
1351 TopoDS_Shape s = it.Value();
1352 if (aMapOfShape.Add(s)) {
1353 aListOfShape.Append(s);
1354 nbTypes[s.ShapeType()]++;
1359 Astr = Astr + " VERTEX : " + TCollection_AsciiString(nbTypes[TopAbs_VERTEX]) + "\n";
1360 Astr = Astr + " EDGE : " + TCollection_AsciiString(nbTypes[TopAbs_EDGE]) + "\n";
1361 Astr = Astr + " WIRE : " + TCollection_AsciiString(nbTypes[TopAbs_WIRE]) + "\n";
1362 Astr = Astr + " FACE : " + TCollection_AsciiString(nbTypes[TopAbs_FACE]) + "\n";
1363 Astr = Astr + " SHELL : " + TCollection_AsciiString(nbTypes[TopAbs_SHELL]) + "\n";
1364 Astr = Astr + " SOLID : " + TCollection_AsciiString(nbTypes[TopAbs_SOLID]) + "\n";
1365 Astr = Astr + " COMPSOLID : " + TCollection_AsciiString(nbTypes[TopAbs_COMPSOLID]) + "\n";
1366 Astr = Astr + " COMPOUND : " + TCollection_AsciiString(nbTypes[TopAbs_COMPOUND]) + "\n";
1367 Astr = Astr + " SHAPE : " + TCollection_AsciiString(aMapOfShape.Extent());
1369 catch (Standard_Failure) {
1370 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1371 SetErrorCode(aFail->GetMessageString());
1380 //=======================================================================
1381 //function : CheckSingularCase
1382 //purpose : auxilary for GetMinDistance()
1383 // workaround for bugs 19899, 19908 and 19910 from Mantis
1384 //=======================================================================
1385 static double CheckSingularCase(const TopoDS_Shape& aSh1,
1386 const TopoDS_Shape& aSh2,
1387 gp_Pnt& Ptmp1, gp_Pnt& Ptmp2)
1389 bool IsChange1 = false;
1390 double AddDist1 = 0.0;
1391 TopExp_Explorer anExp;
1392 TopoDS_Shape tmpSh1, tmpSh2;
1394 for ( anExp.Init( aSh1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1396 tmpSh1 = anExp.Current();
1399 TopoDS_Shape sh = aSh1;
1400 while(sh.ShapeType()==TopAbs_COMPOUND) {
1401 TopoDS_Iterator it(sh);
1404 Handle(Geom_Surface) S = BRep_Tool::Surface(TopoDS::Face(tmpSh1));
1405 if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1406 S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1407 if( sh.ShapeType()==TopAbs_SHELL || sh.ShapeType()==TopAbs_FACE ) {
1410 // changes for 0020677: EDF 1219 GEOM: MinDistance gives 0 instead of 20.88
1411 //S->Bounds(U1,U2,V1,V2); changed by
1412 ShapeAnalysis::GetFaceUVBounds(TopoDS::Face(tmpSh1),U1,U2,V1,V2);
1413 // end of changes for 020677 (dmv)
1414 Handle(Geom_RectangularTrimmedSurface) TrS1 =
1415 new Geom_RectangularTrimmedSurface(S,U1,(U1+U2)/2.,V1,V2);
1416 Handle(Geom_RectangularTrimmedSurface) TrS2 =
1417 new Geom_RectangularTrimmedSurface(S,(U1+U2)/2.,U2,V1,V2);
1420 TopoDS_Compound Comp;
1421 B.MakeCompound(Comp);
1422 B.MakeFace(F1,TrS1,1.e-7);
1424 B.MakeFace(F2,TrS2,1.e-7);
1426 Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
1428 sfs->SetPrecision(1.e-6);
1429 sfs->SetMaxTolerance(1.0);
1431 tmpSh1 = sfs->Shape();
1435 if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ) {
1436 Handle(Geom_SphericalSurface) SS = Handle(Geom_SphericalSurface)::DownCast(S);
1437 gp_Pnt PC = SS->Location();
1440 B.MakeVertex(V,PC,1.e-7);
1442 AddDist1 = SS->Radius();
1446 Handle(Geom_ToroidalSurface) TS = Handle(Geom_ToroidalSurface)::DownCast(S);
1447 gp_Ax3 ax3 = TS->Position();
1448 Handle(Geom_Circle) C = new Geom_Circle(ax3.Ax2(),TS->MajorRadius());
1451 B.MakeEdge(E,C,1.e-7);
1453 AddDist1 = TS->MinorRadius();
1463 bool IsChange2 = false;
1464 double AddDist2 = 0.0;
1466 for ( anExp.Init( aSh2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1468 tmpSh2 = anExp.Current();
1471 TopoDS_Shape sh = aSh2;
1472 while(sh.ShapeType()==TopAbs_COMPOUND) {
1473 TopoDS_Iterator it(sh);
1476 Handle(Geom_Surface) S = BRep_Tool::Surface(TopoDS::Face(tmpSh2));
1477 if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1478 S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1479 if( sh.ShapeType()==TopAbs_SHELL || sh.ShapeType()==TopAbs_FACE ) {
1482 //S->Bounds(U1,U2,V1,V2);
1483 ShapeAnalysis::GetFaceUVBounds(TopoDS::Face(tmpSh2),U1,U2,V1,V2);
1484 Handle(Geom_RectangularTrimmedSurface) TrS1 =
1485 new Geom_RectangularTrimmedSurface(S,U1,(U1+U2)/2.,V1,V2);
1486 Handle(Geom_RectangularTrimmedSurface) TrS2 =
1487 new Geom_RectangularTrimmedSurface(S,(U1+U2)/2.,U2,V1,V2);
1490 TopoDS_Compound Comp;
1491 B.MakeCompound(Comp);
1492 B.MakeFace(F1,TrS1,1.e-7);
1494 B.MakeFace(F2,TrS2,1.e-7);
1496 Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
1498 sfs->SetPrecision(1.e-6);
1499 sfs->SetMaxTolerance(1.0);
1501 tmpSh2 = sfs->Shape();
1505 if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ) {
1506 Handle(Geom_SphericalSurface) SS = Handle(Geom_SphericalSurface)::DownCast(S);
1507 gp_Pnt PC = SS->Location();
1510 B.MakeVertex(V,PC,1.e-7);
1512 AddDist2 = SS->Radius();
1515 else if( S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1516 Handle(Geom_ToroidalSurface) TS = Handle(Geom_ToroidalSurface)::DownCast(S);
1517 gp_Ax3 ax3 = TS->Position();
1518 Handle(Geom_Circle) C = new Geom_Circle(ax3.Ax2(),TS->MajorRadius());
1521 B.MakeEdge(E,C,1.e-7);
1523 AddDist2 = TS->MinorRadius();
1534 if( !IsChange1 && !IsChange2 )
1537 BRepExtrema_DistShapeShape dst(tmpSh1,tmpSh2);
1539 double MinDist = 1.e9;
1540 gp_Pnt PMin1, PMin2, P1, P2;
1541 for (int i = 1; i <= dst.NbSolution(); i++) {
1542 P1 = dst.PointOnShape1(i);
1543 P2 = dst.PointOnShape2(i);
1544 Standard_Real Dist = P1.Distance(P2);
1545 if (MinDist > Dist) {
1556 gp_Dir aDir(gp_Vec(PMin1,PMin2));
1557 if( MinDist > (AddDist1+AddDist2) ) {
1558 Ptmp1 = gp_Pnt( PMin1.X() + aDir.X()*AddDist1,
1559 PMin1.Y() + aDir.Y()*AddDist1,
1560 PMin1.Z() + aDir.Z()*AddDist1 );
1561 Ptmp2 = gp_Pnt( PMin2.X() - aDir.X()*AddDist2,
1562 PMin2.Y() - aDir.Y()*AddDist2,
1563 PMin2.Z() - aDir.Z()*AddDist2 );
1564 return (MinDist - AddDist1 - AddDist2);
1567 if( AddDist1 > 0 ) {
1568 Ptmp1 = gp_Pnt( PMin1.X() + aDir.X()*AddDist1,
1569 PMin1.Y() + aDir.Y()*AddDist1,
1570 PMin1.Z() + aDir.Z()*AddDist1 );
1574 Ptmp2 = gp_Pnt( PMin2.X() - aDir.X()*AddDist2,
1575 PMin2.Y() - aDir.Y()*AddDist2,
1576 PMin2.Z() - aDir.Z()*AddDist2 );
1581 double res = MinDist - AddDist1 - AddDist2;
1582 if(res<0.) res = 0.0;
1588 static bool CheckSingularCase(const TopoDS_Shape& aSh1,
1589 const TopoDS_Shape& aSh2,
1592 TopExp_Explorer anExp;
1593 TopoDS_Shape tmpSh1, tmpSh2;
1595 for ( anExp.Init( aSh1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1597 tmpSh1 = anExp.Current();
1600 Handle(Geom_Surface) S1 = BRep_Tool::Surface(TopoDS::Face(tmpSh1));
1601 if( S1->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1602 S1->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1604 for ( anExp.Init( aSh2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1606 tmpSh2 = anExp.Current();
1607 Handle(Geom_Surface) S2 = BRep_Tool::Surface(TopoDS::Face(tmpSh2));
1608 GeomAPI_IntSS ISS(S1,S2,1.e-7);
1610 for(int i=1; i<=ISS.NbLines(); i++) {
1611 Handle(Geom_Curve) C3d = ISS.Line(i);
1614 B.MakeEdge(E,C3d,1.e-7);
1615 BRepExtrema_DistShapeShape dst(tmpSh2,E);
1617 gp_Pnt PMin1, PMin2, P1, P2;
1618 double MinDist = 1.e9;
1619 for (int i = 1; i <= dst.NbSolution(); i++) {
1620 P1 = dst.PointOnShape1(i);
1621 P2 = dst.PointOnShape2(i);
1622 Standard_Real Dist = P1.Distance(P2);
1623 if (MinDist > Dist) {
1637 for ( anExp.Init( aSh2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1639 tmpSh1 = anExp.Current();
1642 Handle(Geom_Surface) S1 = BRep_Tool::Surface(TopoDS::Face(tmpSh1));
1643 if( S1->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1644 S1->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1646 for ( anExp.Init( aSh1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1648 tmpSh2 = anExp.Current();
1649 Handle(Geom_Surface) S2 = BRep_Tool::Surface(TopoDS::Face(tmpSh2));
1650 GeomAPI_IntSS ISS(S1,S2,1.e-7);
1652 for(int i=1; i<=ISS.NbLines(); i++) {
1653 Handle(Geom_Curve) C3d = ISS.Line(i);
1656 B.MakeEdge(E,C3d,1.e-7);
1657 BRepExtrema_DistShapeShape dst(tmpSh2,E);
1660 double MinDist = 1.e9;
1661 for (int i = 1; i <= dst.NbSolution(); i++) {
1662 P1 = dst.PointOnShape1(i);
1663 P2 = dst.PointOnShape2(i);
1664 Standard_Real Dist = P1.Distance(P2);
1665 if (MinDist > Dist) {
1683 //=============================================================================
1687 //=============================================================================
1688 Standard_Real GEOMImpl_IMeasureOperations::GetMinDistance
1689 (Handle(GEOM_Object) theShape1, Handle(GEOM_Object) theShape2,
1690 Standard_Real& X1, Standard_Real& Y1, Standard_Real& Z1,
1691 Standard_Real& X2, Standard_Real& Y2, Standard_Real& Z2)
1694 Standard_Real MinDist = 1.e9;
1696 if (theShape1.IsNull() || theShape2.IsNull()) return MinDist;
1698 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
1699 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
1700 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return MinDist;
1702 TopoDS_Shape aShape1 = aRefShape1->GetValue();
1703 TopoDS_Shape aShape2 = aRefShape2->GetValue();
1704 if (aShape1.IsNull() || aShape2.IsNull()) {
1705 SetErrorCode("One of Objects has NULL Shape");
1709 //Compute the parameters
1711 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1715 // Issue 0020231: A min distance bug with torus and vertex.
1716 // Make GetMinDistance() return zero if a sole VERTEX is inside any of SOLIDs
1718 // which of shapes consists of only one vertex?
1719 TopExp_Explorer exp1(aShape1,TopAbs_VERTEX), exp2(aShape2,TopAbs_VERTEX);
1720 TopoDS_Shape V1 = exp1.More() ? exp1.Current() : TopoDS_Shape();
1721 TopoDS_Shape V2 = exp2.More() ? exp2.Current() : TopoDS_Shape();
1722 exp1.Next(); exp2.Next();
1723 if ( exp1.More() ) V1.Nullify();
1724 if ( exp2.More() ) V2.Nullify();
1725 // vertex and container of solids
1726 TopoDS_Shape V = V1.IsNull() ? V2 : V1;
1727 TopoDS_Shape S = V1.IsNull() ? aShape1 : aShape2;
1728 if ( !V.IsNull() ) {
1729 // classify vertex against solids
1730 gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( V ) );
1731 for ( exp1.Init( S, TopAbs_SOLID ); exp1.More(); exp1.Next() ) {
1732 BRepClass3d_SolidClassifier classifier( exp1.Current(), p, 1e-6);
1733 if ( classifier.State() == TopAbs_IN ) {
1734 p.Coord(X1, Y1, Z1);
1735 p.Coord(X2, Y2, Z2);
1741 // End Issue 0020231
1744 // additional workaround for bugs 19899, 19908 and 19910 from Mantis
1745 gp_Pnt Ptmp1, Ptmp2;
1746 double dist = CheckSingularCase(aShape1, aShape2, Ptmp1, Ptmp2);
1748 Ptmp1.Coord(X1, Y1, Z1);
1749 Ptmp2.Coord(X2, Y2, Z2);
1754 BRepExtrema_DistShapeShape dst (aShape1, aShape2);
1756 gp_Pnt PMin1, PMin2, P1, P2;
1758 for (int i = 1; i <= dst.NbSolution(); i++) {
1759 P1 = dst.PointOnShape1(i);
1760 P2 = dst.PointOnShape2(i);
1762 Standard_Real Dist = P1.Distance(P2);
1763 if (MinDist > Dist) {
1770 PMin1.Coord(X1, Y1, Z1);
1771 PMin2.Coord(X2, Y2, Z2);
1774 catch (Standard_Failure) {
1775 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1776 SetErrorCode(aFail->GetMessageString());
1784 //=======================================================================
1786 * Get coordinates of point
1788 //=======================================================================
1789 void GEOMImpl_IMeasureOperations::PointCoordinates (Handle(GEOM_Object) theShape,
1790 Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ)
1794 if (theShape.IsNull())
1797 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1798 if (aRefShape.IsNull())
1801 TopoDS_Shape aShape = aRefShape->GetValue();
1802 if (aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX)
1804 SetErrorCode( "Shape must be a vertex" );
1809 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1812 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
1819 catch (Standard_Failure)
1821 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1822 SetErrorCode( aFail->GetMessageString() );
1826 //=======================================================================
1828 * Compute angle (in degrees) between two lines
1830 //=======================================================================
1831 Standard_Real GEOMImpl_IMeasureOperations::GetAngle (Handle(GEOM_Object) theLine1,
1832 Handle(GEOM_Object) theLine2)
1836 Standard_Real anAngle = -1.0;
1838 if (theLine1.IsNull() || theLine2.IsNull())
1841 Handle(GEOM_Function) aRefLine1 = theLine1->GetLastFunction();
1842 Handle(GEOM_Function) aRefLine2 = theLine2->GetLastFunction();
1843 if (aRefLine1.IsNull() || aRefLine2.IsNull())
1846 TopoDS_Shape aLine1 = aRefLine1->GetValue();
1847 TopoDS_Shape aLine2 = aRefLine2->GetValue();
1848 if (aLine1.IsNull() || aLine2.IsNull() ||
1849 aLine1.ShapeType() != TopAbs_EDGE ||
1850 aLine2.ShapeType() != TopAbs_EDGE)
1852 SetErrorCode("Two edges must be given");
1857 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1860 TopoDS_Edge E1 = TopoDS::Edge(aLine1);
1861 TopoDS_Edge E2 = TopoDS::Edge(aLine2);
1864 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp,lp);
1865 Handle(Geom_Curve) C2 = BRep_Tool::Curve(E2,fp,lp);
1867 if ( C1.IsNull() || C2.IsNull() ||
1868 !C1->IsKind(STANDARD_TYPE(Geom_Line)) ||
1869 !C2->IsKind(STANDARD_TYPE(Geom_Line)))
1871 SetErrorCode("The edges must be linear");
1875 Handle(Geom_Line) L1 = Handle(Geom_Line)::DownCast(C1);
1876 Handle(Geom_Line) L2 = Handle(Geom_Line)::DownCast(C2);
1878 gp_Lin aLin1 = L1->Lin();
1879 gp_Lin aLin2 = L2->Lin();
1881 anAngle = aLin1.Angle(aLin2);
1882 anAngle /= PI180; // convert radians into degrees
1886 catch (Standard_Failure)
1888 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1889 SetErrorCode(aFail->GetMessageString());
1896 //=============================================================================
1898 * CurveCurvatureByParam
1900 //=============================================================================
1901 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByParam
1902 (Handle(GEOM_Object) theCurve, Standard_Real& theParam)
1905 Standard_Real aRes = -1.0;
1907 if(theCurve.IsNull()) return aRes;
1909 Handle(GEOM_Function) aRefShape = theCurve->GetLastFunction();
1910 if(aRefShape.IsNull()) return aRes;
1912 TopoDS_Shape aShape = aRefShape->GetValue();
1913 if(aShape.IsNull()) {
1914 SetErrorCode("One of Objects has NULL Shape");
1918 Standard_Real aFP, aLP, aP;
1919 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aFP, aLP);
1920 aP = aFP + (aLP - aFP) * theParam;
1922 if(aCurve.IsNull()) return aRes;
1926 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1929 GeomLProp_CLProps Prop = GeomLProp_CLProps
1930 (aCurve, aP, 2, Precision::Confusion());
1931 aRes = fabs(Prop.Curvature());
1934 catch (Standard_Failure) {
1935 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1936 SetErrorCode(aFail->GetMessageString());
1940 if( aRes > Precision::Confusion() )
1949 //=============================================================================
1951 * CurveCurvatureByPoint
1953 //=============================================================================
1954 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByPoint
1955 (Handle(GEOM_Object) theCurve, Handle(GEOM_Object) thePoint)
1958 Standard_Real aRes = -1.0;
1960 if( theCurve.IsNull() || thePoint.IsNull() ) return aRes;
1962 Handle(GEOM_Function) aRefCurve = theCurve->GetLastFunction();
1963 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
1964 if( aRefCurve.IsNull() || aRefPoint.IsNull() ) return aRes;
1966 TopoDS_Edge anEdge = TopoDS::Edge(aRefCurve->GetValue());
1967 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
1968 if( anEdge.IsNull() || aPnt.IsNull() ) {
1969 SetErrorCode("One of Objects has NULL Shape");
1973 Standard_Real aFP, aLP;
1974 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFP, aLP);
1975 if(aCurve.IsNull()) return aRes;
1976 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
1980 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1983 GeomAPI_ProjectPointOnCurve PPC(aPoint, aCurve, aFP, aLP);
1984 if(PPC.NbPoints()>0) {
1985 GeomLProp_CLProps Prop = GeomLProp_CLProps
1986 (aCurve, PPC.LowerDistanceParameter(), 2, Precision::Confusion());
1987 aRes = fabs(Prop.Curvature());
1991 catch (Standard_Failure) {
1992 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1993 SetErrorCode(aFail->GetMessageString());
1997 if( aRes > Precision::Confusion() )
2006 //=============================================================================
2008 * getSurfaceCurvatures
2010 //=============================================================================
2011 Standard_Real GEOMImpl_IMeasureOperations::getSurfaceCurvatures
2012 (const Handle(Geom_Surface)& aSurf,
2013 Standard_Real theUParam,
2014 Standard_Real theVParam,
2015 Standard_Boolean theNeedMaxCurv)
2018 Standard_Real aRes = 1.0;
2020 if (aSurf.IsNull()) return aRes;
2023 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2026 GeomLProp_SLProps Prop = GeomLProp_SLProps
2027 (aSurf, theUParam, theVParam, 2, Precision::Confusion());
2028 if(Prop.IsCurvatureDefined()) {
2029 if(Prop.IsUmbilic()) {
2030 //cout<<"is umbilic"<<endl;
2031 aRes = fabs(Prop.MeanCurvature());
2034 //cout<<"is not umbilic"<<endl;
2035 double c1 = fabs(Prop.MaxCurvature());
2036 double c2 = fabs(Prop.MinCurvature());
2045 catch (Standard_Failure) {
2046 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2047 SetErrorCode(aFail->GetMessageString());
2051 if( fabs(aRes) > Precision::Confusion() )
2060 //=============================================================================
2062 * MaxSurfaceCurvatureByParam
2064 //=============================================================================
2065 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByParam
2066 (Handle(GEOM_Object) theSurf,
2067 Standard_Real& theUParam,
2068 Standard_Real& theVParam)
2071 Standard_Real aRes = -1.0;
2073 if (theSurf.IsNull()) return aRes;
2075 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2076 if(aRefShape.IsNull()) return aRes;
2078 TopoDS_Shape aShape = aRefShape->GetValue();
2079 if(aShape.IsNull()) {
2080 SetErrorCode("One of Objects has NULL Shape");
2084 TopoDS_Face F = TopoDS::Face(aShape);
2085 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2087 //Compute the parameters
2088 Standard_Real U1,U2,V1,V2;
2089 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2090 Standard_Real U = U1 + (U2-U1)*theUParam;
2091 Standard_Real V = V1 + (V2-V1)*theVParam;
2093 return getSurfaceCurvatures(aSurf, U, V, true);
2097 //=============================================================================
2099 * MaxSurfaceCurvatureByPoint
2101 //=============================================================================
2102 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByPoint
2103 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2106 Standard_Real aRes = -1.0;
2108 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2110 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2111 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2112 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2114 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2115 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2116 if( aFace.IsNull() || aPnt.IsNull() ) {
2117 SetErrorCode("One of Objects has NULL Shape");
2121 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2122 if(aSurf.IsNull()) return aRes;
2123 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2125 //Compute the parameters
2126 ShapeAnalysis_Surface sas(aSurf);
2127 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2129 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), true);
2133 //=============================================================================
2135 * MinSurfaceCurvatureByParam
2137 //=============================================================================
2138 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByParam
2139 (Handle(GEOM_Object) theSurf,
2140 Standard_Real& theUParam,
2141 Standard_Real& theVParam)
2144 Standard_Real aRes = -1.0;
2146 if (theSurf.IsNull()) return aRes;
2148 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2149 if(aRefShape.IsNull()) return aRes;
2151 TopoDS_Shape aShape = aRefShape->GetValue();
2152 if(aShape.IsNull()) {
2153 SetErrorCode("One of Objects has NULL Shape");
2157 TopoDS_Face F = TopoDS::Face(aShape);
2158 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2160 //Compute the parameters
2161 Standard_Real U1,U2,V1,V2;
2162 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2163 Standard_Real U = U1 + (U2-U1)*theUParam;
2164 Standard_Real V = V1 + (V2-V1)*theVParam;
2166 return getSurfaceCurvatures(aSurf, U, V, false);
2170 //=============================================================================
2172 * MinSurfaceCurvatureByPoint
2174 //=============================================================================
2175 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByPoint
2176 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2179 Standard_Real aRes = -1.0;
2181 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2183 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2184 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2185 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2187 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2188 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2189 if( aFace.IsNull() || aPnt.IsNull() ) {
2190 SetErrorCode("One of Objects has NULL Shape");
2194 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2195 if(aSurf.IsNull()) return aRes;
2196 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2198 //Compute the parameters
2199 ShapeAnalysis_Surface sas(aSurf);
2200 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2202 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), false);
2206 //=======================================================================
2207 //function : StructuralDump
2208 //purpose : Structural (data exchange) style of output.
2209 //=======================================================================
2210 void GEOMImpl_IMeasureOperations::StructuralDump (const BRepCheck_Analyzer& theAna,
2211 const TopoDS_Shape& theShape,
2212 TCollection_AsciiString& theDump)
2216 theDump += " -- The Shape has problems :\n";
2217 theDump += " Check Count\n";
2218 theDump += " ------------------------------------------------\n";
2220 Standard_Integer last_stat = (Standard_Integer)BRepCheck_CheckFail;
2221 Handle(TColStd_HArray1OfInteger) NbProblems =
2222 new TColStd_HArray1OfInteger(1, last_stat);
2223 for (i = 1; i <= last_stat; i++)
2224 NbProblems->SetValue(i,0);
2226 Handle(TopTools_HSequenceOfShape) sl;
2227 sl = new TopTools_HSequenceOfShape();
2228 TopTools_DataMapOfShapeListOfShape theMap;
2230 GetProblemShapes(theAna, theShape, sl, NbProblems, theMap);
2233 Standard_Integer count = 0;
2234 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnCurve);
2236 theDump += " Invalid Point on Curve ................... ";
2237 theDump += TCollection_AsciiString(count) + "\n";
2239 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnCurveOnSurface);
2241 theDump += " Invalid Point on CurveOnSurface .......... ";
2242 theDump += TCollection_AsciiString(count) + "\n";
2244 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnSurface);
2246 theDump += " Invalid Point on Surface ................. ";
2247 theDump += TCollection_AsciiString(count) + "\n";
2249 count = NbProblems->Value((Standard_Integer)BRepCheck_No3DCurve);
2251 theDump += " No 3D Curve .............................. ";
2252 theDump += TCollection_AsciiString(count) + "\n";
2254 count = NbProblems->Value((Standard_Integer)BRepCheck_Multiple3DCurve);
2256 theDump += " Multiple 3D Curve ........................ ";
2257 theDump += TCollection_AsciiString(count) + "\n";
2259 count = NbProblems->Value((Standard_Integer)BRepCheck_Invalid3DCurve);
2261 theDump += " Invalid 3D Curve ......................... ";
2262 theDump += TCollection_AsciiString(count) + "\n";
2264 count = NbProblems->Value((Standard_Integer)BRepCheck_NoCurveOnSurface);
2266 theDump += " No Curve on Surface ...................... ";
2267 theDump += TCollection_AsciiString(count) + "\n";
2269 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidCurveOnSurface);
2271 theDump += " Invalid Curve on Surface ................. ";
2272 theDump += TCollection_AsciiString(count) + "\n";
2274 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidCurveOnClosedSurface);
2276 theDump += " Invalid Curve on closed Surface .......... ";
2277 theDump += TCollection_AsciiString(count) + "\n";
2279 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidSameRangeFlag);
2281 theDump += " Invalid SameRange Flag ................... ";
2282 theDump += TCollection_AsciiString(count) + "\n";
2284 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidSameParameterFlag);
2286 theDump += " Invalid SameParameter Flag ............... ";
2287 theDump += TCollection_AsciiString(count) + "\n";
2289 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidDegeneratedFlag);
2291 theDump += " Invalid Degenerated Flag ................. ";
2292 theDump += TCollection_AsciiString(count) + "\n";
2294 count = NbProblems->Value((Standard_Integer)BRepCheck_FreeEdge);
2296 theDump += " Free Edge ................................ ";
2297 theDump += TCollection_AsciiString(count) + "\n";
2299 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidMultiConnexity);
2301 theDump += " Invalid MultiConnexity ................... ";
2302 theDump += TCollection_AsciiString(count) + "\n";
2304 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidRange);
2306 theDump += " Invalid Range ............................ ";
2307 theDump += TCollection_AsciiString(count) + "\n";
2309 count = NbProblems->Value((Standard_Integer)BRepCheck_EmptyWire);
2311 theDump += " Empty Wire ............................... ";
2312 theDump += TCollection_AsciiString(count) + "\n";
2314 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantEdge);
2316 theDump += " Redundant Edge ........................... ";
2317 theDump += TCollection_AsciiString(count) + "\n";
2319 count = NbProblems->Value((Standard_Integer)BRepCheck_SelfIntersectingWire);
2321 theDump += " Self Intersecting Wire ................... ";
2322 theDump += TCollection_AsciiString(count) + "\n";
2324 count = NbProblems->Value((Standard_Integer)BRepCheck_NoSurface);
2326 theDump += " No Surface ............................... ";
2327 theDump += TCollection_AsciiString(count) + "\n";
2329 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidWire);
2331 theDump += " Invalid Wire ............................. ";
2332 theDump += TCollection_AsciiString(count) + "\n";
2334 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantWire);
2336 theDump += " Redundant Wire ........................... ";
2337 theDump += TCollection_AsciiString(count) + "\n";
2339 count = NbProblems->Value((Standard_Integer)BRepCheck_IntersectingWires);
2341 theDump += " Intersecting Wires ....................... ";
2342 theDump += TCollection_AsciiString(count) + "\n";
2344 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidImbricationOfWires);
2346 theDump += " Invalid Imbrication of Wires ............. ";
2347 theDump += TCollection_AsciiString(count) + "\n";
2349 count = NbProblems->Value((Standard_Integer)BRepCheck_EmptyShell);
2351 theDump += " Empty Shell .............................. ";
2352 theDump += TCollection_AsciiString(count) + "\n";
2354 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantFace);
2356 theDump += " Redundant Face ........................... ";
2357 theDump += TCollection_AsciiString(count) + "\n";
2359 count = NbProblems->Value((Standard_Integer)BRepCheck_UnorientableShape);
2361 theDump += " Unorientable Shape ....................... ";
2362 theDump += TCollection_AsciiString(count) + "\n";
2364 count = NbProblems->Value((Standard_Integer)BRepCheck_NotClosed);
2366 theDump += " Not Closed ............................... ";
2367 theDump += TCollection_AsciiString(count) + "\n";
2369 count = NbProblems->Value((Standard_Integer)BRepCheck_NotConnected);
2371 theDump += " Not Connected ............................ ";
2372 theDump += TCollection_AsciiString(count) + "\n";
2374 count = NbProblems->Value((Standard_Integer)BRepCheck_SubshapeNotInShape);
2376 theDump += " Subshape not in Shape .................... ";
2377 theDump += TCollection_AsciiString(count) + "\n";
2379 count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientation);
2381 theDump += " Bad Orientation .......................... ";
2382 theDump += TCollection_AsciiString(count) + "\n";
2384 count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientationOfSubshape);
2386 theDump += " Bad Orientation of Subshape .............. ";
2387 theDump += TCollection_AsciiString(count) + "\n";
2389 count = NbProblems->Value((Standard_Integer)BRepCheck_CheckFail);
2391 theDump += " checkshape failure ....................... ";
2392 theDump += TCollection_AsciiString(count) + "\n";
2395 theDump += " ------------------------------------------------\n";
2396 theDump += "*** Shapes with problems : ";
2397 theDump += TCollection_AsciiString(sl->Length()) + "\n";
2399 Standard_Integer nbv, nbe, nbw, nbf, nbs, nbo;
2400 nbv = nbe = nbw = nbf = nbs = nbo = 0;
2402 for (i = 1; i <= sl->Length(); i++) {
2403 TopoDS_Shape shi = sl->Value(i);
2404 TopAbs_ShapeEnum sti = shi.ShapeType();
2406 case TopAbs_VERTEX : nbv++; break;
2407 case TopAbs_EDGE : nbe++; break;
2408 case TopAbs_WIRE : nbw++; break;
2409 case TopAbs_FACE : nbf++; break;
2410 case TopAbs_SHELL : nbs++; break;
2411 case TopAbs_SOLID : nbo++; break;
2417 theDump += "VERTEX : ";
2418 if (nbv < 10) theDump += " ";
2419 theDump += TCollection_AsciiString(nbv) + "\n";
2422 theDump += "EDGE : ";
2423 if (nbe < 10) theDump += " ";
2424 theDump += TCollection_AsciiString(nbe) + "\n";
2427 theDump += "WIRE : ";
2428 if (nbw < 10) theDump += " ";
2429 theDump += TCollection_AsciiString(nbw) + "\n";
2432 theDump += "FACE : ";
2433 if (nbf < 10) theDump += " ";
2434 theDump += TCollection_AsciiString(nbf) + "\n";
2437 theDump += "SHELL : ";
2438 if (nbs < 10) theDump += " ";
2439 theDump += TCollection_AsciiString(nbs) + "\n";
2442 theDump += "SOLID : ";
2443 if (nbo < 10) theDump += " ";
2444 theDump += TCollection_AsciiString(nbo) + "\n";
2449 //=======================================================================
2450 //function : GetProblemShapes
2451 // purpose : for StructuralDump
2452 //=======================================================================
2453 void GEOMImpl_IMeasureOperations::GetProblemShapes (const BRepCheck_Analyzer& theAna,
2454 const TopoDS_Shape& theShape,
2455 Handle(TopTools_HSequenceOfShape)& sl,
2456 Handle(TColStd_HArray1OfInteger)& NbProblems,
2457 TopTools_DataMapOfShapeListOfShape& theMap)
2459 for (TopoDS_Iterator iter(theShape); iter.More(); iter.Next()) {
2460 GetProblemShapes(theAna, iter.Value(), sl, NbProblems, theMap);
2462 TopAbs_ShapeEnum styp = theShape.ShapeType();
2463 BRepCheck_ListIteratorOfListOfStatus itl;
2464 TopTools_ListOfShape empty;
2465 if (!theMap.IsBound(theShape)) {
2466 theMap.Bind(theShape,empty);
2468 if (!theAna.Result(theShape).IsNull()) {
2469 itl.Initialize(theAna.Result(theShape)->Status());
2470 // !!! May be, we have to print all the problems, not only the first one ?
2471 if (itl.Value() != BRepCheck_NoError) {
2472 sl->Append(theShape);
2473 BRepCheck_Status stat = itl.Value();
2474 NbProblems->SetValue((Standard_Integer)stat,
2475 NbProblems->Value((Standard_Integer)stat) + 1);
2482 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_VERTEX, theMap);
2485 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_WIRE, theMap);
2486 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_EDGE, theMap);
2487 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_VERTEX, theMap);
2492 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_SHELL, theMap);
2499 //=======================================================================
2500 //function : Contains
2501 //=======================================================================
2502 static Standard_Boolean Contains (const TopTools_ListOfShape& L,
2503 const TopoDS_Shape& S)
2505 TopTools_ListIteratorOfListOfShape it;
2506 for (it.Initialize(L); it.More(); it.Next()) {
2507 if (it.Value().IsSame(S)) {
2508 return Standard_True;
2511 return Standard_False;
2514 //=======================================================================
2515 //function : GetProblemSub
2516 // purpose : for StructuralDump
2517 //=======================================================================
2518 void GEOMImpl_IMeasureOperations::GetProblemSub (const BRepCheck_Analyzer& theAna,
2519 const TopoDS_Shape& theShape,
2520 Handle(TopTools_HSequenceOfShape)& sl,
2521 Handle(TColStd_HArray1OfInteger)& NbProblems,
2522 const TopAbs_ShapeEnum Subtype,
2523 TopTools_DataMapOfShapeListOfShape& theMap)
2525 BRepCheck_ListIteratorOfListOfStatus itl;
2526 TopExp_Explorer exp;
2527 for (exp.Init(theShape, Subtype); exp.More(); exp.Next()) {
2528 const TopoDS_Shape& sub = exp.Current();
2530 const Handle(BRepCheck_Result)& res = theAna.Result(sub);
2531 for (res->InitContextIterator();
2532 res->MoreShapeInContext();
2533 res->NextShapeInContext()) {
2534 if (res->ContextualShape().IsSame(theShape) && !Contains(theMap(sub), theShape)) {
2535 theMap(sub).Append(theShape);
2536 itl.Initialize(res->StatusOnShape());
2538 if (itl.Value() != BRepCheck_NoError) {
2539 Standard_Integer ii = 0;
2541 for (ii = 1; ii <= sl->Length(); ii++)
2542 if (sl->Value(ii).IsSame(sub)) break;
2544 if (ii > sl->Length()) {
2546 BRepCheck_Status stat = itl.Value();
2547 NbProblems->SetValue((Standard_Integer)stat,
2548 NbProblems->Value((Standard_Integer)stat) + 1);
2550 for (ii = 1; ii <= sl->Length(); ii++)
2551 if (sl->Value(ii).IsSame(theShape)) break;
2552 if (ii > sl->Length()) {
2553 sl->Append(theShape);
2554 BRepCheck_Status stat = itl.Value();
2555 NbProblems->SetValue((Standard_Integer)stat,
2556 NbProblems->Value((Standard_Integer)stat) + 1);