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>
33 #include <OCC2VTK_Tools.h>
35 #include <GEOM_PythonDump.hxx>
37 #include <utilities.h>
40 #include <Bnd_Box.hxx>
41 #include <BOPAlgo_CheckerSI.hxx>
42 #include <BOPCol_ListOfShape.hxx>
43 #include <BOPDS_DS.hxx>
44 #include <BOPDS_MapOfPassKey.hxx>
45 #include <BRepBndLib.hxx>
46 #include <BRepBuilderAPI_Copy.hxx>
47 #include <BRepCheck_ListIteratorOfListOfStatus.hxx>
48 #include <BRepCheck_Shell.hxx>
49 #include <BRepClass3d_SolidClassifier.hxx>
50 #include <BRepClass_FaceClassifier.hxx>
51 #include <BRepExtrema_DistShapeShape.hxx>
52 #include <BRepExtrema_ShapeProximity.hxx>
53 #include <BRepGProp.hxx>
54 #include <BRepTools.hxx>
55 #include <BRep_Tool.hxx>
56 #include <Geom_Line.hxx>
57 #include <GeomAPI_ProjectPointOnCurve.hxx>
58 #include <GeomAPI_ProjectPointOnSurf.hxx>
59 #include <GeomLProp_CLProps.hxx>
60 #include <GeomLProp_SLProps.hxx>
61 #include <GProp_GProps.hxx>
62 #include <GProp_PrincipalProps.hxx>
63 #include <ShapeAnalysis.hxx>
64 #include <ShapeAnalysis_Surface.hxx>
66 #include <TopExp_Explorer.hxx>
68 #include <TopoDS_Edge.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 > USER_TYPE ) {
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");
749 gp_Ax3 anAx3 = GEOMUtils::GetPosition(aShape);
751 gp_Pnt anOri = anAx3.Location();
752 gp_Dir aDirZ = anAx3.Direction();
753 gp_Dir aDirX = anAx3.XDirection();
756 anOri.Coord(Ox, Oy, Oz);
757 aDirZ.Coord(Zx, Zy, Zz);
758 aDirX.Coord(Xx, Xy, Xz);
760 catch (Standard_Failure) {
761 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
762 SetErrorCode(aFail->GetMessageString());
769 //=============================================================================
773 //=============================================================================
774 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetCentreOfMass
775 (Handle(GEOM_Object) theShape)
779 if (theShape.IsNull()) return NULL;
781 //Add a new CentreOfMass object
782 Handle(GEOM_Object) aCDG = GetEngine()->AddObject(GetDocID(), GEOM_CDG);
784 //Add a new CentreOfMass function
785 Handle(GEOM_Function) aFunction =
786 aCDG->AddFunction(GEOMImpl_MeasureDriver::GetID(), CDG_MEASURE);
787 if (aFunction.IsNull()) return NULL;
789 //Check if the function is set correctly
790 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
792 GEOMImpl_IMeasure aCI (aFunction);
794 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
795 if (aRefShape.IsNull()) return NULL;
797 aCI.SetBase(aRefShape);
799 //Compute the CentreOfMass value
802 if (!GetSolver()->ComputeFunction(aFunction)) {
803 SetErrorCode("Measure driver failed to compute centre of mass");
807 catch (Standard_Failure) {
808 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
809 SetErrorCode(aFail->GetMessageString());
813 //Make a Python command
814 GEOM::TPythonDump(aFunction) << aCDG << " = geompy.MakeCDG(" << theShape << ")";
820 //=============================================================================
824 //=============================================================================
825 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetVertexByIndex
826 (Handle(GEOM_Object) theShape,
827 Standard_Integer theIndex)
831 if (theShape.IsNull()) return NULL;
833 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
834 if (aRefShape.IsNull()) return NULL;
836 //Add a new Vertex object
837 Handle(GEOM_Object) aVertex = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
840 Handle(GEOM_Function) aFunction =
841 aVertex->AddFunction(GEOMImpl_MeasureDriver::GetID(), VERTEX_BY_INDEX);
842 if (aFunction.IsNull()) return NULL;
844 //Check if the function is set correctly
845 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
847 GEOMImpl_IMeasure aCI (aFunction);
848 aCI.SetBase(aRefShape);
849 aCI.SetIndex(theIndex);
854 if (!GetSolver()->ComputeFunction(aFunction)) {
855 SetErrorCode("Vertex by index driver failed.");
859 catch (Standard_Failure) {
860 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
861 SetErrorCode(aFail->GetMessageString());
865 //Make a Python command
866 GEOM::TPythonDump(aFunction) << aVertex << " = geompy.GetVertexByIndex(" << theShape << ", " << theIndex << ")";
872 //=============================================================================
876 //=============================================================================
877 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetNormal
878 (Handle(GEOM_Object) theFace,
879 Handle(GEOM_Object) theOptionalPoint)
883 if (theFace.IsNull()) return NULL;
885 //Add a new Normale object
886 Handle(GEOM_Object) aNorm = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
888 //Add a new Normale function
889 Handle(GEOM_Function) aFunction =
890 aNorm->AddFunction(GEOMImpl_MeasureDriver::GetID(), VECTOR_FACE_NORMALE);
891 if (aFunction.IsNull()) return NULL;
893 //Check if the function is set correctly
894 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
896 GEOMImpl_IMeasure aCI (aFunction);
898 Handle(GEOM_Function) aFace = theFace->GetLastFunction();
899 if (aFace.IsNull()) return NULL;
903 if (!theOptionalPoint.IsNull()) {
904 Handle(GEOM_Function) anOptPnt = theOptionalPoint->GetLastFunction();
905 aCI.SetPoint(anOptPnt);
908 //Compute the Normale value
911 if (!GetSolver()->ComputeFunction(aFunction)) {
912 SetErrorCode("Measure driver failed to compute normake of face");
916 catch (Standard_Failure) {
917 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
918 SetErrorCode(aFail->GetMessageString());
922 //Make a Python command
923 GEOM::TPythonDump pd (aFunction);
924 pd << aNorm << " = geompy.GetNormal(" << theFace;
925 if (!theOptionalPoint.IsNull()) {
926 pd << ", " << theOptionalPoint;
934 //=============================================================================
938 //=============================================================================
939 void GEOMImpl_IMeasureOperations::GetBasicProperties (Handle(GEOM_Object) theShape,
940 Standard_Real& theLength,
941 Standard_Real& theSurfArea,
942 Standard_Real& theVolume)
946 if (theShape.IsNull()) return;
948 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
949 if (aRefShape.IsNull()) return;
951 TopoDS_Shape aShape = aRefShape->GetValue();
952 if (aShape.IsNull()) {
953 SetErrorCode("The Objects has NULL Shape");
957 //Compute the parameters
958 GProp_GProps LProps, SProps;
961 BRepGProp::LinearProperties(aShape, LProps);
962 theLength = LProps.Mass();
964 BRepGProp::SurfaceProperties(aShape, SProps);
965 theSurfArea = SProps.Mass();
968 if (aShape.ShapeType() < TopAbs_SHELL) {
969 for (TopExp_Explorer Exp (aShape, TopAbs_SOLID); Exp.More(); Exp.Next()) {
971 BRepGProp::VolumeProperties(Exp.Current(), VProps);
972 theVolume += VProps.Mass();
976 catch (Standard_Failure) {
977 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
978 SetErrorCode(aFail->GetMessageString());
985 //=============================================================================
989 //=============================================================================
990 void GEOMImpl_IMeasureOperations::GetInertia
991 (Handle(GEOM_Object) theShape,
992 Standard_Real& I11, Standard_Real& I12, Standard_Real& I13,
993 Standard_Real& I21, Standard_Real& I22, Standard_Real& I23,
994 Standard_Real& I31, Standard_Real& I32, Standard_Real& I33,
995 Standard_Real& Ix , Standard_Real& Iy , Standard_Real& Iz)
999 if (theShape.IsNull()) return;
1001 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1002 if (aRefShape.IsNull()) return;
1004 TopoDS_Shape aShape = aRefShape->GetValue();
1005 if (aShape.IsNull()) {
1006 SetErrorCode("The Objects has NULL Shape");
1010 //Compute the parameters
1011 GProp_GProps System;
1015 if (aShape.ShapeType() == TopAbs_VERTEX ||
1016 aShape.ShapeType() == TopAbs_EDGE ||
1017 aShape.ShapeType() == TopAbs_WIRE) {
1018 BRepGProp::LinearProperties(aShape, System);
1019 } else if (aShape.ShapeType() == TopAbs_FACE ||
1020 aShape.ShapeType() == TopAbs_SHELL) {
1021 BRepGProp::SurfaceProperties(aShape, System);
1023 BRepGProp::VolumeProperties(aShape, System);
1025 gp_Mat I = System.MatrixOfInertia();
1039 GProp_PrincipalProps Pr = System.PrincipalProperties();
1040 Pr.Moments(Ix,Iy,Iz);
1042 catch (Standard_Failure) {
1043 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1044 SetErrorCode(aFail->GetMessageString());
1051 //=============================================================================
1055 //=============================================================================
1056 void GEOMImpl_IMeasureOperations::GetBoundingBox
1057 (Handle(GEOM_Object) theShape,
1058 const Standard_Boolean precise,
1059 Standard_Real& Xmin, Standard_Real& Xmax,
1060 Standard_Real& Ymin, Standard_Real& Ymax,
1061 Standard_Real& Zmin, Standard_Real& Zmax)
1065 if (theShape.IsNull()) return;
1067 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1068 if (aRefShape.IsNull()) return;
1070 TopoDS_Shape aShape = aRefShape->GetValue();
1071 if (aShape.IsNull()) {
1072 SetErrorCode("The Objects has NULL Shape");
1076 //Compute the parameters
1081 BRepBuilderAPI_Copy aCopyTool (aShape);
1082 if (!aCopyTool.IsDone()) {
1083 SetErrorCode("GetBoundingBox Error: Bad shape detected");
1087 aShape = aCopyTool.Shape();
1089 // remove triangulation to obtain more exact boundaries
1090 BRepTools::Clean(aShape);
1092 BRepBndLib::Add(aShape, B);
1095 if (!GEOMUtils::PreciseBoundingBox(aShape, B)) {
1096 SetErrorCode("GetBoundingBox Error: Bounding box cannot be precised");
1101 B.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
1103 catch (Standard_Failure) {
1104 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1105 SetErrorCode(aFail->GetMessageString());
1112 //=============================================================================
1116 //=============================================================================
1117 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetBoundingBox
1118 (Handle(GEOM_Object) theShape,
1119 const Standard_Boolean precise)
1123 if (theShape.IsNull()) return NULL;
1125 //Add a new BoundingBox object
1126 Handle(GEOM_Object) aBnd = GetEngine()->AddObject(GetDocID(), GEOM_BOX);
1128 //Add a new BoundingBox function
1129 const int aType = (precise ? BND_BOX_MEASURE_PRECISE : BND_BOX_MEASURE);
1130 Handle(GEOM_Function) aFunction =
1131 aBnd->AddFunction(GEOMImpl_MeasureDriver::GetID(), aType);
1132 if (aFunction.IsNull()) return NULL;
1134 //Check if the function is set correctly
1135 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
1137 GEOMImpl_IMeasure aCI (aFunction);
1139 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1140 if (aRefShape.IsNull()) return NULL;
1142 aCI.SetBase(aRefShape);
1144 //Compute the BoundingBox value
1147 if (!GetSolver()->ComputeFunction(aFunction)) {
1148 SetErrorCode("Measure driver failed to compute a bounding box");
1152 catch (Standard_Failure) {
1153 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1154 SetErrorCode(aFail->GetMessageString());
1158 //Make a Python command
1159 GEOM::TPythonDump aPd(aFunction);
1161 aPd << aBnd << " = geompy.MakeBoundingBox(" << theShape;
1173 //=============================================================================
1177 //=============================================================================
1178 void GEOMImpl_IMeasureOperations::GetTolerance
1179 (Handle(GEOM_Object) theShape,
1180 Standard_Real& FaceMin, Standard_Real& FaceMax,
1181 Standard_Real& EdgeMin, Standard_Real& EdgeMax,
1182 Standard_Real& VertMin, Standard_Real& VertMax)
1186 if (theShape.IsNull()) return;
1188 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1189 if (aRefShape.IsNull()) return;
1191 TopoDS_Shape aShape = aRefShape->GetValue();
1192 if (aShape.IsNull()) {
1193 SetErrorCode("The Objects has NULL Shape");
1197 //Compute the parameters
1199 FaceMin = EdgeMin = VertMin = RealLast();
1200 FaceMax = EdgeMax = VertMax = -RealLast();
1204 for (TopExp_Explorer ExF (aShape, TopAbs_FACE); ExF.More(); ExF.Next()) {
1205 TopoDS_Face Face = TopoDS::Face(ExF.Current());
1206 T = BRep_Tool::Tolerance(Face);
1212 for (TopExp_Explorer ExE (aShape, TopAbs_EDGE); ExE.More(); ExE.Next()) {
1213 TopoDS_Edge Edge = TopoDS::Edge(ExE.Current());
1214 T = BRep_Tool::Tolerance(Edge);
1220 for (TopExp_Explorer ExV (aShape, TopAbs_VERTEX); ExV.More(); ExV.Next()) {
1221 TopoDS_Vertex Vertex = TopoDS::Vertex(ExV.Current());
1222 T = BRep_Tool::Tolerance(Vertex);
1229 catch (Standard_Failure) {
1230 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1231 SetErrorCode(aFail->GetMessageString());
1238 //=============================================================================
1242 //=============================================================================
1243 bool GEOMImpl_IMeasureOperations::CheckShape (Handle(GEOM_Object) theShape,
1244 const Standard_Boolean theIsCheckGeom,
1245 std::list<ShapeError> &theErrors)
1250 if (theShape.IsNull()) return false;
1252 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1253 if (aRefShape.IsNull()) return false;
1255 TopoDS_Shape aShape = aRefShape->GetValue();
1256 if (aShape.IsNull()) {
1257 SetErrorCode("The Objects has NULL Shape");
1261 //Compute the parameters
1262 bool isValid = false;
1265 BRepCheck_Analyzer ana (aShape, theIsCheckGeom);
1266 if (ana.IsValid()) {
1269 FillErrors(ana, aShape, theErrors);
1272 catch (Standard_Failure) {
1273 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1274 SetErrorCode(aFail->GetMessageString());
1282 //=============================================================================
1286 //=============================================================================
1287 TCollection_AsciiString GEOMImpl_IMeasureOperations::PrintShapeErrors
1288 (Handle(GEOM_Object) theShape,
1289 const std::list<ShapeError> &theErrors)
1291 TCollection_AsciiString aDump;
1293 if (theShape.IsNull()) {
1297 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1299 if (aRefShape.IsNull()) {
1303 TopoDS_Shape aShape = aRefShape->GetValue();
1305 if (aShape.IsNull()) {
1306 SetErrorCode("The Objects has NULL Shape");
1310 if (!theErrors.empty()) {
1311 // The shape is not valid. Prepare errors for dump.
1312 TopTools_IndexedMapOfShape anIndices;
1313 std::list<ShapeError>::const_iterator anIter = theErrors.begin();
1314 Standard_Integer nbv, nbe, nbw, nbf, nbs, nbo;
1315 nbv = nbe = nbw = nbf = nbs = nbo = 0;
1317 // Map sub-shapes and their indices
1318 TopExp::MapShapes(aShape, anIndices);
1320 const Standard_Integer aNbSubShapes = anIndices.Extent();
1321 TColStd_MapOfInteger aMapPbInd;
1323 aDump += " -- The Shape has problems :\n";
1324 aDump += " Check Count\n";
1325 aDump += " ------------------------------------------------\n";
1327 for (; anIter != theErrors.end(); anIter++) {
1328 Standard_Integer aNbShapes = anIter->incriminated.size();
1330 switch(anIter->error) {
1331 case BRepCheck_InvalidPointOnCurve:
1332 aDump += " Invalid Point on Curve ................... ";
1334 case BRepCheck_InvalidPointOnCurveOnSurface:
1335 aDump += " Invalid Point on CurveOnSurface .......... ";
1337 case BRepCheck_InvalidPointOnSurface:
1338 aDump += " Invalid Point on Surface ................. ";
1340 case BRepCheck_No3DCurve:
1341 aDump += " No 3D Curve .............................. ";
1343 case BRepCheck_Multiple3DCurve:
1344 aDump += " Multiple 3D Curve ........................ ";
1346 case BRepCheck_Invalid3DCurve:
1347 aDump += " Invalid 3D Curve ......................... ";
1349 case BRepCheck_NoCurveOnSurface:
1350 aDump += " No Curve on Surface ...................... ";
1352 case BRepCheck_InvalidCurveOnSurface:
1353 aDump += " Invalid Curve on Surface ................. ";
1355 case BRepCheck_InvalidCurveOnClosedSurface:
1356 aDump += " Invalid Curve on closed Surface .......... ";
1358 case BRepCheck_InvalidSameRangeFlag:
1359 aDump += " Invalid SameRange Flag ................... ";
1361 case BRepCheck_InvalidSameParameterFlag:
1362 aDump += " Invalid SameParameter Flag ............... ";
1364 case BRepCheck_InvalidDegeneratedFlag:
1365 aDump += " Invalid Degenerated Flag ................. ";
1367 case BRepCheck_FreeEdge:
1368 aDump += " Free Edge ................................ ";
1370 case BRepCheck_InvalidMultiConnexity:
1371 aDump += " Invalid MultiConnexity ................... ";
1373 case BRepCheck_InvalidRange:
1374 aDump += " Invalid Range ............................ ";
1376 case BRepCheck_EmptyWire:
1377 aDump += " Empty Wire ............................... ";
1379 case BRepCheck_RedundantEdge:
1380 aDump += " Redundant Edge ........................... ";
1382 case BRepCheck_SelfIntersectingWire:
1383 aDump += " Self Intersecting Wire ................... ";
1385 case BRepCheck_NoSurface:
1386 aDump += " No Surface ............................... ";
1388 case BRepCheck_InvalidWire:
1389 aDump += " Invalid Wire ............................. ";
1391 case BRepCheck_RedundantWire:
1392 aDump += " Redundant Wire ........................... ";
1394 case BRepCheck_IntersectingWires:
1395 aDump += " Intersecting Wires ....................... ";
1397 case BRepCheck_InvalidImbricationOfWires:
1398 aDump += " Invalid Imbrication of Wires ............. ";
1400 case BRepCheck_EmptyShell:
1401 aDump += " Empty Shell .............................. ";
1403 case BRepCheck_RedundantFace:
1404 aDump += " Redundant Face ........................... ";
1406 case BRepCheck_UnorientableShape:
1407 aDump += " Unorientable Shape ....................... ";
1409 case BRepCheck_NotClosed:
1410 aDump += " Not Closed ............................... ";
1412 case BRepCheck_NotConnected:
1413 aDump += " Not Connected ............................ ";
1415 case BRepCheck_SubshapeNotInShape:
1416 aDump += " Sub-shape not in Shape ................... ";
1418 case BRepCheck_BadOrientation:
1419 aDump += " Bad Orientation .......................... ";
1421 case BRepCheck_BadOrientationOfSubshape:
1422 aDump += " Bad Orientation of Sub-shape ............. ";
1424 case BRepCheck_InvalidToleranceValue:
1425 aDump += " Invalid Tolerance Value .................. ";
1427 case BRepCheck_CheckFail:
1428 aDump += " Check Shape Failure ...................... ";
1434 aDump += TCollection_AsciiString(aNbShapes) + "\n";
1436 // Count types of shape.
1437 std::list<int>::const_iterator aShIter = anIter->incriminated.begin();
1439 for (; aShIter != anIter->incriminated.end(); aShIter++) {
1440 const Standard_Integer anIndex = *aShIter;
1442 if (anIndex > 0 && anIndex <= aNbSubShapes && aMapPbInd.Add(anIndex)) {
1443 const TopoDS_Shape &aSubShape = anIndices.FindKey(anIndex);
1444 const TopAbs_ShapeEnum aType = aSubShape.ShapeType();
1447 case TopAbs_VERTEX : nbv++; break;
1448 case TopAbs_EDGE : nbe++; break;
1449 case TopAbs_WIRE : nbw++; break;
1450 case TopAbs_FACE : nbf++; break;
1451 case TopAbs_SHELL : nbs++; break;
1452 case TopAbs_SOLID : nbo++; break;
1459 const Standard_Integer aNbFaultyShapes = nbv + nbe + nbw + nbf + nbs + nbo;
1460 aDump += " ------------------------------------------------\n";
1461 aDump += "*** Shapes with problems : ";
1462 aDump += TCollection_AsciiString(aNbFaultyShapes) + "\n";
1465 aDump += "VERTEX : ";
1466 if (nbv < 10) aDump += " ";
1467 aDump += TCollection_AsciiString(nbv) + "\n";
1471 if (nbe < 10) aDump += " ";
1472 aDump += TCollection_AsciiString(nbe) + "\n";
1476 if (nbw < 10) aDump += " ";
1477 aDump += TCollection_AsciiString(nbw) + "\n";
1481 if (nbf < 10) aDump += " ";
1482 aDump += TCollection_AsciiString(nbf) + "\n";
1485 aDump += "SHELL : ";
1486 if (nbs < 10) aDump += " ";
1487 aDump += TCollection_AsciiString(nbs) + "\n";
1490 aDump += "SOLID : ";
1491 if (nbo < 10) aDump += " ";
1492 aDump += TCollection_AsciiString(nbo) + "\n";
1499 //=============================================================================
1501 * CheckSelfIntersections
1503 //=============================================================================
1504 bool GEOMImpl_IMeasureOperations::CheckSelfIntersections
1505 (Handle(GEOM_Object) theShape,
1506 const SICheckLevel theCheckLevel,
1507 Handle(TColStd_HSequenceOfInteger)& theIntersections)
1510 bool isGood = false;
1512 if (theIntersections.IsNull())
1513 theIntersections = new TColStd_HSequenceOfInteger;
1515 theIntersections->Clear();
1517 if (theShape.IsNull())
1520 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1521 if (aRefShape.IsNull()) return isGood;
1523 TopoDS_Shape aShape = aRefShape->GetValue();
1524 if (aShape.IsNull()) return isGood;
1527 TopoDS_Shape aScopy;
1529 GEOMAlgo_AlgoTools::CopyShape(aShape, aScopy);
1531 // Map sub-shapes and their indices
1532 TopTools_IndexedMapOfShape anIndices;
1533 TopExp::MapShapes(aScopy, anIndices);
1535 BOPCol_ListOfShape aLCS;
1536 aLCS.Append(aScopy);
1538 BOPAlgo_CheckerSI aCSI; // checker of self-interferences
1539 aCSI.SetArguments(aLCS);
1540 aCSI.SetLevelOfCheck(theCheckLevel);
1542 // 1. Launch the checker
1544 Standard_Integer iErr = aCSI.ErrorStatus();
1548 Standard_Integer aNbS, n1, n2;
1549 BOPDS_MapIteratorMapOfPassKey aItMPK;
1551 // 2. Take the shapes from DS
1552 const BOPDS_DS& aDS = aCSI.DS();
1553 aNbS=aDS.NbShapes();
1555 // 3. Get the pairs of interfered shapes
1556 const BOPDS_MapOfPassKey& aMPK=aDS.Interferences();
1557 aItMPK.Initialize(aMPK);
1558 for (; aItMPK.More(); aItMPK.Next()) {
1559 const BOPDS_PassKey& aPK=aItMPK.Value();
1562 if (n1 > aNbS || n2 > aNbS){
1563 return false; // Error
1565 const TopoDS_Shape& aS1 = aDS.Shape(n1);
1566 const TopoDS_Shape& aS2 = aDS.Shape(n2);
1568 theIntersections->Append(anIndices.FindIndex(aS1));
1569 theIntersections->Append(anIndices.FindIndex(aS2));
1580 //=============================================================================
1584 //=============================================================================
1585 bool GEOMImpl_IMeasureOperations::FastIntersect (Handle(GEOM_Object) theShape1, Handle(GEOM_Object) theShape2,
1586 double theTolerance, float theDeflection,
1587 Handle(TColStd_HSequenceOfInteger)& theIntersections1,
1588 Handle(TColStd_HSequenceOfInteger)& theIntersections2)
1591 bool isGood = false;
1593 if (theIntersections1.IsNull())
1594 theIntersections1 = new TColStd_HSequenceOfInteger;
1596 theIntersections1->Clear();
1598 if (theIntersections2.IsNull())
1599 theIntersections2 = new TColStd_HSequenceOfInteger;
1601 theIntersections2->Clear();
1603 if (theShape1.IsNull() || theShape2.IsNull()) {
1604 SetErrorCode("Objects have NULL Shape");
1608 if (theShape1 == theShape2) {
1609 SetErrorCode("Objects are equal");
1612 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
1613 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
1614 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return isGood;
1616 TopoDS_Shape aShape1 = aRefShape1->GetValue();
1617 TopoDS_Shape aShape2 = aRefShape2->GetValue();
1618 if (aShape1.IsNull() || aShape2.IsNull()) return isGood;
1621 TopoDS_Shape aScopy1, aScopy2;
1622 GEOMAlgo_AlgoTools::CopyShape(aShape1, aScopy1);
1623 GEOMAlgo_AlgoTools::CopyShape(aShape2, aScopy2);
1625 float aDeflection = (theDeflection <= 0.) ? 0.001 : theDeflection;
1626 GEOM::MeshShape(aScopy1, aDeflection);
1627 GEOM::MeshShape(aScopy2, aDeflection);
1629 // Map sub-shapes and their indices
1630 TopTools_IndexedMapOfShape anIndices1, anIndices2;
1631 TopExp::MapShapes(aScopy1, anIndices1);
1632 TopExp::MapShapes(aScopy2, anIndices2);
1634 BOPCol_ListOfShape aLCS1, aLCS2;
1635 aLCS1.Append(aScopy1); aLCS2.Append(aScopy2);
1637 BRepExtrema_ShapeProximity aBSP; // checker of fast interferences
1638 aBSP.LoadShape1(aScopy1); aBSP.LoadShape2(aScopy2);
1639 aBSP.SetTolerance((theTolerance <= 0.) ? 0.0 : theTolerance);
1641 // 1. Launch the checker
1644 // 2. Get sets of IDs of overlapped faces
1645 for (BRepExtrema_OverlappedSubShapes::Iterator anIt1 (aBSP.OverlapSubShapes1()); anIt1.More(); anIt1.Next()) {
1646 const TopoDS_Shape& aS1 = aBSP.GetSubShape1(anIt1.Key());
1647 theIntersections1->Append(anIndices1.FindIndex(aS1));
1650 for (BRepExtrema_OverlappedSubShapes::Iterator anIt2 (aBSP.OverlapSubShapes2()); anIt2.More(); anIt2.Next()) {
1651 const TopoDS_Shape& aS2 = aBSP.GetSubShape2(anIt2.Key());
1652 theIntersections2->Append(anIndices2.FindIndex(aS2));
1655 isGood = !theIntersections1->IsEmpty() && !theIntersections1->IsEmpty();
1662 //=============================================================================
1666 //=============================================================================
1667 TCollection_AsciiString GEOMImpl_IMeasureOperations::IsGoodForSolid (Handle(GEOM_Object) theShape)
1671 TCollection_AsciiString aRes = "";
1673 if (theShape.IsNull()) {
1674 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1677 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1678 if (aRefShape.IsNull()) {
1679 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1682 TopoDS_Shape aShape = aRefShape->GetValue();
1683 if (aShape.IsNull()) {
1684 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1687 if (aShape.ShapeType() == TopAbs_COMPOUND) {
1688 TopoDS_Iterator It (aShape, Standard_True, Standard_True);
1689 if (It.More()) aShape = It.Value();
1691 if (aShape.ShapeType() == TopAbs_SHELL) {
1692 BRepCheck_Shell chkShell (TopoDS::Shell(aShape));
1693 if (chkShell.Closed() == BRepCheck_NotClosed) {
1694 aRes = "WRN_SHAPE_UNCLOSED";
1698 aRes = "WRN_SHAPE_NOT_SHELL";
1710 //=============================================================================
1714 //=============================================================================
1715 TCollection_AsciiString GEOMImpl_IMeasureOperations::WhatIs (Handle(GEOM_Object) theShape)
1719 TCollection_AsciiString Astr;
1721 if (theShape.IsNull()) return Astr;
1723 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1724 if (aRefShape.IsNull()) return Astr;
1726 TopoDS_Shape aShape = aRefShape->GetValue();
1727 if (aShape.IsNull()) {
1728 SetErrorCode("The Objects has NULL Shape");
1732 //Compute the parameters
1733 if (aShape.ShapeType() == TopAbs_EDGE) {
1734 if (BRep_Tool::Degenerated(TopoDS::Edge(aShape))) {
1735 Astr = Astr + " It is a degenerated edge \n";
1739 Astr = Astr + " Number of sub-shapes : \n";
1743 int iType, nbTypes [TopAbs_SHAPE], nbFlatType [TopAbs_SHAPE];
1744 for (iType = 0; iType < TopAbs_SHAPE; ++iType) {
1746 nbFlatType[iType] = 0;
1748 nbTypes[aShape.ShapeType()]++;
1750 TopTools_MapOfShape aMapOfShape;
1751 aMapOfShape.Add(aShape);
1752 TopTools_ListOfShape aListOfShape;
1753 aListOfShape.Append(aShape);
1755 TopTools_ListIteratorOfListOfShape itL (aListOfShape);
1756 for (; itL.More(); itL.Next()) {
1757 TopoDS_Shape sp = itL.Value();
1758 TopoDS_Iterator it (sp);
1759 for (; it.More(); it.Next()) {
1760 TopoDS_Shape s = it.Value();
1761 if (aMapOfShape.Add(s)) {
1762 aListOfShape.Append(s);
1763 nbTypes[s.ShapeType()]++;
1764 if ((sp.ShapeType() == TopAbs_COMPOUND) || (sp.ShapeType() == TopAbs_COMPSOLID)) {
1765 nbFlatType[s.ShapeType()]++;
1771 Astr = Astr + " VERTEX : " + TCollection_AsciiString(nbTypes[TopAbs_VERTEX]) + "\n";
1772 Astr = Astr + " EDGE : " + TCollection_AsciiString(nbTypes[TopAbs_EDGE]) + "\n";
1773 Astr = Astr + " WIRE : " + TCollection_AsciiString(nbTypes[TopAbs_WIRE]) + "\n";
1774 Astr = Astr + " FACE : " + TCollection_AsciiString(nbTypes[TopAbs_FACE]) + "\n";
1775 Astr = Astr + " SHELL : " + TCollection_AsciiString(nbTypes[TopAbs_SHELL]) + "\n";
1776 Astr = Astr + " SOLID : " + TCollection_AsciiString(nbTypes[TopAbs_SOLID]) + "\n";
1777 Astr = Astr + " COMPSOLID : " + TCollection_AsciiString(nbTypes[TopAbs_COMPSOLID]) + "\n";
1778 Astr = Astr + " COMPOUND : " + TCollection_AsciiString(nbTypes[TopAbs_COMPOUND]) + "\n";
1779 Astr = Astr + " SHAPE : " + TCollection_AsciiString(aMapOfShape.Extent()) + "\n";
1781 if ((aShape.ShapeType() == TopAbs_COMPOUND) || (aShape.ShapeType() == TopAbs_COMPSOLID)){
1782 Astr = Astr + " --------------------- \n Flat content : \n";
1783 if (nbFlatType[TopAbs_VERTEX] > 0)
1784 Astr = Astr + " VERTEX : " + TCollection_AsciiString(nbFlatType[TopAbs_VERTEX]) + "\n";
1785 if (nbFlatType[TopAbs_EDGE] > 0)
1786 Astr = Astr + " EDGE : " + TCollection_AsciiString(nbFlatType[TopAbs_EDGE]) + "\n";
1787 if (nbFlatType[TopAbs_WIRE] > 0)
1788 Astr = Astr + " WIRE : " + TCollection_AsciiString(nbFlatType[TopAbs_WIRE]) + "\n";
1789 if (nbFlatType[TopAbs_FACE] > 0)
1790 Astr = Astr + " FACE : " + TCollection_AsciiString(nbFlatType[TopAbs_FACE]) + "\n";
1791 if (nbFlatType[TopAbs_SHELL] > 0)
1792 Astr = Astr + " SHELL : " + TCollection_AsciiString(nbFlatType[TopAbs_SHELL]) + "\n";
1793 if (nbFlatType[TopAbs_SOLID] > 0)
1794 Astr = Astr + " SOLID : " + TCollection_AsciiString(nbFlatType[TopAbs_SOLID]) + "\n";
1797 catch (Standard_Failure) {
1798 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1799 SetErrorCode(aFail->GetMessageString());
1807 //=============================================================================
1811 //=============================================================================
1813 GEOMImpl_IMeasureOperations::AreCoordsInside(Handle(GEOM_Object) theShape,
1814 const std::vector<double>& coords,
1817 std::vector<bool> isInsideRes;
1818 if (!theShape.IsNull()) {
1819 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1820 if (!aRefShape.IsNull()) {
1821 TopoDS_Shape aShape = aRefShape->GetValue();
1822 if (!aShape.IsNull())
1824 TopTools_IndexedMapOfShape mapShape;
1826 TopExp_Explorer anExp;
1827 for ( anExp.Init( aShape, TopAbs_SOLID ); anExp.More(); anExp.Next() )
1828 mapShape.Add( anExp.Current() );
1829 for ( anExp.Init( aShape, TopAbs_FACE, TopAbs_SOLID ); anExp.More(); anExp.Next() )
1830 mapShape.Add( anExp.Current() );
1831 for ( anExp.Init( aShape, TopAbs_EDGE, TopAbs_FACE ); anExp.More(); anExp.Next() )
1832 mapShape.Add( anExp.Current() );
1833 for ( anExp.Init( aShape, TopAbs_VERTEX, TopAbs_EDGE ); anExp.More(); anExp.Next() )
1834 mapShape.Add( anExp.Current() ); //// ?????????
1836 size_t nb_points = coords.size()/3, nb_points_inside = 0;
1837 isInsideRes.resize( nb_points, false );
1839 for ( int iS = 1; iS <= mapShape.Extent(); ++iS )
1841 if ( nb_points_inside == nb_points )
1843 aShape = mapShape( iS );
1844 switch ( aShape.ShapeType() ) {
1847 BRepClass3d_SolidClassifier SC( TopoDS::Solid( aShape ));
1848 for ( size_t i = 0; i < nb_points; i++)
1850 if ( isInsideRes[ i ]) continue;
1851 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
1852 SC.Perform( aPnt, tolerance );
1853 isInsideRes[ i ] = (( SC.State() == TopAbs_IN ) || ( SC.State() == TopAbs_ON ));
1854 nb_points_inside += isInsideRes[ i ];
1860 Standard_Real u1,u2,v1,v2;
1861 const TopoDS_Face& face = TopoDS::Face( aShape );
1862 Handle(Geom_Surface) surf = BRep_Tool::Surface( face );
1863 surf->Bounds( u1,u2,v1,v2 );
1864 GeomAPI_ProjectPointOnSurf project;
1865 project.Init(surf, u1,u2, v1,v2, tolerance );
1866 for ( size_t i = 0; i < nb_points; i++)
1868 if ( isInsideRes[ i ]) continue;
1869 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
1870 project.Perform( aPnt );
1871 if ( project.IsDone() &&
1872 project.NbPoints() > 0 &&
1873 project.LowerDistance() <= tolerance )
1875 Quantity_Parameter u, v;
1876 project.LowerDistanceParameters(u, v);
1877 gp_Pnt2d uv( u, v );
1878 BRepClass_FaceClassifier FC ( face, uv, tolerance );
1879 isInsideRes[ i ] = (( FC.State() == TopAbs_IN ) || ( FC.State() == TopAbs_ON ));
1880 nb_points_inside += isInsideRes[ i ];
1888 const TopoDS_Edge& edge = TopoDS::Edge( aShape );
1889 Handle(Geom_Curve) curve = BRep_Tool::Curve( edge, f, l );
1890 GeomAPI_ProjectPointOnCurve project;
1891 project.Init( curve, f, l );
1892 for ( size_t i = 0; i < nb_points; i++)
1894 if ( isInsideRes[ i ]) continue;
1895 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
1896 project.Perform( aPnt );
1897 isInsideRes[ i ] = ( project.NbPoints() > 0 &&
1898 project.LowerDistance() <= tolerance );
1899 nb_points_inside += isInsideRes[ i ];
1905 gp_Pnt aVPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ));
1906 for ( size_t i = 0; i < nb_points; i++)
1908 if ( isInsideRes[ i ]) continue;
1909 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
1910 isInsideRes[ i ] = ( aPnt.SquareDistance( aVPnt ) <= tolerance * tolerance );
1911 nb_points_inside += isInsideRes[ i ];
1916 } // switch ( aShape.ShapeType() )
1924 //=============================================================================
1928 //=============================================================================
1930 GEOMImpl_IMeasureOperations::GetMinDistance (Handle(GEOM_Object) theShape1,
1931 Handle(GEOM_Object) theShape2,
1940 Standard_Real MinDist = 1.e9;
1942 if (theShape1.IsNull() || theShape2.IsNull()) return MinDist;
1944 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
1945 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
1946 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return MinDist;
1948 TopoDS_Shape aShape1 = aRefShape1->GetValue();
1949 TopoDS_Shape aShape2 = aRefShape2->GetValue();
1950 if (aShape1.IsNull() || aShape2.IsNull()) {
1951 SetErrorCode("One of Objects has NULL Shape");
1955 //Compute the parameters
1959 gp_Pnt aPnt1, aPnt2;
1961 MinDist = GEOMUtils::GetMinDistance(aShape1, aShape2, aPnt1, aPnt2);
1963 if (MinDist >= 0.0) {
1964 aPnt1.Coord(X1, Y1, Z1);
1965 aPnt2.Coord(X2, Y2, Z2);
1970 catch (Standard_Failure) {
1971 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1972 SetErrorCode(aFail->GetMessageString());
1980 //=======================================================================
1982 * Get coordinates of closest points of two shapes
1984 //=======================================================================
1985 Standard_Integer GEOMImpl_IMeasureOperations::ClosestPoints (Handle(GEOM_Object) theShape1,
1986 Handle(GEOM_Object) theShape2,
1987 Handle(TColStd_HSequenceOfReal)& theDoubles)
1990 Standard_Integer nbSolutions = 0;
1992 if (theShape1.IsNull() || theShape2.IsNull()) return nbSolutions;
1994 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
1995 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
1996 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return nbSolutions;
1998 TopoDS_Shape aShape1 = aRefShape1->GetValue();
1999 TopoDS_Shape aShape2 = aRefShape2->GetValue();
2000 if (aShape1.IsNull() || aShape2.IsNull()) {
2001 SetErrorCode("One of Objects has NULL Shape");
2005 // Compute the extremities
2010 // additional workaround for bugs 19899, 19908 and 19910 from Mantis
2012 double dist = GEOMUtils::GetMinDistanceSingular(aShape1, aShape2, P1, P2);
2016 theDoubles->Append(P1.X());
2017 theDoubles->Append(P1.Y());
2018 theDoubles->Append(P1.Z());
2019 theDoubles->Append(P2.X());
2020 theDoubles->Append(P2.Y());
2021 theDoubles->Append(P2.Z());
2027 BRepExtrema_DistShapeShape dst (aShape1, aShape2);
2029 nbSolutions = dst.NbSolution();
2030 if (theDoubles.IsNull()) theDoubles = new TColStd_HSequenceOfReal;
2033 for (int i = 1; i <= nbSolutions; i++) {
2034 P1 = dst.PointOnShape1(i);
2035 P2 = dst.PointOnShape2(i);
2037 theDoubles->Append(P1.X());
2038 theDoubles->Append(P1.Y());
2039 theDoubles->Append(P1.Z());
2040 theDoubles->Append(P2.X());
2041 theDoubles->Append(P2.Y());
2042 theDoubles->Append(P2.Z());
2046 catch (Standard_Failure) {
2047 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2048 SetErrorCode(aFail->GetMessageString());
2056 //=======================================================================
2058 * Get coordinates of point
2060 //=======================================================================
2061 void GEOMImpl_IMeasureOperations::PointCoordinates (Handle(GEOM_Object) theShape,
2062 Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ)
2066 if (theShape.IsNull())
2069 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
2070 if (aRefShape.IsNull())
2073 TopoDS_Shape aShape = aRefShape->GetValue();
2074 if (aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX)
2076 SetErrorCode( "Shape must be a vertex" );
2082 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
2089 catch (Standard_Failure)
2091 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2092 SetErrorCode( aFail->GetMessageString() );
2096 //=======================================================================
2098 * Compute angle (in degrees) between two lines
2100 //=======================================================================
2101 Standard_Real GEOMImpl_IMeasureOperations::GetAngle (Handle(GEOM_Object) theLine1,
2102 Handle(GEOM_Object) theLine2)
2104 if (theLine1->GetType() == GEOM_VECTOR &&
2105 theLine2->GetType() == GEOM_VECTOR)
2106 return GetAngleBtwVectors(theLine1, theLine2);
2110 Standard_Real anAngle = -1.0;
2112 if (theLine1.IsNull() || theLine2.IsNull())
2115 Handle(GEOM_Function) aRefLine1 = theLine1->GetLastFunction();
2116 Handle(GEOM_Function) aRefLine2 = theLine2->GetLastFunction();
2117 if (aRefLine1.IsNull() || aRefLine2.IsNull())
2120 TopoDS_Shape aLine1 = aRefLine1->GetValue();
2121 TopoDS_Shape aLine2 = aRefLine2->GetValue();
2122 if (aLine1.IsNull() || aLine2.IsNull() ||
2123 aLine1.ShapeType() != TopAbs_EDGE ||
2124 aLine2.ShapeType() != TopAbs_EDGE)
2126 SetErrorCode("Two edges must be given");
2132 TopoDS_Edge E1 = TopoDS::Edge(aLine1);
2133 TopoDS_Edge E2 = TopoDS::Edge(aLine2);
2136 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp,lp);
2137 Handle(Geom_Curve) C2 = BRep_Tool::Curve(E2,fp,lp);
2139 if ( C1.IsNull() || C2.IsNull() ||
2140 !C1->IsKind(STANDARD_TYPE(Geom_Line)) ||
2141 !C2->IsKind(STANDARD_TYPE(Geom_Line)))
2143 SetErrorCode("The edges must be linear");
2147 Handle(Geom_Line) L1 = Handle(Geom_Line)::DownCast(C1);
2148 Handle(Geom_Line) L2 = Handle(Geom_Line)::DownCast(C2);
2150 gp_Lin aLin1 = L1->Lin();
2151 gp_Lin aLin2 = L2->Lin();
2153 anAngle = aLin1.Angle(aLin2);
2154 anAngle *= 180. / M_PI; // convert radians into degrees
2156 if (anAngle > 90.0) {
2157 anAngle = 180.0 - anAngle;
2162 catch (Standard_Failure)
2164 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2165 SetErrorCode(aFail->GetMessageString());
2171 //=======================================================================
2173 * Compute angle (in degrees) between two vectors
2175 //=======================================================================
2176 Standard_Real GEOMImpl_IMeasureOperations::GetAngleBtwVectors (Handle(GEOM_Object) theVec1,
2177 Handle(GEOM_Object) theVec2)
2181 Standard_Real anAngle = -1.0;
2183 if (theVec1.IsNull() || theVec2.IsNull())
2186 if (theVec1->GetType() != GEOM_VECTOR || theVec2->GetType() != GEOM_VECTOR) {
2187 SetErrorCode("Two vectors must be given");
2191 Handle(GEOM_Function) aRefVec1 = theVec1->GetLastFunction();
2192 Handle(GEOM_Function) aRefVec2 = theVec2->GetLastFunction();
2193 if (aRefVec1.IsNull() || aRefVec2.IsNull())
2196 TopoDS_Shape aVec1 = aRefVec1->GetValue();
2197 TopoDS_Shape aVec2 = aRefVec2->GetValue();
2198 if (aVec1.IsNull() || aVec2.IsNull() ||
2199 aVec1.ShapeType() != TopAbs_EDGE ||
2200 aVec2.ShapeType() != TopAbs_EDGE)
2202 SetErrorCode("Two edges must be given");
2208 TopoDS_Edge aE1 = TopoDS::Edge(aVec1);
2209 TopoDS_Edge aE2 = TopoDS::Edge(aVec2);
2211 TopoDS_Vertex aP11, aP12, aP21, aP22;
2212 TopExp::Vertices(aE1, aP11, aP12, Standard_True);
2213 TopExp::Vertices(aE2, aP21, aP22, Standard_True);
2214 if (aP11.IsNull() || aP12.IsNull() || aP21.IsNull() || aP22.IsNull()) {
2215 SetErrorCode("Bad edge given");
2219 gp_Vec aV1 (BRep_Tool::Pnt(aP11), BRep_Tool::Pnt(aP12));
2220 gp_Vec aV2 (BRep_Tool::Pnt(aP21), BRep_Tool::Pnt(aP22)) ;
2222 anAngle = aV1.Angle(aV2);
2223 anAngle *= 180. / M_PI; // convert radians into degrees
2227 catch (Standard_Failure)
2229 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2230 SetErrorCode(aFail->GetMessageString());
2237 //=============================================================================
2239 * CurveCurvatureByParam
2241 //=============================================================================
2242 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByParam
2243 (Handle(GEOM_Object) theCurve, Standard_Real& theParam)
2246 Standard_Real aRes = -1.0;
2248 if(theCurve.IsNull()) return aRes;
2250 Handle(GEOM_Function) aRefShape = theCurve->GetLastFunction();
2251 if(aRefShape.IsNull()) return aRes;
2253 TopoDS_Shape aShape = aRefShape->GetValue();
2254 if(aShape.IsNull()) {
2255 SetErrorCode("One of Objects has NULL Shape");
2259 Standard_Real aFP, aLP, aP;
2260 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aFP, aLP);
2261 aP = aFP + (aLP - aFP) * theParam;
2263 if(aCurve.IsNull()) return aRes;
2268 GeomLProp_CLProps Prop = GeomLProp_CLProps
2269 (aCurve, aP, 2, Precision::Confusion());
2270 aRes = fabs(Prop.Curvature());
2273 catch (Standard_Failure) {
2274 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2275 SetErrorCode(aFail->GetMessageString());
2279 if( aRes > Precision::Confusion() )
2288 //=============================================================================
2290 * CurveCurvatureByPoint
2292 //=============================================================================
2293 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByPoint
2294 (Handle(GEOM_Object) theCurve, Handle(GEOM_Object) thePoint)
2297 Standard_Real aRes = -1.0;
2299 if( theCurve.IsNull() || thePoint.IsNull() ) return aRes;
2301 Handle(GEOM_Function) aRefCurve = theCurve->GetLastFunction();
2302 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2303 if( aRefCurve.IsNull() || aRefPoint.IsNull() ) return aRes;
2305 TopoDS_Edge anEdge = TopoDS::Edge(aRefCurve->GetValue());
2306 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2307 if( anEdge.IsNull() || aPnt.IsNull() ) {
2308 SetErrorCode("One of Objects has NULL Shape");
2312 Standard_Real aFP, aLP;
2313 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFP, aLP);
2314 if(aCurve.IsNull()) return aRes;
2315 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2320 GeomAPI_ProjectPointOnCurve PPCurve(aPoint, aCurve, aFP, aLP);
2321 if(PPCurve.NbPoints()>0) {
2322 GeomLProp_CLProps Prop = GeomLProp_CLProps
2323 (aCurve, PPCurve.LowerDistanceParameter(), 2, Precision::Confusion());
2324 aRes = fabs(Prop.Curvature());
2328 catch (Standard_Failure) {
2329 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2330 SetErrorCode(aFail->GetMessageString());
2334 if( aRes > Precision::Confusion() )
2343 //=============================================================================
2345 * getSurfaceCurvatures
2347 //=============================================================================
2348 Standard_Real GEOMImpl_IMeasureOperations::getSurfaceCurvatures
2349 (const Handle(Geom_Surface)& aSurf,
2350 Standard_Real theUParam,
2351 Standard_Real theVParam,
2352 Standard_Boolean theNeedMaxCurv)
2355 Standard_Real aRes = 1.0;
2357 if (aSurf.IsNull()) return aRes;
2361 GeomLProp_SLProps Prop = GeomLProp_SLProps
2362 (aSurf, theUParam, theVParam, 2, Precision::Confusion());
2363 if(Prop.IsCurvatureDefined()) {
2364 if(Prop.IsUmbilic()) {
2365 //cout<<"is umbilic"<<endl;
2366 aRes = fabs(Prop.MeanCurvature());
2369 //cout<<"is not umbilic"<<endl;
2370 double c1 = fabs(Prop.MaxCurvature());
2371 double c2 = fabs(Prop.MinCurvature());
2380 catch (Standard_Failure) {
2381 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2382 SetErrorCode(aFail->GetMessageString());
2386 if( fabs(aRes) > Precision::Confusion() )
2395 //=============================================================================
2397 * MaxSurfaceCurvatureByParam
2399 //=============================================================================
2400 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByParam
2401 (Handle(GEOM_Object) theSurf,
2402 Standard_Real& theUParam,
2403 Standard_Real& theVParam)
2406 Standard_Real aRes = -1.0;
2408 if (theSurf.IsNull()) return aRes;
2410 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2411 if(aRefShape.IsNull()) return aRes;
2413 TopoDS_Shape aShape = aRefShape->GetValue();
2414 if(aShape.IsNull()) {
2415 SetErrorCode("One of Objects has NULL Shape");
2419 TopoDS_Face F = TopoDS::Face(aShape);
2420 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2422 //Compute the parameters
2423 Standard_Real U1,U2,V1,V2;
2424 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2425 Standard_Real U = U1 + (U2-U1)*theUParam;
2426 Standard_Real V = V1 + (V2-V1)*theVParam;
2428 return getSurfaceCurvatures(aSurf, U, V, true);
2432 //=============================================================================
2434 * MaxSurfaceCurvatureByPoint
2436 //=============================================================================
2437 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByPoint
2438 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2441 Standard_Real aRes = -1.0;
2443 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2445 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2446 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2447 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2449 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2450 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2451 if( aFace.IsNull() || aPnt.IsNull() ) {
2452 SetErrorCode("One of Objects has NULL Shape");
2456 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2457 if(aSurf.IsNull()) return aRes;
2458 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2460 //Compute the parameters
2461 ShapeAnalysis_Surface sas(aSurf);
2462 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2464 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), true);
2468 //=============================================================================
2470 * MinSurfaceCurvatureByParam
2472 //=============================================================================
2473 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByParam
2474 (Handle(GEOM_Object) theSurf,
2475 Standard_Real& theUParam,
2476 Standard_Real& theVParam)
2479 Standard_Real aRes = -1.0;
2481 if (theSurf.IsNull()) return aRes;
2483 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2484 if(aRefShape.IsNull()) return aRes;
2486 TopoDS_Shape aShape = aRefShape->GetValue();
2487 if(aShape.IsNull()) {
2488 SetErrorCode("One of Objects has NULL Shape");
2492 TopoDS_Face F = TopoDS::Face(aShape);
2493 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2495 //Compute the parameters
2496 Standard_Real U1,U2,V1,V2;
2497 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2498 Standard_Real U = U1 + (U2-U1)*theUParam;
2499 Standard_Real V = V1 + (V2-V1)*theVParam;
2501 return getSurfaceCurvatures(aSurf, U, V, false);
2505 //=============================================================================
2507 * MinSurfaceCurvatureByPoint
2509 //=============================================================================
2510 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByPoint
2511 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2514 Standard_Real aRes = -1.0;
2516 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2518 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2519 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2520 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2522 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2523 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2524 if( aFace.IsNull() || aPnt.IsNull() ) {
2525 SetErrorCode("One of Objects has NULL Shape");
2529 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2530 if(aSurf.IsNull()) return aRes;
2531 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2533 //Compute the parameters
2534 ShapeAnalysis_Surface sas(aSurf);
2535 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2537 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), false);
2540 //=======================================================================
2541 //function : FillErrorsSub
2542 //purpose : Fill the errors list of subshapes on shape.
2543 //=======================================================================
2544 void GEOMImpl_IMeasureOperations::FillErrorsSub
2545 (const BRepCheck_Analyzer &theAna,
2546 const TopoDS_Shape &theShape,
2547 const TopAbs_ShapeEnum theSubType,
2548 TopTools_DataMapOfIntegerListOfShape &theMapErrors) const
2550 TopExp_Explorer anExp(theShape, theSubType);
2551 TopTools_MapOfShape aMapSubShapes;
2553 for (; anExp.More(); anExp.Next()) {
2554 const TopoDS_Shape &aSubShape = anExp.Current();
2556 if (aMapSubShapes.Add(aSubShape)) {
2557 const Handle(BRepCheck_Result) &aRes = theAna.Result(aSubShape);
2559 for (aRes->InitContextIterator();
2560 aRes->MoreShapeInContext();
2561 aRes->NextShapeInContext()) {
2562 if (aRes->ContextualShape().IsSame(theShape)) {
2563 BRepCheck_ListIteratorOfListOfStatus itl(aRes->StatusOnShape());
2565 if (itl.Value() != BRepCheck_NoError) {
2566 // Add all errors for theShape and its sub-shape.
2567 for (;itl.More(); itl.Next()) {
2568 const Standard_Integer aStat = (Standard_Integer)itl.Value();
2570 if (!theMapErrors.IsBound(aStat)) {
2571 TopTools_ListOfShape anEmpty;
2573 theMapErrors.Bind(aStat, anEmpty);
2576 TopTools_ListOfShape &theShapes = theMapErrors.ChangeFind(aStat);
2578 theShapes.Append(aSubShape);
2579 theShapes.Append(theShape);
2590 //=======================================================================
2591 //function : FillErrors
2592 //purpose : Fill the errors list.
2593 //=======================================================================
2594 void GEOMImpl_IMeasureOperations::FillErrors
2595 (const BRepCheck_Analyzer &theAna,
2596 const TopoDS_Shape &theShape,
2597 TopTools_DataMapOfIntegerListOfShape &theMapErrors,
2598 TopTools_MapOfShape &theMapShapes) const
2600 if (theMapShapes.Add(theShape)) {
2601 // Fill errors of child shapes.
2602 for (TopoDS_Iterator iter(theShape); iter.More(); iter.Next()) {
2603 FillErrors(theAna, iter.Value(), theMapErrors, theMapShapes);
2606 // Fill errors of theShape.
2607 const Handle(BRepCheck_Result) &aRes = theAna.Result(theShape);
2609 if (!aRes.IsNull()) {
2610 BRepCheck_ListIteratorOfListOfStatus itl(aRes->Status());
2612 if (itl.Value() != BRepCheck_NoError) {
2613 // Add all errors for theShape.
2614 for (;itl.More(); itl.Next()) {
2615 const Standard_Integer aStat = (Standard_Integer)itl.Value();
2617 if (!theMapErrors.IsBound(aStat)) {
2618 TopTools_ListOfShape anEmpty;
2620 theMapErrors.Bind(aStat, anEmpty);
2623 theMapErrors.ChangeFind(aStat).Append(theShape);
2628 // Add errors of subshapes on theShape.
2629 const TopAbs_ShapeEnum aType = theShape.ShapeType();
2633 FillErrorsSub(theAna, theShape, TopAbs_VERTEX, theMapErrors);
2636 FillErrorsSub(theAna, theShape, TopAbs_WIRE, theMapErrors);
2637 FillErrorsSub(theAna, theShape, TopAbs_EDGE, theMapErrors);
2638 FillErrorsSub(theAna, theShape, TopAbs_VERTEX, theMapErrors);
2641 FillErrorsSub(theAna, theShape, TopAbs_SHELL, theMapErrors);
2649 //=======================================================================
2650 //function : FillErrors
2651 //purpose : Fill the errors list.
2652 //=======================================================================
2653 void GEOMImpl_IMeasureOperations::FillErrors
2654 (const BRepCheck_Analyzer &theAna,
2655 const TopoDS_Shape &theShape,
2656 std::list<ShapeError> &theErrors) const
2658 // Fill the errors map.
2659 TopTools_DataMapOfIntegerListOfShape aMapErrors;
2660 TopTools_MapOfShape aMapShapes;
2662 FillErrors(theAna, theShape, aMapErrors, aMapShapes);
2664 // Map sub-shapes and their indices
2665 TopTools_IndexedMapOfShape anIndices;
2667 TopExp::MapShapes(theShape, anIndices);
2669 TopTools_DataMapIteratorOfDataMapOfIntegerListOfShape aMapIter(aMapErrors);
2671 for (; aMapIter.More(); aMapIter.Next()) {
2674 anError.error = (BRepCheck_Status)aMapIter.Key();
2676 TopTools_ListIteratorOfListOfShape aListIter(aMapIter.Value());
2677 TopTools_MapOfShape aMapUnique;
2679 for (; aListIter.More(); aListIter.Next()) {
2680 const TopoDS_Shape &aShape = aListIter.Value();
2682 if (aMapUnique.Add(aShape)) {
2683 const Standard_Integer anIndex = anIndices.FindIndex(aShape);
2685 anError.incriminated.push_back(anIndex);
2689 if (!anError.incriminated.empty()) {
2690 theErrors.push_back(anError);