1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include <Standard_Stream.hxx>
24 #include <GEOMImpl_IMeasureOperations.hxx>
26 #include <GEOMImpl_Types.hxx>
27 #include <GEOMImpl_MeasureDriver.hxx>
28 #include <GEOMImpl_IMeasure.hxx>
29 #include <GEOMImpl_IShapesOperations.hxx>
31 #include <GEOMAlgo_ShapeInfo.hxx>
32 #include <GEOMAlgo_ShapeInfoFiller.hxx>
34 #include <GEOM_Function.hxx>
35 #include <GEOM_PythonDump.hxx>
37 #include <NMTTools_CheckerSI.hxx>
39 #include <NMTDS_Tools.hxx>
40 #include <NMTDS_InterfPool.hxx>
41 #include <NMTDS_PInterfPool.hxx>
42 #include <NMTDS_PairBoolean.hxx>
43 #include <NMTDS_ShapesDataStructure.hxx>
44 #include <NMTDS_ListIteratorOfListOfPairBoolean.hxx>
46 #include <Basics_OCCTVersion.hxx>
48 #include <utilities.h>
50 #include <Utils_ExceptHandlers.hxx>
53 #include <TFunction_DriverTable.hxx>
54 #include <TFunction_Driver.hxx>
55 #include <TFunction_Logbook.hxx>
56 #include <TDF_Tool.hxx>
58 #include <BRep_Builder.hxx>
59 #include <BRep_TFace.hxx>
60 #include <BRep_Tool.hxx>
61 #include <BRepAdaptor_Surface.hxx>
62 #include <BRepBuilderAPI_Copy.hxx>
63 #include <BRepBndLib.hxx>
64 #include <BRepCheck.hxx>
65 #include <BRepCheck_ListIteratorOfListOfStatus.hxx>
66 #include <BRepCheck_Result.hxx>
67 #include <BRepCheck_Shell.hxx>
68 #include <BRepClass3d_SolidClassifier.hxx>
69 #include <BRepExtrema_DistShapeShape.hxx>
70 #include <BRepGProp.hxx>
71 #include <BRepTools.hxx>
73 #include <Bnd_Box.hxx>
78 #include <TopoDS_Edge.hxx>
79 #include <TopoDS_Face.hxx>
80 #include <TopoDS_Shape.hxx>
81 #include <TopoDS_Vertex.hxx>
82 #include <TopoDS_Compound.hxx>
83 #include <TopoDS_Iterator.hxx>
84 #include <TopExp_Explorer.hxx>
85 #include <TopTools_MapOfShape.hxx>
86 #include <TopTools_ListOfShape.hxx>
87 #include <TopTools_ListIteratorOfListOfShape.hxx>
89 #include <ShapeAnalysis.hxx>
90 #include <ShapeAnalysis_Surface.hxx>
91 #include <ShapeFix_Shape.hxx>
93 #include <GeomAPI_IntSS.hxx>
94 #include <GeomAPI_ProjectPointOnCurve.hxx>
96 #include <GeomAbs_SurfaceType.hxx>
98 #include <Geom_BezierSurface.hxx>
99 #include <Geom_BSplineSurface.hxx>
100 #include <Geom_Circle.hxx>
101 #include <Geom_ConicalSurface.hxx>
102 #include <Geom_CylindricalSurface.hxx>
103 #include <Geom_Line.hxx>
104 #include <Geom_OffsetSurface.hxx>
105 #include <Geom_Plane.hxx>
106 #include <Geom_RectangularTrimmedSurface.hxx>
107 #include <Geom_SphericalSurface.hxx>
108 #include <Geom_Surface.hxx>
109 #include <Geom_SurfaceOfLinearExtrusion.hxx>
110 #include <Geom_SurfaceOfRevolution.hxx>
111 #include <Geom_ToroidalSurface.hxx>
113 #include <GeomLProp_CLProps.hxx>
114 #include <GeomLProp_SLProps.hxx>
116 #include <GProp_GProps.hxx>
117 #include <GProp_PrincipalProps.hxx>
119 #include <gp_Pln.hxx>
120 #include <gp_Lin.hxx>
122 #include <Standard_Failure.hxx>
123 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
125 //=============================================================================
129 //=============================================================================
130 GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations (GEOM_Engine* theEngine, int theDocID)
131 : GEOM_IOperations(theEngine, theDocID)
133 MESSAGE("GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations");
136 //=============================================================================
140 //=============================================================================
141 GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations()
143 MESSAGE("GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations");
146 //=============================================================================
147 /*! Get kind and parameters of the given shape.
149 //=============================================================================
150 GEOMImpl_IMeasureOperations::ShapeKind GEOMImpl_IMeasureOperations::KindOfShape
151 (Handle(GEOM_Object) theShape,
152 Handle(TColStd_HSequenceOfInteger)& theIntegers,
153 Handle(TColStd_HSequenceOfReal)& theDoubles)
156 ShapeKind aKind = SK_NO_SHAPE;
158 if (theIntegers.IsNull()) theIntegers = new TColStd_HSequenceOfInteger;
159 else theIntegers->Clear();
161 if (theDoubles.IsNull()) theDoubles = new TColStd_HSequenceOfReal;
162 else theDoubles->Clear();
164 if (theShape.IsNull())
167 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
168 if (aRefShape.IsNull()) return aKind;
170 TopoDS_Shape aShape = aRefShape->GetValue();
171 if (aShape.IsNull()) return aKind;
173 int geom_type = theShape->GetType();
175 // check if it's advanced shape
176 if ( geom_type > ADVANCED_BASE ) {
182 GEOMAlgo_ShapeInfoFiller aSF;
183 aSF.SetShape(aShape);
185 Standard_Integer iErr = aSF.ErrorStatus();
187 SetErrorCode("Error in GEOMAlgo_ShapeInfoFiller");
190 const GEOMAlgo_ShapeInfo& anInfo = aSF.Info();
192 // Interprete results
193 TopAbs_ShapeEnum aType = anInfo.Type();
196 case TopAbs_COMPOUND:
197 case TopAbs_COMPSOLID:
199 // (+) geompy.kind.COMPOUND nb_solids nb_faces nb_edges nb_vertices
200 // (+) geompy.kind.COMPSOLID nb_solids nb_faces nb_edges nb_vertices
201 // ??? "nb_faces" - all faces or only 'standalone' faces?
202 if (aType == TopAbs_COMPOUND)
205 aKind = SK_COMPSOLID;
207 //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPOUND));
208 //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPSOLID));
209 theIntegers->Append(anInfo.NbSubShapes(TopAbs_SOLID));
210 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
211 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
212 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
218 // (+) geompy.kind.SHELL geompy.info.closed nb_faces nb_edges nb_vertices
219 // (+) geompy.kind.SHELL geompy.info.unclosed nb_faces nb_edges nb_vertices
222 theIntegers->Append((int)anInfo.KindOfClosed());
224 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
225 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
226 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
232 // (+) geompy.kind.WIRE geompy.info.closed nb_edges nb_vertices
233 // (+) geompy.kind.WIRE geompy.info.unclosed nb_edges nb_vertices
236 theIntegers->Append((int)anInfo.KindOfClosed());
238 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
239 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
247 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
250 case GEOMAlgo_KN_SPHERE:
251 // (+) geompy.kind.SPHERE xc yc zc R
255 gp_Pnt aC = anInfo.Location();
256 theDoubles->Append(aC.X());
257 theDoubles->Append(aC.Y());
258 theDoubles->Append(aC.Z());
260 theDoubles->Append(anInfo.Radius1());
263 case GEOMAlgo_KN_CYLINDER:
264 // (+) geompy.kind.CYLINDER xb yb zb dx dy dz R H
268 gp_Pnt aC = anInfo.Location();
269 theDoubles->Append(aC.X());
270 theDoubles->Append(aC.Y());
271 theDoubles->Append(aC.Z());
273 gp_Ax3 anAx3 = anInfo.Position();
274 gp_Dir aD = anAx3.Direction();
275 theDoubles->Append(aD.X());
276 theDoubles->Append(aD.Y());
277 theDoubles->Append(aD.Z());
279 theDoubles->Append(anInfo.Radius1());
280 theDoubles->Append(anInfo.Height());
283 case GEOMAlgo_KN_BOX:
284 // (+) geompy.kind.BOX xc yc zc ax ay az
288 gp_Pnt aC = anInfo.Location();
289 theDoubles->Append(aC.X());
290 theDoubles->Append(aC.Y());
291 theDoubles->Append(aC.Z());
293 gp_Ax3 anAx3 = anInfo.Position();
294 gp_Dir aD = anAx3.Direction();
295 gp_Dir aX = anAx3.XDirection();
298 if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
299 aX.IsParallel(gp::DX(), Precision::Angular())) {
300 theDoubles->Append(anInfo.Length()); // ax'
301 theDoubles->Append(anInfo.Width()); // ay'
302 theDoubles->Append(anInfo.Height()); // az'
304 else if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
305 aX.IsParallel(gp::DY(), Precision::Angular())) {
306 theDoubles->Append(anInfo.Width()); // ay'
307 theDoubles->Append(anInfo.Length()); // ax'
308 theDoubles->Append(anInfo.Height()); // az'
310 else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
311 aX.IsParallel(gp::DZ(), Precision::Angular())) {
312 theDoubles->Append(anInfo.Height()); // az'
313 theDoubles->Append(anInfo.Width()); // ay'
314 theDoubles->Append(anInfo.Length()); // ax'
316 else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
317 aX.IsParallel(gp::DY(), Precision::Angular())) {
318 theDoubles->Append(anInfo.Height()); // az'
319 theDoubles->Append(anInfo.Length()); // ax'
320 theDoubles->Append(anInfo.Width()); // ay'
322 else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
323 aX.IsParallel(gp::DZ(), Precision::Angular())) {
324 theDoubles->Append(anInfo.Width()); // ay'
325 theDoubles->Append(anInfo.Height()); // az'
326 theDoubles->Append(anInfo.Length()); // ax'
328 else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
329 aX.IsParallel(gp::DX(), Precision::Angular())) {
330 theDoubles->Append(anInfo.Length()); // ax'
331 theDoubles->Append(anInfo.Height()); // az'
332 theDoubles->Append(anInfo.Width()); // ay'
335 // (+) geompy.kind.ROTATED_BOX xo yo zo zx zy zz xx xy xz ax ay az
336 aKind = SK_ROTATED_BOX;
338 // Direction and XDirection
339 theDoubles->Append(aD.X());
340 theDoubles->Append(aD.Y());
341 theDoubles->Append(aD.Z());
343 theDoubles->Append(aX.X());
344 theDoubles->Append(aX.Y());
345 theDoubles->Append(aX.Z());
348 theDoubles->Append(anInfo.Length());
349 theDoubles->Append(anInfo.Width());
350 theDoubles->Append(anInfo.Height());
354 case GEOMAlgo_KN_TORUS:
355 // (+) geompy.kind.TORUS xc yc zc dx dy dz R_1 R_2
359 gp_Pnt aO = anInfo.Location();
360 theDoubles->Append(aO.X());
361 theDoubles->Append(aO.Y());
362 theDoubles->Append(aO.Z());
364 gp_Ax3 anAx3 = anInfo.Position();
365 gp_Dir aD = anAx3.Direction();
366 theDoubles->Append(aD.X());
367 theDoubles->Append(aD.Y());
368 theDoubles->Append(aD.Z());
370 theDoubles->Append(anInfo.Radius1());
371 theDoubles->Append(anInfo.Radius2());
374 case GEOMAlgo_KN_CONE:
375 // (+) geompy.kind.CONE xb yb zb dx dy dz R_1 R_2 H
379 gp_Pnt aO = anInfo.Location();
380 theDoubles->Append(aO.X());
381 theDoubles->Append(aO.Y());
382 theDoubles->Append(aO.Z());
384 gp_Ax3 anAx3 = anInfo.Position();
385 gp_Dir aD = anAx3.Direction();
386 theDoubles->Append(aD.X());
387 theDoubles->Append(aD.Y());
388 theDoubles->Append(aD.Z());
390 theDoubles->Append(anInfo.Radius1());
391 theDoubles->Append(anInfo.Radius2());
392 theDoubles->Append(anInfo.Height());
395 case GEOMAlgo_KN_POLYHEDRON:
396 // (+) geompy.kind.POLYHEDRON nb_faces nb_edges nb_vertices
398 aKind = SK_POLYHEDRON;
400 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
401 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
402 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
406 // (+) geompy.kind.SOLID nb_faces nb_edges nb_vertices
408 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
409 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
410 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
420 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
422 case GEOMAlgo_KN_SPHERE:
423 // (+) geompy.kind.SPHERE2D xc yc zc R
427 gp_Pnt aC = anInfo.Location();
428 theDoubles->Append(aC.X());
429 theDoubles->Append(aC.Y());
430 theDoubles->Append(aC.Z());
432 theDoubles->Append(anInfo.Radius1());
435 case GEOMAlgo_KN_CYLINDER:
436 // (+) geompy.kind.CYLINDER2D xb yb zb dx dy dz R H
438 aKind = SK_CYLINDER2D;
440 gp_Pnt aO = anInfo.Location();
441 theDoubles->Append(aO.X());
442 theDoubles->Append(aO.Y());
443 theDoubles->Append(aO.Z());
445 gp_Ax3 anAx3 = anInfo.Position();
446 gp_Dir aD = anAx3.Direction();
447 theDoubles->Append(aD.X());
448 theDoubles->Append(aD.Y());
449 theDoubles->Append(aD.Z());
451 theDoubles->Append(anInfo.Radius1());
452 theDoubles->Append(anInfo.Height());
455 case GEOMAlgo_KN_TORUS:
456 // (+) geompy.kind.TORUS2D xc yc zc dx dy dz R_1 R_2
460 gp_Pnt aO = anInfo.Location();
461 theDoubles->Append(aO.X());
462 theDoubles->Append(aO.Y());
463 theDoubles->Append(aO.Z());
465 gp_Ax3 anAx3 = anInfo.Position();
466 gp_Dir aD = anAx3.Direction();
467 theDoubles->Append(aD.X());
468 theDoubles->Append(aD.Y());
469 theDoubles->Append(aD.Z());
471 theDoubles->Append(anInfo.Radius1());
472 theDoubles->Append(anInfo.Radius2());
475 case GEOMAlgo_KN_CONE:
476 // (+) geompy.kind.CONE2D xc yc zc dx dy dz R_1 R_2 H
480 gp_Pnt aO = anInfo.Location();
481 theDoubles->Append(aO.X());
482 theDoubles->Append(aO.Y());
483 theDoubles->Append(aO.Z());
485 gp_Ax3 anAx3 = anInfo.Position();
486 gp_Dir aD = anAx3.Direction();
487 theDoubles->Append(aD.X());
488 theDoubles->Append(aD.Y());
489 theDoubles->Append(aD.Z());
491 theDoubles->Append(anInfo.Radius1());
492 theDoubles->Append(anInfo.Radius2());
493 theDoubles->Append(anInfo.Height());
496 case GEOMAlgo_KN_DISKCIRCLE:
497 // (+) geompy.kind.DISK_CIRCLE xc yc zc dx dy dz R
499 aKind = SK_DISK_CIRCLE;
501 gp_Pnt aC = anInfo.Location();
502 theDoubles->Append(aC.X());
503 theDoubles->Append(aC.Y());
504 theDoubles->Append(aC.Z());
506 gp_Ax3 anAx3 = anInfo.Position();
507 gp_Dir aD = anAx3.Direction();
508 theDoubles->Append(aD.X());
509 theDoubles->Append(aD.Y());
510 theDoubles->Append(aD.Z());
512 theDoubles->Append(anInfo.Radius1());
515 case GEOMAlgo_KN_DISKELLIPSE:
516 // (+) geompy.kind.DISK_ELLIPSE xc yc zc dx dy dz R_1 R_2
518 aKind = SK_DISK_ELLIPSE;
520 gp_Pnt aC = anInfo.Location();
521 theDoubles->Append(aC.X());
522 theDoubles->Append(aC.Y());
523 theDoubles->Append(aC.Z());
525 gp_Ax3 anAx3 = anInfo.Position();
526 gp_Dir aD = anAx3.Direction();
527 theDoubles->Append(aD.X());
528 theDoubles->Append(aD.Y());
529 theDoubles->Append(aD.Z());
531 theDoubles->Append(anInfo.Radius1());
532 theDoubles->Append(anInfo.Radius2());
535 case GEOMAlgo_KN_RECTANGLE:
536 case GEOMAlgo_KN_TRIANGLE:
537 case GEOMAlgo_KN_QUADRANGLE:
538 case GEOMAlgo_KN_POLYGON:
539 // (+) geompy.kind.POLYGON xo yo zo dx dy dz nb_edges nb_vertices
543 gp_Pnt aO = anInfo.Location();
544 theDoubles->Append(aO.X());
545 theDoubles->Append(aO.Y());
546 theDoubles->Append(aO.Z());
548 gp_Ax3 anAx3 = anInfo.Position();
549 gp_Dir aD = anAx3.Direction();
550 theDoubles->Append(aD.X());
551 theDoubles->Append(aD.Y());
552 theDoubles->Append(aD.Z());
554 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
555 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
558 case GEOMAlgo_KN_PLANE: // infinite
559 // (+) geompy.kind.PLANE xo yo zo dx dy dz
563 gp_Pnt aC = anInfo.Location();
564 theDoubles->Append(aC.X());
565 theDoubles->Append(aC.Y());
566 theDoubles->Append(aC.Z());
568 gp_Ax3 anAx3 = anInfo.Position();
569 gp_Dir aD = anAx3.Direction();
570 theDoubles->Append(aD.X());
571 theDoubles->Append(aD.Y());
572 theDoubles->Append(aD.Z());
576 if (anInfo.KindOfShape() == GEOMAlgo_KS_PLANE) {
577 // (+) geompy.kind.PLANAR xo yo zo dx dy dz nb_edges nb_vertices
581 gp_Pnt aC = anInfo.Location();
582 theDoubles->Append(aC.X());
583 theDoubles->Append(aC.Y());
584 theDoubles->Append(aC.Z());
586 gp_Ax3 anAx3 = anInfo.Position();
587 gp_Dir aD = anAx3.Direction();
588 theDoubles->Append(aD.X());
589 theDoubles->Append(aD.Y());
590 theDoubles->Append(aD.Z());
592 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
593 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
596 // ??? geompy.kind.FACE nb_edges nb_vertices _surface_type_id_
597 // (+) geompy.kind.FACE nb_edges nb_vertices
599 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
600 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
610 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
612 case GEOMAlgo_KN_CIRCLE:
614 // (+) geompy.kind.CIRCLE xc yc zc dx dy dz R
617 gp_Pnt aC = anInfo.Location();
618 theDoubles->Append(aC.X());
619 theDoubles->Append(aC.Y());
620 theDoubles->Append(aC.Z());
622 gp_Ax3 anAx3 = anInfo.Position();
623 gp_Dir aD = anAx3.Direction();
624 theDoubles->Append(aD.X());
625 theDoubles->Append(aD.Y());
626 theDoubles->Append(aD.Z());
628 theDoubles->Append(anInfo.Radius1());
631 case GEOMAlgo_KN_ARCCIRCLE:
633 // (+) geompy.kind.ARC_CIRCLE xc yc zc dx dy dz R x1 y1 z1 x2 y2 z2
634 aKind = SK_ARC_CIRCLE;
636 gp_Pnt aC = anInfo.Location();
637 theDoubles->Append(aC.X());
638 theDoubles->Append(aC.Y());
639 theDoubles->Append(aC.Z());
641 gp_Ax3 anAx3 = anInfo.Position();
642 gp_Dir aD = anAx3.Direction();
643 theDoubles->Append(aD.X());
644 theDoubles->Append(aD.Y());
645 theDoubles->Append(aD.Z());
647 theDoubles->Append(anInfo.Radius1());
649 gp_Pnt aP1 = anInfo.Pnt1();
650 theDoubles->Append(aP1.X());
651 theDoubles->Append(aP1.Y());
652 theDoubles->Append(aP1.Z());
654 gp_Pnt aP2 = anInfo.Pnt2();
655 theDoubles->Append(aP2.X());
656 theDoubles->Append(aP2.Y());
657 theDoubles->Append(aP2.Z());
660 case GEOMAlgo_KN_ELLIPSE:
662 // (+) geompy.kind.ELLIPSE xc yc zc dx dy dz R_1 R_2
665 gp_Pnt aC = anInfo.Location();
666 theDoubles->Append(aC.X());
667 theDoubles->Append(aC.Y());
668 theDoubles->Append(aC.Z());
670 gp_Ax3 anAx3 = anInfo.Position();
671 gp_Dir aD = anAx3.Direction();
672 theDoubles->Append(aD.X());
673 theDoubles->Append(aD.Y());
674 theDoubles->Append(aD.Z());
676 theDoubles->Append(anInfo.Radius1());
677 theDoubles->Append(anInfo.Radius2());
680 case GEOMAlgo_KN_ARCELLIPSE:
682 // (+) geompy.kind.ARC_ELLIPSE xc yc zc dx dy dz R_1 R_2 x1 y1 z1 x2 y2 z2
683 aKind = SK_ARC_ELLIPSE;
685 gp_Pnt aC = anInfo.Location();
686 theDoubles->Append(aC.X());
687 theDoubles->Append(aC.Y());
688 theDoubles->Append(aC.Z());
690 gp_Ax3 anAx3 = anInfo.Position();
691 gp_Dir aD = anAx3.Direction();
692 theDoubles->Append(aD.X());
693 theDoubles->Append(aD.Y());
694 theDoubles->Append(aD.Z());
696 theDoubles->Append(anInfo.Radius1());
697 theDoubles->Append(anInfo.Radius2());
699 gp_Pnt aP1 = anInfo.Pnt1();
700 theDoubles->Append(aP1.X());
701 theDoubles->Append(aP1.Y());
702 theDoubles->Append(aP1.Z());
704 gp_Pnt aP2 = anInfo.Pnt2();
705 theDoubles->Append(aP2.X());
706 theDoubles->Append(aP2.Y());
707 theDoubles->Append(aP2.Z());
710 case GEOMAlgo_KN_LINE:
712 // ??? geompy.kind.LINE x1 y1 z1 x2 y2 z2
713 // (+) geompy.kind.LINE x1 y1 z1 dx dy dz
716 gp_Pnt aO = anInfo.Location();
717 theDoubles->Append(aO.X());
718 theDoubles->Append(aO.Y());
719 theDoubles->Append(aO.Z());
721 gp_Dir aD = anInfo.Direction();
722 theDoubles->Append(aD.X());
723 theDoubles->Append(aD.Y());
724 theDoubles->Append(aD.Z());
727 case GEOMAlgo_KN_SEGMENT:
729 // (+) geompy.kind.SEGMENT x1 y1 z1 x2 y2 z2
732 gp_Pnt aP1 = anInfo.Pnt1();
733 theDoubles->Append(aP1.X());
734 theDoubles->Append(aP1.Y());
735 theDoubles->Append(aP1.Z());
737 gp_Pnt aP2 = anInfo.Pnt2();
738 theDoubles->Append(aP2.X());
739 theDoubles->Append(aP2.Y());
740 theDoubles->Append(aP2.Z());
744 // ??? geompy.kind.EDGE nb_vertices _curve_type_id_
745 // (+) geompy.kind.EDGE nb_vertices
746 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
753 // (+) geompy.kind.VERTEX x y z
756 gp_Pnt aP = anInfo.Location();
757 theDoubles->Append(aP.X());
758 theDoubles->Append(aP.Y());
759 theDoubles->Append(aP.Z());
768 //=============================================================================
769 /*! Get LCS, corresponding to the given shape.
770 * Origin of the LCS is situated at the shape's center of mass.
771 * Axes of the LCS are obtained from shape's location or,
772 * if the shape is a planar face, from position of its plane.
774 //=============================================================================
775 gp_Ax3 GEOMImpl_IMeasureOperations::GetPosition (const TopoDS_Shape& theShape)
779 if (theShape.IsNull())
783 aResult.Transform(theShape.Location().Transformation());
784 if (theShape.ShapeType() == TopAbs_FACE) {
785 Handle(Geom_Surface) aGS = BRep_Tool::Surface(TopoDS::Face(theShape));
786 if (!aGS.IsNull() && aGS->IsKind(STANDARD_TYPE(Geom_Plane))) {
787 Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast(aGS);
788 gp_Pln aPln = aGPlane->Pln();
789 aResult = aPln.Position();
790 // In case of reverse orinetation of the face invert the plane normal
791 // (the face's normal does not mathc the plane's normal in this case)
792 if(theShape.Orientation() == TopAbs_REVERSED)
794 gp_Dir Vx = aResult.XDirection();
795 gp_Dir N = aResult.Direction().Mirrored(Vx);
796 gp_Pnt P = aResult.Location();
797 aResult = gp_Ax3(P, N, Vx);
805 TopAbs_ShapeEnum aShType = theShape.ShapeType();
807 if (aShType == TopAbs_VERTEX) {
808 aPnt = BRep_Tool::Pnt(TopoDS::Vertex(theShape));
811 if (aShType == TopAbs_COMPOUND) {
812 aShType = GEOMImpl_IShapesOperations::GetTypeOfSimplePart(theShape);
815 GProp_GProps aSystem;
816 if (aShType == TopAbs_EDGE || aShType == TopAbs_WIRE)
817 BRepGProp::LinearProperties(theShape, aSystem);
818 else if (aShType == TopAbs_FACE || aShType == TopAbs_SHELL)
819 BRepGProp::SurfaceProperties(theShape, aSystem);
821 BRepGProp::VolumeProperties(theShape, aSystem);
823 aPnt = aSystem.CentreOfMass();
826 aResult.SetLocation(aPnt);
831 //=============================================================================
835 //=============================================================================
836 void GEOMImpl_IMeasureOperations::GetPosition
837 (Handle(GEOM_Object) theShape,
838 Standard_Real& Ox, Standard_Real& Oy, Standard_Real& Oz,
839 Standard_Real& Zx, Standard_Real& Zy, Standard_Real& Zz,
840 Standard_Real& Xx, Standard_Real& Xy, Standard_Real& Xz)
844 //Set default values: global CS
845 Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
848 if (theShape.IsNull()) return;
850 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
851 if (aRefShape.IsNull()) return;
853 TopoDS_Shape aShape = aRefShape->GetValue();
854 if (aShape.IsNull()) {
855 SetErrorCode("The Objects has NULL Shape");
860 #if OCC_VERSION_LARGE > 0x06010000
864 gp_Ax3 anAx3 = GetPosition(aShape);
866 gp_Pnt anOri = anAx3.Location();
867 gp_Dir aDirZ = anAx3.Direction();
868 gp_Dir aDirX = anAx3.XDirection();
871 anOri.Coord(Ox, Oy, Oz);
872 aDirZ.Coord(Zx, Zy, Zz);
873 aDirX.Coord(Xx, Xy, Xz);
875 catch (Standard_Failure) {
876 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
877 SetErrorCode(aFail->GetMessageString());
884 //=============================================================================
888 //=============================================================================
889 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetCentreOfMass
890 (Handle(GEOM_Object) theShape)
894 if (theShape.IsNull()) return NULL;
896 //Add a new CentreOfMass object
897 Handle(GEOM_Object) aCDG = GetEngine()->AddObject(GetDocID(), GEOM_CDG);
899 //Add a new CentreOfMass function
900 Handle(GEOM_Function) aFunction =
901 aCDG->AddFunction(GEOMImpl_MeasureDriver::GetID(), CDG_MEASURE);
902 if (aFunction.IsNull()) return NULL;
904 //Check if the function is set correctly
905 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
907 GEOMImpl_IMeasure aCI (aFunction);
909 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
910 if (aRefShape.IsNull()) return NULL;
912 aCI.SetBase(aRefShape);
914 //Compute the CentreOfMass value
916 #if OCC_VERSION_LARGE > 0x06010000
919 if (!GetSolver()->ComputeFunction(aFunction)) {
920 SetErrorCode("Measure driver failed to compute centre of mass");
924 catch (Standard_Failure) {
925 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
926 SetErrorCode(aFail->GetMessageString());
930 //Make a Python command
931 GEOM::TPythonDump(aFunction) << aCDG << " = geompy.MakeCDG(" << theShape << ")";
937 //=============================================================================
941 //=============================================================================
942 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetVertexByIndex
943 (Handle(GEOM_Object) theShape,
944 Standard_Integer theIndex)
948 if (theShape.IsNull()) return NULL;
950 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
951 if (aRefShape.IsNull()) return NULL;
953 //Add a new Vertex object
954 Handle(GEOM_Object) aVertex = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
957 Handle(GEOM_Function) aFunction =
958 aVertex->AddFunction(GEOMImpl_MeasureDriver::GetID(), VERTEX_BY_INDEX);
959 if (aFunction.IsNull()) return NULL;
961 //Check if the function is set correctly
962 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
964 GEOMImpl_IMeasure aCI (aFunction);
965 aCI.SetBase(aRefShape);
966 aCI.SetIndex(theIndex);
970 #if OCC_VERSION_LARGE > 0x06010000
973 if (!GetSolver()->ComputeFunction(aFunction)) {
974 SetErrorCode("Vertex by index driver failed.");
978 catch (Standard_Failure) {
979 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
980 SetErrorCode(aFail->GetMessageString());
984 //Make a Python command
985 GEOM::TPythonDump(aFunction) << aVertex << " = geompy.GetVertexByIndex(" << theShape << ", " << theIndex << ")";
991 //=============================================================================
995 //=============================================================================
996 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetNormal
997 (Handle(GEOM_Object) theFace,
998 Handle(GEOM_Object) theOptionalPoint)
1002 if (theFace.IsNull()) return NULL;
1004 //Add a new Normale object
1005 Handle(GEOM_Object) aNorm = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
1007 //Add a new Normale function
1008 Handle(GEOM_Function) aFunction =
1009 aNorm->AddFunction(GEOMImpl_MeasureDriver::GetID(), VECTOR_FACE_NORMALE);
1010 if (aFunction.IsNull()) return NULL;
1012 //Check if the function is set correctly
1013 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
1015 GEOMImpl_IMeasure aCI (aFunction);
1017 Handle(GEOM_Function) aFace = theFace->GetLastFunction();
1018 if (aFace.IsNull()) return NULL;
1022 if (!theOptionalPoint.IsNull()) {
1023 Handle(GEOM_Function) anOptPnt = theOptionalPoint->GetLastFunction();
1024 aCI.SetPoint(anOptPnt);
1027 //Compute the Normale value
1029 #if OCC_VERSION_LARGE > 0x06010000
1032 if (!GetSolver()->ComputeFunction(aFunction)) {
1033 SetErrorCode("Measure driver failed to compute normake of face");
1037 catch (Standard_Failure) {
1038 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1039 SetErrorCode(aFail->GetMessageString());
1043 //Make a Python command
1044 GEOM::TPythonDump pd (aFunction);
1045 pd << aNorm << " = geompy.GetNormal(" << theFace;
1046 if (!theOptionalPoint.IsNull()) {
1047 pd << ", " << theOptionalPoint;
1055 //=============================================================================
1057 * GetBasicProperties
1059 //=============================================================================
1060 void GEOMImpl_IMeasureOperations::GetBasicProperties (Handle(GEOM_Object) theShape,
1061 Standard_Real& theLength,
1062 Standard_Real& theSurfArea,
1063 Standard_Real& theVolume)
1067 if (theShape.IsNull()) return;
1069 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1070 if (aRefShape.IsNull()) return;
1072 TopoDS_Shape aShape = aRefShape->GetValue();
1073 if (aShape.IsNull()) {
1074 SetErrorCode("The Objects has NULL Shape");
1078 //Compute the parameters
1079 GProp_GProps LProps, SProps;
1081 #if OCC_VERSION_LARGE > 0x06010000
1084 BRepGProp::LinearProperties(aShape, LProps);
1085 theLength = LProps.Mass();
1087 BRepGProp::SurfaceProperties(aShape, SProps);
1088 theSurfArea = SProps.Mass();
1091 if (aShape.ShapeType() < TopAbs_SHELL) {
1092 for (TopExp_Explorer Exp (aShape, TopAbs_SOLID); Exp.More(); Exp.Next()) {
1093 GProp_GProps VProps;
1094 BRepGProp::VolumeProperties(Exp.Current(), VProps);
1095 theVolume += VProps.Mass();
1099 catch (Standard_Failure) {
1100 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1101 SetErrorCode(aFail->GetMessageString());
1108 //=============================================================================
1112 //=============================================================================
1113 void GEOMImpl_IMeasureOperations::GetInertia
1114 (Handle(GEOM_Object) theShape,
1115 Standard_Real& I11, Standard_Real& I12, Standard_Real& I13,
1116 Standard_Real& I21, Standard_Real& I22, Standard_Real& I23,
1117 Standard_Real& I31, Standard_Real& I32, Standard_Real& I33,
1118 Standard_Real& Ix , Standard_Real& Iy , Standard_Real& Iz)
1122 if (theShape.IsNull()) return;
1124 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1125 if (aRefShape.IsNull()) return;
1127 TopoDS_Shape aShape = aRefShape->GetValue();
1128 if (aShape.IsNull()) {
1129 SetErrorCode("The Objects has NULL Shape");
1133 //Compute the parameters
1134 GProp_GProps System;
1137 #if OCC_VERSION_LARGE > 0x06010000
1140 if (aShape.ShapeType() == TopAbs_VERTEX ||
1141 aShape.ShapeType() == TopAbs_EDGE ||
1142 aShape.ShapeType() == TopAbs_WIRE) {
1143 BRepGProp::LinearProperties(aShape, System);
1144 } else if (aShape.ShapeType() == TopAbs_FACE ||
1145 aShape.ShapeType() == TopAbs_SHELL) {
1146 BRepGProp::SurfaceProperties(aShape, System);
1148 BRepGProp::VolumeProperties(aShape, System);
1150 gp_Mat I = System.MatrixOfInertia();
1164 GProp_PrincipalProps Pr = System.PrincipalProperties();
1165 Pr.Moments(Ix,Iy,Iz);
1167 catch (Standard_Failure) {
1168 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1169 SetErrorCode(aFail->GetMessageString());
1176 //=============================================================================
1180 //=============================================================================
1181 void GEOMImpl_IMeasureOperations::GetBoundingBox
1182 (Handle(GEOM_Object) theShape,
1183 Standard_Real& Xmin, Standard_Real& Xmax,
1184 Standard_Real& Ymin, Standard_Real& Ymax,
1185 Standard_Real& Zmin, Standard_Real& Zmax)
1189 if (theShape.IsNull()) return;
1191 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1192 if (aRefShape.IsNull()) return;
1194 TopoDS_Shape aShape = aRefShape->GetValue();
1195 if (aShape.IsNull()) {
1196 SetErrorCode("The Objects has NULL Shape");
1200 //Compute the parameters
1204 #if OCC_VERSION_LARGE > 0x06010000
1207 BRepBuilderAPI_Copy aCopyTool (aShape);
1208 if (!aCopyTool.IsDone()) {
1209 SetErrorCode("GetBoundingBox Error: Bad shape detected");
1213 aShape = aCopyTool.Shape();
1215 // remove triangulation to obtain more exact boundaries
1216 BRepTools::Clean(aShape);
1218 BRepBndLib::Add(aShape, B);
1219 B.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
1221 catch (Standard_Failure) {
1222 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1223 SetErrorCode(aFail->GetMessageString());
1230 //=============================================================================
1234 //=============================================================================
1235 void GEOMImpl_IMeasureOperations::GetTolerance
1236 (Handle(GEOM_Object) theShape,
1237 Standard_Real& FaceMin, Standard_Real& FaceMax,
1238 Standard_Real& EdgeMin, Standard_Real& EdgeMax,
1239 Standard_Real& VertMin, Standard_Real& VertMax)
1243 if (theShape.IsNull()) return;
1245 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1246 if (aRefShape.IsNull()) return;
1248 TopoDS_Shape aShape = aRefShape->GetValue();
1249 if (aShape.IsNull()) {
1250 SetErrorCode("The Objects has NULL Shape");
1254 //Compute the parameters
1256 FaceMin = EdgeMin = VertMin = RealLast();
1257 FaceMax = EdgeMax = VertMax = -RealLast();
1260 #if OCC_VERSION_LARGE > 0x06010000
1263 for (TopExp_Explorer ExF (aShape, TopAbs_FACE); ExF.More(); ExF.Next()) {
1264 TopoDS_Face Face = TopoDS::Face(ExF.Current());
1265 T = BRep_Tool::Tolerance(Face);
1271 for (TopExp_Explorer ExE (aShape, TopAbs_EDGE); ExE.More(); ExE.Next()) {
1272 TopoDS_Edge Edge = TopoDS::Edge(ExE.Current());
1273 T = BRep_Tool::Tolerance(Edge);
1279 for (TopExp_Explorer ExV (aShape, TopAbs_VERTEX); ExV.More(); ExV.Next()) {
1280 TopoDS_Vertex Vertex = TopoDS::Vertex(ExV.Current());
1281 T = BRep_Tool::Tolerance(Vertex);
1288 catch (Standard_Failure) {
1289 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1290 SetErrorCode(aFail->GetMessageString());
1297 //=============================================================================
1301 //=============================================================================
1302 bool GEOMImpl_IMeasureOperations::CheckShape (Handle(GEOM_Object) theShape,
1303 const Standard_Boolean theIsCheckGeom,
1304 TCollection_AsciiString& theDump)
1308 if (theShape.IsNull()) return false;
1310 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1311 if (aRefShape.IsNull()) return false;
1313 TopoDS_Shape aShape = aRefShape->GetValue();
1314 if (aShape.IsNull()) {
1315 SetErrorCode("The Objects has NULL Shape");
1319 //Compute the parameters
1320 bool isValid = false;
1322 #if OCC_VERSION_LARGE > 0x06010000
1325 BRepCheck_Analyzer ana (aShape, theIsCheckGeom);
1326 if (ana.IsValid()) {
1330 StructuralDump(ana, aShape, theDump);
1333 catch (Standard_Failure) {
1334 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1335 SetErrorCode(aFail->GetMessageString());
1343 //=============================================================================
1345 * CheckSelfIntersections
1347 //=============================================================================
1348 bool GEOMImpl_IMeasureOperations::CheckSelfIntersections
1349 (Handle(GEOM_Object) theShape,
1350 Handle(TColStd_HSequenceOfInteger)& theIntersections)
1353 bool isGood = false;
1355 if (theIntersections.IsNull())
1356 theIntersections = new TColStd_HSequenceOfInteger;
1358 theIntersections->Clear();
1360 if (theShape.IsNull())
1363 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1364 if (aRefShape.IsNull()) return isGood;
1366 TopoDS_Shape aShape = aRefShape->GetValue();
1367 if (aShape.IsNull()) return isGood;
1371 TopoDS_Compound aCS;
1372 TopoDS_Shape aScopy;
1373 NMTDS_Tools::CopyShape(aShape, aScopy);
1375 // Map sub-shapes and their indices
1376 TopTools_IndexedMapOfShape anIndices;
1377 TopExp::MapShapes(aScopy, anIndices);
1379 aBB.MakeCompound(aCS);
1380 aBB.Add(aCS, aScopy);
1382 NMTTools_CheckerSI aCSI; // checker of self-interferences
1383 aCSI.SetCompositeShape(aCS);
1385 // 1. Launch the checker
1387 Standard_Integer iErr = aCSI.StopStatus();
1389 return false; // Error
1394 // 2. Take the shapes from DS
1395 const NMTDS_ShapesDataStructure& aDS = *(aCSI.DS());
1396 Standard_Integer aNbS = aDS.NumberOfShapesOfTheObject();
1398 // 3. Get the pairs of interfered shapes
1399 NMTDS_PInterfPool pIP = aCSI.IP();
1400 //const NMTDS_ListOfPassKeyBoolean& aLPKB = pIP->Get();
1401 const NMTDS_ListOfPairBoolean& aLPKB = pIP->Get();
1403 Standard_Integer n1, n2;
1404 //NMTDS_ListIteratorOfListOfPassKeyBoolean aIt;
1405 NMTDS_ListIteratorOfListOfPairBoolean aIt;
1407 aIt.Initialize(aLPKB);
1408 for (; aIt.More(); aIt.Next()) {
1409 //const NMTDS_PassKeyBoolean& aPKB = aIt.Value();
1410 const NMTDS_PairBoolean& aPKB = aIt.Value();
1413 if (n1 > aNbS || n2 > aNbS)
1414 return false; // Error
1416 const TopoDS_Shape& aS1 = aDS.Shape(n1);
1417 const TopoDS_Shape& aS2 = aDS.Shape(n2);
1419 theIntersections->Append(anIndices.FindIndex(aS1));
1420 theIntersections->Append(anIndices.FindIndex(aS2));
1428 //=============================================================================
1432 //=============================================================================
1433 TCollection_AsciiString GEOMImpl_IMeasureOperations::IsGoodForSolid (Handle(GEOM_Object) theShape)
1437 TCollection_AsciiString aRes = "";
1439 if (theShape.IsNull()) {
1440 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1443 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1444 if (aRefShape.IsNull()) {
1445 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1448 TopoDS_Shape aShape = aRefShape->GetValue();
1449 if (aShape.IsNull()) {
1450 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1453 if (aShape.ShapeType() == TopAbs_COMPOUND) {
1454 TopoDS_Iterator It (aShape, Standard_True, Standard_True);
1455 if (It.More()) aShape = It.Value();
1457 if (aShape.ShapeType() == TopAbs_SHELL) {
1458 BRepCheck_Shell chkShell (TopoDS::Shell(aShape));
1459 if (chkShell.Closed() == BRepCheck_NotClosed) {
1460 aRes = "WRN_SHAPE_UNCLOSED";
1464 aRes = "WRN_SHAPE_NOT_SHELL";
1476 //=============================================================================
1480 //=============================================================================
1481 TCollection_AsciiString GEOMImpl_IMeasureOperations::WhatIs (Handle(GEOM_Object) theShape)
1485 TCollection_AsciiString Astr;
1487 if (theShape.IsNull()) return Astr;
1489 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1490 if (aRefShape.IsNull()) return Astr;
1492 TopoDS_Shape aShape = aRefShape->GetValue();
1493 if (aShape.IsNull()) {
1494 SetErrorCode("The Objects has NULL Shape");
1498 //Compute the parameters
1499 if (aShape.ShapeType() == TopAbs_EDGE) {
1500 if (BRep_Tool::Degenerated(TopoDS::Edge(aShape))) {
1501 Astr = Astr + " It is a degenerated edge \n";
1505 Astr = Astr + " Number of sub-shapes : \n";
1508 #if OCC_VERSION_LARGE > 0x06010000
1511 int iType, nbTypes [TopAbs_SHAPE];
1512 for (iType = 0; iType < TopAbs_SHAPE; ++iType)
1514 nbTypes[aShape.ShapeType()]++;
1516 TopTools_MapOfShape aMapOfShape;
1517 aMapOfShape.Add(aShape);
1518 TopTools_ListOfShape aListOfShape;
1519 aListOfShape.Append(aShape);
1521 TopTools_ListIteratorOfListOfShape itL (aListOfShape);
1522 for (; itL.More(); itL.Next()) {
1523 TopoDS_Iterator it (itL.Value());
1524 for (; it.More(); it.Next()) {
1525 TopoDS_Shape s = it.Value();
1526 if (aMapOfShape.Add(s)) {
1527 aListOfShape.Append(s);
1528 nbTypes[s.ShapeType()]++;
1533 Astr = Astr + " VERTEX : " + TCollection_AsciiString(nbTypes[TopAbs_VERTEX]) + "\n";
1534 Astr = Astr + " EDGE : " + TCollection_AsciiString(nbTypes[TopAbs_EDGE]) + "\n";
1535 Astr = Astr + " WIRE : " + TCollection_AsciiString(nbTypes[TopAbs_WIRE]) + "\n";
1536 Astr = Astr + " FACE : " + TCollection_AsciiString(nbTypes[TopAbs_FACE]) + "\n";
1537 Astr = Astr + " SHELL : " + TCollection_AsciiString(nbTypes[TopAbs_SHELL]) + "\n";
1538 Astr = Astr + " SOLID : " + TCollection_AsciiString(nbTypes[TopAbs_SOLID]) + "\n";
1539 Astr = Astr + " COMPSOLID : " + TCollection_AsciiString(nbTypes[TopAbs_COMPSOLID]) + "\n";
1540 Astr = Astr + " COMPOUND : " + TCollection_AsciiString(nbTypes[TopAbs_COMPOUND]) + "\n";
1541 Astr = Astr + " SHAPE : " + TCollection_AsciiString(aMapOfShape.Extent());
1543 catch (Standard_Failure) {
1544 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1545 SetErrorCode(aFail->GetMessageString());
1554 //=======================================================================
1555 //function : CheckSingularCase
1556 //purpose : auxilary for GetMinDistance()
1557 // workaround for bugs 19899, 19908 and 19910 from Mantis
1558 //=======================================================================
1559 static double CheckSingularCase(const TopoDS_Shape& aSh1,
1560 const TopoDS_Shape& aSh2,
1561 gp_Pnt& Ptmp1, gp_Pnt& Ptmp2)
1563 bool IsChange1 = false;
1564 double AddDist1 = 0.0;
1565 TopExp_Explorer anExp;
1566 TopoDS_Shape tmpSh1, tmpSh2;
1568 for ( anExp.Init( aSh1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1570 tmpSh1 = anExp.Current();
1573 TopoDS_Shape sh = aSh1;
1574 while(sh.ShapeType()==TopAbs_COMPOUND) {
1575 TopoDS_Iterator it(sh);
1578 Handle(Geom_Surface) S = BRep_Tool::Surface(TopoDS::Face(tmpSh1));
1579 if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1580 S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1581 if( sh.ShapeType()==TopAbs_SHELL || sh.ShapeType()==TopAbs_FACE ) {
1584 // changes for 0020677: EDF 1219 GEOM: MinDistance gives 0 instead of 20.88
1585 //S->Bounds(U1,U2,V1,V2); changed by
1586 ShapeAnalysis::GetFaceUVBounds(TopoDS::Face(tmpSh1),U1,U2,V1,V2);
1587 // end of changes for 020677 (dmv)
1588 Handle(Geom_RectangularTrimmedSurface) TrS1 =
1589 new Geom_RectangularTrimmedSurface(S,U1,(U1+U2)/2.,V1,V2);
1590 Handle(Geom_RectangularTrimmedSurface) TrS2 =
1591 new Geom_RectangularTrimmedSurface(S,(U1+U2)/2.,U2,V1,V2);
1594 TopoDS_Compound Comp;
1595 B.MakeCompound(Comp);
1596 B.MakeFace(F1,TrS1,1.e-7);
1598 B.MakeFace(F2,TrS2,1.e-7);
1600 Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
1602 sfs->SetPrecision(1.e-6);
1603 sfs->SetMaxTolerance(1.0);
1605 tmpSh1 = sfs->Shape();
1609 if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ) {
1610 Handle(Geom_SphericalSurface) SS = Handle(Geom_SphericalSurface)::DownCast(S);
1611 gp_Pnt PC = SS->Location();
1614 B.MakeVertex(V,PC,1.e-7);
1616 AddDist1 = SS->Radius();
1620 Handle(Geom_ToroidalSurface) TS = Handle(Geom_ToroidalSurface)::DownCast(S);
1621 gp_Ax3 ax3 = TS->Position();
1622 Handle(Geom_Circle) C = new Geom_Circle(ax3.Ax2(),TS->MajorRadius());
1625 B.MakeEdge(E,C,1.e-7);
1627 AddDist1 = TS->MinorRadius();
1637 bool IsChange2 = false;
1638 double AddDist2 = 0.0;
1640 for ( anExp.Init( aSh2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1642 tmpSh2 = anExp.Current();
1645 TopoDS_Shape sh = aSh2;
1646 while(sh.ShapeType()==TopAbs_COMPOUND) {
1647 TopoDS_Iterator it(sh);
1650 Handle(Geom_Surface) S = BRep_Tool::Surface(TopoDS::Face(tmpSh2));
1651 if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1652 S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1653 if( sh.ShapeType()==TopAbs_SHELL || sh.ShapeType()==TopAbs_FACE ) {
1656 //S->Bounds(U1,U2,V1,V2);
1657 ShapeAnalysis::GetFaceUVBounds(TopoDS::Face(tmpSh2),U1,U2,V1,V2);
1658 Handle(Geom_RectangularTrimmedSurface) TrS1 =
1659 new Geom_RectangularTrimmedSurface(S,U1,(U1+U2)/2.,V1,V2);
1660 Handle(Geom_RectangularTrimmedSurface) TrS2 =
1661 new Geom_RectangularTrimmedSurface(S,(U1+U2)/2.,U2,V1,V2);
1664 TopoDS_Compound Comp;
1665 B.MakeCompound(Comp);
1666 B.MakeFace(F1,TrS1,1.e-7);
1668 B.MakeFace(F2,TrS2,1.e-7);
1670 Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
1672 sfs->SetPrecision(1.e-6);
1673 sfs->SetMaxTolerance(1.0);
1675 tmpSh2 = sfs->Shape();
1679 if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ) {
1680 Handle(Geom_SphericalSurface) SS = Handle(Geom_SphericalSurface)::DownCast(S);
1681 gp_Pnt PC = SS->Location();
1684 B.MakeVertex(V,PC,1.e-7);
1686 AddDist2 = SS->Radius();
1689 else if( S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1690 Handle(Geom_ToroidalSurface) TS = Handle(Geom_ToroidalSurface)::DownCast(S);
1691 gp_Ax3 ax3 = TS->Position();
1692 Handle(Geom_Circle) C = new Geom_Circle(ax3.Ax2(),TS->MajorRadius());
1695 B.MakeEdge(E,C,1.e-7);
1697 AddDist2 = TS->MinorRadius();
1708 if( !IsChange1 && !IsChange2 )
1711 BRepExtrema_DistShapeShape dst(tmpSh1,tmpSh2);
1713 double MinDist = 1.e9;
1714 gp_Pnt PMin1, PMin2, P1, P2;
1715 for (int i = 1; i <= dst.NbSolution(); i++) {
1716 P1 = dst.PointOnShape1(i);
1717 P2 = dst.PointOnShape2(i);
1718 Standard_Real Dist = P1.Distance(P2);
1719 if (MinDist > Dist) {
1730 gp_Dir aDir(gp_Vec(PMin1,PMin2));
1731 if( MinDist > (AddDist1+AddDist2) ) {
1732 Ptmp1 = gp_Pnt( PMin1.X() + aDir.X()*AddDist1,
1733 PMin1.Y() + aDir.Y()*AddDist1,
1734 PMin1.Z() + aDir.Z()*AddDist1 );
1735 Ptmp2 = gp_Pnt( PMin2.X() - aDir.X()*AddDist2,
1736 PMin2.Y() - aDir.Y()*AddDist2,
1737 PMin2.Z() - aDir.Z()*AddDist2 );
1738 return (MinDist - AddDist1 - AddDist2);
1741 if( AddDist1 > 0 ) {
1742 Ptmp1 = gp_Pnt( PMin1.X() + aDir.X()*AddDist1,
1743 PMin1.Y() + aDir.Y()*AddDist1,
1744 PMin1.Z() + aDir.Z()*AddDist1 );
1748 Ptmp2 = gp_Pnt( PMin2.X() - aDir.X()*AddDist2,
1749 PMin2.Y() - aDir.Y()*AddDist2,
1750 PMin2.Z() - aDir.Z()*AddDist2 );
1755 double res = MinDist - AddDist1 - AddDist2;
1756 if(res<0.) res = 0.0;
1762 static bool CheckSingularCase(const TopoDS_Shape& aSh1,
1763 const TopoDS_Shape& aSh2,
1766 TopExp_Explorer anExp;
1767 TopoDS_Shape tmpSh1, tmpSh2;
1769 for ( anExp.Init( aSh1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1771 tmpSh1 = anExp.Current();
1774 Handle(Geom_Surface) S1 = BRep_Tool::Surface(TopoDS::Face(tmpSh1));
1775 if( S1->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1776 S1->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1778 for ( anExp.Init( aSh2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1780 tmpSh2 = anExp.Current();
1781 Handle(Geom_Surface) S2 = BRep_Tool::Surface(TopoDS::Face(tmpSh2));
1782 GeomAPI_IntSS ISS(S1,S2,1.e-7);
1784 for(int i=1; i<=ISS.NbLines(); i++) {
1785 Handle(Geom_Curve) C3d = ISS.Line(i);
1788 B.MakeEdge(E,C3d,1.e-7);
1789 BRepExtrema_DistShapeShape dst(tmpSh2,E);
1791 gp_Pnt PMin1, PMin2, P1, P2;
1792 double MinDist = 1.e9;
1793 for (int i = 1; i <= dst.NbSolution(); i++) {
1794 P1 = dst.PointOnShape1(i);
1795 P2 = dst.PointOnShape2(i);
1796 Standard_Real Dist = P1.Distance(P2);
1797 if (MinDist > Dist) {
1811 for ( anExp.Init( aSh2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1813 tmpSh1 = anExp.Current();
1816 Handle(Geom_Surface) S1 = BRep_Tool::Surface(TopoDS::Face(tmpSh1));
1817 if( S1->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1818 S1->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1820 for ( anExp.Init( aSh1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1822 tmpSh2 = anExp.Current();
1823 Handle(Geom_Surface) S2 = BRep_Tool::Surface(TopoDS::Face(tmpSh2));
1824 GeomAPI_IntSS ISS(S1,S2,1.e-7);
1826 for(int i=1; i<=ISS.NbLines(); i++) {
1827 Handle(Geom_Curve) C3d = ISS.Line(i);
1830 B.MakeEdge(E,C3d,1.e-7);
1831 BRepExtrema_DistShapeShape dst(tmpSh2,E);
1834 double MinDist = 1.e9;
1835 for (int i = 1; i <= dst.NbSolution(); i++) {
1836 P1 = dst.PointOnShape1(i);
1837 P2 = dst.PointOnShape2(i);
1838 Standard_Real Dist = P1.Distance(P2);
1839 if (MinDist > Dist) {
1857 //=============================================================================
1861 //=============================================================================
1862 std::vector<bool> GEOMImpl_IMeasureOperations::AreCoordsInside(Handle(GEOM_Object) theShape,
1863 const std::vector<double>& coords,
1866 std::vector<bool> res;
1867 if (!theShape.IsNull()) {
1868 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1869 if (!aRefShape.IsNull()) {
1870 TopoDS_Shape aShape = aRefShape->GetValue();
1871 if (!aShape.IsNull()) {
1872 BRepClass3d_SolidClassifier SC(aShape);
1873 unsigned int nb_points = coords.size()/3;
1874 for (int i = 0; i < nb_points; i++) {
1875 double x = coords[3*i];
1876 double y = coords[3*i+1];
1877 double z = coords[3*i+2];
1878 gp_Pnt aPnt(x, y, z);
1879 SC.Perform(aPnt, tolerance);
1880 res.push_back( ( SC.State() == TopAbs_IN ) || ( SC.State() == TopAbs_ON ) );
1888 //=============================================================================
1892 //=============================================================================
1893 Standard_Real GEOMImpl_IMeasureOperations::GetMinDistance
1894 (Handle(GEOM_Object) theShape1, Handle(GEOM_Object) theShape2,
1895 Standard_Real& X1, Standard_Real& Y1, Standard_Real& Z1,
1896 Standard_Real& X2, Standard_Real& Y2, Standard_Real& Z2)
1899 Standard_Real MinDist = 1.e9;
1901 if (theShape1.IsNull() || theShape2.IsNull()) return MinDist;
1903 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
1904 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
1905 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return MinDist;
1907 TopoDS_Shape aShape1 = aRefShape1->GetValue();
1908 TopoDS_Shape aShape2 = aRefShape2->GetValue();
1909 if (aShape1.IsNull() || aShape2.IsNull()) {
1910 SetErrorCode("One of Objects has NULL Shape");
1914 //Compute the parameters
1916 #if OCC_VERSION_LARGE > 0x06010000
1920 // Issue 0020231: A min distance bug with torus and vertex.
1921 // Make GetMinDistance() return zero if a sole VERTEX is inside any of SOLIDs
1923 // which of shapes consists of only one vertex?
1924 TopExp_Explorer exp1(aShape1,TopAbs_VERTEX), exp2(aShape2,TopAbs_VERTEX);
1925 TopoDS_Shape V1 = exp1.More() ? exp1.Current() : TopoDS_Shape();
1926 TopoDS_Shape V2 = exp2.More() ? exp2.Current() : TopoDS_Shape();
1927 exp1.Next(); exp2.Next();
1928 if ( exp1.More() ) V1.Nullify();
1929 if ( exp2.More() ) V2.Nullify();
1930 // vertex and container of solids
1931 TopoDS_Shape V = V1.IsNull() ? V2 : V1;
1932 TopoDS_Shape S = V1.IsNull() ? aShape1 : aShape2;
1933 if ( !V.IsNull() ) {
1934 // classify vertex against solids
1935 gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( V ) );
1936 for ( exp1.Init( S, TopAbs_SOLID ); exp1.More(); exp1.Next() ) {
1937 BRepClass3d_SolidClassifier classifier( exp1.Current(), p, 1e-6);
1938 if ( classifier.State() == TopAbs_IN ) {
1939 p.Coord(X1, Y1, Z1);
1940 p.Coord(X2, Y2, Z2);
1946 // End Issue 0020231
1949 // additional workaround for bugs 19899, 19908 and 19910 from Mantis
1950 gp_Pnt Ptmp1, Ptmp2;
1951 double dist = CheckSingularCase(aShape1, aShape2, Ptmp1, Ptmp2);
1953 Ptmp1.Coord(X1, Y1, Z1);
1954 Ptmp2.Coord(X2, Y2, Z2);
1959 BRepExtrema_DistShapeShape dst (aShape1, aShape2);
1961 gp_Pnt PMin1, PMin2, P1, P2;
1963 for (int i = 1; i <= dst.NbSolution(); i++) {
1964 P1 = dst.PointOnShape1(i);
1965 P2 = dst.PointOnShape2(i);
1967 Standard_Real Dist = P1.Distance(P2);
1968 if (MinDist > Dist) {
1975 PMin1.Coord(X1, Y1, Z1);
1976 PMin2.Coord(X2, Y2, Z2);
1979 catch (Standard_Failure) {
1980 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1981 SetErrorCode(aFail->GetMessageString());
1989 //=======================================================================
1991 * Get coordinates of point
1993 //=======================================================================
1994 void GEOMImpl_IMeasureOperations::PointCoordinates (Handle(GEOM_Object) theShape,
1995 Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ)
1999 if (theShape.IsNull())
2002 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
2003 if (aRefShape.IsNull())
2006 TopoDS_Shape aShape = aRefShape->GetValue();
2007 if (aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX)
2009 SetErrorCode( "Shape must be a vertex" );
2014 #if OCC_VERSION_LARGE > 0x06010000
2017 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
2024 catch (Standard_Failure)
2026 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2027 SetErrorCode( aFail->GetMessageString() );
2031 //=======================================================================
2033 * Compute angle (in degrees) between two lines
2035 //=======================================================================
2036 Standard_Real GEOMImpl_IMeasureOperations::GetAngle (Handle(GEOM_Object) theLine1,
2037 Handle(GEOM_Object) theLine2)
2039 if (theLine1->GetType() == GEOM_VECTOR &&
2040 theLine2->GetType() == GEOM_VECTOR)
2041 return GetAngleBtwVectors(theLine1, theLine2);
2045 Standard_Real anAngle = -1.0;
2047 if (theLine1.IsNull() || theLine2.IsNull())
2050 Handle(GEOM_Function) aRefLine1 = theLine1->GetLastFunction();
2051 Handle(GEOM_Function) aRefLine2 = theLine2->GetLastFunction();
2052 if (aRefLine1.IsNull() || aRefLine2.IsNull())
2055 TopoDS_Shape aLine1 = aRefLine1->GetValue();
2056 TopoDS_Shape aLine2 = aRefLine2->GetValue();
2057 if (aLine1.IsNull() || aLine2.IsNull() ||
2058 aLine1.ShapeType() != TopAbs_EDGE ||
2059 aLine2.ShapeType() != TopAbs_EDGE)
2061 SetErrorCode("Two edges must be given");
2066 #if OCC_VERSION_LARGE > 0x06010000
2069 TopoDS_Edge E1 = TopoDS::Edge(aLine1);
2070 TopoDS_Edge E2 = TopoDS::Edge(aLine2);
2073 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp,lp);
2074 Handle(Geom_Curve) C2 = BRep_Tool::Curve(E2,fp,lp);
2076 if ( C1.IsNull() || C2.IsNull() ||
2077 !C1->IsKind(STANDARD_TYPE(Geom_Line)) ||
2078 !C2->IsKind(STANDARD_TYPE(Geom_Line)))
2080 SetErrorCode("The edges must be linear");
2084 Handle(Geom_Line) L1 = Handle(Geom_Line)::DownCast(C1);
2085 Handle(Geom_Line) L2 = Handle(Geom_Line)::DownCast(C2);
2087 gp_Lin aLin1 = L1->Lin();
2088 gp_Lin aLin2 = L2->Lin();
2090 anAngle = aLin1.Angle(aLin2);
2091 anAngle *= 180. / M_PI; // convert radians into degrees
2093 if (anAngle > 90.0) {
2094 anAngle = 180.0 - anAngle;
2099 catch (Standard_Failure)
2101 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2102 SetErrorCode(aFail->GetMessageString());
2108 //=======================================================================
2110 * Compute angle (in degrees) between two vectors
2112 //=======================================================================
2113 Standard_Real GEOMImpl_IMeasureOperations::GetAngleBtwVectors (Handle(GEOM_Object) theVec1,
2114 Handle(GEOM_Object) theVec2)
2118 Standard_Real anAngle = -1.0;
2120 if (theVec1.IsNull() || theVec2.IsNull())
2123 if (theVec1->GetType() != GEOM_VECTOR || theVec2->GetType() != GEOM_VECTOR) {
2124 SetErrorCode("Two vectors must be given");
2128 Handle(GEOM_Function) aRefVec1 = theVec1->GetLastFunction();
2129 Handle(GEOM_Function) aRefVec2 = theVec2->GetLastFunction();
2130 if (aRefVec1.IsNull() || aRefVec2.IsNull())
2133 TopoDS_Shape aVec1 = aRefVec1->GetValue();
2134 TopoDS_Shape aVec2 = aRefVec2->GetValue();
2135 if (aVec1.IsNull() || aVec2.IsNull() ||
2136 aVec1.ShapeType() != TopAbs_EDGE ||
2137 aVec2.ShapeType() != TopAbs_EDGE)
2139 SetErrorCode("Two edges must be given");
2144 #if OCC_VERSION_LARGE > 0x06010000
2147 TopoDS_Edge aE1 = TopoDS::Edge(aVec1);
2148 TopoDS_Edge aE2 = TopoDS::Edge(aVec2);
2150 TopoDS_Vertex aP11, aP12, aP21, aP22;
2151 TopExp::Vertices(aE1, aP11, aP12, Standard_True);
2152 TopExp::Vertices(aE2, aP21, aP22, Standard_True);
2153 if (aP11.IsNull() || aP12.IsNull() || aP21.IsNull() || aP22.IsNull()) {
2154 SetErrorCode("Bad edge given");
2158 gp_Vec aV1 (BRep_Tool::Pnt(aP11), BRep_Tool::Pnt(aP12));
2159 gp_Vec aV2 (BRep_Tool::Pnt(aP21), BRep_Tool::Pnt(aP22)) ;
2161 anAngle = aV1.Angle(aV2);
2162 anAngle *= 180. / M_PI; // convert radians into degrees
2166 catch (Standard_Failure)
2168 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2169 SetErrorCode(aFail->GetMessageString());
2176 //=============================================================================
2178 * CurveCurvatureByParam
2180 //=============================================================================
2181 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByParam
2182 (Handle(GEOM_Object) theCurve, Standard_Real& theParam)
2185 Standard_Real aRes = -1.0;
2187 if(theCurve.IsNull()) return aRes;
2189 Handle(GEOM_Function) aRefShape = theCurve->GetLastFunction();
2190 if(aRefShape.IsNull()) return aRes;
2192 TopoDS_Shape aShape = aRefShape->GetValue();
2193 if(aShape.IsNull()) {
2194 SetErrorCode("One of Objects has NULL Shape");
2198 Standard_Real aFP, aLP, aP;
2199 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aFP, aLP);
2200 aP = aFP + (aLP - aFP) * theParam;
2202 if(aCurve.IsNull()) return aRes;
2206 #if OCC_VERSION_LARGE > 0x06010000
2209 GeomLProp_CLProps Prop = GeomLProp_CLProps
2210 (aCurve, aP, 2, Precision::Confusion());
2211 aRes = fabs(Prop.Curvature());
2214 catch (Standard_Failure) {
2215 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2216 SetErrorCode(aFail->GetMessageString());
2220 if( aRes > Precision::Confusion() )
2229 //=============================================================================
2231 * CurveCurvatureByPoint
2233 //=============================================================================
2234 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByPoint
2235 (Handle(GEOM_Object) theCurve, Handle(GEOM_Object) thePoint)
2238 Standard_Real aRes = -1.0;
2240 if( theCurve.IsNull() || thePoint.IsNull() ) return aRes;
2242 Handle(GEOM_Function) aRefCurve = theCurve->GetLastFunction();
2243 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2244 if( aRefCurve.IsNull() || aRefPoint.IsNull() ) return aRes;
2246 TopoDS_Edge anEdge = TopoDS::Edge(aRefCurve->GetValue());
2247 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2248 if( anEdge.IsNull() || aPnt.IsNull() ) {
2249 SetErrorCode("One of Objects has NULL Shape");
2253 Standard_Real aFP, aLP;
2254 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFP, aLP);
2255 if(aCurve.IsNull()) return aRes;
2256 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2260 #if OCC_VERSION_LARGE > 0x06010000
2263 GeomAPI_ProjectPointOnCurve PPCurve(aPoint, aCurve, aFP, aLP);
2264 if(PPCurve.NbPoints()>0) {
2265 GeomLProp_CLProps Prop = GeomLProp_CLProps
2266 (aCurve, PPCurve.LowerDistanceParameter(), 2, Precision::Confusion());
2267 aRes = fabs(Prop.Curvature());
2271 catch (Standard_Failure) {
2272 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2273 SetErrorCode(aFail->GetMessageString());
2277 if( aRes > Precision::Confusion() )
2286 //=============================================================================
2288 * getSurfaceCurvatures
2290 //=============================================================================
2291 Standard_Real GEOMImpl_IMeasureOperations::getSurfaceCurvatures
2292 (const Handle(Geom_Surface)& aSurf,
2293 Standard_Real theUParam,
2294 Standard_Real theVParam,
2295 Standard_Boolean theNeedMaxCurv)
2298 Standard_Real aRes = 1.0;
2300 if (aSurf.IsNull()) return aRes;
2303 #if OCC_VERSION_LARGE > 0x06010000
2306 GeomLProp_SLProps Prop = GeomLProp_SLProps
2307 (aSurf, theUParam, theVParam, 2, Precision::Confusion());
2308 if(Prop.IsCurvatureDefined()) {
2309 if(Prop.IsUmbilic()) {
2310 //cout<<"is umbilic"<<endl;
2311 aRes = fabs(Prop.MeanCurvature());
2314 //cout<<"is not umbilic"<<endl;
2315 double c1 = fabs(Prop.MaxCurvature());
2316 double c2 = fabs(Prop.MinCurvature());
2325 catch (Standard_Failure) {
2326 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2327 SetErrorCode(aFail->GetMessageString());
2331 if( fabs(aRes) > Precision::Confusion() )
2340 //=============================================================================
2342 * MaxSurfaceCurvatureByParam
2344 //=============================================================================
2345 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByParam
2346 (Handle(GEOM_Object) theSurf,
2347 Standard_Real& theUParam,
2348 Standard_Real& theVParam)
2351 Standard_Real aRes = -1.0;
2353 if (theSurf.IsNull()) return aRes;
2355 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2356 if(aRefShape.IsNull()) return aRes;
2358 TopoDS_Shape aShape = aRefShape->GetValue();
2359 if(aShape.IsNull()) {
2360 SetErrorCode("One of Objects has NULL Shape");
2364 TopoDS_Face F = TopoDS::Face(aShape);
2365 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2367 //Compute the parameters
2368 Standard_Real U1,U2,V1,V2;
2369 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2370 Standard_Real U = U1 + (U2-U1)*theUParam;
2371 Standard_Real V = V1 + (V2-V1)*theVParam;
2373 return getSurfaceCurvatures(aSurf, U, V, true);
2377 //=============================================================================
2379 * MaxSurfaceCurvatureByPoint
2381 //=============================================================================
2382 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByPoint
2383 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2386 Standard_Real aRes = -1.0;
2388 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2390 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2391 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2392 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2394 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2395 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2396 if( aFace.IsNull() || aPnt.IsNull() ) {
2397 SetErrorCode("One of Objects has NULL Shape");
2401 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2402 if(aSurf.IsNull()) return aRes;
2403 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2405 //Compute the parameters
2406 ShapeAnalysis_Surface sas(aSurf);
2407 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2409 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), true);
2413 //=============================================================================
2415 * MinSurfaceCurvatureByParam
2417 //=============================================================================
2418 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByParam
2419 (Handle(GEOM_Object) theSurf,
2420 Standard_Real& theUParam,
2421 Standard_Real& theVParam)
2424 Standard_Real aRes = -1.0;
2426 if (theSurf.IsNull()) return aRes;
2428 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2429 if(aRefShape.IsNull()) return aRes;
2431 TopoDS_Shape aShape = aRefShape->GetValue();
2432 if(aShape.IsNull()) {
2433 SetErrorCode("One of Objects has NULL Shape");
2437 TopoDS_Face F = TopoDS::Face(aShape);
2438 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2440 //Compute the parameters
2441 Standard_Real U1,U2,V1,V2;
2442 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2443 Standard_Real U = U1 + (U2-U1)*theUParam;
2444 Standard_Real V = V1 + (V2-V1)*theVParam;
2446 return getSurfaceCurvatures(aSurf, U, V, false);
2450 //=============================================================================
2452 * MinSurfaceCurvatureByPoint
2454 //=============================================================================
2455 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByPoint
2456 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2459 Standard_Real aRes = -1.0;
2461 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2463 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2464 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2465 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2467 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2468 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2469 if( aFace.IsNull() || aPnt.IsNull() ) {
2470 SetErrorCode("One of Objects has NULL Shape");
2474 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2475 if(aSurf.IsNull()) return aRes;
2476 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2478 //Compute the parameters
2479 ShapeAnalysis_Surface sas(aSurf);
2480 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2482 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), false);
2486 //=======================================================================
2487 //function : StructuralDump
2488 //purpose : Structural (data exchange) style of output.
2489 //=======================================================================
2490 void GEOMImpl_IMeasureOperations::StructuralDump (const BRepCheck_Analyzer& theAna,
2491 const TopoDS_Shape& theShape,
2492 TCollection_AsciiString& theDump)
2496 theDump += " -- The Shape has problems :\n";
2497 theDump += " Check Count\n";
2498 theDump += " ------------------------------------------------\n";
2500 Standard_Integer last_stat = (Standard_Integer)BRepCheck_CheckFail;
2501 Handle(TColStd_HArray1OfInteger) NbProblems =
2502 new TColStd_HArray1OfInteger(1, last_stat);
2503 for (i = 1; i <= last_stat; i++)
2504 NbProblems->SetValue(i,0);
2506 Handle(TopTools_HSequenceOfShape) sl;
2507 sl = new TopTools_HSequenceOfShape();
2508 TopTools_DataMapOfShapeListOfShape theMap;
2510 GetProblemShapes(theAna, theShape, sl, NbProblems, theMap);
2513 Standard_Integer count = 0;
2514 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnCurve);
2516 theDump += " Invalid Point on Curve ................... ";
2517 theDump += TCollection_AsciiString(count) + "\n";
2519 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnCurveOnSurface);
2521 theDump += " Invalid Point on CurveOnSurface .......... ";
2522 theDump += TCollection_AsciiString(count) + "\n";
2524 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnSurface);
2526 theDump += " Invalid Point on Surface ................. ";
2527 theDump += TCollection_AsciiString(count) + "\n";
2529 count = NbProblems->Value((Standard_Integer)BRepCheck_No3DCurve);
2531 theDump += " No 3D Curve .............................. ";
2532 theDump += TCollection_AsciiString(count) + "\n";
2534 count = NbProblems->Value((Standard_Integer)BRepCheck_Multiple3DCurve);
2536 theDump += " Multiple 3D Curve ........................ ";
2537 theDump += TCollection_AsciiString(count) + "\n";
2539 count = NbProblems->Value((Standard_Integer)BRepCheck_Invalid3DCurve);
2541 theDump += " Invalid 3D Curve ......................... ";
2542 theDump += TCollection_AsciiString(count) + "\n";
2544 count = NbProblems->Value((Standard_Integer)BRepCheck_NoCurveOnSurface);
2546 theDump += " No Curve on Surface ...................... ";
2547 theDump += TCollection_AsciiString(count) + "\n";
2549 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidCurveOnSurface);
2551 theDump += " Invalid Curve on Surface ................. ";
2552 theDump += TCollection_AsciiString(count) + "\n";
2554 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidCurveOnClosedSurface);
2556 theDump += " Invalid Curve on closed Surface .......... ";
2557 theDump += TCollection_AsciiString(count) + "\n";
2559 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidSameRangeFlag);
2561 theDump += " Invalid SameRange Flag ................... ";
2562 theDump += TCollection_AsciiString(count) + "\n";
2564 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidSameParameterFlag);
2566 theDump += " Invalid SameParameter Flag ............... ";
2567 theDump += TCollection_AsciiString(count) + "\n";
2569 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidDegeneratedFlag);
2571 theDump += " Invalid Degenerated Flag ................. ";
2572 theDump += TCollection_AsciiString(count) + "\n";
2574 count = NbProblems->Value((Standard_Integer)BRepCheck_FreeEdge);
2576 theDump += " Free Edge ................................ ";
2577 theDump += TCollection_AsciiString(count) + "\n";
2579 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidMultiConnexity);
2581 theDump += " Invalid MultiConnexity ................... ";
2582 theDump += TCollection_AsciiString(count) + "\n";
2584 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidRange);
2586 theDump += " Invalid Range ............................ ";
2587 theDump += TCollection_AsciiString(count) + "\n";
2589 count = NbProblems->Value((Standard_Integer)BRepCheck_EmptyWire);
2591 theDump += " Empty Wire ............................... ";
2592 theDump += TCollection_AsciiString(count) + "\n";
2594 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantEdge);
2596 theDump += " Redundant Edge ........................... ";
2597 theDump += TCollection_AsciiString(count) + "\n";
2599 count = NbProblems->Value((Standard_Integer)BRepCheck_SelfIntersectingWire);
2601 theDump += " Self Intersecting Wire ................... ";
2602 theDump += TCollection_AsciiString(count) + "\n";
2604 count = NbProblems->Value((Standard_Integer)BRepCheck_NoSurface);
2606 theDump += " No Surface ............................... ";
2607 theDump += TCollection_AsciiString(count) + "\n";
2609 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidWire);
2611 theDump += " Invalid Wire ............................. ";
2612 theDump += TCollection_AsciiString(count) + "\n";
2614 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantWire);
2616 theDump += " Redundant Wire ........................... ";
2617 theDump += TCollection_AsciiString(count) + "\n";
2619 count = NbProblems->Value((Standard_Integer)BRepCheck_IntersectingWires);
2621 theDump += " Intersecting Wires ....................... ";
2622 theDump += TCollection_AsciiString(count) + "\n";
2624 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidImbricationOfWires);
2626 theDump += " Invalid Imbrication of Wires ............. ";
2627 theDump += TCollection_AsciiString(count) + "\n";
2629 count = NbProblems->Value((Standard_Integer)BRepCheck_EmptyShell);
2631 theDump += " Empty Shell .............................. ";
2632 theDump += TCollection_AsciiString(count) + "\n";
2634 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantFace);
2636 theDump += " Redundant Face ........................... ";
2637 theDump += TCollection_AsciiString(count) + "\n";
2639 count = NbProblems->Value((Standard_Integer)BRepCheck_UnorientableShape);
2641 theDump += " Unorientable Shape ....................... ";
2642 theDump += TCollection_AsciiString(count) + "\n";
2644 count = NbProblems->Value((Standard_Integer)BRepCheck_NotClosed);
2646 theDump += " Not Closed ............................... ";
2647 theDump += TCollection_AsciiString(count) + "\n";
2649 count = NbProblems->Value((Standard_Integer)BRepCheck_NotConnected);
2651 theDump += " Not Connected ............................ ";
2652 theDump += TCollection_AsciiString(count) + "\n";
2654 count = NbProblems->Value((Standard_Integer)BRepCheck_SubshapeNotInShape);
2656 theDump += " Sub-shape not in Shape .................... ";
2657 theDump += TCollection_AsciiString(count) + "\n";
2659 count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientation);
2661 theDump += " Bad Orientation .......................... ";
2662 theDump += TCollection_AsciiString(count) + "\n";
2664 count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientationOfSubshape);
2666 theDump += " Bad Orientation of Sub-shape .............. ";
2667 theDump += TCollection_AsciiString(count) + "\n";
2669 count = NbProblems->Value((Standard_Integer)BRepCheck_CheckFail);
2671 theDump += " checkshape failure ....................... ";
2672 theDump += TCollection_AsciiString(count) + "\n";
2675 theDump += " ------------------------------------------------\n";
2676 theDump += "*** Shapes with problems : ";
2677 theDump += TCollection_AsciiString(sl->Length()) + "\n";
2679 Standard_Integer nbv, nbe, nbw, nbf, nbs, nbo;
2680 nbv = nbe = nbw = nbf = nbs = nbo = 0;
2682 for (i = 1; i <= sl->Length(); i++) {
2683 TopoDS_Shape shi = sl->Value(i);
2684 TopAbs_ShapeEnum sti = shi.ShapeType();
2686 case TopAbs_VERTEX : nbv++; break;
2687 case TopAbs_EDGE : nbe++; break;
2688 case TopAbs_WIRE : nbw++; break;
2689 case TopAbs_FACE : nbf++; break;
2690 case TopAbs_SHELL : nbs++; break;
2691 case TopAbs_SOLID : nbo++; break;
2697 theDump += "VERTEX : ";
2698 if (nbv < 10) theDump += " ";
2699 theDump += TCollection_AsciiString(nbv) + "\n";
2702 theDump += "EDGE : ";
2703 if (nbe < 10) theDump += " ";
2704 theDump += TCollection_AsciiString(nbe) + "\n";
2707 theDump += "WIRE : ";
2708 if (nbw < 10) theDump += " ";
2709 theDump += TCollection_AsciiString(nbw) + "\n";
2712 theDump += "FACE : ";
2713 if (nbf < 10) theDump += " ";
2714 theDump += TCollection_AsciiString(nbf) + "\n";
2717 theDump += "SHELL : ";
2718 if (nbs < 10) theDump += " ";
2719 theDump += TCollection_AsciiString(nbs) + "\n";
2722 theDump += "SOLID : ";
2723 if (nbo < 10) theDump += " ";
2724 theDump += TCollection_AsciiString(nbo) + "\n";
2729 //=======================================================================
2730 //function : GetProblemShapes
2731 // purpose : for StructuralDump
2732 //=======================================================================
2733 void GEOMImpl_IMeasureOperations::GetProblemShapes (const BRepCheck_Analyzer& theAna,
2734 const TopoDS_Shape& theShape,
2735 Handle(TopTools_HSequenceOfShape)& sl,
2736 Handle(TColStd_HArray1OfInteger)& NbProblems,
2737 TopTools_DataMapOfShapeListOfShape& theMap)
2739 for (TopoDS_Iterator iter(theShape); iter.More(); iter.Next()) {
2740 GetProblemShapes(theAna, iter.Value(), sl, NbProblems, theMap);
2742 TopAbs_ShapeEnum styp = theShape.ShapeType();
2743 BRepCheck_ListIteratorOfListOfStatus itl;
2744 TopTools_ListOfShape empty;
2745 if (!theMap.IsBound(theShape)) {
2746 theMap.Bind(theShape,empty);
2748 if (!theAna.Result(theShape).IsNull()) {
2749 itl.Initialize(theAna.Result(theShape)->Status());
2750 // !!! May be, we have to print all the problems, not only the first one ?
2751 if (itl.Value() != BRepCheck_NoError) {
2752 sl->Append(theShape);
2753 BRepCheck_Status stat = itl.Value();
2754 NbProblems->SetValue((Standard_Integer)stat,
2755 NbProblems->Value((Standard_Integer)stat) + 1);
2762 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_VERTEX, theMap);
2765 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_WIRE, theMap);
2766 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_EDGE, theMap);
2767 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_VERTEX, theMap);
2772 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_SHELL, theMap);
2779 //=======================================================================
2780 //function : Contains
2781 //=======================================================================
2782 static Standard_Boolean Contains (const TopTools_ListOfShape& L,
2783 const TopoDS_Shape& S)
2785 TopTools_ListIteratorOfListOfShape it;
2786 for (it.Initialize(L); it.More(); it.Next()) {
2787 if (it.Value().IsSame(S)) {
2788 return Standard_True;
2791 return Standard_False;
2794 //=======================================================================
2795 //function : GetProblemSub
2796 // purpose : for StructuralDump
2797 //=======================================================================
2798 void GEOMImpl_IMeasureOperations::GetProblemSub (const BRepCheck_Analyzer& theAna,
2799 const TopoDS_Shape& theShape,
2800 Handle(TopTools_HSequenceOfShape)& sl,
2801 Handle(TColStd_HArray1OfInteger)& NbProblems,
2802 const TopAbs_ShapeEnum Subtype,
2803 TopTools_DataMapOfShapeListOfShape& theMap)
2805 BRepCheck_ListIteratorOfListOfStatus itl;
2806 TopExp_Explorer exp;
2807 for (exp.Init(theShape, Subtype); exp.More(); exp.Next()) {
2808 const TopoDS_Shape& sub = exp.Current();
2810 const Handle(BRepCheck_Result)& res = theAna.Result(sub);
2811 for (res->InitContextIterator();
2812 res->MoreShapeInContext();
2813 res->NextShapeInContext()) {
2814 if (res->ContextualShape().IsSame(theShape) && !Contains(theMap(sub), theShape)) {
2815 theMap(sub).Append(theShape);
2816 itl.Initialize(res->StatusOnShape());
2818 if (itl.Value() != BRepCheck_NoError) {
2819 Standard_Integer ii = 0;
2821 for (ii = 1; ii <= sl->Length(); ii++)
2822 if (sl->Value(ii).IsSame(sub)) break;
2824 if (ii > sl->Length()) {
2826 BRepCheck_Status stat = itl.Value();
2827 NbProblems->SetValue((Standard_Integer)stat,
2828 NbProblems->Value((Standard_Integer)stat) + 1);
2830 for (ii = 1; ii <= sl->Length(); ii++)
2831 if (sl->Value(ii).IsSame(theShape)) break;
2832 if (ii > sl->Length()) {
2833 sl->Append(theShape);
2834 BRepCheck_Status stat = itl.Value();
2835 NbProblems->SetValue((Standard_Integer)stat,
2836 NbProblems->Value((Standard_Integer)stat) + 1);