1 // Copyright (C) 2007-2015 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 <Basics_OCCTVersion.hxx>
25 #include <GEOMImpl_IMeasureOperations.hxx>
26 #include <GEOMImpl_IMeasure.hxx>
27 #include <GEOMImpl_MeasureDriver.hxx>
28 #include <GEOMImpl_Types.hxx>
30 #include <GEOMUtils.hxx>
32 #include <GEOMAlgo_AlgoTools.hxx>
33 #include <GEOMAlgo_KindOfName.hxx>
34 #include <GEOMAlgo_ShapeInfoFiller.hxx>
36 #include <GEOM_PythonDump.hxx>
38 #include <utilities.h>
41 #include <Bnd_Box.hxx>
42 #include <BOPAlgo_CheckerSI.hxx>
43 #include <BOPCol_ListOfShape.hxx>
44 #include <BOPDS_DS.hxx>
45 #include <BOPDS_MapOfPassKey.hxx>
46 #include <BRepBndLib.hxx>
47 #include <BRepBuilderAPI_Copy.hxx>
48 #include <BRepCheck_ListIteratorOfListOfStatus.hxx>
49 #include <BRepCheck_Shell.hxx>
50 #include <BRepClass3d_SolidClassifier.hxx>
51 #include <BRepClass_FaceClassifier.hxx>
52 #include <BRepExtrema_DistShapeShape.hxx>
53 #include <BRepExtrema_ShapeProximity.hxx>
54 #if OCC_VERSION_LARGE > 0x06090000
55 #include <BRepExtrema_SelfIntersection.hxx>
56 #include <BRepExtrema_MapOfIntegerPackedMapOfInteger.hxx>
58 #include <BRepGProp.hxx>
59 #include <BRepTools.hxx>
60 #include <BRep_Tool.hxx>
61 #include <Geom_Line.hxx>
62 #include <GeomAPI_ProjectPointOnCurve.hxx>
63 #include <GeomAPI_ProjectPointOnSurf.hxx>
64 #include <GeomLProp_CLProps.hxx>
65 #include <GeomLProp_SLProps.hxx>
66 #include <GProp_GProps.hxx>
67 #include <GProp_PrincipalProps.hxx>
68 #include <ShapeAnalysis.hxx>
69 #include <ShapeAnalysis_Surface.hxx>
71 #include <TopExp_Explorer.hxx>
73 #include <TopoDS_Edge.hxx>
74 #include <TopTools_IndexedMapOfShape.hxx>
75 #include <TopTools_DataMapIteratorOfDataMapOfIntegerListOfShape.hxx>
76 #include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
77 #include <TopTools_ListIteratorOfListOfShape.hxx>
78 #include <TopTools_ListOfShape.hxx>
79 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
83 //=============================================================================
87 //=============================================================================
88 GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations (GEOM_Engine* theEngine, int theDocID)
89 : GEOM_IOperations(theEngine, theDocID)
91 MESSAGE("GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations");
94 //=============================================================================
98 //=============================================================================
99 GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations()
101 MESSAGE("GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations");
104 //=============================================================================
105 /*! Get kind and parameters of the given shape.
107 //=============================================================================
108 GEOMImpl_IMeasureOperations::ShapeKind GEOMImpl_IMeasureOperations::KindOfShape
109 (Handle(GEOM_Object) theShape,
110 Handle(TColStd_HSequenceOfInteger)& theIntegers,
111 Handle(TColStd_HSequenceOfReal)& theDoubles)
114 ShapeKind aKind = SK_NO_SHAPE;
116 if (theIntegers.IsNull()) theIntegers = new TColStd_HSequenceOfInteger;
117 else theIntegers->Clear();
119 if (theDoubles.IsNull()) theDoubles = new TColStd_HSequenceOfReal;
120 else theDoubles->Clear();
122 if (theShape.IsNull())
125 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
126 if (aRefShape.IsNull()) return aKind;
128 TopoDS_Shape aShape = aRefShape->GetValue();
129 if (aShape.IsNull()) return aKind;
131 int geom_type = theShape->GetType();
133 // check if it's advanced shape
134 if ( geom_type > USER_TYPE ) {
140 GEOMAlgo_ShapeInfoFiller aSF;
141 aSF.SetShape(aShape);
143 Standard_Integer iErr = aSF.ErrorStatus();
145 SetErrorCode("Error in GEOMAlgo_ShapeInfoFiller");
148 const GEOMAlgo_ShapeInfo& anInfo = aSF.Info();
150 // Interprete results
151 TopAbs_ShapeEnum aType = anInfo.Type();
154 case TopAbs_COMPOUND:
155 case TopAbs_COMPSOLID:
157 // (+) geompy.kind.COMPOUND nb_solids nb_faces nb_edges nb_vertices
158 // (+) geompy.kind.COMPSOLID nb_solids nb_faces nb_edges nb_vertices
159 // ??? "nb_faces" - all faces or only 'standalone' faces?
160 if (aType == TopAbs_COMPOUND)
163 aKind = SK_COMPSOLID;
165 //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPOUND));
166 //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPSOLID));
167 theIntegers->Append(anInfo.NbSubShapes(TopAbs_SOLID));
168 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
169 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
170 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
176 // (+) geompy.kind.SHELL geompy.info.closed nb_faces nb_edges nb_vertices
177 // (+) geompy.kind.SHELL geompy.info.unclosed nb_faces nb_edges nb_vertices
180 theIntegers->Append((int)anInfo.KindOfClosed());
182 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
183 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
184 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
190 // (+) geompy.kind.WIRE geompy.info.closed nb_edges nb_vertices
191 // (+) geompy.kind.WIRE geompy.info.unclosed nb_edges nb_vertices
194 theIntegers->Append((int)anInfo.KindOfClosed());
196 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
197 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
205 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
208 case GEOMAlgo_KN_SPHERE:
209 // (+) geompy.kind.SPHERE xc yc zc R
213 gp_Pnt aC = anInfo.Location();
214 theDoubles->Append(aC.X());
215 theDoubles->Append(aC.Y());
216 theDoubles->Append(aC.Z());
218 theDoubles->Append(anInfo.Radius1());
221 case GEOMAlgo_KN_CYLINDER:
222 // (+) geompy.kind.CYLINDER xb yb zb dx dy dz R H
226 gp_Pnt aC = anInfo.Location();
227 theDoubles->Append(aC.X());
228 theDoubles->Append(aC.Y());
229 theDoubles->Append(aC.Z());
231 gp_Ax3 anAx3 = anInfo.Position();
232 gp_Dir aD = anAx3.Direction();
233 theDoubles->Append(aD.X());
234 theDoubles->Append(aD.Y());
235 theDoubles->Append(aD.Z());
237 theDoubles->Append(anInfo.Radius1());
238 theDoubles->Append(anInfo.Height());
241 case GEOMAlgo_KN_BOX:
242 // (+) geompy.kind.BOX xc yc zc ax ay az
246 gp_Pnt aC = anInfo.Location();
247 theDoubles->Append(aC.X());
248 theDoubles->Append(aC.Y());
249 theDoubles->Append(aC.Z());
251 gp_Ax3 anAx3 = anInfo.Position();
252 gp_Dir aD = anAx3.Direction();
253 gp_Dir aX = anAx3.XDirection();
256 if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
257 aX.IsParallel(gp::DX(), Precision::Angular())) {
258 theDoubles->Append(anInfo.Length()); // ax'
259 theDoubles->Append(anInfo.Width()); // ay'
260 theDoubles->Append(anInfo.Height()); // az'
262 else if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
263 aX.IsParallel(gp::DY(), Precision::Angular())) {
264 theDoubles->Append(anInfo.Width()); // ay'
265 theDoubles->Append(anInfo.Length()); // ax'
266 theDoubles->Append(anInfo.Height()); // az'
268 else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
269 aX.IsParallel(gp::DZ(), Precision::Angular())) {
270 theDoubles->Append(anInfo.Height()); // az'
271 theDoubles->Append(anInfo.Width()); // ay'
272 theDoubles->Append(anInfo.Length()); // ax'
274 else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
275 aX.IsParallel(gp::DY(), Precision::Angular())) {
276 theDoubles->Append(anInfo.Height()); // az'
277 theDoubles->Append(anInfo.Length()); // ax'
278 theDoubles->Append(anInfo.Width()); // ay'
280 else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
281 aX.IsParallel(gp::DZ(), Precision::Angular())) {
282 theDoubles->Append(anInfo.Width()); // ay'
283 theDoubles->Append(anInfo.Height()); // az'
284 theDoubles->Append(anInfo.Length()); // ax'
286 else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
287 aX.IsParallel(gp::DX(), Precision::Angular())) {
288 theDoubles->Append(anInfo.Length()); // ax'
289 theDoubles->Append(anInfo.Height()); // az'
290 theDoubles->Append(anInfo.Width()); // ay'
293 // (+) geompy.kind.ROTATED_BOX xo yo zo zx zy zz xx xy xz ax ay az
294 aKind = SK_ROTATED_BOX;
296 // Direction and XDirection
297 theDoubles->Append(aD.X());
298 theDoubles->Append(aD.Y());
299 theDoubles->Append(aD.Z());
301 theDoubles->Append(aX.X());
302 theDoubles->Append(aX.Y());
303 theDoubles->Append(aX.Z());
306 theDoubles->Append(anInfo.Length());
307 theDoubles->Append(anInfo.Width());
308 theDoubles->Append(anInfo.Height());
312 case GEOMAlgo_KN_TORUS:
313 // (+) geompy.kind.TORUS xc yc zc dx dy dz R_1 R_2
317 gp_Pnt aO = anInfo.Location();
318 theDoubles->Append(aO.X());
319 theDoubles->Append(aO.Y());
320 theDoubles->Append(aO.Z());
322 gp_Ax3 anAx3 = anInfo.Position();
323 gp_Dir aD = anAx3.Direction();
324 theDoubles->Append(aD.X());
325 theDoubles->Append(aD.Y());
326 theDoubles->Append(aD.Z());
328 theDoubles->Append(anInfo.Radius1());
329 theDoubles->Append(anInfo.Radius2());
332 case GEOMAlgo_KN_CONE:
333 // (+) geompy.kind.CONE xb yb zb dx dy dz R_1 R_2 H
337 gp_Pnt aO = anInfo.Location();
338 theDoubles->Append(aO.X());
339 theDoubles->Append(aO.Y());
340 theDoubles->Append(aO.Z());
342 gp_Ax3 anAx3 = anInfo.Position();
343 gp_Dir aD = anAx3.Direction();
344 theDoubles->Append(aD.X());
345 theDoubles->Append(aD.Y());
346 theDoubles->Append(aD.Z());
348 theDoubles->Append(anInfo.Radius1());
349 theDoubles->Append(anInfo.Radius2());
350 theDoubles->Append(anInfo.Height());
353 case GEOMAlgo_KN_POLYHEDRON:
354 // (+) geompy.kind.POLYHEDRON nb_faces nb_edges nb_vertices
356 aKind = SK_POLYHEDRON;
358 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
359 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
360 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
364 // (+) geompy.kind.SOLID nb_faces nb_edges nb_vertices
366 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
367 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
368 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
378 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
380 case GEOMAlgo_KN_SPHERE:
381 // (+) geompy.kind.SPHERE2D xc yc zc R
385 gp_Pnt aC = anInfo.Location();
386 theDoubles->Append(aC.X());
387 theDoubles->Append(aC.Y());
388 theDoubles->Append(aC.Z());
390 theDoubles->Append(anInfo.Radius1());
393 case GEOMAlgo_KN_CYLINDER:
394 // (+) geompy.kind.CYLINDER2D xb yb zb dx dy dz R H
396 aKind = SK_CYLINDER2D;
398 gp_Pnt aO = anInfo.Location();
399 theDoubles->Append(aO.X());
400 theDoubles->Append(aO.Y());
401 theDoubles->Append(aO.Z());
403 gp_Ax3 anAx3 = anInfo.Position();
404 gp_Dir aD = anAx3.Direction();
405 theDoubles->Append(aD.X());
406 theDoubles->Append(aD.Y());
407 theDoubles->Append(aD.Z());
409 theDoubles->Append(anInfo.Radius1());
410 theDoubles->Append(anInfo.Height());
413 case GEOMAlgo_KN_TORUS:
414 // (+) geompy.kind.TORUS2D xc yc zc dx dy dz R_1 R_2
418 gp_Pnt aO = anInfo.Location();
419 theDoubles->Append(aO.X());
420 theDoubles->Append(aO.Y());
421 theDoubles->Append(aO.Z());
423 gp_Ax3 anAx3 = anInfo.Position();
424 gp_Dir aD = anAx3.Direction();
425 theDoubles->Append(aD.X());
426 theDoubles->Append(aD.Y());
427 theDoubles->Append(aD.Z());
429 theDoubles->Append(anInfo.Radius1());
430 theDoubles->Append(anInfo.Radius2());
433 case GEOMAlgo_KN_CONE:
434 // (+) geompy.kind.CONE2D xc yc zc dx dy dz R_1 R_2 H
438 gp_Pnt aO = anInfo.Location();
439 theDoubles->Append(aO.X());
440 theDoubles->Append(aO.Y());
441 theDoubles->Append(aO.Z());
443 gp_Ax3 anAx3 = anInfo.Position();
444 gp_Dir aD = anAx3.Direction();
445 theDoubles->Append(aD.X());
446 theDoubles->Append(aD.Y());
447 theDoubles->Append(aD.Z());
449 theDoubles->Append(anInfo.Radius1());
450 theDoubles->Append(anInfo.Radius2());
451 theDoubles->Append(anInfo.Height());
454 case GEOMAlgo_KN_DISKCIRCLE:
455 // (+) geompy.kind.DISK_CIRCLE xc yc zc dx dy dz R
457 aKind = SK_DISK_CIRCLE;
459 gp_Pnt aC = anInfo.Location();
460 theDoubles->Append(aC.X());
461 theDoubles->Append(aC.Y());
462 theDoubles->Append(aC.Z());
464 gp_Ax3 anAx3 = anInfo.Position();
465 gp_Dir aD = anAx3.Direction();
466 theDoubles->Append(aD.X());
467 theDoubles->Append(aD.Y());
468 theDoubles->Append(aD.Z());
470 theDoubles->Append(anInfo.Radius1());
473 case GEOMAlgo_KN_DISKELLIPSE:
474 // (+) geompy.kind.DISK_ELLIPSE xc yc zc dx dy dz R_1 R_2
476 aKind = SK_DISK_ELLIPSE;
478 gp_Pnt aC = anInfo.Location();
479 theDoubles->Append(aC.X());
480 theDoubles->Append(aC.Y());
481 theDoubles->Append(aC.Z());
483 gp_Ax3 anAx3 = anInfo.Position();
484 gp_Dir aD = anAx3.Direction();
485 theDoubles->Append(aD.X());
486 theDoubles->Append(aD.Y());
487 theDoubles->Append(aD.Z());
489 theDoubles->Append(anInfo.Radius1());
490 theDoubles->Append(anInfo.Radius2());
493 case GEOMAlgo_KN_RECTANGLE:
494 case GEOMAlgo_KN_TRIANGLE:
495 case GEOMAlgo_KN_QUADRANGLE:
496 case GEOMAlgo_KN_POLYGON:
497 // (+) geompy.kind.POLYGON xo yo zo dx dy dz nb_edges nb_vertices
501 gp_Pnt aO = anInfo.Location();
502 theDoubles->Append(aO.X());
503 theDoubles->Append(aO.Y());
504 theDoubles->Append(aO.Z());
506 gp_Ax3 anAx3 = anInfo.Position();
507 gp_Dir aD = anAx3.Direction();
508 theDoubles->Append(aD.X());
509 theDoubles->Append(aD.Y());
510 theDoubles->Append(aD.Z());
512 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
513 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
516 case GEOMAlgo_KN_PLANE: // infinite
517 // (+) geompy.kind.PLANE xo yo zo dx dy dz
521 gp_Pnt aC = anInfo.Location();
522 theDoubles->Append(aC.X());
523 theDoubles->Append(aC.Y());
524 theDoubles->Append(aC.Z());
526 gp_Ax3 anAx3 = anInfo.Position();
527 gp_Dir aD = anAx3.Direction();
528 theDoubles->Append(aD.X());
529 theDoubles->Append(aD.Y());
530 theDoubles->Append(aD.Z());
532 if (anInfo.KindOfBounds() != GEOMAlgo_KB_INFINITE)
534 // (+) geompy.kind.PLANAR xo yo zo dx dy dz nb_edges nb_vertices
537 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
538 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
543 // ??? geompy.kind.FACE nb_edges nb_vertices _surface_type_id_
544 // (+) geompy.kind.FACE nb_edges nb_vertices
545 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
546 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
555 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
557 case GEOMAlgo_KN_CIRCLE:
559 // (+) geompy.kind.CIRCLE xc yc zc dx dy dz R
562 gp_Pnt aC = anInfo.Location();
563 theDoubles->Append(aC.X());
564 theDoubles->Append(aC.Y());
565 theDoubles->Append(aC.Z());
567 gp_Ax3 anAx3 = anInfo.Position();
568 gp_Dir aD = anAx3.Direction();
569 theDoubles->Append(aD.X());
570 theDoubles->Append(aD.Y());
571 theDoubles->Append(aD.Z());
573 theDoubles->Append(anInfo.Radius1());
576 case GEOMAlgo_KN_ARCCIRCLE:
578 // (+) geompy.kind.ARC_CIRCLE xc yc zc dx dy dz R x1 y1 z1 x2 y2 z2
579 aKind = SK_ARC_CIRCLE;
581 gp_Pnt aC = anInfo.Location();
582 theDoubles->Append(aC.X());
583 theDoubles->Append(aC.Y());
584 theDoubles->Append(aC.Z());
586 gp_Ax3 anAx3 = anInfo.Position();
587 gp_Dir aD = anAx3.Direction();
588 theDoubles->Append(aD.X());
589 theDoubles->Append(aD.Y());
590 theDoubles->Append(aD.Z());
592 theDoubles->Append(anInfo.Radius1());
594 gp_Pnt aP1 = anInfo.Pnt1();
595 theDoubles->Append(aP1.X());
596 theDoubles->Append(aP1.Y());
597 theDoubles->Append(aP1.Z());
599 gp_Pnt aP2 = anInfo.Pnt2();
600 theDoubles->Append(aP2.X());
601 theDoubles->Append(aP2.Y());
602 theDoubles->Append(aP2.Z());
605 case GEOMAlgo_KN_ELLIPSE:
607 // (+) geompy.kind.ELLIPSE xc yc zc dx dy dz R_1 R_2
610 gp_Pnt aC = anInfo.Location();
611 theDoubles->Append(aC.X());
612 theDoubles->Append(aC.Y());
613 theDoubles->Append(aC.Z());
615 gp_Ax3 anAx3 = anInfo.Position();
616 gp_Dir aD = anAx3.Direction();
617 theDoubles->Append(aD.X());
618 theDoubles->Append(aD.Y());
619 theDoubles->Append(aD.Z());
621 theDoubles->Append(anInfo.Radius1());
622 theDoubles->Append(anInfo.Radius2());
625 case GEOMAlgo_KN_ARCELLIPSE:
627 // (+) geompy.kind.ARC_ELLIPSE xc yc zc dx dy dz R_1 R_2 x1 y1 z1 x2 y2 z2
628 aKind = SK_ARC_ELLIPSE;
630 gp_Pnt aC = anInfo.Location();
631 theDoubles->Append(aC.X());
632 theDoubles->Append(aC.Y());
633 theDoubles->Append(aC.Z());
635 gp_Ax3 anAx3 = anInfo.Position();
636 gp_Dir aD = anAx3.Direction();
637 theDoubles->Append(aD.X());
638 theDoubles->Append(aD.Y());
639 theDoubles->Append(aD.Z());
641 theDoubles->Append(anInfo.Radius1());
642 theDoubles->Append(anInfo.Radius2());
644 gp_Pnt aP1 = anInfo.Pnt1();
645 theDoubles->Append(aP1.X());
646 theDoubles->Append(aP1.Y());
647 theDoubles->Append(aP1.Z());
649 gp_Pnt aP2 = anInfo.Pnt2();
650 theDoubles->Append(aP2.X());
651 theDoubles->Append(aP2.Y());
652 theDoubles->Append(aP2.Z());
655 case GEOMAlgo_KN_LINE:
657 // ??? geompy.kind.LINE x1 y1 z1 x2 y2 z2
658 // (+) geompy.kind.LINE x1 y1 z1 dx dy dz
661 gp_Pnt aO = anInfo.Location();
662 theDoubles->Append(aO.X());
663 theDoubles->Append(aO.Y());
664 theDoubles->Append(aO.Z());
666 gp_Dir aD = anInfo.Direction();
667 theDoubles->Append(aD.X());
668 theDoubles->Append(aD.Y());
669 theDoubles->Append(aD.Z());
672 case GEOMAlgo_KN_SEGMENT:
674 // (+) geompy.kind.SEGMENT x1 y1 z1 x2 y2 z2
677 gp_Pnt aP1 = anInfo.Pnt1();
678 theDoubles->Append(aP1.X());
679 theDoubles->Append(aP1.Y());
680 theDoubles->Append(aP1.Z());
682 gp_Pnt aP2 = anInfo.Pnt2();
683 theDoubles->Append(aP2.X());
684 theDoubles->Append(aP2.Y());
685 theDoubles->Append(aP2.Z());
689 // ??? geompy.kind.EDGE nb_vertices _curve_type_id_
690 // (+) geompy.kind.EDGE nb_vertices
691 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
698 // (+) geompy.kind.VERTEX x y z
701 gp_Pnt aP = anInfo.Location();
702 theDoubles->Append(aP.X());
703 theDoubles->Append(aP.Y());
704 theDoubles->Append(aP.Z());
713 //=============================================================================
717 //=============================================================================
718 void GEOMImpl_IMeasureOperations::GetPosition
719 (Handle(GEOM_Object) theShape,
720 Standard_Real& Ox, Standard_Real& Oy, Standard_Real& Oz,
721 Standard_Real& Zx, Standard_Real& Zy, Standard_Real& Zz,
722 Standard_Real& Xx, Standard_Real& Xy, Standard_Real& Xz)
726 //Set default values: global CS
727 Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
730 if (theShape.IsNull()) return;
732 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
733 if (aRefShape.IsNull()) return;
735 TopoDS_Shape aShape = aRefShape->GetValue();
736 if (aShape.IsNull()) {
737 SetErrorCode("The Objects has NULL Shape");
744 gp_Ax3 anAx3 = GEOMUtils::GetPosition(aShape);
746 gp_Pnt anOri = anAx3.Location();
747 gp_Dir aDirZ = anAx3.Direction();
748 gp_Dir aDirX = anAx3.XDirection();
751 anOri.Coord(Ox, Oy, Oz);
752 aDirZ.Coord(Zx, Zy, Zz);
753 aDirX.Coord(Xx, Xy, Xz);
755 catch (Standard_Failure) {
756 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
757 SetErrorCode(aFail->GetMessageString());
764 //=============================================================================
768 //=============================================================================
769 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetCentreOfMass
770 (Handle(GEOM_Object) theShape)
774 if (theShape.IsNull()) return NULL;
776 //Add a new CentreOfMass object
777 Handle(GEOM_Object) aCDG = GetEngine()->AddObject(GetDocID(), GEOM_CDG);
779 //Add a new CentreOfMass function
780 Handle(GEOM_Function) aFunction =
781 aCDG->AddFunction(GEOMImpl_MeasureDriver::GetID(), CDG_MEASURE);
782 if (aFunction.IsNull()) return NULL;
784 //Check if the function is set correctly
785 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
787 GEOMImpl_IMeasure aCI (aFunction);
789 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
790 if (aRefShape.IsNull()) return NULL;
792 aCI.SetBase(aRefShape);
794 //Compute the CentreOfMass value
797 if (!GetSolver()->ComputeFunction(aFunction)) {
798 SetErrorCode("Measure driver failed to compute centre of mass");
802 catch (Standard_Failure) {
803 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
804 SetErrorCode(aFail->GetMessageString());
808 //Make a Python command
809 GEOM::TPythonDump(aFunction) << aCDG << " = geompy.MakeCDG(" << theShape << ")";
815 //=============================================================================
819 //=============================================================================
820 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetVertexByIndex
821 (Handle(GEOM_Object) theShape,
822 Standard_Integer theIndex)
826 if (theShape.IsNull()) return NULL;
828 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
829 if (aRefShape.IsNull()) return NULL;
831 //Add a new Vertex object
832 Handle(GEOM_Object) aVertex = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
835 Handle(GEOM_Function) aFunction =
836 aVertex->AddFunction(GEOMImpl_MeasureDriver::GetID(), VERTEX_BY_INDEX);
837 if (aFunction.IsNull()) return NULL;
839 //Check if the function is set correctly
840 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
842 GEOMImpl_IMeasure aCI (aFunction);
843 aCI.SetBase(aRefShape);
844 aCI.SetIndex(theIndex);
849 if (!GetSolver()->ComputeFunction(aFunction)) {
850 SetErrorCode("Vertex by index driver failed.");
854 catch (Standard_Failure) {
855 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
856 SetErrorCode(aFail->GetMessageString());
860 //Make a Python command
861 GEOM::TPythonDump(aFunction) << aVertex << " = geompy.GetVertexByIndex(" << theShape << ", " << theIndex << ")";
867 //=============================================================================
871 //=============================================================================
872 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetNormal
873 (Handle(GEOM_Object) theFace,
874 Handle(GEOM_Object) theOptionalPoint)
878 if (theFace.IsNull()) return NULL;
880 //Add a new Normale object
881 Handle(GEOM_Object) aNorm = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
883 //Add a new Normale function
884 Handle(GEOM_Function) aFunction =
885 aNorm->AddFunction(GEOMImpl_MeasureDriver::GetID(), VECTOR_FACE_NORMALE);
886 if (aFunction.IsNull()) return NULL;
888 //Check if the function is set correctly
889 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
891 GEOMImpl_IMeasure aCI (aFunction);
893 Handle(GEOM_Function) aFace = theFace->GetLastFunction();
894 if (aFace.IsNull()) return NULL;
898 if (!theOptionalPoint.IsNull()) {
899 Handle(GEOM_Function) anOptPnt = theOptionalPoint->GetLastFunction();
900 aCI.SetPoint(anOptPnt);
903 //Compute the Normale value
906 if (!GetSolver()->ComputeFunction(aFunction)) {
907 SetErrorCode("Measure driver failed to compute normake of face");
911 catch (Standard_Failure) {
912 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
913 SetErrorCode(aFail->GetMessageString());
917 //Make a Python command
918 GEOM::TPythonDump pd (aFunction);
919 pd << aNorm << " = geompy.GetNormal(" << theFace;
920 if (!theOptionalPoint.IsNull()) {
921 pd << ", " << theOptionalPoint;
929 //=============================================================================
933 //=============================================================================
934 void GEOMImpl_IMeasureOperations::GetBasicProperties (Handle(GEOM_Object) theShape,
935 Standard_Real& theLength,
936 Standard_Real& theSurfArea,
937 Standard_Real& theVolume)
941 if (theShape.IsNull()) return;
943 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
944 if (aRefShape.IsNull()) return;
946 TopoDS_Shape aShape = aRefShape->GetValue();
947 if (aShape.IsNull()) {
948 SetErrorCode("The Objects has NULL Shape");
952 //Compute the parameters
953 GProp_GProps LProps, SProps;
956 BRepGProp::LinearProperties(aShape, LProps);
957 theLength = LProps.Mass();
959 BRepGProp::SurfaceProperties(aShape, SProps);
960 theSurfArea = SProps.Mass();
963 if (aShape.ShapeType() < TopAbs_SHELL) {
964 for (TopExp_Explorer Exp (aShape, TopAbs_SOLID); Exp.More(); Exp.Next()) {
966 BRepGProp::VolumeProperties(Exp.Current(), VProps);
967 theVolume += VProps.Mass();
971 catch (Standard_Failure) {
972 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
973 SetErrorCode(aFail->GetMessageString());
980 //=============================================================================
984 //=============================================================================
985 void GEOMImpl_IMeasureOperations::GetInertia
986 (Handle(GEOM_Object) theShape,
987 Standard_Real& I11, Standard_Real& I12, Standard_Real& I13,
988 Standard_Real& I21, Standard_Real& I22, Standard_Real& I23,
989 Standard_Real& I31, Standard_Real& I32, Standard_Real& I33,
990 Standard_Real& Ix , Standard_Real& Iy , Standard_Real& Iz)
994 if (theShape.IsNull()) return;
996 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
997 if (aRefShape.IsNull()) return;
999 TopoDS_Shape aShape = aRefShape->GetValue();
1000 if (aShape.IsNull()) {
1001 SetErrorCode("The Objects has NULL Shape");
1005 //Compute the parameters
1006 GProp_GProps System;
1010 if (aShape.ShapeType() == TopAbs_VERTEX ||
1011 aShape.ShapeType() == TopAbs_EDGE ||
1012 aShape.ShapeType() == TopAbs_WIRE) {
1013 BRepGProp::LinearProperties(aShape, System);
1014 } else if (aShape.ShapeType() == TopAbs_FACE ||
1015 aShape.ShapeType() == TopAbs_SHELL) {
1016 BRepGProp::SurfaceProperties(aShape, System);
1018 BRepGProp::VolumeProperties(aShape, System);
1020 gp_Mat I = System.MatrixOfInertia();
1034 GProp_PrincipalProps Pr = System.PrincipalProperties();
1035 Pr.Moments(Ix,Iy,Iz);
1037 catch (Standard_Failure) {
1038 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1039 SetErrorCode(aFail->GetMessageString());
1046 //=============================================================================
1050 //=============================================================================
1051 void GEOMImpl_IMeasureOperations::GetBoundingBox
1052 (Handle(GEOM_Object) theShape,
1053 const Standard_Boolean precise,
1054 Standard_Real& Xmin, Standard_Real& Xmax,
1055 Standard_Real& Ymin, Standard_Real& Ymax,
1056 Standard_Real& Zmin, Standard_Real& Zmax)
1060 if (theShape.IsNull()) return;
1062 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1063 if (aRefShape.IsNull()) return;
1065 TopoDS_Shape aShape = aRefShape->GetValue();
1066 if (aShape.IsNull()) {
1067 SetErrorCode("The Objects has NULL Shape");
1071 //Compute the parameters
1076 BRepBuilderAPI_Copy aCopyTool (aShape);
1077 if (!aCopyTool.IsDone()) {
1078 SetErrorCode("GetBoundingBox Error: Bad shape detected");
1082 aShape = aCopyTool.Shape();
1084 // remove triangulation to obtain more exact boundaries
1085 BRepTools::Clean(aShape);
1087 BRepBndLib::Add(aShape, B);
1090 if (!GEOMUtils::PreciseBoundingBox(aShape, B)) {
1091 SetErrorCode("GetBoundingBox Error: Bounding box cannot be precised");
1096 B.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
1098 catch (Standard_Failure) {
1099 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1100 SetErrorCode(aFail->GetMessageString());
1107 //=============================================================================
1111 //=============================================================================
1112 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetBoundingBox
1113 (Handle(GEOM_Object) theShape,
1114 const Standard_Boolean precise)
1118 if (theShape.IsNull()) return NULL;
1120 //Add a new BoundingBox object
1121 Handle(GEOM_Object) aBnd = GetEngine()->AddObject(GetDocID(), GEOM_BOX);
1123 //Add a new BoundingBox function
1124 const int aType = (precise ? BND_BOX_MEASURE_PRECISE : BND_BOX_MEASURE);
1125 Handle(GEOM_Function) aFunction =
1126 aBnd->AddFunction(GEOMImpl_MeasureDriver::GetID(), aType);
1127 if (aFunction.IsNull()) return NULL;
1129 //Check if the function is set correctly
1130 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
1132 GEOMImpl_IMeasure aCI (aFunction);
1134 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1135 if (aRefShape.IsNull()) return NULL;
1137 aCI.SetBase(aRefShape);
1139 //Compute the BoundingBox value
1142 if (!GetSolver()->ComputeFunction(aFunction)) {
1143 SetErrorCode("Measure driver failed to compute a bounding box");
1147 catch (Standard_Failure) {
1148 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1149 SetErrorCode(aFail->GetMessageString());
1153 //Make a Python command
1154 GEOM::TPythonDump aPd(aFunction);
1156 aPd << aBnd << " = geompy.MakeBoundingBox(" << theShape;
1168 //=============================================================================
1172 //=============================================================================
1173 void GEOMImpl_IMeasureOperations::GetTolerance
1174 (Handle(GEOM_Object) theShape,
1175 Standard_Real& FaceMin, Standard_Real& FaceMax,
1176 Standard_Real& EdgeMin, Standard_Real& EdgeMax,
1177 Standard_Real& VertMin, Standard_Real& VertMax)
1181 if (theShape.IsNull()) return;
1183 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1184 if (aRefShape.IsNull()) return;
1186 TopoDS_Shape aShape = aRefShape->GetValue();
1187 if (aShape.IsNull()) {
1188 SetErrorCode("The Objects has NULL Shape");
1192 //Compute the parameters
1194 FaceMin = EdgeMin = VertMin = RealLast();
1195 FaceMax = EdgeMax = VertMax = -RealLast();
1199 for (TopExp_Explorer ExF (aShape, TopAbs_FACE); ExF.More(); ExF.Next()) {
1200 TopoDS_Face Face = TopoDS::Face(ExF.Current());
1201 T = BRep_Tool::Tolerance(Face);
1207 for (TopExp_Explorer ExE (aShape, TopAbs_EDGE); ExE.More(); ExE.Next()) {
1208 TopoDS_Edge Edge = TopoDS::Edge(ExE.Current());
1209 T = BRep_Tool::Tolerance(Edge);
1215 for (TopExp_Explorer ExV (aShape, TopAbs_VERTEX); ExV.More(); ExV.Next()) {
1216 TopoDS_Vertex Vertex = TopoDS::Vertex(ExV.Current());
1217 T = BRep_Tool::Tolerance(Vertex);
1224 catch (Standard_Failure) {
1225 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1226 SetErrorCode(aFail->GetMessageString());
1233 //=============================================================================
1237 //=============================================================================
1238 bool GEOMImpl_IMeasureOperations::CheckShape (Handle(GEOM_Object) theShape,
1239 const Standard_Boolean theIsCheckGeom,
1240 std::list<ShapeError> &theErrors)
1245 if (theShape.IsNull()) return false;
1247 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1248 if (aRefShape.IsNull()) return false;
1250 TopoDS_Shape aShape = aRefShape->GetValue();
1251 if (aShape.IsNull()) {
1252 SetErrorCode("The Objects has NULL Shape");
1256 //Compute the parameters
1257 bool isValid = false;
1260 BRepCheck_Analyzer ana (aShape, theIsCheckGeom);
1261 if (ana.IsValid()) {
1264 FillErrors(ana, aShape, theErrors);
1267 catch (Standard_Failure) {
1268 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1269 SetErrorCode(aFail->GetMessageString());
1277 //=============================================================================
1281 //=============================================================================
1282 TCollection_AsciiString GEOMImpl_IMeasureOperations::PrintShapeErrors
1283 (Handle(GEOM_Object) theShape,
1284 const std::list<ShapeError> &theErrors)
1286 TCollection_AsciiString aDump;
1288 if (theShape.IsNull()) {
1292 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1294 if (aRefShape.IsNull()) {
1298 TopoDS_Shape aShape = aRefShape->GetValue();
1300 if (aShape.IsNull()) {
1301 SetErrorCode("The Objects has NULL Shape");
1305 if (!theErrors.empty()) {
1306 // The shape is not valid. Prepare errors for dump.
1307 TopTools_IndexedMapOfShape anIndices;
1308 std::list<ShapeError>::const_iterator anIter = theErrors.begin();
1309 Standard_Integer nbv, nbe, nbw, nbf, nbs, nbo;
1310 nbv = nbe = nbw = nbf = nbs = nbo = 0;
1312 // Map sub-shapes and their indices
1313 TopExp::MapShapes(aShape, anIndices);
1315 const Standard_Integer aNbSubShapes = anIndices.Extent();
1316 TColStd_MapOfInteger aMapPbInd;
1318 aDump += " -- The Shape has problems :\n";
1319 aDump += " Check Count\n";
1320 aDump += " ------------------------------------------------\n";
1322 for (; anIter != theErrors.end(); anIter++) {
1323 Standard_Integer aNbShapes = anIter->incriminated.size();
1325 switch(anIter->error) {
1326 case BRepCheck_InvalidPointOnCurve:
1327 aDump += " Invalid Point on Curve ................... ";
1329 case BRepCheck_InvalidPointOnCurveOnSurface:
1330 aDump += " Invalid Point on CurveOnSurface .......... ";
1332 case BRepCheck_InvalidPointOnSurface:
1333 aDump += " Invalid Point on Surface ................. ";
1335 case BRepCheck_No3DCurve:
1336 aDump += " No 3D Curve .............................. ";
1338 case BRepCheck_Multiple3DCurve:
1339 aDump += " Multiple 3D Curve ........................ ";
1341 case BRepCheck_Invalid3DCurve:
1342 aDump += " Invalid 3D Curve ......................... ";
1344 case BRepCheck_NoCurveOnSurface:
1345 aDump += " No Curve on Surface ...................... ";
1347 case BRepCheck_InvalidCurveOnSurface:
1348 aDump += " Invalid Curve on Surface ................. ";
1350 case BRepCheck_InvalidCurveOnClosedSurface:
1351 aDump += " Invalid Curve on closed Surface .......... ";
1353 case BRepCheck_InvalidSameRangeFlag:
1354 aDump += " Invalid SameRange Flag ................... ";
1356 case BRepCheck_InvalidSameParameterFlag:
1357 aDump += " Invalid SameParameter Flag ............... ";
1359 case BRepCheck_InvalidDegeneratedFlag:
1360 aDump += " Invalid Degenerated Flag ................. ";
1362 case BRepCheck_FreeEdge:
1363 aDump += " Free Edge ................................ ";
1365 case BRepCheck_InvalidMultiConnexity:
1366 aDump += " Invalid MultiConnexity ................... ";
1368 case BRepCheck_InvalidRange:
1369 aDump += " Invalid Range ............................ ";
1371 case BRepCheck_EmptyWire:
1372 aDump += " Empty Wire ............................... ";
1374 case BRepCheck_RedundantEdge:
1375 aDump += " Redundant Edge ........................... ";
1377 case BRepCheck_SelfIntersectingWire:
1378 aDump += " Self Intersecting Wire ................... ";
1380 case BRepCheck_NoSurface:
1381 aDump += " No Surface ............................... ";
1383 case BRepCheck_InvalidWire:
1384 aDump += " Invalid Wire ............................. ";
1386 case BRepCheck_RedundantWire:
1387 aDump += " Redundant Wire ........................... ";
1389 case BRepCheck_IntersectingWires:
1390 aDump += " Intersecting Wires ....................... ";
1392 case BRepCheck_InvalidImbricationOfWires:
1393 aDump += " Invalid Imbrication of Wires ............. ";
1395 case BRepCheck_EmptyShell:
1396 aDump += " Empty Shell .............................. ";
1398 case BRepCheck_RedundantFace:
1399 aDump += " Redundant Face ........................... ";
1401 case BRepCheck_UnorientableShape:
1402 aDump += " Unorientable Shape ....................... ";
1404 case BRepCheck_NotClosed:
1405 aDump += " Not Closed ............................... ";
1407 case BRepCheck_NotConnected:
1408 aDump += " Not Connected ............................ ";
1410 case BRepCheck_SubshapeNotInShape:
1411 aDump += " Sub-shape not in Shape ................... ";
1413 case BRepCheck_BadOrientation:
1414 aDump += " Bad Orientation .......................... ";
1416 case BRepCheck_BadOrientationOfSubshape:
1417 aDump += " Bad Orientation of Sub-shape ............. ";
1419 case BRepCheck_InvalidToleranceValue:
1420 aDump += " Invalid Tolerance Value .................. ";
1422 case BRepCheck_CheckFail:
1423 aDump += " Check Shape Failure ...................... ";
1429 aDump += TCollection_AsciiString(aNbShapes) + "\n";
1431 // Count types of shape.
1432 std::list<int>::const_iterator aShIter = anIter->incriminated.begin();
1434 for (; aShIter != anIter->incriminated.end(); aShIter++) {
1435 const Standard_Integer anIndex = *aShIter;
1437 if (anIndex > 0 && anIndex <= aNbSubShapes && aMapPbInd.Add(anIndex)) {
1438 const TopoDS_Shape &aSubShape = anIndices.FindKey(anIndex);
1439 const TopAbs_ShapeEnum aType = aSubShape.ShapeType();
1442 case TopAbs_VERTEX : nbv++; break;
1443 case TopAbs_EDGE : nbe++; break;
1444 case TopAbs_WIRE : nbw++; break;
1445 case TopAbs_FACE : nbf++; break;
1446 case TopAbs_SHELL : nbs++; break;
1447 case TopAbs_SOLID : nbo++; break;
1454 const Standard_Integer aNbFaultyShapes = nbv + nbe + nbw + nbf + nbs + nbo;
1455 aDump += " ------------------------------------------------\n";
1456 aDump += "*** Shapes with problems : ";
1457 aDump += TCollection_AsciiString(aNbFaultyShapes) + "\n";
1460 aDump += "VERTEX : ";
1461 if (nbv < 10) aDump += " ";
1462 aDump += TCollection_AsciiString(nbv) + "\n";
1466 if (nbe < 10) aDump += " ";
1467 aDump += TCollection_AsciiString(nbe) + "\n";
1471 if (nbw < 10) aDump += " ";
1472 aDump += TCollection_AsciiString(nbw) + "\n";
1476 if (nbf < 10) aDump += " ";
1477 aDump += TCollection_AsciiString(nbf) + "\n";
1480 aDump += "SHELL : ";
1481 if (nbs < 10) aDump += " ";
1482 aDump += TCollection_AsciiString(nbs) + "\n";
1485 aDump += "SOLID : ";
1486 if (nbo < 10) aDump += " ";
1487 aDump += TCollection_AsciiString(nbo) + "\n";
1494 //=============================================================================
1496 * CheckSelfIntersections
1498 //=============================================================================
1499 bool GEOMImpl_IMeasureOperations::CheckSelfIntersections
1500 (Handle(GEOM_Object) theShape,
1501 const SICheckLevel theCheckLevel,
1502 Handle(TColStd_HSequenceOfInteger)& theIntersections)
1506 if (theIntersections.IsNull())
1507 theIntersections = new TColStd_HSequenceOfInteger;
1509 theIntersections->Clear();
1511 if (theShape.IsNull())
1514 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1515 if (aRefShape.IsNull()) return false;
1517 TopoDS_Shape aShape = aRefShape->GetValue();
1518 if (aShape.IsNull()) return false;
1521 TopoDS_Shape aScopy;
1523 GEOMAlgo_AlgoTools::CopyShape(aShape, aScopy);
1525 // Map sub-shapes and their indices
1526 TopTools_IndexedMapOfShape anIndices;
1527 TopExp::MapShapes(aScopy, anIndices);
1529 BOPCol_ListOfShape aLCS;
1530 aLCS.Append(aScopy);
1532 BOPAlgo_CheckerSI aCSI; // checker of self-interferences
1533 aCSI.SetArguments(aLCS);
1534 aCSI.SetLevelOfCheck(theCheckLevel);
1536 // 1. Launch the checker
1538 Standard_Integer iErr = aCSI.ErrorStatus();
1541 Standard_Integer aNbS, n1, n2;
1542 BOPDS_MapIteratorMapOfPassKey aItMPK;
1544 // 2. Take the shapes from DS
1545 const BOPDS_DS& aDS = aCSI.DS();
1546 aNbS=aDS.NbShapes();
1548 // 3. Get the pairs of interfered shapes
1549 const BOPDS_MapOfPassKey& aMPK=aDS.Interferences();
1550 aItMPK.Initialize(aMPK);
1551 for (; aItMPK.More(); aItMPK.Next()) {
1552 const BOPDS_PassKey& aPK=aItMPK.Value();
1555 if (n1 > aNbS || n2 > aNbS){
1556 return false; // Error
1558 const TopoDS_Shape& aS1 = aDS.Shape(n1);
1559 const TopoDS_Shape& aS2 = aDS.Shape(n2);
1561 theIntersections->Append(anIndices.FindIndex(aS1));
1562 theIntersections->Append(anIndices.FindIndex(aS2));
1569 return theIntersections->IsEmpty();
1572 //=============================================================================
1574 * CheckSelfIntersectionsFast
1576 //=============================================================================
1577 bool GEOMImpl_IMeasureOperations::CheckSelfIntersectionsFast
1578 (Handle(GEOM_Object) theShape,
1579 float theDeflection, double theTolerance,
1580 Handle(TColStd_HSequenceOfInteger)& theIntersections)
1584 if (theIntersections.IsNull())
1585 theIntersections = new TColStd_HSequenceOfInteger;
1587 theIntersections->Clear();
1589 if (theShape.IsNull())
1592 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1593 if (aRefShape.IsNull()) return false;
1595 TopoDS_Shape aShape = aRefShape->GetValue();
1596 if (aShape.IsNull()) return false;
1599 TopoDS_Shape aScopy;
1601 GEOMAlgo_AlgoTools::CopyShape(aShape, aScopy);
1602 GEOMUtils::MeshShape(aScopy, theDeflection);
1604 // Map sub-shapes and their indices
1605 TopTools_IndexedMapOfShape anIndices;
1606 TopExp::MapShapes(aScopy, anIndices);
1608 #if OCC_VERSION_LARGE > 0x06090000
1609 // Checker of fast interferences
1610 BRepExtrema_SelfIntersection aTool(aScopy, (theTolerance <= 0.) ? 0.0 : theTolerance);
1612 // Launch the checker
1615 const BRepExtrema_MapOfIntegerPackedMapOfInteger& intersections = aTool.OverlapElements();
1617 std::set<Standard_Integer> processed;
1619 for (BRepExtrema_MapOfIntegerPackedMapOfInteger::Iterator it(intersections); it.More(); it.Next()) {
1620 Standard_Integer idxLeft = it.Key();
1621 if (processed.count(idxLeft) > 0) continue; // already added
1622 processed.insert(idxLeft);
1623 const TColStd_PackedMapOfInteger& overlaps = it.Value();
1624 for (TColStd_MapIteratorOfPackedMapOfInteger subit(overlaps); subit.More(); subit.Next()) {
1625 Standard_Integer idxRight = subit.Key();
1626 if (processed.count(idxRight) > 0) continue; // already added
1627 const TopoDS_Shape& aS1 = aTool.GetSubShape(idxLeft);
1628 const TopoDS_Shape& aS2 = aTool.GetSubShape(idxRight);
1629 theIntersections->Append(anIndices.FindIndex(aS1));
1630 theIntersections->Append(anIndices.FindIndex(aS2));
1638 return theIntersections->IsEmpty();
1641 //=============================================================================
1645 //=============================================================================
1646 bool GEOMImpl_IMeasureOperations::FastIntersect (Handle(GEOM_Object) theShape1, Handle(GEOM_Object) theShape2,
1647 double theTolerance, float theDeflection,
1648 Handle(TColStd_HSequenceOfInteger)& theIntersections1,
1649 Handle(TColStd_HSequenceOfInteger)& theIntersections2)
1652 bool isGood = false;
1654 if (theIntersections1.IsNull())
1655 theIntersections1 = new TColStd_HSequenceOfInteger;
1657 theIntersections1->Clear();
1659 if (theIntersections2.IsNull())
1660 theIntersections2 = new TColStd_HSequenceOfInteger;
1662 theIntersections2->Clear();
1664 if (theShape1.IsNull() || theShape2.IsNull()) {
1665 SetErrorCode("Objects have NULL Shape");
1669 if (theShape1 == theShape2) {
1670 SetErrorCode("Objects are equal");
1673 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
1674 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
1675 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return isGood;
1677 TopoDS_Shape aShape1 = aRefShape1->GetValue();
1678 TopoDS_Shape aShape2 = aRefShape2->GetValue();
1679 if (aShape1.IsNull() || aShape2.IsNull()) return isGood;
1682 TopoDS_Shape aScopy1, aScopy2;
1683 GEOMAlgo_AlgoTools::CopyShape(aShape1, aScopy1);
1684 GEOMAlgo_AlgoTools::CopyShape(aShape2, aScopy2);
1686 GEOMUtils::MeshShape(aScopy1, theDeflection);
1687 GEOMUtils::MeshShape(aScopy2, theDeflection);
1689 // Map sub-shapes and their indices
1690 TopTools_IndexedMapOfShape anIndices1, anIndices2;
1691 TopExp::MapShapes(aScopy1, anIndices1);
1692 TopExp::MapShapes(aScopy2, anIndices2);
1694 BOPCol_ListOfShape aLCS1, aLCS2;
1695 aLCS1.Append(aScopy1); aLCS2.Append(aScopy2);
1697 BRepExtrema_ShapeProximity aBSP; // checker of fast interferences
1698 aBSP.LoadShape1(aScopy1); aBSP.LoadShape2(aScopy2);
1699 aBSP.SetTolerance((theTolerance <= 0.) ? 0.0 : theTolerance);
1701 // 1. Launch the checker
1704 // 2. Get sets of IDs of overlapped faces
1705 #if OCC_VERSION_LARGE > 0x06090000
1706 for (BRepExtrema_MapOfIntegerPackedMapOfInteger::Iterator anIt1 (aBSP.OverlapSubShapes1()); anIt1.More(); anIt1.Next())
1708 for (BRepExtrema_OverlappedSubShapes::Iterator anIt1 (aBSP.OverlapSubShapes1()); anIt1.More(); anIt1.Next())
1711 const TopoDS_Shape& aS1 = aBSP.GetSubShape1(anIt1.Key());
1712 theIntersections1->Append(anIndices1.FindIndex(aS1));
1715 #if OCC_VERSION_LARGE > 0x06090000
1716 for (BRepExtrema_MapOfIntegerPackedMapOfInteger::Iterator anIt2 (aBSP.OverlapSubShapes2()); anIt2.More(); anIt2.Next())
1718 for (BRepExtrema_OverlappedSubShapes::Iterator anIt2 (aBSP.OverlapSubShapes2()); anIt2.More(); anIt2.Next())
1721 const TopoDS_Shape& aS2 = aBSP.GetSubShape2(anIt2.Key());
1722 theIntersections2->Append(anIndices2.FindIndex(aS2));
1725 isGood = !theIntersections1->IsEmpty() && !theIntersections1->IsEmpty();
1733 //=============================================================================
1737 //=============================================================================
1738 TCollection_AsciiString GEOMImpl_IMeasureOperations::IsGoodForSolid (Handle(GEOM_Object) theShape)
1742 TCollection_AsciiString aRes = "";
1744 if (theShape.IsNull()) {
1745 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1748 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1749 if (aRefShape.IsNull()) {
1750 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1753 TopoDS_Shape aShape = aRefShape->GetValue();
1754 if (aShape.IsNull()) {
1755 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1758 if (aShape.ShapeType() == TopAbs_COMPOUND) {
1759 TopoDS_Iterator It (aShape, Standard_True, Standard_True);
1760 if (It.More()) aShape = It.Value();
1762 if (aShape.ShapeType() == TopAbs_SHELL) {
1763 BRepCheck_Shell chkShell (TopoDS::Shell(aShape));
1764 if (chkShell.Closed() == BRepCheck_NotClosed) {
1765 aRes = "WRN_SHAPE_UNCLOSED";
1769 aRes = "WRN_SHAPE_NOT_SHELL";
1781 //=============================================================================
1785 //=============================================================================
1786 TCollection_AsciiString GEOMImpl_IMeasureOperations::WhatIs (Handle(GEOM_Object) theShape)
1790 TCollection_AsciiString Astr;
1792 if (theShape.IsNull()) return Astr;
1794 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1795 if (aRefShape.IsNull()) return Astr;
1797 TopoDS_Shape aShape = aRefShape->GetValue();
1798 if (aShape.IsNull()) {
1799 SetErrorCode("The Objects has NULL Shape");
1803 //Compute the parameters
1804 if (aShape.ShapeType() == TopAbs_EDGE) {
1805 if (BRep_Tool::Degenerated(TopoDS::Edge(aShape))) {
1806 Astr = Astr + " It is a degenerated edge \n";
1810 Astr = Astr + " Number of sub-shapes : \n";
1814 int iType, nbTypes [TopAbs_SHAPE], nbFlatType [TopAbs_SHAPE];
1815 for (iType = 0; iType < TopAbs_SHAPE; ++iType) {
1817 nbFlatType[iType] = 0;
1819 nbTypes[aShape.ShapeType()]++;
1821 TopTools_MapOfShape aMapOfShape;
1822 aMapOfShape.Add(aShape);
1823 TopTools_ListOfShape aListOfShape;
1824 aListOfShape.Append(aShape);
1826 TopTools_ListIteratorOfListOfShape itL (aListOfShape);
1827 for (; itL.More(); itL.Next()) {
1828 TopoDS_Shape sp = itL.Value();
1829 TopoDS_Iterator it (sp);
1830 for (; it.More(); it.Next()) {
1831 TopoDS_Shape s = it.Value();
1832 if (aMapOfShape.Add(s)) {
1833 aListOfShape.Append(s);
1834 nbTypes[s.ShapeType()]++;
1835 if ((sp.ShapeType() == TopAbs_COMPOUND) || (sp.ShapeType() == TopAbs_COMPSOLID)) {
1836 nbFlatType[s.ShapeType()]++;
1842 Astr = Astr + " VERTEX : " + TCollection_AsciiString(nbTypes[TopAbs_VERTEX]) + "\n";
1843 Astr = Astr + " EDGE : " + TCollection_AsciiString(nbTypes[TopAbs_EDGE]) + "\n";
1844 Astr = Astr + " WIRE : " + TCollection_AsciiString(nbTypes[TopAbs_WIRE]) + "\n";
1845 Astr = Astr + " FACE : " + TCollection_AsciiString(nbTypes[TopAbs_FACE]) + "\n";
1846 Astr = Astr + " SHELL : " + TCollection_AsciiString(nbTypes[TopAbs_SHELL]) + "\n";
1847 Astr = Astr + " SOLID : " + TCollection_AsciiString(nbTypes[TopAbs_SOLID]) + "\n";
1848 Astr = Astr + " COMPSOLID : " + TCollection_AsciiString(nbTypes[TopAbs_COMPSOLID]) + "\n";
1849 Astr = Astr + " COMPOUND : " + TCollection_AsciiString(nbTypes[TopAbs_COMPOUND]) + "\n";
1850 Astr = Astr + " SHAPE : " + TCollection_AsciiString(aMapOfShape.Extent()) + "\n";
1852 if ((aShape.ShapeType() == TopAbs_COMPOUND) || (aShape.ShapeType() == TopAbs_COMPSOLID)){
1853 Astr = Astr + " --------------------- \n Flat content : \n";
1854 if (nbFlatType[TopAbs_VERTEX] > 0)
1855 Astr = Astr + " VERTEX : " + TCollection_AsciiString(nbFlatType[TopAbs_VERTEX]) + "\n";
1856 if (nbFlatType[TopAbs_EDGE] > 0)
1857 Astr = Astr + " EDGE : " + TCollection_AsciiString(nbFlatType[TopAbs_EDGE]) + "\n";
1858 if (nbFlatType[TopAbs_WIRE] > 0)
1859 Astr = Astr + " WIRE : " + TCollection_AsciiString(nbFlatType[TopAbs_WIRE]) + "\n";
1860 if (nbFlatType[TopAbs_FACE] > 0)
1861 Astr = Astr + " FACE : " + TCollection_AsciiString(nbFlatType[TopAbs_FACE]) + "\n";
1862 if (nbFlatType[TopAbs_SHELL] > 0)
1863 Astr = Astr + " SHELL : " + TCollection_AsciiString(nbFlatType[TopAbs_SHELL]) + "\n";
1864 if (nbFlatType[TopAbs_SOLID] > 0)
1865 Astr = Astr + " SOLID : " + TCollection_AsciiString(nbFlatType[TopAbs_SOLID]) + "\n";
1868 catch (Standard_Failure) {
1869 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1870 SetErrorCode(aFail->GetMessageString());
1878 //=============================================================================
1882 //=============================================================================
1884 GEOMImpl_IMeasureOperations::AreCoordsInside(Handle(GEOM_Object) theShape,
1885 const std::vector<double>& coords,
1888 std::vector<bool> isInsideRes;
1889 if (!theShape.IsNull()) {
1890 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1891 if (!aRefShape.IsNull()) {
1892 TopoDS_Shape aShape = aRefShape->GetValue();
1893 if (!aShape.IsNull())
1895 TopTools_IndexedMapOfShape mapShape;
1897 TopExp_Explorer anExp;
1898 for ( anExp.Init( aShape, TopAbs_SOLID ); anExp.More(); anExp.Next() )
1899 mapShape.Add( anExp.Current() );
1900 for ( anExp.Init( aShape, TopAbs_FACE, TopAbs_SOLID ); anExp.More(); anExp.Next() )
1901 mapShape.Add( anExp.Current() );
1902 for ( anExp.Init( aShape, TopAbs_EDGE, TopAbs_FACE ); anExp.More(); anExp.Next() )
1903 mapShape.Add( anExp.Current() );
1904 for ( anExp.Init( aShape, TopAbs_VERTEX, TopAbs_EDGE ); anExp.More(); anExp.Next() )
1905 mapShape.Add( anExp.Current() ); //// ?????????
1907 size_t nb_points = coords.size()/3, nb_points_inside = 0;
1908 isInsideRes.resize( nb_points, false );
1910 for ( int iS = 1; iS <= mapShape.Extent(); ++iS )
1912 if ( nb_points_inside == nb_points )
1914 aShape = mapShape( iS );
1915 switch ( aShape.ShapeType() ) {
1918 BRepClass3d_SolidClassifier SC( TopoDS::Solid( aShape ));
1919 for ( size_t i = 0; i < nb_points; i++)
1921 if ( isInsideRes[ i ]) continue;
1922 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
1923 SC.Perform( aPnt, tolerance );
1924 isInsideRes[ i ] = (( SC.State() == TopAbs_IN ) || ( SC.State() == TopAbs_ON ));
1925 nb_points_inside += isInsideRes[ i ];
1931 Standard_Real u1,u2,v1,v2;
1932 const TopoDS_Face& face = TopoDS::Face( aShape );
1933 Handle(Geom_Surface) surf = BRep_Tool::Surface( face );
1934 surf->Bounds( u1,u2,v1,v2 );
1935 GeomAPI_ProjectPointOnSurf project;
1936 project.Init(surf, u1,u2, v1,v2, tolerance );
1937 for ( size_t i = 0; i < nb_points; i++)
1939 if ( isInsideRes[ i ]) continue;
1940 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
1941 project.Perform( aPnt );
1942 if ( project.IsDone() &&
1943 project.NbPoints() > 0 &&
1944 project.LowerDistance() <= tolerance )
1946 Quantity_Parameter u, v;
1947 project.LowerDistanceParameters(u, v);
1948 gp_Pnt2d uv( u, v );
1949 BRepClass_FaceClassifier FC ( face, uv, tolerance );
1950 isInsideRes[ i ] = (( FC.State() == TopAbs_IN ) || ( FC.State() == TopAbs_ON ));
1951 nb_points_inside += isInsideRes[ i ];
1959 const TopoDS_Edge& edge = TopoDS::Edge( aShape );
1960 Handle(Geom_Curve) curve = BRep_Tool::Curve( edge, f, l );
1961 GeomAPI_ProjectPointOnCurve project;
1962 project.Init( curve, f, l );
1963 for ( size_t i = 0; i < nb_points; i++)
1965 if ( isInsideRes[ i ]) continue;
1966 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
1967 project.Perform( aPnt );
1968 isInsideRes[ i ] = ( project.NbPoints() > 0 &&
1969 project.LowerDistance() <= tolerance );
1970 nb_points_inside += isInsideRes[ i ];
1976 gp_Pnt aVPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ));
1977 for ( size_t i = 0; i < nb_points; i++)
1979 if ( isInsideRes[ i ]) continue;
1980 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
1981 isInsideRes[ i ] = ( aPnt.SquareDistance( aVPnt ) <= tolerance * tolerance );
1982 nb_points_inside += isInsideRes[ i ];
1987 } // switch ( aShape.ShapeType() )
1995 //=============================================================================
1999 //=============================================================================
2001 GEOMImpl_IMeasureOperations::GetMinDistance (Handle(GEOM_Object) theShape1,
2002 Handle(GEOM_Object) theShape2,
2011 Standard_Real MinDist = 1.e9;
2013 if (theShape1.IsNull() || theShape2.IsNull()) return MinDist;
2015 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
2016 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
2017 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return MinDist;
2019 TopoDS_Shape aShape1 = aRefShape1->GetValue();
2020 TopoDS_Shape aShape2 = aRefShape2->GetValue();
2021 if (aShape1.IsNull() || aShape2.IsNull()) {
2022 SetErrorCode("One of Objects has NULL Shape");
2026 //Compute the parameters
2030 gp_Pnt aPnt1, aPnt2;
2032 MinDist = GEOMUtils::GetMinDistance(aShape1, aShape2, aPnt1, aPnt2);
2034 if (MinDist >= 0.0) {
2035 aPnt1.Coord(X1, Y1, Z1);
2036 aPnt2.Coord(X2, Y2, Z2);
2041 catch (Standard_Failure) {
2042 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2043 SetErrorCode(aFail->GetMessageString());
2051 //=======================================================================
2053 * Get coordinates of closest points of two shapes
2055 //=======================================================================
2056 Standard_Integer GEOMImpl_IMeasureOperations::ClosestPoints (Handle(GEOM_Object) theShape1,
2057 Handle(GEOM_Object) theShape2,
2058 Handle(TColStd_HSequenceOfReal)& theDoubles)
2061 Standard_Integer nbSolutions = 0;
2063 if (theShape1.IsNull() || theShape2.IsNull()) return nbSolutions;
2065 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
2066 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
2067 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return nbSolutions;
2069 TopoDS_Shape aShape1 = aRefShape1->GetValue();
2070 TopoDS_Shape aShape2 = aRefShape2->GetValue();
2071 if (aShape1.IsNull() || aShape2.IsNull()) {
2072 SetErrorCode("One of Objects has NULL Shape");
2076 // Compute the extremities
2081 // additional workaround for bugs 19899, 19908 and 19910 from Mantis
2083 double dist = GEOMUtils::GetMinDistanceSingular(aShape1, aShape2, P1, P2);
2087 theDoubles->Append(P1.X());
2088 theDoubles->Append(P1.Y());
2089 theDoubles->Append(P1.Z());
2090 theDoubles->Append(P2.X());
2091 theDoubles->Append(P2.Y());
2092 theDoubles->Append(P2.Z());
2098 BRepExtrema_DistShapeShape dst (aShape1, aShape2);
2100 nbSolutions = dst.NbSolution();
2101 if (theDoubles.IsNull()) theDoubles = new TColStd_HSequenceOfReal;
2104 for (int i = 1; i <= nbSolutions; i++) {
2105 P1 = dst.PointOnShape1(i);
2106 P2 = dst.PointOnShape2(i);
2108 theDoubles->Append(P1.X());
2109 theDoubles->Append(P1.Y());
2110 theDoubles->Append(P1.Z());
2111 theDoubles->Append(P2.X());
2112 theDoubles->Append(P2.Y());
2113 theDoubles->Append(P2.Z());
2117 catch (Standard_Failure) {
2118 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2119 SetErrorCode(aFail->GetMessageString());
2127 //=======================================================================
2129 * Get coordinates of point
2131 //=======================================================================
2132 void GEOMImpl_IMeasureOperations::PointCoordinates (Handle(GEOM_Object) theShape,
2133 Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ)
2137 if (theShape.IsNull())
2140 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
2141 if (aRefShape.IsNull())
2144 TopoDS_Shape aShape = aRefShape->GetValue();
2145 if (aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX)
2147 SetErrorCode( "Shape must be a vertex" );
2153 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
2160 catch (Standard_Failure)
2162 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2163 SetErrorCode( aFail->GetMessageString() );
2167 //=======================================================================
2169 * Compute angle (in degrees) between two lines
2171 //=======================================================================
2172 Standard_Real GEOMImpl_IMeasureOperations::GetAngle (Handle(GEOM_Object) theLine1,
2173 Handle(GEOM_Object) theLine2)
2175 if (theLine1->GetType() == GEOM_VECTOR &&
2176 theLine2->GetType() == GEOM_VECTOR)
2177 return GetAngleBtwVectors(theLine1, theLine2);
2181 Standard_Real anAngle = -1.0;
2183 if (theLine1.IsNull() || theLine2.IsNull())
2186 Handle(GEOM_Function) aRefLine1 = theLine1->GetLastFunction();
2187 Handle(GEOM_Function) aRefLine2 = theLine2->GetLastFunction();
2188 if (aRefLine1.IsNull() || aRefLine2.IsNull())
2191 TopoDS_Shape aLine1 = aRefLine1->GetValue();
2192 TopoDS_Shape aLine2 = aRefLine2->GetValue();
2193 if (aLine1.IsNull() || aLine2.IsNull() ||
2194 aLine1.ShapeType() != TopAbs_EDGE ||
2195 aLine2.ShapeType() != TopAbs_EDGE)
2197 SetErrorCode("Two edges must be given");
2203 TopoDS_Edge E1 = TopoDS::Edge(aLine1);
2204 TopoDS_Edge E2 = TopoDS::Edge(aLine2);
2207 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp,lp);
2208 Handle(Geom_Curve) C2 = BRep_Tool::Curve(E2,fp,lp);
2210 if ( C1.IsNull() || C2.IsNull() ||
2211 !C1->IsKind(STANDARD_TYPE(Geom_Line)) ||
2212 !C2->IsKind(STANDARD_TYPE(Geom_Line)))
2214 SetErrorCode("The edges must be linear");
2218 Handle(Geom_Line) L1 = Handle(Geom_Line)::DownCast(C1);
2219 Handle(Geom_Line) L2 = Handle(Geom_Line)::DownCast(C2);
2221 gp_Lin aLin1 = L1->Lin();
2222 gp_Lin aLin2 = L2->Lin();
2224 anAngle = aLin1.Angle(aLin2);
2225 anAngle *= 180. / M_PI; // convert radians into degrees
2227 if (anAngle > 90.0) {
2228 anAngle = 180.0 - anAngle;
2233 catch (Standard_Failure)
2235 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2236 SetErrorCode(aFail->GetMessageString());
2242 //=======================================================================
2244 * Compute angle (in degrees) between two vectors
2246 //=======================================================================
2247 Standard_Real GEOMImpl_IMeasureOperations::GetAngleBtwVectors (Handle(GEOM_Object) theVec1,
2248 Handle(GEOM_Object) theVec2)
2252 Standard_Real anAngle = -1.0;
2254 if (theVec1.IsNull() || theVec2.IsNull())
2257 if (theVec1->GetType() != GEOM_VECTOR || theVec2->GetType() != GEOM_VECTOR) {
2258 SetErrorCode("Two vectors must be given");
2262 Handle(GEOM_Function) aRefVec1 = theVec1->GetLastFunction();
2263 Handle(GEOM_Function) aRefVec2 = theVec2->GetLastFunction();
2264 if (aRefVec1.IsNull() || aRefVec2.IsNull())
2267 TopoDS_Shape aVec1 = aRefVec1->GetValue();
2268 TopoDS_Shape aVec2 = aRefVec2->GetValue();
2269 if (aVec1.IsNull() || aVec2.IsNull() ||
2270 aVec1.ShapeType() != TopAbs_EDGE ||
2271 aVec2.ShapeType() != TopAbs_EDGE)
2273 SetErrorCode("Two edges must be given");
2279 TopoDS_Edge aE1 = TopoDS::Edge(aVec1);
2280 TopoDS_Edge aE2 = TopoDS::Edge(aVec2);
2282 TopoDS_Vertex aP11, aP12, aP21, aP22;
2283 TopExp::Vertices(aE1, aP11, aP12, Standard_True);
2284 TopExp::Vertices(aE2, aP21, aP22, Standard_True);
2285 if (aP11.IsNull() || aP12.IsNull() || aP21.IsNull() || aP22.IsNull()) {
2286 SetErrorCode("Bad edge given");
2290 gp_Vec aV1 (BRep_Tool::Pnt(aP11), BRep_Tool::Pnt(aP12));
2291 gp_Vec aV2 (BRep_Tool::Pnt(aP21), BRep_Tool::Pnt(aP22)) ;
2293 anAngle = aV1.Angle(aV2);
2294 anAngle *= 180. / M_PI; // convert radians into degrees
2298 catch (Standard_Failure)
2300 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2301 SetErrorCode(aFail->GetMessageString());
2308 //=============================================================================
2310 * CurveCurvatureByParam
2312 //=============================================================================
2313 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByParam
2314 (Handle(GEOM_Object) theCurve, Standard_Real& theParam)
2317 Standard_Real aRes = -1.0;
2319 if(theCurve.IsNull()) return aRes;
2321 Handle(GEOM_Function) aRefShape = theCurve->GetLastFunction();
2322 if(aRefShape.IsNull()) return aRes;
2324 TopoDS_Shape aShape = aRefShape->GetValue();
2325 if(aShape.IsNull()) {
2326 SetErrorCode("One of Objects has NULL Shape");
2330 Standard_Real aFP, aLP, aP;
2331 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aFP, aLP);
2332 aP = aFP + (aLP - aFP) * theParam;
2334 if(aCurve.IsNull()) return aRes;
2339 GeomLProp_CLProps Prop = GeomLProp_CLProps
2340 (aCurve, aP, 2, Precision::Confusion());
2341 aRes = fabs(Prop.Curvature());
2344 catch (Standard_Failure) {
2345 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2346 SetErrorCode(aFail->GetMessageString());
2350 if( aRes > Precision::Confusion() )
2359 //=============================================================================
2361 * CurveCurvatureByPoint
2363 //=============================================================================
2364 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByPoint
2365 (Handle(GEOM_Object) theCurve, Handle(GEOM_Object) thePoint)
2368 Standard_Real aRes = -1.0;
2370 if( theCurve.IsNull() || thePoint.IsNull() ) return aRes;
2372 Handle(GEOM_Function) aRefCurve = theCurve->GetLastFunction();
2373 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2374 if( aRefCurve.IsNull() || aRefPoint.IsNull() ) return aRes;
2376 TopoDS_Edge anEdge = TopoDS::Edge(aRefCurve->GetValue());
2377 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2378 if( anEdge.IsNull() || aPnt.IsNull() ) {
2379 SetErrorCode("One of Objects has NULL Shape");
2383 Standard_Real aFP, aLP;
2384 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFP, aLP);
2385 if(aCurve.IsNull()) return aRes;
2386 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2391 GeomAPI_ProjectPointOnCurve PPCurve(aPoint, aCurve, aFP, aLP);
2392 if(PPCurve.NbPoints()>0) {
2393 GeomLProp_CLProps Prop = GeomLProp_CLProps
2394 (aCurve, PPCurve.LowerDistanceParameter(), 2, Precision::Confusion());
2395 aRes = fabs(Prop.Curvature());
2399 catch (Standard_Failure) {
2400 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2401 SetErrorCode(aFail->GetMessageString());
2405 if( aRes > Precision::Confusion() )
2414 //=============================================================================
2416 * getSurfaceCurvatures
2418 //=============================================================================
2419 Standard_Real GEOMImpl_IMeasureOperations::getSurfaceCurvatures
2420 (const Handle(Geom_Surface)& aSurf,
2421 Standard_Real theUParam,
2422 Standard_Real theVParam,
2423 Standard_Boolean theNeedMaxCurv)
2426 Standard_Real aRes = 1.0;
2428 if (aSurf.IsNull()) return aRes;
2432 GeomLProp_SLProps Prop = GeomLProp_SLProps
2433 (aSurf, theUParam, theVParam, 2, Precision::Confusion());
2434 if(Prop.IsCurvatureDefined()) {
2435 if(Prop.IsUmbilic()) {
2436 //cout<<"is umbilic"<<endl;
2437 aRes = fabs(Prop.MeanCurvature());
2440 //cout<<"is not umbilic"<<endl;
2441 double c1 = fabs(Prop.MaxCurvature());
2442 double c2 = fabs(Prop.MinCurvature());
2451 catch (Standard_Failure) {
2452 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2453 SetErrorCode(aFail->GetMessageString());
2457 if( fabs(aRes) > Precision::Confusion() )
2466 //=============================================================================
2468 * MaxSurfaceCurvatureByParam
2470 //=============================================================================
2471 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByParam
2472 (Handle(GEOM_Object) theSurf,
2473 Standard_Real& theUParam,
2474 Standard_Real& theVParam)
2477 Standard_Real aRes = -1.0;
2479 if (theSurf.IsNull()) return aRes;
2481 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2482 if(aRefShape.IsNull()) return aRes;
2484 TopoDS_Shape aShape = aRefShape->GetValue();
2485 if(aShape.IsNull()) {
2486 SetErrorCode("One of Objects has NULL Shape");
2490 TopoDS_Face F = TopoDS::Face(aShape);
2491 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2493 //Compute the parameters
2494 Standard_Real U1,U2,V1,V2;
2495 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2496 Standard_Real U = U1 + (U2-U1)*theUParam;
2497 Standard_Real V = V1 + (V2-V1)*theVParam;
2499 return getSurfaceCurvatures(aSurf, U, V, true);
2503 //=============================================================================
2505 * MaxSurfaceCurvatureByPoint
2507 //=============================================================================
2508 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByPoint
2509 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2512 Standard_Real aRes = -1.0;
2514 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2516 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2517 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2518 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2520 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2521 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2522 if( aFace.IsNull() || aPnt.IsNull() ) {
2523 SetErrorCode("One of Objects has NULL Shape");
2527 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2528 if(aSurf.IsNull()) return aRes;
2529 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2531 //Compute the parameters
2532 ShapeAnalysis_Surface sas(aSurf);
2533 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2535 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), true);
2539 //=============================================================================
2541 * MinSurfaceCurvatureByParam
2543 //=============================================================================
2544 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByParam
2545 (Handle(GEOM_Object) theSurf,
2546 Standard_Real& theUParam,
2547 Standard_Real& theVParam)
2550 Standard_Real aRes = -1.0;
2552 if (theSurf.IsNull()) return aRes;
2554 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2555 if(aRefShape.IsNull()) return aRes;
2557 TopoDS_Shape aShape = aRefShape->GetValue();
2558 if(aShape.IsNull()) {
2559 SetErrorCode("One of Objects has NULL Shape");
2563 TopoDS_Face F = TopoDS::Face(aShape);
2564 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2566 //Compute the parameters
2567 Standard_Real U1,U2,V1,V2;
2568 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2569 Standard_Real U = U1 + (U2-U1)*theUParam;
2570 Standard_Real V = V1 + (V2-V1)*theVParam;
2572 return getSurfaceCurvatures(aSurf, U, V, false);
2576 //=============================================================================
2578 * MinSurfaceCurvatureByPoint
2580 //=============================================================================
2581 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByPoint
2582 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2585 Standard_Real aRes = -1.0;
2587 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2589 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2590 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2591 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2593 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2594 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2595 if( aFace.IsNull() || aPnt.IsNull() ) {
2596 SetErrorCode("One of Objects has NULL Shape");
2600 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2601 if(aSurf.IsNull()) return aRes;
2602 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2604 //Compute the parameters
2605 ShapeAnalysis_Surface sas(aSurf);
2606 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2608 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), false);
2611 //=======================================================================
2612 //function : FillErrorsSub
2613 //purpose : Fill the errors list of subshapes on shape.
2614 //=======================================================================
2615 void GEOMImpl_IMeasureOperations::FillErrorsSub
2616 (const BRepCheck_Analyzer &theAna,
2617 const TopoDS_Shape &theShape,
2618 const TopAbs_ShapeEnum theSubType,
2619 TopTools_DataMapOfIntegerListOfShape &theMapErrors) const
2621 TopExp_Explorer anExp(theShape, theSubType);
2622 TopTools_MapOfShape aMapSubShapes;
2624 for (; anExp.More(); anExp.Next()) {
2625 const TopoDS_Shape &aSubShape = anExp.Current();
2627 if (aMapSubShapes.Add(aSubShape)) {
2628 const Handle(BRepCheck_Result) &aRes = theAna.Result(aSubShape);
2630 for (aRes->InitContextIterator();
2631 aRes->MoreShapeInContext();
2632 aRes->NextShapeInContext()) {
2633 if (aRes->ContextualShape().IsSame(theShape)) {
2634 BRepCheck_ListIteratorOfListOfStatus itl(aRes->StatusOnShape());
2636 if (itl.Value() != BRepCheck_NoError) {
2637 // Add all errors for theShape and its sub-shape.
2638 for (;itl.More(); itl.Next()) {
2639 const Standard_Integer aStat = (Standard_Integer)itl.Value();
2641 if (!theMapErrors.IsBound(aStat)) {
2642 TopTools_ListOfShape anEmpty;
2644 theMapErrors.Bind(aStat, anEmpty);
2647 TopTools_ListOfShape &theShapes = theMapErrors.ChangeFind(aStat);
2649 theShapes.Append(aSubShape);
2650 theShapes.Append(theShape);
2661 //=======================================================================
2662 //function : FillErrors
2663 //purpose : Fill the errors list.
2664 //=======================================================================
2665 void GEOMImpl_IMeasureOperations::FillErrors
2666 (const BRepCheck_Analyzer &theAna,
2667 const TopoDS_Shape &theShape,
2668 TopTools_DataMapOfIntegerListOfShape &theMapErrors,
2669 TopTools_MapOfShape &theMapShapes) const
2671 if (theMapShapes.Add(theShape)) {
2672 // Fill errors of child shapes.
2673 for (TopoDS_Iterator iter(theShape); iter.More(); iter.Next()) {
2674 FillErrors(theAna, iter.Value(), theMapErrors, theMapShapes);
2677 // Fill errors of theShape.
2678 const Handle(BRepCheck_Result) &aRes = theAna.Result(theShape);
2680 if (!aRes.IsNull()) {
2681 BRepCheck_ListIteratorOfListOfStatus itl(aRes->Status());
2683 if (itl.Value() != BRepCheck_NoError) {
2684 // Add all errors for theShape.
2685 for (;itl.More(); itl.Next()) {
2686 const Standard_Integer aStat = (Standard_Integer)itl.Value();
2688 if (!theMapErrors.IsBound(aStat)) {
2689 TopTools_ListOfShape anEmpty;
2691 theMapErrors.Bind(aStat, anEmpty);
2694 theMapErrors.ChangeFind(aStat).Append(theShape);
2699 // Add errors of subshapes on theShape.
2700 const TopAbs_ShapeEnum aType = theShape.ShapeType();
2704 FillErrorsSub(theAna, theShape, TopAbs_VERTEX, theMapErrors);
2707 FillErrorsSub(theAna, theShape, TopAbs_WIRE, theMapErrors);
2708 FillErrorsSub(theAna, theShape, TopAbs_EDGE, theMapErrors);
2709 FillErrorsSub(theAna, theShape, TopAbs_VERTEX, theMapErrors);
2712 FillErrorsSub(theAna, theShape, TopAbs_SHELL, theMapErrors);
2720 //=======================================================================
2721 //function : FillErrors
2722 //purpose : Fill the errors list.
2723 //=======================================================================
2724 void GEOMImpl_IMeasureOperations::FillErrors
2725 (const BRepCheck_Analyzer &theAna,
2726 const TopoDS_Shape &theShape,
2727 std::list<ShapeError> &theErrors) const
2729 // Fill the errors map.
2730 TopTools_DataMapOfIntegerListOfShape aMapErrors;
2731 TopTools_MapOfShape aMapShapes;
2733 FillErrors(theAna, theShape, aMapErrors, aMapShapes);
2735 // Map sub-shapes and their indices
2736 TopTools_IndexedMapOfShape anIndices;
2738 TopExp::MapShapes(theShape, anIndices);
2740 TopTools_DataMapIteratorOfDataMapOfIntegerListOfShape aMapIter(aMapErrors);
2742 for (; aMapIter.More(); aMapIter.Next()) {
2745 anError.error = (BRepCheck_Status)aMapIter.Key();
2747 TopTools_ListIteratorOfListOfShape aListIter(aMapIter.Value());
2748 TopTools_MapOfShape aMapUnique;
2750 for (; aListIter.More(); aListIter.Next()) {
2751 const TopoDS_Shape &aShape = aListIter.Value();
2753 if (aMapUnique.Add(aShape)) {
2754 const Standard_Integer anIndex = anIndices.FindIndex(aShape);
2756 anError.incriminated.push_back(anIndex);
2760 if (!anError.incriminated.empty()) {
2761 theErrors.push_back(anError);