1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <Standard_Stream.hxx>
25 #include <GEOMImpl_IMeasureOperations.hxx>
27 #include <GEOMImpl_Types.hxx>
28 #include <GEOMImpl_MeasureDriver.hxx>
29 #include <GEOMImpl_IMeasure.hxx>
30 #include <GEOMImpl_IShapesOperations.hxx>
32 #include <GEOMAlgo_ShapeInfo.hxx>
33 #include <GEOMAlgo_ShapeInfoFiller.hxx>
35 #include <GEOM_Function.hxx>
36 #include <GEOM_PythonDump.hxx>
38 #include <utilities.h>
40 #include <Utils_ExceptHandlers.hxx>
43 #include <TFunction_DriverTable.hxx>
44 #include <TFunction_Driver.hxx>
45 #include <TFunction_Logbook.hxx>
46 #include <TDF_Tool.hxx>
48 #include <BRep_Tool.hxx>
49 #include <BRepAdaptor_Surface.hxx>
50 #include <BRepBndLib.hxx>
51 #include <BRepCheck.hxx>
52 #include <BRepCheck_ListIteratorOfListOfStatus.hxx>
53 #include <BRepCheck_Result.hxx>
54 #include <BRepCheck_Shell.hxx>
55 #include <BRepExtrema_DistShapeShape.hxx>
56 #include <BRepGProp.hxx>
57 #include <BRepTools.hxx>
59 #include <Bnd_Box.hxx>
61 #include <GProp_GProps.hxx>
62 #include <GProp_PrincipalProps.hxx>
67 #include <TopoDS_Edge.hxx>
68 #include <TopoDS_Face.hxx>
69 #include <TopoDS_Shape.hxx>
70 #include <TopoDS_Vertex.hxx>
71 #include <TopoDS_Iterator.hxx>
72 #include <TopExp_Explorer.hxx>
73 #include <TopTools_MapOfShape.hxx>
74 #include <TopTools_ListOfShape.hxx>
75 #include <TopTools_ListIteratorOfListOfShape.hxx>
77 #include <GeomAbs_SurfaceType.hxx>
78 #include <Geom_Surface.hxx>
79 #include <Geom_Plane.hxx>
80 #include <Geom_SphericalSurface.hxx>
81 #include <Geom_CylindricalSurface.hxx>
82 #include <Geom_ToroidalSurface.hxx>
83 #include <Geom_ConicalSurface.hxx>
84 #include <Geom_SurfaceOfLinearExtrusion.hxx>
85 #include <Geom_SurfaceOfRevolution.hxx>
86 #include <Geom_BezierSurface.hxx>
87 #include <Geom_BSplineSurface.hxx>
88 #include <Geom_RectangularTrimmedSurface.hxx>
89 #include <Geom_OffsetSurface.hxx>
90 #include <Geom_Line.hxx>
95 #include <GeomAPI_ProjectPointOnCurve.hxx>
96 #include <GeomLProp_CLProps.hxx>
97 #include <GeomLProp_SLProps.hxx>
98 #include <ShapeAnalysis.hxx>
99 #include <ShapeAnalysis_Surface.hxx>
101 #include <Standard_Failure.hxx>
102 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
104 #include <BRepClass3d_SolidClassifier.hxx>
105 #include <BRep_Builder.hxx>
106 #include <GeomAPI_IntSS.hxx>
107 #include <Geom_Circle.hxx>
108 #include <Geom_SphericalSurface.hxx>
109 #include <Geom_ToroidalSurface.hxx>
110 #include <ShapeFix_Shape.hxx>
111 #include <TopoDS_Compound.hxx>
114 //=============================================================================
118 //=============================================================================
119 GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations (GEOM_Engine* theEngine, int theDocID)
120 : GEOM_IOperations(theEngine, theDocID)
122 MESSAGE("GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations");
125 //=============================================================================
129 //=============================================================================
130 GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations()
132 MESSAGE("GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations");
135 //=============================================================================
136 /*! Get kind and parameters of the given shape.
138 //=============================================================================
139 GEOMImpl_IMeasureOperations::ShapeKind GEOMImpl_IMeasureOperations::KindOfShape
140 (Handle(GEOM_Object) theShape,
141 Handle(TColStd_HSequenceOfInteger)& theIntegers,
142 Handle(TColStd_HSequenceOfReal)& theDoubles)
145 ShapeKind aKind = SK_NO_SHAPE;
147 if (theIntegers.IsNull()) theIntegers = new TColStd_HSequenceOfInteger;
148 else theIntegers->Clear();
150 if (theDoubles.IsNull()) theDoubles = new TColStd_HSequenceOfReal;
151 else theDoubles->Clear();
153 if (theShape.IsNull())
156 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
157 if (aRefShape.IsNull()) return aKind;
159 TopoDS_Shape aShape = aRefShape->GetValue();
160 if (aShape.IsNull()) return aKind;
162 int geom_type = theShape->GetType();
164 // check if it's advanced shape
165 if ( geom_type > ADVANCED_BASE ) {
171 GEOMAlgo_ShapeInfoFiller aSF;
172 aSF.SetShape(aShape);
174 Standard_Integer iErr = aSF.ErrorStatus();
176 SetErrorCode("Error in GEOMAlgo_ShapeInfoFiller");
179 const GEOMAlgo_ShapeInfo& anInfo = aSF.Info();
181 // Interprete results
182 TopAbs_ShapeEnum aType = anInfo.Type();
185 case TopAbs_COMPOUND:
186 case TopAbs_COMPSOLID:
188 // (+) geompy.kind.COMPOUND nb_solids nb_faces nb_edges nb_vertices
189 // (+) geompy.kind.COMPSOLID nb_solids nb_faces nb_edges nb_vertices
190 // ??? "nb_faces" - all faces or only 'standalone' faces?
191 if (aType == TopAbs_COMPOUND)
194 aKind = SK_COMPSOLID;
196 //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPOUND));
197 //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPSOLID));
198 theIntegers->Append(anInfo.NbSubShapes(TopAbs_SOLID));
199 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
200 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
201 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
207 // (+) geompy.kind.SHELL geompy.info.closed nb_faces nb_edges nb_vertices
208 // (+) geompy.kind.SHELL geompy.info.unclosed nb_faces nb_edges nb_vertices
211 theIntegers->Append((int)anInfo.KindOfClosed());
213 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
214 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
215 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
221 // (+) geompy.kind.WIRE geompy.info.closed nb_edges nb_vertices
222 // (+) geompy.kind.WIRE geompy.info.unclosed nb_edges nb_vertices
225 theIntegers->Append((int)anInfo.KindOfClosed());
227 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
228 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
236 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
239 case GEOMAlgo_KN_SPHERE:
240 // (+) geompy.kind.SPHERE xc yc zc R
244 gp_Pnt aC = anInfo.Location();
245 theDoubles->Append(aC.X());
246 theDoubles->Append(aC.Y());
247 theDoubles->Append(aC.Z());
249 theDoubles->Append(anInfo.Radius1());
252 case GEOMAlgo_KN_CYLINDER:
253 // (+) geompy.kind.CYLINDER xb yb zb dx dy dz R H
257 gp_Pnt aC = anInfo.Location();
258 theDoubles->Append(aC.X());
259 theDoubles->Append(aC.Y());
260 theDoubles->Append(aC.Z());
262 gp_Ax3 anAx3 = anInfo.Position();
263 gp_Dir aD = anAx3.Direction();
264 theDoubles->Append(aD.X());
265 theDoubles->Append(aD.Y());
266 theDoubles->Append(aD.Z());
268 theDoubles->Append(anInfo.Radius1());
269 theDoubles->Append(anInfo.Height());
272 case GEOMAlgo_KN_BOX:
273 // (+) geompy.kind.BOX xc yc zc ax ay az
277 gp_Pnt aC = anInfo.Location();
278 theDoubles->Append(aC.X());
279 theDoubles->Append(aC.Y());
280 theDoubles->Append(aC.Z());
282 gp_Ax3 anAx3 = anInfo.Position();
283 gp_Dir aD = anAx3.Direction();
284 gp_Dir aX = anAx3.XDirection();
287 if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
288 aX.IsParallel(gp::DX(), Precision::Angular())) {
289 theDoubles->Append(anInfo.Length()); // ax'
290 theDoubles->Append(anInfo.Width()); // ay'
291 theDoubles->Append(anInfo.Height()); // az'
293 else if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
294 aX.IsParallel(gp::DY(), Precision::Angular())) {
295 theDoubles->Append(anInfo.Width()); // ay'
296 theDoubles->Append(anInfo.Length()); // ax'
297 theDoubles->Append(anInfo.Height()); // az'
299 else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
300 aX.IsParallel(gp::DZ(), Precision::Angular())) {
301 theDoubles->Append(anInfo.Height()); // az'
302 theDoubles->Append(anInfo.Width()); // ay'
303 theDoubles->Append(anInfo.Length()); // ax'
305 else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
306 aX.IsParallel(gp::DY(), Precision::Angular())) {
307 theDoubles->Append(anInfo.Height()); // az'
308 theDoubles->Append(anInfo.Length()); // ax'
309 theDoubles->Append(anInfo.Width()); // ay'
311 else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
312 aX.IsParallel(gp::DZ(), Precision::Angular())) {
313 theDoubles->Append(anInfo.Width()); // ay'
314 theDoubles->Append(anInfo.Height()); // az'
315 theDoubles->Append(anInfo.Length()); // ax'
317 else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
318 aX.IsParallel(gp::DX(), Precision::Angular())) {
319 theDoubles->Append(anInfo.Length()); // ax'
320 theDoubles->Append(anInfo.Height()); // az'
321 theDoubles->Append(anInfo.Width()); // ay'
324 // (+) geompy.kind.ROTATED_BOX xo yo zo zx zy zz xx xy xz ax ay az
325 aKind = SK_ROTATED_BOX;
327 // Direction and XDirection
328 theDoubles->Append(aD.X());
329 theDoubles->Append(aD.Y());
330 theDoubles->Append(aD.Z());
332 theDoubles->Append(aX.X());
333 theDoubles->Append(aX.Y());
334 theDoubles->Append(aX.Z());
337 theDoubles->Append(anInfo.Length());
338 theDoubles->Append(anInfo.Width());
339 theDoubles->Append(anInfo.Height());
343 case GEOMAlgo_KN_TORUS:
344 // (+) geompy.kind.TORUS xc yc zc dx dy dz R_1 R_2
348 gp_Pnt aO = anInfo.Location();
349 theDoubles->Append(aO.X());
350 theDoubles->Append(aO.Y());
351 theDoubles->Append(aO.Z());
353 gp_Ax3 anAx3 = anInfo.Position();
354 gp_Dir aD = anAx3.Direction();
355 theDoubles->Append(aD.X());
356 theDoubles->Append(aD.Y());
357 theDoubles->Append(aD.Z());
359 theDoubles->Append(anInfo.Radius1());
360 theDoubles->Append(anInfo.Radius2());
363 case GEOMAlgo_KN_CONE:
364 // (+) geompy.kind.CONE xb yb zb dx dy dz R_1 R_2 H
368 gp_Pnt aO = anInfo.Location();
369 theDoubles->Append(aO.X());
370 theDoubles->Append(aO.Y());
371 theDoubles->Append(aO.Z());
373 gp_Ax3 anAx3 = anInfo.Position();
374 gp_Dir aD = anAx3.Direction();
375 theDoubles->Append(aD.X());
376 theDoubles->Append(aD.Y());
377 theDoubles->Append(aD.Z());
379 theDoubles->Append(anInfo.Radius1());
380 theDoubles->Append(anInfo.Radius2());
381 theDoubles->Append(anInfo.Height());
384 case GEOMAlgo_KN_POLYHEDRON:
385 // (+) geompy.kind.POLYHEDRON nb_faces nb_edges nb_vertices
387 aKind = SK_POLYHEDRON;
389 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
390 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
391 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
395 // (+) geompy.kind.SOLID nb_faces nb_edges nb_vertices
397 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
398 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
399 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
409 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
411 case GEOMAlgo_KN_SPHERE:
412 // (+) geompy.kind.SPHERE2D xc yc zc R
416 gp_Pnt aC = anInfo.Location();
417 theDoubles->Append(aC.X());
418 theDoubles->Append(aC.Y());
419 theDoubles->Append(aC.Z());
421 theDoubles->Append(anInfo.Radius1());
424 case GEOMAlgo_KN_CYLINDER:
425 // (+) geompy.kind.CYLINDER2D xb yb zb dx dy dz R H
427 aKind = SK_CYLINDER2D;
429 gp_Pnt aO = anInfo.Location();
430 theDoubles->Append(aO.X());
431 theDoubles->Append(aO.Y());
432 theDoubles->Append(aO.Z());
434 gp_Ax3 anAx3 = anInfo.Position();
435 gp_Dir aD = anAx3.Direction();
436 theDoubles->Append(aD.X());
437 theDoubles->Append(aD.Y());
438 theDoubles->Append(aD.Z());
440 theDoubles->Append(anInfo.Radius1());
441 theDoubles->Append(anInfo.Height());
444 case GEOMAlgo_KN_TORUS:
445 // (+) geompy.kind.TORUS2D xc yc zc dx dy dz R_1 R_2
449 gp_Pnt aO = anInfo.Location();
450 theDoubles->Append(aO.X());
451 theDoubles->Append(aO.Y());
452 theDoubles->Append(aO.Z());
454 gp_Ax3 anAx3 = anInfo.Position();
455 gp_Dir aD = anAx3.Direction();
456 theDoubles->Append(aD.X());
457 theDoubles->Append(aD.Y());
458 theDoubles->Append(aD.Z());
460 theDoubles->Append(anInfo.Radius1());
461 theDoubles->Append(anInfo.Radius2());
464 case GEOMAlgo_KN_CONE:
465 // (+) geompy.kind.CONE2D xc yc zc dx dy dz R_1 R_2 H
469 gp_Pnt aO = anInfo.Location();
470 theDoubles->Append(aO.X());
471 theDoubles->Append(aO.Y());
472 theDoubles->Append(aO.Z());
474 gp_Ax3 anAx3 = anInfo.Position();
475 gp_Dir aD = anAx3.Direction();
476 theDoubles->Append(aD.X());
477 theDoubles->Append(aD.Y());
478 theDoubles->Append(aD.Z());
480 theDoubles->Append(anInfo.Radius1());
481 theDoubles->Append(anInfo.Radius2());
482 theDoubles->Append(anInfo.Height());
485 case GEOMAlgo_KN_DISKCIRCLE:
486 // (+) geompy.kind.DISK_CIRCLE xc yc zc dx dy dz R
488 aKind = SK_DISK_CIRCLE;
490 gp_Pnt aC = anInfo.Location();
491 theDoubles->Append(aC.X());
492 theDoubles->Append(aC.Y());
493 theDoubles->Append(aC.Z());
495 gp_Ax3 anAx3 = anInfo.Position();
496 gp_Dir aD = anAx3.Direction();
497 theDoubles->Append(aD.X());
498 theDoubles->Append(aD.Y());
499 theDoubles->Append(aD.Z());
501 theDoubles->Append(anInfo.Radius1());
504 case GEOMAlgo_KN_DISKELLIPSE:
505 // (+) geompy.kind.DISK_ELLIPSE xc yc zc dx dy dz R_1 R_2
507 aKind = SK_DISK_ELLIPSE;
509 gp_Pnt aC = anInfo.Location();
510 theDoubles->Append(aC.X());
511 theDoubles->Append(aC.Y());
512 theDoubles->Append(aC.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 theDoubles->Append(anInfo.Radius1());
521 theDoubles->Append(anInfo.Radius2());
524 case GEOMAlgo_KN_RECTANGLE:
525 case GEOMAlgo_KN_TRIANGLE:
526 case GEOMAlgo_KN_QUADRANGLE:
527 case GEOMAlgo_KN_POLYGON:
528 // (+) geompy.kind.POLYGON xo yo zo dx dy dz nb_edges nb_vertices
532 gp_Pnt aO = anInfo.Location();
533 theDoubles->Append(aO.X());
534 theDoubles->Append(aO.Y());
535 theDoubles->Append(aO.Z());
537 gp_Ax3 anAx3 = anInfo.Position();
538 gp_Dir aD = anAx3.Direction();
539 theDoubles->Append(aD.X());
540 theDoubles->Append(aD.Y());
541 theDoubles->Append(aD.Z());
543 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
544 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
547 case GEOMAlgo_KN_PLANE: // infinite
548 // (+) geompy.kind.PLANE xo yo zo dx dy dz
552 gp_Pnt aC = anInfo.Location();
553 theDoubles->Append(aC.X());
554 theDoubles->Append(aC.Y());
555 theDoubles->Append(aC.Z());
557 gp_Ax3 anAx3 = anInfo.Position();
558 gp_Dir aD = anAx3.Direction();
559 theDoubles->Append(aD.X());
560 theDoubles->Append(aD.Y());
561 theDoubles->Append(aD.Z());
565 if (anInfo.KindOfShape() == GEOMAlgo_KS_PLANE) {
566 // (+) geompy.kind.PLANAR xo yo zo dx dy dz nb_edges nb_vertices
570 gp_Pnt aC = anInfo.Location();
571 theDoubles->Append(aC.X());
572 theDoubles->Append(aC.Y());
573 theDoubles->Append(aC.Z());
575 gp_Ax3 anAx3 = anInfo.Position();
576 gp_Dir aD = anAx3.Direction();
577 theDoubles->Append(aD.X());
578 theDoubles->Append(aD.Y());
579 theDoubles->Append(aD.Z());
581 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
582 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
585 // ??? geompy.kind.FACE nb_edges nb_vertices _surface_type_id_
586 // (+) geompy.kind.FACE nb_edges nb_vertices
588 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
589 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
599 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
601 case GEOMAlgo_KN_CIRCLE:
603 // (+) geompy.kind.CIRCLE xc yc zc dx dy dz R
606 gp_Pnt aC = anInfo.Location();
607 theDoubles->Append(aC.X());
608 theDoubles->Append(aC.Y());
609 theDoubles->Append(aC.Z());
611 gp_Ax3 anAx3 = anInfo.Position();
612 gp_Dir aD = anAx3.Direction();
613 theDoubles->Append(aD.X());
614 theDoubles->Append(aD.Y());
615 theDoubles->Append(aD.Z());
617 theDoubles->Append(anInfo.Radius1());
620 case GEOMAlgo_KN_ARCCIRCLE:
622 // (+) geompy.kind.ARC_CIRCLE xc yc zc dx dy dz R x1 y1 z1 x2 y2 z2
623 aKind = SK_ARC_CIRCLE;
625 gp_Pnt aC = anInfo.Location();
626 theDoubles->Append(aC.X());
627 theDoubles->Append(aC.Y());
628 theDoubles->Append(aC.Z());
630 gp_Ax3 anAx3 = anInfo.Position();
631 gp_Dir aD = anAx3.Direction();
632 theDoubles->Append(aD.X());
633 theDoubles->Append(aD.Y());
634 theDoubles->Append(aD.Z());
636 theDoubles->Append(anInfo.Radius1());
638 gp_Pnt aP1 = anInfo.Pnt1();
639 theDoubles->Append(aP1.X());
640 theDoubles->Append(aP1.Y());
641 theDoubles->Append(aP1.Z());
643 gp_Pnt aP2 = anInfo.Pnt2();
644 theDoubles->Append(aP2.X());
645 theDoubles->Append(aP2.Y());
646 theDoubles->Append(aP2.Z());
649 case GEOMAlgo_KN_ELLIPSE:
651 // (+) geompy.kind.ELLIPSE xc yc zc dx dy dz R_1 R_2
654 gp_Pnt aC = anInfo.Location();
655 theDoubles->Append(aC.X());
656 theDoubles->Append(aC.Y());
657 theDoubles->Append(aC.Z());
659 gp_Ax3 anAx3 = anInfo.Position();
660 gp_Dir aD = anAx3.Direction();
661 theDoubles->Append(aD.X());
662 theDoubles->Append(aD.Y());
663 theDoubles->Append(aD.Z());
665 theDoubles->Append(anInfo.Radius1());
666 theDoubles->Append(anInfo.Radius2());
669 case GEOMAlgo_KN_ARCELLIPSE:
671 // (+) geompy.kind.ARC_ELLIPSE xc yc zc dx dy dz R_1 R_2 x1 y1 z1 x2 y2 z2
672 aKind = SK_ARC_ELLIPSE;
674 gp_Pnt aC = anInfo.Location();
675 theDoubles->Append(aC.X());
676 theDoubles->Append(aC.Y());
677 theDoubles->Append(aC.Z());
679 gp_Ax3 anAx3 = anInfo.Position();
680 gp_Dir aD = anAx3.Direction();
681 theDoubles->Append(aD.X());
682 theDoubles->Append(aD.Y());
683 theDoubles->Append(aD.Z());
685 theDoubles->Append(anInfo.Radius1());
686 theDoubles->Append(anInfo.Radius2());
688 gp_Pnt aP1 = anInfo.Pnt1();
689 theDoubles->Append(aP1.X());
690 theDoubles->Append(aP1.Y());
691 theDoubles->Append(aP1.Z());
693 gp_Pnt aP2 = anInfo.Pnt2();
694 theDoubles->Append(aP2.X());
695 theDoubles->Append(aP2.Y());
696 theDoubles->Append(aP2.Z());
699 case GEOMAlgo_KN_LINE:
701 // ??? geompy.kind.LINE x1 y1 z1 x2 y2 z2
702 // (+) geompy.kind.LINE x1 y1 z1 dx dy dz
705 gp_Pnt aO = anInfo.Location();
706 theDoubles->Append(aO.X());
707 theDoubles->Append(aO.Y());
708 theDoubles->Append(aO.Z());
710 gp_Dir aD = anInfo.Direction();
711 theDoubles->Append(aD.X());
712 theDoubles->Append(aD.Y());
713 theDoubles->Append(aD.Z());
716 case GEOMAlgo_KN_SEGMENT:
718 // (+) geompy.kind.SEGMENT x1 y1 z1 x2 y2 z2
721 gp_Pnt aP1 = anInfo.Pnt1();
722 theDoubles->Append(aP1.X());
723 theDoubles->Append(aP1.Y());
724 theDoubles->Append(aP1.Z());
726 gp_Pnt aP2 = anInfo.Pnt2();
727 theDoubles->Append(aP2.X());
728 theDoubles->Append(aP2.Y());
729 theDoubles->Append(aP2.Z());
733 // ??? geompy.kind.EDGE nb_vertices _curve_type_id_
734 // (+) geompy.kind.EDGE nb_vertices
735 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
742 // (+) geompy.kind.VERTEX x y z
745 gp_Pnt aP = anInfo.Location();
746 theDoubles->Append(aP.X());
747 theDoubles->Append(aP.Y());
748 theDoubles->Append(aP.Z());
757 //=============================================================================
758 /*! Get LCS, corresponding to the given shape.
759 * Origin of the LCS is situated at the shape's center of mass.
760 * Axes of the LCS are obtained from shape's location or,
761 * if the shape is a planar face, from position of its plane.
763 //=============================================================================
764 gp_Ax3 GEOMImpl_IMeasureOperations::GetPosition (const TopoDS_Shape& theShape)
768 if (theShape.IsNull())
772 aResult.Transform(theShape.Location().Transformation());
773 if (theShape.ShapeType() == TopAbs_FACE) {
774 Handle(Geom_Surface) aGS = BRep_Tool::Surface(TopoDS::Face(theShape));
775 if (!aGS.IsNull() && aGS->IsKind(STANDARD_TYPE(Geom_Plane))) {
776 Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast(aGS);
777 gp_Pln aPln = aGPlane->Pln();
778 aResult = aPln.Position();
785 TopAbs_ShapeEnum aShType = theShape.ShapeType();
787 if (aShType == TopAbs_VERTEX) {
788 aPnt = BRep_Tool::Pnt(TopoDS::Vertex(theShape));
791 if (aShType == TopAbs_COMPOUND) {
792 aShType = GEOMImpl_IShapesOperations::GetTypeOfSimplePart(theShape);
795 GProp_GProps aSystem;
796 if (aShType == TopAbs_EDGE || aShType == TopAbs_WIRE)
797 BRepGProp::LinearProperties(theShape, aSystem);
798 else if (aShType == TopAbs_FACE || aShType == TopAbs_SHELL)
799 BRepGProp::SurfaceProperties(theShape, aSystem);
801 BRepGProp::VolumeProperties(theShape, aSystem);
803 aPnt = aSystem.CentreOfMass();
806 aResult.SetLocation(aPnt);
811 //=============================================================================
815 //=============================================================================
816 void GEOMImpl_IMeasureOperations::GetPosition
817 (Handle(GEOM_Object) theShape,
818 Standard_Real& Ox, Standard_Real& Oy, Standard_Real& Oz,
819 Standard_Real& Zx, Standard_Real& Zy, Standard_Real& Zz,
820 Standard_Real& Xx, Standard_Real& Xy, Standard_Real& Xz)
824 //Set default values: global CS
825 Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
828 if (theShape.IsNull()) return;
830 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
831 if (aRefShape.IsNull()) return;
833 TopoDS_Shape aShape = aRefShape->GetValue();
834 if (aShape.IsNull()) {
835 SetErrorCode("The Objects has NULL Shape");
840 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
844 gp_Ax3 anAx3 = GetPosition(aShape);
846 gp_Pnt anOri = anAx3.Location();
847 gp_Dir aDirZ = anAx3.Direction();
848 gp_Dir aDirX = anAx3.XDirection();
851 anOri.Coord(Ox, Oy, Oz);
852 aDirZ.Coord(Zx, Zy, Zz);
853 aDirX.Coord(Xx, Xy, Xz);
855 catch (Standard_Failure) {
856 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
857 SetErrorCode(aFail->GetMessageString());
864 //=============================================================================
868 //=============================================================================
869 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetCentreOfMass
870 (Handle(GEOM_Object) theShape)
874 if (theShape.IsNull()) return NULL;
876 //Add a new CentreOfMass object
877 Handle(GEOM_Object) aCDG = GetEngine()->AddObject(GetDocID(), GEOM_CDG);
879 //Add a new CentreOfMass function
880 Handle(GEOM_Function) aFunction =
881 aCDG->AddFunction(GEOMImpl_MeasureDriver::GetID(), CDG_MEASURE);
882 if (aFunction.IsNull()) return NULL;
884 //Check if the function is set correctly
885 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
887 GEOMImpl_IMeasure aCI (aFunction);
889 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
890 if (aRefShape.IsNull()) return NULL;
892 aCI.SetBase(aRefShape);
894 //Compute the CentreOfMass value
896 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
899 if (!GetSolver()->ComputeFunction(aFunction)) {
900 SetErrorCode("Measure driver failed to compute centre of mass");
904 catch (Standard_Failure) {
905 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
906 SetErrorCode(aFail->GetMessageString());
910 //Make a Python command
911 GEOM::TPythonDump(aFunction) << aCDG << " = geompy.MakeCDG(" << theShape << ")";
917 //=============================================================================
921 //=============================================================================
922 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetVertexByIndex
923 (Handle(GEOM_Object) theShape,
924 Standard_Integer theIndex)
928 if (theShape.IsNull()) return NULL;
930 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
931 if (aRefShape.IsNull()) return NULL;
933 //Add a new Vertex object
934 Handle(GEOM_Object) aVertex = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
937 Handle(GEOM_Function) aFunction =
938 aVertex->AddFunction(GEOMImpl_MeasureDriver::GetID(), VERTEX_BY_INDEX);
939 if (aFunction.IsNull()) return NULL;
941 //Check if the function is set correctly
942 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
944 GEOMImpl_IMeasure aCI (aFunction);
945 aCI.SetBase(aRefShape);
946 aCI.SetIndex(theIndex);
950 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
953 if (!GetSolver()->ComputeFunction(aFunction)) {
954 SetErrorCode("Vertex by index driver failed.");
958 catch (Standard_Failure) {
959 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
960 SetErrorCode(aFail->GetMessageString());
964 //Make a Python command
965 GEOM::TPythonDump(aFunction) << aVertex << " = geompy.GetVertexByIndex(" << theShape << ", " << theIndex << ")";
971 //=============================================================================
975 //=============================================================================
976 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetNormal
977 (Handle(GEOM_Object) theFace,
978 Handle(GEOM_Object) theOptionalPoint)
982 if (theFace.IsNull()) return NULL;
984 //Add a new Normale object
985 Handle(GEOM_Object) aNorm = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
987 //Add a new Normale function
988 Handle(GEOM_Function) aFunction =
989 aNorm->AddFunction(GEOMImpl_MeasureDriver::GetID(), VECTOR_FACE_NORMALE);
990 if (aFunction.IsNull()) return NULL;
992 //Check if the function is set correctly
993 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
995 GEOMImpl_IMeasure aCI (aFunction);
997 Handle(GEOM_Function) aFace = theFace->GetLastFunction();
998 if (aFace.IsNull()) return NULL;
1002 if (!theOptionalPoint.IsNull()) {
1003 Handle(GEOM_Function) anOptPnt = theOptionalPoint->GetLastFunction();
1004 aCI.SetPoint(anOptPnt);
1007 //Compute the Normale value
1009 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1012 if (!GetSolver()->ComputeFunction(aFunction)) {
1013 SetErrorCode("Measure driver failed to compute normake of face");
1017 catch (Standard_Failure) {
1018 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1019 SetErrorCode(aFail->GetMessageString());
1023 //Make a Python command
1024 GEOM::TPythonDump pd (aFunction);
1025 pd << aNorm << " = geompy.GetNormal(" << theFace;
1026 if (!theOptionalPoint.IsNull()) {
1027 pd << ", " << theOptionalPoint;
1035 //=============================================================================
1037 * GetBasicProperties
1039 //=============================================================================
1040 void GEOMImpl_IMeasureOperations::GetBasicProperties (Handle(GEOM_Object) theShape,
1041 Standard_Real& theLength,
1042 Standard_Real& theSurfArea,
1043 Standard_Real& theVolume)
1047 if (theShape.IsNull()) return;
1049 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1050 if (aRefShape.IsNull()) return;
1052 TopoDS_Shape aShape = aRefShape->GetValue();
1053 if (aShape.IsNull()) {
1054 SetErrorCode("The Objects has NULL Shape");
1058 //Compute the parameters
1059 GProp_GProps LProps, SProps;
1061 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1064 BRepGProp::LinearProperties(aShape, LProps);
1065 theLength = LProps.Mass();
1067 BRepGProp::SurfaceProperties(aShape, SProps);
1068 theSurfArea = SProps.Mass();
1071 if (aShape.ShapeType() < TopAbs_SHELL) {
1072 for (TopExp_Explorer Exp (aShape, TopAbs_SOLID); Exp.More(); Exp.Next()) {
1073 GProp_GProps VProps;
1074 BRepGProp::VolumeProperties(Exp.Current(), VProps);
1075 theVolume += VProps.Mass();
1079 catch (Standard_Failure) {
1080 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1081 SetErrorCode(aFail->GetMessageString());
1088 //=============================================================================
1092 //=============================================================================
1093 void GEOMImpl_IMeasureOperations::GetInertia
1094 (Handle(GEOM_Object) theShape,
1095 Standard_Real& I11, Standard_Real& I12, Standard_Real& I13,
1096 Standard_Real& I21, Standard_Real& I22, Standard_Real& I23,
1097 Standard_Real& I31, Standard_Real& I32, Standard_Real& I33,
1098 Standard_Real& Ix , Standard_Real& Iy , Standard_Real& Iz)
1102 if (theShape.IsNull()) return;
1104 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1105 if (aRefShape.IsNull()) return;
1107 TopoDS_Shape aShape = aRefShape->GetValue();
1108 if (aShape.IsNull()) {
1109 SetErrorCode("The Objects has NULL Shape");
1113 //Compute the parameters
1114 GProp_GProps System;
1117 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1120 if (aShape.ShapeType() == TopAbs_VERTEX ||
1121 aShape.ShapeType() == TopAbs_EDGE ||
1122 aShape.ShapeType() == TopAbs_WIRE) {
1123 BRepGProp::LinearProperties(aShape, System);
1124 } else if (aShape.ShapeType() == TopAbs_FACE ||
1125 aShape.ShapeType() == TopAbs_SHELL) {
1126 BRepGProp::SurfaceProperties(aShape, System);
1128 BRepGProp::VolumeProperties(aShape, System);
1130 gp_Mat I = System.MatrixOfInertia();
1144 GProp_PrincipalProps Pr = System.PrincipalProperties();
1145 Pr.Moments(Ix,Iy,Iz);
1147 catch (Standard_Failure) {
1148 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1149 SetErrorCode(aFail->GetMessageString());
1156 //=============================================================================
1160 //=============================================================================
1161 void GEOMImpl_IMeasureOperations::GetBoundingBox
1162 (Handle(GEOM_Object) theShape,
1163 Standard_Real& Xmin, Standard_Real& Xmax,
1164 Standard_Real& Ymin, Standard_Real& Ymax,
1165 Standard_Real& Zmin, Standard_Real& Zmax)
1169 if (theShape.IsNull()) return;
1171 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1172 if (aRefShape.IsNull()) return;
1174 TopoDS_Shape aShape = aRefShape->GetValue();
1175 if (aShape.IsNull()) {
1176 SetErrorCode("The Objects has NULL Shape");
1180 //Compute the parameters
1184 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1187 BRepBndLib::Add(aShape, B);
1188 B.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
1190 catch (Standard_Failure) {
1191 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1192 SetErrorCode(aFail->GetMessageString());
1199 //=============================================================================
1203 //=============================================================================
1204 void GEOMImpl_IMeasureOperations::GetTolerance
1205 (Handle(GEOM_Object) theShape,
1206 Standard_Real& FaceMin, Standard_Real& FaceMax,
1207 Standard_Real& EdgeMin, Standard_Real& EdgeMax,
1208 Standard_Real& VertMin, Standard_Real& VertMax)
1212 if (theShape.IsNull()) return;
1214 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1215 if (aRefShape.IsNull()) return;
1217 TopoDS_Shape aShape = aRefShape->GetValue();
1218 if (aShape.IsNull()) {
1219 SetErrorCode("The Objects has NULL Shape");
1223 //Compute the parameters
1225 FaceMin = EdgeMin = VertMin = RealLast();
1226 FaceMax = EdgeMax = VertMax = -RealLast();
1229 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1232 for (TopExp_Explorer ExF (aShape, TopAbs_FACE); ExF.More(); ExF.Next()) {
1233 TopoDS_Face Face = TopoDS::Face(ExF.Current());
1234 T = BRep_Tool::Tolerance(Face);
1240 for (TopExp_Explorer ExE (aShape, TopAbs_EDGE); ExE.More(); ExE.Next()) {
1241 TopoDS_Edge Edge = TopoDS::Edge(ExE.Current());
1242 T = BRep_Tool::Tolerance(Edge);
1248 for (TopExp_Explorer ExV (aShape, TopAbs_VERTEX); ExV.More(); ExV.Next()) {
1249 TopoDS_Vertex Vertex = TopoDS::Vertex(ExV.Current());
1250 T = BRep_Tool::Tolerance(Vertex);
1257 catch (Standard_Failure) {
1258 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1259 SetErrorCode(aFail->GetMessageString());
1266 //=============================================================================
1270 //=============================================================================
1271 bool GEOMImpl_IMeasureOperations::CheckShape (Handle(GEOM_Object) theShape,
1272 const Standard_Boolean theIsCheckGeom,
1273 TCollection_AsciiString& theDump)
1277 if (theShape.IsNull()) return false;
1279 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1280 if (aRefShape.IsNull()) return false;
1282 TopoDS_Shape aShape = aRefShape->GetValue();
1283 if (aShape.IsNull()) {
1284 SetErrorCode("The Objects has NULL Shape");
1288 //Compute the parameters
1289 bool isValid = false;
1291 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1294 BRepCheck_Analyzer ana (aShape, theIsCheckGeom);
1295 if (ana.IsValid()) {
1299 StructuralDump(ana, aShape, theDump);
1302 catch (Standard_Failure) {
1303 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1304 SetErrorCode(aFail->GetMessageString());
1312 //=============================================================================
1316 //=============================================================================
1317 TCollection_AsciiString GEOMImpl_IMeasureOperations::IsGoodForSolid (Handle(GEOM_Object) theShape)
1321 TCollection_AsciiString aRes = "";
1323 if (theShape.IsNull()) {
1324 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1327 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1328 if (aRefShape.IsNull()) {
1329 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1332 TopoDS_Shape aShape = aRefShape->GetValue();
1333 if (aShape.IsNull()) {
1334 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1337 if (aShape.ShapeType() == TopAbs_COMPOUND) {
1338 TopoDS_Iterator It (aShape, Standard_True, Standard_True);
1339 if (It.More()) aShape = It.Value();
1341 if (aShape.ShapeType() == TopAbs_SHELL) {
1342 BRepCheck_Shell chkShell (TopoDS::Shell(aShape));
1343 if (chkShell.Closed() == BRepCheck_NotClosed) {
1344 aRes = "WRN_SHAPE_UNCLOSED";
1348 aRes = "WRN_SHAPE_NOT_SHELL";
1360 //=============================================================================
1364 //=============================================================================
1365 TCollection_AsciiString GEOMImpl_IMeasureOperations::WhatIs (Handle(GEOM_Object) theShape)
1369 TCollection_AsciiString Astr;
1371 if (theShape.IsNull()) return Astr;
1373 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1374 if (aRefShape.IsNull()) return Astr;
1376 TopoDS_Shape aShape = aRefShape->GetValue();
1377 if (aShape.IsNull()) {
1378 SetErrorCode("The Objects has NULL Shape");
1382 //Compute the parameters
1383 if (aShape.ShapeType() == TopAbs_EDGE) {
1384 if (BRep_Tool::Degenerated(TopoDS::Edge(aShape))) {
1385 Astr = Astr + " It is a degenerated edge \n";
1389 Astr = Astr + " Number of sub-shapes : \n";
1392 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1395 int iType, nbTypes [TopAbs_SHAPE];
1396 for (iType = 0; iType < TopAbs_SHAPE; ++iType)
1398 nbTypes[aShape.ShapeType()]++;
1400 TopTools_MapOfShape aMapOfShape;
1401 aMapOfShape.Add(aShape);
1402 TopTools_ListOfShape aListOfShape;
1403 aListOfShape.Append(aShape);
1405 TopTools_ListIteratorOfListOfShape itL (aListOfShape);
1406 for (; itL.More(); itL.Next()) {
1407 TopoDS_Iterator it (itL.Value());
1408 for (; it.More(); it.Next()) {
1409 TopoDS_Shape s = it.Value();
1410 if (aMapOfShape.Add(s)) {
1411 aListOfShape.Append(s);
1412 nbTypes[s.ShapeType()]++;
1417 Astr = Astr + " VERTEX : " + TCollection_AsciiString(nbTypes[TopAbs_VERTEX]) + "\n";
1418 Astr = Astr + " EDGE : " + TCollection_AsciiString(nbTypes[TopAbs_EDGE]) + "\n";
1419 Astr = Astr + " WIRE : " + TCollection_AsciiString(nbTypes[TopAbs_WIRE]) + "\n";
1420 Astr = Astr + " FACE : " + TCollection_AsciiString(nbTypes[TopAbs_FACE]) + "\n";
1421 Astr = Astr + " SHELL : " + TCollection_AsciiString(nbTypes[TopAbs_SHELL]) + "\n";
1422 Astr = Astr + " SOLID : " + TCollection_AsciiString(nbTypes[TopAbs_SOLID]) + "\n";
1423 Astr = Astr + " COMPSOLID : " + TCollection_AsciiString(nbTypes[TopAbs_COMPSOLID]) + "\n";
1424 Astr = Astr + " COMPOUND : " + TCollection_AsciiString(nbTypes[TopAbs_COMPOUND]) + "\n";
1425 Astr = Astr + " SHAPE : " + TCollection_AsciiString(aMapOfShape.Extent());
1427 catch (Standard_Failure) {
1428 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1429 SetErrorCode(aFail->GetMessageString());
1438 //=======================================================================
1439 //function : CheckSingularCase
1440 //purpose : auxilary for GetMinDistance()
1441 // workaround for bugs 19899, 19908 and 19910 from Mantis
1442 //=======================================================================
1443 static double CheckSingularCase(const TopoDS_Shape& aSh1,
1444 const TopoDS_Shape& aSh2,
1445 gp_Pnt& Ptmp1, gp_Pnt& Ptmp2)
1447 bool IsChange1 = false;
1448 double AddDist1 = 0.0;
1449 TopExp_Explorer anExp;
1450 TopoDS_Shape tmpSh1, tmpSh2;
1452 for ( anExp.Init( aSh1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1454 tmpSh1 = anExp.Current();
1457 TopoDS_Shape sh = aSh1;
1458 while(sh.ShapeType()==TopAbs_COMPOUND) {
1459 TopoDS_Iterator it(sh);
1462 Handle(Geom_Surface) S = BRep_Tool::Surface(TopoDS::Face(tmpSh1));
1463 if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1464 S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1465 if( sh.ShapeType()==TopAbs_SHELL || sh.ShapeType()==TopAbs_FACE ) {
1468 // changes for 0020677: EDF 1219 GEOM: MinDistance gives 0 instead of 20.88
1469 //S->Bounds(U1,U2,V1,V2); changed by
1470 ShapeAnalysis::GetFaceUVBounds(TopoDS::Face(tmpSh1),U1,U2,V1,V2);
1471 // end of changes for 020677 (dmv)
1472 Handle(Geom_RectangularTrimmedSurface) TrS1 =
1473 new Geom_RectangularTrimmedSurface(S,U1,(U1+U2)/2.,V1,V2);
1474 Handle(Geom_RectangularTrimmedSurface) TrS2 =
1475 new Geom_RectangularTrimmedSurface(S,(U1+U2)/2.,U2,V1,V2);
1478 TopoDS_Compound Comp;
1479 B.MakeCompound(Comp);
1480 B.MakeFace(F1,TrS1,1.e-7);
1482 B.MakeFace(F2,TrS2,1.e-7);
1484 Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
1486 sfs->SetPrecision(1.e-6);
1487 sfs->SetMaxTolerance(1.0);
1489 tmpSh1 = sfs->Shape();
1493 if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ) {
1494 Handle(Geom_SphericalSurface) SS = Handle(Geom_SphericalSurface)::DownCast(S);
1495 gp_Pnt PC = SS->Location();
1498 B.MakeVertex(V,PC,1.e-7);
1500 AddDist1 = SS->Radius();
1504 Handle(Geom_ToroidalSurface) TS = Handle(Geom_ToroidalSurface)::DownCast(S);
1505 gp_Ax3 ax3 = TS->Position();
1506 Handle(Geom_Circle) C = new Geom_Circle(ax3.Ax2(),TS->MajorRadius());
1509 B.MakeEdge(E,C,1.e-7);
1511 AddDist1 = TS->MinorRadius();
1521 bool IsChange2 = false;
1522 double AddDist2 = 0.0;
1524 for ( anExp.Init( aSh2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1526 tmpSh2 = anExp.Current();
1529 TopoDS_Shape sh = aSh2;
1530 while(sh.ShapeType()==TopAbs_COMPOUND) {
1531 TopoDS_Iterator it(sh);
1534 Handle(Geom_Surface) S = BRep_Tool::Surface(TopoDS::Face(tmpSh2));
1535 if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1536 S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1537 if( sh.ShapeType()==TopAbs_SHELL || sh.ShapeType()==TopAbs_FACE ) {
1540 //S->Bounds(U1,U2,V1,V2);
1541 ShapeAnalysis::GetFaceUVBounds(TopoDS::Face(tmpSh2),U1,U2,V1,V2);
1542 Handle(Geom_RectangularTrimmedSurface) TrS1 =
1543 new Geom_RectangularTrimmedSurface(S,U1,(U1+U2)/2.,V1,V2);
1544 Handle(Geom_RectangularTrimmedSurface) TrS2 =
1545 new Geom_RectangularTrimmedSurface(S,(U1+U2)/2.,U2,V1,V2);
1548 TopoDS_Compound Comp;
1549 B.MakeCompound(Comp);
1550 B.MakeFace(F1,TrS1,1.e-7);
1552 B.MakeFace(F2,TrS2,1.e-7);
1554 Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
1556 sfs->SetPrecision(1.e-6);
1557 sfs->SetMaxTolerance(1.0);
1559 tmpSh2 = sfs->Shape();
1563 if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ) {
1564 Handle(Geom_SphericalSurface) SS = Handle(Geom_SphericalSurface)::DownCast(S);
1565 gp_Pnt PC = SS->Location();
1568 B.MakeVertex(V,PC,1.e-7);
1570 AddDist2 = SS->Radius();
1573 else if( S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1574 Handle(Geom_ToroidalSurface) TS = Handle(Geom_ToroidalSurface)::DownCast(S);
1575 gp_Ax3 ax3 = TS->Position();
1576 Handle(Geom_Circle) C = new Geom_Circle(ax3.Ax2(),TS->MajorRadius());
1579 B.MakeEdge(E,C,1.e-7);
1581 AddDist2 = TS->MinorRadius();
1592 if( !IsChange1 && !IsChange2 )
1595 BRepExtrema_DistShapeShape dst(tmpSh1,tmpSh2);
1597 double MinDist = 1.e9;
1598 gp_Pnt PMin1, PMin2, P1, P2;
1599 for (int i = 1; i <= dst.NbSolution(); i++) {
1600 P1 = dst.PointOnShape1(i);
1601 P2 = dst.PointOnShape2(i);
1602 Standard_Real Dist = P1.Distance(P2);
1603 if (MinDist > Dist) {
1614 gp_Dir aDir(gp_Vec(PMin1,PMin2));
1615 if( MinDist > (AddDist1+AddDist2) ) {
1616 Ptmp1 = gp_Pnt( PMin1.X() + aDir.X()*AddDist1,
1617 PMin1.Y() + aDir.Y()*AddDist1,
1618 PMin1.Z() + aDir.Z()*AddDist1 );
1619 Ptmp2 = gp_Pnt( PMin2.X() - aDir.X()*AddDist2,
1620 PMin2.Y() - aDir.Y()*AddDist2,
1621 PMin2.Z() - aDir.Z()*AddDist2 );
1622 return (MinDist - AddDist1 - AddDist2);
1625 if( AddDist1 > 0 ) {
1626 Ptmp1 = gp_Pnt( PMin1.X() + aDir.X()*AddDist1,
1627 PMin1.Y() + aDir.Y()*AddDist1,
1628 PMin1.Z() + aDir.Z()*AddDist1 );
1632 Ptmp2 = gp_Pnt( PMin2.X() - aDir.X()*AddDist2,
1633 PMin2.Y() - aDir.Y()*AddDist2,
1634 PMin2.Z() - aDir.Z()*AddDist2 );
1639 double res = MinDist - AddDist1 - AddDist2;
1640 if(res<0.) res = 0.0;
1646 static bool CheckSingularCase(const TopoDS_Shape& aSh1,
1647 const TopoDS_Shape& aSh2,
1650 TopExp_Explorer anExp;
1651 TopoDS_Shape tmpSh1, tmpSh2;
1653 for ( anExp.Init( aSh1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1655 tmpSh1 = anExp.Current();
1658 Handle(Geom_Surface) S1 = BRep_Tool::Surface(TopoDS::Face(tmpSh1));
1659 if( S1->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1660 S1->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1662 for ( anExp.Init( aSh2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1664 tmpSh2 = anExp.Current();
1665 Handle(Geom_Surface) S2 = BRep_Tool::Surface(TopoDS::Face(tmpSh2));
1666 GeomAPI_IntSS ISS(S1,S2,1.e-7);
1668 for(int i=1; i<=ISS.NbLines(); i++) {
1669 Handle(Geom_Curve) C3d = ISS.Line(i);
1672 B.MakeEdge(E,C3d,1.e-7);
1673 BRepExtrema_DistShapeShape dst(tmpSh2,E);
1675 gp_Pnt PMin1, PMin2, P1, P2;
1676 double MinDist = 1.e9;
1677 for (int i = 1; i <= dst.NbSolution(); i++) {
1678 P1 = dst.PointOnShape1(i);
1679 P2 = dst.PointOnShape2(i);
1680 Standard_Real Dist = P1.Distance(P2);
1681 if (MinDist > Dist) {
1695 for ( anExp.Init( aSh2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1697 tmpSh1 = anExp.Current();
1700 Handle(Geom_Surface) S1 = BRep_Tool::Surface(TopoDS::Face(tmpSh1));
1701 if( S1->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1702 S1->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1704 for ( anExp.Init( aSh1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1706 tmpSh2 = anExp.Current();
1707 Handle(Geom_Surface) S2 = BRep_Tool::Surface(TopoDS::Face(tmpSh2));
1708 GeomAPI_IntSS ISS(S1,S2,1.e-7);
1710 for(int i=1; i<=ISS.NbLines(); i++) {
1711 Handle(Geom_Curve) C3d = ISS.Line(i);
1714 B.MakeEdge(E,C3d,1.e-7);
1715 BRepExtrema_DistShapeShape dst(tmpSh2,E);
1718 double MinDist = 1.e9;
1719 for (int i = 1; i <= dst.NbSolution(); i++) {
1720 P1 = dst.PointOnShape1(i);
1721 P2 = dst.PointOnShape2(i);
1722 Standard_Real Dist = P1.Distance(P2);
1723 if (MinDist > Dist) {
1741 //=============================================================================
1745 //=============================================================================
1746 std::vector<bool> GEOMImpl_IMeasureOperations::AreCoordsInside(Handle(GEOM_Object) theShape,
1747 const std::vector<double>& coords,
1750 std::vector<bool> res;
1751 if (!theShape.IsNull()) {
1752 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1753 if (!aRefShape.IsNull()) {
1754 TopoDS_Shape aShape = aRefShape->GetValue();
1755 if (!aShape.IsNull()) {
1756 BRepClass3d_SolidClassifier SC(aShape);
1757 unsigned int nb_points = coords.size()/3;
1758 for (int i = 0; i < nb_points; i++) {
1759 double x = coords[3*i];
1760 double y = coords[3*i+1];
1761 double z = coords[3*i+2];
1762 gp_Pnt aPnt(x, y, z);
1763 SC.Perform(aPnt, tolerance);
1764 res.push_back( ( SC.State() == TopAbs_IN ) || ( SC.State() == TopAbs_ON ) );
1772 //=============================================================================
1776 //=============================================================================
1777 Standard_Real GEOMImpl_IMeasureOperations::GetMinDistance
1778 (Handle(GEOM_Object) theShape1, Handle(GEOM_Object) theShape2,
1779 Standard_Real& X1, Standard_Real& Y1, Standard_Real& Z1,
1780 Standard_Real& X2, Standard_Real& Y2, Standard_Real& Z2)
1783 Standard_Real MinDist = 1.e9;
1785 if (theShape1.IsNull() || theShape2.IsNull()) return MinDist;
1787 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
1788 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
1789 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return MinDist;
1791 TopoDS_Shape aShape1 = aRefShape1->GetValue();
1792 TopoDS_Shape aShape2 = aRefShape2->GetValue();
1793 if (aShape1.IsNull() || aShape2.IsNull()) {
1794 SetErrorCode("One of Objects has NULL Shape");
1798 //Compute the parameters
1800 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1804 // Issue 0020231: A min distance bug with torus and vertex.
1805 // Make GetMinDistance() return zero if a sole VERTEX is inside any of SOLIDs
1807 // which of shapes consists of only one vertex?
1808 TopExp_Explorer exp1(aShape1,TopAbs_VERTEX), exp2(aShape2,TopAbs_VERTEX);
1809 TopoDS_Shape V1 = exp1.More() ? exp1.Current() : TopoDS_Shape();
1810 TopoDS_Shape V2 = exp2.More() ? exp2.Current() : TopoDS_Shape();
1811 exp1.Next(); exp2.Next();
1812 if ( exp1.More() ) V1.Nullify();
1813 if ( exp2.More() ) V2.Nullify();
1814 // vertex and container of solids
1815 TopoDS_Shape V = V1.IsNull() ? V2 : V1;
1816 TopoDS_Shape S = V1.IsNull() ? aShape1 : aShape2;
1817 if ( !V.IsNull() ) {
1818 // classify vertex against solids
1819 gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( V ) );
1820 for ( exp1.Init( S, TopAbs_SOLID ); exp1.More(); exp1.Next() ) {
1821 BRepClass3d_SolidClassifier classifier( exp1.Current(), p, 1e-6);
1822 if ( classifier.State() == TopAbs_IN ) {
1823 p.Coord(X1, Y1, Z1);
1824 p.Coord(X2, Y2, Z2);
1830 // End Issue 0020231
1833 // additional workaround for bugs 19899, 19908 and 19910 from Mantis
1834 gp_Pnt Ptmp1, Ptmp2;
1835 double dist = CheckSingularCase(aShape1, aShape2, Ptmp1, Ptmp2);
1837 Ptmp1.Coord(X1, Y1, Z1);
1838 Ptmp2.Coord(X2, Y2, Z2);
1843 BRepExtrema_DistShapeShape dst (aShape1, aShape2);
1845 gp_Pnt PMin1, PMin2, P1, P2;
1847 for (int i = 1; i <= dst.NbSolution(); i++) {
1848 P1 = dst.PointOnShape1(i);
1849 P2 = dst.PointOnShape2(i);
1851 Standard_Real Dist = P1.Distance(P2);
1852 if (MinDist > Dist) {
1859 PMin1.Coord(X1, Y1, Z1);
1860 PMin2.Coord(X2, Y2, Z2);
1863 catch (Standard_Failure) {
1864 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1865 SetErrorCode(aFail->GetMessageString());
1873 //=======================================================================
1875 * Get coordinates of point
1877 //=======================================================================
1878 void GEOMImpl_IMeasureOperations::PointCoordinates (Handle(GEOM_Object) theShape,
1879 Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ)
1883 if (theShape.IsNull())
1886 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1887 if (aRefShape.IsNull())
1890 TopoDS_Shape aShape = aRefShape->GetValue();
1891 if (aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX)
1893 SetErrorCode( "Shape must be a vertex" );
1898 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1901 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
1908 catch (Standard_Failure)
1910 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1911 SetErrorCode( aFail->GetMessageString() );
1915 //=======================================================================
1917 * Compute angle (in degrees) between two lines
1919 //=======================================================================
1920 Standard_Real GEOMImpl_IMeasureOperations::GetAngle (Handle(GEOM_Object) theLine1,
1921 Handle(GEOM_Object) theLine2)
1925 Standard_Real anAngle = -1.0;
1927 if (theLine1.IsNull() || theLine2.IsNull())
1930 Handle(GEOM_Function) aRefLine1 = theLine1->GetLastFunction();
1931 Handle(GEOM_Function) aRefLine2 = theLine2->GetLastFunction();
1932 if (aRefLine1.IsNull() || aRefLine2.IsNull())
1935 TopoDS_Shape aLine1 = aRefLine1->GetValue();
1936 TopoDS_Shape aLine2 = aRefLine2->GetValue();
1937 if (aLine1.IsNull() || aLine2.IsNull() ||
1938 aLine1.ShapeType() != TopAbs_EDGE ||
1939 aLine2.ShapeType() != TopAbs_EDGE)
1941 SetErrorCode("Two edges must be given");
1946 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1949 TopoDS_Edge E1 = TopoDS::Edge(aLine1);
1950 TopoDS_Edge E2 = TopoDS::Edge(aLine2);
1953 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp,lp);
1954 Handle(Geom_Curve) C2 = BRep_Tool::Curve(E2,fp,lp);
1956 if ( C1.IsNull() || C2.IsNull() ||
1957 !C1->IsKind(STANDARD_TYPE(Geom_Line)) ||
1958 !C2->IsKind(STANDARD_TYPE(Geom_Line)))
1960 SetErrorCode("The edges must be linear");
1964 Handle(Geom_Line) L1 = Handle(Geom_Line)::DownCast(C1);
1965 Handle(Geom_Line) L2 = Handle(Geom_Line)::DownCast(C2);
1967 gp_Lin aLin1 = L1->Lin();
1968 gp_Lin aLin2 = L2->Lin();
1970 anAngle = aLin1.Angle(aLin2);
1971 anAngle /= PI180; // convert radians into degrees
1973 if (anAngle > 90.0) {
1974 anAngle = 180.0 - anAngle;
1979 catch (Standard_Failure)
1981 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1982 SetErrorCode(aFail->GetMessageString());
1988 //=======================================================================
1990 * Compute angle (in degrees) between two vectors
1992 //=======================================================================
1993 Standard_Real GEOMImpl_IMeasureOperations::GetAngleBtwVectors (Handle(GEOM_Object) theVec1,
1994 Handle(GEOM_Object) theVec2)
1998 Standard_Real anAngle = -1.0;
2000 if (theVec1.IsNull() || theVec2.IsNull())
2003 Handle(GEOM_Function) aRefVec1 = theVec1->GetLastFunction();
2004 Handle(GEOM_Function) aRefVec2 = theVec2->GetLastFunction();
2005 if (aRefVec1.IsNull() || aRefVec2.IsNull())
2008 TopoDS_Shape aVec1 = aRefVec1->GetValue();
2009 TopoDS_Shape aVec2 = aRefVec2->GetValue();
2010 if (aVec1.IsNull() || aVec2.IsNull() ||
2011 aVec1.ShapeType() != TopAbs_EDGE ||
2012 aVec2.ShapeType() != TopAbs_EDGE)
2014 SetErrorCode("Two edges must be given");
2019 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2022 TopoDS_Edge aE1 = TopoDS::Edge(aVec1);
2023 TopoDS_Edge aE2 = TopoDS::Edge(aVec2);
2025 TopoDS_Vertex aP11, aP12, aP21, aP22;
2026 TopExp::Vertices(aE1, aP11, aP12, Standard_True);
2027 TopExp::Vertices(aE2, aP21, aP22, Standard_True);
2028 if (aP11.IsNull() || aP12.IsNull() || aP21.IsNull() || aP22.IsNull()) {
2029 SetErrorCode("Bad edge given");
2033 gp_Vec aV1 (BRep_Tool::Pnt(aP11), BRep_Tool::Pnt(aP12));
2034 gp_Vec aV2 (BRep_Tool::Pnt(aP21), BRep_Tool::Pnt(aP22)) ;
2036 anAngle = aV1.Angle(aV2);
2037 anAngle /= PI180; // convert radians into degrees
2041 catch (Standard_Failure)
2043 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2044 SetErrorCode(aFail->GetMessageString());
2051 //=============================================================================
2053 * CurveCurvatureByParam
2055 //=============================================================================
2056 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByParam
2057 (Handle(GEOM_Object) theCurve, Standard_Real& theParam)
2060 Standard_Real aRes = -1.0;
2062 if(theCurve.IsNull()) return aRes;
2064 Handle(GEOM_Function) aRefShape = theCurve->GetLastFunction();
2065 if(aRefShape.IsNull()) return aRes;
2067 TopoDS_Shape aShape = aRefShape->GetValue();
2068 if(aShape.IsNull()) {
2069 SetErrorCode("One of Objects has NULL Shape");
2073 Standard_Real aFP, aLP, aP;
2074 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aFP, aLP);
2075 aP = aFP + (aLP - aFP) * theParam;
2077 if(aCurve.IsNull()) return aRes;
2081 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2084 GeomLProp_CLProps Prop = GeomLProp_CLProps
2085 (aCurve, aP, 2, Precision::Confusion());
2086 aRes = fabs(Prop.Curvature());
2089 catch (Standard_Failure) {
2090 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2091 SetErrorCode(aFail->GetMessageString());
2095 if( aRes > Precision::Confusion() )
2104 //=============================================================================
2106 * CurveCurvatureByPoint
2108 //=============================================================================
2109 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByPoint
2110 (Handle(GEOM_Object) theCurve, Handle(GEOM_Object) thePoint)
2113 Standard_Real aRes = -1.0;
2115 if( theCurve.IsNull() || thePoint.IsNull() ) return aRes;
2117 Handle(GEOM_Function) aRefCurve = theCurve->GetLastFunction();
2118 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2119 if( aRefCurve.IsNull() || aRefPoint.IsNull() ) return aRes;
2121 TopoDS_Edge anEdge = TopoDS::Edge(aRefCurve->GetValue());
2122 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2123 if( anEdge.IsNull() || aPnt.IsNull() ) {
2124 SetErrorCode("One of Objects has NULL Shape");
2128 Standard_Real aFP, aLP;
2129 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFP, aLP);
2130 if(aCurve.IsNull()) return aRes;
2131 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2135 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2138 GeomAPI_ProjectPointOnCurve PPCurve(aPoint, aCurve, aFP, aLP);
2139 if(PPCurve.NbPoints()>0) {
2140 GeomLProp_CLProps Prop = GeomLProp_CLProps
2141 (aCurve, PPCurve.LowerDistanceParameter(), 2, Precision::Confusion());
2142 aRes = fabs(Prop.Curvature());
2146 catch (Standard_Failure) {
2147 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2148 SetErrorCode(aFail->GetMessageString());
2152 if( aRes > Precision::Confusion() )
2161 //=============================================================================
2163 * getSurfaceCurvatures
2165 //=============================================================================
2166 Standard_Real GEOMImpl_IMeasureOperations::getSurfaceCurvatures
2167 (const Handle(Geom_Surface)& aSurf,
2168 Standard_Real theUParam,
2169 Standard_Real theVParam,
2170 Standard_Boolean theNeedMaxCurv)
2173 Standard_Real aRes = 1.0;
2175 if (aSurf.IsNull()) return aRes;
2178 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2181 GeomLProp_SLProps Prop = GeomLProp_SLProps
2182 (aSurf, theUParam, theVParam, 2, Precision::Confusion());
2183 if(Prop.IsCurvatureDefined()) {
2184 if(Prop.IsUmbilic()) {
2185 //cout<<"is umbilic"<<endl;
2186 aRes = fabs(Prop.MeanCurvature());
2189 //cout<<"is not umbilic"<<endl;
2190 double c1 = fabs(Prop.MaxCurvature());
2191 double c2 = fabs(Prop.MinCurvature());
2200 catch (Standard_Failure) {
2201 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2202 SetErrorCode(aFail->GetMessageString());
2206 if( fabs(aRes) > Precision::Confusion() )
2215 //=============================================================================
2217 * MaxSurfaceCurvatureByParam
2219 //=============================================================================
2220 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByParam
2221 (Handle(GEOM_Object) theSurf,
2222 Standard_Real& theUParam,
2223 Standard_Real& theVParam)
2226 Standard_Real aRes = -1.0;
2228 if (theSurf.IsNull()) return aRes;
2230 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2231 if(aRefShape.IsNull()) return aRes;
2233 TopoDS_Shape aShape = aRefShape->GetValue();
2234 if(aShape.IsNull()) {
2235 SetErrorCode("One of Objects has NULL Shape");
2239 TopoDS_Face F = TopoDS::Face(aShape);
2240 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2242 //Compute the parameters
2243 Standard_Real U1,U2,V1,V2;
2244 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2245 Standard_Real U = U1 + (U2-U1)*theUParam;
2246 Standard_Real V = V1 + (V2-V1)*theVParam;
2248 return getSurfaceCurvatures(aSurf, U, V, true);
2252 //=============================================================================
2254 * MaxSurfaceCurvatureByPoint
2256 //=============================================================================
2257 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByPoint
2258 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2261 Standard_Real aRes = -1.0;
2263 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2265 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2266 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2267 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2269 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2270 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2271 if( aFace.IsNull() || aPnt.IsNull() ) {
2272 SetErrorCode("One of Objects has NULL Shape");
2276 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2277 if(aSurf.IsNull()) return aRes;
2278 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2280 //Compute the parameters
2281 ShapeAnalysis_Surface sas(aSurf);
2282 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2284 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), true);
2288 //=============================================================================
2290 * MinSurfaceCurvatureByParam
2292 //=============================================================================
2293 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByParam
2294 (Handle(GEOM_Object) theSurf,
2295 Standard_Real& theUParam,
2296 Standard_Real& theVParam)
2299 Standard_Real aRes = -1.0;
2301 if (theSurf.IsNull()) return aRes;
2303 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2304 if(aRefShape.IsNull()) return aRes;
2306 TopoDS_Shape aShape = aRefShape->GetValue();
2307 if(aShape.IsNull()) {
2308 SetErrorCode("One of Objects has NULL Shape");
2312 TopoDS_Face F = TopoDS::Face(aShape);
2313 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2315 //Compute the parameters
2316 Standard_Real U1,U2,V1,V2;
2317 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2318 Standard_Real U = U1 + (U2-U1)*theUParam;
2319 Standard_Real V = V1 + (V2-V1)*theVParam;
2321 return getSurfaceCurvatures(aSurf, U, V, false);
2325 //=============================================================================
2327 * MinSurfaceCurvatureByPoint
2329 //=============================================================================
2330 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByPoint
2331 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2334 Standard_Real aRes = -1.0;
2336 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2338 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2339 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2340 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2342 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2343 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2344 if( aFace.IsNull() || aPnt.IsNull() ) {
2345 SetErrorCode("One of Objects has NULL Shape");
2349 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2350 if(aSurf.IsNull()) return aRes;
2351 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2353 //Compute the parameters
2354 ShapeAnalysis_Surface sas(aSurf);
2355 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2357 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), false);
2361 //=======================================================================
2362 //function : StructuralDump
2363 //purpose : Structural (data exchange) style of output.
2364 //=======================================================================
2365 void GEOMImpl_IMeasureOperations::StructuralDump (const BRepCheck_Analyzer& theAna,
2366 const TopoDS_Shape& theShape,
2367 TCollection_AsciiString& theDump)
2371 theDump += " -- The Shape has problems :\n";
2372 theDump += " Check Count\n";
2373 theDump += " ------------------------------------------------\n";
2375 Standard_Integer last_stat = (Standard_Integer)BRepCheck_CheckFail;
2376 Handle(TColStd_HArray1OfInteger) NbProblems =
2377 new TColStd_HArray1OfInteger(1, last_stat);
2378 for (i = 1; i <= last_stat; i++)
2379 NbProblems->SetValue(i,0);
2381 Handle(TopTools_HSequenceOfShape) sl;
2382 sl = new TopTools_HSequenceOfShape();
2383 TopTools_DataMapOfShapeListOfShape theMap;
2385 GetProblemShapes(theAna, theShape, sl, NbProblems, theMap);
2388 Standard_Integer count = 0;
2389 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnCurve);
2391 theDump += " Invalid Point on Curve ................... ";
2392 theDump += TCollection_AsciiString(count) + "\n";
2394 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnCurveOnSurface);
2396 theDump += " Invalid Point on CurveOnSurface .......... ";
2397 theDump += TCollection_AsciiString(count) + "\n";
2399 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnSurface);
2401 theDump += " Invalid Point on Surface ................. ";
2402 theDump += TCollection_AsciiString(count) + "\n";
2404 count = NbProblems->Value((Standard_Integer)BRepCheck_No3DCurve);
2406 theDump += " No 3D Curve .............................. ";
2407 theDump += TCollection_AsciiString(count) + "\n";
2409 count = NbProblems->Value((Standard_Integer)BRepCheck_Multiple3DCurve);
2411 theDump += " Multiple 3D Curve ........................ ";
2412 theDump += TCollection_AsciiString(count) + "\n";
2414 count = NbProblems->Value((Standard_Integer)BRepCheck_Invalid3DCurve);
2416 theDump += " Invalid 3D Curve ......................... ";
2417 theDump += TCollection_AsciiString(count) + "\n";
2419 count = NbProblems->Value((Standard_Integer)BRepCheck_NoCurveOnSurface);
2421 theDump += " No Curve on Surface ...................... ";
2422 theDump += TCollection_AsciiString(count) + "\n";
2424 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidCurveOnSurface);
2426 theDump += " Invalid Curve on Surface ................. ";
2427 theDump += TCollection_AsciiString(count) + "\n";
2429 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidCurveOnClosedSurface);
2431 theDump += " Invalid Curve on closed Surface .......... ";
2432 theDump += TCollection_AsciiString(count) + "\n";
2434 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidSameRangeFlag);
2436 theDump += " Invalid SameRange Flag ................... ";
2437 theDump += TCollection_AsciiString(count) + "\n";
2439 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidSameParameterFlag);
2441 theDump += " Invalid SameParameter Flag ............... ";
2442 theDump += TCollection_AsciiString(count) + "\n";
2444 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidDegeneratedFlag);
2446 theDump += " Invalid Degenerated Flag ................. ";
2447 theDump += TCollection_AsciiString(count) + "\n";
2449 count = NbProblems->Value((Standard_Integer)BRepCheck_FreeEdge);
2451 theDump += " Free Edge ................................ ";
2452 theDump += TCollection_AsciiString(count) + "\n";
2454 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidMultiConnexity);
2456 theDump += " Invalid MultiConnexity ................... ";
2457 theDump += TCollection_AsciiString(count) + "\n";
2459 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidRange);
2461 theDump += " Invalid Range ............................ ";
2462 theDump += TCollection_AsciiString(count) + "\n";
2464 count = NbProblems->Value((Standard_Integer)BRepCheck_EmptyWire);
2466 theDump += " Empty Wire ............................... ";
2467 theDump += TCollection_AsciiString(count) + "\n";
2469 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantEdge);
2471 theDump += " Redundant Edge ........................... ";
2472 theDump += TCollection_AsciiString(count) + "\n";
2474 count = NbProblems->Value((Standard_Integer)BRepCheck_SelfIntersectingWire);
2476 theDump += " Self Intersecting Wire ................... ";
2477 theDump += TCollection_AsciiString(count) + "\n";
2479 count = NbProblems->Value((Standard_Integer)BRepCheck_NoSurface);
2481 theDump += " No Surface ............................... ";
2482 theDump += TCollection_AsciiString(count) + "\n";
2484 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidWire);
2486 theDump += " Invalid Wire ............................. ";
2487 theDump += TCollection_AsciiString(count) + "\n";
2489 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantWire);
2491 theDump += " Redundant Wire ........................... ";
2492 theDump += TCollection_AsciiString(count) + "\n";
2494 count = NbProblems->Value((Standard_Integer)BRepCheck_IntersectingWires);
2496 theDump += " Intersecting Wires ....................... ";
2497 theDump += TCollection_AsciiString(count) + "\n";
2499 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidImbricationOfWires);
2501 theDump += " Invalid Imbrication of Wires ............. ";
2502 theDump += TCollection_AsciiString(count) + "\n";
2504 count = NbProblems->Value((Standard_Integer)BRepCheck_EmptyShell);
2506 theDump += " Empty Shell .............................. ";
2507 theDump += TCollection_AsciiString(count) + "\n";
2509 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantFace);
2511 theDump += " Redundant Face ........................... ";
2512 theDump += TCollection_AsciiString(count) + "\n";
2514 count = NbProblems->Value((Standard_Integer)BRepCheck_UnorientableShape);
2516 theDump += " Unorientable Shape ....................... ";
2517 theDump += TCollection_AsciiString(count) + "\n";
2519 count = NbProblems->Value((Standard_Integer)BRepCheck_NotClosed);
2521 theDump += " Not Closed ............................... ";
2522 theDump += TCollection_AsciiString(count) + "\n";
2524 count = NbProblems->Value((Standard_Integer)BRepCheck_NotConnected);
2526 theDump += " Not Connected ............................ ";
2527 theDump += TCollection_AsciiString(count) + "\n";
2529 count = NbProblems->Value((Standard_Integer)BRepCheck_SubshapeNotInShape);
2531 theDump += " Subshape not in Shape .................... ";
2532 theDump += TCollection_AsciiString(count) + "\n";
2534 count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientation);
2536 theDump += " Bad Orientation .......................... ";
2537 theDump += TCollection_AsciiString(count) + "\n";
2539 count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientationOfSubshape);
2541 theDump += " Bad Orientation of Subshape .............. ";
2542 theDump += TCollection_AsciiString(count) + "\n";
2544 count = NbProblems->Value((Standard_Integer)BRepCheck_CheckFail);
2546 theDump += " checkshape failure ....................... ";
2547 theDump += TCollection_AsciiString(count) + "\n";
2550 theDump += " ------------------------------------------------\n";
2551 theDump += "*** Shapes with problems : ";
2552 theDump += TCollection_AsciiString(sl->Length()) + "\n";
2554 Standard_Integer nbv, nbe, nbw, nbf, nbs, nbo;
2555 nbv = nbe = nbw = nbf = nbs = nbo = 0;
2557 for (i = 1; i <= sl->Length(); i++) {
2558 TopoDS_Shape shi = sl->Value(i);
2559 TopAbs_ShapeEnum sti = shi.ShapeType();
2561 case TopAbs_VERTEX : nbv++; break;
2562 case TopAbs_EDGE : nbe++; break;
2563 case TopAbs_WIRE : nbw++; break;
2564 case TopAbs_FACE : nbf++; break;
2565 case TopAbs_SHELL : nbs++; break;
2566 case TopAbs_SOLID : nbo++; break;
2572 theDump += "VERTEX : ";
2573 if (nbv < 10) theDump += " ";
2574 theDump += TCollection_AsciiString(nbv) + "\n";
2577 theDump += "EDGE : ";
2578 if (nbe < 10) theDump += " ";
2579 theDump += TCollection_AsciiString(nbe) + "\n";
2582 theDump += "WIRE : ";
2583 if (nbw < 10) theDump += " ";
2584 theDump += TCollection_AsciiString(nbw) + "\n";
2587 theDump += "FACE : ";
2588 if (nbf < 10) theDump += " ";
2589 theDump += TCollection_AsciiString(nbf) + "\n";
2592 theDump += "SHELL : ";
2593 if (nbs < 10) theDump += " ";
2594 theDump += TCollection_AsciiString(nbs) + "\n";
2597 theDump += "SOLID : ";
2598 if (nbo < 10) theDump += " ";
2599 theDump += TCollection_AsciiString(nbo) + "\n";
2604 //=======================================================================
2605 //function : GetProblemShapes
2606 // purpose : for StructuralDump
2607 //=======================================================================
2608 void GEOMImpl_IMeasureOperations::GetProblemShapes (const BRepCheck_Analyzer& theAna,
2609 const TopoDS_Shape& theShape,
2610 Handle(TopTools_HSequenceOfShape)& sl,
2611 Handle(TColStd_HArray1OfInteger)& NbProblems,
2612 TopTools_DataMapOfShapeListOfShape& theMap)
2614 for (TopoDS_Iterator iter(theShape); iter.More(); iter.Next()) {
2615 GetProblemShapes(theAna, iter.Value(), sl, NbProblems, theMap);
2617 TopAbs_ShapeEnum styp = theShape.ShapeType();
2618 BRepCheck_ListIteratorOfListOfStatus itl;
2619 TopTools_ListOfShape empty;
2620 if (!theMap.IsBound(theShape)) {
2621 theMap.Bind(theShape,empty);
2623 if (!theAna.Result(theShape).IsNull()) {
2624 itl.Initialize(theAna.Result(theShape)->Status());
2625 // !!! May be, we have to print all the problems, not only the first one ?
2626 if (itl.Value() != BRepCheck_NoError) {
2627 sl->Append(theShape);
2628 BRepCheck_Status stat = itl.Value();
2629 NbProblems->SetValue((Standard_Integer)stat,
2630 NbProblems->Value((Standard_Integer)stat) + 1);
2637 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_VERTEX, theMap);
2640 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_WIRE, theMap);
2641 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_EDGE, theMap);
2642 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_VERTEX, theMap);
2647 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_SHELL, theMap);
2654 //=======================================================================
2655 //function : Contains
2656 //=======================================================================
2657 static Standard_Boolean Contains (const TopTools_ListOfShape& L,
2658 const TopoDS_Shape& S)
2660 TopTools_ListIteratorOfListOfShape it;
2661 for (it.Initialize(L); it.More(); it.Next()) {
2662 if (it.Value().IsSame(S)) {
2663 return Standard_True;
2666 return Standard_False;
2669 //=======================================================================
2670 //function : GetProblemSub
2671 // purpose : for StructuralDump
2672 //=======================================================================
2673 void GEOMImpl_IMeasureOperations::GetProblemSub (const BRepCheck_Analyzer& theAna,
2674 const TopoDS_Shape& theShape,
2675 Handle(TopTools_HSequenceOfShape)& sl,
2676 Handle(TColStd_HArray1OfInteger)& NbProblems,
2677 const TopAbs_ShapeEnum Subtype,
2678 TopTools_DataMapOfShapeListOfShape& theMap)
2680 BRepCheck_ListIteratorOfListOfStatus itl;
2681 TopExp_Explorer exp;
2682 for (exp.Init(theShape, Subtype); exp.More(); exp.Next()) {
2683 const TopoDS_Shape& sub = exp.Current();
2685 const Handle(BRepCheck_Result)& res = theAna.Result(sub);
2686 for (res->InitContextIterator();
2687 res->MoreShapeInContext();
2688 res->NextShapeInContext()) {
2689 if (res->ContextualShape().IsSame(theShape) && !Contains(theMap(sub), theShape)) {
2690 theMap(sub).Append(theShape);
2691 itl.Initialize(res->StatusOnShape());
2693 if (itl.Value() != BRepCheck_NoError) {
2694 Standard_Integer ii = 0;
2696 for (ii = 1; ii <= sl->Length(); ii++)
2697 if (sl->Value(ii).IsSame(sub)) break;
2699 if (ii > sl->Length()) {
2701 BRepCheck_Status stat = itl.Value();
2702 NbProblems->SetValue((Standard_Integer)stat,
2703 NbProblems->Value((Standard_Integer)stat) + 1);
2705 for (ii = 1; ii <= sl->Length(); ii++)
2706 if (sl->Value(ii).IsSame(theShape)) break;
2707 if (ii > sl->Length()) {
2708 sl->Append(theShape);
2709 BRepCheck_Status stat = itl.Value();
2710 NbProblems->SetValue((Standard_Integer)stat,
2711 NbProblems->Value((Standard_Integer)stat) + 1);