1 // Copyright (C) 2007-2013 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 <GEOMUtils.hxx>
34 #include <GEOMAlgo_ShapeInfo.hxx>
35 #include <GEOMAlgo_ShapeInfoFiller.hxx>
37 #include <GEOM_Function.hxx>
38 #include <GEOM_PythonDump.hxx>
40 #include <NMTTools_CheckerSI.hxx>
42 #include <NMTDS_Tools.hxx>
43 #include <NMTDS_InterfPool.hxx>
44 #include <NMTDS_PInterfPool.hxx>
45 #include <NMTDS_PairBoolean.hxx>
46 #include <NMTDS_ShapesDataStructure.hxx>
47 #include <NMTDS_ListIteratorOfListOfPairBoolean.hxx>
49 #include <Basics_OCCTVersion.hxx>
51 #include <utilities.h>
53 #include <Utils_ExceptHandlers.hxx>
56 #include <TFunction_DriverTable.hxx>
57 #include <TFunction_Driver.hxx>
58 #include <TFunction_Logbook.hxx>
59 #include <TDF_Tool.hxx>
61 #include <BRep_Builder.hxx>
62 #include <BRep_TFace.hxx>
63 #include <BRep_Tool.hxx>
64 #include <BRepAdaptor_Surface.hxx>
65 #include <BRepBuilderAPI_Copy.hxx>
66 #include <BRepBndLib.hxx>
67 #include <BRepCheck.hxx>
68 #include <BRepCheck_ListIteratorOfListOfStatus.hxx>
69 #include <BRepCheck_Result.hxx>
70 #include <BRepCheck_Shell.hxx>
71 #include <BRepClass3d_SolidClassifier.hxx>
72 #include <BRepExtrema_DistShapeShape.hxx>
73 #include <BRepGProp.hxx>
74 #include <BRepTools.hxx>
76 #include <Bnd_Box.hxx>
81 #include <TopoDS_Edge.hxx>
82 #include <TopoDS_Face.hxx>
83 #include <TopoDS_Shape.hxx>
84 #include <TopoDS_Vertex.hxx>
85 #include <TopoDS_Compound.hxx>
86 #include <TopoDS_Iterator.hxx>
87 #include <TopExp_Explorer.hxx>
88 #include <TopTools_MapOfShape.hxx>
89 #include <TopTools_ListOfShape.hxx>
90 #include <TopTools_ListIteratorOfListOfShape.hxx>
92 #include <ShapeAnalysis.hxx>
93 #include <ShapeAnalysis_Surface.hxx>
94 #include <ShapeFix_Shape.hxx>
96 #include <GeomAPI_IntSS.hxx>
97 #include <GeomAPI_ProjectPointOnCurve.hxx>
99 #include <GeomAbs_SurfaceType.hxx>
101 #include <Geom_BezierSurface.hxx>
102 #include <Geom_BSplineSurface.hxx>
103 #include <Geom_Circle.hxx>
104 #include <Geom_ConicalSurface.hxx>
105 #include <Geom_CylindricalSurface.hxx>
106 #include <Geom_Line.hxx>
107 #include <Geom_OffsetSurface.hxx>
108 #include <Geom_Plane.hxx>
109 #include <Geom_RectangularTrimmedSurface.hxx>
110 #include <Geom_SphericalSurface.hxx>
111 #include <Geom_Surface.hxx>
112 #include <Geom_SurfaceOfLinearExtrusion.hxx>
113 #include <Geom_SurfaceOfRevolution.hxx>
114 #include <Geom_ToroidalSurface.hxx>
116 #include <GeomLProp_CLProps.hxx>
117 #include <GeomLProp_SLProps.hxx>
119 #include <GProp_GProps.hxx>
120 #include <GProp_PrincipalProps.hxx>
122 #include <gp_Pln.hxx>
123 #include <gp_Lin.hxx>
125 #include <Standard_Failure.hxx>
126 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
128 //=============================================================================
132 //=============================================================================
133 GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations (GEOM_Engine* theEngine, int theDocID)
134 : GEOM_IOperations(theEngine, theDocID)
136 MESSAGE("GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations");
139 //=============================================================================
143 //=============================================================================
144 GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations()
146 MESSAGE("GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations");
149 //=============================================================================
150 /*! Get kind and parameters of the given shape.
152 //=============================================================================
153 GEOMImpl_IMeasureOperations::ShapeKind GEOMImpl_IMeasureOperations::KindOfShape
154 (Handle(GEOM_Object) theShape,
155 Handle(TColStd_HSequenceOfInteger)& theIntegers,
156 Handle(TColStd_HSequenceOfReal)& theDoubles)
159 ShapeKind aKind = SK_NO_SHAPE;
161 if (theIntegers.IsNull()) theIntegers = new TColStd_HSequenceOfInteger;
162 else theIntegers->Clear();
164 if (theDoubles.IsNull()) theDoubles = new TColStd_HSequenceOfReal;
165 else theDoubles->Clear();
167 if (theShape.IsNull())
170 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
171 if (aRefShape.IsNull()) return aKind;
173 TopoDS_Shape aShape = aRefShape->GetValue();
174 if (aShape.IsNull()) return aKind;
176 int geom_type = theShape->GetType();
178 // check if it's advanced shape
179 if ( geom_type > ADVANCED_BASE ) {
185 GEOMAlgo_ShapeInfoFiller aSF;
186 aSF.SetShape(aShape);
188 Standard_Integer iErr = aSF.ErrorStatus();
190 SetErrorCode("Error in GEOMAlgo_ShapeInfoFiller");
193 const GEOMAlgo_ShapeInfo& anInfo = aSF.Info();
195 // Interprete results
196 TopAbs_ShapeEnum aType = anInfo.Type();
199 case TopAbs_COMPOUND:
200 case TopAbs_COMPSOLID:
202 // (+) geompy.kind.COMPOUND nb_solids nb_faces nb_edges nb_vertices
203 // (+) geompy.kind.COMPSOLID nb_solids nb_faces nb_edges nb_vertices
204 // ??? "nb_faces" - all faces or only 'standalone' faces?
205 if (aType == TopAbs_COMPOUND)
208 aKind = SK_COMPSOLID;
210 //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPOUND));
211 //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPSOLID));
212 theIntegers->Append(anInfo.NbSubShapes(TopAbs_SOLID));
213 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
214 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
215 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
221 // (+) geompy.kind.SHELL geompy.info.closed nb_faces nb_edges nb_vertices
222 // (+) geompy.kind.SHELL geompy.info.unclosed nb_faces nb_edges nb_vertices
225 theIntegers->Append((int)anInfo.KindOfClosed());
227 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
228 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
229 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
235 // (+) geompy.kind.WIRE geompy.info.closed nb_edges nb_vertices
236 // (+) geompy.kind.WIRE geompy.info.unclosed nb_edges nb_vertices
239 theIntegers->Append((int)anInfo.KindOfClosed());
241 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
242 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
250 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
253 case GEOMAlgo_KN_SPHERE:
254 // (+) geompy.kind.SPHERE xc yc zc R
258 gp_Pnt aC = anInfo.Location();
259 theDoubles->Append(aC.X());
260 theDoubles->Append(aC.Y());
261 theDoubles->Append(aC.Z());
263 theDoubles->Append(anInfo.Radius1());
266 case GEOMAlgo_KN_CYLINDER:
267 // (+) geompy.kind.CYLINDER xb yb zb dx dy dz R H
271 gp_Pnt aC = anInfo.Location();
272 theDoubles->Append(aC.X());
273 theDoubles->Append(aC.Y());
274 theDoubles->Append(aC.Z());
276 gp_Ax3 anAx3 = anInfo.Position();
277 gp_Dir aD = anAx3.Direction();
278 theDoubles->Append(aD.X());
279 theDoubles->Append(aD.Y());
280 theDoubles->Append(aD.Z());
282 theDoubles->Append(anInfo.Radius1());
283 theDoubles->Append(anInfo.Height());
286 case GEOMAlgo_KN_BOX:
287 // (+) geompy.kind.BOX xc yc zc ax ay az
291 gp_Pnt aC = anInfo.Location();
292 theDoubles->Append(aC.X());
293 theDoubles->Append(aC.Y());
294 theDoubles->Append(aC.Z());
296 gp_Ax3 anAx3 = anInfo.Position();
297 gp_Dir aD = anAx3.Direction();
298 gp_Dir aX = anAx3.XDirection();
301 if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
302 aX.IsParallel(gp::DX(), Precision::Angular())) {
303 theDoubles->Append(anInfo.Length()); // ax'
304 theDoubles->Append(anInfo.Width()); // ay'
305 theDoubles->Append(anInfo.Height()); // az'
307 else if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
308 aX.IsParallel(gp::DY(), Precision::Angular())) {
309 theDoubles->Append(anInfo.Width()); // ay'
310 theDoubles->Append(anInfo.Length()); // ax'
311 theDoubles->Append(anInfo.Height()); // az'
313 else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
314 aX.IsParallel(gp::DZ(), Precision::Angular())) {
315 theDoubles->Append(anInfo.Height()); // az'
316 theDoubles->Append(anInfo.Width()); // ay'
317 theDoubles->Append(anInfo.Length()); // ax'
319 else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
320 aX.IsParallel(gp::DY(), Precision::Angular())) {
321 theDoubles->Append(anInfo.Height()); // az'
322 theDoubles->Append(anInfo.Length()); // ax'
323 theDoubles->Append(anInfo.Width()); // ay'
325 else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
326 aX.IsParallel(gp::DZ(), Precision::Angular())) {
327 theDoubles->Append(anInfo.Width()); // ay'
328 theDoubles->Append(anInfo.Height()); // az'
329 theDoubles->Append(anInfo.Length()); // ax'
331 else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
332 aX.IsParallel(gp::DX(), Precision::Angular())) {
333 theDoubles->Append(anInfo.Length()); // ax'
334 theDoubles->Append(anInfo.Height()); // az'
335 theDoubles->Append(anInfo.Width()); // ay'
338 // (+) geompy.kind.ROTATED_BOX xo yo zo zx zy zz xx xy xz ax ay az
339 aKind = SK_ROTATED_BOX;
341 // Direction and XDirection
342 theDoubles->Append(aD.X());
343 theDoubles->Append(aD.Y());
344 theDoubles->Append(aD.Z());
346 theDoubles->Append(aX.X());
347 theDoubles->Append(aX.Y());
348 theDoubles->Append(aX.Z());
351 theDoubles->Append(anInfo.Length());
352 theDoubles->Append(anInfo.Width());
353 theDoubles->Append(anInfo.Height());
357 case GEOMAlgo_KN_TORUS:
358 // (+) geompy.kind.TORUS xc yc zc dx dy dz R_1 R_2
362 gp_Pnt aO = anInfo.Location();
363 theDoubles->Append(aO.X());
364 theDoubles->Append(aO.Y());
365 theDoubles->Append(aO.Z());
367 gp_Ax3 anAx3 = anInfo.Position();
368 gp_Dir aD = anAx3.Direction();
369 theDoubles->Append(aD.X());
370 theDoubles->Append(aD.Y());
371 theDoubles->Append(aD.Z());
373 theDoubles->Append(anInfo.Radius1());
374 theDoubles->Append(anInfo.Radius2());
377 case GEOMAlgo_KN_CONE:
378 // (+) geompy.kind.CONE xb yb zb dx dy dz R_1 R_2 H
382 gp_Pnt aO = anInfo.Location();
383 theDoubles->Append(aO.X());
384 theDoubles->Append(aO.Y());
385 theDoubles->Append(aO.Z());
387 gp_Ax3 anAx3 = anInfo.Position();
388 gp_Dir aD = anAx3.Direction();
389 theDoubles->Append(aD.X());
390 theDoubles->Append(aD.Y());
391 theDoubles->Append(aD.Z());
393 theDoubles->Append(anInfo.Radius1());
394 theDoubles->Append(anInfo.Radius2());
395 theDoubles->Append(anInfo.Height());
398 case GEOMAlgo_KN_POLYHEDRON:
399 // (+) geompy.kind.POLYHEDRON nb_faces nb_edges nb_vertices
401 aKind = SK_POLYHEDRON;
403 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
404 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
405 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
409 // (+) geompy.kind.SOLID nb_faces nb_edges nb_vertices
411 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
412 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
413 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
423 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
425 case GEOMAlgo_KN_SPHERE:
426 // (+) geompy.kind.SPHERE2D xc yc zc R
430 gp_Pnt aC = anInfo.Location();
431 theDoubles->Append(aC.X());
432 theDoubles->Append(aC.Y());
433 theDoubles->Append(aC.Z());
435 theDoubles->Append(anInfo.Radius1());
438 case GEOMAlgo_KN_CYLINDER:
439 // (+) geompy.kind.CYLINDER2D xb yb zb dx dy dz R H
441 aKind = SK_CYLINDER2D;
443 gp_Pnt aO = anInfo.Location();
444 theDoubles->Append(aO.X());
445 theDoubles->Append(aO.Y());
446 theDoubles->Append(aO.Z());
448 gp_Ax3 anAx3 = anInfo.Position();
449 gp_Dir aD = anAx3.Direction();
450 theDoubles->Append(aD.X());
451 theDoubles->Append(aD.Y());
452 theDoubles->Append(aD.Z());
454 theDoubles->Append(anInfo.Radius1());
455 theDoubles->Append(anInfo.Height());
458 case GEOMAlgo_KN_TORUS:
459 // (+) geompy.kind.TORUS2D xc yc zc dx dy dz R_1 R_2
463 gp_Pnt aO = anInfo.Location();
464 theDoubles->Append(aO.X());
465 theDoubles->Append(aO.Y());
466 theDoubles->Append(aO.Z());
468 gp_Ax3 anAx3 = anInfo.Position();
469 gp_Dir aD = anAx3.Direction();
470 theDoubles->Append(aD.X());
471 theDoubles->Append(aD.Y());
472 theDoubles->Append(aD.Z());
474 theDoubles->Append(anInfo.Radius1());
475 theDoubles->Append(anInfo.Radius2());
478 case GEOMAlgo_KN_CONE:
479 // (+) geompy.kind.CONE2D xc yc zc dx dy dz R_1 R_2 H
483 gp_Pnt aO = anInfo.Location();
484 theDoubles->Append(aO.X());
485 theDoubles->Append(aO.Y());
486 theDoubles->Append(aO.Z());
488 gp_Ax3 anAx3 = anInfo.Position();
489 gp_Dir aD = anAx3.Direction();
490 theDoubles->Append(aD.X());
491 theDoubles->Append(aD.Y());
492 theDoubles->Append(aD.Z());
494 theDoubles->Append(anInfo.Radius1());
495 theDoubles->Append(anInfo.Radius2());
496 theDoubles->Append(anInfo.Height());
499 case GEOMAlgo_KN_DISKCIRCLE:
500 // (+) geompy.kind.DISK_CIRCLE xc yc zc dx dy dz R
502 aKind = SK_DISK_CIRCLE;
504 gp_Pnt aC = anInfo.Location();
505 theDoubles->Append(aC.X());
506 theDoubles->Append(aC.Y());
507 theDoubles->Append(aC.Z());
509 gp_Ax3 anAx3 = anInfo.Position();
510 gp_Dir aD = anAx3.Direction();
511 theDoubles->Append(aD.X());
512 theDoubles->Append(aD.Y());
513 theDoubles->Append(aD.Z());
515 theDoubles->Append(anInfo.Radius1());
518 case GEOMAlgo_KN_DISKELLIPSE:
519 // (+) geompy.kind.DISK_ELLIPSE xc yc zc dx dy dz R_1 R_2
521 aKind = SK_DISK_ELLIPSE;
523 gp_Pnt aC = anInfo.Location();
524 theDoubles->Append(aC.X());
525 theDoubles->Append(aC.Y());
526 theDoubles->Append(aC.Z());
528 gp_Ax3 anAx3 = anInfo.Position();
529 gp_Dir aD = anAx3.Direction();
530 theDoubles->Append(aD.X());
531 theDoubles->Append(aD.Y());
532 theDoubles->Append(aD.Z());
534 theDoubles->Append(anInfo.Radius1());
535 theDoubles->Append(anInfo.Radius2());
538 case GEOMAlgo_KN_RECTANGLE:
539 case GEOMAlgo_KN_TRIANGLE:
540 case GEOMAlgo_KN_QUADRANGLE:
541 case GEOMAlgo_KN_POLYGON:
542 // (+) geompy.kind.POLYGON xo yo zo dx dy dz nb_edges nb_vertices
546 gp_Pnt aO = anInfo.Location();
547 theDoubles->Append(aO.X());
548 theDoubles->Append(aO.Y());
549 theDoubles->Append(aO.Z());
551 gp_Ax3 anAx3 = anInfo.Position();
552 gp_Dir aD = anAx3.Direction();
553 theDoubles->Append(aD.X());
554 theDoubles->Append(aD.Y());
555 theDoubles->Append(aD.Z());
557 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
558 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
561 case GEOMAlgo_KN_PLANE: // infinite
562 // (+) geompy.kind.PLANE xo yo zo dx dy dz
566 gp_Pnt aC = anInfo.Location();
567 theDoubles->Append(aC.X());
568 theDoubles->Append(aC.Y());
569 theDoubles->Append(aC.Z());
571 gp_Ax3 anAx3 = anInfo.Position();
572 gp_Dir aD = anAx3.Direction();
573 theDoubles->Append(aD.X());
574 theDoubles->Append(aD.Y());
575 theDoubles->Append(aD.Z());
579 if (anInfo.KindOfShape() == GEOMAlgo_KS_PLANE) {
580 // (+) geompy.kind.PLANAR xo yo zo dx dy dz nb_edges nb_vertices
584 gp_Pnt aC = anInfo.Location();
585 theDoubles->Append(aC.X());
586 theDoubles->Append(aC.Y());
587 theDoubles->Append(aC.Z());
589 gp_Ax3 anAx3 = anInfo.Position();
590 gp_Dir aD = anAx3.Direction();
591 theDoubles->Append(aD.X());
592 theDoubles->Append(aD.Y());
593 theDoubles->Append(aD.Z());
595 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
596 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
599 // ??? geompy.kind.FACE nb_edges nb_vertices _surface_type_id_
600 // (+) geompy.kind.FACE nb_edges nb_vertices
602 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
603 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
613 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
615 case GEOMAlgo_KN_CIRCLE:
617 // (+) geompy.kind.CIRCLE xc yc zc dx dy dz R
620 gp_Pnt aC = anInfo.Location();
621 theDoubles->Append(aC.X());
622 theDoubles->Append(aC.Y());
623 theDoubles->Append(aC.Z());
625 gp_Ax3 anAx3 = anInfo.Position();
626 gp_Dir aD = anAx3.Direction();
627 theDoubles->Append(aD.X());
628 theDoubles->Append(aD.Y());
629 theDoubles->Append(aD.Z());
631 theDoubles->Append(anInfo.Radius1());
634 case GEOMAlgo_KN_ARCCIRCLE:
636 // (+) geompy.kind.ARC_CIRCLE xc yc zc dx dy dz R x1 y1 z1 x2 y2 z2
637 aKind = SK_ARC_CIRCLE;
639 gp_Pnt aC = anInfo.Location();
640 theDoubles->Append(aC.X());
641 theDoubles->Append(aC.Y());
642 theDoubles->Append(aC.Z());
644 gp_Ax3 anAx3 = anInfo.Position();
645 gp_Dir aD = anAx3.Direction();
646 theDoubles->Append(aD.X());
647 theDoubles->Append(aD.Y());
648 theDoubles->Append(aD.Z());
650 theDoubles->Append(anInfo.Radius1());
652 gp_Pnt aP1 = anInfo.Pnt1();
653 theDoubles->Append(aP1.X());
654 theDoubles->Append(aP1.Y());
655 theDoubles->Append(aP1.Z());
657 gp_Pnt aP2 = anInfo.Pnt2();
658 theDoubles->Append(aP2.X());
659 theDoubles->Append(aP2.Y());
660 theDoubles->Append(aP2.Z());
663 case GEOMAlgo_KN_ELLIPSE:
665 // (+) geompy.kind.ELLIPSE xc yc zc dx dy dz R_1 R_2
668 gp_Pnt aC = anInfo.Location();
669 theDoubles->Append(aC.X());
670 theDoubles->Append(aC.Y());
671 theDoubles->Append(aC.Z());
673 gp_Ax3 anAx3 = anInfo.Position();
674 gp_Dir aD = anAx3.Direction();
675 theDoubles->Append(aD.X());
676 theDoubles->Append(aD.Y());
677 theDoubles->Append(aD.Z());
679 theDoubles->Append(anInfo.Radius1());
680 theDoubles->Append(anInfo.Radius2());
683 case GEOMAlgo_KN_ARCELLIPSE:
685 // (+) geompy.kind.ARC_ELLIPSE xc yc zc dx dy dz R_1 R_2 x1 y1 z1 x2 y2 z2
686 aKind = SK_ARC_ELLIPSE;
688 gp_Pnt aC = anInfo.Location();
689 theDoubles->Append(aC.X());
690 theDoubles->Append(aC.Y());
691 theDoubles->Append(aC.Z());
693 gp_Ax3 anAx3 = anInfo.Position();
694 gp_Dir aD = anAx3.Direction();
695 theDoubles->Append(aD.X());
696 theDoubles->Append(aD.Y());
697 theDoubles->Append(aD.Z());
699 theDoubles->Append(anInfo.Radius1());
700 theDoubles->Append(anInfo.Radius2());
702 gp_Pnt aP1 = anInfo.Pnt1();
703 theDoubles->Append(aP1.X());
704 theDoubles->Append(aP1.Y());
705 theDoubles->Append(aP1.Z());
707 gp_Pnt aP2 = anInfo.Pnt2();
708 theDoubles->Append(aP2.X());
709 theDoubles->Append(aP2.Y());
710 theDoubles->Append(aP2.Z());
713 case GEOMAlgo_KN_LINE:
715 // ??? geompy.kind.LINE x1 y1 z1 x2 y2 z2
716 // (+) geompy.kind.LINE x1 y1 z1 dx dy dz
719 gp_Pnt aO = anInfo.Location();
720 theDoubles->Append(aO.X());
721 theDoubles->Append(aO.Y());
722 theDoubles->Append(aO.Z());
724 gp_Dir aD = anInfo.Direction();
725 theDoubles->Append(aD.X());
726 theDoubles->Append(aD.Y());
727 theDoubles->Append(aD.Z());
730 case GEOMAlgo_KN_SEGMENT:
732 // (+) geompy.kind.SEGMENT x1 y1 z1 x2 y2 z2
735 gp_Pnt aP1 = anInfo.Pnt1();
736 theDoubles->Append(aP1.X());
737 theDoubles->Append(aP1.Y());
738 theDoubles->Append(aP1.Z());
740 gp_Pnt aP2 = anInfo.Pnt2();
741 theDoubles->Append(aP2.X());
742 theDoubles->Append(aP2.Y());
743 theDoubles->Append(aP2.Z());
747 // ??? geompy.kind.EDGE nb_vertices _curve_type_id_
748 // (+) geompy.kind.EDGE nb_vertices
749 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
756 // (+) geompy.kind.VERTEX x y z
759 gp_Pnt aP = anInfo.Location();
760 theDoubles->Append(aP.X());
761 theDoubles->Append(aP.Y());
762 theDoubles->Append(aP.Z());
771 //=============================================================================
775 //=============================================================================
776 void GEOMImpl_IMeasureOperations::GetPosition
777 (Handle(GEOM_Object) theShape,
778 Standard_Real& Ox, Standard_Real& Oy, Standard_Real& Oz,
779 Standard_Real& Zx, Standard_Real& Zy, Standard_Real& Zz,
780 Standard_Real& Xx, Standard_Real& Xy, Standard_Real& Xz)
784 //Set default values: global CS
785 Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
788 if (theShape.IsNull()) return;
790 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
791 if (aRefShape.IsNull()) return;
793 TopoDS_Shape aShape = aRefShape->GetValue();
794 if (aShape.IsNull()) {
795 SetErrorCode("The Objects has NULL Shape");
800 #if OCC_VERSION_LARGE > 0x06010000
804 gp_Ax3 anAx3 = GEOMUtils::GetPosition(aShape);
806 gp_Pnt anOri = anAx3.Location();
807 gp_Dir aDirZ = anAx3.Direction();
808 gp_Dir aDirX = anAx3.XDirection();
811 anOri.Coord(Ox, Oy, Oz);
812 aDirZ.Coord(Zx, Zy, Zz);
813 aDirX.Coord(Xx, Xy, Xz);
815 catch (Standard_Failure) {
816 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
817 SetErrorCode(aFail->GetMessageString());
824 //=============================================================================
828 //=============================================================================
829 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetCentreOfMass
830 (Handle(GEOM_Object) theShape)
834 if (theShape.IsNull()) return NULL;
836 //Add a new CentreOfMass object
837 Handle(GEOM_Object) aCDG = GetEngine()->AddObject(GetDocID(), GEOM_CDG);
839 //Add a new CentreOfMass function
840 Handle(GEOM_Function) aFunction =
841 aCDG->AddFunction(GEOMImpl_MeasureDriver::GetID(), CDG_MEASURE);
842 if (aFunction.IsNull()) return NULL;
844 //Check if the function is set correctly
845 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
847 GEOMImpl_IMeasure aCI (aFunction);
849 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
850 if (aRefShape.IsNull()) return NULL;
852 aCI.SetBase(aRefShape);
854 //Compute the CentreOfMass value
856 #if OCC_VERSION_LARGE > 0x06010000
859 if (!GetSolver()->ComputeFunction(aFunction)) {
860 SetErrorCode("Measure driver failed to compute centre of mass");
864 catch (Standard_Failure) {
865 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
866 SetErrorCode(aFail->GetMessageString());
870 //Make a Python command
871 GEOM::TPythonDump(aFunction) << aCDG << " = geompy.MakeCDG(" << theShape << ")";
877 //=============================================================================
881 //=============================================================================
882 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetVertexByIndex
883 (Handle(GEOM_Object) theShape,
884 Standard_Integer theIndex)
888 if (theShape.IsNull()) return NULL;
890 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
891 if (aRefShape.IsNull()) return NULL;
893 //Add a new Vertex object
894 Handle(GEOM_Object) aVertex = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
897 Handle(GEOM_Function) aFunction =
898 aVertex->AddFunction(GEOMImpl_MeasureDriver::GetID(), VERTEX_BY_INDEX);
899 if (aFunction.IsNull()) return NULL;
901 //Check if the function is set correctly
902 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
904 GEOMImpl_IMeasure aCI (aFunction);
905 aCI.SetBase(aRefShape);
906 aCI.SetIndex(theIndex);
910 #if OCC_VERSION_LARGE > 0x06010000
913 if (!GetSolver()->ComputeFunction(aFunction)) {
914 SetErrorCode("Vertex by index driver failed.");
918 catch (Standard_Failure) {
919 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
920 SetErrorCode(aFail->GetMessageString());
924 //Make a Python command
925 GEOM::TPythonDump(aFunction) << aVertex << " = geompy.GetVertexByIndex(" << theShape << ", " << theIndex << ")";
931 //=============================================================================
935 //=============================================================================
936 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetNormal
937 (Handle(GEOM_Object) theFace,
938 Handle(GEOM_Object) theOptionalPoint)
942 if (theFace.IsNull()) return NULL;
944 //Add a new Normale object
945 Handle(GEOM_Object) aNorm = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
947 //Add a new Normale function
948 Handle(GEOM_Function) aFunction =
949 aNorm->AddFunction(GEOMImpl_MeasureDriver::GetID(), VECTOR_FACE_NORMALE);
950 if (aFunction.IsNull()) return NULL;
952 //Check if the function is set correctly
953 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
955 GEOMImpl_IMeasure aCI (aFunction);
957 Handle(GEOM_Function) aFace = theFace->GetLastFunction();
958 if (aFace.IsNull()) return NULL;
962 if (!theOptionalPoint.IsNull()) {
963 Handle(GEOM_Function) anOptPnt = theOptionalPoint->GetLastFunction();
964 aCI.SetPoint(anOptPnt);
967 //Compute the Normale value
969 #if OCC_VERSION_LARGE > 0x06010000
972 if (!GetSolver()->ComputeFunction(aFunction)) {
973 SetErrorCode("Measure driver failed to compute normake of face");
977 catch (Standard_Failure) {
978 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
979 SetErrorCode(aFail->GetMessageString());
983 //Make a Python command
984 GEOM::TPythonDump pd (aFunction);
985 pd << aNorm << " = geompy.GetNormal(" << theFace;
986 if (!theOptionalPoint.IsNull()) {
987 pd << ", " << theOptionalPoint;
995 //=============================================================================
999 //=============================================================================
1000 void GEOMImpl_IMeasureOperations::GetBasicProperties (Handle(GEOM_Object) theShape,
1001 Standard_Real& theLength,
1002 Standard_Real& theSurfArea,
1003 Standard_Real& theVolume)
1007 if (theShape.IsNull()) return;
1009 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1010 if (aRefShape.IsNull()) return;
1012 TopoDS_Shape aShape = aRefShape->GetValue();
1013 if (aShape.IsNull()) {
1014 SetErrorCode("The Objects has NULL Shape");
1018 //Compute the parameters
1019 GProp_GProps LProps, SProps;
1021 #if OCC_VERSION_LARGE > 0x06010000
1024 BRepGProp::LinearProperties(aShape, LProps);
1025 theLength = LProps.Mass();
1027 BRepGProp::SurfaceProperties(aShape, SProps);
1028 theSurfArea = SProps.Mass();
1031 if (aShape.ShapeType() < TopAbs_SHELL) {
1032 for (TopExp_Explorer Exp (aShape, TopAbs_SOLID); Exp.More(); Exp.Next()) {
1033 GProp_GProps VProps;
1034 BRepGProp::VolumeProperties(Exp.Current(), VProps);
1035 theVolume += VProps.Mass();
1039 catch (Standard_Failure) {
1040 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1041 SetErrorCode(aFail->GetMessageString());
1048 //=============================================================================
1052 //=============================================================================
1053 void GEOMImpl_IMeasureOperations::GetInertia
1054 (Handle(GEOM_Object) theShape,
1055 Standard_Real& I11, Standard_Real& I12, Standard_Real& I13,
1056 Standard_Real& I21, Standard_Real& I22, Standard_Real& I23,
1057 Standard_Real& I31, Standard_Real& I32, Standard_Real& I33,
1058 Standard_Real& Ix , Standard_Real& Iy , Standard_Real& Iz)
1062 if (theShape.IsNull()) return;
1064 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1065 if (aRefShape.IsNull()) return;
1067 TopoDS_Shape aShape = aRefShape->GetValue();
1068 if (aShape.IsNull()) {
1069 SetErrorCode("The Objects has NULL Shape");
1073 //Compute the parameters
1074 GProp_GProps System;
1077 #if OCC_VERSION_LARGE > 0x06010000
1080 if (aShape.ShapeType() == TopAbs_VERTEX ||
1081 aShape.ShapeType() == TopAbs_EDGE ||
1082 aShape.ShapeType() == TopAbs_WIRE) {
1083 BRepGProp::LinearProperties(aShape, System);
1084 } else if (aShape.ShapeType() == TopAbs_FACE ||
1085 aShape.ShapeType() == TopAbs_SHELL) {
1086 BRepGProp::SurfaceProperties(aShape, System);
1088 BRepGProp::VolumeProperties(aShape, System);
1090 gp_Mat I = System.MatrixOfInertia();
1104 GProp_PrincipalProps Pr = System.PrincipalProperties();
1105 Pr.Moments(Ix,Iy,Iz);
1107 catch (Standard_Failure) {
1108 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1109 SetErrorCode(aFail->GetMessageString());
1116 //=============================================================================
1120 //=============================================================================
1121 void GEOMImpl_IMeasureOperations::GetBoundingBox
1122 (Handle(GEOM_Object) theShape,
1123 Standard_Real& Xmin, Standard_Real& Xmax,
1124 Standard_Real& Ymin, Standard_Real& Ymax,
1125 Standard_Real& Zmin, Standard_Real& Zmax)
1129 if (theShape.IsNull()) return;
1131 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1132 if (aRefShape.IsNull()) return;
1134 TopoDS_Shape aShape = aRefShape->GetValue();
1135 if (aShape.IsNull()) {
1136 SetErrorCode("The Objects has NULL Shape");
1140 //Compute the parameters
1144 #if OCC_VERSION_LARGE > 0x06010000
1147 BRepBuilderAPI_Copy aCopyTool (aShape);
1148 if (!aCopyTool.IsDone()) {
1149 SetErrorCode("GetBoundingBox Error: Bad shape detected");
1153 aShape = aCopyTool.Shape();
1155 // remove triangulation to obtain more exact boundaries
1156 BRepTools::Clean(aShape);
1158 BRepBndLib::Add(aShape, B);
1159 B.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
1161 catch (Standard_Failure) {
1162 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1163 SetErrorCode(aFail->GetMessageString());
1170 //=============================================================================
1174 //=============================================================================
1175 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetBoundingBox
1176 (Handle(GEOM_Object) theShape)
1180 if (theShape.IsNull()) return NULL;
1182 //Add a new BoundingBox object
1183 Handle(GEOM_Object) aBnd = GetEngine()->AddObject(GetDocID(), GEOM_BOX);
1185 //Add a new BoundingBox function
1186 Handle(GEOM_Function) aFunction =
1187 aBnd->AddFunction(GEOMImpl_MeasureDriver::GetID(), BND_BOX_MEASURE);
1188 if (aFunction.IsNull()) return NULL;
1190 //Check if the function is set correctly
1191 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
1193 GEOMImpl_IMeasure aCI (aFunction);
1195 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1196 if (aRefShape.IsNull()) return NULL;
1198 aCI.SetBase(aRefShape);
1200 //Compute the BoundingBox value
1202 #if OCC_VERSION_LARGE > 0x06010000
1205 if (!GetSolver()->ComputeFunction(aFunction)) {
1206 SetErrorCode("Measure driver failed to compute a bounding box");
1210 catch (Standard_Failure) {
1211 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1212 SetErrorCode(aFail->GetMessageString());
1216 //Make a Python command
1217 GEOM::TPythonDump(aFunction) << aBnd << " = geompy.MakeBoundingBox(" << theShape << ")";
1223 //=============================================================================
1227 //=============================================================================
1228 void GEOMImpl_IMeasureOperations::GetTolerance
1229 (Handle(GEOM_Object) theShape,
1230 Standard_Real& FaceMin, Standard_Real& FaceMax,
1231 Standard_Real& EdgeMin, Standard_Real& EdgeMax,
1232 Standard_Real& VertMin, Standard_Real& VertMax)
1236 if (theShape.IsNull()) return;
1238 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1239 if (aRefShape.IsNull()) return;
1241 TopoDS_Shape aShape = aRefShape->GetValue();
1242 if (aShape.IsNull()) {
1243 SetErrorCode("The Objects has NULL Shape");
1247 //Compute the parameters
1249 FaceMin = EdgeMin = VertMin = RealLast();
1250 FaceMax = EdgeMax = VertMax = -RealLast();
1253 #if OCC_VERSION_LARGE > 0x06010000
1256 for (TopExp_Explorer ExF (aShape, TopAbs_FACE); ExF.More(); ExF.Next()) {
1257 TopoDS_Face Face = TopoDS::Face(ExF.Current());
1258 T = BRep_Tool::Tolerance(Face);
1264 for (TopExp_Explorer ExE (aShape, TopAbs_EDGE); ExE.More(); ExE.Next()) {
1265 TopoDS_Edge Edge = TopoDS::Edge(ExE.Current());
1266 T = BRep_Tool::Tolerance(Edge);
1272 for (TopExp_Explorer ExV (aShape, TopAbs_VERTEX); ExV.More(); ExV.Next()) {
1273 TopoDS_Vertex Vertex = TopoDS::Vertex(ExV.Current());
1274 T = BRep_Tool::Tolerance(Vertex);
1281 catch (Standard_Failure) {
1282 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1283 SetErrorCode(aFail->GetMessageString());
1290 //=============================================================================
1294 //=============================================================================
1295 bool GEOMImpl_IMeasureOperations::CheckShape (Handle(GEOM_Object) theShape,
1296 const Standard_Boolean theIsCheckGeom,
1297 TCollection_AsciiString& theDump)
1301 if (theShape.IsNull()) return false;
1303 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1304 if (aRefShape.IsNull()) return false;
1306 TopoDS_Shape aShape = aRefShape->GetValue();
1307 if (aShape.IsNull()) {
1308 SetErrorCode("The Objects has NULL Shape");
1312 //Compute the parameters
1313 bool isValid = false;
1315 #if OCC_VERSION_LARGE > 0x06010000
1318 BRepCheck_Analyzer ana (aShape, theIsCheckGeom);
1319 if (ana.IsValid()) {
1323 StructuralDump(ana, aShape, theDump);
1326 catch (Standard_Failure) {
1327 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1328 SetErrorCode(aFail->GetMessageString());
1336 //=============================================================================
1338 * CheckSelfIntersections
1340 //=============================================================================
1341 bool GEOMImpl_IMeasureOperations::CheckSelfIntersections
1342 (Handle(GEOM_Object) theShape,
1343 Handle(TColStd_HSequenceOfInteger)& theIntersections)
1346 bool isGood = false;
1348 if (theIntersections.IsNull())
1349 theIntersections = new TColStd_HSequenceOfInteger;
1351 theIntersections->Clear();
1353 if (theShape.IsNull())
1356 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1357 if (aRefShape.IsNull()) return isGood;
1359 TopoDS_Shape aShape = aRefShape->GetValue();
1360 if (aShape.IsNull()) return isGood;
1364 TopoDS_Compound aCS;
1365 TopoDS_Shape aScopy;
1366 NMTDS_Tools::CopyShape(aShape, aScopy);
1368 // Map sub-shapes and their indices
1369 TopTools_IndexedMapOfShape anIndices;
1370 TopExp::MapShapes(aScopy, anIndices);
1372 aBB.MakeCompound(aCS);
1373 aBB.Add(aCS, aScopy);
1375 NMTTools_CheckerSI aCSI; // checker of self-interferences
1376 aCSI.SetCompositeShape(aCS);
1378 // 1. Launch the checker
1380 Standard_Integer iErr = aCSI.StopStatus();
1382 return false; // Error
1387 // 2. Take the shapes from DS
1388 const NMTDS_ShapesDataStructure& aDS = *(aCSI.DS());
1389 Standard_Integer aNbS = aDS.NumberOfShapesOfTheObject();
1391 // 3. Get the pairs of interfered shapes
1392 NMTDS_PInterfPool pIP = aCSI.IP();
1393 //const NMTDS_ListOfPassKeyBoolean& aLPKB = pIP->Get();
1394 const NMTDS_ListOfPairBoolean& aLPKB = pIP->Get();
1396 Standard_Integer n1, n2;
1397 //NMTDS_ListIteratorOfListOfPassKeyBoolean aIt;
1398 NMTDS_ListIteratorOfListOfPairBoolean aIt;
1400 aIt.Initialize(aLPKB);
1401 for (; aIt.More(); aIt.Next()) {
1402 //const NMTDS_PassKeyBoolean& aPKB = aIt.Value();
1403 const NMTDS_PairBoolean& aPKB = aIt.Value();
1406 if (n1 > aNbS || n2 > aNbS)
1407 return false; // Error
1409 const TopoDS_Shape& aS1 = aDS.Shape(n1);
1410 const TopoDS_Shape& aS2 = aDS.Shape(n2);
1412 theIntersections->Append(anIndices.FindIndex(aS1));
1413 theIntersections->Append(anIndices.FindIndex(aS2));
1421 //=============================================================================
1425 //=============================================================================
1426 TCollection_AsciiString GEOMImpl_IMeasureOperations::IsGoodForSolid (Handle(GEOM_Object) theShape)
1430 TCollection_AsciiString aRes = "";
1432 if (theShape.IsNull()) {
1433 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1436 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1437 if (aRefShape.IsNull()) {
1438 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1441 TopoDS_Shape aShape = aRefShape->GetValue();
1442 if (aShape.IsNull()) {
1443 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1446 if (aShape.ShapeType() == TopAbs_COMPOUND) {
1447 TopoDS_Iterator It (aShape, Standard_True, Standard_True);
1448 if (It.More()) aShape = It.Value();
1450 if (aShape.ShapeType() == TopAbs_SHELL) {
1451 BRepCheck_Shell chkShell (TopoDS::Shell(aShape));
1452 if (chkShell.Closed() == BRepCheck_NotClosed) {
1453 aRes = "WRN_SHAPE_UNCLOSED";
1457 aRes = "WRN_SHAPE_NOT_SHELL";
1469 //=============================================================================
1473 //=============================================================================
1474 TCollection_AsciiString GEOMImpl_IMeasureOperations::WhatIs (Handle(GEOM_Object) theShape)
1478 TCollection_AsciiString Astr;
1480 if (theShape.IsNull()) return Astr;
1482 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1483 if (aRefShape.IsNull()) return Astr;
1485 TopoDS_Shape aShape = aRefShape->GetValue();
1486 if (aShape.IsNull()) {
1487 SetErrorCode("The Objects has NULL Shape");
1491 //Compute the parameters
1492 if (aShape.ShapeType() == TopAbs_EDGE) {
1493 if (BRep_Tool::Degenerated(TopoDS::Edge(aShape))) {
1494 Astr = Astr + " It is a degenerated edge \n";
1498 Astr = Astr + " Number of sub-shapes : \n";
1501 #if OCC_VERSION_LARGE > 0x06010000
1504 int iType, nbTypes [TopAbs_SHAPE];
1505 for (iType = 0; iType < TopAbs_SHAPE; ++iType)
1507 nbTypes[aShape.ShapeType()]++;
1509 TopTools_MapOfShape aMapOfShape;
1510 aMapOfShape.Add(aShape);
1511 TopTools_ListOfShape aListOfShape;
1512 aListOfShape.Append(aShape);
1514 TopTools_ListIteratorOfListOfShape itL (aListOfShape);
1515 for (; itL.More(); itL.Next()) {
1516 TopoDS_Iterator it (itL.Value());
1517 for (; it.More(); it.Next()) {
1518 TopoDS_Shape s = it.Value();
1519 if (aMapOfShape.Add(s)) {
1520 aListOfShape.Append(s);
1521 nbTypes[s.ShapeType()]++;
1526 Astr = Astr + " VERTEX : " + TCollection_AsciiString(nbTypes[TopAbs_VERTEX]) + "\n";
1527 Astr = Astr + " EDGE : " + TCollection_AsciiString(nbTypes[TopAbs_EDGE]) + "\n";
1528 Astr = Astr + " WIRE : " + TCollection_AsciiString(nbTypes[TopAbs_WIRE]) + "\n";
1529 Astr = Astr + " FACE : " + TCollection_AsciiString(nbTypes[TopAbs_FACE]) + "\n";
1530 Astr = Astr + " SHELL : " + TCollection_AsciiString(nbTypes[TopAbs_SHELL]) + "\n";
1531 Astr = Astr + " SOLID : " + TCollection_AsciiString(nbTypes[TopAbs_SOLID]) + "\n";
1532 Astr = Astr + " COMPSOLID : " + TCollection_AsciiString(nbTypes[TopAbs_COMPSOLID]) + "\n";
1533 Astr = Astr + " COMPOUND : " + TCollection_AsciiString(nbTypes[TopAbs_COMPOUND]) + "\n";
1534 Astr = Astr + " SHAPE : " + TCollection_AsciiString(aMapOfShape.Extent());
1536 catch (Standard_Failure) {
1537 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1538 SetErrorCode(aFail->GetMessageString());
1546 //=============================================================================
1550 //=============================================================================
1551 std::vector<bool> GEOMImpl_IMeasureOperations::AreCoordsInside(Handle(GEOM_Object) theShape,
1552 const std::vector<double>& coords,
1555 std::vector<bool> res;
1556 if (!theShape.IsNull()) {
1557 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1558 if (!aRefShape.IsNull()) {
1559 TopoDS_Shape aShape = aRefShape->GetValue();
1560 if (!aShape.IsNull()) {
1561 BRepClass3d_SolidClassifier SC(aShape);
1562 unsigned int nb_points = coords.size()/3;
1563 for (int i = 0; i < nb_points; i++) {
1564 double x = coords[3*i];
1565 double y = coords[3*i+1];
1566 double z = coords[3*i+2];
1567 gp_Pnt aPnt(x, y, z);
1568 SC.Perform(aPnt, tolerance);
1569 res.push_back( ( SC.State() == TopAbs_IN ) || ( SC.State() == TopAbs_ON ) );
1577 //=======================================================================
1578 //function : CheckSingularCase
1579 //purpose : auxilary for GetMinDistance()
1580 // workaround for bugs 19899, 19908 and 19910 from Mantis
1581 //=======================================================================
1582 static double CheckSingularCase(const TopoDS_Shape& aSh1,
1583 const TopoDS_Shape& aSh2,
1584 gp_Pnt& Ptmp1, gp_Pnt& Ptmp2)
1586 bool IsChange1 = false;
1587 double AddDist1 = 0.0;
1588 TopExp_Explorer anExp;
1589 TopoDS_Shape tmpSh1, tmpSh2;
1591 for ( anExp.Init( aSh1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1593 tmpSh1 = anExp.Current();
1596 TopoDS_Shape sh = aSh1;
1597 while(sh.ShapeType()==TopAbs_COMPOUND) {
1598 TopoDS_Iterator it(sh);
1601 Handle(Geom_Surface) S = BRep_Tool::Surface(TopoDS::Face(tmpSh1));
1602 if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1603 S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1604 if( sh.ShapeType()==TopAbs_SHELL || sh.ShapeType()==TopAbs_FACE ) {
1607 // changes for 0020677: EDF 1219 GEOM: MinDistance gives 0 instead of 20.88
1608 //S->Bounds(U1,U2,V1,V2); changed by
1609 ShapeAnalysis::GetFaceUVBounds(TopoDS::Face(tmpSh1),U1,U2,V1,V2);
1610 // end of changes for 020677 (dmv)
1611 Handle(Geom_RectangularTrimmedSurface) TrS1 =
1612 new Geom_RectangularTrimmedSurface(S,U1,(U1+U2)/2.,V1,V2);
1613 Handle(Geom_RectangularTrimmedSurface) TrS2 =
1614 new Geom_RectangularTrimmedSurface(S,(U1+U2)/2.,U2,V1,V2);
1617 TopoDS_Compound Comp;
1618 B.MakeCompound(Comp);
1619 B.MakeFace(F1,TrS1,1.e-7);
1621 B.MakeFace(F2,TrS2,1.e-7);
1623 Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
1625 sfs->SetPrecision(1.e-6);
1626 sfs->SetMaxTolerance(1.0);
1628 tmpSh1 = sfs->Shape();
1632 if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ) {
1633 Handle(Geom_SphericalSurface) SS = Handle(Geom_SphericalSurface)::DownCast(S);
1634 gp_Pnt PC = SS->Location();
1637 B.MakeVertex(V,PC,1.e-7);
1639 AddDist1 = SS->Radius();
1643 Handle(Geom_ToroidalSurface) TS = Handle(Geom_ToroidalSurface)::DownCast(S);
1644 gp_Ax3 ax3 = TS->Position();
1645 Handle(Geom_Circle) C = new Geom_Circle(ax3.Ax2(),TS->MajorRadius());
1648 B.MakeEdge(E,C,1.e-7);
1650 AddDist1 = TS->MinorRadius();
1660 bool IsChange2 = false;
1661 double AddDist2 = 0.0;
1663 for ( anExp.Init( aSh2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1665 tmpSh2 = anExp.Current();
1668 TopoDS_Shape sh = aSh2;
1669 while(sh.ShapeType()==TopAbs_COMPOUND) {
1670 TopoDS_Iterator it(sh);
1673 Handle(Geom_Surface) S = BRep_Tool::Surface(TopoDS::Face(tmpSh2));
1674 if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1675 S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1676 if( sh.ShapeType()==TopAbs_SHELL || sh.ShapeType()==TopAbs_FACE ) {
1679 //S->Bounds(U1,U2,V1,V2);
1680 ShapeAnalysis::GetFaceUVBounds(TopoDS::Face(tmpSh2),U1,U2,V1,V2);
1681 Handle(Geom_RectangularTrimmedSurface) TrS1 =
1682 new Geom_RectangularTrimmedSurface(S,U1,(U1+U2)/2.,V1,V2);
1683 Handle(Geom_RectangularTrimmedSurface) TrS2 =
1684 new Geom_RectangularTrimmedSurface(S,(U1+U2)/2.,U2,V1,V2);
1687 TopoDS_Compound Comp;
1688 B.MakeCompound(Comp);
1689 B.MakeFace(F1,TrS1,1.e-7);
1691 B.MakeFace(F2,TrS2,1.e-7);
1693 Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
1695 sfs->SetPrecision(1.e-6);
1696 sfs->SetMaxTolerance(1.0);
1698 tmpSh2 = sfs->Shape();
1702 if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ) {
1703 Handle(Geom_SphericalSurface) SS = Handle(Geom_SphericalSurface)::DownCast(S);
1704 gp_Pnt PC = SS->Location();
1707 B.MakeVertex(V,PC,1.e-7);
1709 AddDist2 = SS->Radius();
1712 else if( S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1713 Handle(Geom_ToroidalSurface) TS = Handle(Geom_ToroidalSurface)::DownCast(S);
1714 gp_Ax3 ax3 = TS->Position();
1715 Handle(Geom_Circle) C = new Geom_Circle(ax3.Ax2(),TS->MajorRadius());
1718 B.MakeEdge(E,C,1.e-7);
1720 AddDist2 = TS->MinorRadius();
1731 if( !IsChange1 && !IsChange2 )
1734 BRepExtrema_DistShapeShape dst(tmpSh1,tmpSh2);
1736 double MinDist = 1.e9;
1737 gp_Pnt PMin1, PMin2, P1, P2;
1738 for (int i = 1; i <= dst.NbSolution(); i++) {
1739 P1 = dst.PointOnShape1(i);
1740 P2 = dst.PointOnShape2(i);
1741 Standard_Real Dist = P1.Distance(P2);
1742 if (MinDist > Dist) {
1753 gp_Dir aDir(gp_Vec(PMin1,PMin2));
1754 if( MinDist > (AddDist1+AddDist2) ) {
1755 Ptmp1 = gp_Pnt( PMin1.X() + aDir.X()*AddDist1,
1756 PMin1.Y() + aDir.Y()*AddDist1,
1757 PMin1.Z() + aDir.Z()*AddDist1 );
1758 Ptmp2 = gp_Pnt( PMin2.X() - aDir.X()*AddDist2,
1759 PMin2.Y() - aDir.Y()*AddDist2,
1760 PMin2.Z() - aDir.Z()*AddDist2 );
1761 return (MinDist - AddDist1 - AddDist2);
1764 if( AddDist1 > 0 ) {
1765 Ptmp1 = gp_Pnt( PMin1.X() + aDir.X()*AddDist1,
1766 PMin1.Y() + aDir.Y()*AddDist1,
1767 PMin1.Z() + aDir.Z()*AddDist1 );
1771 Ptmp2 = gp_Pnt( PMin2.X() - aDir.X()*AddDist2,
1772 PMin2.Y() - aDir.Y()*AddDist2,
1773 PMin2.Z() - aDir.Z()*AddDist2 );
1778 double res = MinDist - AddDist1 - AddDist2;
1779 if(res<0.) res = 0.0;
1785 static bool CheckSingularCase(const TopoDS_Shape& aSh1,
1786 const TopoDS_Shape& aSh2,
1789 TopExp_Explorer anExp;
1790 TopoDS_Shape tmpSh1, tmpSh2;
1792 for ( anExp.Init( aSh1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1794 tmpSh1 = anExp.Current();
1797 Handle(Geom_Surface) S1 = BRep_Tool::Surface(TopoDS::Face(tmpSh1));
1798 if( S1->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1799 S1->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1801 for ( anExp.Init( aSh2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1803 tmpSh2 = anExp.Current();
1804 Handle(Geom_Surface) S2 = BRep_Tool::Surface(TopoDS::Face(tmpSh2));
1805 GeomAPI_IntSS ISS(S1,S2,1.e-7);
1807 for(int i=1; i<=ISS.NbLines(); i++) {
1808 Handle(Geom_Curve) C3d = ISS.Line(i);
1811 B.MakeEdge(E,C3d,1.e-7);
1812 BRepExtrema_DistShapeShape dst(tmpSh2,E);
1814 gp_Pnt PMin1, PMin2, P1, P2;
1815 double MinDist = 1.e9;
1816 for (int i = 1; i <= dst.NbSolution(); i++) {
1817 P1 = dst.PointOnShape1(i);
1818 P2 = dst.PointOnShape2(i);
1819 Standard_Real Dist = P1.Distance(P2);
1820 if (MinDist > Dist) {
1834 for ( anExp.Init( aSh2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1836 tmpSh1 = anExp.Current();
1839 Handle(Geom_Surface) S1 = BRep_Tool::Surface(TopoDS::Face(tmpSh1));
1840 if( S1->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1841 S1->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1843 for ( anExp.Init( aSh1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1845 tmpSh2 = anExp.Current();
1846 Handle(Geom_Surface) S2 = BRep_Tool::Surface(TopoDS::Face(tmpSh2));
1847 GeomAPI_IntSS ISS(S1,S2,1.e-7);
1849 for(int i=1; i<=ISS.NbLines(); i++) {
1850 Handle(Geom_Curve) C3d = ISS.Line(i);
1853 B.MakeEdge(E,C3d,1.e-7);
1854 BRepExtrema_DistShapeShape dst(tmpSh2,E);
1857 double MinDist = 1.e9;
1858 for (int i = 1; i <= dst.NbSolution(); i++) {
1859 P1 = dst.PointOnShape1(i);
1860 P2 = dst.PointOnShape2(i);
1861 Standard_Real Dist = P1.Distance(P2);
1862 if (MinDist > Dist) {
1879 //=============================================================================
1883 //=============================================================================
1884 Standard_Real GEOMImpl_IMeasureOperations::GetMinDistance
1885 (Handle(GEOM_Object) theShape1, Handle(GEOM_Object) theShape2,
1886 Standard_Real& X1, Standard_Real& Y1, Standard_Real& Z1,
1887 Standard_Real& X2, Standard_Real& Y2, Standard_Real& Z2)
1890 Standard_Real MinDist = 1.e9;
1892 if (theShape1.IsNull() || theShape2.IsNull()) return MinDist;
1894 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
1895 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
1896 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return MinDist;
1898 TopoDS_Shape aShape1 = aRefShape1->GetValue();
1899 TopoDS_Shape aShape2 = aRefShape2->GetValue();
1900 if (aShape1.IsNull() || aShape2.IsNull()) {
1901 SetErrorCode("One of Objects has NULL Shape");
1905 //Compute the parameters
1907 #if OCC_VERSION_LARGE > 0x06010000
1911 // Issue 0020231: A min distance bug with torus and vertex.
1912 // Make GetMinDistance() return zero if a sole VERTEX is inside any of SOLIDs
1914 // which of shapes consists of only one vertex?
1915 TopExp_Explorer exp1(aShape1,TopAbs_VERTEX), exp2(aShape2,TopAbs_VERTEX);
1916 TopoDS_Shape V1 = exp1.More() ? exp1.Current() : TopoDS_Shape();
1917 TopoDS_Shape V2 = exp2.More() ? exp2.Current() : TopoDS_Shape();
1918 exp1.Next(); exp2.Next();
1919 if ( exp1.More() ) V1.Nullify();
1920 if ( exp2.More() ) V2.Nullify();
1921 // vertex and container of solids
1922 TopoDS_Shape V = V1.IsNull() ? V2 : V1;
1923 TopoDS_Shape S = V1.IsNull() ? aShape1 : aShape2;
1924 if ( !V.IsNull() ) {
1925 // classify vertex against solids
1926 gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( V ) );
1927 for ( exp1.Init( S, TopAbs_SOLID ); exp1.More(); exp1.Next() ) {
1928 BRepClass3d_SolidClassifier classifier( exp1.Current(), p, 1e-6);
1929 if ( classifier.State() == TopAbs_IN ) {
1930 p.Coord(X1, Y1, Z1);
1931 p.Coord(X2, Y2, Z2);
1937 // End Issue 0020231
1940 // additional workaround for bugs 19899, 19908 and 19910 from Mantis
1941 gp_Pnt Ptmp1, Ptmp2;
1942 double dist = CheckSingularCase(aShape1, aShape2, Ptmp1, Ptmp2);
1944 Ptmp1.Coord(X1, Y1, Z1);
1945 Ptmp2.Coord(X2, Y2, Z2);
1950 BRepExtrema_DistShapeShape dst (aShape1, aShape2);
1952 gp_Pnt PMin1, PMin2, P1, P2;
1954 for (int i = 1; i <= dst.NbSolution(); i++) {
1955 P1 = dst.PointOnShape1(i);
1956 P2 = dst.PointOnShape2(i);
1958 Standard_Real Dist = P1.Distance(P2);
1959 if (MinDist > Dist) {
1966 PMin1.Coord(X1, Y1, Z1);
1967 PMin2.Coord(X2, Y2, Z2);
1970 catch (Standard_Failure) {
1971 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1972 SetErrorCode(aFail->GetMessageString());
1980 //=======================================================================
1982 * Get coordinates of closest points of two shapes
1984 //=======================================================================
1985 Standard_Integer GEOMImpl_IMeasureOperations::ClosestPoints (Handle(GEOM_Object) theShape1,
1986 Handle(GEOM_Object) theShape2,
1987 Handle(TColStd_HSequenceOfReal)& theDoubles)
1990 Standard_Integer nbSolutions = 0;
1992 if (theShape1.IsNull() || theShape2.IsNull()) return nbSolutions;
1994 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
1995 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
1996 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return nbSolutions;
1998 TopoDS_Shape aShape1 = aRefShape1->GetValue();
1999 TopoDS_Shape aShape2 = aRefShape2->GetValue();
2000 if (aShape1.IsNull() || aShape2.IsNull()) {
2001 SetErrorCode("One of Objects has NULL Shape");
2005 // Compute the extremities
2007 #if OCC_VERSION_LARGE > 0x06010000
2012 // additional workaround for bugs 19899, 19908 and 19910 from Mantis
2014 double dist = CheckSingularCase(aShape1, aShape2, P1, P2);
2018 theDoubles->Append(P1.X());
2019 theDoubles->Append(P1.Y());
2020 theDoubles->Append(P1.Z());
2021 theDoubles->Append(P2.X());
2022 theDoubles->Append(P2.Y());
2023 theDoubles->Append(P2.Z());
2029 BRepExtrema_DistShapeShape dst (aShape1, aShape2);
2031 nbSolutions = dst.NbSolution();
2032 if (theDoubles.IsNull()) theDoubles = new TColStd_HSequenceOfReal;
2035 for (int i = 1; i <= nbSolutions; i++) {
2036 P1 = dst.PointOnShape1(i);
2037 P2 = dst.PointOnShape2(i);
2039 theDoubles->Append(P1.X());
2040 theDoubles->Append(P1.Y());
2041 theDoubles->Append(P1.Z());
2042 theDoubles->Append(P2.X());
2043 theDoubles->Append(P2.Y());
2044 theDoubles->Append(P2.Z());
2048 catch (Standard_Failure) {
2049 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2050 SetErrorCode(aFail->GetMessageString());
2058 //=======================================================================
2060 * Get coordinates of point
2062 //=======================================================================
2063 void GEOMImpl_IMeasureOperations::PointCoordinates (Handle(GEOM_Object) theShape,
2064 Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ)
2068 if (theShape.IsNull())
2071 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
2072 if (aRefShape.IsNull())
2075 TopoDS_Shape aShape = aRefShape->GetValue();
2076 if (aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX)
2078 SetErrorCode( "Shape must be a vertex" );
2083 #if OCC_VERSION_LARGE > 0x06010000
2086 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
2093 catch (Standard_Failure)
2095 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2096 SetErrorCode( aFail->GetMessageString() );
2100 //=======================================================================
2102 * Compute angle (in degrees) between two lines
2104 //=======================================================================
2105 Standard_Real GEOMImpl_IMeasureOperations::GetAngle (Handle(GEOM_Object) theLine1,
2106 Handle(GEOM_Object) theLine2)
2108 if (theLine1->GetType() == GEOM_VECTOR &&
2109 theLine2->GetType() == GEOM_VECTOR)
2110 return GetAngleBtwVectors(theLine1, theLine2);
2114 Standard_Real anAngle = -1.0;
2116 if (theLine1.IsNull() || theLine2.IsNull())
2119 Handle(GEOM_Function) aRefLine1 = theLine1->GetLastFunction();
2120 Handle(GEOM_Function) aRefLine2 = theLine2->GetLastFunction();
2121 if (aRefLine1.IsNull() || aRefLine2.IsNull())
2124 TopoDS_Shape aLine1 = aRefLine1->GetValue();
2125 TopoDS_Shape aLine2 = aRefLine2->GetValue();
2126 if (aLine1.IsNull() || aLine2.IsNull() ||
2127 aLine1.ShapeType() != TopAbs_EDGE ||
2128 aLine2.ShapeType() != TopAbs_EDGE)
2130 SetErrorCode("Two edges must be given");
2135 #if OCC_VERSION_LARGE > 0x06010000
2138 TopoDS_Edge E1 = TopoDS::Edge(aLine1);
2139 TopoDS_Edge E2 = TopoDS::Edge(aLine2);
2142 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp,lp);
2143 Handle(Geom_Curve) C2 = BRep_Tool::Curve(E2,fp,lp);
2145 if ( C1.IsNull() || C2.IsNull() ||
2146 !C1->IsKind(STANDARD_TYPE(Geom_Line)) ||
2147 !C2->IsKind(STANDARD_TYPE(Geom_Line)))
2149 SetErrorCode("The edges must be linear");
2153 Handle(Geom_Line) L1 = Handle(Geom_Line)::DownCast(C1);
2154 Handle(Geom_Line) L2 = Handle(Geom_Line)::DownCast(C2);
2156 gp_Lin aLin1 = L1->Lin();
2157 gp_Lin aLin2 = L2->Lin();
2159 anAngle = aLin1.Angle(aLin2);
2160 anAngle *= 180. / M_PI; // convert radians into degrees
2162 if (anAngle > 90.0) {
2163 anAngle = 180.0 - anAngle;
2168 catch (Standard_Failure)
2170 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2171 SetErrorCode(aFail->GetMessageString());
2177 //=======================================================================
2179 * Compute angle (in degrees) between two vectors
2181 //=======================================================================
2182 Standard_Real GEOMImpl_IMeasureOperations::GetAngleBtwVectors (Handle(GEOM_Object) theVec1,
2183 Handle(GEOM_Object) theVec2)
2187 Standard_Real anAngle = -1.0;
2189 if (theVec1.IsNull() || theVec2.IsNull())
2192 if (theVec1->GetType() != GEOM_VECTOR || theVec2->GetType() != GEOM_VECTOR) {
2193 SetErrorCode("Two vectors must be given");
2197 Handle(GEOM_Function) aRefVec1 = theVec1->GetLastFunction();
2198 Handle(GEOM_Function) aRefVec2 = theVec2->GetLastFunction();
2199 if (aRefVec1.IsNull() || aRefVec2.IsNull())
2202 TopoDS_Shape aVec1 = aRefVec1->GetValue();
2203 TopoDS_Shape aVec2 = aRefVec2->GetValue();
2204 if (aVec1.IsNull() || aVec2.IsNull() ||
2205 aVec1.ShapeType() != TopAbs_EDGE ||
2206 aVec2.ShapeType() != TopAbs_EDGE)
2208 SetErrorCode("Two edges must be given");
2213 #if OCC_VERSION_LARGE > 0x06010000
2216 TopoDS_Edge aE1 = TopoDS::Edge(aVec1);
2217 TopoDS_Edge aE2 = TopoDS::Edge(aVec2);
2219 TopoDS_Vertex aP11, aP12, aP21, aP22;
2220 TopExp::Vertices(aE1, aP11, aP12, Standard_True);
2221 TopExp::Vertices(aE2, aP21, aP22, Standard_True);
2222 if (aP11.IsNull() || aP12.IsNull() || aP21.IsNull() || aP22.IsNull()) {
2223 SetErrorCode("Bad edge given");
2227 gp_Vec aV1 (BRep_Tool::Pnt(aP11), BRep_Tool::Pnt(aP12));
2228 gp_Vec aV2 (BRep_Tool::Pnt(aP21), BRep_Tool::Pnt(aP22)) ;
2230 anAngle = aV1.Angle(aV2);
2231 anAngle *= 180. / M_PI; // convert radians into degrees
2235 catch (Standard_Failure)
2237 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2238 SetErrorCode(aFail->GetMessageString());
2245 //=============================================================================
2247 * CurveCurvatureByParam
2249 //=============================================================================
2250 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByParam
2251 (Handle(GEOM_Object) theCurve, Standard_Real& theParam)
2254 Standard_Real aRes = -1.0;
2256 if(theCurve.IsNull()) return aRes;
2258 Handle(GEOM_Function) aRefShape = theCurve->GetLastFunction();
2259 if(aRefShape.IsNull()) return aRes;
2261 TopoDS_Shape aShape = aRefShape->GetValue();
2262 if(aShape.IsNull()) {
2263 SetErrorCode("One of Objects has NULL Shape");
2267 Standard_Real aFP, aLP, aP;
2268 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aFP, aLP);
2269 aP = aFP + (aLP - aFP) * theParam;
2271 if(aCurve.IsNull()) return aRes;
2275 #if OCC_VERSION_LARGE > 0x06010000
2278 GeomLProp_CLProps Prop = GeomLProp_CLProps
2279 (aCurve, aP, 2, Precision::Confusion());
2280 aRes = fabs(Prop.Curvature());
2283 catch (Standard_Failure) {
2284 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2285 SetErrorCode(aFail->GetMessageString());
2289 if( aRes > Precision::Confusion() )
2298 //=============================================================================
2300 * CurveCurvatureByPoint
2302 //=============================================================================
2303 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByPoint
2304 (Handle(GEOM_Object) theCurve, Handle(GEOM_Object) thePoint)
2307 Standard_Real aRes = -1.0;
2309 if( theCurve.IsNull() || thePoint.IsNull() ) return aRes;
2311 Handle(GEOM_Function) aRefCurve = theCurve->GetLastFunction();
2312 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2313 if( aRefCurve.IsNull() || aRefPoint.IsNull() ) return aRes;
2315 TopoDS_Edge anEdge = TopoDS::Edge(aRefCurve->GetValue());
2316 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2317 if( anEdge.IsNull() || aPnt.IsNull() ) {
2318 SetErrorCode("One of Objects has NULL Shape");
2322 Standard_Real aFP, aLP;
2323 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFP, aLP);
2324 if(aCurve.IsNull()) return aRes;
2325 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2329 #if OCC_VERSION_LARGE > 0x06010000
2332 GeomAPI_ProjectPointOnCurve PPCurve(aPoint, aCurve, aFP, aLP);
2333 if(PPCurve.NbPoints()>0) {
2334 GeomLProp_CLProps Prop = GeomLProp_CLProps
2335 (aCurve, PPCurve.LowerDistanceParameter(), 2, Precision::Confusion());
2336 aRes = fabs(Prop.Curvature());
2340 catch (Standard_Failure) {
2341 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2342 SetErrorCode(aFail->GetMessageString());
2346 if( aRes > Precision::Confusion() )
2355 //=============================================================================
2357 * getSurfaceCurvatures
2359 //=============================================================================
2360 Standard_Real GEOMImpl_IMeasureOperations::getSurfaceCurvatures
2361 (const Handle(Geom_Surface)& aSurf,
2362 Standard_Real theUParam,
2363 Standard_Real theVParam,
2364 Standard_Boolean theNeedMaxCurv)
2367 Standard_Real aRes = 1.0;
2369 if (aSurf.IsNull()) return aRes;
2372 #if OCC_VERSION_LARGE > 0x06010000
2375 GeomLProp_SLProps Prop = GeomLProp_SLProps
2376 (aSurf, theUParam, theVParam, 2, Precision::Confusion());
2377 if(Prop.IsCurvatureDefined()) {
2378 if(Prop.IsUmbilic()) {
2379 //cout<<"is umbilic"<<endl;
2380 aRes = fabs(Prop.MeanCurvature());
2383 //cout<<"is not umbilic"<<endl;
2384 double c1 = fabs(Prop.MaxCurvature());
2385 double c2 = fabs(Prop.MinCurvature());
2394 catch (Standard_Failure) {
2395 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2396 SetErrorCode(aFail->GetMessageString());
2400 if( fabs(aRes) > Precision::Confusion() )
2409 //=============================================================================
2411 * MaxSurfaceCurvatureByParam
2413 //=============================================================================
2414 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByParam
2415 (Handle(GEOM_Object) theSurf,
2416 Standard_Real& theUParam,
2417 Standard_Real& theVParam)
2420 Standard_Real aRes = -1.0;
2422 if (theSurf.IsNull()) return aRes;
2424 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2425 if(aRefShape.IsNull()) return aRes;
2427 TopoDS_Shape aShape = aRefShape->GetValue();
2428 if(aShape.IsNull()) {
2429 SetErrorCode("One of Objects has NULL Shape");
2433 TopoDS_Face F = TopoDS::Face(aShape);
2434 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2436 //Compute the parameters
2437 Standard_Real U1,U2,V1,V2;
2438 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2439 Standard_Real U = U1 + (U2-U1)*theUParam;
2440 Standard_Real V = V1 + (V2-V1)*theVParam;
2442 return getSurfaceCurvatures(aSurf, U, V, true);
2446 //=============================================================================
2448 * MaxSurfaceCurvatureByPoint
2450 //=============================================================================
2451 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByPoint
2452 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2455 Standard_Real aRes = -1.0;
2457 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2459 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2460 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2461 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2463 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2464 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2465 if( aFace.IsNull() || aPnt.IsNull() ) {
2466 SetErrorCode("One of Objects has NULL Shape");
2470 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2471 if(aSurf.IsNull()) return aRes;
2472 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2474 //Compute the parameters
2475 ShapeAnalysis_Surface sas(aSurf);
2476 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2478 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), true);
2482 //=============================================================================
2484 * MinSurfaceCurvatureByParam
2486 //=============================================================================
2487 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByParam
2488 (Handle(GEOM_Object) theSurf,
2489 Standard_Real& theUParam,
2490 Standard_Real& theVParam)
2493 Standard_Real aRes = -1.0;
2495 if (theSurf.IsNull()) return aRes;
2497 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2498 if(aRefShape.IsNull()) return aRes;
2500 TopoDS_Shape aShape = aRefShape->GetValue();
2501 if(aShape.IsNull()) {
2502 SetErrorCode("One of Objects has NULL Shape");
2506 TopoDS_Face F = TopoDS::Face(aShape);
2507 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2509 //Compute the parameters
2510 Standard_Real U1,U2,V1,V2;
2511 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2512 Standard_Real U = U1 + (U2-U1)*theUParam;
2513 Standard_Real V = V1 + (V2-V1)*theVParam;
2515 return getSurfaceCurvatures(aSurf, U, V, false);
2519 //=============================================================================
2521 * MinSurfaceCurvatureByPoint
2523 //=============================================================================
2524 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByPoint
2525 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2528 Standard_Real aRes = -1.0;
2530 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2532 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2533 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2534 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2536 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2537 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2538 if( aFace.IsNull() || aPnt.IsNull() ) {
2539 SetErrorCode("One of Objects has NULL Shape");
2543 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2544 if(aSurf.IsNull()) return aRes;
2545 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2547 //Compute the parameters
2548 ShapeAnalysis_Surface sas(aSurf);
2549 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2551 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), false);
2555 //=======================================================================
2556 //function : StructuralDump
2557 //purpose : Structural (data exchange) style of output.
2558 //=======================================================================
2559 void GEOMImpl_IMeasureOperations::StructuralDump (const BRepCheck_Analyzer& theAna,
2560 const TopoDS_Shape& theShape,
2561 TCollection_AsciiString& theDump)
2565 theDump += " -- The Shape has problems :\n";
2566 theDump += " Check Count\n";
2567 theDump += " ------------------------------------------------\n";
2569 Standard_Integer last_stat = (Standard_Integer)BRepCheck_CheckFail;
2570 Handle(TColStd_HArray1OfInteger) NbProblems =
2571 new TColStd_HArray1OfInteger(1, last_stat);
2572 for (i = 1; i <= last_stat; i++)
2573 NbProblems->SetValue(i,0);
2575 Handle(TopTools_HSequenceOfShape) sl;
2576 sl = new TopTools_HSequenceOfShape();
2577 TopTools_DataMapOfShapeListOfShape theMap;
2579 GetProblemShapes(theAna, theShape, sl, NbProblems, theMap);
2582 Standard_Integer count = 0;
2583 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnCurve);
2585 theDump += " Invalid Point on Curve ................... ";
2586 theDump += TCollection_AsciiString(count) + "\n";
2588 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnCurveOnSurface);
2590 theDump += " Invalid Point on CurveOnSurface .......... ";
2591 theDump += TCollection_AsciiString(count) + "\n";
2593 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnSurface);
2595 theDump += " Invalid Point on Surface ................. ";
2596 theDump += TCollection_AsciiString(count) + "\n";
2598 count = NbProblems->Value((Standard_Integer)BRepCheck_No3DCurve);
2600 theDump += " No 3D Curve .............................. ";
2601 theDump += TCollection_AsciiString(count) + "\n";
2603 count = NbProblems->Value((Standard_Integer)BRepCheck_Multiple3DCurve);
2605 theDump += " Multiple 3D Curve ........................ ";
2606 theDump += TCollection_AsciiString(count) + "\n";
2608 count = NbProblems->Value((Standard_Integer)BRepCheck_Invalid3DCurve);
2610 theDump += " Invalid 3D Curve ......................... ";
2611 theDump += TCollection_AsciiString(count) + "\n";
2613 count = NbProblems->Value((Standard_Integer)BRepCheck_NoCurveOnSurface);
2615 theDump += " No Curve on Surface ...................... ";
2616 theDump += TCollection_AsciiString(count) + "\n";
2618 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidCurveOnSurface);
2620 theDump += " Invalid Curve on Surface ................. ";
2621 theDump += TCollection_AsciiString(count) + "\n";
2623 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidCurveOnClosedSurface);
2625 theDump += " Invalid Curve on closed Surface .......... ";
2626 theDump += TCollection_AsciiString(count) + "\n";
2628 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidSameRangeFlag);
2630 theDump += " Invalid SameRange Flag ................... ";
2631 theDump += TCollection_AsciiString(count) + "\n";
2633 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidSameParameterFlag);
2635 theDump += " Invalid SameParameter Flag ............... ";
2636 theDump += TCollection_AsciiString(count) + "\n";
2638 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidDegeneratedFlag);
2640 theDump += " Invalid Degenerated Flag ................. ";
2641 theDump += TCollection_AsciiString(count) + "\n";
2643 count = NbProblems->Value((Standard_Integer)BRepCheck_FreeEdge);
2645 theDump += " Free Edge ................................ ";
2646 theDump += TCollection_AsciiString(count) + "\n";
2648 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidMultiConnexity);
2650 theDump += " Invalid MultiConnexity ................... ";
2651 theDump += TCollection_AsciiString(count) + "\n";
2653 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidRange);
2655 theDump += " Invalid Range ............................ ";
2656 theDump += TCollection_AsciiString(count) + "\n";
2658 count = NbProblems->Value((Standard_Integer)BRepCheck_EmptyWire);
2660 theDump += " Empty Wire ............................... ";
2661 theDump += TCollection_AsciiString(count) + "\n";
2663 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantEdge);
2665 theDump += " Redundant Edge ........................... ";
2666 theDump += TCollection_AsciiString(count) + "\n";
2668 count = NbProblems->Value((Standard_Integer)BRepCheck_SelfIntersectingWire);
2670 theDump += " Self Intersecting Wire ................... ";
2671 theDump += TCollection_AsciiString(count) + "\n";
2673 count = NbProblems->Value((Standard_Integer)BRepCheck_NoSurface);
2675 theDump += " No Surface ............................... ";
2676 theDump += TCollection_AsciiString(count) + "\n";
2678 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidWire);
2680 theDump += " Invalid Wire ............................. ";
2681 theDump += TCollection_AsciiString(count) + "\n";
2683 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantWire);
2685 theDump += " Redundant Wire ........................... ";
2686 theDump += TCollection_AsciiString(count) + "\n";
2688 count = NbProblems->Value((Standard_Integer)BRepCheck_IntersectingWires);
2690 theDump += " Intersecting Wires ....................... ";
2691 theDump += TCollection_AsciiString(count) + "\n";
2693 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidImbricationOfWires);
2695 theDump += " Invalid Imbrication of Wires ............. ";
2696 theDump += TCollection_AsciiString(count) + "\n";
2698 count = NbProblems->Value((Standard_Integer)BRepCheck_EmptyShell);
2700 theDump += " Empty Shell .............................. ";
2701 theDump += TCollection_AsciiString(count) + "\n";
2703 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantFace);
2705 theDump += " Redundant Face ........................... ";
2706 theDump += TCollection_AsciiString(count) + "\n";
2708 count = NbProblems->Value((Standard_Integer)BRepCheck_UnorientableShape);
2710 theDump += " Unorientable Shape ....................... ";
2711 theDump += TCollection_AsciiString(count) + "\n";
2713 count = NbProblems->Value((Standard_Integer)BRepCheck_NotClosed);
2715 theDump += " Not Closed ............................... ";
2716 theDump += TCollection_AsciiString(count) + "\n";
2718 count = NbProblems->Value((Standard_Integer)BRepCheck_NotConnected);
2720 theDump += " Not Connected ............................ ";
2721 theDump += TCollection_AsciiString(count) + "\n";
2723 count = NbProblems->Value((Standard_Integer)BRepCheck_SubshapeNotInShape);
2725 theDump += " Sub-shape not in Shape .................... ";
2726 theDump += TCollection_AsciiString(count) + "\n";
2728 count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientation);
2730 theDump += " Bad Orientation .......................... ";
2731 theDump += TCollection_AsciiString(count) + "\n";
2733 count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientationOfSubshape);
2735 theDump += " Bad Orientation of Sub-shape .............. ";
2736 theDump += TCollection_AsciiString(count) + "\n";
2738 count = NbProblems->Value((Standard_Integer)BRepCheck_CheckFail);
2740 theDump += " checkshape failure ....................... ";
2741 theDump += TCollection_AsciiString(count) + "\n";
2744 theDump += " ------------------------------------------------\n";
2745 theDump += "*** Shapes with problems : ";
2746 theDump += TCollection_AsciiString(sl->Length()) + "\n";
2748 Standard_Integer nbv, nbe, nbw, nbf, nbs, nbo;
2749 nbv = nbe = nbw = nbf = nbs = nbo = 0;
2751 for (i = 1; i <= sl->Length(); i++) {
2752 TopoDS_Shape shi = sl->Value(i);
2753 TopAbs_ShapeEnum sti = shi.ShapeType();
2755 case TopAbs_VERTEX : nbv++; break;
2756 case TopAbs_EDGE : nbe++; break;
2757 case TopAbs_WIRE : nbw++; break;
2758 case TopAbs_FACE : nbf++; break;
2759 case TopAbs_SHELL : nbs++; break;
2760 case TopAbs_SOLID : nbo++; break;
2766 theDump += "VERTEX : ";
2767 if (nbv < 10) theDump += " ";
2768 theDump += TCollection_AsciiString(nbv) + "\n";
2771 theDump += "EDGE : ";
2772 if (nbe < 10) theDump += " ";
2773 theDump += TCollection_AsciiString(nbe) + "\n";
2776 theDump += "WIRE : ";
2777 if (nbw < 10) theDump += " ";
2778 theDump += TCollection_AsciiString(nbw) + "\n";
2781 theDump += "FACE : ";
2782 if (nbf < 10) theDump += " ";
2783 theDump += TCollection_AsciiString(nbf) + "\n";
2786 theDump += "SHELL : ";
2787 if (nbs < 10) theDump += " ";
2788 theDump += TCollection_AsciiString(nbs) + "\n";
2791 theDump += "SOLID : ";
2792 if (nbo < 10) theDump += " ";
2793 theDump += TCollection_AsciiString(nbo) + "\n";
2798 //=======================================================================
2799 //function : GetProblemShapes
2800 // purpose : for StructuralDump
2801 //=======================================================================
2802 void GEOMImpl_IMeasureOperations::GetProblemShapes (const BRepCheck_Analyzer& theAna,
2803 const TopoDS_Shape& theShape,
2804 Handle(TopTools_HSequenceOfShape)& sl,
2805 Handle(TColStd_HArray1OfInteger)& NbProblems,
2806 TopTools_DataMapOfShapeListOfShape& theMap)
2808 for (TopoDS_Iterator iter(theShape); iter.More(); iter.Next()) {
2809 GetProblemShapes(theAna, iter.Value(), sl, NbProblems, theMap);
2811 TopAbs_ShapeEnum styp = theShape.ShapeType();
2812 BRepCheck_ListIteratorOfListOfStatus itl;
2813 TopTools_ListOfShape empty;
2814 if (!theMap.IsBound(theShape)) {
2815 theMap.Bind(theShape,empty);
2817 if (!theAna.Result(theShape).IsNull()) {
2818 itl.Initialize(theAna.Result(theShape)->Status());
2819 // !!! May be, we have to print all the problems, not only the first one ?
2820 if (itl.Value() != BRepCheck_NoError) {
2821 sl->Append(theShape);
2822 BRepCheck_Status stat = itl.Value();
2823 NbProblems->SetValue((Standard_Integer)stat,
2824 NbProblems->Value((Standard_Integer)stat) + 1);
2831 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_VERTEX, theMap);
2834 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_WIRE, theMap);
2835 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_EDGE, theMap);
2836 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_VERTEX, theMap);
2841 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_SHELL, theMap);
2848 //=======================================================================
2849 //function : Contains
2850 //=======================================================================
2851 static Standard_Boolean Contains (const TopTools_ListOfShape& L,
2852 const TopoDS_Shape& S)
2854 TopTools_ListIteratorOfListOfShape it;
2855 for (it.Initialize(L); it.More(); it.Next()) {
2856 if (it.Value().IsSame(S)) {
2857 return Standard_True;
2860 return Standard_False;
2863 //=======================================================================
2864 //function : GetProblemSub
2865 // purpose : for StructuralDump
2866 //=======================================================================
2867 void GEOMImpl_IMeasureOperations::GetProblemSub (const BRepCheck_Analyzer& theAna,
2868 const TopoDS_Shape& theShape,
2869 Handle(TopTools_HSequenceOfShape)& sl,
2870 Handle(TColStd_HArray1OfInteger)& NbProblems,
2871 const TopAbs_ShapeEnum Subtype,
2872 TopTools_DataMapOfShapeListOfShape& theMap)
2874 BRepCheck_ListIteratorOfListOfStatus itl;
2875 TopExp_Explorer exp;
2876 for (exp.Init(theShape, Subtype); exp.More(); exp.Next()) {
2877 const TopoDS_Shape& sub = exp.Current();
2879 const Handle(BRepCheck_Result)& res = theAna.Result(sub);
2880 for (res->InitContextIterator();
2881 res->MoreShapeInContext();
2882 res->NextShapeInContext()) {
2883 if (res->ContextualShape().IsSame(theShape) && !Contains(theMap(sub), theShape)) {
2884 theMap(sub).Append(theShape);
2885 itl.Initialize(res->StatusOnShape());
2887 if (itl.Value() != BRepCheck_NoError) {
2888 Standard_Integer ii = 0;
2890 for (ii = 1; ii <= sl->Length(); ii++)
2891 if (sl->Value(ii).IsSame(sub)) break;
2893 if (ii > sl->Length()) {
2895 BRepCheck_Status stat = itl.Value();
2896 NbProblems->SetValue((Standard_Integer)stat,
2897 NbProblems->Value((Standard_Integer)stat) + 1);
2899 for (ii = 1; ii <= sl->Length(); ii++)
2900 if (sl->Value(ii).IsSame(theShape)) break;
2901 if (ii > sl->Length()) {
2902 sl->Append(theShape);
2903 BRepCheck_Status stat = itl.Value();
2904 NbProblems->SetValue((Standard_Integer)stat,
2905 NbProblems->Value((Standard_Integer)stat) + 1);