1 // Copyright (C) 2007-2013 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.
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 <Standard_Stream.hxx>
25 #include <GEOMImpl_IMeasureOperations.hxx>
27 #include <GEOMImpl_Types.hxx>
28 #include <GEOMImpl_MeasureDriver.hxx>
29 #include <GEOMImpl_IMeasure.hxx>
30 #include <GEOMImpl_IShapesOperations.hxx>
32 #include <GEOMUtils.hxx>
34 #include <GEOMAlgo_ShapeInfo.hxx>
35 #include <GEOMAlgo_ShapeInfoFiller.hxx>
37 #include <GEOM_Function.hxx>
38 #include <GEOM_PythonDump.hxx>
40 #include <Basics_OCCTVersion.hxx>
42 #include <utilities.h>
44 #include <Utils_ExceptHandlers.hxx>
47 #include <TFunction_DriverTable.hxx>
48 #include <TFunction_Driver.hxx>
49 #include <TFunction_Logbook.hxx>
50 #include <TDF_Tool.hxx>
52 #include <BRep_Builder.hxx>
53 #include <BRep_TFace.hxx>
54 #include <BRep_Tool.hxx>
55 #include <BRepAdaptor_Surface.hxx>
56 #include <BRepBuilderAPI_Copy.hxx>
57 #include <BRepBndLib.hxx>
58 #include <BRepCheck.hxx>
59 #include <BRepCheck_ListIteratorOfListOfStatus.hxx>
60 #include <BRepCheck_Result.hxx>
61 #include <BRepCheck_Shell.hxx>
62 #include <BRepClass3d_SolidClassifier.hxx>
63 #include <BRepClass_FaceClassifier.hxx>
64 #include <BRepExtrema_DistShapeShape.hxx>
65 #include <BRepGProp.hxx>
66 #include <BRepTools.hxx>
68 #include <Bnd_Box.hxx>
73 #include <TopoDS_Edge.hxx>
74 #include <TopoDS_Face.hxx>
75 #include <TopoDS_Shape.hxx>
76 #include <TopoDS_Vertex.hxx>
77 #include <TopoDS_Compound.hxx>
78 #include <TopoDS_Iterator.hxx>
79 #include <TopExp_Explorer.hxx>
80 #include <TopTools_MapOfShape.hxx>
81 #include <TopTools_ListOfShape.hxx>
82 #include <TopTools_ListIteratorOfListOfShape.hxx>
84 #include <ShapeAnalysis.hxx>
85 #include <ShapeAnalysis_Surface.hxx>
87 #include <GeomAPI_IntSS.hxx>
88 #include <GeomAPI_ProjectPointOnCurve.hxx>
89 #include <GeomAPI_ProjectPointOnSurf.hxx>
91 #include <GeomAbs_SurfaceType.hxx>
93 #include <Geom_Line.hxx>
94 #include <Geom_Surface.hxx>
96 #include <GeomLProp_CLProps.hxx>
97 #include <GeomLProp_SLProps.hxx>
99 #include <GProp_GProps.hxx>
100 #include <GProp_PrincipalProps.hxx>
102 #include <gp_Pln.hxx>
103 #include <gp_Lin.hxx>
105 #include <BOPCol_ListOfShape.hxx>
106 #include <BOPDS_DS.hxx>
107 #include <BOPDS_MapOfPassKey.hxx>
108 #include <BOPDS_PassKey.hxx>
109 #include <GEOMAlgo_AlgoTools.hxx>
110 #include <BOPAlgo_CheckerSI.hxx>
112 #include <Standard_Failure.hxx>
113 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
115 //=============================================================================
119 //=============================================================================
120 GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations (GEOM_Engine* theEngine, int theDocID)
121 : GEOM_IOperations(theEngine, theDocID)
123 MESSAGE("GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations");
126 //=============================================================================
130 //=============================================================================
131 GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations()
133 MESSAGE("GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations");
136 //=============================================================================
137 /*! Get kind and parameters of the given shape.
139 //=============================================================================
140 GEOMImpl_IMeasureOperations::ShapeKind GEOMImpl_IMeasureOperations::KindOfShape
141 (Handle(GEOM_Object) theShape,
142 Handle(TColStd_HSequenceOfInteger)& theIntegers,
143 Handle(TColStd_HSequenceOfReal)& theDoubles)
146 ShapeKind aKind = SK_NO_SHAPE;
148 if (theIntegers.IsNull()) theIntegers = new TColStd_HSequenceOfInteger;
149 else theIntegers->Clear();
151 if (theDoubles.IsNull()) theDoubles = new TColStd_HSequenceOfReal;
152 else theDoubles->Clear();
154 if (theShape.IsNull())
157 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
158 if (aRefShape.IsNull()) return aKind;
160 TopoDS_Shape aShape = aRefShape->GetValue();
161 if (aShape.IsNull()) return aKind;
163 int geom_type = theShape->GetType();
165 // check if it's advanced shape
166 if ( geom_type > ADVANCED_BASE ) {
172 GEOMAlgo_ShapeInfoFiller aSF;
173 aSF.SetShape(aShape);
175 Standard_Integer iErr = aSF.ErrorStatus();
177 SetErrorCode("Error in GEOMAlgo_ShapeInfoFiller");
180 const GEOMAlgo_ShapeInfo& anInfo = aSF.Info();
182 // Interprete results
183 TopAbs_ShapeEnum aType = anInfo.Type();
186 case TopAbs_COMPOUND:
187 case TopAbs_COMPSOLID:
189 // (+) geompy.kind.COMPOUND nb_solids nb_faces nb_edges nb_vertices
190 // (+) geompy.kind.COMPSOLID nb_solids nb_faces nb_edges nb_vertices
191 // ??? "nb_faces" - all faces or only 'standalone' faces?
192 if (aType == TopAbs_COMPOUND)
195 aKind = SK_COMPSOLID;
197 //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPOUND));
198 //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPSOLID));
199 theIntegers->Append(anInfo.NbSubShapes(TopAbs_SOLID));
200 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
201 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
202 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
208 // (+) geompy.kind.SHELL geompy.info.closed nb_faces nb_edges nb_vertices
209 // (+) geompy.kind.SHELL geompy.info.unclosed nb_faces nb_edges nb_vertices
212 theIntegers->Append((int)anInfo.KindOfClosed());
214 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
215 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
216 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
222 // (+) geompy.kind.WIRE geompy.info.closed nb_edges nb_vertices
223 // (+) geompy.kind.WIRE geompy.info.unclosed nb_edges nb_vertices
226 theIntegers->Append((int)anInfo.KindOfClosed());
228 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
229 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
237 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
240 case GEOMAlgo_KN_SPHERE:
241 // (+) geompy.kind.SPHERE xc yc zc R
245 gp_Pnt aC = anInfo.Location();
246 theDoubles->Append(aC.X());
247 theDoubles->Append(aC.Y());
248 theDoubles->Append(aC.Z());
250 theDoubles->Append(anInfo.Radius1());
253 case GEOMAlgo_KN_CYLINDER:
254 // (+) geompy.kind.CYLINDER xb yb zb dx dy dz R H
258 gp_Pnt aC = anInfo.Location();
259 theDoubles->Append(aC.X());
260 theDoubles->Append(aC.Y());
261 theDoubles->Append(aC.Z());
263 gp_Ax3 anAx3 = anInfo.Position();
264 gp_Dir aD = anAx3.Direction();
265 theDoubles->Append(aD.X());
266 theDoubles->Append(aD.Y());
267 theDoubles->Append(aD.Z());
269 theDoubles->Append(anInfo.Radius1());
270 theDoubles->Append(anInfo.Height());
273 case GEOMAlgo_KN_BOX:
274 // (+) geompy.kind.BOX xc yc zc ax ay az
278 gp_Pnt aC = anInfo.Location();
279 theDoubles->Append(aC.X());
280 theDoubles->Append(aC.Y());
281 theDoubles->Append(aC.Z());
283 gp_Ax3 anAx3 = anInfo.Position();
284 gp_Dir aD = anAx3.Direction();
285 gp_Dir aX = anAx3.XDirection();
288 if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
289 aX.IsParallel(gp::DX(), Precision::Angular())) {
290 theDoubles->Append(anInfo.Length()); // ax'
291 theDoubles->Append(anInfo.Width()); // ay'
292 theDoubles->Append(anInfo.Height()); // az'
294 else if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
295 aX.IsParallel(gp::DY(), Precision::Angular())) {
296 theDoubles->Append(anInfo.Width()); // ay'
297 theDoubles->Append(anInfo.Length()); // ax'
298 theDoubles->Append(anInfo.Height()); // az'
300 else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
301 aX.IsParallel(gp::DZ(), Precision::Angular())) {
302 theDoubles->Append(anInfo.Height()); // az'
303 theDoubles->Append(anInfo.Width()); // ay'
304 theDoubles->Append(anInfo.Length()); // ax'
306 else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
307 aX.IsParallel(gp::DY(), Precision::Angular())) {
308 theDoubles->Append(anInfo.Height()); // az'
309 theDoubles->Append(anInfo.Length()); // ax'
310 theDoubles->Append(anInfo.Width()); // ay'
312 else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
313 aX.IsParallel(gp::DZ(), Precision::Angular())) {
314 theDoubles->Append(anInfo.Width()); // ay'
315 theDoubles->Append(anInfo.Height()); // az'
316 theDoubles->Append(anInfo.Length()); // ax'
318 else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
319 aX.IsParallel(gp::DX(), Precision::Angular())) {
320 theDoubles->Append(anInfo.Length()); // ax'
321 theDoubles->Append(anInfo.Height()); // az'
322 theDoubles->Append(anInfo.Width()); // ay'
325 // (+) geompy.kind.ROTATED_BOX xo yo zo zx zy zz xx xy xz ax ay az
326 aKind = SK_ROTATED_BOX;
328 // Direction and XDirection
329 theDoubles->Append(aD.X());
330 theDoubles->Append(aD.Y());
331 theDoubles->Append(aD.Z());
333 theDoubles->Append(aX.X());
334 theDoubles->Append(aX.Y());
335 theDoubles->Append(aX.Z());
338 theDoubles->Append(anInfo.Length());
339 theDoubles->Append(anInfo.Width());
340 theDoubles->Append(anInfo.Height());
344 case GEOMAlgo_KN_TORUS:
345 // (+) geompy.kind.TORUS xc yc zc dx dy dz R_1 R_2
349 gp_Pnt aO = anInfo.Location();
350 theDoubles->Append(aO.X());
351 theDoubles->Append(aO.Y());
352 theDoubles->Append(aO.Z());
354 gp_Ax3 anAx3 = anInfo.Position();
355 gp_Dir aD = anAx3.Direction();
356 theDoubles->Append(aD.X());
357 theDoubles->Append(aD.Y());
358 theDoubles->Append(aD.Z());
360 theDoubles->Append(anInfo.Radius1());
361 theDoubles->Append(anInfo.Radius2());
364 case GEOMAlgo_KN_CONE:
365 // (+) geompy.kind.CONE xb yb zb dx dy dz R_1 R_2 H
369 gp_Pnt aO = anInfo.Location();
370 theDoubles->Append(aO.X());
371 theDoubles->Append(aO.Y());
372 theDoubles->Append(aO.Z());
374 gp_Ax3 anAx3 = anInfo.Position();
375 gp_Dir aD = anAx3.Direction();
376 theDoubles->Append(aD.X());
377 theDoubles->Append(aD.Y());
378 theDoubles->Append(aD.Z());
380 theDoubles->Append(anInfo.Radius1());
381 theDoubles->Append(anInfo.Radius2());
382 theDoubles->Append(anInfo.Height());
385 case GEOMAlgo_KN_POLYHEDRON:
386 // (+) geompy.kind.POLYHEDRON nb_faces nb_edges nb_vertices
388 aKind = SK_POLYHEDRON;
390 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
391 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
392 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
396 // (+) geompy.kind.SOLID nb_faces nb_edges nb_vertices
398 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
399 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
400 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
410 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
412 case GEOMAlgo_KN_SPHERE:
413 // (+) geompy.kind.SPHERE2D xc yc zc R
417 gp_Pnt aC = anInfo.Location();
418 theDoubles->Append(aC.X());
419 theDoubles->Append(aC.Y());
420 theDoubles->Append(aC.Z());
422 theDoubles->Append(anInfo.Radius1());
425 case GEOMAlgo_KN_CYLINDER:
426 // (+) geompy.kind.CYLINDER2D xb yb zb dx dy dz R H
428 aKind = SK_CYLINDER2D;
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.Height());
445 case GEOMAlgo_KN_TORUS:
446 // (+) geompy.kind.TORUS2D xc yc zc dx dy dz R_1 R_2
450 gp_Pnt aO = anInfo.Location();
451 theDoubles->Append(aO.X());
452 theDoubles->Append(aO.Y());
453 theDoubles->Append(aO.Z());
455 gp_Ax3 anAx3 = anInfo.Position();
456 gp_Dir aD = anAx3.Direction();
457 theDoubles->Append(aD.X());
458 theDoubles->Append(aD.Y());
459 theDoubles->Append(aD.Z());
461 theDoubles->Append(anInfo.Radius1());
462 theDoubles->Append(anInfo.Radius2());
465 case GEOMAlgo_KN_CONE:
466 // (+) geompy.kind.CONE2D xc yc zc dx dy dz R_1 R_2 H
470 gp_Pnt aO = anInfo.Location();
471 theDoubles->Append(aO.X());
472 theDoubles->Append(aO.Y());
473 theDoubles->Append(aO.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());
483 theDoubles->Append(anInfo.Height());
486 case GEOMAlgo_KN_DISKCIRCLE:
487 // (+) geompy.kind.DISK_CIRCLE xc yc zc dx dy dz R
489 aKind = SK_DISK_CIRCLE;
491 gp_Pnt aC = anInfo.Location();
492 theDoubles->Append(aC.X());
493 theDoubles->Append(aC.Y());
494 theDoubles->Append(aC.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 theDoubles->Append(anInfo.Radius1());
505 case GEOMAlgo_KN_DISKELLIPSE:
506 // (+) geompy.kind.DISK_ELLIPSE xc yc zc dx dy dz R_1 R_2
508 aKind = SK_DISK_ELLIPSE;
510 gp_Pnt aC = anInfo.Location();
511 theDoubles->Append(aC.X());
512 theDoubles->Append(aC.Y());
513 theDoubles->Append(aC.Z());
515 gp_Ax3 anAx3 = anInfo.Position();
516 gp_Dir aD = anAx3.Direction();
517 theDoubles->Append(aD.X());
518 theDoubles->Append(aD.Y());
519 theDoubles->Append(aD.Z());
521 theDoubles->Append(anInfo.Radius1());
522 theDoubles->Append(anInfo.Radius2());
525 case GEOMAlgo_KN_RECTANGLE:
526 case GEOMAlgo_KN_TRIANGLE:
527 case GEOMAlgo_KN_QUADRANGLE:
528 case GEOMAlgo_KN_POLYGON:
529 // (+) geompy.kind.POLYGON xo yo zo dx dy dz nb_edges nb_vertices
533 gp_Pnt aO = anInfo.Location();
534 theDoubles->Append(aO.X());
535 theDoubles->Append(aO.Y());
536 theDoubles->Append(aO.Z());
538 gp_Ax3 anAx3 = anInfo.Position();
539 gp_Dir aD = anAx3.Direction();
540 theDoubles->Append(aD.X());
541 theDoubles->Append(aD.Y());
542 theDoubles->Append(aD.Z());
544 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
545 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
548 case GEOMAlgo_KN_PLANE: // infinite
549 // (+) geompy.kind.PLANE xo yo zo dx dy dz
553 gp_Pnt aC = anInfo.Location();
554 theDoubles->Append(aC.X());
555 theDoubles->Append(aC.Y());
556 theDoubles->Append(aC.Z());
558 gp_Ax3 anAx3 = anInfo.Position();
559 gp_Dir aD = anAx3.Direction();
560 theDoubles->Append(aD.X());
561 theDoubles->Append(aD.Y());
562 theDoubles->Append(aD.Z());
566 if (anInfo.KindOfShape() == GEOMAlgo_KS_PLANE) {
567 // (+) geompy.kind.PLANAR xo yo zo dx dy dz nb_edges nb_vertices
571 gp_Pnt aC = anInfo.Location();
572 theDoubles->Append(aC.X());
573 theDoubles->Append(aC.Y());
574 theDoubles->Append(aC.Z());
576 gp_Ax3 anAx3 = anInfo.Position();
577 gp_Dir aD = anAx3.Direction();
578 theDoubles->Append(aD.X());
579 theDoubles->Append(aD.Y());
580 theDoubles->Append(aD.Z());
582 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
583 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
586 // ??? geompy.kind.FACE nb_edges nb_vertices _surface_type_id_
587 // (+) geompy.kind.FACE nb_edges nb_vertices
589 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
590 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
600 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
602 case GEOMAlgo_KN_CIRCLE:
604 // (+) geompy.kind.CIRCLE xc yc zc dx dy dz R
607 gp_Pnt aC = anInfo.Location();
608 theDoubles->Append(aC.X());
609 theDoubles->Append(aC.Y());
610 theDoubles->Append(aC.Z());
612 gp_Ax3 anAx3 = anInfo.Position();
613 gp_Dir aD = anAx3.Direction();
614 theDoubles->Append(aD.X());
615 theDoubles->Append(aD.Y());
616 theDoubles->Append(aD.Z());
618 theDoubles->Append(anInfo.Radius1());
621 case GEOMAlgo_KN_ARCCIRCLE:
623 // (+) geompy.kind.ARC_CIRCLE xc yc zc dx dy dz R x1 y1 z1 x2 y2 z2
624 aKind = SK_ARC_CIRCLE;
626 gp_Pnt aC = anInfo.Location();
627 theDoubles->Append(aC.X());
628 theDoubles->Append(aC.Y());
629 theDoubles->Append(aC.Z());
631 gp_Ax3 anAx3 = anInfo.Position();
632 gp_Dir aD = anAx3.Direction();
633 theDoubles->Append(aD.X());
634 theDoubles->Append(aD.Y());
635 theDoubles->Append(aD.Z());
637 theDoubles->Append(anInfo.Radius1());
639 gp_Pnt aP1 = anInfo.Pnt1();
640 theDoubles->Append(aP1.X());
641 theDoubles->Append(aP1.Y());
642 theDoubles->Append(aP1.Z());
644 gp_Pnt aP2 = anInfo.Pnt2();
645 theDoubles->Append(aP2.X());
646 theDoubles->Append(aP2.Y());
647 theDoubles->Append(aP2.Z());
650 case GEOMAlgo_KN_ELLIPSE:
652 // (+) geompy.kind.ELLIPSE xc yc zc dx dy dz R_1 R_2
655 gp_Pnt aC = anInfo.Location();
656 theDoubles->Append(aC.X());
657 theDoubles->Append(aC.Y());
658 theDoubles->Append(aC.Z());
660 gp_Ax3 anAx3 = anInfo.Position();
661 gp_Dir aD = anAx3.Direction();
662 theDoubles->Append(aD.X());
663 theDoubles->Append(aD.Y());
664 theDoubles->Append(aD.Z());
666 theDoubles->Append(anInfo.Radius1());
667 theDoubles->Append(anInfo.Radius2());
670 case GEOMAlgo_KN_ARCELLIPSE:
672 // (+) geompy.kind.ARC_ELLIPSE xc yc zc dx dy dz R_1 R_2 x1 y1 z1 x2 y2 z2
673 aKind = SK_ARC_ELLIPSE;
675 gp_Pnt aC = anInfo.Location();
676 theDoubles->Append(aC.X());
677 theDoubles->Append(aC.Y());
678 theDoubles->Append(aC.Z());
680 gp_Ax3 anAx3 = anInfo.Position();
681 gp_Dir aD = anAx3.Direction();
682 theDoubles->Append(aD.X());
683 theDoubles->Append(aD.Y());
684 theDoubles->Append(aD.Z());
686 theDoubles->Append(anInfo.Radius1());
687 theDoubles->Append(anInfo.Radius2());
689 gp_Pnt aP1 = anInfo.Pnt1();
690 theDoubles->Append(aP1.X());
691 theDoubles->Append(aP1.Y());
692 theDoubles->Append(aP1.Z());
694 gp_Pnt aP2 = anInfo.Pnt2();
695 theDoubles->Append(aP2.X());
696 theDoubles->Append(aP2.Y());
697 theDoubles->Append(aP2.Z());
700 case GEOMAlgo_KN_LINE:
702 // ??? geompy.kind.LINE x1 y1 z1 x2 y2 z2
703 // (+) geompy.kind.LINE x1 y1 z1 dx dy dz
706 gp_Pnt aO = anInfo.Location();
707 theDoubles->Append(aO.X());
708 theDoubles->Append(aO.Y());
709 theDoubles->Append(aO.Z());
711 gp_Dir aD = anInfo.Direction();
712 theDoubles->Append(aD.X());
713 theDoubles->Append(aD.Y());
714 theDoubles->Append(aD.Z());
717 case GEOMAlgo_KN_SEGMENT:
719 // (+) geompy.kind.SEGMENT x1 y1 z1 x2 y2 z2
722 gp_Pnt aP1 = anInfo.Pnt1();
723 theDoubles->Append(aP1.X());
724 theDoubles->Append(aP1.Y());
725 theDoubles->Append(aP1.Z());
727 gp_Pnt aP2 = anInfo.Pnt2();
728 theDoubles->Append(aP2.X());
729 theDoubles->Append(aP2.Y());
730 theDoubles->Append(aP2.Z());
734 // ??? geompy.kind.EDGE nb_vertices _curve_type_id_
735 // (+) geompy.kind.EDGE nb_vertices
736 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
743 // (+) geompy.kind.VERTEX x y z
746 gp_Pnt aP = anInfo.Location();
747 theDoubles->Append(aP.X());
748 theDoubles->Append(aP.Y());
749 theDoubles->Append(aP.Z());
758 //=============================================================================
762 //=============================================================================
763 void GEOMImpl_IMeasureOperations::GetPosition
764 (Handle(GEOM_Object) theShape,
765 Standard_Real& Ox, Standard_Real& Oy, Standard_Real& Oz,
766 Standard_Real& Zx, Standard_Real& Zy, Standard_Real& Zz,
767 Standard_Real& Xx, Standard_Real& Xy, Standard_Real& Xz)
771 //Set default values: global CS
772 Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
775 if (theShape.IsNull()) return;
777 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
778 if (aRefShape.IsNull()) return;
780 TopoDS_Shape aShape = aRefShape->GetValue();
781 if (aShape.IsNull()) {
782 SetErrorCode("The Objects has NULL Shape");
787 #if OCC_VERSION_LARGE > 0x06010000
791 gp_Ax3 anAx3 = GEOMUtils::GetPosition(aShape);
793 gp_Pnt anOri = anAx3.Location();
794 gp_Dir aDirZ = anAx3.Direction();
795 gp_Dir aDirX = anAx3.XDirection();
798 anOri.Coord(Ox, Oy, Oz);
799 aDirZ.Coord(Zx, Zy, Zz);
800 aDirX.Coord(Xx, Xy, Xz);
802 catch (Standard_Failure) {
803 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
804 SetErrorCode(aFail->GetMessageString());
811 //=============================================================================
815 //=============================================================================
816 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetCentreOfMass
817 (Handle(GEOM_Object) theShape)
821 if (theShape.IsNull()) return NULL;
823 //Add a new CentreOfMass object
824 Handle(GEOM_Object) aCDG = GetEngine()->AddObject(GetDocID(), GEOM_CDG);
826 //Add a new CentreOfMass function
827 Handle(GEOM_Function) aFunction =
828 aCDG->AddFunction(GEOMImpl_MeasureDriver::GetID(), CDG_MEASURE);
829 if (aFunction.IsNull()) return NULL;
831 //Check if the function is set correctly
832 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
834 GEOMImpl_IMeasure aCI (aFunction);
836 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
837 if (aRefShape.IsNull()) return NULL;
839 aCI.SetBase(aRefShape);
841 //Compute the CentreOfMass value
843 #if OCC_VERSION_LARGE > 0x06010000
846 if (!GetSolver()->ComputeFunction(aFunction)) {
847 SetErrorCode("Measure driver failed to compute centre of mass");
851 catch (Standard_Failure) {
852 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
853 SetErrorCode(aFail->GetMessageString());
857 //Make a Python command
858 GEOM::TPythonDump(aFunction) << aCDG << " = geompy.MakeCDG(" << theShape << ")";
864 //=============================================================================
868 //=============================================================================
869 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetVertexByIndex
870 (Handle(GEOM_Object) theShape,
871 Standard_Integer theIndex)
875 if (theShape.IsNull()) return NULL;
877 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
878 if (aRefShape.IsNull()) return NULL;
880 //Add a new Vertex object
881 Handle(GEOM_Object) aVertex = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
884 Handle(GEOM_Function) aFunction =
885 aVertex->AddFunction(GEOMImpl_MeasureDriver::GetID(), VERTEX_BY_INDEX);
886 if (aFunction.IsNull()) return NULL;
888 //Check if the function is set correctly
889 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
891 GEOMImpl_IMeasure aCI (aFunction);
892 aCI.SetBase(aRefShape);
893 aCI.SetIndex(theIndex);
897 #if OCC_VERSION_LARGE > 0x06010000
900 if (!GetSolver()->ComputeFunction(aFunction)) {
901 SetErrorCode("Vertex by index driver failed.");
905 catch (Standard_Failure) {
906 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
907 SetErrorCode(aFail->GetMessageString());
911 //Make a Python command
912 GEOM::TPythonDump(aFunction) << aVertex << " = geompy.GetVertexByIndex(" << theShape << ", " << theIndex << ")";
918 //=============================================================================
922 //=============================================================================
923 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetNormal
924 (Handle(GEOM_Object) theFace,
925 Handle(GEOM_Object) theOptionalPoint)
929 if (theFace.IsNull()) return NULL;
931 //Add a new Normale object
932 Handle(GEOM_Object) aNorm = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
934 //Add a new Normale function
935 Handle(GEOM_Function) aFunction =
936 aNorm->AddFunction(GEOMImpl_MeasureDriver::GetID(), VECTOR_FACE_NORMALE);
937 if (aFunction.IsNull()) return NULL;
939 //Check if the function is set correctly
940 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
942 GEOMImpl_IMeasure aCI (aFunction);
944 Handle(GEOM_Function) aFace = theFace->GetLastFunction();
945 if (aFace.IsNull()) return NULL;
949 if (!theOptionalPoint.IsNull()) {
950 Handle(GEOM_Function) anOptPnt = theOptionalPoint->GetLastFunction();
951 aCI.SetPoint(anOptPnt);
954 //Compute the Normale value
956 #if OCC_VERSION_LARGE > 0x06010000
959 if (!GetSolver()->ComputeFunction(aFunction)) {
960 SetErrorCode("Measure driver failed to compute normake of face");
964 catch (Standard_Failure) {
965 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
966 SetErrorCode(aFail->GetMessageString());
970 //Make a Python command
971 GEOM::TPythonDump pd (aFunction);
972 pd << aNorm << " = geompy.GetNormal(" << theFace;
973 if (!theOptionalPoint.IsNull()) {
974 pd << ", " << theOptionalPoint;
982 //=============================================================================
986 //=============================================================================
987 void GEOMImpl_IMeasureOperations::GetBasicProperties (Handle(GEOM_Object) theShape,
988 Standard_Real& theLength,
989 Standard_Real& theSurfArea,
990 Standard_Real& theVolume)
994 if (theShape.IsNull()) return;
996 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
997 if (aRefShape.IsNull()) return;
999 TopoDS_Shape aShape = aRefShape->GetValue();
1000 if (aShape.IsNull()) {
1001 SetErrorCode("The Objects has NULL Shape");
1005 //Compute the parameters
1006 GProp_GProps LProps, SProps;
1008 #if OCC_VERSION_LARGE > 0x06010000
1011 BRepGProp::LinearProperties(aShape, LProps);
1012 theLength = LProps.Mass();
1014 BRepGProp::SurfaceProperties(aShape, SProps);
1015 theSurfArea = SProps.Mass();
1018 if (aShape.ShapeType() < TopAbs_SHELL) {
1019 for (TopExp_Explorer Exp (aShape, TopAbs_SOLID); Exp.More(); Exp.Next()) {
1020 GProp_GProps VProps;
1021 BRepGProp::VolumeProperties(Exp.Current(), VProps);
1022 theVolume += VProps.Mass();
1026 catch (Standard_Failure) {
1027 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1028 SetErrorCode(aFail->GetMessageString());
1035 //=============================================================================
1039 //=============================================================================
1040 void GEOMImpl_IMeasureOperations::GetInertia
1041 (Handle(GEOM_Object) theShape,
1042 Standard_Real& I11, Standard_Real& I12, Standard_Real& I13,
1043 Standard_Real& I21, Standard_Real& I22, Standard_Real& I23,
1044 Standard_Real& I31, Standard_Real& I32, Standard_Real& I33,
1045 Standard_Real& Ix , Standard_Real& Iy , Standard_Real& Iz)
1049 if (theShape.IsNull()) return;
1051 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1052 if (aRefShape.IsNull()) return;
1054 TopoDS_Shape aShape = aRefShape->GetValue();
1055 if (aShape.IsNull()) {
1056 SetErrorCode("The Objects has NULL Shape");
1060 //Compute the parameters
1061 GProp_GProps System;
1064 #if OCC_VERSION_LARGE > 0x06010000
1067 if (aShape.ShapeType() == TopAbs_VERTEX ||
1068 aShape.ShapeType() == TopAbs_EDGE ||
1069 aShape.ShapeType() == TopAbs_WIRE) {
1070 BRepGProp::LinearProperties(aShape, System);
1071 } else if (aShape.ShapeType() == TopAbs_FACE ||
1072 aShape.ShapeType() == TopAbs_SHELL) {
1073 BRepGProp::SurfaceProperties(aShape, System);
1075 BRepGProp::VolumeProperties(aShape, System);
1077 gp_Mat I = System.MatrixOfInertia();
1091 GProp_PrincipalProps Pr = System.PrincipalProperties();
1092 Pr.Moments(Ix,Iy,Iz);
1094 catch (Standard_Failure) {
1095 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1096 SetErrorCode(aFail->GetMessageString());
1103 //=============================================================================
1107 //=============================================================================
1108 void GEOMImpl_IMeasureOperations::GetBoundingBox
1109 (Handle(GEOM_Object) theShape,
1110 const Standard_Boolean precise,
1111 Standard_Real& Xmin, Standard_Real& Xmax,
1112 Standard_Real& Ymin, Standard_Real& Ymax,
1113 Standard_Real& Zmin, Standard_Real& Zmax)
1117 if (theShape.IsNull()) return;
1119 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1120 if (aRefShape.IsNull()) return;
1122 TopoDS_Shape aShape = aRefShape->GetValue();
1123 if (aShape.IsNull()) {
1124 SetErrorCode("The Objects has NULL Shape");
1128 //Compute the parameters
1132 #if OCC_VERSION_LARGE > 0x06010000
1135 BRepBuilderAPI_Copy aCopyTool (aShape);
1136 if (!aCopyTool.IsDone()) {
1137 SetErrorCode("GetBoundingBox Error: Bad shape detected");
1141 aShape = aCopyTool.Shape();
1143 // remove triangulation to obtain more exact boundaries
1144 BRepTools::Clean(aShape);
1146 BRepBndLib::Add(aShape, B);
1149 if (!GEOMUtils::PreciseBoundingBox(aShape, B)) {
1150 SetErrorCode("GetBoundingBox Error: Bounding box cannot be precised");
1155 B.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
1157 catch (Standard_Failure) {
1158 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1159 SetErrorCode(aFail->GetMessageString());
1166 //=============================================================================
1170 //=============================================================================
1171 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetBoundingBox
1172 (Handle(GEOM_Object) theShape,
1173 const Standard_Boolean precise)
1177 if (theShape.IsNull()) return NULL;
1179 //Add a new BoundingBox object
1180 Handle(GEOM_Object) aBnd = GetEngine()->AddObject(GetDocID(), GEOM_BOX);
1182 //Add a new BoundingBox function
1183 const int aType = (precise ? BND_BOX_MEASURE_PRECISE : BND_BOX_MEASURE);
1184 Handle(GEOM_Function) aFunction =
1185 aBnd->AddFunction(GEOMImpl_MeasureDriver::GetID(), aType);
1186 if (aFunction.IsNull()) return NULL;
1188 //Check if the function is set correctly
1189 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
1191 GEOMImpl_IMeasure aCI (aFunction);
1193 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1194 if (aRefShape.IsNull()) return NULL;
1196 aCI.SetBase(aRefShape);
1198 //Compute the BoundingBox value
1200 #if OCC_VERSION_LARGE > 0x06010000
1203 if (!GetSolver()->ComputeFunction(aFunction)) {
1204 SetErrorCode("Measure driver failed to compute a bounding box");
1208 catch (Standard_Failure) {
1209 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1210 SetErrorCode(aFail->GetMessageString());
1214 //Make a Python command
1215 GEOM::TPythonDump aPd(aFunction);
1217 aPd << aBnd << " = geompy.MakeBoundingBox(" << theShape;
1229 //=============================================================================
1233 //=============================================================================
1234 void GEOMImpl_IMeasureOperations::GetTolerance
1235 (Handle(GEOM_Object) theShape,
1236 Standard_Real& FaceMin, Standard_Real& FaceMax,
1237 Standard_Real& EdgeMin, Standard_Real& EdgeMax,
1238 Standard_Real& VertMin, Standard_Real& VertMax)
1242 if (theShape.IsNull()) return;
1244 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1245 if (aRefShape.IsNull()) return;
1247 TopoDS_Shape aShape = aRefShape->GetValue();
1248 if (aShape.IsNull()) {
1249 SetErrorCode("The Objects has NULL Shape");
1253 //Compute the parameters
1255 FaceMin = EdgeMin = VertMin = RealLast();
1256 FaceMax = EdgeMax = VertMax = -RealLast();
1259 #if OCC_VERSION_LARGE > 0x06010000
1262 for (TopExp_Explorer ExF (aShape, TopAbs_FACE); ExF.More(); ExF.Next()) {
1263 TopoDS_Face Face = TopoDS::Face(ExF.Current());
1264 T = BRep_Tool::Tolerance(Face);
1270 for (TopExp_Explorer ExE (aShape, TopAbs_EDGE); ExE.More(); ExE.Next()) {
1271 TopoDS_Edge Edge = TopoDS::Edge(ExE.Current());
1272 T = BRep_Tool::Tolerance(Edge);
1278 for (TopExp_Explorer ExV (aShape, TopAbs_VERTEX); ExV.More(); ExV.Next()) {
1279 TopoDS_Vertex Vertex = TopoDS::Vertex(ExV.Current());
1280 T = BRep_Tool::Tolerance(Vertex);
1287 catch (Standard_Failure) {
1288 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1289 SetErrorCode(aFail->GetMessageString());
1296 //=============================================================================
1300 //=============================================================================
1301 bool GEOMImpl_IMeasureOperations::CheckShape (Handle(GEOM_Object) theShape,
1302 const Standard_Boolean theIsCheckGeom,
1303 TCollection_AsciiString& theDump)
1307 if (theShape.IsNull()) return false;
1309 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1310 if (aRefShape.IsNull()) return false;
1312 TopoDS_Shape aShape = aRefShape->GetValue();
1313 if (aShape.IsNull()) {
1314 SetErrorCode("The Objects has NULL Shape");
1318 //Compute the parameters
1319 bool isValid = false;
1321 #if OCC_VERSION_LARGE > 0x06010000
1324 BRepCheck_Analyzer ana (aShape, theIsCheckGeom);
1325 if (ana.IsValid()) {
1329 StructuralDump(ana, aShape, theDump);
1332 catch (Standard_Failure) {
1333 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1334 SetErrorCode(aFail->GetMessageString());
1342 //=============================================================================
1344 * CheckSelfIntersections
1346 //=============================================================================
1347 bool GEOMImpl_IMeasureOperations::CheckSelfIntersections
1348 (Handle(GEOM_Object) theShape,
1349 Handle(TColStd_HSequenceOfInteger)& theIntersections)
1352 bool isGood = false;
1354 if (theIntersections.IsNull())
1355 theIntersections = new TColStd_HSequenceOfInteger;
1357 theIntersections->Clear();
1359 if (theShape.IsNull())
1362 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1363 if (aRefShape.IsNull()) return isGood;
1365 TopoDS_Shape aShape = aRefShape->GetValue();
1366 if (aShape.IsNull()) return isGood;
1370 TopoDS_Compound aCS;
1371 TopoDS_Shape aScopy;
1373 GEOMAlgo_AlgoTools::CopyShape(aShape, aScopy);
1375 // Map sub-shapes and their indices
1376 TopTools_IndexedMapOfShape anIndices;
1377 TopExp::MapShapes(aScopy, anIndices);
1379 aBB.MakeCompound(aCS);
1380 aBB.Add(aCS, aScopy);
1382 BOPCol_ListOfShape aLCS;
1383 aLCS.Append(aScopy);
1385 BOPAlgo_CheckerSI aCSI; // checker of self-interferences
1386 aCSI.SetArguments(aLCS);
1388 // 1. Launch the checker
1390 Standard_Integer iErr = aCSI.ErrorStatus();
1392 return false; // Error
1397 Standard_Integer aNbS, n1, n2;
1398 BOPDS_MapIteratorMapOfPassKey aItMPK;
1400 // 2. Take the shapes from DS
1401 const BOPDS_DS& aDS = aCSI.DS();
1402 aNbS=aDS.NbShapes();
1404 // 3. Get the pairs of interfered shapes
1405 const BOPDS_MapOfPassKey& aMPK=aDS.Interferences();
1406 aItMPK.Initialize(aMPK);
1407 for (; aItMPK.More(); aItMPK.Next()) {
1408 const BOPDS_PassKey& aPK=aItMPK.Value();
1411 if (n1 > aNbS || n2 > aNbS){
1412 return false; // Error
1414 const TopoDS_Shape& aS1 = aDS.Shape(n1);
1415 const TopoDS_Shape& aS2 = aDS.Shape(n2);
1417 theIntersections->Append(anIndices.FindIndex(aS1));
1418 theIntersections->Append(anIndices.FindIndex(aS2));
1426 //=============================================================================
1430 //=============================================================================
1431 TCollection_AsciiString GEOMImpl_IMeasureOperations::IsGoodForSolid (Handle(GEOM_Object) theShape)
1435 TCollection_AsciiString aRes = "";
1437 if (theShape.IsNull()) {
1438 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1441 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1442 if (aRefShape.IsNull()) {
1443 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1446 TopoDS_Shape aShape = aRefShape->GetValue();
1447 if (aShape.IsNull()) {
1448 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1451 if (aShape.ShapeType() == TopAbs_COMPOUND) {
1452 TopoDS_Iterator It (aShape, Standard_True, Standard_True);
1453 if (It.More()) aShape = It.Value();
1455 if (aShape.ShapeType() == TopAbs_SHELL) {
1456 BRepCheck_Shell chkShell (TopoDS::Shell(aShape));
1457 if (chkShell.Closed() == BRepCheck_NotClosed) {
1458 aRes = "WRN_SHAPE_UNCLOSED";
1462 aRes = "WRN_SHAPE_NOT_SHELL";
1474 //=============================================================================
1478 //=============================================================================
1479 TCollection_AsciiString GEOMImpl_IMeasureOperations::WhatIs (Handle(GEOM_Object) theShape)
1483 TCollection_AsciiString Astr;
1485 if (theShape.IsNull()) return Astr;
1487 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1488 if (aRefShape.IsNull()) return Astr;
1490 TopoDS_Shape aShape = aRefShape->GetValue();
1491 if (aShape.IsNull()) {
1492 SetErrorCode("The Objects has NULL Shape");
1496 //Compute the parameters
1497 if (aShape.ShapeType() == TopAbs_EDGE) {
1498 if (BRep_Tool::Degenerated(TopoDS::Edge(aShape))) {
1499 Astr = Astr + " It is a degenerated edge \n";
1503 Astr = Astr + " Number of sub-shapes : \n";
1506 #if OCC_VERSION_LARGE > 0x06010000
1509 int iType, nbTypes [TopAbs_SHAPE];
1510 for (iType = 0; iType < TopAbs_SHAPE; ++iType)
1512 nbTypes[aShape.ShapeType()]++;
1514 TopTools_MapOfShape aMapOfShape;
1515 aMapOfShape.Add(aShape);
1516 TopTools_ListOfShape aListOfShape;
1517 aListOfShape.Append(aShape);
1519 TopTools_ListIteratorOfListOfShape itL (aListOfShape);
1520 for (; itL.More(); itL.Next()) {
1521 TopoDS_Iterator it (itL.Value());
1522 for (; it.More(); it.Next()) {
1523 TopoDS_Shape s = it.Value();
1524 if (aMapOfShape.Add(s)) {
1525 aListOfShape.Append(s);
1526 nbTypes[s.ShapeType()]++;
1531 Astr = Astr + " VERTEX : " + TCollection_AsciiString(nbTypes[TopAbs_VERTEX]) + "\n";
1532 Astr = Astr + " EDGE : " + TCollection_AsciiString(nbTypes[TopAbs_EDGE]) + "\n";
1533 Astr = Astr + " WIRE : " + TCollection_AsciiString(nbTypes[TopAbs_WIRE]) + "\n";
1534 Astr = Astr + " FACE : " + TCollection_AsciiString(nbTypes[TopAbs_FACE]) + "\n";
1535 Astr = Astr + " SHELL : " + TCollection_AsciiString(nbTypes[TopAbs_SHELL]) + "\n";
1536 Astr = Astr + " SOLID : " + TCollection_AsciiString(nbTypes[TopAbs_SOLID]) + "\n";
1537 Astr = Astr + " COMPSOLID : " + TCollection_AsciiString(nbTypes[TopAbs_COMPSOLID]) + "\n";
1538 Astr = Astr + " COMPOUND : " + TCollection_AsciiString(nbTypes[TopAbs_COMPOUND]) + "\n";
1539 Astr = Astr + " SHAPE : " + TCollection_AsciiString(aMapOfShape.Extent());
1541 catch (Standard_Failure) {
1542 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1543 SetErrorCode(aFail->GetMessageString());
1551 //=============================================================================
1555 //=============================================================================
1557 GEOMImpl_IMeasureOperations::AreCoordsInside(Handle(GEOM_Object) theShape,
1558 const std::vector<double>& coords,
1561 std::vector<bool> isInsideRes;
1562 if (!theShape.IsNull()) {
1563 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1564 if (!aRefShape.IsNull()) {
1565 TopoDS_Shape aShape = aRefShape->GetValue();
1566 if (!aShape.IsNull())
1568 TopTools_IndexedMapOfShape mapShape;
1570 TopExp_Explorer anExp;
1571 for ( anExp.Init( aShape, TopAbs_SOLID ); anExp.More(); anExp.Next() )
1572 mapShape.Add( anExp.Current() );
1573 for ( anExp.Init( aShape, TopAbs_FACE, TopAbs_SOLID ); anExp.More(); anExp.Next() )
1574 mapShape.Add( anExp.Current() );
1575 for ( anExp.Init( aShape, TopAbs_EDGE, TopAbs_FACE ); anExp.More(); anExp.Next() )
1576 mapShape.Add( anExp.Current() );
1577 for ( anExp.Init( aShape, TopAbs_VERTEX, TopAbs_EDGE ); anExp.More(); anExp.Next() )
1578 mapShape.Add( anExp.Current() ); //// ?????????
1580 size_t nb_points = coords.size()/3, nb_points_inside = 0;
1581 isInsideRes.resize( nb_points, false );
1583 for ( int iS = 1; iS <= mapShape.Extent(); ++iS )
1585 if ( nb_points_inside == nb_points )
1587 aShape = mapShape( iS );
1588 switch ( aShape.ShapeType() ) {
1591 BRepClass3d_SolidClassifier SC( TopoDS::Solid( aShape ));
1592 for ( size_t i = 0; i < nb_points; i++)
1594 if ( isInsideRes[ i ]) continue;
1595 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
1596 SC.Perform( aPnt, tolerance );
1597 isInsideRes[ i ] = (( SC.State() == TopAbs_IN ) || ( SC.State() == TopAbs_ON ));
1598 nb_points_inside += isInsideRes[ i ];
1604 Standard_Real u1,u2,v1,v2;
1605 const TopoDS_Face& face = TopoDS::Face( aShape );
1606 Handle(Geom_Surface) surf = BRep_Tool::Surface( face );
1607 surf->Bounds( u1,u2,v1,v2 );
1608 GeomAPI_ProjectPointOnSurf project;
1609 project.Init(surf, u1,u2, v1,v2, tolerance );
1610 for ( size_t i = 0; i < nb_points; i++)
1612 if ( isInsideRes[ i ]) continue;
1613 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
1614 project.Perform( aPnt );
1615 if ( project.IsDone() &&
1616 project.NbPoints() > 0 &&
1617 project.LowerDistance() <= tolerance )
1619 Quantity_Parameter u, v;
1620 project.LowerDistanceParameters(u, v);
1621 gp_Pnt2d uv( u, v );
1622 BRepClass_FaceClassifier FC ( face, uv, tolerance );
1623 isInsideRes[ i ] = (( FC.State() == TopAbs_IN ) || ( FC.State() == TopAbs_ON ));
1624 nb_points_inside += isInsideRes[ i ];
1632 const TopoDS_Edge& edge = TopoDS::Edge( aShape );
1633 Handle(Geom_Curve) curve = BRep_Tool::Curve( edge, f, l );
1634 GeomAPI_ProjectPointOnCurve project;
1635 project.Init( curve, f, l );
1636 for ( size_t i = 0; i < nb_points; i++)
1638 if ( isInsideRes[ i ]) continue;
1639 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
1640 project.Perform( aPnt );
1641 isInsideRes[ i ] = ( project.NbPoints() > 0 &&
1642 project.LowerDistance() <= tolerance );
1643 nb_points_inside += isInsideRes[ i ];
1649 gp_Pnt aVPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ));
1650 for ( size_t i = 0; i < nb_points; i++)
1652 if ( isInsideRes[ i ]) continue;
1653 gp_Pnt aPnt( coords[3*i], coords[3*i+1], coords[3*i+2] );
1654 isInsideRes[ i ] = ( aPnt.SquareDistance( aVPnt ) <= tolerance * tolerance );
1655 nb_points_inside += isInsideRes[ i ];
1660 } // switch ( aShape.ShapeType() )
1668 //=============================================================================
1672 //=============================================================================
1674 GEOMImpl_IMeasureOperations::GetMinDistance (Handle(GEOM_Object) theShape1,
1675 Handle(GEOM_Object) theShape2,
1684 Standard_Real MinDist = 1.e9;
1686 if (theShape1.IsNull() || theShape2.IsNull()) return MinDist;
1688 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
1689 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
1690 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return MinDist;
1692 TopoDS_Shape aShape1 = aRefShape1->GetValue();
1693 TopoDS_Shape aShape2 = aRefShape2->GetValue();
1694 if (aShape1.IsNull() || aShape2.IsNull()) {
1695 SetErrorCode("One of Objects has NULL Shape");
1699 //Compute the parameters
1701 #if OCC_VERSION_LARGE > 0x06010000
1705 gp_Pnt aPnt1, aPnt2;
1707 MinDist = GEOMUtils::GetMinDistance(aShape1, aShape2, aPnt1, aPnt2);
1709 if (MinDist >= 0.0) {
1710 aPnt1.Coord(X1, Y1, Z1);
1711 aPnt2.Coord(X2, Y2, Z2);
1716 catch (Standard_Failure) {
1717 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1718 SetErrorCode(aFail->GetMessageString());
1726 //=======================================================================
1728 * Get coordinates of closest points of two shapes
1730 //=======================================================================
1731 Standard_Integer GEOMImpl_IMeasureOperations::ClosestPoints (Handle(GEOM_Object) theShape1,
1732 Handle(GEOM_Object) theShape2,
1733 Handle(TColStd_HSequenceOfReal)& theDoubles)
1736 Standard_Integer nbSolutions = 0;
1738 if (theShape1.IsNull() || theShape2.IsNull()) return nbSolutions;
1740 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
1741 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
1742 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return nbSolutions;
1744 TopoDS_Shape aShape1 = aRefShape1->GetValue();
1745 TopoDS_Shape aShape2 = aRefShape2->GetValue();
1746 if (aShape1.IsNull() || aShape2.IsNull()) {
1747 SetErrorCode("One of Objects has NULL Shape");
1751 // Compute the extremities
1753 #if OCC_VERSION_LARGE > 0x06010000
1758 // additional workaround for bugs 19899, 19908 and 19910 from Mantis
1760 double dist = GEOMUtils::GetMinDistanceSingular(aShape1, aShape2, P1, P2);
1764 theDoubles->Append(P1.X());
1765 theDoubles->Append(P1.Y());
1766 theDoubles->Append(P1.Z());
1767 theDoubles->Append(P2.X());
1768 theDoubles->Append(P2.Y());
1769 theDoubles->Append(P2.Z());
1775 BRepExtrema_DistShapeShape dst (aShape1, aShape2);
1777 nbSolutions = dst.NbSolution();
1778 if (theDoubles.IsNull()) theDoubles = new TColStd_HSequenceOfReal;
1781 for (int i = 1; i <= nbSolutions; i++) {
1782 P1 = dst.PointOnShape1(i);
1783 P2 = dst.PointOnShape2(i);
1785 theDoubles->Append(P1.X());
1786 theDoubles->Append(P1.Y());
1787 theDoubles->Append(P1.Z());
1788 theDoubles->Append(P2.X());
1789 theDoubles->Append(P2.Y());
1790 theDoubles->Append(P2.Z());
1794 catch (Standard_Failure) {
1795 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1796 SetErrorCode(aFail->GetMessageString());
1804 //=======================================================================
1806 * Get coordinates of point
1808 //=======================================================================
1809 void GEOMImpl_IMeasureOperations::PointCoordinates (Handle(GEOM_Object) theShape,
1810 Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ)
1814 if (theShape.IsNull())
1817 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1818 if (aRefShape.IsNull())
1821 TopoDS_Shape aShape = aRefShape->GetValue();
1822 if (aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX)
1824 SetErrorCode( "Shape must be a vertex" );
1829 #if OCC_VERSION_LARGE > 0x06010000
1832 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
1839 catch (Standard_Failure)
1841 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1842 SetErrorCode( aFail->GetMessageString() );
1846 //=======================================================================
1848 * Compute angle (in degrees) between two lines
1850 //=======================================================================
1851 Standard_Real GEOMImpl_IMeasureOperations::GetAngle (Handle(GEOM_Object) theLine1,
1852 Handle(GEOM_Object) theLine2)
1854 if (theLine1->GetType() == GEOM_VECTOR &&
1855 theLine2->GetType() == GEOM_VECTOR)
1856 return GetAngleBtwVectors(theLine1, theLine2);
1860 Standard_Real anAngle = -1.0;
1862 if (theLine1.IsNull() || theLine2.IsNull())
1865 Handle(GEOM_Function) aRefLine1 = theLine1->GetLastFunction();
1866 Handle(GEOM_Function) aRefLine2 = theLine2->GetLastFunction();
1867 if (aRefLine1.IsNull() || aRefLine2.IsNull())
1870 TopoDS_Shape aLine1 = aRefLine1->GetValue();
1871 TopoDS_Shape aLine2 = aRefLine2->GetValue();
1872 if (aLine1.IsNull() || aLine2.IsNull() ||
1873 aLine1.ShapeType() != TopAbs_EDGE ||
1874 aLine2.ShapeType() != TopAbs_EDGE)
1876 SetErrorCode("Two edges must be given");
1881 #if OCC_VERSION_LARGE > 0x06010000
1884 TopoDS_Edge E1 = TopoDS::Edge(aLine1);
1885 TopoDS_Edge E2 = TopoDS::Edge(aLine2);
1888 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp,lp);
1889 Handle(Geom_Curve) C2 = BRep_Tool::Curve(E2,fp,lp);
1891 if ( C1.IsNull() || C2.IsNull() ||
1892 !C1->IsKind(STANDARD_TYPE(Geom_Line)) ||
1893 !C2->IsKind(STANDARD_TYPE(Geom_Line)))
1895 SetErrorCode("The edges must be linear");
1899 Handle(Geom_Line) L1 = Handle(Geom_Line)::DownCast(C1);
1900 Handle(Geom_Line) L2 = Handle(Geom_Line)::DownCast(C2);
1902 gp_Lin aLin1 = L1->Lin();
1903 gp_Lin aLin2 = L2->Lin();
1905 anAngle = aLin1.Angle(aLin2);
1906 anAngle *= 180. / M_PI; // convert radians into degrees
1908 if (anAngle > 90.0) {
1909 anAngle = 180.0 - anAngle;
1914 catch (Standard_Failure)
1916 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1917 SetErrorCode(aFail->GetMessageString());
1923 //=======================================================================
1925 * Compute angle (in degrees) between two vectors
1927 //=======================================================================
1928 Standard_Real GEOMImpl_IMeasureOperations::GetAngleBtwVectors (Handle(GEOM_Object) theVec1,
1929 Handle(GEOM_Object) theVec2)
1933 Standard_Real anAngle = -1.0;
1935 if (theVec1.IsNull() || theVec2.IsNull())
1938 if (theVec1->GetType() != GEOM_VECTOR || theVec2->GetType() != GEOM_VECTOR) {
1939 SetErrorCode("Two vectors must be given");
1943 Handle(GEOM_Function) aRefVec1 = theVec1->GetLastFunction();
1944 Handle(GEOM_Function) aRefVec2 = theVec2->GetLastFunction();
1945 if (aRefVec1.IsNull() || aRefVec2.IsNull())
1948 TopoDS_Shape aVec1 = aRefVec1->GetValue();
1949 TopoDS_Shape aVec2 = aRefVec2->GetValue();
1950 if (aVec1.IsNull() || aVec2.IsNull() ||
1951 aVec1.ShapeType() != TopAbs_EDGE ||
1952 aVec2.ShapeType() != TopAbs_EDGE)
1954 SetErrorCode("Two edges must be given");
1959 #if OCC_VERSION_LARGE > 0x06010000
1962 TopoDS_Edge aE1 = TopoDS::Edge(aVec1);
1963 TopoDS_Edge aE2 = TopoDS::Edge(aVec2);
1965 TopoDS_Vertex aP11, aP12, aP21, aP22;
1966 TopExp::Vertices(aE1, aP11, aP12, Standard_True);
1967 TopExp::Vertices(aE2, aP21, aP22, Standard_True);
1968 if (aP11.IsNull() || aP12.IsNull() || aP21.IsNull() || aP22.IsNull()) {
1969 SetErrorCode("Bad edge given");
1973 gp_Vec aV1 (BRep_Tool::Pnt(aP11), BRep_Tool::Pnt(aP12));
1974 gp_Vec aV2 (BRep_Tool::Pnt(aP21), BRep_Tool::Pnt(aP22)) ;
1976 anAngle = aV1.Angle(aV2);
1977 anAngle *= 180. / M_PI; // convert radians into degrees
1981 catch (Standard_Failure)
1983 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1984 SetErrorCode(aFail->GetMessageString());
1991 //=============================================================================
1993 * CurveCurvatureByParam
1995 //=============================================================================
1996 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByParam
1997 (Handle(GEOM_Object) theCurve, Standard_Real& theParam)
2000 Standard_Real aRes = -1.0;
2002 if(theCurve.IsNull()) return aRes;
2004 Handle(GEOM_Function) aRefShape = theCurve->GetLastFunction();
2005 if(aRefShape.IsNull()) return aRes;
2007 TopoDS_Shape aShape = aRefShape->GetValue();
2008 if(aShape.IsNull()) {
2009 SetErrorCode("One of Objects has NULL Shape");
2013 Standard_Real aFP, aLP, aP;
2014 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aFP, aLP);
2015 aP = aFP + (aLP - aFP) * theParam;
2017 if(aCurve.IsNull()) return aRes;
2021 #if OCC_VERSION_LARGE > 0x06010000
2024 GeomLProp_CLProps Prop = GeomLProp_CLProps
2025 (aCurve, aP, 2, Precision::Confusion());
2026 aRes = fabs(Prop.Curvature());
2029 catch (Standard_Failure) {
2030 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2031 SetErrorCode(aFail->GetMessageString());
2035 if( aRes > Precision::Confusion() )
2044 //=============================================================================
2046 * CurveCurvatureByPoint
2048 //=============================================================================
2049 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByPoint
2050 (Handle(GEOM_Object) theCurve, Handle(GEOM_Object) thePoint)
2053 Standard_Real aRes = -1.0;
2055 if( theCurve.IsNull() || thePoint.IsNull() ) return aRes;
2057 Handle(GEOM_Function) aRefCurve = theCurve->GetLastFunction();
2058 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2059 if( aRefCurve.IsNull() || aRefPoint.IsNull() ) return aRes;
2061 TopoDS_Edge anEdge = TopoDS::Edge(aRefCurve->GetValue());
2062 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2063 if( anEdge.IsNull() || aPnt.IsNull() ) {
2064 SetErrorCode("One of Objects has NULL Shape");
2068 Standard_Real aFP, aLP;
2069 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFP, aLP);
2070 if(aCurve.IsNull()) return aRes;
2071 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2075 #if OCC_VERSION_LARGE > 0x06010000
2078 GeomAPI_ProjectPointOnCurve PPCurve(aPoint, aCurve, aFP, aLP);
2079 if(PPCurve.NbPoints()>0) {
2080 GeomLProp_CLProps Prop = GeomLProp_CLProps
2081 (aCurve, PPCurve.LowerDistanceParameter(), 2, Precision::Confusion());
2082 aRes = fabs(Prop.Curvature());
2086 catch (Standard_Failure) {
2087 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2088 SetErrorCode(aFail->GetMessageString());
2092 if( aRes > Precision::Confusion() )
2101 //=============================================================================
2103 * getSurfaceCurvatures
2105 //=============================================================================
2106 Standard_Real GEOMImpl_IMeasureOperations::getSurfaceCurvatures
2107 (const Handle(Geom_Surface)& aSurf,
2108 Standard_Real theUParam,
2109 Standard_Real theVParam,
2110 Standard_Boolean theNeedMaxCurv)
2113 Standard_Real aRes = 1.0;
2115 if (aSurf.IsNull()) return aRes;
2118 #if OCC_VERSION_LARGE > 0x06010000
2121 GeomLProp_SLProps Prop = GeomLProp_SLProps
2122 (aSurf, theUParam, theVParam, 2, Precision::Confusion());
2123 if(Prop.IsCurvatureDefined()) {
2124 if(Prop.IsUmbilic()) {
2125 //cout<<"is umbilic"<<endl;
2126 aRes = fabs(Prop.MeanCurvature());
2129 //cout<<"is not umbilic"<<endl;
2130 double c1 = fabs(Prop.MaxCurvature());
2131 double c2 = fabs(Prop.MinCurvature());
2140 catch (Standard_Failure) {
2141 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2142 SetErrorCode(aFail->GetMessageString());
2146 if( fabs(aRes) > Precision::Confusion() )
2155 //=============================================================================
2157 * MaxSurfaceCurvatureByParam
2159 //=============================================================================
2160 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByParam
2161 (Handle(GEOM_Object) theSurf,
2162 Standard_Real& theUParam,
2163 Standard_Real& theVParam)
2166 Standard_Real aRes = -1.0;
2168 if (theSurf.IsNull()) return aRes;
2170 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2171 if(aRefShape.IsNull()) return aRes;
2173 TopoDS_Shape aShape = aRefShape->GetValue();
2174 if(aShape.IsNull()) {
2175 SetErrorCode("One of Objects has NULL Shape");
2179 TopoDS_Face F = TopoDS::Face(aShape);
2180 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2182 //Compute the parameters
2183 Standard_Real U1,U2,V1,V2;
2184 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2185 Standard_Real U = U1 + (U2-U1)*theUParam;
2186 Standard_Real V = V1 + (V2-V1)*theVParam;
2188 return getSurfaceCurvatures(aSurf, U, V, true);
2192 //=============================================================================
2194 * MaxSurfaceCurvatureByPoint
2196 //=============================================================================
2197 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByPoint
2198 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2201 Standard_Real aRes = -1.0;
2203 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2205 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2206 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2207 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2209 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2210 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2211 if( aFace.IsNull() || aPnt.IsNull() ) {
2212 SetErrorCode("One of Objects has NULL Shape");
2216 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2217 if(aSurf.IsNull()) return aRes;
2218 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2220 //Compute the parameters
2221 ShapeAnalysis_Surface sas(aSurf);
2222 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2224 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), true);
2228 //=============================================================================
2230 * MinSurfaceCurvatureByParam
2232 //=============================================================================
2233 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByParam
2234 (Handle(GEOM_Object) theSurf,
2235 Standard_Real& theUParam,
2236 Standard_Real& theVParam)
2239 Standard_Real aRes = -1.0;
2241 if (theSurf.IsNull()) return aRes;
2243 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2244 if(aRefShape.IsNull()) return aRes;
2246 TopoDS_Shape aShape = aRefShape->GetValue();
2247 if(aShape.IsNull()) {
2248 SetErrorCode("One of Objects has NULL Shape");
2252 TopoDS_Face F = TopoDS::Face(aShape);
2253 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2255 //Compute the parameters
2256 Standard_Real U1,U2,V1,V2;
2257 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2258 Standard_Real U = U1 + (U2-U1)*theUParam;
2259 Standard_Real V = V1 + (V2-V1)*theVParam;
2261 return getSurfaceCurvatures(aSurf, U, V, false);
2265 //=============================================================================
2267 * MinSurfaceCurvatureByPoint
2269 //=============================================================================
2270 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByPoint
2271 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2274 Standard_Real aRes = -1.0;
2276 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2278 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2279 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2280 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2282 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2283 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2284 if( aFace.IsNull() || aPnt.IsNull() ) {
2285 SetErrorCode("One of Objects has NULL Shape");
2289 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2290 if(aSurf.IsNull()) return aRes;
2291 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2293 //Compute the parameters
2294 ShapeAnalysis_Surface sas(aSurf);
2295 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2297 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), false);
2301 //=======================================================================
2302 //function : StructuralDump
2303 //purpose : Structural (data exchange) style of output.
2304 //=======================================================================
2305 void GEOMImpl_IMeasureOperations::StructuralDump (const BRepCheck_Analyzer& theAna,
2306 const TopoDS_Shape& theShape,
2307 TCollection_AsciiString& theDump)
2311 theDump += " -- The Shape has problems :\n";
2312 theDump += " Check Count\n";
2313 theDump += " ------------------------------------------------\n";
2315 Standard_Integer last_stat = (Standard_Integer)BRepCheck_CheckFail;
2316 Handle(TColStd_HArray1OfInteger) NbProblems =
2317 new TColStd_HArray1OfInteger(1, last_stat);
2318 for (i = 1; i <= last_stat; i++)
2319 NbProblems->SetValue(i,0);
2321 Handle(TopTools_HSequenceOfShape) sl;
2322 sl = new TopTools_HSequenceOfShape();
2323 TopTools_DataMapOfShapeListOfShape theMap;
2325 GetProblemShapes(theAna, theShape, sl, NbProblems, theMap);
2328 Standard_Integer count = 0;
2329 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnCurve);
2331 theDump += " Invalid Point on Curve ................... ";
2332 theDump += TCollection_AsciiString(count) + "\n";
2334 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnCurveOnSurface);
2336 theDump += " Invalid Point on CurveOnSurface .......... ";
2337 theDump += TCollection_AsciiString(count) + "\n";
2339 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnSurface);
2341 theDump += " Invalid Point on Surface ................. ";
2342 theDump += TCollection_AsciiString(count) + "\n";
2344 count = NbProblems->Value((Standard_Integer)BRepCheck_No3DCurve);
2346 theDump += " No 3D Curve .............................. ";
2347 theDump += TCollection_AsciiString(count) + "\n";
2349 count = NbProblems->Value((Standard_Integer)BRepCheck_Multiple3DCurve);
2351 theDump += " Multiple 3D Curve ........................ ";
2352 theDump += TCollection_AsciiString(count) + "\n";
2354 count = NbProblems->Value((Standard_Integer)BRepCheck_Invalid3DCurve);
2356 theDump += " Invalid 3D Curve ......................... ";
2357 theDump += TCollection_AsciiString(count) + "\n";
2359 count = NbProblems->Value((Standard_Integer)BRepCheck_NoCurveOnSurface);
2361 theDump += " No Curve on Surface ...................... ";
2362 theDump += TCollection_AsciiString(count) + "\n";
2364 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidCurveOnSurface);
2366 theDump += " Invalid Curve on Surface ................. ";
2367 theDump += TCollection_AsciiString(count) + "\n";
2369 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidCurveOnClosedSurface);
2371 theDump += " Invalid Curve on closed Surface .......... ";
2372 theDump += TCollection_AsciiString(count) + "\n";
2374 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidSameRangeFlag);
2376 theDump += " Invalid SameRange Flag ................... ";
2377 theDump += TCollection_AsciiString(count) + "\n";
2379 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidSameParameterFlag);
2381 theDump += " Invalid SameParameter Flag ............... ";
2382 theDump += TCollection_AsciiString(count) + "\n";
2384 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidDegeneratedFlag);
2386 theDump += " Invalid Degenerated Flag ................. ";
2387 theDump += TCollection_AsciiString(count) + "\n";
2389 count = NbProblems->Value((Standard_Integer)BRepCheck_FreeEdge);
2391 theDump += " Free Edge ................................ ";
2392 theDump += TCollection_AsciiString(count) + "\n";
2394 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidMultiConnexity);
2396 theDump += " Invalid MultiConnexity ................... ";
2397 theDump += TCollection_AsciiString(count) + "\n";
2399 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidRange);
2401 theDump += " Invalid Range ............................ ";
2402 theDump += TCollection_AsciiString(count) + "\n";
2404 count = NbProblems->Value((Standard_Integer)BRepCheck_EmptyWire);
2406 theDump += " Empty Wire ............................... ";
2407 theDump += TCollection_AsciiString(count) + "\n";
2409 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantEdge);
2411 theDump += " Redundant Edge ........................... ";
2412 theDump += TCollection_AsciiString(count) + "\n";
2414 count = NbProblems->Value((Standard_Integer)BRepCheck_SelfIntersectingWire);
2416 theDump += " Self Intersecting Wire ................... ";
2417 theDump += TCollection_AsciiString(count) + "\n";
2419 count = NbProblems->Value((Standard_Integer)BRepCheck_NoSurface);
2421 theDump += " No Surface ............................... ";
2422 theDump += TCollection_AsciiString(count) + "\n";
2424 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidWire);
2426 theDump += " Invalid Wire ............................. ";
2427 theDump += TCollection_AsciiString(count) + "\n";
2429 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantWire);
2431 theDump += " Redundant Wire ........................... ";
2432 theDump += TCollection_AsciiString(count) + "\n";
2434 count = NbProblems->Value((Standard_Integer)BRepCheck_IntersectingWires);
2436 theDump += " Intersecting Wires ....................... ";
2437 theDump += TCollection_AsciiString(count) + "\n";
2439 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidImbricationOfWires);
2441 theDump += " Invalid Imbrication of Wires ............. ";
2442 theDump += TCollection_AsciiString(count) + "\n";
2444 count = NbProblems->Value((Standard_Integer)BRepCheck_EmptyShell);
2446 theDump += " Empty Shell .............................. ";
2447 theDump += TCollection_AsciiString(count) + "\n";
2449 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantFace);
2451 theDump += " Redundant Face ........................... ";
2452 theDump += TCollection_AsciiString(count) + "\n";
2454 count = NbProblems->Value((Standard_Integer)BRepCheck_UnorientableShape);
2456 theDump += " Unorientable Shape ....................... ";
2457 theDump += TCollection_AsciiString(count) + "\n";
2459 count = NbProblems->Value((Standard_Integer)BRepCheck_NotClosed);
2461 theDump += " Not Closed ............................... ";
2462 theDump += TCollection_AsciiString(count) + "\n";
2464 count = NbProblems->Value((Standard_Integer)BRepCheck_NotConnected);
2466 theDump += " Not Connected ............................ ";
2467 theDump += TCollection_AsciiString(count) + "\n";
2469 count = NbProblems->Value((Standard_Integer)BRepCheck_SubshapeNotInShape);
2471 theDump += " Sub-shape not in Shape .................... ";
2472 theDump += TCollection_AsciiString(count) + "\n";
2474 count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientation);
2476 theDump += " Bad Orientation .......................... ";
2477 theDump += TCollection_AsciiString(count) + "\n";
2479 count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientationOfSubshape);
2481 theDump += " Bad Orientation of Sub-shape .............. ";
2482 theDump += TCollection_AsciiString(count) + "\n";
2484 count = NbProblems->Value((Standard_Integer)BRepCheck_CheckFail);
2486 theDump += " checkshape failure ....................... ";
2487 theDump += TCollection_AsciiString(count) + "\n";
2490 theDump += " ------------------------------------------------\n";
2491 theDump += "*** Shapes with problems : ";
2492 theDump += TCollection_AsciiString(sl->Length()) + "\n";
2494 Standard_Integer nbv, nbe, nbw, nbf, nbs, nbo;
2495 nbv = nbe = nbw = nbf = nbs = nbo = 0;
2497 for (i = 1; i <= sl->Length(); i++) {
2498 TopoDS_Shape shi = sl->Value(i);
2499 TopAbs_ShapeEnum sti = shi.ShapeType();
2501 case TopAbs_VERTEX : nbv++; break;
2502 case TopAbs_EDGE : nbe++; break;
2503 case TopAbs_WIRE : nbw++; break;
2504 case TopAbs_FACE : nbf++; break;
2505 case TopAbs_SHELL : nbs++; break;
2506 case TopAbs_SOLID : nbo++; break;
2512 theDump += "VERTEX : ";
2513 if (nbv < 10) theDump += " ";
2514 theDump += TCollection_AsciiString(nbv) + "\n";
2517 theDump += "EDGE : ";
2518 if (nbe < 10) theDump += " ";
2519 theDump += TCollection_AsciiString(nbe) + "\n";
2522 theDump += "WIRE : ";
2523 if (nbw < 10) theDump += " ";
2524 theDump += TCollection_AsciiString(nbw) + "\n";
2527 theDump += "FACE : ";
2528 if (nbf < 10) theDump += " ";
2529 theDump += TCollection_AsciiString(nbf) + "\n";
2532 theDump += "SHELL : ";
2533 if (nbs < 10) theDump += " ";
2534 theDump += TCollection_AsciiString(nbs) + "\n";
2537 theDump += "SOLID : ";
2538 if (nbo < 10) theDump += " ";
2539 theDump += TCollection_AsciiString(nbo) + "\n";
2544 //=======================================================================
2545 //function : GetProblemShapes
2546 // purpose : for StructuralDump
2547 //=======================================================================
2548 void GEOMImpl_IMeasureOperations::GetProblemShapes (const BRepCheck_Analyzer& theAna,
2549 const TopoDS_Shape& theShape,
2550 Handle(TopTools_HSequenceOfShape)& sl,
2551 Handle(TColStd_HArray1OfInteger)& NbProblems,
2552 TopTools_DataMapOfShapeListOfShape& theMap)
2554 for (TopoDS_Iterator iter(theShape); iter.More(); iter.Next()) {
2555 GetProblemShapes(theAna, iter.Value(), sl, NbProblems, theMap);
2557 TopAbs_ShapeEnum styp = theShape.ShapeType();
2558 BRepCheck_ListIteratorOfListOfStatus itl;
2559 TopTools_ListOfShape empty;
2560 if (!theMap.IsBound(theShape)) {
2561 theMap.Bind(theShape,empty);
2563 if (!theAna.Result(theShape).IsNull()) {
2564 itl.Initialize(theAna.Result(theShape)->Status());
2565 // !!! May be, we have to print all the problems, not only the first one ?
2566 if (itl.Value() != BRepCheck_NoError) {
2567 sl->Append(theShape);
2568 BRepCheck_Status stat = itl.Value();
2569 NbProblems->SetValue((Standard_Integer)stat,
2570 NbProblems->Value((Standard_Integer)stat) + 1);
2577 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_VERTEX, theMap);
2580 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_WIRE, theMap);
2581 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_EDGE, theMap);
2582 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_VERTEX, theMap);
2587 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_SHELL, theMap);
2594 //=======================================================================
2595 //function : Contains
2596 //=======================================================================
2597 static Standard_Boolean Contains (const TopTools_ListOfShape& L,
2598 const TopoDS_Shape& S)
2600 TopTools_ListIteratorOfListOfShape it;
2601 for (it.Initialize(L); it.More(); it.Next()) {
2602 if (it.Value().IsSame(S)) {
2603 return Standard_True;
2606 return Standard_False;
2609 //=======================================================================
2610 //function : GetProblemSub
2611 // purpose : for StructuralDump
2612 //=======================================================================
2613 void GEOMImpl_IMeasureOperations::GetProblemSub (const BRepCheck_Analyzer& theAna,
2614 const TopoDS_Shape& theShape,
2615 Handle(TopTools_HSequenceOfShape)& sl,
2616 Handle(TColStd_HArray1OfInteger)& NbProblems,
2617 const TopAbs_ShapeEnum Subtype,
2618 TopTools_DataMapOfShapeListOfShape& theMap)
2620 BRepCheck_ListIteratorOfListOfStatus itl;
2621 TopExp_Explorer exp;
2622 for (exp.Init(theShape, Subtype); exp.More(); exp.Next()) {
2623 const TopoDS_Shape& sub = exp.Current();
2625 const Handle(BRepCheck_Result)& res = theAna.Result(sub);
2626 for (res->InitContextIterator();
2627 res->MoreShapeInContext();
2628 res->NextShapeInContext()) {
2629 if (res->ContextualShape().IsSame(theShape) && !Contains(theMap(sub), theShape)) {
2630 theMap(sub).Append(theShape);
2631 itl.Initialize(res->StatusOnShape());
2633 if (itl.Value() != BRepCheck_NoError) {
2634 Standard_Integer ii = 0;
2636 for (ii = 1; ii <= sl->Length(); ii++)
2637 if (sl->Value(ii).IsSame(sub)) break;
2639 if (ii > sl->Length()) {
2641 BRepCheck_Status stat = itl.Value();
2642 NbProblems->SetValue((Standard_Integer)stat,
2643 NbProblems->Value((Standard_Integer)stat) + 1);
2645 for (ii = 1; ii <= sl->Length(); ii++)
2646 if (sl->Value(ii).IsSame(theShape)) break;
2647 if (ii > sl->Length()) {
2648 sl->Append(theShape);
2649 BRepCheck_Status stat = itl.Value();
2650 NbProblems->SetValue((Standard_Integer)stat,
2651 NbProblems->Value((Standard_Integer)stat) + 1);