1 // Copyright (C) 2007-2014 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 <BRep_Builder.hxx>
45 #include <BRepBndLib.hxx>
46 #include <BRepBuilderAPI_Copy.hxx>
47 #include <BRepCheck_ListIteratorOfListOfStatus.hxx>
48 #include <BRepCheck_Shell.hxx>
49 #include <BRepClass3d_SolidClassifier.hxx>
50 #include <BRepClass_FaceClassifier.hxx>
51 #include <BRepExtrema_DistShapeShape.hxx>
52 #include <BRepGProp.hxx>
53 #include <BRepTools.hxx>
54 #include <BRep_Tool.hxx>
55 #include <Geom_Line.hxx>
56 #include <GeomAPI_ProjectPointOnCurve.hxx>
57 #include <GeomAPI_ProjectPointOnSurf.hxx>
58 #include <GeomLProp_CLProps.hxx>
59 #include <GeomLProp_SLProps.hxx>
60 #include <GProp_GProps.hxx>
61 #include <GProp_PrincipalProps.hxx>
62 #include <ShapeAnalysis.hxx>
63 #include <ShapeAnalysis_Surface.hxx>
65 #include <TopExp_Explorer.hxx>
67 #include <TopoDS_Edge.hxx>
68 #include <TopoDS_Compound.hxx>
69 #include <TopTools_IndexedMapOfShape.hxx>
70 #include <TopTools_DataMapIteratorOfDataMapOfIntegerListOfShape.hxx>
71 #include <TopTools_ListIteratorOfListOfShape.hxx>
72 #include <TopTools_ListOfShape.hxx>
73 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
75 //=============================================================================
79 //=============================================================================
80 GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations (GEOM_Engine* theEngine, int theDocID)
81 : GEOM_IOperations(theEngine, theDocID)
83 MESSAGE("GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations");
86 //=============================================================================
90 //=============================================================================
91 GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations()
93 MESSAGE("GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations");
96 //=============================================================================
97 /*! Get kind and parameters of the given shape.
99 //=============================================================================
100 GEOMImpl_IMeasureOperations::ShapeKind GEOMImpl_IMeasureOperations::KindOfShape
101 (Handle(GEOM_Object) theShape,
102 Handle(TColStd_HSequenceOfInteger)& theIntegers,
103 Handle(TColStd_HSequenceOfReal)& theDoubles)
106 ShapeKind aKind = SK_NO_SHAPE;
108 if (theIntegers.IsNull()) theIntegers = new TColStd_HSequenceOfInteger;
109 else theIntegers->Clear();
111 if (theDoubles.IsNull()) theDoubles = new TColStd_HSequenceOfReal;
112 else theDoubles->Clear();
114 if (theShape.IsNull())
117 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
118 if (aRefShape.IsNull()) return aKind;
120 TopoDS_Shape aShape = aRefShape->GetValue();
121 if (aShape.IsNull()) return aKind;
123 int geom_type = theShape->GetType();
125 // check if it's advanced shape
126 if ( geom_type > ADVANCED_BASE ) {
132 GEOMAlgo_ShapeInfoFiller aSF;
133 aSF.SetShape(aShape);
135 Standard_Integer iErr = aSF.ErrorStatus();
137 SetErrorCode("Error in GEOMAlgo_ShapeInfoFiller");
140 const GEOMAlgo_ShapeInfo& anInfo = aSF.Info();
142 // Interprete results
143 TopAbs_ShapeEnum aType = anInfo.Type();
146 case TopAbs_COMPOUND:
147 case TopAbs_COMPSOLID:
149 // (+) geompy.kind.COMPOUND nb_solids nb_faces nb_edges nb_vertices
150 // (+) geompy.kind.COMPSOLID nb_solids nb_faces nb_edges nb_vertices
151 // ??? "nb_faces" - all faces or only 'standalone' faces?
152 if (aType == TopAbs_COMPOUND)
155 aKind = SK_COMPSOLID;
157 //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPOUND));
158 //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPSOLID));
159 theIntegers->Append(anInfo.NbSubShapes(TopAbs_SOLID));
160 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
161 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
162 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
168 // (+) geompy.kind.SHELL geompy.info.closed nb_faces nb_edges nb_vertices
169 // (+) geompy.kind.SHELL geompy.info.unclosed nb_faces nb_edges nb_vertices
172 theIntegers->Append((int)anInfo.KindOfClosed());
174 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
175 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
176 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
182 // (+) geompy.kind.WIRE geompy.info.closed nb_edges nb_vertices
183 // (+) geompy.kind.WIRE geompy.info.unclosed nb_edges nb_vertices
186 theIntegers->Append((int)anInfo.KindOfClosed());
188 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
189 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
197 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
200 case GEOMAlgo_KN_SPHERE:
201 // (+) geompy.kind.SPHERE xc yc zc R
205 gp_Pnt aC = anInfo.Location();
206 theDoubles->Append(aC.X());
207 theDoubles->Append(aC.Y());
208 theDoubles->Append(aC.Z());
210 theDoubles->Append(anInfo.Radius1());
213 case GEOMAlgo_KN_CYLINDER:
214 // (+) geompy.kind.CYLINDER xb yb zb dx dy dz R H
218 gp_Pnt aC = anInfo.Location();
219 theDoubles->Append(aC.X());
220 theDoubles->Append(aC.Y());
221 theDoubles->Append(aC.Z());
223 gp_Ax3 anAx3 = anInfo.Position();
224 gp_Dir aD = anAx3.Direction();
225 theDoubles->Append(aD.X());
226 theDoubles->Append(aD.Y());
227 theDoubles->Append(aD.Z());
229 theDoubles->Append(anInfo.Radius1());
230 theDoubles->Append(anInfo.Height());
233 case GEOMAlgo_KN_BOX:
234 // (+) geompy.kind.BOX xc yc zc ax ay az
238 gp_Pnt aC = anInfo.Location();
239 theDoubles->Append(aC.X());
240 theDoubles->Append(aC.Y());
241 theDoubles->Append(aC.Z());
243 gp_Ax3 anAx3 = anInfo.Position();
244 gp_Dir aD = anAx3.Direction();
245 gp_Dir aX = anAx3.XDirection();
248 if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
249 aX.IsParallel(gp::DX(), Precision::Angular())) {
250 theDoubles->Append(anInfo.Length()); // ax'
251 theDoubles->Append(anInfo.Width()); // ay'
252 theDoubles->Append(anInfo.Height()); // az'
254 else if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
255 aX.IsParallel(gp::DY(), Precision::Angular())) {
256 theDoubles->Append(anInfo.Width()); // ay'
257 theDoubles->Append(anInfo.Length()); // ax'
258 theDoubles->Append(anInfo.Height()); // az'
260 else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
261 aX.IsParallel(gp::DZ(), Precision::Angular())) {
262 theDoubles->Append(anInfo.Height()); // az'
263 theDoubles->Append(anInfo.Width()); // ay'
264 theDoubles->Append(anInfo.Length()); // ax'
266 else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
267 aX.IsParallel(gp::DY(), Precision::Angular())) {
268 theDoubles->Append(anInfo.Height()); // az'
269 theDoubles->Append(anInfo.Length()); // ax'
270 theDoubles->Append(anInfo.Width()); // ay'
272 else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
273 aX.IsParallel(gp::DZ(), Precision::Angular())) {
274 theDoubles->Append(anInfo.Width()); // ay'
275 theDoubles->Append(anInfo.Height()); // az'
276 theDoubles->Append(anInfo.Length()); // ax'
278 else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
279 aX.IsParallel(gp::DX(), Precision::Angular())) {
280 theDoubles->Append(anInfo.Length()); // ax'
281 theDoubles->Append(anInfo.Height()); // az'
282 theDoubles->Append(anInfo.Width()); // ay'
285 // (+) geompy.kind.ROTATED_BOX xo yo zo zx zy zz xx xy xz ax ay az
286 aKind = SK_ROTATED_BOX;
288 // Direction and XDirection
289 theDoubles->Append(aD.X());
290 theDoubles->Append(aD.Y());
291 theDoubles->Append(aD.Z());
293 theDoubles->Append(aX.X());
294 theDoubles->Append(aX.Y());
295 theDoubles->Append(aX.Z());
298 theDoubles->Append(anInfo.Length());
299 theDoubles->Append(anInfo.Width());
300 theDoubles->Append(anInfo.Height());
304 case GEOMAlgo_KN_TORUS:
305 // (+) geompy.kind.TORUS xc yc zc dx dy dz R_1 R_2
309 gp_Pnt aO = anInfo.Location();
310 theDoubles->Append(aO.X());
311 theDoubles->Append(aO.Y());
312 theDoubles->Append(aO.Z());
314 gp_Ax3 anAx3 = anInfo.Position();
315 gp_Dir aD = anAx3.Direction();
316 theDoubles->Append(aD.X());
317 theDoubles->Append(aD.Y());
318 theDoubles->Append(aD.Z());
320 theDoubles->Append(anInfo.Radius1());
321 theDoubles->Append(anInfo.Radius2());
324 case GEOMAlgo_KN_CONE:
325 // (+) geompy.kind.CONE xb yb zb dx dy dz R_1 R_2 H
329 gp_Pnt aO = anInfo.Location();
330 theDoubles->Append(aO.X());
331 theDoubles->Append(aO.Y());
332 theDoubles->Append(aO.Z());
334 gp_Ax3 anAx3 = anInfo.Position();
335 gp_Dir aD = anAx3.Direction();
336 theDoubles->Append(aD.X());
337 theDoubles->Append(aD.Y());
338 theDoubles->Append(aD.Z());
340 theDoubles->Append(anInfo.Radius1());
341 theDoubles->Append(anInfo.Radius2());
342 theDoubles->Append(anInfo.Height());
345 case GEOMAlgo_KN_POLYHEDRON:
346 // (+) geompy.kind.POLYHEDRON nb_faces nb_edges nb_vertices
348 aKind = SK_POLYHEDRON;
350 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
351 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
352 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
356 // (+) geompy.kind.SOLID nb_faces nb_edges nb_vertices
358 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
359 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
360 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
370 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
372 case GEOMAlgo_KN_SPHERE:
373 // (+) geompy.kind.SPHERE2D xc yc zc R
377 gp_Pnt aC = anInfo.Location();
378 theDoubles->Append(aC.X());
379 theDoubles->Append(aC.Y());
380 theDoubles->Append(aC.Z());
382 theDoubles->Append(anInfo.Radius1());
385 case GEOMAlgo_KN_CYLINDER:
386 // (+) geompy.kind.CYLINDER2D xb yb zb dx dy dz R H
388 aKind = SK_CYLINDER2D;
390 gp_Pnt aO = anInfo.Location();
391 theDoubles->Append(aO.X());
392 theDoubles->Append(aO.Y());
393 theDoubles->Append(aO.Z());
395 gp_Ax3 anAx3 = anInfo.Position();
396 gp_Dir aD = anAx3.Direction();
397 theDoubles->Append(aD.X());
398 theDoubles->Append(aD.Y());
399 theDoubles->Append(aD.Z());
401 theDoubles->Append(anInfo.Radius1());
402 theDoubles->Append(anInfo.Height());
405 case GEOMAlgo_KN_TORUS:
406 // (+) geompy.kind.TORUS2D xc yc zc dx dy dz R_1 R_2
410 gp_Pnt aO = anInfo.Location();
411 theDoubles->Append(aO.X());
412 theDoubles->Append(aO.Y());
413 theDoubles->Append(aO.Z());
415 gp_Ax3 anAx3 = anInfo.Position();
416 gp_Dir aD = anAx3.Direction();
417 theDoubles->Append(aD.X());
418 theDoubles->Append(aD.Y());
419 theDoubles->Append(aD.Z());
421 theDoubles->Append(anInfo.Radius1());
422 theDoubles->Append(anInfo.Radius2());
425 case GEOMAlgo_KN_CONE:
426 // (+) geompy.kind.CONE2D xc yc zc dx dy dz R_1 R_2 H
430 gp_Pnt aO = anInfo.Location();
431 theDoubles->Append(aO.X());
432 theDoubles->Append(aO.Y());
433 theDoubles->Append(aO.Z());
435 gp_Ax3 anAx3 = anInfo.Position();
436 gp_Dir aD = anAx3.Direction();
437 theDoubles->Append(aD.X());
438 theDoubles->Append(aD.Y());
439 theDoubles->Append(aD.Z());
441 theDoubles->Append(anInfo.Radius1());
442 theDoubles->Append(anInfo.Radius2());
443 theDoubles->Append(anInfo.Height());
446 case GEOMAlgo_KN_DISKCIRCLE:
447 // (+) geompy.kind.DISK_CIRCLE xc yc zc dx dy dz R
449 aKind = SK_DISK_CIRCLE;
451 gp_Pnt aC = anInfo.Location();
452 theDoubles->Append(aC.X());
453 theDoubles->Append(aC.Y());
454 theDoubles->Append(aC.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());
465 case GEOMAlgo_KN_DISKELLIPSE:
466 // (+) geompy.kind.DISK_ELLIPSE xc yc zc dx dy dz R_1 R_2
468 aKind = SK_DISK_ELLIPSE;
470 gp_Pnt aC = anInfo.Location();
471 theDoubles->Append(aC.X());
472 theDoubles->Append(aC.Y());
473 theDoubles->Append(aC.Z());
475 gp_Ax3 anAx3 = anInfo.Position();
476 gp_Dir aD = anAx3.Direction();
477 theDoubles->Append(aD.X());
478 theDoubles->Append(aD.Y());
479 theDoubles->Append(aD.Z());
481 theDoubles->Append(anInfo.Radius1());
482 theDoubles->Append(anInfo.Radius2());
485 case GEOMAlgo_KN_RECTANGLE:
486 case GEOMAlgo_KN_TRIANGLE:
487 case GEOMAlgo_KN_QUADRANGLE:
488 case GEOMAlgo_KN_POLYGON:
489 // (+) geompy.kind.POLYGON xo yo zo dx dy dz nb_edges nb_vertices
493 gp_Pnt aO = anInfo.Location();
494 theDoubles->Append(aO.X());
495 theDoubles->Append(aO.Y());
496 theDoubles->Append(aO.Z());
498 gp_Ax3 anAx3 = anInfo.Position();
499 gp_Dir aD = anAx3.Direction();
500 theDoubles->Append(aD.X());
501 theDoubles->Append(aD.Y());
502 theDoubles->Append(aD.Z());
504 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
505 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
508 case GEOMAlgo_KN_PLANE: // infinite
509 // (+) geompy.kind.PLANE xo yo zo dx dy dz
513 gp_Pnt aC = anInfo.Location();
514 theDoubles->Append(aC.X());
515 theDoubles->Append(aC.Y());
516 theDoubles->Append(aC.Z());
518 gp_Ax3 anAx3 = anInfo.Position();
519 gp_Dir aD = anAx3.Direction();
520 theDoubles->Append(aD.X());
521 theDoubles->Append(aD.Y());
522 theDoubles->Append(aD.Z());
526 if (anInfo.KindOfShape() == GEOMAlgo_KS_PLANE) {
527 // (+) geompy.kind.PLANAR xo yo zo dx dy dz nb_edges nb_vertices
531 gp_Pnt aC = anInfo.Location();
532 theDoubles->Append(aC.X());
533 theDoubles->Append(aC.Y());
534 theDoubles->Append(aC.Z());
536 gp_Ax3 anAx3 = anInfo.Position();
537 gp_Dir aD = anAx3.Direction();
538 theDoubles->Append(aD.X());
539 theDoubles->Append(aD.Y());
540 theDoubles->Append(aD.Z());
542 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
543 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
546 // ??? geompy.kind.FACE nb_edges nb_vertices _surface_type_id_
547 // (+) geompy.kind.FACE nb_edges nb_vertices
549 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
550 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
560 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
562 case GEOMAlgo_KN_CIRCLE:
564 // (+) geompy.kind.CIRCLE xc yc zc dx dy dz R
567 gp_Pnt aC = anInfo.Location();
568 theDoubles->Append(aC.X());
569 theDoubles->Append(aC.Y());
570 theDoubles->Append(aC.Z());
572 gp_Ax3 anAx3 = anInfo.Position();
573 gp_Dir aD = anAx3.Direction();
574 theDoubles->Append(aD.X());
575 theDoubles->Append(aD.Y());
576 theDoubles->Append(aD.Z());
578 theDoubles->Append(anInfo.Radius1());
581 case GEOMAlgo_KN_ARCCIRCLE:
583 // (+) geompy.kind.ARC_CIRCLE xc yc zc dx dy dz R x1 y1 z1 x2 y2 z2
584 aKind = SK_ARC_CIRCLE;
586 gp_Pnt aC = anInfo.Location();
587 theDoubles->Append(aC.X());
588 theDoubles->Append(aC.Y());
589 theDoubles->Append(aC.Z());
591 gp_Ax3 anAx3 = anInfo.Position();
592 gp_Dir aD = anAx3.Direction();
593 theDoubles->Append(aD.X());
594 theDoubles->Append(aD.Y());
595 theDoubles->Append(aD.Z());
597 theDoubles->Append(anInfo.Radius1());
599 gp_Pnt aP1 = anInfo.Pnt1();
600 theDoubles->Append(aP1.X());
601 theDoubles->Append(aP1.Y());
602 theDoubles->Append(aP1.Z());
604 gp_Pnt aP2 = anInfo.Pnt2();
605 theDoubles->Append(aP2.X());
606 theDoubles->Append(aP2.Y());
607 theDoubles->Append(aP2.Z());
610 case GEOMAlgo_KN_ELLIPSE:
612 // (+) geompy.kind.ELLIPSE xc yc zc dx dy dz R_1 R_2
615 gp_Pnt aC = anInfo.Location();
616 theDoubles->Append(aC.X());
617 theDoubles->Append(aC.Y());
618 theDoubles->Append(aC.Z());
620 gp_Ax3 anAx3 = anInfo.Position();
621 gp_Dir aD = anAx3.Direction();
622 theDoubles->Append(aD.X());
623 theDoubles->Append(aD.Y());
624 theDoubles->Append(aD.Z());
626 theDoubles->Append(anInfo.Radius1());
627 theDoubles->Append(anInfo.Radius2());
630 case GEOMAlgo_KN_ARCELLIPSE:
632 // (+) geompy.kind.ARC_ELLIPSE xc yc zc dx dy dz R_1 R_2 x1 y1 z1 x2 y2 z2
633 aKind = SK_ARC_ELLIPSE;
635 gp_Pnt aC = anInfo.Location();
636 theDoubles->Append(aC.X());
637 theDoubles->Append(aC.Y());
638 theDoubles->Append(aC.Z());
640 gp_Ax3 anAx3 = anInfo.Position();
641 gp_Dir aD = anAx3.Direction();
642 theDoubles->Append(aD.X());
643 theDoubles->Append(aD.Y());
644 theDoubles->Append(aD.Z());
646 theDoubles->Append(anInfo.Radius1());
647 theDoubles->Append(anInfo.Radius2());
649 gp_Pnt aP1 = anInfo.Pnt1();
650 theDoubles->Append(aP1.X());
651 theDoubles->Append(aP1.Y());
652 theDoubles->Append(aP1.Z());
654 gp_Pnt aP2 = anInfo.Pnt2();
655 theDoubles->Append(aP2.X());
656 theDoubles->Append(aP2.Y());
657 theDoubles->Append(aP2.Z());
660 case GEOMAlgo_KN_LINE:
662 // ??? geompy.kind.LINE x1 y1 z1 x2 y2 z2
663 // (+) geompy.kind.LINE x1 y1 z1 dx dy dz
666 gp_Pnt aO = anInfo.Location();
667 theDoubles->Append(aO.X());
668 theDoubles->Append(aO.Y());
669 theDoubles->Append(aO.Z());
671 gp_Dir aD = anInfo.Direction();
672 theDoubles->Append(aD.X());
673 theDoubles->Append(aD.Y());
674 theDoubles->Append(aD.Z());
677 case GEOMAlgo_KN_SEGMENT:
679 // (+) geompy.kind.SEGMENT x1 y1 z1 x2 y2 z2
682 gp_Pnt aP1 = anInfo.Pnt1();
683 theDoubles->Append(aP1.X());
684 theDoubles->Append(aP1.Y());
685 theDoubles->Append(aP1.Z());
687 gp_Pnt aP2 = anInfo.Pnt2();
688 theDoubles->Append(aP2.X());
689 theDoubles->Append(aP2.Y());
690 theDoubles->Append(aP2.Z());
694 // ??? geompy.kind.EDGE nb_vertices _curve_type_id_
695 // (+) geompy.kind.EDGE nb_vertices
696 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
703 // (+) geompy.kind.VERTEX x y z
706 gp_Pnt aP = anInfo.Location();
707 theDoubles->Append(aP.X());
708 theDoubles->Append(aP.Y());
709 theDoubles->Append(aP.Z());
718 //=============================================================================
722 //=============================================================================
723 void GEOMImpl_IMeasureOperations::GetPosition
724 (Handle(GEOM_Object) theShape,
725 Standard_Real& Ox, Standard_Real& Oy, Standard_Real& Oz,
726 Standard_Real& Zx, Standard_Real& Zy, Standard_Real& Zz,
727 Standard_Real& Xx, Standard_Real& Xy, Standard_Real& Xz)
731 //Set default values: global CS
732 Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
735 if (theShape.IsNull()) return;
737 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
738 if (aRefShape.IsNull()) return;
740 TopoDS_Shape aShape = aRefShape->GetValue();
741 if (aShape.IsNull()) {
742 SetErrorCode("The Objects has NULL Shape");
747 #if OCC_VERSION_LARGE > 0x06010000
751 gp_Ax3 anAx3 = GEOMUtils::GetPosition(aShape);
753 gp_Pnt anOri = anAx3.Location();
754 gp_Dir aDirZ = anAx3.Direction();
755 gp_Dir aDirX = anAx3.XDirection();
758 anOri.Coord(Ox, Oy, Oz);
759 aDirZ.Coord(Zx, Zy, Zz);
760 aDirX.Coord(Xx, Xy, Xz);
762 catch (Standard_Failure) {
763 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
764 SetErrorCode(aFail->GetMessageString());
771 //=============================================================================
775 //=============================================================================
776 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetCentreOfMass
777 (Handle(GEOM_Object) theShape)
781 if (theShape.IsNull()) return NULL;
783 //Add a new CentreOfMass object
784 Handle(GEOM_Object) aCDG = GetEngine()->AddObject(GetDocID(), GEOM_CDG);
786 //Add a new CentreOfMass function
787 Handle(GEOM_Function) aFunction =
788 aCDG->AddFunction(GEOMImpl_MeasureDriver::GetID(), CDG_MEASURE);
789 if (aFunction.IsNull()) return NULL;
791 //Check if the function is set correctly
792 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
794 GEOMImpl_IMeasure aCI (aFunction);
796 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
797 if (aRefShape.IsNull()) return NULL;
799 aCI.SetBase(aRefShape);
801 //Compute the CentreOfMass value
803 #if OCC_VERSION_LARGE > 0x06010000
806 if (!GetSolver()->ComputeFunction(aFunction)) {
807 SetErrorCode("Measure driver failed to compute centre of mass");
811 catch (Standard_Failure) {
812 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
813 SetErrorCode(aFail->GetMessageString());
817 //Make a Python command
818 GEOM::TPythonDump(aFunction) << aCDG << " = geompy.MakeCDG(" << theShape << ")";
824 //=============================================================================
828 //=============================================================================
829 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetVertexByIndex
830 (Handle(GEOM_Object) theShape,
831 Standard_Integer theIndex)
835 if (theShape.IsNull()) return NULL;
837 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
838 if (aRefShape.IsNull()) return NULL;
840 //Add a new Vertex object
841 Handle(GEOM_Object) aVertex = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
844 Handle(GEOM_Function) aFunction =
845 aVertex->AddFunction(GEOMImpl_MeasureDriver::GetID(), VERTEX_BY_INDEX);
846 if (aFunction.IsNull()) return NULL;
848 //Check if the function is set correctly
849 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
851 GEOMImpl_IMeasure aCI (aFunction);
852 aCI.SetBase(aRefShape);
853 aCI.SetIndex(theIndex);
857 #if OCC_VERSION_LARGE > 0x06010000
860 if (!GetSolver()->ComputeFunction(aFunction)) {
861 SetErrorCode("Vertex by index driver failed.");
865 catch (Standard_Failure) {
866 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
867 SetErrorCode(aFail->GetMessageString());
871 //Make a Python command
872 GEOM::TPythonDump(aFunction) << aVertex << " = geompy.GetVertexByIndex(" << theShape << ", " << theIndex << ")";
878 //=============================================================================
882 //=============================================================================
883 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetNormal
884 (Handle(GEOM_Object) theFace,
885 Handle(GEOM_Object) theOptionalPoint)
889 if (theFace.IsNull()) return NULL;
891 //Add a new Normale object
892 Handle(GEOM_Object) aNorm = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
894 //Add a new Normale function
895 Handle(GEOM_Function) aFunction =
896 aNorm->AddFunction(GEOMImpl_MeasureDriver::GetID(), VECTOR_FACE_NORMALE);
897 if (aFunction.IsNull()) return NULL;
899 //Check if the function is set correctly
900 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
902 GEOMImpl_IMeasure aCI (aFunction);
904 Handle(GEOM_Function) aFace = theFace->GetLastFunction();
905 if (aFace.IsNull()) return NULL;
909 if (!theOptionalPoint.IsNull()) {
910 Handle(GEOM_Function) anOptPnt = theOptionalPoint->GetLastFunction();
911 aCI.SetPoint(anOptPnt);
914 //Compute the Normale value
916 #if OCC_VERSION_LARGE > 0x06010000
919 if (!GetSolver()->ComputeFunction(aFunction)) {
920 SetErrorCode("Measure driver failed to compute normake of face");
924 catch (Standard_Failure) {
925 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
926 SetErrorCode(aFail->GetMessageString());
930 //Make a Python command
931 GEOM::TPythonDump pd (aFunction);
932 pd << aNorm << " = geompy.GetNormal(" << theFace;
933 if (!theOptionalPoint.IsNull()) {
934 pd << ", " << theOptionalPoint;
942 //=============================================================================
946 //=============================================================================
947 void GEOMImpl_IMeasureOperations::GetBasicProperties (Handle(GEOM_Object) theShape,
948 Standard_Real& theLength,
949 Standard_Real& theSurfArea,
950 Standard_Real& theVolume)
954 if (theShape.IsNull()) return;
956 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
957 if (aRefShape.IsNull()) return;
959 TopoDS_Shape aShape = aRefShape->GetValue();
960 if (aShape.IsNull()) {
961 SetErrorCode("The Objects has NULL Shape");
965 //Compute the parameters
966 GProp_GProps LProps, SProps;
968 #if OCC_VERSION_LARGE > 0x06010000
971 BRepGProp::LinearProperties(aShape, LProps);
972 theLength = LProps.Mass();
974 BRepGProp::SurfaceProperties(aShape, SProps);
975 theSurfArea = SProps.Mass();
978 if (aShape.ShapeType() < TopAbs_SHELL) {
979 for (TopExp_Explorer Exp (aShape, TopAbs_SOLID); Exp.More(); Exp.Next()) {
981 BRepGProp::VolumeProperties(Exp.Current(), VProps);
982 theVolume += VProps.Mass();
986 catch (Standard_Failure) {
987 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
988 SetErrorCode(aFail->GetMessageString());
995 //=============================================================================
999 //=============================================================================
1000 void GEOMImpl_IMeasureOperations::GetInertia
1001 (Handle(GEOM_Object) theShape,
1002 Standard_Real& I11, Standard_Real& I12, Standard_Real& I13,
1003 Standard_Real& I21, Standard_Real& I22, Standard_Real& I23,
1004 Standard_Real& I31, Standard_Real& I32, Standard_Real& I33,
1005 Standard_Real& Ix , Standard_Real& Iy , Standard_Real& Iz)
1009 if (theShape.IsNull()) return;
1011 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1012 if (aRefShape.IsNull()) return;
1014 TopoDS_Shape aShape = aRefShape->GetValue();
1015 if (aShape.IsNull()) {
1016 SetErrorCode("The Objects has NULL Shape");
1020 //Compute the parameters
1021 GProp_GProps System;
1024 #if OCC_VERSION_LARGE > 0x06010000
1027 if (aShape.ShapeType() == TopAbs_VERTEX ||
1028 aShape.ShapeType() == TopAbs_EDGE ||
1029 aShape.ShapeType() == TopAbs_WIRE) {
1030 BRepGProp::LinearProperties(aShape, System);
1031 } else if (aShape.ShapeType() == TopAbs_FACE ||
1032 aShape.ShapeType() == TopAbs_SHELL) {
1033 BRepGProp::SurfaceProperties(aShape, System);
1035 BRepGProp::VolumeProperties(aShape, System);
1037 gp_Mat I = System.MatrixOfInertia();
1051 GProp_PrincipalProps Pr = System.PrincipalProperties();
1052 Pr.Moments(Ix,Iy,Iz);
1054 catch (Standard_Failure) {
1055 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1056 SetErrorCode(aFail->GetMessageString());
1063 //=============================================================================
1067 //=============================================================================
1068 void GEOMImpl_IMeasureOperations::GetBoundingBox
1069 (Handle(GEOM_Object) theShape,
1070 const Standard_Boolean precise,
1071 Standard_Real& Xmin, Standard_Real& Xmax,
1072 Standard_Real& Ymin, Standard_Real& Ymax,
1073 Standard_Real& Zmin, Standard_Real& Zmax)
1077 if (theShape.IsNull()) return;
1079 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1080 if (aRefShape.IsNull()) return;
1082 TopoDS_Shape aShape = aRefShape->GetValue();
1083 if (aShape.IsNull()) {
1084 SetErrorCode("The Objects has NULL Shape");
1088 //Compute the parameters
1092 #if OCC_VERSION_LARGE > 0x06010000
1095 BRepBuilderAPI_Copy aCopyTool (aShape);
1096 if (!aCopyTool.IsDone()) {
1097 SetErrorCode("GetBoundingBox Error: Bad shape detected");
1101 aShape = aCopyTool.Shape();
1103 // remove triangulation to obtain more exact boundaries
1104 BRepTools::Clean(aShape);
1106 BRepBndLib::Add(aShape, B);
1109 if (!GEOMUtils::PreciseBoundingBox(aShape, B)) {
1110 SetErrorCode("GetBoundingBox Error: Bounding box cannot be precised");
1115 B.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
1117 catch (Standard_Failure) {
1118 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1119 SetErrorCode(aFail->GetMessageString());
1126 //=============================================================================
1130 //=============================================================================
1131 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetBoundingBox
1132 (Handle(GEOM_Object) theShape,
1133 const Standard_Boolean precise)
1137 if (theShape.IsNull()) return NULL;
1139 //Add a new BoundingBox object
1140 Handle(GEOM_Object) aBnd = GetEngine()->AddObject(GetDocID(), GEOM_BOX);
1142 //Add a new BoundingBox function
1143 const int aType = (precise ? BND_BOX_MEASURE_PRECISE : BND_BOX_MEASURE);
1144 Handle(GEOM_Function) aFunction =
1145 aBnd->AddFunction(GEOMImpl_MeasureDriver::GetID(), aType);
1146 if (aFunction.IsNull()) return NULL;
1148 //Check if the function is set correctly
1149 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
1151 GEOMImpl_IMeasure aCI (aFunction);
1153 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1154 if (aRefShape.IsNull()) return NULL;
1156 aCI.SetBase(aRefShape);
1158 //Compute the BoundingBox value
1160 #if OCC_VERSION_LARGE > 0x06010000
1163 if (!GetSolver()->ComputeFunction(aFunction)) {
1164 SetErrorCode("Measure driver failed to compute a bounding box");
1168 catch (Standard_Failure) {
1169 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1170 SetErrorCode(aFail->GetMessageString());
1174 //Make a Python command
1175 GEOM::TPythonDump aPd(aFunction);
1177 aPd << aBnd << " = geompy.MakeBoundingBox(" << theShape;
1189 //=============================================================================
1193 //=============================================================================
1194 void GEOMImpl_IMeasureOperations::GetTolerance
1195 (Handle(GEOM_Object) theShape,
1196 Standard_Real& FaceMin, Standard_Real& FaceMax,
1197 Standard_Real& EdgeMin, Standard_Real& EdgeMax,
1198 Standard_Real& VertMin, Standard_Real& VertMax)
1202 if (theShape.IsNull()) return;
1204 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1205 if (aRefShape.IsNull()) return;
1207 TopoDS_Shape aShape = aRefShape->GetValue();
1208 if (aShape.IsNull()) {
1209 SetErrorCode("The Objects has NULL Shape");
1213 //Compute the parameters
1215 FaceMin = EdgeMin = VertMin = RealLast();
1216 FaceMax = EdgeMax = VertMax = -RealLast();
1219 #if OCC_VERSION_LARGE > 0x06010000
1222 for (TopExp_Explorer ExF (aShape, TopAbs_FACE); ExF.More(); ExF.Next()) {
1223 TopoDS_Face Face = TopoDS::Face(ExF.Current());
1224 T = BRep_Tool::Tolerance(Face);
1230 for (TopExp_Explorer ExE (aShape, TopAbs_EDGE); ExE.More(); ExE.Next()) {
1231 TopoDS_Edge Edge = TopoDS::Edge(ExE.Current());
1232 T = BRep_Tool::Tolerance(Edge);
1238 for (TopExp_Explorer ExV (aShape, TopAbs_VERTEX); ExV.More(); ExV.Next()) {
1239 TopoDS_Vertex Vertex = TopoDS::Vertex(ExV.Current());
1240 T = BRep_Tool::Tolerance(Vertex);
1247 catch (Standard_Failure) {
1248 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1249 SetErrorCode(aFail->GetMessageString());
1256 //=============================================================================
1260 //=============================================================================
1261 bool GEOMImpl_IMeasureOperations::CheckShape (Handle(GEOM_Object) theShape,
1262 const Standard_Boolean theIsCheckGeom,
1263 std::list<ShapeError> &theErrors)
1268 if (theShape.IsNull()) return false;
1270 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1271 if (aRefShape.IsNull()) return false;
1273 TopoDS_Shape aShape = aRefShape->GetValue();
1274 if (aShape.IsNull()) {
1275 SetErrorCode("The Objects has NULL Shape");
1279 //Compute the parameters
1280 bool isValid = false;
1282 #if OCC_VERSION_LARGE > 0x06010000
1285 BRepCheck_Analyzer ana (aShape, theIsCheckGeom);
1286 if (ana.IsValid()) {
1289 FillErrors(ana, aShape, theErrors);
1292 catch (Standard_Failure) {
1293 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1294 SetErrorCode(aFail->GetMessageString());
1302 //=============================================================================
1306 //=============================================================================
1307 TCollection_AsciiString GEOMImpl_IMeasureOperations::PrintShapeErrors
1308 (Handle(GEOM_Object) theShape,
1309 const std::list<ShapeError> &theErrors)
1311 TCollection_AsciiString aDump;
1313 if (theShape.IsNull()) {
1317 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1319 if (aRefShape.IsNull()) {
1323 TopoDS_Shape aShape = aRefShape->GetValue();
1325 if (aShape.IsNull()) {
1326 SetErrorCode("The Objects has NULL Shape");
1330 if (!theErrors.empty()) {
1331 // The shape is not valid. Prepare errors for dump.
1332 TopTools_IndexedMapOfShape anIndices;
1333 std::list<ShapeError>::const_iterator anIter = theErrors.begin();
1334 Standard_Integer nbv, nbe, nbw, nbf, nbs, nbo;
1335 nbv = nbe = nbw = nbf = nbs = nbo = 0;
1337 // Map sub-shapes and their indices
1338 TopExp::MapShapes(aShape, anIndices);
1340 const Standard_Integer aNbSubShapes = anIndices.Extent();
1341 TColStd_MapOfInteger aMapPbInd;
1343 aDump += " -- The Shape has problems :\n";
1344 aDump += " Check Count\n";
1345 aDump += " ------------------------------------------------\n";
1347 for (; anIter != theErrors.end(); anIter++) {
1348 Standard_Integer aNbShapes = anIter->incriminated.size();
1350 switch(anIter->error) {
1351 case BRepCheck_InvalidPointOnCurve:
1352 aDump += " Invalid Point on Curve ................... ";
1354 case BRepCheck_InvalidPointOnCurveOnSurface:
1355 aDump += " Invalid Point on CurveOnSurface .......... ";
1357 case BRepCheck_InvalidPointOnSurface:
1358 aDump += " Invalid Point on Surface ................. ";
1360 case BRepCheck_No3DCurve:
1361 aDump += " No 3D Curve .............................. ";
1363 case BRepCheck_Multiple3DCurve:
1364 aDump += " Multiple 3D Curve ........................ ";
1366 case BRepCheck_Invalid3DCurve:
1367 aDump += " Invalid 3D Curve ......................... ";
1369 case BRepCheck_NoCurveOnSurface:
1370 aDump += " No Curve on Surface ...................... ";
1372 case BRepCheck_InvalidCurveOnSurface:
1373 aDump += " Invalid Curve on Surface ................. ";
1375 case BRepCheck_InvalidCurveOnClosedSurface:
1376 aDump += " Invalid Curve on closed Surface .......... ";
1378 case BRepCheck_InvalidSameRangeFlag:
1379 aDump += " Invalid SameRange Flag ................... ";
1381 case BRepCheck_InvalidSameParameterFlag:
1382 aDump += " Invalid SameParameter Flag ............... ";
1384 case BRepCheck_InvalidDegeneratedFlag:
1385 aDump += " Invalid Degenerated Flag ................. ";
1387 case BRepCheck_FreeEdge:
1388 aDump += " Free Edge ................................ ";
1390 case BRepCheck_InvalidMultiConnexity:
1391 aDump += " Invalid MultiConnexity ................... ";
1393 case BRepCheck_InvalidRange:
1394 aDump += " Invalid Range ............................ ";
1396 case BRepCheck_EmptyWire:
1397 aDump += " Empty Wire ............................... ";
1399 case BRepCheck_RedundantEdge:
1400 aDump += " Redundant Edge ........................... ";
1402 case BRepCheck_SelfIntersectingWire:
1403 aDump += " Self Intersecting Wire ................... ";
1405 case BRepCheck_NoSurface:
1406 aDump += " No Surface ............................... ";
1408 case BRepCheck_InvalidWire:
1409 aDump += " Invalid Wire ............................. ";
1411 case BRepCheck_RedundantWire:
1412 aDump += " Redundant Wire ........................... ";
1414 case BRepCheck_IntersectingWires:
1415 aDump += " Intersecting Wires ....................... ";
1417 case BRepCheck_InvalidImbricationOfWires:
1418 aDump += " Invalid Imbrication of Wires ............. ";
1420 case BRepCheck_EmptyShell:
1421 aDump += " Empty Shell .............................. ";
1423 case BRepCheck_RedundantFace:
1424 aDump += " Redundant Face ........................... ";
1426 case BRepCheck_UnorientableShape:
1427 aDump += " Unorientable Shape ....................... ";
1429 case BRepCheck_NotClosed:
1430 aDump += " Not Closed ............................... ";
1432 case BRepCheck_NotConnected:
1433 aDump += " Not Connected ............................ ";
1435 case BRepCheck_SubshapeNotInShape:
1436 aDump += " Sub-shape not in Shape ................... ";
1438 case BRepCheck_BadOrientation:
1439 aDump += " Bad Orientation .......................... ";
1441 case BRepCheck_BadOrientationOfSubshape:
1442 aDump += " Bad Orientation of Sub-shape ............. ";
1444 case BRepCheck_InvalidToleranceValue:
1445 aDump += " Invalid Tolerance Value .................. ";
1447 case BRepCheck_CheckFail:
1448 aDump += " Check Shape Failure ...................... ";
1454 aDump += TCollection_AsciiString(aNbShapes) + "\n";
1456 // Count types of shape.
1457 std::list<int>::const_iterator aShIter = anIter->incriminated.begin();
1459 for (; aShIter != anIter->incriminated.end(); aShIter++) {
1460 const Standard_Integer anIndex = *aShIter;
1462 if (anIndex > 0 && anIndex <= aNbSubShapes && aMapPbInd.Add(anIndex)) {
1463 const TopoDS_Shape &aSubShape = anIndices.FindKey(anIndex);
1464 const TopAbs_ShapeEnum aType = aSubShape.ShapeType();
1467 case TopAbs_VERTEX : nbv++; break;
1468 case TopAbs_EDGE : nbe++; break;
1469 case TopAbs_WIRE : nbw++; break;
1470 case TopAbs_FACE : nbf++; break;
1471 case TopAbs_SHELL : nbs++; break;
1472 case TopAbs_SOLID : nbo++; break;
1479 const Standard_Integer aNbFaultyShapes = nbv + nbe + nbw + nbf + nbs + nbo;
1480 aDump += " ------------------------------------------------\n";
1481 aDump += "*** Shapes with problems : ";
1482 aDump += TCollection_AsciiString(aNbFaultyShapes) + "\n";
1485 aDump += "VERTEX : ";
1486 if (nbv < 10) aDump += " ";
1487 aDump += TCollection_AsciiString(nbv) + "\n";
1491 if (nbe < 10) aDump += " ";
1492 aDump += TCollection_AsciiString(nbe) + "\n";
1496 if (nbw < 10) aDump += " ";
1497 aDump += TCollection_AsciiString(nbw) + "\n";
1501 if (nbf < 10) aDump += " ";
1502 aDump += TCollection_AsciiString(nbf) + "\n";
1505 aDump += "SHELL : ";
1506 if (nbs < 10) aDump += " ";
1507 aDump += TCollection_AsciiString(nbs) + "\n";
1510 aDump += "SOLID : ";
1511 if (nbo < 10) aDump += " ";
1512 aDump += TCollection_AsciiString(nbo) + "\n";
1519 //=============================================================================
1521 * CheckSelfIntersections
1523 //=============================================================================
1524 bool GEOMImpl_IMeasureOperations::CheckSelfIntersections
1525 (Handle(GEOM_Object) theShape,
1526 Handle(TColStd_HSequenceOfInteger)& theIntersections)
1529 bool isGood = false;
1531 if (theIntersections.IsNull())
1532 theIntersections = new TColStd_HSequenceOfInteger;
1534 theIntersections->Clear();
1536 if (theShape.IsNull())
1539 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1540 if (aRefShape.IsNull()) return isGood;
1542 TopoDS_Shape aShape = aRefShape->GetValue();
1543 if (aShape.IsNull()) return isGood;
1547 TopoDS_Compound aCS;
1548 TopoDS_Shape aScopy;
1550 GEOMAlgo_AlgoTools::CopyShape(aShape, aScopy);
1552 // Map sub-shapes and their indices
1553 TopTools_IndexedMapOfShape anIndices;
1554 TopExp::MapShapes(aScopy, anIndices);
1556 aBB.MakeCompound(aCS);
1557 aBB.Add(aCS, aScopy);
1559 BOPCol_ListOfShape aLCS;
1560 aLCS.Append(aScopy);
1562 BOPAlgo_CheckerSI aCSI; // checker of self-interferences
1563 aCSI.SetArguments(aLCS);
1565 // 1. Launch the checker
1567 Standard_Integer iErr = aCSI.ErrorStatus();
1569 return false; // Error
1574 Standard_Integer aNbS, n1, n2;
1575 BOPDS_MapIteratorMapOfPassKey aItMPK;
1577 // 2. Take the shapes from DS
1578 const BOPDS_DS& aDS = aCSI.DS();
1579 aNbS=aDS.NbShapes();
1581 // 3. Get the pairs of interfered shapes
1582 const BOPDS_MapOfPassKey& aMPK=aDS.Interferences();
1583 aItMPK.Initialize(aMPK);
1584 for (; aItMPK.More(); aItMPK.Next()) {
1585 const BOPDS_PassKey& aPK=aItMPK.Value();
1588 if (n1 > aNbS || n2 > aNbS){
1589 return false; // Error
1591 const TopoDS_Shape& aS1 = aDS.Shape(n1);
1592 const TopoDS_Shape& aS2 = aDS.Shape(n2);
1594 theIntersections->Append(anIndices.FindIndex(aS1));
1595 theIntersections->Append(anIndices.FindIndex(aS2));
1603 //=============================================================================
1607 //=============================================================================
1608 TCollection_AsciiString GEOMImpl_IMeasureOperations::IsGoodForSolid (Handle(GEOM_Object) theShape)
1612 TCollection_AsciiString aRes = "";
1614 if (theShape.IsNull()) {
1615 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1618 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1619 if (aRefShape.IsNull()) {
1620 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1623 TopoDS_Shape aShape = aRefShape->GetValue();
1624 if (aShape.IsNull()) {
1625 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1628 if (aShape.ShapeType() == TopAbs_COMPOUND) {
1629 TopoDS_Iterator It (aShape, Standard_True, Standard_True);
1630 if (It.More()) aShape = It.Value();
1632 if (aShape.ShapeType() == TopAbs_SHELL) {
1633 BRepCheck_Shell chkShell (TopoDS::Shell(aShape));
1634 if (chkShell.Closed() == BRepCheck_NotClosed) {
1635 aRes = "WRN_SHAPE_UNCLOSED";
1639 aRes = "WRN_SHAPE_NOT_SHELL";
1651 //=============================================================================
1655 //=============================================================================
1656 TCollection_AsciiString GEOMImpl_IMeasureOperations::WhatIs (Handle(GEOM_Object) theShape)
1660 TCollection_AsciiString Astr;
1662 if (theShape.IsNull()) return Astr;
1664 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1665 if (aRefShape.IsNull()) return Astr;
1667 TopoDS_Shape aShape = aRefShape->GetValue();
1668 if (aShape.IsNull()) {
1669 SetErrorCode("The Objects has NULL Shape");
1673 //Compute the parameters
1674 if (aShape.ShapeType() == TopAbs_EDGE) {
1675 if (BRep_Tool::Degenerated(TopoDS::Edge(aShape))) {
1676 Astr = Astr + " It is a degenerated edge \n";
1680 Astr = Astr + " Number of sub-shapes : \n";
1683 #if OCC_VERSION_LARGE > 0x06010000
1686 int iType, nbTypes [TopAbs_SHAPE];
1687 for (iType = 0; iType < TopAbs_SHAPE; ++iType)
1689 nbTypes[aShape.ShapeType()]++;
1691 TopTools_MapOfShape aMapOfShape;
1692 aMapOfShape.Add(aShape);
1693 TopTools_ListOfShape aListOfShape;
1694 aListOfShape.Append(aShape);
1696 TopTools_ListIteratorOfListOfShape itL (aListOfShape);
1697 for (; itL.More(); itL.Next()) {
1698 TopoDS_Iterator it (itL.Value());
1699 for (; it.More(); it.Next()) {
1700 TopoDS_Shape s = it.Value();
1701 if (aMapOfShape.Add(s)) {
1702 aListOfShape.Append(s);
1703 nbTypes[s.ShapeType()]++;
1708 Astr = Astr + " VERTEX : " + TCollection_AsciiString(nbTypes[TopAbs_VERTEX]) + "\n";
1709 Astr = Astr + " EDGE : " + TCollection_AsciiString(nbTypes[TopAbs_EDGE]) + "\n";
1710 Astr = Astr + " WIRE : " + TCollection_AsciiString(nbTypes[TopAbs_WIRE]) + "\n";
1711 Astr = Astr + " FACE : " + TCollection_AsciiString(nbTypes[TopAbs_FACE]) + "\n";
1712 Astr = Astr + " SHELL : " + TCollection_AsciiString(nbTypes[TopAbs_SHELL]) + "\n";
1713 Astr = Astr + " SOLID : " + TCollection_AsciiString(nbTypes[TopAbs_SOLID]) + "\n";
1714 Astr = Astr + " COMPSOLID : " + TCollection_AsciiString(nbTypes[TopAbs_COMPSOLID]) + "\n";
1715 Astr = Astr + " COMPOUND : " + TCollection_AsciiString(nbTypes[TopAbs_COMPOUND]) + "\n";
1716 Astr = Astr + " SHAPE : " + TCollection_AsciiString(aMapOfShape.Extent());
1718 catch (Standard_Failure) {
1719 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1720 SetErrorCode(aFail->GetMessageString());
1728 //=============================================================================
1732 //=============================================================================
1734 GEOMImpl_IMeasureOperations::AreCoordsInside(Handle(GEOM_Object) theShape,
1735 const std::vector<double>& coords,
1738 std::vector<bool> isInsideRes;
1739 if (!theShape.IsNull()) {
1740 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1741 if (!aRefShape.IsNull()) {
1742 TopoDS_Shape aShape = aRefShape->GetValue();
1743 if (!aShape.IsNull())
1745 TopTools_IndexedMapOfShape mapShape;
1747 TopExp_Explorer anExp;
1748 for ( anExp.Init( aShape, TopAbs_SOLID ); anExp.More(); anExp.Next() )
1749 mapShape.Add( anExp.Current() );
1750 for ( anExp.Init( aShape, TopAbs_FACE, TopAbs_SOLID ); anExp.More(); anExp.Next() )
1751 mapShape.Add( anExp.Current() );
1752 for ( anExp.Init( aShape, TopAbs_EDGE, TopAbs_FACE ); anExp.More(); anExp.Next() )
1753 mapShape.Add( anExp.Current() );
1754 for ( anExp.Init( aShape, TopAbs_VERTEX, TopAbs_EDGE ); anExp.More(); anExp.Next() )
1755 mapShape.Add( anExp.Current() ); //// ?????????
1757 size_t nb_points = coords.size()/3, nb_points_inside = 0;
1758 isInsideRes.resize( nb_points, false );
1760 for ( int iS = 1; iS <= mapShape.Extent(); ++iS )
1762 if ( nb_points_inside == nb_points )
1764 aShape = mapShape( iS );
1765 switch ( aShape.ShapeType() ) {
1768 BRepClass3d_SolidClassifier SC( TopoDS::Solid( aShape ));
1769 for ( size_t i = 0; i < nb_points; i++)
1771 if ( isInsideRes[ i ]) continue;
1772 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
1773 SC.Perform( aPnt, tolerance );
1774 isInsideRes[ i ] = (( SC.State() == TopAbs_IN ) || ( SC.State() == TopAbs_ON ));
1775 nb_points_inside += isInsideRes[ i ];
1781 Standard_Real u1,u2,v1,v2;
1782 const TopoDS_Face& face = TopoDS::Face( aShape );
1783 Handle(Geom_Surface) surf = BRep_Tool::Surface( face );
1784 surf->Bounds( u1,u2,v1,v2 );
1785 GeomAPI_ProjectPointOnSurf project;
1786 project.Init(surf, u1,u2, v1,v2, tolerance );
1787 for ( size_t i = 0; i < nb_points; i++)
1789 if ( isInsideRes[ i ]) continue;
1790 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
1791 project.Perform( aPnt );
1792 if ( project.IsDone() &&
1793 project.NbPoints() > 0 &&
1794 project.LowerDistance() <= tolerance )
1796 Quantity_Parameter u, v;
1797 project.LowerDistanceParameters(u, v);
1798 gp_Pnt2d uv( u, v );
1799 BRepClass_FaceClassifier FC ( face, uv, tolerance );
1800 isInsideRes[ i ] = (( FC.State() == TopAbs_IN ) || ( FC.State() == TopAbs_ON ));
1801 nb_points_inside += isInsideRes[ i ];
1809 const TopoDS_Edge& edge = TopoDS::Edge( aShape );
1810 Handle(Geom_Curve) curve = BRep_Tool::Curve( edge, f, l );
1811 GeomAPI_ProjectPointOnCurve project;
1812 project.Init( curve, f, l );
1813 for ( size_t i = 0; i < nb_points; i++)
1815 if ( isInsideRes[ i ]) continue;
1816 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
1817 project.Perform( aPnt );
1818 isInsideRes[ i ] = ( project.NbPoints() > 0 &&
1819 project.LowerDistance() <= tolerance );
1820 nb_points_inside += isInsideRes[ i ];
1826 gp_Pnt aVPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ));
1827 for ( size_t i = 0; i < nb_points; i++)
1829 if ( isInsideRes[ i ]) continue;
1830 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
1831 isInsideRes[ i ] = ( aPnt.SquareDistance( aVPnt ) <= tolerance * tolerance );
1832 nb_points_inside += isInsideRes[ i ];
1837 } // switch ( aShape.ShapeType() )
1845 //=============================================================================
1849 //=============================================================================
1851 GEOMImpl_IMeasureOperations::GetMinDistance (Handle(GEOM_Object) theShape1,
1852 Handle(GEOM_Object) theShape2,
1861 Standard_Real MinDist = 1.e9;
1863 if (theShape1.IsNull() || theShape2.IsNull()) return MinDist;
1865 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
1866 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
1867 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return MinDist;
1869 TopoDS_Shape aShape1 = aRefShape1->GetValue();
1870 TopoDS_Shape aShape2 = aRefShape2->GetValue();
1871 if (aShape1.IsNull() || aShape2.IsNull()) {
1872 SetErrorCode("One of Objects has NULL Shape");
1876 //Compute the parameters
1878 #if OCC_VERSION_LARGE > 0x06010000
1882 gp_Pnt aPnt1, aPnt2;
1884 MinDist = GEOMUtils::GetMinDistance(aShape1, aShape2, aPnt1, aPnt2);
1886 if (MinDist >= 0.0) {
1887 aPnt1.Coord(X1, Y1, Z1);
1888 aPnt2.Coord(X2, Y2, Z2);
1893 catch (Standard_Failure) {
1894 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1895 SetErrorCode(aFail->GetMessageString());
1903 //=======================================================================
1905 * Get coordinates of closest points of two shapes
1907 //=======================================================================
1908 Standard_Integer GEOMImpl_IMeasureOperations::ClosestPoints (Handle(GEOM_Object) theShape1,
1909 Handle(GEOM_Object) theShape2,
1910 Handle(TColStd_HSequenceOfReal)& theDoubles)
1913 Standard_Integer nbSolutions = 0;
1915 if (theShape1.IsNull() || theShape2.IsNull()) return nbSolutions;
1917 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
1918 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
1919 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return nbSolutions;
1921 TopoDS_Shape aShape1 = aRefShape1->GetValue();
1922 TopoDS_Shape aShape2 = aRefShape2->GetValue();
1923 if (aShape1.IsNull() || aShape2.IsNull()) {
1924 SetErrorCode("One of Objects has NULL Shape");
1928 // Compute the extremities
1930 #if OCC_VERSION_LARGE > 0x06010000
1935 // additional workaround for bugs 19899, 19908 and 19910 from Mantis
1937 double dist = GEOMUtils::GetMinDistanceSingular(aShape1, aShape2, P1, P2);
1941 theDoubles->Append(P1.X());
1942 theDoubles->Append(P1.Y());
1943 theDoubles->Append(P1.Z());
1944 theDoubles->Append(P2.X());
1945 theDoubles->Append(P2.Y());
1946 theDoubles->Append(P2.Z());
1952 BRepExtrema_DistShapeShape dst (aShape1, aShape2);
1954 nbSolutions = dst.NbSolution();
1955 if (theDoubles.IsNull()) theDoubles = new TColStd_HSequenceOfReal;
1958 for (int i = 1; i <= nbSolutions; i++) {
1959 P1 = dst.PointOnShape1(i);
1960 P2 = dst.PointOnShape2(i);
1962 theDoubles->Append(P1.X());
1963 theDoubles->Append(P1.Y());
1964 theDoubles->Append(P1.Z());
1965 theDoubles->Append(P2.X());
1966 theDoubles->Append(P2.Y());
1967 theDoubles->Append(P2.Z());
1971 catch (Standard_Failure) {
1972 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1973 SetErrorCode(aFail->GetMessageString());
1981 //=======================================================================
1983 * Get coordinates of point
1985 //=======================================================================
1986 void GEOMImpl_IMeasureOperations::PointCoordinates (Handle(GEOM_Object) theShape,
1987 Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ)
1991 if (theShape.IsNull())
1994 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1995 if (aRefShape.IsNull())
1998 TopoDS_Shape aShape = aRefShape->GetValue();
1999 if (aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX)
2001 SetErrorCode( "Shape must be a vertex" );
2006 #if OCC_VERSION_LARGE > 0x06010000
2009 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
2016 catch (Standard_Failure)
2018 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2019 SetErrorCode( aFail->GetMessageString() );
2023 //=======================================================================
2025 * Compute angle (in degrees) between two lines
2027 //=======================================================================
2028 Standard_Real GEOMImpl_IMeasureOperations::GetAngle (Handle(GEOM_Object) theLine1,
2029 Handle(GEOM_Object) theLine2)
2031 if (theLine1->GetType() == GEOM_VECTOR &&
2032 theLine2->GetType() == GEOM_VECTOR)
2033 return GetAngleBtwVectors(theLine1, theLine2);
2037 Standard_Real anAngle = -1.0;
2039 if (theLine1.IsNull() || theLine2.IsNull())
2042 Handle(GEOM_Function) aRefLine1 = theLine1->GetLastFunction();
2043 Handle(GEOM_Function) aRefLine2 = theLine2->GetLastFunction();
2044 if (aRefLine1.IsNull() || aRefLine2.IsNull())
2047 TopoDS_Shape aLine1 = aRefLine1->GetValue();
2048 TopoDS_Shape aLine2 = aRefLine2->GetValue();
2049 if (aLine1.IsNull() || aLine2.IsNull() ||
2050 aLine1.ShapeType() != TopAbs_EDGE ||
2051 aLine2.ShapeType() != TopAbs_EDGE)
2053 SetErrorCode("Two edges must be given");
2058 #if OCC_VERSION_LARGE > 0x06010000
2061 TopoDS_Edge E1 = TopoDS::Edge(aLine1);
2062 TopoDS_Edge E2 = TopoDS::Edge(aLine2);
2065 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp,lp);
2066 Handle(Geom_Curve) C2 = BRep_Tool::Curve(E2,fp,lp);
2068 if ( C1.IsNull() || C2.IsNull() ||
2069 !C1->IsKind(STANDARD_TYPE(Geom_Line)) ||
2070 !C2->IsKind(STANDARD_TYPE(Geom_Line)))
2072 SetErrorCode("The edges must be linear");
2076 Handle(Geom_Line) L1 = Handle(Geom_Line)::DownCast(C1);
2077 Handle(Geom_Line) L2 = Handle(Geom_Line)::DownCast(C2);
2079 gp_Lin aLin1 = L1->Lin();
2080 gp_Lin aLin2 = L2->Lin();
2082 anAngle = aLin1.Angle(aLin2);
2083 anAngle *= 180. / M_PI; // convert radians into degrees
2085 if (anAngle > 90.0) {
2086 anAngle = 180.0 - anAngle;
2091 catch (Standard_Failure)
2093 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2094 SetErrorCode(aFail->GetMessageString());
2100 //=======================================================================
2102 * Compute angle (in degrees) between two vectors
2104 //=======================================================================
2105 Standard_Real GEOMImpl_IMeasureOperations::GetAngleBtwVectors (Handle(GEOM_Object) theVec1,
2106 Handle(GEOM_Object) theVec2)
2110 Standard_Real anAngle = -1.0;
2112 if (theVec1.IsNull() || theVec2.IsNull())
2115 if (theVec1->GetType() != GEOM_VECTOR || theVec2->GetType() != GEOM_VECTOR) {
2116 SetErrorCode("Two vectors must be given");
2120 Handle(GEOM_Function) aRefVec1 = theVec1->GetLastFunction();
2121 Handle(GEOM_Function) aRefVec2 = theVec2->GetLastFunction();
2122 if (aRefVec1.IsNull() || aRefVec2.IsNull())
2125 TopoDS_Shape aVec1 = aRefVec1->GetValue();
2126 TopoDS_Shape aVec2 = aRefVec2->GetValue();
2127 if (aVec1.IsNull() || aVec2.IsNull() ||
2128 aVec1.ShapeType() != TopAbs_EDGE ||
2129 aVec2.ShapeType() != TopAbs_EDGE)
2131 SetErrorCode("Two edges must be given");
2136 #if OCC_VERSION_LARGE > 0x06010000
2139 TopoDS_Edge aE1 = TopoDS::Edge(aVec1);
2140 TopoDS_Edge aE2 = TopoDS::Edge(aVec2);
2142 TopoDS_Vertex aP11, aP12, aP21, aP22;
2143 TopExp::Vertices(aE1, aP11, aP12, Standard_True);
2144 TopExp::Vertices(aE2, aP21, aP22, Standard_True);
2145 if (aP11.IsNull() || aP12.IsNull() || aP21.IsNull() || aP22.IsNull()) {
2146 SetErrorCode("Bad edge given");
2150 gp_Vec aV1 (BRep_Tool::Pnt(aP11), BRep_Tool::Pnt(aP12));
2151 gp_Vec aV2 (BRep_Tool::Pnt(aP21), BRep_Tool::Pnt(aP22)) ;
2153 anAngle = aV1.Angle(aV2);
2154 anAngle *= 180. / M_PI; // convert radians into degrees
2158 catch (Standard_Failure)
2160 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2161 SetErrorCode(aFail->GetMessageString());
2168 //=============================================================================
2170 * CurveCurvatureByParam
2172 //=============================================================================
2173 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByParam
2174 (Handle(GEOM_Object) theCurve, Standard_Real& theParam)
2177 Standard_Real aRes = -1.0;
2179 if(theCurve.IsNull()) return aRes;
2181 Handle(GEOM_Function) aRefShape = theCurve->GetLastFunction();
2182 if(aRefShape.IsNull()) return aRes;
2184 TopoDS_Shape aShape = aRefShape->GetValue();
2185 if(aShape.IsNull()) {
2186 SetErrorCode("One of Objects has NULL Shape");
2190 Standard_Real aFP, aLP, aP;
2191 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aFP, aLP);
2192 aP = aFP + (aLP - aFP) * theParam;
2194 if(aCurve.IsNull()) return aRes;
2198 #if OCC_VERSION_LARGE > 0x06010000
2201 GeomLProp_CLProps Prop = GeomLProp_CLProps
2202 (aCurve, aP, 2, Precision::Confusion());
2203 aRes = fabs(Prop.Curvature());
2206 catch (Standard_Failure) {
2207 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2208 SetErrorCode(aFail->GetMessageString());
2212 if( aRes > Precision::Confusion() )
2221 //=============================================================================
2223 * CurveCurvatureByPoint
2225 //=============================================================================
2226 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByPoint
2227 (Handle(GEOM_Object) theCurve, Handle(GEOM_Object) thePoint)
2230 Standard_Real aRes = -1.0;
2232 if( theCurve.IsNull() || thePoint.IsNull() ) return aRes;
2234 Handle(GEOM_Function) aRefCurve = theCurve->GetLastFunction();
2235 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2236 if( aRefCurve.IsNull() || aRefPoint.IsNull() ) return aRes;
2238 TopoDS_Edge anEdge = TopoDS::Edge(aRefCurve->GetValue());
2239 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2240 if( anEdge.IsNull() || aPnt.IsNull() ) {
2241 SetErrorCode("One of Objects has NULL Shape");
2245 Standard_Real aFP, aLP;
2246 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFP, aLP);
2247 if(aCurve.IsNull()) return aRes;
2248 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2252 #if OCC_VERSION_LARGE > 0x06010000
2255 GeomAPI_ProjectPointOnCurve PPCurve(aPoint, aCurve, aFP, aLP);
2256 if(PPCurve.NbPoints()>0) {
2257 GeomLProp_CLProps Prop = GeomLProp_CLProps
2258 (aCurve, PPCurve.LowerDistanceParameter(), 2, Precision::Confusion());
2259 aRes = fabs(Prop.Curvature());
2263 catch (Standard_Failure) {
2264 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2265 SetErrorCode(aFail->GetMessageString());
2269 if( aRes > Precision::Confusion() )
2278 //=============================================================================
2280 * getSurfaceCurvatures
2282 //=============================================================================
2283 Standard_Real GEOMImpl_IMeasureOperations::getSurfaceCurvatures
2284 (const Handle(Geom_Surface)& aSurf,
2285 Standard_Real theUParam,
2286 Standard_Real theVParam,
2287 Standard_Boolean theNeedMaxCurv)
2290 Standard_Real aRes = 1.0;
2292 if (aSurf.IsNull()) return aRes;
2295 #if OCC_VERSION_LARGE > 0x06010000
2298 GeomLProp_SLProps Prop = GeomLProp_SLProps
2299 (aSurf, theUParam, theVParam, 2, Precision::Confusion());
2300 if(Prop.IsCurvatureDefined()) {
2301 if(Prop.IsUmbilic()) {
2302 //cout<<"is umbilic"<<endl;
2303 aRes = fabs(Prop.MeanCurvature());
2306 //cout<<"is not umbilic"<<endl;
2307 double c1 = fabs(Prop.MaxCurvature());
2308 double c2 = fabs(Prop.MinCurvature());
2317 catch (Standard_Failure) {
2318 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2319 SetErrorCode(aFail->GetMessageString());
2323 if( fabs(aRes) > Precision::Confusion() )
2332 //=============================================================================
2334 * MaxSurfaceCurvatureByParam
2336 //=============================================================================
2337 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByParam
2338 (Handle(GEOM_Object) theSurf,
2339 Standard_Real& theUParam,
2340 Standard_Real& theVParam)
2343 Standard_Real aRes = -1.0;
2345 if (theSurf.IsNull()) return aRes;
2347 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2348 if(aRefShape.IsNull()) return aRes;
2350 TopoDS_Shape aShape = aRefShape->GetValue();
2351 if(aShape.IsNull()) {
2352 SetErrorCode("One of Objects has NULL Shape");
2356 TopoDS_Face F = TopoDS::Face(aShape);
2357 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2359 //Compute the parameters
2360 Standard_Real U1,U2,V1,V2;
2361 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2362 Standard_Real U = U1 + (U2-U1)*theUParam;
2363 Standard_Real V = V1 + (V2-V1)*theVParam;
2365 return getSurfaceCurvatures(aSurf, U, V, true);
2369 //=============================================================================
2371 * MaxSurfaceCurvatureByPoint
2373 //=============================================================================
2374 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByPoint
2375 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2378 Standard_Real aRes = -1.0;
2380 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2382 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2383 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2384 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2386 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2387 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2388 if( aFace.IsNull() || aPnt.IsNull() ) {
2389 SetErrorCode("One of Objects has NULL Shape");
2393 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2394 if(aSurf.IsNull()) return aRes;
2395 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2397 //Compute the parameters
2398 ShapeAnalysis_Surface sas(aSurf);
2399 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2401 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), true);
2405 //=============================================================================
2407 * MinSurfaceCurvatureByParam
2409 //=============================================================================
2410 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByParam
2411 (Handle(GEOM_Object) theSurf,
2412 Standard_Real& theUParam,
2413 Standard_Real& theVParam)
2416 Standard_Real aRes = -1.0;
2418 if (theSurf.IsNull()) return aRes;
2420 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2421 if(aRefShape.IsNull()) return aRes;
2423 TopoDS_Shape aShape = aRefShape->GetValue();
2424 if(aShape.IsNull()) {
2425 SetErrorCode("One of Objects has NULL Shape");
2429 TopoDS_Face F = TopoDS::Face(aShape);
2430 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2432 //Compute the parameters
2433 Standard_Real U1,U2,V1,V2;
2434 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2435 Standard_Real U = U1 + (U2-U1)*theUParam;
2436 Standard_Real V = V1 + (V2-V1)*theVParam;
2438 return getSurfaceCurvatures(aSurf, U, V, false);
2442 //=============================================================================
2444 * MinSurfaceCurvatureByPoint
2446 //=============================================================================
2447 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByPoint
2448 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2451 Standard_Real aRes = -1.0;
2453 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2455 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2456 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2457 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2459 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2460 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2461 if( aFace.IsNull() || aPnt.IsNull() ) {
2462 SetErrorCode("One of Objects has NULL Shape");
2466 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2467 if(aSurf.IsNull()) return aRes;
2468 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2470 //Compute the parameters
2471 ShapeAnalysis_Surface sas(aSurf);
2472 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2474 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), false);
2477 //=======================================================================
2478 //function : FillErrorsSub
2479 //purpose : Fill the errors list of subshapes on shape.
2480 //=======================================================================
2481 void GEOMImpl_IMeasureOperations::FillErrorsSub
2482 (const BRepCheck_Analyzer &theAna,
2483 const TopoDS_Shape &theShape,
2484 const TopAbs_ShapeEnum theSubType,
2485 TopTools_DataMapOfIntegerListOfShape &theMapErrors) const
2487 TopExp_Explorer anExp(theShape, theSubType);
2488 TopTools_MapOfShape aMapSubShapes;
2490 for (; anExp.More(); anExp.Next()) {
2491 const TopoDS_Shape &aSubShape = anExp.Current();
2493 if (aMapSubShapes.Add(aSubShape)) {
2494 const Handle(BRepCheck_Result) &aRes = theAna.Result(aSubShape);
2496 for (aRes->InitContextIterator();
2497 aRes->MoreShapeInContext();
2498 aRes->NextShapeInContext()) {
2499 if (aRes->ContextualShape().IsSame(theShape)) {
2500 BRepCheck_ListIteratorOfListOfStatus itl(aRes->StatusOnShape());
2502 if (itl.Value() != BRepCheck_NoError) {
2503 // Add all errors for theShape and its sub-shape.
2504 for (;itl.More(); itl.Next()) {
2505 const Standard_Integer aStat = (Standard_Integer)itl.Value();
2507 if (!theMapErrors.IsBound(aStat)) {
2508 TopTools_ListOfShape anEmpty;
2510 theMapErrors.Bind(aStat, anEmpty);
2513 TopTools_ListOfShape &theShapes = theMapErrors.ChangeFind(aStat);
2515 theShapes.Append(aSubShape);
2516 theShapes.Append(theShape);
2527 //=======================================================================
2528 //function : FillErrors
2529 //purpose : Fill the errors list.
2530 //=======================================================================
2531 void GEOMImpl_IMeasureOperations::FillErrors
2532 (const BRepCheck_Analyzer &theAna,
2533 const TopoDS_Shape &theShape,
2534 TopTools_DataMapOfIntegerListOfShape &theMapErrors,
2535 TopTools_MapOfShape &theMapShapes) const
2537 if (theMapShapes.Add(theShape)) {
2538 // Fill errors of child shapes.
2539 for (TopoDS_Iterator iter(theShape); iter.More(); iter.Next()) {
2540 FillErrors(theAna, iter.Value(), theMapErrors, theMapShapes);
2543 // Fill errors of theShape.
2544 const Handle(BRepCheck_Result) &aRes = theAna.Result(theShape);
2546 if (!aRes.IsNull()) {
2547 BRepCheck_ListIteratorOfListOfStatus itl(aRes->Status());
2549 if (itl.Value() != BRepCheck_NoError) {
2550 // Add all errors for theShape.
2551 for (;itl.More(); itl.Next()) {
2552 const Standard_Integer aStat = (Standard_Integer)itl.Value();
2554 if (!theMapErrors.IsBound(aStat)) {
2555 TopTools_ListOfShape anEmpty;
2557 theMapErrors.Bind(aStat, anEmpty);
2560 theMapErrors.ChangeFind(aStat).Append(theShape);
2565 // Add errors of subshapes on theShape.
2566 const TopAbs_ShapeEnum aType = theShape.ShapeType();
2570 FillErrorsSub(theAna, theShape, TopAbs_VERTEX, theMapErrors);
2573 FillErrorsSub(theAna, theShape, TopAbs_WIRE, theMapErrors);
2574 FillErrorsSub(theAna, theShape, TopAbs_EDGE, theMapErrors);
2575 FillErrorsSub(theAna, theShape, TopAbs_VERTEX, theMapErrors);
2578 FillErrorsSub(theAna, theShape, TopAbs_SHELL, theMapErrors);
2586 //=======================================================================
2587 //function : FillErrors
2588 //purpose : Fill the errors list.
2589 //=======================================================================
2590 void GEOMImpl_IMeasureOperations::FillErrors
2591 (const BRepCheck_Analyzer &theAna,
2592 const TopoDS_Shape &theShape,
2593 std::list<ShapeError> &theErrors) const
2595 // Fill the errors map.
2596 TopTools_DataMapOfIntegerListOfShape aMapErrors;
2597 TopTools_MapOfShape aMapShapes;
2599 FillErrors(theAna, theShape, aMapErrors, aMapShapes);
2601 // Map sub-shapes and their indices
2602 TopTools_IndexedMapOfShape anIndices;
2604 TopExp::MapShapes(theShape, anIndices);
2606 TopTools_DataMapIteratorOfDataMapOfIntegerListOfShape aMapIter(aMapErrors);
2608 for (; aMapIter.More(); aMapIter.Next()) {
2611 anError.error = (BRepCheck_Status)aMapIter.Key();
2613 TopTools_ListIteratorOfListOfShape aListIter(aMapIter.Value());
2614 TopTools_MapOfShape aMapUnique;
2616 for (; aListIter.More(); aListIter.Next()) {
2617 const TopoDS_Shape &aShape = aListIter.Value();
2619 if (aMapUnique.Add(aShape)) {
2620 const Standard_Integer anIndex = anIndices.FindIndex(aShape);
2622 anError.incriminated.push_back(anIndex);
2626 if (!anError.incriminated.empty()) {
2627 theErrors.push_back(anError);