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
538 gp_Pnt aC = anInfo.Location();
539 theDoubles->Append(aC.X());
540 theDoubles->Append(aC.Y());
541 theDoubles->Append(aC.Z());
543 gp_Ax3 anAx3 = anInfo.Position();
544 gp_Dir aD = anAx3.Direction();
545 theDoubles->Append(aD.X());
546 theDoubles->Append(aD.Y());
547 theDoubles->Append(aD.Z());
549 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
550 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
555 // ??? geompy.kind.FACE nb_edges nb_vertices _surface_type_id_
556 // (+) geompy.kind.FACE nb_edges nb_vertices
557 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
558 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
567 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
569 case GEOMAlgo_KN_CIRCLE:
571 // (+) geompy.kind.CIRCLE xc yc zc dx dy dz R
574 gp_Pnt aC = anInfo.Location();
575 theDoubles->Append(aC.X());
576 theDoubles->Append(aC.Y());
577 theDoubles->Append(aC.Z());
579 gp_Ax3 anAx3 = anInfo.Position();
580 gp_Dir aD = anAx3.Direction();
581 theDoubles->Append(aD.X());
582 theDoubles->Append(aD.Y());
583 theDoubles->Append(aD.Z());
585 theDoubles->Append(anInfo.Radius1());
588 case GEOMAlgo_KN_ARCCIRCLE:
590 // (+) geompy.kind.ARC_CIRCLE xc yc zc dx dy dz R x1 y1 z1 x2 y2 z2
591 aKind = SK_ARC_CIRCLE;
593 gp_Pnt aC = anInfo.Location();
594 theDoubles->Append(aC.X());
595 theDoubles->Append(aC.Y());
596 theDoubles->Append(aC.Z());
598 gp_Ax3 anAx3 = anInfo.Position();
599 gp_Dir aD = anAx3.Direction();
600 theDoubles->Append(aD.X());
601 theDoubles->Append(aD.Y());
602 theDoubles->Append(aD.Z());
604 theDoubles->Append(anInfo.Radius1());
606 gp_Pnt aP1 = anInfo.Pnt1();
607 theDoubles->Append(aP1.X());
608 theDoubles->Append(aP1.Y());
609 theDoubles->Append(aP1.Z());
611 gp_Pnt aP2 = anInfo.Pnt2();
612 theDoubles->Append(aP2.X());
613 theDoubles->Append(aP2.Y());
614 theDoubles->Append(aP2.Z());
617 case GEOMAlgo_KN_ELLIPSE:
619 // (+) geompy.kind.ELLIPSE xc yc zc dx dy dz R_1 R_2
622 gp_Pnt aC = anInfo.Location();
623 theDoubles->Append(aC.X());
624 theDoubles->Append(aC.Y());
625 theDoubles->Append(aC.Z());
627 gp_Ax3 anAx3 = anInfo.Position();
628 gp_Dir aD = anAx3.Direction();
629 theDoubles->Append(aD.X());
630 theDoubles->Append(aD.Y());
631 theDoubles->Append(aD.Z());
633 theDoubles->Append(anInfo.Radius1());
634 theDoubles->Append(anInfo.Radius2());
637 case GEOMAlgo_KN_ARCELLIPSE:
639 // (+) geompy.kind.ARC_ELLIPSE xc yc zc dx dy dz R_1 R_2 x1 y1 z1 x2 y2 z2
640 aKind = SK_ARC_ELLIPSE;
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());
656 gp_Pnt aP1 = anInfo.Pnt1();
657 theDoubles->Append(aP1.X());
658 theDoubles->Append(aP1.Y());
659 theDoubles->Append(aP1.Z());
661 gp_Pnt aP2 = anInfo.Pnt2();
662 theDoubles->Append(aP2.X());
663 theDoubles->Append(aP2.Y());
664 theDoubles->Append(aP2.Z());
667 case GEOMAlgo_KN_LINE:
669 // ??? geompy.kind.LINE x1 y1 z1 x2 y2 z2
670 // (+) geompy.kind.LINE x1 y1 z1 dx dy dz
673 gp_Pnt aO = anInfo.Location();
674 theDoubles->Append(aO.X());
675 theDoubles->Append(aO.Y());
676 theDoubles->Append(aO.Z());
678 gp_Dir aD = anInfo.Direction();
679 theDoubles->Append(aD.X());
680 theDoubles->Append(aD.Y());
681 theDoubles->Append(aD.Z());
684 case GEOMAlgo_KN_SEGMENT:
686 // (+) geompy.kind.SEGMENT x1 y1 z1 x2 y2 z2
689 gp_Pnt aP1 = anInfo.Pnt1();
690 theDoubles->Append(aP1.X());
691 theDoubles->Append(aP1.Y());
692 theDoubles->Append(aP1.Z());
694 gp_Pnt aP2 = anInfo.Pnt2();
695 theDoubles->Append(aP2.X());
696 theDoubles->Append(aP2.Y());
697 theDoubles->Append(aP2.Z());
701 // ??? geompy.kind.EDGE nb_vertices _curve_type_id_
702 // (+) geompy.kind.EDGE nb_vertices
703 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
710 // (+) geompy.kind.VERTEX x y z
713 gp_Pnt aP = anInfo.Location();
714 theDoubles->Append(aP.X());
715 theDoubles->Append(aP.Y());
716 theDoubles->Append(aP.Z());
725 //=============================================================================
729 //=============================================================================
730 void GEOMImpl_IMeasureOperations::GetPosition
731 (Handle(GEOM_Object) theShape,
732 Standard_Real& Ox, Standard_Real& Oy, Standard_Real& Oz,
733 Standard_Real& Zx, Standard_Real& Zy, Standard_Real& Zz,
734 Standard_Real& Xx, Standard_Real& Xy, Standard_Real& Xz)
738 //Set default values: global CS
739 Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
742 if (theShape.IsNull()) return;
744 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
745 if (aRefShape.IsNull()) return;
747 TopoDS_Shape aShape = aRefShape->GetValue();
748 if (aShape.IsNull()) {
749 SetErrorCode("The Objects has NULL Shape");
756 gp_Ax3 anAx3 = GEOMUtils::GetPosition(aShape);
758 gp_Pnt anOri = anAx3.Location();
759 gp_Dir aDirZ = anAx3.Direction();
760 gp_Dir aDirX = anAx3.XDirection();
763 anOri.Coord(Ox, Oy, Oz);
764 aDirZ.Coord(Zx, Zy, Zz);
765 aDirX.Coord(Xx, Xy, Xz);
767 catch (Standard_Failure) {
768 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
769 SetErrorCode(aFail->GetMessageString());
776 //=============================================================================
780 //=============================================================================
781 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetCentreOfMass
782 (Handle(GEOM_Object) theShape)
786 if (theShape.IsNull()) return NULL;
788 //Add a new CentreOfMass object
789 Handle(GEOM_Object) aCDG = GetEngine()->AddObject(GetDocID(), GEOM_CDG);
791 //Add a new CentreOfMass function
792 Handle(GEOM_Function) aFunction =
793 aCDG->AddFunction(GEOMImpl_MeasureDriver::GetID(), CDG_MEASURE);
794 if (aFunction.IsNull()) return NULL;
796 //Check if the function is set correctly
797 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
799 GEOMImpl_IMeasure aCI (aFunction);
801 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
802 if (aRefShape.IsNull()) return NULL;
804 aCI.SetBase(aRefShape);
806 //Compute the CentreOfMass value
809 if (!GetSolver()->ComputeFunction(aFunction)) {
810 SetErrorCode("Measure driver failed to compute centre of mass");
814 catch (Standard_Failure) {
815 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
816 SetErrorCode(aFail->GetMessageString());
820 //Make a Python command
821 GEOM::TPythonDump(aFunction) << aCDG << " = geompy.MakeCDG(" << theShape << ")";
827 //=============================================================================
831 //=============================================================================
832 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetVertexByIndex
833 (Handle(GEOM_Object) theShape,
834 Standard_Integer theIndex)
838 if (theShape.IsNull()) return NULL;
840 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
841 if (aRefShape.IsNull()) return NULL;
843 //Add a new Vertex object
844 Handle(GEOM_Object) aVertex = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
847 Handle(GEOM_Function) aFunction =
848 aVertex->AddFunction(GEOMImpl_MeasureDriver::GetID(), VERTEX_BY_INDEX);
849 if (aFunction.IsNull()) return NULL;
851 //Check if the function is set correctly
852 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
854 GEOMImpl_IMeasure aCI (aFunction);
855 aCI.SetBase(aRefShape);
856 aCI.SetIndex(theIndex);
861 if (!GetSolver()->ComputeFunction(aFunction)) {
862 SetErrorCode("Vertex by index driver failed.");
866 catch (Standard_Failure) {
867 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
868 SetErrorCode(aFail->GetMessageString());
872 //Make a Python command
873 GEOM::TPythonDump(aFunction) << aVertex << " = geompy.GetVertexByIndex(" << theShape << ", " << theIndex << ")";
879 //=============================================================================
883 //=============================================================================
884 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetNormal
885 (Handle(GEOM_Object) theFace,
886 Handle(GEOM_Object) theOptionalPoint)
890 if (theFace.IsNull()) return NULL;
892 //Add a new Normale object
893 Handle(GEOM_Object) aNorm = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
895 //Add a new Normale function
896 Handle(GEOM_Function) aFunction =
897 aNorm->AddFunction(GEOMImpl_MeasureDriver::GetID(), VECTOR_FACE_NORMALE);
898 if (aFunction.IsNull()) return NULL;
900 //Check if the function is set correctly
901 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
903 GEOMImpl_IMeasure aCI (aFunction);
905 Handle(GEOM_Function) aFace = theFace->GetLastFunction();
906 if (aFace.IsNull()) return NULL;
910 if (!theOptionalPoint.IsNull()) {
911 Handle(GEOM_Function) anOptPnt = theOptionalPoint->GetLastFunction();
912 aCI.SetPoint(anOptPnt);
915 //Compute the Normale value
918 if (!GetSolver()->ComputeFunction(aFunction)) {
919 SetErrorCode("Measure driver failed to compute normake of face");
923 catch (Standard_Failure) {
924 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
925 SetErrorCode(aFail->GetMessageString());
929 //Make a Python command
930 GEOM::TPythonDump pd (aFunction);
931 pd << aNorm << " = geompy.GetNormal(" << theFace;
932 if (!theOptionalPoint.IsNull()) {
933 pd << ", " << theOptionalPoint;
941 //=============================================================================
945 //=============================================================================
946 void GEOMImpl_IMeasureOperations::GetBasicProperties (Handle(GEOM_Object) theShape,
947 Standard_Real& theLength,
948 Standard_Real& theSurfArea,
949 Standard_Real& theVolume)
953 if (theShape.IsNull()) return;
955 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
956 if (aRefShape.IsNull()) return;
958 TopoDS_Shape aShape = aRefShape->GetValue();
959 if (aShape.IsNull()) {
960 SetErrorCode("The Objects has NULL Shape");
964 //Compute the parameters
965 GProp_GProps LProps, SProps;
968 BRepGProp::LinearProperties(aShape, LProps);
969 theLength = LProps.Mass();
971 BRepGProp::SurfaceProperties(aShape, SProps);
972 theSurfArea = SProps.Mass();
975 if (aShape.ShapeType() < TopAbs_SHELL) {
976 for (TopExp_Explorer Exp (aShape, TopAbs_SOLID); Exp.More(); Exp.Next()) {
978 BRepGProp::VolumeProperties(Exp.Current(), VProps);
979 theVolume += VProps.Mass();
983 catch (Standard_Failure) {
984 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
985 SetErrorCode(aFail->GetMessageString());
992 //=============================================================================
996 //=============================================================================
997 void GEOMImpl_IMeasureOperations::GetInertia
998 (Handle(GEOM_Object) theShape,
999 Standard_Real& I11, Standard_Real& I12, Standard_Real& I13,
1000 Standard_Real& I21, Standard_Real& I22, Standard_Real& I23,
1001 Standard_Real& I31, Standard_Real& I32, Standard_Real& I33,
1002 Standard_Real& Ix , Standard_Real& Iy , Standard_Real& Iz)
1006 if (theShape.IsNull()) return;
1008 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1009 if (aRefShape.IsNull()) return;
1011 TopoDS_Shape aShape = aRefShape->GetValue();
1012 if (aShape.IsNull()) {
1013 SetErrorCode("The Objects has NULL Shape");
1017 //Compute the parameters
1018 GProp_GProps System;
1022 if (aShape.ShapeType() == TopAbs_VERTEX ||
1023 aShape.ShapeType() == TopAbs_EDGE ||
1024 aShape.ShapeType() == TopAbs_WIRE) {
1025 BRepGProp::LinearProperties(aShape, System);
1026 } else if (aShape.ShapeType() == TopAbs_FACE ||
1027 aShape.ShapeType() == TopAbs_SHELL) {
1028 BRepGProp::SurfaceProperties(aShape, System);
1030 BRepGProp::VolumeProperties(aShape, System);
1032 gp_Mat I = System.MatrixOfInertia();
1046 GProp_PrincipalProps Pr = System.PrincipalProperties();
1047 Pr.Moments(Ix,Iy,Iz);
1049 catch (Standard_Failure) {
1050 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1051 SetErrorCode(aFail->GetMessageString());
1058 //=============================================================================
1062 //=============================================================================
1063 void GEOMImpl_IMeasureOperations::GetBoundingBox
1064 (Handle(GEOM_Object) theShape,
1065 const Standard_Boolean precise,
1066 Standard_Real& Xmin, Standard_Real& Xmax,
1067 Standard_Real& Ymin, Standard_Real& Ymax,
1068 Standard_Real& Zmin, Standard_Real& Zmax)
1072 if (theShape.IsNull()) return;
1074 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1075 if (aRefShape.IsNull()) return;
1077 TopoDS_Shape aShape = aRefShape->GetValue();
1078 if (aShape.IsNull()) {
1079 SetErrorCode("The Objects has NULL Shape");
1083 //Compute the parameters
1088 BRepBuilderAPI_Copy aCopyTool (aShape);
1089 if (!aCopyTool.IsDone()) {
1090 SetErrorCode("GetBoundingBox Error: Bad shape detected");
1094 aShape = aCopyTool.Shape();
1096 // remove triangulation to obtain more exact boundaries
1097 BRepTools::Clean(aShape);
1099 BRepBndLib::Add(aShape, B);
1102 if (!GEOMUtils::PreciseBoundingBox(aShape, B)) {
1103 SetErrorCode("GetBoundingBox Error: Bounding box cannot be precised");
1108 B.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
1110 catch (Standard_Failure) {
1111 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1112 SetErrorCode(aFail->GetMessageString());
1119 //=============================================================================
1123 //=============================================================================
1124 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetBoundingBox
1125 (Handle(GEOM_Object) theShape,
1126 const Standard_Boolean precise)
1130 if (theShape.IsNull()) return NULL;
1132 //Add a new BoundingBox object
1133 Handle(GEOM_Object) aBnd = GetEngine()->AddObject(GetDocID(), GEOM_BOX);
1135 //Add a new BoundingBox function
1136 const int aType = (precise ? BND_BOX_MEASURE_PRECISE : BND_BOX_MEASURE);
1137 Handle(GEOM_Function) aFunction =
1138 aBnd->AddFunction(GEOMImpl_MeasureDriver::GetID(), aType);
1139 if (aFunction.IsNull()) return NULL;
1141 //Check if the function is set correctly
1142 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
1144 GEOMImpl_IMeasure aCI (aFunction);
1146 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1147 if (aRefShape.IsNull()) return NULL;
1149 aCI.SetBase(aRefShape);
1151 //Compute the BoundingBox value
1154 if (!GetSolver()->ComputeFunction(aFunction)) {
1155 SetErrorCode("Measure driver failed to compute a bounding box");
1159 catch (Standard_Failure) {
1160 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1161 SetErrorCode(aFail->GetMessageString());
1165 //Make a Python command
1166 GEOM::TPythonDump aPd(aFunction);
1168 aPd << aBnd << " = geompy.MakeBoundingBox(" << theShape;
1180 //=============================================================================
1184 //=============================================================================
1185 void GEOMImpl_IMeasureOperations::GetTolerance
1186 (Handle(GEOM_Object) theShape,
1187 Standard_Real& FaceMin, Standard_Real& FaceMax,
1188 Standard_Real& EdgeMin, Standard_Real& EdgeMax,
1189 Standard_Real& VertMin, Standard_Real& VertMax)
1193 if (theShape.IsNull()) return;
1195 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1196 if (aRefShape.IsNull()) return;
1198 TopoDS_Shape aShape = aRefShape->GetValue();
1199 if (aShape.IsNull()) {
1200 SetErrorCode("The Objects has NULL Shape");
1204 //Compute the parameters
1206 FaceMin = EdgeMin = VertMin = RealLast();
1207 FaceMax = EdgeMax = VertMax = -RealLast();
1211 for (TopExp_Explorer ExF (aShape, TopAbs_FACE); ExF.More(); ExF.Next()) {
1212 TopoDS_Face Face = TopoDS::Face(ExF.Current());
1213 T = BRep_Tool::Tolerance(Face);
1219 for (TopExp_Explorer ExE (aShape, TopAbs_EDGE); ExE.More(); ExE.Next()) {
1220 TopoDS_Edge Edge = TopoDS::Edge(ExE.Current());
1221 T = BRep_Tool::Tolerance(Edge);
1227 for (TopExp_Explorer ExV (aShape, TopAbs_VERTEX); ExV.More(); ExV.Next()) {
1228 TopoDS_Vertex Vertex = TopoDS::Vertex(ExV.Current());
1229 T = BRep_Tool::Tolerance(Vertex);
1236 catch (Standard_Failure) {
1237 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1238 SetErrorCode(aFail->GetMessageString());
1245 //=============================================================================
1249 //=============================================================================
1250 bool GEOMImpl_IMeasureOperations::CheckShape (Handle(GEOM_Object) theShape,
1251 const Standard_Boolean theIsCheckGeom,
1252 std::list<ShapeError> &theErrors)
1257 if (theShape.IsNull()) return false;
1259 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1260 if (aRefShape.IsNull()) return false;
1262 TopoDS_Shape aShape = aRefShape->GetValue();
1263 if (aShape.IsNull()) {
1264 SetErrorCode("The Objects has NULL Shape");
1268 //Compute the parameters
1269 bool isValid = false;
1272 BRepCheck_Analyzer ana (aShape, theIsCheckGeom);
1273 if (ana.IsValid()) {
1276 FillErrors(ana, aShape, theErrors);
1279 catch (Standard_Failure) {
1280 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1281 SetErrorCode(aFail->GetMessageString());
1289 //=============================================================================
1293 //=============================================================================
1294 TCollection_AsciiString GEOMImpl_IMeasureOperations::PrintShapeErrors
1295 (Handle(GEOM_Object) theShape,
1296 const std::list<ShapeError> &theErrors)
1298 TCollection_AsciiString aDump;
1300 if (theShape.IsNull()) {
1304 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1306 if (aRefShape.IsNull()) {
1310 TopoDS_Shape aShape = aRefShape->GetValue();
1312 if (aShape.IsNull()) {
1313 SetErrorCode("The Objects has NULL Shape");
1317 if (!theErrors.empty()) {
1318 // The shape is not valid. Prepare errors for dump.
1319 TopTools_IndexedMapOfShape anIndices;
1320 std::list<ShapeError>::const_iterator anIter = theErrors.begin();
1321 Standard_Integer nbv, nbe, nbw, nbf, nbs, nbo;
1322 nbv = nbe = nbw = nbf = nbs = nbo = 0;
1324 // Map sub-shapes and their indices
1325 TopExp::MapShapes(aShape, anIndices);
1327 const Standard_Integer aNbSubShapes = anIndices.Extent();
1328 TColStd_MapOfInteger aMapPbInd;
1330 aDump += " -- The Shape has problems :\n";
1331 aDump += " Check Count\n";
1332 aDump += " ------------------------------------------------\n";
1334 for (; anIter != theErrors.end(); anIter++) {
1335 Standard_Integer aNbShapes = anIter->incriminated.size();
1337 switch(anIter->error) {
1338 case BRepCheck_InvalidPointOnCurve:
1339 aDump += " Invalid Point on Curve ................... ";
1341 case BRepCheck_InvalidPointOnCurveOnSurface:
1342 aDump += " Invalid Point on CurveOnSurface .......... ";
1344 case BRepCheck_InvalidPointOnSurface:
1345 aDump += " Invalid Point on Surface ................. ";
1347 case BRepCheck_No3DCurve:
1348 aDump += " No 3D Curve .............................. ";
1350 case BRepCheck_Multiple3DCurve:
1351 aDump += " Multiple 3D Curve ........................ ";
1353 case BRepCheck_Invalid3DCurve:
1354 aDump += " Invalid 3D Curve ......................... ";
1356 case BRepCheck_NoCurveOnSurface:
1357 aDump += " No Curve on Surface ...................... ";
1359 case BRepCheck_InvalidCurveOnSurface:
1360 aDump += " Invalid Curve on Surface ................. ";
1362 case BRepCheck_InvalidCurveOnClosedSurface:
1363 aDump += " Invalid Curve on closed Surface .......... ";
1365 case BRepCheck_InvalidSameRangeFlag:
1366 aDump += " Invalid SameRange Flag ................... ";
1368 case BRepCheck_InvalidSameParameterFlag:
1369 aDump += " Invalid SameParameter Flag ............... ";
1371 case BRepCheck_InvalidDegeneratedFlag:
1372 aDump += " Invalid Degenerated Flag ................. ";
1374 case BRepCheck_FreeEdge:
1375 aDump += " Free Edge ................................ ";
1377 case BRepCheck_InvalidMultiConnexity:
1378 aDump += " Invalid MultiConnexity ................... ";
1380 case BRepCheck_InvalidRange:
1381 aDump += " Invalid Range ............................ ";
1383 case BRepCheck_EmptyWire:
1384 aDump += " Empty Wire ............................... ";
1386 case BRepCheck_RedundantEdge:
1387 aDump += " Redundant Edge ........................... ";
1389 case BRepCheck_SelfIntersectingWire:
1390 aDump += " Self Intersecting Wire ................... ";
1392 case BRepCheck_NoSurface:
1393 aDump += " No Surface ............................... ";
1395 case BRepCheck_InvalidWire:
1396 aDump += " Invalid Wire ............................. ";
1398 case BRepCheck_RedundantWire:
1399 aDump += " Redundant Wire ........................... ";
1401 case BRepCheck_IntersectingWires:
1402 aDump += " Intersecting Wires ....................... ";
1404 case BRepCheck_InvalidImbricationOfWires:
1405 aDump += " Invalid Imbrication of Wires ............. ";
1407 case BRepCheck_EmptyShell:
1408 aDump += " Empty Shell .............................. ";
1410 case BRepCheck_RedundantFace:
1411 aDump += " Redundant Face ........................... ";
1413 case BRepCheck_UnorientableShape:
1414 aDump += " Unorientable Shape ....................... ";
1416 case BRepCheck_NotClosed:
1417 aDump += " Not Closed ............................... ";
1419 case BRepCheck_NotConnected:
1420 aDump += " Not Connected ............................ ";
1422 case BRepCheck_SubshapeNotInShape:
1423 aDump += " Sub-shape not in Shape ................... ";
1425 case BRepCheck_BadOrientation:
1426 aDump += " Bad Orientation .......................... ";
1428 case BRepCheck_BadOrientationOfSubshape:
1429 aDump += " Bad Orientation of Sub-shape ............. ";
1431 case BRepCheck_InvalidToleranceValue:
1432 aDump += " Invalid Tolerance Value .................. ";
1434 case BRepCheck_CheckFail:
1435 aDump += " Check Shape Failure ...................... ";
1441 aDump += TCollection_AsciiString(aNbShapes) + "\n";
1443 // Count types of shape.
1444 std::list<int>::const_iterator aShIter = anIter->incriminated.begin();
1446 for (; aShIter != anIter->incriminated.end(); aShIter++) {
1447 const Standard_Integer anIndex = *aShIter;
1449 if (anIndex > 0 && anIndex <= aNbSubShapes && aMapPbInd.Add(anIndex)) {
1450 const TopoDS_Shape &aSubShape = anIndices.FindKey(anIndex);
1451 const TopAbs_ShapeEnum aType = aSubShape.ShapeType();
1454 case TopAbs_VERTEX : nbv++; break;
1455 case TopAbs_EDGE : nbe++; break;
1456 case TopAbs_WIRE : nbw++; break;
1457 case TopAbs_FACE : nbf++; break;
1458 case TopAbs_SHELL : nbs++; break;
1459 case TopAbs_SOLID : nbo++; break;
1466 const Standard_Integer aNbFaultyShapes = nbv + nbe + nbw + nbf + nbs + nbo;
1467 aDump += " ------------------------------------------------\n";
1468 aDump += "*** Shapes with problems : ";
1469 aDump += TCollection_AsciiString(aNbFaultyShapes) + "\n";
1472 aDump += "VERTEX : ";
1473 if (nbv < 10) aDump += " ";
1474 aDump += TCollection_AsciiString(nbv) + "\n";
1478 if (nbe < 10) aDump += " ";
1479 aDump += TCollection_AsciiString(nbe) + "\n";
1483 if (nbw < 10) aDump += " ";
1484 aDump += TCollection_AsciiString(nbw) + "\n";
1488 if (nbf < 10) aDump += " ";
1489 aDump += TCollection_AsciiString(nbf) + "\n";
1492 aDump += "SHELL : ";
1493 if (nbs < 10) aDump += " ";
1494 aDump += TCollection_AsciiString(nbs) + "\n";
1497 aDump += "SOLID : ";
1498 if (nbo < 10) aDump += " ";
1499 aDump += TCollection_AsciiString(nbo) + "\n";
1506 //=============================================================================
1508 * CheckSelfIntersections
1510 //=============================================================================
1511 bool GEOMImpl_IMeasureOperations::CheckSelfIntersections
1512 (Handle(GEOM_Object) theShape,
1513 const SICheckLevel theCheckLevel,
1514 Handle(TColStd_HSequenceOfInteger)& theIntersections)
1518 if (theIntersections.IsNull())
1519 theIntersections = new TColStd_HSequenceOfInteger;
1521 theIntersections->Clear();
1523 if (theShape.IsNull())
1526 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1527 if (aRefShape.IsNull()) return false;
1529 TopoDS_Shape aShape = aRefShape->GetValue();
1530 if (aShape.IsNull()) return false;
1533 TopoDS_Shape aScopy;
1535 GEOMAlgo_AlgoTools::CopyShape(aShape, aScopy);
1537 // Map sub-shapes and their indices
1538 TopTools_IndexedMapOfShape anIndices;
1539 TopExp::MapShapes(aScopy, anIndices);
1541 BOPCol_ListOfShape aLCS;
1542 aLCS.Append(aScopy);
1544 BOPAlgo_CheckerSI aCSI; // checker of self-interferences
1545 aCSI.SetArguments(aLCS);
1546 aCSI.SetLevelOfCheck(theCheckLevel);
1548 // 1. Launch the checker
1550 Standard_Integer iErr = aCSI.ErrorStatus();
1553 Standard_Integer aNbS, n1, n2;
1554 BOPDS_MapIteratorMapOfPassKey aItMPK;
1556 // 2. Take the shapes from DS
1557 const BOPDS_DS& aDS = aCSI.DS();
1558 aNbS=aDS.NbShapes();
1560 // 3. Get the pairs of interfered shapes
1561 const BOPDS_MapOfPassKey& aMPK=aDS.Interferences();
1562 aItMPK.Initialize(aMPK);
1563 for (; aItMPK.More(); aItMPK.Next()) {
1564 const BOPDS_PassKey& aPK=aItMPK.Value();
1567 if (n1 > aNbS || n2 > aNbS){
1568 return false; // Error
1570 const TopoDS_Shape& aS1 = aDS.Shape(n1);
1571 const TopoDS_Shape& aS2 = aDS.Shape(n2);
1573 theIntersections->Append(anIndices.FindIndex(aS1));
1574 theIntersections->Append(anIndices.FindIndex(aS2));
1581 return theIntersections->IsEmpty();
1584 //=============================================================================
1586 * CheckSelfIntersectionsFast
1588 //=============================================================================
1589 bool GEOMImpl_IMeasureOperations::CheckSelfIntersectionsFast
1590 (Handle(GEOM_Object) theShape,
1591 float theDeflection, double theTolerance,
1592 Handle(TColStd_HSequenceOfInteger)& theIntersections)
1596 if (theIntersections.IsNull())
1597 theIntersections = new TColStd_HSequenceOfInteger;
1599 theIntersections->Clear();
1601 if (theShape.IsNull())
1604 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1605 if (aRefShape.IsNull()) return false;
1607 TopoDS_Shape aShape = aRefShape->GetValue();
1608 if (aShape.IsNull()) return false;
1611 TopoDS_Shape aScopy;
1613 GEOMAlgo_AlgoTools::CopyShape(aShape, aScopy);
1614 GEOMUtils::MeshShape(aScopy, theDeflection);
1616 // Map sub-shapes and their indices
1617 TopTools_IndexedMapOfShape anIndices;
1618 TopExp::MapShapes(aScopy, anIndices);
1620 #if OCC_VERSION_LARGE > 0x06090000
1621 // Checker of fast interferences
1622 BRepExtrema_SelfIntersection aTool(aScopy, (theTolerance <= 0.) ? 0.0 : theTolerance);
1624 // Launch the checker
1627 const BRepExtrema_MapOfIntegerPackedMapOfInteger& intersections = aTool.OverlapElements();
1629 std::set<Standard_Integer> processed;
1631 for (BRepExtrema_MapOfIntegerPackedMapOfInteger::Iterator it(intersections); it.More(); it.Next()) {
1632 Standard_Integer idxLeft = it.Key();
1633 if (processed.count(idxLeft) > 0) continue; // already added
1634 processed.insert(idxLeft);
1635 const TColStd_PackedMapOfInteger& overlaps = it.Value();
1636 for (TColStd_MapIteratorOfPackedMapOfInteger subit(overlaps); subit.More(); subit.Next()) {
1637 Standard_Integer idxRight = subit.Key();
1638 if (processed.count(idxRight) > 0) continue; // already added
1639 const TopoDS_Shape& aS1 = aTool.GetSubShape(idxLeft);
1640 const TopoDS_Shape& aS2 = aTool.GetSubShape(idxRight);
1641 theIntersections->Append(anIndices.FindIndex(aS1));
1642 theIntersections->Append(anIndices.FindIndex(aS2));
1650 return theIntersections->IsEmpty();
1653 //=============================================================================
1657 //=============================================================================
1658 bool GEOMImpl_IMeasureOperations::FastIntersect (Handle(GEOM_Object) theShape1, Handle(GEOM_Object) theShape2,
1659 double theTolerance, float theDeflection,
1660 Handle(TColStd_HSequenceOfInteger)& theIntersections1,
1661 Handle(TColStd_HSequenceOfInteger)& theIntersections2)
1664 bool isGood = false;
1666 if (theIntersections1.IsNull())
1667 theIntersections1 = new TColStd_HSequenceOfInteger;
1669 theIntersections1->Clear();
1671 if (theIntersections2.IsNull())
1672 theIntersections2 = new TColStd_HSequenceOfInteger;
1674 theIntersections2->Clear();
1676 if (theShape1.IsNull() || theShape2.IsNull()) {
1677 SetErrorCode("Objects have NULL Shape");
1681 if (theShape1 == theShape2) {
1682 SetErrorCode("Objects are equal");
1685 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
1686 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
1687 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return isGood;
1689 TopoDS_Shape aShape1 = aRefShape1->GetValue();
1690 TopoDS_Shape aShape2 = aRefShape2->GetValue();
1691 if (aShape1.IsNull() || aShape2.IsNull()) return isGood;
1694 TopoDS_Shape aScopy1, aScopy2;
1695 GEOMAlgo_AlgoTools::CopyShape(aShape1, aScopy1);
1696 GEOMAlgo_AlgoTools::CopyShape(aShape2, aScopy2);
1698 GEOMUtils::MeshShape(aScopy1, theDeflection);
1699 GEOMUtils::MeshShape(aScopy2, theDeflection);
1701 // Map sub-shapes and their indices
1702 TopTools_IndexedMapOfShape anIndices1, anIndices2;
1703 TopExp::MapShapes(aScopy1, anIndices1);
1704 TopExp::MapShapes(aScopy2, anIndices2);
1706 BOPCol_ListOfShape aLCS1, aLCS2;
1707 aLCS1.Append(aScopy1); aLCS2.Append(aScopy2);
1709 BRepExtrema_ShapeProximity aBSP; // checker of fast interferences
1710 aBSP.LoadShape1(aScopy1); aBSP.LoadShape2(aScopy2);
1711 aBSP.SetTolerance((theTolerance <= 0.) ? 0.0 : theTolerance);
1713 // 1. Launch the checker
1716 // 2. Get sets of IDs of overlapped faces
1717 #if OCC_VERSION_LARGE > 0x06090000
1718 for (BRepExtrema_MapOfIntegerPackedMapOfInteger::Iterator anIt1 (aBSP.OverlapSubShapes1()); anIt1.More(); anIt1.Next())
1720 for (BRepExtrema_OverlappedSubShapes::Iterator anIt1 (aBSP.OverlapSubShapes1()); anIt1.More(); anIt1.Next())
1723 const TopoDS_Shape& aS1 = aBSP.GetSubShape1(anIt1.Key());
1724 theIntersections1->Append(anIndices1.FindIndex(aS1));
1727 #if OCC_VERSION_LARGE > 0x06090000
1728 for (BRepExtrema_MapOfIntegerPackedMapOfInteger::Iterator anIt2 (aBSP.OverlapSubShapes2()); anIt2.More(); anIt2.Next())
1730 for (BRepExtrema_OverlappedSubShapes::Iterator anIt2 (aBSP.OverlapSubShapes2()); anIt2.More(); anIt2.Next())
1733 const TopoDS_Shape& aS2 = aBSP.GetSubShape2(anIt2.Key());
1734 theIntersections2->Append(anIndices2.FindIndex(aS2));
1737 isGood = !theIntersections1->IsEmpty() && !theIntersections1->IsEmpty();
1745 //=============================================================================
1749 //=============================================================================
1750 TCollection_AsciiString GEOMImpl_IMeasureOperations::IsGoodForSolid (Handle(GEOM_Object) theShape)
1754 TCollection_AsciiString aRes = "";
1756 if (theShape.IsNull()) {
1757 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1760 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1761 if (aRefShape.IsNull()) {
1762 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1765 TopoDS_Shape aShape = aRefShape->GetValue();
1766 if (aShape.IsNull()) {
1767 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1770 if (aShape.ShapeType() == TopAbs_COMPOUND) {
1771 TopoDS_Iterator It (aShape, Standard_True, Standard_True);
1772 if (It.More()) aShape = It.Value();
1774 if (aShape.ShapeType() == TopAbs_SHELL) {
1775 BRepCheck_Shell chkShell (TopoDS::Shell(aShape));
1776 if (chkShell.Closed() == BRepCheck_NotClosed) {
1777 aRes = "WRN_SHAPE_UNCLOSED";
1781 aRes = "WRN_SHAPE_NOT_SHELL";
1793 //=============================================================================
1797 //=============================================================================
1798 TCollection_AsciiString GEOMImpl_IMeasureOperations::WhatIs (Handle(GEOM_Object) theShape)
1802 TCollection_AsciiString Astr;
1804 if (theShape.IsNull()) return Astr;
1806 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1807 if (aRefShape.IsNull()) return Astr;
1809 TopoDS_Shape aShape = aRefShape->GetValue();
1810 if (aShape.IsNull()) {
1811 SetErrorCode("The Objects has NULL Shape");
1815 //Compute the parameters
1816 if (aShape.ShapeType() == TopAbs_EDGE) {
1817 if (BRep_Tool::Degenerated(TopoDS::Edge(aShape))) {
1818 Astr = Astr + " It is a degenerated edge \n";
1822 Astr = Astr + " Number of sub-shapes : \n";
1826 int iType, nbTypes [TopAbs_SHAPE], nbFlatType [TopAbs_SHAPE];
1827 for (iType = 0; iType < TopAbs_SHAPE; ++iType) {
1829 nbFlatType[iType] = 0;
1831 nbTypes[aShape.ShapeType()]++;
1833 TopTools_MapOfShape aMapOfShape;
1834 aMapOfShape.Add(aShape);
1835 TopTools_ListOfShape aListOfShape;
1836 aListOfShape.Append(aShape);
1838 TopTools_ListIteratorOfListOfShape itL (aListOfShape);
1839 for (; itL.More(); itL.Next()) {
1840 TopoDS_Shape sp = itL.Value();
1841 TopoDS_Iterator it (sp);
1842 for (; it.More(); it.Next()) {
1843 TopoDS_Shape s = it.Value();
1844 if (aMapOfShape.Add(s)) {
1845 aListOfShape.Append(s);
1846 nbTypes[s.ShapeType()]++;
1847 if ((sp.ShapeType() == TopAbs_COMPOUND) || (sp.ShapeType() == TopAbs_COMPSOLID)) {
1848 nbFlatType[s.ShapeType()]++;
1854 Astr = Astr + " VERTEX : " + TCollection_AsciiString(nbTypes[TopAbs_VERTEX]) + "\n";
1855 Astr = Astr + " EDGE : " + TCollection_AsciiString(nbTypes[TopAbs_EDGE]) + "\n";
1856 Astr = Astr + " WIRE : " + TCollection_AsciiString(nbTypes[TopAbs_WIRE]) + "\n";
1857 Astr = Astr + " FACE : " + TCollection_AsciiString(nbTypes[TopAbs_FACE]) + "\n";
1858 Astr = Astr + " SHELL : " + TCollection_AsciiString(nbTypes[TopAbs_SHELL]) + "\n";
1859 Astr = Astr + " SOLID : " + TCollection_AsciiString(nbTypes[TopAbs_SOLID]) + "\n";
1860 Astr = Astr + " COMPSOLID : " + TCollection_AsciiString(nbTypes[TopAbs_COMPSOLID]) + "\n";
1861 Astr = Astr + " COMPOUND : " + TCollection_AsciiString(nbTypes[TopAbs_COMPOUND]) + "\n";
1862 Astr = Astr + " SHAPE : " + TCollection_AsciiString(aMapOfShape.Extent()) + "\n";
1864 if ((aShape.ShapeType() == TopAbs_COMPOUND) || (aShape.ShapeType() == TopAbs_COMPSOLID)){
1865 Astr = Astr + " --------------------- \n Flat content : \n";
1866 if (nbFlatType[TopAbs_VERTEX] > 0)
1867 Astr = Astr + " VERTEX : " + TCollection_AsciiString(nbFlatType[TopAbs_VERTEX]) + "\n";
1868 if (nbFlatType[TopAbs_EDGE] > 0)
1869 Astr = Astr + " EDGE : " + TCollection_AsciiString(nbFlatType[TopAbs_EDGE]) + "\n";
1870 if (nbFlatType[TopAbs_WIRE] > 0)
1871 Astr = Astr + " WIRE : " + TCollection_AsciiString(nbFlatType[TopAbs_WIRE]) + "\n";
1872 if (nbFlatType[TopAbs_FACE] > 0)
1873 Astr = Astr + " FACE : " + TCollection_AsciiString(nbFlatType[TopAbs_FACE]) + "\n";
1874 if (nbFlatType[TopAbs_SHELL] > 0)
1875 Astr = Astr + " SHELL : " + TCollection_AsciiString(nbFlatType[TopAbs_SHELL]) + "\n";
1876 if (nbFlatType[TopAbs_SOLID] > 0)
1877 Astr = Astr + " SOLID : " + TCollection_AsciiString(nbFlatType[TopAbs_SOLID]) + "\n";
1880 catch (Standard_Failure) {
1881 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1882 SetErrorCode(aFail->GetMessageString());
1890 //=============================================================================
1894 //=============================================================================
1896 GEOMImpl_IMeasureOperations::AreCoordsInside(Handle(GEOM_Object) theShape,
1897 const std::vector<double>& coords,
1900 std::vector<bool> isInsideRes;
1901 if (!theShape.IsNull()) {
1902 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1903 if (!aRefShape.IsNull()) {
1904 TopoDS_Shape aShape = aRefShape->GetValue();
1905 if (!aShape.IsNull())
1907 TopTools_IndexedMapOfShape mapShape;
1909 TopExp_Explorer anExp;
1910 for ( anExp.Init( aShape, TopAbs_SOLID ); anExp.More(); anExp.Next() )
1911 mapShape.Add( anExp.Current() );
1912 for ( anExp.Init( aShape, TopAbs_FACE, TopAbs_SOLID ); anExp.More(); anExp.Next() )
1913 mapShape.Add( anExp.Current() );
1914 for ( anExp.Init( aShape, TopAbs_EDGE, TopAbs_FACE ); anExp.More(); anExp.Next() )
1915 mapShape.Add( anExp.Current() );
1916 for ( anExp.Init( aShape, TopAbs_VERTEX, TopAbs_EDGE ); anExp.More(); anExp.Next() )
1917 mapShape.Add( anExp.Current() ); //// ?????????
1919 size_t nb_points = coords.size()/3, nb_points_inside = 0;
1920 isInsideRes.resize( nb_points, false );
1922 for ( int iS = 1; iS <= mapShape.Extent(); ++iS )
1924 if ( nb_points_inside == nb_points )
1926 aShape = mapShape( iS );
1927 switch ( aShape.ShapeType() ) {
1930 BRepClass3d_SolidClassifier SC( TopoDS::Solid( aShape ));
1931 for ( size_t i = 0; i < nb_points; i++)
1933 if ( isInsideRes[ i ]) continue;
1934 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
1935 SC.Perform( aPnt, tolerance );
1936 isInsideRes[ i ] = (( SC.State() == TopAbs_IN ) || ( SC.State() == TopAbs_ON ));
1937 nb_points_inside += isInsideRes[ i ];
1943 Standard_Real u1,u2,v1,v2;
1944 const TopoDS_Face& face = TopoDS::Face( aShape );
1945 Handle(Geom_Surface) surf = BRep_Tool::Surface( face );
1946 surf->Bounds( u1,u2,v1,v2 );
1947 GeomAPI_ProjectPointOnSurf project;
1948 project.Init(surf, u1,u2, v1,v2, tolerance );
1949 for ( size_t i = 0; i < nb_points; i++)
1951 if ( isInsideRes[ i ]) continue;
1952 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
1953 project.Perform( aPnt );
1954 if ( project.IsDone() &&
1955 project.NbPoints() > 0 &&
1956 project.LowerDistance() <= tolerance )
1958 Quantity_Parameter u, v;
1959 project.LowerDistanceParameters(u, v);
1960 gp_Pnt2d uv( u, v );
1961 BRepClass_FaceClassifier FC ( face, uv, tolerance );
1962 isInsideRes[ i ] = (( FC.State() == TopAbs_IN ) || ( FC.State() == TopAbs_ON ));
1963 nb_points_inside += isInsideRes[ i ];
1971 const TopoDS_Edge& edge = TopoDS::Edge( aShape );
1972 Handle(Geom_Curve) curve = BRep_Tool::Curve( edge, f, l );
1973 GeomAPI_ProjectPointOnCurve project;
1974 project.Init( curve, f, l );
1975 for ( size_t i = 0; i < nb_points; i++)
1977 if ( isInsideRes[ i ]) continue;
1978 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
1979 project.Perform( aPnt );
1980 isInsideRes[ i ] = ( project.NbPoints() > 0 &&
1981 project.LowerDistance() <= tolerance );
1982 nb_points_inside += isInsideRes[ i ];
1988 gp_Pnt aVPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ));
1989 for ( size_t i = 0; i < nb_points; i++)
1991 if ( isInsideRes[ i ]) continue;
1992 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
1993 isInsideRes[ i ] = ( aPnt.SquareDistance( aVPnt ) <= tolerance * tolerance );
1994 nb_points_inside += isInsideRes[ i ];
1999 } // switch ( aShape.ShapeType() )
2007 //=============================================================================
2011 //=============================================================================
2013 GEOMImpl_IMeasureOperations::GetMinDistance (Handle(GEOM_Object) theShape1,
2014 Handle(GEOM_Object) theShape2,
2023 Standard_Real MinDist = 1.e9;
2025 if (theShape1.IsNull() || theShape2.IsNull()) return MinDist;
2027 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
2028 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
2029 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return MinDist;
2031 TopoDS_Shape aShape1 = aRefShape1->GetValue();
2032 TopoDS_Shape aShape2 = aRefShape2->GetValue();
2033 if (aShape1.IsNull() || aShape2.IsNull()) {
2034 SetErrorCode("One of Objects has NULL Shape");
2038 //Compute the parameters
2042 gp_Pnt aPnt1, aPnt2;
2044 MinDist = GEOMUtils::GetMinDistance(aShape1, aShape2, aPnt1, aPnt2);
2046 if (MinDist >= 0.0) {
2047 aPnt1.Coord(X1, Y1, Z1);
2048 aPnt2.Coord(X2, Y2, Z2);
2053 catch (Standard_Failure) {
2054 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2055 SetErrorCode(aFail->GetMessageString());
2063 //=======================================================================
2065 * Get coordinates of closest points of two shapes
2067 //=======================================================================
2068 Standard_Integer GEOMImpl_IMeasureOperations::ClosestPoints (Handle(GEOM_Object) theShape1,
2069 Handle(GEOM_Object) theShape2,
2070 Handle(TColStd_HSequenceOfReal)& theDoubles)
2073 Standard_Integer nbSolutions = 0;
2075 if (theShape1.IsNull() || theShape2.IsNull()) return nbSolutions;
2077 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
2078 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
2079 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return nbSolutions;
2081 TopoDS_Shape aShape1 = aRefShape1->GetValue();
2082 TopoDS_Shape aShape2 = aRefShape2->GetValue();
2083 if (aShape1.IsNull() || aShape2.IsNull()) {
2084 SetErrorCode("One of Objects has NULL Shape");
2088 // Compute the extremities
2093 // additional workaround for bugs 19899, 19908 and 19910 from Mantis
2095 double dist = GEOMUtils::GetMinDistanceSingular(aShape1, aShape2, P1, P2);
2099 theDoubles->Append(P1.X());
2100 theDoubles->Append(P1.Y());
2101 theDoubles->Append(P1.Z());
2102 theDoubles->Append(P2.X());
2103 theDoubles->Append(P2.Y());
2104 theDoubles->Append(P2.Z());
2110 BRepExtrema_DistShapeShape dst (aShape1, aShape2);
2112 nbSolutions = dst.NbSolution();
2113 if (theDoubles.IsNull()) theDoubles = new TColStd_HSequenceOfReal;
2116 for (int i = 1; i <= nbSolutions; i++) {
2117 P1 = dst.PointOnShape1(i);
2118 P2 = dst.PointOnShape2(i);
2120 theDoubles->Append(P1.X());
2121 theDoubles->Append(P1.Y());
2122 theDoubles->Append(P1.Z());
2123 theDoubles->Append(P2.X());
2124 theDoubles->Append(P2.Y());
2125 theDoubles->Append(P2.Z());
2129 catch (Standard_Failure) {
2130 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2131 SetErrorCode(aFail->GetMessageString());
2139 //=======================================================================
2141 * Get coordinates of point
2143 //=======================================================================
2144 void GEOMImpl_IMeasureOperations::PointCoordinates (Handle(GEOM_Object) theShape,
2145 Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ)
2149 if (theShape.IsNull())
2152 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
2153 if (aRefShape.IsNull())
2156 TopoDS_Shape aShape = aRefShape->GetValue();
2157 if (aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX)
2159 SetErrorCode( "Shape must be a vertex" );
2165 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
2172 catch (Standard_Failure)
2174 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2175 SetErrorCode( aFail->GetMessageString() );
2179 //=======================================================================
2181 * Compute angle (in degrees) between two lines
2183 //=======================================================================
2184 Standard_Real GEOMImpl_IMeasureOperations::GetAngle (Handle(GEOM_Object) theLine1,
2185 Handle(GEOM_Object) theLine2)
2187 if (theLine1->GetType() == GEOM_VECTOR &&
2188 theLine2->GetType() == GEOM_VECTOR)
2189 return GetAngleBtwVectors(theLine1, theLine2);
2193 Standard_Real anAngle = -1.0;
2195 if (theLine1.IsNull() || theLine2.IsNull())
2198 Handle(GEOM_Function) aRefLine1 = theLine1->GetLastFunction();
2199 Handle(GEOM_Function) aRefLine2 = theLine2->GetLastFunction();
2200 if (aRefLine1.IsNull() || aRefLine2.IsNull())
2203 TopoDS_Shape aLine1 = aRefLine1->GetValue();
2204 TopoDS_Shape aLine2 = aRefLine2->GetValue();
2205 if (aLine1.IsNull() || aLine2.IsNull() ||
2206 aLine1.ShapeType() != TopAbs_EDGE ||
2207 aLine2.ShapeType() != TopAbs_EDGE)
2209 SetErrorCode("Two edges must be given");
2215 TopoDS_Edge E1 = TopoDS::Edge(aLine1);
2216 TopoDS_Edge E2 = TopoDS::Edge(aLine2);
2219 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp,lp);
2220 Handle(Geom_Curve) C2 = BRep_Tool::Curve(E2,fp,lp);
2222 if ( C1.IsNull() || C2.IsNull() ||
2223 !C1->IsKind(STANDARD_TYPE(Geom_Line)) ||
2224 !C2->IsKind(STANDARD_TYPE(Geom_Line)))
2226 SetErrorCode("The edges must be linear");
2230 Handle(Geom_Line) L1 = Handle(Geom_Line)::DownCast(C1);
2231 Handle(Geom_Line) L2 = Handle(Geom_Line)::DownCast(C2);
2233 gp_Lin aLin1 = L1->Lin();
2234 gp_Lin aLin2 = L2->Lin();
2236 anAngle = aLin1.Angle(aLin2);
2237 anAngle *= 180. / M_PI; // convert radians into degrees
2239 if (anAngle > 90.0) {
2240 anAngle = 180.0 - anAngle;
2245 catch (Standard_Failure)
2247 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2248 SetErrorCode(aFail->GetMessageString());
2254 //=======================================================================
2256 * Compute angle (in degrees) between two vectors
2258 //=======================================================================
2259 Standard_Real GEOMImpl_IMeasureOperations::GetAngleBtwVectors (Handle(GEOM_Object) theVec1,
2260 Handle(GEOM_Object) theVec2)
2264 Standard_Real anAngle = -1.0;
2266 if (theVec1.IsNull() || theVec2.IsNull())
2269 if (theVec1->GetType() != GEOM_VECTOR || theVec2->GetType() != GEOM_VECTOR) {
2270 SetErrorCode("Two vectors must be given");
2274 Handle(GEOM_Function) aRefVec1 = theVec1->GetLastFunction();
2275 Handle(GEOM_Function) aRefVec2 = theVec2->GetLastFunction();
2276 if (aRefVec1.IsNull() || aRefVec2.IsNull())
2279 TopoDS_Shape aVec1 = aRefVec1->GetValue();
2280 TopoDS_Shape aVec2 = aRefVec2->GetValue();
2281 if (aVec1.IsNull() || aVec2.IsNull() ||
2282 aVec1.ShapeType() != TopAbs_EDGE ||
2283 aVec2.ShapeType() != TopAbs_EDGE)
2285 SetErrorCode("Two edges must be given");
2291 TopoDS_Edge aE1 = TopoDS::Edge(aVec1);
2292 TopoDS_Edge aE2 = TopoDS::Edge(aVec2);
2294 TopoDS_Vertex aP11, aP12, aP21, aP22;
2295 TopExp::Vertices(aE1, aP11, aP12, Standard_True);
2296 TopExp::Vertices(aE2, aP21, aP22, Standard_True);
2297 if (aP11.IsNull() || aP12.IsNull() || aP21.IsNull() || aP22.IsNull()) {
2298 SetErrorCode("Bad edge given");
2302 gp_Vec aV1 (BRep_Tool::Pnt(aP11), BRep_Tool::Pnt(aP12));
2303 gp_Vec aV2 (BRep_Tool::Pnt(aP21), BRep_Tool::Pnt(aP22)) ;
2305 anAngle = aV1.Angle(aV2);
2306 anAngle *= 180. / M_PI; // convert radians into degrees
2310 catch (Standard_Failure)
2312 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2313 SetErrorCode(aFail->GetMessageString());
2320 //=============================================================================
2322 * CurveCurvatureByParam
2324 //=============================================================================
2325 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByParam
2326 (Handle(GEOM_Object) theCurve, Standard_Real& theParam)
2329 Standard_Real aRes = -1.0;
2331 if(theCurve.IsNull()) return aRes;
2333 Handle(GEOM_Function) aRefShape = theCurve->GetLastFunction();
2334 if(aRefShape.IsNull()) return aRes;
2336 TopoDS_Shape aShape = aRefShape->GetValue();
2337 if(aShape.IsNull()) {
2338 SetErrorCode("One of Objects has NULL Shape");
2342 Standard_Real aFP, aLP, aP;
2343 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aFP, aLP);
2344 aP = aFP + (aLP - aFP) * theParam;
2346 if(aCurve.IsNull()) return aRes;
2351 GeomLProp_CLProps Prop = GeomLProp_CLProps
2352 (aCurve, aP, 2, Precision::Confusion());
2353 aRes = fabs(Prop.Curvature());
2356 catch (Standard_Failure) {
2357 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2358 SetErrorCode(aFail->GetMessageString());
2362 if( aRes > Precision::Confusion() )
2371 //=============================================================================
2373 * CurveCurvatureByPoint
2375 //=============================================================================
2376 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByPoint
2377 (Handle(GEOM_Object) theCurve, Handle(GEOM_Object) thePoint)
2380 Standard_Real aRes = -1.0;
2382 if( theCurve.IsNull() || thePoint.IsNull() ) return aRes;
2384 Handle(GEOM_Function) aRefCurve = theCurve->GetLastFunction();
2385 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2386 if( aRefCurve.IsNull() || aRefPoint.IsNull() ) return aRes;
2388 TopoDS_Edge anEdge = TopoDS::Edge(aRefCurve->GetValue());
2389 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2390 if( anEdge.IsNull() || aPnt.IsNull() ) {
2391 SetErrorCode("One of Objects has NULL Shape");
2395 Standard_Real aFP, aLP;
2396 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFP, aLP);
2397 if(aCurve.IsNull()) return aRes;
2398 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2403 GeomAPI_ProjectPointOnCurve PPCurve(aPoint, aCurve, aFP, aLP);
2404 if(PPCurve.NbPoints()>0) {
2405 GeomLProp_CLProps Prop = GeomLProp_CLProps
2406 (aCurve, PPCurve.LowerDistanceParameter(), 2, Precision::Confusion());
2407 aRes = fabs(Prop.Curvature());
2411 catch (Standard_Failure) {
2412 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2413 SetErrorCode(aFail->GetMessageString());
2417 if( aRes > Precision::Confusion() )
2426 //=============================================================================
2428 * getSurfaceCurvatures
2430 //=============================================================================
2431 Standard_Real GEOMImpl_IMeasureOperations::getSurfaceCurvatures
2432 (const Handle(Geom_Surface)& aSurf,
2433 Standard_Real theUParam,
2434 Standard_Real theVParam,
2435 Standard_Boolean theNeedMaxCurv)
2438 Standard_Real aRes = 1.0;
2440 if (aSurf.IsNull()) return aRes;
2444 GeomLProp_SLProps Prop = GeomLProp_SLProps
2445 (aSurf, theUParam, theVParam, 2, Precision::Confusion());
2446 if(Prop.IsCurvatureDefined()) {
2447 if(Prop.IsUmbilic()) {
2448 //cout<<"is umbilic"<<endl;
2449 aRes = fabs(Prop.MeanCurvature());
2452 //cout<<"is not umbilic"<<endl;
2453 double c1 = fabs(Prop.MaxCurvature());
2454 double c2 = fabs(Prop.MinCurvature());
2463 catch (Standard_Failure) {
2464 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2465 SetErrorCode(aFail->GetMessageString());
2469 if( fabs(aRes) > Precision::Confusion() )
2478 //=============================================================================
2480 * MaxSurfaceCurvatureByParam
2482 //=============================================================================
2483 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByParam
2484 (Handle(GEOM_Object) theSurf,
2485 Standard_Real& theUParam,
2486 Standard_Real& theVParam)
2489 Standard_Real aRes = -1.0;
2491 if (theSurf.IsNull()) return aRes;
2493 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2494 if(aRefShape.IsNull()) return aRes;
2496 TopoDS_Shape aShape = aRefShape->GetValue();
2497 if(aShape.IsNull()) {
2498 SetErrorCode("One of Objects has NULL Shape");
2502 TopoDS_Face F = TopoDS::Face(aShape);
2503 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2505 //Compute the parameters
2506 Standard_Real U1,U2,V1,V2;
2507 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2508 Standard_Real U = U1 + (U2-U1)*theUParam;
2509 Standard_Real V = V1 + (V2-V1)*theVParam;
2511 return getSurfaceCurvatures(aSurf, U, V, true);
2515 //=============================================================================
2517 * MaxSurfaceCurvatureByPoint
2519 //=============================================================================
2520 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByPoint
2521 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2524 Standard_Real aRes = -1.0;
2526 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2528 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2529 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2530 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2532 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2533 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2534 if( aFace.IsNull() || aPnt.IsNull() ) {
2535 SetErrorCode("One of Objects has NULL Shape");
2539 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2540 if(aSurf.IsNull()) return aRes;
2541 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2543 //Compute the parameters
2544 ShapeAnalysis_Surface sas(aSurf);
2545 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2547 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), true);
2551 //=============================================================================
2553 * MinSurfaceCurvatureByParam
2555 //=============================================================================
2556 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByParam
2557 (Handle(GEOM_Object) theSurf,
2558 Standard_Real& theUParam,
2559 Standard_Real& theVParam)
2562 Standard_Real aRes = -1.0;
2564 if (theSurf.IsNull()) return aRes;
2566 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2567 if(aRefShape.IsNull()) return aRes;
2569 TopoDS_Shape aShape = aRefShape->GetValue();
2570 if(aShape.IsNull()) {
2571 SetErrorCode("One of Objects has NULL Shape");
2575 TopoDS_Face F = TopoDS::Face(aShape);
2576 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2578 //Compute the parameters
2579 Standard_Real U1,U2,V1,V2;
2580 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2581 Standard_Real U = U1 + (U2-U1)*theUParam;
2582 Standard_Real V = V1 + (V2-V1)*theVParam;
2584 return getSurfaceCurvatures(aSurf, U, V, false);
2588 //=============================================================================
2590 * MinSurfaceCurvatureByPoint
2592 //=============================================================================
2593 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByPoint
2594 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2597 Standard_Real aRes = -1.0;
2599 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2601 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2602 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2603 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2605 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2606 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2607 if( aFace.IsNull() || aPnt.IsNull() ) {
2608 SetErrorCode("One of Objects has NULL Shape");
2612 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2613 if(aSurf.IsNull()) return aRes;
2614 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2616 //Compute the parameters
2617 ShapeAnalysis_Surface sas(aSurf);
2618 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2620 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), false);
2623 //=======================================================================
2624 //function : FillErrorsSub
2625 //purpose : Fill the errors list of subshapes on shape.
2626 //=======================================================================
2627 void GEOMImpl_IMeasureOperations::FillErrorsSub
2628 (const BRepCheck_Analyzer &theAna,
2629 const TopoDS_Shape &theShape,
2630 const TopAbs_ShapeEnum theSubType,
2631 TopTools_DataMapOfIntegerListOfShape &theMapErrors) const
2633 TopExp_Explorer anExp(theShape, theSubType);
2634 TopTools_MapOfShape aMapSubShapes;
2636 for (; anExp.More(); anExp.Next()) {
2637 const TopoDS_Shape &aSubShape = anExp.Current();
2639 if (aMapSubShapes.Add(aSubShape)) {
2640 const Handle(BRepCheck_Result) &aRes = theAna.Result(aSubShape);
2642 for (aRes->InitContextIterator();
2643 aRes->MoreShapeInContext();
2644 aRes->NextShapeInContext()) {
2645 if (aRes->ContextualShape().IsSame(theShape)) {
2646 BRepCheck_ListIteratorOfListOfStatus itl(aRes->StatusOnShape());
2648 if (itl.Value() != BRepCheck_NoError) {
2649 // Add all errors for theShape and its sub-shape.
2650 for (;itl.More(); itl.Next()) {
2651 const Standard_Integer aStat = (Standard_Integer)itl.Value();
2653 if (!theMapErrors.IsBound(aStat)) {
2654 TopTools_ListOfShape anEmpty;
2656 theMapErrors.Bind(aStat, anEmpty);
2659 TopTools_ListOfShape &theShapes = theMapErrors.ChangeFind(aStat);
2661 theShapes.Append(aSubShape);
2662 theShapes.Append(theShape);
2673 //=======================================================================
2674 //function : FillErrors
2675 //purpose : Fill the errors list.
2676 //=======================================================================
2677 void GEOMImpl_IMeasureOperations::FillErrors
2678 (const BRepCheck_Analyzer &theAna,
2679 const TopoDS_Shape &theShape,
2680 TopTools_DataMapOfIntegerListOfShape &theMapErrors,
2681 TopTools_MapOfShape &theMapShapes) const
2683 if (theMapShapes.Add(theShape)) {
2684 // Fill errors of child shapes.
2685 for (TopoDS_Iterator iter(theShape); iter.More(); iter.Next()) {
2686 FillErrors(theAna, iter.Value(), theMapErrors, theMapShapes);
2689 // Fill errors of theShape.
2690 const Handle(BRepCheck_Result) &aRes = theAna.Result(theShape);
2692 if (!aRes.IsNull()) {
2693 BRepCheck_ListIteratorOfListOfStatus itl(aRes->Status());
2695 if (itl.Value() != BRepCheck_NoError) {
2696 // Add all errors for theShape.
2697 for (;itl.More(); itl.Next()) {
2698 const Standard_Integer aStat = (Standard_Integer)itl.Value();
2700 if (!theMapErrors.IsBound(aStat)) {
2701 TopTools_ListOfShape anEmpty;
2703 theMapErrors.Bind(aStat, anEmpty);
2706 theMapErrors.ChangeFind(aStat).Append(theShape);
2711 // Add errors of subshapes on theShape.
2712 const TopAbs_ShapeEnum aType = theShape.ShapeType();
2716 FillErrorsSub(theAna, theShape, TopAbs_VERTEX, theMapErrors);
2719 FillErrorsSub(theAna, theShape, TopAbs_WIRE, theMapErrors);
2720 FillErrorsSub(theAna, theShape, TopAbs_EDGE, theMapErrors);
2721 FillErrorsSub(theAna, theShape, TopAbs_VERTEX, theMapErrors);
2724 FillErrorsSub(theAna, theShape, TopAbs_SHELL, theMapErrors);
2732 //=======================================================================
2733 //function : FillErrors
2734 //purpose : Fill the errors list.
2735 //=======================================================================
2736 void GEOMImpl_IMeasureOperations::FillErrors
2737 (const BRepCheck_Analyzer &theAna,
2738 const TopoDS_Shape &theShape,
2739 std::list<ShapeError> &theErrors) const
2741 // Fill the errors map.
2742 TopTools_DataMapOfIntegerListOfShape aMapErrors;
2743 TopTools_MapOfShape aMapShapes;
2745 FillErrors(theAna, theShape, aMapErrors, aMapShapes);
2747 // Map sub-shapes and their indices
2748 TopTools_IndexedMapOfShape anIndices;
2750 TopExp::MapShapes(theShape, anIndices);
2752 TopTools_DataMapIteratorOfDataMapOfIntegerListOfShape aMapIter(aMapErrors);
2754 for (; aMapIter.More(); aMapIter.Next()) {
2757 anError.error = (BRepCheck_Status)aMapIter.Key();
2759 TopTools_ListIteratorOfListOfShape aListIter(aMapIter.Value());
2760 TopTools_MapOfShape aMapUnique;
2762 for (; aListIter.More(); aListIter.Next()) {
2763 const TopoDS_Shape &aShape = aListIter.Value();
2765 if (aMapUnique.Add(aShape)) {
2766 const Standard_Integer anIndex = anIndices.FindIndex(aShape);
2768 anError.incriminated.push_back(anIndex);
2772 if (!anError.incriminated.empty()) {
2773 theErrors.push_back(anError);