1 // Copyright (C) 2007-2008 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
22 #include <Standard_Stream.hxx>
24 #include <GEOMImpl_IMeasureOperations.hxx>
26 #include <GEOMImpl_Types.hxx>
27 #include <GEOMImpl_MeasureDriver.hxx>
28 #include <GEOMImpl_IMeasure.hxx>
30 #include <GEOMAlgo_ShapeInfo.hxx>
31 #include <GEOMAlgo_ShapeInfoFiller.hxx>
33 #include <GEOM_Function.hxx>
34 #include <GEOM_PythonDump.hxx>
36 #include <utilities.h>
38 #include <Utils_ExceptHandlers.hxx>
41 #include <TFunction_DriverTable.hxx>
42 #include <TFunction_Driver.hxx>
43 #include <TFunction_Logbook.hxx>
44 #include <TDF_Tool.hxx>
46 #include <BRep_Tool.hxx>
47 #include <BRepAdaptor_Surface.hxx>
48 #include <BRepBndLib.hxx>
49 #include <BRepCheck.hxx>
50 #include <BRepCheck_Result.hxx>
51 #include <BRepCheck_ListIteratorOfListOfStatus.hxx>
52 #include <BRepExtrema_DistShapeShape.hxx>
53 #include <BRepGProp.hxx>
54 #include <BRepTools.hxx>
56 #include <Bnd_Box.hxx>
58 #include <GProp_GProps.hxx>
59 #include <GProp_PrincipalProps.hxx>
63 #include <TopoDS_Edge.hxx>
64 #include <TopoDS_Face.hxx>
65 #include <TopoDS_Shape.hxx>
66 #include <TopoDS_Vertex.hxx>
67 #include <TopoDS_Iterator.hxx>
68 #include <TopExp_Explorer.hxx>
69 #include <TopTools_MapOfShape.hxx>
70 #include <TopTools_ListOfShape.hxx>
71 #include <TopTools_ListIteratorOfListOfShape.hxx>
73 #include <GeomAbs_SurfaceType.hxx>
74 #include <Geom_Surface.hxx>
75 #include <Geom_Plane.hxx>
76 #include <Geom_SphericalSurface.hxx>
77 #include <Geom_CylindricalSurface.hxx>
78 #include <Geom_ToroidalSurface.hxx>
79 #include <Geom_ConicalSurface.hxx>
80 #include <Geom_SurfaceOfLinearExtrusion.hxx>
81 #include <Geom_SurfaceOfRevolution.hxx>
82 #include <Geom_BezierSurface.hxx>
83 #include <Geom_BSplineSurface.hxx>
84 #include <Geom_RectangularTrimmedSurface.hxx>
85 #include <Geom_OffsetSurface.hxx>
86 #include <Geom_Line.hxx>
91 #include <GeomAPI_ProjectPointOnCurve.hxx>
92 #include <GeomLProp_CLProps.hxx>
93 #include <GeomLProp_SLProps.hxx>
94 #include <ShapeAnalysis.hxx>
95 #include <ShapeAnalysis_Surface.hxx>
97 #include <Standard_Failure.hxx>
98 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
100 #include <BRepClass3d_SolidClassifier.hxx>
101 #include <BRep_Builder.hxx>
102 #include <GeomAPI_IntSS.hxx>
103 #include <Geom_Circle.hxx>
104 #include <Geom_SphericalSurface.hxx>
105 #include <Geom_ToroidalSurface.hxx>
106 #include <ShapeFix_Shape.hxx>
107 #include <TopoDS_Compound.hxx>
110 //=============================================================================
114 //=============================================================================
115 GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations (GEOM_Engine* theEngine, int theDocID)
116 : GEOM_IOperations(theEngine, theDocID)
118 MESSAGE("GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations");
121 //=============================================================================
125 //=============================================================================
126 GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations()
128 MESSAGE("GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations");
131 //=============================================================================
132 /*! Get kind and parameters of the given shape.
134 //=============================================================================
135 GEOMImpl_IMeasureOperations::ShapeKind GEOMImpl_IMeasureOperations::KindOfShape
136 (Handle(GEOM_Object) theShape,
137 Handle(TColStd_HSequenceOfInteger)& theIntegers,
138 Handle(TColStd_HSequenceOfReal)& theDoubles)
141 ShapeKind aKind = SK_NO_SHAPE;
143 if (theIntegers.IsNull()) theIntegers = new TColStd_HSequenceOfInteger;
144 else theIntegers->Clear();
146 if (theDoubles.IsNull()) theDoubles = new TColStd_HSequenceOfReal;
147 else theDoubles->Clear();
149 if (theShape.IsNull())
152 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
153 if (aRefShape.IsNull()) return aKind;
155 TopoDS_Shape aShape = aRefShape->GetValue();
156 if (aShape.IsNull()) return aKind;
158 int geom_type = theShape->GetType();
160 // check if it's advanced shape
161 if ( geom_type > ADVANCED_BASE ) {
167 GEOMAlgo_ShapeInfoFiller aSF;
168 aSF.SetShape(aShape);
170 Standard_Integer iErr = aSF.ErrorStatus();
172 SetErrorCode("Error in GEOMAlgo_ShapeInfoFiller");
175 const GEOMAlgo_ShapeInfo& anInfo = aSF.Info();
177 // Interprete results
178 TopAbs_ShapeEnum aType = anInfo.Type();
181 case TopAbs_COMPOUND:
182 case TopAbs_COMPSOLID:
184 // (+) geompy.kind.COMPOUND nb_solids nb_faces nb_edges nb_vertices
185 // (+) geompy.kind.COMPSOLID nb_solids nb_faces nb_edges nb_vertices
186 // ??? "nb_faces" - all faces or only 'standalone' faces?
187 if (aType == TopAbs_COMPOUND)
190 aKind = SK_COMPSOLID;
192 //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPOUND));
193 //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPSOLID));
194 theIntegers->Append(anInfo.NbSubShapes(TopAbs_SOLID));
195 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
196 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
197 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
203 // (+) geompy.kind.SHELL geompy.info.closed nb_faces nb_edges nb_vertices
204 // (+) geompy.kind.SHELL geompy.info.unclosed nb_faces nb_edges nb_vertices
207 theIntegers->Append((int)anInfo.KindOfClosed());
209 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
210 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
211 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
217 // (+) geompy.kind.WIRE geompy.info.closed nb_edges nb_vertices
218 // (+) geompy.kind.WIRE geompy.info.unclosed nb_edges nb_vertices
221 theIntegers->Append((int)anInfo.KindOfClosed());
223 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
224 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
232 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
235 case GEOMAlgo_KN_SPHERE:
236 // (+) geompy.kind.SPHERE xc yc zc R
240 gp_Pnt aC = anInfo.Location();
241 theDoubles->Append(aC.X());
242 theDoubles->Append(aC.Y());
243 theDoubles->Append(aC.Z());
245 theDoubles->Append(anInfo.Radius1());
248 case GEOMAlgo_KN_CYLINDER:
249 // (+) geompy.kind.CYLINDER xb yb zb dx dy dz R H
253 gp_Pnt aC = anInfo.Location();
254 theDoubles->Append(aC.X());
255 theDoubles->Append(aC.Y());
256 theDoubles->Append(aC.Z());
258 gp_Ax3 anAx3 = anInfo.Position();
259 gp_Dir aD = anAx3.Direction();
260 theDoubles->Append(aD.X());
261 theDoubles->Append(aD.Y());
262 theDoubles->Append(aD.Z());
264 theDoubles->Append(anInfo.Radius1());
265 theDoubles->Append(anInfo.Height());
268 case GEOMAlgo_KN_BOX:
269 // (+) geompy.kind.BOX xc yc zc ax ay az
273 gp_Pnt aC = anInfo.Location();
274 theDoubles->Append(aC.X());
275 theDoubles->Append(aC.Y());
276 theDoubles->Append(aC.Z());
278 gp_Ax3 anAx3 = anInfo.Position();
279 gp_Dir aD = anAx3.Direction();
280 gp_Dir aX = anAx3.XDirection();
283 if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
284 aX.IsParallel(gp::DX(), Precision::Angular())) {
285 theDoubles->Append(anInfo.Length()); // ax'
286 theDoubles->Append(anInfo.Width()); // ay'
287 theDoubles->Append(anInfo.Height()); // az'
289 else if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
290 aX.IsParallel(gp::DY(), Precision::Angular())) {
291 theDoubles->Append(anInfo.Width()); // ay'
292 theDoubles->Append(anInfo.Length()); // ax'
293 theDoubles->Append(anInfo.Height()); // az'
295 else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
296 aX.IsParallel(gp::DZ(), Precision::Angular())) {
297 theDoubles->Append(anInfo.Height()); // az'
298 theDoubles->Append(anInfo.Width()); // ay'
299 theDoubles->Append(anInfo.Length()); // ax'
301 else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
302 aX.IsParallel(gp::DY(), Precision::Angular())) {
303 theDoubles->Append(anInfo.Height()); // az'
304 theDoubles->Append(anInfo.Length()); // ax'
305 theDoubles->Append(anInfo.Width()); // ay'
307 else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
308 aX.IsParallel(gp::DZ(), Precision::Angular())) {
309 theDoubles->Append(anInfo.Width()); // ay'
310 theDoubles->Append(anInfo.Height()); // az'
311 theDoubles->Append(anInfo.Length()); // ax'
313 else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
314 aX.IsParallel(gp::DX(), Precision::Angular())) {
315 theDoubles->Append(anInfo.Length()); // ax'
316 theDoubles->Append(anInfo.Height()); // az'
317 theDoubles->Append(anInfo.Width()); // ay'
320 // (+) geompy.kind.ROTATED_BOX xo yo zo zx zy zz xx xy xz ax ay az
321 aKind = SK_ROTATED_BOX;
323 // Direction and XDirection
324 theDoubles->Append(aD.X());
325 theDoubles->Append(aD.Y());
326 theDoubles->Append(aD.Z());
328 theDoubles->Append(aX.X());
329 theDoubles->Append(aX.Y());
330 theDoubles->Append(aX.Z());
333 theDoubles->Append(anInfo.Length());
334 theDoubles->Append(anInfo.Width());
335 theDoubles->Append(anInfo.Height());
339 case GEOMAlgo_KN_TORUS:
340 // (+) geompy.kind.TORUS xc yc zc dx dy dz R_1 R_2
344 gp_Pnt aO = anInfo.Location();
345 theDoubles->Append(aO.X());
346 theDoubles->Append(aO.Y());
347 theDoubles->Append(aO.Z());
349 gp_Ax3 anAx3 = anInfo.Position();
350 gp_Dir aD = anAx3.Direction();
351 theDoubles->Append(aD.X());
352 theDoubles->Append(aD.Y());
353 theDoubles->Append(aD.Z());
355 theDoubles->Append(anInfo.Radius1());
356 theDoubles->Append(anInfo.Radius2());
359 case GEOMAlgo_KN_CONE:
360 // (+) geompy.kind.CONE xb yb zb dx dy dz R_1 R_2 H
364 gp_Pnt aO = anInfo.Location();
365 theDoubles->Append(aO.X());
366 theDoubles->Append(aO.Y());
367 theDoubles->Append(aO.Z());
369 gp_Ax3 anAx3 = anInfo.Position();
370 gp_Dir aD = anAx3.Direction();
371 theDoubles->Append(aD.X());
372 theDoubles->Append(aD.Y());
373 theDoubles->Append(aD.Z());
375 theDoubles->Append(anInfo.Radius1());
376 theDoubles->Append(anInfo.Radius2());
377 theDoubles->Append(anInfo.Height());
380 case GEOMAlgo_KN_POLYHEDRON:
381 // (+) geompy.kind.POLYHEDRON nb_faces nb_edges nb_vertices
383 aKind = SK_POLYHEDRON;
385 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
386 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
387 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
391 // (+) geompy.kind.SOLID nb_faces nb_edges nb_vertices
393 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
394 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
395 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
405 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
407 case GEOMAlgo_KN_SPHERE:
408 // (+) geompy.kind.SPHERE2D xc yc zc R
412 gp_Pnt aC = anInfo.Location();
413 theDoubles->Append(aC.X());
414 theDoubles->Append(aC.Y());
415 theDoubles->Append(aC.Z());
417 theDoubles->Append(anInfo.Radius1());
420 case GEOMAlgo_KN_CYLINDER:
421 // (+) geompy.kind.CYLINDER2D xb yb zb dx dy dz R H
423 aKind = SK_CYLINDER2D;
425 gp_Pnt aO = anInfo.Location();
426 theDoubles->Append(aO.X());
427 theDoubles->Append(aO.Y());
428 theDoubles->Append(aO.Z());
430 gp_Ax3 anAx3 = anInfo.Position();
431 gp_Dir aD = anAx3.Direction();
432 theDoubles->Append(aD.X());
433 theDoubles->Append(aD.Y());
434 theDoubles->Append(aD.Z());
436 theDoubles->Append(anInfo.Radius1());
437 theDoubles->Append(anInfo.Height());
440 case GEOMAlgo_KN_TORUS:
441 // (+) geompy.kind.TORUS2D xc yc zc dx dy dz R_1 R_2
445 gp_Pnt aO = anInfo.Location();
446 theDoubles->Append(aO.X());
447 theDoubles->Append(aO.Y());
448 theDoubles->Append(aO.Z());
450 gp_Ax3 anAx3 = anInfo.Position();
451 gp_Dir aD = anAx3.Direction();
452 theDoubles->Append(aD.X());
453 theDoubles->Append(aD.Y());
454 theDoubles->Append(aD.Z());
456 theDoubles->Append(anInfo.Radius1());
457 theDoubles->Append(anInfo.Radius2());
460 case GEOMAlgo_KN_CONE:
461 // (+) geompy.kind.CONE2D xc yc zc dx dy dz R_1 R_2 H
465 gp_Pnt aO = anInfo.Location();
466 theDoubles->Append(aO.X());
467 theDoubles->Append(aO.Y());
468 theDoubles->Append(aO.Z());
470 gp_Ax3 anAx3 = anInfo.Position();
471 gp_Dir aD = anAx3.Direction();
472 theDoubles->Append(aD.X());
473 theDoubles->Append(aD.Y());
474 theDoubles->Append(aD.Z());
476 theDoubles->Append(anInfo.Radius1());
477 theDoubles->Append(anInfo.Radius2());
478 theDoubles->Append(anInfo.Height());
481 case GEOMAlgo_KN_DISKCIRCLE:
482 // (+) geompy.kind.DISK_CIRCLE xc yc zc dx dy dz R
484 aKind = SK_DISK_CIRCLE;
486 gp_Pnt aC = anInfo.Location();
487 theDoubles->Append(aC.X());
488 theDoubles->Append(aC.Y());
489 theDoubles->Append(aC.Z());
491 gp_Ax3 anAx3 = anInfo.Position();
492 gp_Dir aD = anAx3.Direction();
493 theDoubles->Append(aD.X());
494 theDoubles->Append(aD.Y());
495 theDoubles->Append(aD.Z());
497 theDoubles->Append(anInfo.Radius1());
500 case GEOMAlgo_KN_DISKELLIPSE:
501 // (+) geompy.kind.DISK_ELLIPSE xc yc zc dx dy dz R_1 R_2
503 aKind = SK_DISK_ELLIPSE;
505 gp_Pnt aC = anInfo.Location();
506 theDoubles->Append(aC.X());
507 theDoubles->Append(aC.Y());
508 theDoubles->Append(aC.Z());
510 gp_Ax3 anAx3 = anInfo.Position();
511 gp_Dir aD = anAx3.Direction();
512 theDoubles->Append(aD.X());
513 theDoubles->Append(aD.Y());
514 theDoubles->Append(aD.Z());
516 theDoubles->Append(anInfo.Radius1());
517 theDoubles->Append(anInfo.Radius2());
520 case GEOMAlgo_KN_RECTANGLE:
521 case GEOMAlgo_KN_TRIANGLE:
522 case GEOMAlgo_KN_QUADRANGLE:
523 case GEOMAlgo_KN_POLYGON:
524 // (+) geompy.kind.POLYGON xo yo zo dx dy dz nb_edges nb_vertices
528 gp_Pnt aO = anInfo.Location();
529 theDoubles->Append(aO.X());
530 theDoubles->Append(aO.Y());
531 theDoubles->Append(aO.Z());
533 gp_Ax3 anAx3 = anInfo.Position();
534 gp_Dir aD = anAx3.Direction();
535 theDoubles->Append(aD.X());
536 theDoubles->Append(aD.Y());
537 theDoubles->Append(aD.Z());
539 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
540 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
543 case GEOMAlgo_KN_PLANE: // infinite
544 // (+) geompy.kind.PLANE xo yo zo dx dy dz
548 gp_Pnt aC = anInfo.Location();
549 theDoubles->Append(aC.X());
550 theDoubles->Append(aC.Y());
551 theDoubles->Append(aC.Z());
553 gp_Ax3 anAx3 = anInfo.Position();
554 gp_Dir aD = anAx3.Direction();
555 theDoubles->Append(aD.X());
556 theDoubles->Append(aD.Y());
557 theDoubles->Append(aD.Z());
561 if (anInfo.KindOfShape() == GEOMAlgo_KS_PLANE) {
562 // (+) geompy.kind.PLANAR xo yo zo dx dy dz nb_edges nb_vertices
566 gp_Pnt aC = anInfo.Location();
567 theDoubles->Append(aC.X());
568 theDoubles->Append(aC.Y());
569 theDoubles->Append(aC.Z());
571 gp_Ax3 anAx3 = anInfo.Position();
572 gp_Dir aD = anAx3.Direction();
573 theDoubles->Append(aD.X());
574 theDoubles->Append(aD.Y());
575 theDoubles->Append(aD.Z());
577 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
578 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
581 // ??? geompy.kind.FACE nb_edges nb_vertices _surface_type_id_
582 // (+) geompy.kind.FACE nb_edges nb_vertices
584 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
585 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
595 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
597 case GEOMAlgo_KN_CIRCLE:
599 // (+) geompy.kind.CIRCLE xc yc zc dx dy dz R
602 gp_Pnt aC = anInfo.Location();
603 theDoubles->Append(aC.X());
604 theDoubles->Append(aC.Y());
605 theDoubles->Append(aC.Z());
607 gp_Ax3 anAx3 = anInfo.Position();
608 gp_Dir aD = anAx3.Direction();
609 theDoubles->Append(aD.X());
610 theDoubles->Append(aD.Y());
611 theDoubles->Append(aD.Z());
613 theDoubles->Append(anInfo.Radius1());
616 case GEOMAlgo_KN_ARCCIRCLE:
618 // (+) geompy.kind.ARC_CIRCLE xc yc zc dx dy dz R x1 y1 z1 x2 y2 z2
619 aKind = SK_ARC_CIRCLE;
621 gp_Pnt aC = anInfo.Location();
622 theDoubles->Append(aC.X());
623 theDoubles->Append(aC.Y());
624 theDoubles->Append(aC.Z());
626 gp_Ax3 anAx3 = anInfo.Position();
627 gp_Dir aD = anAx3.Direction();
628 theDoubles->Append(aD.X());
629 theDoubles->Append(aD.Y());
630 theDoubles->Append(aD.Z());
632 theDoubles->Append(anInfo.Radius1());
634 gp_Pnt aP1 = anInfo.Pnt1();
635 theDoubles->Append(aP1.X());
636 theDoubles->Append(aP1.Y());
637 theDoubles->Append(aP1.Z());
639 gp_Pnt aP2 = anInfo.Pnt2();
640 theDoubles->Append(aP2.X());
641 theDoubles->Append(aP2.Y());
642 theDoubles->Append(aP2.Z());
645 case GEOMAlgo_KN_ELLIPSE:
647 // (+) geompy.kind.ELLIPSE xc yc zc dx dy dz R_1 R_2
650 gp_Pnt aC = anInfo.Location();
651 theDoubles->Append(aC.X());
652 theDoubles->Append(aC.Y());
653 theDoubles->Append(aC.Z());
655 gp_Ax3 anAx3 = anInfo.Position();
656 gp_Dir aD = anAx3.Direction();
657 theDoubles->Append(aD.X());
658 theDoubles->Append(aD.Y());
659 theDoubles->Append(aD.Z());
661 theDoubles->Append(anInfo.Radius1());
662 theDoubles->Append(anInfo.Radius2());
665 case GEOMAlgo_KN_ARCELLIPSE:
667 // (+) geompy.kind.ARC_ELLIPSE xc yc zc dx dy dz R_1 R_2 x1 y1 z1 x2 y2 z2
668 aKind = SK_ARC_ELLIPSE;
670 gp_Pnt aC = anInfo.Location();
671 theDoubles->Append(aC.X());
672 theDoubles->Append(aC.Y());
673 theDoubles->Append(aC.Z());
675 gp_Ax3 anAx3 = anInfo.Position();
676 gp_Dir aD = anAx3.Direction();
677 theDoubles->Append(aD.X());
678 theDoubles->Append(aD.Y());
679 theDoubles->Append(aD.Z());
681 theDoubles->Append(anInfo.Radius1());
682 theDoubles->Append(anInfo.Radius2());
684 gp_Pnt aP1 = anInfo.Pnt1();
685 theDoubles->Append(aP1.X());
686 theDoubles->Append(aP1.Y());
687 theDoubles->Append(aP1.Z());
689 gp_Pnt aP2 = anInfo.Pnt2();
690 theDoubles->Append(aP2.X());
691 theDoubles->Append(aP2.Y());
692 theDoubles->Append(aP2.Z());
695 case GEOMAlgo_KN_LINE:
697 // ??? geompy.kind.LINE x1 y1 z1 x2 y2 z2
698 // (+) geompy.kind.LINE x1 y1 z1 dx dy dz
701 gp_Pnt aO = anInfo.Location();
702 theDoubles->Append(aO.X());
703 theDoubles->Append(aO.Y());
704 theDoubles->Append(aO.Z());
706 gp_Dir aD = anInfo.Direction();
707 theDoubles->Append(aD.X());
708 theDoubles->Append(aD.Y());
709 theDoubles->Append(aD.Z());
712 case GEOMAlgo_KN_SEGMENT:
714 // (+) geompy.kind.SEGMENT x1 y1 z1 x2 y2 z2
717 gp_Pnt aP1 = anInfo.Pnt1();
718 theDoubles->Append(aP1.X());
719 theDoubles->Append(aP1.Y());
720 theDoubles->Append(aP1.Z());
722 gp_Pnt aP2 = anInfo.Pnt2();
723 theDoubles->Append(aP2.X());
724 theDoubles->Append(aP2.Y());
725 theDoubles->Append(aP2.Z());
729 // ??? geompy.kind.EDGE nb_vertices _curve_type_id_
730 // (+) geompy.kind.EDGE nb_vertices
731 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
738 // (+) geompy.kind.VERTEX x y z
741 gp_Pnt aP = anInfo.Location();
742 theDoubles->Append(aP.X());
743 theDoubles->Append(aP.Y());
744 theDoubles->Append(aP.Z());
753 //=============================================================================
754 /*! Get LCS, corresponding to the given shape.
755 * Origin of the LCS is situated at the shape's center of mass.
756 * Axes of the LCS are obtained from shape's location or,
757 * if the shape is a planar face, from position of its plane.
759 //=============================================================================
760 gp_Ax3 GEOMImpl_IMeasureOperations::GetPosition (const TopoDS_Shape& theShape)
764 if (theShape.IsNull())
768 aResult.Transform(theShape.Location().Transformation());
769 if (theShape.ShapeType() == TopAbs_FACE) {
770 Handle(Geom_Surface) aGS = BRep_Tool::Surface(TopoDS::Face(theShape));
771 if (!aGS.IsNull() && aGS->IsKind(STANDARD_TYPE(Geom_Plane))) {
772 Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast(aGS);
773 gp_Pln aPln = aGPlane->Pln();
774 aResult = aPln.Position();
780 if (theShape.ShapeType() == TopAbs_VERTEX) {
781 aPnt = BRep_Tool::Pnt(TopoDS::Vertex(theShape));
784 GProp_GProps aSystem;
785 if (theShape.ShapeType() == TopAbs_EDGE || theShape.ShapeType() == TopAbs_WIRE)
786 BRepGProp::LinearProperties(theShape, aSystem);
787 else if (theShape.ShapeType() == TopAbs_FACE || theShape.ShapeType() == TopAbs_SHELL)
788 BRepGProp::SurfaceProperties(theShape, aSystem);
790 BRepGProp::VolumeProperties(theShape, aSystem);
792 aPnt = aSystem.CentreOfMass();
795 aResult.SetLocation(aPnt);
800 //=============================================================================
804 //=============================================================================
805 void GEOMImpl_IMeasureOperations::GetPosition
806 (Handle(GEOM_Object) theShape,
807 Standard_Real& Ox, Standard_Real& Oy, Standard_Real& Oz,
808 Standard_Real& Zx, Standard_Real& Zy, Standard_Real& Zz,
809 Standard_Real& Xx, Standard_Real& Xy, Standard_Real& Xz)
813 //Set default values: global CS
814 Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
817 if (theShape.IsNull()) return;
819 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
820 if (aRefShape.IsNull()) return;
822 TopoDS_Shape aShape = aRefShape->GetValue();
823 if (aShape.IsNull()) {
824 SetErrorCode("The Objects has NULL Shape");
829 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
833 gp_Ax3 anAx3 = GetPosition(aShape);
835 gp_Pnt anOri = anAx3.Location();
836 gp_Dir aDirZ = anAx3.Direction();
837 gp_Dir aDirX = anAx3.XDirection();
840 anOri.Coord(Ox, Oy, Oz);
841 aDirZ.Coord(Zx, Zy, Zz);
842 aDirX.Coord(Xx, Xy, Xz);
844 catch (Standard_Failure) {
845 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
846 SetErrorCode(aFail->GetMessageString());
853 //=============================================================================
857 //=============================================================================
858 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetCentreOfMass
859 (Handle(GEOM_Object) theShape)
863 if (theShape.IsNull()) return NULL;
865 //Add a new CentreOfMass object
866 Handle(GEOM_Object) aCDG = GetEngine()->AddObject(GetDocID(), GEOM_CDG);
868 //Add a new CentreOfMass function
869 Handle(GEOM_Function) aFunction =
870 aCDG->AddFunction(GEOMImpl_MeasureDriver::GetID(), CDG_MEASURE);
871 if (aFunction.IsNull()) return NULL;
873 //Check if the function is set correctly
874 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
876 GEOMImpl_IMeasure aCI (aFunction);
878 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
879 if (aRefShape.IsNull()) return NULL;
881 aCI.SetBase(aRefShape);
883 //Compute the CentreOfMass value
885 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
888 if (!GetSolver()->ComputeFunction(aFunction)) {
889 SetErrorCode("Measure driver failed to compute centre of mass");
893 catch (Standard_Failure) {
894 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
895 SetErrorCode(aFail->GetMessageString());
899 //Make a Python command
900 GEOM::TPythonDump(aFunction) << aCDG << " = geompy.MakeCDG(" << theShape << ")";
906 //=============================================================================
910 //=============================================================================
911 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetVertexByIndex
912 (Handle(GEOM_Object) theShape,
913 Standard_Integer theIndex)
917 if (theShape.IsNull()) return NULL;
919 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
920 if (aRefShape.IsNull()) return NULL;
922 //Add a new Vertex object
923 Handle(GEOM_Object) aVertex = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
926 Handle(GEOM_Function) aFunction =
927 aVertex->AddFunction(GEOMImpl_MeasureDriver::GetID(), VERTEX_BY_INDEX);
928 if (aFunction.IsNull()) return NULL;
930 //Check if the function is set correctly
931 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
933 GEOMImpl_IMeasure aCI (aFunction);
934 aCI.SetBase(aRefShape);
935 aCI.SetIndex(theIndex);
939 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
942 if (!GetSolver()->ComputeFunction(aFunction)) {
943 SetErrorCode("Vertex by index driver failed.");
947 catch (Standard_Failure) {
948 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
949 SetErrorCode(aFail->GetMessageString());
953 //Make a Python command
954 GEOM::TPythonDump(aFunction) << aVertex << " = geompy.GetVertexByIndex(" << theShape << ", " << theIndex << ")";
960 //=============================================================================
964 //=============================================================================
965 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetNormal
966 (Handle(GEOM_Object) theFace,
967 Handle(GEOM_Object) theOptionalPoint)
971 if (theFace.IsNull()) return NULL;
973 //Add a new Normale object
974 Handle(GEOM_Object) aNorm = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
976 //Add a new Normale function
977 Handle(GEOM_Function) aFunction =
978 aNorm->AddFunction(GEOMImpl_MeasureDriver::GetID(), VECTOR_FACE_NORMALE);
979 if (aFunction.IsNull()) return NULL;
981 //Check if the function is set correctly
982 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
984 GEOMImpl_IMeasure aCI (aFunction);
986 Handle(GEOM_Function) aFace = theFace->GetLastFunction();
987 if (aFace.IsNull()) return NULL;
991 if (!theOptionalPoint.IsNull()) {
992 Handle(GEOM_Function) anOptPnt = theOptionalPoint->GetLastFunction();
993 aCI.SetPoint(anOptPnt);
996 //Compute the Normale value
998 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1001 if (!GetSolver()->ComputeFunction(aFunction)) {
1002 SetErrorCode("Measure driver failed to compute normake of face");
1006 catch (Standard_Failure) {
1007 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1008 SetErrorCode(aFail->GetMessageString());
1012 //Make a Python command
1013 GEOM::TPythonDump pd (aFunction);
1014 pd << aNorm << " = geompy.GetNormal(" << theFace;
1015 if (!theOptionalPoint.IsNull()) {
1016 pd << ", " << theOptionalPoint;
1024 //=============================================================================
1026 * GetBasicProperties
1028 //=============================================================================
1029 void GEOMImpl_IMeasureOperations::GetBasicProperties (Handle(GEOM_Object) theShape,
1030 Standard_Real& theLength,
1031 Standard_Real& theSurfArea,
1032 Standard_Real& theVolume)
1036 if (theShape.IsNull()) return;
1038 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1039 if (aRefShape.IsNull()) return;
1041 TopoDS_Shape aShape = aRefShape->GetValue();
1042 if (aShape.IsNull()) {
1043 SetErrorCode("The Objects has NULL Shape");
1047 //Compute the parameters
1048 GProp_GProps LProps, SProps;
1050 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1053 BRepGProp::LinearProperties(aShape, LProps);
1054 theLength = LProps.Mass();
1056 BRepGProp::SurfaceProperties(aShape, SProps);
1057 theSurfArea = SProps.Mass();
1060 if (aShape.ShapeType() < TopAbs_SHELL) {
1061 for (TopExp_Explorer Exp (aShape, TopAbs_SOLID); Exp.More(); Exp.Next()) {
1062 GProp_GProps VProps;
1063 BRepGProp::VolumeProperties(Exp.Current(), VProps);
1064 theVolume += VProps.Mass();
1068 catch (Standard_Failure) {
1069 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1070 SetErrorCode(aFail->GetMessageString());
1077 //=============================================================================
1081 //=============================================================================
1082 void GEOMImpl_IMeasureOperations::GetInertia
1083 (Handle(GEOM_Object) theShape,
1084 Standard_Real& I11, Standard_Real& I12, Standard_Real& I13,
1085 Standard_Real& I21, Standard_Real& I22, Standard_Real& I23,
1086 Standard_Real& I31, Standard_Real& I32, Standard_Real& I33,
1087 Standard_Real& Ix , Standard_Real& Iy , Standard_Real& Iz)
1091 if (theShape.IsNull()) return;
1093 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1094 if (aRefShape.IsNull()) return;
1096 TopoDS_Shape aShape = aRefShape->GetValue();
1097 if (aShape.IsNull()) {
1098 SetErrorCode("The Objects has NULL Shape");
1102 //Compute the parameters
1103 GProp_GProps System;
1106 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1109 if (aShape.ShapeType() == TopAbs_VERTEX ||
1110 aShape.ShapeType() == TopAbs_EDGE ||
1111 aShape.ShapeType() == TopAbs_WIRE) {
1112 BRepGProp::LinearProperties(aShape, System);
1113 } else if (aShape.ShapeType() == TopAbs_FACE ||
1114 aShape.ShapeType() == TopAbs_SHELL) {
1115 BRepGProp::SurfaceProperties(aShape, System);
1117 BRepGProp::VolumeProperties(aShape, System);
1119 gp_Mat I = System.MatrixOfInertia();
1133 GProp_PrincipalProps Pr = System.PrincipalProperties();
1134 Pr.Moments(Ix,Iy,Iz);
1136 catch (Standard_Failure) {
1137 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1138 SetErrorCode(aFail->GetMessageString());
1145 //=============================================================================
1149 //=============================================================================
1150 void GEOMImpl_IMeasureOperations::GetBoundingBox
1151 (Handle(GEOM_Object) theShape,
1152 Standard_Real& Xmin, Standard_Real& Xmax,
1153 Standard_Real& Ymin, Standard_Real& Ymax,
1154 Standard_Real& Zmin, Standard_Real& Zmax)
1158 if (theShape.IsNull()) return;
1160 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1161 if (aRefShape.IsNull()) return;
1163 TopoDS_Shape aShape = aRefShape->GetValue();
1164 if (aShape.IsNull()) {
1165 SetErrorCode("The Objects has NULL Shape");
1169 //Compute the parameters
1173 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1176 BRepBndLib::Add(aShape, B);
1177 B.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
1179 catch (Standard_Failure) {
1180 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1181 SetErrorCode(aFail->GetMessageString());
1188 //=============================================================================
1192 //=============================================================================
1193 void GEOMImpl_IMeasureOperations::GetTolerance
1194 (Handle(GEOM_Object) theShape,
1195 Standard_Real& FaceMin, Standard_Real& FaceMax,
1196 Standard_Real& EdgeMin, Standard_Real& EdgeMax,
1197 Standard_Real& VertMin, Standard_Real& VertMax)
1201 if (theShape.IsNull()) return;
1203 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1204 if (aRefShape.IsNull()) return;
1206 TopoDS_Shape aShape = aRefShape->GetValue();
1207 if (aShape.IsNull()) {
1208 SetErrorCode("The Objects has NULL Shape");
1212 //Compute the parameters
1214 FaceMin = EdgeMin = VertMin = RealLast();
1215 FaceMax = EdgeMax = VertMax = -RealLast();
1218 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1221 for (TopExp_Explorer ExF (aShape, TopAbs_FACE); ExF.More(); ExF.Next()) {
1222 TopoDS_Face Face = TopoDS::Face(ExF.Current());
1223 T = BRep_Tool::Tolerance(Face);
1229 for (TopExp_Explorer ExE (aShape, TopAbs_EDGE); ExE.More(); ExE.Next()) {
1230 TopoDS_Edge Edge = TopoDS::Edge(ExE.Current());
1231 T = BRep_Tool::Tolerance(Edge);
1237 for (TopExp_Explorer ExV (aShape, TopAbs_VERTEX); ExV.More(); ExV.Next()) {
1238 TopoDS_Vertex Vertex = TopoDS::Vertex(ExV.Current());
1239 T = BRep_Tool::Tolerance(Vertex);
1246 catch (Standard_Failure) {
1247 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1248 SetErrorCode(aFail->GetMessageString());
1255 //=============================================================================
1259 //=============================================================================
1260 bool GEOMImpl_IMeasureOperations::CheckShape (Handle(GEOM_Object) theShape,
1261 const Standard_Boolean theIsCheckGeom,
1262 TCollection_AsciiString& theDump)
1266 if (theShape.IsNull()) return false;
1268 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1269 if (aRefShape.IsNull()) return false;
1271 TopoDS_Shape aShape = aRefShape->GetValue();
1272 if (aShape.IsNull()) {
1273 SetErrorCode("The Objects has NULL Shape");
1277 //Compute the parameters
1278 bool isValid = false;
1280 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1283 BRepCheck_Analyzer ana (aShape, theIsCheckGeom);
1284 if (ana.IsValid()) {
1288 StructuralDump(ana, aShape, theDump);
1291 catch (Standard_Failure) {
1292 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1293 SetErrorCode(aFail->GetMessageString());
1301 //=============================================================================
1305 //=============================================================================
1306 TCollection_AsciiString GEOMImpl_IMeasureOperations::WhatIs (Handle(GEOM_Object) theShape)
1310 TCollection_AsciiString Astr;
1312 if (theShape.IsNull()) return Astr;
1314 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1315 if (aRefShape.IsNull()) return Astr;
1317 TopoDS_Shape aShape = aRefShape->GetValue();
1318 if (aShape.IsNull()) {
1319 SetErrorCode("The Objects has NULL Shape");
1323 //Compute the parameters
1324 if (aShape.ShapeType() == TopAbs_EDGE) {
1325 if (BRep_Tool::Degenerated(TopoDS::Edge(aShape))) {
1326 Astr = Astr + " It is a degenerated edge \n";
1330 Astr = Astr + " Number of sub-shapes : \n";
1333 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1336 int iType, nbTypes [TopAbs_SHAPE];
1337 for (iType = 0; iType < TopAbs_SHAPE; ++iType)
1339 nbTypes[aShape.ShapeType()]++;
1341 TopTools_MapOfShape aMapOfShape;
1342 aMapOfShape.Add(aShape);
1343 TopTools_ListOfShape aListOfShape;
1344 aListOfShape.Append(aShape);
1346 TopTools_ListIteratorOfListOfShape itL (aListOfShape);
1347 for (; itL.More(); itL.Next()) {
1348 TopoDS_Iterator it (itL.Value());
1349 for (; it.More(); it.Next()) {
1350 TopoDS_Shape s = it.Value();
1351 if (aMapOfShape.Add(s)) {
1352 aListOfShape.Append(s);
1353 nbTypes[s.ShapeType()]++;
1358 Astr = Astr + " VERTEX : " + TCollection_AsciiString(nbTypes[TopAbs_VERTEX]) + "\n";
1359 Astr = Astr + " EDGE : " + TCollection_AsciiString(nbTypes[TopAbs_EDGE]) + "\n";
1360 Astr = Astr + " WIRE : " + TCollection_AsciiString(nbTypes[TopAbs_WIRE]) + "\n";
1361 Astr = Astr + " FACE : " + TCollection_AsciiString(nbTypes[TopAbs_FACE]) + "\n";
1362 Astr = Astr + " SHELL : " + TCollection_AsciiString(nbTypes[TopAbs_SHELL]) + "\n";
1363 Astr = Astr + " SOLID : " + TCollection_AsciiString(nbTypes[TopAbs_SOLID]) + "\n";
1364 Astr = Astr + " COMPSOLID : " + TCollection_AsciiString(nbTypes[TopAbs_COMPSOLID]) + "\n";
1365 Astr = Astr + " COMPOUND : " + TCollection_AsciiString(nbTypes[TopAbs_COMPOUND]) + "\n";
1366 Astr = Astr + " SHAPE : " + TCollection_AsciiString(aMapOfShape.Extent());
1368 catch (Standard_Failure) {
1369 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1370 SetErrorCode(aFail->GetMessageString());
1379 //=======================================================================
1380 //function : CheckSingularCase
1381 //purpose : auxilary for GetMinDistance()
1382 // workaround for bugs 19899, 19908 and 19910 from Mantis
1383 //=======================================================================
1384 static double CheckSingularCase(const TopoDS_Shape& aSh1,
1385 const TopoDS_Shape& aSh2,
1386 gp_Pnt& Ptmp1, gp_Pnt& Ptmp2)
1388 bool IsChange1 = false;
1389 double AddDist1 = 0.0;
1390 TopExp_Explorer anExp;
1391 TopoDS_Shape tmpSh1, tmpSh2;
1393 for ( anExp.Init( aSh1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1395 tmpSh1 = anExp.Current();
1398 TopoDS_Shape sh = aSh1;
1399 while(sh.ShapeType()==TopAbs_COMPOUND) {
1400 TopoDS_Iterator it(sh);
1403 Handle(Geom_Surface) S = BRep_Tool::Surface(TopoDS::Face(tmpSh1));
1404 if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1405 S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1406 if( sh.ShapeType()==TopAbs_SHELL || sh.ShapeType()==TopAbs_FACE ) {
1409 // changes for 0020677: EDF 1219 GEOM: MinDistance gives 0 instead of 20.88
1410 //S->Bounds(U1,U2,V1,V2); changed by
1411 ShapeAnalysis::GetFaceUVBounds(TopoDS::Face(tmpSh1),U1,U2,V1,V2);
1412 // end of changes for 020677 (dmv)
1413 Handle(Geom_RectangularTrimmedSurface) TrS1 =
1414 new Geom_RectangularTrimmedSurface(S,U1,(U1+U2)/2.,V1,V2);
1415 Handle(Geom_RectangularTrimmedSurface) TrS2 =
1416 new Geom_RectangularTrimmedSurface(S,(U1+U2)/2.,U2,V1,V2);
1419 TopoDS_Compound Comp;
1420 B.MakeCompound(Comp);
1421 B.MakeFace(F1,TrS1,1.e-7);
1423 B.MakeFace(F2,TrS2,1.e-7);
1425 Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
1427 sfs->SetPrecision(1.e-6);
1428 sfs->SetMaxTolerance(1.0);
1430 tmpSh1 = sfs->Shape();
1434 if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ) {
1435 Handle(Geom_SphericalSurface) SS = Handle(Geom_SphericalSurface)::DownCast(S);
1436 gp_Pnt PC = SS->Location();
1439 B.MakeVertex(V,PC,1.e-7);
1441 AddDist1 = SS->Radius();
1445 Handle(Geom_ToroidalSurface) TS = Handle(Geom_ToroidalSurface)::DownCast(S);
1446 gp_Ax3 ax3 = TS->Position();
1447 Handle(Geom_Circle) C = new Geom_Circle(ax3.Ax2(),TS->MajorRadius());
1450 B.MakeEdge(E,C,1.e-7);
1452 AddDist1 = TS->MinorRadius();
1462 bool IsChange2 = false;
1463 double AddDist2 = 0.0;
1465 for ( anExp.Init( aSh2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1467 tmpSh2 = anExp.Current();
1470 TopoDS_Shape sh = aSh2;
1471 while(sh.ShapeType()==TopAbs_COMPOUND) {
1472 TopoDS_Iterator it(sh);
1475 Handle(Geom_Surface) S = BRep_Tool::Surface(TopoDS::Face(tmpSh2));
1476 if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1477 S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1478 if( sh.ShapeType()==TopAbs_SHELL || sh.ShapeType()==TopAbs_FACE ) {
1481 S->Bounds(U1,U2,V1,V2);
1482 Handle(Geom_RectangularTrimmedSurface) TrS1 =
1483 new Geom_RectangularTrimmedSurface(S,U1,(U1+U2)/2.,V1,V2);
1484 Handle(Geom_RectangularTrimmedSurface) TrS2 =
1485 new Geom_RectangularTrimmedSurface(S,(U1+U2)/2.,U2,V1,V2);
1488 TopoDS_Compound Comp;
1489 B.MakeCompound(Comp);
1490 B.MakeFace(F1,TrS1,1.e-7);
1492 B.MakeFace(F2,TrS2,1.e-7);
1494 Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
1496 sfs->SetPrecision(1.e-6);
1497 sfs->SetMaxTolerance(1.0);
1499 tmpSh2 = sfs->Shape();
1503 if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ) {
1504 Handle(Geom_SphericalSurface) SS = Handle(Geom_SphericalSurface)::DownCast(S);
1505 gp_Pnt PC = SS->Location();
1508 B.MakeVertex(V,PC,1.e-7);
1510 AddDist2 = SS->Radius();
1513 else if( S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1514 Handle(Geom_ToroidalSurface) TS = Handle(Geom_ToroidalSurface)::DownCast(S);
1515 gp_Ax3 ax3 = TS->Position();
1516 Handle(Geom_Circle) C = new Geom_Circle(ax3.Ax2(),TS->MajorRadius());
1519 B.MakeEdge(E,C,1.e-7);
1521 AddDist2 = TS->MinorRadius();
1532 if( !IsChange1 && !IsChange2 )
1535 BRepExtrema_DistShapeShape dst(tmpSh1,tmpSh2);
1537 double MinDist = 1.e9;
1538 gp_Pnt PMin1, PMin2, P1, P2;
1539 for (int i = 1; i <= dst.NbSolution(); i++) {
1540 P1 = dst.PointOnShape1(i);
1541 P2 = dst.PointOnShape2(i);
1542 Standard_Real Dist = P1.Distance(P2);
1543 if (MinDist > Dist) {
1554 gp_Dir aDir(gp_Vec(PMin1,PMin2));
1555 if( MinDist > (AddDist1+AddDist2) ) {
1556 Ptmp1 = gp_Pnt( PMin1.X() + aDir.X()*AddDist1,
1557 PMin1.Y() + aDir.Y()*AddDist1,
1558 PMin1.Z() + aDir.Z()*AddDist1 );
1559 Ptmp2 = gp_Pnt( PMin2.X() - aDir.X()*AddDist2,
1560 PMin2.Y() - aDir.Y()*AddDist2,
1561 PMin2.Z() - aDir.Z()*AddDist2 );
1562 return (MinDist - AddDist1 - AddDist2);
1565 if( AddDist1 > 0 ) {
1566 Ptmp1 = gp_Pnt( PMin1.X() + aDir.X()*AddDist1,
1567 PMin1.Y() + aDir.Y()*AddDist1,
1568 PMin1.Z() + aDir.Z()*AddDist1 );
1572 Ptmp2 = gp_Pnt( PMin2.X() - aDir.X()*AddDist2,
1573 PMin2.Y() - aDir.Y()*AddDist2,
1574 PMin2.Z() - aDir.Z()*AddDist2 );
1579 double res = MinDist - AddDist1 - AddDist2;
1580 if(res<0.) res = 0.0;
1586 static bool CheckSingularCase(const TopoDS_Shape& aSh1,
1587 const TopoDS_Shape& aSh2,
1590 TopExp_Explorer anExp;
1591 TopoDS_Shape tmpSh1, tmpSh2;
1593 for ( anExp.Init( aSh1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1595 tmpSh1 = anExp.Current();
1598 Handle(Geom_Surface) S1 = BRep_Tool::Surface(TopoDS::Face(tmpSh1));
1599 if( S1->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1600 S1->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1602 for ( anExp.Init( aSh2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1604 tmpSh2 = anExp.Current();
1605 Handle(Geom_Surface) S2 = BRep_Tool::Surface(TopoDS::Face(tmpSh2));
1606 GeomAPI_IntSS ISS(S1,S2,1.e-7);
1608 for(int i=1; i<=ISS.NbLines(); i++) {
1609 Handle(Geom_Curve) C3d = ISS.Line(i);
1612 B.MakeEdge(E,C3d,1.e-7);
1613 BRepExtrema_DistShapeShape dst(tmpSh2,E);
1615 gp_Pnt PMin1, PMin2, P1, P2;
1616 double MinDist = 1.e9;
1617 for (int i = 1; i <= dst.NbSolution(); i++) {
1618 P1 = dst.PointOnShape1(i);
1619 P2 = dst.PointOnShape2(i);
1620 Standard_Real Dist = P1.Distance(P2);
1621 if (MinDist > Dist) {
1635 for ( anExp.Init( aSh2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1637 tmpSh1 = anExp.Current();
1640 Handle(Geom_Surface) S1 = BRep_Tool::Surface(TopoDS::Face(tmpSh1));
1641 if( S1->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1642 S1->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1644 for ( anExp.Init( aSh1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1646 tmpSh2 = anExp.Current();
1647 Handle(Geom_Surface) S2 = BRep_Tool::Surface(TopoDS::Face(tmpSh2));
1648 GeomAPI_IntSS ISS(S1,S2,1.e-7);
1650 for(int i=1; i<=ISS.NbLines(); i++) {
1651 Handle(Geom_Curve) C3d = ISS.Line(i);
1654 B.MakeEdge(E,C3d,1.e-7);
1655 BRepExtrema_DistShapeShape dst(tmpSh2,E);
1658 double MinDist = 1.e9;
1659 for (int i = 1; i <= dst.NbSolution(); i++) {
1660 P1 = dst.PointOnShape1(i);
1661 P2 = dst.PointOnShape2(i);
1662 Standard_Real Dist = P1.Distance(P2);
1663 if (MinDist > Dist) {
1681 //=============================================================================
1685 //=============================================================================
1686 Standard_Real GEOMImpl_IMeasureOperations::GetMinDistance
1687 (Handle(GEOM_Object) theShape1, Handle(GEOM_Object) theShape2,
1688 Standard_Real& X1, Standard_Real& Y1, Standard_Real& Z1,
1689 Standard_Real& X2, Standard_Real& Y2, Standard_Real& Z2)
1692 Standard_Real MinDist = 1.e9;
1694 if (theShape1.IsNull() || theShape2.IsNull()) return MinDist;
1696 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
1697 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
1698 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return MinDist;
1700 TopoDS_Shape aShape1 = aRefShape1->GetValue();
1701 TopoDS_Shape aShape2 = aRefShape2->GetValue();
1702 if (aShape1.IsNull() || aShape2.IsNull()) {
1703 SetErrorCode("One of Objects has NULL Shape");
1707 //Compute the parameters
1709 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1713 // Issue 0020231: A min distance bug with torus and vertex.
1714 // Make GetMinDistance() return zero if a sole VERTEX is inside any of SOLIDs
1716 // which of shapes consists of only one vertex?
1717 TopExp_Explorer exp1(aShape1,TopAbs_VERTEX), exp2(aShape2,TopAbs_VERTEX);
1718 TopoDS_Shape V1 = exp1.More() ? exp1.Current() : TopoDS_Shape();
1719 TopoDS_Shape V2 = exp2.More() ? exp2.Current() : TopoDS_Shape();
1720 exp1.Next(); exp2.Next();
1721 if ( exp1.More() ) V1.Nullify();
1722 if ( exp2.More() ) V2.Nullify();
1723 // vertex and container of solids
1724 TopoDS_Shape V = V1.IsNull() ? V2 : V1;
1725 TopoDS_Shape S = V1.IsNull() ? aShape1 : aShape2;
1726 if ( !V.IsNull() ) {
1727 // classify vertex against solids
1728 gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( V ) );
1729 for ( exp1.Init( S, TopAbs_SOLID ); exp1.More(); exp1.Next() ) {
1730 BRepClass3d_SolidClassifier classifier( exp1.Current(), p, 1e-6);
1731 if ( classifier.State() == TopAbs_IN ) {
1732 p.Coord(X1, Y1, Z1);
1733 p.Coord(X2, Y2, Z2);
1739 // End Issue 0020231
1742 // additional workaround for bugs 19899, 19908 and 19910 from Mantis
1743 gp_Pnt Ptmp1, Ptmp2;
1744 double dist = CheckSingularCase(aShape1, aShape2, Ptmp1, Ptmp2);
1746 Ptmp1.Coord(X1, Y1, Z1);
1747 Ptmp2.Coord(X2, Y2, Z2);
1752 BRepExtrema_DistShapeShape dst (aShape1, aShape2);
1754 gp_Pnt PMin1, PMin2, P1, P2;
1756 for (int i = 1; i <= dst.NbSolution(); i++) {
1757 P1 = dst.PointOnShape1(i);
1758 P2 = dst.PointOnShape2(i);
1760 Standard_Real Dist = P1.Distance(P2);
1761 if (MinDist > Dist) {
1768 PMin1.Coord(X1, Y1, Z1);
1769 PMin2.Coord(X2, Y2, Z2);
1772 catch (Standard_Failure) {
1773 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1774 SetErrorCode(aFail->GetMessageString());
1782 //=======================================================================
1784 * Get coordinates of point
1786 //=======================================================================
1787 void GEOMImpl_IMeasureOperations::PointCoordinates (Handle(GEOM_Object) theShape,
1788 Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ)
1792 if (theShape.IsNull())
1795 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1796 if (aRefShape.IsNull())
1799 TopoDS_Shape aShape = aRefShape->GetValue();
1800 if (aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX)
1802 SetErrorCode( "Shape must be a vertex" );
1807 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1810 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
1817 catch (Standard_Failure)
1819 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1820 SetErrorCode( aFail->GetMessageString() );
1824 //=======================================================================
1826 * Compute angle (in degrees) between two lines
1828 //=======================================================================
1829 Standard_Real GEOMImpl_IMeasureOperations::GetAngle (Handle(GEOM_Object) theLine1,
1830 Handle(GEOM_Object) theLine2)
1834 Standard_Real anAngle = -1.0;
1836 if (theLine1.IsNull() || theLine2.IsNull())
1839 Handle(GEOM_Function) aRefLine1 = theLine1->GetLastFunction();
1840 Handle(GEOM_Function) aRefLine2 = theLine2->GetLastFunction();
1841 if (aRefLine1.IsNull() || aRefLine2.IsNull())
1844 TopoDS_Shape aLine1 = aRefLine1->GetValue();
1845 TopoDS_Shape aLine2 = aRefLine2->GetValue();
1846 if (aLine1.IsNull() || aLine2.IsNull() ||
1847 aLine1.ShapeType() != TopAbs_EDGE ||
1848 aLine2.ShapeType() != TopAbs_EDGE)
1850 SetErrorCode("Two edges must be given");
1855 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1858 TopoDS_Edge E1 = TopoDS::Edge(aLine1);
1859 TopoDS_Edge E2 = TopoDS::Edge(aLine2);
1862 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp,lp);
1863 Handle(Geom_Curve) C2 = BRep_Tool::Curve(E2,fp,lp);
1865 if ( C1.IsNull() || C2.IsNull() ||
1866 !C1->IsKind(STANDARD_TYPE(Geom_Line)) ||
1867 !C2->IsKind(STANDARD_TYPE(Geom_Line)))
1869 SetErrorCode("The edges must be linear");
1873 Handle(Geom_Line) L1 = Handle(Geom_Line)::DownCast(C1);
1874 Handle(Geom_Line) L2 = Handle(Geom_Line)::DownCast(C2);
1876 gp_Lin aLin1 = L1->Lin();
1877 gp_Lin aLin2 = L2->Lin();
1879 anAngle = aLin1.Angle(aLin2);
1880 anAngle /= PI180; // convert radians into degrees
1884 catch (Standard_Failure)
1886 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1887 SetErrorCode(aFail->GetMessageString());
1894 //=============================================================================
1896 * CurveCurvatureByParam
1898 //=============================================================================
1899 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByParam
1900 (Handle(GEOM_Object) theCurve, Standard_Real& theParam)
1903 Standard_Real aRes = -1.0;
1905 if(theCurve.IsNull()) return aRes;
1907 Handle(GEOM_Function) aRefShape = theCurve->GetLastFunction();
1908 if(aRefShape.IsNull()) return aRes;
1910 TopoDS_Shape aShape = aRefShape->GetValue();
1911 if(aShape.IsNull()) {
1912 SetErrorCode("One of Objects has NULL Shape");
1916 Standard_Real aFP, aLP, aP;
1917 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aFP, aLP);
1918 aP = aFP + (aLP - aFP) * theParam;
1920 if(aCurve.IsNull()) return aRes;
1924 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1927 GeomLProp_CLProps Prop = GeomLProp_CLProps
1928 (aCurve, aP, 2, Precision::Confusion());
1929 aRes = fabs(Prop.Curvature());
1932 catch (Standard_Failure) {
1933 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1934 SetErrorCode(aFail->GetMessageString());
1938 if( aRes > Precision::Confusion() )
1947 //=============================================================================
1949 * CurveCurvatureByPoint
1951 //=============================================================================
1952 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByPoint
1953 (Handle(GEOM_Object) theCurve, Handle(GEOM_Object) thePoint)
1956 Standard_Real aRes = -1.0;
1958 if( theCurve.IsNull() || thePoint.IsNull() ) return aRes;
1960 Handle(GEOM_Function) aRefCurve = theCurve->GetLastFunction();
1961 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
1962 if( aRefCurve.IsNull() || aRefPoint.IsNull() ) return aRes;
1964 TopoDS_Edge anEdge = TopoDS::Edge(aRefCurve->GetValue());
1965 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
1966 if( anEdge.IsNull() || aPnt.IsNull() ) {
1967 SetErrorCode("One of Objects has NULL Shape");
1971 Standard_Real aFP, aLP;
1972 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFP, aLP);
1973 if(aCurve.IsNull()) return aRes;
1974 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
1978 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1981 GeomAPI_ProjectPointOnCurve PPC(aPoint, aCurve, aFP, aLP);
1982 if(PPC.NbPoints()>0) {
1983 GeomLProp_CLProps Prop = GeomLProp_CLProps
1984 (aCurve, PPC.LowerDistanceParameter(), 2, Precision::Confusion());
1985 aRes = fabs(Prop.Curvature());
1989 catch (Standard_Failure) {
1990 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1991 SetErrorCode(aFail->GetMessageString());
1995 if( aRes > Precision::Confusion() )
2004 //=============================================================================
2006 * getSurfaceCurvatures
2008 //=============================================================================
2009 Standard_Real GEOMImpl_IMeasureOperations::getSurfaceCurvatures
2010 (const Handle(Geom_Surface)& aSurf,
2011 Standard_Real theUParam,
2012 Standard_Real theVParam,
2013 Standard_Boolean theNeedMaxCurv)
2016 Standard_Real aRes = 1.0;
2018 if (aSurf.IsNull()) return aRes;
2021 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2024 GeomLProp_SLProps Prop = GeomLProp_SLProps
2025 (aSurf, theUParam, theVParam, 2, Precision::Confusion());
2026 if(Prop.IsCurvatureDefined()) {
2027 if(Prop.IsUmbilic()) {
2028 //cout<<"is umbilic"<<endl;
2029 aRes = fabs(Prop.MeanCurvature());
2032 //cout<<"is not umbilic"<<endl;
2033 double c1 = fabs(Prop.MaxCurvature());
2034 double c2 = fabs(Prop.MinCurvature());
2043 catch (Standard_Failure) {
2044 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2045 SetErrorCode(aFail->GetMessageString());
2049 if( fabs(aRes) > Precision::Confusion() )
2058 //=============================================================================
2060 * MaxSurfaceCurvatureByParam
2062 //=============================================================================
2063 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByParam
2064 (Handle(GEOM_Object) theSurf,
2065 Standard_Real& theUParam,
2066 Standard_Real& theVParam)
2069 Standard_Real aRes = -1.0;
2071 if (theSurf.IsNull()) return aRes;
2073 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2074 if(aRefShape.IsNull()) return aRes;
2076 TopoDS_Shape aShape = aRefShape->GetValue();
2077 if(aShape.IsNull()) {
2078 SetErrorCode("One of Objects has NULL Shape");
2082 TopoDS_Face F = TopoDS::Face(aShape);
2083 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2085 //Compute the parameters
2086 Standard_Real U1,U2,V1,V2;
2087 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2088 Standard_Real U = U1 + (U2-U1)*theUParam;
2089 Standard_Real V = V1 + (V2-V1)*theVParam;
2091 return getSurfaceCurvatures(aSurf, U, V, true);
2095 //=============================================================================
2097 * MaxSurfaceCurvatureByPoint
2099 //=============================================================================
2100 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByPoint
2101 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2104 Standard_Real aRes = -1.0;
2106 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2108 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2109 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2110 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2112 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2113 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2114 if( aFace.IsNull() || aPnt.IsNull() ) {
2115 SetErrorCode("One of Objects has NULL Shape");
2119 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2120 if(aSurf.IsNull()) return aRes;
2121 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2123 //Compute the parameters
2124 ShapeAnalysis_Surface sas(aSurf);
2125 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2127 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), true);
2131 //=============================================================================
2133 * MinSurfaceCurvatureByParam
2135 //=============================================================================
2136 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByParam
2137 (Handle(GEOM_Object) theSurf,
2138 Standard_Real& theUParam,
2139 Standard_Real& theVParam)
2142 Standard_Real aRes = -1.0;
2144 if (theSurf.IsNull()) return aRes;
2146 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2147 if(aRefShape.IsNull()) return aRes;
2149 TopoDS_Shape aShape = aRefShape->GetValue();
2150 if(aShape.IsNull()) {
2151 SetErrorCode("One of Objects has NULL Shape");
2155 TopoDS_Face F = TopoDS::Face(aShape);
2156 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2158 //Compute the parameters
2159 Standard_Real U1,U2,V1,V2;
2160 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2161 Standard_Real U = U1 + (U2-U1)*theUParam;
2162 Standard_Real V = V1 + (V2-V1)*theVParam;
2164 return getSurfaceCurvatures(aSurf, U, V, false);
2168 //=============================================================================
2170 * MinSurfaceCurvatureByPoint
2172 //=============================================================================
2173 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByPoint
2174 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2177 Standard_Real aRes = -1.0;
2179 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2181 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2182 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2183 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2185 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2186 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2187 if( aFace.IsNull() || aPnt.IsNull() ) {
2188 SetErrorCode("One of Objects has NULL Shape");
2192 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2193 if(aSurf.IsNull()) return aRes;
2194 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2196 //Compute the parameters
2197 ShapeAnalysis_Surface sas(aSurf);
2198 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2200 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), false);
2204 //=======================================================================
2205 //function : StructuralDump
2206 //purpose : Structural (data exchange) style of output.
2207 //=======================================================================
2208 void GEOMImpl_IMeasureOperations::StructuralDump (const BRepCheck_Analyzer& theAna,
2209 const TopoDS_Shape& theShape,
2210 TCollection_AsciiString& theDump)
2214 theDump += " -- The Shape has problems :\n";
2215 theDump += " Check Count\n";
2216 theDump += " ------------------------------------------------\n";
2218 Standard_Integer last_stat = (Standard_Integer)BRepCheck_CheckFail;
2219 Handle(TColStd_HArray1OfInteger) NbProblems =
2220 new TColStd_HArray1OfInteger(1, last_stat);
2221 for (i = 1; i <= last_stat; i++)
2222 NbProblems->SetValue(i,0);
2224 Handle(TopTools_HSequenceOfShape) sl;
2225 sl = new TopTools_HSequenceOfShape();
2226 TopTools_DataMapOfShapeListOfShape theMap;
2228 GetProblemShapes(theAna, theShape, sl, NbProblems, theMap);
2231 Standard_Integer count = 0;
2232 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnCurve);
2234 theDump += " Invalid Point on Curve ................... ";
2235 theDump += TCollection_AsciiString(count) + "\n";
2237 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnCurveOnSurface);
2239 theDump += " Invalid Point on CurveOnSurface .......... ";
2240 theDump += TCollection_AsciiString(count) + "\n";
2242 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnSurface);
2244 theDump += " Invalid Point on Surface ................. ";
2245 theDump += TCollection_AsciiString(count) + "\n";
2247 count = NbProblems->Value((Standard_Integer)BRepCheck_No3DCurve);
2249 theDump += " No 3D Curve .............................. ";
2250 theDump += TCollection_AsciiString(count) + "\n";
2252 count = NbProblems->Value((Standard_Integer)BRepCheck_Multiple3DCurve);
2254 theDump += " Multiple 3D Curve ........................ ";
2255 theDump += TCollection_AsciiString(count) + "\n";
2257 count = NbProblems->Value((Standard_Integer)BRepCheck_Invalid3DCurve);
2259 theDump += " Invalid 3D Curve ......................... ";
2260 theDump += TCollection_AsciiString(count) + "\n";
2262 count = NbProblems->Value((Standard_Integer)BRepCheck_NoCurveOnSurface);
2264 theDump += " No Curve on Surface ...................... ";
2265 theDump += TCollection_AsciiString(count) + "\n";
2267 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidCurveOnSurface);
2269 theDump += " Invalid Curve on Surface ................. ";
2270 theDump += TCollection_AsciiString(count) + "\n";
2272 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidCurveOnClosedSurface);
2274 theDump += " Invalid Curve on closed Surface .......... ";
2275 theDump += TCollection_AsciiString(count) + "\n";
2277 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidSameRangeFlag);
2279 theDump += " Invalid SameRange Flag ................... ";
2280 theDump += TCollection_AsciiString(count) + "\n";
2282 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidSameParameterFlag);
2284 theDump += " Invalid SameParameter Flag ............... ";
2285 theDump += TCollection_AsciiString(count) + "\n";
2287 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidDegeneratedFlag);
2289 theDump += " Invalid Degenerated Flag ................. ";
2290 theDump += TCollection_AsciiString(count) + "\n";
2292 count = NbProblems->Value((Standard_Integer)BRepCheck_FreeEdge);
2294 theDump += " Free Edge ................................ ";
2295 theDump += TCollection_AsciiString(count) + "\n";
2297 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidMultiConnexity);
2299 theDump += " Invalid MultiConnexity ................... ";
2300 theDump += TCollection_AsciiString(count) + "\n";
2302 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidRange);
2304 theDump += " Invalid Range ............................ ";
2305 theDump += TCollection_AsciiString(count) + "\n";
2307 count = NbProblems->Value((Standard_Integer)BRepCheck_EmptyWire);
2309 theDump += " Empty Wire ............................... ";
2310 theDump += TCollection_AsciiString(count) + "\n";
2312 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantEdge);
2314 theDump += " Redundant Edge ........................... ";
2315 theDump += TCollection_AsciiString(count) + "\n";
2317 count = NbProblems->Value((Standard_Integer)BRepCheck_SelfIntersectingWire);
2319 theDump += " Self Intersecting Wire ................... ";
2320 theDump += TCollection_AsciiString(count) + "\n";
2322 count = NbProblems->Value((Standard_Integer)BRepCheck_NoSurface);
2324 theDump += " No Surface ............................... ";
2325 theDump += TCollection_AsciiString(count) + "\n";
2327 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidWire);
2329 theDump += " Invalid Wire ............................. ";
2330 theDump += TCollection_AsciiString(count) + "\n";
2332 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantWire);
2334 theDump += " Redundant Wire ........................... ";
2335 theDump += TCollection_AsciiString(count) + "\n";
2337 count = NbProblems->Value((Standard_Integer)BRepCheck_IntersectingWires);
2339 theDump += " Intersecting Wires ....................... ";
2340 theDump += TCollection_AsciiString(count) + "\n";
2342 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidImbricationOfWires);
2344 theDump += " Invalid Imbrication of Wires ............. ";
2345 theDump += TCollection_AsciiString(count) + "\n";
2347 count = NbProblems->Value((Standard_Integer)BRepCheck_EmptyShell);
2349 theDump += " Empty Shell .............................. ";
2350 theDump += TCollection_AsciiString(count) + "\n";
2352 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantFace);
2354 theDump += " Redundant Face ........................... ";
2355 theDump += TCollection_AsciiString(count) + "\n";
2357 count = NbProblems->Value((Standard_Integer)BRepCheck_UnorientableShape);
2359 theDump += " Unorientable Shape ....................... ";
2360 theDump += TCollection_AsciiString(count) + "\n";
2362 count = NbProblems->Value((Standard_Integer)BRepCheck_NotClosed);
2364 theDump += " Not Closed ............................... ";
2365 theDump += TCollection_AsciiString(count) + "\n";
2367 count = NbProblems->Value((Standard_Integer)BRepCheck_NotConnected);
2369 theDump += " Not Connected ............................ ";
2370 theDump += TCollection_AsciiString(count) + "\n";
2372 count = NbProblems->Value((Standard_Integer)BRepCheck_SubshapeNotInShape);
2374 theDump += " Subshape not in Shape .................... ";
2375 theDump += TCollection_AsciiString(count) + "\n";
2377 count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientation);
2379 theDump += " Bad Orientation .......................... ";
2380 theDump += TCollection_AsciiString(count) + "\n";
2382 count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientationOfSubshape);
2384 theDump += " Bad Orientation of Subshape .............. ";
2385 theDump += TCollection_AsciiString(count) + "\n";
2387 count = NbProblems->Value((Standard_Integer)BRepCheck_CheckFail);
2389 theDump += " checkshape failure ....................... ";
2390 theDump += TCollection_AsciiString(count) + "\n";
2393 theDump += " ------------------------------------------------\n";
2394 theDump += "*** Shapes with problems : ";
2395 theDump += TCollection_AsciiString(sl->Length()) + "\n";
2397 Standard_Integer nbv, nbe, nbw, nbf, nbs, nbo;
2398 nbv = nbe = nbw = nbf = nbs = nbo = 0;
2400 for (i = 1; i <= sl->Length(); i++) {
2401 TopoDS_Shape shi = sl->Value(i);
2402 TopAbs_ShapeEnum sti = shi.ShapeType();
2404 case TopAbs_VERTEX : nbv++; break;
2405 case TopAbs_EDGE : nbe++; break;
2406 case TopAbs_WIRE : nbw++; break;
2407 case TopAbs_FACE : nbf++; break;
2408 case TopAbs_SHELL : nbs++; break;
2409 case TopAbs_SOLID : nbo++; break;
2415 theDump += "VERTEX : ";
2416 if (nbv < 10) theDump += " ";
2417 theDump += TCollection_AsciiString(nbv) + "\n";
2420 theDump += "EDGE : ";
2421 if (nbe < 10) theDump += " ";
2422 theDump += TCollection_AsciiString(nbe) + "\n";
2425 theDump += "WIRE : ";
2426 if (nbw < 10) theDump += " ";
2427 theDump += TCollection_AsciiString(nbw) + "\n";
2430 theDump += "FACE : ";
2431 if (nbf < 10) theDump += " ";
2432 theDump += TCollection_AsciiString(nbf) + "\n";
2435 theDump += "SHELL : ";
2436 if (nbs < 10) theDump += " ";
2437 theDump += TCollection_AsciiString(nbs) + "\n";
2440 theDump += "SOLID : ";
2441 if (nbo < 10) theDump += " ";
2442 theDump += TCollection_AsciiString(nbo) + "\n";
2447 //=======================================================================
2448 //function : GetProblemShapes
2449 // purpose : for StructuralDump
2450 //=======================================================================
2451 void GEOMImpl_IMeasureOperations::GetProblemShapes (const BRepCheck_Analyzer& theAna,
2452 const TopoDS_Shape& theShape,
2453 Handle(TopTools_HSequenceOfShape)& sl,
2454 Handle(TColStd_HArray1OfInteger)& NbProblems,
2455 TopTools_DataMapOfShapeListOfShape& theMap)
2457 for (TopoDS_Iterator iter(theShape); iter.More(); iter.Next()) {
2458 GetProblemShapes(theAna, iter.Value(), sl, NbProblems, theMap);
2460 TopAbs_ShapeEnum styp = theShape.ShapeType();
2461 BRepCheck_ListIteratorOfListOfStatus itl;
2462 TopTools_ListOfShape empty;
2463 if (!theMap.IsBound(theShape)) {
2464 theMap.Bind(theShape,empty);
2466 if (!theAna.Result(theShape).IsNull()) {
2467 itl.Initialize(theAna.Result(theShape)->Status());
2468 // !!! May be, we have to print all the problems, not only the first one ?
2469 if (itl.Value() != BRepCheck_NoError) {
2470 sl->Append(theShape);
2471 BRepCheck_Status stat = itl.Value();
2472 NbProblems->SetValue((Standard_Integer)stat,
2473 NbProblems->Value((Standard_Integer)stat) + 1);
2480 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_VERTEX, theMap);
2483 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_WIRE, theMap);
2484 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_EDGE, theMap);
2485 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_VERTEX, theMap);
2490 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_SHELL, theMap);
2497 //=======================================================================
2498 //function : Contains
2499 //=======================================================================
2500 static Standard_Boolean Contains (const TopTools_ListOfShape& L,
2501 const TopoDS_Shape& S)
2503 TopTools_ListIteratorOfListOfShape it;
2504 for (it.Initialize(L); it.More(); it.Next()) {
2505 if (it.Value().IsSame(S)) {
2506 return Standard_True;
2509 return Standard_False;
2512 //=======================================================================
2513 //function : GetProblemSub
2514 // purpose : for StructuralDump
2515 //=======================================================================
2516 void GEOMImpl_IMeasureOperations::GetProblemSub (const BRepCheck_Analyzer& theAna,
2517 const TopoDS_Shape& theShape,
2518 Handle(TopTools_HSequenceOfShape)& sl,
2519 Handle(TColStd_HArray1OfInteger)& NbProblems,
2520 const TopAbs_ShapeEnum Subtype,
2521 TopTools_DataMapOfShapeListOfShape& theMap)
2523 BRepCheck_ListIteratorOfListOfStatus itl;
2524 TopExp_Explorer exp;
2525 for (exp.Init(theShape, Subtype); exp.More(); exp.Next()) {
2526 const TopoDS_Shape& sub = exp.Current();
2528 const Handle(BRepCheck_Result)& res = theAna.Result(sub);
2529 for (res->InitContextIterator();
2530 res->MoreShapeInContext();
2531 res->NextShapeInContext()) {
2532 if (res->ContextualShape().IsSame(theShape) && !Contains(theMap(sub), theShape)) {
2533 theMap(sub).Append(theShape);
2534 itl.Initialize(res->StatusOnShape());
2536 if (itl.Value() != BRepCheck_NoError) {
2537 Standard_Integer ii = 0;
2539 for (ii = 1; ii <= sl->Length(); ii++)
2540 if (sl->Value(ii).IsSame(sub)) break;
2542 if (ii > sl->Length()) {
2544 BRepCheck_Status stat = itl.Value();
2545 NbProblems->SetValue((Standard_Integer)stat,
2546 NbProblems->Value((Standard_Integer)stat) + 1);
2548 for (ii = 1; ii <= sl->Length(); ii++)
2549 if (sl->Value(ii).IsSame(theShape)) break;
2550 if (ii > sl->Length()) {
2551 sl->Append(theShape);
2552 BRepCheck_Status stat = itl.Value();
2553 NbProblems->SetValue((Standard_Integer)stat,
2554 NbProblems->Value((Standard_Integer)stat) + 1);