1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <GEOMImpl_IMeasureOperations.hxx>
24 #include <GEOMImpl_IMeasure.hxx>
25 #include <GEOMImpl_MeasureDriver.hxx>
26 #include <GEOMImpl_Types.hxx>
28 #include <GEOMUtils.hxx>
30 #include <GEOMAlgo_AlgoTools.hxx>
31 #include <GEOMAlgo_KindOfName.hxx>
32 #include <GEOMAlgo_ShapeInfoFiller.hxx>
34 #include <GEOM_PythonDump.hxx>
36 #include <utilities.h>
39 #include <Bnd_Box.hxx>
40 #include <BOPAlgo_CheckerSI.hxx>
41 #include <BOPCol_ListOfShape.hxx>
42 #include <BOPDS_DS.hxx>
43 #include <BOPDS_MapOfPassKey.hxx>
44 #include <BOPDS_MapOfPair.hxx>
45 #include <BOPDS_Pair.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 #include <BRepExtrema_SelfIntersection.hxx>
55 #include <BRepExtrema_MapOfIntegerPackedMapOfInteger.hxx>
56 #include <BRepGProp.hxx>
57 #include <BRepTools.hxx>
58 #include <BRep_Tool.hxx>
59 #include <Geom_Line.hxx>
60 #include <GeomAPI_ProjectPointOnCurve.hxx>
61 #include <GeomAPI_ProjectPointOnSurf.hxx>
62 #include <GeomLProp_CLProps.hxx>
63 #include <GeomLProp_SLProps.hxx>
64 #include <Geom_Plane.hxx>
65 #include <GProp_GProps.hxx>
66 #include <GProp_PrincipalProps.hxx>
67 #include <ShapeAnalysis.hxx>
68 #include <ShapeAnalysis_Surface.hxx>
70 #include <TopExp_Explorer.hxx>
72 #include <TopoDS_Edge.hxx>
73 #include <TopTools_IndexedMapOfShape.hxx>
74 #include <TopTools_DataMapIteratorOfDataMapOfIntegerListOfShape.hxx>
75 #include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
76 #include <TopTools_ListIteratorOfListOfShape.hxx>
77 #include <TopTools_ListOfShape.hxx>
78 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
82 //=============================================================================
86 //=============================================================================
87 GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations (GEOM_Engine* theEngine, int theDocID)
88 : GEOM_IOperations(theEngine, theDocID)
90 MESSAGE("GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations");
93 //=============================================================================
97 //=============================================================================
98 GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations()
100 MESSAGE("GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations");
103 //=============================================================================
104 /*! Get kind and parameters of the given shape.
106 //=============================================================================
107 GEOMImpl_IMeasureOperations::ShapeKind GEOMImpl_IMeasureOperations::KindOfShape
108 (Handle(GEOM_Object) theShape,
109 Handle(TColStd_HSequenceOfInteger)& theIntegers,
110 Handle(TColStd_HSequenceOfReal)& theDoubles)
113 ShapeKind aKind = SK_NO_SHAPE;
115 if (theIntegers.IsNull()) theIntegers = new TColStd_HSequenceOfInteger;
116 else theIntegers->Clear();
118 if (theDoubles.IsNull()) theDoubles = new TColStd_HSequenceOfReal;
119 else theDoubles->Clear();
121 if (theShape.IsNull())
124 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
125 if (aRefShape.IsNull()) return aKind;
127 TopoDS_Shape aShape = aRefShape->GetValue();
128 if (aShape.IsNull()) return aKind;
130 int geom_type = theShape->GetType();
132 // check if it's advanced shape
133 if ( geom_type > USER_TYPE ) {
139 GEOMAlgo_ShapeInfoFiller aSF;
140 aSF.SetShape(aShape);
143 Standard_Integer iErr = aSF.ErrorStatus();
146 SetErrorCode("Error in GEOMAlgo_ShapeInfoFiller");
149 const GEOMAlgo_ShapeInfo& anInfo = aSF.Info();
151 // specific processing for some "advandced" objects
152 switch ( geom_type ) {
154 // local coordinate systen
155 // (+) geompy.kind.LCS xc yc zc xx xy xz yx yy yz zx zy zz
157 TopoDS_Face aFace = TopoDS::Face( aShape );
158 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
159 gp_Pnt aC = aPlane->Pln().Location();
160 gp_Ax3 anAx3 = aPlane->Pln().Position();
162 theDoubles->Append(aC.X());
163 theDoubles->Append(aC.Y());
164 theDoubles->Append(aC.Z());
166 gp_Dir aD = anAx3.XDirection();
167 theDoubles->Append(aD.X());
168 theDoubles->Append(aD.Y());
169 theDoubles->Append(aD.Z());
170 aD = anAx3.YDirection();
171 theDoubles->Append(aD.X());
172 theDoubles->Append(aD.Y());
173 theDoubles->Append(aD.Z());
174 aD = anAx3.Direction();
175 theDoubles->Append(aD.X());
176 theDoubles->Append(aD.Y());
177 theDoubles->Append(aD.Z());
183 // Interprete results
184 TopAbs_ShapeEnum aType = anInfo.Type();
187 case TopAbs_COMPOUND:
188 case TopAbs_COMPSOLID:
190 // (+) geompy.kind.COMPOUND nb_solids nb_faces nb_edges nb_vertices
191 // (+) geompy.kind.COMPSOLID nb_solids nb_faces nb_edges nb_vertices
192 // ??? "nb_faces" - all faces or only 'standalone' faces?
193 if (aType == TopAbs_COMPOUND)
196 aKind = SK_COMPSOLID;
198 //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPOUND));
199 //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPSOLID));
200 theIntegers->Append(anInfo.NbSubShapes(TopAbs_SOLID));
201 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
202 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
203 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
209 // (+) geompy.kind.SHELL geompy.info.closed nb_faces nb_edges nb_vertices
210 // (+) geompy.kind.SHELL geompy.info.unclosed nb_faces nb_edges nb_vertices
213 theIntegers->Append((int)anInfo.KindOfClosed());
215 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
216 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
217 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
223 // (+) geompy.kind.WIRE geompy.info.closed nb_edges nb_vertices
224 // (+) geompy.kind.WIRE geompy.info.unclosed nb_edges nb_vertices
227 theIntegers->Append((int)anInfo.KindOfClosed());
229 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
230 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
238 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
241 case GEOMAlgo_KN_SPHERE:
242 // (+) geompy.kind.SPHERE xc yc zc R
246 gp_Pnt aC = anInfo.Location();
247 theDoubles->Append(aC.X());
248 theDoubles->Append(aC.Y());
249 theDoubles->Append(aC.Z());
251 theDoubles->Append(anInfo.Radius1());
254 case GEOMAlgo_KN_CYLINDER:
255 // (+) geompy.kind.CYLINDER xb yb zb dx dy dz R H
259 gp_Pnt aC = anInfo.Location();
260 theDoubles->Append(aC.X());
261 theDoubles->Append(aC.Y());
262 theDoubles->Append(aC.Z());
264 gp_Ax3 anAx3 = anInfo.Position();
265 gp_Dir aD = anAx3.Direction();
266 theDoubles->Append(aD.X());
267 theDoubles->Append(aD.Y());
268 theDoubles->Append(aD.Z());
270 theDoubles->Append(anInfo.Radius1());
271 theDoubles->Append(anInfo.Height());
274 case GEOMAlgo_KN_BOX:
275 // (+) geompy.kind.BOX xc yc zc ax ay az
279 gp_Pnt aC = anInfo.Location();
280 theDoubles->Append(aC.X());
281 theDoubles->Append(aC.Y());
282 theDoubles->Append(aC.Z());
284 gp_Ax3 anAx3 = anInfo.Position();
285 gp_Dir aD = anAx3.Direction();
286 gp_Dir aX = anAx3.XDirection();
289 if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
290 aX.IsParallel(gp::DX(), Precision::Angular())) {
291 theDoubles->Append(anInfo.Length()); // ax'
292 theDoubles->Append(anInfo.Width()); // ay'
293 theDoubles->Append(anInfo.Height()); // az'
295 else if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
296 aX.IsParallel(gp::DY(), Precision::Angular())) {
297 theDoubles->Append(anInfo.Width()); // ay'
298 theDoubles->Append(anInfo.Length()); // ax'
299 theDoubles->Append(anInfo.Height()); // az'
301 else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
302 aX.IsParallel(gp::DZ(), Precision::Angular())) {
303 theDoubles->Append(anInfo.Height()); // az'
304 theDoubles->Append(anInfo.Width()); // ay'
305 theDoubles->Append(anInfo.Length()); // ax'
307 else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
308 aX.IsParallel(gp::DY(), Precision::Angular())) {
309 theDoubles->Append(anInfo.Height()); // az'
310 theDoubles->Append(anInfo.Length()); // ax'
311 theDoubles->Append(anInfo.Width()); // ay'
313 else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
314 aX.IsParallel(gp::DZ(), Precision::Angular())) {
315 theDoubles->Append(anInfo.Width()); // ay'
316 theDoubles->Append(anInfo.Height()); // az'
317 theDoubles->Append(anInfo.Length()); // ax'
319 else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
320 aX.IsParallel(gp::DX(), Precision::Angular())) {
321 theDoubles->Append(anInfo.Length()); // ax'
322 theDoubles->Append(anInfo.Height()); // az'
323 theDoubles->Append(anInfo.Width()); // ay'
326 // (+) geompy.kind.ROTATED_BOX xo yo zo zx zy zz xx xy xz ax ay az
327 aKind = SK_ROTATED_BOX;
329 // Direction and XDirection
330 theDoubles->Append(aD.X());
331 theDoubles->Append(aD.Y());
332 theDoubles->Append(aD.Z());
334 theDoubles->Append(aX.X());
335 theDoubles->Append(aX.Y());
336 theDoubles->Append(aX.Z());
339 theDoubles->Append(anInfo.Length());
340 theDoubles->Append(anInfo.Width());
341 theDoubles->Append(anInfo.Height());
345 case GEOMAlgo_KN_TORUS:
346 // (+) geompy.kind.TORUS xc yc zc dx dy dz R_1 R_2
350 gp_Pnt aO = anInfo.Location();
351 theDoubles->Append(aO.X());
352 theDoubles->Append(aO.Y());
353 theDoubles->Append(aO.Z());
355 gp_Ax3 anAx3 = anInfo.Position();
356 gp_Dir aD = anAx3.Direction();
357 theDoubles->Append(aD.X());
358 theDoubles->Append(aD.Y());
359 theDoubles->Append(aD.Z());
361 theDoubles->Append(anInfo.Radius1());
362 theDoubles->Append(anInfo.Radius2());
365 case GEOMAlgo_KN_CONE:
366 // (+) geompy.kind.CONE xb yb zb dx dy dz R_1 R_2 H
370 gp_Pnt aO = anInfo.Location();
371 theDoubles->Append(aO.X());
372 theDoubles->Append(aO.Y());
373 theDoubles->Append(aO.Z());
375 gp_Ax3 anAx3 = anInfo.Position();
376 gp_Dir aD = anAx3.Direction();
377 theDoubles->Append(aD.X());
378 theDoubles->Append(aD.Y());
379 theDoubles->Append(aD.Z());
381 theDoubles->Append(anInfo.Radius1());
382 theDoubles->Append(anInfo.Radius2());
383 theDoubles->Append(anInfo.Height());
386 case GEOMAlgo_KN_POLYHEDRON:
387 // (+) geompy.kind.POLYHEDRON nb_faces nb_edges nb_vertices
389 aKind = SK_POLYHEDRON;
391 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
392 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
393 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
397 // (+) geompy.kind.SOLID nb_faces nb_edges nb_vertices
399 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
400 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
401 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
411 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
413 case GEOMAlgo_KN_SPHERE:
414 // (+) geompy.kind.SPHERE2D xc yc zc R
418 gp_Pnt aC = anInfo.Location();
419 theDoubles->Append(aC.X());
420 theDoubles->Append(aC.Y());
421 theDoubles->Append(aC.Z());
423 theDoubles->Append(anInfo.Radius1());
426 case GEOMAlgo_KN_CYLINDER:
427 // (+) geompy.kind.CYLINDER2D xb yb zb dx dy dz R H
429 aKind = SK_CYLINDER2D;
431 gp_Pnt aO = anInfo.Location();
432 theDoubles->Append(aO.X());
433 theDoubles->Append(aO.Y());
434 theDoubles->Append(aO.Z());
436 gp_Ax3 anAx3 = anInfo.Position();
437 gp_Dir aD = anAx3.Direction();
438 theDoubles->Append(aD.X());
439 theDoubles->Append(aD.Y());
440 theDoubles->Append(aD.Z());
442 theDoubles->Append(anInfo.Radius1());
443 theDoubles->Append(anInfo.Height());
446 case GEOMAlgo_KN_TORUS:
447 // (+) geompy.kind.TORUS2D xc yc zc dx dy dz R_1 R_2
451 gp_Pnt aO = anInfo.Location();
452 theDoubles->Append(aO.X());
453 theDoubles->Append(aO.Y());
454 theDoubles->Append(aO.Z());
456 gp_Ax3 anAx3 = anInfo.Position();
457 gp_Dir aD = anAx3.Direction();
458 theDoubles->Append(aD.X());
459 theDoubles->Append(aD.Y());
460 theDoubles->Append(aD.Z());
462 theDoubles->Append(anInfo.Radius1());
463 theDoubles->Append(anInfo.Radius2());
466 case GEOMAlgo_KN_CONE:
467 // (+) geompy.kind.CONE2D xc yc zc dx dy dz R_1 R_2 H
471 gp_Pnt aO = anInfo.Location();
472 theDoubles->Append(aO.X());
473 theDoubles->Append(aO.Y());
474 theDoubles->Append(aO.Z());
476 gp_Ax3 anAx3 = anInfo.Position();
477 gp_Dir aD = anAx3.Direction();
478 theDoubles->Append(aD.X());
479 theDoubles->Append(aD.Y());
480 theDoubles->Append(aD.Z());
482 theDoubles->Append(anInfo.Radius1());
483 theDoubles->Append(anInfo.Radius2());
484 theDoubles->Append(anInfo.Height());
487 case GEOMAlgo_KN_DISKCIRCLE:
488 // (+) geompy.kind.DISK_CIRCLE xc yc zc dx dy dz R
490 aKind = SK_DISK_CIRCLE;
492 gp_Pnt aC = anInfo.Location();
493 theDoubles->Append(aC.X());
494 theDoubles->Append(aC.Y());
495 theDoubles->Append(aC.Z());
497 gp_Ax3 anAx3 = anInfo.Position();
498 gp_Dir aD = anAx3.Direction();
499 theDoubles->Append(aD.X());
500 theDoubles->Append(aD.Y());
501 theDoubles->Append(aD.Z());
503 theDoubles->Append(anInfo.Radius1());
506 case GEOMAlgo_KN_DISKELLIPSE:
507 // (+) geompy.kind.DISK_ELLIPSE xc yc zc dx dy dz R_1 R_2
509 aKind = SK_DISK_ELLIPSE;
511 gp_Pnt aC = anInfo.Location();
512 theDoubles->Append(aC.X());
513 theDoubles->Append(aC.Y());
514 theDoubles->Append(aC.Z());
516 gp_Ax3 anAx3 = anInfo.Position();
517 gp_Dir aD = anAx3.Direction();
518 theDoubles->Append(aD.X());
519 theDoubles->Append(aD.Y());
520 theDoubles->Append(aD.Z());
522 theDoubles->Append(anInfo.Radius1());
523 theDoubles->Append(anInfo.Radius2());
526 case GEOMAlgo_KN_RECTANGLE:
527 case GEOMAlgo_KN_TRIANGLE:
528 case GEOMAlgo_KN_QUADRANGLE:
529 case GEOMAlgo_KN_POLYGON:
530 // (+) geompy.kind.POLYGON xo yo zo dx dy dz nb_edges nb_vertices
534 gp_Pnt aO = anInfo.Location();
535 theDoubles->Append(aO.X());
536 theDoubles->Append(aO.Y());
537 theDoubles->Append(aO.Z());
539 gp_Ax3 anAx3 = anInfo.Position();
540 gp_Dir aD = anAx3.Direction();
541 theDoubles->Append(aD.X());
542 theDoubles->Append(aD.Y());
543 theDoubles->Append(aD.Z());
545 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
546 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
549 case GEOMAlgo_KN_PLANE: // infinite
550 // (+) geompy.kind.PLANE xo yo zo dx dy dz
554 gp_Pnt aC = anInfo.Location();
555 theDoubles->Append(aC.X());
556 theDoubles->Append(aC.Y());
557 theDoubles->Append(aC.Z());
559 gp_Ax3 anAx3 = anInfo.Position();
560 gp_Dir aD = anAx3.Direction();
561 theDoubles->Append(aD.X());
562 theDoubles->Append(aD.Y());
563 theDoubles->Append(aD.Z());
565 if (anInfo.KindOfBounds() != GEOMAlgo_KB_INFINITE)
567 // (+) geompy.kind.PLANAR xo yo zo dx dy dz nb_edges nb_vertices
570 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
571 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
576 // ??? geompy.kind.FACE nb_edges nb_vertices _surface_type_id_
577 // (+) geompy.kind.FACE nb_edges nb_vertices
578 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
579 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
588 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
590 case GEOMAlgo_KN_CIRCLE:
592 // (+) geompy.kind.CIRCLE xc yc zc dx dy dz R
595 gp_Pnt aC = anInfo.Location();
596 theDoubles->Append(aC.X());
597 theDoubles->Append(aC.Y());
598 theDoubles->Append(aC.Z());
600 gp_Ax3 anAx3 = anInfo.Position();
601 gp_Dir aD = anAx3.Direction();
602 theDoubles->Append(aD.X());
603 theDoubles->Append(aD.Y());
604 theDoubles->Append(aD.Z());
606 theDoubles->Append(anInfo.Radius1());
609 case GEOMAlgo_KN_ARCCIRCLE:
611 // (+) geompy.kind.ARC_CIRCLE xc yc zc dx dy dz R x1 y1 z1 x2 y2 z2
612 aKind = SK_ARC_CIRCLE;
614 gp_Pnt aC = anInfo.Location();
615 theDoubles->Append(aC.X());
616 theDoubles->Append(aC.Y());
617 theDoubles->Append(aC.Z());
619 gp_Ax3 anAx3 = anInfo.Position();
620 gp_Dir aD = anAx3.Direction();
621 theDoubles->Append(aD.X());
622 theDoubles->Append(aD.Y());
623 theDoubles->Append(aD.Z());
625 theDoubles->Append(anInfo.Radius1());
627 gp_Pnt aP1 = anInfo.Pnt1();
628 theDoubles->Append(aP1.X());
629 theDoubles->Append(aP1.Y());
630 theDoubles->Append(aP1.Z());
632 gp_Pnt aP2 = anInfo.Pnt2();
633 theDoubles->Append(aP2.X());
634 theDoubles->Append(aP2.Y());
635 theDoubles->Append(aP2.Z());
638 case GEOMAlgo_KN_ELLIPSE:
640 // (+) geompy.kind.ELLIPSE xc yc zc dx dy dz R_1 R_2
643 gp_Pnt aC = anInfo.Location();
644 theDoubles->Append(aC.X());
645 theDoubles->Append(aC.Y());
646 theDoubles->Append(aC.Z());
648 gp_Ax3 anAx3 = anInfo.Position();
649 gp_Dir aD = anAx3.Direction();
650 theDoubles->Append(aD.X());
651 theDoubles->Append(aD.Y());
652 theDoubles->Append(aD.Z());
654 theDoubles->Append(anInfo.Radius1());
655 theDoubles->Append(anInfo.Radius2());
658 case GEOMAlgo_KN_ARCELLIPSE:
660 // (+) geompy.kind.ARC_ELLIPSE xc yc zc dx dy dz R_1 R_2 x1 y1 z1 x2 y2 z2
661 aKind = SK_ARC_ELLIPSE;
663 gp_Pnt aC = anInfo.Location();
664 theDoubles->Append(aC.X());
665 theDoubles->Append(aC.Y());
666 theDoubles->Append(aC.Z());
668 gp_Ax3 anAx3 = anInfo.Position();
669 gp_Dir aD = anAx3.Direction();
670 theDoubles->Append(aD.X());
671 theDoubles->Append(aD.Y());
672 theDoubles->Append(aD.Z());
674 theDoubles->Append(anInfo.Radius1());
675 theDoubles->Append(anInfo.Radius2());
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());
688 case GEOMAlgo_KN_LINE:
690 // ??? geompy.kind.LINE x1 y1 z1 x2 y2 z2
691 // (+) geompy.kind.LINE x1 y1 z1 dx dy dz
694 gp_Pnt aO = anInfo.Location();
695 theDoubles->Append(aO.X());
696 theDoubles->Append(aO.Y());
697 theDoubles->Append(aO.Z());
699 gp_Dir aD = anInfo.Direction();
700 theDoubles->Append(aD.X());
701 theDoubles->Append(aD.Y());
702 theDoubles->Append(aD.Z());
705 case GEOMAlgo_KN_SEGMENT:
707 // (+) geompy.kind.SEGMENT x1 y1 z1 x2 y2 z2
710 gp_Pnt aP1 = anInfo.Pnt1();
711 theDoubles->Append(aP1.X());
712 theDoubles->Append(aP1.Y());
713 theDoubles->Append(aP1.Z());
715 gp_Pnt aP2 = anInfo.Pnt2();
716 theDoubles->Append(aP2.X());
717 theDoubles->Append(aP2.Y());
718 theDoubles->Append(aP2.Z());
722 // ??? geompy.kind.EDGE nb_vertices _curve_type_id_
723 // (+) geompy.kind.EDGE nb_vertices
724 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
731 // (+) geompy.kind.VERTEX x y z
734 gp_Pnt aP = anInfo.Location();
735 theDoubles->Append(aP.X());
736 theDoubles->Append(aP.Y());
737 theDoubles->Append(aP.Z());
746 //=============================================================================
750 //=============================================================================
751 void GEOMImpl_IMeasureOperations::GetPosition
752 (Handle(GEOM_Object) theShape,
753 Standard_Real& Ox, Standard_Real& Oy, Standard_Real& Oz,
754 Standard_Real& Zx, Standard_Real& Zy, Standard_Real& Zz,
755 Standard_Real& Xx, Standard_Real& Xy, Standard_Real& Xz)
759 //Set default values: global CS
760 Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
763 if (theShape.IsNull()) return;
765 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
766 if (aRefShape.IsNull()) return;
768 TopoDS_Shape aShape = aRefShape->GetValue();
769 if (aShape.IsNull()) {
770 SetErrorCode("The Objects has NULL Shape");
777 gp_Ax3 anAx3 = GEOMUtils::GetPosition(aShape);
779 gp_Pnt anOri = anAx3.Location();
780 gp_Dir aDirZ = anAx3.Direction();
781 gp_Dir aDirX = anAx3.XDirection();
784 anOri.Coord(Ox, Oy, Oz);
785 aDirZ.Coord(Zx, Zy, Zz);
786 aDirX.Coord(Xx, Xy, Xz);
788 catch (Standard_Failure) {
789 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
790 SetErrorCode(aFail->GetMessageString());
797 //=============================================================================
801 //=============================================================================
802 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetCentreOfMass
803 (Handle(GEOM_Object) theShape)
807 if (theShape.IsNull()) return NULL;
809 //Add a new CentreOfMass object
810 Handle(GEOM_Object) aCDG = GetEngine()->AddObject(GetDocID(), GEOM_CDG);
812 //Add a new CentreOfMass function
813 Handle(GEOM_Function) aFunction =
814 aCDG->AddFunction(GEOMImpl_MeasureDriver::GetID(), CDG_MEASURE);
815 if (aFunction.IsNull()) return NULL;
817 //Check if the function is set correctly
818 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
820 GEOMImpl_IMeasure aCI (aFunction);
822 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
823 if (aRefShape.IsNull()) return NULL;
825 aCI.SetBase(aRefShape);
827 //Compute the CentreOfMass value
830 if (!GetSolver()->ComputeFunction(aFunction)) {
831 SetErrorCode("Measure driver failed to compute centre of mass");
835 catch (Standard_Failure) {
836 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
837 SetErrorCode(aFail->GetMessageString());
841 //Make a Python command
842 GEOM::TPythonDump(aFunction) << aCDG << " = geompy.MakeCDG(" << theShape << ")";
848 //=============================================================================
852 //=============================================================================
853 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetVertexByIndex
854 (Handle(GEOM_Object) theShape,
855 Standard_Integer theIndex)
859 if (theShape.IsNull()) return NULL;
861 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
862 if (aRefShape.IsNull()) return NULL;
864 //Add a new Vertex object
865 Handle(GEOM_Object) aVertex = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
868 Handle(GEOM_Function) aFunction =
869 aVertex->AddFunction(GEOMImpl_MeasureDriver::GetID(), VERTEX_BY_INDEX);
870 if (aFunction.IsNull()) return NULL;
872 //Check if the function is set correctly
873 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
875 GEOMImpl_IMeasure aCI (aFunction);
876 aCI.SetBase(aRefShape);
877 aCI.SetIndex(theIndex);
882 if (!GetSolver()->ComputeFunction(aFunction)) {
883 SetErrorCode("Vertex by index driver failed.");
887 catch (Standard_Failure) {
888 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
889 SetErrorCode(aFail->GetMessageString());
893 //Make a Python command
894 GEOM::TPythonDump(aFunction) << aVertex << " = geompy.GetVertexByIndex(" << theShape << ", " << theIndex << ")";
900 //=============================================================================
904 //=============================================================================
905 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetNormal
906 (Handle(GEOM_Object) theFace,
907 Handle(GEOM_Object) theOptionalPoint)
911 if (theFace.IsNull()) return NULL;
913 //Add a new Normale object
914 Handle(GEOM_Object) aNorm = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
916 //Add a new Normale function
917 Handle(GEOM_Function) aFunction =
918 aNorm->AddFunction(GEOMImpl_MeasureDriver::GetID(), VECTOR_FACE_NORMALE);
919 if (aFunction.IsNull()) return NULL;
921 //Check if the function is set correctly
922 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
924 GEOMImpl_IMeasure aCI (aFunction);
926 Handle(GEOM_Function) aFace = theFace->GetLastFunction();
927 if (aFace.IsNull()) return NULL;
931 if (!theOptionalPoint.IsNull()) {
932 Handle(GEOM_Function) anOptPnt = theOptionalPoint->GetLastFunction();
933 aCI.SetPoint(anOptPnt);
936 //Compute the Normale value
939 if (!GetSolver()->ComputeFunction(aFunction)) {
940 SetErrorCode("Measure driver failed to compute normake of face");
944 catch (Standard_Failure) {
945 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
946 SetErrorCode(aFail->GetMessageString());
950 //Make a Python command
951 GEOM::TPythonDump pd (aFunction);
952 pd << aNorm << " = geompy.GetNormal(" << theFace;
953 if (!theOptionalPoint.IsNull()) {
954 pd << ", " << theOptionalPoint;
962 //=============================================================================
966 //=============================================================================
967 void GEOMImpl_IMeasureOperations::GetBasicProperties (Handle(GEOM_Object) theShape,
968 const Standard_Real theTolerance,
969 Standard_Real& theLength,
970 Standard_Real& theSurfArea,
971 Standard_Real& theVolume)
975 if (theShape.IsNull()) return;
977 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
978 if (aRefShape.IsNull()) return;
980 TopoDS_Shape aShape = aRefShape->GetValue();
981 if (aShape.IsNull()) {
982 SetErrorCode("The Objects has NULL Shape");
986 //Compute the parameters
987 GProp_GProps LProps, SProps;
988 Standard_Real anEps = theTolerance >= 0 ? theTolerance : 1.e-6;
991 BRepGProp::LinearProperties(aShape, LProps, Standard_True);
992 theLength = LProps.Mass();
994 BRepGProp::SurfaceProperties(aShape, SProps, anEps, Standard_True);
995 theSurfArea = SProps.Mass();
998 if (aShape.ShapeType() < TopAbs_SHELL) {
999 for (TopExp_Explorer Exp (aShape, TopAbs_SOLID); Exp.More(); Exp.Next()) {
1000 GProp_GProps VProps;
1001 BRepGProp::VolumeProperties(Exp.Current(), VProps, anEps, Standard_True);
1002 theVolume += VProps.Mass();
1006 catch (Standard_Failure) {
1007 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1008 SetErrorCode(aFail->GetMessageString());
1015 //=============================================================================
1019 //=============================================================================
1020 void GEOMImpl_IMeasureOperations::GetInertia
1021 (Handle(GEOM_Object) theShape,
1022 Standard_Real& I11, Standard_Real& I12, Standard_Real& I13,
1023 Standard_Real& I21, Standard_Real& I22, Standard_Real& I23,
1024 Standard_Real& I31, Standard_Real& I32, Standard_Real& I33,
1025 Standard_Real& Ix , Standard_Real& Iy , Standard_Real& Iz)
1029 if (theShape.IsNull()) return;
1031 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1032 if (aRefShape.IsNull()) return;
1034 TopoDS_Shape aShape = aRefShape->GetValue();
1035 if (aShape.IsNull()) {
1036 SetErrorCode("The Objects has NULL Shape");
1040 //Compute the parameters
1041 GProp_GProps System;
1045 if (aShape.ShapeType() == TopAbs_VERTEX ||
1046 aShape.ShapeType() == TopAbs_EDGE ||
1047 aShape.ShapeType() == TopAbs_WIRE) {
1048 BRepGProp::LinearProperties(aShape, System, Standard_True);
1049 } else if (aShape.ShapeType() == TopAbs_FACE ||
1050 aShape.ShapeType() == TopAbs_SHELL) {
1051 BRepGProp::SurfaceProperties(aShape, System, Standard_True);
1053 BRepGProp::VolumeProperties(aShape, System, Standard_True);
1055 gp_Mat I = System.MatrixOfInertia();
1069 GProp_PrincipalProps Pr = System.PrincipalProperties();
1070 Pr.Moments(Ix,Iy,Iz);
1072 catch (Standard_Failure) {
1073 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1074 SetErrorCode(aFail->GetMessageString());
1081 //=============================================================================
1085 //=============================================================================
1086 void GEOMImpl_IMeasureOperations::GetBoundingBox
1087 (Handle(GEOM_Object) theShape,
1088 const Standard_Boolean precise,
1089 Standard_Real& Xmin, Standard_Real& Xmax,
1090 Standard_Real& Ymin, Standard_Real& Ymax,
1091 Standard_Real& Zmin, Standard_Real& Zmax)
1095 if (theShape.IsNull()) return;
1097 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1098 if (aRefShape.IsNull()) return;
1100 TopoDS_Shape aShape = aRefShape->GetValue();
1101 if (aShape.IsNull()) {
1102 SetErrorCode("The Objects has NULL Shape");
1106 //Compute the parameters
1111 BRepBuilderAPI_Copy aCopyTool (aShape);
1112 if (!aCopyTool.IsDone()) {
1113 SetErrorCode("GetBoundingBox Error: Bad shape detected");
1117 aShape = aCopyTool.Shape();
1119 // remove triangulation to obtain more exact boundaries
1120 BRepTools::Clean(aShape);
1122 BRepBndLib::Add(aShape, B);
1125 if (!GEOMUtils::PreciseBoundingBox(aShape, B)) {
1126 SetErrorCode("GetBoundingBox Error: Bounding box cannot be precised");
1131 B.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
1133 catch (Standard_Failure) {
1134 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1135 SetErrorCode(aFail->GetMessageString());
1142 //=============================================================================
1146 //=============================================================================
1147 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetBoundingBox
1148 (Handle(GEOM_Object) theShape,
1149 const Standard_Boolean precise)
1153 if (theShape.IsNull()) return NULL;
1155 //Add a new BoundingBox object
1156 Handle(GEOM_Object) aBnd = GetEngine()->AddObject(GetDocID(), GEOM_BOX);
1158 //Add a new BoundingBox function
1159 const int aType = (precise ? BND_BOX_MEASURE_PRECISE : BND_BOX_MEASURE);
1160 Handle(GEOM_Function) aFunction =
1161 aBnd->AddFunction(GEOMImpl_MeasureDriver::GetID(), aType);
1162 if (aFunction.IsNull()) return NULL;
1164 //Check if the function is set correctly
1165 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
1167 GEOMImpl_IMeasure aCI (aFunction);
1169 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1170 if (aRefShape.IsNull()) return NULL;
1172 aCI.SetBase(aRefShape);
1174 //Compute the BoundingBox value
1177 if (!GetSolver()->ComputeFunction(aFunction)) {
1178 SetErrorCode("Measure driver failed to compute a bounding box");
1182 catch (Standard_Failure) {
1183 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1184 SetErrorCode(aFail->GetMessageString());
1188 //Make a Python command
1189 GEOM::TPythonDump aPd(aFunction);
1191 aPd << aBnd << " = geompy.MakeBoundingBox(" << theShape;
1203 //=============================================================================
1207 //=============================================================================
1208 void GEOMImpl_IMeasureOperations::GetTolerance
1209 (Handle(GEOM_Object) theShape,
1210 Standard_Real& FaceMin, Standard_Real& FaceMax,
1211 Standard_Real& EdgeMin, Standard_Real& EdgeMax,
1212 Standard_Real& VertMin, Standard_Real& VertMax)
1216 if (theShape.IsNull()) return;
1218 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1219 if (aRefShape.IsNull()) return;
1221 TopoDS_Shape aShape = aRefShape->GetValue();
1222 if (aShape.IsNull()) {
1223 SetErrorCode("The Objects has NULL Shape");
1227 //Compute the parameters
1229 FaceMin = EdgeMin = VertMin = RealLast();
1230 FaceMax = EdgeMax = VertMax = -RealLast();
1234 for (TopExp_Explorer ExF (aShape, TopAbs_FACE); ExF.More(); ExF.Next()) {
1235 TopoDS_Face Face = TopoDS::Face(ExF.Current());
1236 T = BRep_Tool::Tolerance(Face);
1242 for (TopExp_Explorer ExE (aShape, TopAbs_EDGE); ExE.More(); ExE.Next()) {
1243 TopoDS_Edge Edge = TopoDS::Edge(ExE.Current());
1244 T = BRep_Tool::Tolerance(Edge);
1250 for (TopExp_Explorer ExV (aShape, TopAbs_VERTEX); ExV.More(); ExV.Next()) {
1251 TopoDS_Vertex Vertex = TopoDS::Vertex(ExV.Current());
1252 T = BRep_Tool::Tolerance(Vertex);
1259 catch (Standard_Failure) {
1260 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1261 SetErrorCode(aFail->GetMessageString());
1268 //=============================================================================
1272 //=============================================================================
1273 bool GEOMImpl_IMeasureOperations::CheckShape (Handle(GEOM_Object) theShape,
1274 const Standard_Boolean theIsCheckGeom,
1275 std::list<ShapeError> &theErrors)
1280 if (theShape.IsNull()) return false;
1282 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1283 if (aRefShape.IsNull()) return false;
1285 TopoDS_Shape aShape = aRefShape->GetValue();
1286 if (aShape.IsNull()) {
1287 SetErrorCode("The Objects has NULL Shape");
1291 //Compute the parameters
1292 bool isValid = false;
1295 BRepCheck_Analyzer ana (aShape, theIsCheckGeom);
1296 if (ana.IsValid()) {
1299 FillErrors(ana, aShape, theErrors);
1302 catch (Standard_Failure) {
1303 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1304 SetErrorCode(aFail->GetMessageString());
1312 //=============================================================================
1316 //=============================================================================
1317 TCollection_AsciiString GEOMImpl_IMeasureOperations::PrintShapeErrors
1318 (Handle(GEOM_Object) theShape,
1319 const std::list<ShapeError> &theErrors)
1321 TCollection_AsciiString aDump;
1323 if (theShape.IsNull()) {
1327 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1329 if (aRefShape.IsNull()) {
1333 TopoDS_Shape aShape = aRefShape->GetValue();
1335 if (aShape.IsNull()) {
1336 SetErrorCode("The Objects has NULL Shape");
1340 if (!theErrors.empty()) {
1341 // The shape is not valid. Prepare errors for dump.
1342 TopTools_IndexedMapOfShape anIndices;
1343 std::list<ShapeError>::const_iterator anIter = theErrors.begin();
1344 Standard_Integer nbv, nbe, nbw, nbf, nbs, nbo;
1345 nbv = nbe = nbw = nbf = nbs = nbo = 0;
1347 // Map sub-shapes and their indices
1348 TopExp::MapShapes(aShape, anIndices);
1350 const Standard_Integer aNbSubShapes = anIndices.Extent();
1351 TColStd_MapOfInteger aMapPbInd;
1353 aDump += " -- The Shape has problems :\n";
1354 aDump += " Check Count\n";
1355 aDump += " ------------------------------------------------\n";
1357 for (; anIter != theErrors.end(); anIter++) {
1358 Standard_Integer aNbShapes = anIter->incriminated.size();
1360 switch(anIter->error) {
1361 case BRepCheck_InvalidPointOnCurve:
1362 aDump += " Invalid Point on Curve ................... ";
1364 case BRepCheck_InvalidPointOnCurveOnSurface:
1365 aDump += " Invalid Point on CurveOnSurface .......... ";
1367 case BRepCheck_InvalidPointOnSurface:
1368 aDump += " Invalid Point on Surface ................. ";
1370 case BRepCheck_No3DCurve:
1371 aDump += " No 3D Curve .............................. ";
1373 case BRepCheck_Multiple3DCurve:
1374 aDump += " Multiple 3D Curve ........................ ";
1376 case BRepCheck_Invalid3DCurve:
1377 aDump += " Invalid 3D Curve ......................... ";
1379 case BRepCheck_NoCurveOnSurface:
1380 aDump += " No Curve on Surface ...................... ";
1382 case BRepCheck_InvalidCurveOnSurface:
1383 aDump += " Invalid Curve on Surface ................. ";
1385 case BRepCheck_InvalidCurveOnClosedSurface:
1386 aDump += " Invalid Curve on closed Surface .......... ";
1388 case BRepCheck_InvalidSameRangeFlag:
1389 aDump += " Invalid SameRange Flag ................... ";
1391 case BRepCheck_InvalidSameParameterFlag:
1392 aDump += " Invalid SameParameter Flag ............... ";
1394 case BRepCheck_InvalidDegeneratedFlag:
1395 aDump += " Invalid Degenerated Flag ................. ";
1397 case BRepCheck_FreeEdge:
1398 aDump += " Free Edge ................................ ";
1400 case BRepCheck_InvalidMultiConnexity:
1401 aDump += " Invalid MultiConnexity ................... ";
1403 case BRepCheck_InvalidRange:
1404 aDump += " Invalid Range ............................ ";
1406 case BRepCheck_EmptyWire:
1407 aDump += " Empty Wire ............................... ";
1409 case BRepCheck_RedundantEdge:
1410 aDump += " Redundant Edge ........................... ";
1412 case BRepCheck_SelfIntersectingWire:
1413 aDump += " Self Intersecting Wire ................... ";
1415 case BRepCheck_NoSurface:
1416 aDump += " No Surface ............................... ";
1418 case BRepCheck_InvalidWire:
1419 aDump += " Invalid Wire ............................. ";
1421 case BRepCheck_RedundantWire:
1422 aDump += " Redundant Wire ........................... ";
1424 case BRepCheck_IntersectingWires:
1425 aDump += " Intersecting Wires ....................... ";
1427 case BRepCheck_InvalidImbricationOfWires:
1428 aDump += " Invalid Imbrication of Wires ............. ";
1430 case BRepCheck_EmptyShell:
1431 aDump += " Empty Shell .............................. ";
1433 case BRepCheck_RedundantFace:
1434 aDump += " Redundant Face ........................... ";
1436 case BRepCheck_UnorientableShape:
1437 aDump += " Unorientable Shape ....................... ";
1439 case BRepCheck_NotClosed:
1440 aDump += " Not Closed ............................... ";
1442 case BRepCheck_NotConnected:
1443 aDump += " Not Connected ............................ ";
1445 case BRepCheck_SubshapeNotInShape:
1446 aDump += " Sub-shape not in Shape ................... ";
1448 case BRepCheck_BadOrientation:
1449 aDump += " Bad Orientation .......................... ";
1451 case BRepCheck_BadOrientationOfSubshape:
1452 aDump += " Bad Orientation of Sub-shape ............. ";
1454 case BRepCheck_InvalidToleranceValue:
1455 aDump += " Invalid Tolerance Value .................. ";
1457 case BRepCheck_CheckFail:
1458 aDump += " Check Shape Failure ...................... ";
1464 aDump += TCollection_AsciiString(aNbShapes) + "\n";
1466 // Count types of shape.
1467 std::list<int>::const_iterator aShIter = anIter->incriminated.begin();
1469 for (; aShIter != anIter->incriminated.end(); aShIter++) {
1470 const Standard_Integer anIndex = *aShIter;
1472 if (anIndex > 0 && anIndex <= aNbSubShapes && aMapPbInd.Add(anIndex)) {
1473 const TopoDS_Shape &aSubShape = anIndices.FindKey(anIndex);
1474 const TopAbs_ShapeEnum aType = aSubShape.ShapeType();
1477 case TopAbs_VERTEX : nbv++; break;
1478 case TopAbs_EDGE : nbe++; break;
1479 case TopAbs_WIRE : nbw++; break;
1480 case TopAbs_FACE : nbf++; break;
1481 case TopAbs_SHELL : nbs++; break;
1482 case TopAbs_SOLID : nbo++; break;
1489 const Standard_Integer aNbFaultyShapes = nbv + nbe + nbw + nbf + nbs + nbo;
1490 aDump += " ------------------------------------------------\n";
1491 aDump += "*** Shapes with problems : ";
1492 aDump += TCollection_AsciiString(aNbFaultyShapes) + "\n";
1495 aDump += "VERTEX : ";
1496 if (nbv < 10) aDump += " ";
1497 aDump += TCollection_AsciiString(nbv) + "\n";
1501 if (nbe < 10) aDump += " ";
1502 aDump += TCollection_AsciiString(nbe) + "\n";
1506 if (nbw < 10) aDump += " ";
1507 aDump += TCollection_AsciiString(nbw) + "\n";
1511 if (nbf < 10) aDump += " ";
1512 aDump += TCollection_AsciiString(nbf) + "\n";
1515 aDump += "SHELL : ";
1516 if (nbs < 10) aDump += " ";
1517 aDump += TCollection_AsciiString(nbs) + "\n";
1520 aDump += "SOLID : ";
1521 if (nbo < 10) aDump += " ";
1522 aDump += TCollection_AsciiString(nbo) + "\n";
1529 //=============================================================================
1531 * CheckSelfIntersections
1533 //=============================================================================
1534 bool GEOMImpl_IMeasureOperations::CheckSelfIntersections
1535 (Handle(GEOM_Object) theShape,
1536 const SICheckLevel theCheckLevel,
1537 Handle(TColStd_HSequenceOfInteger)& theIntersections)
1541 if (theIntersections.IsNull())
1542 theIntersections = new TColStd_HSequenceOfInteger;
1544 theIntersections->Clear();
1546 if (theShape.IsNull())
1549 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1550 if (aRefShape.IsNull()) return false;
1552 TopoDS_Shape aShape = aRefShape->GetValue();
1553 if (aShape.IsNull()) return false;
1556 TopoDS_Shape aScopy;
1558 GEOMAlgo_AlgoTools::CopyShape(aShape, aScopy);
1560 // Map sub-shapes and their indices
1561 TopTools_IndexedMapOfShape anIndices;
1562 TopExp::MapShapes(aScopy, anIndices);
1564 BOPCol_ListOfShape aLCS;
1565 aLCS.Append(aScopy);
1567 BOPAlgo_CheckerSI aCSI; // checker of self-interferences
1568 aCSI.SetArguments(aLCS);
1569 aCSI.SetLevelOfCheck(theCheckLevel);
1571 // 1. Launch the checker
1573 Standard_Boolean iErr = aCSI.HasErrors();
1576 Standard_Integer aNbS, n1, n2;
1577 BOPDS_MapIteratorOfMapOfPair aItMPK;
1579 // 2. Take the shapes from DS
1580 const BOPDS_DS& aDS = aCSI.DS();
1581 aNbS=aDS.NbShapes();
1583 // 3. Get the pairs of interfered shapes
1584 const BOPDS_MapOfPair& aMPK=aDS.Interferences();
1585 aItMPK.Initialize(aMPK);
1586 for (; aItMPK.More(); aItMPK.Next()) {
1587 const BOPDS_Pair& aPK=aItMPK.Value();
1588 aPK.Indices(n1, n2);
1590 if (n1 > aNbS || n2 > aNbS){
1591 return false; // Error
1593 const TopoDS_Shape& aS1 = aDS.Shape(n1);
1594 const TopoDS_Shape& aS2 = aDS.Shape(n2);
1596 theIntersections->Append(anIndices.FindIndex(aS1));
1597 theIntersections->Append(anIndices.FindIndex(aS2));
1604 return theIntersections->IsEmpty();
1607 //=============================================================================
1609 * CheckSelfIntersectionsFast
1611 //=============================================================================
1612 bool GEOMImpl_IMeasureOperations::CheckSelfIntersectionsFast
1613 (Handle(GEOM_Object) theShape,
1614 float theDeflection, double theTolerance,
1615 Handle(TColStd_HSequenceOfInteger)& theIntersections)
1619 if (theIntersections.IsNull())
1620 theIntersections = new TColStd_HSequenceOfInteger;
1622 theIntersections->Clear();
1624 if (theShape.IsNull())
1627 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1628 if (aRefShape.IsNull()) return false;
1630 TopoDS_Shape aShape = aRefShape->GetValue();
1631 if (aShape.IsNull()) return false;
1634 TopoDS_Shape aScopy;
1636 GEOMAlgo_AlgoTools::CopyShape(aShape, aScopy);
1637 GEOMUtils::MeshShape(aScopy, theDeflection);
1639 // Map sub-shapes and their indices
1640 TopTools_IndexedMapOfShape anIndices;
1641 TopExp::MapShapes(aScopy, anIndices);
1643 // Checker of fast interferences
1644 BRepExtrema_SelfIntersection aTool(aScopy, (theTolerance <= 0.) ? 0.0 : theTolerance);
1646 // Launch the checker
1649 const BRepExtrema_MapOfIntegerPackedMapOfInteger& intersections = aTool.OverlapElements();
1651 std::set<Standard_Integer> processed;
1653 for (BRepExtrema_MapOfIntegerPackedMapOfInteger::Iterator it(intersections); it.More(); it.Next()) {
1654 Standard_Integer idxLeft = it.Key();
1655 if (processed.count(idxLeft) > 0) continue; // already added
1656 processed.insert(idxLeft);
1657 const TColStd_PackedMapOfInteger& overlaps = it.Value();
1658 for (TColStd_MapIteratorOfPackedMapOfInteger subit(overlaps); subit.More(); subit.Next()) {
1659 Standard_Integer idxRight = subit.Key();
1660 if (processed.count(idxRight) > 0) continue; // already added
1661 const TopoDS_Shape& aS1 = aTool.GetSubShape(idxLeft);
1662 const TopoDS_Shape& aS2 = aTool.GetSubShape(idxRight);
1663 theIntersections->Append(anIndices.FindIndex(aS1));
1664 theIntersections->Append(anIndices.FindIndex(aS2));
1671 return theIntersections->IsEmpty();
1674 //=============================================================================
1678 //=============================================================================
1679 bool GEOMImpl_IMeasureOperations::CheckBOPArguments
1680 (const Handle(GEOM_Object) &theShape)
1684 if (theShape.IsNull()) {
1688 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1690 if (aRefShape.IsNull()) {
1694 TopoDS_Shape aShape = aRefShape->GetValue();
1696 if (aShape.IsNull()) {
1700 //Compute the parameters
1701 bool isValid = GEOMUtils::CheckBOPArguments(aShape);
1708 //=============================================================================
1712 //=============================================================================
1713 bool GEOMImpl_IMeasureOperations::FastIntersect (Handle(GEOM_Object) theShape1, Handle(GEOM_Object) theShape2,
1714 double theTolerance, float theDeflection,
1715 Handle(TColStd_HSequenceOfInteger)& theIntersections1,
1716 Handle(TColStd_HSequenceOfInteger)& theIntersections2)
1719 bool isGood = false;
1721 if (theIntersections1.IsNull())
1722 theIntersections1 = new TColStd_HSequenceOfInteger;
1724 theIntersections1->Clear();
1726 if (theIntersections2.IsNull())
1727 theIntersections2 = new TColStd_HSequenceOfInteger;
1729 theIntersections2->Clear();
1731 if (theShape1.IsNull() || theShape2.IsNull()) {
1732 SetErrorCode("Objects have NULL Shape");
1736 if (theShape1 == theShape2) {
1737 SetErrorCode("Objects are equal");
1740 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
1741 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
1742 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return isGood;
1744 TopoDS_Shape aShape1 = aRefShape1->GetValue();
1745 TopoDS_Shape aShape2 = aRefShape2->GetValue();
1746 if (aShape1.IsNull() || aShape2.IsNull()) return isGood;
1749 TopoDS_Shape aScopy1, aScopy2;
1750 GEOMAlgo_AlgoTools::CopyShape(aShape1, aScopy1);
1751 GEOMAlgo_AlgoTools::CopyShape(aShape2, aScopy2);
1753 GEOMUtils::MeshShape(aScopy1, theDeflection);
1754 GEOMUtils::MeshShape(aScopy2, theDeflection);
1756 // Map sub-shapes and their indices
1757 TopTools_IndexedMapOfShape anIndices1, anIndices2;
1758 TopExp::MapShapes(aScopy1, anIndices1);
1759 TopExp::MapShapes(aScopy2, anIndices2);
1761 BOPCol_ListOfShape aLCS1, aLCS2;
1762 aLCS1.Append(aScopy1); aLCS2.Append(aScopy2);
1764 BRepExtrema_ShapeProximity aBSP; // checker of fast interferences
1765 aBSP.LoadShape1(aScopy1); aBSP.LoadShape2(aScopy2);
1766 aBSP.SetTolerance((theTolerance <= 0.) ? 0.0 : theTolerance);
1768 // 1. Launch the checker
1771 // 2. Get sets of IDs of overlapped faces
1772 for (BRepExtrema_MapOfIntegerPackedMapOfInteger::Iterator anIt1 (aBSP.OverlapSubShapes1()); anIt1.More(); anIt1.Next())
1774 const TopoDS_Shape& aS1 = aBSP.GetSubShape1(anIt1.Key());
1775 theIntersections1->Append(anIndices1.FindIndex(aS1));
1778 for (BRepExtrema_MapOfIntegerPackedMapOfInteger::Iterator anIt2 (aBSP.OverlapSubShapes2()); anIt2.More(); anIt2.Next())
1780 const TopoDS_Shape& aS2 = aBSP.GetSubShape2(anIt2.Key());
1781 theIntersections2->Append(anIndices2.FindIndex(aS2));
1784 isGood = !theIntersections1->IsEmpty() && !theIntersections1->IsEmpty();
1792 //=============================================================================
1796 //=============================================================================
1797 TCollection_AsciiString GEOMImpl_IMeasureOperations::IsGoodForSolid (Handle(GEOM_Object) theShape)
1801 TCollection_AsciiString aRes = "";
1803 if (theShape.IsNull()) {
1804 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1807 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1808 if (aRefShape.IsNull()) {
1809 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1812 TopoDS_Shape aShape = aRefShape->GetValue();
1813 if (aShape.IsNull()) {
1814 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1817 if (aShape.ShapeType() == TopAbs_COMPOUND) {
1818 TopoDS_Iterator It (aShape, Standard_True, Standard_True);
1819 if (It.More()) aShape = It.Value();
1821 if (aShape.ShapeType() == TopAbs_SHELL) {
1822 BRepCheck_Shell chkShell (TopoDS::Shell(aShape));
1823 if (chkShell.Closed() == BRepCheck_NotClosed) {
1824 aRes = "WRN_SHAPE_UNCLOSED";
1828 aRes = "WRN_SHAPE_NOT_SHELL";
1840 //=============================================================================
1844 //=============================================================================
1845 TCollection_AsciiString GEOMImpl_IMeasureOperations::WhatIs (Handle(GEOM_Object) theShape)
1849 TCollection_AsciiString Astr;
1851 if (theShape.IsNull()) return Astr;
1853 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1854 if (aRefShape.IsNull()) return Astr;
1856 TopoDS_Shape aShape = aRefShape->GetValue();
1857 if (aShape.IsNull()) {
1858 SetErrorCode("The Objects has NULL Shape");
1862 //Compute the parameters
1863 if (aShape.ShapeType() == TopAbs_EDGE) {
1864 if (BRep_Tool::Degenerated(TopoDS::Edge(aShape))) {
1865 Astr = Astr + " It is a degenerated edge \n";
1869 Astr = Astr + " Number of sub-shapes : \n";
1873 int iType, nbTypes [TopAbs_SHAPE], nbFlatType [TopAbs_SHAPE];
1874 for (iType = 0; iType < TopAbs_SHAPE; ++iType) {
1876 nbFlatType[iType] = 0;
1878 nbTypes[aShape.ShapeType()]++;
1880 TopTools_MapOfShape aMapOfShape;
1881 aMapOfShape.Add(aShape);
1882 TopTools_ListOfShape aListOfShape;
1883 aListOfShape.Append(aShape);
1885 TopTools_ListIteratorOfListOfShape itL (aListOfShape);
1886 for (; itL.More(); itL.Next()) {
1887 TopoDS_Shape sp = itL.Value();
1888 TopoDS_Iterator it (sp);
1889 for (; it.More(); it.Next()) {
1890 TopoDS_Shape s = it.Value();
1891 if (aMapOfShape.Add(s)) {
1892 aListOfShape.Append(s);
1893 nbTypes[s.ShapeType()]++;
1894 if ((sp.ShapeType() == TopAbs_COMPOUND) || (sp.ShapeType() == TopAbs_COMPSOLID)) {
1895 nbFlatType[s.ShapeType()]++;
1901 Astr = Astr + " VERTEX : " + TCollection_AsciiString(nbTypes[TopAbs_VERTEX]) + "\n";
1902 Astr = Astr + " EDGE : " + TCollection_AsciiString(nbTypes[TopAbs_EDGE]) + "\n";
1903 Astr = Astr + " WIRE : " + TCollection_AsciiString(nbTypes[TopAbs_WIRE]) + "\n";
1904 Astr = Astr + " FACE : " + TCollection_AsciiString(nbTypes[TopAbs_FACE]) + "\n";
1905 Astr = Astr + " SHELL : " + TCollection_AsciiString(nbTypes[TopAbs_SHELL]) + "\n";
1906 Astr = Astr + " SOLID : " + TCollection_AsciiString(nbTypes[TopAbs_SOLID]) + "\n";
1907 Astr = Astr + " COMPSOLID : " + TCollection_AsciiString(nbTypes[TopAbs_COMPSOLID]) + "\n";
1908 Astr = Astr + " COMPOUND : " + TCollection_AsciiString(nbTypes[TopAbs_COMPOUND]) + "\n";
1909 Astr = Astr + " SHAPE : " + TCollection_AsciiString(aMapOfShape.Extent()) + "\n";
1911 if ((aShape.ShapeType() == TopAbs_COMPOUND) || (aShape.ShapeType() == TopAbs_COMPSOLID)){
1912 Astr = Astr + " --------------------- \n Flat content : \n";
1913 if (nbFlatType[TopAbs_VERTEX] > 0)
1914 Astr = Astr + " VERTEX : " + TCollection_AsciiString(nbFlatType[TopAbs_VERTEX]) + "\n";
1915 if (nbFlatType[TopAbs_EDGE] > 0)
1916 Astr = Astr + " EDGE : " + TCollection_AsciiString(nbFlatType[TopAbs_EDGE]) + "\n";
1917 if (nbFlatType[TopAbs_WIRE] > 0)
1918 Astr = Astr + " WIRE : " + TCollection_AsciiString(nbFlatType[TopAbs_WIRE]) + "\n";
1919 if (nbFlatType[TopAbs_FACE] > 0)
1920 Astr = Astr + " FACE : " + TCollection_AsciiString(nbFlatType[TopAbs_FACE]) + "\n";
1921 if (nbFlatType[TopAbs_SHELL] > 0)
1922 Astr = Astr + " SHELL : " + TCollection_AsciiString(nbFlatType[TopAbs_SHELL]) + "\n";
1923 if (nbFlatType[TopAbs_SOLID] > 0)
1924 Astr = Astr + " SOLID : " + TCollection_AsciiString(nbFlatType[TopAbs_SOLID]) + "\n";
1927 catch (Standard_Failure) {
1928 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1929 SetErrorCode(aFail->GetMessageString());
1937 //=============================================================================
1941 //=============================================================================
1943 GEOMImpl_IMeasureOperations::AreCoordsInside(Handle(GEOM_Object) theShape,
1944 const std::vector<double>& coords,
1947 std::vector<bool> isInsideRes;
1948 if (!theShape.IsNull()) {
1949 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1950 if (!aRefShape.IsNull()) {
1951 TopoDS_Shape aShape = aRefShape->GetValue();
1952 if (!aShape.IsNull())
1954 TopTools_IndexedMapOfShape mapShape;
1956 TopExp_Explorer anExp;
1957 for ( anExp.Init( aShape, TopAbs_SOLID ); anExp.More(); anExp.Next() )
1958 mapShape.Add( anExp.Current() );
1959 for ( anExp.Init( aShape, TopAbs_FACE, TopAbs_SOLID ); anExp.More(); anExp.Next() )
1960 mapShape.Add( anExp.Current() );
1961 for ( anExp.Init( aShape, TopAbs_EDGE, TopAbs_FACE ); anExp.More(); anExp.Next() )
1962 mapShape.Add( anExp.Current() );
1963 for ( anExp.Init( aShape, TopAbs_VERTEX, TopAbs_EDGE ); anExp.More(); anExp.Next() )
1964 mapShape.Add( anExp.Current() ); //// ?????????
1966 size_t nb_points = coords.size()/3, nb_points_inside = 0;
1967 isInsideRes.resize( nb_points, false );
1969 for ( int iS = 1; iS <= mapShape.Extent(); ++iS )
1971 if ( nb_points_inside == nb_points )
1973 aShape = mapShape( iS );
1974 switch ( aShape.ShapeType() ) {
1977 BRepClass3d_SolidClassifier SC( TopoDS::Solid( aShape ));
1978 for ( size_t i = 0; i < nb_points; i++)
1980 if ( isInsideRes[ i ]) continue;
1981 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
1982 SC.Perform( aPnt, tolerance );
1983 isInsideRes[ i ] = (( SC.State() == TopAbs_IN ) || ( SC.State() == TopAbs_ON ));
1984 nb_points_inside += isInsideRes[ i ];
1990 Standard_Real u1,u2,v1,v2;
1991 const TopoDS_Face& face = TopoDS::Face( aShape );
1992 Handle(Geom_Surface) surf = BRep_Tool::Surface( face );
1993 surf->Bounds( u1,u2,v1,v2 );
1994 GeomAPI_ProjectPointOnSurf project;
1995 project.Init(surf, u1,u2, v1,v2, tolerance );
1996 for ( size_t i = 0; i < nb_points; i++)
1998 if ( isInsideRes[ i ]) continue;
1999 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
2000 project.Perform( aPnt );
2001 if ( project.IsDone() &&
2002 project.NbPoints() > 0 &&
2003 project.LowerDistance() <= tolerance )
2006 project.LowerDistanceParameters(u, v);
2007 gp_Pnt2d uv( u, v );
2008 BRepClass_FaceClassifier FC ( face, uv, tolerance );
2009 isInsideRes[ i ] = (( FC.State() == TopAbs_IN ) || ( FC.State() == TopAbs_ON ));
2010 nb_points_inside += isInsideRes[ i ];
2018 const TopoDS_Edge& edge = TopoDS::Edge( aShape );
2019 Handle(Geom_Curve) curve = BRep_Tool::Curve( edge, f, l );
2020 GeomAPI_ProjectPointOnCurve project;
2021 project.Init( curve, f, l );
2022 for ( size_t i = 0; i < nb_points; i++)
2024 if ( isInsideRes[ i ]) continue;
2025 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
2026 project.Perform( aPnt );
2027 isInsideRes[ i ] = ( project.NbPoints() > 0 &&
2028 project.LowerDistance() <= tolerance );
2029 nb_points_inside += isInsideRes[ i ];
2035 gp_Pnt aVPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ));
2036 for ( size_t i = 0; i < nb_points; i++)
2038 if ( isInsideRes[ i ]) continue;
2039 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
2040 isInsideRes[ i ] = ( aPnt.SquareDistance( aVPnt ) <= tolerance * tolerance );
2041 nb_points_inside += isInsideRes[ i ];
2046 } // switch ( aShape.ShapeType() )
2054 //=============================================================================
2058 //=============================================================================
2060 GEOMImpl_IMeasureOperations::GetMinDistance (Handle(GEOM_Object) theShape1,
2061 Handle(GEOM_Object) theShape2,
2070 Standard_Real MinDist = 1.e9;
2072 if (theShape1.IsNull() || theShape2.IsNull()) return MinDist;
2074 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
2075 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
2076 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return MinDist;
2078 TopoDS_Shape aShape1 = aRefShape1->GetValue();
2079 TopoDS_Shape aShape2 = aRefShape2->GetValue();
2080 if (aShape1.IsNull() || aShape2.IsNull()) {
2081 SetErrorCode("One of Objects has NULL Shape");
2085 //Compute the parameters
2089 gp_Pnt aPnt1, aPnt2;
2091 MinDist = GEOMUtils::GetMinDistance(aShape1, aShape2, aPnt1, aPnt2);
2093 if (MinDist >= 0.0) {
2094 aPnt1.Coord(X1, Y1, Z1);
2095 aPnt2.Coord(X2, Y2, Z2);
2100 catch (Standard_Failure) {
2101 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2102 SetErrorCode(aFail->GetMessageString());
2110 //=======================================================================
2112 * Get coordinates of closest points of two shapes
2114 //=======================================================================
2115 Standard_Integer GEOMImpl_IMeasureOperations::ClosestPoints (Handle(GEOM_Object) theShape1,
2116 Handle(GEOM_Object) theShape2,
2117 Handle(TColStd_HSequenceOfReal)& theDoubles)
2120 Standard_Integer nbSolutions = 0;
2122 if (theShape1.IsNull() || theShape2.IsNull()) return nbSolutions;
2124 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
2125 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
2126 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return nbSolutions;
2128 TopoDS_Shape aShape1 = aRefShape1->GetValue();
2129 TopoDS_Shape aShape2 = aRefShape2->GetValue();
2130 if (aShape1.IsNull() || aShape2.IsNull()) {
2131 SetErrorCode("One of Objects has NULL Shape");
2135 // Compute the extremities
2140 // additional workaround for bugs 19899, 19908 and 19910 from Mantis
2142 double dist = GEOMUtils::GetMinDistanceSingular(aShape1, aShape2, P1, P2);
2146 theDoubles->Append(P1.X());
2147 theDoubles->Append(P1.Y());
2148 theDoubles->Append(P1.Z());
2149 theDoubles->Append(P2.X());
2150 theDoubles->Append(P2.Y());
2151 theDoubles->Append(P2.Z());
2157 BRepExtrema_DistShapeShape dst (aShape1, aShape2);
2159 nbSolutions = dst.NbSolution();
2160 if (theDoubles.IsNull()) theDoubles = new TColStd_HSequenceOfReal;
2163 for (int i = 1; i <= nbSolutions; i++) {
2164 P1 = dst.PointOnShape1(i);
2165 P2 = dst.PointOnShape2(i);
2167 theDoubles->Append(P1.X());
2168 theDoubles->Append(P1.Y());
2169 theDoubles->Append(P1.Z());
2170 theDoubles->Append(P2.X());
2171 theDoubles->Append(P2.Y());
2172 theDoubles->Append(P2.Z());
2176 catch (Standard_Failure) {
2177 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2178 SetErrorCode(aFail->GetMessageString());
2186 //=======================================================================
2188 * Get coordinates of point
2190 //=======================================================================
2191 void GEOMImpl_IMeasureOperations::PointCoordinates (Handle(GEOM_Object) theShape,
2192 Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ)
2196 if (theShape.IsNull())
2199 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
2200 if (aRefShape.IsNull())
2203 TopoDS_Shape aShape = aRefShape->GetValue();
2204 if (aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX)
2206 SetErrorCode( "Shape must be a vertex" );
2212 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
2219 catch (Standard_Failure)
2221 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2222 SetErrorCode( aFail->GetMessageString() );
2226 //=======================================================================
2228 * Compute angle (in degrees) between two lines
2230 //=======================================================================
2231 Standard_Real GEOMImpl_IMeasureOperations::GetAngle (Handle(GEOM_Object) theLine1,
2232 Handle(GEOM_Object) theLine2)
2234 if (theLine1->GetType() == GEOM_VECTOR &&
2235 theLine2->GetType() == GEOM_VECTOR)
2236 return GetAngleBtwVectors(theLine1, theLine2);
2240 Standard_Real anAngle = -1.0;
2242 if (theLine1.IsNull() || theLine2.IsNull())
2245 Handle(GEOM_Function) aRefLine1 = theLine1->GetLastFunction();
2246 Handle(GEOM_Function) aRefLine2 = theLine2->GetLastFunction();
2247 if (aRefLine1.IsNull() || aRefLine2.IsNull())
2250 TopoDS_Shape aLine1 = aRefLine1->GetValue();
2251 TopoDS_Shape aLine2 = aRefLine2->GetValue();
2252 if (aLine1.IsNull() || aLine2.IsNull() ||
2253 aLine1.ShapeType() != TopAbs_EDGE ||
2254 aLine2.ShapeType() != TopAbs_EDGE)
2256 SetErrorCode("Two edges must be given");
2262 TopoDS_Edge E1 = TopoDS::Edge(aLine1);
2263 TopoDS_Edge E2 = TopoDS::Edge(aLine2);
2266 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp,lp);
2267 Handle(Geom_Curve) C2 = BRep_Tool::Curve(E2,fp,lp);
2269 if ( C1.IsNull() || C2.IsNull() ||
2270 !C1->IsKind(STANDARD_TYPE(Geom_Line)) ||
2271 !C2->IsKind(STANDARD_TYPE(Geom_Line)))
2273 SetErrorCode("The edges must be linear");
2277 Handle(Geom_Line) L1 = Handle(Geom_Line)::DownCast(C1);
2278 Handle(Geom_Line) L2 = Handle(Geom_Line)::DownCast(C2);
2280 gp_Lin aLin1 = L1->Lin();
2281 gp_Lin aLin2 = L2->Lin();
2283 anAngle = aLin1.Angle(aLin2);
2284 anAngle *= 180. / M_PI; // convert radians into degrees
2286 if (anAngle > 90.0) {
2287 anAngle = 180.0 - anAngle;
2292 catch (Standard_Failure)
2294 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2295 SetErrorCode(aFail->GetMessageString());
2301 //=======================================================================
2303 * Compute angle (in degrees) between two vectors
2305 //=======================================================================
2306 Standard_Real GEOMImpl_IMeasureOperations::GetAngleBtwVectors (Handle(GEOM_Object) theVec1,
2307 Handle(GEOM_Object) theVec2)
2311 Standard_Real anAngle = -1.0;
2313 if (theVec1.IsNull() || theVec2.IsNull())
2316 if (theVec1->GetType() != GEOM_VECTOR || theVec2->GetType() != GEOM_VECTOR) {
2317 SetErrorCode("Two vectors must be given");
2321 Handle(GEOM_Function) aRefVec1 = theVec1->GetLastFunction();
2322 Handle(GEOM_Function) aRefVec2 = theVec2->GetLastFunction();
2323 if (aRefVec1.IsNull() || aRefVec2.IsNull())
2326 TopoDS_Shape aVec1 = aRefVec1->GetValue();
2327 TopoDS_Shape aVec2 = aRefVec2->GetValue();
2328 if (aVec1.IsNull() || aVec2.IsNull() ||
2329 aVec1.ShapeType() != TopAbs_EDGE ||
2330 aVec2.ShapeType() != TopAbs_EDGE)
2332 SetErrorCode("Two edges must be given");
2338 TopoDS_Edge aE1 = TopoDS::Edge(aVec1);
2339 TopoDS_Edge aE2 = TopoDS::Edge(aVec2);
2341 TopoDS_Vertex aP11, aP12, aP21, aP22;
2342 TopExp::Vertices(aE1, aP11, aP12, Standard_True);
2343 TopExp::Vertices(aE2, aP21, aP22, Standard_True);
2344 if (aP11.IsNull() || aP12.IsNull() || aP21.IsNull() || aP22.IsNull()) {
2345 SetErrorCode("Bad edge given");
2349 gp_Vec aV1 (BRep_Tool::Pnt(aP11), BRep_Tool::Pnt(aP12));
2350 gp_Vec aV2 (BRep_Tool::Pnt(aP21), BRep_Tool::Pnt(aP22)) ;
2352 anAngle = aV1.Angle(aV2);
2353 anAngle *= 180. / M_PI; // convert radians into degrees
2357 catch (Standard_Failure)
2359 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2360 SetErrorCode(aFail->GetMessageString());
2367 //=============================================================================
2369 * CurveCurvatureByParam
2371 //=============================================================================
2372 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByParam
2373 (Handle(GEOM_Object) theCurve, Standard_Real& theParam)
2376 Standard_Real aRes = -1.0;
2378 if(theCurve.IsNull()) return aRes;
2380 Handle(GEOM_Function) aRefShape = theCurve->GetLastFunction();
2381 if(aRefShape.IsNull()) return aRes;
2383 TopoDS_Shape aShape = aRefShape->GetValue();
2384 if(aShape.IsNull()) {
2385 SetErrorCode("One of Objects has NULL Shape");
2389 Standard_Real aFP, aLP, aP;
2390 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aFP, aLP);
2391 aP = aFP + (aLP - aFP) * theParam;
2393 if(aCurve.IsNull()) return aRes;
2398 GeomLProp_CLProps Prop = GeomLProp_CLProps
2399 (aCurve, aP, 2, Precision::Confusion());
2400 aRes = fabs(Prop.Curvature());
2403 catch (Standard_Failure) {
2404 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2405 SetErrorCode(aFail->GetMessageString());
2409 if( aRes > Precision::Confusion() )
2418 //=============================================================================
2420 * CurveCurvatureByPoint
2422 //=============================================================================
2423 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByPoint
2424 (Handle(GEOM_Object) theCurve, Handle(GEOM_Object) thePoint)
2427 Standard_Real aRes = -1.0;
2429 if( theCurve.IsNull() || thePoint.IsNull() ) return aRes;
2431 Handle(GEOM_Function) aRefCurve = theCurve->GetLastFunction();
2432 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2433 if( aRefCurve.IsNull() || aRefPoint.IsNull() ) return aRes;
2435 TopoDS_Edge anEdge = TopoDS::Edge(aRefCurve->GetValue());
2436 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2437 if( anEdge.IsNull() || aPnt.IsNull() ) {
2438 SetErrorCode("One of Objects has NULL Shape");
2442 Standard_Real aFP, aLP;
2443 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFP, aLP);
2444 if(aCurve.IsNull()) return aRes;
2445 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2450 GeomAPI_ProjectPointOnCurve PPCurve(aPoint, aCurve, aFP, aLP);
2451 if(PPCurve.NbPoints()>0) {
2452 GeomLProp_CLProps Prop = GeomLProp_CLProps
2453 (aCurve, PPCurve.LowerDistanceParameter(), 2, Precision::Confusion());
2454 aRes = fabs(Prop.Curvature());
2458 catch (Standard_Failure) {
2459 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2460 SetErrorCode(aFail->GetMessageString());
2464 if( aRes > Precision::Confusion() )
2473 //=============================================================================
2475 * getSurfaceCurvatures
2477 //=============================================================================
2478 Standard_Real GEOMImpl_IMeasureOperations::getSurfaceCurvatures
2479 (const Handle(Geom_Surface)& aSurf,
2480 Standard_Real theUParam,
2481 Standard_Real theVParam,
2482 Standard_Boolean theNeedMaxCurv)
2485 Standard_Real aRes = 1.0;
2487 if (aSurf.IsNull()) return aRes;
2491 GeomLProp_SLProps Prop = GeomLProp_SLProps
2492 (aSurf, theUParam, theVParam, 2, Precision::Confusion());
2493 if(Prop.IsCurvatureDefined()) {
2494 if(Prop.IsUmbilic()) {
2495 //cout<<"is umbilic"<<endl;
2496 aRes = fabs(Prop.MeanCurvature());
2499 //cout<<"is not umbilic"<<endl;
2500 double c1 = fabs(Prop.MaxCurvature());
2501 double c2 = fabs(Prop.MinCurvature());
2510 catch (Standard_Failure) {
2511 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2512 SetErrorCode(aFail->GetMessageString());
2516 if( fabs(aRes) > Precision::Confusion() )
2525 //=============================================================================
2527 * MaxSurfaceCurvatureByParam
2529 //=============================================================================
2530 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByParam
2531 (Handle(GEOM_Object) theSurf,
2532 Standard_Real& theUParam,
2533 Standard_Real& theVParam)
2536 Standard_Real aRes = -1.0;
2538 if (theSurf.IsNull()) return aRes;
2540 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2541 if(aRefShape.IsNull()) return aRes;
2543 TopoDS_Shape aShape = aRefShape->GetValue();
2544 if(aShape.IsNull()) {
2545 SetErrorCode("One of Objects has NULL Shape");
2549 TopoDS_Face F = TopoDS::Face(aShape);
2550 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2552 //Compute the parameters
2553 Standard_Real U1,U2,V1,V2;
2554 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2555 Standard_Real U = U1 + (U2-U1)*theUParam;
2556 Standard_Real V = V1 + (V2-V1)*theVParam;
2558 return getSurfaceCurvatures(aSurf, U, V, true);
2562 //=============================================================================
2564 * MaxSurfaceCurvatureByPoint
2566 //=============================================================================
2567 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByPoint
2568 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2571 Standard_Real aRes = -1.0;
2573 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2575 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2576 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2577 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2579 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2580 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2581 if( aFace.IsNull() || aPnt.IsNull() ) {
2582 SetErrorCode("One of Objects has NULL Shape");
2586 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2587 if(aSurf.IsNull()) return aRes;
2588 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2590 //Compute the parameters
2591 ShapeAnalysis_Surface sas(aSurf);
2592 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2594 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), true);
2598 //=============================================================================
2600 * MinSurfaceCurvatureByParam
2602 //=============================================================================
2603 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByParam
2604 (Handle(GEOM_Object) theSurf,
2605 Standard_Real& theUParam,
2606 Standard_Real& theVParam)
2609 Standard_Real aRes = -1.0;
2611 if (theSurf.IsNull()) return aRes;
2613 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2614 if(aRefShape.IsNull()) return aRes;
2616 TopoDS_Shape aShape = aRefShape->GetValue();
2617 if(aShape.IsNull()) {
2618 SetErrorCode("One of Objects has NULL Shape");
2622 TopoDS_Face F = TopoDS::Face(aShape);
2623 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2625 //Compute the parameters
2626 Standard_Real U1,U2,V1,V2;
2627 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2628 Standard_Real U = U1 + (U2-U1)*theUParam;
2629 Standard_Real V = V1 + (V2-V1)*theVParam;
2631 return getSurfaceCurvatures(aSurf, U, V, false);
2635 //=============================================================================
2637 * MinSurfaceCurvatureByPoint
2639 //=============================================================================
2640 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByPoint
2641 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2644 Standard_Real aRes = -1.0;
2646 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2648 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2649 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2650 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2652 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2653 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2654 if( aFace.IsNull() || aPnt.IsNull() ) {
2655 SetErrorCode("One of Objects has NULL Shape");
2659 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2660 if(aSurf.IsNull()) return aRes;
2661 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2663 //Compute the parameters
2664 ShapeAnalysis_Surface sas(aSurf);
2665 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2667 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), false);
2670 //=======================================================================
2671 //function : FillErrorsSub
2672 //purpose : Fill the errors list of subshapes on shape.
2673 //=======================================================================
2674 void GEOMImpl_IMeasureOperations::FillErrorsSub
2675 (const BRepCheck_Analyzer &theAna,
2676 const TopoDS_Shape &theShape,
2677 const TopAbs_ShapeEnum theSubType,
2678 TopTools_DataMapOfIntegerListOfShape &theMapErrors) const
2680 TopExp_Explorer anExp(theShape, theSubType);
2681 TopTools_MapOfShape aMapSubShapes;
2683 for (; anExp.More(); anExp.Next()) {
2684 const TopoDS_Shape &aSubShape = anExp.Current();
2686 if (aMapSubShapes.Add(aSubShape)) {
2687 const Handle(BRepCheck_Result) &aRes = theAna.Result(aSubShape);
2689 for (aRes->InitContextIterator();
2690 aRes->MoreShapeInContext();
2691 aRes->NextShapeInContext()) {
2692 if (aRes->ContextualShape().IsSame(theShape)) {
2693 BRepCheck_ListIteratorOfListOfStatus itl(aRes->StatusOnShape());
2695 if (itl.Value() != BRepCheck_NoError) {
2696 // Add all errors for theShape and its sub-shape.
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 TopTools_ListOfShape &theShapes = theMapErrors.ChangeFind(aStat);
2708 theShapes.Append(aSubShape);
2709 theShapes.Append(theShape);
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 TopTools_DataMapOfIntegerListOfShape &theMapErrors,
2728 TopTools_MapOfShape &theMapShapes) const
2730 if (theMapShapes.Add(theShape)) {
2731 // Fill errors of child shapes.
2732 for (TopoDS_Iterator iter(theShape); iter.More(); iter.Next()) {
2733 FillErrors(theAna, iter.Value(), theMapErrors, theMapShapes);
2736 // Fill errors of theShape.
2737 const Handle(BRepCheck_Result) &aRes = theAna.Result(theShape);
2739 if (!aRes.IsNull()) {
2740 BRepCheck_ListIteratorOfListOfStatus itl(aRes->Status());
2742 if (itl.Value() != BRepCheck_NoError) {
2743 // Add all errors for theShape.
2744 for (;itl.More(); itl.Next()) {
2745 const Standard_Integer aStat = (Standard_Integer)itl.Value();
2747 if (!theMapErrors.IsBound(aStat)) {
2748 TopTools_ListOfShape anEmpty;
2750 theMapErrors.Bind(aStat, anEmpty);
2753 theMapErrors.ChangeFind(aStat).Append(theShape);
2758 // Add errors of subshapes on theShape.
2759 const TopAbs_ShapeEnum aType = theShape.ShapeType();
2763 FillErrorsSub(theAna, theShape, TopAbs_VERTEX, theMapErrors);
2766 FillErrorsSub(theAna, theShape, TopAbs_WIRE, theMapErrors);
2767 FillErrorsSub(theAna, theShape, TopAbs_EDGE, theMapErrors);
2768 FillErrorsSub(theAna, theShape, TopAbs_VERTEX, theMapErrors);
2771 FillErrorsSub(theAna, theShape, TopAbs_SHELL, theMapErrors);
2779 //=======================================================================
2780 //function : FillErrors
2781 //purpose : Fill the errors list.
2782 //=======================================================================
2783 void GEOMImpl_IMeasureOperations::FillErrors
2784 (const BRepCheck_Analyzer &theAna,
2785 const TopoDS_Shape &theShape,
2786 std::list<ShapeError> &theErrors) const
2788 // Fill the errors map.
2789 TopTools_DataMapOfIntegerListOfShape aMapErrors;
2790 TopTools_MapOfShape aMapShapes;
2792 FillErrors(theAna, theShape, aMapErrors, aMapShapes);
2794 // Map sub-shapes and their indices
2795 TopTools_IndexedMapOfShape anIndices;
2797 TopExp::MapShapes(theShape, anIndices);
2799 TopTools_DataMapIteratorOfDataMapOfIntegerListOfShape aMapIter(aMapErrors);
2801 for (; aMapIter.More(); aMapIter.Next()) {
2804 anError.error = (BRepCheck_Status)aMapIter.Key();
2806 TopTools_ListIteratorOfListOfShape aListIter(aMapIter.Value());
2807 TopTools_MapOfShape aMapUnique;
2809 for (; aListIter.More(); aListIter.Next()) {
2810 const TopoDS_Shape &aShape = aListIter.Value();
2812 if (aMapUnique.Add(aShape)) {
2813 const Standard_Integer anIndex = anIndices.FindIndex(aShape);
2815 anError.incriminated.push_back(anIndex);
2819 if (!anError.incriminated.empty()) {
2820 theErrors.push_back(anError);