1 // Copyright (C) 2007-2012 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 <GEOMAlgo_ShapeInfo.hxx>
33 #include <GEOMAlgo_ShapeInfoFiller.hxx>
35 #include <GEOM_Function.hxx>
36 #include <GEOM_PythonDump.hxx>
38 #include <NMTTools_CheckerSI.hxx>
40 #include <NMTDS_Tools.hxx>
41 #include <NMTDS_InterfPool.hxx>
42 #include <NMTDS_PInterfPool.hxx>
43 //#include <NMTDS_PassKeyBoolean.hxx>
44 #include <NMTDS_PairBoolean.hxx>
45 #include <NMTDS_ShapesDataStructure.hxx>
46 //#include <NMTDS_ListIteratorOfListOfPassKeyBoolean.hxx>
47 #include <NMTDS_ListIteratorOfListOfPairBoolean.hxx>
49 #include <Basics_OCCTVersion.hxx>
51 #include <utilities.h>
53 #include <Utils_ExceptHandlers.hxx>
56 #include <TFunction_DriverTable.hxx>
57 #include <TFunction_Driver.hxx>
58 #include <TFunction_Logbook.hxx>
59 #include <TDF_Tool.hxx>
61 #include <BRep_Tool.hxx>
62 #include <BRepAdaptor_Surface.hxx>
63 #include <BRepBndLib.hxx>
64 #include <BRepCheck.hxx>
65 #include <BRepCheck_ListIteratorOfListOfStatus.hxx>
66 #include <BRepCheck_Result.hxx>
67 #include <BRepCheck_Shell.hxx>
68 #include <BRepExtrema_DistShapeShape.hxx>
69 #include <BRepGProp.hxx>
70 #include <BRepTools.hxx>
72 #include <Bnd_Box.hxx>
74 #include <GProp_GProps.hxx>
75 #include <GProp_PrincipalProps.hxx>
80 #include <TopoDS_Edge.hxx>
81 #include <TopoDS_Face.hxx>
82 #include <TopoDS_Shape.hxx>
83 #include <TopoDS_Vertex.hxx>
84 #include <TopoDS_Iterator.hxx>
85 #include <TopExp_Explorer.hxx>
86 #include <TopTools_MapOfShape.hxx>
87 #include <TopTools_ListOfShape.hxx>
88 #include <TopTools_ListIteratorOfListOfShape.hxx>
90 #include <GeomAbs_SurfaceType.hxx>
91 #include <Geom_Surface.hxx>
92 #include <Geom_Plane.hxx>
93 #include <Geom_SphericalSurface.hxx>
94 #include <Geom_CylindricalSurface.hxx>
95 #include <Geom_ToroidalSurface.hxx>
96 #include <Geom_ConicalSurface.hxx>
97 #include <Geom_SurfaceOfLinearExtrusion.hxx>
98 #include <Geom_SurfaceOfRevolution.hxx>
99 #include <Geom_BezierSurface.hxx>
100 #include <Geom_BSplineSurface.hxx>
101 #include <Geom_RectangularTrimmedSurface.hxx>
102 #include <Geom_OffsetSurface.hxx>
103 #include <Geom_Line.hxx>
105 #include <gp_Pln.hxx>
106 #include <gp_Lin.hxx>
108 #include <GeomAPI_ProjectPointOnCurve.hxx>
109 #include <GeomLProp_CLProps.hxx>
110 #include <GeomLProp_SLProps.hxx>
111 #include <ShapeAnalysis.hxx>
112 #include <ShapeAnalysis_Surface.hxx>
114 #include <Standard_Failure.hxx>
115 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
117 #include <BRepClass3d_SolidClassifier.hxx>
118 #include <BRep_Builder.hxx>
119 #include <GeomAPI_IntSS.hxx>
120 #include <Geom_Circle.hxx>
121 #include <Geom_SphericalSurface.hxx>
122 #include <Geom_ToroidalSurface.hxx>
123 #include <ShapeFix_Shape.hxx>
124 #include <TopoDS_Compound.hxx>
127 //=============================================================================
131 //=============================================================================
132 GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations (GEOM_Engine* theEngine, int theDocID)
133 : GEOM_IOperations(theEngine, theDocID)
135 MESSAGE("GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations");
138 //=============================================================================
142 //=============================================================================
143 GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations()
145 MESSAGE("GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations");
148 //=============================================================================
149 /*! Get kind and parameters of the given shape.
151 //=============================================================================
152 GEOMImpl_IMeasureOperations::ShapeKind GEOMImpl_IMeasureOperations::KindOfShape
153 (Handle(GEOM_Object) theShape,
154 Handle(TColStd_HSequenceOfInteger)& theIntegers,
155 Handle(TColStd_HSequenceOfReal)& theDoubles)
158 ShapeKind aKind = SK_NO_SHAPE;
160 if (theIntegers.IsNull()) theIntegers = new TColStd_HSequenceOfInteger;
161 else theIntegers->Clear();
163 if (theDoubles.IsNull()) theDoubles = new TColStd_HSequenceOfReal;
164 else theDoubles->Clear();
166 if (theShape.IsNull())
169 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
170 if (aRefShape.IsNull()) return aKind;
172 TopoDS_Shape aShape = aRefShape->GetValue();
173 if (aShape.IsNull()) return aKind;
175 int geom_type = theShape->GetType();
177 // check if it's advanced shape
178 if ( geom_type > ADVANCED_BASE ) {
184 GEOMAlgo_ShapeInfoFiller aSF;
185 aSF.SetShape(aShape);
187 Standard_Integer iErr = aSF.ErrorStatus();
189 SetErrorCode("Error in GEOMAlgo_ShapeInfoFiller");
192 const GEOMAlgo_ShapeInfo& anInfo = aSF.Info();
194 // Interprete results
195 TopAbs_ShapeEnum aType = anInfo.Type();
198 case TopAbs_COMPOUND:
199 case TopAbs_COMPSOLID:
201 // (+) geompy.kind.COMPOUND nb_solids nb_faces nb_edges nb_vertices
202 // (+) geompy.kind.COMPSOLID nb_solids nb_faces nb_edges nb_vertices
203 // ??? "nb_faces" - all faces or only 'standalone' faces?
204 if (aType == TopAbs_COMPOUND)
207 aKind = SK_COMPSOLID;
209 //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPOUND));
210 //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPSOLID));
211 theIntegers->Append(anInfo.NbSubShapes(TopAbs_SOLID));
212 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
213 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
214 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
220 // (+) geompy.kind.SHELL geompy.info.closed nb_faces nb_edges nb_vertices
221 // (+) geompy.kind.SHELL geompy.info.unclosed nb_faces nb_edges nb_vertices
224 theIntegers->Append((int)anInfo.KindOfClosed());
226 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
227 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
228 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
234 // (+) geompy.kind.WIRE geompy.info.closed nb_edges nb_vertices
235 // (+) geompy.kind.WIRE geompy.info.unclosed nb_edges nb_vertices
238 theIntegers->Append((int)anInfo.KindOfClosed());
240 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
241 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
249 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
252 case GEOMAlgo_KN_SPHERE:
253 // (+) geompy.kind.SPHERE xc yc zc R
257 gp_Pnt aC = anInfo.Location();
258 theDoubles->Append(aC.X());
259 theDoubles->Append(aC.Y());
260 theDoubles->Append(aC.Z());
262 theDoubles->Append(anInfo.Radius1());
265 case GEOMAlgo_KN_CYLINDER:
266 // (+) geompy.kind.CYLINDER xb yb zb dx dy dz R H
270 gp_Pnt aC = anInfo.Location();
271 theDoubles->Append(aC.X());
272 theDoubles->Append(aC.Y());
273 theDoubles->Append(aC.Z());
275 gp_Ax3 anAx3 = anInfo.Position();
276 gp_Dir aD = anAx3.Direction();
277 theDoubles->Append(aD.X());
278 theDoubles->Append(aD.Y());
279 theDoubles->Append(aD.Z());
281 theDoubles->Append(anInfo.Radius1());
282 theDoubles->Append(anInfo.Height());
285 case GEOMAlgo_KN_BOX:
286 // (+) geompy.kind.BOX xc yc zc ax ay az
290 gp_Pnt aC = anInfo.Location();
291 theDoubles->Append(aC.X());
292 theDoubles->Append(aC.Y());
293 theDoubles->Append(aC.Z());
295 gp_Ax3 anAx3 = anInfo.Position();
296 gp_Dir aD = anAx3.Direction();
297 gp_Dir aX = anAx3.XDirection();
300 if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
301 aX.IsParallel(gp::DX(), Precision::Angular())) {
302 theDoubles->Append(anInfo.Length()); // ax'
303 theDoubles->Append(anInfo.Width()); // ay'
304 theDoubles->Append(anInfo.Height()); // az'
306 else if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
307 aX.IsParallel(gp::DY(), Precision::Angular())) {
308 theDoubles->Append(anInfo.Width()); // ay'
309 theDoubles->Append(anInfo.Length()); // ax'
310 theDoubles->Append(anInfo.Height()); // az'
312 else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
313 aX.IsParallel(gp::DZ(), Precision::Angular())) {
314 theDoubles->Append(anInfo.Height()); // az'
315 theDoubles->Append(anInfo.Width()); // ay'
316 theDoubles->Append(anInfo.Length()); // ax'
318 else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
319 aX.IsParallel(gp::DY(), Precision::Angular())) {
320 theDoubles->Append(anInfo.Height()); // az'
321 theDoubles->Append(anInfo.Length()); // ax'
322 theDoubles->Append(anInfo.Width()); // ay'
324 else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
325 aX.IsParallel(gp::DZ(), Precision::Angular())) {
326 theDoubles->Append(anInfo.Width()); // ay'
327 theDoubles->Append(anInfo.Height()); // az'
328 theDoubles->Append(anInfo.Length()); // ax'
330 else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
331 aX.IsParallel(gp::DX(), Precision::Angular())) {
332 theDoubles->Append(anInfo.Length()); // ax'
333 theDoubles->Append(anInfo.Height()); // az'
334 theDoubles->Append(anInfo.Width()); // ay'
337 // (+) geompy.kind.ROTATED_BOX xo yo zo zx zy zz xx xy xz ax ay az
338 aKind = SK_ROTATED_BOX;
340 // Direction and XDirection
341 theDoubles->Append(aD.X());
342 theDoubles->Append(aD.Y());
343 theDoubles->Append(aD.Z());
345 theDoubles->Append(aX.X());
346 theDoubles->Append(aX.Y());
347 theDoubles->Append(aX.Z());
350 theDoubles->Append(anInfo.Length());
351 theDoubles->Append(anInfo.Width());
352 theDoubles->Append(anInfo.Height());
356 case GEOMAlgo_KN_TORUS:
357 // (+) geompy.kind.TORUS xc yc zc dx dy dz R_1 R_2
361 gp_Pnt aO = anInfo.Location();
362 theDoubles->Append(aO.X());
363 theDoubles->Append(aO.Y());
364 theDoubles->Append(aO.Z());
366 gp_Ax3 anAx3 = anInfo.Position();
367 gp_Dir aD = anAx3.Direction();
368 theDoubles->Append(aD.X());
369 theDoubles->Append(aD.Y());
370 theDoubles->Append(aD.Z());
372 theDoubles->Append(anInfo.Radius1());
373 theDoubles->Append(anInfo.Radius2());
376 case GEOMAlgo_KN_CONE:
377 // (+) geompy.kind.CONE xb yb zb dx dy dz R_1 R_2 H
381 gp_Pnt aO = anInfo.Location();
382 theDoubles->Append(aO.X());
383 theDoubles->Append(aO.Y());
384 theDoubles->Append(aO.Z());
386 gp_Ax3 anAx3 = anInfo.Position();
387 gp_Dir aD = anAx3.Direction();
388 theDoubles->Append(aD.X());
389 theDoubles->Append(aD.Y());
390 theDoubles->Append(aD.Z());
392 theDoubles->Append(anInfo.Radius1());
393 theDoubles->Append(anInfo.Radius2());
394 theDoubles->Append(anInfo.Height());
397 case GEOMAlgo_KN_POLYHEDRON:
398 // (+) geompy.kind.POLYHEDRON nb_faces nb_edges nb_vertices
400 aKind = SK_POLYHEDRON;
402 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
403 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
404 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
408 // (+) geompy.kind.SOLID nb_faces nb_edges nb_vertices
410 theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
411 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
412 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
422 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
424 case GEOMAlgo_KN_SPHERE:
425 // (+) geompy.kind.SPHERE2D xc yc zc R
429 gp_Pnt aC = anInfo.Location();
430 theDoubles->Append(aC.X());
431 theDoubles->Append(aC.Y());
432 theDoubles->Append(aC.Z());
434 theDoubles->Append(anInfo.Radius1());
437 case GEOMAlgo_KN_CYLINDER:
438 // (+) geompy.kind.CYLINDER2D xb yb zb dx dy dz R H
440 aKind = SK_CYLINDER2D;
442 gp_Pnt aO = anInfo.Location();
443 theDoubles->Append(aO.X());
444 theDoubles->Append(aO.Y());
445 theDoubles->Append(aO.Z());
447 gp_Ax3 anAx3 = anInfo.Position();
448 gp_Dir aD = anAx3.Direction();
449 theDoubles->Append(aD.X());
450 theDoubles->Append(aD.Y());
451 theDoubles->Append(aD.Z());
453 theDoubles->Append(anInfo.Radius1());
454 theDoubles->Append(anInfo.Height());
457 case GEOMAlgo_KN_TORUS:
458 // (+) geompy.kind.TORUS2D xc yc zc dx dy dz R_1 R_2
462 gp_Pnt aO = anInfo.Location();
463 theDoubles->Append(aO.X());
464 theDoubles->Append(aO.Y());
465 theDoubles->Append(aO.Z());
467 gp_Ax3 anAx3 = anInfo.Position();
468 gp_Dir aD = anAx3.Direction();
469 theDoubles->Append(aD.X());
470 theDoubles->Append(aD.Y());
471 theDoubles->Append(aD.Z());
473 theDoubles->Append(anInfo.Radius1());
474 theDoubles->Append(anInfo.Radius2());
477 case GEOMAlgo_KN_CONE:
478 // (+) geompy.kind.CONE2D xc yc zc dx dy dz R_1 R_2 H
482 gp_Pnt aO = anInfo.Location();
483 theDoubles->Append(aO.X());
484 theDoubles->Append(aO.Y());
485 theDoubles->Append(aO.Z());
487 gp_Ax3 anAx3 = anInfo.Position();
488 gp_Dir aD = anAx3.Direction();
489 theDoubles->Append(aD.X());
490 theDoubles->Append(aD.Y());
491 theDoubles->Append(aD.Z());
493 theDoubles->Append(anInfo.Radius1());
494 theDoubles->Append(anInfo.Radius2());
495 theDoubles->Append(anInfo.Height());
498 case GEOMAlgo_KN_DISKCIRCLE:
499 // (+) geompy.kind.DISK_CIRCLE xc yc zc dx dy dz R
501 aKind = SK_DISK_CIRCLE;
503 gp_Pnt aC = anInfo.Location();
504 theDoubles->Append(aC.X());
505 theDoubles->Append(aC.Y());
506 theDoubles->Append(aC.Z());
508 gp_Ax3 anAx3 = anInfo.Position();
509 gp_Dir aD = anAx3.Direction();
510 theDoubles->Append(aD.X());
511 theDoubles->Append(aD.Y());
512 theDoubles->Append(aD.Z());
514 theDoubles->Append(anInfo.Radius1());
517 case GEOMAlgo_KN_DISKELLIPSE:
518 // (+) geompy.kind.DISK_ELLIPSE xc yc zc dx dy dz R_1 R_2
520 aKind = SK_DISK_ELLIPSE;
522 gp_Pnt aC = anInfo.Location();
523 theDoubles->Append(aC.X());
524 theDoubles->Append(aC.Y());
525 theDoubles->Append(aC.Z());
527 gp_Ax3 anAx3 = anInfo.Position();
528 gp_Dir aD = anAx3.Direction();
529 theDoubles->Append(aD.X());
530 theDoubles->Append(aD.Y());
531 theDoubles->Append(aD.Z());
533 theDoubles->Append(anInfo.Radius1());
534 theDoubles->Append(anInfo.Radius2());
537 case GEOMAlgo_KN_RECTANGLE:
538 case GEOMAlgo_KN_TRIANGLE:
539 case GEOMAlgo_KN_QUADRANGLE:
540 case GEOMAlgo_KN_POLYGON:
541 // (+) geompy.kind.POLYGON xo yo zo dx dy dz nb_edges nb_vertices
545 gp_Pnt aO = anInfo.Location();
546 theDoubles->Append(aO.X());
547 theDoubles->Append(aO.Y());
548 theDoubles->Append(aO.Z());
550 gp_Ax3 anAx3 = anInfo.Position();
551 gp_Dir aD = anAx3.Direction();
552 theDoubles->Append(aD.X());
553 theDoubles->Append(aD.Y());
554 theDoubles->Append(aD.Z());
556 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
557 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
560 case GEOMAlgo_KN_PLANE: // infinite
561 // (+) geompy.kind.PLANE xo yo zo dx dy dz
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());
578 if (anInfo.KindOfShape() == GEOMAlgo_KS_PLANE) {
579 // (+) geompy.kind.PLANAR xo yo zo dx dy dz nb_edges nb_vertices
583 gp_Pnt aC = anInfo.Location();
584 theDoubles->Append(aC.X());
585 theDoubles->Append(aC.Y());
586 theDoubles->Append(aC.Z());
588 gp_Ax3 anAx3 = anInfo.Position();
589 gp_Dir aD = anAx3.Direction();
590 theDoubles->Append(aD.X());
591 theDoubles->Append(aD.Y());
592 theDoubles->Append(aD.Z());
594 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
595 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
598 // ??? geompy.kind.FACE nb_edges nb_vertices _surface_type_id_
599 // (+) geompy.kind.FACE nb_edges nb_vertices
601 theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
602 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
612 GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
614 case GEOMAlgo_KN_CIRCLE:
616 // (+) geompy.kind.CIRCLE xc yc zc dx dy dz R
619 gp_Pnt aC = anInfo.Location();
620 theDoubles->Append(aC.X());
621 theDoubles->Append(aC.Y());
622 theDoubles->Append(aC.Z());
624 gp_Ax3 anAx3 = anInfo.Position();
625 gp_Dir aD = anAx3.Direction();
626 theDoubles->Append(aD.X());
627 theDoubles->Append(aD.Y());
628 theDoubles->Append(aD.Z());
630 theDoubles->Append(anInfo.Radius1());
633 case GEOMAlgo_KN_ARCCIRCLE:
635 // (+) geompy.kind.ARC_CIRCLE xc yc zc dx dy dz R x1 y1 z1 x2 y2 z2
636 aKind = SK_ARC_CIRCLE;
638 gp_Pnt aC = anInfo.Location();
639 theDoubles->Append(aC.X());
640 theDoubles->Append(aC.Y());
641 theDoubles->Append(aC.Z());
643 gp_Ax3 anAx3 = anInfo.Position();
644 gp_Dir aD = anAx3.Direction();
645 theDoubles->Append(aD.X());
646 theDoubles->Append(aD.Y());
647 theDoubles->Append(aD.Z());
649 theDoubles->Append(anInfo.Radius1());
651 gp_Pnt aP1 = anInfo.Pnt1();
652 theDoubles->Append(aP1.X());
653 theDoubles->Append(aP1.Y());
654 theDoubles->Append(aP1.Z());
656 gp_Pnt aP2 = anInfo.Pnt2();
657 theDoubles->Append(aP2.X());
658 theDoubles->Append(aP2.Y());
659 theDoubles->Append(aP2.Z());
662 case GEOMAlgo_KN_ELLIPSE:
664 // (+) geompy.kind.ELLIPSE xc yc zc dx dy dz R_1 R_2
667 gp_Pnt aC = anInfo.Location();
668 theDoubles->Append(aC.X());
669 theDoubles->Append(aC.Y());
670 theDoubles->Append(aC.Z());
672 gp_Ax3 anAx3 = anInfo.Position();
673 gp_Dir aD = anAx3.Direction();
674 theDoubles->Append(aD.X());
675 theDoubles->Append(aD.Y());
676 theDoubles->Append(aD.Z());
678 theDoubles->Append(anInfo.Radius1());
679 theDoubles->Append(anInfo.Radius2());
682 case GEOMAlgo_KN_ARCELLIPSE:
684 // (+) geompy.kind.ARC_ELLIPSE xc yc zc dx dy dz R_1 R_2 x1 y1 z1 x2 y2 z2
685 aKind = SK_ARC_ELLIPSE;
687 gp_Pnt aC = anInfo.Location();
688 theDoubles->Append(aC.X());
689 theDoubles->Append(aC.Y());
690 theDoubles->Append(aC.Z());
692 gp_Ax3 anAx3 = anInfo.Position();
693 gp_Dir aD = anAx3.Direction();
694 theDoubles->Append(aD.X());
695 theDoubles->Append(aD.Y());
696 theDoubles->Append(aD.Z());
698 theDoubles->Append(anInfo.Radius1());
699 theDoubles->Append(anInfo.Radius2());
701 gp_Pnt aP1 = anInfo.Pnt1();
702 theDoubles->Append(aP1.X());
703 theDoubles->Append(aP1.Y());
704 theDoubles->Append(aP1.Z());
706 gp_Pnt aP2 = anInfo.Pnt2();
707 theDoubles->Append(aP2.X());
708 theDoubles->Append(aP2.Y());
709 theDoubles->Append(aP2.Z());
712 case GEOMAlgo_KN_LINE:
714 // ??? geompy.kind.LINE x1 y1 z1 x2 y2 z2
715 // (+) geompy.kind.LINE x1 y1 z1 dx dy dz
718 gp_Pnt aO = anInfo.Location();
719 theDoubles->Append(aO.X());
720 theDoubles->Append(aO.Y());
721 theDoubles->Append(aO.Z());
723 gp_Dir aD = anInfo.Direction();
724 theDoubles->Append(aD.X());
725 theDoubles->Append(aD.Y());
726 theDoubles->Append(aD.Z());
729 case GEOMAlgo_KN_SEGMENT:
731 // (+) geompy.kind.SEGMENT x1 y1 z1 x2 y2 z2
734 gp_Pnt aP1 = anInfo.Pnt1();
735 theDoubles->Append(aP1.X());
736 theDoubles->Append(aP1.Y());
737 theDoubles->Append(aP1.Z());
739 gp_Pnt aP2 = anInfo.Pnt2();
740 theDoubles->Append(aP2.X());
741 theDoubles->Append(aP2.Y());
742 theDoubles->Append(aP2.Z());
746 // ??? geompy.kind.EDGE nb_vertices _curve_type_id_
747 // (+) geompy.kind.EDGE nb_vertices
748 theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
755 // (+) geompy.kind.VERTEX x y z
758 gp_Pnt aP = anInfo.Location();
759 theDoubles->Append(aP.X());
760 theDoubles->Append(aP.Y());
761 theDoubles->Append(aP.Z());
770 //=============================================================================
771 /*! Get LCS, corresponding to the given shape.
772 * Origin of the LCS is situated at the shape's center of mass.
773 * Axes of the LCS are obtained from shape's location or,
774 * if the shape is a planar face, from position of its plane.
776 //=============================================================================
777 gp_Ax3 GEOMImpl_IMeasureOperations::GetPosition (const TopoDS_Shape& theShape)
781 if (theShape.IsNull())
785 aResult.Transform(theShape.Location().Transformation());
786 if (theShape.ShapeType() == TopAbs_FACE) {
787 Handle(Geom_Surface) aGS = BRep_Tool::Surface(TopoDS::Face(theShape));
788 if (!aGS.IsNull() && aGS->IsKind(STANDARD_TYPE(Geom_Plane))) {
789 Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast(aGS);
790 gp_Pln aPln = aGPlane->Pln();
791 aResult = aPln.Position();
792 // In case of reverse orinetation of the face invert the plane normal
793 // (the face's normal does not mathc the plane's normal in this case)
794 if(theShape.Orientation() == TopAbs_REVERSED)
796 gp_Dir Vx = aResult.XDirection();
797 gp_Dir N = aResult.Direction().Mirrored(Vx);
798 gp_Pnt P = aResult.Location();
799 aResult = gp_Ax3(P, N, Vx);
807 TopAbs_ShapeEnum aShType = theShape.ShapeType();
809 if (aShType == TopAbs_VERTEX) {
810 aPnt = BRep_Tool::Pnt(TopoDS::Vertex(theShape));
813 if (aShType == TopAbs_COMPOUND) {
814 aShType = GEOMImpl_IShapesOperations::GetTypeOfSimplePart(theShape);
817 GProp_GProps aSystem;
818 if (aShType == TopAbs_EDGE || aShType == TopAbs_WIRE)
819 BRepGProp::LinearProperties(theShape, aSystem);
820 else if (aShType == TopAbs_FACE || aShType == TopAbs_SHELL)
821 BRepGProp::SurfaceProperties(theShape, aSystem);
823 BRepGProp::VolumeProperties(theShape, aSystem);
825 aPnt = aSystem.CentreOfMass();
828 aResult.SetLocation(aPnt);
833 //=============================================================================
837 //=============================================================================
838 void GEOMImpl_IMeasureOperations::GetPosition
839 (Handle(GEOM_Object) theShape,
840 Standard_Real& Ox, Standard_Real& Oy, Standard_Real& Oz,
841 Standard_Real& Zx, Standard_Real& Zy, Standard_Real& Zz,
842 Standard_Real& Xx, Standard_Real& Xy, Standard_Real& Xz)
846 //Set default values: global CS
847 Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
850 if (theShape.IsNull()) return;
852 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
853 if (aRefShape.IsNull()) return;
855 TopoDS_Shape aShape = aRefShape->GetValue();
856 if (aShape.IsNull()) {
857 SetErrorCode("The Objects has NULL Shape");
862 #if OCC_VERSION_LARGE > 0x06010000
866 gp_Ax3 anAx3 = GetPosition(aShape);
868 gp_Pnt anOri = anAx3.Location();
869 gp_Dir aDirZ = anAx3.Direction();
870 gp_Dir aDirX = anAx3.XDirection();
873 anOri.Coord(Ox, Oy, Oz);
874 aDirZ.Coord(Zx, Zy, Zz);
875 aDirX.Coord(Xx, Xy, Xz);
877 catch (Standard_Failure) {
878 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
879 SetErrorCode(aFail->GetMessageString());
886 //=============================================================================
890 //=============================================================================
891 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetCentreOfMass
892 (Handle(GEOM_Object) theShape)
896 if (theShape.IsNull()) return NULL;
898 //Add a new CentreOfMass object
899 Handle(GEOM_Object) aCDG = GetEngine()->AddObject(GetDocID(), GEOM_CDG);
901 //Add a new CentreOfMass function
902 Handle(GEOM_Function) aFunction =
903 aCDG->AddFunction(GEOMImpl_MeasureDriver::GetID(), CDG_MEASURE);
904 if (aFunction.IsNull()) return NULL;
906 //Check if the function is set correctly
907 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
909 GEOMImpl_IMeasure aCI (aFunction);
911 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
912 if (aRefShape.IsNull()) return NULL;
914 aCI.SetBase(aRefShape);
916 //Compute the CentreOfMass value
918 #if OCC_VERSION_LARGE > 0x06010000
921 if (!GetSolver()->ComputeFunction(aFunction)) {
922 SetErrorCode("Measure driver failed to compute centre of mass");
926 catch (Standard_Failure) {
927 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
928 SetErrorCode(aFail->GetMessageString());
932 //Make a Python command
933 GEOM::TPythonDump(aFunction) << aCDG << " = geompy.MakeCDG(" << theShape << ")";
939 //=============================================================================
943 //=============================================================================
944 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetVertexByIndex
945 (Handle(GEOM_Object) theShape,
946 Standard_Integer theIndex)
950 if (theShape.IsNull()) return NULL;
952 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
953 if (aRefShape.IsNull()) return NULL;
955 //Add a new Vertex object
956 Handle(GEOM_Object) aVertex = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
959 Handle(GEOM_Function) aFunction =
960 aVertex->AddFunction(GEOMImpl_MeasureDriver::GetID(), VERTEX_BY_INDEX);
961 if (aFunction.IsNull()) return NULL;
963 //Check if the function is set correctly
964 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
966 GEOMImpl_IMeasure aCI (aFunction);
967 aCI.SetBase(aRefShape);
968 aCI.SetIndex(theIndex);
972 #if OCC_VERSION_LARGE > 0x06010000
975 if (!GetSolver()->ComputeFunction(aFunction)) {
976 SetErrorCode("Vertex by index driver failed.");
980 catch (Standard_Failure) {
981 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
982 SetErrorCode(aFail->GetMessageString());
986 //Make a Python command
987 GEOM::TPythonDump(aFunction) << aVertex << " = geompy.GetVertexByIndex(" << theShape << ", " << theIndex << ")";
993 //=============================================================================
997 //=============================================================================
998 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetNormal
999 (Handle(GEOM_Object) theFace,
1000 Handle(GEOM_Object) theOptionalPoint)
1004 if (theFace.IsNull()) return NULL;
1006 //Add a new Normale object
1007 Handle(GEOM_Object) aNorm = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
1009 //Add a new Normale function
1010 Handle(GEOM_Function) aFunction =
1011 aNorm->AddFunction(GEOMImpl_MeasureDriver::GetID(), VECTOR_FACE_NORMALE);
1012 if (aFunction.IsNull()) return NULL;
1014 //Check if the function is set correctly
1015 if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
1017 GEOMImpl_IMeasure aCI (aFunction);
1019 Handle(GEOM_Function) aFace = theFace->GetLastFunction();
1020 if (aFace.IsNull()) return NULL;
1024 if (!theOptionalPoint.IsNull()) {
1025 Handle(GEOM_Function) anOptPnt = theOptionalPoint->GetLastFunction();
1026 aCI.SetPoint(anOptPnt);
1029 //Compute the Normale value
1031 #if OCC_VERSION_LARGE > 0x06010000
1034 if (!GetSolver()->ComputeFunction(aFunction)) {
1035 SetErrorCode("Measure driver failed to compute normake of face");
1039 catch (Standard_Failure) {
1040 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1041 SetErrorCode(aFail->GetMessageString());
1045 //Make a Python command
1046 GEOM::TPythonDump pd (aFunction);
1047 pd << aNorm << " = geompy.GetNormal(" << theFace;
1048 if (!theOptionalPoint.IsNull()) {
1049 pd << ", " << theOptionalPoint;
1057 //=============================================================================
1059 * GetBasicProperties
1061 //=============================================================================
1062 void GEOMImpl_IMeasureOperations::GetBasicProperties (Handle(GEOM_Object) theShape,
1063 Standard_Real& theLength,
1064 Standard_Real& theSurfArea,
1065 Standard_Real& theVolume)
1069 if (theShape.IsNull()) return;
1071 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1072 if (aRefShape.IsNull()) return;
1074 TopoDS_Shape aShape = aRefShape->GetValue();
1075 if (aShape.IsNull()) {
1076 SetErrorCode("The Objects has NULL Shape");
1080 //Compute the parameters
1081 GProp_GProps LProps, SProps;
1083 #if OCC_VERSION_LARGE > 0x06010000
1086 BRepGProp::LinearProperties(aShape, LProps);
1087 theLength = LProps.Mass();
1089 BRepGProp::SurfaceProperties(aShape, SProps);
1090 theSurfArea = SProps.Mass();
1093 if (aShape.ShapeType() < TopAbs_SHELL) {
1094 for (TopExp_Explorer Exp (aShape, TopAbs_SOLID); Exp.More(); Exp.Next()) {
1095 GProp_GProps VProps;
1096 BRepGProp::VolumeProperties(Exp.Current(), VProps);
1097 theVolume += VProps.Mass();
1101 catch (Standard_Failure) {
1102 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1103 SetErrorCode(aFail->GetMessageString());
1110 //=============================================================================
1114 //=============================================================================
1115 void GEOMImpl_IMeasureOperations::GetInertia
1116 (Handle(GEOM_Object) theShape,
1117 Standard_Real& I11, Standard_Real& I12, Standard_Real& I13,
1118 Standard_Real& I21, Standard_Real& I22, Standard_Real& I23,
1119 Standard_Real& I31, Standard_Real& I32, Standard_Real& I33,
1120 Standard_Real& Ix , Standard_Real& Iy , Standard_Real& Iz)
1124 if (theShape.IsNull()) return;
1126 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1127 if (aRefShape.IsNull()) return;
1129 TopoDS_Shape aShape = aRefShape->GetValue();
1130 if (aShape.IsNull()) {
1131 SetErrorCode("The Objects has NULL Shape");
1135 //Compute the parameters
1136 GProp_GProps System;
1139 #if OCC_VERSION_LARGE > 0x06010000
1142 if (aShape.ShapeType() == TopAbs_VERTEX ||
1143 aShape.ShapeType() == TopAbs_EDGE ||
1144 aShape.ShapeType() == TopAbs_WIRE) {
1145 BRepGProp::LinearProperties(aShape, System);
1146 } else if (aShape.ShapeType() == TopAbs_FACE ||
1147 aShape.ShapeType() == TopAbs_SHELL) {
1148 BRepGProp::SurfaceProperties(aShape, System);
1150 BRepGProp::VolumeProperties(aShape, System);
1152 gp_Mat I = System.MatrixOfInertia();
1166 GProp_PrincipalProps Pr = System.PrincipalProperties();
1167 Pr.Moments(Ix,Iy,Iz);
1169 catch (Standard_Failure) {
1170 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1171 SetErrorCode(aFail->GetMessageString());
1178 //=============================================================================
1182 //=============================================================================
1183 void GEOMImpl_IMeasureOperations::GetBoundingBox
1184 (Handle(GEOM_Object) theShape,
1185 Standard_Real& Xmin, Standard_Real& Xmax,
1186 Standard_Real& Ymin, Standard_Real& Ymax,
1187 Standard_Real& Zmin, Standard_Real& Zmax)
1191 if (theShape.IsNull()) return;
1193 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1194 if (aRefShape.IsNull()) return;
1196 TopoDS_Shape aShape = aRefShape->GetValue();
1197 if (aShape.IsNull()) {
1198 SetErrorCode("The Objects has NULL Shape");
1202 //Compute the parameters
1206 #if OCC_VERSION_LARGE > 0x06010000
1209 BRepBndLib::Add(aShape, B);
1210 B.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
1212 catch (Standard_Failure) {
1213 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1214 SetErrorCode(aFail->GetMessageString());
1221 //=============================================================================
1225 //=============================================================================
1226 void GEOMImpl_IMeasureOperations::GetTolerance
1227 (Handle(GEOM_Object) theShape,
1228 Standard_Real& FaceMin, Standard_Real& FaceMax,
1229 Standard_Real& EdgeMin, Standard_Real& EdgeMax,
1230 Standard_Real& VertMin, Standard_Real& VertMax)
1234 if (theShape.IsNull()) return;
1236 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1237 if (aRefShape.IsNull()) return;
1239 TopoDS_Shape aShape = aRefShape->GetValue();
1240 if (aShape.IsNull()) {
1241 SetErrorCode("The Objects has NULL Shape");
1245 //Compute the parameters
1247 FaceMin = EdgeMin = VertMin = RealLast();
1248 FaceMax = EdgeMax = VertMax = -RealLast();
1251 #if OCC_VERSION_LARGE > 0x06010000
1254 for (TopExp_Explorer ExF (aShape, TopAbs_FACE); ExF.More(); ExF.Next()) {
1255 TopoDS_Face Face = TopoDS::Face(ExF.Current());
1256 T = BRep_Tool::Tolerance(Face);
1262 for (TopExp_Explorer ExE (aShape, TopAbs_EDGE); ExE.More(); ExE.Next()) {
1263 TopoDS_Edge Edge = TopoDS::Edge(ExE.Current());
1264 T = BRep_Tool::Tolerance(Edge);
1270 for (TopExp_Explorer ExV (aShape, TopAbs_VERTEX); ExV.More(); ExV.Next()) {
1271 TopoDS_Vertex Vertex = TopoDS::Vertex(ExV.Current());
1272 T = BRep_Tool::Tolerance(Vertex);
1279 catch (Standard_Failure) {
1280 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1281 SetErrorCode(aFail->GetMessageString());
1288 //=============================================================================
1292 //=============================================================================
1293 bool GEOMImpl_IMeasureOperations::CheckShape (Handle(GEOM_Object) theShape,
1294 const Standard_Boolean theIsCheckGeom,
1295 TCollection_AsciiString& theDump)
1299 if (theShape.IsNull()) return false;
1301 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1302 if (aRefShape.IsNull()) return false;
1304 TopoDS_Shape aShape = aRefShape->GetValue();
1305 if (aShape.IsNull()) {
1306 SetErrorCode("The Objects has NULL Shape");
1310 //Compute the parameters
1311 bool isValid = false;
1313 #if OCC_VERSION_LARGE > 0x06010000
1316 BRepCheck_Analyzer ana (aShape, theIsCheckGeom);
1317 if (ana.IsValid()) {
1321 StructuralDump(ana, aShape, theDump);
1324 catch (Standard_Failure) {
1325 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1326 SetErrorCode(aFail->GetMessageString());
1334 //=============================================================================
1336 * CheckSelfIntersections
1338 //=============================================================================
1339 bool GEOMImpl_IMeasureOperations::CheckSelfIntersections
1340 (Handle(GEOM_Object) theShape,
1341 Handle(TColStd_HSequenceOfInteger)& theIntersections)
1344 bool isGood = false;
1346 if (theIntersections.IsNull())
1347 theIntersections = new TColStd_HSequenceOfInteger;
1349 theIntersections->Clear();
1351 if (theShape.IsNull())
1354 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1355 if (aRefShape.IsNull()) return isGood;
1357 TopoDS_Shape aShape = aRefShape->GetValue();
1358 if (aShape.IsNull()) return isGood;
1362 TopoDS_Compound aCS;
1363 TopoDS_Shape aScopy;
1364 NMTDS_Tools::CopyShape(aShape, aScopy);
1366 // Map sub-shapes and their indices
1367 TopTools_IndexedMapOfShape anIndices;
1368 TopExp::MapShapes(aScopy, anIndices);
1370 aBB.MakeCompound(aCS);
1371 aBB.Add(aCS, aScopy);
1373 NMTTools_CheckerSI aCSI; // checker of self-interferences
1374 aCSI.SetCompositeShape(aCS);
1376 // 1. Launch the checker
1378 Standard_Integer iErr = aCSI.StopStatus();
1380 return false; // Error
1385 // 2. Take the shapes from DS
1386 const NMTDS_ShapesDataStructure& aDS = *(aCSI.DS());
1387 Standard_Integer aNbS = aDS.NumberOfShapesOfTheObject();
1389 // 3. Get the pairs of interfered shapes
1390 NMTDS_PInterfPool pIP = aCSI.IP();
1391 //const NMTDS_ListOfPassKeyBoolean& aLPKB = pIP->Get();
1392 const NMTDS_ListOfPairBoolean& aLPKB = pIP->Get();
1394 Standard_Integer n1, n2;
1395 //NMTDS_ListIteratorOfListOfPassKeyBoolean aIt;
1396 NMTDS_ListIteratorOfListOfPairBoolean aIt;
1398 aIt.Initialize(aLPKB);
1399 for (; aIt.More(); aIt.Next()) {
1400 //const NMTDS_PassKeyBoolean& aPKB = aIt.Value();
1401 const NMTDS_PairBoolean& aPKB = aIt.Value();
1404 if (n1 > aNbS || n2 > aNbS)
1405 return false; // Error
1407 const TopoDS_Shape& aS1 = aDS.Shape(n1);
1408 const TopoDS_Shape& aS2 = aDS.Shape(n2);
1410 theIntersections->Append(anIndices.FindIndex(aS1));
1411 theIntersections->Append(anIndices.FindIndex(aS2));
1419 //=============================================================================
1423 //=============================================================================
1424 TCollection_AsciiString GEOMImpl_IMeasureOperations::IsGoodForSolid (Handle(GEOM_Object) theShape)
1428 TCollection_AsciiString aRes = "";
1430 if (theShape.IsNull()) {
1431 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1434 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1435 if (aRefShape.IsNull()) {
1436 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1439 TopoDS_Shape aShape = aRefShape->GetValue();
1440 if (aShape.IsNull()) {
1441 aRes = "WRN_NULL_OBJECT_OR_SHAPE";
1444 if (aShape.ShapeType() == TopAbs_COMPOUND) {
1445 TopoDS_Iterator It (aShape, Standard_True, Standard_True);
1446 if (It.More()) aShape = It.Value();
1448 if (aShape.ShapeType() == TopAbs_SHELL) {
1449 BRepCheck_Shell chkShell (TopoDS::Shell(aShape));
1450 if (chkShell.Closed() == BRepCheck_NotClosed) {
1451 aRes = "WRN_SHAPE_UNCLOSED";
1455 aRes = "WRN_SHAPE_NOT_SHELL";
1467 //=============================================================================
1471 //=============================================================================
1472 TCollection_AsciiString GEOMImpl_IMeasureOperations::WhatIs (Handle(GEOM_Object) theShape)
1476 TCollection_AsciiString Astr;
1478 if (theShape.IsNull()) return Astr;
1480 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1481 if (aRefShape.IsNull()) return Astr;
1483 TopoDS_Shape aShape = aRefShape->GetValue();
1484 if (aShape.IsNull()) {
1485 SetErrorCode("The Objects has NULL Shape");
1489 //Compute the parameters
1490 if (aShape.ShapeType() == TopAbs_EDGE) {
1491 if (BRep_Tool::Degenerated(TopoDS::Edge(aShape))) {
1492 Astr = Astr + " It is a degenerated edge \n";
1496 Astr = Astr + " Number of sub-shapes : \n";
1499 #if OCC_VERSION_LARGE > 0x06010000
1502 int iType, nbTypes [TopAbs_SHAPE];
1503 for (iType = 0; iType < TopAbs_SHAPE; ++iType)
1505 nbTypes[aShape.ShapeType()]++;
1507 TopTools_MapOfShape aMapOfShape;
1508 aMapOfShape.Add(aShape);
1509 TopTools_ListOfShape aListOfShape;
1510 aListOfShape.Append(aShape);
1512 TopTools_ListIteratorOfListOfShape itL (aListOfShape);
1513 for (; itL.More(); itL.Next()) {
1514 TopoDS_Iterator it (itL.Value());
1515 for (; it.More(); it.Next()) {
1516 TopoDS_Shape s = it.Value();
1517 if (aMapOfShape.Add(s)) {
1518 aListOfShape.Append(s);
1519 nbTypes[s.ShapeType()]++;
1524 Astr = Astr + " VERTEX : " + TCollection_AsciiString(nbTypes[TopAbs_VERTEX]) + "\n";
1525 Astr = Astr + " EDGE : " + TCollection_AsciiString(nbTypes[TopAbs_EDGE]) + "\n";
1526 Astr = Astr + " WIRE : " + TCollection_AsciiString(nbTypes[TopAbs_WIRE]) + "\n";
1527 Astr = Astr + " FACE : " + TCollection_AsciiString(nbTypes[TopAbs_FACE]) + "\n";
1528 Astr = Astr + " SHELL : " + TCollection_AsciiString(nbTypes[TopAbs_SHELL]) + "\n";
1529 Astr = Astr + " SOLID : " + TCollection_AsciiString(nbTypes[TopAbs_SOLID]) + "\n";
1530 Astr = Astr + " COMPSOLID : " + TCollection_AsciiString(nbTypes[TopAbs_COMPSOLID]) + "\n";
1531 Astr = Astr + " COMPOUND : " + TCollection_AsciiString(nbTypes[TopAbs_COMPOUND]) + "\n";
1532 Astr = Astr + " SHAPE : " + TCollection_AsciiString(aMapOfShape.Extent());
1534 catch (Standard_Failure) {
1535 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1536 SetErrorCode(aFail->GetMessageString());
1545 //=======================================================================
1546 //function : CheckSingularCase
1547 //purpose : auxilary for GetMinDistance()
1548 // workaround for bugs 19899, 19908 and 19910 from Mantis
1549 //=======================================================================
1550 static double CheckSingularCase(const TopoDS_Shape& aSh1,
1551 const TopoDS_Shape& aSh2,
1552 gp_Pnt& Ptmp1, gp_Pnt& Ptmp2)
1554 bool IsChange1 = false;
1555 double AddDist1 = 0.0;
1556 TopExp_Explorer anExp;
1557 TopoDS_Shape tmpSh1, tmpSh2;
1559 for ( anExp.Init( aSh1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1561 tmpSh1 = anExp.Current();
1564 TopoDS_Shape sh = aSh1;
1565 while(sh.ShapeType()==TopAbs_COMPOUND) {
1566 TopoDS_Iterator it(sh);
1569 Handle(Geom_Surface) S = BRep_Tool::Surface(TopoDS::Face(tmpSh1));
1570 if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1571 S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1572 if( sh.ShapeType()==TopAbs_SHELL || sh.ShapeType()==TopAbs_FACE ) {
1575 // changes for 0020677: EDF 1219 GEOM: MinDistance gives 0 instead of 20.88
1576 //S->Bounds(U1,U2,V1,V2); changed by
1577 ShapeAnalysis::GetFaceUVBounds(TopoDS::Face(tmpSh1),U1,U2,V1,V2);
1578 // end of changes for 020677 (dmv)
1579 Handle(Geom_RectangularTrimmedSurface) TrS1 =
1580 new Geom_RectangularTrimmedSurface(S,U1,(U1+U2)/2.,V1,V2);
1581 Handle(Geom_RectangularTrimmedSurface) TrS2 =
1582 new Geom_RectangularTrimmedSurface(S,(U1+U2)/2.,U2,V1,V2);
1585 TopoDS_Compound Comp;
1586 B.MakeCompound(Comp);
1587 B.MakeFace(F1,TrS1,1.e-7);
1589 B.MakeFace(F2,TrS2,1.e-7);
1591 Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
1593 sfs->SetPrecision(1.e-6);
1594 sfs->SetMaxTolerance(1.0);
1596 tmpSh1 = sfs->Shape();
1600 if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ) {
1601 Handle(Geom_SphericalSurface) SS = Handle(Geom_SphericalSurface)::DownCast(S);
1602 gp_Pnt PC = SS->Location();
1605 B.MakeVertex(V,PC,1.e-7);
1607 AddDist1 = SS->Radius();
1611 Handle(Geom_ToroidalSurface) TS = Handle(Geom_ToroidalSurface)::DownCast(S);
1612 gp_Ax3 ax3 = TS->Position();
1613 Handle(Geom_Circle) C = new Geom_Circle(ax3.Ax2(),TS->MajorRadius());
1616 B.MakeEdge(E,C,1.e-7);
1618 AddDist1 = TS->MinorRadius();
1628 bool IsChange2 = false;
1629 double AddDist2 = 0.0;
1631 for ( anExp.Init( aSh2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1633 tmpSh2 = anExp.Current();
1636 TopoDS_Shape sh = aSh2;
1637 while(sh.ShapeType()==TopAbs_COMPOUND) {
1638 TopoDS_Iterator it(sh);
1641 Handle(Geom_Surface) S = BRep_Tool::Surface(TopoDS::Face(tmpSh2));
1642 if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1643 S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1644 if( sh.ShapeType()==TopAbs_SHELL || sh.ShapeType()==TopAbs_FACE ) {
1647 //S->Bounds(U1,U2,V1,V2);
1648 ShapeAnalysis::GetFaceUVBounds(TopoDS::Face(tmpSh2),U1,U2,V1,V2);
1649 Handle(Geom_RectangularTrimmedSurface) TrS1 =
1650 new Geom_RectangularTrimmedSurface(S,U1,(U1+U2)/2.,V1,V2);
1651 Handle(Geom_RectangularTrimmedSurface) TrS2 =
1652 new Geom_RectangularTrimmedSurface(S,(U1+U2)/2.,U2,V1,V2);
1655 TopoDS_Compound Comp;
1656 B.MakeCompound(Comp);
1657 B.MakeFace(F1,TrS1,1.e-7);
1659 B.MakeFace(F2,TrS2,1.e-7);
1661 Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
1663 sfs->SetPrecision(1.e-6);
1664 sfs->SetMaxTolerance(1.0);
1666 tmpSh2 = sfs->Shape();
1670 if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ) {
1671 Handle(Geom_SphericalSurface) SS = Handle(Geom_SphericalSurface)::DownCast(S);
1672 gp_Pnt PC = SS->Location();
1675 B.MakeVertex(V,PC,1.e-7);
1677 AddDist2 = SS->Radius();
1680 else if( S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1681 Handle(Geom_ToroidalSurface) TS = Handle(Geom_ToroidalSurface)::DownCast(S);
1682 gp_Ax3 ax3 = TS->Position();
1683 Handle(Geom_Circle) C = new Geom_Circle(ax3.Ax2(),TS->MajorRadius());
1686 B.MakeEdge(E,C,1.e-7);
1688 AddDist2 = TS->MinorRadius();
1699 if( !IsChange1 && !IsChange2 )
1702 BRepExtrema_DistShapeShape dst(tmpSh1,tmpSh2);
1704 double MinDist = 1.e9;
1705 gp_Pnt PMin1, PMin2, P1, P2;
1706 for (int i = 1; i <= dst.NbSolution(); i++) {
1707 P1 = dst.PointOnShape1(i);
1708 P2 = dst.PointOnShape2(i);
1709 Standard_Real Dist = P1.Distance(P2);
1710 if (MinDist > Dist) {
1721 gp_Dir aDir(gp_Vec(PMin1,PMin2));
1722 if( MinDist > (AddDist1+AddDist2) ) {
1723 Ptmp1 = gp_Pnt( PMin1.X() + aDir.X()*AddDist1,
1724 PMin1.Y() + aDir.Y()*AddDist1,
1725 PMin1.Z() + aDir.Z()*AddDist1 );
1726 Ptmp2 = gp_Pnt( PMin2.X() - aDir.X()*AddDist2,
1727 PMin2.Y() - aDir.Y()*AddDist2,
1728 PMin2.Z() - aDir.Z()*AddDist2 );
1729 return (MinDist - AddDist1 - AddDist2);
1732 if( AddDist1 > 0 ) {
1733 Ptmp1 = gp_Pnt( PMin1.X() + aDir.X()*AddDist1,
1734 PMin1.Y() + aDir.Y()*AddDist1,
1735 PMin1.Z() + aDir.Z()*AddDist1 );
1739 Ptmp2 = gp_Pnt( PMin2.X() - aDir.X()*AddDist2,
1740 PMin2.Y() - aDir.Y()*AddDist2,
1741 PMin2.Z() - aDir.Z()*AddDist2 );
1746 double res = MinDist - AddDist1 - AddDist2;
1747 if(res<0.) res = 0.0;
1753 static bool CheckSingularCase(const TopoDS_Shape& aSh1,
1754 const TopoDS_Shape& aSh2,
1757 TopExp_Explorer anExp;
1758 TopoDS_Shape tmpSh1, tmpSh2;
1760 for ( anExp.Init( aSh1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1762 tmpSh1 = anExp.Current();
1765 Handle(Geom_Surface) S1 = BRep_Tool::Surface(TopoDS::Face(tmpSh1));
1766 if( S1->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1767 S1->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1769 for ( anExp.Init( aSh2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1771 tmpSh2 = anExp.Current();
1772 Handle(Geom_Surface) S2 = BRep_Tool::Surface(TopoDS::Face(tmpSh2));
1773 GeomAPI_IntSS ISS(S1,S2,1.e-7);
1775 for(int i=1; i<=ISS.NbLines(); i++) {
1776 Handle(Geom_Curve) C3d = ISS.Line(i);
1779 B.MakeEdge(E,C3d,1.e-7);
1780 BRepExtrema_DistShapeShape dst(tmpSh2,E);
1782 gp_Pnt PMin1, PMin2, P1, P2;
1783 double MinDist = 1.e9;
1784 for (int i = 1; i <= dst.NbSolution(); i++) {
1785 P1 = dst.PointOnShape1(i);
1786 P2 = dst.PointOnShape2(i);
1787 Standard_Real Dist = P1.Distance(P2);
1788 if (MinDist > Dist) {
1802 for ( anExp.Init( aSh2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1804 tmpSh1 = anExp.Current();
1807 Handle(Geom_Surface) S1 = BRep_Tool::Surface(TopoDS::Face(tmpSh1));
1808 if( S1->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1809 S1->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1811 for ( anExp.Init( aSh1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1813 tmpSh2 = anExp.Current();
1814 Handle(Geom_Surface) S2 = BRep_Tool::Surface(TopoDS::Face(tmpSh2));
1815 GeomAPI_IntSS ISS(S1,S2,1.e-7);
1817 for(int i=1; i<=ISS.NbLines(); i++) {
1818 Handle(Geom_Curve) C3d = ISS.Line(i);
1821 B.MakeEdge(E,C3d,1.e-7);
1822 BRepExtrema_DistShapeShape dst(tmpSh2,E);
1825 double MinDist = 1.e9;
1826 for (int i = 1; i <= dst.NbSolution(); i++) {
1827 P1 = dst.PointOnShape1(i);
1828 P2 = dst.PointOnShape2(i);
1829 Standard_Real Dist = P1.Distance(P2);
1830 if (MinDist > Dist) {
1848 //=============================================================================
1852 //=============================================================================
1853 std::vector<bool> GEOMImpl_IMeasureOperations::AreCoordsInside(Handle(GEOM_Object) theShape,
1854 const std::vector<double>& coords,
1857 std::vector<bool> res;
1858 if (!theShape.IsNull()) {
1859 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1860 if (!aRefShape.IsNull()) {
1861 TopoDS_Shape aShape = aRefShape->GetValue();
1862 if (!aShape.IsNull()) {
1863 BRepClass3d_SolidClassifier SC(aShape);
1864 unsigned int nb_points = coords.size()/3;
1865 for (int i = 0; i < nb_points; i++) {
1866 double x = coords[3*i];
1867 double y = coords[3*i+1];
1868 double z = coords[3*i+2];
1869 gp_Pnt aPnt(x, y, z);
1870 SC.Perform(aPnt, tolerance);
1871 res.push_back( ( SC.State() == TopAbs_IN ) || ( SC.State() == TopAbs_ON ) );
1879 //=============================================================================
1883 //=============================================================================
1884 Standard_Real GEOMImpl_IMeasureOperations::GetMinDistance
1885 (Handle(GEOM_Object) theShape1, Handle(GEOM_Object) theShape2,
1886 Standard_Real& X1, Standard_Real& Y1, Standard_Real& Z1,
1887 Standard_Real& X2, Standard_Real& Y2, Standard_Real& Z2)
1890 Standard_Real MinDist = 1.e9;
1892 if (theShape1.IsNull() || theShape2.IsNull()) return MinDist;
1894 Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
1895 Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
1896 if (aRefShape1.IsNull() || aRefShape2.IsNull()) return MinDist;
1898 TopoDS_Shape aShape1 = aRefShape1->GetValue();
1899 TopoDS_Shape aShape2 = aRefShape2->GetValue();
1900 if (aShape1.IsNull() || aShape2.IsNull()) {
1901 SetErrorCode("One of Objects has NULL Shape");
1905 //Compute the parameters
1907 #if OCC_VERSION_LARGE > 0x06010000
1911 // Issue 0020231: A min distance bug with torus and vertex.
1912 // Make GetMinDistance() return zero if a sole VERTEX is inside any of SOLIDs
1914 // which of shapes consists of only one vertex?
1915 TopExp_Explorer exp1(aShape1,TopAbs_VERTEX), exp2(aShape2,TopAbs_VERTEX);
1916 TopoDS_Shape V1 = exp1.More() ? exp1.Current() : TopoDS_Shape();
1917 TopoDS_Shape V2 = exp2.More() ? exp2.Current() : TopoDS_Shape();
1918 exp1.Next(); exp2.Next();
1919 if ( exp1.More() ) V1.Nullify();
1920 if ( exp2.More() ) V2.Nullify();
1921 // vertex and container of solids
1922 TopoDS_Shape V = V1.IsNull() ? V2 : V1;
1923 TopoDS_Shape S = V1.IsNull() ? aShape1 : aShape2;
1924 if ( !V.IsNull() ) {
1925 // classify vertex against solids
1926 gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( V ) );
1927 for ( exp1.Init( S, TopAbs_SOLID ); exp1.More(); exp1.Next() ) {
1928 BRepClass3d_SolidClassifier classifier( exp1.Current(), p, 1e-6);
1929 if ( classifier.State() == TopAbs_IN ) {
1930 p.Coord(X1, Y1, Z1);
1931 p.Coord(X2, Y2, Z2);
1937 // End Issue 0020231
1940 // additional workaround for bugs 19899, 19908 and 19910 from Mantis
1941 gp_Pnt Ptmp1, Ptmp2;
1942 double dist = CheckSingularCase(aShape1, aShape2, Ptmp1, Ptmp2);
1944 Ptmp1.Coord(X1, Y1, Z1);
1945 Ptmp2.Coord(X2, Y2, Z2);
1950 BRepExtrema_DistShapeShape dst (aShape1, aShape2);
1952 gp_Pnt PMin1, PMin2, P1, P2;
1954 for (int i = 1; i <= dst.NbSolution(); i++) {
1955 P1 = dst.PointOnShape1(i);
1956 P2 = dst.PointOnShape2(i);
1958 Standard_Real Dist = P1.Distance(P2);
1959 if (MinDist > Dist) {
1966 PMin1.Coord(X1, Y1, Z1);
1967 PMin2.Coord(X2, Y2, Z2);
1970 catch (Standard_Failure) {
1971 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1972 SetErrorCode(aFail->GetMessageString());
1980 //=======================================================================
1982 * Get coordinates of point
1984 //=======================================================================
1985 void GEOMImpl_IMeasureOperations::PointCoordinates (Handle(GEOM_Object) theShape,
1986 Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ)
1990 if (theShape.IsNull())
1993 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1994 if (aRefShape.IsNull())
1997 TopoDS_Shape aShape = aRefShape->GetValue();
1998 if (aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX)
2000 SetErrorCode( "Shape must be a vertex" );
2005 #if OCC_VERSION_LARGE > 0x06010000
2008 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
2015 catch (Standard_Failure)
2017 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2018 SetErrorCode( aFail->GetMessageString() );
2022 //=======================================================================
2024 * Compute angle (in degrees) between two lines
2026 //=======================================================================
2027 Standard_Real GEOMImpl_IMeasureOperations::GetAngle (Handle(GEOM_Object) theLine1,
2028 Handle(GEOM_Object) theLine2)
2030 if (theLine1->GetType() == GEOM_VECTOR &&
2031 theLine2->GetType() == GEOM_VECTOR)
2032 return GetAngleBtwVectors(theLine1, theLine2);
2036 Standard_Real anAngle = -1.0;
2038 if (theLine1.IsNull() || theLine2.IsNull())
2041 Handle(GEOM_Function) aRefLine1 = theLine1->GetLastFunction();
2042 Handle(GEOM_Function) aRefLine2 = theLine2->GetLastFunction();
2043 if (aRefLine1.IsNull() || aRefLine2.IsNull())
2046 TopoDS_Shape aLine1 = aRefLine1->GetValue();
2047 TopoDS_Shape aLine2 = aRefLine2->GetValue();
2048 if (aLine1.IsNull() || aLine2.IsNull() ||
2049 aLine1.ShapeType() != TopAbs_EDGE ||
2050 aLine2.ShapeType() != TopAbs_EDGE)
2052 SetErrorCode("Two edges must be given");
2057 #if OCC_VERSION_LARGE > 0x06010000
2060 TopoDS_Edge E1 = TopoDS::Edge(aLine1);
2061 TopoDS_Edge E2 = TopoDS::Edge(aLine2);
2064 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp,lp);
2065 Handle(Geom_Curve) C2 = BRep_Tool::Curve(E2,fp,lp);
2067 if ( C1.IsNull() || C2.IsNull() ||
2068 !C1->IsKind(STANDARD_TYPE(Geom_Line)) ||
2069 !C2->IsKind(STANDARD_TYPE(Geom_Line)))
2071 SetErrorCode("The edges must be linear");
2075 Handle(Geom_Line) L1 = Handle(Geom_Line)::DownCast(C1);
2076 Handle(Geom_Line) L2 = Handle(Geom_Line)::DownCast(C2);
2078 gp_Lin aLin1 = L1->Lin();
2079 gp_Lin aLin2 = L2->Lin();
2081 anAngle = aLin1.Angle(aLin2);
2082 anAngle *= 180. / M_PI; // convert radians into degrees
2084 if (anAngle > 90.0) {
2085 anAngle = 180.0 - anAngle;
2090 catch (Standard_Failure)
2092 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2093 SetErrorCode(aFail->GetMessageString());
2099 //=======================================================================
2101 * Compute angle (in degrees) between two vectors
2103 //=======================================================================
2104 Standard_Real GEOMImpl_IMeasureOperations::GetAngleBtwVectors (Handle(GEOM_Object) theVec1,
2105 Handle(GEOM_Object) theVec2)
2109 Standard_Real anAngle = -1.0;
2111 if (theVec1.IsNull() || theVec2.IsNull())
2114 Handle(GEOM_Function) aRefVec1 = theVec1->GetLastFunction();
2115 Handle(GEOM_Function) aRefVec2 = theVec2->GetLastFunction();
2116 if (aRefVec1.IsNull() || aRefVec2.IsNull())
2119 TopoDS_Shape aVec1 = aRefVec1->GetValue();
2120 TopoDS_Shape aVec2 = aRefVec2->GetValue();
2121 if (aVec1.IsNull() || aVec2.IsNull() ||
2122 aVec1.ShapeType() != TopAbs_EDGE ||
2123 aVec2.ShapeType() != TopAbs_EDGE)
2125 SetErrorCode("Two edges must be given");
2130 #if OCC_VERSION_LARGE > 0x06010000
2133 TopoDS_Edge aE1 = TopoDS::Edge(aVec1);
2134 TopoDS_Edge aE2 = TopoDS::Edge(aVec2);
2136 TopoDS_Vertex aP11, aP12, aP21, aP22;
2137 TopExp::Vertices(aE1, aP11, aP12, Standard_True);
2138 TopExp::Vertices(aE2, aP21, aP22, Standard_True);
2139 if (aP11.IsNull() || aP12.IsNull() || aP21.IsNull() || aP22.IsNull()) {
2140 SetErrorCode("Bad edge given");
2144 gp_Vec aV1 (BRep_Tool::Pnt(aP11), BRep_Tool::Pnt(aP12));
2145 gp_Vec aV2 (BRep_Tool::Pnt(aP21), BRep_Tool::Pnt(aP22)) ;
2147 anAngle = aV1.Angle(aV2);
2148 anAngle *= 180. / M_PI; // convert radians into degrees
2152 catch (Standard_Failure)
2154 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2155 SetErrorCode(aFail->GetMessageString());
2162 //=============================================================================
2164 * CurveCurvatureByParam
2166 //=============================================================================
2167 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByParam
2168 (Handle(GEOM_Object) theCurve, Standard_Real& theParam)
2171 Standard_Real aRes = -1.0;
2173 if(theCurve.IsNull()) return aRes;
2175 Handle(GEOM_Function) aRefShape = theCurve->GetLastFunction();
2176 if(aRefShape.IsNull()) return aRes;
2178 TopoDS_Shape aShape = aRefShape->GetValue();
2179 if(aShape.IsNull()) {
2180 SetErrorCode("One of Objects has NULL Shape");
2184 Standard_Real aFP, aLP, aP;
2185 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aFP, aLP);
2186 aP = aFP + (aLP - aFP) * theParam;
2188 if(aCurve.IsNull()) return aRes;
2192 #if OCC_VERSION_LARGE > 0x06010000
2195 GeomLProp_CLProps Prop = GeomLProp_CLProps
2196 (aCurve, aP, 2, Precision::Confusion());
2197 aRes = fabs(Prop.Curvature());
2200 catch (Standard_Failure) {
2201 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2202 SetErrorCode(aFail->GetMessageString());
2206 if( aRes > Precision::Confusion() )
2215 //=============================================================================
2217 * CurveCurvatureByPoint
2219 //=============================================================================
2220 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByPoint
2221 (Handle(GEOM_Object) theCurve, Handle(GEOM_Object) thePoint)
2224 Standard_Real aRes = -1.0;
2226 if( theCurve.IsNull() || thePoint.IsNull() ) return aRes;
2228 Handle(GEOM_Function) aRefCurve = theCurve->GetLastFunction();
2229 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2230 if( aRefCurve.IsNull() || aRefPoint.IsNull() ) return aRes;
2232 TopoDS_Edge anEdge = TopoDS::Edge(aRefCurve->GetValue());
2233 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2234 if( anEdge.IsNull() || aPnt.IsNull() ) {
2235 SetErrorCode("One of Objects has NULL Shape");
2239 Standard_Real aFP, aLP;
2240 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFP, aLP);
2241 if(aCurve.IsNull()) return aRes;
2242 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2246 #if OCC_VERSION_LARGE > 0x06010000
2249 GeomAPI_ProjectPointOnCurve PPCurve(aPoint, aCurve, aFP, aLP);
2250 if(PPCurve.NbPoints()>0) {
2251 GeomLProp_CLProps Prop = GeomLProp_CLProps
2252 (aCurve, PPCurve.LowerDistanceParameter(), 2, Precision::Confusion());
2253 aRes = fabs(Prop.Curvature());
2257 catch (Standard_Failure) {
2258 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2259 SetErrorCode(aFail->GetMessageString());
2263 if( aRes > Precision::Confusion() )
2272 //=============================================================================
2274 * getSurfaceCurvatures
2276 //=============================================================================
2277 Standard_Real GEOMImpl_IMeasureOperations::getSurfaceCurvatures
2278 (const Handle(Geom_Surface)& aSurf,
2279 Standard_Real theUParam,
2280 Standard_Real theVParam,
2281 Standard_Boolean theNeedMaxCurv)
2284 Standard_Real aRes = 1.0;
2286 if (aSurf.IsNull()) return aRes;
2289 #if OCC_VERSION_LARGE > 0x06010000
2292 GeomLProp_SLProps Prop = GeomLProp_SLProps
2293 (aSurf, theUParam, theVParam, 2, Precision::Confusion());
2294 if(Prop.IsCurvatureDefined()) {
2295 if(Prop.IsUmbilic()) {
2296 //cout<<"is umbilic"<<endl;
2297 aRes = fabs(Prop.MeanCurvature());
2300 //cout<<"is not umbilic"<<endl;
2301 double c1 = fabs(Prop.MaxCurvature());
2302 double c2 = fabs(Prop.MinCurvature());
2311 catch (Standard_Failure) {
2312 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2313 SetErrorCode(aFail->GetMessageString());
2317 if( fabs(aRes) > Precision::Confusion() )
2326 //=============================================================================
2328 * MaxSurfaceCurvatureByParam
2330 //=============================================================================
2331 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByParam
2332 (Handle(GEOM_Object) theSurf,
2333 Standard_Real& theUParam,
2334 Standard_Real& theVParam)
2337 Standard_Real aRes = -1.0;
2339 if (theSurf.IsNull()) return aRes;
2341 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2342 if(aRefShape.IsNull()) return aRes;
2344 TopoDS_Shape aShape = aRefShape->GetValue();
2345 if(aShape.IsNull()) {
2346 SetErrorCode("One of Objects has NULL Shape");
2350 TopoDS_Face F = TopoDS::Face(aShape);
2351 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2353 //Compute the parameters
2354 Standard_Real U1,U2,V1,V2;
2355 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2356 Standard_Real U = U1 + (U2-U1)*theUParam;
2357 Standard_Real V = V1 + (V2-V1)*theVParam;
2359 return getSurfaceCurvatures(aSurf, U, V, true);
2363 //=============================================================================
2365 * MaxSurfaceCurvatureByPoint
2367 //=============================================================================
2368 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByPoint
2369 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2372 Standard_Real aRes = -1.0;
2374 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2376 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2377 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2378 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2380 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2381 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2382 if( aFace.IsNull() || aPnt.IsNull() ) {
2383 SetErrorCode("One of Objects has NULL Shape");
2387 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2388 if(aSurf.IsNull()) return aRes;
2389 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2391 //Compute the parameters
2392 ShapeAnalysis_Surface sas(aSurf);
2393 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2395 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), true);
2399 //=============================================================================
2401 * MinSurfaceCurvatureByParam
2403 //=============================================================================
2404 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByParam
2405 (Handle(GEOM_Object) theSurf,
2406 Standard_Real& theUParam,
2407 Standard_Real& theVParam)
2410 Standard_Real aRes = -1.0;
2412 if (theSurf.IsNull()) return aRes;
2414 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2415 if(aRefShape.IsNull()) return aRes;
2417 TopoDS_Shape aShape = aRefShape->GetValue();
2418 if(aShape.IsNull()) {
2419 SetErrorCode("One of Objects has NULL Shape");
2423 TopoDS_Face F = TopoDS::Face(aShape);
2424 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2426 //Compute the parameters
2427 Standard_Real U1,U2,V1,V2;
2428 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2429 Standard_Real U = U1 + (U2-U1)*theUParam;
2430 Standard_Real V = V1 + (V2-V1)*theVParam;
2432 return getSurfaceCurvatures(aSurf, U, V, false);
2436 //=============================================================================
2438 * MinSurfaceCurvatureByPoint
2440 //=============================================================================
2441 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByPoint
2442 (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2445 Standard_Real aRes = -1.0;
2447 if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2449 Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2450 Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2451 if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2453 TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2454 TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2455 if( aFace.IsNull() || aPnt.IsNull() ) {
2456 SetErrorCode("One of Objects has NULL Shape");
2460 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2461 if(aSurf.IsNull()) return aRes;
2462 gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2464 //Compute the parameters
2465 ShapeAnalysis_Surface sas(aSurf);
2466 gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2468 return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), false);
2472 //=======================================================================
2473 //function : StructuralDump
2474 //purpose : Structural (data exchange) style of output.
2475 //=======================================================================
2476 void GEOMImpl_IMeasureOperations::StructuralDump (const BRepCheck_Analyzer& theAna,
2477 const TopoDS_Shape& theShape,
2478 TCollection_AsciiString& theDump)
2482 theDump += " -- The Shape has problems :\n";
2483 theDump += " Check Count\n";
2484 theDump += " ------------------------------------------------\n";
2486 Standard_Integer last_stat = (Standard_Integer)BRepCheck_CheckFail;
2487 Handle(TColStd_HArray1OfInteger) NbProblems =
2488 new TColStd_HArray1OfInteger(1, last_stat);
2489 for (i = 1; i <= last_stat; i++)
2490 NbProblems->SetValue(i,0);
2492 Handle(TopTools_HSequenceOfShape) sl;
2493 sl = new TopTools_HSequenceOfShape();
2494 TopTools_DataMapOfShapeListOfShape theMap;
2496 GetProblemShapes(theAna, theShape, sl, NbProblems, theMap);
2499 Standard_Integer count = 0;
2500 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnCurve);
2502 theDump += " Invalid Point on Curve ................... ";
2503 theDump += TCollection_AsciiString(count) + "\n";
2505 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnCurveOnSurface);
2507 theDump += " Invalid Point on CurveOnSurface .......... ";
2508 theDump += TCollection_AsciiString(count) + "\n";
2510 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnSurface);
2512 theDump += " Invalid Point on Surface ................. ";
2513 theDump += TCollection_AsciiString(count) + "\n";
2515 count = NbProblems->Value((Standard_Integer)BRepCheck_No3DCurve);
2517 theDump += " No 3D Curve .............................. ";
2518 theDump += TCollection_AsciiString(count) + "\n";
2520 count = NbProblems->Value((Standard_Integer)BRepCheck_Multiple3DCurve);
2522 theDump += " Multiple 3D Curve ........................ ";
2523 theDump += TCollection_AsciiString(count) + "\n";
2525 count = NbProblems->Value((Standard_Integer)BRepCheck_Invalid3DCurve);
2527 theDump += " Invalid 3D Curve ......................... ";
2528 theDump += TCollection_AsciiString(count) + "\n";
2530 count = NbProblems->Value((Standard_Integer)BRepCheck_NoCurveOnSurface);
2532 theDump += " No Curve on Surface ...................... ";
2533 theDump += TCollection_AsciiString(count) + "\n";
2535 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidCurveOnSurface);
2537 theDump += " Invalid Curve on Surface ................. ";
2538 theDump += TCollection_AsciiString(count) + "\n";
2540 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidCurveOnClosedSurface);
2542 theDump += " Invalid Curve on closed Surface .......... ";
2543 theDump += TCollection_AsciiString(count) + "\n";
2545 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidSameRangeFlag);
2547 theDump += " Invalid SameRange Flag ................... ";
2548 theDump += TCollection_AsciiString(count) + "\n";
2550 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidSameParameterFlag);
2552 theDump += " Invalid SameParameter Flag ............... ";
2553 theDump += TCollection_AsciiString(count) + "\n";
2555 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidDegeneratedFlag);
2557 theDump += " Invalid Degenerated Flag ................. ";
2558 theDump += TCollection_AsciiString(count) + "\n";
2560 count = NbProblems->Value((Standard_Integer)BRepCheck_FreeEdge);
2562 theDump += " Free Edge ................................ ";
2563 theDump += TCollection_AsciiString(count) + "\n";
2565 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidMultiConnexity);
2567 theDump += " Invalid MultiConnexity ................... ";
2568 theDump += TCollection_AsciiString(count) + "\n";
2570 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidRange);
2572 theDump += " Invalid Range ............................ ";
2573 theDump += TCollection_AsciiString(count) + "\n";
2575 count = NbProblems->Value((Standard_Integer)BRepCheck_EmptyWire);
2577 theDump += " Empty Wire ............................... ";
2578 theDump += TCollection_AsciiString(count) + "\n";
2580 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantEdge);
2582 theDump += " Redundant Edge ........................... ";
2583 theDump += TCollection_AsciiString(count) + "\n";
2585 count = NbProblems->Value((Standard_Integer)BRepCheck_SelfIntersectingWire);
2587 theDump += " Self Intersecting Wire ................... ";
2588 theDump += TCollection_AsciiString(count) + "\n";
2590 count = NbProblems->Value((Standard_Integer)BRepCheck_NoSurface);
2592 theDump += " No Surface ............................... ";
2593 theDump += TCollection_AsciiString(count) + "\n";
2595 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidWire);
2597 theDump += " Invalid Wire ............................. ";
2598 theDump += TCollection_AsciiString(count) + "\n";
2600 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantWire);
2602 theDump += " Redundant Wire ........................... ";
2603 theDump += TCollection_AsciiString(count) + "\n";
2605 count = NbProblems->Value((Standard_Integer)BRepCheck_IntersectingWires);
2607 theDump += " Intersecting Wires ....................... ";
2608 theDump += TCollection_AsciiString(count) + "\n";
2610 count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidImbricationOfWires);
2612 theDump += " Invalid Imbrication of Wires ............. ";
2613 theDump += TCollection_AsciiString(count) + "\n";
2615 count = NbProblems->Value((Standard_Integer)BRepCheck_EmptyShell);
2617 theDump += " Empty Shell .............................. ";
2618 theDump += TCollection_AsciiString(count) + "\n";
2620 count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantFace);
2622 theDump += " Redundant Face ........................... ";
2623 theDump += TCollection_AsciiString(count) + "\n";
2625 count = NbProblems->Value((Standard_Integer)BRepCheck_UnorientableShape);
2627 theDump += " Unorientable Shape ....................... ";
2628 theDump += TCollection_AsciiString(count) + "\n";
2630 count = NbProblems->Value((Standard_Integer)BRepCheck_NotClosed);
2632 theDump += " Not Closed ............................... ";
2633 theDump += TCollection_AsciiString(count) + "\n";
2635 count = NbProblems->Value((Standard_Integer)BRepCheck_NotConnected);
2637 theDump += " Not Connected ............................ ";
2638 theDump += TCollection_AsciiString(count) + "\n";
2640 count = NbProblems->Value((Standard_Integer)BRepCheck_SubshapeNotInShape);
2642 theDump += " Sub-shape not in Shape .................... ";
2643 theDump += TCollection_AsciiString(count) + "\n";
2645 count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientation);
2647 theDump += " Bad Orientation .......................... ";
2648 theDump += TCollection_AsciiString(count) + "\n";
2650 count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientationOfSubshape);
2652 theDump += " Bad Orientation of Sub-shape .............. ";
2653 theDump += TCollection_AsciiString(count) + "\n";
2655 count = NbProblems->Value((Standard_Integer)BRepCheck_CheckFail);
2657 theDump += " checkshape failure ....................... ";
2658 theDump += TCollection_AsciiString(count) + "\n";
2661 theDump += " ------------------------------------------------\n";
2662 theDump += "*** Shapes with problems : ";
2663 theDump += TCollection_AsciiString(sl->Length()) + "\n";
2665 Standard_Integer nbv, nbe, nbw, nbf, nbs, nbo;
2666 nbv = nbe = nbw = nbf = nbs = nbo = 0;
2668 for (i = 1; i <= sl->Length(); i++) {
2669 TopoDS_Shape shi = sl->Value(i);
2670 TopAbs_ShapeEnum sti = shi.ShapeType();
2672 case TopAbs_VERTEX : nbv++; break;
2673 case TopAbs_EDGE : nbe++; break;
2674 case TopAbs_WIRE : nbw++; break;
2675 case TopAbs_FACE : nbf++; break;
2676 case TopAbs_SHELL : nbs++; break;
2677 case TopAbs_SOLID : nbo++; break;
2683 theDump += "VERTEX : ";
2684 if (nbv < 10) theDump += " ";
2685 theDump += TCollection_AsciiString(nbv) + "\n";
2688 theDump += "EDGE : ";
2689 if (nbe < 10) theDump += " ";
2690 theDump += TCollection_AsciiString(nbe) + "\n";
2693 theDump += "WIRE : ";
2694 if (nbw < 10) theDump += " ";
2695 theDump += TCollection_AsciiString(nbw) + "\n";
2698 theDump += "FACE : ";
2699 if (nbf < 10) theDump += " ";
2700 theDump += TCollection_AsciiString(nbf) + "\n";
2703 theDump += "SHELL : ";
2704 if (nbs < 10) theDump += " ";
2705 theDump += TCollection_AsciiString(nbs) + "\n";
2708 theDump += "SOLID : ";
2709 if (nbo < 10) theDump += " ";
2710 theDump += TCollection_AsciiString(nbo) + "\n";
2715 //=======================================================================
2716 //function : GetProblemShapes
2717 // purpose : for StructuralDump
2718 //=======================================================================
2719 void GEOMImpl_IMeasureOperations::GetProblemShapes (const BRepCheck_Analyzer& theAna,
2720 const TopoDS_Shape& theShape,
2721 Handle(TopTools_HSequenceOfShape)& sl,
2722 Handle(TColStd_HArray1OfInteger)& NbProblems,
2723 TopTools_DataMapOfShapeListOfShape& theMap)
2725 for (TopoDS_Iterator iter(theShape); iter.More(); iter.Next()) {
2726 GetProblemShapes(theAna, iter.Value(), sl, NbProblems, theMap);
2728 TopAbs_ShapeEnum styp = theShape.ShapeType();
2729 BRepCheck_ListIteratorOfListOfStatus itl;
2730 TopTools_ListOfShape empty;
2731 if (!theMap.IsBound(theShape)) {
2732 theMap.Bind(theShape,empty);
2734 if (!theAna.Result(theShape).IsNull()) {
2735 itl.Initialize(theAna.Result(theShape)->Status());
2736 // !!! May be, we have to print all the problems, not only the first one ?
2737 if (itl.Value() != BRepCheck_NoError) {
2738 sl->Append(theShape);
2739 BRepCheck_Status stat = itl.Value();
2740 NbProblems->SetValue((Standard_Integer)stat,
2741 NbProblems->Value((Standard_Integer)stat) + 1);
2748 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_VERTEX, theMap);
2751 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_WIRE, theMap);
2752 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_EDGE, theMap);
2753 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_VERTEX, theMap);
2758 GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_SHELL, theMap);
2765 //=======================================================================
2766 //function : Contains
2767 //=======================================================================
2768 static Standard_Boolean Contains (const TopTools_ListOfShape& L,
2769 const TopoDS_Shape& S)
2771 TopTools_ListIteratorOfListOfShape it;
2772 for (it.Initialize(L); it.More(); it.Next()) {
2773 if (it.Value().IsSame(S)) {
2774 return Standard_True;
2777 return Standard_False;
2780 //=======================================================================
2781 //function : GetProblemSub
2782 // purpose : for StructuralDump
2783 //=======================================================================
2784 void GEOMImpl_IMeasureOperations::GetProblemSub (const BRepCheck_Analyzer& theAna,
2785 const TopoDS_Shape& theShape,
2786 Handle(TopTools_HSequenceOfShape)& sl,
2787 Handle(TColStd_HArray1OfInteger)& NbProblems,
2788 const TopAbs_ShapeEnum Subtype,
2789 TopTools_DataMapOfShapeListOfShape& theMap)
2791 BRepCheck_ListIteratorOfListOfStatus itl;
2792 TopExp_Explorer exp;
2793 for (exp.Init(theShape, Subtype); exp.More(); exp.Next()) {
2794 const TopoDS_Shape& sub = exp.Current();
2796 const Handle(BRepCheck_Result)& res = theAna.Result(sub);
2797 for (res->InitContextIterator();
2798 res->MoreShapeInContext();
2799 res->NextShapeInContext()) {
2800 if (res->ContextualShape().IsSame(theShape) && !Contains(theMap(sub), theShape)) {
2801 theMap(sub).Append(theShape);
2802 itl.Initialize(res->StatusOnShape());
2804 if (itl.Value() != BRepCheck_NoError) {
2805 Standard_Integer ii = 0;
2807 for (ii = 1; ii <= sl->Length(); ii++)
2808 if (sl->Value(ii).IsSame(sub)) break;
2810 if (ii > sl->Length()) {
2812 BRepCheck_Status stat = itl.Value();
2813 NbProblems->SetValue((Standard_Integer)stat,
2814 NbProblems->Value((Standard_Integer)stat) + 1);
2816 for (ii = 1; ii <= sl->Length(); ii++)
2817 if (sl->Value(ii).IsSame(theShape)) break;
2818 if (ii > sl->Length()) {
2819 sl->Append(theShape);
2820 BRepCheck_Status stat = itl.Value();
2821 NbProblems->SetValue((Standard_Integer)stat,
2822 NbProblems->Value((Standard_Integer)stat) + 1);