1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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 <GEOMImpl_IMeasureOperations.hxx>
24 #include <GEOMImpl_IMeasure.hxx>
25 #include <GEOMImpl_MeasureDriver.hxx>
26 #include <GEOMImpl_Types.hxx>
28 #include <GEOMUtils.hxx>
30 #include <GEOMAlgo_AlgoTools.hxx>
31 #include <GEOMAlgo_KindOfName.hxx>
32 #include <GEOMAlgo_ShapeInfoFiller.hxx>
34 #include <GEOM_PythonDump.hxx>
36 #include <utilities.h>
39 #include <Bnd_Box.hxx>
40 #include <BOPAlgo_CheckerSI.hxx>
41 #include <TopTools_ListOfShape.hxx>
42 #include <BOPDS_DS.hxx>
43 #include <BOPDS_MapOfPair.hxx>
44 #include <BOPDS_Pair.hxx>
45 #include <BRepBndLib.hxx>
46 #include <BRepBuilderAPI_Copy.hxx>
47 #include <BRepCheck_ListIteratorOfListOfStatus.hxx>
48 #include <BRepCheck_Shell.hxx>
49 #include <BRepClass3d_SolidClassifier.hxx>
50 #include <BRepClass_FaceClassifier.hxx>
51 #include <BRepExtrema_DistShapeShape.hxx>
52 #include <BRepExtrema_ShapeProximity.hxx>
53 #include <BRepExtrema_SelfIntersection.hxx>
54 #include <BRepExtrema_MapOfIntegerPackedMapOfInteger.hxx>
55 #include <BRepGProp.hxx>
56 #include <BRepTools.hxx>
57 #include <BRep_Tool.hxx>
58 #include <Geom_Line.hxx>
59 #include <GeomAPI_ProjectPointOnCurve.hxx>
60 #include <GeomAPI_ProjectPointOnSurf.hxx>
61 #include <GeomLProp_CLProps.hxx>
62 #include <GeomLProp_SLProps.hxx>
63 #include <Geom_Plane.hxx>
64 #include <GProp_GProps.hxx>
65 #include <GProp_PrincipalProps.hxx>
66 #include <ShapeAnalysis.hxx>
67 #include <ShapeAnalysis_Surface.hxx>
69 #include <TopExp_Explorer.hxx>
71 #include <TopoDS_Edge.hxx>
72 #include <TopTools_IndexedMapOfShape.hxx>
73 #include <TopTools_DataMapIteratorOfDataMapOfIntegerListOfShape.hxx>
74 #include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
75 #include <TopTools_ListIteratorOfListOfShape.hxx>
76 #include <TopTools_ListOfShape.hxx>
77 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
81 //=============================================================================
85 //=============================================================================
86 GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations (GEOM_Engine* theEngine)
87 : GEOM_IOperations(theEngine)
89 MESSAGE("GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations");
92 //=============================================================================
96 //=============================================================================
97 GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations()
99 MESSAGE("GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations");
102 //=============================================================================
103 /*! Get kind and parameters of the given shape.
105 //=============================================================================
106 GEOMImpl_IMeasureOperations::ShapeKind GEOMImpl_IMeasureOperations::KindOfShape
107 (Handle(GEOM_Object) theShape,
108 Handle(TColStd_HSequenceOfInteger)& theIntegers,
109 Handle(TColStd_HSequenceOfReal)& theDoubles)
112 ShapeKind aKind = SK_NO_SHAPE;
114 if (theIntegers.IsNull()) theIntegers = new TColStd_HSequenceOfInteger;
115 else theIntegers->Clear();
117 if (theDoubles.IsNull()) theDoubles = new TColStd_HSequenceOfReal;
118 else theDoubles->Clear();
120 if (theShape.IsNull())
123 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
124 if (aRefShape.IsNull()) return aKind;
126 TopoDS_Shape aShape = aRefShape->GetValue();
127 if (aShape.IsNull()) return aKind;
129 int geom_type = theShape->GetType();
131 // check if it's advanced shape
132 if ( geom_type > USER_TYPE ) {
138 GEOMAlgo_ShapeInfoFiller aSF;
139 aSF.SetShape(aShape);
142 Standard_Integer iErr = aSF.ErrorStatus();
145 SetErrorCode("Error in GEOMAlgo_ShapeInfoFiller");
148 const GEOMAlgo_ShapeInfo& anInfo = aSF.Info();
150 // specific processing for some "advanced" objects
151 switch ( geom_type ) {
153 // local coordinate system
154 // (+) geompy.kind.LCS xc yc zc xx xy xz yx yy yz zx zy zz
156 TopoDS_Face aFace = TopoDS::Face( aShape );
157 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
158 gp_Pnt aC = aPlane->Pln().Location();
159 gp_Ax3 anAx3 = aPlane->Pln().Position();
161 theDoubles->Append(aC.X());
162 theDoubles->Append(aC.Y());
163 theDoubles->Append(aC.Z());
165 gp_Dir aD = anAx3.XDirection();
166 theDoubles->Append(aD.X());
167 theDoubles->Append(aD.Y());
168 theDoubles->Append(aD.Z());
169 aD = anAx3.YDirection();
170 theDoubles->Append(aD.X());
171 theDoubles->Append(aD.Y());
172 theDoubles->Append(aD.Z());
173 aD = anAx3.Direction();
174 theDoubles->Append(aD.X());
175 theDoubles->Append(aD.Y());
176 theDoubles->Append(aD.Z());
182 // Interprete results
183 TopAbs_ShapeEnum aType = anInfo.Type();
186 case TopAbs_COMPOUND:
187 case TopAbs_COMPSOLID:
189 // (+) geompy.kind.COMPOUND nb_solids nb_faces nb_edges nb_vertices
190 // (+) geompy.kind.COMPSOLID nb_solids nb_faces nb_edges nb_vertices
191 // ??? "nb_faces" - all faces or only 'standalone' faces?
192 if (aType == TopAbs_COMPOUND)
195 aKind = SK_COMPSOLID;
197 //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPOUND));
198 //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPSOLID));
199 theIntegers->Append(anInfo.NbSubShapes(TopAbs_SOLID));
200 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
201 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
202 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
208 // (+) geompy.kind.SHELL geompy.info.closed nb_faces nb_edges nb_vertices
209 // (+) geompy.kind.SHELL geompy.info.unclosed nb_faces nb_edges nb_vertices
212 theIntegers->Append((int)anInfo.KindOfClosed());
214 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
215 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
216 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
222 // (+) geompy.kind.WIRE geompy.info.closed nb_edges nb_vertices
223 // (+) geompy.kind.WIRE geompy.info.unclosed nb_edges nb_vertices
226 theIntegers->Append((int)anInfo.KindOfClosed());
228 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
229 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
237 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
240 case GEOMAlgo_KN_SPHERE:
241 // (+) geompy.kind.SPHERE xc yc zc R
245 gp_Pnt aC = anInfo.Location();
246 theDoubles->Append(aC.X());
247 theDoubles->Append(aC.Y());
248 theDoubles->Append(aC.Z());
250 theDoubles->Append(anInfo.Radius1());
253 case GEOMAlgo_KN_CYLINDER:
254 // (+) geompy.kind.CYLINDER xb yb zb dx dy dz R H
258 gp_Pnt aC = anInfo.Location();
259 theDoubles->Append(aC.X());
260 theDoubles->Append(aC.Y());
261 theDoubles->Append(aC.Z());
263 gp_Ax3 anAx3 = anInfo.Position();
264 gp_Dir aD = anAx3.Direction();
265 theDoubles->Append(aD.X());
266 theDoubles->Append(aD.Y());
267 theDoubles->Append(aD.Z());
269 theDoubles->Append(anInfo.Radius1());
270 theDoubles->Append(anInfo.Height());
273 case GEOMAlgo_KN_BOX:
274 // (+) geompy.kind.BOX xc yc zc ax ay az
278 gp_Pnt aC = anInfo.Location();
279 theDoubles->Append(aC.X());
280 theDoubles->Append(aC.Y());
281 theDoubles->Append(aC.Z());
283 gp_Ax3 anAx3 = anInfo.Position();
284 gp_Dir aD = anAx3.Direction();
285 gp_Dir aX = anAx3.XDirection();
288 if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
289 aX.IsParallel(gp::DX(), Precision::Angular())) {
290 theDoubles->Append(anInfo.Length()); // ax'
291 theDoubles->Append(anInfo.Width()); // ay'
292 theDoubles->Append(anInfo.Height()); // az'
294 else if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
295 aX.IsParallel(gp::DY(), Precision::Angular())) {
296 theDoubles->Append(anInfo.Width()); // ay'
297 theDoubles->Append(anInfo.Length()); // ax'
298 theDoubles->Append(anInfo.Height()); // az'
300 else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
301 aX.IsParallel(gp::DZ(), Precision::Angular())) {
302 theDoubles->Append(anInfo.Height()); // az'
303 theDoubles->Append(anInfo.Width()); // ay'
304 theDoubles->Append(anInfo.Length()); // ax'
306 else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
307 aX.IsParallel(gp::DY(), Precision::Angular())) {
308 theDoubles->Append(anInfo.Height()); // az'
309 theDoubles->Append(anInfo.Length()); // ax'
310 theDoubles->Append(anInfo.Width()); // ay'
312 else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
313 aX.IsParallel(gp::DZ(), Precision::Angular())) {
314 theDoubles->Append(anInfo.Width()); // ay'
315 theDoubles->Append(anInfo.Height()); // az'
316 theDoubles->Append(anInfo.Length()); // ax'
318 else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
319 aX.IsParallel(gp::DX(), Precision::Angular())) {
320 theDoubles->Append(anInfo.Length()); // ax'
321 theDoubles->Append(anInfo.Height()); // az'
322 theDoubles->Append(anInfo.Width()); // ay'
325 // (+) geompy.kind.ROTATED_BOX xo yo zo zx zy zz xx xy xz ax ay az
326 aKind = SK_ROTATED_BOX;
328 // Direction and XDirection
329 theDoubles->Append(aD.X());
330 theDoubles->Append(aD.Y());
331 theDoubles->Append(aD.Z());
333 theDoubles->Append(aX.X());
334 theDoubles->Append(aX.Y());
335 theDoubles->Append(aX.Z());
338 theDoubles->Append(anInfo.Length());
339 theDoubles->Append(anInfo.Width());
340 theDoubles->Append(anInfo.Height());
344 case GEOMAlgo_KN_TORUS:
345 // (+) geompy.kind.TORUS xc yc zc dx dy dz R_1 R_2
349 gp_Pnt aO = anInfo.Location();
350 theDoubles->Append(aO.X());
351 theDoubles->Append(aO.Y());
352 theDoubles->Append(aO.Z());
354 gp_Ax3 anAx3 = anInfo.Position();
355 gp_Dir aD = anAx3.Direction();
356 theDoubles->Append(aD.X());
357 theDoubles->Append(aD.Y());
358 theDoubles->Append(aD.Z());
360 theDoubles->Append(anInfo.Radius1());
361 theDoubles->Append(anInfo.Radius2());
364 case GEOMAlgo_KN_CONE:
365 // (+) geompy.kind.CONE xb yb zb dx dy dz R_1 R_2 H
369 gp_Pnt aO = anInfo.Location();
370 theDoubles->Append(aO.X());
371 theDoubles->Append(aO.Y());
372 theDoubles->Append(aO.Z());
374 gp_Ax3 anAx3 = anInfo.Position();
375 gp_Dir aD = anAx3.Direction();
376 theDoubles->Append(aD.X());
377 theDoubles->Append(aD.Y());
378 theDoubles->Append(aD.Z());
380 theDoubles->Append(anInfo.Radius1());
381 theDoubles->Append(anInfo.Radius2());
382 theDoubles->Append(anInfo.Height());
385 case GEOMAlgo_KN_POLYHEDRON:
386 // (+) geompy.kind.POLYHEDRON nb_faces nb_edges nb_vertices
388 aKind = SK_POLYHEDRON;
390 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
391 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
392 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
396 // (+) geompy.kind.SOLID nb_faces nb_edges nb_vertices
398 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
399 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
400 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
410 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
412 case GEOMAlgo_KN_SPHERE:
413 // (+) geompy.kind.SPHERE2D xc yc zc R
417 gp_Pnt aC = anInfo.Location();
418 theDoubles->Append(aC.X());
419 theDoubles->Append(aC.Y());
420 theDoubles->Append(aC.Z());
422 theDoubles->Append(anInfo.Radius1());
425 case GEOMAlgo_KN_CYLINDER:
426 // (+) geompy.kind.CYLINDER2D xb yb zb dx dy dz R H
428 aKind = SK_CYLINDER2D;
430 gp_Pnt aO = anInfo.Location();
431 theDoubles->Append(aO.X());
432 theDoubles->Append(aO.Y());
433 theDoubles->Append(aO.Z());
435 gp_Ax3 anAx3 = anInfo.Position();
436 gp_Dir aD = anAx3.Direction();
437 theDoubles->Append(aD.X());
438 theDoubles->Append(aD.Y());
439 theDoubles->Append(aD.Z());
441 theDoubles->Append(anInfo.Radius1());
442 theDoubles->Append(anInfo.Height());
445 case GEOMAlgo_KN_TORUS:
446 // (+) geompy.kind.TORUS2D xc yc zc dx dy dz R_1 R_2
450 gp_Pnt aO = anInfo.Location();
451 theDoubles->Append(aO.X());
452 theDoubles->Append(aO.Y());
453 theDoubles->Append(aO.Z());
455 gp_Ax3 anAx3 = anInfo.Position();
456 gp_Dir aD = anAx3.Direction();
457 theDoubles->Append(aD.X());
458 theDoubles->Append(aD.Y());
459 theDoubles->Append(aD.Z());
461 theDoubles->Append(anInfo.Radius1());
462 theDoubles->Append(anInfo.Radius2());
465 case GEOMAlgo_KN_CONE:
466 // (+) geompy.kind.CONE2D xc yc zc dx dy dz R_1 R_2 H
470 gp_Pnt aO = anInfo.Location();
471 theDoubles->Append(aO.X());
472 theDoubles->Append(aO.Y());
473 theDoubles->Append(aO.Z());
475 gp_Ax3 anAx3 = anInfo.Position();
476 gp_Dir aD = anAx3.Direction();
477 theDoubles->Append(aD.X());
478 theDoubles->Append(aD.Y());
479 theDoubles->Append(aD.Z());
481 theDoubles->Append(anInfo.Radius1());
482 theDoubles->Append(anInfo.Radius2());
483 theDoubles->Append(anInfo.Height());
486 case GEOMAlgo_KN_DISKCIRCLE:
487 // (+) geompy.kind.DISK_CIRCLE xc yc zc dx dy dz R
489 aKind = SK_DISK_CIRCLE;
491 gp_Pnt aC = anInfo.Location();
492 theDoubles->Append(aC.X());
493 theDoubles->Append(aC.Y());
494 theDoubles->Append(aC.Z());
496 gp_Ax3 anAx3 = anInfo.Position();
497 gp_Dir aD = anAx3.Direction();
498 theDoubles->Append(aD.X());
499 theDoubles->Append(aD.Y());
500 theDoubles->Append(aD.Z());
502 theDoubles->Append(anInfo.Radius1());
505 case GEOMAlgo_KN_DISKELLIPSE:
506 // (+) geompy.kind.DISK_ELLIPSE xc yc zc dx dy dz R_1 R_2
508 aKind = SK_DISK_ELLIPSE;
510 gp_Pnt aC = anInfo.Location();
511 theDoubles->Append(aC.X());
512 theDoubles->Append(aC.Y());
513 theDoubles->Append(aC.Z());
515 gp_Ax3 anAx3 = anInfo.Position();
516 gp_Dir aD = anAx3.Direction();
517 theDoubles->Append(aD.X());
518 theDoubles->Append(aD.Y());
519 theDoubles->Append(aD.Z());
521 theDoubles->Append(anInfo.Radius1());
522 theDoubles->Append(anInfo.Radius2());
525 case GEOMAlgo_KN_RECTANGLE:
526 case GEOMAlgo_KN_TRIANGLE:
527 case GEOMAlgo_KN_QUADRANGLE:
528 case GEOMAlgo_KN_POLYGON:
529 // (+) geompy.kind.POLYGON xo yo zo dx dy dz nb_edges nb_vertices
533 gp_Pnt aO = anInfo.Location();
534 theDoubles->Append(aO.X());
535 theDoubles->Append(aO.Y());
536 theDoubles->Append(aO.Z());
538 gp_Ax3 anAx3 = anInfo.Position();
539 gp_Dir aD = anAx3.Direction();
540 theDoubles->Append(aD.X());
541 theDoubles->Append(aD.Y());
542 theDoubles->Append(aD.Z());
544 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
545 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
548 case GEOMAlgo_KN_PLANE: // infinite
549 // (+) geompy.kind.PLANE xo yo zo dx dy dz
553 gp_Pnt aC = anInfo.Location();
554 theDoubles->Append(aC.X());
555 theDoubles->Append(aC.Y());
556 theDoubles->Append(aC.Z());
558 gp_Ax3 anAx3 = anInfo.Position();
559 gp_Dir aD = anAx3.Direction();
560 theDoubles->Append(aD.X());
561 theDoubles->Append(aD.Y());
562 theDoubles->Append(aD.Z());
564 if (anInfo.KindOfBounds() != GEOMAlgo_KB_INFINITE)
566 // (+) geompy.kind.PLANAR xo yo zo dx dy dz nb_edges nb_vertices
569 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
570 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
575 // ??? geompy.kind.FACE nb_edges nb_vertices _surface_type_id_
576 // (+) geompy.kind.FACE nb_edges nb_vertices
577 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
578 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
587 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
589 case GEOMAlgo_KN_CIRCLE:
591 // (+) geompy.kind.CIRCLE xc yc zc dx dy dz R
594 gp_Pnt aC = anInfo.Location();
595 theDoubles->Append(aC.X());
596 theDoubles->Append(aC.Y());
597 theDoubles->Append(aC.Z());
599 gp_Ax3 anAx3 = anInfo.Position();
600 gp_Dir aD = anAx3.Direction();
601 theDoubles->Append(aD.X());
602 theDoubles->Append(aD.Y());
603 theDoubles->Append(aD.Z());
605 theDoubles->Append(anInfo.Radius1());
608 case GEOMAlgo_KN_ARCCIRCLE:
610 // (+) geompy.kind.ARC_CIRCLE xc yc zc dx dy dz R x1 y1 z1 x2 y2 z2
611 aKind = SK_ARC_CIRCLE;
613 gp_Pnt aC = anInfo.Location();
614 theDoubles->Append(aC.X());
615 theDoubles->Append(aC.Y());
616 theDoubles->Append(aC.Z());
618 gp_Ax3 anAx3 = anInfo.Position();
619 gp_Dir aD = anAx3.Direction();
620 theDoubles->Append(aD.X());
621 theDoubles->Append(aD.Y());
622 theDoubles->Append(aD.Z());
624 theDoubles->Append(anInfo.Radius1());
626 gp_Pnt aP1 = anInfo.Pnt1();
627 theDoubles->Append(aP1.X());
628 theDoubles->Append(aP1.Y());
629 theDoubles->Append(aP1.Z());
631 gp_Pnt aP2 = anInfo.Pnt2();
632 theDoubles->Append(aP2.X());
633 theDoubles->Append(aP2.Y());
634 theDoubles->Append(aP2.Z());
637 case GEOMAlgo_KN_ELLIPSE:
639 // (+) geompy.kind.ELLIPSE xc yc zc dx dy dz R_1 R_2
642 gp_Pnt aC = anInfo.Location();
643 theDoubles->Append(aC.X());
644 theDoubles->Append(aC.Y());
645 theDoubles->Append(aC.Z());
647 gp_Ax3 anAx3 = anInfo.Position();
648 gp_Dir aD = anAx3.Direction();
649 theDoubles->Append(aD.X());
650 theDoubles->Append(aD.Y());
651 theDoubles->Append(aD.Z());
653 theDoubles->Append(anInfo.Radius1());
654 theDoubles->Append(anInfo.Radius2());
657 case GEOMAlgo_KN_ARCELLIPSE:
659 // (+) geompy.kind.ARC_ELLIPSE xc yc zc dx dy dz R_1 R_2 x1 y1 z1 x2 y2 z2
660 aKind = SK_ARC_ELLIPSE;
662 gp_Pnt aC = anInfo.Location();
663 theDoubles->Append(aC.X());
664 theDoubles->Append(aC.Y());
665 theDoubles->Append(aC.Z());
667 gp_Ax3 anAx3 = anInfo.Position();
668 gp_Dir aD = anAx3.Direction();
669 theDoubles->Append(aD.X());
670 theDoubles->Append(aD.Y());
671 theDoubles->Append(aD.Z());
673 theDoubles->Append(anInfo.Radius1());
674 theDoubles->Append(anInfo.Radius2());
676 gp_Pnt aP1 = anInfo.Pnt1();
677 theDoubles->Append(aP1.X());
678 theDoubles->Append(aP1.Y());
679 theDoubles->Append(aP1.Z());
681 gp_Pnt aP2 = anInfo.Pnt2();
682 theDoubles->Append(aP2.X());
683 theDoubles->Append(aP2.Y());
684 theDoubles->Append(aP2.Z());
687 case GEOMAlgo_KN_LINE:
689 // ??? geompy.kind.LINE x1 y1 z1 x2 y2 z2
690 // (+) geompy.kind.LINE x1 y1 z1 dx dy dz
693 gp_Pnt aO = anInfo.Location();
694 theDoubles->Append(aO.X());
695 theDoubles->Append(aO.Y());
696 theDoubles->Append(aO.Z());
698 gp_Dir aD = anInfo.Direction();
699 theDoubles->Append(aD.X());
700 theDoubles->Append(aD.Y());
701 theDoubles->Append(aD.Z());
704 case GEOMAlgo_KN_SEGMENT:
706 // (+) geompy.kind.SEGMENT x1 y1 z1 x2 y2 z2
709 gp_Pnt aP1 = anInfo.Pnt1();
710 theDoubles->Append(aP1.X());
711 theDoubles->Append(aP1.Y());
712 theDoubles->Append(aP1.Z());
714 gp_Pnt aP2 = anInfo.Pnt2();
715 theDoubles->Append(aP2.X());
716 theDoubles->Append(aP2.Y());
717 theDoubles->Append(aP2.Z());
721 // ??? geompy.kind.EDGE nb_vertices _curve_type_id_
722 // (+) geompy.kind.EDGE nb_vertices
723 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
730 // (+) geompy.kind.VERTEX x y z
733 gp_Pnt aP = anInfo.Location();
734 theDoubles->Append(aP.X());
735 theDoubles->Append(aP.Y());
736 theDoubles->Append(aP.Z());
746 //=============================================================================
750 //=============================================================================
751 void GEOMImpl_IMeasureOperations::GetPosition
752 (Handle(GEOM_Object) theShape,
753 Standard_Real& Ox, Standard_Real& Oy, Standard_Real& Oz,
754 Standard_Real& Zx, Standard_Real& Zy, Standard_Real& Zz,
755 Standard_Real& Xx, Standard_Real& Xy, Standard_Real& Xz)
759 //Set default values: global CS
760 Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
763 if (theShape.IsNull()) return;
765 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
766 if (aRefShape.IsNull()) return;
768 TopoDS_Shape aShape = aRefShape->GetValue();
769 if (aShape.IsNull()) {
770 SetErrorCode("The Objects has NULL Shape");
777 gp_Ax3 anAx3 = GEOMUtils::GetPosition(aShape);
779 gp_Pnt anOri = anAx3.Location();
780 gp_Dir aDirZ = anAx3.Direction();
781 gp_Dir aDirX = anAx3.XDirection();
784 anOri.Coord(Ox, Oy, Oz);
785 aDirZ.Coord(Zx, Zy, Zz);
786 aDirX.Coord(Xx, Xy, Xz);
788 catch (Standard_Failure& aFail) {
789 SetErrorCode(aFail.GetMessageString());
796 //=============================================================================
800 //=============================================================================
801 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetCentreOfMass
802 (Handle(GEOM_Object) theShape)
806 if (theShape.IsNull()) return NULL;
808 //Add a new CentreOfMass object
809 Handle(GEOM_Object) aCDG = GetEngine()->AddObject(GEOM_CDG);
811 //Add a new CentreOfMass function
812 Handle(GEOM_Function) aFunction =
813 aCDG->AddFunction(GEOMImpl_MeasureDriver::GetID(), CDG_MEASURE);
814 if (aFunction.IsNull()) return NULL;
816 //Check if the function is set correctly
817 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
819 GEOMImpl_IMeasure aCI (aFunction);
821 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
822 if (aRefShape.IsNull()) return NULL;
824 aCI.SetBase(aRefShape);
826 //Compute the CentreOfMass value
829 if (!GetSolver()->ComputeFunction(aFunction)) {
830 SetErrorCode("Measure driver failed to compute centre of mass");
834 catch (Standard_Failure& aFail) {
835 SetErrorCode(aFail.GetMessageString());
839 //Make a Python command
840 GEOM::TPythonDump(aFunction) << aCDG << " = geompy.MakeCDG(" << theShape << ")";
846 //=============================================================================
850 //=============================================================================
851 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetVertexByIndex
852 (Handle(GEOM_Object) theShape,
853 Standard_Integer theIndex)
857 if (theShape.IsNull()) return NULL;
859 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
860 if (aRefShape.IsNull()) return NULL;
862 //Add a new Vertex object
863 Handle(GEOM_Object) aVertex = GetEngine()->AddObject(GEOM_POINT);
866 Handle(GEOM_Function) aFunction =
867 aVertex->AddFunction(GEOMImpl_MeasureDriver::GetID(), VERTEX_BY_INDEX);
868 if (aFunction.IsNull()) return NULL;
870 //Check if the function is set correctly
871 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
873 GEOMImpl_IMeasure aCI (aFunction);
874 aCI.SetBase(aRefShape);
875 aCI.SetIndex(theIndex);
880 if (!GetSolver()->ComputeFunction(aFunction)) {
881 SetErrorCode("Vertex by index driver failed.");
885 catch (Standard_Failure& aFail) {
886 SetErrorCode(aFail.GetMessageString());
890 //Make a Python command
891 GEOM::TPythonDump(aFunction) << aVertex << " = geompy.GetVertexByIndex(" << theShape << ", " << theIndex << ")";
897 //=============================================================================
901 //=============================================================================
902 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetNormal
903 (Handle(GEOM_Object) theFace,
904 Handle(GEOM_Object) theOptionalPoint)
908 if (theFace.IsNull()) return NULL;
910 //Add a new Normale object
911 Handle(GEOM_Object) aNorm = GetEngine()->AddObject(GEOM_VECTOR);
913 //Add a new Normale function
914 Handle(GEOM_Function) aFunction =
915 aNorm->AddFunction(GEOMImpl_MeasureDriver::GetID(), VECTOR_FACE_NORMALE);
916 if (aFunction.IsNull()) return NULL;
918 //Check if the function is set correctly
919 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
921 GEOMImpl_IMeasure aCI (aFunction);
923 Handle(GEOM_Function) aFace = theFace->GetLastFunction();
924 if (aFace.IsNull()) return NULL;
928 if (!theOptionalPoint.IsNull()) {
929 Handle(GEOM_Function) anOptPnt = theOptionalPoint->GetLastFunction();
930 aCI.SetPoint(anOptPnt);
933 //Compute the Normale value
936 if (!GetSolver()->ComputeFunction(aFunction)) {
937 SetErrorCode("Measure driver failed to compute normake of face");
941 catch (Standard_Failure& aFail) {
942 SetErrorCode(aFail.GetMessageString());
946 //Make a Python command
947 GEOM::TPythonDump pd (aFunction);
948 pd << aNorm << " = geompy.GetNormal(" << theFace;
949 if (!theOptionalPoint.IsNull()) {
950 pd << ", " << theOptionalPoint;
958 //=============================================================================
962 //=============================================================================
963 void GEOMImpl_IMeasureOperations::GetBasicProperties (Handle(GEOM_Object) theShape,
964 const Standard_Real theTolerance,
965 Standard_Real& theLength,
966 Standard_Real& theSurfArea,
967 Standard_Real& theVolume)
971 if (theShape.IsNull()) return;
973 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
974 if (aRefShape.IsNull()) return;
976 TopoDS_Shape aShape = aRefShape->GetValue();
977 if (aShape.IsNull()) {
978 SetErrorCode("The Objects has NULL Shape");
982 //Compute the parameters
983 GProp_GProps LProps, SProps;
984 Standard_Real anEps = theTolerance >= 0 ? theTolerance : 1.e-6;
987 BRepGProp::LinearProperties(aShape, LProps, Standard_True);
988 theLength = LProps.Mass();
990 BRepGProp::SurfaceProperties(aShape, SProps, anEps, Standard_True);
991 theSurfArea = SProps.Mass();
994 if (aShape.ShapeType() < TopAbs_SHELL) {
995 for (TopExp_Explorer Exp (aShape, TopAbs_SOLID); Exp.More(); Exp.Next()) {
997 BRepGProp::VolumeProperties(Exp.Current(), VProps, anEps, Standard_True);
998 theVolume += VProps.Mass();
1002 catch (Standard_Failure& aFail) {
1003 SetErrorCode(aFail.GetMessageString());
1010 //=============================================================================
1014 //=============================================================================
1015 void GEOMImpl_IMeasureOperations::GetInertia
1016 (Handle(GEOM_Object) theShape,
1017 Standard_Real& I11, Standard_Real& I12, Standard_Real& I13,
1018 Standard_Real& I21, Standard_Real& I22, Standard_Real& I23,
1019 Standard_Real& I31, Standard_Real& I32, Standard_Real& I33,
1020 Standard_Real& Ix , Standard_Real& Iy , Standard_Real& Iz)
1024 if (theShape.IsNull()) return;
1026 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1027 if (aRefShape.IsNull()) return;
1029 TopoDS_Shape aShape = aRefShape->GetValue();
1030 if (aShape.IsNull()) {
1031 SetErrorCode("The Objects has NULL Shape");
1035 //Compute the parameters
1036 GProp_GProps System;
1040 if (aShape.ShapeType() == TopAbs_VERTEX ||
1041 aShape.ShapeType() == TopAbs_EDGE ||
1042 aShape.ShapeType() == TopAbs_WIRE) {
1043 BRepGProp::LinearProperties(aShape, System, Standard_True);
1044 } else if (aShape.ShapeType() == TopAbs_FACE ||
1045 aShape.ShapeType() == TopAbs_SHELL) {
1046 BRepGProp::SurfaceProperties(aShape, System, Standard_True);
1048 BRepGProp::VolumeProperties(aShape, System, Standard_True);
1050 gp_Mat I = System.MatrixOfInertia();
1064 GProp_PrincipalProps Pr = System.PrincipalProperties();
1065 Pr.Moments(Ix,Iy,Iz);
1067 catch (Standard_Failure& aFail) {
1068 SetErrorCode(aFail.GetMessageString());
1075 //=============================================================================
1079 //=============================================================================
1080 void GEOMImpl_IMeasureOperations::GetBoundingBox
1081 (Handle(GEOM_Object) theShape,
1082 const Standard_Boolean precise,
1083 Standard_Real& Xmin, Standard_Real& Xmax,
1084 Standard_Real& Ymin, Standard_Real& Ymax,
1085 Standard_Real& Zmin, Standard_Real& Zmax)
1089 if (theShape.IsNull()) return;
1091 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1092 if (aRefShape.IsNull()) return;
1094 TopoDS_Shape aShape = aRefShape->GetValue();
1095 if (aShape.IsNull()) {
1096 SetErrorCode("The Objects has NULL Shape");
1100 //Compute the parameters
1105 BRepBuilderAPI_Copy aCopyTool (aShape);
1106 if (!aCopyTool.IsDone()) {
1107 SetErrorCode("GetBoundingBox Error: Bad shape detected");
1111 aShape = aCopyTool.Shape();
1113 // remove triangulation to obtain more exact boundaries
1114 BRepTools::Clean(aShape);
1116 BRepBndLib::Add(aShape, B);
1119 if (!GEOMUtils::PreciseBoundingBox(aShape, B)) {
1120 SetErrorCode("GetBoundingBox Error: Bounding box cannot be precised");
1125 B.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
1127 catch (Standard_Failure& aFail) {
1128 SetErrorCode(aFail.GetMessageString());
1135 //=============================================================================
1139 //=============================================================================
1140 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetBoundingBox
1141 (Handle(GEOM_Object) theShape,
1142 const Standard_Boolean precise)
1146 if (theShape.IsNull()) return NULL;
1148 //Add a new BoundingBox object
1149 Handle(GEOM_Object) aBnd = GetEngine()->AddObject(GEOM_BOX);
1151 //Add a new BoundingBox function
1152 const int aType = (precise ? BND_BOX_MEASURE_PRECISE : BND_BOX_MEASURE);
1153 Handle(GEOM_Function) aFunction =
1154 aBnd->AddFunction(GEOMImpl_MeasureDriver::GetID(), aType);
1155 if (aFunction.IsNull()) return NULL;
1157 //Check if the function is set correctly
1158 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
1160 GEOMImpl_IMeasure aCI (aFunction);
1162 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1163 if (aRefShape.IsNull()) return NULL;
1165 aCI.SetBase(aRefShape);
1167 //Compute the BoundingBox value
1170 if (!GetSolver()->ComputeFunction(aFunction)) {
1171 SetErrorCode("Measure driver failed to compute a bounding box");
1175 catch (Standard_Failure& aFail) {
1176 SetErrorCode(aFail.GetMessageString());
1180 //Make a Python command
1181 GEOM::TPythonDump aPd(aFunction);
1183 aPd << aBnd << " = geompy.MakeBoundingBox(" << theShape;
1195 //=============================================================================
1199 //=============================================================================
1200 void GEOMImpl_IMeasureOperations::GetTolerance
1201 (Handle(GEOM_Object) theShape,
1202 Standard_Real& FaceMin, Standard_Real& FaceMax,
1203 Standard_Real& EdgeMin, Standard_Real& EdgeMax,
1204 Standard_Real& VertMin, Standard_Real& VertMax)
1208 if (theShape.IsNull()) return;
1210 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1211 if (aRefShape.IsNull()) return;
1213 TopoDS_Shape aShape = aRefShape->GetValue();
1214 if (aShape.IsNull()) {
1215 SetErrorCode("The Objects has NULL Shape");
1219 //Compute the parameters
1221 FaceMin = EdgeMin = VertMin = RealLast();
1222 FaceMax = EdgeMax = VertMax = -RealLast();
1226 for (TopExp_Explorer ExF (aShape, TopAbs_FACE); ExF.More(); ExF.Next()) {
1227 TopoDS_Face Face = TopoDS::Face(ExF.Current());
1228 T = BRep_Tool::Tolerance(Face);
1234 for (TopExp_Explorer ExE (aShape, TopAbs_EDGE); ExE.More(); ExE.Next()) {
1235 TopoDS_Edge Edge = TopoDS::Edge(ExE.Current());
1236 T = BRep_Tool::Tolerance(Edge);
1242 for (TopExp_Explorer ExV (aShape, TopAbs_VERTEX); ExV.More(); ExV.Next()) {
1243 TopoDS_Vertex Vertex = TopoDS::Vertex(ExV.Current());
1244 T = BRep_Tool::Tolerance(Vertex);
1251 catch (Standard_Failure& aFail) {
1252 SetErrorCode(aFail.GetMessageString());
1259 //=============================================================================
1263 //=============================================================================
1264 bool GEOMImpl_IMeasureOperations::CheckShape (Handle(GEOM_Object) theShape,
1265 const Standard_Boolean theIsCheckGeom,
1266 std::list<ShapeError> &theErrors)
1271 if (theShape.IsNull()) return false;
1273 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1274 if (aRefShape.IsNull()) return false;
1276 TopoDS_Shape aShape = aRefShape->GetValue();
1277 if (aShape.IsNull()) {
1278 SetErrorCode("The Objects has NULL Shape");
1282 //Compute the parameters
1283 bool isValid = false;
1286 BRepCheck_Analyzer ana (aShape, theIsCheckGeom);
1287 if (ana.IsValid()) {
1290 FillErrors(ana, aShape, theErrors);
1293 catch (Standard_Failure& aFail) {
1294 SetErrorCode(aFail.GetMessageString());
1302 //=============================================================================
1306 //=============================================================================
1307 TCollection_AsciiString GEOMImpl_IMeasureOperations::PrintShapeErrors
1308 (Handle(GEOM_Object) theShape,
1309 const std::list<ShapeError> &theErrors)
1311 TCollection_AsciiString aDump;
1313 if (theShape.IsNull()) {
1317 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1319 if (aRefShape.IsNull()) {
1323 TopoDS_Shape aShape = aRefShape->GetValue();
1325 if (aShape.IsNull()) {
1326 SetErrorCode("The Objects has NULL Shape");
1330 if (!theErrors.empty()) {
1331 // The shape is not valid. Prepare errors for dump.
1332 TopTools_IndexedMapOfShape anIndices;
1333 std::list<ShapeError>::const_iterator anIter = theErrors.begin();
1334 Standard_Integer nbv, nbe, nbw, nbf, nbs, nbo;
1335 nbv = nbe = nbw = nbf = nbs = nbo = 0;
1337 // Map sub-shapes and their indices
1338 TopExp::MapShapes(aShape, anIndices);
1340 const Standard_Integer aNbSubShapes = anIndices.Extent();
1341 TColStd_MapOfInteger aMapPbInd;
1343 aDump += " -- The Shape has problems :\n";
1344 aDump += " Check Count\n";
1345 aDump += " ------------------------------------------------\n";
1347 for (; anIter != theErrors.end(); anIter++) {
1348 Standard_Integer aNbShapes = anIter->incriminated.size();
1350 switch(anIter->error) {
1351 case BRepCheck_InvalidPointOnCurve:
1352 aDump += " Invalid Point on Curve ................... ";
1354 case BRepCheck_InvalidPointOnCurveOnSurface:
1355 aDump += " Invalid Point on CurveOnSurface .......... ";
1357 case BRepCheck_InvalidPointOnSurface:
1358 aDump += " Invalid Point on Surface ................. ";
1360 case BRepCheck_No3DCurve:
1361 aDump += " No 3D Curve .............................. ";
1363 case BRepCheck_Multiple3DCurve:
1364 aDump += " Multiple 3D Curve ........................ ";
1366 case BRepCheck_Invalid3DCurve:
1367 aDump += " Invalid 3D Curve ......................... ";
1369 case BRepCheck_NoCurveOnSurface:
1370 aDump += " No Curve on Surface ...................... ";
1372 case BRepCheck_InvalidCurveOnSurface:
1373 aDump += " Invalid Curve on Surface ................. ";
1375 case BRepCheck_InvalidCurveOnClosedSurface:
1376 aDump += " Invalid Curve on closed Surface .......... ";
1378 case BRepCheck_InvalidSameRangeFlag:
1379 aDump += " Invalid SameRange Flag ................... ";
1381 case BRepCheck_InvalidSameParameterFlag:
1382 aDump += " Invalid SameParameter Flag ............... ";
1384 case BRepCheck_InvalidDegeneratedFlag:
1385 aDump += " Invalid Degenerated Flag ................. ";
1387 case BRepCheck_FreeEdge:
1388 aDump += " Free Edge ................................ ";
1390 case BRepCheck_InvalidMultiConnexity:
1391 aDump += " Invalid MultiConnexity ................... ";
1393 case BRepCheck_InvalidRange:
1394 aDump += " Invalid Range ............................ ";
1396 case BRepCheck_EmptyWire:
1397 aDump += " Empty Wire ............................... ";
1399 case BRepCheck_RedundantEdge:
1400 aDump += " Redundant Edge ........................... ";
1402 case BRepCheck_SelfIntersectingWire:
1403 aDump += " Self Intersecting Wire ................... ";
1405 case BRepCheck_NoSurface:
1406 aDump += " No Surface ............................... ";
1408 case BRepCheck_InvalidWire:
1409 aDump += " Invalid Wire ............................. ";
1411 case BRepCheck_RedundantWire:
1412 aDump += " Redundant Wire ........................... ";
1414 case BRepCheck_IntersectingWires:
1415 aDump += " Intersecting Wires ....................... ";
1417 case BRepCheck_InvalidImbricationOfWires:
1418 aDump += " Invalid Imbrication of Wires ............. ";
1420 case BRepCheck_EmptyShell:
1421 aDump += " Empty Shell .............................. ";
1423 case BRepCheck_RedundantFace:
1424 aDump += " Redundant Face ........................... ";
1426 case BRepCheck_UnorientableShape:
1427 aDump += " Unorientable Shape ....................... ";
1429 case BRepCheck_NotClosed:
1430 aDump += " Not Closed ............................... ";
1432 case BRepCheck_NotConnected:
1433 aDump += " Not Connected ............................ ";
1435 case BRepCheck_SubshapeNotInShape:
1436 aDump += " Sub-shape not in Shape ................... ";
1438 case BRepCheck_BadOrientation:
1439 aDump += " Bad Orientation .......................... ";
1441 case BRepCheck_BadOrientationOfSubshape:
1442 aDump += " Bad Orientation of Sub-shape ............. ";
1444 case BRepCheck_InvalidToleranceValue:
1445 aDump += " Invalid Tolerance Value .................. ";
1447 case BRepCheck_CheckFail:
1448 aDump += " Check Shape Failure ...................... ";
1454 aDump += TCollection_AsciiString(aNbShapes) + "\n";
1456 // Count types of shape.
1457 std::list<int>::const_iterator aShIter = anIter->incriminated.begin();
1459 for (; aShIter != anIter->incriminated.end(); aShIter++) {
1460 const Standard_Integer anIndex = *aShIter;
1462 if (anIndex > 0 && anIndex <= aNbSubShapes && aMapPbInd.Add(anIndex)) {
1463 const TopoDS_Shape &aSubShape = anIndices.FindKey(anIndex);
1464 const TopAbs_ShapeEnum aType = aSubShape.ShapeType();
1467 case TopAbs_VERTEX : nbv++; break;
1468 case TopAbs_EDGE : nbe++; break;
1469 case TopAbs_WIRE : nbw++; break;
1470 case TopAbs_FACE : nbf++; break;
1471 case TopAbs_SHELL : nbs++; break;
1472 case TopAbs_SOLID : nbo++; break;
1479 const Standard_Integer aNbFaultyShapes = nbv + nbe + nbw + nbf + nbs + nbo;
1480 aDump += " ------------------------------------------------\n";
1481 aDump += "*** Shapes with problems : ";
1482 aDump += TCollection_AsciiString(aNbFaultyShapes) + "\n";
1485 aDump += "VERTEX : ";
1486 if (nbv < 10) aDump += " ";
1487 aDump += TCollection_AsciiString(nbv) + "\n";
1491 if (nbe < 10) aDump += " ";
1492 aDump += TCollection_AsciiString(nbe) + "\n";
1496 if (nbw < 10) aDump += " ";
1497 aDump += TCollection_AsciiString(nbw) + "\n";
1501 if (nbf < 10) aDump += " ";
1502 aDump += TCollection_AsciiString(nbf) + "\n";
1505 aDump += "SHELL : ";
1506 if (nbs < 10) aDump += " ";
1507 aDump += TCollection_AsciiString(nbs) + "\n";
1510 aDump += "SOLID : ";
1511 if (nbo < 10) aDump += " ";
1512 aDump += TCollection_AsciiString(nbo) + "\n";
1519 //=============================================================================
1521 * CheckSelfIntersections
1523 //=============================================================================
1524 bool GEOMImpl_IMeasureOperations::CheckSelfIntersections
1525 (Handle(GEOM_Object) theShape,
1526 const SICheckLevel theCheckLevel,
1527 Handle(TColStd_HSequenceOfInteger)& theIntersections)
1531 if (theIntersections.IsNull())
1532 theIntersections = new TColStd_HSequenceOfInteger;
1534 theIntersections->Clear();
1536 if (theShape.IsNull())
1539 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1540 if (aRefShape.IsNull()) return false;
1542 TopoDS_Shape aShape = aRefShape->GetValue();
1543 if (aShape.IsNull()) return false;
1546 TopoDS_Shape aScopy;
1548 GEOMAlgo_AlgoTools::CopyShape(aShape, aScopy);
1550 // Map sub-shapes and their indices
1551 TopTools_IndexedMapOfShape anIndices;
1552 TopExp::MapShapes(aScopy, anIndices);
1554 TopTools_ListOfShape aLCS;
1555 aLCS.Append(aScopy);
1557 BOPAlgo_CheckerSI aCSI; // checker of self-interferences
1558 aCSI.SetArguments(aLCS);
1559 aCSI.SetLevelOfCheck(theCheckLevel);
1561 // 1. Launch the checker
1563 Standard_Boolean iErr = aCSI.HasErrors();
1566 Standard_Integer aNbS, n1, n2;
1567 BOPDS_MapIteratorOfMapOfPair aItMPK;
1569 // 2. Take the shapes from DS
1570 const BOPDS_DS& aDS = aCSI.DS();
1571 aNbS=aDS.NbShapes();
1573 // 3. Get the pairs of interfered shapes
1574 const BOPDS_MapOfPair& aMPK=aDS.Interferences();
1575 aItMPK.Initialize(aMPK);
1576 for (; aItMPK.More(); aItMPK.Next()) {
1577 const BOPDS_Pair& aPK=aItMPK.Value();
1578 aPK.Indices(n1, n2);
1580 if (n1 > aNbS || n2 > aNbS){
1581 return false; // Error
1583 const TopoDS_Shape& aS1 = aDS.Shape(n1);
1584 const TopoDS_Shape& aS2 = aDS.Shape(n2);
1586 theIntersections->Append(anIndices.FindIndex(aS1));
1587 theIntersections->Append(anIndices.FindIndex(aS2));
1594 return theIntersections->IsEmpty();
1597 //=============================================================================
1599 * CheckSelfIntersectionsFast
1601 //=============================================================================
1602 bool GEOMImpl_IMeasureOperations::CheckSelfIntersectionsFast
1603 (Handle(GEOM_Object) theShape,
1604 float theDeflection, double theTolerance,
1605 Handle(TColStd_HSequenceOfInteger)& theIntersections)
1609 if (theIntersections.IsNull())
1610 theIntersections = new TColStd_HSequenceOfInteger;
1612 theIntersections->Clear();
1614 if (theShape.IsNull())
1617 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1618 if (aRefShape.IsNull()) return false;
1620 TopoDS_Shape aShape = aRefShape->GetValue();
1621 if (aShape.IsNull()) return false;
1624 TopoDS_Shape aScopy;
1626 GEOMAlgo_AlgoTools::CopyShape(aShape, aScopy);
1627 GEOMUtils::MeshShape(aScopy, theDeflection);
1629 // Map sub-shapes and their indices
1630 TopTools_IndexedMapOfShape anIndices;
1631 TopExp::MapShapes(aScopy, anIndices);
1633 // Checker of fast interferences
1634 BRepExtrema_SelfIntersection aTool(aScopy, (theTolerance <= 0.) ? 0.0 : theTolerance);
1636 // Launch the checker
1639 const BRepExtrema_MapOfIntegerPackedMapOfInteger& intersections = aTool.OverlapElements();
1641 std::set<Standard_Integer> processed;
1643 for (BRepExtrema_MapOfIntegerPackedMapOfInteger::Iterator it(intersections); it.More(); it.Next()) {
1644 Standard_Integer idxLeft = it.Key();
1645 if (processed.count(idxLeft) > 0) continue; // already added
1646 processed.insert(idxLeft);
1647 const TColStd_PackedMapOfInteger& overlaps = it.Value();
1648 for (TColStd_MapIteratorOfPackedMapOfInteger subit(overlaps); subit.More(); subit.Next()) {
1649 Standard_Integer idxRight = subit.Key();
1650 if (processed.count(idxRight) > 0) continue; // already added
1651 const TopoDS_Shape& aS1 = aTool.GetSubShape(idxLeft);
1652 const TopoDS_Shape& aS2 = aTool.GetSubShape(idxRight);
1653 theIntersections->Append(anIndices.FindIndex(aS1));
1654 theIntersections->Append(anIndices.FindIndex(aS2));
1661 return theIntersections->IsEmpty();
1664 //=============================================================================
1668 //=============================================================================
1669 bool GEOMImpl_IMeasureOperations::CheckBOPArguments
1670 (const Handle(GEOM_Object) &theShape)
1674 if (theShape.IsNull()) {
1678 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1680 if (aRefShape.IsNull()) {
1684 TopoDS_Shape aShape = aRefShape->GetValue();
1686 if (aShape.IsNull()) {
1690 //Compute the parameters
1691 bool isValid = GEOMUtils::CheckBOPArguments(aShape);
1698 //=============================================================================
1702 //=============================================================================
1703 bool GEOMImpl_IMeasureOperations::FastIntersect (Handle(GEOM_Object) theShape1, Handle(GEOM_Object) theShape2,
1704 double theTolerance, float theDeflection,
1705 Handle(TColStd_HSequenceOfInteger)& theIntersections1,
1706 Handle(TColStd_HSequenceOfInteger)& theIntersections2)
1709 bool isGood = false;
1711 if (theIntersections1.IsNull())
1712 theIntersections1 = new TColStd_HSequenceOfInteger;
1714 theIntersections1->Clear();
1716 if (theIntersections2.IsNull())
1717 theIntersections2 = new TColStd_HSequenceOfInteger;
1719 theIntersections2->Clear();
1721 if (theShape1.IsNull() || theShape2.IsNull()) {
1722 SetErrorCode("Objects have NULL Shape");
1726 if (theShape1 == theShape2) {
1727 SetErrorCode("Objects are equal");
1730 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
1731 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
1732 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return isGood;
1734 TopoDS_Shape aShape1 = aRefShape1->GetValue();
1735 TopoDS_Shape aShape2 = aRefShape2->GetValue();
1736 if (aShape1.IsNull() || aShape2.IsNull()) return isGood;
1739 TopoDS_Shape aScopy1, aScopy2;
1740 GEOMAlgo_AlgoTools::CopyShape(aShape1, aScopy1);
1741 GEOMAlgo_AlgoTools::CopyShape(aShape2, aScopy2);
1743 GEOMUtils::MeshShape(aScopy1, theDeflection);
1744 GEOMUtils::MeshShape(aScopy2, theDeflection);
1746 // Map sub-shapes and their indices
1747 TopTools_IndexedMapOfShape anIndices1, anIndices2;
1748 TopExp::MapShapes(aScopy1, anIndices1);
1749 TopExp::MapShapes(aScopy2, anIndices2);
1751 TopTools_ListOfShape aLCS1, aLCS2;
1752 aLCS1.Append(aScopy1); aLCS2.Append(aScopy2);
1754 BRepExtrema_ShapeProximity aBSP; // checker of fast interferences
1755 aBSP.LoadShape1(aScopy1); aBSP.LoadShape2(aScopy2);
1756 aBSP.SetTolerance((theTolerance <= 0.) ? 0.0 : theTolerance);
1758 // 1. Launch the checker
1761 // 2. Get sets of IDs of overlapped faces
1762 for (BRepExtrema_MapOfIntegerPackedMapOfInteger::Iterator anIt1 (aBSP.OverlapSubShapes1()); anIt1.More(); anIt1.Next())
1764 const TopoDS_Shape& aS1 = aBSP.GetSubShape1(anIt1.Key());
1765 theIntersections1->Append(anIndices1.FindIndex(aS1));
1768 for (BRepExtrema_MapOfIntegerPackedMapOfInteger::Iterator anIt2 (aBSP.OverlapSubShapes2()); anIt2.More(); anIt2.Next())
1770 const TopoDS_Shape& aS2 = aBSP.GetSubShape2(anIt2.Key());
1771 theIntersections2->Append(anIndices2.FindIndex(aS2));
1774 isGood = !theIntersections1->IsEmpty() && !theIntersections1->IsEmpty();
1782 //=============================================================================
1786 //=============================================================================
1787 TCollection_AsciiString GEOMImpl_IMeasureOperations::IsGoodForSolid (Handle(GEOM_Object) theShape)
1791 TCollection_AsciiString aRes = "";
1793 if (theShape.IsNull()) {
1794 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1797 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1798 if (aRefShape.IsNull()) {
1799 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1802 TopoDS_Shape aShape = aRefShape->GetValue();
1803 if (aShape.IsNull()) {
1804 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1807 if (aShape.ShapeType() == TopAbs_COMPOUND) {
1808 TopoDS_Iterator It (aShape, Standard_True, Standard_True);
1809 if (It.More()) aShape = It.Value();
1811 if (aShape.ShapeType() == TopAbs_SHELL) {
1812 BRepCheck_Shell chkShell (TopoDS::Shell(aShape));
1813 if (chkShell.Closed() == BRepCheck_NotClosed) {
1814 aRes = "WRN_SHAPE_UNCLOSED";
1818 aRes = "WRN_SHAPE_NOT_SHELL";
1830 //=============================================================================
1834 //=============================================================================
1835 TCollection_AsciiString GEOMImpl_IMeasureOperations::WhatIs (Handle(GEOM_Object) theShape)
1839 TCollection_AsciiString Astr;
1841 if (theShape.IsNull()) return Astr;
1843 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1844 if (aRefShape.IsNull()) return Astr;
1846 TopoDS_Shape aShape = aRefShape->GetValue();
1847 if (aShape.IsNull()) {
1848 SetErrorCode("The Objects has NULL Shape");
1852 //Compute the parameters
1853 if (aShape.ShapeType() == TopAbs_EDGE) {
1854 if (BRep_Tool::Degenerated(TopoDS::Edge(aShape))) {
1855 Astr = Astr + " It is a degenerated edge \n";
1859 Astr = Astr + " Number of sub-shapes : \n";
1863 int iType, nbTypes [TopAbs_SHAPE], nbFlatType [TopAbs_SHAPE];
1864 for (iType = 0; iType < TopAbs_SHAPE; ++iType) {
1866 nbFlatType[iType] = 0;
1868 nbTypes[aShape.ShapeType()]++;
1870 TopTools_MapOfShape aMapOfShape;
1871 aMapOfShape.Add(aShape);
1872 TopTools_ListOfShape aListOfShape;
1873 aListOfShape.Append(aShape);
1875 TopTools_ListIteratorOfListOfShape itL (aListOfShape);
1876 for (; itL.More(); itL.Next()) {
1877 TopoDS_Shape sp = itL.Value();
1878 TopoDS_Iterator it (sp);
1879 for (; it.More(); it.Next()) {
1880 TopoDS_Shape s = it.Value();
1881 if (aMapOfShape.Add(s)) {
1882 aListOfShape.Append(s);
1883 nbTypes[s.ShapeType()]++;
1884 if ((sp.ShapeType() == TopAbs_COMPOUND) || (sp.ShapeType() == TopAbs_COMPSOLID)) {
1885 nbFlatType[s.ShapeType()]++;
1891 Astr = Astr + " VERTEX : " + TCollection_AsciiString(nbTypes[TopAbs_VERTEX]) + "\n";
1892 Astr = Astr + " EDGE : " + TCollection_AsciiString(nbTypes[TopAbs_EDGE]) + "\n";
1893 Astr = Astr + " WIRE : " + TCollection_AsciiString(nbTypes[TopAbs_WIRE]) + "\n";
1894 Astr = Astr + " FACE : " + TCollection_AsciiString(nbTypes[TopAbs_FACE]) + "\n";
1895 Astr = Astr + " SHELL : " + TCollection_AsciiString(nbTypes[TopAbs_SHELL]) + "\n";
1896 Astr = Astr + " SOLID : " + TCollection_AsciiString(nbTypes[TopAbs_SOLID]) + "\n";
1897 Astr = Astr + " COMPSOLID : " + TCollection_AsciiString(nbTypes[TopAbs_COMPSOLID]) + "\n";
1898 Astr = Astr + " COMPOUND : " + TCollection_AsciiString(nbTypes[TopAbs_COMPOUND]) + "\n";
1899 Astr = Astr + " SHAPE : " + TCollection_AsciiString(aMapOfShape.Extent()) + "\n";
1901 if ((aShape.ShapeType() == TopAbs_COMPOUND) || (aShape.ShapeType() == TopAbs_COMPSOLID)){
1902 Astr = Astr + " --------------------- \n Flat content : \n";
1903 if (nbFlatType[TopAbs_VERTEX] > 0)
1904 Astr = Astr + " VERTEX : " + TCollection_AsciiString(nbFlatType[TopAbs_VERTEX]) + "\n";
1905 if (nbFlatType[TopAbs_EDGE] > 0)
1906 Astr = Astr + " EDGE : " + TCollection_AsciiString(nbFlatType[TopAbs_EDGE]) + "\n";
1907 if (nbFlatType[TopAbs_WIRE] > 0)
1908 Astr = Astr + " WIRE : " + TCollection_AsciiString(nbFlatType[TopAbs_WIRE]) + "\n";
1909 if (nbFlatType[TopAbs_FACE] > 0)
1910 Astr = Astr + " FACE : " + TCollection_AsciiString(nbFlatType[TopAbs_FACE]) + "\n";
1911 if (nbFlatType[TopAbs_SHELL] > 0)
1912 Astr = Astr + " SHELL : " + TCollection_AsciiString(nbFlatType[TopAbs_SHELL]) + "\n";
1913 if (nbFlatType[TopAbs_SOLID] > 0)
1914 Astr = Astr + " SOLID : " + TCollection_AsciiString(nbFlatType[TopAbs_SOLID]) + "\n";
1917 catch (Standard_Failure& aFail) {
1918 SetErrorCode(aFail.GetMessageString());
1926 //=============================================================================
1930 //=============================================================================
1932 GEOMImpl_IMeasureOperations::AreCoordsInside(Handle(GEOM_Object) theShape,
1933 const std::vector<double>& coords,
1936 std::vector<bool> isInsideRes;
1937 if (!theShape.IsNull()) {
1938 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1939 if (!aRefShape.IsNull()) {
1940 TopoDS_Shape aShape = aRefShape->GetValue();
1941 if (!aShape.IsNull())
1943 TopTools_IndexedMapOfShape mapShape;
1945 TopExp_Explorer anExp;
1946 for ( anExp.Init( aShape, TopAbs_SOLID ); anExp.More(); anExp.Next() )
1947 mapShape.Add( anExp.Current() );
1948 for ( anExp.Init( aShape, TopAbs_FACE, TopAbs_SOLID ); anExp.More(); anExp.Next() )
1949 mapShape.Add( anExp.Current() );
1950 for ( anExp.Init( aShape, TopAbs_EDGE, TopAbs_FACE ); anExp.More(); anExp.Next() )
1951 mapShape.Add( anExp.Current() );
1952 for ( anExp.Init( aShape, TopAbs_VERTEX, TopAbs_EDGE ); anExp.More(); anExp.Next() )
1953 mapShape.Add( anExp.Current() ); //// ?????????
1955 size_t nb_points = coords.size()/3, nb_points_inside = 0;
1956 isInsideRes.resize( nb_points, false );
1958 for ( int iS = 1; iS <= mapShape.Extent(); ++iS )
1960 if ( nb_points_inside == nb_points )
1962 aShape = mapShape( iS );
1963 switch ( aShape.ShapeType() ) {
1966 BRepClass3d_SolidClassifier SC( TopoDS::Solid( aShape ));
1967 for ( size_t i = 0; i < nb_points; i++)
1969 if ( isInsideRes[ i ]) continue;
1970 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
1971 SC.Perform( aPnt, tolerance );
1972 isInsideRes[ i ] = (( SC.State() == TopAbs_IN ) || ( SC.State() == TopAbs_ON ));
1973 nb_points_inside += isInsideRes[ i ];
1979 Standard_Real u1,u2,v1,v2;
1980 const TopoDS_Face& face = TopoDS::Face( aShape );
1981 Handle(Geom_Surface) surf = BRep_Tool::Surface( face );
1982 surf->Bounds( u1,u2,v1,v2 );
1983 GeomAPI_ProjectPointOnSurf project;
1984 project.Init(surf, u1,u2, v1,v2, tolerance );
1985 for ( size_t i = 0; i < nb_points; i++)
1987 if ( isInsideRes[ i ]) continue;
1988 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
1989 project.Perform( aPnt );
1990 if ( project.IsDone() &&
1991 project.NbPoints() > 0 &&
1992 project.LowerDistance() <= tolerance )
1995 project.LowerDistanceParameters(u, v);
1996 gp_Pnt2d uv( u, v );
1997 BRepClass_FaceClassifier FC ( face, uv, tolerance );
1998 isInsideRes[ i ] = (( FC.State() == TopAbs_IN ) || ( FC.State() == TopAbs_ON ));
1999 nb_points_inside += isInsideRes[ i ];
2007 const TopoDS_Edge& edge = TopoDS::Edge( aShape );
2008 Handle(Geom_Curve) curve = BRep_Tool::Curve( edge, f, l );
2009 GeomAPI_ProjectPointOnCurve project;
2010 project.Init( curve, f, l );
2011 for ( size_t i = 0; i < nb_points; i++)
2013 if ( isInsideRes[ i ]) continue;
2014 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
2015 project.Perform( aPnt );
2016 isInsideRes[ i ] = ( project.NbPoints() > 0 &&
2017 project.LowerDistance() <= tolerance );
2018 nb_points_inside += isInsideRes[ i ];
2024 gp_Pnt aVPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ));
2025 for ( size_t i = 0; i < nb_points; i++)
2027 if ( isInsideRes[ i ]) continue;
2028 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
2029 isInsideRes[ i ] = ( aPnt.SquareDistance( aVPnt ) <= tolerance * tolerance );
2030 nb_points_inside += isInsideRes[ i ];
2035 } // switch ( aShape.ShapeType() )
2043 //=============================================================================
2047 //=============================================================================
2049 GEOMImpl_IMeasureOperations::GetMinDistance (Handle(GEOM_Object) theShape1,
2050 Handle(GEOM_Object) theShape2,
2059 Standard_Real MinDist = 1.e9;
2061 if (theShape1.IsNull() || theShape2.IsNull()) return MinDist;
2063 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
2064 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
2065 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return MinDist;
2067 TopoDS_Shape aShape1 = aRefShape1->GetValue();
2068 TopoDS_Shape aShape2 = aRefShape2->GetValue();
2069 if (aShape1.IsNull() || aShape2.IsNull()) {
2070 SetErrorCode("One of Objects has NULL Shape");
2074 //Compute the parameters
2078 gp_Pnt aPnt1, aPnt2;
2080 MinDist = GEOMUtils::GetMinDistance(aShape1, aShape2, aPnt1, aPnt2);
2082 if (MinDist >= 0.0) {
2083 aPnt1.Coord(X1, Y1, Z1);
2084 aPnt2.Coord(X2, Y2, Z2);
2089 catch (Standard_Failure& aFail) {
2090 SetErrorCode(aFail.GetMessageString());
2098 //=======================================================================
2100 * Get coordinates of closest points of two shapes
2102 //=======================================================================
2103 Standard_Integer GEOMImpl_IMeasureOperations::ClosestPoints (Handle(GEOM_Object) theShape1,
2104 Handle(GEOM_Object) theShape2,
2105 Handle(TColStd_HSequenceOfReal)& theDoubles)
2108 Standard_Integer nbSolutions = 0;
2110 if (theShape1.IsNull() || theShape2.IsNull()) return nbSolutions;
2112 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
2113 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
2114 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return nbSolutions;
2116 TopoDS_Shape aShape1 = aRefShape1->GetValue();
2117 TopoDS_Shape aShape2 = aRefShape2->GetValue();
2118 if (aShape1.IsNull() || aShape2.IsNull()) {
2119 SetErrorCode("One of Objects has NULL Shape");
2123 // Compute the extremities
2128 // additional workaround for bugs 19899, 19908 and 19910 from Mantis
2130 double dist = GEOMUtils::GetMinDistanceSingular(aShape1, aShape2, P1, P2);
2134 theDoubles->Append(P1.X());
2135 theDoubles->Append(P1.Y());
2136 theDoubles->Append(P1.Z());
2137 theDoubles->Append(P2.X());
2138 theDoubles->Append(P2.Y());
2139 theDoubles->Append(P2.Z());
2145 BRepExtrema_DistShapeShape dst (aShape1, aShape2);
2147 nbSolutions = dst.NbSolution();
2148 if (theDoubles.IsNull()) theDoubles = new TColStd_HSequenceOfReal;
2151 for (int i = 1; i <= nbSolutions; i++) {
2152 P1 = dst.PointOnShape1(i);
2153 P2 = dst.PointOnShape2(i);
2155 theDoubles->Append(P1.X());
2156 theDoubles->Append(P1.Y());
2157 theDoubles->Append(P1.Z());
2158 theDoubles->Append(P2.X());
2159 theDoubles->Append(P2.Y());
2160 theDoubles->Append(P2.Z());
2164 catch (Standard_Failure& aFail) {
2165 SetErrorCode(aFail.GetMessageString());
2173 //=======================================================================
2175 * Get coordinates of point
2177 //=======================================================================
2178 void GEOMImpl_IMeasureOperations::PointCoordinates (Handle(GEOM_Object) theShape,
2179 Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ)
2183 if (theShape.IsNull())
2186 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
2187 if (aRefShape.IsNull())
2190 TopoDS_Shape aShape = aRefShape->GetValue();
2191 if (aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX)
2193 SetErrorCode( "Shape must be a vertex" );
2199 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
2206 catch (Standard_Failure& aFail)
2208 SetErrorCode( aFail.GetMessageString() );
2212 //=======================================================================
2214 * Compute angle (in degrees) between two lines
2216 //=======================================================================
2217 Standard_Real GEOMImpl_IMeasureOperations::GetAngle (Handle(GEOM_Object) theLine1,
2218 Handle(GEOM_Object) theLine2)
2220 if (theLine1->GetType() == GEOM_VECTOR &&
2221 theLine2->GetType() == GEOM_VECTOR)
2222 return GetAngleBtwVectors(theLine1, theLine2);
2226 Standard_Real anAngle = -1.0;
2228 if (theLine1.IsNull() || theLine2.IsNull())
2231 Handle(GEOM_Function) aRefLine1 = theLine1->GetLastFunction();
2232 Handle(GEOM_Function) aRefLine2 = theLine2->GetLastFunction();
2233 if (aRefLine1.IsNull() || aRefLine2.IsNull())
2236 TopoDS_Shape aLine1 = aRefLine1->GetValue();
2237 TopoDS_Shape aLine2 = aRefLine2->GetValue();
2238 if (aLine1.IsNull() || aLine2.IsNull() ||
2239 aLine1.ShapeType() != TopAbs_EDGE ||
2240 aLine2.ShapeType() != TopAbs_EDGE)
2242 SetErrorCode("Two edges must be given");
2248 TopoDS_Edge E1 = TopoDS::Edge(aLine1);
2249 TopoDS_Edge E2 = TopoDS::Edge(aLine2);
2252 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp,lp);
2253 Handle(Geom_Curve) C2 = BRep_Tool::Curve(E2,fp,lp);
2255 if ( C1.IsNull() || C2.IsNull() ||
2256 !C1->IsKind(STANDARD_TYPE(Geom_Line)) ||
2257 !C2->IsKind(STANDARD_TYPE(Geom_Line)))
2259 SetErrorCode("The edges must be linear");
2263 Handle(Geom_Line) L1 = Handle(Geom_Line)::DownCast(C1);
2264 Handle(Geom_Line) L2 = Handle(Geom_Line)::DownCast(C2);
2266 gp_Lin aLin1 = L1->Lin();
2267 gp_Lin aLin2 = L2->Lin();
2269 anAngle = aLin1.Angle(aLin2);
2270 anAngle *= 180. / M_PI; // convert radians into degrees
2272 if (anAngle > 90.0) {
2273 anAngle = 180.0 - anAngle;
2278 catch (Standard_Failure& aFail)
2280 SetErrorCode(aFail.GetMessageString());
2286 //=======================================================================
2288 * Compute angle (in degrees) between two vectors
2290 //=======================================================================
2291 Standard_Real GEOMImpl_IMeasureOperations::GetAngleBtwVectors (Handle(GEOM_Object) theVec1,
2292 Handle(GEOM_Object) theVec2)
2296 Standard_Real anAngle = -1.0;
2298 if (theVec1.IsNull() || theVec2.IsNull())
2301 if (theVec1->GetType() != GEOM_VECTOR || theVec2->GetType() != GEOM_VECTOR) {
2302 SetErrorCode("Two vectors must be given");
2306 Handle(GEOM_Function) aRefVec1 = theVec1->GetLastFunction();
2307 Handle(GEOM_Function) aRefVec2 = theVec2->GetLastFunction();
2308 if (aRefVec1.IsNull() || aRefVec2.IsNull())
2311 TopoDS_Shape aVec1 = aRefVec1->GetValue();
2312 TopoDS_Shape aVec2 = aRefVec2->GetValue();
2313 if (aVec1.IsNull() || aVec2.IsNull() ||
2314 aVec1.ShapeType() != TopAbs_EDGE ||
2315 aVec2.ShapeType() != TopAbs_EDGE)
2317 SetErrorCode("Two edges must be given");
2323 TopoDS_Edge aE1 = TopoDS::Edge(aVec1);
2324 TopoDS_Edge aE2 = TopoDS::Edge(aVec2);
2326 TopoDS_Vertex aP11, aP12, aP21, aP22;
2327 TopExp::Vertices(aE1, aP11, aP12, Standard_True);
2328 TopExp::Vertices(aE2, aP21, aP22, Standard_True);
2329 if (aP11.IsNull() || aP12.IsNull() || aP21.IsNull() || aP22.IsNull()) {
2330 SetErrorCode("Bad edge given");
2334 gp_Vec aV1 (BRep_Tool::Pnt(aP11), BRep_Tool::Pnt(aP12));
2335 gp_Vec aV2 (BRep_Tool::Pnt(aP21), BRep_Tool::Pnt(aP22)) ;
2337 anAngle = aV1.Angle(aV2);
2338 anAngle *= 180. / M_PI; // convert radians into degrees
2342 catch (Standard_Failure& aFail)
2344 SetErrorCode(aFail.GetMessageString());
2351 //=============================================================================
2353 * CurveCurvatureByParam
2355 //=============================================================================
2356 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByParam
2357 (Handle(GEOM_Object) theCurve, Standard_Real& theParam)
2360 Standard_Real aRes = -1.0;
2362 if(theCurve.IsNull()) return aRes;
2364 Handle(GEOM_Function) aRefShape = theCurve->GetLastFunction();
2365 if(aRefShape.IsNull()) return aRes;
2367 TopoDS_Shape aShape = aRefShape->GetValue();
2368 if(aShape.IsNull()) {
2369 SetErrorCode("One of Objects has NULL Shape");
2373 Standard_Real aFP, aLP, aP;
2374 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aFP, aLP);
2375 aP = aFP + (aLP - aFP) * theParam;
2377 if(aCurve.IsNull()) return aRes;
2382 GeomLProp_CLProps Prop = GeomLProp_CLProps
2383 (aCurve, aP, 2, Precision::Confusion());
2384 aRes = fabs(Prop.Curvature());
2387 catch (Standard_Failure& aFail) {
2388 SetErrorCode(aFail.GetMessageString());
2392 if( aRes > Precision::Confusion() )
2401 //=============================================================================
2403 * CurveCurvatureByPoint
2405 //=============================================================================
2406 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByPoint
2407 (Handle(GEOM_Object) theCurve, Handle(GEOM_Object) thePoint)
2410 Standard_Real aRes = -1.0;
2412 if( theCurve.IsNull() || thePoint.IsNull() ) return aRes;
2414 Handle(GEOM_Function) aRefCurve = theCurve->GetLastFunction();
2415 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2416 if( aRefCurve.IsNull() || aRefPoint.IsNull() ) return aRes;
2418 TopoDS_Edge anEdge = TopoDS::Edge(aRefCurve->GetValue());
2419 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2420 if( anEdge.IsNull() || aPnt.IsNull() ) {
2421 SetErrorCode("One of Objects has NULL Shape");
2425 Standard_Real aFP, aLP;
2426 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFP, aLP);
2427 if(aCurve.IsNull()) return aRes;
2428 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2433 GeomAPI_ProjectPointOnCurve PPCurve(aPoint, aCurve, aFP, aLP);
2434 if(PPCurve.NbPoints()>0) {
2435 GeomLProp_CLProps Prop = GeomLProp_CLProps
2436 (aCurve, PPCurve.LowerDistanceParameter(), 2, Precision::Confusion());
2437 aRes = fabs(Prop.Curvature());
2441 catch (Standard_Failure& aFail) {
2442 SetErrorCode(aFail.GetMessageString());
2446 if( aRes > Precision::Confusion() )
2455 //=============================================================================
2457 * getSurfaceCurvatures
2459 //=============================================================================
2460 Standard_Real GEOMImpl_IMeasureOperations::getSurfaceCurvatures
2461 (const Handle(Geom_Surface)& aSurf,
2462 Standard_Real theUParam,
2463 Standard_Real theVParam,
2464 Standard_Boolean theNeedMaxCurv)
2467 Standard_Real aRes = 1.0;
2469 if (aSurf.IsNull()) return aRes;
2473 GeomLProp_SLProps Prop = GeomLProp_SLProps
2474 (aSurf, theUParam, theVParam, 2, Precision::Confusion());
2475 if(Prop.IsCurvatureDefined()) {
2476 if(Prop.IsUmbilic()) {
2477 //cout<<"is umbilic"<<endl;
2478 aRes = fabs(Prop.MeanCurvature());
2481 //cout<<"is not umbilic"<<endl;
2482 double c1 = fabs(Prop.MaxCurvature());
2483 double c2 = fabs(Prop.MinCurvature());
2492 catch (Standard_Failure& aFail) {
2493 SetErrorCode(aFail.GetMessageString());
2497 if( fabs(aRes) > Precision::Confusion() )
2506 //=============================================================================
2508 * MaxSurfaceCurvatureByParam
2510 //=============================================================================
2511 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByParam
2512 (Handle(GEOM_Object) theSurf,
2513 Standard_Real& theUParam,
2514 Standard_Real& theVParam)
2517 Standard_Real aRes = -1.0;
2519 if (theSurf.IsNull()) return aRes;
2521 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2522 if(aRefShape.IsNull()) return aRes;
2524 TopoDS_Shape aShape = aRefShape->GetValue();
2525 if(aShape.IsNull()) {
2526 SetErrorCode("One of Objects has NULL Shape");
2530 TopoDS_Face F = TopoDS::Face(aShape);
2531 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2533 //Compute the parameters
2534 Standard_Real U1,U2,V1,V2;
2535 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2536 Standard_Real U = U1 + (U2-U1)*theUParam;
2537 Standard_Real V = V1 + (V2-V1)*theVParam;
2539 return getSurfaceCurvatures(aSurf, U, V, true);
2543 //=============================================================================
2545 * MaxSurfaceCurvatureByPoint
2547 //=============================================================================
2548 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByPoint
2549 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2552 Standard_Real aRes = -1.0;
2554 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2556 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2557 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2558 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2560 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2561 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2562 if( aFace.IsNull() || aPnt.IsNull() ) {
2563 SetErrorCode("One of Objects has NULL Shape");
2567 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2568 if(aSurf.IsNull()) return aRes;
2569 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2571 //Compute the parameters
2572 ShapeAnalysis_Surface sas(aSurf);
2573 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2575 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), true);
2579 //=============================================================================
2581 * MinSurfaceCurvatureByParam
2583 //=============================================================================
2584 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByParam
2585 (Handle(GEOM_Object) theSurf,
2586 Standard_Real& theUParam,
2587 Standard_Real& theVParam)
2590 Standard_Real aRes = -1.0;
2592 if (theSurf.IsNull()) return aRes;
2594 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2595 if(aRefShape.IsNull()) return aRes;
2597 TopoDS_Shape aShape = aRefShape->GetValue();
2598 if(aShape.IsNull()) {
2599 SetErrorCode("One of Objects has NULL Shape");
2603 TopoDS_Face F = TopoDS::Face(aShape);
2604 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2606 //Compute the parameters
2607 Standard_Real U1,U2,V1,V2;
2608 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2609 Standard_Real U = U1 + (U2-U1)*theUParam;
2610 Standard_Real V = V1 + (V2-V1)*theVParam;
2612 return getSurfaceCurvatures(aSurf, U, V, false);
2616 //=============================================================================
2618 * MinSurfaceCurvatureByPoint
2620 //=============================================================================
2621 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByPoint
2622 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2625 Standard_Real aRes = -1.0;
2627 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2629 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2630 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2631 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2633 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2634 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2635 if( aFace.IsNull() || aPnt.IsNull() ) {
2636 SetErrorCode("One of Objects has NULL Shape");
2640 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2641 if(aSurf.IsNull()) return aRes;
2642 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2644 //Compute the parameters
2645 ShapeAnalysis_Surface sas(aSurf);
2646 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2648 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), false);
2651 //=======================================================================
2652 //function : FillErrorsSub
2653 //purpose : Fill the errors list of subshapes on shape.
2654 //=======================================================================
2655 void GEOMImpl_IMeasureOperations::FillErrorsSub
2656 (const BRepCheck_Analyzer &theAna,
2657 const TopoDS_Shape &theShape,
2658 const TopAbs_ShapeEnum theSubType,
2659 TopTools_DataMapOfIntegerListOfShape &theMapErrors) const
2661 TopExp_Explorer anExp(theShape, theSubType);
2662 TopTools_MapOfShape aMapSubShapes;
2664 for (; anExp.More(); anExp.Next()) {
2665 const TopoDS_Shape &aSubShape = anExp.Current();
2667 if (aMapSubShapes.Add(aSubShape)) {
2668 const Handle(BRepCheck_Result) &aRes = theAna.Result(aSubShape);
2670 for (aRes->InitContextIterator();
2671 aRes->MoreShapeInContext();
2672 aRes->NextShapeInContext()) {
2673 if (aRes->ContextualShape().IsSame(theShape)) {
2674 BRepCheck_ListIteratorOfListOfStatus itl(aRes->StatusOnShape());
2676 if (itl.Value() != BRepCheck_NoError) {
2677 // Add all errors for theShape and its sub-shape.
2678 for (;itl.More(); itl.Next()) {
2679 const Standard_Integer aStat = (Standard_Integer)itl.Value();
2681 if (!theMapErrors.IsBound(aStat)) {
2682 TopTools_ListOfShape anEmpty;
2684 theMapErrors.Bind(aStat, anEmpty);
2687 TopTools_ListOfShape &theShapes = theMapErrors.ChangeFind(aStat);
2689 theShapes.Append(aSubShape);
2690 theShapes.Append(theShape);
2701 //=======================================================================
2702 //function : FillErrors
2703 //purpose : Fill the errors list.
2704 //=======================================================================
2705 void GEOMImpl_IMeasureOperations::FillErrors
2706 (const BRepCheck_Analyzer &theAna,
2707 const TopoDS_Shape &theShape,
2708 TopTools_DataMapOfIntegerListOfShape &theMapErrors,
2709 TopTools_MapOfShape &theMapShapes) const
2711 if (theMapShapes.Add(theShape)) {
2712 // Fill errors of child shapes.
2713 for (TopoDS_Iterator iter(theShape); iter.More(); iter.Next()) {
2714 FillErrors(theAna, iter.Value(), theMapErrors, theMapShapes);
2717 // Fill errors of theShape.
2718 const Handle(BRepCheck_Result) &aRes = theAna.Result(theShape);
2720 if (!aRes.IsNull()) {
2721 BRepCheck_ListIteratorOfListOfStatus itl(aRes->Status());
2723 if (itl.Value() != BRepCheck_NoError) {
2724 // Add all errors for theShape.
2725 for (;itl.More(); itl.Next()) {
2726 const Standard_Integer aStat = (Standard_Integer)itl.Value();
2728 if (!theMapErrors.IsBound(aStat)) {
2729 TopTools_ListOfShape anEmpty;
2731 theMapErrors.Bind(aStat, anEmpty);
2734 theMapErrors.ChangeFind(aStat).Append(theShape);
2739 // Add errors of subshapes on theShape.
2740 const TopAbs_ShapeEnum aType = theShape.ShapeType();
2744 FillErrorsSub(theAna, theShape, TopAbs_VERTEX, theMapErrors);
2747 FillErrorsSub(theAna, theShape, TopAbs_WIRE, theMapErrors);
2748 FillErrorsSub(theAna, theShape, TopAbs_EDGE, theMapErrors);
2749 FillErrorsSub(theAna, theShape, TopAbs_VERTEX, theMapErrors);
2752 FillErrorsSub(theAna, theShape, TopAbs_SHELL, theMapErrors);
2760 //=======================================================================
2761 //function : FillErrors
2762 //purpose : Fill the errors list.
2763 //=======================================================================
2764 void GEOMImpl_IMeasureOperations::FillErrors
2765 (const BRepCheck_Analyzer &theAna,
2766 const TopoDS_Shape &theShape,
2767 std::list<ShapeError> &theErrors) const
2769 // Fill the errors map.
2770 TopTools_DataMapOfIntegerListOfShape aMapErrors;
2771 TopTools_MapOfShape aMapShapes;
2773 FillErrors(theAna, theShape, aMapErrors, aMapShapes);
2775 // Map sub-shapes and their indices
2776 TopTools_IndexedMapOfShape anIndices;
2778 TopExp::MapShapes(theShape, anIndices);
2780 TopTools_DataMapIteratorOfDataMapOfIntegerListOfShape aMapIter(aMapErrors);
2782 for (; aMapIter.More(); aMapIter.Next()) {
2785 anError.error = (BRepCheck_Status)aMapIter.Key();
2787 TopTools_ListIteratorOfListOfShape aListIter(aMapIter.Value());
2788 TopTools_MapOfShape aMapUnique;
2790 for (; aListIter.More(); aListIter.Next()) {
2791 const TopoDS_Shape &aShape = aListIter.Value();
2793 if (aMapUnique.Add(aShape)) {
2794 const Standard_Integer anIndex = anIndices.FindIndex(aShape);
2796 anError.incriminated.push_back(anIndex);
2800 if (!anError.incriminated.empty()) {
2801 theErrors.push_back(anError);