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 <BRepBndLib.hxx>
45 #include <BRepBuilderAPI_Copy.hxx>
46 #include <BRepCheck_ListIteratorOfListOfStatus.hxx>
47 #include <BRepCheck_Shell.hxx>
48 #include <BRepClass3d_SolidClassifier.hxx>
49 #include <BRepClass_FaceClassifier.hxx>
50 #include <BRepExtrema_DistShapeShape.hxx>
51 #include <BRepGProp.hxx>
52 #include <BRepTools.hxx>
53 #include <BRep_Tool.hxx>
54 #include <Geom_Line.hxx>
55 #include <GeomAPI_ProjectPointOnCurve.hxx>
56 #include <GeomAPI_ProjectPointOnSurf.hxx>
57 #include <GeomLProp_CLProps.hxx>
58 #include <GeomLProp_SLProps.hxx>
59 #include <GProp_GProps.hxx>
60 #include <GProp_PrincipalProps.hxx>
61 #include <ShapeAnalysis.hxx>
62 #include <ShapeAnalysis_Surface.hxx>
64 #include <TopExp_Explorer.hxx>
66 #include <TopoDS_Edge.hxx>
67 #include <TopTools_IndexedMapOfShape.hxx>
68 #include <TopTools_DataMapIteratorOfDataMapOfIntegerListOfShape.hxx>
69 #include <TopTools_ListIteratorOfListOfShape.hxx>
70 #include <TopTools_ListOfShape.hxx>
71 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
73 //=============================================================================
77 //=============================================================================
78 GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations (GEOM_Engine* theEngine, int theDocID)
79 : GEOM_IOperations(theEngine, theDocID)
81 MESSAGE("GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations");
84 //=============================================================================
88 //=============================================================================
89 GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations()
91 MESSAGE("GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations");
94 //=============================================================================
95 /*! Get kind and parameters of the given shape.
97 //=============================================================================
98 GEOMImpl_IMeasureOperations::ShapeKind GEOMImpl_IMeasureOperations::KindOfShape
99 (Handle(GEOM_Object) theShape,
100 Handle(TColStd_HSequenceOfInteger)& theIntegers,
101 Handle(TColStd_HSequenceOfReal)& theDoubles)
104 ShapeKind aKind = SK_NO_SHAPE;
106 if (theIntegers.IsNull()) theIntegers = new TColStd_HSequenceOfInteger;
107 else theIntegers->Clear();
109 if (theDoubles.IsNull()) theDoubles = new TColStd_HSequenceOfReal;
110 else theDoubles->Clear();
112 if (theShape.IsNull())
115 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
116 if (aRefShape.IsNull()) return aKind;
118 TopoDS_Shape aShape = aRefShape->GetValue();
119 if (aShape.IsNull()) return aKind;
121 int geom_type = theShape->GetType();
123 // check if it's advanced shape
124 if ( geom_type > ADVANCED_BASE ) {
130 GEOMAlgo_ShapeInfoFiller aSF;
131 aSF.SetShape(aShape);
133 Standard_Integer iErr = aSF.ErrorStatus();
135 SetErrorCode("Error in GEOMAlgo_ShapeInfoFiller");
138 const GEOMAlgo_ShapeInfo& anInfo = aSF.Info();
140 // Interprete results
141 TopAbs_ShapeEnum aType = anInfo.Type();
144 case TopAbs_COMPOUND:
145 case TopAbs_COMPSOLID:
147 // (+) geompy.kind.COMPOUND nb_solids nb_faces nb_edges nb_vertices
148 // (+) geompy.kind.COMPSOLID nb_solids nb_faces nb_edges nb_vertices
149 // ??? "nb_faces" - all faces or only 'standalone' faces?
150 if (aType == TopAbs_COMPOUND)
153 aKind = SK_COMPSOLID;
155 //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPOUND));
156 //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPSOLID));
157 theIntegers->Append(anInfo.NbSubShapes(TopAbs_SOLID));
158 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
159 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
160 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
166 // (+) geompy.kind.SHELL geompy.info.closed nb_faces nb_edges nb_vertices
167 // (+) geompy.kind.SHELL geompy.info.unclosed nb_faces nb_edges nb_vertices
170 theIntegers->Append((int)anInfo.KindOfClosed());
172 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
173 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
174 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
180 // (+) geompy.kind.WIRE geompy.info.closed nb_edges nb_vertices
181 // (+) geompy.kind.WIRE geompy.info.unclosed nb_edges nb_vertices
184 theIntegers->Append((int)anInfo.KindOfClosed());
186 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
187 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
195 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
198 case GEOMAlgo_KN_SPHERE:
199 // (+) geompy.kind.SPHERE xc yc zc R
203 gp_Pnt aC = anInfo.Location();
204 theDoubles->Append(aC.X());
205 theDoubles->Append(aC.Y());
206 theDoubles->Append(aC.Z());
208 theDoubles->Append(anInfo.Radius1());
211 case GEOMAlgo_KN_CYLINDER:
212 // (+) geompy.kind.CYLINDER xb yb zb dx dy dz R H
216 gp_Pnt aC = anInfo.Location();
217 theDoubles->Append(aC.X());
218 theDoubles->Append(aC.Y());
219 theDoubles->Append(aC.Z());
221 gp_Ax3 anAx3 = anInfo.Position();
222 gp_Dir aD = anAx3.Direction();
223 theDoubles->Append(aD.X());
224 theDoubles->Append(aD.Y());
225 theDoubles->Append(aD.Z());
227 theDoubles->Append(anInfo.Radius1());
228 theDoubles->Append(anInfo.Height());
231 case GEOMAlgo_KN_BOX:
232 // (+) geompy.kind.BOX xc yc zc ax ay az
236 gp_Pnt aC = anInfo.Location();
237 theDoubles->Append(aC.X());
238 theDoubles->Append(aC.Y());
239 theDoubles->Append(aC.Z());
241 gp_Ax3 anAx3 = anInfo.Position();
242 gp_Dir aD = anAx3.Direction();
243 gp_Dir aX = anAx3.XDirection();
246 if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
247 aX.IsParallel(gp::DX(), Precision::Angular())) {
248 theDoubles->Append(anInfo.Length()); // ax'
249 theDoubles->Append(anInfo.Width()); // ay'
250 theDoubles->Append(anInfo.Height()); // az'
252 else if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
253 aX.IsParallel(gp::DY(), Precision::Angular())) {
254 theDoubles->Append(anInfo.Width()); // ay'
255 theDoubles->Append(anInfo.Length()); // ax'
256 theDoubles->Append(anInfo.Height()); // az'
258 else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
259 aX.IsParallel(gp::DZ(), Precision::Angular())) {
260 theDoubles->Append(anInfo.Height()); // az'
261 theDoubles->Append(anInfo.Width()); // ay'
262 theDoubles->Append(anInfo.Length()); // ax'
264 else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
265 aX.IsParallel(gp::DY(), Precision::Angular())) {
266 theDoubles->Append(anInfo.Height()); // az'
267 theDoubles->Append(anInfo.Length()); // ax'
268 theDoubles->Append(anInfo.Width()); // ay'
270 else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
271 aX.IsParallel(gp::DZ(), Precision::Angular())) {
272 theDoubles->Append(anInfo.Width()); // ay'
273 theDoubles->Append(anInfo.Height()); // az'
274 theDoubles->Append(anInfo.Length()); // ax'
276 else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
277 aX.IsParallel(gp::DX(), Precision::Angular())) {
278 theDoubles->Append(anInfo.Length()); // ax'
279 theDoubles->Append(anInfo.Height()); // az'
280 theDoubles->Append(anInfo.Width()); // ay'
283 // (+) geompy.kind.ROTATED_BOX xo yo zo zx zy zz xx xy xz ax ay az
284 aKind = SK_ROTATED_BOX;
286 // Direction and XDirection
287 theDoubles->Append(aD.X());
288 theDoubles->Append(aD.Y());
289 theDoubles->Append(aD.Z());
291 theDoubles->Append(aX.X());
292 theDoubles->Append(aX.Y());
293 theDoubles->Append(aX.Z());
296 theDoubles->Append(anInfo.Length());
297 theDoubles->Append(anInfo.Width());
298 theDoubles->Append(anInfo.Height());
302 case GEOMAlgo_KN_TORUS:
303 // (+) geompy.kind.TORUS xc yc zc dx dy dz R_1 R_2
307 gp_Pnt aO = anInfo.Location();
308 theDoubles->Append(aO.X());
309 theDoubles->Append(aO.Y());
310 theDoubles->Append(aO.Z());
312 gp_Ax3 anAx3 = anInfo.Position();
313 gp_Dir aD = anAx3.Direction();
314 theDoubles->Append(aD.X());
315 theDoubles->Append(aD.Y());
316 theDoubles->Append(aD.Z());
318 theDoubles->Append(anInfo.Radius1());
319 theDoubles->Append(anInfo.Radius2());
322 case GEOMAlgo_KN_CONE:
323 // (+) geompy.kind.CONE xb yb zb dx dy dz R_1 R_2 H
327 gp_Pnt aO = anInfo.Location();
328 theDoubles->Append(aO.X());
329 theDoubles->Append(aO.Y());
330 theDoubles->Append(aO.Z());
332 gp_Ax3 anAx3 = anInfo.Position();
333 gp_Dir aD = anAx3.Direction();
334 theDoubles->Append(aD.X());
335 theDoubles->Append(aD.Y());
336 theDoubles->Append(aD.Z());
338 theDoubles->Append(anInfo.Radius1());
339 theDoubles->Append(anInfo.Radius2());
340 theDoubles->Append(anInfo.Height());
343 case GEOMAlgo_KN_POLYHEDRON:
344 // (+) geompy.kind.POLYHEDRON nb_faces nb_edges nb_vertices
346 aKind = SK_POLYHEDRON;
348 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
349 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
350 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
354 // (+) geompy.kind.SOLID nb_faces nb_edges nb_vertices
356 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
357 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
358 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
368 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
370 case GEOMAlgo_KN_SPHERE:
371 // (+) geompy.kind.SPHERE2D xc yc zc R
375 gp_Pnt aC = anInfo.Location();
376 theDoubles->Append(aC.X());
377 theDoubles->Append(aC.Y());
378 theDoubles->Append(aC.Z());
380 theDoubles->Append(anInfo.Radius1());
383 case GEOMAlgo_KN_CYLINDER:
384 // (+) geompy.kind.CYLINDER2D xb yb zb dx dy dz R H
386 aKind = SK_CYLINDER2D;
388 gp_Pnt aO = anInfo.Location();
389 theDoubles->Append(aO.X());
390 theDoubles->Append(aO.Y());
391 theDoubles->Append(aO.Z());
393 gp_Ax3 anAx3 = anInfo.Position();
394 gp_Dir aD = anAx3.Direction();
395 theDoubles->Append(aD.X());
396 theDoubles->Append(aD.Y());
397 theDoubles->Append(aD.Z());
399 theDoubles->Append(anInfo.Radius1());
400 theDoubles->Append(anInfo.Height());
403 case GEOMAlgo_KN_TORUS:
404 // (+) geompy.kind.TORUS2D xc yc zc dx dy dz R_1 R_2
408 gp_Pnt aO = anInfo.Location();
409 theDoubles->Append(aO.X());
410 theDoubles->Append(aO.Y());
411 theDoubles->Append(aO.Z());
413 gp_Ax3 anAx3 = anInfo.Position();
414 gp_Dir aD = anAx3.Direction();
415 theDoubles->Append(aD.X());
416 theDoubles->Append(aD.Y());
417 theDoubles->Append(aD.Z());
419 theDoubles->Append(anInfo.Radius1());
420 theDoubles->Append(anInfo.Radius2());
423 case GEOMAlgo_KN_CONE:
424 // (+) geompy.kind.CONE2D xc yc zc dx dy dz R_1 R_2 H
428 gp_Pnt aO = anInfo.Location();
429 theDoubles->Append(aO.X());
430 theDoubles->Append(aO.Y());
431 theDoubles->Append(aO.Z());
433 gp_Ax3 anAx3 = anInfo.Position();
434 gp_Dir aD = anAx3.Direction();
435 theDoubles->Append(aD.X());
436 theDoubles->Append(aD.Y());
437 theDoubles->Append(aD.Z());
439 theDoubles->Append(anInfo.Radius1());
440 theDoubles->Append(anInfo.Radius2());
441 theDoubles->Append(anInfo.Height());
444 case GEOMAlgo_KN_DISKCIRCLE:
445 // (+) geompy.kind.DISK_CIRCLE xc yc zc dx dy dz R
447 aKind = SK_DISK_CIRCLE;
449 gp_Pnt aC = anInfo.Location();
450 theDoubles->Append(aC.X());
451 theDoubles->Append(aC.Y());
452 theDoubles->Append(aC.Z());
454 gp_Ax3 anAx3 = anInfo.Position();
455 gp_Dir aD = anAx3.Direction();
456 theDoubles->Append(aD.X());
457 theDoubles->Append(aD.Y());
458 theDoubles->Append(aD.Z());
460 theDoubles->Append(anInfo.Radius1());
463 case GEOMAlgo_KN_DISKELLIPSE:
464 // (+) geompy.kind.DISK_ELLIPSE xc yc zc dx dy dz R_1 R_2
466 aKind = SK_DISK_ELLIPSE;
468 gp_Pnt aC = anInfo.Location();
469 theDoubles->Append(aC.X());
470 theDoubles->Append(aC.Y());
471 theDoubles->Append(aC.Z());
473 gp_Ax3 anAx3 = anInfo.Position();
474 gp_Dir aD = anAx3.Direction();
475 theDoubles->Append(aD.X());
476 theDoubles->Append(aD.Y());
477 theDoubles->Append(aD.Z());
479 theDoubles->Append(anInfo.Radius1());
480 theDoubles->Append(anInfo.Radius2());
483 case GEOMAlgo_KN_RECTANGLE:
484 case GEOMAlgo_KN_TRIANGLE:
485 case GEOMAlgo_KN_QUADRANGLE:
486 case GEOMAlgo_KN_POLYGON:
487 // (+) geompy.kind.POLYGON xo yo zo dx dy dz nb_edges nb_vertices
491 gp_Pnt aO = anInfo.Location();
492 theDoubles->Append(aO.X());
493 theDoubles->Append(aO.Y());
494 theDoubles->Append(aO.Z());
496 gp_Ax3 anAx3 = anInfo.Position();
497 gp_Dir aD = anAx3.Direction();
498 theDoubles->Append(aD.X());
499 theDoubles->Append(aD.Y());
500 theDoubles->Append(aD.Z());
502 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
503 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
506 case GEOMAlgo_KN_PLANE: // infinite
507 // (+) geompy.kind.PLANE xo yo zo dx dy dz
511 gp_Pnt aC = anInfo.Location();
512 theDoubles->Append(aC.X());
513 theDoubles->Append(aC.Y());
514 theDoubles->Append(aC.Z());
516 gp_Ax3 anAx3 = anInfo.Position();
517 gp_Dir aD = anAx3.Direction();
518 theDoubles->Append(aD.X());
519 theDoubles->Append(aD.Y());
520 theDoubles->Append(aD.Z());
524 if (anInfo.KindOfShape() == GEOMAlgo_KS_PLANE) {
525 // (+) geompy.kind.PLANAR xo yo zo dx dy dz nb_edges nb_vertices
529 gp_Pnt aC = anInfo.Location();
530 theDoubles->Append(aC.X());
531 theDoubles->Append(aC.Y());
532 theDoubles->Append(aC.Z());
534 gp_Ax3 anAx3 = anInfo.Position();
535 gp_Dir aD = anAx3.Direction();
536 theDoubles->Append(aD.X());
537 theDoubles->Append(aD.Y());
538 theDoubles->Append(aD.Z());
540 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
541 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
544 // ??? geompy.kind.FACE nb_edges nb_vertices _surface_type_id_
545 // (+) geompy.kind.FACE nb_edges nb_vertices
547 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
548 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
558 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
560 case GEOMAlgo_KN_CIRCLE:
562 // (+) geompy.kind.CIRCLE xc yc zc dx dy dz R
565 gp_Pnt aC = anInfo.Location();
566 theDoubles->Append(aC.X());
567 theDoubles->Append(aC.Y());
568 theDoubles->Append(aC.Z());
570 gp_Ax3 anAx3 = anInfo.Position();
571 gp_Dir aD = anAx3.Direction();
572 theDoubles->Append(aD.X());
573 theDoubles->Append(aD.Y());
574 theDoubles->Append(aD.Z());
576 theDoubles->Append(anInfo.Radius1());
579 case GEOMAlgo_KN_ARCCIRCLE:
581 // (+) geompy.kind.ARC_CIRCLE xc yc zc dx dy dz R x1 y1 z1 x2 y2 z2
582 aKind = SK_ARC_CIRCLE;
584 gp_Pnt aC = anInfo.Location();
585 theDoubles->Append(aC.X());
586 theDoubles->Append(aC.Y());
587 theDoubles->Append(aC.Z());
589 gp_Ax3 anAx3 = anInfo.Position();
590 gp_Dir aD = anAx3.Direction();
591 theDoubles->Append(aD.X());
592 theDoubles->Append(aD.Y());
593 theDoubles->Append(aD.Z());
595 theDoubles->Append(anInfo.Radius1());
597 gp_Pnt aP1 = anInfo.Pnt1();
598 theDoubles->Append(aP1.X());
599 theDoubles->Append(aP1.Y());
600 theDoubles->Append(aP1.Z());
602 gp_Pnt aP2 = anInfo.Pnt2();
603 theDoubles->Append(aP2.X());
604 theDoubles->Append(aP2.Y());
605 theDoubles->Append(aP2.Z());
608 case GEOMAlgo_KN_ELLIPSE:
610 // (+) geompy.kind.ELLIPSE xc yc zc dx dy dz R_1 R_2
613 gp_Pnt aC = anInfo.Location();
614 theDoubles->Append(aC.X());
615 theDoubles->Append(aC.Y());
616 theDoubles->Append(aC.Z());
618 gp_Ax3 anAx3 = anInfo.Position();
619 gp_Dir aD = anAx3.Direction();
620 theDoubles->Append(aD.X());
621 theDoubles->Append(aD.Y());
622 theDoubles->Append(aD.Z());
624 theDoubles->Append(anInfo.Radius1());
625 theDoubles->Append(anInfo.Radius2());
628 case GEOMAlgo_KN_ARCELLIPSE:
630 // (+) geompy.kind.ARC_ELLIPSE xc yc zc dx dy dz R_1 R_2 x1 y1 z1 x2 y2 z2
631 aKind = SK_ARC_ELLIPSE;
633 gp_Pnt aC = anInfo.Location();
634 theDoubles->Append(aC.X());
635 theDoubles->Append(aC.Y());
636 theDoubles->Append(aC.Z());
638 gp_Ax3 anAx3 = anInfo.Position();
639 gp_Dir aD = anAx3.Direction();
640 theDoubles->Append(aD.X());
641 theDoubles->Append(aD.Y());
642 theDoubles->Append(aD.Z());
644 theDoubles->Append(anInfo.Radius1());
645 theDoubles->Append(anInfo.Radius2());
647 gp_Pnt aP1 = anInfo.Pnt1();
648 theDoubles->Append(aP1.X());
649 theDoubles->Append(aP1.Y());
650 theDoubles->Append(aP1.Z());
652 gp_Pnt aP2 = anInfo.Pnt2();
653 theDoubles->Append(aP2.X());
654 theDoubles->Append(aP2.Y());
655 theDoubles->Append(aP2.Z());
658 case GEOMAlgo_KN_LINE:
660 // ??? geompy.kind.LINE x1 y1 z1 x2 y2 z2
661 // (+) geompy.kind.LINE x1 y1 z1 dx dy dz
664 gp_Pnt aO = anInfo.Location();
665 theDoubles->Append(aO.X());
666 theDoubles->Append(aO.Y());
667 theDoubles->Append(aO.Z());
669 gp_Dir aD = anInfo.Direction();
670 theDoubles->Append(aD.X());
671 theDoubles->Append(aD.Y());
672 theDoubles->Append(aD.Z());
675 case GEOMAlgo_KN_SEGMENT:
677 // (+) geompy.kind.SEGMENT x1 y1 z1 x2 y2 z2
680 gp_Pnt aP1 = anInfo.Pnt1();
681 theDoubles->Append(aP1.X());
682 theDoubles->Append(aP1.Y());
683 theDoubles->Append(aP1.Z());
685 gp_Pnt aP2 = anInfo.Pnt2();
686 theDoubles->Append(aP2.X());
687 theDoubles->Append(aP2.Y());
688 theDoubles->Append(aP2.Z());
692 // ??? geompy.kind.EDGE nb_vertices _curve_type_id_
693 // (+) geompy.kind.EDGE nb_vertices
694 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
701 // (+) geompy.kind.VERTEX x y z
704 gp_Pnt aP = anInfo.Location();
705 theDoubles->Append(aP.X());
706 theDoubles->Append(aP.Y());
707 theDoubles->Append(aP.Z());
716 //=============================================================================
720 //=============================================================================
721 void GEOMImpl_IMeasureOperations::GetPosition
722 (Handle(GEOM_Object) theShape,
723 Standard_Real& Ox, Standard_Real& Oy, Standard_Real& Oz,
724 Standard_Real& Zx, Standard_Real& Zy, Standard_Real& Zz,
725 Standard_Real& Xx, Standard_Real& Xy, Standard_Real& Xz)
729 //Set default values: global CS
730 Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
733 if (theShape.IsNull()) return;
735 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
736 if (aRefShape.IsNull()) return;
738 TopoDS_Shape aShape = aRefShape->GetValue();
739 if (aShape.IsNull()) {
740 SetErrorCode("The Objects has NULL Shape");
747 gp_Ax3 anAx3 = GEOMUtils::GetPosition(aShape);
749 gp_Pnt anOri = anAx3.Location();
750 gp_Dir aDirZ = anAx3.Direction();
751 gp_Dir aDirX = anAx3.XDirection();
754 anOri.Coord(Ox, Oy, Oz);
755 aDirZ.Coord(Zx, Zy, Zz);
756 aDirX.Coord(Xx, Xy, Xz);
758 catch (Standard_Failure) {
759 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
760 SetErrorCode(aFail->GetMessageString());
767 //=============================================================================
771 //=============================================================================
772 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetCentreOfMass
773 (Handle(GEOM_Object) theShape)
777 if (theShape.IsNull()) return NULL;
779 //Add a new CentreOfMass object
780 Handle(GEOM_Object) aCDG = GetEngine()->AddObject(GetDocID(), GEOM_CDG);
782 //Add a new CentreOfMass function
783 Handle(GEOM_Function) aFunction =
784 aCDG->AddFunction(GEOMImpl_MeasureDriver::GetID(), CDG_MEASURE);
785 if (aFunction.IsNull()) return NULL;
787 //Check if the function is set correctly
788 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
790 GEOMImpl_IMeasure aCI (aFunction);
792 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
793 if (aRefShape.IsNull()) return NULL;
795 aCI.SetBase(aRefShape);
797 //Compute the CentreOfMass value
800 if (!GetSolver()->ComputeFunction(aFunction)) {
801 SetErrorCode("Measure driver failed to compute centre of mass");
805 catch (Standard_Failure) {
806 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
807 SetErrorCode(aFail->GetMessageString());
811 //Make a Python command
812 GEOM::TPythonDump(aFunction) << aCDG << " = geompy.MakeCDG(" << theShape << ")";
818 //=============================================================================
822 //=============================================================================
823 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetVertexByIndex
824 (Handle(GEOM_Object) theShape,
825 Standard_Integer theIndex)
829 if (theShape.IsNull()) return NULL;
831 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
832 if (aRefShape.IsNull()) return NULL;
834 //Add a new Vertex object
835 Handle(GEOM_Object) aVertex = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
838 Handle(GEOM_Function) aFunction =
839 aVertex->AddFunction(GEOMImpl_MeasureDriver::GetID(), VERTEX_BY_INDEX);
840 if (aFunction.IsNull()) return NULL;
842 //Check if the function is set correctly
843 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
845 GEOMImpl_IMeasure aCI (aFunction);
846 aCI.SetBase(aRefShape);
847 aCI.SetIndex(theIndex);
852 if (!GetSolver()->ComputeFunction(aFunction)) {
853 SetErrorCode("Vertex by index driver failed.");
857 catch (Standard_Failure) {
858 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
859 SetErrorCode(aFail->GetMessageString());
863 //Make a Python command
864 GEOM::TPythonDump(aFunction) << aVertex << " = geompy.GetVertexByIndex(" << theShape << ", " << theIndex << ")";
870 //=============================================================================
874 //=============================================================================
875 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetNormal
876 (Handle(GEOM_Object) theFace,
877 Handle(GEOM_Object) theOptionalPoint)
881 if (theFace.IsNull()) return NULL;
883 //Add a new Normale object
884 Handle(GEOM_Object) aNorm = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
886 //Add a new Normale function
887 Handle(GEOM_Function) aFunction =
888 aNorm->AddFunction(GEOMImpl_MeasureDriver::GetID(), VECTOR_FACE_NORMALE);
889 if (aFunction.IsNull()) return NULL;
891 //Check if the function is set correctly
892 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
894 GEOMImpl_IMeasure aCI (aFunction);
896 Handle(GEOM_Function) aFace = theFace->GetLastFunction();
897 if (aFace.IsNull()) return NULL;
901 if (!theOptionalPoint.IsNull()) {
902 Handle(GEOM_Function) anOptPnt = theOptionalPoint->GetLastFunction();
903 aCI.SetPoint(anOptPnt);
906 //Compute the Normale value
909 if (!GetSolver()->ComputeFunction(aFunction)) {
910 SetErrorCode("Measure driver failed to compute normake of face");
914 catch (Standard_Failure) {
915 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
916 SetErrorCode(aFail->GetMessageString());
920 //Make a Python command
921 GEOM::TPythonDump pd (aFunction);
922 pd << aNorm << " = geompy.GetNormal(" << theFace;
923 if (!theOptionalPoint.IsNull()) {
924 pd << ", " << theOptionalPoint;
932 //=============================================================================
936 //=============================================================================
937 void GEOMImpl_IMeasureOperations::GetBasicProperties (Handle(GEOM_Object) theShape,
938 Standard_Real& theLength,
939 Standard_Real& theSurfArea,
940 Standard_Real& theVolume)
944 if (theShape.IsNull()) return;
946 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
947 if (aRefShape.IsNull()) return;
949 TopoDS_Shape aShape = aRefShape->GetValue();
950 if (aShape.IsNull()) {
951 SetErrorCode("The Objects has NULL Shape");
955 //Compute the parameters
956 GProp_GProps LProps, SProps;
959 BRepGProp::LinearProperties(aShape, LProps);
960 theLength = LProps.Mass();
962 BRepGProp::SurfaceProperties(aShape, SProps);
963 theSurfArea = SProps.Mass();
966 if (aShape.ShapeType() < TopAbs_SHELL) {
967 for (TopExp_Explorer Exp (aShape, TopAbs_SOLID); Exp.More(); Exp.Next()) {
969 BRepGProp::VolumeProperties(Exp.Current(), VProps);
970 theVolume += VProps.Mass();
974 catch (Standard_Failure) {
975 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
976 SetErrorCode(aFail->GetMessageString());
983 //=============================================================================
987 //=============================================================================
988 void GEOMImpl_IMeasureOperations::GetInertia
989 (Handle(GEOM_Object) theShape,
990 Standard_Real& I11, Standard_Real& I12, Standard_Real& I13,
991 Standard_Real& I21, Standard_Real& I22, Standard_Real& I23,
992 Standard_Real& I31, Standard_Real& I32, Standard_Real& I33,
993 Standard_Real& Ix , Standard_Real& Iy , Standard_Real& Iz)
997 if (theShape.IsNull()) return;
999 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1000 if (aRefShape.IsNull()) return;
1002 TopoDS_Shape aShape = aRefShape->GetValue();
1003 if (aShape.IsNull()) {
1004 SetErrorCode("The Objects has NULL Shape");
1008 //Compute the parameters
1009 GProp_GProps System;
1013 if (aShape.ShapeType() == TopAbs_VERTEX ||
1014 aShape.ShapeType() == TopAbs_EDGE ||
1015 aShape.ShapeType() == TopAbs_WIRE) {
1016 BRepGProp::LinearProperties(aShape, System);
1017 } else if (aShape.ShapeType() == TopAbs_FACE ||
1018 aShape.ShapeType() == TopAbs_SHELL) {
1019 BRepGProp::SurfaceProperties(aShape, System);
1021 BRepGProp::VolumeProperties(aShape, System);
1023 gp_Mat I = System.MatrixOfInertia();
1037 GProp_PrincipalProps Pr = System.PrincipalProperties();
1038 Pr.Moments(Ix,Iy,Iz);
1040 catch (Standard_Failure) {
1041 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1042 SetErrorCode(aFail->GetMessageString());
1049 //=============================================================================
1053 //=============================================================================
1054 void GEOMImpl_IMeasureOperations::GetBoundingBox
1055 (Handle(GEOM_Object) theShape,
1056 const Standard_Boolean precise,
1057 Standard_Real& Xmin, Standard_Real& Xmax,
1058 Standard_Real& Ymin, Standard_Real& Ymax,
1059 Standard_Real& Zmin, Standard_Real& Zmax)
1063 if (theShape.IsNull()) return;
1065 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1066 if (aRefShape.IsNull()) return;
1068 TopoDS_Shape aShape = aRefShape->GetValue();
1069 if (aShape.IsNull()) {
1070 SetErrorCode("The Objects has NULL Shape");
1074 //Compute the parameters
1079 BRepBuilderAPI_Copy aCopyTool (aShape);
1080 if (!aCopyTool.IsDone()) {
1081 SetErrorCode("GetBoundingBox Error: Bad shape detected");
1085 aShape = aCopyTool.Shape();
1087 // remove triangulation to obtain more exact boundaries
1088 BRepTools::Clean(aShape);
1090 BRepBndLib::Add(aShape, B);
1093 if (!GEOMUtils::PreciseBoundingBox(aShape, B)) {
1094 SetErrorCode("GetBoundingBox Error: Bounding box cannot be precised");
1099 B.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
1101 catch (Standard_Failure) {
1102 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1103 SetErrorCode(aFail->GetMessageString());
1110 //=============================================================================
1114 //=============================================================================
1115 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetBoundingBox
1116 (Handle(GEOM_Object) theShape,
1117 const Standard_Boolean precise)
1121 if (theShape.IsNull()) return NULL;
1123 //Add a new BoundingBox object
1124 Handle(GEOM_Object) aBnd = GetEngine()->AddObject(GetDocID(), GEOM_BOX);
1126 //Add a new BoundingBox function
1127 const int aType = (precise ? BND_BOX_MEASURE_PRECISE : BND_BOX_MEASURE);
1128 Handle(GEOM_Function) aFunction =
1129 aBnd->AddFunction(GEOMImpl_MeasureDriver::GetID(), aType);
1130 if (aFunction.IsNull()) return NULL;
1132 //Check if the function is set correctly
1133 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
1135 GEOMImpl_IMeasure aCI (aFunction);
1137 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1138 if (aRefShape.IsNull()) return NULL;
1140 aCI.SetBase(aRefShape);
1142 //Compute the BoundingBox value
1145 if (!GetSolver()->ComputeFunction(aFunction)) {
1146 SetErrorCode("Measure driver failed to compute a bounding box");
1150 catch (Standard_Failure) {
1151 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1152 SetErrorCode(aFail->GetMessageString());
1156 //Make a Python command
1157 GEOM::TPythonDump aPd(aFunction);
1159 aPd << aBnd << " = geompy.MakeBoundingBox(" << theShape;
1171 //=============================================================================
1175 //=============================================================================
1176 void GEOMImpl_IMeasureOperations::GetTolerance
1177 (Handle(GEOM_Object) theShape,
1178 Standard_Real& FaceMin, Standard_Real& FaceMax,
1179 Standard_Real& EdgeMin, Standard_Real& EdgeMax,
1180 Standard_Real& VertMin, Standard_Real& VertMax)
1184 if (theShape.IsNull()) return;
1186 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1187 if (aRefShape.IsNull()) return;
1189 TopoDS_Shape aShape = aRefShape->GetValue();
1190 if (aShape.IsNull()) {
1191 SetErrorCode("The Objects has NULL Shape");
1195 //Compute the parameters
1197 FaceMin = EdgeMin = VertMin = RealLast();
1198 FaceMax = EdgeMax = VertMax = -RealLast();
1202 for (TopExp_Explorer ExF (aShape, TopAbs_FACE); ExF.More(); ExF.Next()) {
1203 TopoDS_Face Face = TopoDS::Face(ExF.Current());
1204 T = BRep_Tool::Tolerance(Face);
1210 for (TopExp_Explorer ExE (aShape, TopAbs_EDGE); ExE.More(); ExE.Next()) {
1211 TopoDS_Edge Edge = TopoDS::Edge(ExE.Current());
1212 T = BRep_Tool::Tolerance(Edge);
1218 for (TopExp_Explorer ExV (aShape, TopAbs_VERTEX); ExV.More(); ExV.Next()) {
1219 TopoDS_Vertex Vertex = TopoDS::Vertex(ExV.Current());
1220 T = BRep_Tool::Tolerance(Vertex);
1227 catch (Standard_Failure) {
1228 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1229 SetErrorCode(aFail->GetMessageString());
1236 //=============================================================================
1240 //=============================================================================
1241 bool GEOMImpl_IMeasureOperations::CheckShape (Handle(GEOM_Object) theShape,
1242 const Standard_Boolean theIsCheckGeom,
1243 std::list<ShapeError> &theErrors)
1248 if (theShape.IsNull()) return false;
1250 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1251 if (aRefShape.IsNull()) return false;
1253 TopoDS_Shape aShape = aRefShape->GetValue();
1254 if (aShape.IsNull()) {
1255 SetErrorCode("The Objects has NULL Shape");
1259 //Compute the parameters
1260 bool isValid = false;
1263 BRepCheck_Analyzer ana (aShape, theIsCheckGeom);
1264 if (ana.IsValid()) {
1267 FillErrors(ana, aShape, theErrors);
1270 catch (Standard_Failure) {
1271 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1272 SetErrorCode(aFail->GetMessageString());
1280 //=============================================================================
1284 //=============================================================================
1285 TCollection_AsciiString GEOMImpl_IMeasureOperations::PrintShapeErrors
1286 (Handle(GEOM_Object) theShape,
1287 const std::list<ShapeError> &theErrors)
1289 TCollection_AsciiString aDump;
1291 if (theShape.IsNull()) {
1295 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1297 if (aRefShape.IsNull()) {
1301 TopoDS_Shape aShape = aRefShape->GetValue();
1303 if (aShape.IsNull()) {
1304 SetErrorCode("The Objects has NULL Shape");
1308 if (!theErrors.empty()) {
1309 // The shape is not valid. Prepare errors for dump.
1310 TopTools_IndexedMapOfShape anIndices;
1311 std::list<ShapeError>::const_iterator anIter = theErrors.begin();
1312 Standard_Integer nbv, nbe, nbw, nbf, nbs, nbo;
1313 nbv = nbe = nbw = nbf = nbs = nbo = 0;
1315 // Map sub-shapes and their indices
1316 TopExp::MapShapes(aShape, anIndices);
1318 const Standard_Integer aNbSubShapes = anIndices.Extent();
1319 TColStd_MapOfInteger aMapPbInd;
1321 aDump += " -- The Shape has problems :\n";
1322 aDump += " Check Count\n";
1323 aDump += " ------------------------------------------------\n";
1325 for (; anIter != theErrors.end(); anIter++) {
1326 Standard_Integer aNbShapes = anIter->incriminated.size();
1328 switch(anIter->error) {
1329 case BRepCheck_InvalidPointOnCurve:
1330 aDump += " Invalid Point on Curve ................... ";
1332 case BRepCheck_InvalidPointOnCurveOnSurface:
1333 aDump += " Invalid Point on CurveOnSurface .......... ";
1335 case BRepCheck_InvalidPointOnSurface:
1336 aDump += " Invalid Point on Surface ................. ";
1338 case BRepCheck_No3DCurve:
1339 aDump += " No 3D Curve .............................. ";
1341 case BRepCheck_Multiple3DCurve:
1342 aDump += " Multiple 3D Curve ........................ ";
1344 case BRepCheck_Invalid3DCurve:
1345 aDump += " Invalid 3D Curve ......................... ";
1347 case BRepCheck_NoCurveOnSurface:
1348 aDump += " No Curve on Surface ...................... ";
1350 case BRepCheck_InvalidCurveOnSurface:
1351 aDump += " Invalid Curve on Surface ................. ";
1353 case BRepCheck_InvalidCurveOnClosedSurface:
1354 aDump += " Invalid Curve on closed Surface .......... ";
1356 case BRepCheck_InvalidSameRangeFlag:
1357 aDump += " Invalid SameRange Flag ................... ";
1359 case BRepCheck_InvalidSameParameterFlag:
1360 aDump += " Invalid SameParameter Flag ............... ";
1362 case BRepCheck_InvalidDegeneratedFlag:
1363 aDump += " Invalid Degenerated Flag ................. ";
1365 case BRepCheck_FreeEdge:
1366 aDump += " Free Edge ................................ ";
1368 case BRepCheck_InvalidMultiConnexity:
1369 aDump += " Invalid MultiConnexity ................... ";
1371 case BRepCheck_InvalidRange:
1372 aDump += " Invalid Range ............................ ";
1374 case BRepCheck_EmptyWire:
1375 aDump += " Empty Wire ............................... ";
1377 case BRepCheck_RedundantEdge:
1378 aDump += " Redundant Edge ........................... ";
1380 case BRepCheck_SelfIntersectingWire:
1381 aDump += " Self Intersecting Wire ................... ";
1383 case BRepCheck_NoSurface:
1384 aDump += " No Surface ............................... ";
1386 case BRepCheck_InvalidWire:
1387 aDump += " Invalid Wire ............................. ";
1389 case BRepCheck_RedundantWire:
1390 aDump += " Redundant Wire ........................... ";
1392 case BRepCheck_IntersectingWires:
1393 aDump += " Intersecting Wires ....................... ";
1395 case BRepCheck_InvalidImbricationOfWires:
1396 aDump += " Invalid Imbrication of Wires ............. ";
1398 case BRepCheck_EmptyShell:
1399 aDump += " Empty Shell .............................. ";
1401 case BRepCheck_RedundantFace:
1402 aDump += " Redundant Face ........................... ";
1404 case BRepCheck_UnorientableShape:
1405 aDump += " Unorientable Shape ....................... ";
1407 case BRepCheck_NotClosed:
1408 aDump += " Not Closed ............................... ";
1410 case BRepCheck_NotConnected:
1411 aDump += " Not Connected ............................ ";
1413 case BRepCheck_SubshapeNotInShape:
1414 aDump += " Sub-shape not in Shape ................... ";
1416 case BRepCheck_BadOrientation:
1417 aDump += " Bad Orientation .......................... ";
1419 case BRepCheck_BadOrientationOfSubshape:
1420 aDump += " Bad Orientation of Sub-shape ............. ";
1422 case BRepCheck_InvalidToleranceValue:
1423 aDump += " Invalid Tolerance Value .................. ";
1425 case BRepCheck_CheckFail:
1426 aDump += " Check Shape Failure ...................... ";
1432 aDump += TCollection_AsciiString(aNbShapes) + "\n";
1434 // Count types of shape.
1435 std::list<int>::const_iterator aShIter = anIter->incriminated.begin();
1437 for (; aShIter != anIter->incriminated.end(); aShIter++) {
1438 const Standard_Integer anIndex = *aShIter;
1440 if (anIndex > 0 && anIndex <= aNbSubShapes && aMapPbInd.Add(anIndex)) {
1441 const TopoDS_Shape &aSubShape = anIndices.FindKey(anIndex);
1442 const TopAbs_ShapeEnum aType = aSubShape.ShapeType();
1445 case TopAbs_VERTEX : nbv++; break;
1446 case TopAbs_EDGE : nbe++; break;
1447 case TopAbs_WIRE : nbw++; break;
1448 case TopAbs_FACE : nbf++; break;
1449 case TopAbs_SHELL : nbs++; break;
1450 case TopAbs_SOLID : nbo++; break;
1457 const Standard_Integer aNbFaultyShapes = nbv + nbe + nbw + nbf + nbs + nbo;
1458 aDump += " ------------------------------------------------\n";
1459 aDump += "*** Shapes with problems : ";
1460 aDump += TCollection_AsciiString(aNbFaultyShapes) + "\n";
1463 aDump += "VERTEX : ";
1464 if (nbv < 10) aDump += " ";
1465 aDump += TCollection_AsciiString(nbv) + "\n";
1469 if (nbe < 10) aDump += " ";
1470 aDump += TCollection_AsciiString(nbe) + "\n";
1474 if (nbw < 10) aDump += " ";
1475 aDump += TCollection_AsciiString(nbw) + "\n";
1479 if (nbf < 10) aDump += " ";
1480 aDump += TCollection_AsciiString(nbf) + "\n";
1483 aDump += "SHELL : ";
1484 if (nbs < 10) aDump += " ";
1485 aDump += TCollection_AsciiString(nbs) + "\n";
1488 aDump += "SOLID : ";
1489 if (nbo < 10) aDump += " ";
1490 aDump += TCollection_AsciiString(nbo) + "\n";
1497 //=============================================================================
1499 * CheckSelfIntersections
1501 //=============================================================================
1502 bool GEOMImpl_IMeasureOperations::CheckSelfIntersections
1503 (Handle(GEOM_Object) theShape,
1504 Handle(TColStd_HSequenceOfInteger)& theIntersections)
1507 bool isGood = false;
1509 if (theIntersections.IsNull())
1510 theIntersections = new TColStd_HSequenceOfInteger;
1512 theIntersections->Clear();
1514 if (theShape.IsNull())
1517 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1518 if (aRefShape.IsNull()) return isGood;
1520 TopoDS_Shape aShape = aRefShape->GetValue();
1521 if (aShape.IsNull()) return isGood;
1524 TopoDS_Shape aScopy;
1526 GEOMAlgo_AlgoTools::CopyShape(aShape, aScopy);
1528 // Map sub-shapes and their indices
1529 TopTools_IndexedMapOfShape anIndices;
1530 TopExp::MapShapes(aScopy, anIndices);
1532 BOPCol_ListOfShape aLCS;
1533 aLCS.Append(aScopy);
1535 BOPAlgo_CheckerSI aCSI; // checker of self-interferences
1536 aCSI.SetArguments(aLCS);
1538 // 1. Launch the checker
1540 Standard_Integer iErr = aCSI.ErrorStatus();
1544 Standard_Integer aNbS, n1, n2;
1545 BOPDS_MapIteratorMapOfPassKey aItMPK;
1547 // 2. Take the shapes from DS
1548 const BOPDS_DS& aDS = aCSI.DS();
1549 aNbS=aDS.NbShapes();
1551 // 3. Get the pairs of interfered shapes
1552 const BOPDS_MapOfPassKey& aMPK=aDS.Interferences();
1553 aItMPK.Initialize(aMPK);
1554 for (; aItMPK.More(); aItMPK.Next()) {
1555 const BOPDS_PassKey& aPK=aItMPK.Value();
1558 if (n1 > aNbS || n2 > aNbS){
1559 return false; // Error
1561 const TopoDS_Shape& aS1 = aDS.Shape(n1);
1562 const TopoDS_Shape& aS2 = aDS.Shape(n2);
1564 theIntersections->Append(anIndices.FindIndex(aS1));
1565 theIntersections->Append(anIndices.FindIndex(aS2));
1576 //=============================================================================
1580 //=============================================================================
1581 TCollection_AsciiString GEOMImpl_IMeasureOperations::IsGoodForSolid (Handle(GEOM_Object) theShape)
1585 TCollection_AsciiString aRes = "";
1587 if (theShape.IsNull()) {
1588 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1591 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1592 if (aRefShape.IsNull()) {
1593 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1596 TopoDS_Shape aShape = aRefShape->GetValue();
1597 if (aShape.IsNull()) {
1598 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1601 if (aShape.ShapeType() == TopAbs_COMPOUND) {
1602 TopoDS_Iterator It (aShape, Standard_True, Standard_True);
1603 if (It.More()) aShape = It.Value();
1605 if (aShape.ShapeType() == TopAbs_SHELL) {
1606 BRepCheck_Shell chkShell (TopoDS::Shell(aShape));
1607 if (chkShell.Closed() == BRepCheck_NotClosed) {
1608 aRes = "WRN_SHAPE_UNCLOSED";
1612 aRes = "WRN_SHAPE_NOT_SHELL";
1624 //=============================================================================
1628 //=============================================================================
1629 TCollection_AsciiString GEOMImpl_IMeasureOperations::WhatIs (Handle(GEOM_Object) theShape)
1633 TCollection_AsciiString Astr;
1635 if (theShape.IsNull()) return Astr;
1637 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1638 if (aRefShape.IsNull()) return Astr;
1640 TopoDS_Shape aShape = aRefShape->GetValue();
1641 if (aShape.IsNull()) {
1642 SetErrorCode("The Objects has NULL Shape");
1646 //Compute the parameters
1647 if (aShape.ShapeType() == TopAbs_EDGE) {
1648 if (BRep_Tool::Degenerated(TopoDS::Edge(aShape))) {
1649 Astr = Astr + " It is a degenerated edge \n";
1653 Astr = Astr + " Number of sub-shapes : \n";
1657 int iType, nbTypes [TopAbs_SHAPE];
1658 for (iType = 0; iType < TopAbs_SHAPE; ++iType)
1660 nbTypes[aShape.ShapeType()]++;
1662 TopTools_MapOfShape aMapOfShape;
1663 aMapOfShape.Add(aShape);
1664 TopTools_ListOfShape aListOfShape;
1665 aListOfShape.Append(aShape);
1667 TopTools_ListIteratorOfListOfShape itL (aListOfShape);
1668 for (; itL.More(); itL.Next()) {
1669 TopoDS_Iterator it (itL.Value());
1670 for (; it.More(); it.Next()) {
1671 TopoDS_Shape s = it.Value();
1672 if (aMapOfShape.Add(s)) {
1673 aListOfShape.Append(s);
1674 nbTypes[s.ShapeType()]++;
1679 Astr = Astr + " VERTEX : " + TCollection_AsciiString(nbTypes[TopAbs_VERTEX]) + "\n";
1680 Astr = Astr + " EDGE : " + TCollection_AsciiString(nbTypes[TopAbs_EDGE]) + "\n";
1681 Astr = Astr + " WIRE : " + TCollection_AsciiString(nbTypes[TopAbs_WIRE]) + "\n";
1682 Astr = Astr + " FACE : " + TCollection_AsciiString(nbTypes[TopAbs_FACE]) + "\n";
1683 Astr = Astr + " SHELL : " + TCollection_AsciiString(nbTypes[TopAbs_SHELL]) + "\n";
1684 Astr = Astr + " SOLID : " + TCollection_AsciiString(nbTypes[TopAbs_SOLID]) + "\n";
1685 Astr = Astr + " COMPSOLID : " + TCollection_AsciiString(nbTypes[TopAbs_COMPSOLID]) + "\n";
1686 Astr = Astr + " COMPOUND : " + TCollection_AsciiString(nbTypes[TopAbs_COMPOUND]) + "\n";
1687 Astr = Astr + " SHAPE : " + TCollection_AsciiString(aMapOfShape.Extent());
1689 catch (Standard_Failure) {
1690 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1691 SetErrorCode(aFail->GetMessageString());
1699 //=============================================================================
1703 //=============================================================================
1705 GEOMImpl_IMeasureOperations::AreCoordsInside(Handle(GEOM_Object) theShape,
1706 const std::vector<double>& coords,
1709 std::vector<bool> isInsideRes;
1710 if (!theShape.IsNull()) {
1711 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1712 if (!aRefShape.IsNull()) {
1713 TopoDS_Shape aShape = aRefShape->GetValue();
1714 if (!aShape.IsNull())
1716 TopTools_IndexedMapOfShape mapShape;
1718 TopExp_Explorer anExp;
1719 for ( anExp.Init( aShape, TopAbs_SOLID ); anExp.More(); anExp.Next() )
1720 mapShape.Add( anExp.Current() );
1721 for ( anExp.Init( aShape, TopAbs_FACE, TopAbs_SOLID ); anExp.More(); anExp.Next() )
1722 mapShape.Add( anExp.Current() );
1723 for ( anExp.Init( aShape, TopAbs_EDGE, TopAbs_FACE ); anExp.More(); anExp.Next() )
1724 mapShape.Add( anExp.Current() );
1725 for ( anExp.Init( aShape, TopAbs_VERTEX, TopAbs_EDGE ); anExp.More(); anExp.Next() )
1726 mapShape.Add( anExp.Current() ); //// ?????????
1728 size_t nb_points = coords.size()/3, nb_points_inside = 0;
1729 isInsideRes.resize( nb_points, false );
1731 for ( int iS = 1; iS <= mapShape.Extent(); ++iS )
1733 if ( nb_points_inside == nb_points )
1735 aShape = mapShape( iS );
1736 switch ( aShape.ShapeType() ) {
1739 BRepClass3d_SolidClassifier SC( TopoDS::Solid( aShape ));
1740 for ( size_t i = 0; i < nb_points; i++)
1742 if ( isInsideRes[ i ]) continue;
1743 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
1744 SC.Perform( aPnt, tolerance );
1745 isInsideRes[ i ] = (( SC.State() == TopAbs_IN ) || ( SC.State() == TopAbs_ON ));
1746 nb_points_inside += isInsideRes[ i ];
1752 Standard_Real u1,u2,v1,v2;
1753 const TopoDS_Face& face = TopoDS::Face( aShape );
1754 Handle(Geom_Surface) surf = BRep_Tool::Surface( face );
1755 surf->Bounds( u1,u2,v1,v2 );
1756 GeomAPI_ProjectPointOnSurf project;
1757 project.Init(surf, u1,u2, v1,v2, tolerance );
1758 for ( size_t i = 0; i < nb_points; i++)
1760 if ( isInsideRes[ i ]) continue;
1761 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
1762 project.Perform( aPnt );
1763 if ( project.IsDone() &&
1764 project.NbPoints() > 0 &&
1765 project.LowerDistance() <= tolerance )
1767 Quantity_Parameter u, v;
1768 project.LowerDistanceParameters(u, v);
1769 gp_Pnt2d uv( u, v );
1770 BRepClass_FaceClassifier FC ( face, uv, tolerance );
1771 isInsideRes[ i ] = (( FC.State() == TopAbs_IN ) || ( FC.State() == TopAbs_ON ));
1772 nb_points_inside += isInsideRes[ i ];
1780 const TopoDS_Edge& edge = TopoDS::Edge( aShape );
1781 Handle(Geom_Curve) curve = BRep_Tool::Curve( edge, f, l );
1782 GeomAPI_ProjectPointOnCurve project;
1783 project.Init( curve, f, l );
1784 for ( size_t i = 0; i < nb_points; i++)
1786 if ( isInsideRes[ i ]) continue;
1787 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
1788 project.Perform( aPnt );
1789 isInsideRes[ i ] = ( project.NbPoints() > 0 &&
1790 project.LowerDistance() <= tolerance );
1791 nb_points_inside += isInsideRes[ i ];
1797 gp_Pnt aVPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ));
1798 for ( size_t i = 0; i < nb_points; i++)
1800 if ( isInsideRes[ i ]) continue;
1801 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
1802 isInsideRes[ i ] = ( aPnt.SquareDistance( aVPnt ) <= tolerance * tolerance );
1803 nb_points_inside += isInsideRes[ i ];
1808 } // switch ( aShape.ShapeType() )
1816 //=============================================================================
1820 //=============================================================================
1822 GEOMImpl_IMeasureOperations::GetMinDistance (Handle(GEOM_Object) theShape1,
1823 Handle(GEOM_Object) theShape2,
1832 Standard_Real MinDist = 1.e9;
1834 if (theShape1.IsNull() || theShape2.IsNull()) return MinDist;
1836 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
1837 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
1838 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return MinDist;
1840 TopoDS_Shape aShape1 = aRefShape1->GetValue();
1841 TopoDS_Shape aShape2 = aRefShape2->GetValue();
1842 if (aShape1.IsNull() || aShape2.IsNull()) {
1843 SetErrorCode("One of Objects has NULL Shape");
1847 //Compute the parameters
1851 gp_Pnt aPnt1, aPnt2;
1853 MinDist = GEOMUtils::GetMinDistance(aShape1, aShape2, aPnt1, aPnt2);
1855 if (MinDist >= 0.0) {
1856 aPnt1.Coord(X1, Y1, Z1);
1857 aPnt2.Coord(X2, Y2, Z2);
1862 catch (Standard_Failure) {
1863 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1864 SetErrorCode(aFail->GetMessageString());
1872 //=======================================================================
1874 * Get coordinates of closest points of two shapes
1876 //=======================================================================
1877 Standard_Integer GEOMImpl_IMeasureOperations::ClosestPoints (Handle(GEOM_Object) theShape1,
1878 Handle(GEOM_Object) theShape2,
1879 Handle(TColStd_HSequenceOfReal)& theDoubles)
1882 Standard_Integer nbSolutions = 0;
1884 if (theShape1.IsNull() || theShape2.IsNull()) return nbSolutions;
1886 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
1887 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
1888 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return nbSolutions;
1890 TopoDS_Shape aShape1 = aRefShape1->GetValue();
1891 TopoDS_Shape aShape2 = aRefShape2->GetValue();
1892 if (aShape1.IsNull() || aShape2.IsNull()) {
1893 SetErrorCode("One of Objects has NULL Shape");
1897 // Compute the extremities
1902 // additional workaround for bugs 19899, 19908 and 19910 from Mantis
1904 double dist = GEOMUtils::GetMinDistanceSingular(aShape1, aShape2, P1, P2);
1908 theDoubles->Append(P1.X());
1909 theDoubles->Append(P1.Y());
1910 theDoubles->Append(P1.Z());
1911 theDoubles->Append(P2.X());
1912 theDoubles->Append(P2.Y());
1913 theDoubles->Append(P2.Z());
1919 BRepExtrema_DistShapeShape dst (aShape1, aShape2);
1921 nbSolutions = dst.NbSolution();
1922 if (theDoubles.IsNull()) theDoubles = new TColStd_HSequenceOfReal;
1925 for (int i = 1; i <= nbSolutions; i++) {
1926 P1 = dst.PointOnShape1(i);
1927 P2 = dst.PointOnShape2(i);
1929 theDoubles->Append(P1.X());
1930 theDoubles->Append(P1.Y());
1931 theDoubles->Append(P1.Z());
1932 theDoubles->Append(P2.X());
1933 theDoubles->Append(P2.Y());
1934 theDoubles->Append(P2.Z());
1938 catch (Standard_Failure) {
1939 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1940 SetErrorCode(aFail->GetMessageString());
1948 //=======================================================================
1950 * Get coordinates of point
1952 //=======================================================================
1953 void GEOMImpl_IMeasureOperations::PointCoordinates (Handle(GEOM_Object) theShape,
1954 Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ)
1958 if (theShape.IsNull())
1961 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1962 if (aRefShape.IsNull())
1965 TopoDS_Shape aShape = aRefShape->GetValue();
1966 if (aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX)
1968 SetErrorCode( "Shape must be a vertex" );
1974 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
1981 catch (Standard_Failure)
1983 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1984 SetErrorCode( aFail->GetMessageString() );
1988 //=======================================================================
1990 * Compute angle (in degrees) between two lines
1992 //=======================================================================
1993 Standard_Real GEOMImpl_IMeasureOperations::GetAngle (Handle(GEOM_Object) theLine1,
1994 Handle(GEOM_Object) theLine2)
1996 if (theLine1->GetType() == GEOM_VECTOR &&
1997 theLine2->GetType() == GEOM_VECTOR)
1998 return GetAngleBtwVectors(theLine1, theLine2);
2002 Standard_Real anAngle = -1.0;
2004 if (theLine1.IsNull() || theLine2.IsNull())
2007 Handle(GEOM_Function) aRefLine1 = theLine1->GetLastFunction();
2008 Handle(GEOM_Function) aRefLine2 = theLine2->GetLastFunction();
2009 if (aRefLine1.IsNull() || aRefLine2.IsNull())
2012 TopoDS_Shape aLine1 = aRefLine1->GetValue();
2013 TopoDS_Shape aLine2 = aRefLine2->GetValue();
2014 if (aLine1.IsNull() || aLine2.IsNull() ||
2015 aLine1.ShapeType() != TopAbs_EDGE ||
2016 aLine2.ShapeType() != TopAbs_EDGE)
2018 SetErrorCode("Two edges must be given");
2024 TopoDS_Edge E1 = TopoDS::Edge(aLine1);
2025 TopoDS_Edge E2 = TopoDS::Edge(aLine2);
2028 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp,lp);
2029 Handle(Geom_Curve) C2 = BRep_Tool::Curve(E2,fp,lp);
2031 if ( C1.IsNull() || C2.IsNull() ||
2032 !C1->IsKind(STANDARD_TYPE(Geom_Line)) ||
2033 !C2->IsKind(STANDARD_TYPE(Geom_Line)))
2035 SetErrorCode("The edges must be linear");
2039 Handle(Geom_Line) L1 = Handle(Geom_Line)::DownCast(C1);
2040 Handle(Geom_Line) L2 = Handle(Geom_Line)::DownCast(C2);
2042 gp_Lin aLin1 = L1->Lin();
2043 gp_Lin aLin2 = L2->Lin();
2045 anAngle = aLin1.Angle(aLin2);
2046 anAngle *= 180. / M_PI; // convert radians into degrees
2048 if (anAngle > 90.0) {
2049 anAngle = 180.0 - anAngle;
2054 catch (Standard_Failure)
2056 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2057 SetErrorCode(aFail->GetMessageString());
2063 //=======================================================================
2065 * Compute angle (in degrees) between two vectors
2067 //=======================================================================
2068 Standard_Real GEOMImpl_IMeasureOperations::GetAngleBtwVectors (Handle(GEOM_Object) theVec1,
2069 Handle(GEOM_Object) theVec2)
2073 Standard_Real anAngle = -1.0;
2075 if (theVec1.IsNull() || theVec2.IsNull())
2078 if (theVec1->GetType() != GEOM_VECTOR || theVec2->GetType() != GEOM_VECTOR) {
2079 SetErrorCode("Two vectors must be given");
2083 Handle(GEOM_Function) aRefVec1 = theVec1->GetLastFunction();
2084 Handle(GEOM_Function) aRefVec2 = theVec2->GetLastFunction();
2085 if (aRefVec1.IsNull() || aRefVec2.IsNull())
2088 TopoDS_Shape aVec1 = aRefVec1->GetValue();
2089 TopoDS_Shape aVec2 = aRefVec2->GetValue();
2090 if (aVec1.IsNull() || aVec2.IsNull() ||
2091 aVec1.ShapeType() != TopAbs_EDGE ||
2092 aVec2.ShapeType() != TopAbs_EDGE)
2094 SetErrorCode("Two edges must be given");
2100 TopoDS_Edge aE1 = TopoDS::Edge(aVec1);
2101 TopoDS_Edge aE2 = TopoDS::Edge(aVec2);
2103 TopoDS_Vertex aP11, aP12, aP21, aP22;
2104 TopExp::Vertices(aE1, aP11, aP12, Standard_True);
2105 TopExp::Vertices(aE2, aP21, aP22, Standard_True);
2106 if (aP11.IsNull() || aP12.IsNull() || aP21.IsNull() || aP22.IsNull()) {
2107 SetErrorCode("Bad edge given");
2111 gp_Vec aV1 (BRep_Tool::Pnt(aP11), BRep_Tool::Pnt(aP12));
2112 gp_Vec aV2 (BRep_Tool::Pnt(aP21), BRep_Tool::Pnt(aP22)) ;
2114 anAngle = aV1.Angle(aV2);
2115 anAngle *= 180. / M_PI; // convert radians into degrees
2119 catch (Standard_Failure)
2121 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2122 SetErrorCode(aFail->GetMessageString());
2129 //=============================================================================
2131 * CurveCurvatureByParam
2133 //=============================================================================
2134 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByParam
2135 (Handle(GEOM_Object) theCurve, Standard_Real& theParam)
2138 Standard_Real aRes = -1.0;
2140 if(theCurve.IsNull()) return aRes;
2142 Handle(GEOM_Function) aRefShape = theCurve->GetLastFunction();
2143 if(aRefShape.IsNull()) return aRes;
2145 TopoDS_Shape aShape = aRefShape->GetValue();
2146 if(aShape.IsNull()) {
2147 SetErrorCode("One of Objects has NULL Shape");
2151 Standard_Real aFP, aLP, aP;
2152 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aFP, aLP);
2153 aP = aFP + (aLP - aFP) * theParam;
2155 if(aCurve.IsNull()) return aRes;
2160 GeomLProp_CLProps Prop = GeomLProp_CLProps
2161 (aCurve, aP, 2, Precision::Confusion());
2162 aRes = fabs(Prop.Curvature());
2165 catch (Standard_Failure) {
2166 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2167 SetErrorCode(aFail->GetMessageString());
2171 if( aRes > Precision::Confusion() )
2180 //=============================================================================
2182 * CurveCurvatureByPoint
2184 //=============================================================================
2185 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByPoint
2186 (Handle(GEOM_Object) theCurve, Handle(GEOM_Object) thePoint)
2189 Standard_Real aRes = -1.0;
2191 if( theCurve.IsNull() || thePoint.IsNull() ) return aRes;
2193 Handle(GEOM_Function) aRefCurve = theCurve->GetLastFunction();
2194 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2195 if( aRefCurve.IsNull() || aRefPoint.IsNull() ) return aRes;
2197 TopoDS_Edge anEdge = TopoDS::Edge(aRefCurve->GetValue());
2198 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2199 if( anEdge.IsNull() || aPnt.IsNull() ) {
2200 SetErrorCode("One of Objects has NULL Shape");
2204 Standard_Real aFP, aLP;
2205 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFP, aLP);
2206 if(aCurve.IsNull()) return aRes;
2207 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2212 GeomAPI_ProjectPointOnCurve PPCurve(aPoint, aCurve, aFP, aLP);
2213 if(PPCurve.NbPoints()>0) {
2214 GeomLProp_CLProps Prop = GeomLProp_CLProps
2215 (aCurve, PPCurve.LowerDistanceParameter(), 2, Precision::Confusion());
2216 aRes = fabs(Prop.Curvature());
2220 catch (Standard_Failure) {
2221 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2222 SetErrorCode(aFail->GetMessageString());
2226 if( aRes > Precision::Confusion() )
2235 //=============================================================================
2237 * getSurfaceCurvatures
2239 //=============================================================================
2240 Standard_Real GEOMImpl_IMeasureOperations::getSurfaceCurvatures
2241 (const Handle(Geom_Surface)& aSurf,
2242 Standard_Real theUParam,
2243 Standard_Real theVParam,
2244 Standard_Boolean theNeedMaxCurv)
2247 Standard_Real aRes = 1.0;
2249 if (aSurf.IsNull()) return aRes;
2253 GeomLProp_SLProps Prop = GeomLProp_SLProps
2254 (aSurf, theUParam, theVParam, 2, Precision::Confusion());
2255 if(Prop.IsCurvatureDefined()) {
2256 if(Prop.IsUmbilic()) {
2257 //cout<<"is umbilic"<<endl;
2258 aRes = fabs(Prop.MeanCurvature());
2261 //cout<<"is not umbilic"<<endl;
2262 double c1 = fabs(Prop.MaxCurvature());
2263 double c2 = fabs(Prop.MinCurvature());
2272 catch (Standard_Failure) {
2273 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2274 SetErrorCode(aFail->GetMessageString());
2278 if( fabs(aRes) > Precision::Confusion() )
2287 //=============================================================================
2289 * MaxSurfaceCurvatureByParam
2291 //=============================================================================
2292 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByParam
2293 (Handle(GEOM_Object) theSurf,
2294 Standard_Real& theUParam,
2295 Standard_Real& theVParam)
2298 Standard_Real aRes = -1.0;
2300 if (theSurf.IsNull()) return aRes;
2302 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2303 if(aRefShape.IsNull()) return aRes;
2305 TopoDS_Shape aShape = aRefShape->GetValue();
2306 if(aShape.IsNull()) {
2307 SetErrorCode("One of Objects has NULL Shape");
2311 TopoDS_Face F = TopoDS::Face(aShape);
2312 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2314 //Compute the parameters
2315 Standard_Real U1,U2,V1,V2;
2316 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2317 Standard_Real U = U1 + (U2-U1)*theUParam;
2318 Standard_Real V = V1 + (V2-V1)*theVParam;
2320 return getSurfaceCurvatures(aSurf, U, V, true);
2324 //=============================================================================
2326 * MaxSurfaceCurvatureByPoint
2328 //=============================================================================
2329 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByPoint
2330 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2333 Standard_Real aRes = -1.0;
2335 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2337 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2338 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2339 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2341 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2342 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2343 if( aFace.IsNull() || aPnt.IsNull() ) {
2344 SetErrorCode("One of Objects has NULL Shape");
2348 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2349 if(aSurf.IsNull()) return aRes;
2350 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2352 //Compute the parameters
2353 ShapeAnalysis_Surface sas(aSurf);
2354 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2356 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), true);
2360 //=============================================================================
2362 * MinSurfaceCurvatureByParam
2364 //=============================================================================
2365 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByParam
2366 (Handle(GEOM_Object) theSurf,
2367 Standard_Real& theUParam,
2368 Standard_Real& theVParam)
2371 Standard_Real aRes = -1.0;
2373 if (theSurf.IsNull()) return aRes;
2375 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2376 if(aRefShape.IsNull()) return aRes;
2378 TopoDS_Shape aShape = aRefShape->GetValue();
2379 if(aShape.IsNull()) {
2380 SetErrorCode("One of Objects has NULL Shape");
2384 TopoDS_Face F = TopoDS::Face(aShape);
2385 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2387 //Compute the parameters
2388 Standard_Real U1,U2,V1,V2;
2389 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2390 Standard_Real U = U1 + (U2-U1)*theUParam;
2391 Standard_Real V = V1 + (V2-V1)*theVParam;
2393 return getSurfaceCurvatures(aSurf, U, V, false);
2397 //=============================================================================
2399 * MinSurfaceCurvatureByPoint
2401 //=============================================================================
2402 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByPoint
2403 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2406 Standard_Real aRes = -1.0;
2408 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2410 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2411 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2412 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2414 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2415 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2416 if( aFace.IsNull() || aPnt.IsNull() ) {
2417 SetErrorCode("One of Objects has NULL Shape");
2421 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2422 if(aSurf.IsNull()) return aRes;
2423 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2425 //Compute the parameters
2426 ShapeAnalysis_Surface sas(aSurf);
2427 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2429 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), false);
2432 //=======================================================================
2433 //function : FillErrorsSub
2434 //purpose : Fill the errors list of subshapes on shape.
2435 //=======================================================================
2436 void GEOMImpl_IMeasureOperations::FillErrorsSub
2437 (const BRepCheck_Analyzer &theAna,
2438 const TopoDS_Shape &theShape,
2439 const TopAbs_ShapeEnum theSubType,
2440 TopTools_DataMapOfIntegerListOfShape &theMapErrors) const
2442 TopExp_Explorer anExp(theShape, theSubType);
2443 TopTools_MapOfShape aMapSubShapes;
2445 for (; anExp.More(); anExp.Next()) {
2446 const TopoDS_Shape &aSubShape = anExp.Current();
2448 if (aMapSubShapes.Add(aSubShape)) {
2449 const Handle(BRepCheck_Result) &aRes = theAna.Result(aSubShape);
2451 for (aRes->InitContextIterator();
2452 aRes->MoreShapeInContext();
2453 aRes->NextShapeInContext()) {
2454 if (aRes->ContextualShape().IsSame(theShape)) {
2455 BRepCheck_ListIteratorOfListOfStatus itl(aRes->StatusOnShape());
2457 if (itl.Value() != BRepCheck_NoError) {
2458 // Add all errors for theShape and its sub-shape.
2459 for (;itl.More(); itl.Next()) {
2460 const Standard_Integer aStat = (Standard_Integer)itl.Value();
2462 if (!theMapErrors.IsBound(aStat)) {
2463 TopTools_ListOfShape anEmpty;
2465 theMapErrors.Bind(aStat, anEmpty);
2468 TopTools_ListOfShape &theShapes = theMapErrors.ChangeFind(aStat);
2470 theShapes.Append(aSubShape);
2471 theShapes.Append(theShape);
2482 //=======================================================================
2483 //function : FillErrors
2484 //purpose : Fill the errors list.
2485 //=======================================================================
2486 void GEOMImpl_IMeasureOperations::FillErrors
2487 (const BRepCheck_Analyzer &theAna,
2488 const TopoDS_Shape &theShape,
2489 TopTools_DataMapOfIntegerListOfShape &theMapErrors,
2490 TopTools_MapOfShape &theMapShapes) const
2492 if (theMapShapes.Add(theShape)) {
2493 // Fill errors of child shapes.
2494 for (TopoDS_Iterator iter(theShape); iter.More(); iter.Next()) {
2495 FillErrors(theAna, iter.Value(), theMapErrors, theMapShapes);
2498 // Fill errors of theShape.
2499 const Handle(BRepCheck_Result) &aRes = theAna.Result(theShape);
2501 if (!aRes.IsNull()) {
2502 BRepCheck_ListIteratorOfListOfStatus itl(aRes->Status());
2504 if (itl.Value() != BRepCheck_NoError) {
2505 // Add all errors for theShape.
2506 for (;itl.More(); itl.Next()) {
2507 const Standard_Integer aStat = (Standard_Integer)itl.Value();
2509 if (!theMapErrors.IsBound(aStat)) {
2510 TopTools_ListOfShape anEmpty;
2512 theMapErrors.Bind(aStat, anEmpty);
2515 theMapErrors.ChangeFind(aStat).Append(theShape);
2520 // Add errors of subshapes on theShape.
2521 const TopAbs_ShapeEnum aType = theShape.ShapeType();
2525 FillErrorsSub(theAna, theShape, TopAbs_VERTEX, theMapErrors);
2528 FillErrorsSub(theAna, theShape, TopAbs_WIRE, theMapErrors);
2529 FillErrorsSub(theAna, theShape, TopAbs_EDGE, theMapErrors);
2530 FillErrorsSub(theAna, theShape, TopAbs_VERTEX, theMapErrors);
2533 FillErrorsSub(theAna, theShape, TopAbs_SHELL, theMapErrors);
2541 //=======================================================================
2542 //function : FillErrors
2543 //purpose : Fill the errors list.
2544 //=======================================================================
2545 void GEOMImpl_IMeasureOperations::FillErrors
2546 (const BRepCheck_Analyzer &theAna,
2547 const TopoDS_Shape &theShape,
2548 std::list<ShapeError> &theErrors) const
2550 // Fill the errors map.
2551 TopTools_DataMapOfIntegerListOfShape aMapErrors;
2552 TopTools_MapOfShape aMapShapes;
2554 FillErrors(theAna, theShape, aMapErrors, aMapShapes);
2556 // Map sub-shapes and their indices
2557 TopTools_IndexedMapOfShape anIndices;
2559 TopExp::MapShapes(theShape, anIndices);
2561 TopTools_DataMapIteratorOfDataMapOfIntegerListOfShape aMapIter(aMapErrors);
2563 for (; aMapIter.More(); aMapIter.Next()) {
2566 anError.error = (BRepCheck_Status)aMapIter.Key();
2568 TopTools_ListIteratorOfListOfShape aListIter(aMapIter.Value());
2569 TopTools_MapOfShape aMapUnique;
2571 for (; aListIter.More(); aListIter.Next()) {
2572 const TopoDS_Shape &aShape = aListIter.Value();
2574 if (aMapUnique.Add(aShape)) {
2575 const Standard_Integer anIndex = anIndices.FindIndex(aShape);
2577 anError.incriminated.push_back(anIndex);
2581 if (!anError.incriminated.empty()) {
2582 theErrors.push_back(anError);