1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include <Standard_Stream.hxx>
23 #include <GEOMImpl_IMeasureOperations.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOMImpl_MeasureDriver.hxx>
27 #include <GEOMImpl_IMeasure.hxx>
29 #include <GEOMAlgo_ShapeInfo.hxx>
30 #include <GEOMAlgo_ShapeInfoFiller.hxx>
32 #include <GEOM_Function.hxx>
33 #include <GEOM_PythonDump.hxx>
35 #include <utilities.h>
37 #include <Utils_ExceptHandlers.hxx>
40 #include <TFunction_DriverTable.hxx>
41 #include <TFunction_Driver.hxx>
42 #include <TFunction_Logbook.hxx>
43 #include <TDF_Tool.hxx>
45 #include <BRep_Tool.hxx>
46 #include <BRepAdaptor_Surface.hxx>
47 #include <BRepBndLib.hxx>
48 #include <BRepCheck.hxx>
49 #include <BRepCheck_Result.hxx>
50 #include <BRepCheck_ListIteratorOfListOfStatus.hxx>
51 #include <BRepExtrema_DistShapeShape.hxx>
52 #include <BRepGProp.hxx>
53 #include <BRepTools.hxx>
55 #include <Bnd_Box.hxx>
57 #include <GProp_GProps.hxx>
58 #include <GProp_PrincipalProps.hxx>
62 #include <TopoDS_Edge.hxx>
63 #include <TopoDS_Face.hxx>
64 #include <TopoDS_Shape.hxx>
65 #include <TopoDS_Vertex.hxx>
66 #include <TopoDS_Iterator.hxx>
67 #include <TopExp_Explorer.hxx>
68 #include <TopTools_MapOfShape.hxx>
69 #include <TopTools_ListOfShape.hxx>
70 #include <TopTools_ListIteratorOfListOfShape.hxx>
72 #include <GeomAbs_SurfaceType.hxx>
73 #include <Geom_Surface.hxx>
74 #include <Geom_Plane.hxx>
75 #include <Geom_SphericalSurface.hxx>
76 #include <Geom_CylindricalSurface.hxx>
77 #include <Geom_ToroidalSurface.hxx>
78 #include <Geom_ConicalSurface.hxx>
79 #include <Geom_SurfaceOfLinearExtrusion.hxx>
80 #include <Geom_SurfaceOfRevolution.hxx>
81 #include <Geom_BezierSurface.hxx>
82 #include <Geom_BSplineSurface.hxx>
83 #include <Geom_RectangularTrimmedSurface.hxx>
84 #include <Geom_OffsetSurface.hxx>
85 #include <Geom_Line.hxx>
90 #include <GeomAPI_ProjectPointOnCurve.hxx>
91 #include <ShapeAnalysis.hxx>
92 #include <ShapeAnalysis_Surface.hxx>
93 #include <GeomLProp_CLProps.hxx>
94 #include <GeomLProp_SLProps.hxx>
96 #include <Standard_Failure.hxx>
97 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
99 //=============================================================================
103 //=============================================================================
104 GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations (GEOM_Engine* theEngine, int theDocID)
105 : GEOM_IOperations(theEngine, theDocID)
107 MESSAGE("GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations");
110 //=============================================================================
114 //=============================================================================
115 GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations()
117 MESSAGE("GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations");
120 //=============================================================================
121 /*! Get kind and parameters of the given shape.
123 //=============================================================================
124 GEOMImpl_IMeasureOperations::ShapeKind GEOMImpl_IMeasureOperations::KindOfShape
125 (Handle(GEOM_Object) theShape,
126 Handle(TColStd_HSequenceOfInteger)& theIntegers,
127 Handle(TColStd_HSequenceOfReal)& theDoubles)
130 ShapeKind aKind = SK_NO_SHAPE;
132 if (theIntegers.IsNull()) theIntegers = new TColStd_HSequenceOfInteger;
133 else theIntegers->Clear();
135 if (theDoubles.IsNull()) theDoubles = new TColStd_HSequenceOfReal;
136 else theDoubles->Clear();
138 if (theShape.IsNull())
141 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
142 if (aRefShape.IsNull()) return aKind;
144 TopoDS_Shape aShape = aRefShape->GetValue();
145 if (aShape.IsNull()) return aKind;
148 GEOMAlgo_ShapeInfoFiller aSF;
149 aSF.SetShape(aShape);
151 Standard_Integer iErr = aSF.ErrorStatus();
153 SetErrorCode("Error in GEOMAlgo_ShapeInfoFiller");
156 const GEOMAlgo_ShapeInfo& anInfo = aSF.Info();
158 // Interprete results
159 TopAbs_ShapeEnum aType = anInfo.Type();
162 case TopAbs_COMPOUND:
163 case TopAbs_COMPSOLID:
165 // (+) geompy.kind.COMPOUND nb_solids nb_faces nb_edges nb_vertices
166 // (+) geompy.kind.COMPSOLID nb_solids nb_faces nb_edges nb_vertices
167 // ??? "nb_faces" - all faces or only 'standalone' faces?
168 if (aType == TopAbs_COMPOUND)
171 aKind = SK_COMPSOLID;
173 //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPOUND));
174 //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPSOLID));
175 theIntegers->Append(anInfo.NbSubShapes(TopAbs_SOLID));
176 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
177 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
178 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
184 // (+) geompy.kind.SHELL geompy.info.closed nb_faces nb_edges nb_vertices
185 // (+) geompy.kind.SHELL geompy.info.unclosed nb_faces nb_edges nb_vertices
188 theIntegers->Append((int)anInfo.KindOfClosed());
190 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
191 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
192 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
198 // (+) geompy.kind.WIRE geompy.info.closed nb_edges nb_vertices
199 // (+) geompy.kind.WIRE geompy.info.unclosed nb_edges nb_vertices
202 theIntegers->Append((int)anInfo.KindOfClosed());
204 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
205 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
213 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
216 case GEOMAlgo_KN_SPHERE:
217 // (+) geompy.kind.SPHERE xc yc zc R
221 gp_Pnt aC = anInfo.Location();
222 theDoubles->Append(aC.X());
223 theDoubles->Append(aC.Y());
224 theDoubles->Append(aC.Z());
226 theDoubles->Append(anInfo.Radius1());
229 case GEOMAlgo_KN_CYLINDER:
230 // (+) geompy.kind.CYLINDER xb yb zb dx dy dz R H
234 gp_Pnt aC = anInfo.Location();
235 theDoubles->Append(aC.X());
236 theDoubles->Append(aC.Y());
237 theDoubles->Append(aC.Z());
239 gp_Ax3 anAx3 = anInfo.Position();
240 gp_Dir aD = anAx3.Direction();
241 theDoubles->Append(aD.X());
242 theDoubles->Append(aD.Y());
243 theDoubles->Append(aD.Z());
245 theDoubles->Append(anInfo.Radius1());
246 theDoubles->Append(anInfo.Height());
249 case GEOMAlgo_KN_BOX:
250 // (+) geompy.kind.BOX xc yc zc ax ay az
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 gp_Dir aX = anAx3.XDirection();
264 if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
265 aX.IsParallel(gp::DX(), Precision::Angular())) {
266 theDoubles->Append(anInfo.Length()); // ax'
267 theDoubles->Append(anInfo.Width()); // ay'
268 theDoubles->Append(anInfo.Height()); // az'
270 else if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
271 aX.IsParallel(gp::DY(), Precision::Angular())) {
272 theDoubles->Append(anInfo.Width()); // ay'
273 theDoubles->Append(anInfo.Length()); // ax'
274 theDoubles->Append(anInfo.Height()); // az'
276 else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
277 aX.IsParallel(gp::DZ(), Precision::Angular())) {
278 theDoubles->Append(anInfo.Height()); // az'
279 theDoubles->Append(anInfo.Width()); // ay'
280 theDoubles->Append(anInfo.Length()); // ax'
282 else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
283 aX.IsParallel(gp::DY(), Precision::Angular())) {
284 theDoubles->Append(anInfo.Height()); // az'
285 theDoubles->Append(anInfo.Length()); // ax'
286 theDoubles->Append(anInfo.Width()); // ay'
288 else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
289 aX.IsParallel(gp::DZ(), Precision::Angular())) {
290 theDoubles->Append(anInfo.Width()); // ay'
291 theDoubles->Append(anInfo.Height()); // az'
292 theDoubles->Append(anInfo.Length()); // ax'
294 else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
295 aX.IsParallel(gp::DX(), Precision::Angular())) {
296 theDoubles->Append(anInfo.Length()); // ax'
297 theDoubles->Append(anInfo.Height()); // az'
298 theDoubles->Append(anInfo.Width()); // ay'
301 // (+) geompy.kind.ROTATED_BOX xo yo zo zx zy zz xx xy xz ax ay az
302 aKind = SK_ROTATED_BOX;
304 // Direction and XDirection
305 theDoubles->Append(aD.X());
306 theDoubles->Append(aD.Y());
307 theDoubles->Append(aD.Z());
309 theDoubles->Append(aX.X());
310 theDoubles->Append(aX.Y());
311 theDoubles->Append(aX.Z());
314 theDoubles->Append(anInfo.Length());
315 theDoubles->Append(anInfo.Width());
316 theDoubles->Append(anInfo.Height());
320 case GEOMAlgo_KN_TORUS:
321 // (+) geompy.kind.TORUS xc yc zc dx dy dz R_1 R_2
325 gp_Pnt aO = anInfo.Location();
326 theDoubles->Append(aO.X());
327 theDoubles->Append(aO.Y());
328 theDoubles->Append(aO.Z());
330 gp_Ax3 anAx3 = anInfo.Position();
331 gp_Dir aD = anAx3.Direction();
332 theDoubles->Append(aD.X());
333 theDoubles->Append(aD.Y());
334 theDoubles->Append(aD.Z());
336 theDoubles->Append(anInfo.Radius1());
337 theDoubles->Append(anInfo.Radius2());
340 case GEOMAlgo_KN_CONE:
341 // (+) geompy.kind.CONE xb yb zb dx dy dz R_1 R_2 H
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());
358 theDoubles->Append(anInfo.Height());
361 case GEOMAlgo_KN_POLYHEDRON:
362 // (+) geompy.kind.POLYHEDRON nb_faces nb_edges nb_vertices
364 aKind = SK_POLYHEDRON;
366 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
367 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
368 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
372 // (+) geompy.kind.SOLID nb_faces nb_edges nb_vertices
374 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
375 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
376 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
386 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
388 case GEOMAlgo_KN_SPHERE:
389 // (+) geompy.kind.SPHERE2D xc yc zc R
393 gp_Pnt aC = anInfo.Location();
394 theDoubles->Append(aC.X());
395 theDoubles->Append(aC.Y());
396 theDoubles->Append(aC.Z());
398 theDoubles->Append(anInfo.Radius1());
401 case GEOMAlgo_KN_CYLINDER:
402 // (+) geompy.kind.CYLINDER2D xb yb zb dx dy dz R H
404 aKind = SK_CYLINDER2D;
406 gp_Pnt aO = anInfo.Location();
407 theDoubles->Append(aO.X());
408 theDoubles->Append(aO.Y());
409 theDoubles->Append(aO.Z());
411 gp_Ax3 anAx3 = anInfo.Position();
412 gp_Dir aD = anAx3.Direction();
413 theDoubles->Append(aD.X());
414 theDoubles->Append(aD.Y());
415 theDoubles->Append(aD.Z());
417 theDoubles->Append(anInfo.Radius1());
418 theDoubles->Append(anInfo.Height());
421 case GEOMAlgo_KN_TORUS:
422 // (+) geompy.kind.TORUS2D xc yc zc dx dy dz R_1 R_2
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.Radius2());
441 case GEOMAlgo_KN_CONE:
442 // (+) geompy.kind.CONE2D xc yc zc dx dy dz R_1 R_2 H
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());
459 theDoubles->Append(anInfo.Height());
462 case GEOMAlgo_KN_DISKCIRCLE:
463 // (+) geompy.kind.DISK_CIRCLE xc yc zc dx dy dz R
465 aKind = SK_DISK_CIRCLE;
467 gp_Pnt aC = anInfo.Location();
468 theDoubles->Append(aC.X());
469 theDoubles->Append(aC.Y());
470 theDoubles->Append(aC.Z());
472 gp_Ax3 anAx3 = anInfo.Position();
473 gp_Dir aD = anAx3.Direction();
474 theDoubles->Append(aD.X());
475 theDoubles->Append(aD.Y());
476 theDoubles->Append(aD.Z());
478 theDoubles->Append(anInfo.Radius1());
481 case GEOMAlgo_KN_DISKELLIPSE:
482 // (+) geompy.kind.DISK_ELLIPSE xc yc zc dx dy dz R_1 R_2
484 aKind = SK_DISK_ELLIPSE;
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());
498 theDoubles->Append(anInfo.Radius2());
501 case GEOMAlgo_KN_RECTANGLE:
502 case GEOMAlgo_KN_TRIANGLE:
503 case GEOMAlgo_KN_QUADRANGLE:
504 case GEOMAlgo_KN_POLYGON:
505 // (+) geompy.kind.POLYGON xo yo zo dx dy dz nb_edges nb_vertices
509 gp_Pnt aO = anInfo.Location();
510 theDoubles->Append(aO.X());
511 theDoubles->Append(aO.Y());
512 theDoubles->Append(aO.Z());
514 gp_Ax3 anAx3 = anInfo.Position();
515 gp_Dir aD = anAx3.Direction();
516 theDoubles->Append(aD.X());
517 theDoubles->Append(aD.Y());
518 theDoubles->Append(aD.Z());
520 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
521 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
524 case GEOMAlgo_KN_PLANE: // infinite
525 // (+) geompy.kind.PLANE xo yo zo dx dy dz
529 gp_Pnt aC = anInfo.Location();
530 theDoubles->Append(aC.X());
531 theDoubles->Append(aC.Y());
532 theDoubles->Append(aC.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());
542 if (anInfo.KindOfShape() == GEOMAlgo_KS_PLANE) {
543 // (+) geompy.kind.PLANAR xo yo zo dx dy dz nb_edges nb_vertices
547 gp_Pnt aC = anInfo.Location();
548 theDoubles->Append(aC.X());
549 theDoubles->Append(aC.Y());
550 theDoubles->Append(aC.Z());
552 gp_Ax3 anAx3 = anInfo.Position();
553 gp_Dir aD = anAx3.Direction();
554 theDoubles->Append(aD.X());
555 theDoubles->Append(aD.Y());
556 theDoubles->Append(aD.Z());
558 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
559 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
562 // ??? geompy.kind.FACE nb_edges nb_vertices _surface_type_id_
563 // (+) geompy.kind.FACE nb_edges nb_vertices
565 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
566 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
576 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
578 case GEOMAlgo_KN_CIRCLE:
580 // (+) geompy.kind.CIRCLE xc yc zc dx dy dz R
583 gp_Pnt aC = anInfo.Location();
584 theDoubles->Append(aC.X());
585 theDoubles->Append(aC.Y());
586 theDoubles->Append(aC.Z());
588 gp_Ax3 anAx3 = anInfo.Position();
589 gp_Dir aD = anAx3.Direction();
590 theDoubles->Append(aD.X());
591 theDoubles->Append(aD.Y());
592 theDoubles->Append(aD.Z());
594 theDoubles->Append(anInfo.Radius1());
597 case GEOMAlgo_KN_ARCCIRCLE:
599 // (+) geompy.kind.ARC_CIRCLE xc yc zc dx dy dz R x1 y1 z1 x2 y2 z2
600 aKind = SK_ARC_CIRCLE;
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());
615 gp_Pnt aP1 = anInfo.Pnt1();
616 theDoubles->Append(aP1.X());
617 theDoubles->Append(aP1.Y());
618 theDoubles->Append(aP1.Z());
620 gp_Pnt aP2 = anInfo.Pnt2();
621 theDoubles->Append(aP2.X());
622 theDoubles->Append(aP2.Y());
623 theDoubles->Append(aP2.Z());
626 case GEOMAlgo_KN_ELLIPSE:
628 // (+) geompy.kind.ELLIPSE xc yc zc dx dy dz R_1 R_2
631 gp_Pnt aC = anInfo.Location();
632 theDoubles->Append(aC.X());
633 theDoubles->Append(aC.Y());
634 theDoubles->Append(aC.Z());
636 gp_Ax3 anAx3 = anInfo.Position();
637 gp_Dir aD = anAx3.Direction();
638 theDoubles->Append(aD.X());
639 theDoubles->Append(aD.Y());
640 theDoubles->Append(aD.Z());
642 theDoubles->Append(anInfo.Radius1());
643 theDoubles->Append(anInfo.Radius2());
646 case GEOMAlgo_KN_ARCELLIPSE:
648 // (+) geompy.kind.ARC_ELLIPSE xc yc zc dx dy dz R_1 R_2 x1 y1 z1 x2 y2 z2
649 aKind = SK_ARC_ELLIPSE;
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());
665 gp_Pnt aP1 = anInfo.Pnt1();
666 theDoubles->Append(aP1.X());
667 theDoubles->Append(aP1.Y());
668 theDoubles->Append(aP1.Z());
670 gp_Pnt aP2 = anInfo.Pnt2();
671 theDoubles->Append(aP2.X());
672 theDoubles->Append(aP2.Y());
673 theDoubles->Append(aP2.Z());
676 case GEOMAlgo_KN_LINE:
678 // ??? geompy.kind.LINE x1 y1 z1 x2 y2 z2
679 // (+) geompy.kind.LINE x1 y1 z1 dx dy dz
682 gp_Pnt aO = anInfo.Location();
683 theDoubles->Append(aO.X());
684 theDoubles->Append(aO.Y());
685 theDoubles->Append(aO.Z());
687 gp_Dir aD = anInfo.Direction();
688 theDoubles->Append(aD.X());
689 theDoubles->Append(aD.Y());
690 theDoubles->Append(aD.Z());
693 case GEOMAlgo_KN_SEGMENT:
695 // (+) geompy.kind.SEGMENT x1 y1 z1 x2 y2 z2
698 gp_Pnt aP1 = anInfo.Pnt1();
699 theDoubles->Append(aP1.X());
700 theDoubles->Append(aP1.Y());
701 theDoubles->Append(aP1.Z());
703 gp_Pnt aP2 = anInfo.Pnt2();
704 theDoubles->Append(aP2.X());
705 theDoubles->Append(aP2.Y());
706 theDoubles->Append(aP2.Z());
710 // ??? geompy.kind.EDGE nb_vertices _curve_type_id_
711 // (+) geompy.kind.EDGE nb_vertices
712 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
719 // (+) geompy.kind.VERTEX x y z
722 gp_Pnt aP = anInfo.Location();
723 theDoubles->Append(aP.X());
724 theDoubles->Append(aP.Y());
725 theDoubles->Append(aP.Z());
734 //=============================================================================
735 /*! Get LCS, corresponding to the given shape.
736 * Origin of the LCS is situated at the shape's center of mass.
737 * Axes of the LCS are obtained from shape's location or,
738 * if the shape is a planar face, from position of its plane.
740 //=============================================================================
741 gp_Ax3 GEOMImpl_IMeasureOperations::GetPosition (const TopoDS_Shape& theShape)
745 if (theShape.IsNull())
749 aResult.Transform(theShape.Location().Transformation());
750 if (theShape.ShapeType() == TopAbs_FACE) {
751 Handle(Geom_Surface) aGS = BRep_Tool::Surface(TopoDS::Face(theShape));
752 if (!aGS.IsNull() && aGS->IsKind(STANDARD_TYPE(Geom_Plane))) {
753 Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast(aGS);
754 gp_Pln aPln = aGPlane->Pln();
755 aResult = aPln.Position();
761 if (theShape.ShapeType() == TopAbs_VERTEX) {
762 aPnt = BRep_Tool::Pnt(TopoDS::Vertex(theShape));
765 GProp_GProps aSystem;
766 if (theShape.ShapeType() == TopAbs_EDGE || theShape.ShapeType() == TopAbs_WIRE)
767 BRepGProp::LinearProperties(theShape, aSystem);
768 else if (theShape.ShapeType() == TopAbs_FACE || theShape.ShapeType() == TopAbs_SHELL)
769 BRepGProp::SurfaceProperties(theShape, aSystem);
771 BRepGProp::VolumeProperties(theShape, aSystem);
773 aPnt = aSystem.CentreOfMass();
776 aResult.SetLocation(aPnt);
781 //=============================================================================
785 //=============================================================================
786 void GEOMImpl_IMeasureOperations::GetPosition
787 (Handle(GEOM_Object) theShape,
788 Standard_Real& Ox, Standard_Real& Oy, Standard_Real& Oz,
789 Standard_Real& Zx, Standard_Real& Zy, Standard_Real& Zz,
790 Standard_Real& Xx, Standard_Real& Xy, Standard_Real& Xz)
794 //Set default values: global CS
795 Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
798 if (theShape.IsNull()) return;
800 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
801 if (aRefShape.IsNull()) return;
803 TopoDS_Shape aShape = aRefShape->GetValue();
804 if (aShape.IsNull()) {
805 SetErrorCode("The Objects has NULL Shape");
810 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
814 gp_Ax3 anAx3 = GetPosition(aShape);
816 gp_Pnt anOri = anAx3.Location();
817 gp_Dir aDirZ = anAx3.Direction();
818 gp_Dir aDirX = anAx3.XDirection();
821 anOri.Coord(Ox, Oy, Oz);
822 aDirZ.Coord(Zx, Zy, Zz);
823 aDirX.Coord(Xx, Xy, Xz);
825 catch (Standard_Failure) {
826 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
827 SetErrorCode(aFail->GetMessageString());
834 //=============================================================================
838 //=============================================================================
839 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetCentreOfMass
840 (Handle(GEOM_Object) theShape)
844 if (theShape.IsNull()) return NULL;
846 //Add a new CentreOfMass object
847 Handle(GEOM_Object) aCDG = GetEngine()->AddObject(GetDocID(), GEOM_CDG);
849 //Add a new CentreOfMass function
850 Handle(GEOM_Function) aFunction =
851 aCDG->AddFunction(GEOMImpl_MeasureDriver::GetID(), CDG_MEASURE);
852 if (aFunction.IsNull()) return NULL;
854 //Check if the function is set correctly
855 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
857 GEOMImpl_IMeasure aCI (aFunction);
859 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
860 if (aRefShape.IsNull()) return NULL;
862 aCI.SetBase(aRefShape);
864 //Compute the CentreOfMass value
866 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
869 if (!GetSolver()->ComputeFunction(aFunction)) {
870 SetErrorCode("Measure driver failed to compute centre of mass");
874 catch (Standard_Failure) {
875 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
876 SetErrorCode(aFail->GetMessageString());
880 //Make a Python command
881 GEOM::TPythonDump(aFunction) << aCDG << " = geompy.MakeCDG(" << theShape << ")";
887 //=============================================================================
891 //=============================================================================
892 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetNormal
893 (Handle(GEOM_Object) theFace,
894 Handle(GEOM_Object) theOptionalPoint)
898 if (theFace.IsNull()) return NULL;
900 //Add a new Normale object
901 Handle(GEOM_Object) aNorm = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
903 //Add a new Normale function
904 Handle(GEOM_Function) aFunction =
905 aNorm->AddFunction(GEOMImpl_MeasureDriver::GetID(), VECTOR_FACE_NORMALE);
906 if (aFunction.IsNull()) return NULL;
908 //Check if the function is set correctly
909 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
911 GEOMImpl_IMeasure aCI (aFunction);
913 Handle(GEOM_Function) aFace = theFace->GetLastFunction();
914 if (aFace.IsNull()) return NULL;
918 if (!theOptionalPoint.IsNull()) {
919 Handle(GEOM_Function) anOptPnt = theOptionalPoint->GetLastFunction();
920 aCI.SetPoint(anOptPnt);
923 //Compute the Normale value
925 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
928 if (!GetSolver()->ComputeFunction(aFunction)) {
929 SetErrorCode("Measure driver failed to compute normake of face");
933 catch (Standard_Failure) {
934 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
935 SetErrorCode(aFail->GetMessageString());
939 //Make a Python command
940 GEOM::TPythonDump pd (aFunction);
941 pd << aNorm << " = geompy.GetNormal(" << theFace;
942 if (!theOptionalPoint.IsNull()) {
943 pd << ", " << theOptionalPoint;
951 //=============================================================================
955 //=============================================================================
956 void GEOMImpl_IMeasureOperations::GetBasicProperties (Handle(GEOM_Object) theShape,
957 Standard_Real& theLength,
958 Standard_Real& theSurfArea,
959 Standard_Real& theVolume)
963 if (theShape.IsNull()) return;
965 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
966 if (aRefShape.IsNull()) return;
968 TopoDS_Shape aShape = aRefShape->GetValue();
969 if (aShape.IsNull()) {
970 SetErrorCode("The Objects has NULL Shape");
974 //Compute the parameters
975 GProp_GProps LProps, SProps;
977 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
980 BRepGProp::LinearProperties(aShape, LProps);
981 theLength = LProps.Mass();
983 BRepGProp::SurfaceProperties(aShape, SProps);
984 theSurfArea = SProps.Mass();
987 if (aShape.ShapeType() < TopAbs_SHELL) {
988 for (TopExp_Explorer Exp (aShape, TopAbs_SOLID); Exp.More(); Exp.Next()) {
990 BRepGProp::VolumeProperties(Exp.Current(), VProps);
991 theVolume += VProps.Mass();
995 catch (Standard_Failure) {
996 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
997 SetErrorCode(aFail->GetMessageString());
1004 //=============================================================================
1008 //=============================================================================
1009 void GEOMImpl_IMeasureOperations::GetInertia
1010 (Handle(GEOM_Object) theShape,
1011 Standard_Real& I11, Standard_Real& I12, Standard_Real& I13,
1012 Standard_Real& I21, Standard_Real& I22, Standard_Real& I23,
1013 Standard_Real& I31, Standard_Real& I32, Standard_Real& I33,
1014 Standard_Real& Ix , Standard_Real& Iy , Standard_Real& Iz)
1018 if (theShape.IsNull()) return;
1020 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1021 if (aRefShape.IsNull()) return;
1023 TopoDS_Shape aShape = aRefShape->GetValue();
1024 if (aShape.IsNull()) {
1025 SetErrorCode("The Objects has NULL Shape");
1029 //Compute the parameters
1030 GProp_GProps System;
1033 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1036 if (aShape.ShapeType() == TopAbs_VERTEX ||
1037 aShape.ShapeType() == TopAbs_EDGE ||
1038 aShape.ShapeType() == TopAbs_WIRE) {
1039 BRepGProp::LinearProperties(aShape, System);
1040 } else if (aShape.ShapeType() == TopAbs_FACE ||
1041 aShape.ShapeType() == TopAbs_SHELL) {
1042 BRepGProp::SurfaceProperties(aShape, System);
1044 BRepGProp::VolumeProperties(aShape, System);
1046 gp_Mat I = System.MatrixOfInertia();
1060 GProp_PrincipalProps Pr = System.PrincipalProperties();
1061 Pr.Moments(Ix,Iy,Iz);
1063 catch (Standard_Failure) {
1064 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1065 SetErrorCode(aFail->GetMessageString());
1072 //=============================================================================
1076 //=============================================================================
1077 void GEOMImpl_IMeasureOperations::GetBoundingBox
1078 (Handle(GEOM_Object) theShape,
1079 Standard_Real& Xmin, Standard_Real& Xmax,
1080 Standard_Real& Ymin, Standard_Real& Ymax,
1081 Standard_Real& Zmin, Standard_Real& Zmax)
1085 if (theShape.IsNull()) return;
1087 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1088 if (aRefShape.IsNull()) return;
1090 TopoDS_Shape aShape = aRefShape->GetValue();
1091 if (aShape.IsNull()) {
1092 SetErrorCode("The Objects has NULL Shape");
1096 //Compute the parameters
1100 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1103 BRepBndLib::Add(aShape, B);
1104 B.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
1106 catch (Standard_Failure) {
1107 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1108 SetErrorCode(aFail->GetMessageString());
1115 //=============================================================================
1119 //=============================================================================
1120 void GEOMImpl_IMeasureOperations::GetTolerance
1121 (Handle(GEOM_Object) theShape,
1122 Standard_Real& FaceMin, Standard_Real& FaceMax,
1123 Standard_Real& EdgeMin, Standard_Real& EdgeMax,
1124 Standard_Real& VertMin, Standard_Real& VertMax)
1128 if (theShape.IsNull()) return;
1130 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1131 if (aRefShape.IsNull()) return;
1133 TopoDS_Shape aShape = aRefShape->GetValue();
1134 if (aShape.IsNull()) {
1135 SetErrorCode("The Objects has NULL Shape");
1139 //Compute the parameters
1141 FaceMin = EdgeMin = VertMin = RealLast();
1142 FaceMax = EdgeMax = VertMax = -RealLast();
1145 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1148 for (TopExp_Explorer ExF (aShape, TopAbs_FACE); ExF.More(); ExF.Next()) {
1149 TopoDS_Face Face = TopoDS::Face(ExF.Current());
1150 T = BRep_Tool::Tolerance(Face);
1156 for (TopExp_Explorer ExE (aShape, TopAbs_EDGE); ExE.More(); ExE.Next()) {
1157 TopoDS_Edge Edge = TopoDS::Edge(ExE.Current());
1158 T = BRep_Tool::Tolerance(Edge);
1164 for (TopExp_Explorer ExV (aShape, TopAbs_VERTEX); ExV.More(); ExV.Next()) {
1165 TopoDS_Vertex Vertex = TopoDS::Vertex(ExV.Current());
1166 T = BRep_Tool::Tolerance(Vertex);
1173 catch (Standard_Failure) {
1174 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1175 SetErrorCode(aFail->GetMessageString());
1182 //=============================================================================
1186 //=============================================================================
1187 bool GEOMImpl_IMeasureOperations::CheckShape (Handle(GEOM_Object) theShape,
1188 const Standard_Boolean theIsCheckGeom,
1189 TCollection_AsciiString& theDump)
1193 if (theShape.IsNull()) return false;
1195 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1196 if (aRefShape.IsNull()) return false;
1198 TopoDS_Shape aShape = aRefShape->GetValue();
1199 if (aShape.IsNull()) {
1200 SetErrorCode("The Objects has NULL Shape");
1204 //Compute the parameters
1205 bool isValid = false;
1207 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1210 BRepCheck_Analyzer ana (aShape, theIsCheckGeom);
1211 if (ana.IsValid()) {
1215 StructuralDump(ana, aShape, theDump);
1218 catch (Standard_Failure) {
1219 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1220 SetErrorCode(aFail->GetMessageString());
1228 //=============================================================================
1232 //=============================================================================
1233 TCollection_AsciiString GEOMImpl_IMeasureOperations::WhatIs (Handle(GEOM_Object) theShape)
1237 TCollection_AsciiString Astr;
1239 if (theShape.IsNull()) return Astr;
1241 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1242 if (aRefShape.IsNull()) return Astr;
1244 TopoDS_Shape aShape = aRefShape->GetValue();
1245 if (aShape.IsNull()) {
1246 SetErrorCode("The Objects has NULL Shape");
1250 //Compute the parameters
1251 if (aShape.ShapeType() == TopAbs_EDGE) {
1252 if (BRep_Tool::Degenerated(TopoDS::Edge(aShape))) {
1253 Astr = Astr + " It is a degenerated edge \n";
1257 Astr = Astr + " Number of sub-shapes : \n";
1260 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1263 int iType, nbTypes [TopAbs_SHAPE];
1264 for (iType = 0; iType < TopAbs_SHAPE; ++iType)
1266 nbTypes[aShape.ShapeType()]++;
1268 TopTools_MapOfShape aMapOfShape;
1269 aMapOfShape.Add(aShape);
1270 TopTools_ListOfShape aListOfShape;
1271 aListOfShape.Append(aShape);
1273 TopTools_ListIteratorOfListOfShape itL (aListOfShape);
1274 for (; itL.More(); itL.Next()) {
1275 TopoDS_Iterator it (itL.Value());
1276 for (; it.More(); it.Next()) {
1277 TopoDS_Shape s = it.Value();
1278 if (aMapOfShape.Add(s)) {
1279 aListOfShape.Append(s);
1280 nbTypes[s.ShapeType()]++;
1285 Astr = Astr + " VERTEX : " + TCollection_AsciiString(nbTypes[TopAbs_VERTEX]) + "\n";
1286 Astr = Astr + " EDGE : " + TCollection_AsciiString(nbTypes[TopAbs_EDGE]) + "\n";
1287 Astr = Astr + " WIRE : " + TCollection_AsciiString(nbTypes[TopAbs_WIRE]) + "\n";
1288 Astr = Astr + " FACE : " + TCollection_AsciiString(nbTypes[TopAbs_FACE]) + "\n";
1289 Astr = Astr + " SHELL : " + TCollection_AsciiString(nbTypes[TopAbs_SHELL]) + "\n";
1290 Astr = Astr + " SOLID : " + TCollection_AsciiString(nbTypes[TopAbs_SOLID]) + "\n";
1291 Astr = Astr + " COMPSOLID : " + TCollection_AsciiString(nbTypes[TopAbs_COMPSOLID]) + "\n";
1292 Astr = Astr + " COMPOUND : " + TCollection_AsciiString(nbTypes[TopAbs_COMPOUND]) + "\n";
1293 Astr = Astr + " SHAPE : " + TCollection_AsciiString(aMapOfShape.Extent());
1295 catch (Standard_Failure) {
1296 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1297 SetErrorCode(aFail->GetMessageString());
1305 //=============================================================================
1309 //=============================================================================
1310 Standard_Real GEOMImpl_IMeasureOperations::GetMinDistance
1311 (Handle(GEOM_Object) theShape1, Handle(GEOM_Object) theShape2,
1312 Standard_Real& X1, Standard_Real& Y1, Standard_Real& Z1,
1313 Standard_Real& X2, Standard_Real& Y2, Standard_Real& Z2)
1316 Standard_Real MinDist = 1.e9;
1318 if (theShape1.IsNull() || theShape2.IsNull()) return MinDist;
1320 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
1321 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
1322 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return MinDist;
1324 TopoDS_Shape aShape1 = aRefShape1->GetValue();
1325 TopoDS_Shape aShape2 = aRefShape2->GetValue();
1326 if (aShape1.IsNull() || aShape2.IsNull()) {
1327 SetErrorCode("One of Objects has NULL Shape");
1331 //Compute the parameters
1333 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1336 BRepExtrema_DistShapeShape dst (aShape1, aShape2);
1338 gp_Pnt PMin1, PMin2, P1, P2;
1340 for (int i = 1; i <= dst.NbSolution(); i++) {
1341 P1 = dst.PointOnShape1(i);
1342 P2 = dst.PointOnShape2(i);
1344 Standard_Real Dist = P1.Distance(P2);
1345 if (MinDist > Dist) {
1352 PMin1.Coord(X1, Y1, Z1);
1353 PMin2.Coord(X2, Y2, Z2);
1356 catch (Standard_Failure) {
1357 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1358 SetErrorCode(aFail->GetMessageString());
1366 //=======================================================================
1368 * Get coordinates of point
1370 //=======================================================================
1371 void GEOMImpl_IMeasureOperations::PointCoordinates (Handle(GEOM_Object) theShape,
1372 Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ)
1376 if (theShape.IsNull())
1379 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1380 if (aRefShape.IsNull())
1383 TopoDS_Shape aShape = aRefShape->GetValue();
1384 if (aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX)
1386 SetErrorCode( "Shape must be a vertex" );
1391 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1394 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
1401 catch (Standard_Failure)
1403 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1404 SetErrorCode( aFail->GetMessageString() );
1408 //=======================================================================
1410 * Compute angle (in degrees) between two lines
1412 //=======================================================================
1413 Standard_Real GEOMImpl_IMeasureOperations::GetAngle (Handle(GEOM_Object) theLine1,
1414 Handle(GEOM_Object) theLine2)
1418 Standard_Real anAngle = -1.0;
1420 if (theLine1.IsNull() || theLine2.IsNull())
1423 Handle(GEOM_Function) aRefLine1 = theLine1->GetLastFunction();
1424 Handle(GEOM_Function) aRefLine2 = theLine2->GetLastFunction();
1425 if (aRefLine1.IsNull() || aRefLine2.IsNull())
1428 TopoDS_Shape aLine1 = aRefLine1->GetValue();
1429 TopoDS_Shape aLine2 = aRefLine2->GetValue();
1430 if (aLine1.IsNull() || aLine2.IsNull() ||
1431 aLine1.ShapeType() != TopAbs_EDGE ||
1432 aLine2.ShapeType() != TopAbs_EDGE)
1434 SetErrorCode("Two edges must be given");
1439 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1442 TopoDS_Edge E1 = TopoDS::Edge(aLine1);
1443 TopoDS_Edge E2 = TopoDS::Edge(aLine2);
1446 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp,lp);
1447 Handle(Geom_Curve) C2 = BRep_Tool::Curve(E2,fp,lp);
1449 if (!C1->IsKind(STANDARD_TYPE(Geom_Line)) ||
1450 !C2->IsKind(STANDARD_TYPE(Geom_Line)))
1452 SetErrorCode("The edges must be linear");
1456 Handle(Geom_Line) L1 = Handle(Geom_Line)::DownCast(C1);
1457 Handle(Geom_Line) L2 = Handle(Geom_Line)::DownCast(C2);
1459 gp_Lin aLin1 = L1->Lin();
1460 gp_Lin aLin2 = L2->Lin();
1462 anAngle = aLin1.Angle(aLin2);
1463 anAngle /= PI180; // convert radians into degrees
1467 catch (Standard_Failure)
1469 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1470 SetErrorCode(aFail->GetMessageString());
1477 //=============================================================================
1479 * CurveCurvatureByParam
1481 //=============================================================================
1482 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByParam
1483 (Handle(GEOM_Object) theCurve, Standard_Real& theParam)
1486 Standard_Real aRes = -1.0;
1488 if(theCurve.IsNull()) return aRes;
1490 Handle(GEOM_Function) aRefShape = theCurve->GetLastFunction();
1491 if(aRefShape.IsNull()) return aRes;
1493 TopoDS_Shape aShape = aRefShape->GetValue();
1494 if(aShape.IsNull()) {
1495 SetErrorCode("One of Objects has NULL Shape");
1499 Standard_Real aFP, aLP, aP;
1500 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aFP, aLP);
1501 aP = aFP + (aLP - aFP) * theParam;
1503 if(aCurve.IsNull()) return aRes;
1507 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1510 GeomLProp_CLProps Prop = GeomLProp_CLProps
1511 (aCurve, aP, 2, Precision::Confusion());
1512 aRes = fabs(Prop.Curvature());
1515 catch (Standard_Failure) {
1516 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1517 SetErrorCode(aFail->GetMessageString());
1521 if( aRes > Precision::Confusion() )
1530 //=============================================================================
1532 * CurveCurvatureByPoint
1534 //=============================================================================
1535 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByPoint
1536 (Handle(GEOM_Object) theCurve, Handle(GEOM_Object) thePoint)
1539 Standard_Real aRes = -1.0;
1541 if( theCurve.IsNull() || thePoint.IsNull() ) return aRes;
1543 Handle(GEOM_Function) aRefCurve = theCurve->GetLastFunction();
1544 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
1545 if( aRefCurve.IsNull() || aRefPoint.IsNull() ) return aRes;
1547 TopoDS_Edge anEdge = TopoDS::Edge(aRefCurve->GetValue());
1548 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
1549 if( anEdge.IsNull() || aPnt.IsNull() ) {
1550 SetErrorCode("One of Objects has NULL Shape");
1554 Standard_Real aFP, aLP;
1555 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFP, aLP);
1556 if(aCurve.IsNull()) return aRes;
1557 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
1561 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1564 GeomAPI_ProjectPointOnCurve PPC(aPoint, aCurve, aFP, aLP);
1565 if(PPC.NbPoints()>0) {
1566 GeomLProp_CLProps Prop = GeomLProp_CLProps
1567 (aCurve, PPC.LowerDistanceParameter(), 2, Precision::Confusion());
1568 aRes = fabs(Prop.Curvature());
1572 catch (Standard_Failure) {
1573 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1574 SetErrorCode(aFail->GetMessageString());
1578 if( aRes > Precision::Confusion() )
1587 //=============================================================================
1589 * getSurfaceCurvatures
1591 //=============================================================================
1592 Standard_Real GEOMImpl_IMeasureOperations::getSurfaceCurvatures
1593 (const Handle(Geom_Surface)& aSurf,
1594 Standard_Real theUParam,
1595 Standard_Real theVParam,
1596 Standard_Boolean theNeedMaxCurv)
1599 Standard_Real aRes = 1.0;
1601 if (aSurf.IsNull()) return aRes;
1604 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1607 GeomLProp_SLProps Prop = GeomLProp_SLProps
1608 (aSurf, theUParam, theVParam, 2, Precision::Confusion());
1609 if(Prop.IsCurvatureDefined()) {
1610 if(Prop.IsUmbilic()) {
1611 //cout<<"is umbilic"<<endl;
1612 aRes = fabs(Prop.MeanCurvature());
1615 //cout<<"is not umbilic"<<endl;
1616 double c1 = fabs(Prop.MaxCurvature());
1617 double c2 = fabs(Prop.MinCurvature());
1626 catch (Standard_Failure) {
1627 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1628 SetErrorCode(aFail->GetMessageString());
1632 if( fabs(aRes) > Precision::Confusion() )
1641 //=============================================================================
1643 * MaxSurfaceCurvatureByParam
1645 //=============================================================================
1646 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByParam
1647 (Handle(GEOM_Object) theSurf,
1648 Standard_Real& theUParam,
1649 Standard_Real& theVParam)
1652 Standard_Real aRes = -1.0;
1654 if (theSurf.IsNull()) return aRes;
1656 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
1657 if(aRefShape.IsNull()) return aRes;
1659 TopoDS_Shape aShape = aRefShape->GetValue();
1660 if(aShape.IsNull()) {
1661 SetErrorCode("One of Objects has NULL Shape");
1665 TopoDS_Face F = TopoDS::Face(aShape);
1666 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
1668 //Compute the parameters
1669 Standard_Real U1,U2,V1,V2;
1670 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
1671 Standard_Real U = U1 + (U2-U1)*theUParam;
1672 Standard_Real V = V1 + (V2-V1)*theVParam;
1674 return getSurfaceCurvatures(aSurf, U, V, true);
1678 //=============================================================================
1680 * MaxSurfaceCurvatureByPoint
1682 //=============================================================================
1683 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByPoint
1684 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
1687 Standard_Real aRes = -1.0;
1689 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
1691 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
1692 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
1693 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
1695 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
1696 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
1697 if( aFace.IsNull() || aPnt.IsNull() ) {
1698 SetErrorCode("One of Objects has NULL Shape");
1702 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
1703 if(aSurf.IsNull()) return aRes;
1704 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
1706 //Compute the parameters
1707 ShapeAnalysis_Surface sas(aSurf);
1708 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
1710 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), true);
1714 //=============================================================================
1716 * MinSurfaceCurvatureByParam
1718 //=============================================================================
1719 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByParam
1720 (Handle(GEOM_Object) theSurf,
1721 Standard_Real& theUParam,
1722 Standard_Real& theVParam)
1725 Standard_Real aRes = -1.0;
1727 if (theSurf.IsNull()) return aRes;
1729 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
1730 if(aRefShape.IsNull()) return aRes;
1732 TopoDS_Shape aShape = aRefShape->GetValue();
1733 if(aShape.IsNull()) {
1734 SetErrorCode("One of Objects has NULL Shape");
1738 TopoDS_Face F = TopoDS::Face(aShape);
1739 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
1741 //Compute the parameters
1742 Standard_Real U1,U2,V1,V2;
1743 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
1744 Standard_Real U = U1 + (U2-U1)*theUParam;
1745 Standard_Real V = V1 + (V2-V1)*theVParam;
1747 return getSurfaceCurvatures(aSurf, U, V, false);
1751 //=============================================================================
1753 * MinSurfaceCurvatureByPoint
1755 //=============================================================================
1756 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByPoint
1757 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
1760 Standard_Real aRes = -1.0;
1762 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
1764 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
1765 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
1766 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
1768 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
1769 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
1770 if( aFace.IsNull() || aPnt.IsNull() ) {
1771 SetErrorCode("One of Objects has NULL Shape");
1775 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
1776 if(aSurf.IsNull()) return aRes;
1777 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
1779 //Compute the parameters
1780 ShapeAnalysis_Surface sas(aSurf);
1781 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
1783 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), false);
1787 //=======================================================================
1788 //function : StructuralDump
1789 //purpose : Structural (data exchange) style of output.
1790 //=======================================================================
1791 void GEOMImpl_IMeasureOperations::StructuralDump (const BRepCheck_Analyzer& theAna,
1792 const TopoDS_Shape& theShape,
1793 TCollection_AsciiString& theDump)
1797 theDump += " -- The Shape has problems :\n";
1798 theDump += " Check Count\n";
1799 theDump += " ------------------------------------------------\n";
1801 Standard_Integer last_stat = (Standard_Integer)BRepCheck_CheckFail;
1802 Handle(TColStd_HArray1OfInteger) NbProblems =
1803 new TColStd_HArray1OfInteger(1, last_stat);
1804 for (i = 1; i <= last_stat; i++)
1805 NbProblems->SetValue(i,0);
1807 Handle(TopTools_HSequenceOfShape) sl;
1808 sl = new TopTools_HSequenceOfShape();
1809 TopTools_DataMapOfShapeListOfShape theMap;
1811 GetProblemShapes(theAna, theShape, sl, NbProblems, theMap);
1814 Standard_Integer count = 0;
1815 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnCurve);
1817 theDump += " Invalid Point on Curve ................... ";
1818 theDump += TCollection_AsciiString(count) + "\n";
1820 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnCurveOnSurface);
1822 theDump += " Invalid Point on CurveOnSurface .......... ";
1823 theDump += TCollection_AsciiString(count) + "\n";
1825 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnSurface);
1827 theDump += " Invalid Point on Surface ................. ";
1828 theDump += TCollection_AsciiString(count) + "\n";
1830 count = NbProblems->Value((Standard_Integer)BRepCheck_No3DCurve);
1832 theDump += " No 3D Curve .............................. ";
1833 theDump += TCollection_AsciiString(count) + "\n";
1835 count = NbProblems->Value((Standard_Integer)BRepCheck_Multiple3DCurve);
1837 theDump += " Multiple 3D Curve ........................ ";
1838 theDump += TCollection_AsciiString(count) + "\n";
1840 count = NbProblems->Value((Standard_Integer)BRepCheck_Invalid3DCurve);
1842 theDump += " Invalid 3D Curve ......................... ";
1843 theDump += TCollection_AsciiString(count) + "\n";
1845 count = NbProblems->Value((Standard_Integer)BRepCheck_NoCurveOnSurface);
1847 theDump += " No Curve on Surface ...................... ";
1848 theDump += TCollection_AsciiString(count) + "\n";
1850 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidCurveOnSurface);
1852 theDump += " Invalid Curve on Surface ................. ";
1853 theDump += TCollection_AsciiString(count) + "\n";
1855 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidCurveOnClosedSurface);
1857 theDump += " Invalid Curve on closed Surface .......... ";
1858 theDump += TCollection_AsciiString(count) + "\n";
1860 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidSameRangeFlag);
1862 theDump += " Invalid SameRange Flag ................... ";
1863 theDump += TCollection_AsciiString(count) + "\n";
1865 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidSameParameterFlag);
1867 theDump += " Invalid SameParameter Flag ............... ";
1868 theDump += TCollection_AsciiString(count) + "\n";
1870 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidDegeneratedFlag);
1872 theDump += " Invalid Degenerated Flag ................. ";
1873 theDump += TCollection_AsciiString(count) + "\n";
1875 count = NbProblems->Value((Standard_Integer)BRepCheck_FreeEdge);
1877 theDump += " Free Edge ................................ ";
1878 theDump += TCollection_AsciiString(count) + "\n";
1880 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidMultiConnexity);
1882 theDump += " Invalid MultiConnexity ................... ";
1883 theDump += TCollection_AsciiString(count) + "\n";
1885 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidRange);
1887 theDump += " Invalid Range ............................ ";
1888 theDump += TCollection_AsciiString(count) + "\n";
1890 count = NbProblems->Value((Standard_Integer)BRepCheck_EmptyWire);
1892 theDump += " Empty Wire ............................... ";
1893 theDump += TCollection_AsciiString(count) + "\n";
1895 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantEdge);
1897 theDump += " Redundant Edge ........................... ";
1898 theDump += TCollection_AsciiString(count) + "\n";
1900 count = NbProblems->Value((Standard_Integer)BRepCheck_SelfIntersectingWire);
1902 theDump += " Self Intersecting Wire ................... ";
1903 theDump += TCollection_AsciiString(count) + "\n";
1905 count = NbProblems->Value((Standard_Integer)BRepCheck_NoSurface);
1907 theDump += " No Surface ............................... ";
1908 theDump += TCollection_AsciiString(count) + "\n";
1910 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidWire);
1912 theDump += " Invalid Wire ............................. ";
1913 theDump += TCollection_AsciiString(count) + "\n";
1915 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantWire);
1917 theDump += " Redundant Wire ........................... ";
1918 theDump += TCollection_AsciiString(count) + "\n";
1920 count = NbProblems->Value((Standard_Integer)BRepCheck_IntersectingWires);
1922 theDump += " Intersecting Wires ....................... ";
1923 theDump += TCollection_AsciiString(count) + "\n";
1925 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidImbricationOfWires);
1927 theDump += " Invalid Imbrication of Wires ............. ";
1928 theDump += TCollection_AsciiString(count) + "\n";
1930 count = NbProblems->Value((Standard_Integer)BRepCheck_EmptyShell);
1932 theDump += " Empty Shell .............................. ";
1933 theDump += TCollection_AsciiString(count) + "\n";
1935 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantFace);
1937 theDump += " Redundant Face ........................... ";
1938 theDump += TCollection_AsciiString(count) + "\n";
1940 count = NbProblems->Value((Standard_Integer)BRepCheck_UnorientableShape);
1942 theDump += " Unorientable Shape ....................... ";
1943 theDump += TCollection_AsciiString(count) + "\n";
1945 count = NbProblems->Value((Standard_Integer)BRepCheck_NotClosed);
1947 theDump += " Not Closed ............................... ";
1948 theDump += TCollection_AsciiString(count) + "\n";
1950 count = NbProblems->Value((Standard_Integer)BRepCheck_NotConnected);
1952 theDump += " Not Connected ............................ ";
1953 theDump += TCollection_AsciiString(count) + "\n";
1955 count = NbProblems->Value((Standard_Integer)BRepCheck_SubshapeNotInShape);
1957 theDump += " Subshape not in Shape .................... ";
1958 theDump += TCollection_AsciiString(count) + "\n";
1960 count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientation);
1962 theDump += " Bad Orientation .......................... ";
1963 theDump += TCollection_AsciiString(count) + "\n";
1965 count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientationOfSubshape);
1967 theDump += " Bad Orientation of Subshape .............. ";
1968 theDump += TCollection_AsciiString(count) + "\n";
1970 count = NbProblems->Value((Standard_Integer)BRepCheck_CheckFail);
1972 theDump += " checkshape failure ....................... ";
1973 theDump += TCollection_AsciiString(count) + "\n";
1976 theDump += " ------------------------------------------------\n";
1977 theDump += "*** Shapes with problems : ";
1978 theDump += TCollection_AsciiString(sl->Length()) + "\n";
1980 Standard_Integer nbv, nbe, nbw, nbf, nbs, nbo;
1981 nbv = nbe = nbw = nbf = nbs = nbo = 0;
1983 for (i = 1; i <= sl->Length(); i++) {
1984 TopoDS_Shape shi = sl->Value(i);
1985 TopAbs_ShapeEnum sti = shi.ShapeType();
1987 case TopAbs_VERTEX : nbv++; break;
1988 case TopAbs_EDGE : nbe++; break;
1989 case TopAbs_WIRE : nbw++; break;
1990 case TopAbs_FACE : nbf++; break;
1991 case TopAbs_SHELL : nbs++; break;
1992 case TopAbs_SOLID : nbo++; break;
1998 theDump += "VERTEX : ";
1999 if (nbv < 10) theDump += " ";
2000 theDump += TCollection_AsciiString(nbv) + "\n";
2003 theDump += "EDGE : ";
2004 if (nbe < 10) theDump += " ";
2005 theDump += TCollection_AsciiString(nbe) + "\n";
2008 theDump += "WIRE : ";
2009 if (nbw < 10) theDump += " ";
2010 theDump += TCollection_AsciiString(nbw) + "\n";
2013 theDump += "FACE : ";
2014 if (nbf < 10) theDump += " ";
2015 theDump += TCollection_AsciiString(nbf) + "\n";
2018 theDump += "SHELL : ";
2019 if (nbs < 10) theDump += " ";
2020 theDump += TCollection_AsciiString(nbs) + "\n";
2023 theDump += "SOLID : ";
2024 if (nbo < 10) theDump += " ";
2025 theDump += TCollection_AsciiString(nbo) + "\n";
2030 //=======================================================================
2031 //function : GetProblemShapes
2032 // purpose : for StructuralDump
2033 //=======================================================================
2034 void GEOMImpl_IMeasureOperations::GetProblemShapes (const BRepCheck_Analyzer& theAna,
2035 const TopoDS_Shape& theShape,
2036 Handle(TopTools_HSequenceOfShape)& sl,
2037 Handle(TColStd_HArray1OfInteger)& NbProblems,
2038 TopTools_DataMapOfShapeListOfShape& theMap)
2040 for (TopoDS_Iterator iter(theShape); iter.More(); iter.Next()) {
2041 GetProblemShapes(theAna, iter.Value(), sl, NbProblems, theMap);
2043 TopAbs_ShapeEnum styp = theShape.ShapeType();
2044 BRepCheck_ListIteratorOfListOfStatus itl;
2045 TopTools_ListOfShape empty;
2046 if (!theMap.IsBound(theShape)) {
2047 theMap.Bind(theShape,empty);
2049 if (!theAna.Result(theShape).IsNull()) {
2050 itl.Initialize(theAna.Result(theShape)->Status());
2051 // !!! May be, we have to print all the problems, not only the first one ?
2052 if (itl.Value() != BRepCheck_NoError) {
2053 sl->Append(theShape);
2054 BRepCheck_Status stat = itl.Value();
2055 NbProblems->SetValue((Standard_Integer)stat,
2056 NbProblems->Value((Standard_Integer)stat) + 1);
2063 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_VERTEX, theMap);
2066 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_WIRE, theMap);
2067 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_EDGE, theMap);
2068 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_VERTEX, theMap);
2073 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_SHELL, theMap);
2080 //=======================================================================
2081 //function : Contains
2082 //=======================================================================
2083 static Standard_Boolean Contains (const TopTools_ListOfShape& L,
2084 const TopoDS_Shape& S)
2086 TopTools_ListIteratorOfListOfShape it;
2087 for (it.Initialize(L); it.More(); it.Next()) {
2088 if (it.Value().IsSame(S)) {
2089 return Standard_True;
2092 return Standard_False;
2095 //=======================================================================
2096 //function : GetProblemSub
2097 // purpose : for StructuralDump
2098 //=======================================================================
2099 void GEOMImpl_IMeasureOperations::GetProblemSub (const BRepCheck_Analyzer& theAna,
2100 const TopoDS_Shape& theShape,
2101 Handle(TopTools_HSequenceOfShape)& sl,
2102 Handle(TColStd_HArray1OfInteger)& NbProblems,
2103 const TopAbs_ShapeEnum Subtype,
2104 TopTools_DataMapOfShapeListOfShape& theMap)
2106 BRepCheck_ListIteratorOfListOfStatus itl;
2107 TopExp_Explorer exp;
2108 for (exp.Init(theShape, Subtype); exp.More(); exp.Next()) {
2109 const TopoDS_Shape& sub = exp.Current();
2111 const Handle(BRepCheck_Result)& res = theAna.Result(sub);
2112 for (res->InitContextIterator();
2113 res->MoreShapeInContext();
2114 res->NextShapeInContext()) {
2115 if (res->ContextualShape().IsSame(theShape) && !Contains(theMap(sub), theShape)) {
2116 theMap(sub).Append(theShape);
2117 itl.Initialize(res->StatusOnShape());
2119 if (itl.Value() != BRepCheck_NoError) {
2120 Standard_Integer ii = 0;
2122 for (ii = 1; ii <= sl->Length(); ii++)
2123 if (sl->Value(ii).IsSame(sub)) break;
2125 if (ii > sl->Length()) {
2127 BRepCheck_Status stat = itl.Value();
2128 NbProblems->SetValue((Standard_Integer)stat,
2129 NbProblems->Value((Standard_Integer)stat) + 1);
2131 for (ii = 1; ii <= sl->Length(); ii++)
2132 if (sl->Value(ii).IsSame(theShape)) break;
2133 if (ii > sl->Length()) {
2134 sl->Append(theShape);
2135 BRepCheck_Status stat = itl.Value();
2136 NbProblems->SetValue((Standard_Integer)stat,
2137 NbProblems->Value((Standard_Integer)stat) + 1);